]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkscrolledwindow.c
System fnmatch wasn't going to be UTF-8 clean, neither was our version.
[~andy/gtk] / gtk / gtkscrolledwindow.c
index 299ef5be6606b533d18e897fae80e1b64228232b..cc78baaa651e155d26b293522da20705610a6e3e 100644 (file)
@@ -28,7 +28,6 @@
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkscrolledwindow.h"
-#include "gtksignal.h"
 #include "gtkintl.h"
 
 
 
 #define DEFAULT_SCROLLBAR_SPACING  3
 
-#define SCROLLBAR_SPACING(w)                                                           \
-  (GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing >= 0 ?                         \
-   GTK_SCROLLED_WINDOW_GET_CLASS (w)->scrollbar_spacing : DEFAULT_SCROLLBAR_SPACING)
-
 enum {
   PROP_0,
   PROP_HADJUSTMENT,
@@ -138,26 +133,29 @@ static GtkContainerClass *parent_class = NULL;
 
 static guint signals[LAST_SIGNAL] = {0};
 
-GtkType
+GType
 gtk_scrolled_window_get_type (void)
 {
-  static GtkType scrolled_window_type = 0;
+  static GType scrolled_window_type = 0;
 
   if (!scrolled_window_type)
     {
-      static const GtkTypeInfo scrolled_window_info =
+      static const GTypeInfo scrolled_window_info =
       {
-       "GtkScrolledWindow",
-       sizeof (GtkScrolledWindow),
        sizeof (GtkScrolledWindowClass),
-       (GtkClassInitFunc) gtk_scrolled_window_class_init,
-       (GtkObjectInitFunc) gtk_scrolled_window_init,
-       /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_scrolled_window_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkScrolledWindow),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_scrolled_window_init,
       };
 
-      scrolled_window_type = gtk_type_unique (GTK_TYPE_BIN, &scrolled_window_info);
+      scrolled_window_type =
+       g_type_register_static (GTK_TYPE_BIN, "GtkScrolledWindow",
+                               &scrolled_window_info, 0);
     }
 
   return scrolled_window_type;
@@ -207,7 +205,8 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
   object_class = (GtkObjectClass*) class;
   widget_class = (GtkWidgetClass*) class;
   container_class = (GtkContainerClass*) class;
-  parent_class = gtk_type_class (GTK_TYPE_BIN);
+
+  parent_class = g_type_class_peek_parent (class);
 
   gobject_class->finalize = gtk_scrolled_window_finalize;
   gobject_class->set_property = gtk_scrolled_window_set_property;
@@ -234,14 +233,14 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                   PROP_HADJUSTMENT,
                                   g_param_spec_object ("hadjustment",
                                                        _("Horizontal Adjustment"),
-                                                       _("The GtkAdjustment for the horizontal position."),
+                                                       _("The GtkAdjustment for the horizontal position"),
                                                        GTK_TYPE_ADJUSTMENT,
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
   g_object_class_install_property (gobject_class,
                                   PROP_VADJUSTMENT,
                                   g_param_spec_object ("vadjustment",
                                                        _("Vertical Adjustment"),
-                                                       _("The GtkAdjustment for the vertical position."),
+                                                       _("The GtkAdjustment for the vertical position"),
                                                        GTK_TYPE_ADJUSTMENT,
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
   g_object_class_install_property (gobject_class,
@@ -278,6 +277,15 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                                      GTK_SHADOW_NONE,
                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
 
+  gtk_widget_class_install_style_property (widget_class,
+                                          g_param_spec_int ("scrollbar_spacing",
+                                                            _("Scrollbar spacing"),
+                                                            _("Number of pixels between the scrollbars and the scrolled window"),
+                                                            0,
+                                                            G_MAXINT,
+                                                            DEFAULT_SCROLLBAR_SPACING,
+                                                            G_PARAM_READABLE));
+
   signals[SCROLL_CHILD] =
     g_signal_new ("scroll_child",
                   G_TYPE_FROM_CLASS (object_class),
@@ -324,8 +332,6 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
 {
   GTK_WIDGET_SET_FLAGS (scrolled_window, GTK_NO_WINDOW | GTK_CAN_FOCUS);
 
-  gtk_container_set_resize_mode (GTK_CONTAINER (scrolled_window), GTK_RESIZE_QUEUE);
-
   scrolled_window->hscrollbar = NULL;
   scrolled_window->vscrollbar = NULL;
   scrolled_window->hscrollbar_policy = GTK_POLICY_ALWAYS;
@@ -379,7 +385,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
       gtk_widget_pop_composite_child ();
 
       gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window));
-      gtk_widget_ref (scrolled_window->hscrollbar);
+      g_object_ref (scrolled_window->hscrollbar);
       gtk_widget_show (scrolled_window->hscrollbar);
     }
   else
@@ -390,17 +396,17 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
       if (old_adjustment == hadjustment)
        return;
 
-      gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment),
-                                    GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
-                                    scrolled_window);
+      g_signal_handlers_disconnect_by_func (old_adjustment,
+                                           gtk_scrolled_window_adjustment_changed,
+                                           scrolled_window);
       gtk_range_set_adjustment (GTK_RANGE (scrolled_window->hscrollbar),
                                hadjustment);
     }
   hadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
-  gtk_signal_connect (GTK_OBJECT (hadjustment),
-                     "changed",
-                     GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
-                     scrolled_window);
+  g_signal_connect (hadjustment,
+                   "changed",
+                   G_CALLBACK (gtk_scrolled_window_adjustment_changed),
+                   scrolled_window);
   gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
   
   if (bin->child)
@@ -433,7 +439,7 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
       gtk_widget_pop_composite_child ();
 
       gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window));
