diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 60e464c85a..0db4cb0b39 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -71,8 +71,9 @@ protected: void GtkDisableEvents(); void GtkEnableEvents(); - // Update the number of digits used to match our range (and base). - void GtkSetEntryWidth(); + // Update the width of the entry field to fit the current range (and also + // base or number of digits depending on the derived class). + virtual void GtkSetEntryWidth() = 0; virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const wxOVERRIDE; virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE; @@ -136,6 +137,9 @@ public: virtual int GetBase() const wxOVERRIDE { return m_base; } virtual bool SetBase(int base) wxOVERRIDE; +protected: + virtual void GtkSetEntryWidth() wxOVERRIDE; + private: // Common part of all ctors. void Init() @@ -201,6 +205,9 @@ public: virtual int GetBase() const wxOVERRIDE { return 10; } virtual bool SetBase(int WXUNUSED(base)) wxOVERRIDE { return false; } +protected: + virtual void GtkSetEntryWidth() wxOVERRIDE; + wxDECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble); }; diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index ebc501113b..85205b652a 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -353,18 +353,6 @@ GdkWindow *wxSpinCtrlGTKBase::GTKGetWindow(wxArrayGdkWindows& windows) const return NULL; } -void wxSpinCtrlGTKBase::GtkSetEntryWidth() -{ - const int minVal = static_cast(DoGetMin()); - const int maxVal = static_cast(DoGetMax()); - - gtk_entry_set_width_chars - ( - GTK_ENTRY(m_widget), - wxSpinCtrlImpl::GetMaxValueLength(minVal, maxVal, GetBase()) - ); -} - wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const { wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") ); @@ -436,6 +424,18 @@ wx_gtk_spin_output(GtkSpinButton* spin, wxSpinCtrl* win) } // extern "C" +void wxSpinCtrl::GtkSetEntryWidth() +{ + const int minVal = static_cast(DoGetMin()); + const int maxVal = static_cast(DoGetMax()); + + gtk_entry_set_width_chars + ( + GTK_ENTRY(m_widget), + wxSpinCtrlImpl::GetMaxValueLength(minVal, maxVal, GetBase()) + ); +} + bool wxSpinCtrl::SetBase(int base) { // Currently we only support base 10 and 16. We could add support for base @@ -485,6 +485,15 @@ bool wxSpinCtrl::SetBase(int base) wxIMPLEMENT_DYNAMIC_CLASS(wxSpinCtrlDouble, wxSpinCtrlGTKBase); +void wxSpinCtrlDouble::GtkSetEntryWidth() +{ + const unsigned digits = GetDigits(); + const int lenMin = wxString::Format("%.*f", digits, GetMin()).length(); + const int lenMax = wxString::Format("%.*f", digits, GetMax()).length(); + + gtk_entry_set_width_chars(GTK_ENTRY(m_widget), wxMax(lenMin, lenMax)); +} + unsigned wxSpinCtrlDouble::GetDigits() const { wxCHECK_MSG( m_widget, 0, "invalid spin button" ); @@ -498,6 +507,10 @@ void wxSpinCtrlDouble::SetDigits(unsigned digits) wxSpinCtrlEventDisabler disable(this); gtk_spin_button_set_digits( GTK_SPIN_BUTTON(m_widget), digits); + + InvalidateBestSize(); + + GtkSetEntryWidth(); } #endif // wxUSE_SPINCTRL