]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkvscale.c
New static function to set the background of all windows.
[~andy/gtk] / gtk / gtkvscale.c
index 2dca2cc99e3723710fadd69bf431b9d4cbbb5010..ae28fddfdcb052f2b21db7e6e511cccd39f05a15 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <math.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include "gtkvscale.h"
-#include "gtksignal.h"
 #include "gtkintl.h"
 
 #define VALUE_SPACING 2
@@ -38,26 +39,28 @@ static void     gtk_vscale_init             (GtkVScale      *vscale);
 static gboolean gtk_vscale_expose           (GtkWidget      *widget,
                                              GdkEventExpose *event);
 
-GtkType
+GType
 gtk_vscale_get_type (void)
 {
-  static GtkType vscale_type = 0;
+  static GType vscale_type = 0;
   
   if (!vscale_type)
     {
-      static const GtkTypeInfo vscale_info =
+      static const GTypeInfo vscale_info =
       {
-        "GtkVScale",
-        sizeof (GtkVScale),
-        sizeof (GtkVScaleClass),
-        (GtkClassInitFunc) gtk_vscale_class_init,
-        (GtkObjectInitFunc) gtk_vscale_init,
-        /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
+       sizeof (GtkVScaleClass),
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_vscale_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkVScale),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_vscale_init,
       };
       
-      vscale_type = gtk_type_unique (GTK_TYPE_SCALE, &vscale_info);
+      vscale_type = g_type_register_static (GTK_TYPE_SCALE, "GtkVScale",
+                                           &vscale_info, 0);
     }
   
   return vscale_type;
@@ -66,11 +69,9 @@ gtk_vscale_get_type (void)
 static void
 gtk_vscale_class_init (GtkVScaleClass *class)
 {
-  GObjectClass   *gobject_class;
   GtkWidgetClass *widget_class;
   GtkRangeClass *range_class;
   
-  gobject_class = G_OBJECT_CLASS (class);
   widget_class = GTK_WIDGET_CLASS (class);
   range_class = GTK_RANGE_CLASS (class); 
 
@@ -94,13 +95,7 @@ gtk_vscale_init (GtkVScale *vscale)
 GtkWidget*
 gtk_vscale_new (GtkAdjustment *adjustment)
 {
-  GtkWidget *vscale;
-  
-  vscale = gtk_widget_new (GTK_TYPE_VSCALE,
-                          "adjustment", adjustment,
-                          NULL);
-  
-  return vscale;
+  return g_object_new (GTK_TYPE_VSCALE, "adjustment", adjustment, NULL);
 }
 
 
@@ -110,10 +105,10 @@ gtk_vscale_new (GtkAdjustment *adjustment)
  * @max: maximum value
  * @step: step increment (tick size) used with keyboard shortcuts
  * 
- * Creates a new vertical scale widget that lets the user
- * input a number between @min and @max with the increment @step.
- * @step must be nonzero; it's the distance the slider moves when
- * using the arrow keys to adjust the scale value.
+ * Creates a new vertical scale widget that lets the user input a
+ * number between @min and @max (including @min and @max) with the
+ * increment @step.  @step must be nonzero; it's the distance the
+ * slider moves when using the arrow keys to adjust the scale value.
  * 
  * Return value: a new #GtkVScale
  **/
@@ -129,7 +124,7 @@ gtk_vscale_new_with_range (gdouble min,
   g_return_val_if_fail (min < max, NULL);
   g_return_val_if_fail (step != 0.0, NULL);
 
-  adj = gtk_adjustment_new (min, min, max, step, 10 * step, step);
+  adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
   
   scale = g_object_new (GTK_TYPE_VSCALE,
                         "adjustment", adj,
@@ -160,6 +155,12 @@ gtk_vscale_expose (GtkWidget      *widget,
   scale = GTK_SCALE (widget);
   vscale = GTK_VSCALE (widget);
   
+  /* We need to chain up _first_ so the various geometry members of
+   * GtkRange struct are updated.
+   */
+  if (GTK_WIDGET_CLASS (parent_class)->expose_event)
+    GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+
   if (scale->draw_value)
     {
       PangoLayout *layout;
@@ -210,6 +211,9 @@ gtk_vscale_expose (GtkWidget      *widget,
           break;
         }
       
+      x += widget->allocation.x;
+      y += widget->allocation.y;
+      
       state_type = GTK_STATE_NORMAL;
       if (!GTK_WIDGET_IS_SENSITIVE (scale))
         state_type = GTK_STATE_INSENSITIVE;
@@ -224,8 +228,8 @@ gtk_vscale_expose (GtkWidget      *widget,
                         x, y,
                         layout);
 
-      g_object_unref (G_OBJECT (layout));
+      g_object_unref (layout);
     }
   
-  return (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+  return FALSE;
 }