From dce65bed1ca463b75c0ec948f6f54b258f663e37 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2019 17:13:36 +0200 Subject: [PATCH] Fix width returned by wxSpinCtrl::GetSizeFromTextSize() in wxMSW Since the changes of 05b980aba1db842b9be77deae58af3bfffb92d1d, this function returned a value which was too small because the code in it never accounted for the text control margins, but this was hidden by a weird hack adding extra "3*y/10 + 10" pixels to the horizontal extent which was removed by the commit above. Really fix it now by reusing wxTextCtrl::GetSizeFromTextSize() which correctly accounts for the margins and everything else. See #12297. Closes #18391. --- src/msw/spinctrl.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 058e08ed3d..1835296b47 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -734,21 +734,14 @@ wxSize wxSpinCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const { wxSize sizeBtn = wxSpinButton::DoGetBestSize(); - int y; - wxGetCharSize(GetHWND(), NULL, &y, GetFont()); - // JACS: we should always use the height calculated - // from above, because otherwise we'll get a spin control - // that's too big. So never use the height calculated - // from wxSpinButton::DoGetBestSize(). + // Create a temporary wxTextCtrl wrapping our existing HWND in order to be + // able to reuse its GetSizeFromTextSize() implementation. + wxTextCtrl text; + TempHWNDSetter set(&text, m_hwndBuddy); - wxSize tsize(xlen + sizeBtn.x - GetOverlap(), - EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); - - // Check if the user requested a non-standard height. - if ( ylen > 0 ) - tsize.IncBy(0, ylen - y); - - return tsize; + // Increase the width to accommodate the button, which should fit inside + // the text control while taking account of the overlap. + return text.GetSizeFromTextSize(xlen + sizeBtn.x - GetOverlap(), ylen); } void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)