From d2776b2fba0917abd0c45de337773bd93822febc Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 7 Oct 2019 16:40:04 +0700 Subject: [PATCH] Invalidate wxSpinCtrl best size when needed in wxGTK Also fix the initial min and best size. --- src/gtk/spinctrl.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 932bc4623d..eaeeea8b3c 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -267,6 +267,8 @@ void wxSpinCtrlGTKBase::DoSetRange(double minVal, double maxVal) wxSpinCtrlEventDisabler disable(this); gtk_spin_button_set_range( GTK_SPIN_BUTTON(m_widget), minVal, maxVal); + + InvalidateBestSize(); } void wxSpinCtrlGTKBase::DoSetIncrement(double inc) @@ -354,15 +356,8 @@ GdkWindow *wxSpinCtrlGTKBase::GTKGetWindow(wxArrayGdkWindows& windows) const wxSize wxSpinCtrlGTKBase::DoGetBestSize() const { const int minVal = static_cast(DoGetMin()); - const int lenMin = wxString::Format("%d", minVal).length(); - const int maxVal = static_cast(DoGetMax()); - const int lenMax = wxString::Format("%d", maxVal).length(); - - wxString longestText(wxMax(lenMin, lenMax), '9'); - if ( minVal < 0 ) - longestText.insert(0, "-"); - return DoGetSizeFromTextSize(GetTextExtent(longestText).x, -1); + return wxPrivate::wxSpinCtrlGetBestSize(this, minVal, maxVal, GetBase()); } wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const @@ -477,6 +472,11 @@ bool wxSpinCtrl::SetBase(int base) this); } + InvalidateBestSize(); + + // Update the displayed text after changing the base it uses. + SetValue(GetValue()); + return true; }