[gtk+/gtk-2-24] range: add a primary-button-warps-slider style property



commit cc7abf6a1cccd66a802c5272cd2ac6c944962c78
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 3 11:43:04 2012 -0400

    range: add a primary-button-warps-slider style property
    
    Setting this to TRUE (it's FALSE by default) enables the behavior we
    have in GTK3 for scrollbars.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683279

 gtk/gtkrange.c |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 3932976..5fcbef0 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -532,6 +532,12 @@ gtk_range_class_init (GtkRangeClass *class)
 							     G_MAXINT,
 							     0,
 							     GTK_PARAM_READABLE));
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_boolean ("primary-button-warps-slider",
+                                                                 P_("Primary button warps slider"),
+                                                                 P_("Whether a primary click on the trough should warp the slider into position"),
+                                                                 FALSE,
+                                                                 GTK_PARAM_READABLE));
 
   /**
    * GtkRange:activate-slider:
@@ -2310,6 +2316,8 @@ gtk_range_button_press (GtkWidget      *widget,
 			GdkEventButton *event)
 {
   GtkRange *range = GTK_RANGE (widget);
+  gboolean primary_warps;
+  gint page_increment_button, warp_button;
   
   if (!gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
@@ -2322,11 +2330,25 @@ gtk_range_button_press (GtkWidget      *widget,
   range->layout->mouse_y = event->y;
   if (gtk_range_update_mouse_location (range))
     gtk_widget_queue_draw (widget);
-    
+
+  gtk_widget_style_get (widget,
+                        "primary-button-warps-slider", &primary_warps,
+                        NULL);
+  if (primary_warps)
+    {
+      warp_button = 1;
+      page_increment_button = 3;
+    }
+  else
+    {
+      warp_button = 2;
+      page_increment_button = 1;
+    }
+
   if (range->layout->mouse_location == MOUSE_TROUGH  &&
-      event->button == 1)
+      event->button == page_increment_button)
     {
-      /* button 1 steps by page increment, as with button 2 on a stepper
+      /* this button steps by page increment, as with button 2 on a stepper
        */
       GtkScrollType scroll;
       gdouble click_value;
@@ -2369,18 +2391,17 @@ gtk_range_button_press (GtkWidget      *widget,
       return TRUE;
     }
   else if ((range->layout->mouse_location == MOUSE_TROUGH &&
-            event->button == 2) ||
+            event->button == warp_button) ||
            range->layout->mouse_location == MOUSE_SLIDER)
     {
       gboolean need_value_update = FALSE;
       gboolean activate_slider;
 
       /* Any button can be used to drag the slider, but you can start
-       * dragging the slider with a trough click using button 2;
-       * On button 2 press, we warp the slider to mouse position,
-       * then begin the slider drag.
+       * dragging the slider with a trough click using the warp button;
+       * we warp the slider to mouse position, then begin the slider drag.
        */
-      if (event->button == 2)
+      if (event->button == warp_button)
         {
           gdouble slider_low_value, slider_high_value, new_value;
           



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]