From 8cbca5dcfd5d3d8df4152b5552f4315de4b8eeb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Zalewski?= Date: Thu, 21 Sep 2006 22:18:04 +0200 Subject: [PATCH] comctl32: toolbar: If wParam in TB_ADDBUTTON is large, enlarge the bitmap before ImageList_AddMasked rather then call ImageList_SetImagesCount after. --- dlls/comctl32/comctl32.h | 1 + dlls/comctl32/commctrl.c | 61 ++++++++++++++++++++++++++++++++++++++++ dlls/comctl32/toolbar.c | 7 +++-- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h index f6d233ff2fd..66a0973183c 100644 --- a/dlls/comctl32/comctl32.h +++ b/dlls/comctl32/comctl32.h @@ -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); diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c index 5cfc24cf844..81f5f86e000 100644 --- a/dlls/comctl32/commctrl.c +++ b/dlls/comctl32/commctrl.c @@ -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] * diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c index 164a2fef6cc..fe26ac1b378 100644 --- a/dlls/comctl32/toolbar.c +++ b/dlls/comctl32/toolbar.c @@ -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);