From 8189ce89ed4855fb0871ce1a19959b730dc5ab30 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 May 2020 02:12:43 +0200 Subject: [PATCH] Improve wxTextCtrl::DoGetSizeFromTextSize() in wxOSX Always return fully initialized wxSize value, even if one of the input values is unspecified. Also use TEXTCTRL_BORDER_SIZE to make it slightly more clear what's going on. --- src/osx/textctrl_osx.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index caf9530137..4e64b8c530 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -241,9 +241,24 @@ wxSize wxTextCtrl::DoGetBestSize() const wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const { - wxSize size = wxDefaultSize; - if (xlen > 0) size.SetWidth(HasFlag(wxNO_BORDER) ? xlen + 4 : xlen + 9); - if (ylen > 0) size.SetHeight(HasFlag(wxNO_BORDER) ? ylen + 2 : ylen + 7); + wxSize size; + + // Initialize to defaults unless both components are specified (at least + // one of them should be, but the other one could be -1). + if ( xlen <= 0 || ylen <= 0 ) + size = DoGetBestSize(); + + // Use extra margin size which works under macOS 10.15 and also add the + // border for consistency with DoGetBestSize() -- we'll remove it below if + // it's not needed. + if ( xlen > 0 ) + size.x = xlen + 4 + TEXTCTRL_BORDER_SIZE; + if ( ylen > 0 ) + size.y = ylen + 2 + TEXTCTRL_BORDER_SIZE; + + if ( HasFlag(wxNO_BORDER) ) + size.DecBy(TEXTCTRL_BORDER_SIZE); + return size; }