comctl32: toolbar: If wParam in TB_ADDBUTTON is large, enlarge the

bitmap before ImageList_AddMasked rather then call
ImageList_SetImagesCount after.
This commit is contained in:
Mikołaj Zalewski 2006-09-21 22:18:04 +02:00 committed by Alexandre Julliard
parent c77890d4f3
commit 8cbca5dcfd
3 changed files with 67 additions and 2 deletions

View file

@ -143,6 +143,7 @@ extern COMCTL32_SysColor comctl32_color;
HWND COMCTL32_CreateToolTip (HWND);
VOID COMCTL32_RefreshSysColors(void);
void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark, BOOL bHorizontal);
void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground);
INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
BOOL Str_SetPtrWtoA (LPSTR *lppDest, LPCWSTR lpSrc);

View file

@ -1448,6 +1448,67 @@ void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark
DeleteObject(hPen);
}
/***********************************************************************
* COMCTL32_EnsureBitmapSize [internal]
*
* If needed enlarge the bitmap so that the width is at least cxMinWidth
* the height is at least cyMinHeight. If the bitmap already have these
* dimensions nothing changes.
*
* PARAMS
* hBitmap [I/O] Bitmap to modify. The handle may change
* cxMinWidth [I] If the width of the bitmap is smaller then it will
* be enlarged to this value
* cyMinHeight [I] If the height of the bitmap is smaller then it will
* be enlarged to this value
* cyBackground [I] The color with which the new area will be filled
*
* RETURNS
* none
*/
void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground)
{
int cxNew, cyNew;
BITMAP bmp;
HBITMAP hNewBitmap;
HBITMAP hNewDCBitmap, hOldDCBitmap;
HBRUSH hNewDCBrush;
HDC hdcNew, hdcOld;
if (!GetObjectW(*pBitmap, sizeof(BITMAP), &bmp))
return;
cxNew = (cxMinWidth > bmp.bmWidth ? cxMinWidth : bmp.bmWidth);
cyNew = (cyMinHeight > bmp.bmHeight ? cyMinHeight : bmp.bmHeight);
if (cxNew == bmp.bmWidth && cyNew == bmp.bmHeight)
return;
hdcNew = CreateCompatibleDC(NULL);
hNewBitmap = CreateBitmap(cxNew, cyNew, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
hNewDCBitmap = SelectObject(hdcNew, hNewBitmap);
hNewDCBrush = SelectObject(hdcNew, CreateSolidBrush(crBackground));
hdcOld = CreateCompatibleDC(NULL);
hOldDCBitmap = SelectObject(hdcOld, *pBitmap);
BitBlt(hdcNew, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOld, 0, 0, SRCCOPY);
if (bmp.bmWidth < cxMinWidth)
PatBlt(hdcNew, bmp.bmWidth, 0, cxNew, bmp.bmHeight, PATCOPY);
if (bmp.bmHeight < cyMinHeight)
PatBlt(hdcNew, 0, bmp.bmHeight, bmp.bmWidth, cyNew, PATCOPY);
if (bmp.bmWidth < cxMinWidth && bmp.bmHeight < cyMinHeight)
PatBlt(hdcNew, bmp.bmWidth, bmp.bmHeight, cxNew, cyNew, PATCOPY);
SelectObject(hdcNew, hNewDCBitmap);
DeleteObject(SelectObject(hdcNew, hNewDCBrush));
DeleteDC(hdcNew);
SelectObject(hdcOld, hOldDCBitmap);
DeleteDC(hdcOld);
DeleteObject(*pBitmap);
*pBitmap = hNewBitmap;
return;
}
/***********************************************************************
* MirrorIcon [COMCTL32.414]
*

View file

@ -2578,6 +2578,7 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TB
HBITMAP hbmLoad;
INT nCountBefore = ImageList_GetImageCount(himlDef);
INT nCountAfter;
INT cxIcon, cyIcon;
INT nAdded;
INT nIndex;
@ -2613,6 +2614,10 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TB
}
else
hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
/* enlarge the bitmap if needed */
ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
DeleteObject(hbmLoad);
@ -2624,8 +2629,6 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TB
if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
{
ImageList_SetImageCount(himlDef, nCountBefore + 1);
} else if (nAdded < (INT)bitmap->nButtons) { /* if not enough buttons, grow the list */
ImageList_SetImageCount(himlDef, nCountBefore + bitmap->nButtons);
} else if (nAdded > (INT)bitmap->nButtons) {
TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
nCountBefore, nAdded, bitmap->nButtons, nCountAfter);