]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkscrolledwindow.c
Fix several bugs handling GtkTrayIcon symbolic colors
[~andy/gtk] / gtk / gtkscrolledwindow.c
index c23b771b50a36eecdcf760b20751d075959f19eb..86fa7ab65354f4038c39821ab70653d032394e4e 100644 (file)
  */
 
 #include "config.h"
+
 #include <math.h>
-#include <gdk/gdkkeysyms.h>
+
 #include "gtkbindings.h"
-#include "gtksizerequest.h"
 #include "gtkmarshalers.h"
+#include "gtkscrollable.h"
 #include "gtkscrolledwindow.h"
 #include "gtkwindow.h"
 #include "gtkprivate.h"
+#include "gtktypebuiltins.h"
 #include "gtkintl.h"
 
+
+/**
+ * SECTION:gtkscrolledwindow
+ * @Short_description: Adds scrollbars to its child widget
+ * @Title: GtkScrolledWindow
+ * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment
+ *
+ * #GtkScrolledWindow is a #GtkBin subclass: it's a container
+ * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
+ * to the child widget and optionally draws a beveled frame around the
+ * child widget.
+ *
+ * The scrolled window can work in two ways. Some widgets have native
+ * scrolling support; these widgets implement the #GtkScrollable interface.
+ * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
+ * and #GtkLayout.
+ *
+ * For widgets that lack native scrolling support, the #GtkViewport
+ * widget acts as an adaptor class, implementing scrollability for child
+ * widgets that lack their own scrolling capabilities. Use #GtkViewport
+ * to scroll child widgets such as #GtkTable, #GtkBox, and so on.
+ *
+ * If a widget has native scrolling abilities, it can be added to the
+ * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
+ * must first add the widget to a #GtkViewport, then add the #GtkViewport
+ * to the scrolled window. The convenience function
+ * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
+ * ignore the presence of the viewport.
+ *
+ * The position of the scrollbars is controlled by the scroll
+ * adjustments. See #GtkAdjustment for the fields in an adjustment - for
+ * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
+ * represents the position of the scrollbar, which must be between the
+ * "lower" field and "upper - page_size." The "page_size" field
+ * represents the size of the visible scrollable area. The
+ * "step_increment" and "page_increment" fields are used when the user
+ * asks to step down (using the small stepper arrows) or page down (using
+ * for example the PageDown key).
+ *
+ * If a #GtkScrolledWindow doesn't behave quite as you would like, or
+ * doesn't have exactly the right layout, it's very possible to set up
+ * your own scrolling with #GtkScrollbar and for example a #GtkTable.
+ */
+
+
 /* scrolled window policy and size requisition handling:
  *
  * gtk size requisition works as follows:
@@ -88,6 +135,9 @@ struct _GtkScrolledWindowPrivate
   guint    vscrollbar_visible     : 1;
   guint    window_placement       : 2;
   guint    focus_out              : 1;   /* Flag used by ::move-focus-out implementation */
+
+  gint     min_content_width;
+  gint     min_content_height;
 };
 
 
@@ -99,7 +149,9 @@ enum {
   PROP_VSCROLLBAR_POLICY,
   PROP_WINDOW_PLACEMENT,
   PROP_WINDOW_PLACEMENT_SET,
-  PROP_SHADOW_TYPE
+  PROP_SHADOW_TYPE,
+  PROP_MIN_CONTENT_WIDTH,
+  PROP_MIN_CONTENT_HEIGHT
 };
 
 /* Signals */
@@ -110,7 +162,6 @@ enum
   LAST_SIGNAL
 };
 
