diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index be7e1013eb..0b96827dd6 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -71,7 +71,9 @@ protected: void GtkDisableEvents() const; void GtkEnableEvents() const; - virtual wxSize DoGetBestSize() const wxOVERRIDE; + // Update the number of digits used to match our range (and base). + void GtkSetEntryWidth(); + virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE; virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE; diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 76711360f9..6ed8512381 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -137,6 +137,8 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id, gtk_entry_set_alignment(GTK_ENTRY(m_widget), align); + GtkSetEntryWidth(); + gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget), (int)(m_windowStyle & wxSP_WRAP) ); @@ -271,6 +273,8 @@ void wxSpinCtrlGTKBase::DoSetRange(double minVal, double maxVal) gtk_spin_button_set_range( GTK_SPIN_BUTTON(m_widget), minVal, maxVal); InvalidateBestSize(); + + GtkSetEntryWidth(); } void wxSpinCtrlGTKBase::DoSetIncrement(double inc) @@ -355,11 +359,16 @@ GdkWindow *wxSpinCtrlGTKBase::GTKGetWindow(wxArrayGdkWindows& windows) const return NULL; } -wxSize wxSpinCtrlGTKBase::DoGetBestSize() const +void wxSpinCtrlGTKBase::GtkSetEntryWidth() { const int minVal = static_cast(DoGetMin()); const int maxVal = static_cast(DoGetMax()); - return wxSpinCtrlImpl::GetBestSize(this, minVal, maxVal, GetBase()); + + gtk_entry_set_width_chars + ( + GTK_ENTRY(m_widget), + wxSpinCtrlImpl::GetMaxValueLength(minVal, maxVal, GetBase()) + ); } wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const @@ -476,6 +485,8 @@ bool wxSpinCtrl::SetBase(int base) InvalidateBestSize(); + GtkSetEntryWidth(); + // Update the displayed text after changing the base it uses. SetValue(GetValue());