X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/738f9e5a12b8bb3936cc10347be98390602d3660..59fe1666ce79d76b7decec871801c7622a789299:/src/gtk1/spinctrl.cpp?ds=sidebyside diff --git a/src/gtk1/spinctrl.cpp b/src/gtk1/spinctrl.cpp index bf19e51002..7f04c11479 100644 --- a/src/gtk1/spinctrl.cpp +++ b/src/gtk1/spinctrl.cpp @@ -85,13 +85,19 @@ static void gtk_spinctrl_callback( GtkWidget *WXUNUSED(widget), wxSpinCtrl *win IMPLEMENT_DYNAMIC_CLASS(wxSpinCtrl,wxControl) +BEGIN_EVENT_TABLE(wxSpinCtrl, wxControl) + EVT_CHAR(wxSpinCtrl::OnChar) +END_EVENT_TABLE() + 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; + m_acceptsFocus = TRUE; wxSize new_size = size; if (new_size.y == -1) @@ -123,6 +129,8 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, SetBackgroundColour( parent->GetBackgroundColour() ); + SetValue( value ); + Show( TRUE ); return TRUE; @@ -149,6 +157,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.mbc_str() ); + } +} + void wxSpinCtrl::SetValue( int value ) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); @@ -185,6 +210,27 @@ void wxSpinCtrl::SetRange(int minVal, int maxVal) SetFocus(); } +void wxSpinCtrl::OnChar( wxKeyEvent &event ) +{ + wxCHECK_RET( m_widget != NULL, wxT("invalid spin ctrl") ); + + if (event.KeyCode() == WXK_RETURN) + { + wxWindow *top_frame = m_parent; + while (top_frame->GetParent() && !(top_frame->GetParent()->m_isFrame)) + top_frame = top_frame->GetParent(); + GtkWindow *window = GTK_WINDOW(top_frame->m_widget); + + if (window->default_widget) + { + gtk_widget_activate (window->default_widget); + return; + } + } + + event.Skip(); +} + bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window ) { return GTK_SPIN_BUTTON(m_widget)->panel == window;