-static void     gtk_scrolled_window_destroy            (GtkObject         *object);
 static void     gtk_scrolled_window_set_property       (GObject           *object,
                                                         guint              prop_id,
                                                         const GValue      *value,
@@ -120,10 +171,11 @@ static void     gtk_scrolled_window_get_property       (GObject           *objec
                                                         GValue            *value,
                                                         GParamSpec        *pspec);
 
+static void     gtk_scrolled_window_destroy            (GtkWidget         *widget);
 static void     gtk_scrolled_window_screen_changed     (GtkWidget         *widget,
                                                         GdkScreen         *previous_screen);
-static gboolean gtk_scrolled_window_expose             (GtkWidget         *widget,
-                                                        GdkEventExpose    *event);
+static gboolean gtk_scrolled_window_draw               (GtkWidget         *widget,
+                                                        cairo_t           *cr);
 static void     gtk_scrolled_window_size_allocate      (GtkWidget         *widget,
                                                         GtkAllocation     *allocation);
 static gboolean gtk_scrolled_window_scroll_event       (GtkWidget         *widget,
@@ -151,27 +203,24 @@ static void     gtk_scrolled_window_adjustment_changed (GtkAdjustment     *adjus
 
 static void  gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
 
-static void  gtk_scrolled_window_size_request_init     (GtkSizeRequestIface *iface);
-static void  gtk_scrolled_window_get_width             (GtkSizeRequest      *widget,
+static void  gtk_scrolled_window_get_preferred_width   (GtkWidget           *widget,
                                                        gint                *minimum_size,
                                                        gint                *natural_size);
-static void  gtk_scrolled_window_get_height            (GtkSizeRequest      *widget,
+static void  gtk_scrolled_window_get_preferred_height  (GtkWidget           *widget,
                                                        gint                *minimum_size,
                                                        gint                *natural_size);
-static void  gtk_scrolled_window_get_height_for_width  (GtkSizeRequest      *layout,
+static void  gtk_scrolled_window_get_preferred_height_for_width  (GtkWidget           *layout,
                                                        gint                 width,
                                                        gint                *minimum_height,
                                                        gint                *natural_height);
-static void  gtk_scrolled_window_get_width_for_height  (GtkSizeRequest      *layout,
+static void  gtk_scrolled_window_get_preferred_width_for_height  (GtkWidget           *layout,
                                                        gint                 width,
                                                        gint                *minimum_height,
                                                        gint                *natural_height);
 
 static guint signals[LAST_SIGNAL] = {0};
 
-G_DEFINE_TYPE_WITH_CODE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN,
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
-                                                gtk_scrolled_window_size_request_init))
+G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
 
 
 static void
@@ -210,29 +259,31 @@ static void
 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-  GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
   GtkBindingSet *binding_set;
 
-  object_class = (GtkObjectClass*) class;
   widget_class = (GtkWidgetClass*) class;
   container_class = (GtkContainerClass*) class;
 
   gobject_class->set_property = gtk_scrolled_window_set_property;
   gobject_class->get_property = gtk_scrolled_window_get_property;
 
-  object_class->destroy = gtk_scrolled_window_destroy;
-
+  widget_class->destroy = gtk_scrolled_window_destroy;
   widget_class->screen_changed = gtk_scrolled_window_screen_changed;
-  widget_class->expose_event = gtk_scrolled_window_expose;
+  widget_class->draw = gtk_scrolled_window_draw;
   widget_class->size_allocate = gtk_scrolled_window_size_allocate;
   widget_class->scroll_event = gtk_scrolled_window_scroll_event;
   widget_class->focus = gtk_scrolled_window_focus;
+  widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
+  widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
+  widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
+  widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
 
   container_class->add = gtk_scrolled_window_add;
   container_class->remove = gtk_scrolled_window_remove;
   container_class->forall = gtk_scrolled_window_forall;
+  gtk_container_class_handle_border_width (container_class);
 
   class->scrollbar_spacing = -1;
 
@@ -328,24 +379,50 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                                             GTK_PARAM_READABLE));
 
   /**
-   * GtkSettings:gtk-scrolled-window-placement:
+   * GtkScrolledWindow:min-content-width:
    *
-   * Where the contents of scrolled windows are located with respect to the 
-   * scrollbars, if not overridden by the scrolled window's own placement.
+   * The minimum content width of @scrolled_window, or -1 if not set.
    *
-   * Since: 2.10
+   * Since: 3.0
    */
-  gtk_settings_install_property (g_param_spec_enum ("gtk-scrolled-window-placement",
-                                                   P_("Scrolled Window Placement"),
-                                                   P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
-                                                   GTK_TYPE_CORNER_TYPE,
-                                                   GTK_CORNER_TOP_LEFT,
-                                                   G_PARAM_READABLE | G_PARAM_WRITABLE));
-
+  g_object_class_install_property (gobject_class,
+                                   PROP_MIN_CONTENT_WIDTH,
+                                   g_param_spec_int ("min-content-width",
+                                                     P_("Minimum Content Width"),
+                                                     P_("The minimum width that the scrolled window will allocate to its content"),
+                                                     -1, G_MAXINT, -1,
+                                                     GTK_PARAM_READWRITE));
 
+  /**
+   * GtkScrolledWindow:min-content-height:
+   *
+   * The minimum content height of @scrolled_window, or -1 if not set.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_MIN_CONTENT_HEIGHT,
+                                   g_param_spec_int ("min-content-height",
+                                                     P_("Minimum Content Height"),
+                                                     P_("The minimum height that the scrolled window will allocate to its content"),
+                                                     -1, G_MAXINT, -1,
+                                                     GTK_PARAM_READWRITE));
+  /**
+   * GtkScrolledWindow::scroll-child:
+   * @scrolled_window: a #GtkScrolledWindow
+   * @scroll: a #GtkScrollType describing how much to scroll
+   * @horizontal: whether the keybinding scrolls the child
+   *   horizontally or not
+   *
+   * The ::scroll-child signal is a
+   * <link linkend="keybinding-signals">keybinding signal</link>
+   * which gets emitted when a keybinding that scrolls is pressed.
+   * The horizontal or vertical adjustment is updated which triggers a
+   * signal that the scrolled windows child may listen to and scroll itself.
+   */
   signals[SCROLL_CHILD] =
     g_signal_new (I_("scroll-child"),
-                  G_TYPE_FROM_CLASS (object_class),
+                  G_TYPE_FROM_CLASS (gobject_class),
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
                   NULL, NULL,
@@ -353,9 +430,27 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                   G_TYPE_BOOLEAN, 2,
                   GTK_TYPE_SCROLL_TYPE,
                  G_TYPE_BOOLEAN);
+
+  /**
+   * GtkScrolledWindow::move-focus-out:
+   * @scrolled_window: a #GtkScrolledWindow
+   * @direction_type: either %GTK_DIR_TAB_FORWARD or
+   *   %GTK_DIR_TAB_BACKWARD
+   *
+   * The ::move-focus-out signal is a
+   * <link linkend="keybinding-signals">keybinding signal</link>
+   * which gets emitted when focus is moved away from the scrolled
+   * window by a keybinding.
+   * The #GtkWidget::move-focus signal is emitted with @direction_type
+   * on this scrolled windows toplevel parent in the container hierarchy.
+   * The default bindings for this signal are
+   * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
+   * and
+   * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
+   */
   signals[MOVE_FOCUS_OUT] =
     g_signal_new (I_("move-focus-out"),
-                  G_TYPE_FROM_CLASS (object_class),
+                  G_TYPE_FROM_CLASS (gobject_class),
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
                   NULL, NULL,
@@ -407,6 +502,8 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
   priv->focus_out = FALSE;
   priv->window_placement = GTK_CORNER_TOP_LEFT;
   gtk_scrolled_window_update_real_placement (scrolled_window);
+  priv->min_content_width = -1;
+  priv->min_content_height = -1;
 }
 
 /**
@@ -470,7 +567,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
   if (!priv->hscrollbar)
     {
       gtk_widget_push_composite_child ();
-      priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
+      priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
       gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
       gtk_widget_pop_composite_child ();
 
@@ -481,7 +578,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;
@@ -500,10 +597,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_hadjustment (GTK_SCROLLABLE (child), hadjustment);
 
   g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
 }
@@ -517,7 +612,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;
@@ -535,7 +630,7 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
   if (!priv->vscrollbar)
     {
       gtk_widget_push_composite_child ();
-      priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
+      priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
       gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
       gtk_widget_pop_composite_child ();
 
@@ -565,10 +660,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");
 }
@@ -703,10 +796,10 @@ 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 vertical
- *     scrollbar, or %NULL.
+ * @hscrollbar_policy: (out) (allow-none): location to store the policy 
+ *     for the horizontal scrollbar, or %NULL.
+ * @vscrollbar_policy: (out) (allow-none): 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().
@@ -910,9 +1003,9 @@ gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
 }
 
 static void
-gtk_scrolled_window_destroy (GtkObject *object)
+gtk_scrolled_window_destroy (GtkWidget *widget)
 {
-  GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
+  GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
 
   if (priv->hscrollbar)
@@ -936,7 +1029,7 @@ gtk_scrolled_window_destroy (GtkObject *object)
       priv->vscrollbar = NULL;
     }
 
-  GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
+  GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
 }
 
 static void
@@ -981,6 +1074,14 @@ gtk_scrolled_window_set_property (GObject      *object,
       gtk_scrolled_window_set_shadow_type (scrolled_window,
                                           g_value_get_enum (value));
       break;
+    case PROP_MIN_CONTENT_WIDTH:
+      gtk_scrolled_window_set_min_content_width (scrolled_window,
+                                                 g_value_get_int (value));
+      break;
+    case PROP_MIN_CONTENT_HEIGHT:
+      gtk_scrolled_window_set_min_content_height (scrolled_window,
+                                                  g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1006,12 +1107,6 @@ gtk_scrolled_window_get_property (GObject    *object,
       g_value_set_object (value,
                          G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
       break;
-    case PROP_HSCROLLBAR_POLICY:
-      g_value_set_enum (value, priv->hscrollbar_policy);
-      break;
-    case PROP_VSCROLLBAR_POLICY:
-      g_value_set_enum (value, priv->vscrollbar_policy);
-      break;
     case PROP_WINDOW_PLACEMENT:
       g_value_set_enum (value, priv->window_placement);
       break;
@@ -1021,6 +1116,18 @@ gtk_scrolled_window_get_property (GObject    *object,
     case PROP_SHADOW_TYPE:
       g_value_set_enum (value, priv->shadow_type);
       break;
+    case PROP_HSCROLLBAR_POLICY:
+      g_value_set_enum (value, priv->hscrollbar_policy);
+      break;
+    case PROP_VSCROLLBAR_POLICY:
+      g_value_set_enum (value, priv->vscrollbar_policy);
+      break;
+    case PROP_MIN_CONTENT_WIDTH:
+      g_value_set_int (value, priv->min_content_width);
+      break;
+    case PROP_MIN_CONTENT_HEIGHT:
+      g_value_set_int (value, priv->min_content_height);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1083,69 +1190,61 @@ gtk_scrolled_window_screen_changed (GtkWidget *widget,
                     GUINT_TO_POINTER (window_placement_connection));
 }
 
-static void
-gtk_scrolled_window_paint (GtkWidget    *widget,
-                          GdkRectangle *area)
+static gboolean
+gtk_scrolled_window_draw (GtkWidget *widget,
+                          cairo_t   *cr)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
 
   if (priv->shadow_type != GTK_SHADOW_NONE)
     {
-      GtkAllocation allocation;
       GtkAllocation relative_allocation;
-      GtkStyle *style;
+      GtkStyleContext *context;
       gboolean scrollbars_within_bevel;
 
-      style = gtk_widget_get_style (widget);
-      gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
+      context = gtk_widget_get_style_context (widget);
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
 
-      gtk_widget_get_allocation (widget, &allocation);
+      gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
 
       if (!scrollbars_within_bevel)
         {
+          GtkStateFlags state;
+          GtkBorder padding, border;
+
+          state = gtk_widget_get_state_flags (widget);
+          gtk_style_context_get_padding (context, state, &padding);
+          gtk_style_context_get_border (context, state, &border);
+
           gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
 
-          relative_allocation.x -= style->xthickness;
-          relative_allocation.y -= style->ythickness;
-          relative_allocation.width += 2 * style->xthickness;
-          relative_allocation.height += 2 * style->ythickness;
+          relative_allocation.x -= padding.left + border.left;
+          relative_allocation.y -= padding.top + border.top;
+          relative_allocation.width += padding.left + padding.right + border.left + border.right;
+          relative_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
         }
       else
         {
-          GtkContainer *container = GTK_CONTAINER (widget);
-          guint border_width;
-
-          border_width = gtk_container_get_border_width (container);
-
-          relative_allocation.x = border_width;
-          relative_allocation.y = border_width;
-          relative_allocation.width = allocation.width - 2 * border_width;
-          relative_allocation.height = allocation.height - 2 * border_width;
+          relative_allocation.x = 0;
+          relative_allocation.y = 0;
+          relative_allocation.width = gtk_widget_get_allocated_width (widget);
+          relative_allocation.height = gtk_widget_get_allocated_height (widget);
         }
 
-      gtk_paint_shadow (style,
-                        gtk_widget_get_window (widget),
-                       GTK_STATE_NORMAL, priv->shadow_type,
-                       area, widget, "scrolled_window",
-                        allocation.x + relative_allocation.x,
-                        allocation.y + relative_allocation.y,
+      gtk_render_frame (context, cr,
+                        relative_allocation.x,
+                        relative_allocation.y,
                        relative_allocation.width,
                        relative_allocation.height);
-    }
-}
 
-static gboolean
-gtk_scrolled_window_expose (GtkWidget      *widget,
-                           GdkEventExpose *event)
-{
-  if (gtk_widget_is_drawable (widget))
-    {
-      gtk_scrolled_window_paint (widget, &event->area);
-
-      GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event (widget, event);
+      gtk_style_context_restore (context);
     }
 
+  GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
+
   return FALSE;
 }
 
@@ -1248,27 +1347,27 @@ gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
 
   if (adjustment)
     {
-      gdouble value = adjustment->value;
+      gdouble value = gtk_adjustment_get_value (adjustment);
       
       switch (scroll)
        {
        case GTK_SCROLL_STEP_FORWARD:
-         value += adjustment->step_increment;
+         value += gtk_adjustment_get_step_increment (adjustment);
          break;
        case GTK_SCROLL_STEP_BACKWARD:
-         value -= adjustment->step_increment;
+         value -= gtk_adjustment_get_step_increment (adjustment);
          break;
        case GTK_SCROLL_PAGE_FORWARD:
-         value += adjustment->page_increment;
+         value += gtk_adjustment_get_page_increment (adjustment);
          break;
        case GTK_SCROLL_PAGE_BACKWARD:
-         value -= adjustment->page_increment;
+         value -= gtk_adjustment_get_page_increment (adjustment);
          break;
        case GTK_SCROLL_START:
-         value = adjustment->lower;
+         value = gtk_adjustment_get_lower (adjustment);
          break;
        case GTK_SCROLL_END:
-         value = adjustment->upper;
+         value = gtk_adjustment_get_upper (adjustment);
          break;
        default:
          g_assert_not_reached ();
@@ -1313,9 +1412,9 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
   GtkAllocation widget_allocation;
   GtkScrolledWindow *scrolled_window;
   GtkScrolledWindowPrivate *priv;
-  GtkStyle *style;
-  gint scrollbar_spacing;
-  guint border_width;
+  gint sb_spacing;
+  gint sb_width;
+  gint sb_height;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (allocation != NULL);
@@ -1323,17 +1422,34 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   priv = scrolled_window->priv;
 
-  scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+  /* Get possible scrollbar dimensions */
+  sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+  gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
+  gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
 
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-  allocation->x = border_width;
-  allocation->y = border_width;
+  /* Subtract some things from our available allocation size */
+  allocation->x = 0;
+  allocation->y = 0;
 
   if (priv->shadow_type != GTK_SHADOW_NONE)
     {
-      style = gtk_widget_get_style (widget);
-      allocation->x += style->xthickness;
-      allocation->y += style->ythickness;
+      GtkStyleContext *context;
+      GtkStateFlags state;
+      GtkBorder padding, border;
+
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
+
+      gtk_style_context_get_border (context, state, &border);
+      gtk_style_context_get_padding (context, state, &padding);
+
+      allocation->x += padding.left + border.left;
+      allocation->y += padding.top + border.top;
+
+      gtk_style_context_restore (context);
     }
 
   gtk_widget_get_allocation (widget, &widget_allocation);
@@ -1342,11 +1458,8 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
 
   if (priv->vscrollbar_visible)
     {
-      GtkRequisition vscrollbar_requisition;
       gboolean is_rtl;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
-                                 &vscrollbar_requisition, NULL);
       is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
   
       if ((!is_rtl && 
@@ -1355,40 +1468,60 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
          (is_rtl && 
           (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
            priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
-       allocation->x += (vscrollbar_requisition.width +  scrollbar_spacing);
+       allocation->x += (sb_width +  sb_spacing);
 
-      allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
+      allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
     }
   if (priv->hscrollbar_visible)
     {
-      GtkRequisition hscrollbar_requisition;
-
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
-                                 &hscrollbar_requisition, NULL);
 
       if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
          priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
-       allocation->y += (hscrollbar_requisition.height + scrollbar_spacing);
+       allocation->y += (sb_height + sb_spacing);
 
-      allocation->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
+      allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
     }
 }
 
+static void
+gtk_scrolled_window_allocate_child (GtkScrolledWindow *swindow,
+                                   GtkAllocation     *relative_allocation)
+{
+  GtkWidget     *widget = GTK_WIDGET (swindow), *child;
+  GtkAllocation  allocation;
+  GtkAllocation  child_allocation;
+
+  child = gtk_bin_get_child (GTK_BIN (widget));
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gtk_scrolled_window_relative_allocation (widget, relative_allocation);
+  child_allocation.x = relative_allocation->x + allocation.x;
+  child_allocation.y = relative_allocation->y + allocation.y;
+  child_allocation.width = relative_allocation->width;
+  child_allocation.height = relative_allocation->height;
+
+  gtk_widget_size_allocate (child, &child_allocation);
+}
+
 static void
 gtk_scrolled_window_size_allocate (GtkWidget     *widget,
                                   GtkAllocation *allocation)
 {
   GtkScrolledWindow *scrolled_window;
   GtkScrolledWindowPrivate *priv;
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding, border;
   GtkBin *bin;
   GtkAllocation relative_allocation;
   GtkAllocation child_allocation;
   GtkWidget *child;
   gboolean scrollbars_within_bevel;
-  gint scrollbar_spacing;
-  guint border_width;
-  
+  gint sb_spacing;
+  gint sb_width;
+  gint sb_height;
   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
   g_return_if_fail (allocation != NULL);
 
@@ -1396,15 +1529,26 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   bin = GTK_BIN (scrolled_window);
   priv = scrolled_window->priv;
 
-  scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+  /* Get possible scrollbar dimensions */
+  sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+  gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
+  gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
 
-  style = gtk_widget_get_style (widget);
-  gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
 
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (scrolled_window));
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
+
+  gtk_style_context_get_padding (context, state, &padding);
+  gtk_style_context_get_border (context, state, &border);
+
+  gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
 
   gtk_widget_set_allocation (widget, allocation);
 
+  gtk_style_context_restore (context);
+
   if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
     priv->hscrollbar_visible = TRUE;
   else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
@@ -1417,38 +1561,174 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   child = gtk_bin_get_child (bin);
   if (child && gtk_widget_get_visible (child))
     {
+      gint child_scroll_width;
+      gint child_scroll_height;
       gboolean previous_hvis;
       gboolean previous_vvis;
       guint count = 0;
-      
-      do
+
+      /* Determine scrollbar visibility first via hfw apis */
+      if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
        {
-         gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+         if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
+           gtk_widget_get_preferred_width (child, &child_scroll_width, NULL);
+         else
+           gtk_widget_get_preferred_width (child, NULL, &child_scroll_width);
          
-         child_allocation.x = relative_allocation.x + allocation->x;
-         child_allocation.y = relative_allocation.y + allocation->y;
-         child_allocation.width = relative_allocation.width;
-         child_allocation.height = relative_allocation.height;
+         if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+           {
+             /* First try without a vertical scrollbar if the content will fit the height
+              * given the extra width of the scrollbar */
+             if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
+               gtk_widget_get_preferred_height_for_width (child, 
+                                                          MAX (allocation->width, child_scroll_width), 
+                                                          &child_scroll_height, NULL);
+             else
+               gtk_widget_get_preferred_height_for_width (child,
+                                                          MAX (allocation->width, child_scroll_width), 
+                                                          NULL, &child_scroll_height);
+             
+             if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+               {
+                 /* Does the content height fit the allocation height ? */
+                 priv->vscrollbar_visible = child_scroll_height > allocation->height;
+                 
+                 /* Does the content width fit the allocation with minus a possible scrollbar ? */
+                 priv->hscrollbar_visible = 
+                   child_scroll_width > allocation->width - 
+                   (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+                 
+                 /* Now that we've guessed the hscrollbar, does the content height fit
+                  * the possible new allocation height ? */
+                 priv->vscrollbar_visible = 
+                   child_scroll_height > allocation->height - 
+                   (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+                 
+                 /* Now that we've guessed the vscrollbar, does the content width fit
+                  * the possible new allocation width ? */
+                 priv->hscrollbar_visible = 
+                   child_scroll_width > allocation->width - 
+                   (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+               }
+             else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
+               {
+                 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+                 priv->vscrollbar_visible = child_scroll_height > allocation->height - 
+                   (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+               }
+           }
+         else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
+           {
+             priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+             
+             if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+               priv->hscrollbar_visible = 
+                 child_scroll_width > allocation->width - 
+                 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
+             else
+               priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+           }
+       } 
+      else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
+       {
+         if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
+           gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
+         else
+           gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
+         
+         if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+           {
+             /* First try without a horizontal scrollbar if the content will fit the width
+              * given the extra height of the scrollbar */
+             if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
+               gtk_widget_get_preferred_width_for_height (child, 
+                                                          MAX (allocation->height, child_scroll_height), 
+                                                          &child_scroll_width, NULL);
+             else
+               gtk_widget_get_preferred_width_for_height (child, 
+                                                          MAX (allocation->height, child_scroll_height), 
+                                                          NULL, &child_scroll_width);
+             
+             if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+               {
+                 /* Does the content width fit the allocation width ? */
+                 priv->hscrollbar_visible = child_scroll_width > allocation->width;
+                 
+                 /* Does the content height fit the allocation with minus a possible scrollbar ? */
+                 priv->vscrollbar_visible = 
+                   child_scroll_height > allocation->height - 
+                   (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+                 
+                 /* Now that we've guessed the vscrollbar, does the content width fit
+                  * the possible new allocation width ? */
+                 priv->hscrollbar_visible = 
+                   child_scroll_width > allocation->width - 
+                   (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+                 
+                 /* Now that we've guessed the hscrollbar, does the content height fit
+                  * the possible new allocation height ? */
+                 priv->vscrollbar_visible = 
+                   child_scroll_height > allocation->height - 
+                   (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+               }
+             else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
+               {
+                 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+                 priv->hscrollbar_visible = child_scroll_width > allocation->width - 
+                   (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+               }
+           }
+         else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
+           {
+             priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+             
+             if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+               priv->vscrollbar_visible = 
+                 child_scroll_height > allocation->height - 
+                 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
+             else
+               priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+           }
+       }
 
+      /* Now after guessing scrollbar visibility; fall back on the allocation loop which 
+       * observes the adjustments to detect scrollbar visibility and also avoids 
+       * infinite recursion
+       */
+      do
+       {
          previous_hvis = priv->hscrollbar_visible;
          previous_vvis = priv->vscrollbar_visible;
+         gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
 
-         gtk_widget_size_allocate (child, &child_allocation);
+         /* Explicitly force scrollbar visibility checks.
+          *
+          * Since we make a guess above, the child might not decide to update the adjustments 
+          * if they logically did not change since the last configuration
+          */
+         if (priv->hscrollbar)
+           gtk_scrolled_window_adjustment_changed 
+             (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), scrolled_window);
+
+         if (priv->vscrollbar)
+           gtk_scrolled_window_adjustment_changed 
+             (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)), scrolled_window);
 
          /* If, after the first iteration, the hscrollbar and the
-          * vscrollbar flip visiblity, then we need both.
+          * vscrollbar flip visiblity... or if one of the scrollbars flip
+          * on each itteration indefinitly/infinitely, then we just need both 
+          * at this size.
           */
-         if (count &&
-             previous_hvis != priv->hscrollbar_visible &&
-             previous_vvis != priv->vscrollbar_visible)
+         if ((count &&
+              previous_hvis != priv->hscrollbar_visible &&
+              previous_vvis != priv->vscrollbar_visible) || count > 3)
            {
              priv->hscrollbar_visible = TRUE;
              priv->vscrollbar_visible = TRUE;
 
-             /* a new resize is already queued at this point,
-              * so we will immediatedly get reinvoked
-              */
-             return;
+             gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
+
+             break;
            }
          
          count++;
@@ -1465,11 +1745,6 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
 
   if (priv->hscrollbar_visible)
     {
-      GtkRequisition hscrollbar_requisition;
-
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
-                                 &hscrollbar_requisition, NULL);
-
       if (!gtk_widget_get_visible (priv->hscrollbar))
        gtk_widget_show (priv->hscrollbar);
 
@@ -1478,14 +1753,14 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
          priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
        child_allocation.y = (relative_allocation.y +
                              relative_allocation.height +
-                             scrollbar_spacing +
+                             sb_spacing +
                              (priv->shadow_type == GTK_SHADOW_NONE ?
-                              0 : style->ythickness));
+                              0 : padding.top + border.top));
       else
-       child_allocation.y = border_width;
+       child_allocation.y = 0;
 
       child_allocation.width = relative_allocation.width;
-      child_allocation.height = hscrollbar_requisition.height;
+      child_allocation.height = sb_height;
       child_allocation.x += allocation->x;
       child_allocation.y += allocation->y;
 
@@ -1493,17 +1768,17 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
        {
           if (!scrollbars_within_bevel)
             {
-              child_allocation.x -= style->xthickness;
-              child_allocation.width += 2 * style->xthickness;
+              child_allocation.x -= padding.left + border.left;
+              child_allocation.width += padding.left + padding.right + border.left + border.right;
             }
           else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
                    GTK_CORNER_TOP_LEFT == priv->real_window_placement)
             {
-              child_allocation.y -= style->ythickness;
+              child_allocation.y -= padding.top + border.top;
             }
           else
             {
-              child_allocation.y += style->ythickness;
+              child_allocation.y += padding.top + border.top;
             }
        }
 
@@ -1514,13 +1789,9 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
 
   if (priv->vscrollbar_visible)
     {
-      GtkRequisition vscrollbar_requisition;
       if (!gtk_widget_get_visible (priv->vscrollbar))
        gtk_widget_show (priv->vscrollbar);
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
-                                 &vscrollbar_requisition, NULL);
-
       if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL && 
           (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
            priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
@@ -1529,14 +1800,14 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
            priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
        child_allocation.x = (relative_allocation.x +
                              relative_allocation.width +
-                             scrollbar_spacing +
+                             sb_spacing +
                              (priv->shadow_type == GTK_SHADOW_NONE ?
-                              0 : style->xthickness));
+                              0 : padding.left + border.left));
       else
-       child_allocation.x = border_width;
+       child_allocation.x = 0;
 
       child_allocation.y = relative_allocation.y;
-      child_allocation.width = vscrollbar_requisition.width;
+      child_allocation.width = sb_width;
       child_allocation.height = relative_allocation.height;
       child_allocation.x += allocation->x;
       child_allocation.y += allocation->y;
@@ -1545,17 +1816,17 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
        {
           if (!scrollbars_within_bevel)
             {
-              child_allocation.y -= style->ythickness;
-             child_allocation.height += 2 * style->ythickness;
+              child_allocation.y -= padding.top + border.top;
+             child_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
             }
           else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
                    GTK_CORNER_TOP_LEFT == priv->real_window_placement)
             {
-              child_allocation.x -= style->xthickness;
+              child_allocation.x -= padding.left + border.left;
             }
           else
             {
-              child_allocation.x += style->xthickness;
+              child_allocation.x += padding.left + border.left;
             }
        }
 
@@ -1586,12 +1857,12 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
 
   if (range && gtk_widget_get_visible (range))
     {
-      GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
+      GtkAdjustment *adjustment = gtk_range_get_adjustment (GTK_RANGE (range));
       gdouble delta;
 
       delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
 
-      gtk_adjustment_set_value (adj, adj->value + delta);
+      gtk_adjustment_set_value (adjustment, gtk_adjustment_get_value (adjustment) + delta);
 
       return TRUE;
     }
@@ -1642,7 +1913,7 @@ static void
 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
                                        gpointer       data)
 {
-  GtkScrolledWindowPrivate *priv;;
+  GtkScrolledWindowPrivate *priv;
   GtkScrolledWindow *scrolled_window;
 
   g_return_if_fail (adjustment != NULL);
@@ -1659,8 +1930,9 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
          gboolean visible;
 
          visible = priv->hscrollbar_visible;
-         priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
-                                             adjustment->page_size);
+         priv->hscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
+                                     gtk_adjustment_get_page_size (adjustment));
+
          if (priv->hscrollbar_visible != visible)
            gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
        }
@@ -1673,8 +1945,9 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
          gboolean visible;
 
          visible = priv->vscrollbar_visible;
-         priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
-                                             adjustment->page_size);
+         priv->vscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
+                                     gtk_adjustment_get_page_size (adjustment));
+
          if (priv->vscrollbar_visible != visible)
            gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
        }
