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

comctl32: toolbar: Copy bitmaps with CopyImage so that it works also for DIBs…

comctl32: toolbar: Copy bitmaps with CopyImage so that it works also for DIBs (based on a patch by Oleg Krylov).
parent 79e265ac
......@@ -2664,33 +2664,7 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TB
TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
/* Add bitmaps to the default image list */
if (bitmap->hInst == NULL) /* a handle was passed */
{
BITMAP bmp;
HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
HDC hdcImage, hdcBitmap;
/* copy the bitmap before adding it so that the user's bitmap
* doesn't get modified.
*/
GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
hdcImage = CreateCompatibleDC(0);
hdcBitmap = CreateCompatibleDC(0);
/* create new bitmap */
hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
/* Copy the user's image */
BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
hdcBitmap, 0, 0, SRCCOPY);
SelectObject (hdcImage, hOldBitmapLoad);
SelectObject (hdcBitmap, hOldBitmapBitmap);
DeleteDC (hdcImage);
DeleteDC (hdcBitmap);
}
hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
else
hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
......@@ -4175,7 +4149,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
HBITMAP hBitmap;
HBITMAP hbmLoad = NULL;
int i = 0, nOldButtons = 0, pos = 0;
int nOldBitmaps, nNewBitmaps = 0;
HIMAGELIST himlDef = 0;
......@@ -4192,16 +4165,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
else if (lpReplace->hInstOld != 0)
FIXME("resources not in the current module not implemented\n");
if (lpReplace->hInstNew)
{
hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
hBitmap = hbmLoad;
}
else
{
hBitmap = (HBITMAP) lpReplace->nIDNew;
}
TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
......@@ -4222,11 +4185,17 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (nOldButtons == 0)
{
WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
if (hbmLoad)
DeleteObject (hbmLoad);
return FALSE;
}
/* copy the bitmap before adding it as ImageList_AddMasked modifies the
* bitmap
*/
if (lpReplace->hInstNew)
hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
else
hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
nOldBitmaps = ImageList_GetImageCount(himlDef);
......@@ -4237,35 +4206,9 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (hBitmap)
{
BITMAP bmp;
HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
HDC hdcImage, hdcBitmap;
/* copy the bitmap before adding it so that the user's bitmap
* doesn't get modified.
*/
GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
hdcImage = CreateCompatibleDC(0);
hdcBitmap = CreateCompatibleDC(0);
/* create new bitmap */
hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
/* Copy the user's image */
BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
hdcBitmap, 0, 0, SRCCOPY);
SelectObject (hdcImage, hOldBitmapLoad);
SelectObject (hdcBitmap, hOldBitmapBitmap);
DeleteDC (hdcImage);
DeleteDC (hdcBitmap);
ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
nNewBitmaps = ImageList_GetImageCount(himlDef);
DeleteObject (hbmLoad);
DeleteObject(hBitmap);
}
infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
......@@ -4274,9 +4217,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
pos, nOldBitmaps, nNewBitmaps);
InvalidateRect(hwnd, NULL, TRUE);
if (hbmLoad)
DeleteObject (hbmLoad);
return TRUE;
}
......
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