]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkscrolledwindow.c
Deprecate flag macros for toplevel, state, no window and composite child
[~andy/gtk] / gtk / gtkscrolledwindow.c
index e9dc57c1befc981efcce6000a14dc3d990c511d6..fb9cd0c704fc94fcf2b82c8e6d8b90de02c36dd3 100644 (file)
@@ -21,7 +21,7 @@
  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
 #include "config.h"
@@ -99,49 +99,48 @@ enum
   LAST_SIGNAL
 };
 
-static void gtk_scrolled_window_destroy            (GtkObject              *object);
-static void gtk_scrolled_window_finalize           (GObject                *object);
-static void gtk_scrolled_window_set_property       (GObject                *object,
-                                                   guint                   prop_id,
-                                                   const GValue           *value,
-                                                   GParamSpec             *pspec);
-static void gtk_scrolled_window_get_property       (GObject                *object,
-                                                   guint                   prop_id,
-                                                   GValue                 *value,
-                                                   GParamSpec             *pspec);
-
-static void gtk_scrolled_window_screen_changed     (GtkWidget              *widget,
-                                                   GdkScreen              *previous_screen);
-static gint gtk_scrolled_window_expose             (GtkWidget              *widget,
-                                                   GdkEventExpose         *event);
-static void gtk_scrolled_window_size_request       (GtkWidget              *widget,
-                                                   GtkRequisition         *requisition);
-static void gtk_scrolled_window_size_allocate      (GtkWidget              *widget,
-                                                   GtkAllocation          *allocation);
-static gint gtk_scrolled_window_scroll_event       (GtkWidget              *widget,
-                                                   GdkEventScroll         *event);
-static gint gtk_scrolled_window_focus              (GtkWidget              *widget,
-                                                   GtkDirectionType        direction);
-static void gtk_scrolled_window_add                (GtkContainer           *container,
-                                                   GtkWidget              *widget);
-static void gtk_scrolled_window_remove             (GtkContainer           *container,
-                                                   GtkWidget              *widget);
-static void gtk_scrolled_window_forall             (GtkContainer           *container,
-                                                   gboolean                include_internals,
-                                                   GtkCallback             callback,
-                                                   gpointer                callback_data);
-static gboolean gtk_scrolled_window_scroll_child   (GtkScrolledWindow      *scrolled_window,
-                                                   GtkScrollType           scroll,
-                                                   gboolean                horizontal);
-static void gtk_scrolled_window_move_focus_out     (GtkScrolledWindow      *scrolled_window,
-                                                   GtkDirectionType        direction_type);
-
-static void gtk_scrolled_window_relative_allocation(GtkWidget              *widget,
-                                                   GtkAllocation          *allocation);
-static void gtk_scrolled_window_adjustment_changed (GtkAdjustment          *adjustment,
-                                                   gpointer                data);
-
-static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow   *scrolled_window);
+static void     gtk_scrolled_window_destroy            (GtkObject         *object);
+static void     gtk_scrolled_window_set_property       (GObject           *object,
+                                                        guint              prop_id,
+                                                        const GValue      *value,
+                                                        GParamSpec        *pspec);
+static void     gtk_scrolled_window_get_property       (GObject           *object,
+                                                        guint              prop_id,
+                                                        GValue            *value,
+                                                        GParamSpec        *pspec);
+
+static void     gtk_scrolled_window_screen_changed     (GtkWidget         *widget,
+                                                        GdkScreen         *previous_screen);
+static gboolean gtk_scrolled_window_expose             (GtkWidget         *widget,
+                                                        GdkEventExpose    *event);
+static void     gtk_scrolled_window_size_request       (GtkWidget         *widget,
+                                                        GtkRequisition    *requisition);
+static void     gtk_scrolled_window_size_allocate      (GtkWidget         *widget,
+                                                        GtkAllocation     *allocation);
+static gboolean gtk_scrolled_window_scroll_event       (GtkWidget         *widget,
+                                                        GdkEventScroll    *event);
+static gboolean gtk_scrolled_window_focus              (GtkWidget         *widget,
+                                                        GtkDirectionType   direction);
+static void     gtk_scrolled_window_add                (GtkContainer      *container,
+                                                        GtkWidget         *widget);
+static void     gtk_scrolled_window_remove             (GtkContainer      *container,
+                                                        GtkWidget         *widget);
+static void     gtk_scrolled_window_forall             (GtkContainer      *container,
+                                                        gboolean           include_internals,
+                                                        GtkCallback        callback,
+                                                        gpointer           callback_data);
+static gboolean gtk_scrolled_window_scroll_child       (GtkScrolledWindow *scrolled_window,
+                                                        GtkScrollType      scroll,
+                                                        gboolean           horizontal);
+static void     gtk_scrolled_window_move_focus_out     (GtkScrolledWindow *scrolled_window,
+                                                        GtkDirectionType   direction_type);
+
+static void     gtk_scrolled_window_relative_allocation(GtkWidget         *widget,
+                                                        GtkAllocation     *allocation);
+static void     gtk_scrolled_window_adjustment_changed (GtkAdjustment     *adjustment,
+                                                        gpointer           data);
+
+static void  gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
 
 static guint signals[LAST_SIGNAL] = {0};
 