@@ -1683,12 +1956,13 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
 
 static void
 gtk_scrolled_window_add (GtkContainer *container,
-                        GtkWidget    *child)
+                         GtkWidget    *child)
 {
   GtkScrolledWindowPrivate *priv;
   GtkScrolledWindow *scrolled_window;
   GtkBin *bin;
   GtkWidget *child_widget;
+  GtkAdjustment *hadj, *vadj;
 
   bin = GTK_BIN (container);
   child_widget = gtk_bin_get_child (bin);
@@ -1700,12 +1974,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 (priv->hscrollbar));
+  vadj = gtk_range_get_adjustment (GTK_RANGE (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
@@ -1715,8 +1991,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);
@@ -1741,9 +2017,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,
@@ -1771,7 +2046,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);
     }
 
@@ -1813,19 +2088,10 @@ _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
 
 
 static void
-gtk_scrolled_window_size_request_init (GtkSizeRequestIface *iface)
-{
-  iface->get_width            = gtk_scrolled_window_get_width;
-  iface->get_height           = gtk_scrolled_window_get_height;
-  iface->get_height_for_width = gtk_scrolled_window_get_height_for_width;
-  iface->get_width_for_height = gtk_scrolled_window_get_width_for_height;
-}
-
-static void
-gtk_scrolled_window_get_size (GtkSizeRequest *widget,
-                             GtkOrientation  orientation,
-                             gint           *minimum_size,
-                             gint           *natural_size)
+gtk_scrolled_window_get_preferred_size (GtkWidget      *widget,
+                                        GtkOrientation  orientation,
+                                        gint           *minimum_size,
+                                        gint           *natural_size)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
@@ -1836,10 +2102,8 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
   GtkRequisition hscrollbar_requisition;
   GtkRequisition vscrollbar_requisition;
   GtkRequisition minimum_req, natural_req;
