diff options
Diffstat (limited to 'gtk/gtkscrolledwindow.c')
-rw-r--r-- | gtk/gtkscrolledwindow.c | 98 |
1 files changed, 55 insertions, 43 deletions
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 191c3c3921..483a348757 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -29,6 +29,7 @@ #include <gdk/gdkkeysyms.h> #include "gtkbindings.h" #include "gtkmarshalers.h" +#include "gtkscrollable.h" #include "gtkscrolledwindow.h" #include "gtkwindow.h" #include "gtktypeutils.h" @@ -40,7 +41,7 @@ * SECTION:gtkscrolledwindow * @Short_description: Adds scrollbars to its child widget * @Title: GtkScrolledWindow - * @See_also: #GtkViewport, #GtkAdjustment, #GtkWidgetClass + * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment * * #GtkScrolledWindow is a #GtkBin subclass: it's a container * the accepts a single child widget. #GtkScrolledWindow adds scrollbars @@ -48,16 +49,7 @@ * child widget. * * The scrolled window can work in two ways. Some widgets have native - * scrolling support; these widgets have "slots" for #GtkAdjustment - * objects. - * <footnote><para>The scrolled window installs #GtkAdjustment objects in - * the child window's slots using the set_scroll_adjustments_signal, - * found in #GtkWidgetClass. (Conceptually, these widgets implement a - * "Scrollable" interface; because GTK+ 1.2 lacked interface support in - * the object system, this interface is hackily implemented as a signal - * in #GtkWidgetClass. The GTK+ 2.0 object system would allow a clean - * implementation, but it wasn't worth breaking the - * API.)</para></footnote> + * scrolling support; these widgets implement the #GtkScrollable interface. * Widgets with native scroll support include #GtkTreeView, #GtkTextView, * and #GtkLayout. * @@ -549,7 +541,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, else { GtkAdjustment *old_adjustment; - + old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)); if (old_adjustment == hadjustment) return; @@ -568,10 +560,8 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window); child = gtk_bin_get_child (bin); - if (child) - gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))); + if (GTK_IS_SCROLLABLE (child)) + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), hadjustment); g_object_notify (G_OBJECT (scrolled_window), "hadjustment"); } @@ -585,7 +575,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, */ void gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, - GtkAdjustment *vadjustment) + GtkAdjustment *vadjustment) { GtkScrolledWindowPrivate *priv; GtkBin *bin; @@ -633,10 +623,8 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window); child = gtk_bin_get_child (bin); - if (child) - gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))); + if (GTK_IS_SCROLLABLE (child)) + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment); g_object_notify (G_OBJECT (scrolled_window), "vadjustment"); } @@ -1853,6 +1841,7 @@ gtk_scrolled_window_add (GtkContainer *container, GtkScrolledWindow *scrolled_window; GtkBin *bin; GtkWidget *child_widget; + GtkAdjustment *hadj, *vadj; bin = GTK_BIN (container); child_widget = gtk_bin_get_child (bin); @@ -1864,12 +1853,14 @@ gtk_scrolled_window_add (GtkContainer *container, _gtk_bin_set_child (bin, child); gtk_widget_set_parent (child, GTK_WIDGET (bin)); - /* this is a temporary message */ - if (!gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), - gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))) + hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar)); + vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar)); + + if (GTK_IS_SCROLLABLE (child)) + g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL); + else g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget " - "use gtk_scrolled_window_add_with_viewport() instead"); + "use gtk_scrolled_window_add_with_viewport() instead"); } static void @@ -1879,8 +1870,8 @@ gtk_scrolled_window_remove (GtkContainer *container, g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); g_return_if_fail (child != NULL); g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child); - - gtk_widget_set_scroll_adjustments (child, NULL, NULL); + + g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL); /* chain parent class handler to remove child */ GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child); @@ -1905,9 +1896,8 @@ gtk_scrolled_window_remove (GtkContainer *container, * 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. + * A widget supports scrolling natively if it implements the + * #GtkScrollable interface. */ void gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, @@ -1935,7 +1925,7 @@ gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, { viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window), - gtk_scrolled_window_get_vadjustment (scrolled_window)); + gtk_scrolled_window_get_vadjustment (scrolled_window)); gtk_container_add (GTK_CONTAINER (scrolled_window), viewport); } @@ -2025,9 +2015,20 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, } else { - /* Always ask for at least enough to fit the scrollbars */ - minimum_req.width += vscrollbar_requisition.width; - natural_req.width += vscrollbar_requisition.width; + gint min_display_width = + gtk_scrollable_get_min_display_width (GTK_SCROLLABLE (child)); + + if (min_display_width > 0) + { + minimum_req.width += min_display_width; + natural_req.width += min_display_width; + extra_width = -1; + } + else + { + minimum_req.width += vscrollbar_requisition.width; + natural_req.width += vscrollbar_requisition.width; + } } } else /* GTK_ORIENTATION_VERTICAL */ @@ -2043,9 +2044,20 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, } else { - /* Always ask for at least enough to fit the scrollbars */ - minimum_req.height += hscrollbar_requisition.height; - natural_req.height += hscrollbar_requisition.height; + gint min_display_height = + gtk_scrollable_get_min_display_height (GTK_SCROLLABLE (child)); + + if (min_display_height > 0) + { + minimum_req.height += min_display_height; + natural_req.height += min_display_height; + extra_height = -1; + } + else + { + minimum_req.height += vscrollbar_requisition.height; + natural_req.height += vscrollbar_requisition.height; + } } } } @@ -2064,14 +2076,14 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget, { minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height); natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height); - if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS) + if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS) extra_width = scrollbar_spacing + vscrollbar_requisition.width; } - minimum_req.width += extra_width; - minimum_req.height += extra_height; - natural_req.width += extra_width; - natural_req.height += extra_height; + minimum_req.width += MAX (0, extra_width); + minimum_req.height += MAX (0, extra_height); + natural_req.width += MAX (0, extra_width); + natural_req.height += MAX (0, extra_height); if (priv->shadow_type != GTK_SHADOW_NONE) { |