]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/slider.cpp
don't give an error when editing of the items label is cancelled (patch 1482176)
[wxWidgets.git] / src / gtk / slider.cpp
index 8cdeb4cc19c9a1bea88c840cbc57efd357c6efe7..6003bdf6fe4d68ca6a07d962c1a77b8a16981c8e 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        gtk/slider.cpp
+// Name:        src/gtk/slider.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#if wxUSE_SLIDER
+
 #include "wx/slider.h"
 
-#if wxUSE_SLIDER
+#ifndef WX_PRECOMP
+    #include "wx/utils.h"
+#endif
 
-#include "wx/utils.h"
 #include "wx/math.h"
 #include "wx/gtk/private.h"
 
-//-----------------------------------------------------------------------------
-// idle system
-//-----------------------------------------------------------------------------
-
-extern void wxapp_install_idle_handler();
-extern bool g_isIdle;
-
 //-----------------------------------------------------------------------------
 // data
 //-----------------------------------------------------------------------------
@@ -52,25 +48,34 @@ static inline int AdjustValueToInt(double x)
 static void
 ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue)
 {
-    int orient = win->GetWindowStyleFlag() & wxSL_VERTICAL ? wxVERTICAL
-                                                           : wxHORIZONTAL;
+    const int orient = win->HasFlag(wxSL_VERTICAL) ? wxVERTICAL
+                                                   : wxHORIZONTAL;
 
-    int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5);
-    wxScrollEvent event( evtType, win->GetId(), value, orient );
-    event.SetEventObject( win );
-    win->GetEventHandler()->ProcessEvent( event );
+    const int value = (int)(dvalue < 0 ? dvalue - 0.5 : dvalue + 0.5);
+
+    // if we have any "special" event (i.e. the value changed by a line or a
+    // page), send this specific event first
+    if ( evtType != wxEVT_NULL )
+    {
+        wxScrollEvent event( evtType, win->GetId(), value, orient );
+        event.SetEventObject( win );
+        win->GetEventHandler()->ProcessEvent( event );
+    }
 
+    // but, in any case, except if we're dragging the slider (and so the change
+    // is not definitive), send a generic "changed" event
     if ( evtType != wxEVT_SCROLL_THUMBTRACK )
     {
-        wxScrollEvent event2(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
-        event2.SetEventObject( win );
-        win->GetEventHandler()->ProcessEvent( event2 );
+        wxScrollEvent event(wxEVT_SCROLL_CHANGED, win->GetId(), value, orient);
+        event.SetEventObject( win );
+        win->GetEventHandler()->ProcessEvent( event );
     }
 
-    wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() );
-    cevent.SetEventObject( win );
-    cevent.SetInt( value );
-    win->GetEventHandler()->ProcessEvent( cevent );
+    // and also generate a command event for compatibility
+    wxCommandEvent event( wxEVT_COMMAND_SLIDER_UPDATED, win->GetId() );
+    event.SetEventObject( win );
+    event.SetInt( value );
+    win->GetEventHandler()->ProcessEvent( event );
 }
 
 //-----------------------------------------------------------------------------
@@ -79,7 +84,6 @@ ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue)
 
 extern "C" {
 static void gtk_slider_callback( GtkAdjustment *adjust,
-                                 SCROLLBAR_CBACK_ARG
                                  wxSlider *win )
 {
     if (g_isIdle) wxapp_install_idle_handler();
@@ -108,6 +112,8 @@ static void gtk_slider_callback( GtkAdjustment *adjust,
         evtType = wxEVT_SCROLL_TOP;
     else if ( AreSameAdjustValues(adjust->value, adjust->upper) )
         evtType = wxEVT_SCROLL_BOTTOM;
+    else
+        evtType = wxEVT_NULL; // wxEVT_SCROLL_CHANGED will still be generated
 
     ProcessScrollEvent(win, evtType, dvalue);
 
@@ -150,14 +156,14 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
         const wxPoint& pos, const wxSize& size,
         long style, const wxValidator& validator, const wxString& name )
 {
-    m_acceptsFocus = TRUE;
-    m_needParent = TRUE;
+    m_acceptsFocus = true;
+    m_needParent = true;
 
     if (!PreCreation( parent, pos, size ) ||
         !CreateBase( parent, id, pos, size, style, validator, name ))
     {
         wxFAIL_MSG( wxT("wxSlider creation failed") );
-        return FALSE;
+        return false;
     }
 
     m_oldPos = 0.0;
@@ -202,14 +208,12 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
         gtk_range_set_inverted( GTK_RANGE(m_widget), TRUE );
 
     GtkEnableEvents();
-    gtk_signal_connect( GTK_OBJECT(m_widget),
-                        "button_press_event",
-                        (GtkSignalFunc)gtk_slider_button_press_callback,
-                        (gpointer) this );
-    gtk_signal_connect( GTK_OBJECT(m_widget),
-                        "button_release_event",
-                        (GtkSignalFunc)gtk_slider_button_release_callback,
-                        (gpointer) this );
+    g_signal_connect (m_widget, "button_press_event",
+                      G_CALLBACK (gtk_slider_button_press_callback),
+                      this);
+    g_signal_connect (m_widget, "button_release_event",
+                      G_CALLBACK (gtk_slider_button_release_callback),
+                      this);
 
     SetRange( minValue, maxValue );
     SetValue( value );
@@ -218,7 +222,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
 
     PostCreation(size);
 
-    return TRUE;
+    return true;
 }
 
 int wxSlider::GetValue() const
@@ -237,7 +241,7 @@ void wxSlider::SetValue( int value )
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
+    g_signal_emit_by_name (m_adjust, "value_changed");
 
     GtkEnableEvents();
 }
@@ -260,7 +264,7 @@ void wxSlider::SetRange( int minValue, int maxValue )
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
@@ -285,7 +289,7 @@ void wxSlider::SetPageSize( int pageSize )
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
@@ -305,7 +309,7 @@ void wxSlider::SetThumbLength( int len )
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
@@ -332,17 +336,15 @@ bool wxSlider::IsOwnGtkWindow( GdkWindow *window )
 
 void wxSlider::GtkDisableEvents()
 {
-    gtk_signal_disconnect_by_func( GTK_OBJECT(m_adjust),
-                        GTK_SIGNAL_FUNC(gtk_slider_callback),
-                        (gpointer) this );
+    g_signal_handlers_disconnect_by_func (m_adjust,
+                                          (gpointer) gtk_slider_callback,
+                                          this);
 }
 
 void wxSlider::GtkEnableEvents()
 {
-    gtk_signal_connect( GTK_OBJECT (m_adjust),
-                        "value_changed",
-                        GTK_SIGNAL_FUNC(gtk_slider_callback),
-                        (gpointer) this );
+    g_signal_connect (m_adjust, "value_changed",
+                      G_CALLBACK (gtk_slider_callback), this);
 }
 
 // static
@@ -352,4 +354,4 @@ wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
     return GetDefaultAttributesFromGTKWidget(gtk_vscale_new);
 }
 
-#endif
+#endif // wxUSE_SLIDER