[COMCTL32_WINETEST] Sync with Wine Staging 1.7.47. CORE-9924
[reactos.git] / rostests / winetests / comctl32 / toolbar.c
1 /* Unit tests for toolbar.
2 *
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Mikolaj Zalewski
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "commctrl.h"
30
31 #include "resources.h"
32
33 #include "wine/test.h"
34
35 #include "msg.h"
36
37 #define PARENT_SEQ_INDEX 0
38 #define NUM_MSG_SEQUENCES 1
39
40 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
41
42 static HWND hMainWnd;
43 static BOOL g_fBlockHotItemChange;
44 static BOOL g_fReceivedHotItemChange;
45 static BOOL g_fExpectedHotItemOld;
46 static BOOL g_fExpectedHotItemNew;
47 static DWORD g_dwExpectedDispInfoMask;
48 static BOOL g_ResetDispTextPtr;
49
50 static const struct message ttgetdispinfo_parent_seq[] = {
51 { WM_NOTIFY, sent|id, 0, 0, TBN_GETINFOTIPA },
52 /* next line is todo, currently TTN_GETDISPINFOW is raised here */
53 { WM_NOTIFY, sent|id, 0, 0, TTN_GETDISPINFOA },
54 { 0 }
55 };
56
57 static const struct message save_parent_seq[] = {
58 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, -1 },
59 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 0 },
60 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 1 },
61 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 2 },
62 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 3 },
63 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 4 },
64 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 5 },
65 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_SAVE, 6 },
66 { 0 }
67 };
68
69 static const struct message restore_parent_seq[] = {
70 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, -1 },
71 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 0 },
72 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 1 },
73 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 2 },
74 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 3 },
75 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 4 },
76 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 5 },
77 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 6 },
78 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 7 },
79 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 8 },
80 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 9 },
81 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_RESTORE, 0xa },
82 { WM_NOTIFY, sent|id, 0, 0, TBN_BEGINADJUST },
83 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_GETBUTTONINFOA, 0 },
84 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_GETBUTTONINFOA, 1 },
85 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_GETBUTTONINFOA, 2 },
86 { WM_NOTIFY, sent|id|custdraw, 0, 0, TBN_GETBUTTONINFOA, 3 },
87 { WM_NOTIFY, sent|id, 0, 0, TBN_ENDADJUST },
88 { 0 }
89 };
90
91 #define DEFINE_EXPECT(func) \
92 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
93
94 #define CHECK_EXPECT2(func) \
95 do { \
96 ok(expect_ ##func, "unexpected call " #func "\n"); \
97 called_ ## func = TRUE; \
98 }while(0)
99
100 #define CHECK_CALLED(func) \
101 do { \
102 ok(called_ ## func, "expected " #func "\n"); \
103 expect_ ## func = called_ ## func = FALSE; \
104 }while(0)
105
106 #define SET_EXPECT(func) \
107 expect_ ## func = TRUE
108
109 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
110
111 #define check_rect(name, val, exp, ...) ok(val.top == exp.top && val.bottom == exp.bottom && \
112 val.left == exp.left && val.right == exp.right, "invalid rect (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d) - (" name ")\n", \
113 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom, __VA_ARGS__);
114
115 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
116
117 #define check_button_size(handle, width, height, ...) {\
118 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
119 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
120 }
121
122 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
123 p->iBitmap = -2;
124 p->idCommand = idCommand;
125 p->fsState = TBSTATE_ENABLED;
126 p->fsStyle = fsStyle;
127 p->iString = nString;
128 }
129
130 static void *alloced_str;
131
132 static LRESULT parent_wnd_notify(LPARAM lParam)
133 {
134 NMHDR *hdr = (NMHDR *)lParam;
135 NMTBHOTITEM *nmhi;
136 NMTBDISPINFOA *nmdisp;
137 switch (hdr->code)
138 {
139 case TBN_HOTITEMCHANGE:
140 nmhi = (NMTBHOTITEM *)lParam;
141 g_fReceivedHotItemChange = TRUE;
142 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
143 {
144 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
145 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
146 }
147 if (g_fBlockHotItemChange)
148 return 1;
149 break;
150
151 case TBN_GETDISPINFOA:
152 ok(FALSE, "TBN_GETDISPINFOA received\n");
153 break;
154
155 case TBN_GETINFOTIPA:
156 {
157 NMTBGETINFOTIPA *tbgit = (NMTBGETINFOTIPA*)lParam;
158
159 if (g_ResetDispTextPtr)
160 {
161 tbgit->pszText = NULL;
162 return 0;
163 }
164 break;
165 }
166 case TBN_GETDISPINFOW:
167 nmdisp = (NMTBDISPINFOA *)lParam;
168
169 compare(nmdisp->dwMask, g_dwExpectedDispInfoMask, "%x");
170 ok(nmdisp->pszText == NULL, "pszText is not NULL\n");
171 break;
172 case TBN_SAVE:
173 {
174 NMTBSAVE *save = (NMTBSAVE *)lParam;
175 if (save->iItem == -1)
176 {
177 save->cbData = save->cbData * 2 + 11 * sizeof(DWORD);
178 save->pData = HeapAlloc( GetProcessHeap(), 0, save->cbData );
179 save->pData[0] = 0xcafe;
180 save->pCurrent = save->pData + 1;
181 }
182 else
183 {
184 save->pCurrent[0] = 0xcafe0000 + save->iItem;
185 save->pCurrent++;
186 }
187
188 /* Add on 5 more pseudo buttons. */
189 if (save->iItem == save->cButtons - 1)
190 {
191 save->pCurrent[0] = 0xffffffff;
192 save->pCurrent[1] = 0xcafe0007;
193 save->pCurrent[2] = 0xfffffffe;
194 save->pCurrent[3] = 0xcafe0008;
195 save->pCurrent[4] = 0x80000000;
196 save->pCurrent[5] = 0xcafe0009;
197 save->pCurrent[6] = 0x7fffffff;
198 save->pCurrent[7] = 0xcafe000a;
199 save->pCurrent[8] = 0x100;
200 save->pCurrent[9] = 0xcafe000b;
201 }
202
203 /* Return value is ignored */
204 return 1;
205 }
206 case TBN_RESTORE:
207 {
208 NMTBRESTORE *restore = (NMTBRESTORE *)lParam;
209
210 if (restore->iItem == -1)
211 {
212 ok( restore->cButtons == 25, "got %d\n", restore->cButtons );
213 ok( *restore->pCurrent == 0xcafe, "got %08x\n", *restore->pCurrent );
214 /* Skip the last one */
215 restore->cButtons = 11;
216 restore->pCurrent++;
217 /* BytesPerRecord is ignored */
218 restore->cbBytesPerRecord = 10;
219 }
220 else
221 {
222 ok( *restore->pCurrent == 0xcafe0000 + restore->iItem, "got %08x\n", *restore->pCurrent );
223 if (restore->iItem < 7 || restore->iItem == 10)
224 {
225 ok( restore->tbButton.iBitmap == -1, "got %08x\n", restore->tbButton.iBitmap );
226 if (restore->iItem < 7)
227 ok( restore->tbButton.idCommand == restore->iItem * 2 + 1, "%d: got %08x\n", restore->iItem, restore->tbButton.idCommand );
228 else
229 ok( restore->tbButton.idCommand == 0x7fffffff, "%d: got %08x\n", restore->iItem, restore->tbButton.idCommand );
230 ok( restore->tbButton.fsState == 0, "%d: got %02x\n", restore->iItem, restore->tbButton.fsState );
231 ok( restore->tbButton.fsStyle == 0, "%d: got %02x\n", restore->iItem, restore->tbButton.fsStyle );
232 }
233 else
234 {
235 ok( restore->tbButton.iBitmap == 8, "got %08x\n", restore->tbButton.iBitmap );
236 ok( restore->tbButton.idCommand == 0, "%d: got %08x\n", restore->iItem, restore->tbButton.idCommand );
237 if (restore->iItem == 7)
238 ok( restore->tbButton.fsState == 0, "%d: got %02x\n", restore->iItem, restore->tbButton.fsState );
239 else
240 ok( restore->tbButton.fsState == TBSTATE_HIDDEN, "%d: got %02x\n", restore->iItem, restore->tbButton.fsState );
241 ok( restore->tbButton.fsStyle == BTNS_SEP, "%d: got %02x\n", restore->iItem, restore->tbButton.fsStyle );
242 }
243
244 ok( restore->tbButton.dwData == 0, "got %08lx\n", restore->tbButton.dwData );
245 ok( restore->tbButton.iString == 0, "got %08lx\n", restore->tbButton.iString );
246
247 restore->tbButton.iBitmap = 0;
248 restore->tbButton.fsState = TBSTATE_ENABLED;
249 restore->tbButton.fsStyle = 0;
250 restore->tbButton.dwData = restore->iItem;
251
252 if (restore->iItem == 0)
253 {
254 restore->tbButton.iString = (INT_PTR)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 8 );
255 strcpy( (char *)restore->tbButton.iString, "foo" );
256 }
257 else if (restore->iItem == 1)
258 restore->tbButton.iString = 2;
259 else
260 restore->tbButton.iString = -1;
261
262 restore->pCurrent++;
263 /* Altering cButtons after the 1st call makes no difference. */
264 restore->cButtons--;
265 }
266
267 /* Returning non-zero from the 1st call aborts the restore,
268 otherwise the return value is ignored. */
269 if (restore->iItem == -1) return 0;
270 return 1;
271 }
272 case TBN_GETBUTTONINFOA:
273 {
274 NMTOOLBARA *tb = (NMTOOLBARA *)lParam;
275 tb->tbButton.iBitmap = 0;
276 tb->tbButton.fsState = 0;
277 tb->tbButton.fsStyle = 0;
278 tb->tbButton.dwData = 0;
279 ok( tb->cchText == 128, "got %d\n", tb->cchText );
280 switch (tb->iItem)
281 {
282 case 0:
283 tb->tbButton.idCommand = 7;
284 alloced_str = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 8 );
285 strcpy( alloced_str, "foo" );
286 tb->tbButton.iString = (INT_PTR)alloced_str;
287 return 1;
288 case 1:
289 tb->tbButton.idCommand = 9;
290 tb->tbButton.iString = 0;
291 /* tb->pszText is ignored */
292 strcpy( tb->pszText, "foo" );
293 return 1;
294 case 2:
295 tb->tbButton.idCommand = 11;
296 tb->tbButton.iString = 3;
297 return 1;
298 }
299 return 0;
300 }
301 }
302 return 0;
303 }
304
305 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
306 {
307 static LONG defwndproc_counter = 0;
308 struct message msg;
309 LRESULT ret;
310
311 msg.message = message;
312 msg.flags = sent|wparam|lparam;
313 if (defwndproc_counter) msg.flags |= defwinproc;
314 msg.wParam = wParam;
315 msg.lParam = lParam;
316 if (message == WM_NOTIFY && lParam)
317 {
318 msg.id = ((NMHDR*)lParam)->code;
319 switch (msg.id)
320 {
321 case TBN_SAVE:
322 {
323 NMTBSAVE *save = (NMTBSAVE *)lParam;
324 msg.stage = save->iItem;
325 }
326 break;
327 case TBN_RESTORE:
328 {
329 NMTBRESTORE *restore = (NMTBRESTORE *)lParam;
330 msg.stage = restore->iItem;
331 }
332 break;
333 case TBN_GETBUTTONINFOA:
334 {
335 NMTOOLBARA *tb = (NMTOOLBARA *)lParam;
336 msg.stage = tb->iItem;
337 }
338 break;
339 }
340 }
341
342 /* log system messages, except for painting */
343 if (message < WM_USER &&
344 message != WM_PAINT &&
345 message != WM_ERASEBKGND &&
346 message != WM_NCPAINT &&
347 message != WM_NCHITTEST &&
348 message != WM_GETTEXT &&
349 message != WM_GETICON &&
350 message != WM_DEVICECHANGE)
351 {
352 add_message(sequences, PARENT_SEQ_INDEX, &msg);
353 }
354
355 switch (message)
356 {
357 case WM_NOTIFY:
358 return parent_wnd_notify(lParam);
359 }
360
361 defwndproc_counter++;
362 ret = DefWindowProcA(hWnd, message, wParam, lParam);
363 defwndproc_counter--;
364
365 return ret;
366 }
367
368 static void basic_test(void)
369 {
370 TBBUTTON buttons[9];
371 HWND hToolbar;
372 int i;
373
374 for (i=0; i<9; i++)
375 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
376 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
377 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
378
379 hToolbar = CreateToolbarEx(hMainWnd,
380 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
381 WS_CHILD | TBSTYLE_LIST,
382 100,
383 0, NULL, 0,
384 buttons, sizeof(buttons)/sizeof(buttons[0]),
385 0, 0, 20, 16, sizeof(TBBUTTON));
386 ok(hToolbar != NULL, "Toolbar creation\n");
387 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
388
389 /* test for exclusion working inside a separator-separated :-) group */
390 SendMessageA(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
391 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
392 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
393
394 SendMessageA(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
395 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
396 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
397
398 SendMessageA(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
399 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
400 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
401
402 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
403 SendMessageA(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
404 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
405 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
406 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
407
408 SendMessageA(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
409 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
410 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
411 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
412
413 SendMessageA(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
414 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
415 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
416 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
417 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
418
419 /* tests with invalid index */
420 compare(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 0xdeadbeef, 0), -1L, "%ld");
421 compare(SendMessageA(hToolbar, TB_ISBUTTONPRESSED, 0xdeadbeef, 0), -1L, "%ld");
422 compare(SendMessageA(hToolbar, TB_ISBUTTONENABLED, 0xdeadbeef, 0), -1L, "%ld");
423 compare(SendMessageA(hToolbar, TB_ISBUTTONINDETERMINATE, 0xdeadbeef, 0), -1L, "%ld");
424 compare(SendMessageA(hToolbar, TB_ISBUTTONHIGHLIGHTED, 0xdeadbeef, 0), -1L, "%ld");
425 compare(SendMessageA(hToolbar, TB_ISBUTTONHIDDEN, 0xdeadbeef, 0), -1L, "%ld");
426
427 DestroyWindow(hToolbar);
428 }
429
430 static void rebuild_toolbar(HWND *hToolbar)
431 {
432 if (*hToolbar)
433 DestroyWindow(*hToolbar);
434 *hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
435 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
436 ok(*hToolbar != NULL, "Toolbar creation problem\n");
437 ok(SendMessageA(*hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
438 ok(SendMessageA(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
439 ok(SendMessageA(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
440 }
441
442 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
443 {
444 TBBUTTON buttons[5];
445 rebuild_toolbar(hToolbar);
446
447 ZeroMemory(&buttons, sizeof(buttons));
448 buttons[0].idCommand = 1;
449 buttons[0].fsStyle = BTNS_BUTTON;
450 buttons[0].fsState = TBSTATE_ENABLED;
451 buttons[0].iString = -1;
452 buttons[1].idCommand = 3;
453 buttons[1].fsStyle = BTNS_BUTTON;
454 buttons[1].fsState = TBSTATE_ENABLED;
455 buttons[1].iString = -1;
456 buttons[2].idCommand = 5;
457 buttons[2].fsStyle = BTNS_SEP;
458 buttons[2].fsState = TBSTATE_ENABLED;
459 buttons[2].iString = -1;
460 buttons[3].idCommand = 7;
461 buttons[3].fsStyle = BTNS_BUTTON;
462 buttons[3].fsState = TBSTATE_ENABLED;
463 buttons[3].iString = -1;
464 buttons[4].idCommand = 9;
465 buttons[4].fsStyle = BTNS_BUTTON;
466 buttons[4].fsState = 0; /* disabled */
467 buttons[4].iString = -1;
468 ok(SendMessageA(*hToolbar, TB_ADDBUTTONSA, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONSA failed\n");
469 ok(SendMessageA(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
470 }
471
472 static void add_128x15_bitmap(HWND hToolbar, int nCmds)
473 {
474 TBADDBITMAP bmp128;
475 bmp128.hInst = GetModuleHandleA(NULL);
476 bmp128.nID = IDB_BITMAP_128x15;
477 ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
478 }
479
480 #define CHECK_IMAGELIST(count, dx, dy) { \
481 int cx, cy; \
482 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
483 ok(himl != NULL, "No image list\n"); \
484 if (himl != NULL) {\
485 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
486 ImageList_GetIconSize(himl, &cx, &cy); \
487 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
488 } \
489 }
490
491 static void test_add_bitmap(void)
492 {
493 HWND hToolbar = NULL;
494 TBADDBITMAP bmp128;
495 TBADDBITMAP bmp80;
496 TBADDBITMAP stdsmall;
497 TBADDBITMAP addbmp;
498 HIMAGELIST himl;
499 INT ret;
500
501 /* empty 128x15 bitmap */
502 bmp128.hInst = GetModuleHandleA(NULL);
503 bmp128.nID = IDB_BITMAP_128x15;
504
505 /* empty 80x15 bitmap */
506 bmp80.hInst = GetModuleHandleA(NULL);
507 bmp80.nID = IDB_BITMAP_80x15;
508
509 /* standard bitmap - 240x15 pixels */
510 stdsmall.hInst = HINST_COMMCTRL;
511 stdsmall.nID = IDB_STD_SMALL_COLOR;
512
513 rebuild_toolbar(&hToolbar);
514 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
515 CHECK_IMAGELIST(8, 16, 16);
516
517 /* adding more bitmaps */
518 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
519 CHECK_IMAGELIST(13, 16, 16);
520 /* adding the same bitmap will simply return the index of the already loaded block */
521 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
522 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
523 CHECK_IMAGELIST(13, 16, 16);
524 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
525 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
526 CHECK_IMAGELIST(13, 16, 16);
527 /* even if we increase the wParam */
528 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
529 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
530 CHECK_IMAGELIST(13, 16, 16);
531
532 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
533 rebuild_toolbar(&hToolbar);
534 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
535 CHECK_IMAGELIST(8, 16, 16);
536 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
537 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
538 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
539 CHECK_IMAGELIST(13, 16, 16);
540
541 /* the same for negative wParam */
542 rebuild_toolbar(&hToolbar);
543 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
544 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
545 CHECK_IMAGELIST(8, 16, 16);
546 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
547 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
548 CHECK_IMAGELIST(13, 16, 16);
549
550 /* for zero only one bitmap will be added */
551 rebuild_toolbar(&hToolbar);
552 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
553 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
554 CHECK_IMAGELIST(1, 16, 16);
555
556 /* if wParam is larger than the amount of icons, the list is grown */
557 rebuild_toolbar(&hToolbar);
558 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
559 CHECK_IMAGELIST(100, 16, 16);
560 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
561 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
562 CHECK_IMAGELIST(200, 16, 16);
563
564 /* adding built-in items - the wParam is ignored */
565 rebuild_toolbar(&hToolbar);
566 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
567 CHECK_IMAGELIST(5, 16, 16);
568 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
569 CHECK_IMAGELIST(20, 16, 16);
570 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
571 CHECK_IMAGELIST(28, 16, 16);
572
573 /* when we increase the bitmap size, less icons will be created */
574 rebuild_toolbar(&hToolbar);
575 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
576 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
577 CHECK_IMAGELIST(6, 20, 20);
578 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
579 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
580 CHECK_IMAGELIST(10, 20, 20);
581 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
582 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
583 UpdateWindow(hToolbar);
584 CHECK_IMAGELIST(26, 8, 8);
585 /* loading a standard bitmaps automatically resizes the icons */
586 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
587 UpdateWindow(hToolbar);
588 CHECK_IMAGELIST(28, 16, 16);
589
590 /* two more SETBITMAPSIZE tests */
591 rebuild_toolbar(&hToolbar);
592 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
593 CHECK_IMAGELIST(100, 16, 16);
594 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
595 CHECK_IMAGELIST(200, 16, 16);
596 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
597 UpdateWindow(hToolbar);
598 CHECK_IMAGELIST(200, 8, 8);
599 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
600 UpdateWindow(hToolbar);
601 CHECK_IMAGELIST(200, 30, 30);
602 rebuild_toolbar(&hToolbar);
603 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
604 CHECK_IMAGELIST(8, 16, 16);
605 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
606 CHECK_IMAGELIST(13, 16, 16);
607 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
608 UpdateWindow(hToolbar);
609 CHECK_IMAGELIST(8, 30, 30);
610 /* when the width or height is zero, set it to 1 */
611 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
612 UpdateWindow(hToolbar);
613 CHECK_IMAGELIST(208, 1, 1);
614 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
615 UpdateWindow(hToolbar);
616 CHECK_IMAGELIST(208, 1, 5);
617 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
618 UpdateWindow(hToolbar);
619 CHECK_IMAGELIST(41, 5, 1);
620
621 /* the control can add bitmaps to an existing image list */
622 rebuild_toolbar(&hToolbar);
623 himl = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_80x15),
624 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
625 ok(himl != NULL, "failed to create imagelist\n");
626 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
627 CHECK_IMAGELIST(4, 20, 15);
628 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
629 CHECK_IMAGELIST(10, 20, 15);
630 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
631 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
632 UpdateWindow(hToolbar);
633 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(15, 14), "%x");
634 CHECK_IMAGELIST(10, 20, 15);
635 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
636 UpdateWindow(hToolbar);
637 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
638 CHECK_IMAGELIST(22, 20, 15);
639
640 /* check standard bitmaps */
641 addbmp.hInst = HINST_COMMCTRL;
642 addbmp.nID = IDB_STD_SMALL_COLOR;
643 rebuild_toolbar(&hToolbar);
644 ImageList_Destroy(himl);
645
646 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
647 CHECK_IMAGELIST(15, 16, 16);
648 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
649 addbmp.nID = IDB_STD_LARGE_COLOR;
650 rebuild_toolbar(&hToolbar);
651 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
652 CHECK_IMAGELIST(15, 24, 24);
653 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(31, 30), "%x");
654
655 addbmp.nID = IDB_VIEW_SMALL_COLOR;
656 rebuild_toolbar(&hToolbar);
657 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
658 CHECK_IMAGELIST(12, 16, 16);
659 addbmp.nID = IDB_VIEW_LARGE_COLOR;
660 rebuild_toolbar(&hToolbar);
661 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
662 CHECK_IMAGELIST(12, 24, 24);
663
664 addbmp.nID = IDB_HIST_SMALL_COLOR;
665 rebuild_toolbar(&hToolbar);
666 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
667 CHECK_IMAGELIST(5, 16, 16);
668 addbmp.nID = IDB_HIST_LARGE_COLOR;
669 rebuild_toolbar(&hToolbar);
670 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
671 CHECK_IMAGELIST(5, 24, 24);
672
673
674 DestroyWindow(hToolbar);
675 }
676
677 #define CHECK_STRING_TABLE(count, tab) { \
678 INT _i; \
679 CHAR _buf[260]; \
680 for (_i = 0; _i < (count); _i++) {\
681 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, _i), (LPARAM)_buf); \
682 ok(ret >= 0, "TB_GETSTRINGA - unexpected return %d while checking string %d\n", ret, _i); \
683 if (ret >= 0) \
684 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
685 } \
686 ok(SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
687 "Too many strings in table\n"); \
688 }
689
690 static void test_add_string(void)
691 {
692 LPCSTR test1 = "a\0b\0";
693 LPCSTR test2 = "|a|b||\0";
694 LPCSTR ret1[] = {"a", "b"};
695 LPCSTR ret2[] = {"a", "b", "|a|b||"};
696 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
697 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
698 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
699 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
700 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
701 HWND hToolbar = NULL;
702 TBBUTTON button;
703 int ret;
704 CHAR buf[260];
705
706 rebuild_toolbar(&hToolbar);
707 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
708 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
709 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, 1), (LPARAM)buf);
710 if (ret == 0)
711 {
712 win_skip("TB_GETSTRINGA needs 5.80\n");
713 return;
714 }
715 CHECK_STRING_TABLE(2, ret1);
716 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
717 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
718 CHECK_STRING_TABLE(3, ret2);
719
720 /* null instance handle */
721 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, IDS_TBADD1);
722 ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
723
724 /* invalid instance handle */
725 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0xdeadbeef, IDS_TBADD1);
726 ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
727
728 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD1);
729 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
730 CHECK_STRING_TABLE(3, ret2);
731 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD2);
732 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
733 CHECK_STRING_TABLE(5, ret3);
734 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD3);
735 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
736 CHECK_STRING_TABLE(6, ret4);
737 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD4);
738 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
739 CHECK_STRING_TABLE(8, ret5);
740 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD5);
741 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
742 CHECK_STRING_TABLE(11, ret6);
743 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD7);
744 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
745 CHECK_STRING_TABLE(14, ret7);
746
747 ZeroMemory(&button, sizeof(button));
748 button.iString = (UINT_PTR)"Test";
749 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
750 CHECK_STRING_TABLE(14, ret7);
751 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
752 CHECK_STRING_TABLE(14, ret7);
753
754 DestroyWindow(hToolbar);
755 }
756
757 static void expect_hot_notify(int idold, int idnew)
758 {
759 g_fExpectedHotItemOld = idold;
760 g_fExpectedHotItemNew = idnew;
761 g_fReceivedHotItemChange = FALSE;
762 }
763
764 #define check_hot_notify() \
765 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
766 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
767
768 static void test_hotitem(void)
769 {
770 HWND hToolbar = NULL;
771 TBBUTTONINFOA tbinfo;
772 LRESULT ret;
773
774 g_fBlockHotItemChange = FALSE;
775
776 rebuild_toolbar_with_buttons(&hToolbar);
777 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
778 * comctl6 doesn't have this requirement even when theme == NULL */
779 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLongA(hToolbar, GWL_STYLE));
780 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
781 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
782 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 1, 0);
783 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
784 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
785 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
786 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 2, 0);
787 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
788
789 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
790 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
791 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
792 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
793 ret = SendMessageA(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
794 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
795 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
796 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
797
798 expect_hot_notify(0, 7);
799 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
800 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
801 check_hot_notify();
802 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
803 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
804 g_fBlockHotItemChange = TRUE;
805 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 2, 0);
806 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
807 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
808 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
809 g_fBlockHotItemChange = FALSE;
810
811 g_fReceivedHotItemChange = FALSE;
812 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
813 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
814 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
815
816 g_fReceivedHotItemChange = FALSE;
817 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
818 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
819 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
820
821 expect_hot_notify(7, 0);
822 ret = SendMessageA(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
823 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
824 check_hot_notify();
825 SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
826
827 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
828 expect_hot_notify(7, 9);
829 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 4, 0);
830 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
831 check_hot_notify();
832 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
833 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
834 /* enabling the button won't change that */
835 SendMessageA(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
836 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
837 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
838
839 /* disabling a hot button works */
840 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
841 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
842 g_fReceivedHotItemChange = FALSE;
843 SendMessageA(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
844 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
845 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
846 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
847
848 SendMessageA(hToolbar, TB_SETHOTITEM, 1, 0);
849 tbinfo.cbSize = sizeof(TBBUTTONINFOA);
850 tbinfo.dwMask = TBIF_STATE;
851 tbinfo.fsState = 0; /* disabled */
852 g_fReceivedHotItemChange = FALSE;
853 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFOA failed\n");
854 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
855 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
856 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
857
858 DestroyWindow(hToolbar);
859 }
860
861 #if 0 /* use this to generate more tests*/
862
863 static void dump_sizes(HWND hToolbar)
864 {
865 SIZE sz;
866 RECT r;
867 int count = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0);
868 int i;
869
870 GetClientRect(hToolbar, &r);
871 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
872 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
873 sz.cx, sz.cy, count);
874 for (i=0; i<count; i++)
875 {
876 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
877 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
878 }
879 printf("\n }, },\n");
880 }
881
882 #define check_sizes() dump_sizes(hToolbar);
883 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
884
885 #else
886
887 static int system_font_height(void) {
888 HDC hDC;
889 TEXTMETRICA tm;
890
891 hDC = CreateCompatibleDC(NULL);
892 GetTextMetricsA(hDC, &tm);
893 DeleteDC(NULL);
894
895 return tm.tmHeight;
896 }
897
898 static int string_width(const CHAR *s) {
899 SIZE sz;
900 HDC hdc;
901
902 hdc = CreateCompatibleDC(NULL);
903 GetTextExtentPoint32A(hdc, s, strlen(s), &sz);
904 DeleteDC(hdc);
905
906 return sz.cx;
907 }
908
909 typedef struct
910 {
911 RECT rcClient;
912 SIZE szMin;
913 INT nButtons;
914 RECT *prcButtons;
915 } tbsize_result_t;
916
917 static tbsize_result_t init_tbsize_result(int nButtonsAlloc, int cleft, int ctop, int cright, int cbottom, int minx, int miny) {
918 tbsize_result_t ret;
919
920 SetRect(&ret.rcClient, cleft, ctop, cright, cbottom);
921 ret.szMin.cx = minx;
922 ret.szMin.cy = miny;
923 ret.nButtons = 0;
924 ret.prcButtons = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nButtonsAlloc*sizeof(RECT));
925
926 return ret;
927 }
928
929 static void tbsize_addbutton(tbsize_result_t *tbsr, int left, int top, int right, int bottom) {
930 SetRect(&tbsr->prcButtons[tbsr->nButtons], left, top, right, bottom);
931 tbsr->nButtons++;
932 }
933
934 #define STRING0 "A"
935 #define STRING1 "MMMMMMMMMMMMM"
936 #define STRING2 "Tst"
937
938 static tbsize_result_t *tbsize_results;
939
940 #define tbsize_results_num 28
941
942 static void init_tbsize_results(void) {
943 int fontheight = system_font_height();
944 int buttonwidth;
945
946 tbsize_results = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tbsize_results_num*sizeof(tbsize_result_t));
947
948 tbsize_results[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
949 tbsize_addbutton(&tbsize_results[0], 0, 2, 23, 24);
950 tbsize_addbutton(&tbsize_results[0], 23, 2, 46, 24);
951 tbsize_addbutton(&tbsize_results[0], 46, 2, 54, 24);
952 tbsize_addbutton(&tbsize_results[0], 54, 2, 77, 24);
953 tbsize_addbutton(&tbsize_results[0], 77, 2, 100, 24);
954
955 tbsize_results[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
956 tbsize_addbutton(&tbsize_results[1], 0, 2, 23, 24);
957 tbsize_addbutton(&tbsize_results[1], 23, 2, 46, 24);
958 tbsize_addbutton(&tbsize_results[1], 46, 2, 54, 24);
959 tbsize_addbutton(&tbsize_results[1], 54, 2, 77, 24);
960 tbsize_addbutton(&tbsize_results[1], 77, 2, 100, 24);
961 tbsize_addbutton(&tbsize_results[1], 100, 2, 123, 24);
962 tbsize_addbutton(&tbsize_results[1], 0, 24, 23, 46);
963
964 tbsize_results[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
965 tbsize_addbutton(&tbsize_results[2], 0, 2, 23, 24);
966 tbsize_addbutton(&tbsize_results[2], 23, 2, 46, 24);
967 tbsize_addbutton(&tbsize_results[2], 46, 2, 54, 24);
968 tbsize_addbutton(&tbsize_results[2], 54, 2, 77, 24);
969 tbsize_addbutton(&tbsize_results[2], 77, 2, 100, 24);
970 tbsize_addbutton(&tbsize_results[2], 100, 2, 123, 24);
971 tbsize_addbutton(&tbsize_results[2], 0, 24, 23, 46);
972
973 tbsize_results[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
974 tbsize_addbutton(&tbsize_results[3], 0, 2, 23, 24);
975 tbsize_addbutton(&tbsize_results[3], 23, 2, 46, 24);
976 tbsize_addbutton(&tbsize_results[3], 46, 2, 54, 24);
977 tbsize_addbutton(&tbsize_results[3], 54, 2, 77, 24);
978 tbsize_addbutton(&tbsize_results[3], 77, 2, 100, 24);
979 tbsize_addbutton(&tbsize_results[3], 100, 2, 123, 24);
980 tbsize_addbutton(&tbsize_results[3], 123, 2, 146, 24);
981
982 tbsize_results[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
983 tbsize_addbutton(&tbsize_results[4], 0, 2, 23, 24);
984 tbsize_addbutton(&tbsize_results[4], 23, 2, 46, 24);
985 tbsize_addbutton(&tbsize_results[4], 46, 2, 54, 24);
986 tbsize_addbutton(&tbsize_results[4], 54, 2, 77, 24);
987 tbsize_addbutton(&tbsize_results[4], 77, 2, 100, 24);
988 tbsize_addbutton(&tbsize_results[4], 100, 2, 123, 24);
989 tbsize_addbutton(&tbsize_results[4], 123, 2, 146, 24);
990 tbsize_addbutton(&tbsize_results[4], 146, 2, 169, 24);
991 tbsize_addbutton(&tbsize_results[4], 169, 2, 192, 24);
992
993 tbsize_results[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
994 tbsize_addbutton(&tbsize_results[5], 0, 2, 23, 24);
995 tbsize_addbutton(&tbsize_results[5], 23, 2, 46, 24);
996 tbsize_addbutton(&tbsize_results[5], 0, 2, 8, 29);
997 tbsize_addbutton(&tbsize_results[5], 0, 29, 23, 51);
998 tbsize_addbutton(&tbsize_results[5], 23, 29, 46, 51);
999 tbsize_addbutton(&tbsize_results[5], 46, 29, 69, 51);
1000 tbsize_addbutton(&tbsize_results[5], 69, 29, 92, 51);
1001 tbsize_addbutton(&tbsize_results[5], 92, 29, 115, 51);
1002 tbsize_addbutton(&tbsize_results[5], 115, 29, 138, 51);
1003 tbsize_addbutton(&tbsize_results[5], 138, 29, 161, 51);
1004 tbsize_addbutton(&tbsize_results[5], 161, 29, 184, 51);
1005 tbsize_addbutton(&tbsize_results[5], 184, 29, 207, 51);
1006 tbsize_addbutton(&tbsize_results[5], 207, 29, 230, 51);
1007 tbsize_addbutton(&tbsize_results[5], 230, 29, 253, 51);
1008 tbsize_addbutton(&tbsize_results[5], 253, 29, 276, 51);
1009 tbsize_addbutton(&tbsize_results[5], 276, 29, 299, 51);
1010 tbsize_addbutton(&tbsize_results[5], 299, 29, 322, 51);
1011 tbsize_addbutton(&tbsize_results[5], 322, 29, 345, 51);
1012 tbsize_addbutton(&tbsize_results[5], 345, 29, 368, 51);
1013 tbsize_addbutton(&tbsize_results[5], 368, 29, 391, 51);
1014 tbsize_addbutton(&tbsize_results[5], 391, 29, 414, 51);
1015 tbsize_addbutton(&tbsize_results[5], 414, 29, 437, 51);
1016 tbsize_addbutton(&tbsize_results[5], 437, 29, 460, 51);
1017 tbsize_addbutton(&tbsize_results[5], 460, 29, 483, 51);
1018 tbsize_addbutton(&tbsize_results[5], 483, 29, 506, 51);
1019 tbsize_addbutton(&tbsize_results[5], 506, 29, 529, 51);
1020 tbsize_addbutton(&tbsize_results[5], 529, 29, 552, 51);
1021 tbsize_addbutton(&tbsize_results[5], 552, 29, 575, 51);
1022 tbsize_addbutton(&tbsize_results[5], 575, 29, 598, 51);
1023 tbsize_addbutton(&tbsize_results[5], 598, 29, 621, 51);
1024 tbsize_addbutton(&tbsize_results[5], 621, 29, 644, 51);
1025 tbsize_addbutton(&tbsize_results[5], 644, 29, 667, 51);
1026 tbsize_addbutton(&tbsize_results[5], 0, 51, 23, 73);
1027 tbsize_addbutton(&tbsize_results[5], 23, 51, 46, 73);
1028 tbsize_addbutton(&tbsize_results[5], 46, 51, 69, 73);
1029 tbsize_addbutton(&tbsize_results[5], 69, 51, 92, 73);
1030 tbsize_addbutton(&tbsize_results[5], 92, 51, 115, 73);
1031 tbsize_addbutton(&tbsize_results[5], 115, 51, 138, 73);
1032 tbsize_addbutton(&tbsize_results[5], 138, 51, 161, 73);
1033
1034 tbsize_results[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
1035 tbsize_addbutton(&tbsize_results[6], 0, 2, 23, 24);
1036 tbsize_addbutton(&tbsize_results[6], 23, 2, 46, 24);
1037 tbsize_addbutton(&tbsize_results[6], 46, 2, 94, 24);
1038 tbsize_addbutton(&tbsize_results[6], 94, 2, 117, 24);
1039 tbsize_addbutton(&tbsize_results[6], 117, 2, 140, 24);
1040 tbsize_addbutton(&tbsize_results[6], 140, 2, 163, 24);
1041 tbsize_addbutton(&tbsize_results[6], 0, 24, 23, 46);
1042
1043 tbsize_results[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
1044 tbsize_addbutton(&tbsize_results[7], 0, 2, 23, 24);
1045 tbsize_addbutton(&tbsize_results[7], 23, 2, 46, 24);
1046 tbsize_addbutton(&tbsize_results[7], 0, 24, 92, 32);
1047 tbsize_addbutton(&tbsize_results[7], 0, 32, 23, 54);
1048 tbsize_addbutton(&tbsize_results[7], 23, 32, 46, 54);
1049 tbsize_addbutton(&tbsize_results[7], 46, 32, 69, 54);
1050 tbsize_addbutton(&tbsize_results[7], 69, 32, 92, 54);
1051
1052 tbsize_results[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
1053 tbsize_addbutton(&tbsize_results[8], 0, 2, 31, 32);
1054 tbsize_addbutton(&tbsize_results[8], 31, 2, 62, 32);
1055 tbsize_addbutton(&tbsize_results[8], 62, 2, 70, 32);
1056 tbsize_addbutton(&tbsize_results[8], 70, 2, 101, 32);
1057 tbsize_addbutton(&tbsize_results[8], 101, 2, 132, 32);
1058 tbsize_addbutton(&tbsize_results[8], 132, 2, 163, 32);
1059 tbsize_addbutton(&tbsize_results[8], 0, 32, 31, 62);
1060
1061 tbsize_results[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1062 tbsize_addbutton(&tbsize_results[9], 0, 2, 31, 32);
1063 tbsize_addbutton(&tbsize_results[9], 31, 2, 62, 32);
1064 tbsize_addbutton(&tbsize_results[9], 62, 2, 70, 32);
1065 tbsize_addbutton(&tbsize_results[9], 70, 2, 101, 32);
1066 tbsize_addbutton(&tbsize_results[9], 101, 2, 132, 32);
1067 tbsize_addbutton(&tbsize_results[9], 132, 2, 163, 32);
1068 tbsize_addbutton(&tbsize_results[9], 0, 32, 31, 62);
1069
1070 tbsize_results[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1071 tbsize_addbutton(&tbsize_results[10], 0, 0, 31, 30);
1072 tbsize_addbutton(&tbsize_results[10], 31, 0, 62, 30);
1073 tbsize_addbutton(&tbsize_results[10], 62, 0, 70, 30);
1074 tbsize_addbutton(&tbsize_results[10], 70, 0, 101, 30);
1075 tbsize_addbutton(&tbsize_results[10], 101, 0, 132, 30);
1076 tbsize_addbutton(&tbsize_results[10], 132, 0, 163, 30);
1077 tbsize_addbutton(&tbsize_results[10], 0, 30, 31, 60);
1078
1079 tbsize_results[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
1080 tbsize_addbutton(&tbsize_results[11], 0, 0, 31, 30);
1081 tbsize_addbutton(&tbsize_results[11], 31, 0, 62, 30);
1082 tbsize_addbutton(&tbsize_results[11], 0, 30, 124, 38);
1083 tbsize_addbutton(&tbsize_results[11], 0, 38, 31, 68);
1084 tbsize_addbutton(&tbsize_results[11], 31, 38, 62, 68);
1085 tbsize_addbutton(&tbsize_results[11], 62, 38, 93, 68);
1086 tbsize_addbutton(&tbsize_results[11], 93, 38, 124, 68);
1087
1088 tbsize_results[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1089 tbsize_addbutton(&tbsize_results[12], 0, 2, 23, 24);
1090 tbsize_addbutton(&tbsize_results[12], 23, 2, 46, 24);
1091 tbsize_addbutton(&tbsize_results[12], 46, 2, 54, 24);
1092 tbsize_addbutton(&tbsize_results[12], 54, 2, 77, 24);
1093 tbsize_addbutton(&tbsize_results[12], 77, 2, 100, 24);
1094 tbsize_addbutton(&tbsize_results[12], 100, 2, 123, 24);
1095 tbsize_addbutton(&tbsize_results[12], 123, 2, 146, 24);
1096
1097 tbsize_results[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
1098 tbsize_addbutton(&tbsize_results[13], 0, 0, 23, 100);
1099 tbsize_addbutton(&tbsize_results[13], 23, 0, 46, 100);
1100 tbsize_addbutton(&tbsize_results[13], 46, 0, 54, 100);
1101 tbsize_addbutton(&tbsize_results[13], 54, 0, 77, 100);
1102 tbsize_addbutton(&tbsize_results[13], 77, 0, 100, 100);
1103 tbsize_addbutton(&tbsize_results[13], 100, 0, 123, 100);
1104 tbsize_addbutton(&tbsize_results[13], 123, 0, 146, 100);
1105
1106 tbsize_results[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
1107 tbsize_addbutton(&tbsize_results[14], 0, 0, 23, 100);
1108 tbsize_addbutton(&tbsize_results[14], 23, 0, 46, 100);
1109 tbsize_addbutton(&tbsize_results[14], 46, 0, 54, 100);
1110 tbsize_addbutton(&tbsize_results[14], 54, 0, 77, 100);
1111 tbsize_addbutton(&tbsize_results[14], 77, 0, 100, 100);
1112 tbsize_addbutton(&tbsize_results[14], 100, 0, 123, 100);
1113 tbsize_addbutton(&tbsize_results[14], 123, 0, 146, 100);
1114 tbsize_addbutton(&tbsize_results[14], 146, 0, 169, 100);
1115 tbsize_addbutton(&tbsize_results[14], 169, 0, 192, 100);
1116 tbsize_addbutton(&tbsize_results[14], 192, 0, 215, 100);
1117
1118 tbsize_results[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
1119 tbsize_addbutton(&tbsize_results[15], 0, 0, 23, 23 + fontheight);
1120 tbsize_addbutton(&tbsize_results[15], 23, 0, 46, 23 + fontheight);
1121 tbsize_addbutton(&tbsize_results[15], 46, 0, 54, 23 + fontheight);
1122 tbsize_addbutton(&tbsize_results[15], 54, 0, 77, 23 + fontheight);
1123 tbsize_addbutton(&tbsize_results[15], 77, 0, 100, 23 + fontheight);
1124 tbsize_addbutton(&tbsize_results[15], 100, 0, 123, 23 + fontheight);
1125 tbsize_addbutton(&tbsize_results[15], 123, 0, 146, 23 + fontheight);
1126 tbsize_addbutton(&tbsize_results[15], 146, 0, 169, 23 + fontheight);
1127 tbsize_addbutton(&tbsize_results[15], 169, 0, 192, 23 + fontheight);
1128 tbsize_addbutton(&tbsize_results[15], 192, 0, 215, 23 + fontheight);
1129 tbsize_addbutton(&tbsize_results[15], 215, 0, 238, 23 + fontheight);
1130
1131 tbsize_results[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
1132 tbsize_addbutton(&tbsize_results[16], 0, 0, 23, 22);
1133 tbsize_addbutton(&tbsize_results[16], 23, 0, 46, 22);
1134 tbsize_addbutton(&tbsize_results[16], 46, 0, 54, 22);
1135 tbsize_addbutton(&tbsize_results[16], 54, 0, 77, 22);
1136 tbsize_addbutton(&tbsize_results[16], 77, 0, 100, 22);
1137 tbsize_addbutton(&tbsize_results[16], 100, 0, 123, 22);
1138 tbsize_addbutton(&tbsize_results[16], 123, 0, 146, 22);
1139 tbsize_addbutton(&tbsize_results[16], 146, 0, 169, 22);
1140 tbsize_addbutton(&tbsize_results[16], 169, 0, 192, 22);
1141 tbsize_addbutton(&tbsize_results[16], 192, 0, 215, 22);
1142 tbsize_addbutton(&tbsize_results[16], 215, 0, 238, 22);
1143
1144 buttonwidth = 7 + string_width(STRING1);
1145
1146 tbsize_results[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
1147 tbsize_addbutton(&tbsize_results[17], 0, 2, buttonwidth, 25 + fontheight);
1148 tbsize_addbutton(&tbsize_results[17], buttonwidth, 2, 2*buttonwidth + 4, 25 + fontheight);
1149 tbsize_addbutton(&tbsize_results[17], 2*buttonwidth + 4, 2, 3*buttonwidth + 4, 25 + fontheight);
1150
1151 tbsize_results[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
1152 tbsize_addbutton(&tbsize_results[18], 0, 2, buttonwidth, 10 + fontheight);
1153 tbsize_addbutton(&tbsize_results[18], buttonwidth, 2, 2*buttonwidth, 10 + fontheight);
1154 tbsize_addbutton(&tbsize_results[18], 2*buttonwidth, 2, 3*buttonwidth, 10 + fontheight);
1155 tbsize_addbutton(&tbsize_results[18], 3*buttonwidth, 2, 4*buttonwidth, 10 + fontheight);
1156 tbsize_addbutton(&tbsize_results[18], 4*buttonwidth, 2, 5*buttonwidth + 4, 10 + fontheight);
1157 tbsize_addbutton(&tbsize_results[18], 5*buttonwidth + 4, 2, 5*buttonwidth + 4 + string_width(STRING2) + 11, 10 + fontheight);
1158
1159 tbsize_results[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
1160 tbsize_addbutton(&tbsize_results[19], 0, 0, buttonwidth, 22 + fontheight);
1161 tbsize_addbutton(&tbsize_results[19], buttonwidth, 0, 2*buttonwidth, 22 + fontheight);
1162 tbsize_addbutton(&tbsize_results[19], 2*buttonwidth, 0, 3*buttonwidth, 22 + fontheight);
1163 tbsize_addbutton(&tbsize_results[19], 3*buttonwidth, 0, 4*buttonwidth, 22 + fontheight);
1164 tbsize_addbutton(&tbsize_results[19], 4*buttonwidth, 0, 5*buttonwidth + 4, 22 + fontheight);
1165 tbsize_addbutton(&tbsize_results[19], 5*buttonwidth + 4, 0, 5*buttonwidth + 4 + string_width(STRING2) + 11, 22 + fontheight);
1166
1167 tbsize_results[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
1168 tbsize_addbutton(&tbsize_results[20], 0, 2, 100, 102);
1169 tbsize_addbutton(&tbsize_results[20], 100, 2, 139, 102);
1170 tbsize_addbutton(&tbsize_results[20], 139, 2, 239, 102);
1171
1172 tbsize_results[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
1173 tbsize_addbutton(&tbsize_results[21], 0, 2, 75, 40);
1174 tbsize_addbutton(&tbsize_results[21], 75, 2, 118, 40);
1175 tbsize_addbutton(&tbsize_results[21], 118, 2, 165 + string_width(STRING2), 40);
1176
1177 tbsize_results[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1178 tbsize_addbutton(&tbsize_results[22], 0, 2, 47 + string_width(STRING2), 40);
1179
1180 tbsize_results[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
1181 tbsize_addbutton(&tbsize_results[23], 0, 2, 672, 25 + fontheight);
1182 tbsize_addbutton(&tbsize_results[23], 0, 25 + fontheight, 672, 48 + 2*fontheight);
1183
1184 tbsize_results[24] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1185 tbsize_addbutton(&tbsize_results[24], 0, 2, 11 + string_width(STRING2), 24);
1186
1187 tbsize_results[25] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1188 tbsize_addbutton(&tbsize_results[25], 0, 2, 40, 24);
1189
1190 tbsize_results[26] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1191 tbsize_addbutton(&tbsize_results[26], 0, 2, 40, 24);
1192
1193 tbsize_results[27] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1194 tbsize_addbutton(&tbsize_results[27], 0, 2, 40, 24);
1195 }
1196
1197 static void free_tbsize_results(void) {
1198 int i;
1199
1200 for (i = 0; i < tbsize_results_num; i++)
1201 HeapFree(GetProcessHeap(), 0, tbsize_results[i].prcButtons);
1202 HeapFree(GetProcessHeap(), 0, tbsize_results);
1203 tbsize_results = NULL;
1204 }
1205
1206 static int tbsize_numtests = 0;
1207
1208 typedef struct
1209 {
1210 int test_num;
1211 int rect_index;
1212 RECT rcButton;
1213 } tbsize_alt_result_t;
1214
1215 static tbsize_alt_result_t tbsize_alt_results[] =
1216 {
1217 { 5, 2, { 0, 24, 8, 29 } },
1218 { 20, 1, { 100, 2, 107, 102 } },
1219 { 20, 2, { 107, 2, 207, 102 } }
1220 };
1221
1222 static DWORD tbsize_alt_numtests = 0;
1223
1224 #define check_sizes_todo(todomask) { \
1225 RECT rc; \
1226 int buttonCount, i, mask=(todomask); \
1227 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1228 GetClientRect(hToolbar, &rc); \
1229 /*check_rect("client", rc, res->rcClient);*/ \
1230 buttonCount = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1231 compare(buttonCount, res->nButtons, "%d"); \
1232 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1233 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1234 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1235 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
1236 win_skip("Alternate rect found\n"); \
1237 tbsize_alt_numtests++; \
1238 } else if (!(mask&1)) { \
1239 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1240 } else {\
1241 todo_wine { check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); } \
1242 } \
1243 mask >>= 1; \
1244 } \
1245 tbsize_numtests++; \
1246 }
1247
1248 #define check_sizes() check_sizes_todo(0)
1249
1250 #endif
1251
1252 static TBBUTTON buttons1[] = {
1253 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
1254 {0, 11, 0, 0, {0, }, 0, -1},
1255 };
1256 static TBBUTTON buttons2[] = {
1257 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1258 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1259 };
1260 static TBBUTTON buttons3[] = {
1261 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
1262 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
1263 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
1264 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)STRING2}
1265 };
1266 static TBBUTTON buttons4[] = {
1267 {0, 40, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)STRING2},
1268 {0, 41, TBSTATE_ENABLED, 0, {0, }, 0, (UINT_PTR)STRING2},
1269 {0, 41, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0, }, 0, (UINT_PTR)STRING2}
1270 };
1271
1272 static void test_sizes(void)
1273 {
1274 HWND hToolbar = NULL;
1275 HIMAGELIST himl, himl2;
1276 TBBUTTONINFOA tbinfo;
1277 TBBUTTON button;
1278 int style;
1279 int i;
1280 int fontheight = system_font_height();
1281
1282 init_tbsize_results();
1283
1284 rebuild_toolbar_with_buttons(&hToolbar);
1285 style = GetWindowLongA(hToolbar, GWL_STYLE);
1286 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
1287 check_sizes();
1288 /* the TBSTATE_WRAP makes a second row */
1289 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1290 check_sizes();
1291 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1292 check_sizes();
1293 SendMessageA(hToolbar, TB_GETBUTTON, 5, (LPARAM)&button);
1294 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "got %08x\n", button.fsState);
1295 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1296 SetWindowLongA(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
1297 check_sizes();
1298 SendMessageA(hToolbar, TB_GETBUTTON, 5, (LPARAM)&button);
1299 ok(button.fsState == TBSTATE_ENABLED, "got %08x\n", button.fsState);
1300 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1301 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1302 check_sizes();
1303 /* only after adding enough buttons the bar will be wrapped on a
1304 * separator and then on the first button */
1305 for (i=0; i<15; i++)
1306 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1307 check_sizes_todo(0x4);
1308 SendMessageA(hToolbar, TB_GETBUTTON, 31, (LPARAM)&button);
1309 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "got %08x\n", button.fsState);
1310 SetWindowLongA(hToolbar, GWL_STYLE, style);
1311 SendMessageA(hToolbar, TB_GETBUTTON, 31, (LPARAM)&button);
1312 ok(button.fsState == TBSTATE_ENABLED, "got %08x\n", button.fsState);
1313
1314 rebuild_toolbar_with_buttons(&hToolbar);
1315 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1316 /* setting the buttons vertical will only change the window client size */
1317 SetWindowLongA(hToolbar, GWL_STYLE, style | CCS_VERT);
1318 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1319 check_sizes_todo(0x3c);
1320 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1321 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
1322 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1323 check_sizes_todo(0x7c);
1324
1325 rebuild_toolbar_with_buttons(&hToolbar);
1326 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1327 /* a TB_SETBITMAPSIZE changes button sizes*/
1328 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1329 check_sizes();
1330
1331 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1332 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1333 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1334 check_sizes();
1335 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1336 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
1337 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1338 check_sizes();
1339 /* some vertical toolbar sizes */
1340 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
1341 check_sizes_todo(0x7c);
1342
1343 rebuild_toolbar_with_buttons(&hToolbar);
1344 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1345 /* newly added buttons will be use the previous margin */
1346 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1347 check_sizes();
1348 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1349 check_button_size(hToolbar, 23, 22);
1350 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1351 check_button_size(hToolbar, 23, 22);
1352 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1353 check_button_size(hToolbar, 23, 100);
1354 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1355 check_button_size(hToolbar, 23, 22);
1356 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1357 check_button_size(hToolbar, 23, 100);
1358 check_sizes();
1359 /* add some buttons with non-default sizes */
1360 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1361 SendMessageA(hToolbar, TB_INSERTBUTTONA, -1, (LPARAM)&buttons2[0]);
1362 check_sizes();
1363 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1364 /* TB_ADDSTRINGA resets the size */
1365 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM) STRING0 "\0" STRING1 "\0");
1366 check_button_size(hToolbar, 23, 23 + fontheight);
1367 check_sizes();
1368 /* TB_SETBUTTONSIZE can be used to crop the text */
1369 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1370 check_button_size(hToolbar, 23, 22);
1371 check_sizes();
1372 /* the default size is bitmap size + padding */
1373 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
1374 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1375 check_button_size(hToolbar, 17, 17);
1376 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
1377 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1378 check_button_size(hToolbar, 4, 4);
1379
1380 rebuild_toolbar(&hToolbar);
1381 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1382 check_button_size(hToolbar, 23, 22);
1383 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
1384 check_button_size(hToolbar, 23, 21);
1385 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1386 add_128x15_bitmap(hToolbar, 16);
1387 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1388 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
1389 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1390 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1391 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1392 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1393 /* check the imagelist */
1394 InvalidateRect(hToolbar, NULL, TRUE);
1395 UpdateWindow(hToolbar);
1396 CHECK_IMAGELIST(16, 14, 12);
1397
1398 rebuild_toolbar(&hToolbar);
1399 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1400 /* the height is increased after a TB_ADDSTRINGA */
1401 check_button_size(hToolbar, 23, 23 + fontheight);
1402 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1403 /* if a string is in the pool, even adding a button without a string resets the size */
1404 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]);
1405 check_button_size(hToolbar, 23, 22);
1406 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1407 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1408 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]);
1409 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1410 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1411 check_sizes();
1412 /* delete button doesn't change the buttons size */
1413 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
1414 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
1415 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1416 /* TB_INSERTBUTTONAS will */
1417 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons2[0]);
1418 check_button_size(hToolbar, 23, 22);
1419
1420 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1421 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1422 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
1423 check_button_size(hToolbar, 100, 100);
1424 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
1425 check_button_size(hToolbar, 100, 100);
1426 /* however changing the hidden flag with TB_SETSTATE does */
1427 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
1428 check_button_size(hToolbar, 100, 100);
1429 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
1430 check_button_size(hToolbar, 23, 22);
1431
1432 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1433 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1434 himl = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_80x15),
1435 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1436 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1437 check_button_size(hToolbar, 100, 21);
1438 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1439 check_button_size(hToolbar, 100, 100);
1440 /* But there are no update when we change imagelist, and image sizes are the same */
1441 himl2 = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_128x15),
1442 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1443 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LRESULT)himl2) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1444 check_button_size(hToolbar, 100, 100);
1445 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1446 check_button_size(hToolbar, 27, 21);
1447 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl2, "TB_SETIMAGELIST failed\n");
1448 check_button_size(hToolbar, 27, 7);
1449 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1450 check_button_size(hToolbar, 8, 7)
1451 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1452 check_button_size(hToolbar, 27, 21)
1453 /* the text is taken into account */
1454 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1455 SendMessageA(hToolbar, TB_ADDBUTTONSA, 4, (LPARAM)buttons3);
1456 check_button_size(hToolbar, 7 + string_width(STRING1), 22 + fontheight);
1457 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1458 check_button_size(hToolbar, 7 + string_width(STRING1), 8 + fontheight);
1459 /* the style change also comes into effect */
1460 check_sizes();
1461 SetWindowLongA(hToolbar, GWL_STYLE, GetWindowLongA(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1462 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1463 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1464
1465 rebuild_toolbar(&hToolbar);
1466 ImageList_Destroy(himl);
1467 ImageList_Destroy(himl2);
1468
1469 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1470 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1471 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
1472 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1473
1474 rebuild_toolbar(&hToolbar);
1475
1476 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1477 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1478 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONSA failed\n");
1479 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONSA failed\n");
1480 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]) == 1, "TB_ADDBUTTONSA failed\n");
1481 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1482 check_sizes();
1483
1484 rebuild_toolbar(&hToolbar);
1485 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLongA(hToolbar, GWL_STYLE));
1486 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1487 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1488 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONSA failed\n");
1489 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONSA failed\n");
1490 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1491 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1492 check_sizes_todo(0xff);
1493
1494 rebuild_toolbar(&hToolbar);
1495 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLongA(hToolbar, GWL_STYLE));
1496 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1497 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1498 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1499 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1500 check_sizes();
1501
1502 rebuild_toolbar(&hToolbar);
1503 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLongA(hToolbar, GWL_STYLE));
1504 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1505 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1506 tbinfo.cx = 672;
1507 tbinfo.cbSize = sizeof(TBBUTTONINFOA);
1508 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
1509 if (SendMessageA(hToolbar, TB_SETBUTTONINFOA, 0, (LPARAM)&tbinfo))
1510 {
1511 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1512 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1513 check_sizes();
1514 }
1515 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1516 {
1517 tbinfo.dwMask = TBIF_SIZE;
1518 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 33, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1519 tbsize_numtests++;
1520 }
1521
1522 /* Single BTNS_AUTOSIZE button with string. */
1523 rebuild_toolbar(&hToolbar);
1524 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[0]) == 1, "TB_ADDBUTTONSA failed\n");
1525 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1526 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1527 check_sizes();
1528
1529 /* Single non-BTNS_AUTOSIZE button with string. */
1530 rebuild_toolbar(&hToolbar);
1531 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[1]) == 1, "TB_ADDBUTTONSA failed\n");
1532 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1533 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1534 check_sizes();
1535
1536 /* Single non-BTNS_AUTOSIZE button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1537 rebuild_toolbar(&hToolbar);
1538 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1539 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1540 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[1]) == 1, "TB_ADDBUTTONSA failed\n");
1541 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1542 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1543 check_sizes();
1544
1545 /* Single non-BTNS_AUTOSIZE, BTNS_SHOWTEXT button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1546 rebuild_toolbar(&hToolbar);
1547 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1548 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1549 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[2]) == 1, "TB_ADDBUTTONSA failed\n");
1550 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1551 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1552 check_sizes();
1553
1554 free_tbsize_results();
1555 DestroyWindow(hToolbar);
1556 }
1557
1558 /* Toolbar control has two ways of reacting to a change. We call them a
1559 * relayout and recalc. A recalc forces a recompute of values like button size
1560 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1561 * values. This functions creates a flat toolbar with a top margin of a non-flat
1562 * toolbar. We will notice a recalc, as it will recompte the top margin and
1563 * change it to zero*/
1564 static void prepare_recalc_test(HWND *phToolbar)
1565 {
1566 RECT rect;
1567 rebuild_toolbar_with_buttons(phToolbar);
1568 SetWindowLongA(*phToolbar, GWL_STYLE,
1569 GetWindowLongA(*phToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1570 SendMessageA(*phToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1571 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1572 rect.top);
1573 }
1574
1575 static BOOL did_recalc(HWND hToolbar)
1576 {
1577 RECT rect;
1578 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1579 ok(rect.top == 2 || rect.top == 0, "Unexpected top margin %d in recalc test\n",
1580 rect.top);
1581 return (rect.top == 0);
1582 }
1583
1584 /* call after a recalc did happen to return to an unstable state */
1585 static void restore_recalc_state(HWND hToolbar)
1586 {
1587 RECT rect;
1588 /* return to style with a 2px top margin */
1589 SetWindowLongA(hToolbar, GWL_STYLE,
1590 SendMessageA(hToolbar, TB_GETSTYLE, 0, 0) & ~TBSTYLE_FLAT);
1591 /* recalc */
1592 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1593 /* top margin will be 0px if a recalc occurs */
1594 SetWindowLongA(hToolbar, GWL_STYLE,
1595 SendMessageA(hToolbar, TB_GETSTYLE, 0, 0) | TBSTYLE_FLAT);
1596 /* safety check */
1597 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1598 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1599 rect.top);
1600 }
1601
1602 static void test_recalc(void)
1603 {
1604 HWND hToolbar = NULL;
1605 TBBUTTONINFOA bi;
1606 CHAR test[] = "Test";
1607 const int EX_STYLES_COUNT = 5;
1608 int i;
1609 BOOL recalc;
1610 DWORD style;
1611
1612 /* Like TB_ADDBUTTONSA tested in test_sized, inserting a button without text
1613 * results in a relayout, while adding one with text forces a recalc */
1614 prepare_recalc_test(&hToolbar);
1615 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[0]);
1616 recalc = did_recalc(hToolbar);
1617 ok(!recalc, "Unexpected recalc - adding button without text\n");
1618
1619 prepare_recalc_test(&hToolbar);
1620 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[3]);
1621 recalc = did_recalc(hToolbar);
1622 ok(recalc, "Expected a recalc - adding button with text\n");
1623
1624 /* TB_SETBUTTONINFOA, even when adding a text, results only in a relayout */
1625 prepare_recalc_test(&hToolbar);
1626 bi.cbSize = sizeof(bi);
1627 bi.dwMask = TBIF_TEXT;
1628 bi.pszText = test;
1629 SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&bi);
1630 recalc = did_recalc(hToolbar);
1631 ok(!recalc, "Unexpected recalc - setting a button text\n");
1632
1633 /* most extended styled doesn't force a recalc (testing all the bits gives
1634 * the same results, but prints some ERRs while testing) */
1635 for (i = 0; i < EX_STYLES_COUNT; i++)
1636 {
1637 if (i == 1 || i == 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1638 continue;
1639 prepare_recalc_test(&hToolbar);
1640 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1641 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, (1 << i));
1642 recalc = did_recalc(hToolbar);
1643 ok(!recalc, "Unexpected recalc - setting bit %d\n", i);
1644 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1645 recalc = did_recalc(hToolbar);
1646 ok(!recalc, "Unexpected recalc - clearing bit %d\n", i);
1647 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1648 }
1649
1650 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1651 prepare_recalc_test(&hToolbar);
1652 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1653 recalc = did_recalc(hToolbar);
1654 if (recalc)
1655 {
1656 ok(recalc, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1657 restore_recalc_state(hToolbar);
1658 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1659 recalc = did_recalc(hToolbar);
1660 ok(!recalc, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1661 restore_recalc_state(hToolbar);
1662 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1663 recalc = did_recalc(hToolbar);
1664 ok(recalc, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1665 }
1666 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1667
1668 /* undocumented exstyle 0x2 seems to change the top margin, which
1669 * interferes with these tests */
1670
1671 /* Show that a change in TBSTYLE_WRAPABLE causes a recalc */
1672 prepare_recalc_test(&hToolbar);
1673 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1674 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1675 recalc = did_recalc(hToolbar);
1676 ok(!recalc, "recalc %d\n", recalc);
1677
1678 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_TOOLTIPS | TBSTYLE_TRANSPARENT | CCS_BOTTOM);
1679 recalc = did_recalc(hToolbar);
1680 ok(!recalc, "recalc %d\n", recalc);
1681
1682 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_WRAPABLE);
1683 recalc = did_recalc(hToolbar);
1684 ok(recalc, "recalc %d\n", recalc);
1685 restore_recalc_state(hToolbar);
1686
1687 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_WRAPABLE);
1688 recalc = did_recalc(hToolbar);
1689 ok(!recalc, "recalc %d\n", recalc);
1690
1691 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1692 recalc = did_recalc(hToolbar);
1693 ok(recalc, "recalc %d\n", recalc);
1694 restore_recalc_state(hToolbar);
1695
1696 /* Changing CCS_VERT does not recalc */
1697 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | CCS_VERT);
1698 recalc = did_recalc(hToolbar);
1699 ok(!recalc, "recalc %d\n", recalc);
1700 restore_recalc_state(hToolbar);
1701
1702 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1703 recalc = did_recalc(hToolbar);
1704 ok(!recalc, "recalc %d\n", recalc);
1705 restore_recalc_state(hToolbar);
1706
1707 /* Setting the window's style directly also causes recalc */
1708 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE);
1709 recalc = did_recalc(hToolbar);
1710 ok(recalc, "recalc %d\n", recalc);
1711
1712 DestroyWindow(hToolbar);
1713 }
1714
1715 static void test_getbuttoninfo(void)
1716 {
1717 HWND hToolbar = NULL;
1718 int i;
1719
1720 rebuild_toolbar_with_buttons(&hToolbar);
1721 for (i = 0; i < 128; i++)
1722 {
1723 TBBUTTONINFOA tbi;
1724 int ret;
1725
1726 tbi.cbSize = i;
1727 tbi.dwMask = TBIF_COMMAND;
1728 ret = (int)SendMessageA(hToolbar, TB_GETBUTTONINFOA, 1, (LPARAM)&tbi);
1729 if (i == sizeof(TBBUTTONINFOA)) {
1730 compare(ret, 0, "%d");
1731 } else {
1732 compare(ret, -1, "%d");
1733 }
1734 }
1735 DestroyWindow(hToolbar);
1736 }
1737
1738 static void test_createtoolbarex(void)
1739 {
1740 HWND hToolbar;
1741 TBBUTTON btns[3];
1742 ZeroMemory(&btns, sizeof(btns));
1743
1744 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1745 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1746 CHECK_IMAGELIST(16, 20, 20);
1747 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1748 DestroyWindow(hToolbar);
1749
1750 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1751 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1752 CHECK_IMAGELIST(32, 4, 4);
1753 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1754 DestroyWindow(hToolbar);
1755
1756 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1757 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1758 CHECK_IMAGELIST(16, 12, 12);
1759 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1760 DestroyWindow(hToolbar);
1761
1762 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1763 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1764 CHECK_IMAGELIST(16, 12, 8);
1765 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1766 DestroyWindow(hToolbar);
1767
1768 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1769 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1770 CHECK_IMAGELIST(16, 16, 8);
1771 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1772 DestroyWindow(hToolbar);
1773
1774 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1775 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1776 CHECK_IMAGELIST(16, 12, 16);
1777 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1778 DestroyWindow(hToolbar);
1779
1780 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1781 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1782 CHECK_IMAGELIST(16, 16, 16);
1783 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1784 DestroyWindow(hToolbar);
1785 }
1786
1787 static void test_dispinfo(void)
1788 {
1789 HWND hToolbar = NULL;
1790 const TBBUTTON buttons_disp[] = {
1791 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1792 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1793 };
1794 BOOL ret;
1795
1796 rebuild_toolbar(&hToolbar);
1797 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1798 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1799 g_dwExpectedDispInfoMask = TBNF_IMAGE;
1800 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1801 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1802 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1803 ShowWindow(hToolbar, SW_SHOW);
1804 UpdateWindow(hToolbar);
1805
1806 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1807 compare(ret, FALSE, "%d");
1808 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1809 InvalidateRect(hToolbar, NULL, FALSE);
1810 UpdateWindow(hToolbar);
1811
1812 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1813 compare(ret, TRUE, "%d");
1814 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1815 InvalidateRect(hToolbar, NULL, FALSE);
1816 UpdateWindow(hToolbar);
1817
1818 DestroyWindow(hToolbar);
1819 g_dwExpectedDispInfoMask = 0;
1820 }
1821
1822 typedef struct
1823 {
1824 int nRows;
1825 BOOL bLarger;
1826 int expectedRows;
1827 } tbrows_result_t;
1828
1829 static tbrows_result_t tbrows_results[] =
1830 {
1831 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1832 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1833 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1834 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1835 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1836 {1, TRUE, 1} /* 5: Back to simple case */
1837 };
1838
1839 static void test_setrows(void)
1840 {
1841 TBBUTTON buttons[9];
1842 HWND hToolbar;
1843 DWORD i;
1844
1845 for (i=0; i<9; i++)
1846 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1847
1848 /* Test 1 - 9 buttons */
1849 hToolbar = CreateToolbarEx(hMainWnd,
1850 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1851 | CCS_NOMOVEY | CCS_TOP,
1852 0,
1853 0, NULL, 0,
1854 buttons, sizeof(buttons)/sizeof(buttons[0]),
1855 20, 20, 0, 0, sizeof(TBBUTTON));
1856 ok(hToolbar != NULL, "Toolbar creation\n");
1857 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1858
1859 /* test setting rows to each of 1-10 with bLarger true and false */
1860 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1861 RECT rc;
1862 int rows;
1863
1864 memset(&rc, 0xCC, sizeof(rc));
1865 SendMessageA(hToolbar, TB_SETROWS,
1866 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1867 (LPARAM) &rc);
1868
1869 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1870 ok(rows == tbrows_results[i].expectedRows,
1871 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1872 tbrows_results[i].expectedRows);
1873 }
1874
1875 DestroyWindow(hToolbar);
1876 }
1877
1878 static void test_getstring(void)
1879 {
1880 HWND hToolbar = NULL;
1881 char str[10];
1882 WCHAR strW[10];
1883 static const char answer[] = "STR";
1884 static const WCHAR answerW[] = { 'S','T','R',0 };
1885 INT r;
1886
1887 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1888 ok(hToolbar != NULL, "Toolbar creation problem\n");
1889
1890 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1891 if (r == 0)
1892 {
1893 win_skip("TB_GETSTRINGA and TB_GETSTRINGW need 5.80\n");
1894 DestroyWindow(hToolbar);
1895 return;
1896 }
1897 expect(-1, r);
1898 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1899 expect(-1, r);
1900 r = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)answer);
1901 expect(0, r);
1902 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1903 expect(lstrlenA(answer), r);
1904 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1905 expect(lstrlenA(answer), r);
1906 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1907 expect(lstrlenA(answer), r);
1908 expect(0, lstrcmpA(answer, str));
1909 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1910 expect(lstrlenA(answer), r);
1911 expect(0, lstrcmpW(answerW, strW));
1912
1913 DestroyWindow(hToolbar);
1914 }
1915
1916 static void test_tooltip(void)
1917 {
1918 HWND hToolbar = NULL;
1919 const TBBUTTON buttons_disp[] = {
1920 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1921 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1922 };
1923 NMTTDISPINFOW nmtti;
1924 HWND tooltip;
1925
1926 rebuild_toolbar(&hToolbar);
1927
1928 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1929
1930 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1931 memset(&nmtti, 0, sizeof(nmtti));
1932 nmtti.hdr.code = TTN_GETDISPINFOW;
1933 nmtti.hdr.idFrom = 20;
1934
1935 SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1936
1937 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1938 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1939 ok_sequence(sequences, PARENT_SEQ_INDEX, ttgetdispinfo_parent_seq,
1940 "dispinfo from tooltip", TRUE);
1941
1942 g_ResetDispTextPtr = TRUE;
1943 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1944 g_ResetDispTextPtr = FALSE;
1945
1946 DestroyWindow(hToolbar);
1947
1948 /* TBSTYLE_TOOLTIPS */
1949 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
1950 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1951 tooltip = (HWND)SendMessageA(hToolbar, TB_GETTOOLTIPS, 0, 0);
1952 ok(tooltip == NULL, "got %p\n", tooltip);
1953 DestroyWindow(hToolbar);
1954 }
1955
1956 static void test_get_set_style(void)
1957 {
1958 TBBUTTON buttons[9];
1959 DWORD style, style2, ret;
1960 HWND hToolbar;
1961 int i;
1962
1963 for (i=0; i<9; i++)
1964 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
1965 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
1966 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
1967
1968 hToolbar = CreateToolbarEx(hMainWnd,
1969 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
1970 WS_CHILD | TBSTYLE_LIST,
1971 100,
1972 0, NULL, 0,
1973 buttons, sizeof(buttons)/sizeof(buttons[0]),
1974 0, 0, 20, 16, sizeof(TBBUTTON));
1975 ok(hToolbar != NULL, "Toolbar creation\n");
1976 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
1977
1978 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1979 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
1980 todo_wine
1981 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
1982
1983 /* try to alter common window bits */
1984 style2 |= WS_BORDER;
1985 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
1986 ok(ret == 0, "got %d\n", ret);
1987 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1988 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
1989 ok((style != style2) && (style == (style2 | WS_BORDER)),
1990 "got 0x%08x, expected 0x%08x\n", style, style2);
1991 ok(style & WS_BORDER, "got 0x%08x\n", style);
1992
1993 /* now styles are the same, alter window style */
1994 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
1995 ok(ret == 0, "got %d\n", ret);
1996 style2 |= WS_BORDER;
1997 SetWindowLongA(hToolbar, GWL_STYLE, style2);
1998 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1999 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
2000
2001 DestroyWindow(hToolbar);
2002 }
2003
2004 static HHOOK g_tbhook;
2005 static HWND g_toolbar;
2006
2007 DEFINE_EXPECT(g_hook_create);
2008 DEFINE_EXPECT(g_hook_WM_NCCREATE);
2009 DEFINE_EXPECT(g_hook_WM_CREATE);
2010
2011 static LRESULT WINAPI toolbar_subclass_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2012 {
2013 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
2014 LRESULT ret;
2015 DWORD style;
2016
2017 if (msg == WM_NCCREATE)
2018 {
2019 if (g_toolbar == hwnd)
2020 {
2021 CHECK_EXPECT2(g_hook_WM_NCCREATE);
2022 g_toolbar = hwnd;
2023 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2024
2025 /* control is already set up */
2026 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2027 ok(style != 0, "got %x\n", style);
2028
2029 style = GetWindowLongA(hwnd, GWL_STYLE);
2030 ok((style & TBSTYLE_TOOLTIPS) == 0, "got 0x%08x\n", style);
2031 SetWindowLongA(hwnd, GWL_STYLE, style|TBSTYLE_TOOLTIPS);
2032 style = GetWindowLongA(hwnd, GWL_STYLE);
2033 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2034
2035 return ret;
2036 }
2037 }
2038 else if (msg == WM_CREATE)
2039 {
2040 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2041
2042 if (g_toolbar == hwnd)
2043 {
2044 CHECK_EXPECT2(g_hook_WM_CREATE);
2045
2046 style = GetWindowLongA(hwnd, GWL_STYLE);
2047 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2048
2049 /* test if toolbar-specific messages are already working before WM_CREATE */
2050 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2051 ok(style != 0, "got %x\n", style);
2052 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
2053 ok((cs->style & TBSTYLE_TOOLTIPS) == 0, "0x%08x\n", cs->style);
2054
2055 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2056
2057 style = GetWindowLongA(hwnd, GWL_STYLE);
2058 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2059
2060 /* test if toolbar-specific messages are already working before WM_CREATE */
2061 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2062 ok(style != 0, "got %x\n", style);
2063 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
2064
2065 return ret;
2066 }
2067 }
2068
2069 return CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2070 }
2071
2072 static LRESULT CALLBACK cbt_hook_proc(int code, WPARAM wParam, LPARAM lParam)
2073 {
2074 if (code == HCBT_CREATEWND)
2075 {
2076 HWND hwnd = (HWND)wParam;
2077
2078 if (!g_toolbar)
2079 {
2080 WNDPROC oldproc;
2081
2082 CHECK_EXPECT2(g_hook_create);
2083 g_toolbar = hwnd;
2084 /* subclass */
2085 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)toolbar_subclass_proc);
2086 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
2087 }
2088 return 0;
2089 }
2090
2091 return CallNextHookEx(g_tbhook, code, wParam, lParam);
2092 }
2093
2094 static void test_create(void)
2095 {
2096 HWND hwnd, tooltip;
2097 DWORD style;
2098
2099 g_tbhook = SetWindowsHookA(WH_CBT, cbt_hook_proc);
2100
2101 SET_EXPECT(g_hook_create);
2102 SET_EXPECT(g_hook_WM_NCCREATE);
2103 SET_EXPECT(g_hook_WM_CREATE);
2104
2105 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
2106 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2107
2108 CHECK_CALLED(g_hook_create);
2109 CHECK_CALLED(g_hook_WM_NCCREATE);
2110 CHECK_CALLED(g_hook_WM_CREATE);
2111
2112 style = GetWindowLongA(hwnd, GWL_STYLE);
2113 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2114
2115 tooltip = (HWND)SendMessageA(hwnd, TB_GETTOOLTIPS, 0, 0);
2116 ok(tooltip != NULL, "got %p\n", tooltip);
2117 ok(GetParent(tooltip) == hMainWnd, "got %p, %p\n", hMainWnd, hwnd);
2118
2119 DestroyWindow(hwnd);
2120 UnhookWindowsHook(WH_CBT, cbt_hook_proc);
2121
2122 /* TBSTYLE_TRANSPARENT */
2123 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL,
2124 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|TBSTYLE_GROUP,
2125 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2126
2127 style = GetWindowLongA(hwnd, GWL_STYLE);
2128 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
2129
2130 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2131 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
2132
2133 DestroyWindow(hwnd);
2134 }
2135
2136 typedef struct {
2137 DWORD mask;
2138 DWORD style;
2139 DWORD style_set;
2140 } extended_style_t;
2141
2142 static const extended_style_t extended_style_test[] = {
2143 {
2144 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
2145 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
2146 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER
2147 },
2148 {
2149 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS,
2150 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS
2151 },
2152
2153 { 0, TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS },
2154 { 0, 0, 0 },
2155 { 0, TBSTYLE_EX_DRAWDDARROWS, TBSTYLE_EX_DRAWDDARROWS },
2156 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS },
2157
2158 { 0, 0, 0 },
2159 { TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS, 0 },
2160 { TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS, 0 },
2161 { TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS, 0 },
2162
2163 {
2164 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
2165 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS
2166 },
2167 {
2168 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
2169 TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_DOUBLEBUFFER
2170 }
2171 };
2172
2173 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
2174 {
2175 DWORD style, oldstyle, oldstyle2;
2176 const extended_style_t *ptr;
2177 HWND hwnd = NULL;
2178 int i;
2179
2180 rebuild_toolbar(&hwnd);
2181
2182 SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS);
2183 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2184 if (style == TBSTYLE_EX_MIXEDBUTTONS)
2185 {
2186 win_skip("Some extended style bits are not supported\n");
2187 DestroyWindow(hwnd);
2188 return;
2189 }
2190
2191 for (i = 0; i < sizeof(extended_style_test)/sizeof(extended_style_t); i++)
2192 {
2193 ptr = &extended_style_test[i];
2194
2195 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2196
2197 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, ptr->mask, ptr->style);
2198 ok(oldstyle == oldstyle2, "%d: got old style 0x%08x, expected 0x%08x\n", i, oldstyle, oldstyle2);
2199 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2200 ok(style == ptr->style_set, "%d: got style 0x%08x, expected 0x%08x\n", i, style, ptr->style_set);
2201 }
2202
2203 /* Windows sets CCS_VERT when TB_GETEXTENDEDSTYLE is set */
2204 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2205 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_VERTICAL);
2206 ok(oldstyle == oldstyle2, "got old style 0x%08x, expected 0x%08x\n", oldstyle, oldstyle2);
2207 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2208 ok(style == TBSTYLE_EX_VERTICAL, "got style 0x%08x, expected 0x%08x\n", style, TBSTYLE_EX_VERTICAL);
2209 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2210 todo_wine
2211 ok(style == CCS_VERT, "got style 0x%08x, expected CCS_VERT\n", style);
2212
2213 DestroyWindow(hwnd);
2214 }
2215
2216 static void test_noresize(void)
2217 {
2218 HWND wnd;
2219 int i;
2220 TBBUTTON button = {0, 10, TBSTATE_ENABLED, 0, {0, }, 0, -1};
2221
2222 wnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE | CCS_NORESIZE | TBSTYLE_WRAPABLE, 0, 0, 100, 20,
2223 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2224 SendMessageA(wnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
2225
2226 for (i=0; i<30; i++)
2227 {
2228 button.idCommand = 10 + i;
2229 SendMessageA(wnd, TB_ADDBUTTONSA, 1, (LPARAM)&button);
2230 }
2231
2232 SendMessageA(wnd, TB_SETSTATE, 10, TBSTATE_WRAP|TBSTATE_ENABLED);
2233
2234 /* autosize clears the wrap on button 0 */
2235 SendMessageA(wnd, TB_AUTOSIZE, 0, 0);
2236 for (i=0; i<30; i++)
2237 {
2238 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2239 if (i % 4 == 3)
2240 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2241 else
2242 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2243 }
2244
2245 /* changing the parent doesn't do anything */
2246 MoveWindow(hMainWnd, 0,0, 400, 200, FALSE);
2247 for (i=0; i<30; i++)
2248 {
2249 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2250 if (i % 4 == 3)
2251 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2252 else
2253 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2254 }
2255
2256 /* again nothing here */
2257 SendMessageA(wnd, TB_AUTOSIZE, 0, 0);
2258 for (i=0; i<30; i++)
2259 {
2260 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2261 if (i % 4 == 3)
2262 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2263 else
2264 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2265 }
2266
2267 DestroyWindow(wnd);
2268
2269 }
2270
2271 static void test_save(void)
2272 {
2273 HWND wnd = NULL;
2274 TBSAVEPARAMSW params;
2275 static const WCHAR subkey[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','T','e','s','t',0};
2276 static const WCHAR value[] = {'t','o','o','l','b','a','r','t','e','s','t',0};
2277 LONG res;
2278 HKEY key;
2279 BYTE data[100];
2280 DWORD size = sizeof(data), type, i, count;
2281 TBBUTTON tb;
2282 static const TBBUTTON more_btns[2] =
2283 {
2284 {0, 11, TBSTATE_HIDDEN, BTNS_BUTTON, {0}, 0, -1},
2285 {0, 13, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, -1}
2286 };
2287 static const DWORD expect[] = {0xcafe, 1, 0xcafe0000, 3, 0xcafe0001, 5, 0xcafe0002, 7, 0xcafe0003,
2288 9, 0xcafe0004, 11, 0xcafe0005, 13, 0xcafe0006, 0xffffffff, 0xcafe0007,
2289 0xfffffffe, 0xcafe0008, 0x80000000, 0xcafe0009, 0x7fffffff, 0xcafe000a,
2290 0x100, 0xcafe000b};
2291 static const TBBUTTON expect_btns[] =
2292 {
2293 {0, 1, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
2294 {0, 3, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 1, 2},
2295 {0, 5, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 2, 0},
2296 {0, 7, 0, BTNS_BUTTON, {0}, 0, (INT_PTR)"foo"},
2297 {0, 9, 0, BTNS_BUTTON, {0}, 0, 0},
2298 {0, 11, 0, BTNS_BUTTON, {0}, 0, 3},
2299 {0, 13, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 6, 0},
2300 {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 7, 0},
2301 {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 8, 0},
2302 {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 9, 0},
2303 {0, 0x7fffffff, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0xa, 0},
2304 };
2305
2306 params.hkr = HKEY_CURRENT_USER;
2307 params.pszSubKey = subkey;
2308 params.pszValueName = value;
2309
2310 rebuild_toolbar_with_buttons( &wnd );
2311 SendMessageW( wnd, TB_ADDBUTTONSW, sizeof(more_btns) / sizeof(more_btns[0]), (LPARAM)more_btns );
2312
2313 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2314 res = SendMessageW( wnd, TB_SAVERESTOREW, TRUE, (LPARAM)&params );
2315 ok( res, "saving failed\n" );
2316 ok_sequence(sequences, PARENT_SEQ_INDEX, save_parent_seq, "save", FALSE);
2317 DestroyWindow( wnd );
2318
2319 res = RegOpenKeyW( HKEY_CURRENT_USER, subkey, &key );
2320 ok( !res, "got %08x\n", res );
2321 res = RegQueryValueExW( key, value, NULL, &type, data, &size );
2322 ok( !res, "got %08x\n", res );
2323 ok( type == REG_BINARY, "got %08x\n", type );
2324 ok( size == sizeof(expect), "got %08x\n", size );
2325 ok( !memcmp( data, expect, size ), "mismatch\n" );
2326
2327 RegCloseKey( key );
2328
2329 wnd = NULL;
2330 rebuild_toolbar( &wnd );
2331
2332 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2333 res = SendMessageW( wnd, TB_SAVERESTOREW, FALSE, (LPARAM)&params );
2334 ok( res, "restoring failed\n" );
2335 ok_sequence(sequences, PARENT_SEQ_INDEX, restore_parent_seq, "restore", FALSE);
2336 count = SendMessageW( wnd, TB_BUTTONCOUNT, 0, 0 );
2337 ok( count == sizeof(expect_btns) / sizeof(expect_btns[0]), "got %d\n", count );
2338
2339 for (i = 0; i < count; i++)
2340 {
2341 res = SendMessageW( wnd, TB_GETBUTTON, i, (LPARAM)&tb );
2342 ok( res, "got %d\n", res );
2343
2344 ok( tb.iBitmap == expect_btns[i].iBitmap, "%d: got %d\n", i, tb.iBitmap );
2345 ok( tb.idCommand == expect_btns[i].idCommand, "%d: got %d\n", i, tb.idCommand );
2346 ok( tb.fsState == expect_btns[i].fsState, "%d: got %02x\n", i, tb.fsState );
2347 ok( tb.fsStyle == expect_btns[i].fsStyle, "%d: got %02x\n", i, tb.fsStyle );
2348 ok( tb.dwData == expect_btns[i].dwData, "%d: got %lx\n", i, tb.dwData );
2349 if (IS_INTRESOURCE(expect_btns[i].iString))
2350 ok( tb.iString == expect_btns[i].iString, "%d: got %lx\n", i, tb.iString );
2351 else
2352 ok( !strcmp( (char *)tb.iString, (char *)expect_btns[i].iString ),
2353 "%d: got %s\n", i, (char *)tb.iString );
2354
2355 /* In fact the ptr value set in TBN_GETBUTTONINFOA is simply copied */
2356 if (tb.idCommand == 7)
2357 ok( tb.iString == (INT_PTR)alloced_str, "string not set\n");
2358 }
2359
2360 DestroyWindow( wnd );
2361 RegOpenKeyW( HKEY_CURRENT_USER, subkey, &key );
2362 RegDeleteValueW( key, value );
2363 RegCloseKey( key );
2364 }
2365
2366 START_TEST(toolbar)
2367 {
2368 WNDCLASSA wc;
2369 MSG msg;
2370 RECT rc;
2371
2372 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2373
2374 InitCommonControls();
2375
2376 wc.style = CS_HREDRAW | CS_VREDRAW;
2377 wc.cbClsExtra = 0;
2378 wc.cbWndExtra = 0;
2379 wc.hInstance = GetModuleHandleA(NULL);
2380 wc.hIcon = NULL;
2381 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_IBEAM);
2382 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
2383 wc.lpszMenuName = NULL;
2384 wc.lpszClassName = "Toolbar test parent";
2385 wc.lpfnWndProc = parent_wnd_proc;
2386 RegisterClassA(&wc);
2387
2388 hMainWnd = CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW,
2389 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
2390 GetClientRect(hMainWnd, &rc);
2391 ShowWindow(hMainWnd, SW_SHOW);
2392
2393 basic_test();
2394 test_add_bitmap();
2395 test_add_string();
2396 test_hotitem();
2397 test_sizes();
2398 test_recalc();
2399 test_getbuttoninfo();
2400 test_createtoolbarex();
2401 test_dispinfo();
2402 test_setrows();
2403 test_getstring();
2404 test_tooltip();
2405 test_get_set_style();
2406 test_create();
2407 test_TB_GET_SET_EXTENDEDSTYLE();
2408 test_noresize();
2409 test_save();
2410
2411 PostQuitMessage(0);
2412 while(GetMessageA(&msg,0,0,0)) {
2413 TranslateMessage(&msg);
2414 DispatchMessageA(&msg);
2415 }
2416 DestroyWindow(hMainWnd);
2417 }