-  GtkStyle *style;
   GtkWidget *child;
   gint min_child_size, nat_child_size;
-  guint border_width;
 
   scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
 
@@ -1850,19 +2114,19 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
   natural_req.width = 0;
   natural_req.height = 0;
 
-  gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
-                             &hscrollbar_requisition, NULL);
-  gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
-                             &vscrollbar_requisition, NULL);
+  gtk_widget_get_preferred_size (priv->hscrollbar,
+                                 &hscrollbar_requisition, NULL);
+  gtk_widget_get_preferred_size (priv->vscrollbar,
+                                 &vscrollbar_requisition, NULL);
 
   child = gtk_bin_get_child (bin);
   if (child && gtk_widget_get_visible (child))
     {
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
        {
-         gtk_size_request_get_width (GTK_SIZE_REQUEST (child),
-                                     &min_child_size,
-                                     &nat_child_size);
+         gtk_widget_get_preferred_width (child,
+                                          &min_child_size,
+                                          &nat_child_size);
 
          if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
            {
@@ -1871,12 +2135,12 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
            }
          else
            {
-             GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
-             
-             if (aux_info && aux_info->width > 0)
+              gint min_content_width = priv->min_content_width;
+
+             if (min_content_width >= 0)
                {
-                 minimum_req.width += aux_info->width;
-                 natural_req.width += aux_info->width;
+                 minimum_req.width = MAX (minimum_req.width, min_content_width);
+                 natural_req.width = MAX (natural_req.width, min_content_width);
                  extra_width = -1;
                }
              else
@@ -1888,9 +2152,9 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
        }
       else /* GTK_ORIENTATION_VERTICAL */
        {
-         gtk_size_request_get_height (GTK_SIZE_REQUEST (child),
-                                      &min_child_size,
-                                      &nat_child_size);
+         gtk_widget_get_preferred_height (child,
+                                           &min_child_size,
+                                           &nat_child_size);
 
          if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
            {
@@ -1899,18 +2163,18 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
            }
          else
            {
-             GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
-             
-             if (aux_info && aux_info->height > 0)
+             gint min_content_height = priv->min_content_height;
+
+             if (min_content_height >= 0)
                {
-                 minimum_req.height += aux_info->height;
-                 natural_req.height += aux_info->height;
+                 minimum_req.height = MAX (minimum_req.height, min_content_height);
+                 natural_req.height = MAX (natural_req.height, min_content_height);
                  extra_height = -1;
                }
              else
                {
-                 minimum_req.height += hscrollbar_requisition.height;
-                 natural_req.height += hscrollbar_requisition.height;
+                 minimum_req.height += vscrollbar_requisition.height;
+                 natural_req.height += vscrollbar_requisition.height;
                }
            }
        }
@@ -1930,23 +2194,36 @@ gtk_scrolled_window_get_size (GtkSizeRequest *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;
     }
 
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-  minimum_req.width += border_width * 2 + MAX (0, extra_width);
-  minimum_req.height += border_width * 2 + MAX (0, extra_height);
-  natural_req.width += border_width * 2 + MAX (0, extra_width);
-  natural_req.height += border_width * 2 + MAX (0, 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)
     {
-      style = gtk_widget_get_style (GTK_WIDGET (widget));
-      minimum_req.width += 2 * style->xthickness;
-      minimum_req.height += 2 * style->ythickness;
-      natural_req.width += 2 * style->xthickness;
-      natural_req.height += 2 * style->ythickness;
+      GtkStyleContext *context;
+      GtkStateFlags state;
+      GtkBorder padding, border;
+
+      context = gtk_widget_get_style_context (GTK_WIDGET (widget));
+      state = gtk_widget_get_state_flags (GTK_WIDGET (widget));
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
+
+      gtk_style_context_get_padding (context, state, &padding);
+      gtk_style_context_get_border (context, state, &border);
+
+      minimum_req.width += padding.left + padding.right + border.left + border.right;
+      minimum_req.height += padding.top + padding.bottom + border.top + border.bottom;
+      natural_req.width += padding.left + padding.right + border.left + border.right;
+      natural_req.height += padding.top + padding.bottom + border.top + border.bottom;
+
+      gtk_style_context_restore (context);
     }
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -1966,39 +2243,137 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
 }
 
 static void     
-gtk_scrolled_window_get_width (GtkSizeRequest      *widget,
-                              gint                   *minimum_size,
-                              gint                   *natural_size)
+gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
+                                         gint      *minimum_size,
+                                         gint      *natural_size)
 {
-  gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+  gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
 }
 
 static void
