]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkscrolledwindow.c
Really make GtkFileSystem private by _-prefixing all functions.
[~andy/gtk] / gtk / gtkscrolledwindow.c
index 59f244b3d318602edba97bea1cb51df2c86fa9bc..91f3258ce1c0a642e31c0afb5b96f95269b1c5f8 100644 (file)
@@ -30,6 +30,7 @@
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkscrolledwindow.h"
+#include "gtkwindow.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 #include "gtkalias.h"
@@ -42,9 +43,9 @@
  *   to be best suited to display its contents, including children.
  *   the width and/or height reported from a widget upon size requisition
  *   may be overidden by the user by specifying a width and/or height
- *   other than 0 through gtk_widget_set_usize().
+ *   other than 0 through gtk_widget_set_size_request().
  *
- * a scrolled window needs (for imlementing all three policy types) to
+ * a scrolled window needs (for implementing all three policy types) to
  * request its width and height based on two different rationales.
  * 1)   the user wants the scrolled window to just fit into the space
  *      that it gets allocated for a specifc dimension.
 
 #define DEFAULT_SCROLLBAR_SPACING  3
 
+typedef struct {
+       gboolean window_placement_set;
+       GtkCornerType real_window_placement;
+} GtkScrolledWindowPrivate;
+
+#define GTK_SCROLLED_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCROLLED_WINDOW, GtkScrolledWindowPrivate))
+
 enum {
   PROP_0,
   PROP_HADJUSTMENT,
@@ -79,8 +87,8 @@ enum {
   PROP_HSCROLLBAR_POLICY,
   PROP_VSCROLLBAR_POLICY,
   PROP_WINDOW_PLACEMENT,
-  PROP_SHADOW_TYPE,
-  PROP_LAST
+  PROP_WINDOW_PLACEMENT_SET,
+  PROP_SHADOW_TYPE
 };
 
 /* Signals */
@@ -91,8 +99,6 @@ enum
   LAST_SIGNAL
 };
 
-static void gtk_scrolled_window_class_init         (GtkScrolledWindowClass *klass);
-static void gtk_scrolled_window_init               (GtkScrolledWindow      *scrolled_window);
 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,
@@ -104,6 +110,8 @@ static void gtk_scrolled_window_get_property       (GObject                *obje
                                                    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,
@@ -122,7 +130,7 @@ static void gtk_scrolled_window_forall             (GtkContainer           *cont
                                                    gboolean                include_internals,
                                                    GtkCallback             callback,
                                                    gpointer                callback_data);
-static void gtk_scrolled_window_scroll_child       (GtkScrolledWindow      *scrolled_window,
+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,
@@ -133,37 +141,11 @@ static void gtk_scrolled_window_relative_allocation(GtkWidget              *widg
 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment          *adjustment,
                                                    gpointer                data);
 
-static GtkContainerClass *parent_class = NULL;
+static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow   *scrolled_window);
 
 static guint signals[LAST_SIGNAL] = {0};
 
-GType
-gtk_scrolled_window_get_type (void)
-{
-  static GType scrolled_window_type = 0;
-
-  if (!scrolled_window_type)
-    {
-      static const GTypeInfo scrolled_window_info =
-      {
-       sizeof (GtkScrolledWindowClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_scrolled_window_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkScrolledWindow),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_scrolled_window_init,
-      };
-
-      scrolled_window_type =
-       g_type_register_static (GTK_TYPE_BIN, "GtkScrolledWindow",
-                               &scrolled_window_info, 0);
-    }
-
-  return scrolled_window_type;
-}
+G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
 
 static void
 add_scroll_binding (GtkBindingSet  *binding_set,
@@ -210,14 +192,13 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
   widget_class = (GtkWidgetClass*) class;
   container_class = (GtkContainerClass*) class;
 
-  parent_class = g_type_class_peek_parent (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;
 
   object_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->size_request = gtk_scrolled_window_size_request;
   widget_class->size_allocate = gtk_scrolled_window_size_allocate;
@@ -268,10 +249,27 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                    PROP_WINDOW_PLACEMENT,
                                    g_param_spec_enum ("window-placement",
                                                       P_("Window Placement"),
-                                                      P_("Where the contents are located with respect to the scrollbars"),
+                                                      P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
                                                      GTK_TYPE_CORNER_TYPE,
                                                      GTK_CORNER_TOP_LEFT,
                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
+  
+  /**
+   * GtkScrolledWindow:window-placement-set:
+   *
+   * Whether "window-placement" should be used to determine the location 
+   * of the contents with respect to the scrollbars. Otherwise, the 
+   * "gtk-scrolled-window-placement" setting is used.
+   *
+   * Since: 2.10
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_WINDOW_PLACEMENT_SET,
+                                   g_param_spec_boolean ("window-placement-set",
+                                                        P_("Window Placement Set"),
+                                                        P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
+                                                        FALSE,
+                                                        GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
   g_object_class_install_property (gobject_class,
                                    PROP_SHADOW_TYPE,
                                    g_param_spec_enum ("shadow-type",
@@ -281,6 +279,20 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                                      GTK_SHADOW_NONE,
                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
 
+  /**
+   * GtkScrolledWindow:scrollbars-within-bevel:
+   *
+   * Whether to place scrollbars within the scrolled window's bevel.
+   *
+   * Since: 2.12
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                          g_param_spec_boolean ("scrollbars-within-bevel",
+                                                                P_("Scrollbars within bevel"),
+                                                                P_("Place scrollbars within the scrolled window's bevel"),
+                                                                FALSE,
+                                                                GTK_PARAM_READABLE));
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("scrollbar-spacing",
                                                             P_("Scrollbar spacing"),
@@ -290,18 +302,34 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
                                                             DEFAULT_SCROLLBAR_SPACING,
                                                             GTK_PARAM_READABLE));
 
+  /**
+   * GtkSettings:gtk-scrolled-window-placement:
+   *
+   * Where the contents of scrolled windows are located with respect to the 
+   * scrollbars, if not overridden by the scrolled window's own placement.
+   *
+   * Since: 2.10
+   */
+  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));
+
+
   signals[SCROLL_CHILD] =
-    g_signal_new ("scroll_child",
+    g_signal_new (I_("scroll_child"),
                   G_TYPE_FROM_CLASS (object_class),
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
                   NULL, NULL,
-                  _gtk_marshal_VOID__ENUM_BOOLEAN,
-                  G_TYPE_NONE, 2,
+                  _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
+                  G_TYPE_BOOLEAN, 2,
                   GTK_TYPE_SCROLL_TYPE,
                  G_TYPE_BOOLEAN);
   signals[MOVE_FOCUS_OUT] =
-    g_signal_new ("move_focus_out",
+    g_signal_new (I_("move_focus_out"),
                   G_TYPE_FROM_CLASS (object_class),
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
@@ -329,6 +357,8 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
 
   add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
   add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
+
+  g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
 }
 
 static void
@@ -344,7 +374,7 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
   scrolled_window->vscrollbar_visible = FALSE;
   scrolled_window->focus_out = FALSE;
   scrolled_window->window_placement = GTK_CORNER_TOP_LEFT;
-  
+  gtk_scrolled_window_update_real_placement (scrolled_window);
 }
 
 GtkWidget*
@@ -495,6 +525,44 @@ gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
          NULL);
 }
 
+/**
+ * gtk_scrolled_window_get_hscrollbar:
+ * @scrolled_window: a #GtkScrolledWindow
+ * 
+ * Returns the horizontal scrollbar of @scrolled_window.
+ *
+ * Returns: the horizontal scrollbar of the scrolled window, or 
+ *  %NULL if it does not have one.
+ *
+ * Since: 2.8
+ */
+GtkWidget*
+gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
+{
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
+  
+  return scrolled_window->hscrollbar;
+}
+
+/**
+ * gtk_scrolled_window_get_vscrollbar:
+ * @scrolled_window: a #GtkScrolledWindow
+ * 
+ * Returns the vertical scrollbar of @scrolled_window.
+ *
+ * Returns: the vertical scrollbar of the scrolled window, or
+ *  %NULL if it does not have one.
+ *
+ * Since: 2.8
+ */
+GtkWidget*
+gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
+{
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
+
+  return scrolled_window->vscrollbar;
+}
+
 void
 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
                                GtkPolicyType      hscrollbar_policy,
@@ -541,30 +609,93 @@ gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
     *vscrollbar_policy = scrolled_window->vscrollbar_policy;
 }
 
