Adjust entry width of wxSpinCtrl in wxGTK to its range
Ensure that the entry is always (just) big enough to show any value valid in this spin control. This also ensures that GetBestSize() doesn't need to be overridden to use GetSizeFromTextSize() any longer as the best size will be determined correctly by GTK itself.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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<int>(DoGetMin());
|
||||
const int maxVal = static_cast<int>(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());
|
||||
|
||||
|
Reference in New Issue
Block a user