]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/spinctrl.cpp
corrected off by 1 error in cMB2WC() call (thanks valgrind)
[wxWidgets.git] / src / gtk / spinctrl.cpp
index 0e91452d8c05d58555b62c2d121c0c25d9bea81e..d14e452c6cc495d39c0733f20d0a0995c592c6a8 100644 (file)
@@ -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,8 +37,6 @@ 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)
         return;
@@ -64,14 +63,12 @@ extern "C" {
 static void
 gtk_changed(GtkSpinButton* spinbutton, wxSpinCtrl* win)
 {
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-
     if (!win->m_hasVMT || win->m_blockScrollEvent)
         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);
@@ -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 ))
     {
@@ -118,8 +112,8 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
     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 );
 
@@ -155,9 +149,9 @@ 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();
+    GtkEnableEvents();
 
     return m_pos;
 }
@@ -175,9 +169,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 +179,9 @@ void wxSpinCtrl::SetValue( int value )
 {
     wxCHECK_RET( (m_widget != NULL), wxT("invalid spin button") );
 
-    BlockScrollEvent();
+    GtkDisableEvents();
     gtk_spin_button_set_value((GtkSpinButton*)m_widget, value);
-    UnblockScrollEvent();
+    GtkEnableEvents();
 }
 
 void wxSpinCtrl::SetSelection(long from, long to)
@@ -207,9 +201,28 @@ void wxSpinCtrl::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();
+    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 )
@@ -249,16 +262,20 @@ void wxSpinCtrl::OnChar( wxKeyEvent &event )
     event.Skip();
 }
 
-bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window )
+GdkWindow *wxSpinCtrl::GTKGetWindow(wxArrayGdkWindows& windows) const
 {
     GtkSpinButton* spinbutton = GTK_SPIN_BUTTON(m_widget);
-    return window == spinbutton->entry.text_area || window == spinbutton->panel;
+
+    windows.push_back(spinbutton->entry.text_area);
+    windows.push_back(spinbutton->panel);
+
+    return NULL;
 }
 
 wxSize wxSpinCtrl::DoGetBestSize() const
 {
     wxSize ret( wxControl::DoGetBestSize() );
-    wxSize best(95, ret.y);
+    wxSize best(95, ret.y); // FIXME: 95?
     CacheBestSize(best);
     return best;
 }