]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/spinbutt.cpp
Wrong order of calls
[wxWidgets.git] / src / gtk / spinbutt.cpp
index 86f7f8f5bf7194459ab0edf9b16de493566dc94f..45138d8ae483481fc4baffeeb43d91499e0eecf1 100644 (file)
@@ -38,7 +38,7 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win)
     const double value = gtk_spin_button_get_value(spinbutton);
     const int pos = int(value);
     const int oldPos = win->m_pos;
-    if (!win->m_hasVMT || g_blockEventsOnDrag || win->m_blockScrollEvent || pos == oldPos)
+    if (!win->m_hasVMT || g_blockEventsOnDrag || pos == oldPos)
     {
         win->m_pos = pos;
         return;
@@ -48,13 +48,13 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win)
     event.SetPosition(pos);
     event.SetEventObject(win);
 
-    if ((win->GetEventHandler()->ProcessEvent( event )) &&
+    if ((win->HandleWindowEvent( event )) &&
         !event.IsAllowed() )
     {
         /* program has vetoed */
-        win->BlockScrollEvent();
+        // this will cause another "value_changed" signal,
+        // but because pos == oldPos nothing will happen
         gtk_spin_button_set_value(spinbutton, oldPos);
-        win->UnblockScrollEvent();
         return;
     }
 
@@ -64,7 +64,7 @@ gtk_value_changed(GtkSpinButton* spinbutton, wxSpinButton* win)
     wxSpinEvent event2(wxEVT_SCROLL_THUMBTRACK, win->GetId());
     event2.SetPosition(pos);
     event2.SetEventObject(win);
-    win->GetEventHandler()->ProcessEvent(event2);
+    win->HandleWindowEvent(event2);
 }
 }
 
@@ -91,8 +91,6 @@ bool wxSpinButton::Create(wxWindow *parent,
                           long style,
                           const wxString& name)
 {
-    m_needParent = true;
-
     wxSize new_size = size,
            sizeBest = DoGetBestSize();
     new_size.x = sizeBest.x;            // override width always
@@ -109,6 +107,7 @@ bool wxSpinButton::Create(wxWindow *parent,
     m_pos = 0;
 
     m_widget = gtk_spin_button_new_with_range(0, 100, 1);
+    g_object_ref(m_widget);
 
     gtk_spin_button_set_wrap( GTK_SPIN_BUTTON(m_widget),
                               (int)(m_windowStyle & wxSP_WRAP) );
@@ -152,18 +151,20 @@ void wxSpinButton::SetValue( int value )
 {
     wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
 
-    BlockScrollEvent();
+    GtkDisableEvents();
     gtk_spin_button_set_value((GtkSpinButton*)m_widget, value);
-    UnblockScrollEvent();
+    m_pos = int(gtk_spin_button_get_value((GtkSpinButton*)m_widget));
+    GtkEnableEvents();
 }
 
 void wxSpinButton::SetRange(int minVal, int maxVal)
 {
     wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
 
-    BlockScrollEvent();
+    GtkDisableEvents();
     gtk_spin_button_set_range((GtkSpinButton*)m_widget, minVal, maxVal);
-    UnblockScrollEvent();
+    m_pos = int(gtk_spin_button_get_value((GtkSpinButton*)m_widget));
+    GtkEnableEvents();
 }
 
 void wxSpinButton::OnSize( wxSizeEvent &WXUNUSED(event) )
@@ -174,6 +175,18 @@ void wxSpinButton::OnSize( wxSizeEvent &WXUNUSED(event) )
     gtk_widget_set_size_request( m_widget, m_width, m_height );
 }
 
+void wxSpinButton::GtkDisableEvents() const
+{
+    g_signal_handlers_block_by_func(m_widget,
+        (gpointer)gtk_value_changed, (void*) this);
+}
+
+void wxSpinButton::GtkEnableEvents() const
+{
+    g_signal_handlers_unblock_by_func(m_widget,
+        (gpointer)gtk_value_changed, (void*) this);
+}
+
 GdkWindow *wxSpinButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
 {
     return GTK_SPIN_BUTTON(m_widget)->panel;