X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/738f9e5a12b8bb3936cc10347be98390602d3660..8aaef28406647d6aa706c34f57dd151f00b18e5b:/src/gtk/spinctrl.cpp diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index bf19e51002..7b40f4ccbe 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -86,10 +86,11 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl,wxControl) bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, - long style, - int min, int max, int initial, - const wxString& name) + const wxString& value, + const wxPoint& pos, const wxSize& size, + long style, + int min, int max, int initial, + const wxString& name) { m_needParent = TRUE; @@ -123,6 +124,8 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, SetBackgroundColour( parent->GetBackgroundColour() ); + SetValue( value ); + Show( TRUE ); return TRUE; @@ -149,6 +152,23 @@ int wxSpinCtrl::GetValue() const return (int)ceil(m_adjust->value); } +void wxSpinCtrl::SetValue( const wxString& value ) +{ + wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); + + int n; + if ( (wxSscanf(value, wxT("%d"), &n) == 1) ) + { + // a number - set it + SetValue(n); + } + else + { + // invalid number - set text as is (wxMSW compatible) + gtk_entry_set_text( GTK_ENTRY(m_widget), value.c_str() ); + } +} + void wxSpinCtrl::SetValue( int value ) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );