]> Pileus Git - ~andy/gtk/commitdiff
CLAMP digits into a meaningfull range (we need to stay below a certain
authorTim Janik <timj@gtk.org>
Mon, 18 Jan 1999 19:42:59 +0000 (19:42 +0000)
committerTim Janik <timj@src.gnome.org>
Mon, 18 Jan 1999 19:42:59 +0000 (19:42 +0000)
Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>

        * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
        meaningfull range (we need to stay below a certain limit anyways
        to avoid string buffer overflows).

        * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
        area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
        * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
        (gtk_hscale_draw_value): safety CLAMP the value's x position for
        GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
        our allocation.

        * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
        and GtkScale::value_pos arguments.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkhscale.c
gtk/gtkscale.c
gtk/gtkscale.h
gtk/gtkvscale.c

index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index c43c80d510bb944a06280e1a0b22a9b7e308c278..59c0f636c625f5888f34842c2343838d3b4deb27 100644 (file)
@@ -1,3 +1,19 @@
+Mon Jan 18 18:53:08 1999  Tim Janik  <timj@gtk.org>
+
+       * gtk/gtkscale.c (gtk_scale_set_digits): CLAMP digits into a
+       meaningfull range (we need to stay below a certain limit anyways
+       to avoid string buffer overflows).
+
+       * gtk/gtkvscale.c (gtk_vscale_pos_background): fixed up background
+       area calculations for GTK_POS_RIGHT and GTK_POS_BOTTOM.
+       * gtk/gtkhscale.c (gtk_hscale_pos_background): likewise.
+       (gtk_hscale_draw_value): safety CLAMP the value's x position for
+       GTK_POS_TOP and GTK_POS_BOTTOM, so we don't paint strings outside of
+       our allocation.
+
+       * gtk/gtkscale.c: implemented GtkScale::digits, GtkScale::draw_value
+       and GtkScale::value_pos arguments.
+
 Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
 
        * docs/Changes-1.2.txt: Some editing, a little more
index 62513627f46881ee48d72744b67a408058598b31..4e349fb085759f165c8d71a646ff7bc29cfd7d37 100644 (file)
@@ -455,14 +455,14 @@ gtk_hscale_pos_background (GtkHScale *hscale,
       *w -= twidth;
       break;
     case GTK_POS_RIGHT:
-      *x = tx;
+      *x += twidth;
       *w -= twidth;
       break;
     case GTK_POS_TOP:
       *h -= theight;
       break;
     case GTK_POS_BOTTOM:
-      *y = ty;
+      *y += theight;
       *h -= theight;
       break;
     }
@@ -541,6 +541,8 @@ gtk_hscale_draw_value (GtkScale *scale)
           gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
           
           x += widget->allocation.x + (width - text_width) / 2;
+         x = CLAMP (x, widget->allocation.x,
+                    widget->allocation.x + widget->allocation.width - text_width);
           y -= GTK_WIDGET (scale)->style->font->descent;
           break;
         case GTK_POS_BOTTOM:
@@ -550,6 +552,8 @@ gtk_hscale_draw_value (GtkScale *scale)
           gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height);
           
           x += widget->allocation.x + (width - text_width) / 2;
+         x = CLAMP (x, widget->allocation.x,
+                    widget->allocation.x + widget->allocation.width - text_width);
           y += height + GTK_WIDGET (scale)->style->font->ascent;
           break;
         }
index d44a4681c295602d8a909088d17b49ee9252c90b..57fce9bc0f7a1d43b785862367acdc445dbd0160 100644 (file)
 
 #define SCALE_CLASS(w)  GTK_SCALE_CLASS (GTK_OBJECT (w)->klass)
 
+enum {
+  ARG_0,
+  ARG_DIGITS,
+  ARG_DRAW_VALUE,
+  ARG_VALUE_POS
+};
+
 
 static void gtk_scale_class_init      (GtkScaleClass *klass);
 static void gtk_scale_init            (GtkScale      *scale);
+static void gtk_scale_set_arg         (GtkObject     *object,
+                                      GtkArg        *arg,
+                                      guint          arg_id);
+static void gtk_scale_get_arg         (GtkObject     *object,
+                                      GtkArg        *arg,
+                                      guint          arg_id);
 static void gtk_scale_map             (GtkWidget     *widget);
 static void gtk_scale_unmap           (GtkWidget     *widget);
 
@@ -70,12 +83,28 @@ gtk_scale_class_init (GtkScaleClass *class)
   object_class = (GtkObjectClass*) class;
   range_class = (GtkRangeClass*) class;
   widget_class = (GtkWidgetClass*) class;
-
+  
   parent_class = gtk_type_class (GTK_TYPE_RANGE);
