X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ef5c70f96f5e06e1c8f8119f51b99dd019583d2b..16487a6fde0a205051f4a8a573ef5da2158f4d83:/src/gtk/spinctrl.cpp diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 2cea9634f5..cc7b511f0a 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -18,6 +18,7 @@ #ifndef WX_PRECOMP #include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED #include "wx/utils.h" + #include "wx/wxcrtvararg.h" #endif #include "wx/gtk/private.h" @@ -36,10 +37,8 @@ extern "C" { static void gtk_value_changed(GtkSpinButton* spinbutton, wxSpinCtrl* win) { - if (g_isIdle) wxapp_install_idle_handler(); - win->m_pos = int(gtk_spin_button_get_value(spinbutton)); - if (!win->m_hasVMT || g_blockEventsOnDrag || win->m_blockScrollEvent) + if (!win->m_hasVMT || g_blockEventsOnDrag) return; wxCommandEvent event( wxEVT_COMMAND_SPINCTRL_UPDATED, win->GetId()); @@ -52,7 +51,7 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinCtrl* win) // values in range 5..50 is then, ummm, quite challenging (hint: you can't // enter 1!) (VZ) event.SetInt(win->m_pos); - win->GetEventHandler()->ProcessEvent( event ); + win->HandleWindowEvent( event ); } } @@ -64,18 +63,16 @@ extern "C" { static void gtk_changed(GtkSpinButton* spinbutton, wxSpinCtrl* win) { - if (g_isIdle) - wxapp_install_idle_handler(); - - if (!win->m_hasVMT || win->m_blockScrollEvent) + if (!win->m_hasVMT) return; wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() ); event.SetEventObject( win ); + event.SetString( GTK_ENTRY(spinbutton)->text ); // see above event.SetInt(win->m_pos); - win->GetEventHandler()->ProcessEvent( event ); + win->HandleWindowEvent( event ); } } @@ -101,9 +98,6 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, int min, int max, int initial, const wxString& name) { - m_needParent = true; - m_acceptsFocus = true; - if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { @@ -112,14 +106,14 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id, } m_widget = gtk_spin_button_new_with_range(min, max, 1); - gtk_spin_button_set_value((GtkSpinButton*)m_widget, initial); - m_pos = int(gtk_spin_button_get_value((GtkSpinButton*)m_widget)); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), initial); + m_pos = (int) gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget)); gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget), (int)(m_windowStyle & wxSP_WRAP) ); - g_signal_connect(m_widget, "value_changed", G_CALLBACK(gtk_value_changed), this); - g_signal_connect(m_widget, "changed", G_CALLBACK(gtk_changed), this); + g_signal_connect_after(m_widget, "value_changed", G_CALLBACK(gtk_value_changed), this); + g_signal_connect_after(m_widget, "changed", G_CALLBACK(gtk_changed), this); m_parent->DoAddChild( this ); @@ -138,7 +132,7 @@ int wxSpinCtrl::GetMin() const wxCHECK_MSG( (m_widget != NULL), 0, wxT("invalid spin button") ); double min; - gtk_spin_button_get_range((GtkSpinButton*)m_widget, &min, NULL); + gtk_spin_button_get_range( GTK_SPIN_BUTTON(m_widget), &min, NULL); return int(min); } @@ -147,7 +141,7 @@ int wxSpinCtrl::GetMax() const wxCHECK_MSG( (m_widget != NULL), 0, wxT("invalid spin button") ); double max; - gtk_spin_button_get_range((GtkSpinButton*)m_widget, NULL, &max); + gtk_spin_button_get_range( GTK_SPIN_BUTTON(m_widget), NULL, &max); return int(max); } @@ -155,9 +149,11 @@ int wxSpinCtrl::GetValue() const { wxCHECK_MSG( (m_widget != NULL), 0, wxT("invalid spin button") ); - wx_const_cast(wxSpinCtrl*, this)->BlockScrollEvent(); + GtkDisableEvents(); gtk_spin_button_update( GTK_SPIN_BUTTON(m_widget) ); - wx_const_cast(wxSpinCtrl*, this)->UnblockScrollEvent(); + wx_const_cast(wxSpinCtrl*, this)->m_pos = + int(gtk_spin_button_get_value(GTK_SPIN_BUTTON(m_widget))); + GtkEnableEvents(); return m_pos; } @@ -175,9 +171,9 @@ void wxSpinCtrl::SetValue( const wxString& value ) else { // invalid number - set text as is (wxMSW compatible) - BlockScrollEvent(); + GtkDisableEvents(); gtk_entry_set_text( GTK_ENTRY(m_widget), wxGTK_CONV( value ) ); - UnblockScrollEvent(); + GtkEnableEvents(); } } @@ -185,9 +181,10 @@ void wxSpinCtrl::SetValue( int value ) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); - BlockScrollEvent(); - gtk_spin_button_set_value((GtkSpinButton*)m_widget, value); - UnblockScrollEvent(); + GtkDisableEvents(); + gtk_spin_button_set_value( GTK_SPIN_BUTTON(m_widget), value); + m_pos = (int) gtk_spin_button_get_value( GTK_SPIN_BUTTON(m_widget)); + GtkEnableEvents(); } void wxSpinCtrl::SetSelection(long from, long to) @@ -207,9 +204,29 @@ void wxSpinCtrl::SetRange(int minVal, int maxVal) { wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") ); - BlockScrollEvent(); - gtk_spin_button_set_range((GtkSpinButton*)m_widget, minVal, maxVal); - UnblockScrollEvent(); + GtkDisableEvents(); + gtk_spin_button_set_range( GTK_SPIN_BUTTON(m_widget), minVal, maxVal); + m_pos = int(gtk_spin_button_get_value(GTK_SPIN_BUTTON(m_widget))); + GtkEnableEvents(); +} + + +void wxSpinCtrl::GtkDisableEvents() const +{ + g_signal_handlers_block_by_func( m_widget, + (gpointer)gtk_value_changed, (void*) this); + + g_signal_handlers_block_by_func(m_widget, + (gpointer)gtk_changed, (void*) this); +} + +void wxSpinCtrl::GtkEnableEvents() const +{ + g_signal_handlers_unblock_by_func(m_widget, + (gpointer)gtk_value_changed, (void*) this); + + g_signal_handlers_unblock_by_func(m_widget, + (gpointer)gtk_changed, (void*) this); } void wxSpinCtrl::OnChar( wxKeyEvent &event ) @@ -243,7 +260,7 @@ void wxSpinCtrl::OnChar( wxKeyEvent &event ) GtkSpinButton *gsb = GTK_SPIN_BUTTON(m_widget); wxString val = wxGTK_CONV_BACK( gtk_entry_get_text( &gsb->entry ) ); evt.SetString( val ); - if (GetEventHandler()->ProcessEvent(evt)) return; + if (HandleWindowEvent(evt)) return; } event.Skip();