From: Ivan Ivlev <iviv@etersoft.ru> Signed-off-by: Ivan Ivlev <iviv@etersoft.ru> --- dlls/comctl32/toolbar.c | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c index 3826b18d4c6..5dffa4687c9 100644 --- a/dlls/comctl32/toolbar.c +++ b/dlls/comctl32/toolbar.c @@ -248,6 +248,7 @@ static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_IN static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button); static LRESULT TOOLBAR_SetButtonInfo(TOOLBAR_INFO *infoPtr, INT Id, const TBBUTTONINFOW *lptbbi, BOOL isW); +static int TOOLBAR_AutoSizeButtonWidth(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, int btnIdx); static inline int default_top_margin(const TOOLBAR_INFO *infoPtr) @@ -1414,6 +1415,8 @@ TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr) else if ((btnPtr[i].fsStyle & BTNS_SEP) && !(infoPtr->dwStyle & CCS_VERT)) cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH; + else if (btnPtr[i].fsStyle & BTNS_AUTOSIZE) + cx = TOOLBAR_AutoSizeButtonWidth(infoPtr, &btnPtr[i], i); else cx = infoPtr->nButtonWidth; @@ -1687,6 +1690,27 @@ static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeS return sizeButton; } +static int +TOOLBAR_AutoSizeButtonWidth(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, int btnIdx) +{ + SIZE sz, sizeButton; + HDC hdc; + HFONT hOldFont; + BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0); + + hdc = GetDC (infoPtr->hwndSelf); + hOldFont = SelectObject (hdc, infoPtr->hFont); + + TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz); + + SelectObject (hdc, hOldFont); + ReleaseDC (infoPtr->hwndSelf, hdc); + + sizeButton = TOOLBAR_MeasureButton(infoPtr, sz, + TOOLBAR_IsValidBitmapIndex(infoPtr, btnPtr[btnIdx].iBitmap), + validImageList); + return sizeButton.cx; +} /*********************************************************************** * TOOLBAR_CalcToolbar @@ -1727,11 +1751,9 @@ static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr) { TBUTTON_INFO *btnPtr; - SIZE sizeButton; INT i, nRows, nSepRows; INT x, y, cx, cy; BOOL bWrap; - BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0); TOOLBAR_WrapToolbar(infoPtr); @@ -1777,24 +1799,7 @@ TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr) if (btnPtr->cx) cx = btnPtr->cx; else if (btnPtr->fsStyle & BTNS_AUTOSIZE) - { - SIZE sz; - HDC hdc; - HFONT hOldFont; - - hdc = GetDC (infoPtr->hwndSelf); - hOldFont = SelectObject (hdc, infoPtr->hFont); - - TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz); - - SelectObject (hdc, hOldFont); - ReleaseDC (infoPtr->hwndSelf, hdc); - - sizeButton = TOOLBAR_MeasureButton(infoPtr, sz, - TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap), - validImageList); - cx = sizeButton.cx; - } + cx = TOOLBAR_AutoSizeButtonWidth(infoPtr, btnPtr, i); else cx = infoPtr->nButtonWidth; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10261