comctl32: toolbar: Copy bitmaps with CopyImage so that it works also for DIBs (based on a patch by Oleg Krylov).

This commit is contained in:
Mikołaj Zalewski 2007-02-06 23:12:46 +01:00 committed by Alexandre Julliard
parent 79e265accd
commit dadc4248cf
1 changed files with 11 additions and 71 deletions

View File

@ -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); TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
/* Add bitmaps to the default image list */ /* Add bitmaps to the default image list */
if (bitmap->hInst == NULL) /* a handle was passed */ if (bitmap->hInst == NULL) /* a handle was passed */
{ hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
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);
}
else else
hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0); 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); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam; LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
HBITMAP hBitmap; HBITMAP hBitmap;
HBITMAP hbmLoad = NULL;
int i = 0, nOldButtons = 0, pos = 0; int i = 0, nOldButtons = 0, pos = 0;
int nOldBitmaps, nNewBitmaps = 0; int nOldBitmaps, nNewBitmaps = 0;
HIMAGELIST himlDef = 0; HIMAGELIST himlDef = 0;
@ -4192,16 +4165,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
else if (lpReplace->hInstOld != 0) else if (lpReplace->hInstOld != 0)
FIXME("resources not in the current module not implemented\n"); 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); TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
for (i = 0; i < infoPtr->nNumBitmapInfos; i++) { for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
TBITMAP_INFO *tbi = &infoPtr->bitmaps[i]; TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
@ -4222,11 +4185,17 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (nOldButtons == 0) if (nOldButtons == 0)
{ {
WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld); WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
if (hbmLoad)
DeleteObject (hbmLoad);
return FALSE; 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? */ himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
nOldBitmaps = ImageList_GetImageCount(himlDef); nOldBitmaps = ImageList_GetImageCount(himlDef);
@ -4237,35 +4206,9 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
if (hBitmap) if (hBitmap)
{ {
BITMAP bmp; ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
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);
nNewBitmaps = ImageList_GetImageCount(himlDef); nNewBitmaps = ImageList_GetImageCount(himlDef);
DeleteObject (hbmLoad); DeleteObject(hBitmap);
} }
infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps; infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
@ -4274,9 +4217,6 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
pos, nOldBitmaps, nNewBitmaps); pos, nOldBitmaps, nNewBitmaps);
InvalidateRect(hwnd, NULL, TRUE); InvalidateRect(hwnd, NULL, TRUE);
if (hbmLoad)
DeleteObject (hbmLoad);
return TRUE; return TRUE;
} }