-gtk_scrolled_window_get_height (GtkSizeRequest      *widget,
-                               gint                *minimum_size,
-                               gint                *natural_size)
+gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
+                                          gint      *minimum_size,
+                                          gint      *natural_size)
 {  
-  gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+  gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
 }
 
 static void
-gtk_scrolled_window_get_height_for_width (GtkSizeRequest *widget,
-                                         gint            width,
-                                         gint           *minimum_height,
-                                         gint           *natural_height)
+gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
+                                                    gint       width,
+                                                    gint      *minimum_height,
+                                                    gint      *natural_height)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height (widget, minimum_height, natural_height);
+  GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
 }
 
 static void
-gtk_scrolled_window_get_width_for_height (GtkSizeRequest *widget,
-                                         gint       height,
-                                         gint      *minimum_width,
-                                         gint      *natural_width)
+gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
+                                                    gint       height,
+                                                    gint      *minimum_width,
+                                                    gint      *natural_width)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_width, natural_width);
+  GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
+}
+
+/**
+ * gtk_scrolled_window_get_min_content_width:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Gets the minimum content width of @scrolled_window, or -1 if not set.
+ *
+ * Returns: the minimum content width
+ *
+ * Since: 3.0
+ */
+gint
+gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
+{
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
+
+  return scrolled_window->priv->min_content_width;
+}
+
+/**
+ * gtk_scrolled_window_set_min_content_width:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @width: the minimal content width
+ *
+ * Sets the minimum width that @scrolled_window should keep visible.
+ * Note that this can and (usually will) be smaller than the minimum
+ * size of the content.
+ *
+ * Since: 3.0
+ */
+void
+gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
+                                           gint               width)
+{
+  GtkScrolledWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+  priv = scrolled_window->priv;
+
+  if (priv->min_content_width != width)
+    {
+      priv->min_content_width = width;
+
+      gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+      g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
+    }
+}
+
+/**
+ * gtk_scrolled_window_get_min_content_height:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Gets the minimal content height of @scrolled_window, or -1 if not set.
+ *
+ * Returns: the minimal content height
+ *
+ * Since: 3.0
+ */
+gint
+gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
+{
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
+
+  return scrolled_window->priv->min_content_height;
+}
+
+/**
+ * gtk_scrolled_window_set_min_content_height:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @height: the minimal content height
+ *
+ * Sets the minimum height that @scrolled_window should keep visible.
+ * Note that this can and (usually will) be smaller than the minimum
+ * size of the content.
+ *
+ * Since: 3.0
+ */
+void
+gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
+                                            gint               height)
+{
+  GtkScrolledWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+  priv = scrolled_window->priv;
+
+  if (priv->min_content_height != height)
+    {
+      priv->min_content_height = height;
+
+      gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+      g_object_notify (G_OBJECT (scrolled_window), "min-content-height");
+    }
 }