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