1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "resources.h"
33 #include "wine/test.h"
36 static BOOL g_fBlockHotItemChange
;
37 static BOOL g_fReceivedHotItemChange
;
38 static BOOL g_fExpectedHotItemOld
;
39 static BOOL g_fExpectedHotItemNew
;
41 #define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \
42 val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \
43 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom);
45 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
47 static void MakeButton(TBBUTTON
*p
, int idCommand
, int fsStyle
, int nString
) {
49 p
->idCommand
= idCommand
;
50 p
->fsState
= TBSTATE_ENABLED
;
55 static LRESULT
MyWnd_Notify(LPARAM lParam
)
57 NMHDR
*hdr
= (NMHDR
*)lParam
;
61 case TBN_HOTITEMCHANGE
:
62 nmhi
= (NMTBHOTITEM
*)lParam
;
63 g_fReceivedHotItemChange
= TRUE
;
64 if (g_fExpectedHotItemOld
!= g_fExpectedHotItemNew
)
66 compare(nmhi
->idOld
, g_fExpectedHotItemOld
, "%d");
67 compare(nmhi
->idNew
, g_fExpectedHotItemNew
, "%d");
69 if (g_fBlockHotItemChange
)
76 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
81 return MyWnd_Notify(lParam
);
83 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
86 static void basic_test(void)
92 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
93 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
94 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
96 hToolbar
= CreateToolbarEx(hMainWnd
,
97 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
98 WS_CHILD
| TBSTYLE_LIST
,
101 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
102 0, 0, 20, 16, sizeof(TBBUTTON
));
103 ok(hToolbar
!= NULL
, "Toolbar creation\n");
104 SendMessage(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
106 /* test for exclusion working inside a separator-separated :-) group */
107 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 */
108 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
109 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1001, 0), "A2 not pressed\n");
111 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1004, 1); /* press A5, release A1 */
112 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 pressed\n");
113 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 not pressed anymore\n");
115 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1005, 1); /* press A6, release A5 */
116 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
117 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 not pressed anymore\n");
119 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
120 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1007, 1); /* press B2 */
121 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
122 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 still not pressed\n");
123 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 pressed\n");
125 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 and ensure B group didn't suffer */
126 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 not pressed anymore\n");
127 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
128 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 still pressed\n");
130 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1008, 1); /* press B3, and ensure A group didn't suffer */
131 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
132 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
133 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 not pressed\n");
134 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1008, 0), "B3 pressed\n");
135 DestroyWindow(hToolbar
);
138 static void rebuild_toolbar(HWND
*hToolbar
)
140 if (*hToolbar
!= NULL
)
141 DestroyWindow(*hToolbar
);
142 *hToolbar
= CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
143 hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
144 ok(*hToolbar
!= NULL
, "Toolbar creation problem\n");
145 ok(SendMessage(*hToolbar
, TB_BUTTONSTRUCTSIZE
, (WPARAM
)sizeof(TBBUTTON
), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
146 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
147 ok(SendMessage(*hToolbar
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0)==1, "WM_SETFONT\n");
150 static void rebuild_toolbar_with_buttons(HWND
*hToolbar
)
153 rebuild_toolbar(hToolbar
);
155 ZeroMemory(&buttons
, sizeof(buttons
));
156 buttons
[0].idCommand
= 1;
157 buttons
[0].fsStyle
= BTNS_BUTTON
;
158 buttons
[0].fsState
= TBSTATE_ENABLED
;
159 buttons
[0].iString
= -1;
160 buttons
[1].idCommand
= 3;
161 buttons
[1].fsStyle
= BTNS_BUTTON
;
162 buttons
[1].fsState
= TBSTATE_ENABLED
;
163 buttons
[1].iString
= -1;
164 buttons
[2].idCommand
= 5;
165 buttons
[2].fsStyle
= BTNS_SEP
;
166 buttons
[2].fsState
= TBSTATE_ENABLED
;
167 buttons
[2].iString
= -1;
168 buttons
[3].idCommand
= 7;
169 buttons
[3].fsStyle
= BTNS_BUTTON
;
170 buttons
[3].fsState
= TBSTATE_ENABLED
;
171 buttons
[3].iString
= -1;
172 buttons
[4].idCommand
= 9;
173 buttons
[4].fsStyle
= BTNS_BUTTON
;
174 buttons
[4].fsState
= 0; /* disabled */
175 buttons
[4].iString
= -1;
176 ok(SendMessage(*hToolbar
, TB_ADDBUTTONS
, 5, (LPARAM
)buttons
) == 1, "TB_ADDBUTTONS failed\n");
177 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
181 #define CHECK_IMAGELIST(count, dx, dy) { \
183 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
184 ok(himl != NULL, "No image list\n"); \
186 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
187 ImageList_GetIconSize(himl, &cx, &cy); \
188 ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
192 #define CHECK_IMAGELIST_TODO_COUNT(count, dx, dy) { \
194 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
195 ok(himl != NULL, "No image list\n"); \
197 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
198 ImageList_GetIconSize(himl, &cx, &cy); \
199 ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
203 #define CHECK_IMAGELIST_TODO_COUNT_SIZE(count, dx, dy) { \
205 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
206 ok(himl != NULL, "No image list\n"); \
208 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
209 ImageList_GetIconSize(himl, &cx, &cy); \
210 todo_wine ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
214 static void test_add_bitmap(void)
216 HWND hToolbar
= NULL
;
219 TBADDBITMAP stdsmall
;
224 /* empty 128x15 bitmap */
225 bmp128
.hInst
= GetModuleHandle(NULL
);
226 bmp128
.nID
= IDB_BITMAP_128x15
;
228 /* empty 80x15 bitmap */
229 bmp80
.hInst
= GetModuleHandle(NULL
);
230 bmp80
.nID
= IDB_BITMAP_80x15
;
232 /* standard bitmap - 240x15 pixels */
233 stdsmall
.hInst
= HINST_COMMCTRL
;
234 stdsmall
.nID
= IDB_STD_SMALL_COLOR
;
236 rebuild_toolbar(&hToolbar
);
237 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
238 CHECK_IMAGELIST(8, 16, 15);
240 /* adding more bitmaps */
241 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 8, "TB_ADDBITMAP - unexpected return\n");
242 CHECK_IMAGELIST(13, 16, 15);
243 /* adding the same bitmap will simply return the index of the already loaded block */
244 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
);
245 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
246 CHECK_IMAGELIST(13, 16, 15);
247 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
248 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
249 CHECK_IMAGELIST(13, 16, 15);
250 /* even if we increase the wParam */
251 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 55, (LPARAM
)&bmp80
);
252 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
253 CHECK_IMAGELIST(13, 16, 15);
255 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
256 rebuild_toolbar(&hToolbar
);
257 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
258 CHECK_IMAGELIST(8, 16, 15);
259 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
260 ok(ret
== 3, "TB_ADDBITMAP - unexpected return %d\n", ret
);
261 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
262 CHECK_IMAGELIST(13, 16, 15);
264 /* the same for negative wParam */
265 rebuild_toolbar(&hToolbar
);
266 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, -143, (LPARAM
)&bmp128
);
267 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
268 CHECK_IMAGELIST(8, 16, 15);
269 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
270 ok(ret
== -143, "TB_ADDBITMAP - unexpected return %d\n", ret
);
271 CHECK_IMAGELIST(13, 16, 15);
273 /* for zero only one bitmap will be added */
274 rebuild_toolbar(&hToolbar
);
275 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&bmp80
);
276 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
277 CHECK_IMAGELIST(1, 16, 15);
279 /* if wParam is larger than the amount of icons, the list is grown */
280 rebuild_toolbar(&hToolbar
);
281 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
282 CHECK_IMAGELIST(100, 16, 15);
283 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
);
284 ok(ret
== 100, "TB_ADDBITMAP - unexpected return %d\n", ret
);
285 CHECK_IMAGELIST(200, 16, 15);
287 /* adding built-in items - the wParam is ignored */
288 rebuild_toolbar(&hToolbar
);
289 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
290 CHECK_IMAGELIST(5, 16, 15);
291 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 5, "TB_ADDBITMAP - unexpected return\n");
292 CHECK_IMAGELIST(20, 16, 15);
293 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 20, "TB_ADDBITMAP - unexpected return\n");
294 CHECK_IMAGELIST(28, 16, 15);
296 /* when we increase the bitmap size, less icons will be created */
297 rebuild_toolbar(&hToolbar
);
298 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
299 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
300 CHECK_IMAGELIST(6, 20, 20);
301 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
302 ok(ret
== 1, "TB_ADDBITMAP - unexpected return %d\n", ret
);
303 CHECK_IMAGELIST(10, 20, 20);
304 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
305 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
306 UpdateWindow(hToolbar
);
307 CHECK_IMAGELIST(26, 8, 8);
308 /* loading a standard bitmaps automatically resizes the icons */
309 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&stdsmall
) == 2, "TB_ADDBITMAP - unexpected return\n");
310 UpdateWindow(hToolbar
);
311 CHECK_IMAGELIST(28, 16, 15);
313 /* two more SETBITMAPSIZE tests */
314 rebuild_toolbar(&hToolbar
);
315 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
316 CHECK_IMAGELIST(100, 16, 15);
317 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 100, "TB_ADDBITMAP - unexpected return\n");
318 CHECK_IMAGELIST(200, 16, 15);
319 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
320 UpdateWindow(hToolbar
);
321 CHECK_IMAGELIST(200, 8, 8);
322 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
323 UpdateWindow(hToolbar
);
324 CHECK_IMAGELIST(200, 30, 30);
325 rebuild_toolbar(&hToolbar
);
326 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
327 CHECK_IMAGELIST(8, 16, 15);
328 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp80
) == 5, "TB_ADDBITMAP - unexpected return\n");
329 CHECK_IMAGELIST(13, 16, 15);
330 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
331 UpdateWindow(hToolbar
);
332 CHECK_IMAGELIST(8, 30, 30);
333 /* when the width or height is zero, set it to 1 */
334 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
335 UpdateWindow(hToolbar
);
336 CHECK_IMAGELIST(208, 1, 1);
337 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 5)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
338 UpdateWindow(hToolbar
);
339 CHECK_IMAGELIST(208, 1, 5);
340 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(5, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
341 UpdateWindow(hToolbar
);
342 CHECK_IMAGELIST(41, 5, 1);
344 /* the control can add bitmaps to an existing image list */
345 rebuild_toolbar(&hToolbar
);
346 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_80x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
347 ok(himl
!= NULL
, "failed to create imagelist\n");
348 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
349 CHECK_IMAGELIST(4, 20, 15);
350 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
351 CHECK_IMAGELIST(10, 20, 15);
352 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change!) */
353 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
354 UpdateWindow(hToolbar
);
355 CHECK_IMAGELIST(10, 20, 15);
356 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 1, "TB_SETBITMAPSIZE failed\n");
357 UpdateWindow(hToolbar
);
358 CHECK_IMAGELIST_TODO_COUNT(22, 20, 15);
360 /* check standard bitmaps */
361 addbmp
.hInst
= HINST_COMMCTRL
;
362 addbmp
.nID
= IDB_STD_SMALL_COLOR
;
363 rebuild_toolbar(&hToolbar
);
364 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
365 CHECK_IMAGELIST(15, 16, 15);
366 addbmp
.nID
= IDB_STD_LARGE_COLOR
;
367 rebuild_toolbar(&hToolbar
);
368 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
369 CHECK_IMAGELIST(15, 24, 24);
371 addbmp
.nID
= IDB_VIEW_SMALL_COLOR
;
372 rebuild_toolbar(&hToolbar
);
373 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
374 CHECK_IMAGELIST(12, 16, 15);
375 addbmp
.nID
= IDB_VIEW_LARGE_COLOR
;
376 rebuild_toolbar(&hToolbar
);
377 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
378 CHECK_IMAGELIST(12, 24, 24);
380 addbmp
.nID
= IDB_HIST_SMALL_COLOR
;
381 rebuild_toolbar(&hToolbar
);
382 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
383 CHECK_IMAGELIST(5, 16, 15);
384 addbmp
.nID
= IDB_HIST_LARGE_COLOR
;
385 rebuild_toolbar(&hToolbar
);
386 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
387 CHECK_IMAGELIST(5, 24, 24);
390 DestroyWindow(hToolbar
);
393 #define CHECK_STRING_TABLE(count, tab) { \
396 for (_i = 0; _i < (count); _i++) {\
397 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
398 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
400 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
402 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
403 "Too many string in table\n"); \
406 static void test_add_string(void)
408 LPCSTR test1
= "a\0b\0";
409 LPCSTR test2
= "|a|b||\0";
410 LPCSTR ret1
[] = {"a", "b"};
411 LPCSTR ret2
[] = {"a", "b", "|a|b||"};
412 LPCSTR ret3
[] = {"a", "b", "|a|b||", "p", "q"};
413 LPCSTR ret4
[] = {"a", "b", "|a|b||", "p", "q", "p"};
414 LPCSTR ret5
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
415 LPCSTR ret6
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
416 LPCSTR ret7
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
417 HWND hToolbar
= NULL
;
421 rebuild_toolbar(&hToolbar
);
422 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test1
);
423 ok(ret
== 0, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
424 CHECK_STRING_TABLE(2, ret1
);
425 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test2
);
426 ok(ret
== 2, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
427 CHECK_STRING_TABLE(3, ret2
);
429 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD1
);
430 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
431 CHECK_STRING_TABLE(3, ret2
);
432 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD2
);
433 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
434 CHECK_STRING_TABLE(5, ret3
);
435 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD3
);
436 ok(ret
== 5, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
437 CHECK_STRING_TABLE(6, ret4
);
438 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD4
);
439 ok(ret
== 6, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
440 CHECK_STRING_TABLE(8, ret5
);
441 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD5
);
442 ok(ret
== 8, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
443 CHECK_STRING_TABLE(11, ret6
);
444 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD7
);
445 ok(ret
== 11, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
446 CHECK_STRING_TABLE(14, ret7
);
448 ZeroMemory(&button
, sizeof(button
));
449 button
.iString
= (UINT_PTR
)"Test";
450 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 0, (LPARAM
)&button
);
451 CHECK_STRING_TABLE(14, ret7
);
452 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
453 CHECK_STRING_TABLE(14, ret7
);
455 DestroyWindow(hToolbar
);
458 static void expect_hot_notify(int idold
, int idnew
)
460 g_fExpectedHotItemOld
= idold
;
461 g_fExpectedHotItemNew
= idnew
;
462 g_fReceivedHotItemChange
= FALSE
;
465 #define check_hot_notify() \
466 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
467 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
469 static void test_hotitem(void)
471 HWND hToolbar
= NULL
;
475 g_fBlockHotItemChange
= FALSE
;
477 rebuild_toolbar_with_buttons(&hToolbar
);
478 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
479 * comctl6 doesn't have this requirement even when theme == NULL */
480 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_FLAT
| GetWindowLong(hToolbar
, GWL_STYLE
));
481 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
482 ok(ret
== -1, "Hot item: %ld, expected -1\n", ret
);
483 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
484 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
485 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
486 ok(ret
== 1, "Hot item: %ld, expected 1\n", ret
);
487 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
488 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
490 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeef, 0);
491 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
492 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
493 ok(ret
== 2, "Hot item: %lx, expected 2\n", ret
);
494 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeef, 0);
495 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
496 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
497 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
499 expect_hot_notify(0, 7);
500 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
501 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
503 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
504 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
505 g_fBlockHotItemChange
= TRUE
;
506 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
507 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
508 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
509 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
510 g_fBlockHotItemChange
= FALSE
;
512 g_fReceivedHotItemChange
= FALSE
;
513 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeaf, 0);
514 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
515 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received for invalid parameter\n");
517 g_fReceivedHotItemChange
= FALSE
;
518 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
519 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
520 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received after a duplication\n");
522 expect_hot_notify(7, 0);
523 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeaf, 0);
524 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
526 SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
528 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
529 expect_hot_notify(7, 9);
530 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 4, 0);
531 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
533 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
534 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
535 /* enabling the button won't change that */
536 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 9, TRUE
);
537 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
538 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
540 /* disabling a hot button works */
541 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
542 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
543 g_fReceivedHotItemChange
= FALSE
;
544 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 7, FALSE
);
545 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
546 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
547 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
549 SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
550 tbinfo
.cbSize
= sizeof(TBBUTTONINFO
);
551 tbinfo
.dwMask
= TBIF_STATE
;
552 tbinfo
.fsState
= 0; /* disabled */
553 g_fReceivedHotItemChange
= FALSE
;
554 ok(SendMessage(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&tbinfo
) == TRUE
, "TB_SETBUTTONINFO failed\n");
555 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
556 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
557 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
559 DestroyWindow(hToolbar
);
562 #if 0 /* use this to generate more tests*/
564 static void dump_sizes(HWND hToolbar
)
568 int count
= SendMessage(hToolbar
, TB_BUTTONCOUNT
, 0, 0);
571 GetClientRect(hToolbar
, &r
);
572 SendMessageA(hToolbar
, TB_GETMAXSIZE
, 0, &sz
);
573 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r
.left
, r
.top
, r
.right
, r
.bottom
,
574 sz
.cx
, sz
.cy
, count
);
575 for (i
=0; i
<count
; i
++)
577 SendMessageA(hToolbar
, TB_GETITEMRECT
, i
, &r
);
578 printf("%s{%3d, %3d, %3d, %3d}, ", (i
%3==0 ? "\n " : ""), r
.left
, r
.top
, r
.right
, r
.bottom
);
580 printf("\n }, }, \n");
583 #define check_sizes() dump_sizes(hToolbar);
584 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
596 static tbsize_result_t tbsize_results
[] =
598 { {0, 0, 672, 26}, {100, 22}, 5, {
599 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
600 { 54, 2, 77, 24}, { 77, 2, 100, 24},
602 { {0, 0, 672, 26}, {146, 22}, 7, {
603 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
604 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
607 { {0, 0, 672, 48}, {146, 22}, 7, {
608 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
609 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
612 { {0, 0, 672, 26}, {146, 22}, 7, {
613 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
614 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
617 { {0, 0, 672, 26}, {192, 22}, 9, {
618 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
619 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
620 {123, 2, 146, 24}, {146, 2, 169, 24}, {169, 2, 192, 24},
622 { {0, 0, 672, 92}, {882, 22}, 39, {
623 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 2, 8, 29},
624 { 0, 29, 23, 51}, { 23, 29, 46, 51}, { 46, 29, 69, 51},
625 { 69, 29, 92, 51}, { 92, 29, 115, 51}, {115, 29, 138, 51},
626 {138, 29, 161, 51}, {161, 29, 184, 51}, {184, 29, 207, 51},
627 {207, 29, 230, 51}, {230, 29, 253, 51}, {253, 29, 276, 51},
628 {276, 29, 299, 51}, {299, 29, 322, 51}, {322, 29, 345, 51},
629 {345, 29, 368, 51}, {368, 29, 391, 51}, {391, 29, 414, 51},
630 {414, 29, 437, 51}, {437, 29, 460, 51}, {460, 29, 483, 51},
631 {483, 29, 506, 51}, {506, 29, 529, 51}, {529, 29, 552, 51},
632 {552, 29, 575, 51}, {575, 29, 598, 51}, {598, 29, 621, 51},
633 {621, 29, 644, 51}, {644, 29, 667, 51}, { 0, 51, 23, 73},
634 { 23, 51, 46, 73}, { 46, 51, 69, 73}, { 69, 51, 92, 73},
635 { 92, 51, 115, 73}, {115, 51, 138, 73}, {138, 51, 161, 73},
637 { {0, 0, 48, 226}, {23, 140}, 7, {
638 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 94, 24},
639 { 94, 2, 117, 24}, {117, 2, 140, 24}, {140, 2, 163, 24},
642 { {0, 0, 92, 226}, {23, 140}, 7, {
643 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 24, 92, 32},
644 { 0, 32, 23, 54}, { 23, 32, 46, 54}, { 46, 32, 69, 54},
647 { {0, 0, 672, 26}, {194, 30}, 7, {
648 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
649 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
652 { {0, 0, 672, 64}, {194, 30}, 7, {
653 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
654 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
657 { {0, 0, 672, 64}, {194, 30}, 7, {
658 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 62, 0, 70, 30},
659 { 70, 0, 101, 30}, {101, 0, 132, 30}, {132, 0, 163, 30},
662 { {0, 0, 124, 226}, {31, 188}, 7, {
663 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 0, 30, 124, 38},
664 { 0, 38, 31, 68}, { 31, 38, 62, 68}, { 62, 38, 93, 68},
667 { {0, 0, 672, 26}, {146, 22}, 7, {
668 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
669 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
672 { {0, 0, 672, 26}, {146, 100}, 7, {
673 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
674 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
677 { {0, 0, 672, 26}, {215, 100}, 10, {
678 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
679 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
680 {123, 0, 146, 100}, {146, 0, 169, 100}, {169, 0, 192, 100},
683 { {0, 0, 672, 26}, {238, 39}, 11, {
684 { 0, 0, 23, 39}, { 23, 0, 46, 39}, { 46, 0, 54, 39},
685 { 54, 0, 77, 39}, { 77, 0, 100, 39}, {100, 0, 123, 39},
686 {123, 0, 146, 39}, {146, 0, 169, 39}, {169, 0, 192, 39},
687 {192, 0, 215, 39}, {215, 0, 238, 39},
689 { {0, 0, 672, 26}, {238, 22}, 11, {
690 { 0, 0, 23, 22}, { 23, 0, 46, 22}, { 46, 0, 54, 22},
691 { 54, 0, 77, 22}, { 77, 0, 100, 22}, {100, 0, 123, 22},
692 {123, 0, 146, 22}, {146, 0, 169, 22}, {169, 0, 192, 22},
693 {192, 0, 215, 22}, {215, 0, 238, 22},
695 { {0, 0, 672, 26}, {489, 39}, 3, {
696 { 0, 2, 163, 41}, {163, 2, 330, 41}, {330, 2, 493, 41},
700 static int tbsize_numtests
= 0;
702 #define check_sizes_todo(todomask) { \
704 int buttonCount, i, mask=(todomask); \
705 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
706 assert(tbsize_numtests < sizeof(tbsize_results)/sizeof(tbsize_results[0])); \
707 GetClientRect(hToolbar, &rc); \
708 /*check_rect("client", rc, res->rcClient);*/ \
709 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
710 compare(buttonCount, res->nButtons, "%d"); \
711 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
712 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
714 check_rect("button", rc, res->rcButtons[i]); \
716 todo_wine { check_rect("button", rc, res->rcButtons[i]); } \
723 #define check_sizes() check_sizes_todo(0)
727 static TBBUTTON buttons1
[] = {
728 {0, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
, 0, {0, }, 0, -1},
729 {0, 11, 0, 0, {0, }, 0, -1},
731 static TBBUTTON buttons2
[] = {
732 {0, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
733 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
735 static TBBUTTON buttons3
[] = {
736 {0, 30, TBSTATE_ENABLED
, 0, {0, }, 0, 0},
737 {0, 31, TBSTATE_ENABLED
, 0, {0, }, 0, 1},
738 {0, 32, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, 1},
739 {0, 33, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)"Tst"}
742 static void test_sizes(void)
744 HWND hToolbar
= NULL
;
748 rebuild_toolbar_with_buttons(&hToolbar
);
749 style
= GetWindowLong(hToolbar
, GWL_STYLE
);
750 ok(style
== (WS_CHILD
|WS_VISIBLE
|CCS_TOP
), "Invalid style %x\n", style
);
752 /* the TBSTATE_WRAP makes a second row */
753 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
755 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
757 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
758 SetWindowLong(hToolbar
, GWL_STYLE
, style
|TBSTYLE_WRAPABLE
);
760 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
761 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
763 /* only after adding enough buttons the bar will be wrapped on a
764 * separator and then on the first button */
766 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
767 check_sizes_todo(0x4);
769 rebuild_toolbar_with_buttons(&hToolbar
);
770 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
771 /* setting the buttons vertical will only change the window client size */
772 SetWindowLong(hToolbar
, GWL_STYLE
, style
| CCS_VERT
);
773 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
774 check_sizes_todo(0x3c);
775 /* with a TBSTYLE_WRAPABLE a wrapping will occure on the separator */
776 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
| CCS_VERT
);
777 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
778 check_sizes_todo(0x7c);
780 rebuild_toolbar_with_buttons(&hToolbar
);
781 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
782 /* a TB_SETBITMAPSIZE changes button sizes*/
783 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
786 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
787 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
788 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
790 /* but after a TB_SETBITMAPSIZE the top margins is changed */
791 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20));
792 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
794 /* some vertical toolbar sizes */
795 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| CCS_VERT
);
796 check_sizes_todo(0x7c);
798 rebuild_toolbar_with_buttons(&hToolbar
);
799 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
800 /* newly added buttons will be use the previous margin */
801 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
803 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
804 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
805 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
806 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
807 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
808 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
809 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
810 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
811 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
812 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
814 /* add some buttons with non-default sizes */
815 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
816 SendMessageA(hToolbar
, TB_INSERTBUTTON
, -1, (LPARAM
)&buttons2
[0]);
818 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
819 /* TB_ADDSTRING resets the size */
820 SendMessageA(hToolbar
, TB_ADDSTRING
, 0, (LPARAM
)"A\0MMMMMMMMMMMMM\0");
821 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
823 /* TB_SETBUTTONSIZE can be used to crop the text */
824 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
825 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
827 /* except for the first size, the default size is bitmap size + padding */
828 SendMessageA(hToolbar
, TB_SETPADDING
, 0, MAKELONG(1, 1));
829 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
830 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n");
831 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(3, 3));
832 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
833 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n");
835 rebuild_toolbar(&hToolbar
);
836 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
837 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
838 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 15));
839 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
841 rebuild_toolbar(&hToolbar
);
842 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"A\0MMMMMMMMMMMMM\0");
843 /* the height is increased after a TB_ADDSTRING */
844 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
845 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
846 /* if a string is in the pool, even adding a button without a string resets the size */
847 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]);
848 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
849 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
850 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
851 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]);
852 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
853 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
855 /* delete button doesn't change the buttons size */
856 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 2, 0);
857 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
858 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
859 /* TB_INSERTBUTTONS will */
860 SendMessageA(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons2
[0]);
861 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
863 rebuild_toolbar(&hToolbar
);
864 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]);
865 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
866 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 0, 0);
867 ok(SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
869 DestroyWindow(hToolbar
);
878 InitCommonControls();
880 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
883 wc
.hInstance
= GetModuleHandleA(NULL
);
885 wc
.hCursor
= LoadCursorA(NULL
, MAKEINTRESOURCEA(IDC_IBEAM
));
886 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
887 wc
.lpszMenuName
= NULL
;
888 wc
.lpszClassName
= "MyTestWnd";
889 wc
.lpfnWndProc
= MyWndProc
;
892 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
893 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
894 GetClientRect(hMainWnd
, &rc
);
895 ShowWindow(hMainWnd
, SW_SHOW
);
904 while(GetMessageA(&msg
,0,0,0)) {
905 TranslateMessage(&msg
);
906 DispatchMessageA(&msg
);
908 DestroyWindow(hMainWnd
);