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