Fix width returned by wxSpinCtrl::GetSizeFromTextSize() in wxMSW

Since the changes of 05b980aba1, 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.
This commit is contained in:
Vadim Zeitlin 2019-04-25 17:13:36 +02:00
parent 2aef6570bb
commit dce65bed1c

View File

@ -734,21 +734,14 @@ wxSize wxSpinCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
{ {
wxSize sizeBtn = wxSpinButton::DoGetBestSize(); wxSize sizeBtn = wxSpinButton::DoGetBestSize();
int y; // Create a temporary wxTextCtrl wrapping our existing HWND in order to be
wxGetCharSize(GetHWND(), NULL, &y, GetFont()); // able to reuse its GetSizeFromTextSize() implementation.
// JACS: we should always use the height calculated wxTextCtrl text;
// from above, because otherwise we'll get a spin control TempHWNDSetter set(&text, m_hwndBuddy);
// that's too big. So never use the height calculated
// from wxSpinButton::DoGetBestSize().
wxSize tsize(xlen + sizeBtn.x - GetOverlap(), // Increase the width to accommodate the button, which should fit inside
EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); // the text control while taking account of the overlap.
return text.GetSizeFromTextSize(xlen + sizeBtn.x - GetOverlap(), ylen);
// Check if the user requested a non-standard height.
if ( ylen > 0 )
tsize.IncBy(0, ylen - y);
return tsize;
} }
void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)