@@ -192,7 +191,6 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
   widget_class = (GtkWidgetClass*) class;
   container_class = (GtkContainerClass*) class;
 
-  gobject_class->finalize = gtk_scrolled_window_finalize;
   gobject_class->set_property = gtk_scrolled_window_set_property;
   gobject_class->get_property = gtk_scrolled_window_get_property;
 
@@ -377,6 +375,20 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
   gtk_scrolled_window_update_real_placement (scrolled_window);
 }
 
+/**
+ * gtk_scrolled_window_new:
+ * @hadjustment: (allow-none): horizontal adjustment
+ * @vadjustment: (allow-none): vertical adjustment
+ *
+ * Creates a new scrolled window.
+ *
+ * The two arguments are the scrolled window's adjustments; these will be
+ * shared with the scrollbars and the child widget to keep the bars in sync 
+ * with the child. Usually you want to pass %NULL for the adjustments, which 
+ * will cause the scrolled window to create them for you.
+ *
+ * Returns: a new scrolled window
+ */
 GtkWidget*
 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
                         GtkAdjustment *vadjustment)
@@ -397,6 +409,13 @@ gtk_scrolled_window_new (GtkAdjustment *hadjustment,
   return scrolled_window;
 }
 
+/**
+ * gtk_scrolled_window_set_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hadjustment: horizontal scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the horizontal scrollbar.
+ */
 void
 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
                                     GtkAdjustment     *hadjustment)
@@ -451,6 +470,13 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
   g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
 }
 
+/**
+ * gtk_scrolled_window_set_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @vadjustment: vertical scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the vertical scrollbar.
+ */
 void
 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
                                     GtkAdjustment     *vadjustment)
@@ -505,6 +531,16 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
   g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
 }
 
+/**
+ * gtk_scrolled_window_get_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the horizontal scrollbar's adjustment, used to connect the
+ * horizontal scrollbar to the child widget's horizontal scroll
+ * functionality.
+ *
+ * Returns: the horizontal #GtkAdjustment
+ */
 GtkAdjustment*
 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
 {
@@ -515,6 +551,16 @@ gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
          NULL);
 }
 
+/**
+ * gtk_scrolled_window_get_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * 
+ * Returns the vertical scrollbar's adjustment, used to connect the
+ * vertical scrollbar to the child widget's vertical scroll
+ * functionality.
+ * 
+ * Returns: the vertical #GtkAdjustment
+ */
 GtkAdjustment*
 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
 {
@@ -563,6 +609,21 @@ gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
   return scrolled_window->vscrollbar;
 }
 
+/**
+ * gtk_scrolled_window_set_policy:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hscrollbar_policy: policy for horizontal bar
+ * @vscrollbar_policy: policy for vertical bar
+ * 
+ * Sets the scrollbar policy for the horizontal and vertical scrollbars.
+ *
+ * The policy determines when the scrollbar should appear; it is a value
+ * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
+ * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
+ * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
+ * if needed (that is, if the slider part of the bar would be smaller
+ * than the trough - the display is larger than the page size).
+ */
 void
 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
                                GtkPolicyType      hscrollbar_policy,
@@ -590,12 +651,14 @@ gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
 /**
  * gtk_scrolled_window_get_policy:
  * @scrolled_window: a #GtkScrolledWindow
- * @hscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
- * @vscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
+ * @hscrollbar_policy: location to store the policy for the horizontal 
+ *     scrollbar, or %NULL.
+ * @vscrollbar_policy: location to store the policy for the vertical
+ *     scrollbar, or %NULL.
  * 
  * Retrieves the current policy values for the horizontal and vertical
  * scrollbars. See gtk_scrolled_window_set_policy().
- **/
+ */
 void
 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
                                GtkPolicyType     *hscrollbar_policy,
@@ -667,6 +730,7 @@ gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
  *
  * Sets the placement of the contents with respect to the scrollbars
  * for the scrolled window.
+ * 
  * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
  * in the top left, with the scrollbars underneath and to the right.
  * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
@@ -674,7 +738,7 @@ gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
  *
  * See also gtk_scrolled_window_get_placement() and
  * gtk_scrolled_window_unset_placement().
- **/
+ */
 void
 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
                                   GtkCornerType      window_placement)
@@ -786,25 +850,30 @@ gtk_scrolled_window_destroy (GtkObject *object)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
 