-void
-gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
-                                  GtkCornerType      window_placement)
+static void
+gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
 {
-  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+  GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+  GtkSettings *settings;
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
 
+  if (priv->window_placement_set || settings == NULL)
+    priv->real_window_placement = scrolled_window->window_placement;
+  else
+    g_object_get (settings,
+                 "gtk-scrolled-window-placement",
+                 &priv->real_window_placement,
+                 NULL);
+}
+
+static void
+gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
+                                           GtkCornerType      window_placement)
+{
   if (scrolled_window->window_placement != window_placement)
     {
       scrolled_window->window_placement = window_placement;
 
+      gtk_scrolled_window_update_real_placement (scrolled_window);
       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
       
       g_object_notify (G_OBJECT (scrolled_window), "window-placement");
     }
 }
 
+static void
+gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
+                                      gboolean           placement_set,
+                                      gboolean           emit_resize)
+{
+  GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
+  if (priv->window_placement_set != placement_set)
+    {
+      priv->window_placement_set = placement_set;
+
+      gtk_scrolled_window_update_real_placement (scrolled_window);
+      if (emit_resize)
+        gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+      g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
+    }
+}
+
+/**
+ * gtk_scrolled_window_set_placement:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @window_placement: position of the child 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,
+ * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
+ *
+ * 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)
+{
+  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+  gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
+  gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
+}
+
 /**
  * gtk_scrolled_window_get_placement:
  * @scrolled_window: a #GtkScrolledWindow
  *
- * Gets the placement of the scrollbars for the scrolled window. See 
- * gtk_scrolled_window_set_placement().
+ * Gets the placement of the contents with respect to the scrollbars
+ * for the scrolled window. See gtk_scrolled_window_set_placement().
  *
  * Return value: the current placement value.
+ *
+ * See also gtk_scrolled_window_set_placement() and
+ * gtk_scrolled_window_unset_placement().
  **/
 GtkCornerType
 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
@@ -574,6 +705,36 @@ gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
   return scrolled_window->window_placement;
 }
 
