]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/slider.cpp
fixing Clipboard::IsSupported when asking for unicode text and only non-unicode text...
[wxWidgets.git] / src / gtk / slider.cpp
index 8cdeb4cc19c9a1bea88c840cbc57efd357c6efe7..bcaacf7a7373bdba08b0a7ffeaab230075d49c37 100644 (file)
 #include "wx/math.h"
 #include "wx/gtk/private.h"
 
 #include "wx/math.h"
 #include "wx/gtk/private.h"
 
-//-----------------------------------------------------------------------------
-// idle system
-//-----------------------------------------------------------------------------
-
-extern void wxapp_install_idle_handler();
-extern bool g_isIdle;
-
 //-----------------------------------------------------------------------------
 // data
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // data
 //-----------------------------------------------------------------------------
@@ -52,25 +45,34 @@ static inline int AdjustValueToInt(double x)
 static void
 ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue)
 {
 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 )
     {
     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 +81,6 @@ ProcessScrollEvent(wxSlider *win, wxEventType evtType, double dvalue)
 
 extern "C" {
 static void gtk_slider_callback( GtkAdjustment *adjust,
 
 extern "C" {
 static void gtk_slider_callback( GtkAdjustment *adjust,
-                                 SCROLLBAR_CBACK_ARG
                                  wxSlider *win )
 {
     if (g_isIdle) wxapp_install_idle_handler();
                                  wxSlider *win )
 {
     if (g_isIdle) wxapp_install_idle_handler();
@@ -108,6 +109,8 @@ static void gtk_slider_callback( GtkAdjustment *adjust,
         evtType = wxEVT_SCROLL_TOP;
     else if ( AreSameAdjustValues(adjust->value, adjust->upper) )
         evtType = wxEVT_SCROLL_BOTTOM;
         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);
 
 
     ProcessScrollEvent(win, evtType, dvalue);
 
@@ -202,14 +205,12 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
         gtk_range_set_inverted( GTK_RANGE(m_widget), TRUE );
 
     GtkEnableEvents();
         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 );
 
     SetRange( minValue, maxValue );
     SetValue( value );
@@ -237,7 +238,7 @@ void wxSlider::SetValue( int value )
 
     GtkDisableEvents();
 
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
+    g_signal_emit_by_name (m_adjust, "value_changed");
 
     GtkEnableEvents();
 }
 
     GtkEnableEvents();
 }
@@ -260,7 +261,7 @@ void wxSlider::SetRange( int minValue, int maxValue )
 
     GtkDisableEvents();
 
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
 
     GtkEnableEvents();
 }
@@ -285,7 +286,7 @@ void wxSlider::SetPageSize( int pageSize )
 
     GtkDisableEvents();
 
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
 
     GtkEnableEvents();
 }
@@ -305,7 +306,7 @@ void wxSlider::SetThumbLength( int len )
 
     GtkDisableEvents();
 
 
     GtkDisableEvents();
 
-    gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
+    g_signal_emit_by_name (m_adjust, "changed");
 
     GtkEnableEvents();
 }
 
     GtkEnableEvents();
 }
@@ -332,17 +333,15 @@ bool wxSlider::IsOwnGtkWindow( GdkWindow *window )
 
 void wxSlider::GtkDisableEvents()
 {
 
 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()
 {
 }
 
 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
 }
 
 // static