[COMCTL32] Unset the toolbar's hot item when deleting a button. CORE-14222
[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 3\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_GETHOTITEM 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_GETHOTITEM 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_GETHOTITEM returned %ld, expected 1\n", ret);
910 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
911
912 /* deleting a button unsets the hot item */
913 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 0, 0);
914 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
915 g_fReceivedHotItemChange = FALSE;
916 ret = SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
917 ok(ret == TRUE, "TB_DELETEBUTTON returned %ld, expected TRUE\n", ret);
918 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
919 ok(ret == -1, "TB_GETHOTITEM returned %ld, expected -1\n", ret);
920 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
921
922 DestroyWindow(hToolbar);
923 }
924
925 #if 0 /* use this to generate more tests*/
926
927 static void dump_sizes(HWND hToolbar)
928 {
929 SIZE sz;
930 RECT r;
931 int count = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0);
932 int i;
933
934 GetClientRect(hToolbar, &r);
935 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
936 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
937 sz.cx, sz.cy, count);
938 for (i=0; i<count; i++)
939 {
940 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
941 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
942 }
943 printf("\n }, },\n");
944 }
945
946 #define check_sizes() dump_sizes(hToolbar);
947 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
948
949 #else
950
951 static int system_font_height(void) {
952 HDC hDC;
953 TEXTMETRICA tm;
954
955 hDC = CreateCompatibleDC(NULL);
956 GetTextMetricsA(hDC, &tm);
957 DeleteDC(NULL);
958
959 return tm.tmHeight;
960 }
961
962 static int string_width(const CHAR *s) {
963 SIZE sz;
964 HDC hdc;
965
966 hdc = CreateCompatibleDC(NULL);
967 GetTextExtentPoint32A(hdc, s, strlen(s), &sz);
968 DeleteDC(hdc);
969
970 return sz.cx;
971 }
972
973 typedef struct
974 {
975 RECT rcClient;
976 SIZE szMin;
977 INT nButtons;
978 RECT *prcButtons;
979 } tbsize_result_t;
980
981 static tbsize_result_t init_tbsize_result(int nButtonsAlloc, int cleft, int ctop, int cright, int cbottom, int minx, int miny) {
982 tbsize_result_t ret;
983
984 SetRect(&ret.rcClient, cleft, ctop, cright, cbottom);
985 ret.szMin.cx = minx;
986 ret.szMin.cy = miny;
987 ret.nButtons = 0;
988 ret.prcButtons = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nButtonsAlloc*sizeof(RECT));
989
990 return ret;
991 }
992
993 static void tbsize_addbutton(tbsize_result_t *tbsr, int left, int top, int right, int bottom) {
994 SetRect(&tbsr->prcButtons[tbsr->nButtons], left, top, right, bottom);
995 tbsr->nButtons++;
996 }
997
998 #define STRING0 "A"
999 #define STRING1 "MMMMMMMMMMMMM"
1000 #define STRING2 "Tst"
1001
1002 static tbsize_result_t *tbsize_results;
1003
1004 #define tbsize_results_num 28
1005
1006 static void init_tbsize_results(void) {
1007 int fontheight = system_font_height();
1008 int buttonwidth;
1009
1010 tbsize_results = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tbsize_results_num*sizeof(tbsize_result_t));
1011
1012 tbsize_results[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
1013 tbsize_addbutton(&tbsize_results[0], 0, 2, 23, 24);
1014 tbsize_addbutton(&tbsize_results[0], 23, 2, 46, 24);
1015 tbsize_addbutton(&tbsize_results[0], 46, 2, 54, 24);
1016 tbsize_addbutton(&tbsize_results[0], 54, 2, 77, 24);
1017 tbsize_addbutton(&tbsize_results[0], 77, 2, 100, 24);
1018
1019 tbsize_results[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1020 tbsize_addbutton(&tbsize_results[1], 0, 2, 23, 24);
1021 tbsize_addbutton(&tbsize_results[1], 23, 2, 46, 24);
1022 tbsize_addbutton(&tbsize_results[1], 46, 2, 54, 24);
1023 tbsize_addbutton(&tbsize_results[1], 54, 2, 77, 24);
1024 tbsize_addbutton(&tbsize_results[1], 77, 2, 100, 24);
1025 tbsize_addbutton(&tbsize_results[1], 100, 2, 123, 24);
1026 tbsize_addbutton(&tbsize_results[1], 0, 24, 23, 46);
1027
1028 tbsize_results[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1029 tbsize_addbutton(&tbsize_results[2], 0, 2, 23, 24);
1030 tbsize_addbutton(&tbsize_results[2], 23, 2, 46, 24);
1031 tbsize_addbutton(&tbsize_results[2], 46, 2, 54, 24);
1032 tbsize_addbutton(&tbsize_results[2], 54, 2, 77, 24);
1033 tbsize_addbutton(&tbsize_results[2], 77, 2, 100, 24);
1034 tbsize_addbutton(&tbsize_results[2], 100, 2, 123, 24);
1035 tbsize_addbutton(&tbsize_results[2], 0, 24, 23, 46);
1036
1037 tbsize_results[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1038 tbsize_addbutton(&tbsize_results[3], 0, 2, 23, 24);
1039 tbsize_addbutton(&tbsize_results[3], 23, 2, 46, 24);
1040 tbsize_addbutton(&tbsize_results[3], 46, 2, 54, 24);
1041 tbsize_addbutton(&tbsize_results[3], 54, 2, 77, 24);
1042 tbsize_addbutton(&tbsize_results[3], 77, 2, 100, 24);
1043 tbsize_addbutton(&tbsize_results[3], 100, 2, 123, 24);
1044 tbsize_addbutton(&tbsize_results[3], 123, 2, 146, 24);
1045
1046 tbsize_results[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
1047 tbsize_addbutton(&tbsize_results[4], 0, 2, 23, 24);
1048 tbsize_addbutton(&tbsize_results[4], 23, 2, 46, 24);
1049 tbsize_addbutton(&tbsize_results[4], 46, 2, 54, 24);
1050 tbsize_addbutton(&tbsize_results[4], 54, 2, 77, 24);
1051 tbsize_addbutton(&tbsize_results[4], 77, 2, 100, 24);
1052 tbsize_addbutton(&tbsize_results[4], 100, 2, 123, 24);
1053 tbsize_addbutton(&tbsize_results[4], 123, 2, 146, 24);
1054 tbsize_addbutton(&tbsize_results[4], 146, 2, 169, 24);
1055 tbsize_addbutton(&tbsize_results[4], 169, 2, 192, 24);
1056
1057 tbsize_results[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
1058 tbsize_addbutton(&tbsize_results[5], 0, 2, 23, 24);
1059 tbsize_addbutton(&tbsize_results[5], 23, 2, 46, 24);
1060 tbsize_addbutton(&tbsize_results[5], 0, 2, 8, 29);
1061 tbsize_addbutton(&tbsize_results[5], 0, 29, 23, 51);
1062 tbsize_addbutton(&tbsize_results[5], 23, 29, 46, 51);
1063 tbsize_addbutton(&tbsize_results[5], 46, 29, 69, 51);
1064 tbsize_addbutton(&tbsize_results[5], 69, 29, 92, 51);
1065 tbsize_addbutton(&tbsize_results[5], 92, 29, 115, 51);
1066 tbsize_addbutton(&tbsize_results[5], 115, 29, 138, 51);
1067 tbsize_addbutton(&tbsize_results[5], 138, 29, 161, 51);
1068 tbsize_addbutton(&tbsize_results[5], 161, 29, 184, 51);
1069 tbsize_addbutton(&tbsize_results[5], 184, 29, 207, 51);
1070 tbsize_addbutton(&tbsize_results[5], 207, 29, 230, 51);
1071 tbsize_addbutton(&tbsize_results[5], 230, 29, 253, 51);
1072 tbsize_addbutton(&tbsize_results[5], 253, 29, 276, 51);
1073 tbsize_addbutton(&tbsize_results[5], 276, 29, 299, 51);
1074 tbsize_addbutton(&tbsize_results[5], 299, 29, 322, 51);
1075 tbsize_addbutton(&tbsize_results[5], 322, 29, 345, 51);
1076 tbsize_addbutton(&tbsize_results[5], 345, 29, 368, 51);
1077 tbsize_addbutton(&tbsize_results[5], 368, 29, 391, 51);
1078 tbsize_addbutton(&tbsize_results[5], 391, 29, 414, 51);
1079 tbsize_addbutton(&tbsize_results[5], 414, 29, 437, 51);
1080 tbsize_addbutton(&tbsize_results[5], 437, 29, 460, 51);
1081 tbsize_addbutton(&tbsize_results[5], 460, 29, 483, 51);
1082 tbsize_addbutton(&tbsize_results[5], 483, 29, 506, 51);
1083 tbsize_addbutton(&tbsize_results[5], 506, 29, 529, 51);
1084 tbsize_addbutton(&tbsize_results[5], 529, 29, 552, 51);
1085 tbsize_addbutton(&tbsize_results[5], 552, 29, 575, 51);
1086 tbsize_addbutton(&tbsize_results[5], 575, 29, 598, 51);
1087 tbsize_addbutton(&tbsize_results[5], 598, 29, 621, 51);
1088 tbsize_addbutton(&tbsize_results[5], 621, 29, 644, 51);
1089 tbsize_addbutton(&tbsize_results[5], 644, 29, 667, 51);
1090 tbsize_addbutton(&tbsize_results[5], 0, 51, 23, 73);
1091 tbsize_addbutton(&tbsize_results[5], 23, 51, 46, 73);
1092 tbsize_addbutton(&tbsize_results[5], 46, 51, 69, 73);
1093 tbsize_addbutton(&tbsize_results[5], 69, 51, 92, 73);
1094 tbsize_addbutton(&tbsize_results[5], 92, 51, 115, 73);
1095 tbsize_addbutton(&tbsize_results[5], 115, 51, 138, 73);
1096 tbsize_addbutton(&tbsize_results[5], 138, 51, 161, 73);
1097
1098 tbsize_results[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
1099 tbsize_addbutton(&tbsize_results[6], 0, 2, 23, 24);
1100 tbsize_addbutton(&tbsize_results[6], 23, 2, 46, 24);
1101 tbsize_addbutton(&tbsize_results[6], 46, 2, 94, 24);
1102 tbsize_addbutton(&tbsize_results[6], 94, 2, 117, 24);
1103 tbsize_addbutton(&tbsize_results[6], 117, 2, 140, 24);
1104 tbsize_addbutton(&tbsize_results[6], 140, 2, 163, 24);
1105 tbsize_addbutton(&tbsize_results[6], 0, 24, 23, 46);
1106
1107 tbsize_results[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
1108 tbsize_addbutton(&tbsize_results[7], 0, 2, 23, 24);
1109 tbsize_addbutton(&tbsize_results[7], 23, 2, 46, 24);
1110 tbsize_addbutton(&tbsize_results[7], 0, 24, 92, 32);
1111 tbsize_addbutton(&tbsize_results[7], 0, 32, 23, 54);
1112 tbsize_addbutton(&tbsize_results[7], 23, 32, 46, 54);
1113 tbsize_addbutton(&tbsize_results[7], 46, 32, 69, 54);
1114 tbsize_addbutton(&tbsize_results[7], 69, 32, 92, 54);
1115
1116 tbsize_results[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
1117 tbsize_addbutton(&tbsize_results[8], 0, 2, 31, 32);
1118 tbsize_addbutton(&tbsize_results[8], 31, 2, 62, 32);
1119 tbsize_addbutton(&tbsize_results[8], 62, 2, 70, 32);
1120 tbsize_addbutton(&tbsize_results[8], 70, 2, 101, 32);
1121 tbsize_addbutton(&tbsize_results[8], 101, 2, 132, 32);
1122 tbsize_addbutton(&tbsize_results[8], 132, 2, 163, 32);
1123 tbsize_addbutton(&tbsize_results[8], 0, 32, 31, 62);
1124
1125 tbsize_results[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1126 tbsize_addbutton(&tbsize_results[9], 0, 2, 31, 32);
1127 tbsize_addbutton(&tbsize_results[9], 31, 2, 62, 32);
1128 tbsize_addbutton(&tbsize_results[9], 62, 2, 70, 32);
1129 tbsize_addbutton(&tbsize_results[9], 70, 2, 101, 32);
1130 tbsize_addbutton(&tbsize_results[9], 101, 2, 132, 32);
1131 tbsize_addbutton(&tbsize_results[9], 132, 2, 163, 32);
1132 tbsize_addbutton(&tbsize_results[9], 0, 32, 31, 62);
1133
1134 tbsize_results[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1135 tbsize_addbutton(&tbsize_results[10], 0, 0, 31, 30);
1136 tbsize_addbutton(&tbsize_results[10], 31, 0, 62, 30);
1137 tbsize_addbutton(&tbsize_results[10], 62, 0, 70, 30);
1138 tbsize_addbutton(&tbsize_results[10], 70, 0, 101, 30);
1139 tbsize_addbutton(&tbsize_results[10], 101, 0, 132, 30);
1140 tbsize_addbutton(&tbsize_results[10], 132, 0, 163, 30);
1141 tbsize_addbutton(&tbsize_results[10], 0, 30, 31, 60);
1142
1143 tbsize_results[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
1144 tbsize_addbutton(&tbsize_results[11], 0, 0, 31, 30);
1145 tbsize_addbutton(&tbsize_results[11], 31, 0, 62, 30);
1146 tbsize_addbutton(&tbsize_results[11], 0, 30, 124, 38);
1147 tbsize_addbutton(&tbsize_results[11], 0, 38, 31, 68);
1148 tbsize_addbutton(&tbsize_results[11], 31, 38, 62, 68);
1149 tbsize_addbutton(&tbsize_results[11], 62, 38, 93, 68);
1150 tbsize_addbutton(&tbsize_results[11], 93, 38, 124, 68);
1151
1152 tbsize_results[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1153 tbsize_addbutton(&tbsize_results[12], 0, 2, 23, 24);
1154 tbsize_addbutton(&tbsize_results[12], 23, 2, 46, 24);
1155 tbsize_addbutton(&tbsize_results[12], 46, 2, 54, 24);
1156 tbsize_addbutton(&tbsize_results[12], 54, 2, 77, 24);
1157 tbsize_addbutton(&tbsize_results[12], 77, 2, 100, 24);
1158 tbsize_addbutton(&tbsize_results[12], 100, 2, 123, 24);
1159 tbsize_addbutton(&tbsize_results[12], 123, 2, 146, 24);
1160
1161 tbsize_results[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
1162 tbsize_addbutton(&tbsize_results[13], 0, 0, 23, 100);
1163 tbsize_addbutton(&tbsize_results[13], 23, 0, 46, 100);
1164 tbsize_addbutton(&tbsize_results[13], 46, 0, 54, 100);
1165 tbsize_addbutton(&tbsize_results[13], 54, 0, 77, 100);
1166 tbsize_addbutton(&tbsize_results[13], 77, 0, 100, 100);
1167 tbsize_addbutton(&tbsize_results[13], 100, 0, 123, 100);
1168 tbsize_addbutton(&tbsize_results[13], 123, 0, 146, 100);
1169
1170 tbsize_results[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
1171 tbsize_addbutton(&tbsize_results[14], 0, 0, 23, 100);
1172 tbsize_addbutton(&tbsize_results[14], 23, 0, 46, 100);
1173 tbsize_addbutton(&tbsize_results[14], 46, 0, 54, 100);
1174 tbsize_addbutton(&tbsize_results[14], 54, 0, 77, 100);
1175 tbsize_addbutton(&tbsize_results[14], 77, 0, 100, 100);
1176 tbsize_addbutton(&tbsize_results[14], 100, 0, 123, 100);
1177 tbsize_addbutton(&tbsize_results[14], 123, 0, 146, 100);
1178 tbsize_addbutton(&tbsize_results[14], 146, 0, 169, 100);
1179 tbsize_addbutton(&tbsize_results[14], 169, 0, 192, 100);
1180 tbsize_addbutton(&tbsize_results[14], 192, 0, 215, 100);
1181
1182 tbsize_results[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
1183 tbsize_addbutton(&tbsize_results[15], 0, 0, 23, 23 + fontheight);
1184 tbsize_addbutton(&tbsize_results[15], 23, 0, 46, 23 + fontheight);
1185 tbsize_addbutton(&tbsize_results[15], 46, 0, 54, 23 + fontheight);
1186 tbsize_addbutton(&tbsize_results[15], 54, 0, 77, 23 + fontheight);
1187 tbsize_addbutton(&tbsize_results[15], 77, 0, 100, 23 + fontheight);
1188 tbsize_addbutton(&tbsize_results[15], 100, 0, 123, 23 + fontheight);
1189 tbsize_addbutton(&tbsize_results[15], 123, 0, 146, 23 + fontheight);
1190 tbsize_addbutton(&tbsize_results[15], 146, 0, 169, 23 + fontheight);
1191 tbsize_addbutton(&tbsize_results[15], 169, 0, 192, 23 + fontheight);
1192 tbsize_addbutton(&tbsize_results[15], 192, 0, 215, 23 + fontheight);
1193 tbsize_addbutton(&tbsize_results[15], 215, 0, 238, 23 + fontheight);
1194
1195 tbsize_results[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
1196 tbsize_addbutton(&tbsize_results[16], 0, 0, 23, 22);
1197 tbsize_addbutton(&tbsize_results[16], 23, 0, 46, 22);
1198 tbsize_addbutton(&tbsize_results[16], 46, 0, 54, 22);
1199 tbsize_addbutton(&tbsize_results[16], 54, 0, 77, 22);
1200 tbsize_addbutton(&tbsize_results[16], 77, 0, 100, 22);
1201 tbsize_addbutton(&tbsize_results[16], 100, 0, 123, 22);
1202 tbsize_addbutton(&tbsize_results[16], 123, 0, 146, 22);
1203 tbsize_addbutton(&tbsize_results[16], 146, 0, 169, 22);
1204 tbsize_addbutton(&tbsize_results[16], 169, 0, 192, 22);
1205 tbsize_addbutton(&tbsize_results[16], 192, 0, 215, 22);
1206 tbsize_addbutton(&tbsize_results[16], 215, 0, 238, 22);
1207
1208 buttonwidth = 7 + string_width(STRING1);
1209
1210 tbsize_results[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
1211 tbsize_addbutton(&tbsize_results[17], 0, 2, buttonwidth, 25 + fontheight);
1212 tbsize_addbutton(&tbsize_results[17], buttonwidth, 2, 2*buttonwidth + 4, 25 + fontheight);
1213 tbsize_addbutton(&tbsize_results[17], 2*buttonwidth + 4, 2, 3*buttonwidth + 4, 25 + fontheight);
1214
1215 tbsize_results[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
1216 tbsize_addbutton(&tbsize_results[18], 0, 2, buttonwidth, 10 + fontheight);
1217 tbsize_addbutton(&tbsize_results[18], buttonwidth, 2, 2*buttonwidth, 10 + fontheight);
1218 tbsize_addbutton(&tbsize_results[18], 2*buttonwidth, 2, 3*buttonwidth, 10 + fontheight);
1219 tbsize_addbutton(&tbsize_results[18], 3*buttonwidth, 2, 4*buttonwidth, 10 + fontheight);
1220 tbsize_addbutton(&tbsize_results[18], 4*buttonwidth, 2, 5*buttonwidth + 4, 10 + fontheight);
1221 tbsize_addbutton(&tbsize_results[18], 5*buttonwidth + 4, 2, 5*buttonwidth + 4 + string_width(STRING2) + 11, 10 + fontheight);
1222
1223 tbsize_results[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
1224 tbsize_addbutton(&tbsize_results[19], 0, 0, buttonwidth, 22 + fontheight);
1225 tbsize_addbutton(&tbsize_results[19], buttonwidth, 0, 2*buttonwidth, 22 + fontheight);
1226 tbsize_addbutton(&tbsize_results[19], 2*buttonwidth, 0, 3*buttonwidth, 22 + fontheight);
1227 tbsize_addbutton(&tbsize_results[19], 3*buttonwidth, 0, 4*buttonwidth, 22 + fontheight);
1228 tbsize_addbutton(&tbsize_results[19], 4*buttonwidth, 0, 5*buttonwidth + 4, 22 + fontheight);
1229 tbsize_addbutton(&tbsize_results[19], 5*buttonwidth + 4, 0, 5*buttonwidth + 4 + string_width(STRING2) + 11, 22 + fontheight);
1230
1231 tbsize_results[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
1232 tbsize_addbutton(&tbsize_results[20], 0, 2, 100, 102);
1233 tbsize_addbutton(&tbsize_results[20], 100, 2, 139, 102);
1234 tbsize_addbutton(&tbsize_results[20], 139, 2, 239, 102);
1235
1236 tbsize_results[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
1237 tbsize_addbutton(&tbsize_results[21], 0, 2, 75, 40);
1238 tbsize_addbutton(&tbsize_results[21], 75, 2, 118, 40);
1239 tbsize_addbutton(&tbsize_results[21], 118, 2, 165 + string_width(STRING2), 40);
1240
1241 tbsize_results[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1242 tbsize_addbutton(&tbsize_results[22], 0, 2, 47 + string_width(STRING2), 40);
1243
1244 tbsize_results[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
1245 tbsize_addbutton(&tbsize_results[23], 0, 2, 672, 25 + fontheight);
1246 tbsize_addbutton(&tbsize_results[23], 0, 25 + fontheight, 672, 48 + 2*fontheight);
1247
1248 tbsize_results[24] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1249 tbsize_addbutton(&tbsize_results[24], 0, 2, 11 + string_width(STRING2), 24);
1250
1251 tbsize_results[25] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1252 tbsize_addbutton(&tbsize_results[25], 0, 2, 40, 24);
1253
1254 tbsize_results[26] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1255 tbsize_addbutton(&tbsize_results[26], 0, 2, 40, 24);
1256
1257 tbsize_results[27] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1258 tbsize_addbutton(&tbsize_results[27], 0, 2, 40, 24);
1259 }
1260
1261 static void free_tbsize_results(void) {
1262 int i;
1263
1264 for (i = 0; i < tbsize_results_num; i++)
1265 HeapFree(GetProcessHeap(), 0, tbsize_results[i].prcButtons);
1266 HeapFree(GetProcessHeap(), 0, tbsize_results);
1267 tbsize_results = NULL;
1268 }
1269
1270 static int tbsize_numtests = 0;
1271
1272 typedef struct
1273 {
1274 int test_num;
1275 int rect_index;
1276 RECT rcButton;
1277 } tbsize_alt_result_t;
1278
1279 static tbsize_alt_result_t tbsize_alt_results[] =
1280 {
1281 { 5, 2, { 0, 24, 8, 29 } },
1282 { 20, 1, { 100, 2, 107, 102 } },
1283 { 20, 2, { 107, 2, 207, 102 } }
1284 };
1285
1286 static DWORD tbsize_alt_numtests = 0;
1287
1288 #define check_sizes_todo(todomask) { \
1289 RECT rc; \
1290 int buttonCount, i, mask=(todomask); \
1291 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1292 GetClientRect(hToolbar, &rc); \
1293 /*check_rect("client", rc, res->rcClient);*/ \
1294 buttonCount = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1295 compare(buttonCount, res->nButtons, "%d"); \
1296 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1297 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1298 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1299 EqualRect(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton))) { \
1300 win_skip("Alternate rect found\n"); \
1301 tbsize_alt_numtests++; \
1302 } else todo_wine_if(mask&1) \
1303 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1304 mask >>= 1; \
1305 } \
1306 tbsize_numtests++; \
1307 }
1308
1309 #define check_sizes() check_sizes_todo(0)
1310
1311 #endif
1312
1313 static TBBUTTON buttons1[] = {
1314 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
1315 {0, 11, 0, 0, {0, }, 0, -1},
1316 };
1317 static TBBUTTON buttons2[] = {
1318 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1319 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1320 };
1321 static TBBUTTON buttons3[] = {
1322 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
1323 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
1324 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
1325 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)STRING2}
1326 };
1327 static TBBUTTON buttons4[] = {
1328 {0, 40, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)STRING2},
1329 {0, 41, TBSTATE_ENABLED, 0, {0, }, 0, (UINT_PTR)STRING2},
1330 {0, 41, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0, }, 0, (UINT_PTR)STRING2}
1331 };
1332
1333 static void test_sizes(void)
1334 {
1335 HWND hToolbar = NULL;
1336 HIMAGELIST himl, himl2;
1337 TBBUTTONINFOA tbinfo;
1338 TBBUTTON button;
1339 int style;
1340 int i;
1341 int fontheight = system_font_height();
1342
1343 init_tbsize_results();
1344
1345 rebuild_toolbar_with_buttons(&hToolbar);
1346 style = GetWindowLongA(hToolbar, GWL_STYLE);
1347 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
1348 check_sizes();
1349 /* the TBSTATE_WRAP makes a second row */
1350 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1351 check_sizes();
1352 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1353 check_sizes();
1354 SendMessageA(hToolbar, TB_GETBUTTON, 5, (LPARAM)&button);
1355 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "got %08x\n", button.fsState);
1356 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1357 SetWindowLongA(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
1358 check_sizes();
1359 SendMessageA(hToolbar, TB_GETBUTTON, 5, (LPARAM)&button);
1360 ok(button.fsState == TBSTATE_ENABLED, "got %08x\n", button.fsState);
1361 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1362 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1363 check_sizes();
1364 /* only after adding enough buttons the bar will be wrapped on a
1365 * separator and then on the first button */
1366 for (i=0; i<15; i++)
1367 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1368 check_sizes_todo(0x4);
1369 SendMessageA(hToolbar, TB_GETBUTTON, 31, (LPARAM)&button);
1370 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "got %08x\n", button.fsState);
1371 SetWindowLongA(hToolbar, GWL_STYLE, style);
1372 SendMessageA(hToolbar, TB_GETBUTTON, 31, (LPARAM)&button);
1373 ok(button.fsState == TBSTATE_ENABLED, "got %08x\n", button.fsState);
1374
1375 rebuild_toolbar_with_buttons(&hToolbar);
1376 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1377 /* setting the buttons vertical will only change the window client size */
1378 SetWindowLongA(hToolbar, GWL_STYLE, style | CCS_VERT);
1379 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1380 check_sizes_todo(0x3c);
1381 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1382 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
1383 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1384 check_sizes_todo(0x7c);
1385
1386 rebuild_toolbar_with_buttons(&hToolbar);
1387 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1388 /* a TB_SETBITMAPSIZE changes button sizes*/
1389 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1390 check_sizes();
1391
1392 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1393 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1394 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1395 check_sizes();
1396 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1397 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
1398 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1399 check_sizes();
1400 /* some vertical toolbar sizes */
1401 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
1402 check_sizes_todo(0x7c);
1403
1404 rebuild_toolbar_with_buttons(&hToolbar);
1405 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1406 /* newly added buttons will be use the previous margin */
1407 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1408 check_sizes();
1409 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1410 check_button_size(hToolbar, 23, 22);
1411 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1412 check_button_size(hToolbar, 23, 22);
1413 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1414 check_button_size(hToolbar, 23, 100);
1415 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1416 check_button_size(hToolbar, 23, 22);
1417 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1418 check_button_size(hToolbar, 23, 100);
1419 check_sizes();
1420 /* add some buttons with non-default sizes */
1421 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1422 SendMessageA(hToolbar, TB_INSERTBUTTONA, -1, (LPARAM)&buttons2[0]);
1423 check_sizes();
1424 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1425 /* TB_ADDSTRINGA resets the size */
1426 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM) STRING0 "\0" STRING1 "\0");
1427 check_button_size(hToolbar, 23, 23 + fontheight);
1428 check_sizes();
1429 /* TB_SETBUTTONSIZE can be used to crop the text */
1430 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1431 check_button_size(hToolbar, 23, 22);
1432 check_sizes();
1433 /* the default size is bitmap size + padding */
1434 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
1435 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1436 check_button_size(hToolbar, 17, 17);
1437 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
1438 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1439 check_button_size(hToolbar, 4, 4);
1440
1441 rebuild_toolbar(&hToolbar);
1442 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1443 check_button_size(hToolbar, 23, 22);
1444 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
1445 check_button_size(hToolbar, 23, 21);
1446 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1447 add_128x15_bitmap(hToolbar, 16);
1448 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1449 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
1450 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1451 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1452 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1453 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1454 /* check the imagelist */
1455 InvalidateRect(hToolbar, NULL, TRUE);
1456 UpdateWindow(hToolbar);
1457 CHECK_IMAGELIST(16, 14, 12);
1458
1459 rebuild_toolbar(&hToolbar);
1460 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1461 /* the height is increased after a TB_ADDSTRINGA */
1462 check_button_size(hToolbar, 23, 23 + fontheight);
1463 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1464 /* if a string is in the pool, even adding a button without a string resets the size */
1465 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]);
1466 check_button_size(hToolbar, 23, 22);
1467 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1468 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1469 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]);
1470 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1471 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1472 check_sizes();
1473 /* delete button doesn't change the buttons size */
1474 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
1475 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
1476 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1477 /* TB_INSERTBUTTONAS will */
1478 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons2[0]);
1479 check_button_size(hToolbar, 23, 22);
1480
1481 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1482 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1483 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
1484 check_button_size(hToolbar, 100, 100);
1485 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
1486 check_button_size(hToolbar, 100, 100);
1487 /* however changing the hidden flag with TB_SETSTATE does */
1488 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
1489 check_button_size(hToolbar, 100, 100);
1490 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
1491 check_button_size(hToolbar, 23, 22);
1492
1493 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1494 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1495 himl = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_80x15),
1496 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1497 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1498 check_button_size(hToolbar, 100, 21);
1499 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1500 check_button_size(hToolbar, 100, 100);
1501 /* But there are no update when we change imagelist, and image sizes are the same */
1502 himl2 = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_128x15),
1503 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1504 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LRESULT)himl2) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1505 check_button_size(hToolbar, 100, 100);
1506 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1507 check_button_size(hToolbar, 27, 21);
1508 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl2, "TB_SETIMAGELIST failed\n");
1509 check_button_size(hToolbar, 27, 7);
1510 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1511 check_button_size(hToolbar, 8, 7)
1512 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1513 check_button_size(hToolbar, 27, 21)
1514 /* the text is taken into account */
1515 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1516 SendMessageA(hToolbar, TB_ADDBUTTONSA, 4, (LPARAM)buttons3);
1517 check_button_size(hToolbar, 7 + string_width(STRING1), 22 + fontheight);
1518 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1519 check_button_size(hToolbar, 7 + string_width(STRING1), 8 + fontheight);
1520 /* the style change also comes into effect */
1521 check_sizes();
1522 SetWindowLongA(hToolbar, GWL_STYLE, GetWindowLongA(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1523 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1524 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1525
1526 rebuild_toolbar(&hToolbar);
1527 ImageList_Destroy(himl);
1528 ImageList_Destroy(himl2);
1529
1530 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1531 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1532 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
1533 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1534
1535 rebuild_toolbar(&hToolbar);
1536
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[0]) == 1, "TB_ADDBUTTONSA failed\n");
1542 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1543 check_sizes();
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)&buttons2[0]) == 1, "TB_ADDBUTTONSA failed\n");
1550 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONSA failed\n");
1551 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1552 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1553 check_sizes_todo(0xff);
1554
1555 rebuild_toolbar(&hToolbar);
1556 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLongA(hToolbar, GWL_STYLE));
1557 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1558 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1559 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1560 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1561 check_sizes();
1562
1563 rebuild_toolbar(&hToolbar);
1564 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLongA(hToolbar, GWL_STYLE));
1565 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1566 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1567 tbinfo.cx = 672;
1568 tbinfo.cbSize = sizeof(TBBUTTONINFOA);
1569 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
1570 if (SendMessageA(hToolbar, TB_SETBUTTONINFOA, 0, (LPARAM)&tbinfo))
1571 {
1572 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1573 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1574 check_sizes();
1575 }
1576 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1577 {
1578 tbinfo.dwMask = TBIF_SIZE;
1579 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 33, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1580 tbsize_numtests++;
1581 }
1582
1583 /* Single BTNS_AUTOSIZE button with string. */
1584 rebuild_toolbar(&hToolbar);
1585 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[0]) == 1, "TB_ADDBUTTONSA failed\n");
1586 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1587 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1588 check_sizes();
1589
1590 /* Single non-BTNS_AUTOSIZE button with string. */
1591 rebuild_toolbar(&hToolbar);
1592 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[1]) == 1, "TB_ADDBUTTONSA failed\n");
1593 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1594 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1595 check_sizes();
1596
1597 /* Single non-BTNS_AUTOSIZE button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1598 rebuild_toolbar(&hToolbar);
1599 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1600 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[1]) == 1, "TB_ADDBUTTONSA failed\n");
1601 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1602 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1603 check_sizes();
1604
1605 /* Single non-BTNS_AUTOSIZE, BTNS_SHOWTEXT button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1606 rebuild_toolbar(&hToolbar);
1607 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1608 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons4[2]) == 1, "TB_ADDBUTTONSA failed\n");
1609 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1610 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1611 check_sizes();
1612
1613 free_tbsize_results();
1614 DestroyWindow(hToolbar);
1615 }
1616
1617 /* Toolbar control has two ways of reacting to a change. We call them a
1618 * relayout and recalc. A recalc forces a recompute of values like button size
1619 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1620 * values. This functions creates a flat toolbar with a top margin of a non-flat
1621 * toolbar. We will notice a recalc, as it will recompte the top margin and
1622 * change it to zero*/
1623 static void prepare_recalc_test(HWND *phToolbar)
1624 {
1625 RECT rect;
1626 rebuild_toolbar_with_buttons(phToolbar);
1627 SetWindowLongA(*phToolbar, GWL_STYLE,
1628 GetWindowLongA(*phToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1629 SendMessageA(*phToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1630 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1631 rect.top);
1632 }
1633
1634 static BOOL did_recalc(HWND hToolbar)
1635 {
1636 RECT rect;
1637 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1638 ok(rect.top == 2 || rect.top == 0, "Unexpected top margin %d in recalc test\n",
1639 rect.top);
1640 return (rect.top == 0);
1641 }
1642
1643 /* call after a recalc did happen to return to an unstable state */
1644 static void restore_recalc_state(HWND hToolbar)
1645 {
1646 RECT rect;
1647 /* return to style with a 2px top margin */
1648 SetWindowLongA(hToolbar, GWL_STYLE,
1649 SendMessageA(hToolbar, TB_GETSTYLE, 0, 0) & ~TBSTYLE_FLAT);
1650 /* recalc */
1651 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1652 /* top margin will be 0px if a recalc occurs */
1653 SetWindowLongA(hToolbar, GWL_STYLE,
1654 SendMessageA(hToolbar, TB_GETSTYLE, 0, 0) | TBSTYLE_FLAT);
1655 /* safety check */
1656 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1657 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1658 rect.top);
1659 }
1660
1661 static void test_recalc(void)
1662 {
1663 HWND hToolbar = NULL;
1664 TBBUTTONINFOA bi;
1665 CHAR test[] = "Test";
1666 const int EX_STYLES_COUNT = 5;
1667 int i;
1668 BOOL recalc;
1669 DWORD style;
1670
1671 /* Like TB_ADDBUTTONSA tested in test_sized, inserting a button without text
1672 * results in a relayout, while adding one with text forces a recalc */
1673 prepare_recalc_test(&hToolbar);
1674 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[0]);
1675 recalc = did_recalc(hToolbar);
1676 ok(!recalc, "Unexpected recalc - adding button without text\n");
1677
1678 prepare_recalc_test(&hToolbar);
1679 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[3]);
1680 recalc = did_recalc(hToolbar);
1681 ok(recalc, "Expected a recalc - adding button with text\n");
1682
1683 /* TB_SETBUTTONINFOA, even when adding a text, results only in a relayout */
1684 prepare_recalc_test(&hToolbar);
1685 bi.cbSize = sizeof(bi);
1686 bi.dwMask = TBIF_TEXT;
1687 bi.pszText = test;
1688 SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&bi);
1689 recalc = did_recalc(hToolbar);
1690 ok(!recalc, "Unexpected recalc - setting a button text\n");
1691
1692 /* most extended styled doesn't force a recalc (testing all the bits gives
1693 * the same results, but prints some ERRs while testing) */
1694 for (i = 0; i < EX_STYLES_COUNT; i++)
1695 {
1696 if (i == 1 || i == 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1697 continue;
1698 prepare_recalc_test(&hToolbar);
1699 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1700 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, (1 << i));
1701 recalc = did_recalc(hToolbar);
1702 ok(!recalc, "Unexpected recalc - setting bit %d\n", i);
1703 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1704 recalc = did_recalc(hToolbar);
1705 ok(!recalc, "Unexpected recalc - clearing bit %d\n", i);
1706 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1707 }
1708
1709 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1710 prepare_recalc_test(&hToolbar);
1711 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1712 recalc = did_recalc(hToolbar);
1713 if (recalc)
1714 {
1715 ok(recalc, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1716 restore_recalc_state(hToolbar);
1717 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1718 recalc = did_recalc(hToolbar);
1719 ok(!recalc, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1720 restore_recalc_state(hToolbar);
1721 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1722 recalc = did_recalc(hToolbar);
1723 ok(recalc, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1724 }
1725 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1726
1727 /* undocumented exstyle 0x2 seems to change the top margin, which
1728 * interferes with these tests */
1729
1730 /* Show that a change in TBSTYLE_WRAPABLE causes a recalc */
1731 prepare_recalc_test(&hToolbar);
1732 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1733 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1734 recalc = did_recalc(hToolbar);
1735 ok(!recalc, "recalc %d\n", recalc);
1736
1737 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_TOOLTIPS | TBSTYLE_TRANSPARENT | CCS_BOTTOM);
1738 recalc = did_recalc(hToolbar);
1739 ok(!recalc, "recalc %d\n", recalc);
1740
1741 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_WRAPABLE);
1742 recalc = did_recalc(hToolbar);
1743 ok(recalc, "recalc %d\n", recalc);
1744 restore_recalc_state(hToolbar);
1745
1746 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | TBSTYLE_WRAPABLE);
1747 recalc = did_recalc(hToolbar);
1748 ok(!recalc, "recalc %d\n", recalc);
1749
1750 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1751 recalc = did_recalc(hToolbar);
1752 ok(recalc, "recalc %d\n", recalc);
1753 restore_recalc_state(hToolbar);
1754
1755 /* Changing CCS_VERT does not recalc */
1756 SendMessageA(hToolbar, TB_SETSTYLE, 0, style | CCS_VERT);
1757 recalc = did_recalc(hToolbar);
1758 ok(!recalc, "recalc %d\n", recalc);
1759 restore_recalc_state(hToolbar);
1760
1761 SendMessageA(hToolbar, TB_SETSTYLE, 0, style);
1762 recalc = did_recalc(hToolbar);
1763 ok(!recalc, "recalc %d\n", recalc);
1764 restore_recalc_state(hToolbar);
1765
1766 /* Setting the window's style directly also causes recalc */
1767 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE);
1768 recalc = did_recalc(hToolbar);
1769 ok(recalc, "recalc %d\n", recalc);
1770
1771 DestroyWindow(hToolbar);
1772 }
1773
1774 static void test_getbuttoninfo(void)
1775 {
1776 HWND hToolbar = NULL;
1777 TBBUTTONINFOW tbiW;
1778 TBBUTTONINFOA tbi;
1779 int i;
1780
1781 rebuild_toolbar_with_buttons(&hToolbar);
1782 for (i = 0; i < 128; i++)
1783 {
1784 int ret;
1785
1786 tbi.cbSize = i;
1787 tbi.dwMask = TBIF_COMMAND;
1788 ret = (int)SendMessageA(hToolbar, TB_GETBUTTONINFOA, 1, (LPARAM)&tbi);
1789 if (i == sizeof(TBBUTTONINFOA)) {
1790 compare(ret, 0, "%d");
1791 } else {
1792 compare(ret, -1, "%d");
1793 }
1794 }
1795
1796 /* TBIF_TEXT with NULL pszText */
1797 memset(&tbiW, 0, sizeof(tbiW));
1798 tbiW.cbSize = sizeof(tbiW);
1799 tbiW.dwMask = TBIF_BYINDEX | TBIF_STYLE | TBIF_COMMAND | TBIF_TEXT;
1800 i = SendMessageA(hToolbar, TB_GETBUTTONINFOW, 1, (LPARAM)&tbiW);
1801 ok(i == 1, "Got index %d\n", i);
1802
1803 DestroyWindow(hToolbar);
1804 }
1805
1806 static void test_createtoolbarex(void)
1807 {
1808 HWND hToolbar;
1809 TBBUTTON btns[3];
1810 ZeroMemory(&btns, sizeof(btns));
1811
1812 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1813 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1814 CHECK_IMAGELIST(16, 20, 20);
1815 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1816 DestroyWindow(hToolbar);
1817
1818 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1819 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1820 CHECK_IMAGELIST(32, 4, 4);
1821 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1822 DestroyWindow(hToolbar);
1823
1824 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1825 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1826 CHECK_IMAGELIST(16, 12, 12);
1827 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1828 DestroyWindow(hToolbar);
1829
1830 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1831 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1832 CHECK_IMAGELIST(16, 12, 8);
1833 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1834 DestroyWindow(hToolbar);
1835
1836 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1837 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1838 CHECK_IMAGELIST(16, 16, 8);
1839 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1840 DestroyWindow(hToolbar);
1841
1842 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1843 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1844 CHECK_IMAGELIST(16, 12, 16);
1845 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1846 DestroyWindow(hToolbar);
1847
1848 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1849 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1850 CHECK_IMAGELIST(16, 16, 16);
1851 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1852 DestroyWindow(hToolbar);
1853 }
1854
1855 static void test_dispinfo(void)
1856 {
1857 HWND hToolbar = NULL;
1858 const TBBUTTON buttons_disp[] = {
1859 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1860 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1861 };
1862 BOOL ret;
1863
1864 rebuild_toolbar(&hToolbar);
1865 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1866 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1867 g_dwExpectedDispInfoMask = TBNF_IMAGE;
1868 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1869 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1870 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1871 ShowWindow(hToolbar, SW_SHOW);
1872 UpdateWindow(hToolbar);
1873
1874 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1875 compare(ret, FALSE, "%d");
1876 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1877 InvalidateRect(hToolbar, NULL, FALSE);
1878 UpdateWindow(hToolbar);
1879
1880 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1881 compare(ret, TRUE, "%d");
1882 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1883 InvalidateRect(hToolbar, NULL, FALSE);
1884 UpdateWindow(hToolbar);
1885
1886 DestroyWindow(hToolbar);
1887 g_dwExpectedDispInfoMask = 0;
1888 }
1889
1890 typedef struct
1891 {
1892 int nRows;
1893 BOOL bLarger;
1894 int expectedRows;
1895 } tbrows_result_t;
1896
1897 static tbrows_result_t tbrows_results[] =
1898 {
1899 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1900 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1901 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1902 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1903 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1904 {1, TRUE, 1} /* 5: Back to simple case */
1905 };
1906
1907 static void test_setrows(void)
1908 {
1909 TBBUTTON buttons[9];
1910 HWND hToolbar;
1911 DWORD i;
1912
1913 for (i=0; i<9; i++)
1914 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1915
1916 /* Test 1 - 9 buttons */
1917 hToolbar = CreateToolbarEx(hMainWnd,
1918 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1919 | CCS_NOMOVEY | CCS_TOP,
1920 0,
1921 0, NULL, 0,
1922 buttons, sizeof(buttons)/sizeof(buttons[0]),
1923 20, 20, 0, 0, sizeof(TBBUTTON));
1924 ok(hToolbar != NULL, "Toolbar creation\n");
1925 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1926
1927 /* test setting rows to each of 1-10 with bLarger true and false */
1928 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1929 RECT rc;
1930 int rows;
1931
1932 memset(&rc, 0xCC, sizeof(rc));
1933 SendMessageA(hToolbar, TB_SETROWS,
1934 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1935 (LPARAM) &rc);
1936
1937 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1938 ok(rows == tbrows_results[i].expectedRows,
1939 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1940 tbrows_results[i].expectedRows);
1941 }
1942
1943 DestroyWindow(hToolbar);
1944 }
1945
1946 static void test_getstring(void)
1947 {
1948 HWND hToolbar = NULL;
1949 char str[10];
1950 WCHAR strW[10];
1951 static const char answer[] = "STR";
1952 static const WCHAR answerW[] = { 'S','T','R',0 };
1953 INT r;
1954
1955 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1956 ok(hToolbar != NULL, "Toolbar creation problem\n");
1957
1958 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1959 if (r == 0)
1960 {
1961 win_skip("TB_GETSTRINGA and TB_GETSTRINGW need 5.80\n");
1962 DestroyWindow(hToolbar);
1963 return;
1964 }
1965 expect(-1, r);
1966 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1967 expect(-1, r);
1968 r = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)answer);
1969 expect(0, r);
1970 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1971 expect(lstrlenA(answer), r);
1972 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1973 expect(lstrlenA(answer), r);
1974 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1975 expect(lstrlenA(answer), r);
1976 expect(0, lstrcmpA(answer, str));
1977 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1978 expect(lstrlenA(answer), r);
1979 expect(0, lstrcmpW(answerW, strW));
1980
1981 DestroyWindow(hToolbar);
1982 }
1983
1984 static void test_tooltip(void)
1985 {
1986 HWND hToolbar = NULL;
1987 const TBBUTTON buttons_disp[] = {
1988 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1989 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1990 };
1991 NMTTDISPINFOW nmtti;
1992 HWND tooltip;
1993
1994 rebuild_toolbar(&hToolbar);
1995
1996 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1997
1998 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1999 memset(&nmtti, 0, sizeof(nmtti));
2000 nmtti.hdr.code = TTN_GETDISPINFOW;
2001 nmtti.hdr.idFrom = 20;
2002
2003 SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
2004
2005 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2006 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
2007 ok_sequence(sequences, PARENT_SEQ_INDEX, ttgetdispinfo_parent_seq,
2008 "dispinfo from tooltip", TRUE);
2009
2010 g_ResetDispTextPtr = TRUE;
2011 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
2012 g_ResetDispTextPtr = FALSE;
2013
2014 DestroyWindow(hToolbar);
2015
2016 /* TBSTYLE_TOOLTIPS */
2017 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
2018 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2019 tooltip = (HWND)SendMessageA(hToolbar, TB_GETTOOLTIPS, 0, 0);
2020 ok(tooltip == NULL, "got %p\n", tooltip);
2021 DestroyWindow(hToolbar);
2022 }
2023
2024 static void test_get_set_style(void)
2025 {
2026 TBBUTTON buttons[9];
2027 DWORD style, style2, ret;
2028 HWND hToolbar;
2029 int i;
2030
2031 for (i=0; i<9; i++)
2032 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
2033 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
2034 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
2035
2036 hToolbar = CreateToolbarEx(hMainWnd,
2037 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
2038 WS_CHILD | TBSTYLE_LIST,
2039 100,
2040 0, NULL, 0,
2041 buttons, sizeof(buttons)/sizeof(buttons[0]),
2042 0, 0, 20, 16, sizeof(TBBUTTON));
2043 ok(hToolbar != NULL, "Toolbar creation\n");
2044 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
2045
2046 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
2047 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
2048 todo_wine
2049 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
2050
2051 /* try to alter common window bits */
2052 style2 |= WS_BORDER;
2053 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
2054 ok(ret == 0, "got %d\n", ret);
2055 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
2056 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
2057 ok((style != style2) && (style == (style2 | WS_BORDER)),
2058 "got 0x%08x, expected 0x%08x\n", style, style2);
2059 ok(style & WS_BORDER, "got 0x%08x\n", style);
2060
2061 /* now styles are the same, alter window style */
2062 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
2063 ok(ret == 0, "got %d\n", ret);
2064 style2 |= WS_BORDER;
2065 SetWindowLongA(hToolbar, GWL_STYLE, style2);
2066 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
2067 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
2068
2069 DestroyWindow(hToolbar);
2070 }
2071
2072 static HHOOK g_tbhook;
2073 static HWND g_toolbar;
2074
2075 DEFINE_EXPECT(g_hook_create);
2076 DEFINE_EXPECT(g_hook_WM_NCCREATE);
2077 DEFINE_EXPECT(g_hook_WM_CREATE);
2078
2079 static LRESULT WINAPI toolbar_subclass_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2080 {
2081 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
2082 LRESULT ret;
2083 DWORD style;
2084
2085 if (msg == WM_NCCREATE)
2086 {
2087 if (g_toolbar == hwnd)
2088 {
2089 CHECK_EXPECT2(g_hook_WM_NCCREATE);
2090 g_toolbar = hwnd;
2091 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2092
2093 /* control is already set up */
2094 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2095 ok(style != 0, "got %x\n", style);
2096
2097 style = GetWindowLongA(hwnd, GWL_STYLE);
2098 ok((style & TBSTYLE_TOOLTIPS) == 0, "got 0x%08x\n", style);
2099 SetWindowLongA(hwnd, GWL_STYLE, style|TBSTYLE_TOOLTIPS);
2100 style = GetWindowLongA(hwnd, GWL_STYLE);
2101 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2102
2103 return ret;
2104 }
2105 }
2106 else if (msg == WM_CREATE)
2107 {
2108 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2109
2110 if (g_toolbar == hwnd)
2111 {
2112 CHECK_EXPECT2(g_hook_WM_CREATE);
2113
2114 style = GetWindowLongA(hwnd, GWL_STYLE);
2115 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2116
2117 /* test if toolbar-specific messages are already working before WM_CREATE */
2118 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2119 ok(style != 0, "got %x\n", style);
2120 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
2121 ok((cs->style & TBSTYLE_TOOLTIPS) == 0, "0x%08x\n", cs->style);
2122
2123 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2124
2125 style = GetWindowLongA(hwnd, GWL_STYLE);
2126 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2127
2128 /* test if toolbar-specific messages are already working before WM_CREATE */
2129 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2130 ok(style != 0, "got %x\n", style);
2131 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
2132
2133 return ret;
2134 }
2135 }
2136
2137 return CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
2138 }
2139
2140 static LRESULT CALLBACK cbt_hook_proc(int code, WPARAM wParam, LPARAM lParam)
2141 {
2142 if (code == HCBT_CREATEWND)
2143 {
2144 HWND hwnd = (HWND)wParam;
2145
2146 if (!g_toolbar)
2147 {
2148 WNDPROC oldproc;
2149
2150 CHECK_EXPECT2(g_hook_create);
2151 g_toolbar = hwnd;
2152 /* subclass */
2153 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)toolbar_subclass_proc);
2154 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
2155 }
2156 return 0;
2157 }
2158
2159 return CallNextHookEx(g_tbhook, code, wParam, lParam);
2160 }
2161
2162 static void test_create(void)
2163 {
2164 HWND hwnd, tooltip;
2165 DWORD style;
2166
2167 g_tbhook = SetWindowsHookA(WH_CBT, cbt_hook_proc);
2168
2169 SET_EXPECT(g_hook_create);
2170 SET_EXPECT(g_hook_WM_NCCREATE);
2171 SET_EXPECT(g_hook_WM_CREATE);
2172
2173 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
2174 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2175
2176 CHECK_CALLED(g_hook_create);
2177 CHECK_CALLED(g_hook_WM_NCCREATE);
2178 CHECK_CALLED(g_hook_WM_CREATE);
2179
2180 style = GetWindowLongA(hwnd, GWL_STYLE);
2181 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
2182
2183 tooltip = (HWND)SendMessageA(hwnd, TB_GETTOOLTIPS, 0, 0);
2184 ok(tooltip != NULL, "got %p\n", tooltip);
2185 ok(GetParent(tooltip) == hMainWnd, "got %p, %p\n", hMainWnd, hwnd);
2186
2187 DestroyWindow(hwnd);
2188 UnhookWindowsHook(WH_CBT, cbt_hook_proc);
2189
2190 /* TBSTYLE_TRANSPARENT */
2191 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL,
2192 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|TBSTYLE_GROUP,
2193 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2194
2195 style = GetWindowLongA(hwnd, GWL_STYLE);
2196 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
2197
2198 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2199 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
2200
2201 DestroyWindow(hwnd);
2202 }
2203
2204 typedef struct {
2205 DWORD mask;
2206 DWORD style;
2207 DWORD style_set;
2208 } extended_style_t;
2209
2210 static const extended_style_t extended_style_test[] = {
2211 {
2212 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
2213 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
2214 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER
2215 },
2216 {
2217 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS,
2218 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS
2219 },
2220
2221 { 0, TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS },
2222 { 0, 0, 0 },
2223 { 0, TBSTYLE_EX_DRAWDDARROWS, TBSTYLE_EX_DRAWDDARROWS },
2224 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS },
2225
2226 { 0, 0, 0 },
2227 { TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS, 0 },
2228 { TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS, 0 },
2229 { TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS, 0 },
2230
2231 {
2232 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
2233 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS
2234 },
2235 {
2236 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
2237 TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_DOUBLEBUFFER
2238 }
2239 };
2240
2241 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
2242 {
2243 DWORD style, oldstyle, oldstyle2;
2244 const extended_style_t *ptr;
2245 HWND hwnd = NULL;
2246 int i;
2247
2248 rebuild_toolbar(&hwnd);
2249
2250 SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS);
2251 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2252 if (style == TBSTYLE_EX_MIXEDBUTTONS)
2253 {
2254 win_skip("Some extended style bits are not supported\n");
2255 DestroyWindow(hwnd);
2256 return;
2257 }
2258
2259 for (i = 0; i < sizeof(extended_style_test)/sizeof(extended_style_t); i++)
2260 {
2261 ptr = &extended_style_test[i];
2262
2263 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2264
2265 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, ptr->mask, ptr->style);
2266 ok(oldstyle == oldstyle2, "%d: got old style 0x%08x, expected 0x%08x\n", i, oldstyle, oldstyle2);
2267 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2268 ok(style == ptr->style_set, "%d: got style 0x%08x, expected 0x%08x\n", i, style, ptr->style_set);
2269 }
2270
2271 /* Windows sets CCS_VERT when TB_GETEXTENDEDSTYLE is set */
2272 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2273 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_VERTICAL);
2274 ok(oldstyle == oldstyle2, "got old style 0x%08x, expected 0x%08x\n", oldstyle, oldstyle2);
2275 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
2276 ok(style == TBSTYLE_EX_VERTICAL, "got style 0x%08x, expected 0x%08x\n", style, TBSTYLE_EX_VERTICAL);
2277 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
2278 todo_wine
2279 ok(style == CCS_VERT, "got style 0x%08x, expected CCS_VERT\n", style);
2280
2281 DestroyWindow(hwnd);
2282 }
2283
2284 static void test_noresize(void)
2285 {
2286 HWND wnd;
2287 int i;
2288 TBBUTTON button = {0, 10, TBSTATE_ENABLED, 0, {0, }, 0, -1};
2289
2290 wnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE | CCS_NORESIZE | TBSTYLE_WRAPABLE, 0, 0, 100, 20,
2291 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
2292 SendMessageA(wnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
2293
2294 for (i=0; i<30; i++)
2295 {
2296 button.idCommand = 10 + i;
2297 SendMessageA(wnd, TB_ADDBUTTONSA, 1, (LPARAM)&button);
2298 }
2299
2300 SendMessageA(wnd, TB_SETSTATE, 10, TBSTATE_WRAP|TBSTATE_ENABLED);
2301
2302 /* autosize clears the wrap on button 0 */
2303 SendMessageA(wnd, TB_AUTOSIZE, 0, 0);
2304 for (i=0; i<30; i++)
2305 {
2306 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2307 if (i % 4 == 3)
2308 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2309 else
2310 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2311 }
2312
2313 /* changing the parent doesn't do anything */
2314 MoveWindow(hMainWnd, 0,0, 400, 200, FALSE);
2315 for (i=0; i<30; i++)
2316 {
2317 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2318 if (i % 4 == 3)
2319 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2320 else
2321 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2322 }
2323
2324 /* again nothing here */
2325 SendMessageA(wnd, TB_AUTOSIZE, 0, 0);
2326 for (i=0; i<30; i++)
2327 {
2328 SendMessageA(wnd, TB_GETBUTTON, i, (LPARAM)&button);
2329 if (i % 4 == 3)
2330 ok(button.fsState == (TBSTATE_WRAP|TBSTATE_ENABLED), "%d: got %08x\n", i, button.fsState);
2331 else
2332 ok(button.fsState == TBSTATE_ENABLED, "%d: got %08x\n", i, button.fsState);
2333 }
2334
2335 DestroyWindow(wnd);
2336
2337 }
2338
2339 static void test_save(void)
2340 {
2341 HWND wnd = NULL;
2342 TBSAVEPARAMSW params;
2343 static const WCHAR subkey[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
2344 'W','i','n','e','T','e','s','t',0};
2345 static const WCHAR value[] = {'t','o','o','l','b','a','r','t','e','s','t',0};
2346 LONG res;
2347 HKEY key;
2348 BYTE data[100];
2349 DWORD size = sizeof(data), type, i, count;
2350 TBBUTTON tb;
2351 static const TBBUTTON more_btns[2] =
2352 {
2353 {0, 11, TBSTATE_HIDDEN, BTNS_BUTTON, {0}, 0, -1},
2354 {0, 13, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, -1}
2355 };
2356 static const DWORD expect[] = {0xcafe, 1, 0xcafe0000, 3, 0xcafe0001, 5, 0xcafe0002, 7, 0xcafe0003,
2357 9, 0xcafe0004, 11, 0xcafe0005, 13, 0xcafe0006, 0xffffffff, 0xcafe0007,
2358 0xfffffffe, 0xcafe0008, 0x80000000, 0xcafe0009, 0x7fffffff, 0xcafe000a,
2359 0x100, 0xcafe000b};
2360 static const TBBUTTON expect_btns[] =
2361 {
2362 {0, 1, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
2363 {0, 3, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 1, 2},
2364 {0, 5, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 2, 0},
2365 {0, 7, 0, BTNS_BUTTON, {0}, 0, (INT_PTR)"foo"},
2366 {0, 9, 0, BTNS_BUTTON, {0}, 0, 0},
2367 {0, 11, 0, BTNS_BUTTON, {0}, 0, 3},
2368 {0, 13, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 6, 0},
2369 {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 7, 0},
2370 {0, 0, TBSTATE_ENABLED