+/**
+ * gtk_scrolled_window_unset_placement:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Unsets the placement of the contents with respect to the scrollbars
+ * for the scrolled window. If no window placement is set for a scrolled
+ * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
+ *
+ * See also gtk_scrolled_window_set_placement() and
+ * gtk_scrolled_window_get_placement().
+ *
+ * Since: 2.10
+ **/
+void
+gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
+{
+  GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
+  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+  if (priv->window_placement_set)
+    {
+      priv->window_placement_set = FALSE;
+
+      gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+      g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
+    }
+}
+
 /**
  * gtk_scrolled_window_set_shadow_type:
  * @scrolled_window: a #GtkScrolledWindow
@@ -623,18 +784,14 @@ gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
 static void
 gtk_scrolled_window_destroy (GtkObject *object)
 {
-  GtkScrolledWindow *scrolled_window;
-
-  g_return_if_fail (GTK_IS_SCROLLED_WINDOW (object));
-
-  scrolled_window = GTK_SCROLLED_WINDOW (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);
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
 }
 
 static void
@@ -645,7 +802,7 @@ gtk_scrolled_window_finalize (GObject *object)
   g_object_unref (scrolled_window->hscrollbar);
   g_object_unref (scrolled_window->vscrollbar);
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_scrolled_window_parent_class)->finalize (object);
 }
 
 static void
@@ -677,8 +834,13 @@ gtk_scrolled_window_set_property (GObject      *object,
                                      g_value_get_enum (value));
       break;
     case PROP_WINDOW_PLACEMENT:
-      gtk_scrolled_window_set_placement (scrolled_window,
-                                        g_value_get_enum (value));
+      gtk_scrolled_window_set_placement_internal (scrolled_window,
+                                                 g_value_get_enum (value));
+      break;
+    case PROP_WINDOW_PLACEMENT_SET:
+      gtk_scrolled_window_set_placement_set (scrolled_window,
+                                            g_value_get_boolean (value),
+                                            TRUE);
       break;
     case PROP_SHADOW_TYPE:
       gtk_scrolled_window_set_shadow_type (scrolled_window,
@@ -697,6 +859,7 @@ gtk_scrolled_window_get_property (GObject    *object,
                                  GParamSpec *pspec)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
+  GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
   
   switch (prop_id)
     {
@@ -717,6 +880,9 @@ gtk_scrolled_window_get_property (GObject    *object,
     case PROP_WINDOW_PLACEMENT:
       g_value_set_enum (value, scrolled_window->window_placement);
       break;
+    case PROP_WINDOW_PLACEMENT_SET:
+      g_value_set_boolean (value, priv->window_placement_set);
+      break;
     case PROP_SHADOW_TYPE:
       g_value_set_enum (value, scrolled_window->shadow_type);
       break;
@@ -726,22 +892,94 @@ gtk_scrolled_window_get_property (GObject    *object,
     }
 }
 
+static void
+traverse_container (GtkWidget *widget,
+                   gpointer   data)
+{
+  if (GTK_IS_SCROLLED_WINDOW (widget))
+    {
+      gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
+      gtk_widget_queue_resize (widget);
+    }
+  else if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
+}
+
+static void
+gtk_scrolled_window_settings_changed (GtkSettings *settings)
+{
+  GList *list, *l;
+
+  list = gtk_window_list_toplevels ();
+
+  for (l = list; l; l = l->next)
+    gtk_container_forall (GTK_CONTAINER (l->data), 
+                         traverse_container, NULL);
+
+  g_list_free (list);
+}
+
+static void
+gtk_scrolled_window_screen_changed (GtkWidget *widget,
+                                   GdkScreen *previous_screen)
+{
+  GtkSettings *settings;
+  guint window_placement_connection;
+
+  gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
+
+  if (!gtk_widget_has_screen (widget))
+    return;
+
+  settings = gtk_widget_get_settings (widget);
+
+  window_placement_connection = 
+    GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings), 
+                                        "gtk-scrolled-window-connection"));
+  
+  if (window_placement_connection)
+    return;
+
+  window_placement_connection =
+    g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
+                     G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
+  g_object_set_data (G_OBJECT (settings), 
+                    I_("gtk-scrolled-window-connection"),
+                    GUINT_TO_POINTER (window_placement_connection));
+}
+
 static void
 gtk_scrolled_window_paint (GtkWidget    *widget,
                           GdkRectangle *area)
 {
-  GtkAllocation relative_allocation;
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
 
   if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
     {
-      gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
-      
-      relative_allocation.x -= widget->style->xthickness;
-      relative_allocation.y -= widget->style->ythickness;
-      relative_allocation.width += 2 * widget->style->xthickness;
-      relative_allocation.height += 2 * widget->style->ythickness;
+      GtkAllocation relative_allocation;
+      gboolean scrollbars_within_bevel;
+
+      gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
       
+      if (!scrollbars_within_bevel)
+        {
+          gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+
+          relative_allocation.x -= widget->style->xthickness;
+          relative_allocation.y -= widget->style->ythickness;
+          relative_allocation.width += 2 * widget->style->xthickness;
+          relative_allocation.height += 2 * widget->style->ythickness;
+        }
+      else
+        {
+          GtkContainer *container = GTK_CONTAINER (widget);
+
+          relative_allocation.x = container->border_width;
+          relative_allocation.y = container->border_width;
+          relative_allocation.width = widget->allocation.width - 2 * container->border_width;
+          relative_allocation.height = widget->allocation.height - 2 * container->border_width;
+        }
+
       gtk_paint_shadow (widget->style, widget->window,
                        GTK_STATE_NORMAL, scrolled_window->shadow_type,
                        area, widget, "scrolled_window",
@@ -760,7 +998,7 @@ gtk_scrolled_window_expose (GtkWidget      *widget,
     {
       gtk_scrolled_window_paint (widget, &event->area);
 
-      (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+      (* GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event) (widget, event);
     }
 
   return FALSE;
@@ -775,7 +1013,7 @@ gtk_scrolled_window_forall (GtkContainer *container,
   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
   g_return_if_fail (callback != NULL);
 
-  GTK_CONTAINER_CLASS (parent_class)->forall (container,
+  GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
                                              include_internals,
                                              callback,
                                              callback_data);
@@ -792,7 +1030,7 @@ gtk_scrolled_window_forall (GtkContainer *container,
     }
 }
 
-static void
+static gboolean
 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
                                  GtkScrollType      scroll,
                                  gboolean           horizontal)
@@ -841,10 +1079,14 @@ gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
     case GTK_SCROLL_END:
       break;
     default:
-      g_warning ("Invalid scroll type %d for GtkSpinButton::change-value", scroll);
-      return;
+      g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
+      return FALSE;
     }
 
+  if ((horizontal && (!scrolled_window->hscrollbar || !scrolled_window->hscrollbar_visible)) ||
+      (!horizontal && (!scrolled_window->vscrollbar || !scrolled_window->vscrollbar_visible)))
+    return FALSE;
+
   if (horizontal)
     {
       if (scrolled_window->hscrollbar)
@@ -888,7 +1130,11 @@ gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
       value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
       
       gtk_adjustment_set_value (adjustment, value);
+
+      return TRUE;
     }
+
+  return FALSE;
 }
 
 static void
@@ -1010,6 +1256,7 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
                                         GtkAllocation *allocation)
 {
   GtkScrolledWindow *scrolled_window;
+  GtkScrolledWindowPrivate *priv;
   gint scrollbar_spacing;
 
   g_return_if_fail (widget != NULL);
@@ -1018,6 +1265,8 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
 
+  priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
   allocation->x = GTK_CONTAINER (widget)->border_width;
   allocation->y = GTK_CONTAINER (widget)->border_width;
 
@@ -1040,11 +1289,11 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
       is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
   
       if ((!is_rtl && 
-          (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
-           scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
+          (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
+           priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
          (is_rtl && 
-          (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
-           scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)))
+          (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
+           priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
        allocation->x += (vscrollbar_requisition.width +  scrollbar_spacing);
 
       allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
@@ -1055,8 +1304,8 @@ gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
       gtk_widget_get_child_requisition (scrolled_window->hscrollbar,
                                        &hscrollbar_requisition);
   
-      if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
-         scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+      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->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
@@ -1068,9 +1317,11 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
                                   GtkAllocation *allocation)
 {
   GtkScrolledWindow *scrolled_window;
+  GtkScrolledWindowPrivate *priv;
   GtkBin *bin;
   GtkAllocation relative_allocation;
   GtkAllocation child_allocation;
+  gboolean scrollbars_within_bevel;
   gint scrollbar_spacing;
   
   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
@@ -1080,6 +1331,9 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   bin = GTK_BIN (scrolled_window);
 
   scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+  gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
+
+  priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
 
   widget->allocation = *allocation;
 
@@ -1134,7 +1388,11 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
             previous_vvis != scrolled_window->vscrollbar_visible);
     }
   else
-    gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+    {
+      scrolled_window->hscrollbar_visible = scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS;
+      scrolled_window->vscrollbar_visible = scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS;
+      gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+    }
   
   if (scrolled_window->hscrollbar_visible)
     {
@@ -1146,8 +1404,8 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
        gtk_widget_show (scrolled_window->hscrollbar);
 
       child_allocation.x = relative_allocation.x;
-      if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
-         scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT)
+      if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
+         priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
        child_allocation.y = (relative_allocation.y +
                              relative_allocation.height +
                              scrollbar_spacing +
@@ -1163,8 +1421,20 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
 
       if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
        {
-         child_allocation.x -= widget->style->xthickness;
-         child_allocation.width += 2 * widget->style->xthickness;
+          if (!scrollbars_within_bevel)
+            {
+              child_allocation.x -= widget->style->xthickness;
+              child_allocation.width += 2 * widget->style->xthickness;
+            }
+          else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
+                   GTK_CORNER_TOP_LEFT == priv->real_window_placement)
+            {
+              child_allocation.y -= widget->style->ythickness;
+            }
+          else
+            {
+              child_allocation.y += widget->style->ythickness;
+            }
        }
 
       gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation);
@@ -1182,11 +1452,11 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
                                        &vscrollbar_requisition);
 
       if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL && 
-          (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
-           scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
+          (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
+           priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
          (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR && 
-          (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
-           scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)))
+          (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
+           priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
        child_allocation.x = (relative_allocation.x +
                              relative_allocation.width +
                              scrollbar_spacing +
@@ -1203,8 +1473,20 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
 
       if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
        {
-         child_allocation.y -= widget->style->ythickness;
-         child_allocation.height += 2 * widget->style->ythickness;
+          if (!scrollbars_within_bevel)
+            {
+              child_allocation.y -= widget->style->ythickness;
+             child_allocation.height += 2 * widget->style->ythickness;
+            }
+          else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
+                   GTK_CORNER_TOP_LEFT == priv->real_window_placement)
+            {
+              child_allocation.x -= widget->style->xthickness;
+            }
+          else
+            {
+              child_allocation.x += widget->style->xthickness;
+            }
        }
 
       gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation);
@@ -1353,7 +1635,7 @@ gtk_scrolled_window_remove (GtkContainer *container,
   gtk_widget_set_scroll_adjustments (child, NULL, NULL);
 
   /* chain parent class handler to remove child */
-  GTK_CONTAINER_CLASS (parent_class)->remove (container, child);
+  GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
 }
 
 void