Index: gtk/gtkrange.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrange.c,v
retrieving revision 1.126
diff -u -p -r1.126 gtkrange.c
--- gtk/gtkrange.c	18 May 2006 11:39:42 -0000	1.126
+++ gtk/gtkrange.c	19 May 2006 12:20:18 -0000
@@ -169,6 +169,8 @@ static void          gtk_range_calc_requ
                                                          GdkRectangle  *range_rect,
                                                          GtkBorder     *border,
                                                          gint          *n_steppers_p,
+                                                         gboolean      *has_steppers_ab,
+                                                         gboolean      *has_steppers_cd,
                                                          gint          *slider_length_p);
 static void          gtk_range_adjustment_value_changed (GtkAdjustment *adjustment,
                                                          gpointer       data);
@@ -898,7 +900,7 @@ gtk_range_size_request (GtkWidget      *
 
   gtk_range_calc_request (range, 
                           slider_width, stepper_size, trough_border, stepper_spacing,
-                          &range_rect, &border, NULL, NULL);
+                          &range_rect, &border, NULL, NULL, NULL, NULL);
 
   requisition->width = range_rect.width + border.left + border.right;
   requisition->height = range_rect.height + border.top + border.bottom;
@@ -1360,23 +1362,44 @@ coord_to_value (GtkRange *range,
 {
   gdouble frac;
   gdouble value;
-  
+  gint    stepper_spacing;
+  gint    trough_length;
+  gint    trough_start;
+  gint    slider_length;
+
+  gtk_widget_style_get (GTK_WIDGET (range),
+                        "stepper-spacing", &stepper_spacing,
+                        NULL);
+
   if (range->orientation == GTK_ORIENTATION_VERTICAL)
-    if (range->layout->trough.height == range->layout->slider.height)
-      frac = 1.0;
-    else 
-      frac = ((coord - range->layout->trough.y) /
-	      (gdouble) (range->layout->trough.height - range->layout->slider.height));
+    {
+      trough_length = range->layout->trough.height;
+      trough_start  = range->layout->trough.y;
+      slider_length = range->layout->slider.height;
+    }
+  else
+    {
+      trough_length = range->layout->trough.width;
+      trough_start  = range->layout->trough.x;
+      slider_length = range->layout->slider.width;
+    }
+
+  trough_length -= (stepper_spacing *
+                    ((range->has_stepper_a || range->has_stepper_b) +
+                     (range->has_stepper_c || range->has_stepper_d)));
+
+  trough_start += (stepper_spacing *
+                   (range->has_stepper_a || range->has_stepper_b));
+
+  if (trough_length == slider_length)
+    frac = 1.0;
   else
-    if (range->layout->trough.width == range->layout->slider.width)
-      frac = 1.0;
-    else
-      frac = ((coord - range->layout->trough.x) /
-	      (gdouble) (range->layout->trough.width - range->layout->slider.width));
+    frac = (MAX (0, (coord - trough_start)) /
+            (gdouble) (trough_length - slider_length));
 
   if (should_invert (range))
     frac = 1.0 - frac;
-  
+
   value = range->adjustment->lower +
     frac * (range->adjustment->upper - range->adjustment->lower - range->adjustment->page_size);
 
@@ -2222,10 +2245,14 @@ gtk_range_calc_request (GtkRange      *r
                         GdkRectangle  *range_rect,
                         GtkBorder     *border,
                         gint          *n_steppers_p,
+                        gboolean      *has_steppers_ab,
+                        gboolean      *has_steppers_cd,
                         gint          *slider_length_p)
 {
   gint slider_length;
   gint n_steppers;
+  gint n_steppers_ab;
+  gint n_steppers_cd;
 
   border->left = 0;
   border->right = 0;
@@ -2234,16 +2261,20 @@ gtk_range_calc_request (GtkRange      *r
 
   if (GTK_RANGE_GET_CLASS (range)->get_range_border)
     (* GTK_RANGE_GET_CLASS (range)->get_range_border) (range, border);
-  
-  n_steppers = 0;
+
+  n_steppers_ab = 0;
+  n_steppers_cd = 0;
+
   if (range->has_stepper_a)
-    n_steppers += 1;
+    n_steppers_ab += 1;
   if (range->has_stepper_b)
-    n_steppers += 1;
+    n_steppers_ab += 1;
   if (range->has_stepper_c)
-    n_steppers += 1;
+    n_steppers_cd += 1;
   if (range->has_stepper_d)
-    n_steppers += 1;
+    n_steppers_cd += 1;
+
+  n_steppers = n_steppers_ab + n_steppers_cd;
 
   slider_length = range->min_slider_size;
 
@@ -2256,17 +2287,35 @@ gtk_range_calc_request (GtkRange      *r
   if (range->orientation == GTK_ORIENTATION_VERTICAL)
     {
       range_rect->width = trough_border * 2 + slider_width;
-      range_rect->height = stepper_size * n_steppers + stepper_spacing * 2 + trough_border * 2 + slider_length;
+      range_rect->height = stepper_size * n_steppers + trough_border * 2 + slider_length;
+
+      if (n_steppers_ab > 0)
+        range_rect->height += stepper_spacing;
+
+      if (n_steppers_cd > 0)
+        range_rect->height += stepper_spacing;
     }
   else
     {
-      range_rect->width = stepper_size * n_steppers + stepper_spacing * 2 + trough_border * 2 + slider_length;
+      range_rect->width = stepper_size * n_steppers + trough_border * 2 + slider_length;
       range_rect->height = trough_border * 2 + slider_width;
+
+      if (n_steppers_ab > 0)
+        range_rect->width += stepper_spacing;
+
+      if (n_steppers_cd > 0)
+        range_rect->width += stepper_spacing;
     }
 
   if (n_steppers_p)
     *n_steppers_p = n_steppers;
 
+  if (has_steppers_ab)
+    *has_steppers_ab = (n_steppers_ab > 0);
+
+  if (has_steppers_cd)
+    *has_steppers_cd = (n_steppers_cd > 0);
+
   if (slider_length_p)
     *slider_length_p = slider_length;
 }
@@ -2279,6 +2328,8 @@ gtk_range_calc_layout (GtkRange *range,
   gint slider_length;
   GtkBorder border;
   gint n_steppers;
+  gboolean has_steppers_ab;
+  gboolean has_steppers_cd;
   GdkRectangle range_rect;
   GtkRangeLayout *layout;
   GtkWidget *widget;
@@ -2305,7 +2356,8 @@ gtk_range_calc_layout (GtkRange *range,
 
   gtk_range_calc_request (range, 
                           slider_width, stepper_size, trough_border, stepper_spacing,
-                          &range_rect, &border, &n_steppers, &slider_length);
+                          &range_rect, &border, &n_steppers,
+                          &has_steppers_ab, &has_steppers_cd, &slider_length);
   
   /* We never expand to fill available space in the small dimension
    * (i.e. vertical scrollbars are always a fixed width)
@@ -2424,9 +2476,9 @@ gtk_range_calc_layout (GtkRange *range,
       {
         gint y, bottom, top, height;
         
-        top = layout->trough.y + stepper_spacing;
-        bottom = layout->trough.y + layout->trough.height - stepper_spacing;
-        
+        top = layout->trough.y + stepper_spacing * has_steppers_ab;
+        bottom = layout->trough.y + layout->trough.height - stepper_spacing * has_steppers_cd;
+
         /* slider height is the fraction (page_size /
          * total_adjustment_range) times the trough height in pixels
          */
@@ -2440,8 +2492,10 @@ gtk_range_calc_layout (GtkRange *range,
         if (height < range->min_slider_size ||
             range->slider_size_fixed)
           height = range->min_slider_size;
-        
-        height = MIN (height, (layout->trough.height - stepper_spacing * 2));
+
+        height = MIN (height, (layout->trough.height -
+                               stepper_spacing * (has_steppers_ab +
+                                                  has_steppers_cd)));
         
         y = top;
         
@@ -2564,8 +2618,8 @@ gtk_range_calc_layout (GtkRange *range,
       {
         gint x, left, right, width;
         
-        left = layout->trough.x + stepper_spacing;
-        right = layout->trough.x + layout->trough.width - stepper_spacing;
+        left = layout->trough.x + stepper_spacing * has_steppers_ab;
+        right = layout->trough.x + layout->trough.width - stepper_spacing * has_steppers_cd;
         
         /* slider width is the fraction (page_size /
          * total_adjustment_range) times the trough width in pixels
@@ -2581,7 +2635,9 @@ gtk_range_calc_layout (GtkRange *range,
             range->slider_size_fixed)
           width = range->min_slider_size;
         
-        width = MIN (width, (layout->trough.width - stepper_spacing * 2));
+        width = MIN (width, (layout->trough.width -
+                             stepper_spacing * (has_steppers_ab +
+                                                has_steppers_cd)));
         
         x = left;
         
