Commit 2fa45673 authored by Mikołaj Zalewski's avatar Mikołaj Zalewski Committed by Alexandre Julliard

comctl32: toolbar: Fix the return code of TB_ADDBITMAP.

parent 12d3235e
......@@ -173,22 +173,22 @@ static void test_add_bitmap(void)
CHECK_IMAGELIST(13, 16, 15);
/* adding the same bitmap will simply return the index of the already loaded block */
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
todo_wine ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(13, 16, 15);
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
todo_wine ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(13, 16, 15);
/* even if we increase the wParam */
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
todo_wine ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(13, 16, 15);
/* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
rebuild_toolbar(&hToolbar);
ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
CHECK_IMAGELIST(8, 16, 15);
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
todo_wine ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
/* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
CHECK_IMAGELIST(13, 16, 15);
......@@ -198,7 +198,7 @@ static void test_add_bitmap(void)
ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(8, 16, 15);
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
todo_wine ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(13, 16, 15);
/* for zero only one bitmap will be added */
......@@ -230,14 +230,14 @@ static void test_add_bitmap(void)
ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
CHECK_IMAGELIST(6, 20, 20);
ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
todo_wine ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
CHECK_IMAGELIST(10, 20, 20);
/* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
UpdateWindow(hToolbar);
CHECK_IMAGELIST_TODO_COUNT_SIZE(26, 8, 8);
/* loading a standard bitmaps automatically resizes the icons */
todo_wine ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
UpdateWindow(hToolbar);
CHECK_IMAGELIST_TODO_COUNT_SIZE(28, 16, 15);
......
......@@ -2580,6 +2580,7 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
TBITMAP_INFO info;
INT nIndex = 0, nCount;
INT iSumButtons, i;
HBITMAP hbmLoad;
HIMAGELIST himlDef;
......@@ -2652,6 +2653,16 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
info.nID = lpAddBmp->nID;
TRACE("adding %d bitmaps!\n", info.nButtons);
}
/* check if the bitmap is already loaded and compute iSumButtons */
iSumButtons = 0;
for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
{
if (infoPtr->bitmaps[i].hInst == info.hInst &&
infoPtr->bitmaps[i].nID == info.nID)
return iSumButtons;
iSumButtons += infoPtr->bitmaps[i].nButtons;
}
if (!infoPtr->cimlDef) {
/* create new default image list */
......@@ -2733,7 +2744,7 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
InvalidateRect(hwnd, NULL, TRUE);
return nIndex;
return iSumButtons;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment