Mikołaj Zalewski : comctl32: toolbar: If wParam in TB_ADDBUTTON is large, enlarge the
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Sep 26 05:30:00 CDT 2006
Module: wine
Branch: master
Commit: 8cbca5dcfd5d3d8df4152b5552f4315de4b8eeb6
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=8cbca5dcfd5d3d8df4152b5552f4315de4b8eeb6
Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date: Thu Sep 21 22:18:04 2006 +0200
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 f6d233f..66a0973 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 5cfc24c..81f5f86 100644
--- a/dlls/comctl32/commctrl.c
+++ b/dlls/comctl32/commctrl.c
@@ -1449,6 +1449,67 @@ void COMCTL32_DrawInsertMark(HDC hDC, co
}
/***********************************************************************
+ * 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]
*
* Mirrors an icon so that it will appear correctly on a mirrored DC.
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 164a2fe..fe26ac1 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -2578,6 +2578,7 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INF
HBITMAP hbmLoad;
INT nCountBefore = ImageList_GetImageCount(himlDef);
INT nCountAfter;
+ INT cxIcon, cyIcon;
INT nAdded;
INT nIndex;
@@ -2613,6 +2614,10 @@ TOOLBAR_AddBitmapToImageList(TOOLBAR_INF
}
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_INF
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);
More information about the wine-cvs
mailing list