-      gtk_widget_ref (scrolled_window->vscrollbar);
+      g_object_ref (scrolled_window->vscrollbar);
       gtk_widget_show (scrolled_window->vscrollbar);
     }
   else
@@ -444,17 +450,17 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
       if (old_adjustment == vadjustment)
        return;
 
-      gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment),
-                                    GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
-                                    scrolled_window);
+      g_signal_handlers_disconnect_by_func (old_adjustment,
+                                           gtk_scrolled_window_adjustment_changed,
+                                           scrolled_window);
       gtk_range_set_adjustment (GTK_RANGE (scrolled_window->vscrollbar),
                                vadjustment);
     }
   vadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
-  gtk_signal_connect (GTK_OBJECT (vadjustment),
-                     "changed",
-                     GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed),
-                     scrolled_window);
+  g_signal_connect (vadjustment,
+                   "changed",
+                   G_CALLBACK (gtk_scrolled_window_adjustment_changed),
+                   scrolled_window);
   gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
 
   if (bin->child)
@@ -585,7 +591,7 @@ gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
       scrolled_window->shadow_type = type;
 
       if (GTK_WIDGET_DRAWABLE (scrolled_window))
-       gtk_widget_queue_clear (GTK_WIDGET (scrolled_window));
+       gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
 
       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
 
@@ -632,8 +638,8 @@ gtk_scrolled_window_finalize (GObject *object)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
 
-  gtk_widget_unref (scrolled_window->hscrollbar);
-  gtk_widget_unref (scrolled_window->vscrollbar);
+  g_object_unref (scrolled_window->hscrollbar);
+  g_object_unref (scrolled_window->vscrollbar);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -897,7 +903,7 @@ gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
   g_object_ref (scrolled_window);
   
   scrolled_window->focus_out = TRUE;
-  g_signal_emit_by_name (G_OBJECT (toplevel), "move_focus", direction_type);
+  g_signal_emit_by_name (toplevel, "move_focus", direction_type);
   scrolled_window->focus_out = FALSE;
   
   g_object_unref (scrolled_window);