+  
+  gtk_object_add_arg_type ("GtkScale::digits",
+                          GTK_TYPE_INT,
+                          GTK_ARG_READWRITE,
+                          ARG_DIGITS);
+  gtk_object_add_arg_type ("GtkScale::draw_value",
+                          GTK_TYPE_BOOL,
+                          GTK_ARG_READWRITE,
+                          ARG_DRAW_VALUE);
+  gtk_object_add_arg_type ("GtkScale::value_pos",
+                          GTK_TYPE_POSITION_TYPE,
+                          GTK_ARG_READWRITE,
+                          ARG_VALUE_POS);
+
+  object_class->set_arg = gtk_scale_set_arg;
+  object_class->get_arg = gtk_scale_get_arg;
 
   widget_class->map = gtk_scale_map;
   widget_class->unmap = gtk_scale_unmap;
-
+  
   range_class->draw_background = gtk_scale_draw_background;
 
   class->slider_length = 31;
@@ -83,6 +112,57 @@ gtk_scale_class_init (GtkScaleClass *class)
   class->draw_value = NULL;
 }
 
+static void
+gtk_scale_set_arg (GtkObject      *object,
+                  GtkArg         *arg,
+                  guint           arg_id)
+{
+  GtkScale *scale;
+
+  scale = GTK_SCALE (object);
+
+  switch (arg_id)
+    {
+    case ARG_DIGITS:
+      gtk_scale_set_digits (scale, GTK_VALUE_INT (*arg));
+      break;
+    case ARG_DRAW_VALUE:
+      gtk_scale_set_draw_value (scale, GTK_VALUE_BOOL (*arg));
+      break;
+    case ARG_VALUE_POS:
+      gtk_scale_set_value_pos (scale, GTK_VALUE_ENUM (*arg));
+      break;
+    default:
+      break;
+    }
+}
+
+static void
+gtk_scale_get_arg (GtkObject      *object,
+                  GtkArg         *arg,
+                  guint           arg_id)
+{
+  GtkScale *scale;
+
+  scale = GTK_SCALE (object);
+
+  switch (arg_id)
+    {
+    case ARG_DIGITS:
+      GTK_VALUE_INT (*arg) = GTK_RANGE (scale)->digits;
+      break;
+    case ARG_DRAW_VALUE:
+      GTK_VALUE_BOOL (*arg) = scale->draw_value;
+      break;
+    case ARG_VALUE_POS:
+      GTK_VALUE_ENUM (*arg) = scale->value_pos;
+      break;
+    default:
+      arg->type = GTK_TYPE_INVALID;
+      break;
+    }
+}
+
 static void
 gtk_scale_init (GtkScale *scale)
 {
@@ -131,28 +211,30 @@ gtk_scale_set_digits (GtkScale *scale,
   g_return_if_fail (scale != NULL);
   g_return_if_fail (GTK_IS_SCALE (scale));
 
+  digits = CLAMP (digits, -1, 16);
+
   if (GTK_RANGE (scale)->digits != digits)
     {
       GTK_RANGE (scale)->digits = digits;
 
-      if (GTK_WIDGET_VISIBLE (scale) && GTK_WIDGET_MAPPED (scale))
-       gtk_widget_queue_resize (GTK_WIDGET (scale));
+      gtk_widget_queue_resize (GTK_WIDGET (scale));
     }
 }
 
 void
 gtk_scale_set_draw_value (GtkScale *scale,
-                         gint      draw_value)
+                         gboolean  draw_value)
 {
   g_return_if_fail (scale != NULL);
   g_return_if_fail (GTK_IS_SCALE (scale));
 
+  draw_value = draw_value != FALSE;
+
   if (scale->draw_value != draw_value)
     {
-      scale->draw_value = (draw_value != 0);
+      scale->draw_value = draw_value;
 
-      if (GTK_WIDGET_VISIBLE (scale) && GTK_WIDGET_MAPPED (scale))
-       gtk_widget_queue_resize (GTK_WIDGET (scale));
+      gtk_widget_queue_resize (GTK_WIDGET (scale));
     }
 }
 
index 31a6b31f375af64c11387e0ad607024177175848..d573ca4b433c73513fddb7018d3124f298f90afc 100644 (file)
@@ -62,7 +62,7 @@ GtkType gtk_scale_get_type        (void);
 void    gtk_scale_set_digits      (GtkScale        *scale,
                                   gint             digits);
 void    gtk_scale_set_draw_value  (GtkScale        *scale,
-                                  gint             draw_value);
+                                  gboolean         draw_value);
 void    gtk_scale_set_value_pos   (GtkScale        *scale,
                                   GtkPositionType  pos);
 gint    gtk_scale_get_value_width (GtkScale        *scale);
index cacf96426bd8797b745f878a9197b07ebeb7f59f..cb88083f90eafb4168acb5fbb587e5f6616a6964 100644 (file)
@@ -459,14 +459,14 @@ gtk_vscale_pos_background (GtkVScale *vscale,
       *w -= twidth;
       break;
     case GTK_POS_RIGHT:
-      *x = tx;
+      *x += twidth;
       *w -= twidth;
       break;
     case GTK_POS_TOP:
       *h -= theight;
       break;
     case GTK_POS_BOTTOM:
-      *y = ty;
+      *y += theight;
       *h -= theight;
       break;
     }