-  gtk_widget_unparent (scrolled_window->hscrollbar);
-  gtk_widget_unparent (scrolled_window->vscrollbar);
-  gtk_widget_destroy (scrolled_window->hscrollbar);
-  gtk_widget_destroy (scrolled_window->vscrollbar);
+  if (scrolled_window->hscrollbar)
+    {
+      g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+                                           gtk_scrolled_window_adjustment_changed,
+                                           scrolled_window);
+      gtk_widget_unparent (scrolled_window->hscrollbar);
+      gtk_widget_destroy (scrolled_window->hscrollbar);
+      g_object_unref (scrolled_window->hscrollbar);
+      scrolled_window->hscrollbar = NULL;
+    }
+  if (scrolled_window->vscrollbar)
+    {
+      g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)),
+                                           gtk_scrolled_window_adjustment_changed,
+                                           scrolled_window);
+      gtk_widget_unparent (scrolled_window->vscrollbar);
+      gtk_widget_destroy (scrolled_window->vscrollbar);
+      g_object_unref (scrolled_window->vscrollbar);
+      scrolled_window->vscrollbar = NULL;
+    }
 
   GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
 }
 
-static void
-gtk_scrolled_window_finalize (GObject *object)
-{
-  GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
-
-  g_object_unref (scrolled_window->hscrollbar);
-  g_object_unref (scrolled_window->vscrollbar);
-
-  G_OBJECT_CLASS (gtk_scrolled_window_parent_class)->finalize (object);
-}
-
 static void
 gtk_scrolled_window_set_property (GObject      *object,
                                  guint         prop_id,
@@ -990,7 +1059,7 @@ gtk_scrolled_window_paint (GtkWidget    *widget,
     }
 }
 
-static gint
+static gboolean
 gtk_scrolled_window_expose (GtkWidget      *widget,
                            GdkEventExpose *event)
 {
@@ -998,7 +1067,7 @@ gtk_scrolled_window_expose (GtkWidget      *widget,
     {
       gtk_scrolled_window_paint (widget, &event->area);
 
-      (* GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event) (widget, event);
+      GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event (widget, event);
     }
 
   return FALSE;
@@ -1127,6 +1196,8 @@ gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
          break;
        }
 
+      value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
+      
       gtk_adjustment_set_value (adjustment, value);
 
       return TRUE;
@@ -1145,7 +1216,7 @@ gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
    * a flag, then propagating the focus motion to the notebook.
    */
   toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
-  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+  if (!gtk_widget_is_toplevel (toplevel))
     return;
 
   g_object_ref (scrolled_window);
@@ -1493,8 +1564,8 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
     gtk_widget_hide (scrolled_window->vscrollbar);
 }
 
-static gint
-gtk_scrolled_window_scroll_event (GtkWidget *widget,
+static gboolean
+gtk_scrolled_window_scroll_event (GtkWidget      *widget,
                                  GdkEventScroll *event)
 {
   GtkWidget *range;
@@ -1510,11 +1581,13 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget,
   if (range && GTK_WIDGET_VISIBLE (range))
     {
       GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
-      gdouble delta;
+      gdouble delta, new_value;
 
       delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
 
-      gtk_adjustment_set_value (adj, adj->value + delta);
+      new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size);
+      
+      gtk_adjustment_set_value (adj, new_value);
 
       return TRUE;
     }
@@ -1522,7 +1595,7 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget,
   return FALSE;
 }
 
-static gint
+static gboolean
 gtk_scrolled_window_focus (GtkWidget        *widget,
                           GtkDirectionType  direction)
 {
@@ -1547,7 +1620,7 @@ gtk_scrolled_window_focus (GtkWidget        *widget,
        return TRUE;
     }
 
-  if (!had_focus_child)
+  if (!had_focus_child && GTK_WIDGET_CAN_FOCUS (widget))
     {
       gtk_widget_grab_focus (widget);
       return TRUE;
@@ -1634,6 +1707,29 @@ gtk_scrolled_window_remove (GtkContainer *container,
   GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
 }
 
+/**
+ * gtk_scrolled_window_add_with_viewport:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @child: the widget you want to scroll
+ *
+ * Used to add children without native scrolling capabilities. This
+ * is simply a convenience function; it is equivalent to adding the
+ * unscrollable child to a viewport, then adding the viewport to the
+ * scrolled window. If a child has native scrolling, use
+ * gtk_container_add() instead of this function.
+ *
+ * The viewport scrolls the child by moving its #GdkWindow, and takes
+ * the size of the child to be the size of its toplevel #GdkWindow. 
+ * This will be very wrong for most widgets that support native scrolling;
+ * for example, if you add a widget such as #GtkTreeView with a viewport,
+ * the whole widget will scroll, including the column headings. Thus, 
+ * widgets with native scrolling support should not be used with the 
+ * #GtkViewport proxy.
+ *
+ * A widget supports scrolling natively if the 
+ * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
+ * i.e. has been filled in with a valid signal identifier.
+ */
 void
 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
                                       GtkWidget         *child)
@@ -1666,7 +1762,7 @@ gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
   gtk_container_add (GTK_CONTAINER (viewport), child);
 }
 
-/**
+/*
  * _gtk_scrolled_window_get_spacing:
  * @scrolled_window: a scrolled window
  * 
@@ -1674,7 +1770,7 @@ gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
  * the scrolled widget. Used by GtkCombo
  * 
  * Return value: the spacing, in pixels.
- **/
+ */
 gint
 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
 {