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 HWND (WINAPI
*pCreateToolbarEx
)(HWND
, DWORD
, UINT
, INT
, HINSTANCE
, UINT_PTR
, const TBBUTTON
*,
41 INT
, INT
, INT
, INT
, INT
, UINT
);
42 static BOOL (WINAPI
*pImageList_Destroy
)(HIMAGELIST
);
43 static INT (WINAPI
*pImageList_GetImageCount
)(HIMAGELIST
);
44 static BOOL (WINAPI
*pImageList_GetIconSize
)(HIMAGELIST
, int *, int *);
45 static HIMAGELIST (WINAPI
*pImageList_LoadImageA
)(HINSTANCE
, LPCSTR
, int, int, COLORREF
, UINT
, UINT
);
47 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
50 static BOOL g_fBlockHotItemChange
;
51 static BOOL g_fReceivedHotItemChange
;
52 static BOOL g_fExpectedHotItemOld
;
53 static BOOL g_fExpectedHotItemNew
;
54 static DWORD g_dwExpectedDispInfoMask
;
55 static BOOL g_ResetDispTextPtr
;
57 static const struct message ttgetdispinfo_parent_seq
[] = {
58 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_GETINFOTIPA
},
59 { WM_NOTIFY
, sent
|id
, 0, 0, TTN_GETDISPINFOA
},
63 static const struct message save_parent_seq
[] = {
64 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, -1 },
65 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 0 },
66 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 1 },
67 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 2 },
68 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 3 },
69 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 4 },
70 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 5 },
71 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 6 },
75 static const struct message restore_parent_seq
[] = {
76 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, -1 },
77 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 0 },
78 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 1 },
79 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 2 },
80 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 3 },
81 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 4 },
82 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 5 },
83 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 6 },
84 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 7 },
85 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 8 },
86 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 9 },
87 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 0xa },
88 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_BEGINADJUST
},
89 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 0 },
90 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 1 },
91 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 2 },
92 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 3 },
93 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_ENDADJUST
},
97 #define DEFINE_EXPECT(func) \
98 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
100 #define CHECK_EXPECT2(func) \
102 ok(expect_ ##func, "unexpected call " #func "\n"); \
103 called_ ## func = TRUE; \
106 #define CHECK_CALLED(func) \
108 ok(called_ ## func, "expected " #func "\n"); \
109 expect_ ## func = called_ ## func = FALSE; \
112 #define SET_EXPECT(func) \
113 expect_ ## func = TRUE
115 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
117 #define check_rect(name, val, exp, ...) ok(EqualRect(&val, &exp), \
118 "invalid rect %s - expected %s - (" name ")\n", \
119 wine_dbgstr_rect(&val), wine_dbgstr_rect(&exp), __VA_ARGS__);
121 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
123 #define check_button_size(handle, width, height, ...) {\
124 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
125 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
128 static void MakeButton(TBBUTTON
*p
, int idCommand
, int fsStyle
, int nString
) {
130 p
->idCommand
= idCommand
;
131 p
->fsState
= TBSTATE_ENABLED
;
132 p
->fsStyle
= fsStyle
;
133 p
->iString
= nString
;
136 static void *alloced_str
;
138 static LRESULT
parent_wnd_notify(LPARAM lParam
)
140 NMHDR
*hdr
= (NMHDR
*)lParam
;
142 NMTBDISPINFOA
*nmdisp
;
145 case TBN_HOTITEMCHANGE
:
146 nmhi
= (NMTBHOTITEM
*)lParam
;
147 g_fReceivedHotItemChange
= TRUE
;
148 if (g_fExpectedHotItemOld
!= g_fExpectedHotItemNew
)
150 compare(nmhi
->idOld
, g_fExpectedHotItemOld
, "%d");
151 compare(nmhi
->idNew
, g_fExpectedHotItemNew
, "%d");
153 if (g_fBlockHotItemChange
)
157 case TBN_GETDISPINFOA
:
158 ok(FALSE
, "TBN_GETDISPINFOA received\n");
161 case TBN_GETINFOTIPA
:
162 case TBN_GETINFOTIPW
:
164 NMTBGETINFOTIPA
*tbgit
= (NMTBGETINFOTIPA
*)lParam
;
166 if (g_ResetDispTextPtr
)
168 tbgit
->pszText
= NULL
;
173 case TBN_GETDISPINFOW
:
174 nmdisp
= (NMTBDISPINFOA
*)lParam
;
176 compare(nmdisp
->dwMask
, g_dwExpectedDispInfoMask
, "%x");
177 ok(nmdisp
->pszText
== NULL
, "pszText is not NULL\n");
181 NMTBSAVE
*save
= (NMTBSAVE
*)lParam
;
182 if (save
->iItem
== -1)
184 save
->cbData
= save
->cbData
* 2 + 11 * sizeof(DWORD
);
185 save
->pData
= heap_alloc( save
->cbData
);
186 save
->pData
[0] = 0xcafe;
187 save
->pCurrent
= save
->pData
+ 1;
191 save
->pCurrent
[0] = 0xcafe0000 + save
->iItem
;
195 /* Add on 5 more pseudo buttons. */
196 if (save
->iItem
== save
->cButtons
- 1)
198 save
->pCurrent
[0] = 0xffffffff;
199 save
->pCurrent
[1] = 0xcafe0007;
200 save
->pCurrent
[2] = 0xfffffffe;
201 save
->pCurrent
[3] = 0xcafe0008;
202 save
->pCurrent
[4] = 0x80000000;
203 save
->pCurrent
[5] = 0xcafe0009;
204 save
->pCurrent
[6] = 0x7fffffff;
205 save
->pCurrent
[7] = 0xcafe000a;
206 save
->pCurrent
[8] = 0x100;
207 save
->pCurrent
[9] = 0xcafe000b;
210 /* Return value is ignored */
215 NMTBRESTORE
*restore
= (NMTBRESTORE
*)lParam
;
217 if (restore
->iItem
== -1)
219 ok( restore
->cButtons
== 25, "got %d\n", restore
->cButtons
);
220 ok( *restore
->pCurrent
== 0xcafe, "got %08x\n", *restore
->pCurrent
);
221 /* Skip the last one */
222 restore
->cButtons
= 11;
224 /* BytesPerRecord is ignored */
225 restore
->cbBytesPerRecord
= 10;
229 ok( *restore
->pCurrent
== 0xcafe0000 + restore
->iItem
, "got %08x\n", *restore
->pCurrent
);
230 if (restore
->iItem
< 7 || restore
->iItem
== 10)
232 ok( restore
->tbButton
.iBitmap
== -1, "got %08x\n", restore
->tbButton
.iBitmap
);
233 if (restore
->iItem
< 7)
234 ok( restore
->tbButton
.idCommand
== restore
->iItem
* 2 + 1, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
236 ok( restore
->tbButton
.idCommand
== 0x7fffffff, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
237 ok( restore
->tbButton
.fsState
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
238 ok( restore
->tbButton
.fsStyle
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsStyle
);
242 ok( restore
->tbButton
.iBitmap
== 8, "got %08x\n", restore
->tbButton
.iBitmap
);
243 ok( restore
->tbButton
.idCommand
== 0, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
244 if (restore
->iItem
== 7)
245 ok( restore
->tbButton
.fsState
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
247 ok( restore
->tbButton
.fsState
== TBSTATE_HIDDEN
, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
248 ok( restore
->tbButton
.fsStyle
== BTNS_SEP
, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsStyle
);
251 ok( restore
->tbButton
.dwData
== 0, "got %08lx\n", restore
->tbButton
.dwData
);
252 ok( restore
->tbButton
.iString
== 0, "got %08lx\n", restore
->tbButton
.iString
);
254 restore
->tbButton
.iBitmap
= 0;
255 restore
->tbButton
.fsState
= TBSTATE_ENABLED
;
256 restore
->tbButton
.fsStyle
= 0;
257 restore
->tbButton
.dwData
= restore
->iItem
;
259 if (restore
->iItem
== 0)
261 restore
->tbButton
.iString
= (INT_PTR
)heap_alloc_zero( 8 );
262 strcpy( (char *)restore
->tbButton
.iString
, "foo" );
264 else if (restore
->iItem
== 1)
265 restore
->tbButton
.iString
= 2;
267 restore
->tbButton
.iString
= -1;
270 /* Altering cButtons after the 1st call makes no difference. */
274 /* Returning non-zero from the 1st call aborts the restore,
275 otherwise the return value is ignored. */
276 if (restore
->iItem
== -1) return 0;
279 case TBN_GETBUTTONINFOA
:
281 NMTOOLBARA
*tb
= (NMTOOLBARA
*)lParam
;
282 tb
->tbButton
.iBitmap
= 0;
283 tb
->tbButton
.fsState
= 0;
284 tb
->tbButton
.fsStyle
= 0;
285 tb
->tbButton
.dwData
= 0;
286 ok( tb
->cchText
== 128, "got %d\n", tb
->cchText
);
290 tb
->tbButton
.idCommand
= 7;
291 alloced_str
= heap_alloc_zero( 8 );
292 strcpy( alloced_str
, "foo" );
293 tb
->tbButton
.iString
= (INT_PTR
)alloced_str
;
296 tb
->tbButton
.idCommand
= 9;
297 tb
->tbButton
.iString
= 0;
298 /* tb->pszText is ignored */
299 strcpy( tb
->pszText
, "foo" );
302 tb
->tbButton
.idCommand
= 11;
303 tb
->tbButton
.iString
= 3;
312 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
314 static LONG defwndproc_counter
= 0;
318 msg
.message
= message
;
319 msg
.flags
= sent
|wparam
|lparam
;
320 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
323 if (message
== WM_NOTIFY
&& lParam
)
325 msg
.id
= ((NMHDR
*)lParam
)->code
;
330 NMTBSAVE
*save
= (NMTBSAVE
*)lParam
;
331 msg
.stage
= save
->iItem
;
336 NMTBRESTORE
*restore
= (NMTBRESTORE
*)lParam
;
337 msg
.stage
= restore
->iItem
;
340 case TBN_GETBUTTONINFOA
:
342 NMTOOLBARA
*tb
= (NMTOOLBARA
*)lParam
;
343 msg
.stage
= tb
->iItem
;
349 /* log system messages, except for painting */
350 if (message
< WM_USER
&&
351 message
!= WM_PAINT
&&
352 message
!= WM_ERASEBKGND
&&
353 message
!= WM_NCPAINT
&&
354 message
!= WM_NCHITTEST
&&
355 message
!= WM_GETTEXT
&&
356 message
!= WM_GETICON
&&
357 message
!= WM_DEVICECHANGE
)
359 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
365 return parent_wnd_notify(lParam
);
368 defwndproc_counter
++;
369 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
370 defwndproc_counter
--;
375 static void basic_test(void)
382 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
383 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
384 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
386 hToolbar
= pCreateToolbarEx(hMainWnd
,
387 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
388 WS_CHILD
| TBSTYLE_LIST
,
391 buttons
, ARRAY_SIZE(buttons
),
392 0, 0, 20, 16, sizeof(TBBUTTON
));
393 ok(hToolbar
!= NULL
, "Toolbar creation\n");
394 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
396 /* test for exclusion working inside a separator-separated :-) group */
397 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 */
398 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
399 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1001, 0), "A2 not pressed\n");
401 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1004, 1); /* press A5, release A1 */
402 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 pressed\n");
403 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 not pressed anymore\n");
405 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1005, 1); /* press A6, release A5 */
406 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
407 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 not pressed anymore\n");
409 /* test for inter-group crosstalk, i.e. two radio groups interfering with each other */
410 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1007, 1); /* press B2 */
411 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
412 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 still not pressed\n");
413 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 pressed\n");
415 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 and ensure B group didn't suffer */
416 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 not pressed anymore\n");
417 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
418 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 still pressed\n");
420 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1008, 1); /* press B3, and ensure A group didn't suffer */
421 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
422 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
423 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 not pressed\n");
424 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1008, 0), "B3 pressed\n");
426 /* tests with invalid index */
427 compare(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 0xdeadbeef, 0), -1L, "%ld");
428 compare(SendMessageA(hToolbar
, TB_ISBUTTONPRESSED
, 0xdeadbeef, 0), -1L, "%ld");
429 compare(SendMessageA(hToolbar
, TB_ISBUTTONENABLED
, 0xdeadbeef, 0), -1L, "%ld");
430 compare(SendMessageA(hToolbar
, TB_ISBUTTONINDETERMINATE
, 0xdeadbeef, 0), -1L, "%ld");
431 compare(SendMessageA(hToolbar
, TB_ISBUTTONHIGHLIGHTED
, 0xdeadbeef, 0), -1L, "%ld");
432 compare(SendMessageA(hToolbar
, TB_ISBUTTONHIDDEN
, 0xdeadbeef, 0), -1L, "%ld");
434 DestroyWindow(hToolbar
);
437 static void rebuild_toolbar_ex(HWND
*hToolbar
, DWORD exstyle
)
440 DestroyWindow(*hToolbar
);
441 *hToolbar
= CreateWindowExA(exstyle
, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
,
442 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
443 ok(*hToolbar
!= NULL
, "Toolbar creation problem\n");
444 ok(SendMessageA(*hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
445 ok(SendMessageA(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
446 ok(SendMessageA(*hToolbar
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0)==1, "WM_SETFONT\n");
449 static void rebuild_toolbar(HWND
*hToolbar
)
451 rebuild_toolbar_ex(hToolbar
, 0);
454 static void rebuild_toolbar_with_buttons(HWND
*hToolbar
)
457 rebuild_toolbar(hToolbar
);
459 ZeroMemory(&buttons
, sizeof(buttons
));
460 buttons
[0].idCommand
= 1;
461 buttons
[0].fsStyle
= BTNS_BUTTON
;
462 buttons
[0].fsState
= TBSTATE_ENABLED
;
463 buttons
[0].iString
= -1;
464 buttons
[1].idCommand
= 3;
465 buttons
[1].fsStyle
= BTNS_BUTTON
;
466 buttons
[1].fsState
= TBSTATE_ENABLED
;
467 buttons
[1].iString
= -1;
468 buttons
[2].idCommand
= 5;
469 buttons
[2].fsStyle
= BTNS_SEP
;
470 buttons
[2].fsState
= TBSTATE_ENABLED
;
471 buttons
[2].iString
= -1;
472 buttons
[3].idCommand
= 7;
473 buttons
[3].fsStyle
= BTNS_BUTTON
;
474 buttons
[3].fsState
= TBSTATE_ENABLED
;
475 buttons
[3].iString
= -1;
476 buttons
[4].idCommand
= 9;
477 buttons
[4].fsStyle
= BTNS_BUTTON
;
478 buttons
[4].fsState
= 0; /* disabled */
479 buttons
[4].iString
= -1;
480 ok(SendMessageA(*hToolbar
, TB_ADDBUTTONSA
, 5, (LPARAM
)buttons
) == 1, "TB_ADDBUTTONSA failed\n");
481 ok(SendMessageA(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
484 static void add_128x15_bitmap(HWND hToolbar
, int nCmds
)
487 bmp128
.hInst
= GetModuleHandleA(NULL
);
488 bmp128
.nID
= IDB_BITMAP_128x15
;
489 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, nCmds
, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
492 #define CHECK_IMAGELIST(count, dx, dy) { \
494 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
495 ok(himl != NULL, "No image list\n"); \
497 ok(pImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, pImageList_GetImageCount(himl)); \
498 pImageList_GetIconSize(himl, &cx, &cy); \
499 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
503 static void test_add_bitmap(void)
505 TBADDBITMAP stdsmall
, std
;
506 HWND hToolbar
= NULL
;
513 /* Test default bitmaps range */
514 for (id
= IDB_STD_SMALL_COLOR
; id
< IDB_HIST_LARGE_COLOR
; id
++)
519 rebuild_toolbar(&hToolbar
);
521 std
.hInst
= HINST_COMMCTRL
;
524 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&std
);
525 ok(ret
== 0, "Got %d\n", ret
);
527 himl
= (HIMAGELIST
)SendMessageA(hToolbar
, TB_GETIMAGELIST
, 0, 0);
528 ok(himl
!= NULL
, "Got %p\n", himl
);
530 ret
= pImageList_GetIconSize(himl
, &cx
, &cy
);
531 ok(ret
, "Got %d\n", ret
);
532 ok(cx
== cy
, "Got %d x %d\n", cx
, cy
);
534 count
= pImageList_GetImageCount(himl
);
539 case IDB_STD_SMALL_COLOR
:
540 case IDB_STD_LARGE_COLOR
:
543 ok(count
== 15, "got count %d\n", count
);
545 case IDB_VIEW_SMALL_COLOR
:
546 case IDB_VIEW_LARGE_COLOR
:
549 ok(count
== 12, "got count %d\n", count
);
551 case IDB_HIST_SMALL_COLOR
:
552 case IDB_HIST_LARGE_COLOR
:
553 ok(count
== 5, "got count %d\n", count
);
556 ok(0, "id %d, count %d\n", id
, count
);
562 case IDB_STD_SMALL_COLOR
:
564 case IDB_VIEW_SMALL_COLOR
:
566 case IDB_HIST_SMALL_COLOR
:
567 ok(cx
== 16, "got size %d\n", cx
);
569 case IDB_STD_LARGE_COLOR
:
571 case IDB_VIEW_LARGE_COLOR
:
573 case IDB_HIST_LARGE_COLOR
:
574 ok(cx
== 24, "got size %d\n", cx
);
577 ok(0, "id %d, size %d\n", id
, cx
);
581 /* empty 128x15 bitmap */
582 bmp128
.hInst
= GetModuleHandleA(NULL
);
583 bmp128
.nID
= IDB_BITMAP_128x15
;
585 /* empty 80x15 bitmap */
586 bmp80
.hInst
= GetModuleHandleA(NULL
);
587 bmp80
.nID
= IDB_BITMAP_80x15
;
589 /* standard bitmap - 240x15 pixels */
590 stdsmall
.hInst
= HINST_COMMCTRL
;
591 stdsmall
.nID
= IDB_STD_SMALL_COLOR
;
593 rebuild_toolbar(&hToolbar
);
594 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
595 CHECK_IMAGELIST(8, 16, 16);
597 /* adding more bitmaps */
598 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 8, "TB_ADDBITMAP - unexpected return\n");
599 CHECK_IMAGELIST(13, 16, 16);
600 /* adding the same bitmap will simply return the index of the already loaded block */
601 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
);
602 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
603 CHECK_IMAGELIST(13, 16, 16);
604 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
605 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
606 CHECK_IMAGELIST(13, 16, 16);
607 /* even if we increase the wParam */
608 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 55, (LPARAM
)&bmp80
);
609 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
610 CHECK_IMAGELIST(13, 16, 16);
612 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
613 rebuild_toolbar(&hToolbar
);
614 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
615 CHECK_IMAGELIST(8, 16, 16);
616 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
617 ok(ret
== 3, "TB_ADDBITMAP - unexpected return %d\n", ret
);
618 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
619 CHECK_IMAGELIST(13, 16, 16);
621 /* the same for negative wParam */
622 rebuild_toolbar(&hToolbar
);
623 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, -143, (LPARAM
)&bmp128
);
624 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
625 CHECK_IMAGELIST(8, 16, 16);
626 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
627 ok(ret
== -143, "TB_ADDBITMAP - unexpected return %d\n", ret
);
628 CHECK_IMAGELIST(13, 16, 16);
630 /* for zero only one bitmap will be added */
631 rebuild_toolbar(&hToolbar
);
632 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&bmp80
);
633 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
634 CHECK_IMAGELIST(1, 16, 16);
636 /* if wParam is larger than the amount of icons, the list is grown */
637 rebuild_toolbar(&hToolbar
);
638 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
639 CHECK_IMAGELIST(100, 16, 16);
640 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
);
641 ok(ret
== 100, "TB_ADDBITMAP - unexpected return %d\n", ret
);
642 CHECK_IMAGELIST(200, 16, 16);
644 /* adding built-in items - the wParam is ignored */
645 rebuild_toolbar(&hToolbar
);
646 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
647 CHECK_IMAGELIST(5, 16, 16);
648 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 5, "TB_ADDBITMAP - unexpected return\n");
649 CHECK_IMAGELIST(20, 16, 16);
650 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 20, "TB_ADDBITMAP - unexpected return\n");
651 CHECK_IMAGELIST(28, 16, 16);
653 /* when we increase the bitmap size, less icons will be created */
654 rebuild_toolbar(&hToolbar
);
655 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
656 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
657 CHECK_IMAGELIST(6, 20, 20);
658 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
659 ok(ret
== 1, "TB_ADDBITMAP - unexpected return %d\n", ret
);
660 CHECK_IMAGELIST(10, 20, 20);
661 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
662 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
663 UpdateWindow(hToolbar
);
664 CHECK_IMAGELIST(26, 8, 8);
665 /* loading a standard bitmaps automatically resizes the icons */
666 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&stdsmall
) == 2, "TB_ADDBITMAP - unexpected return\n");
667 UpdateWindow(hToolbar
);
668 CHECK_IMAGELIST(28, 16, 16);
670 /* two more SETBITMAPSIZE tests */
671 rebuild_toolbar(&hToolbar
);
672 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
673 CHECK_IMAGELIST(100, 16, 16);
674 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 100, "TB_ADDBITMAP - unexpected return\n");
675 CHECK_IMAGELIST(200, 16, 16);
676 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
677 UpdateWindow(hToolbar
);
678 CHECK_IMAGELIST(200, 8, 8);
679 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
680 UpdateWindow(hToolbar
);
681 CHECK_IMAGELIST(200, 30, 30);
682 rebuild_toolbar(&hToolbar
);
683 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
684 CHECK_IMAGELIST(8, 16, 16);
685 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp80
) == 5, "TB_ADDBITMAP - unexpected return\n");
686 CHECK_IMAGELIST(13, 16, 16);
687 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
688 UpdateWindow(hToolbar
);
689 CHECK_IMAGELIST(8, 30, 30);
690 /* when the width or height is zero, set it to 1 */
691 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
692 UpdateWindow(hToolbar
);
693 CHECK_IMAGELIST(208, 1, 1);
694 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 5)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
695 UpdateWindow(hToolbar
);
696 CHECK_IMAGELIST(208, 1, 5);
697 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(5, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
698 UpdateWindow(hToolbar
);
699 CHECK_IMAGELIST(41, 5, 1);
701 /* the control can add bitmaps to an existing image list */
702 rebuild_toolbar(&hToolbar
);
703 himl
= pImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_80x15
),
704 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
705 ok(himl
!= NULL
, "failed to create imagelist\n");
706 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
707 CHECK_IMAGELIST(4, 20, 15);
708 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
709 CHECK_IMAGELIST(10, 20, 15);
710 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
711 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
712 UpdateWindow(hToolbar
);
713 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(15, 14), "%x");
714 CHECK_IMAGELIST(10, 20, 15);
715 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 1, "TB_SETBITMAPSIZE failed\n");
716 UpdateWindow(hToolbar
);
717 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
718 CHECK_IMAGELIST(22, 20, 15);
720 /* check standard bitmaps */
721 addbmp
.hInst
= HINST_COMMCTRL
;
722 addbmp
.nID
= IDB_STD_SMALL_COLOR
;
723 rebuild_toolbar(&hToolbar
);
724 pImageList_Destroy(himl
);
726 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
727 CHECK_IMAGELIST(15, 16, 16);
728 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
729 addbmp
.nID
= IDB_STD_LARGE_COLOR
;
730 rebuild_toolbar(&hToolbar
);
731 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
732 CHECK_IMAGELIST(15, 24, 24);
733 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(31, 30), "%x");
735 addbmp
.nID
= IDB_VIEW_SMALL_COLOR
;
736 rebuild_toolbar(&hToolbar
);
737 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
738 CHECK_IMAGELIST(12, 16, 16);
739 addbmp
.nID
= IDB_VIEW_LARGE_COLOR
;
740 rebuild_toolbar(&hToolbar
);
741 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
742 CHECK_IMAGELIST(12, 24, 24);
744 addbmp
.nID
= IDB_HIST_SMALL_COLOR
;
745 rebuild_toolbar(&hToolbar
);
746 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
747 CHECK_IMAGELIST(5, 16, 16);
748 addbmp
.nID
= IDB_HIST_LARGE_COLOR
;
749 rebuild_toolbar(&hToolbar
);
750 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
751 CHECK_IMAGELIST(5, 24, 24);
754 DestroyWindow(hToolbar
);
757 #define CHECK_STRING_TABLE(count, tab) { \
760 for (_i = 0; _i < (count); _i++) {\
761 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, _i), (LPARAM)_buf); \
762 ok(ret >= 0, "TB_GETSTRINGA - unexpected return %d while checking string %d\n", ret, _i); \
764 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
766 ok(SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
767 "Too many strings in table\n"); \
770 static void test_add_string(void)
772 LPCSTR test1
= "a\0b\0";
773 LPCSTR test2
= "|a|b||\0";
774 LPCSTR ret1
[] = {"a", "b"};
775 LPCSTR ret2
[] = {"a", "b", "|a|b||"};
776 LPCSTR ret3
[] = {"a", "b", "|a|b||", "p", "q"};
777 LPCSTR ret4
[] = {"a", "b", "|a|b||", "p", "q", "p"};
778 LPCSTR ret5
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
779 LPCSTR ret6
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
780 LPCSTR ret7
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
781 HWND hToolbar
= NULL
;
786 rebuild_toolbar(&hToolbar
);
787 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test1
);
788 ok(ret
== 0, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
789 ret
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(260, 1), (LPARAM
)buf
);
792 win_skip("TB_GETSTRINGA needs 5.80\n");
795 CHECK_STRING_TABLE(2, ret1
);
796 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test2
);
797 ok(ret
== 2, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
798 CHECK_STRING_TABLE(3, ret2
);
800 /* null instance handle */
801 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, IDS_TBADD1
);
802 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
804 /* invalid instance handle */
805 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0xdeadbeef, IDS_TBADD1
);
806 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
808 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD1
);
809 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
810 CHECK_STRING_TABLE(3, ret2
);
811 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD2
);
812 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
813 CHECK_STRING_TABLE(5, ret3
);
814 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD3
);
815 ok(ret
== 5, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
816 CHECK_STRING_TABLE(6, ret4
);
817 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD4
);
818 ok(ret
== 6, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
819 CHECK_STRING_TABLE(8, ret5
);
820 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD5
);
821 ok(ret
== 8, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
822 CHECK_STRING_TABLE(11, ret6
);
823 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD7
);
824 ok(ret
== 11, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
825 CHECK_STRING_TABLE(14, ret7
);
827 ZeroMemory(&button
, sizeof(button
));
828 button
.iString
= (UINT_PTR
)"Test";
829 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 0, (LPARAM
)&button
);
830 CHECK_STRING_TABLE(14, ret7
);
831 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
832 CHECK_STRING_TABLE(14, ret7
);
834 DestroyWindow(hToolbar
);
837 static void expect_hot_notify(int idold
, int idnew
)
839 g_fExpectedHotItemOld
= idold
;
840 g_fExpectedHotItemNew
= idnew
;
841 g_fReceivedHotItemChange
= FALSE
;
844 #define check_hot_notify() \
845 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
846 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
848 static void test_hotitem(void)
850 HWND hToolbar
= NULL
;
851 TBBUTTONINFOA tbinfo
;
854 g_fBlockHotItemChange
= FALSE
;
856 rebuild_toolbar_with_buttons(&hToolbar
);
857 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
858 * comctl6 doesn't have this requirement even when theme == NULL */
859 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_FLAT
| GetWindowLongA(hToolbar
, GWL_STYLE
));
860 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
861 ok(ret
== -1, "Hot item: %ld, expected -1\n", ret
);
862 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 1, 0);
863 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
864 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
865 ok(ret
== 1, "Hot item: %ld, expected 1\n", ret
);
866 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 2, 0);
867 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
869 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 0xbeef, 0);
870 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
871 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
872 ok(ret
== 2, "Hot item: %lx, expected 2\n", ret
);
873 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, -0xbeef, 0);
874 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
875 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
876 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
878 expect_hot_notify(0, 7);
879 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
880 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
882 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
883 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
884 g_fBlockHotItemChange
= TRUE
;
885 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 2, 0);
886 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
887 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
888 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
889 g_fBlockHotItemChange
= FALSE
;
891 g_fReceivedHotItemChange
= FALSE
;
892 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 0xbeaf, 0);
893 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
894 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received for invalid parameter\n");
896 g_fReceivedHotItemChange
= FALSE
;
897 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
898 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
899 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received after a duplication\n");
901 expect_hot_notify(7, 0);
902 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, -0xbeaf, 0);
903 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
905 SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
907 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
908 expect_hot_notify(7, 9);
909 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 4, 0);
910 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
912 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
913 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
914 /* enabling the button won't change that */
915 SendMessageA(hToolbar
, TB_ENABLEBUTTON
, 9, TRUE
);
916 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
917 ok(ret
== -1, "TB_GETHOTITEM returned %ld, expected -1\n", ret
);
919 /* disabling a hot button works */
920 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
921 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
922 g_fReceivedHotItemChange
= FALSE
;
923 SendMessageA(hToolbar
, TB_ENABLEBUTTON
, 7, FALSE
);
924 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
925 ok(ret
== 3, "TB_GETHOTITEM returned %ld, expected 3\n", ret
);
926 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
928 SendMessageA(hToolbar
, TB_SETHOTITEM
, 1, 0);
929 tbinfo
.cbSize
= sizeof(TBBUTTONINFOA
);
930 tbinfo
.dwMask
= TBIF_STATE
;
931 tbinfo
.fsState
= 0; /* disabled */
932 g_fReceivedHotItemChange
= FALSE
;
933 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&tbinfo
) == TRUE
, "TB_SETBUTTONINFOA failed\n");
934 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
935 ok(ret
== 1, "TB_GETHOTITEM returned %ld, expected 1\n", ret
);
936 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
938 /* deleting a button unsets the hot item */
939 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 0, 0);
940 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
941 g_fReceivedHotItemChange
= FALSE
;
942 ret
= SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
943 ok(ret
== TRUE
, "TB_DELETEBUTTON returned %ld, expected TRUE\n", ret
);
944 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
945 ok(ret
== -1, "TB_GETHOTITEM returned %ld, expected -1\n", ret
);
946 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
948 DestroyWindow(hToolbar
);
951 #if 0 /* use this to generate more tests*/
953 static void dump_sizes(HWND hToolbar
)
957 int count
= SendMessageA(hToolbar
, TB_BUTTONCOUNT
, 0, 0);
960 GetClientRect(hToolbar
, &r
);
961 SendMessageA(hToolbar
, TB_GETMAXSIZE
, 0, &sz
);
962 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r
.left
, r
.top
, r
.right
, r
.bottom
,
963 sz
.cx
, sz
.cy
, count
);
964 for (i
=0; i
<count
; i
++)
966 SendMessageA(hToolbar
, TB_GETITEMRECT
, i
, &r
);
967 printf("%s{%3d, %3d, %3d, %3d}, ", (i
%3==0 ? "\n " : ""), r
.left
, r
.top
, r
.right
, r
.bottom
);
969 printf("\n }, },\n");
972 #define check_sizes() dump_sizes(hToolbar);
973 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
977 static int system_font_height(void) {
981 hDC
= CreateCompatibleDC(NULL
);
982 GetTextMetricsA(hDC
, &tm
);
988 static int string_width(const CHAR
*s
) {
992 hdc
= CreateCompatibleDC(NULL
);
993 GetTextExtentPoint32A(hdc
, s
, strlen(s
), &sz
);
1007 static tbsize_result_t
init_tbsize_result(int nButtonsAlloc
, int cleft
, int ctop
, int cright
, int cbottom
, int minx
, int miny
) {
1008 tbsize_result_t ret
;
1010 SetRect(&ret
.rcClient
, cleft
, ctop
, cright
, cbottom
);
1011 ret
.szMin
.cx
= minx
;
1012 ret
.szMin
.cy
= miny
;
1014 ret
.prcButtons
= heap_alloc_zero(nButtonsAlloc
* sizeof(*ret
.prcButtons
));
1019 static void tbsize_addbutton(tbsize_result_t
*tbsr
, int left
, int top
, int right
, int bottom
) {
1020 SetRect(&tbsr
->prcButtons
[tbsr
->nButtons
], left
, top
, right
, bottom
);
1025 #define STRING1 "MMMMMMMMMMMMM"
1026 #define STRING2 "Tst"
1028 static tbsize_result_t
*tbsize_results
;
1030 #define tbsize_results_num 29
1032 static void init_tbsize_results(void) {
1033 int fontheight
= system_font_height();
1036 tbsize_results
= heap_alloc_zero(tbsize_results_num
* sizeof(*tbsize_results
));
1038 tbsize_results
[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
1039 tbsize_addbutton(&tbsize_results
[0], 0, 2, 23, 24);
1040 tbsize_addbutton(&tbsize_results
[0], 23, 2, 46, 24);
1041 tbsize_addbutton(&tbsize_results
[0], 46, 2, 54, 24);
1042 tbsize_addbutton(&tbsize_results
[0], 54, 2, 77, 24);
1043 tbsize_addbutton(&tbsize_results
[0], 77, 2, 100, 24);
1045 tbsize_results
[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1046 tbsize_addbutton(&tbsize_results
[1], 0, 2, 23, 24);
1047 tbsize_addbutton(&tbsize_results
[1], 23, 2, 46, 24);
1048 tbsize_addbutton(&tbsize_results
[1], 46, 2, 54, 24);
1049 tbsize_addbutton(&tbsize_results
[1], 54, 2, 77, 24);
1050 tbsize_addbutton(&tbsize_results
[1], 77, 2, 100, 24);
1051 tbsize_addbutton(&tbsize_results
[1], 100, 2, 123, 24);
1052 tbsize_addbutton(&tbsize_results
[1], 0, 24, 23, 46);
1054 tbsize_results
[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1055 tbsize_addbutton(&tbsize_results
[2], 0, 2, 23, 24);
1056 tbsize_addbutton(&tbsize_results
[2], 23, 2, 46, 24);
1057 tbsize_addbutton(&tbsize_results
[2], 46, 2, 54, 24);
1058 tbsize_addbutton(&tbsize_results
[2], 54, 2, 77, 24);
1059 tbsize_addbutton(&tbsize_results
[2], 77, 2, 100, 24);
1060 tbsize_addbutton(&tbsize_results
[2], 100, 2, 123, 24);
1061 tbsize_addbutton(&tbsize_results
[2], 0, 24, 23, 46);
1063 tbsize_results
[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1064 tbsize_addbutton(&tbsize_results
[3], 0, 2, 23, 24);
1065 tbsize_addbutton(&tbsize_results
[3], 23, 2, 46, 24);
1066 tbsize_addbutton(&tbsize_results
[3], 46, 2, 54, 24);
1067 tbsize_addbutton(&tbsize_results
[3], 54, 2, 77, 24);
1068 tbsize_addbutton(&tbsize_results
[3], 77, 2, 100, 24);
1069 tbsize_addbutton(&tbsize_results
[3], 100, 2, 123, 24);
1070 tbsize_addbutton(&tbsize_results
[3], 123, 2, 146, 24);
1072 tbsize_results
[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
1073 tbsize_addbutton(&tbsize_results
[4], 0, 2, 23, 24);
1074 tbsize_addbutton(&tbsize_results
[4], 23, 2, 46, 24);
1075 tbsize_addbutton(&tbsize_results
[4], 46, 2, 54, 24);
1076 tbsize_addbutton(&tbsize_results
[4], 54, 2, 77, 24);
1077 tbsize_addbutton(&tbsize_results
[4], 77, 2, 100, 24);
1078 tbsize_addbutton(&tbsize_results
[4], 100, 2, 123, 24);
1079 tbsize_addbutton(&tbsize_results
[4], 123, 2, 146, 24);
1080 tbsize_addbutton(&tbsize_results
[4], 146, 2, 169, 24);
1081 tbsize_addbutton(&tbsize_results
[4], 169, 2, 192, 24);
1083 tbsize_results
[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
1084 tbsize_addbutton(&tbsize_results
[5], 0, 2, 23, 24);
1085 tbsize_addbutton(&tbsize_results
[5], 23, 2, 46, 24);
1086 tbsize_addbutton(&tbsize_results
[5], 0, 2, 8, 29);
1087 tbsize_addbutton(&tbsize_results
[5], 0, 29, 23, 51);
1088 tbsize_addbutton(&tbsize_results
[5], 23, 29, 46, 51);
1089 tbsize_addbutton(&tbsize_results
[5], 46, 29, 69, 51);
1090 tbsize_addbutton(&tbsize_results
[5], 69, 29, 92, 51);
1091 tbsize_addbutton(&tbsize_results
[5], 92, 29, 115, 51);
1092 tbsize_addbutton(&tbsize_results
[5], 115, 29, 138, 51);
1093 tbsize_addbutton(&tbsize_results
[5], 138, 29, 161, 51);
1094 tbsize_addbutton(&tbsize_results
[5], 161, 29, 184, 51);
1095 tbsize_addbutton(&tbsize_results
[5], 184, 29, 207, 51);
1096 tbsize_addbutton(&tbsize_results
[5], 207, 29, 230, 51);
1097 tbsize_addbutton(&tbsize_results
[5], 230, 29, 253, 51);
1098 tbsize_addbutton(&tbsize_results
[5], 253, 29, 276, 51);
1099 tbsize_addbutton(&tbsize_results
[5], 276, 29, 299, 51);
1100 tbsize_addbutton(&tbsize_results
[5], 299, 29, 322, 51);
1101 tbsize_addbutton(&tbsize_results
[5], 322, 29, 345, 51);
1102 tbsize_addbutton(&tbsize_results
[5], 345, 29, 368, 51);
1103 tbsize_addbutton(&tbsize_results
[5], 368, 29, 391, 51);
1104 tbsize_addbutton(&tbsize_results
[5], 391, 29, 414, 51);
1105 tbsize_addbutton(&tbsize_results
[5], 414, 29, 437, 51);
1106 tbsize_addbutton(&tbsize_results
[5], 437, 29, 460, 51);
1107 tbsize_addbutton(&tbsize_results
[5], 460, 29, 483, 51);
1108 tbsize_addbutton(&tbsize_results
[5], 483, 29, 506, 51);
1109 tbsize_addbutton(&tbsize_results
[5], 506, 29, 529, 51);
1110 tbsize_addbutton(&tbsize_results
[5], 529, 29, 552, 51);
1111 tbsize_addbutton(&tbsize_results
[5], 552, 29, 575, 51);
1112 tbsize_addbutton(&tbsize_results
[5], 575, 29, 598, 51);
1113 tbsize_addbutton(&tbsize_results
[5], 598, 29, 621, 51);
1114 tbsize_addbutton(&tbsize_results
[5], 621, 29, 644, 51);
1115 tbsize_addbutton(&tbsize_results
[5], 644, 29, 667, 51);
1116 tbsize_addbutton(&tbsize_results
[5], 0, 51, 23, 73);
1117 tbsize_addbutton(&tbsize_results
[5], 23, 51, 46, 73);
1118 tbsize_addbutton(&tbsize_results
[5], 46, 51, 69, 73);
1119 tbsize_addbutton(&tbsize_results
[5], 69, 51, 92, 73);
1120 tbsize_addbutton(&tbsize_results
[5], 92, 51, 115, 73);
1121 tbsize_addbutton(&tbsize_results
[5], 115, 51, 138, 73);
1122 tbsize_addbutton(&tbsize_results
[5], 138, 51, 161, 73);
1124 tbsize_results
[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
1125 tbsize_addbutton(&tbsize_results
[6], 0, 2, 23, 24);
1126 tbsize_addbutton(&tbsize_results
[6], 23, 2, 46, 24);
1127 tbsize_addbutton(&tbsize_results
[6], 46, 2, 94, 24);
1128 tbsize_addbutton(&tbsize_results
[6], 94, 2, 117, 24);
1129 tbsize_addbutton(&tbsize_results
[6], 117, 2, 140, 24);
1130 tbsize_addbutton(&tbsize_results
[6], 140, 2, 163, 24);
1131 tbsize_addbutton(&tbsize_results
[6], 0, 24, 23, 46);
1133 tbsize_results
[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
1134 tbsize_addbutton(&tbsize_results
[7], 0, 2, 23, 24);
1135 tbsize_addbutton(&tbsize_results
[7], 23, 2, 46, 24);
1136 tbsize_addbutton(&tbsize_results
[7], 0, 24, 92, 32);
1137 tbsize_addbutton(&tbsize_results
[7], 0, 32, 23, 54);
1138 tbsize_addbutton(&tbsize_results
[7], 23, 32, 46, 54);
1139 tbsize_addbutton(&tbsize_results
[7], 46, 32, 69, 54);
1140 tbsize_addbutton(&tbsize_results
[7], 69, 32, 92, 54);
1142 tbsize_results
[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
1143 tbsize_addbutton(&tbsize_results
[8], 0, 2, 31, 32);
1144 tbsize_addbutton(&tbsize_results
[8], 31, 2, 62, 32);
1145 tbsize_addbutton(&tbsize_results
[8], 62, 2, 70, 32);
1146 tbsize_addbutton(&tbsize_results
[8], 70, 2, 101, 32);
1147 tbsize_addbutton(&tbsize_results
[8], 101, 2, 132, 32);
1148 tbsize_addbutton(&tbsize_results
[8], 132, 2, 163, 32);
1149 tbsize_addbutton(&tbsize_results
[8], 0, 32, 31, 62);
1151 tbsize_results
[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1152 tbsize_addbutton(&tbsize_results
[9], 0, 2, 31, 32);
1153 tbsize_addbutton(&tbsize_results
[9], 31, 2, 62, 32);
1154 tbsize_addbutton(&tbsize_results
[9], 62, 2, 70, 32);
1155 tbsize_addbutton(&tbsize_results
[9], 70, 2, 101, 32);
1156 tbsize_addbutton(&tbsize_results
[9], 101, 2, 132, 32);
1157 tbsize_addbutton(&tbsize_results
[9], 132, 2, 163, 32);
1158 tbsize_addbutton(&tbsize_results
[9], 0, 32, 31, 62);
1160 tbsize_results
[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1161 tbsize_addbutton(&tbsize_results
[10], 0, 0, 31, 30);
1162 tbsize_addbutton(&tbsize_results
[10], 31, 0, 62, 30);
1163 tbsize_addbutton(&tbsize_results
[10], 62, 0, 70, 30);
1164 tbsize_addbutton(&tbsize_results
[10], 70, 0, 101, 30);
1165 tbsize_addbutton(&tbsize_results
[10], 101, 0, 132, 30);
1166 tbsize_addbutton(&tbsize_results
[10], 132, 0, 163, 30);
1167 tbsize_addbutton(&tbsize_results
[10], 0, 30, 31, 60);
1169 tbsize_results
[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
1170 tbsize_addbutton(&tbsize_results
[11], 0, 0, 31, 30);
1171 tbsize_addbutton(&tbsize_results
[11], 31, 0, 62, 30);
1172 tbsize_addbutton(&tbsize_results
[11], 0, 30, 124, 38);
1173 tbsize_addbutton(&tbsize_results
[11], 0, 38, 31, 68);
1174 tbsize_addbutton(&tbsize_results
[11], 31, 38, 62, 68);
1175 tbsize_addbutton(&tbsize_results
[11], 62, 38, 93, 68);
1176 tbsize_addbutton(&tbsize_results
[11], 93, 38, 124, 68);
1178 tbsize_results
[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1179 tbsize_addbutton(&tbsize_results
[12], 0, 2, 23, 24);
1180 tbsize_addbutton(&tbsize_results
[12], 23, 2, 46, 24);
1181 tbsize_addbutton(&tbsize_results
[12], 46, 2, 54, 24);
1182 tbsize_addbutton(&tbsize_results
[12], 54, 2, 77, 24);
1183 tbsize_addbutton(&tbsize_results
[12], 77, 2, 100, 24);
1184 tbsize_addbutton(&tbsize_results
[12], 100, 2, 123, 24);
1185 tbsize_addbutton(&tbsize_results
[12], 123, 2, 146, 24);
1187 tbsize_results
[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
1188 tbsize_addbutton(&tbsize_results
[13], 0, 0, 23, 100);
1189 tbsize_addbutton(&tbsize_results
[13], 23, 0, 46, 100);
1190 tbsize_addbutton(&tbsize_results
[13], 46, 0, 54, 100);
1191 tbsize_addbutton(&tbsize_results
[13], 54, 0, 77, 100);
1192 tbsize_addbutton(&tbsize_results
[13], 77, 0, 100, 100);
1193 tbsize_addbutton(&tbsize_results
[13], 100, 0, 123, 100);
1194 tbsize_addbutton(&tbsize_results
[13], 123, 0, 146, 100);
1196 tbsize_results
[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
1197 tbsize_addbutton(&tbsize_results
[14], 0, 0, 23, 100);
1198 tbsize_addbutton(&tbsize_results
[14], 23, 0, 46, 100);
1199 tbsize_addbutton(&tbsize_results
[14], 46, 0, 54, 100);
1200 tbsize_addbutton(&tbsize_results
[14], 54, 0, 77, 100);
1201 tbsize_addbutton(&tbsize_results
[14], 77, 0, 100, 100);
1202 tbsize_addbutton(&tbsize_results
[14], 100, 0, 123, 100);
1203 tbsize_addbutton(&tbsize_results
[14], 123, 0, 146, 100);
1204 tbsize_addbutton(&tbsize_results
[14], 146, 0, 169, 100);
1205 tbsize_addbutton(&tbsize_results
[14], 169, 0, 192, 100);
1206 tbsize_addbutton(&tbsize_results
[14], 192, 0, 215, 100);
1208 tbsize_results
[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
1209 tbsize_addbutton(&tbsize_results
[15], 0, 0, 23, 23 + fontheight
);
1210 tbsize_addbutton(&tbsize_results
[15], 23, 0, 46, 23 + fontheight
);
1211 tbsize_addbutton(&tbsize_results
[15], 46, 0, 54, 23 + fontheight
);
1212 tbsize_addbutton(&tbsize_results
[15], 54, 0, 77, 23 + fontheight
);
1213 tbsize_addbutton(&tbsize_results
[15], 77, 0, 100, 23 + fontheight
);
1214 tbsize_addbutton(&tbsize_results
[15], 100, 0, 123, 23 + fontheight
);
1215 tbsize_addbutton(&tbsize_results
[15], 123, 0, 146, 23 + fontheight
);
1216 tbsize_addbutton(&tbsize_results
[15], 146, 0, 169, 23 + fontheight
);
1217 tbsize_addbutton(&tbsize_results
[15], 169, 0, 192, 23 + fontheight
);
1218 tbsize_addbutton(&tbsize_results
[15], 192, 0, 215, 23 + fontheight
);
1219 tbsize_addbutton(&tbsize_results
[15], 215, 0, 238, 23 + fontheight
);
1221 tbsize_results
[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
1222 tbsize_addbutton(&tbsize_results
[16], 0, 0, 23, 22);
1223 tbsize_addbutton(&tbsize_results
[16], 23, 0, 46, 22);
1224 tbsize_addbutton(&tbsize_results
[16], 46, 0, 54, 22);
1225 tbsize_addbutton(&tbsize_results
[16], 54, 0, 77, 22);
1226 tbsize_addbutton(&tbsize_results
[16], 77, 0, 100, 22);
1227 tbsize_addbutton(&tbsize_results
[16], 100, 0, 123, 22);
1228 tbsize_addbutton(&tbsize_results
[16], 123, 0, 146, 22);
1229 tbsize_addbutton(&tbsize_results
[16], 146, 0, 169, 22);
1230 tbsize_addbutton(&tbsize_results
[16], 169, 0, 192, 22);
1231 tbsize_addbutton(&tbsize_results
[16], 192, 0, 215, 22);
1232 tbsize_addbutton(&tbsize_results
[16], 215, 0, 238, 22);
1234 buttonwidth
= 7 + string_width(STRING1
);
1236 tbsize_results
[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
1237 tbsize_addbutton(&tbsize_results
[17], 0, 2, buttonwidth
, 25 + fontheight
);
1238 tbsize_addbutton(&tbsize_results
[17], buttonwidth
, 2, 2*buttonwidth
+ 4, 25 + fontheight
);
1239 tbsize_addbutton(&tbsize_results
[17], 2*buttonwidth
+ 4, 2, 3*buttonwidth
+ 4, 25 + fontheight
);
1241 tbsize_results
[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
1242 tbsize_addbutton(&tbsize_results
[18], 0, 2, buttonwidth
, 10 + fontheight
);
1243 tbsize_addbutton(&tbsize_results
[18], buttonwidth
, 2, 2*buttonwidth
, 10 + fontheight
);
1244 tbsize_addbutton(&tbsize_results
[18], 2*buttonwidth
, 2, 3*buttonwidth
, 10 + fontheight
);
1245 tbsize_addbutton(&tbsize_results
[18], 3*buttonwidth
, 2, 4*buttonwidth
, 10 + fontheight
);
1246 tbsize_addbutton(&tbsize_results
[18], 4*buttonwidth
, 2, 5*buttonwidth
+ 4, 10 + fontheight
);
1247 tbsize_addbutton(&tbsize_results
[18], 5*buttonwidth
+ 4, 2, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 10 + fontheight
);
1249 tbsize_results
[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
1250 tbsize_addbutton(&tbsize_results
[19], 0, 0, buttonwidth
, 22 + fontheight
);
1251 tbsize_addbutton(&tbsize_results
[19], buttonwidth
, 0, 2*buttonwidth
, 22 + fontheight
);
1252 tbsize_addbutton(&tbsize_results
[19], 2*buttonwidth
, 0, 3*buttonwidth
, 22 + fontheight
);
1253 tbsize_addbutton(&tbsize_results
[19], 3*buttonwidth
, 0, 4*buttonwidth
, 22 + fontheight
);
1254 tbsize_addbutton(&tbsize_results
[19], 4*buttonwidth
, 0, 5*buttonwidth
+ 4, 22 + fontheight
);
1255 tbsize_addbutton(&tbsize_results
[19], 5*buttonwidth
+ 4, 0, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 22 + fontheight
);
1257 tbsize_results
[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
1258 tbsize_addbutton(&tbsize_results
[20], 0, 2, 100, 102);
1259 tbsize_addbutton(&tbsize_results
[20], 100, 2, 139, 102);
1260 tbsize_addbutton(&tbsize_results
[20], 139, 2, 239, 102);
1262 tbsize_results
[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
1263 tbsize_addbutton(&tbsize_results
[21], 0, 2, 75, 40);
1264 tbsize_addbutton(&tbsize_results
[21], 75, 2, 118, 40);
1265 tbsize_addbutton(&tbsize_results
[21], 118, 2, 165 + string_width(STRING2
), 40);
1267 tbsize_results
[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1268 tbsize_addbutton(&tbsize_results
[22], 0, 2, 47 + string_width(STRING2
), 40);
1270 tbsize_results
[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
1271 tbsize_addbutton(&tbsize_results
[23], 0, 2, 672, 25 + fontheight
);
1272 tbsize_addbutton(&tbsize_results
[23], 0, 25 + fontheight
, 672, 48 + 2*fontheight
);
1274 tbsize_results
[24] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1275 tbsize_addbutton(&tbsize_results
[24], 0, 2, 11 + string_width(STRING2
), 24);
1277 tbsize_results
[25] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1278 tbsize_addbutton(&tbsize_results
[25], 0, 2, 40, 24);
1280 tbsize_results
[26] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1281 tbsize_addbutton(&tbsize_results
[26], 0, 2, 40, 24);
1283 tbsize_results
[27] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1284 tbsize_addbutton(&tbsize_results
[27], 0, 2, 40, 24);
1286 tbsize_results
[28] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1287 tbsize_addbutton(&tbsize_results
[28], 0, 2, 23, 24);
1290 static void free_tbsize_results(void) {
1293 for (i
= 0; i
< tbsize_results_num
; i
++)
1294 heap_free(tbsize_results
[i
].prcButtons
);
1295 heap_free(tbsize_results
);
1296 tbsize_results
= NULL
;
1299 static int tbsize_numtests
= 0;
1306 } tbsize_alt_result_t
;
1308 static tbsize_alt_result_t tbsize_alt_results
[] =
1310 { 5, 2, { 0, 24, 8, 29 } },
1311 { 20, 1, { 100, 2, 107, 102 } },
1312 { 20, 2, { 107, 2, 207, 102 } }
1315 static DWORD tbsize_alt_numtests
= 0;
1317 #define check_sizes_todo(todomask) { \
1319 int buttonCount, i, mask=(todomask); \
1320 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1321 GetClientRect(hToolbar, &rc); \
1322 /*check_rect("client", rc, res->rcClient);*/ \
1323 buttonCount = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1324 compare(buttonCount, res->nButtons, "%d"); \
1325 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1326 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1327 if (broken(tbsize_alt_numtests < ARRAY_SIZE(tbsize_alt_results) && \
1328 EqualRect(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton))) { \
1329 win_skip("Alternate rect found\n"); \
1330 tbsize_alt_numtests++; \
1331 } else todo_wine_if(mask&1) \
1332 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1335 tbsize_numtests++; \
1338 #define check_sizes() check_sizes_todo(0)
1342 static TBBUTTON buttons1
[] = {
1343 {0, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1344 {0, 11, 0, 0, {0, }, 0, -1},
1346 static TBBUTTON buttons2
[] = {
1347 {0, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1348 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1350 static TBBUTTON buttons3
[] = {
1351 {0, 30, TBSTATE_ENABLED
, 0, {0, }, 0, 0},
1352 {0, 31, TBSTATE_ENABLED
, 0, {0, }, 0, 1},
1353 {0, 32, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, 1},
1354 {0, 33, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
}
1356 static TBBUTTON buttons4
[] = {
1357 {0, 40, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
},
1358 {0, 41, TBSTATE_ENABLED
, 0, {0, }, 0, (UINT_PTR
)STRING2
},
1359 {0, 41, TBSTATE_ENABLED
, BTNS_SHOWTEXT
, {0, }, 0, (UINT_PTR
)STRING2
}
1362 static void test_sizes(void)
1364 HWND hToolbar
= NULL
;
1365 HIMAGELIST himl
, himl2
;
1366 TBBUTTONINFOA tbinfo
;
1370 int fontheight
= system_font_height();
1373 init_tbsize_results();
1375 rebuild_toolbar_with_buttons(&hToolbar
);
1376 style
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1377 ok(style
== (WS_CHILD
|WS_VISIBLE
|CCS_TOP
), "Invalid style %x\n", style
);
1379 /* the TBSTATE_WRAP makes a second row */
1380 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1382 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1384 SendMessageA(hToolbar
, TB_GETBUTTON
, 5, (LPARAM
)&button
);
1385 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "got %08x\n", button
.fsState
);
1386 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1387 SetWindowLongA(hToolbar
, GWL_STYLE
, style
|TBSTYLE_WRAPABLE
);
1389 SendMessageA(hToolbar
, TB_GETBUTTON
, 5, (LPARAM
)&button
);
1390 ok(button
.fsState
== TBSTATE_ENABLED
, "got %08x\n", button
.fsState
);
1391 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1392 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1394 /* only after adding enough buttons the bar will be wrapped on a
1395 * separator and then on the first button */
1396 for (i
=0; i
<15; i
++)
1397 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1398 check_sizes_todo(0x4);
1399 SendMessageA(hToolbar
, TB_GETBUTTON
, 31, (LPARAM
)&button
);
1400 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "got %08x\n", button
.fsState
);
1401 SetWindowLongA(hToolbar
, GWL_STYLE
, style
);
1402 SendMessageA(hToolbar
, TB_GETBUTTON
, 31, (LPARAM
)&button
);
1403 ok(button
.fsState
== TBSTATE_ENABLED
, "got %08x\n", button
.fsState
);
1405 rebuild_toolbar_with_buttons(&hToolbar
);
1406 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1407 /* setting the buttons vertical will only change the window client size */
1408 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| CCS_VERT
);
1409 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1410 check_sizes_todo(0x3c);
1411 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1412 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1413 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1414 check_sizes_todo(0x7c);
1416 rebuild_toolbar_with_buttons(&hToolbar
);
1417 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1418 /* a TB_SETBITMAPSIZE changes button sizes*/
1419 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1422 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1423 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1424 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1426 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1427 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20));
1428 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1430 /* some vertical toolbar sizes */
1431 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1432 check_sizes_todo(0x7c);
1434 rebuild_toolbar_with_buttons(&hToolbar
);
1435 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1436 /* newly added buttons will be use the previous margin */
1437 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons2
);
1439 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1440 check_button_size(hToolbar
, 23, 22);
1441 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1442 check_button_size(hToolbar
, 23, 22);
1443 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1444 check_button_size(hToolbar
, 23, 100);
1445 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1446 check_button_size(hToolbar
, 23, 22);
1447 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1448 check_button_size(hToolbar
, 23, 100);
1450 /* add some buttons with non-default sizes */
1451 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons2
);
1452 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, -1, (LPARAM
)&buttons2
[0]);
1454 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]);
1455 /* TB_ADDSTRINGA resets the size */
1456 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
) STRING0
"\0" STRING1
"\0");
1457 check_button_size(hToolbar
, 23, 23 + fontheight
);
1459 /* TB_SETBUTTONSIZE can be used to crop the text */
1460 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1461 check_button_size(hToolbar
, 23, 22);
1463 /* the default size is bitmap size + padding */
1464 SendMessageA(hToolbar
, TB_SETPADDING
, 0, MAKELONG(1, 1));
1465 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1466 check_button_size(hToolbar
, 17, 17);
1467 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(3, 3));
1468 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1469 check_button_size(hToolbar
, 4, 4);
1471 rebuild_toolbar(&hToolbar
);
1472 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1473 check_button_size(hToolbar
, 23, 22);
1474 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 15));
1475 check_button_size(hToolbar
, 23, 21);
1476 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1477 add_128x15_bitmap(hToolbar
, 16);
1478 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1479 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 21), "%x");
1480 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1481 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1482 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1483 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1484 /* check the imagelist */
1485 InvalidateRect(hToolbar
, NULL
, TRUE
);
1486 UpdateWindow(hToolbar
);
1487 CHECK_IMAGELIST(16, 14, 12);
1489 rebuild_toolbar(&hToolbar
);
1490 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1491 /* the height is increased after a TB_ADDSTRINGA */
1492 check_button_size(hToolbar
, 23, 23 + fontheight
);
1493 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1494 /* if a string is in the pool, even adding a button without a string resets the size */
1495 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]);
1496 check_button_size(hToolbar
, 23, 22);
1497 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1498 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1499 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]);
1500 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1501 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]);
1503 /* delete button doesn't change the buttons size */
1504 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 2, 0);
1505 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
1506 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1507 /* TB_INSERTBUTTONAS will */
1508 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons2
[0]);
1509 check_button_size(hToolbar
, 23, 22);
1511 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1512 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1513 ok(SendMessageA(hToolbar
, TB_MOVEBUTTON
, 0, 1), "TB_MOVEBUTTON failed\n");
1514 check_button_size(hToolbar
, 100, 100);
1515 ok(SendMessageA(hToolbar
, TB_HIDEBUTTON
, 20, TRUE
), "TB_HIDEBUTTON failed\n");
1516 check_button_size(hToolbar
, 100, 100);
1517 /* however changing the hidden flag with TB_SETSTATE does */
1518 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
|TBSTATE_HIDDEN
), "TB_SETSTATE failed\n");
1519 check_button_size(hToolbar
, 100, 100);
1520 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
), "TB_SETSTATE failed\n");
1521 check_button_size(hToolbar
, 23, 22);
1523 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1524 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1525 himl
= pImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_80x15
),
1526 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1527 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1528 check_button_size(hToolbar
, 100, 21);
1529 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1530 check_button_size(hToolbar
, 100, 100);
1531 /* But there are no update when we change imagelist, and image sizes are the same */
1532 himl2
= pImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_128x15
),
1533 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1534 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LRESULT
)himl2
) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1535 check_button_size(hToolbar
, 100, 100);
1536 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1537 check_button_size(hToolbar
, 27, 21);
1538 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl2
, "TB_SETIMAGELIST failed\n");
1539 check_button_size(hToolbar
, 27, 7);
1540 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1541 check_button_size(hToolbar
, 8, 7)
1542 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1543 check_button_size(hToolbar
, 27, 21)
1544 /* the text is taken into account */
1545 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1546 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 4, (LPARAM
)buttons3
);
1547 check_button_size(hToolbar
, 7 + string_width(STRING1
), 22 + fontheight
);
1548 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1549 check_button_size(hToolbar
, 7 + string_width(STRING1
), 8 + fontheight
);
1550 /* the style change also comes into effect */
1552 SetWindowLongA(hToolbar
, GWL_STYLE
, GetWindowLongA(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1553 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1554 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1556 rebuild_toolbar(&hToolbar
);
1557 pImageList_Destroy(himl
);
1558 pImageList_Destroy(himl2
);
1560 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]);
1561 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1562 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 0, 0);
1563 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1565 rebuild_toolbar(&hToolbar
);
1567 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1568 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1569 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1570 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1571 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1572 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1575 rebuild_toolbar(&hToolbar
);
1576 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1577 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1578 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1579 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1580 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1581 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1582 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1583 check_sizes_todo(0xff);
1585 rebuild_toolbar(&hToolbar
);
1586 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1587 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1588 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1589 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1590 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1593 rebuild_toolbar(&hToolbar
);
1594 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_WRAPABLE
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1595 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1596 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1598 tbinfo
.cbSize
= sizeof(TBBUTTONINFOA
);
1599 tbinfo
.dwMask
= TBIF_SIZE
| TBIF_BYINDEX
;
1600 if (SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 0, (LPARAM
)&tbinfo
))
1602 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFOA failed\n");
1603 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1606 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1608 tbinfo
.dwMask
= TBIF_SIZE
;
1609 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 33, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFOA failed\n");
1613 /* Single BTNS_AUTOSIZE button with string. */
1614 rebuild_toolbar(&hToolbar
);
1615 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1616 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1617 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1620 /* Single non-BTNS_AUTOSIZE button with string. */
1621 rebuild_toolbar(&hToolbar
);
1622 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[1]) == 1, "TB_ADDBUTTONSA failed\n");
1623 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1624 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1627 /* Single non-BTNS_AUTOSIZE button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1628 rebuild_toolbar(&hToolbar
);
1629 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1630 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[1]) == 1, "TB_ADDBUTTONSA failed\n");
1631 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1632 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1635 /* Single non-BTNS_AUTOSIZE, BTNS_SHOWTEXT button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1636 rebuild_toolbar(&hToolbar
);
1637 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1638 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1639 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1640 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1643 /* Toolbar with borders around client area */
1644 rebuild_toolbar_ex(&hToolbar
, WS_EX_DLGMODALFRAME
);
1645 SetWindowLongA(hToolbar
, GWL_STYLE
, CCS_NODIVIDER
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1646 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)buttons1
);
1648 GetClientRect(hToolbar
, &rect
);
1649 ok(rect
.top
== 0, "rect.top = %d\n", rect
.top
);
1650 ok(rect
.bottom
== 26, "rect.bottom = %d\n", rect
.bottom
);
1652 rebuild_toolbar_ex(&hToolbar
, WS_EX_DLGMODALFRAME
);
1653 GetClientRect(hToolbar
, &rect
);
1654 ok(rect
.top
== 0, "rect.top = %d\n", rect
.top
);
1655 ok(rect
.bottom
== 26, "rect.bottom = %d\n", rect
.bottom
);
1657 free_tbsize_results();
1658 DestroyWindow(hToolbar
);
1661 /* Toolbar control has two ways of reacting to a change. We call them a
1662 * relayout and recalc. A recalc forces a recompute of values like button size
1663 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1664 * values. This functions creates a flat toolbar with a top margin of a non-flat
1665 * toolbar. We will notice a recalc, as it will recompte the top margin and
1666 * change it to zero*/
1667 static void prepare_recalc_test(HWND
*phToolbar
)
1670 rebuild_toolbar_with_buttons(phToolbar
);
1671 SetWindowLongA(*phToolbar
, GWL_STYLE
,
1672 GetWindowLongA(*phToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1673 SendMessageA(*phToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1674 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1678 static BOOL
did_recalc(HWND hToolbar
)
1681 SendMessageA(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1682 ok(rect
.top
== 2 || rect
.top
== 0, "Unexpected top margin %d in recalc test\n",
1684 return (rect
.top
== 0);
1687 /* call after a recalc did happen to return to an unstable state */
1688 static void restore_recalc_state(HWND hToolbar
)
1691 /* return to style with a 2px top margin */
1692 SetWindowLongA(hToolbar
, GWL_STYLE
,
1693 SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0) & ~TBSTYLE_FLAT
);
1695 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]);
1696 /* top margin will be 0px if a recalc occurs */
1697 SetWindowLongA(hToolbar
, GWL_STYLE
,
1698 SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0) | TBSTYLE_FLAT
);
1700 SendMessageA(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1701 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1705 static void test_recalc(void)
1707 HWND hToolbar
= NULL
;
1709 CHAR test
[] = "Test";
1710 const int EX_STYLES_COUNT
= 5;
1715 /* Like TB_ADDBUTTONSA tested in test_sized, inserting a button without text
1716 * results in a relayout, while adding one with text forces a recalc */
1717 prepare_recalc_test(&hToolbar
);
1718 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons3
[0]);
1719 recalc
= did_recalc(hToolbar
);
1720 ok(!recalc
, "Unexpected recalc - adding button without text\n");
1722 prepare_recalc_test(&hToolbar
);
1723 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons3
[3]);
1724 recalc
= did_recalc(hToolbar
);
1725 ok(recalc
, "Expected a recalc - adding button with text\n");
1727 /* TB_SETBUTTONINFOA, even when adding a text, results only in a relayout */
1728 prepare_recalc_test(&hToolbar
);
1729 bi
.cbSize
= sizeof(bi
);
1730 bi
.dwMask
= TBIF_TEXT
;
1732 SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&bi
);
1733 recalc
= did_recalc(hToolbar
);
1734 ok(!recalc
, "Unexpected recalc - setting a button text\n");
1736 /* most extended styled doesn't force a recalc (testing all the bits gives
1737 * the same results, but prints some ERRs while testing) */
1738 for (i
= 0; i
< EX_STYLES_COUNT
; i
++)
1740 if (i
== 1 || i
== 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1742 prepare_recalc_test(&hToolbar
);
1743 expect(0, (int)SendMessageA(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1744 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, (1 << i
));
1745 recalc
= did_recalc(hToolbar
);
1746 ok(!recalc
, "Unexpected recalc - setting bit %d\n", i
);
1747 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1748 recalc
= did_recalc(hToolbar
);
1749 ok(!recalc
, "Unexpected recalc - clearing bit %d\n", i
);
1750 expect(0, (int)SendMessageA(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1753 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1754 prepare_recalc_test(&hToolbar
);
1755 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1756 recalc
= did_recalc(hToolbar
);
1759 ok(recalc
, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1760 restore_recalc_state(hToolbar
);
1761 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1762 recalc
= did_recalc(hToolbar
);
1763 ok(!recalc
, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1764 restore_recalc_state(hToolbar
);
1765 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1766 recalc
= did_recalc(hToolbar
);
1767 ok(recalc
, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1769 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1771 /* undocumented exstyle 0x2 seems to change the top margin, which
1772 * interferes with these tests */
1774 /* Show that a change in TBSTYLE_WRAPABLE causes a recalc */
1775 prepare_recalc_test(&hToolbar
);
1776 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1777 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1778 recalc
= did_recalc(hToolbar
);
1779 ok(!recalc
, "recalc %d\n", recalc
);
1781 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_TOOLTIPS
| TBSTYLE_TRANSPARENT
| CCS_BOTTOM
);
1782 recalc
= did_recalc(hToolbar
);
1783 ok(!recalc
, "recalc %d\n", recalc
);
1785 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_WRAPABLE
);
1786 recalc
= did_recalc(hToolbar
);
1787 ok(recalc
, "recalc %d\n", recalc
);
1788 restore_recalc_state(hToolbar
);
1790 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_WRAPABLE
);
1791 recalc
= did_recalc(hToolbar
);
1792 ok(!recalc
, "recalc %d\n", recalc
);
1794 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1795 recalc
= did_recalc(hToolbar
);
1796 ok(recalc
, "recalc %d\n", recalc
);
1797 restore_recalc_state(hToolbar
);
1799 /* Changing CCS_VERT does not recalc */
1800 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| CCS_VERT
);
1801 recalc
= did_recalc(hToolbar
);
1802 ok(!recalc
, "recalc %d\n", recalc
);
1803 restore_recalc_state(hToolbar
);
1805 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1806 recalc
= did_recalc(hToolbar
);
1807 ok(!recalc
, "recalc %d\n", recalc
);
1808 restore_recalc_state(hToolbar
);
1810 /* Setting the window's style directly also causes recalc */
1811 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
);
1812 recalc
= did_recalc(hToolbar
);
1813 ok(recalc
, "recalc %d\n", recalc
);
1815 DestroyWindow(hToolbar
);
1818 static void test_getbuttoninfo(void)
1820 HWND hToolbar
= NULL
;
1825 rebuild_toolbar_with_buttons(&hToolbar
);
1826 for (i
= 0; i
< 128; i
++)
1831 tbi
.dwMask
= TBIF_COMMAND
;
1832 ret
= (int)SendMessageA(hToolbar
, TB_GETBUTTONINFOA
, 1, (LPARAM
)&tbi
);
1833 if (i
== sizeof(TBBUTTONINFOA
)) {
1834 compare(ret
, 0, "%d");
1836 compare(ret
, -1, "%d");
1840 /* TBIF_TEXT with NULL pszText */
1841 memset(&tbiW
, 0, sizeof(tbiW
));
1842 tbiW
.cbSize
= sizeof(tbiW
);
1843 tbiW
.dwMask
= TBIF_BYINDEX
| TBIF_STYLE
| TBIF_COMMAND
| TBIF_TEXT
;
1844 i
= SendMessageA(hToolbar
, TB_GETBUTTONINFOW
, 1, (LPARAM
)&tbiW
);
1845 ok(i
== 1, "Got index %d\n", i
);
1847 DestroyWindow(hToolbar
);
1850 static void test_createtoolbarex(void)
1854 ZeroMemory(&btns
, sizeof(btns
));
1856 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1857 3, 20, 20, 16, 16, sizeof(TBBUTTON
));
1858 CHECK_IMAGELIST(16, 20, 20);
1859 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x1a001b, "%x");
1860 DestroyWindow(hToolbar
);
1862 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1863 3, 4, 4, 16, 16, sizeof(TBBUTTON
));
1864 CHECK_IMAGELIST(32, 4, 4);
1865 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xa000b, "%x");
1866 DestroyWindow(hToolbar
);
1868 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1869 3, 0, 8, 12, 12, sizeof(TBBUTTON
));
1870 CHECK_IMAGELIST(16, 12, 12);
1871 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x120013, "%x");
1872 DestroyWindow(hToolbar
);
1874 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1875 3, -1, 8, 12, 12, sizeof(TBBUTTON
));
1876 CHECK_IMAGELIST(16, 12, 8);
1877 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0013, "%x");
1878 DestroyWindow(hToolbar
);
1880 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1881 3, -1, 8, -1, 12, sizeof(TBBUTTON
));
1882 CHECK_IMAGELIST(16, 16, 8);
1883 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0017, "%x");
1884 DestroyWindow(hToolbar
);
1886 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1887 3, 0, 0, 12, -1, sizeof(TBBUTTON
));
1888 CHECK_IMAGELIST(16, 12, 16);
1889 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160013, "%x");
1890 DestroyWindow(hToolbar
);
1892 hToolbar
= pCreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1893 3, 0, 0, 0, 12, sizeof(TBBUTTON
));
1894 CHECK_IMAGELIST(16, 16, 16);
1895 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160017, "%x");
1896 DestroyWindow(hToolbar
);
1899 static void test_dispinfo(void)
1901 HWND hToolbar
= NULL
;
1902 const TBBUTTON buttons_disp
[] = {
1903 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1904 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1908 rebuild_toolbar(&hToolbar
);
1909 SendMessageA(hToolbar
, TB_LOADIMAGES
, IDB_HIST_SMALL_COLOR
, (LPARAM
)HINST_COMMCTRL
);
1910 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons_disp
);
1911 g_dwExpectedDispInfoMask
= TBNF_IMAGE
;
1912 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1913 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1914 compare((BOOL
)SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0, "%d");
1915 ShowWindow(hToolbar
, SW_SHOW
);
1916 UpdateWindow(hToolbar
);
1918 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, TRUE
, 0);
1919 compare(ret
, FALSE
, "%d");
1920 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 1L, "%ld");
1921 InvalidateRect(hToolbar
, NULL
, FALSE
);
1922 UpdateWindow(hToolbar
);
1924 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1925 compare(ret
, TRUE
, "%d");
1926 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0L, "%ld");
1927 InvalidateRect(hToolbar
, NULL
, FALSE
);
1928 UpdateWindow(hToolbar
);
1930 DestroyWindow(hToolbar
);
1931 g_dwExpectedDispInfoMask
= 0;
1941 static tbrows_result_t tbrows_results
[] =
1943 {1, TRUE
, 1}, /* 0: Simple case 9 in a row */
1944 {2, TRUE
, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1945 {3, FALSE
, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1946 {8, FALSE
, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1947 {8, TRUE
, 9}, /* 4: 8 lines but grow - should be 9 lines */
1948 {1, TRUE
, 1} /* 5: Back to simple case */
1951 static void test_setrows(void)
1953 TBBUTTON buttons
[9];
1958 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_FLAT
| TBSTYLE_CHECKGROUP
, 0);
1960 /* Test 1 - 9 buttons */
1961 hToolbar
= pCreateToolbarEx(hMainWnd
,
1962 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
| CCS_NORESIZE
| CCS_NOPARENTALIGN
1963 | CCS_NOMOVEY
| CCS_TOP
,
1966 buttons
, ARRAY_SIZE(buttons
),
1967 20, 20, 0, 0, sizeof(TBBUTTON
));
1968 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1969 ok(SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1971 /* test setting rows to each of 1-10 with bLarger true and false */
1972 for (i
=0; i
<ARRAY_SIZE(tbrows_results
); i
++) {
1976 memset(&rc
, 0xCC, sizeof(rc
));
1977 SendMessageA(hToolbar
, TB_SETROWS
,
1978 MAKELONG(tbrows_results
[i
].nRows
, tbrows_results
[i
].bLarger
),
1981 rows
= SendMessageA(hToolbar
, TB_GETROWS
, MAKELONG(0,0), MAKELONG(0,0));
1982 ok(rows
== tbrows_results
[i
].expectedRows
,
1983 "[%d] Unexpected number of rows %d (expected %d)\n", i
, rows
,
1984 tbrows_results
[i
].expectedRows
);
1987 DestroyWindow(hToolbar
);
1990 static void test_getstring(void)
1992 HWND hToolbar
= NULL
;
1997 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
1998 ok(hToolbar
!= NULL
, "Toolbar creation problem\n");
2000 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(0, 0), 0);
2003 win_skip("TB_GETSTRINGA and TB_GETSTRINGW need 5.80\n");
2004 DestroyWindow(hToolbar
);
2008 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
2010 r
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"STR");
2012 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(0, 0), 0);
2013 ok(r
== 3, "Unexpected return value %d.\n", r
);
2014 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
2015 ok(r
== 3, "Unexpected return value %d.\n", r
);
2016 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(sizeof(str
), 0), (LPARAM
)str
);
2017 ok(r
== 3, "Unexpected return value %d.\n", r
);
2018 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(sizeof(strW
), 0), (LPARAM
)strW
);
2019 ok(r
== 3, "Unexpected return value %d.\n", r
);
2020 ok(!lstrcmpW(L
"STR", strW
), "Unexpected string %s.\n", wine_dbgstr_w(strW
));
2022 DestroyWindow(hToolbar
);
2025 static void test_tooltip(void)
2027 HWND hToolbar
= NULL
;
2028 const TBBUTTON buttons_disp
[] = {
2029 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
2030 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
2032 NMTTDISPINFOW nmtti
;
2035 rebuild_toolbar(&hToolbar
);
2037 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons_disp
);
2039 /* W used to get through toolbar code that assumes tooltip is always Unicode */
2040 memset(&nmtti
, 0, sizeof(nmtti
));
2041 nmtti
.hdr
.code
= TTN_GETDISPINFOW
;
2042 nmtti
.hdr
.idFrom
= 20;
2044 SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
2046 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2047 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
2048 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ttgetdispinfo_parent_seq
,
2049 "dispinfo from tooltip", FALSE
);
2051 g_ResetDispTextPtr
= TRUE
;
2052 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
2053 /* Same for TBN_GETINFOTIPW */
2054 SendMessageA(hToolbar
, TB_SETUNICODEFORMAT
, TRUE
, 0);
2055 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
2056 g_ResetDispTextPtr
= FALSE
;
2058 DestroyWindow(hToolbar
);
2060 /* TBSTYLE_TOOLTIPS */
2061 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
2062 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2063 tooltip
= (HWND
)SendMessageA(hToolbar
, TB_GETTOOLTIPS
, 0, 0);
2064 ok(tooltip
== NULL
, "got %p\n", tooltip
);
2065 DestroyWindow(hToolbar
);
2068 static void test_get_set_style(void)
2070 TBBUTTON buttons
[9];
2071 DWORD style
, style2
, ret
;
2076 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
2077 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
2078 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
2080 hToolbar
= pCreateToolbarEx(hMainWnd
,
2081 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
2082 WS_CHILD
| TBSTYLE_LIST
,
2085 buttons
, ARRAY_SIZE(buttons
),
2086 0, 0, 20, 16, sizeof(TBBUTTON
));
2087 ok(hToolbar
!= NULL
, "Toolbar creation\n");
2088 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
2090 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
2091 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
2093 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
2095 /* try to alter common window bits */
2096 style2
|= WS_BORDER
;
2097 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
2098 ok(ret
== 0, "got %d\n", ret
);
2099 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
2100 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
2101 ok((style
!= style2
) && (style
== (style2
| WS_BORDER
)),
2102 "got 0x%08x, expected 0x%08x\n", style
, style2
);
2103 ok(style
& WS_BORDER
, "got 0x%08x\n", style
);
2105 /* now styles are the same, alter window style */
2106 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
2107 ok(ret
== 0, "got %d\n", ret
);
2108 style2
|= WS_BORDER
;
2109 SetWindowLongA(hToolbar
, GWL_STYLE
, style2
);
2110 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
2111 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
2113 DestroyWindow(hToolbar
);
2116 static HHOOK g_tbhook
;
2117 static HWND g_toolbar
;
2119 DEFINE_EXPECT(g_hook_create
);
2120 DEFINE_EXPECT(g_hook_WM_NCCREATE
);
2121 DEFINE_EXPECT(g_hook_WM_CREATE
);
2123 static LRESULT WINAPI
toolbar_subclass_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2125 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
2129 if (msg
== WM_NCCREATE
)
2131 if (g_toolbar
== hwnd
)
2133 CHECK_EXPECT2(g_hook_WM_NCCREATE
);
2135 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2137 /* control is already set up */
2138 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2139 ok(style
!= 0, "got %x\n", style
);
2141 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2142 ok((style
& TBSTYLE_TOOLTIPS
) == 0, "got 0x%08x\n", style
);
2143 SetWindowLongA(hwnd
, GWL_STYLE
, style
|TBSTYLE_TOOLTIPS
);
2144 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2145 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2150 else if (msg
== WM_CREATE
)
2152 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
2154 if (g_toolbar
== hwnd
)
2156 CHECK_EXPECT2(g_hook_WM_CREATE
);
2158 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2159 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2161 /* test if toolbar-specific messages are already working before WM_CREATE */
2162 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2163 ok(style
!= 0, "got %x\n", style
);
2164 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
2165 ok((cs
->style
& TBSTYLE_TOOLTIPS
) == 0, "0x%08x\n", cs
->style
);
2167 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2169 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2170 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2172 /* test if toolbar-specific messages are already working before WM_CREATE */
2173 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2174 ok(style
!= 0, "got %x\n", style
);
2175 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
2181 return CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2184 static LRESULT CALLBACK
cbt_hook_proc(int code
, WPARAM wParam
, LPARAM lParam
)
2186 if (code
== HCBT_CREATEWND
)
2188 HWND hwnd
= (HWND
)wParam
;
2194 CHECK_EXPECT2(g_hook_create
);
2197 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)toolbar_subclass_proc
);
2198 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
2203 return CallNextHookEx(g_tbhook
, code
, wParam
, lParam
);
2206 static void test_create(void)
2211 g_tbhook
= SetWindowsHookA(WH_CBT
, cbt_hook_proc
);
2213 SET_EXPECT(g_hook_create
);
2214 SET_EXPECT(g_hook_WM_NCCREATE
);
2215 SET_EXPECT(g_hook_WM_CREATE
);
2217 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
2218 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2220 CHECK_CALLED(g_hook_create
);
2221 CHECK_CALLED(g_hook_WM_NCCREATE
);
2222 CHECK_CALLED(g_hook_WM_CREATE
);
2224 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2225 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2227 tooltip
= (HWND
)SendMessageA(hwnd
, TB_GETTOOLTIPS
, 0, 0);
2228 ok(tooltip
!= NULL
, "got %p\n", tooltip
);
2229 ok(GetParent(tooltip
) == hMainWnd
, "got %p, %p\n", hMainWnd
, hwnd
);
2231 DestroyWindow(hwnd
);
2232 UnhookWindowsHook(WH_CBT
, cbt_hook_proc
);
2234 /* TBSTYLE_TRANSPARENT */
2235 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
,
2236 WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|TBSTYLE_FLAT
|TBSTYLE_TOOLTIPS
|TBSTYLE_GROUP
,
2237 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2239 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2240 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
2242 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2243 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
2245 DestroyWindow(hwnd
);
2254 static const extended_style_t extended_style_test
[] = {
2256 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
2257 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
2258 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
2261 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
,
2262 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
2265 { 0, TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
},
2267 { 0, TBSTYLE_EX_DRAWDDARROWS
, TBSTYLE_EX_DRAWDDARROWS
},
2268 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
},
2271 { TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
2272 { TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, 0 },
2273 { TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
2276 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
2277 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
2280 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
2281 TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_DOUBLEBUFFER
2285 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
2287 DWORD style
, oldstyle
, oldstyle2
;
2288 const extended_style_t
*ptr
;
2292 rebuild_toolbar(&hwnd
);
2294 SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
);
2295 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2296 if (style
== TBSTYLE_EX_MIXEDBUTTONS
)
2298 win_skip("Some extended style bits are not supported\n");
2299 DestroyWindow(hwnd
);
2303 for (i
= 0; i
< ARRAY_SIZE(extended_style_test
); i
++)
2305 ptr
= &extended_style_test
[i
];
2307 oldstyle2
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2309 oldstyle
= SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, ptr
->mask
, ptr
->style
);
2310 ok(oldstyle
== oldstyle2
, "%d: got old style 0x%08x, expected 0x%08x\n", i
, oldstyle
, oldstyle2
);
2311 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2312 ok(style
== ptr
->style_set
, "%d: got style 0x%08x, expected 0x%08x\n", i
, style
, ptr
->style_set
);
2315 /* Windows sets CCS_VERT when TB_GETEXTENDEDSTYLE is set */
2316 oldstyle2
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2317 oldstyle
= SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_VERTICAL
);
2318 ok(oldstyle
== oldstyle2
, "got old style 0x%08x, expected 0x%08x\n", oldstyle
, oldstyle2
);
2319 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2320 ok(style
== TBSTYLE_EX_VERTICAL
, "got style 0x%08x, expected 0x%08x\n", style
, TBSTYLE_EX_VERTICAL
);
2321 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2323 ok(style
== CCS_VERT
, "got style 0x%08x, expected CCS_VERT\n", style
);
2325 DestroyWindow(hwnd
);
2328 static void test_noresize(void)
2332 TBBUTTON button
= {0, 10, TBSTATE_ENABLED
, 0, {0, }, 0, -1};
2334 wnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
| CCS_NORESIZE
| TBSTYLE_WRAPABLE
, 0, 0, 100, 20,
2335 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2336 SendMessageA(wnd
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
2338 for (i
=0; i
<30; i
++)
2340 button
.idCommand
= 10 + i
;
2341 SendMessageA(wnd
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
2344 SendMessageA(wnd
, TB_SETSTATE
, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
);
2346 /* autosize clears the wrap on button 0 */
2347 SendMessageA(wnd
, TB_AUTOSIZE
, 0, 0);
2348 for (i
=0; i
<30; i
++)
2350 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2352 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2354 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2357 /* changing the parent doesn't do anything */
2358 MoveWindow(hMainWnd
, 0,0, 400, 200, FALSE
);
2359 for (i
=0; i
<30; i
++)
2361 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2363 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2365 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2368 /* again nothing here */
2369 SendMessageA(wnd
, TB_AUTOSIZE
, 0, 0);
2370 for (i
=0; i
<30; i
++)
2372 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2374 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2376 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2383 static void test_save(void)
2386 TBSAVEPARAMSW params
;
2390 DWORD size
= sizeof(data
), type
, i
, count
;
2392 static const TBBUTTON more_btns
[2] =
2394 {0, 11, TBSTATE_HIDDEN
, BTNS_BUTTON
, {0}, 0, -1},
2395 {0, 13, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, -1}
2397 static const DWORD expect
[] = {0xcafe, 1, 0xcafe0000, 3, 0xcafe0001, 5, 0xcafe0002, 7, 0xcafe0003,
2398 9, 0xcafe0004, 11, 0xcafe0005, 13, 0xcafe0006, 0xffffffff, 0xcafe0007,
2399 0xfffffffe, 0xcafe0008, 0x80000000, 0xcafe0009, 0x7fffffff, 0xcafe000a,
2401 static const TBBUTTON expect_btns
[] =
2403 {0, 1, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0},
2404 {0, 3, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 1, 2},
2405 {0, 5, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 2, 0},
2406 {0, 7, 0, BTNS_BUTTON
, {0}, 0, (INT_PTR
)"foo"},
2407 {0, 9, 0, BTNS_BUTTON
, {0}, 0, 0},
2408 {0, 11, 0, BTNS_BUTTON
, {0}, 0, 3},
2409 {0, 13, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 6, 0},
2410 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 7, 0},
2411 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 8, 0},
2412 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 9, 0},
2413 {0, 0x7fffffff, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0xa, 0},
2416 params
.hkr
= HKEY_CURRENT_USER
;
2417 params
.pszSubKey
= L
"Software\\Wine\\WineTest";
2418 params
.pszValueName
= L
"toolbartest";
2420 rebuild_toolbar_with_buttons( &wnd
);
2421 SendMessageW(wnd
, TB_ADDBUTTONSW
, ARRAY_SIZE(more_btns
), (LPARAM
)more_btns
);
2423 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2424 res
= SendMessageW( wnd
, TB_SAVERESTOREW
, TRUE
, (LPARAM
)¶ms
);
2425 ok( res
, "saving failed\n" );
2426 ok_sequence(sequences
, PARENT_SEQ_INDEX
, save_parent_seq
, "save", FALSE
);
2427 DestroyWindow( wnd
);
2429 res
= RegOpenKeyW( HKEY_CURRENT_USER
, L
"Software\\Wine\\WineTest", &key
);
2430 ok( !res
, "got %08x\n", res
);
2431 res
= RegQueryValueExW( key
, L
"toolbartest", NULL
, &type
, data
, &size
);
2432 ok( !res
, "got %08x\n", res
);
2433 ok( type
== REG_BINARY
, "got %08x\n", type
);
2434 ok( size
== sizeof(expect
), "got %08x\n", size
);
2435 ok( !memcmp( data
, expect
, size
), "mismatch\n" );
2440 rebuild_toolbar( &wnd
);
2442 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2443 res
= SendMessageW( wnd
, TB_SAVERESTOREW
, FALSE
, (LPARAM
)¶ms
);
2444 ok( res
, "restoring failed\n" );
2445 ok_sequence(sequences
, PARENT_SEQ_INDEX
, restore_parent_seq
, "restore", FALSE
);
2446 count
= SendMessageW( wnd
, TB_BUTTONCOUNT
, 0, 0 );
2447 ok( count
== ARRAY_SIZE(expect_btns
), "got %d\n", count
);
2449 for (i
= 0; i
< count
; i
++)
2451 res
= SendMessageW( wnd
, TB_GETBUTTON
, i
, (LPARAM
)&tb
);
2452 ok( res
, "got %d\n", res
);
2454 ok( tb
.iBitmap
== expect_btns
[i
].iBitmap
, "%d: got %d\n", i
, tb
.iBitmap
);
2455 ok( tb
.idCommand
== expect_btns
[i
].idCommand
, "%d: got %d\n", i
, tb
.idCommand
);
2456 ok( tb
.fsState
== expect_btns
[i
].fsState
, "%d: got %02x\n", i
, tb
.fsState
);
2457 ok( tb
.fsStyle
== expect_btns
[i
].fsStyle
, "%d: got %02x\n", i
, tb
.fsStyle
);
2458 ok( tb
.dwData
== expect_btns
[i
].dwData
, "%d: got %lx\n", i
, tb
.dwData
);
2459 if (IS_INTRESOURCE(expect_btns
[i
].iString
))
2460 ok( tb
.iString
== expect_btns
[i
].iString
, "%d: got %lx\n", i
, tb
.iString
);
2462 ok( !strcmp( (char *)tb
.iString
, (char *)expect_btns
[i
].iString
),
2463 "%d: got %s\n", i
, (char *)tb
.iString
);
2465 /* In fact the ptr value set in TBN_GETBUTTONINFOA is simply copied */
2466 if (tb
.idCommand
== 7)
2467 ok( tb
.iString
== (INT_PTR
)alloced_str
, "string not set\n");
2470 DestroyWindow( wnd
);
2471 RegOpenKeyW( HKEY_CURRENT_USER
, L
"Software\\Wine\\WineTest", &key
);
2472 RegDeleteValueW( key
, L
"toolbartest" );
2476 static void test_drawtext_flags(void)
2481 rebuild_toolbar(&hwnd
);
2483 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, 0, 0);
2485 ok(flags
== 0, "Unexpected draw text flags %#x\n", flags
);
2487 /* zero mask, flags are retained */
2488 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, 0, DT_BOTTOM
);
2490 ok(flags
== 0, "Unexpected draw text flags %#x\n", flags
);
2491 ok(!(flags
& DT_BOTTOM
), "Unexpected DT_BOTTOM style\n");
2493 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, 0, 0);
2495 ok(flags
== 0, "Unexpected draw text flags %#x\n", flags
);
2496 ok(!(flags
& DT_BOTTOM
), "Unexpected DT_BOTTOM style\n");
2499 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, DT_BOTTOM
, DT_BOTTOM
);
2501 ok(flags
== 0, "Unexpected draw text flags %#x\n", flags
);
2502 ok(!(flags
& DT_BOTTOM
), "Unexpected DT_BOTTOM style\n");
2504 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, DT_BOTTOM
, 0);
2506 ok(flags
== DT_BOTTOM
, "Unexpected draw text flags %#x\n", flags
);
2507 ok(flags
& DT_BOTTOM
, "Expected DT_BOTTOM style, %#x\n", flags
);
2509 flags
= SendMessageA(hwnd
, TB_SETDRAWTEXTFLAGS
, DT_BOTTOM
, 0);
2511 ok(flags
== 0, "Unexpected draw text flags %#x\n", flags
);
2512 ok(!(flags
& DT_BOTTOM
), "Unexpected DT_BOTTOM style\n");
2514 DestroyWindow(hwnd
);
2517 static void test_imagelist(void)
2519 HIMAGELIST imagelist
;
2523 rebuild_toolbar(&hwnd
);
2525 imagelist
= (HIMAGELIST
)SendMessageA(hwnd
, TB_GETIMAGELIST
, 0, 0);
2526 ok(imagelist
== NULL
, "got %p\n", imagelist
);
2528 ret
= SendMessageA(hwnd
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 16));
2529 ok(ret
, "got %d\n", ret
);
2531 imagelist
= (HIMAGELIST
)SendMessageA(hwnd
, TB_GETIMAGELIST
, 0, 0);
2532 ok(imagelist
== NULL
, "got %p\n", imagelist
);
2534 DestroyWindow(hwnd
);
2537 static void init_functions(void)
2539 HMODULE hComCtl32
= LoadLibraryA("comctl32.dll");
2541 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
2543 X(ImageList_GetIconSize
);
2544 X(ImageList_GetImageCount
);
2545 X(ImageList_LoadImageA
);
2546 X(ImageList_Destroy
);
2556 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
2559 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2562 wc
.hInstance
= GetModuleHandleA(NULL
);
2564 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_IBEAM
);
2565 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2566 wc
.lpszMenuName
= NULL
;
2567 wc
.lpszClassName
= "Toolbar test parent";
2568 wc
.lpfnWndProc
= parent_wnd_proc
;
2569 RegisterClassA(&wc
);
2571 hMainWnd
= CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW
,
2572 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
2573 GetClientRect(hMainWnd
, &rc
);
2574 ShowWindow(hMainWnd
, SW_SHOW
);
2582 test_getbuttoninfo();
2583 test_createtoolbarex();
2588 test_get_set_style();
2590 test_TB_GET_SET_EXTENDEDSTYLE();
2593 test_drawtext_flags();
2597 while(GetMessageA(&msg
,0,0,0)) {
2598 TranslateMessage(&msg
);
2599 DispatchMessageA(&msg
);
2601 DestroyWindow(hMainWnd
);