@@ -911,6 +917,7 @@ gtk_scrolled_window_size_request (GtkWidget      *widget,
   GtkBin *bin;
   gint extra_width;
   gint extra_height;
+  gint scrollbar_spacing;
   GtkRequisition hscrollbar_requisition;
   GtkRequisition vscrollbar_requisition;
   GtkRequisition child_requisition;
@@ -921,6 +928,8 @@ gtk_scrolled_window_size_request (GtkWidget      *widget,
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   bin = GTK_BIN (scrolled_window);
 
+  scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+
   extra_width = 0;
   extra_height = 0;
   requisition->width = 0;
@@ -971,7 +980,7 @@ gtk_scrolled_window_size_request (GtkWidget      *widget,
     {
       requisition->width = MAX (requisition->width, hscrollbar_requisition.width);
       if (!extra_height || scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
-       extra_height = SCROLLBAR_SPACING (scrolled_window) + hscrollbar_requisition.height;
+       extra_height = scrollbar_spacing + hscrollbar_requisition.height;
     }
 
   if (scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
@@ -979,7 +988,7 @@ gtk_scrolled_window_size_request (GtkWidget      *widget,
     {
       requisition->height = MAX (requisition->height, vscrollbar_requisition.height);
       if (!extra_height || scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
-       extra_width = SCROLLBAR_SPACING (scrolled_window) + vscrollbar_requisition.width;
+       extra_width = scrollbar_spacing + vscrollbar_requisition.width;
     }
 
   requisition->width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
@@ -997,11 +1006,13 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
                                         GtkAllocation *allocation)
 {
   GtkScrolledWindow *scrolled_window;
+  gint scrollbar_spacing;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (allocation != NULL);
 
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
+  scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
 
   allocation->x = GTK_CONTAINER (widget)->border_width;
   allocation->y = GTK_CONTAINER (widget)->border_width;
@@ -1023,12 +1034,9 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
   
       if (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
          scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
-       allocation->x += (vscrollbar_requisition.width +
-                         SCROLLBAR_SPACING (scrolled_window));
+       allocation->x += (vscrollbar_requisition.width +  scrollbar_spacing);
 
-      allocation->width = MAX (1, (gint)allocation->width -
-                              ((gint)vscrollbar_requisition.width +
-                               (gint)SCROLLBAR_SPACING (scrolled_window)));
+      allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
     }
   if (scrolled_window->hscrollbar_visible)
     {
@@ -1038,12 +1046,9 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
   
       if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
          scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
-       allocation->y += (hscrollbar_requisition.height +
-                         SCROLLBAR_SPACING (scrolled_window));
+       allocation->y += (hscrollbar_requisition.height + scrollbar_spacing);
 
-      allocation->height = MAX (1, (gint)allocation->height -
-                               ((gint)hscrollbar_requisition.height +
-                                (gint)SCROLLBAR_SPACING (scrolled_window)));
+      allocation->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
     }
 }
 
@@ -1055,6 +1060,7 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   GtkBin *bin;
   GtkAllocation relative_allocation;
   GtkAllocation child_allocation;
+  gint scrollbar_spacing;
   
   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
   g_return_if_fail (allocation != NULL);
@@ -1062,6 +1068,8 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   bin = GTK_BIN (scrolled_window);
 
+  scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+
   widget->allocation = *allocation;
 
   if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
@@ -1131,7 +1139,7 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
          scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT)
        child_allocation.y = (relative_allocation.y +
                              relative_allocation.height +
-                             SCROLLBAR_SPACING (scrolled_window) +
+                             scrollbar_spacing +
                              (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
                               0 : widget->style->ythickness));
       else
@@ -1166,7 +1174,7 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
          scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)
        child_allocation.x = (relative_allocation.x +
                              relative_allocation.width +
-                             SCROLLBAR_SPACING (scrolled_window) +
+                             scrollbar_spacing +
                              (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
                               0 : widget->style->xthickness));
       else
@@ -1366,3 +1374,35 @@ gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
   gtk_widget_show (viewport);
   gtk_container_add (GTK_CONTAINER (viewport), child);
 }
+
+/**
+ * _gtk_scrolled_window_get_spacing:
+ * @scrolled_window: a scrolled window
+ * 
+ * Gets the spacing between the scrolled window's scrollbars and
+ * the scrolled widget. Used by GtkCombo
+ * 
+ * Return value: the spacing, in pixels.
+ **/
+gint
+_gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
+{
+  GtkScrolledWindowClass *class;
+    
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
+
+  class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
+
+  if (class->scrollbar_spacing >= 0)
+    return class->scrollbar_spacing;
+  else
+    {
+      gint scrollbar_spacing;
+      
+      gtk_widget_style_get (GTK_WIDGET (scrolled_window),
+                           "scrollbar_spacing", &scrollbar_spacing,
+                           NULL);
+
+      return scrollbar_spacing;
+    }
+}