]> Pileus Git - ~andy/gtk/blob - gtk/gtkscrolledwindow.c
Change FSF Address
[~andy/gtk] / gtk / gtkscrolledwindow.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*
19  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
20  * file for a list of people on the GTK+ Team.  See the ChangeLog
21  * files for a list of changes.  These files are distributed with
22  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23  */
24
25 #include "config.h"
26
27 #include <math.h>
28
29 #include "gtkbindings.h"
30 #include "gtkmarshalers.h"
31 #include "gtkscrollable.h"
32 #include "gtkscrollbar.h"
33 #include "gtkscrolledwindow.h"
34 #include "gtkwindow.h"
35 #include "gtkviewport.h"
36 #include "gtkprivate.h"
37 #include "gtktypebuiltins.h"
38 #include "gtkintl.h"
39 #include "gtkviewport.h"
40 #include "a11y/gtkscrolledwindowaccessible.h"
41
42 /**
43  * SECTION:gtkscrolledwindow
44  * @Short_description: Adds scrollbars to its child widget
45  * @Title: GtkScrolledWindow
46  * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment
47  *
48  * #GtkScrolledWindow is a #GtkBin subclass: it's a container
49  * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
50  * to the child widget and optionally draws a beveled frame around the
51  * child widget.
52  *
53  * The scrolled window can work in two ways. Some widgets have native
54  * scrolling support; these widgets implement the #GtkScrollable interface.
55  * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
56  * and #GtkLayout.
57  *
58  * For widgets that lack native scrolling support, the #GtkViewport
59  * widget acts as an adaptor class, implementing scrollability for child
60  * widgets that lack their own scrolling capabilities. Use #GtkViewport
61  * to scroll child widgets such as #GtkGrid, #GtkBox, and so on.
62  *
63  * If a widget has native scrolling abilities, it can be added to the
64  * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
65  * must first add the widget to a #GtkViewport, then add the #GtkViewport
66  * to the scrolled window. The convenience function
67  * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
68  * ignore the presence of the viewport.
69  *
70  * The position of the scrollbars is controlled by the scroll
71  * adjustments. See #GtkAdjustment for the fields in an adjustment - for
72  * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
73  * represents the position of the scrollbar, which must be between the
74  * "lower" field and "upper - page_size." The "page_size" field
75  * represents the size of the visible scrollable area. The
76  * "step_increment" and "page_increment" fields are used when the user
77  * asks to step down (using the small stepper arrows) or page down (using
78  * for example the PageDown key).
79  *
80  * If a #GtkScrolledWindow doesn't behave quite as you would like, or
81  * doesn't have exactly the right layout, it's very possible to set up
82  * your own scrolling with #GtkScrollbar and for example a #GtkGrid.
83  */
84
85
86 /* scrolled window policy and size requisition handling:
87  *
88  * gtk size requisition works as follows:
89  *   a widget upon size-request reports the width and height that it finds
90  *   to be best suited to display its contents, including children.
91  *   the width and/or height reported from a widget upon size requisition
92  *   may be overidden by the user by specifying a width and/or height
93  *   other than 0 through gtk_widget_set_size_request().
94  *
95  * a scrolled window needs (for implementing all three policy types) to
96  * request its width and height based on two different rationales.
97  * 1)   the user wants the scrolled window to just fit into the space
98  *      that it gets allocated for a specifc dimension.
99  * 1.1) this does not apply if the user specified a concrete value
100  *      value for that specific dimension by either specifying usize for the
101  *      scrolled window or for its child.
102  * 2)   the user wants the scrolled window to take as much space up as
103  *      is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
104  *
105  * also, kinda obvious:
106  * 3)   a user would certainly not have choosen a scrolled window as a container
107  *      for the child, if the resulting allocation takes up more space than the
108  *      child would have allocated without the scrolled window.
109  *
110  * conclusions:
111  * A) from 1) follows: the scrolled window shouldn't request more space for a
112  *    specifc dimension than is required at minimum.
113  * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
114  *    window (done automatically) or by usize of the child (needs to be checked).
115  * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
116  *    child's dimension.
117  * D) from 3) follows: the scrolled window child's minimum width and minimum height
118  *    under A) at least correspond to the space taken up by its scrollbars.
119  */
120
121 #define DEFAULT_SCROLLBAR_SPACING  3
122
123 struct _GtkScrolledWindowPrivate
124 {
125   GtkWidget     *hscrollbar;
126   GtkWidget     *vscrollbar;
127
128   GtkCornerType  real_window_placement;
129   guint16  shadow_type;
130
131   guint    window_placement_set   : 1;
132   guint    hscrollbar_policy      : 2;
133   guint    vscrollbar_policy      : 2;
134   guint    hscrollbar_visible     : 1;
135   guint    vscrollbar_visible     : 1;
136   guint    window_placement       : 2;
137   guint    focus_out              : 1; /* Flag used by ::move-focus-out implementation */
138
139   gint     min_content_width;
140   gint     min_content_height;
141 };
142
143
144 enum {
145   PROP_0,
146   PROP_HADJUSTMENT,
147   PROP_VADJUSTMENT,
148   PROP_HSCROLLBAR_POLICY,
149   PROP_VSCROLLBAR_POLICY,
150   PROP_WINDOW_PLACEMENT,
151   PROP_WINDOW_PLACEMENT_SET,
152   PROP_SHADOW_TYPE,
153   PROP_MIN_CONTENT_WIDTH,
154   PROP_MIN_CONTENT_HEIGHT
155 };
156
157 /* Signals */
158 enum
159 {
160   SCROLL_CHILD,
161   MOVE_FOCUS_OUT,
162   LAST_SIGNAL
163 };
164
165 static void     gtk_scrolled_window_set_property       (GObject           *object,
166                                                         guint              prop_id,
167                                                         const GValue      *value,
168                                                         GParamSpec        *pspec);
169 static void     gtk_scrolled_window_get_property       (GObject           *object,
170                                                         guint              prop_id,
171                                                         GValue            *value,
172                                                         GParamSpec        *pspec);
173
174 static void     gtk_scrolled_window_destroy            (GtkWidget         *widget);
175 static void     gtk_scrolled_window_screen_changed     (GtkWidget         *widget,
176                                                         GdkScreen         *previous_screen);
177 static gboolean gtk_scrolled_window_draw               (GtkWidget         *widget,
178                                                         cairo_t           *cr);
179 static void     gtk_scrolled_window_size_allocate      (GtkWidget         *widget,
180                                                         GtkAllocation     *allocation);
181 static gboolean gtk_scrolled_window_scroll_event       (GtkWidget         *widget,
182                                                         GdkEventScroll    *event);
183 static gboolean gtk_scrolled_window_focus              (GtkWidget         *widget,
184                                                         GtkDirectionType   direction);
185 static void     gtk_scrolled_window_add                (GtkContainer      *container,
186                                                         GtkWidget         *widget);
187 static void     gtk_scrolled_window_remove             (GtkContainer      *container,
188                                                         GtkWidget         *widget);
189 static void     gtk_scrolled_window_forall             (GtkContainer      *container,
190                                                         gboolean           include_internals,
191                                                         GtkCallback        callback,
192                                                         gpointer           callback_data);
193 static gboolean gtk_scrolled_window_scroll_child       (GtkScrolledWindow *scrolled_window,
194                                                         GtkScrollType      scroll,
195                                                         gboolean           horizontal);
196 static void     gtk_scrolled_window_move_focus_out     (GtkScrolledWindow *scrolled_window,
197                                                         GtkDirectionType   direction_type);
198
199 static void     gtk_scrolled_window_relative_allocation(GtkWidget         *widget,
200                                                         GtkAllocation     *allocation);
201 static void     gtk_scrolled_window_adjustment_changed (GtkAdjustment     *adjustment,
202                                                         gpointer           data);
203
204 static void  gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
205
206 static void  gtk_scrolled_window_get_preferred_width   (GtkWidget           *widget,
207                                                         gint                *minimum_size,
208                                                         gint                *natural_size);
209 static void  gtk_scrolled_window_get_preferred_height  (GtkWidget           *widget,
210                                                         gint                *minimum_size,
211                                                         gint                *natural_size);
212 static void  gtk_scrolled_window_get_preferred_height_for_width  (GtkWidget           *layout,
213                                                         gint                 width,
214                                                         gint                *minimum_height,
215                                                         gint                *natural_height);
216 static void  gtk_scrolled_window_get_preferred_width_for_height  (GtkWidget           *layout,
217                                                         gint                 width,
218                                                         gint                *minimum_height,
219                                                         gint                *natural_height);
220
221 static guint signals[LAST_SIGNAL] = {0};
222
223 G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
224
225
226 static void
227 add_scroll_binding (GtkBindingSet  *binding_set,
228                     guint           keyval,
229                     GdkModifierType mask,
230                     GtkScrollType   scroll,
231                     gboolean        horizontal)
232 {
233   guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
234   
235   gtk_binding_entry_add_signal (binding_set, keyval, mask,
236                                 "scroll-child", 2,
237                                 GTK_TYPE_SCROLL_TYPE, scroll,
238                                 G_TYPE_BOOLEAN, horizontal);
239   gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
240                                 "scroll-child", 2,
241                                 GTK_TYPE_SCROLL_TYPE, scroll,
242                                 G_TYPE_BOOLEAN, horizontal);
243 }
244
245 static void
246 add_tab_bindings (GtkBindingSet    *binding_set,
247                   GdkModifierType   modifiers,
248                   GtkDirectionType  direction)
249 {
250   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
251                                 "move-focus-out", 1,
252                                 GTK_TYPE_DIRECTION_TYPE, direction);
253   gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
254                                 "move-focus-out", 1,
255                                 GTK_TYPE_DIRECTION_TYPE, direction);
256 }
257
258 static void
259 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
260 {
261   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
262   GtkWidgetClass *widget_class;
263   GtkContainerClass *container_class;
264   GtkBindingSet *binding_set;
265
266   widget_class = (GtkWidgetClass*) class;
267   container_class = (GtkContainerClass*) class;
268
269   gobject_class->set_property = gtk_scrolled_window_set_property;
270   gobject_class->get_property = gtk_scrolled_window_get_property;
271
272   widget_class->destroy = gtk_scrolled_window_destroy;
273   widget_class->screen_changed = gtk_scrolled_window_screen_changed;
274   widget_class->draw = gtk_scrolled_window_draw;
275   widget_class->size_allocate = gtk_scrolled_window_size_allocate;
276   widget_class->scroll_event = gtk_scrolled_window_scroll_event;
277   widget_class->focus = gtk_scrolled_window_focus;
278   widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
279   widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
280   widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
281   widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
282
283   container_class->add = gtk_scrolled_window_add;
284   container_class->remove = gtk_scrolled_window_remove;
285   container_class->forall = gtk_scrolled_window_forall;
286   gtk_container_class_handle_border_width (container_class);
287
288   class->scrollbar_spacing = -1;
289
290   class->scroll_child = gtk_scrolled_window_scroll_child;
291   class->move_focus_out = gtk_scrolled_window_move_focus_out;
292   
293   g_object_class_install_property (gobject_class,
294                                    PROP_HADJUSTMENT,
295                                    g_param_spec_object ("hadjustment",
296                                                         P_("Horizontal Adjustment"),
297                                                         P_("The GtkAdjustment for the horizontal position"),
298                                                         GTK_TYPE_ADJUSTMENT,
299                                                         GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
300   g_object_class_install_property (gobject_class,
301                                    PROP_VADJUSTMENT,
302                                    g_param_spec_object ("vadjustment",
303                                                         P_("Vertical Adjustment"),
304                                                         P_("The GtkAdjustment for the vertical position"),
305                                                         GTK_TYPE_ADJUSTMENT,
306                                                         GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
307   g_object_class_install_property (gobject_class,
308                                    PROP_HSCROLLBAR_POLICY,
309                                    g_param_spec_enum ("hscrollbar-policy",
310                                                       P_("Horizontal Scrollbar Policy"),
311                                                       P_("When the horizontal scrollbar is displayed"),
312                                                       GTK_TYPE_POLICY_TYPE,
313                                                       GTK_POLICY_AUTOMATIC,
314                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
315   g_object_class_install_property (gobject_class,
316                                    PROP_VSCROLLBAR_POLICY,
317                                    g_param_spec_enum ("vscrollbar-policy",
318                                                       P_("Vertical Scrollbar Policy"),
319                                                       P_("When the vertical scrollbar is displayed"),
320                                                       GTK_TYPE_POLICY_TYPE,
321                                                       GTK_POLICY_AUTOMATIC,
322                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
323
324   g_object_class_install_property (gobject_class,
325                                    PROP_WINDOW_PLACEMENT,
326                                    g_param_spec_enum ("window-placement",
327                                                       P_("Window Placement"),
328                                                       P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
329                                                       GTK_TYPE_CORNER_TYPE,
330                                                       GTK_CORNER_TOP_LEFT,
331                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
332   
333   /**
334    * GtkScrolledWindow:window-placement-set:
335    *
336    * Whether "window-placement" should be used to determine the location 
337    * of the contents with respect to the scrollbars. Otherwise, the 
338    * "gtk-scrolled-window-placement" setting is used.
339    *
340    * Since: 2.10
341    */
342   g_object_class_install_property (gobject_class,
343                                    PROP_WINDOW_PLACEMENT_SET,
344                                    g_param_spec_boolean ("window-placement-set",
345                                                          P_("Window Placement Set"),
346                                                          P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
347                                                          FALSE,
348                                                          GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
349   g_object_class_install_property (gobject_class,
350                                    PROP_SHADOW_TYPE,
351                                    g_param_spec_enum ("shadow-type",
352                                                       P_("Shadow Type"),
353                                                       P_("Style of bevel around the contents"),
354                                                       GTK_TYPE_SHADOW_TYPE,
355                                                       GTK_SHADOW_NONE,
356                                                       GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
357
358   /**
359    * GtkScrolledWindow:scrollbars-within-bevel:
360    *
361    * Whether to place scrollbars within the scrolled window's bevel.
362    *
363    * Since: 2.12
364    */
365   gtk_widget_class_install_style_property (widget_class,
366                                            g_param_spec_boolean ("scrollbars-within-bevel",
367                                                                  P_("Scrollbars within bevel"),
368                                                                  P_("Place scrollbars within the scrolled window's bevel"),
369                                                                  FALSE,
370                                                                  GTK_PARAM_READABLE));
371
372   gtk_widget_class_install_style_property (widget_class,
373                                            g_param_spec_int ("scrollbar-spacing",
374                                                              P_("Scrollbar spacing"),
375                                                              P_("Number of pixels between the scrollbars and the scrolled window"),
376                                                              0,
377                                                              G_MAXINT,
378                                                              DEFAULT_SCROLLBAR_SPACING,
379                                                              GTK_PARAM_READABLE));
380
381   /**
382    * GtkScrolledWindow:min-content-width:
383    *
384    * The minimum content width of @scrolled_window, or -1 if not set.
385    *
386    * Since: 3.0
387    */
388   g_object_class_install_property (gobject_class,
389                                    PROP_MIN_CONTENT_WIDTH,
390                                    g_param_spec_int ("min-content-width",
391                                                      P_("Minimum Content Width"),
392                                                      P_("The minimum width that the scrolled window will allocate to its content"),
393                                                      -1, G_MAXINT, -1,
394                                                      GTK_PARAM_READWRITE));
395
396   /**
397    * GtkScrolledWindow:min-content-height:
398    *
399    * The minimum content height of @scrolled_window, or -1 if not set.
400    *
401    * Since: 3.0
402    */
403   g_object_class_install_property (gobject_class,
404                                    PROP_MIN_CONTENT_HEIGHT,
405                                    g_param_spec_int ("min-content-height",
406                                                      P_("Minimum Content Height"),
407                                                      P_("The minimum height that the scrolled window will allocate to its content"),
408                                                      -1, G_MAXINT, -1,
409                                                      GTK_PARAM_READWRITE));
410   /**
411    * GtkScrolledWindow::scroll-child:
412    * @scrolled_window: a #GtkScrolledWindow
413    * @scroll: a #GtkScrollType describing how much to scroll
414    * @horizontal: whether the keybinding scrolls the child
415    *   horizontally or not
416    *
417    * The ::scroll-child signal is a
418    * <link linkend="keybinding-signals">keybinding signal</link>
419    * which gets emitted when a keybinding that scrolls is pressed.
420    * The horizontal or vertical adjustment is updated which triggers a
421    * signal that the scrolled windows child may listen to and scroll itself.
422    */
423   signals[SCROLL_CHILD] =
424     g_signal_new (I_("scroll-child"),
425                   G_TYPE_FROM_CLASS (gobject_class),
426                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
427                   G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
428                   NULL, NULL,
429                   _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
430                   G_TYPE_BOOLEAN, 2,
431                   GTK_TYPE_SCROLL_TYPE,
432                   G_TYPE_BOOLEAN);
433
434   /**
435    * GtkScrolledWindow::move-focus-out:
436    * @scrolled_window: a #GtkScrolledWindow
437    * @direction_type: either %GTK_DIR_TAB_FORWARD or
438    *   %GTK_DIR_TAB_BACKWARD
439    *
440    * The ::move-focus-out signal is a
441    * <link linkend="keybinding-signals">keybinding signal</link>
442    * which gets emitted when focus is moved away from the scrolled
443    * window by a keybinding.
444    * The #GtkWidget::move-focus signal is emitted with @direction_type
445    * on this scrolled windows toplevel parent in the container hierarchy.
446    * The default bindings for this signal are
447    * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
448    * and
449    * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
450    */
451   signals[MOVE_FOCUS_OUT] =
452     g_signal_new (I_("move-focus-out"),
453                   G_TYPE_FROM_CLASS (gobject_class),
454                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
455                   G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
456                   NULL, NULL,
457                   _gtk_marshal_VOID__ENUM,
458                   G_TYPE_NONE, 1,
459                   GTK_TYPE_DIRECTION_TYPE);
460   
461   binding_set = gtk_binding_set_by_class (class);
462
463   add_scroll_binding (binding_set, GDK_KEY_Left,  GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
464   add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD,  TRUE);
465   add_scroll_binding (binding_set, GDK_KEY_Up,    GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
466   add_scroll_binding (binding_set, GDK_KEY_Down,  GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD,  FALSE);
467
468   add_scroll_binding (binding_set, GDK_KEY_Page_Up,   GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
469   add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD,  TRUE);
470   add_scroll_binding (binding_set, GDK_KEY_Page_Up,   0,                GTK_SCROLL_PAGE_BACKWARD, FALSE);
471   add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0,                GTK_SCROLL_PAGE_FORWARD,  FALSE);
472
473   add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
474   add_scroll_binding (binding_set, GDK_KEY_End,  GDK_CONTROL_MASK, GTK_SCROLL_END,   TRUE);
475   add_scroll_binding (binding_set, GDK_KEY_Home, 0,                GTK_SCROLL_START, FALSE);
476   add_scroll_binding (binding_set, GDK_KEY_End,  0,                GTK_SCROLL_END,   FALSE);
477
478   add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
479   add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
480
481   g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
482
483   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCROLLED_WINDOW_ACCESSIBLE);
484 }
485
486 static void
487 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
488 {
489   GtkScrolledWindowPrivate *priv;
490
491   scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
492                                                               GTK_TYPE_SCROLLED_WINDOW,
493                                                               GtkScrolledWindowPrivate);
494
495   gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
496   gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
497
498   priv->hscrollbar = NULL;
499   priv->vscrollbar = NULL;
500   priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
501   priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
502   priv->hscrollbar_visible = FALSE;
503   priv->vscrollbar_visible = FALSE;
504   priv->focus_out = FALSE;
505   priv->window_placement = GTK_CORNER_TOP_LEFT;
506   gtk_scrolled_window_update_real_placement (scrolled_window);
507   priv->min_content_width = -1;
508   priv->min_content_height = -1;
509 }
510
511 /**
512  * gtk_scrolled_window_new:
513  * @hadjustment: (allow-none): horizontal adjustment
514  * @vadjustment: (allow-none): vertical adjustment
515  *
516  * Creates a new scrolled window.
517  *
518  * The two arguments are the scrolled window's adjustments; these will be
519  * shared with the scrollbars and the child widget to keep the bars in sync 
520  * with the child. Usually you want to pass %NULL for the adjustments, which 
521  * will cause the scrolled window to create them for you.
522  *
523  * Returns: a new scrolled window
524  */
525 GtkWidget*
526 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
527                          GtkAdjustment *vadjustment)
528 {
529   GtkWidget *scrolled_window;
530
531   if (hadjustment)
532     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
533
534   if (vadjustment)
535     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
536
537   scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
538                                     "hadjustment", hadjustment,
539                                     "vadjustment", vadjustment,
540                                     NULL);
541
542   return scrolled_window;
543 }
544
545 /**
546  * gtk_scrolled_window_set_hadjustment:
547  * @scrolled_window: a #GtkScrolledWindow
548  * @hadjustment: horizontal scroll adjustment
549  *
550  * Sets the #GtkAdjustment for the horizontal scrollbar.
551  */
552 void
553 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
554                                      GtkAdjustment     *hadjustment)
555 {
556   GtkScrolledWindowPrivate *priv;
557   GtkBin *bin;
558   GtkWidget *child;
559
560   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
561   if (hadjustment)
562     g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
563   else
564     hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
565
566   bin = GTK_BIN (scrolled_window);
567   priv = scrolled_window->priv;
568
569   if (!priv->hscrollbar)
570     {
571       gtk_widget_push_composite_child ();
572       priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
573       gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
574       gtk_widget_pop_composite_child ();
575
576       gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
577       g_object_ref (priv->hscrollbar);
578       gtk_widget_show (priv->hscrollbar);
579     }
580   else
581     {
582       GtkAdjustment *old_adjustment;
583
584       old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
585       if (old_adjustment == hadjustment)
586         return;
587
588       g_signal_handlers_disconnect_by_func (old_adjustment,
589                                             gtk_scrolled_window_adjustment_changed,
590                                             scrolled_window);
591       gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
592                                 hadjustment);
593     }
594   hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
595   g_signal_connect (hadjustment,
596                     "changed",
597                     G_CALLBACK (gtk_scrolled_window_adjustment_changed),
598                     scrolled_window);
599   gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
600
601   child = gtk_bin_get_child (bin);
602   if (GTK_IS_SCROLLABLE (child))
603     gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (child), hadjustment);
604
605   g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
606 }
607
608 /**
609  * gtk_scrolled_window_set_vadjustment:
610  * @scrolled_window: a #GtkScrolledWindow
611  * @vadjustment: vertical scroll adjustment
612  *
613  * Sets the #GtkAdjustment for the vertical scrollbar.
614  */
615 void
616 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
617                                      GtkAdjustment     *vadjustment)
618 {
619   GtkScrolledWindowPrivate *priv;
620   GtkBin *bin;
621   GtkWidget *child;
622
623   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
624   if (vadjustment)
625     g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
626   else
627     vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
628
629   bin = GTK_BIN (scrolled_window);
630   priv = scrolled_window->priv;
631
632   if (!priv->vscrollbar)
633     {
634       gtk_widget_push_composite_child ();
635       priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
636       gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
637       gtk_widget_pop_composite_child ();
638
639       gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
640       g_object_ref (priv->vscrollbar);
641       gtk_widget_show (priv->vscrollbar);
642     }
643   else
644     {
645       GtkAdjustment *old_adjustment;
646       
647       old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
648       if (old_adjustment == vadjustment)
649         return;
650
651       g_signal_handlers_disconnect_by_func (old_adjustment,
652                                             gtk_scrolled_window_adjustment_changed,
653                                             scrolled_window);
654       gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
655                                 vadjustment);
656     }
657   vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
658   g_signal_connect (vadjustment,
659                     "changed",
660                     G_CALLBACK (gtk_scrolled_window_adjustment_changed),
661                     scrolled_window);
662   gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
663
664   child = gtk_bin_get_child (bin);
665   if (GTK_IS_SCROLLABLE (child))
666     gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
667
668   g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
669 }
670
671 /**
672  * gtk_scrolled_window_get_hadjustment:
673  * @scrolled_window: a #GtkScrolledWindow
674  *
675  * Returns the horizontal scrollbar's adjustment, used to connect the
676  * horizontal scrollbar to the child widget's horizontal scroll
677  * functionality.
678  *
679  * Returns: (transfer none): the horizontal #GtkAdjustment
680  */
681 GtkAdjustment*
682 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
683 {
684   GtkScrolledWindowPrivate *priv;
685
686   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
687
688   priv = scrolled_window->priv;
689
690   return (priv->hscrollbar ?
691           gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
692           NULL);
693 }
694
695 /**
696  * gtk_scrolled_window_get_vadjustment:
697  * @scrolled_window: a #GtkScrolledWindow
698  * 
699  * Returns the vertical scrollbar's adjustment, used to connect the
700  * vertical scrollbar to the child widget's vertical scroll functionality.
701  * 
702  * Returns: (transfer none): the vertical #GtkAdjustment
703  */
704 GtkAdjustment*
705 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
706 {
707   GtkScrolledWindowPrivate *priv;
708
709   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
710
711   priv = scrolled_window->priv;
712
713   return (priv->vscrollbar ?
714           gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
715           NULL);
716 }
717
718 /**
719  * gtk_scrolled_window_get_hscrollbar:
720  * @scrolled_window: a #GtkScrolledWindow
721  *
722  * Returns the horizontal scrollbar of @scrolled_window.
723  *
724  * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
725  *     or %NULL if it does not have one.
726  *
727  * Since: 2.8
728  */
729 GtkWidget*
730 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
731 {
732   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
733
734   return scrolled_window->priv->hscrollbar;
735 }
736
737 /**
738  * gtk_scrolled_window_get_vscrollbar:
739  * @scrolled_window: a #GtkScrolledWindow
740  * 
741  * Returns the vertical scrollbar of @scrolled_window.
742  *
743  * Returns: (transfer none): the vertical scrollbar of the scrolled window,
744  *     or %NULL if it does not have one.
745  *
746  * Since: 2.8
747  */
748 GtkWidget*
749 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
750 {
751   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
752
753   return scrolled_window->priv->vscrollbar;
754 }
755
756 /**
757  * gtk_scrolled_window_set_policy:
758  * @scrolled_window: a #GtkScrolledWindow
759  * @hscrollbar_policy: policy for horizontal bar
760  * @vscrollbar_policy: policy for vertical bar
761  * 
762  * Sets the scrollbar policy for the horizontal and vertical scrollbars.
763  *
764  * The policy determines when the scrollbar should appear; it is a value
765  * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
766  * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
767  * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
768  * if needed (that is, if the slider part of the bar would be smaller
769  * than the trough - the display is larger than the page size).
770  */
771 void
772 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
773                                 GtkPolicyType      hscrollbar_policy,
774                                 GtkPolicyType      vscrollbar_policy)
775 {
776   GtkScrolledWindowPrivate *priv;
777   GObject *object = G_OBJECT (scrolled_window);
778   
779   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
780
781   priv = scrolled_window->priv;
782
783   if ((priv->hscrollbar_policy != hscrollbar_policy) ||
784       (priv->vscrollbar_policy != vscrollbar_policy))
785     {
786       priv->hscrollbar_policy = hscrollbar_policy;
787       priv->vscrollbar_policy = vscrollbar_policy;
788
789       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
790
791       g_object_freeze_notify (object);
792       g_object_notify (object, "hscrollbar-policy");
793       g_object_notify (object, "vscrollbar-policy");
794       g_object_thaw_notify (object);
795     }
796 }
797
798 /**
799  * gtk_scrolled_window_get_policy:
800  * @scrolled_window: a #GtkScrolledWindow
801  * @hscrollbar_policy: (out) (allow-none): location to store the policy 
802  *     for the horizontal scrollbar, or %NULL.
803  * @vscrollbar_policy: (out) (allow-none): location to store the policy
804  *     for the vertical scrollbar, or %NULL.
805  * 
806  * Retrieves the current policy values for the horizontal and vertical
807  * scrollbars. See gtk_scrolled_window_set_policy().
808  */
809 void
810 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
811                                 GtkPolicyType     *hscrollbar_policy,
812                                 GtkPolicyType     *vscrollbar_policy)
813 {
814   GtkScrolledWindowPrivate *priv;
815
816   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
817
818   priv = scrolled_window->priv;
819
820   if (hscrollbar_policy)
821     *hscrollbar_policy = priv->hscrollbar_policy;
822   if (vscrollbar_policy)
823     *vscrollbar_policy = priv->vscrollbar_policy;
824 }
825
826 static void
827 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
828 {
829   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
830   GtkSettings *settings;
831
832   settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
833
834   if (priv->window_placement_set || settings == NULL)
835     priv->real_window_placement = priv->window_placement;
836   else
837     g_object_get (settings,
838                   "gtk-scrolled-window-placement",
839                   &priv->real_window_placement,
840                   NULL);
841 }
842
843 static void
844 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
845                                             GtkCornerType      window_placement)
846 {
847   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
848
849   if (priv->window_placement != window_placement)
850     {
851       priv->window_placement = window_placement;
852
853       gtk_scrolled_window_update_real_placement (scrolled_window);
854       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
855       
856       g_object_notify (G_OBJECT (scrolled_window), "window-placement");
857     }
858 }
859
860 static void
861 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
862                                        gboolean           placement_set,
863                                        gboolean           emit_resize)
864 {
865   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
866
867   if (priv->window_placement_set != placement_set)
868     {
869       priv->window_placement_set = placement_set;
870
871       gtk_scrolled_window_update_real_placement (scrolled_window);
872       if (emit_resize)
873         gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
874
875       g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
876     }
877 }
878
879 /**
880  * gtk_scrolled_window_set_placement:
881  * @scrolled_window: a #GtkScrolledWindow
882  * @window_placement: position of the child window
883  *
884  * Sets the placement of the contents with respect to the scrollbars
885  * for the scrolled window.
886  * 
887  * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
888  * in the top left, with the scrollbars underneath and to the right.
889  * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
890  * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
891  *
892  * See also gtk_scrolled_window_get_placement() and
893  * gtk_scrolled_window_unset_placement().
894  */
895 void
896 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
897                                    GtkCornerType      window_placement)
898 {
899   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
900
901   gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
902   gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
903 }
904
905 /**
906  * gtk_scrolled_window_get_placement:
907  * @scrolled_window: a #GtkScrolledWindow
908  *
909  * Gets the placement of the contents with respect to the scrollbars
910  * for the scrolled window. See gtk_scrolled_window_set_placement().
911  *
912  * Return value: the current placement value.
913  *
914  * See also gtk_scrolled_window_set_placement() and
915  * gtk_scrolled_window_unset_placement().
916  **/
917 GtkCornerType
918 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
919 {
920   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
921
922   return scrolled_window->priv->window_placement;
923 }
924
925 /**
926  * gtk_scrolled_window_unset_placement:
927  * @scrolled_window: a #GtkScrolledWindow
928  *
929  * Unsets the placement of the contents with respect to the scrollbars
930  * for the scrolled window. If no window placement is set for a scrolled
931  * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
932  *
933  * See also gtk_scrolled_window_set_placement() and
934  * gtk_scrolled_window_get_placement().
935  *
936  * Since: 2.10
937  **/
938 void
939 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
940 {
941   GtkScrolledWindowPrivate *priv;
942
943   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
944
945   priv = scrolled_window->priv;
946
947   if (priv->window_placement_set)
948     {
949       priv->window_placement_set = FALSE;
950
951       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
952
953       g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
954     }
955 }
956
957 /**
958  * gtk_scrolled_window_set_shadow_type:
959  * @scrolled_window: a #GtkScrolledWindow
960  * @type: kind of shadow to draw around scrolled window contents
961  *
962  * Changes the type of shadow drawn around the contents of
963  * @scrolled_window.
964  * 
965  **/
966 void
967 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
968                                      GtkShadowType      type)
969 {
970   GtkScrolledWindowPrivate *priv;
971
972   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
973   g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
974
975   priv = scrolled_window->priv;
976
977   if (priv->shadow_type != type)
978     {
979       priv->shadow_type = type;
980
981       if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
982         gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
983
984       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
985
986       g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
987     }
988 }
989
990 /**
991  * gtk_scrolled_window_get_shadow_type:
992  * @scrolled_window: a #GtkScrolledWindow
993  *
994  * Gets the shadow type of the scrolled window. See 
995  * gtk_scrolled_window_set_shadow_type().
996  *
997  * Return value: the current shadow type
998  **/
999 GtkShadowType
1000 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
1001 {
1002   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
1003
1004   return scrolled_window->priv->shadow_type;
1005 }
1006
1007 static void
1008 gtk_scrolled_window_destroy (GtkWidget *widget)
1009 {
1010   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1011   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1012
1013   if (priv->hscrollbar)
1014     {
1015       g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
1016                                             gtk_scrolled_window_adjustment_changed,
1017                                             scrolled_window);
1018       gtk_widget_unparent (priv->hscrollbar);
1019       gtk_widget_destroy (priv->hscrollbar);
1020       g_object_unref (priv->hscrollbar);
1021       priv->hscrollbar = NULL;
1022     }
1023   if (priv->vscrollbar)
1024     {
1025       g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
1026                                             gtk_scrolled_window_adjustment_changed,
1027                                             scrolled_window);
1028       gtk_widget_unparent (priv->vscrollbar);
1029       gtk_widget_destroy (priv->vscrollbar);
1030       g_object_unref (priv->vscrollbar);
1031       priv->vscrollbar = NULL;
1032     }
1033
1034   GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
1035 }
1036
1037 static void
1038 gtk_scrolled_window_set_property (GObject      *object,
1039                                   guint         prop_id,
1040                                   const GValue *value,
1041                                   GParamSpec   *pspec)
1042 {
1043   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1044   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1045
1046   switch (prop_id)
1047     {
1048     case PROP_HADJUSTMENT:
1049       gtk_scrolled_window_set_hadjustment (scrolled_window,
1050                                            g_value_get_object (value));
1051       break;
1052     case PROP_VADJUSTMENT:
1053       gtk_scrolled_window_set_vadjustment (scrolled_window,
1054                                            g_value_get_object (value));
1055       break;
1056     case PROP_HSCROLLBAR_POLICY:
1057       gtk_scrolled_window_set_policy (scrolled_window,
1058                                       g_value_get_enum (value),
1059                                       priv->vscrollbar_policy);
1060       break;
1061     case PROP_VSCROLLBAR_POLICY:
1062       gtk_scrolled_window_set_policy (scrolled_window,
1063                                       priv->hscrollbar_policy,
1064                                       g_value_get_enum (value));
1065       break;
1066     case PROP_WINDOW_PLACEMENT:
1067       gtk_scrolled_window_set_placement_internal (scrolled_window,
1068                                                   g_value_get_enum (value));
1069       break;
1070     case PROP_WINDOW_PLACEMENT_SET:
1071       gtk_scrolled_window_set_placement_set (scrolled_window,
1072                                              g_value_get_boolean (value),
1073                                              TRUE);
1074       break;
1075     case PROP_SHADOW_TYPE:
1076       gtk_scrolled_window_set_shadow_type (scrolled_window,
1077                                            g_value_get_enum (value));
1078       break;
1079     case PROP_MIN_CONTENT_WIDTH:
1080       gtk_scrolled_window_set_min_content_width (scrolled_window,
1081                                                  g_value_get_int (value));
1082       break;
1083     case PROP_MIN_CONTENT_HEIGHT:
1084       gtk_scrolled_window_set_min_content_height (scrolled_window,
1085                                                   g_value_get_int (value));
1086       break;
1087     default:
1088       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1089       break;
1090     }
1091 }
1092
1093 static void
1094 gtk_scrolled_window_get_property (GObject    *object,
1095                                   guint       prop_id,
1096                                   GValue     *value,
1097                                   GParamSpec *pspec)
1098 {
1099   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1100   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1101
1102   switch (prop_id)
1103     {
1104     case PROP_HADJUSTMENT:
1105       g_value_set_object (value,
1106                           G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1107       break;
1108     case PROP_VADJUSTMENT:
1109       g_value_set_object (value,
1110                           G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1111       break;
1112     case PROP_WINDOW_PLACEMENT:
1113       g_value_set_enum (value, priv->window_placement);
1114       break;
1115     case PROP_WINDOW_PLACEMENT_SET:
1116       g_value_set_boolean (value, priv->window_placement_set);
1117       break;
1118     case PROP_SHADOW_TYPE:
1119       g_value_set_enum (value, priv->shadow_type);
1120       break;
1121     case PROP_HSCROLLBAR_POLICY:
1122       g_value_set_enum (value, priv->hscrollbar_policy);
1123       break;
1124     case PROP_VSCROLLBAR_POLICY:
1125       g_value_set_enum (value, priv->vscrollbar_policy);
1126       break;
1127     case PROP_MIN_CONTENT_WIDTH:
1128       g_value_set_int (value, priv->min_content_width);
1129       break;
1130     case PROP_MIN_CONTENT_HEIGHT:
1131       g_value_set_int (value, priv->min_content_height);
1132       break;
1133     default:
1134       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1135       break;
1136     }
1137 }
1138
1139 static void
1140 traverse_container (GtkWidget *widget,
1141                     gpointer   data)
1142 {
1143   if (GTK_IS_SCROLLED_WINDOW (widget))
1144     {
1145       gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1146       gtk_widget_queue_resize (widget);
1147     }
1148   else if (GTK_IS_CONTAINER (widget))
1149     gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1150 }
1151
1152 static void
1153 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1154 {
1155   GList *list, *l;
1156
1157   list = gtk_window_list_toplevels ();
1158
1159   for (l = list; l; l = l->next)
1160     gtk_container_forall (GTK_CONTAINER (l->data), 
1161                           traverse_container, NULL);
1162
1163   g_list_free (list);
1164 }
1165
1166 static void
1167 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1168                                     GdkScreen *previous_screen)
1169 {
1170   GtkSettings *settings;
1171   guint window_placement_connection;
1172
1173   gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1174
1175   if (!gtk_widget_has_screen (widget))
1176     return;
1177
1178   settings = gtk_widget_get_settings (widget);
1179
1180   window_placement_connection = 
1181     GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings), 
1182                                          "gtk-scrolled-window-connection"));
1183   
1184   if (window_placement_connection)
1185     return;
1186
1187   window_placement_connection =
1188     g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1189                       G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1190   g_object_set_data (G_OBJECT (settings), 
1191                      I_("gtk-scrolled-window-connection"),
1192                      GUINT_TO_POINTER (window_placement_connection));
1193 }
1194
1195 static gboolean
1196 gtk_scrolled_window_draw (GtkWidget *widget,
1197                           cairo_t   *cr)
1198 {
1199   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1200   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1201   GtkStyleContext *context;
1202
1203   context = gtk_widget_get_style_context (widget);
1204
1205   gtk_render_background (context, cr, 0, 0,
1206                          gtk_widget_get_allocated_width (widget),
1207                          gtk_widget_get_allocated_height (widget));
1208
1209   if (priv->shadow_type != GTK_SHADOW_NONE)
1210     {
1211       GtkAllocation relative_allocation;
1212       gboolean scrollbars_within_bevel;
1213
1214       gtk_style_context_save (context);
1215       gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
1216
1217       gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1218
1219       if (!scrollbars_within_bevel)
1220         {
1221           GtkStateFlags state;
1222           GtkBorder padding, border;
1223
1224           state = gtk_widget_get_state_flags (widget);
1225           gtk_style_context_get_padding (context, state, &padding);
1226           gtk_style_context_get_border (context, state, &border);
1227
1228           gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1229
1230           relative_allocation.x -= padding.left + border.left;
1231           relative_allocation.y -= padding.top + border.top;
1232           relative_allocation.width += padding.left + padding.right + border.left + border.right;
1233           relative_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
1234         }
1235       else
1236         {
1237           relative_allocation.x = 0;
1238           relative_allocation.y = 0;
1239           relative_allocation.width = gtk_widget_get_allocated_width (widget);
1240           relative_allocation.height = gtk_widget_get_allocated_height (widget);
1241         }
1242
1243       gtk_render_frame (context, cr,
1244                         relative_allocation.x,
1245                         relative_allocation.y,
1246                         relative_allocation.width,
1247                         relative_allocation.height);
1248
1249       gtk_style_context_restore (context);
1250     }
1251
1252   GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1253
1254   return FALSE;
1255 }
1256
1257 static void
1258 gtk_scrolled_window_forall (GtkContainer *container,
1259                             gboolean      include_internals,
1260                             GtkCallback   callback,
1261                             gpointer      callback_data)
1262 {
1263   GtkScrolledWindowPrivate *priv;
1264   GtkScrolledWindow *scrolled_window;
1265
1266   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1267   g_return_if_fail (callback != NULL);
1268
1269   GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1270                                               include_internals,
1271                                               callback,
1272                                               callback_data);
1273   if (include_internals)
1274     {
1275       scrolled_window = GTK_SCROLLED_WINDOW (container);
1276       priv = scrolled_window->priv;
1277
1278       if (priv->vscrollbar)
1279         callback (priv->vscrollbar, callback_data);
1280       if (priv->hscrollbar)
1281         callback (priv->hscrollbar, callback_data);
1282     }
1283 }
1284
1285 static gboolean
1286 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1287                                   GtkScrollType      scroll,
1288                                   gboolean           horizontal)
1289 {
1290   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1291   GtkAdjustment *adjustment = NULL;
1292   
1293   switch (scroll)
1294     {
1295     case GTK_SCROLL_STEP_UP:
1296       scroll = GTK_SCROLL_STEP_BACKWARD;
1297       horizontal = FALSE;
1298       break;
1299     case GTK_SCROLL_STEP_DOWN:
1300       scroll = GTK_SCROLL_STEP_FORWARD;
1301       horizontal = FALSE;
1302       break;
1303     case GTK_SCROLL_STEP_LEFT:
1304       scroll = GTK_SCROLL_STEP_BACKWARD;
1305       horizontal = TRUE;
1306       break;
1307     case GTK_SCROLL_STEP_RIGHT:
1308       scroll = GTK_SCROLL_STEP_FORWARD;
1309       horizontal = TRUE;
1310       break;
1311     case GTK_SCROLL_PAGE_UP:
1312       scroll = GTK_SCROLL_PAGE_BACKWARD;
1313       horizontal = FALSE;
1314       break;
1315     case GTK_SCROLL_PAGE_DOWN:
1316       scroll = GTK_SCROLL_PAGE_FORWARD;
1317       horizontal = FALSE;
1318       break;
1319     case GTK_SCROLL_PAGE_LEFT:
1320       scroll = GTK_SCROLL_STEP_BACKWARD;
1321       horizontal = TRUE;
1322       break;
1323     case GTK_SCROLL_PAGE_RIGHT:
1324       scroll = GTK_SCROLL_STEP_FORWARD;
1325       horizontal = TRUE;
1326       break;
1327     case GTK_SCROLL_STEP_BACKWARD:
1328     case GTK_SCROLL_STEP_FORWARD:
1329     case GTK_SCROLL_PAGE_BACKWARD:
1330     case GTK_SCROLL_PAGE_FORWARD:
1331     case GTK_SCROLL_START:
1332     case GTK_SCROLL_END:
1333       break;
1334     default:
1335       g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1336       return FALSE;
1337     }
1338
1339   if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1340       (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1341     return FALSE;
1342
1343   if (horizontal)
1344     {
1345       if (priv->hscrollbar)
1346         adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1347     }
1348   else
1349     {
1350       if (priv->vscrollbar)
1351         adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1352     }
1353
1354   if (adjustment)
1355     {
1356       gdouble value = gtk_adjustment_get_value (adjustment);
1357       
1358       switch (scroll)
1359         {
1360         case GTK_SCROLL_STEP_FORWARD:
1361           value += gtk_adjustment_get_step_increment (adjustment);
1362           break;
1363         case GTK_SCROLL_STEP_BACKWARD:
1364           value -= gtk_adjustment_get_step_increment (adjustment);
1365           break;
1366         case GTK_SCROLL_PAGE_FORWARD:
1367           value += gtk_adjustment_get_page_increment (adjustment);
1368           break;
1369         case GTK_SCROLL_PAGE_BACKWARD:
1370           value -= gtk_adjustment_get_page_increment (adjustment);
1371           break;
1372         case GTK_SCROLL_START:
1373           value = gtk_adjustment_get_lower (adjustment);
1374           break;
1375         case GTK_SCROLL_END:
1376           value = gtk_adjustment_get_upper (adjustment);
1377           break;
1378         default:
1379           g_assert_not_reached ();
1380           break;
1381         }
1382
1383       gtk_adjustment_set_value (adjustment, value);
1384
1385       return TRUE;
1386     }
1387
1388   return FALSE;
1389 }
1390
1391 static void
1392 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1393                                     GtkDirectionType   direction_type)
1394 {
1395   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1396   GtkWidget *toplevel;
1397   
1398   /* Focus out of the scrolled window entirely. We do this by setting
1399    * a flag, then propagating the focus motion to the notebook.
1400    */
1401   toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1402   if (!gtk_widget_is_toplevel (toplevel))
1403     return;
1404
1405   g_object_ref (scrolled_window);
1406
1407   priv->focus_out = TRUE;
1408   g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1409   priv->focus_out = FALSE;
1410
1411   g_object_unref (scrolled_window);
1412 }
1413
1414 static void
1415 gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
1416                                          GtkAllocation *allocation)
1417 {
1418   GtkAllocation widget_allocation;
1419   GtkScrolledWindow *scrolled_window;
1420   GtkScrolledWindowPrivate *priv;
1421   gint sb_spacing;
1422   gint sb_width;
1423   gint sb_height;
1424
1425   g_return_if_fail (widget != NULL);
1426   g_return_if_fail (allocation != NULL);
1427
1428   scrolled_window = GTK_SCROLLED_WINDOW (widget);
1429   priv = scrolled_window->priv;
1430
1431   /* Get possible scrollbar dimensions */
1432   sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1433   gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1434   gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1435
1436   /* Subtract some things from our available allocation size */
1437   allocation->x = 0;
1438   allocation->y = 0;
1439
1440   if (priv->shadow_type != GTK_SHADOW_NONE)
1441     {
1442       GtkStyleContext *context;
1443       GtkStateFlags state;
1444       GtkBorder padding, border;
1445
1446       context = gtk_widget_get_style_context (widget);
1447       state = gtk_widget_get_state_flags (widget);
1448
1449       gtk_style_context_save (context);
1450       gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
1451
1452       gtk_style_context_get_border (context, state, &border);
1453       gtk_style_context_get_padding (context, state, &padding);
1454
1455       allocation->x += padding.left + border.left;
1456       allocation->y += padding.top + border.top;
1457
1458       gtk_style_context_restore (context);
1459     }
1460
1461   gtk_widget_get_allocation (widget, &widget_allocation);
1462   allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1463   allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1464
1465   if (priv->vscrollbar_visible)
1466     {
1467       gboolean is_rtl;
1468
1469       is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1470   
1471       if ((!is_rtl && 
1472            (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1473             priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1474           (is_rtl && 
1475            (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1476             priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1477         allocation->x += (sb_width +  sb_spacing);
1478
1479       allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1480     }
1481   if (priv->hscrollbar_visible)
1482     {
1483
1484       if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1485           priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1486         allocation->y += (sb_height + sb_spacing);
1487
1488       allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1489     }
1490 }
1491
1492 static void
1493 gtk_scrolled_window_allocate_child (GtkScrolledWindow *swindow,
1494                                     GtkAllocation     *relative_allocation)
1495 {
1496   GtkWidget     *widget = GTK_WIDGET (swindow), *child;
1497   GtkAllocation  allocation;
1498   GtkAllocation  child_allocation;
1499
1500   child = gtk_bin_get_child (GTK_BIN (widget));
1501
1502   gtk_widget_get_allocation (widget, &allocation);
1503
1504   gtk_scrolled_window_relative_allocation (widget, relative_allocation);
1505   child_allocation.x = relative_allocation->x + allocation.x;
1506   child_allocation.y = relative_allocation->y + allocation.y;
1507   child_allocation.width = relative_allocation->width;
1508   child_allocation.height = relative_allocation->height;
1509
1510   gtk_widget_size_allocate (child, &child_allocation);
1511 }
1512
1513 static void
1514 gtk_scrolled_window_size_allocate (GtkWidget     *widget,
1515                                    GtkAllocation *allocation)
1516 {
1517   GtkScrolledWindow *scrolled_window;
1518   GtkScrolledWindowPrivate *priv;
1519   GtkStyleContext *context;
1520   GtkStateFlags state;
1521   GtkBorder padding, border;
1522   GtkBin *bin;
1523   GtkAllocation relative_allocation;
1524   GtkAllocation child_allocation;
1525   GtkWidget *child;
1526   gboolean scrollbars_within_bevel;
1527   gint sb_spacing;
1528   gint sb_width;
1529   gint sb_height;
1530  
1531   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1532   g_return_if_fail (allocation != NULL);
1533
1534   scrolled_window = GTK_SCROLLED_WINDOW (widget);
1535   bin = GTK_BIN (scrolled_window);
1536   priv = scrolled_window->priv;
1537
1538   /* Get possible scrollbar dimensions */
1539   sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1540   gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1541   gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1542
1543   context = gtk_widget_get_style_context (widget);
1544   state = gtk_widget_get_state_flags (widget);
1545
1546   gtk_style_context_save (context);
1547   gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
1548
1549   gtk_style_context_get_padding (context, state, &padding);
1550   gtk_style_context_get_border (context, state, &border);
1551
1552   gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1553
1554   gtk_widget_set_allocation (widget, allocation);
1555
1556   gtk_style_context_restore (context);
1557
1558   if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1559     priv->hscrollbar_visible = TRUE;
1560   else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1561     priv->hscrollbar_visible = FALSE;
1562   if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1563     priv->vscrollbar_visible = TRUE;
1564   else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1565     priv->vscrollbar_visible = FALSE;
1566
1567   child = gtk_bin_get_child (bin);
1568   if (child && gtk_widget_get_visible (child))
1569     {
1570       gint child_scroll_width;
1571       gint child_scroll_height;
1572       gboolean previous_hvis;
1573       gboolean previous_vvis;
1574       guint count = 0;
1575
1576       /* Determine scrollbar visibility first via hfw apis */
1577       if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1578         {
1579           if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1580             gtk_widget_get_preferred_width (child, &child_scroll_width, NULL);
1581           else
1582             gtk_widget_get_preferred_width (child, NULL, &child_scroll_width);
1583           
1584           if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1585             {
1586               /* First try without a vertical scrollbar if the content will fit the height
1587                * given the extra width of the scrollbar */
1588               if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1589                 gtk_widget_get_preferred_height_for_width (child, 
1590                                                            MAX (allocation->width, child_scroll_width), 
1591                                                            &child_scroll_height, NULL);
1592               else
1593                 gtk_widget_get_preferred_height_for_width (child,
1594                                                            MAX (allocation->width, child_scroll_width), 
1595                                                            NULL, &child_scroll_height);
1596               
1597               if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1598                 {
1599                   /* Does the content height fit the allocation height ? */
1600                   priv->vscrollbar_visible = child_scroll_height > allocation->height;
1601                   
1602                   /* Does the content width fit the allocation with minus a possible scrollbar ? */
1603                   priv->hscrollbar_visible = 
1604                     child_scroll_width > allocation->width - 
1605                     (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1606                   
1607                   /* Now that we've guessed the hscrollbar, does the content height fit
1608                    * the possible new allocation height ? */
1609                   priv->vscrollbar_visible = 
1610                     child_scroll_height > allocation->height - 
1611                     (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1612                   
1613                   /* Now that we've guessed the vscrollbar, does the content width fit
1614                    * the possible new allocation width ? */
1615                   priv->hscrollbar_visible = 
1616                     child_scroll_width > allocation->width - 
1617                     (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1618                 }
1619               else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1620                 {
1621                   priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1622                   priv->vscrollbar_visible = child_scroll_height > allocation->height - 
1623                     (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1624                 }
1625             }
1626           else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1627             {
1628               priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1629               
1630               if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1631                 priv->hscrollbar_visible = 
1632                   child_scroll_width > allocation->width - 
1633                   (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1634               else
1635                 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1636             }
1637         } 
1638       else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1639         {
1640           if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1641             gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
1642           else
1643             gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
1644           
1645           if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1646             {
1647               /* First try without a horizontal scrollbar if the content will fit the width
1648                * given the extra height of the scrollbar */
1649               if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1650                 gtk_widget_get_preferred_width_for_height (child, 
1651                                                            MAX (allocation->height, child_scroll_height), 
1652                                                            &child_scroll_width, NULL);
1653               else
1654                 gtk_widget_get_preferred_width_for_height (child, 
1655                                                            MAX (allocation->height, child_scroll_height), 
1656                                                            NULL, &child_scroll_width);
1657               
1658               if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1659                 {
1660                   /* Does the content width fit the allocation width ? */
1661                   priv->hscrollbar_visible = child_scroll_width > allocation->width;
1662                   
1663                   /* Does the content height fit the allocation with minus a possible scrollbar ? */
1664                   priv->vscrollbar_visible = 
1665                     child_scroll_height > allocation->height - 
1666                     (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1667                   
1668                   /* Now that we've guessed the vscrollbar, does the content width fit
1669                    * the possible new allocation width ? */
1670                   priv->hscrollbar_visible = 
1671                     child_scroll_width > allocation->width - 
1672                     (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1673                   
1674                   /* Now that we've guessed the hscrollbar, does the content height fit
1675                    * the possible new allocation height ? */
1676                   priv->vscrollbar_visible = 
1677                     child_scroll_height > allocation->height - 
1678                     (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1679                 }
1680               else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1681                 {
1682                   priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1683                   priv->hscrollbar_visible = child_scroll_width > allocation->width - 
1684                     (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1685                 }
1686             }
1687           else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1688             {
1689               priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1690               
1691               if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1692                 priv->vscrollbar_visible = 
1693                   child_scroll_height > allocation->height - 
1694                   (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1695               else
1696                 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1697             }
1698         }
1699
1700       /* Now after guessing scrollbar visibility; fall back on the allocation loop which 
1701        * observes the adjustments to detect scrollbar visibility and also avoids 
1702        * infinite recursion
1703        */
1704       do
1705         {
1706           previous_hvis = priv->hscrollbar_visible;
1707           previous_vvis = priv->vscrollbar_visible;
1708           gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
1709
1710           /* Explicitly force scrollbar visibility checks.
1711            *
1712            * Since we make a guess above, the child might not decide to update the adjustments 
1713            * if they logically did not change since the last configuration
1714            */
1715           if (priv->hscrollbar)
1716             gtk_scrolled_window_adjustment_changed 
1717               (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)), scrolled_window);
1718
1719           if (priv->vscrollbar)
1720             gtk_scrolled_window_adjustment_changed 
1721               (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)), scrolled_window);
1722
1723           /* If, after the first iteration, the hscrollbar and the
1724            * vscrollbar flip visiblity... or if one of the scrollbars flip
1725            * on each itteration indefinitly/infinitely, then we just need both 
1726            * at this size.
1727            */
1728           if ((count &&
1729                previous_hvis != priv->hscrollbar_visible &&
1730                previous_vvis != priv->vscrollbar_visible) || count > 3)
1731             {
1732               priv->hscrollbar_visible = TRUE;
1733               priv->vscrollbar_visible = TRUE;
1734
1735               gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
1736
1737               break;
1738             }
1739           
1740           count++;
1741         }
1742       while (previous_hvis != priv->hscrollbar_visible ||
1743              previous_vvis != priv->vscrollbar_visible);
1744     }
1745   else
1746     {
1747       priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1748       priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1749       gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1750     }
1751
1752   if (priv->hscrollbar_visible)
1753     {
1754       if (!gtk_widget_get_visible (priv->hscrollbar))
1755         gtk_widget_show (priv->hscrollbar);
1756
1757       child_allocation.x = relative_allocation.x;
1758       if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1759           priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1760         child_allocation.y = (relative_allocation.y +
1761                               relative_allocation.height +
1762                               sb_spacing +
1763                               (priv->shadow_type == GTK_SHADOW_NONE ?
1764                                0 : padding.top + border.top));
1765       else
1766         child_allocation.y = 0;
1767
1768       child_allocation.width = relative_allocation.width;
1769       child_allocation.height = sb_height;
1770       child_allocation.x += allocation->x;
1771       child_allocation.y += allocation->y;
1772
1773       if (priv->shadow_type != GTK_SHADOW_NONE)
1774         {
1775           if (!scrollbars_within_bevel)
1776             {
1777               child_allocation.x -= padding.left + border.left;
1778               child_allocation.width += padding.left + padding.right + border.left + border.right;
1779             }
1780           else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1781                    GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1782             {
1783               child_allocation.y -= padding.top + border.top;
1784             }
1785           else
1786             {
1787               child_allocation.y += padding.top + border.top;
1788             }
1789         }
1790
1791       gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1792     }
1793   else if (gtk_widget_get_visible (priv->hscrollbar))
1794     gtk_widget_hide (priv->hscrollbar);
1795
1796   if (priv->vscrollbar_visible)
1797     {
1798       if (!gtk_widget_get_visible (priv->vscrollbar))
1799         gtk_widget_show (priv->vscrollbar);
1800
1801       if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL && 
1802            (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1803             priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1804           (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR && 
1805            (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1806             priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1807         child_allocation.x = (relative_allocation.x +
1808                               relative_allocation.width +
1809                               sb_spacing +
1810                               (priv->shadow_type == GTK_SHADOW_NONE ?
1811                                0 : padding.left + border.left));
1812       else
1813         child_allocation.x = 0;
1814
1815       child_allocation.y = relative_allocation.y;
1816       child_allocation.width = sb_width;
1817       child_allocation.height = relative_allocation.height;
1818       child_allocation.x += allocation->x;
1819       child_allocation.y += allocation->y;
1820
1821       if (priv->shadow_type != GTK_SHADOW_NONE)
1822         {
1823           if (!scrollbars_within_bevel)
1824             {
1825               child_allocation.y -= padding.top + border.top;
1826               child_allocation.height += padding.top + padding.bottom + border.top + border.bottom;
1827             }
1828           else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1829                    GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1830             {
1831               child_allocation.x -= padding.left + border.left;
1832             }
1833           else
1834             {
1835               child_allocation.x += padding.left + border.left;
1836             }
1837         }
1838
1839       gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1840     }
1841   else if (gtk_widget_get_visible (priv->vscrollbar))
1842     gtk_widget_hide (priv->vscrollbar);
1843 }
1844
1845 static gboolean
1846 gtk_scrolled_window_scroll_event (GtkWidget      *widget,
1847                                   GdkEventScroll *event)
1848 {
1849   GtkScrolledWindowPrivate *priv;
1850   GtkScrolledWindow *scrolled_window;
1851   GtkWidget *range;
1852
1853   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1854   g_return_val_if_fail (event != NULL, FALSE);  
1855
1856   scrolled_window = GTK_SCROLLED_WINDOW (widget);
1857   priv = scrolled_window->priv;
1858
1859   if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1860     range = priv->vscrollbar;
1861   else
1862     range = priv->hscrollbar;
1863
1864   if (range && gtk_widget_get_visible (range))
1865     {
1866       GtkAdjustment *adjustment = gtk_range_get_adjustment (GTK_RANGE (range));
1867       gdouble delta;
1868
1869       delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1870
1871       gtk_adjustment_set_value (adjustment, gtk_adjustment_get_value (adjustment) + delta);
1872
1873       return TRUE;
1874     }
1875
1876   return FALSE;
1877 }
1878
1879 static gboolean
1880 gtk_scrolled_window_focus (GtkWidget        *widget,
1881                            GtkDirectionType  direction)
1882 {
1883   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1884   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1885   GtkWidget *child;
1886   gboolean had_focus_child;
1887
1888   had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1889
1890   if (priv->focus_out)
1891     {
1892       priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1893       return FALSE;
1894     }
1895   
1896   if (gtk_widget_is_focus (widget))
1897     return FALSE;
1898
1899   /* We only put the scrolled window itself in the focus chain if it
1900    * isn't possible to focus any children.
1901    */
1902   child = gtk_bin_get_child (GTK_BIN (widget));
1903   if (child)
1904     {
1905       if (gtk_widget_child_focus (child, direction))
1906         return TRUE;
1907     }
1908
1909   if (!had_focus_child && gtk_widget_get_can_focus (widget))
1910     {
1911       gtk_widget_grab_focus (widget);
1912       return TRUE;
1913     }
1914   else
1915     return FALSE;
1916 }
1917
1918 static void
1919 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1920                                         gpointer       data)
1921 {
1922   GtkScrolledWindowPrivate *priv;
1923   GtkScrolledWindow *scrolled_window;
1924
1925   g_return_if_fail (adjustment != NULL);
1926   g_return_if_fail (data != NULL);
1927
1928   scrolled_window = GTK_SCROLLED_WINDOW (data);
1929   priv = scrolled_window->priv;
1930
1931   if (priv->hscrollbar &&
1932       adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1933     {
1934       if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1935         {
1936           gboolean visible;
1937
1938           visible = priv->hscrollbar_visible;
1939           priv->hscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
1940                                       gtk_adjustment_get_page_size (adjustment));
1941
1942           if (priv->hscrollbar_visible != visible)
1943             gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1944         }
1945     }
1946   else if (priv->vscrollbar &&
1947            adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1948     {
1949       if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1950         {
1951           gboolean visible;
1952
1953           visible = priv->vscrollbar_visible;
1954           priv->vscrollbar_visible = (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment) >
1955                                       gtk_adjustment_get_page_size (adjustment));
1956
1957           if (priv->vscrollbar_visible != visible)
1958             gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1959         }
1960     }
1961 }
1962
1963 static void
1964 gtk_scrolled_window_add (GtkContainer *container,
1965                          GtkWidget    *child)
1966 {
1967   GtkScrolledWindowPrivate *priv;
1968   GtkScrolledWindow *scrolled_window;
1969   GtkBin *bin;
1970   GtkWidget *child_widget;
1971   GtkAdjustment *hadj, *vadj;
1972
1973   bin = GTK_BIN (container);
1974   child_widget = gtk_bin_get_child (bin);
1975   g_return_if_fail (child_widget == NULL);
1976
1977   scrolled_window = GTK_SCROLLED_WINDOW (container);
1978   priv = scrolled_window->priv;
1979
1980   _gtk_bin_set_child (bin, child);
1981   gtk_widget_set_parent (child, GTK_WIDGET (bin));
1982
1983   hadj = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1984   vadj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1985
1986   if (GTK_IS_SCROLLABLE (child))
1987     g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL);
1988   else
1989     g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1990                "use gtk_scrolled_window_add_with_viewport() instead");
1991 }
1992
1993 static void
1994 gtk_scrolled_window_remove (GtkContainer *container,
1995                             GtkWidget    *child)
1996 {
1997   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1998   g_return_if_fail (child != NULL);
1999   g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
2000
2001   g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
2002
2003   /* chain parent class handler to remove child */
2004   GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
2005 }
2006
2007 /**
2008  * gtk_scrolled_window_add_with_viewport:
2009  * @scrolled_window: a #GtkScrolledWindow
2010  * @child: the widget you want to scroll
2011  *
2012  * Used to add children without native scrolling capabilities. This
2013  * is simply a convenience function; it is equivalent to adding the
2014  * unscrollable child to a viewport, then adding the viewport to the
2015  * scrolled window. If a child has native scrolling, use
2016  * gtk_container_add() instead of this function.
2017  *
2018  * The viewport scrolls the child by moving its #GdkWindow, and takes
2019  * the size of the child to be the size of its toplevel #GdkWindow. 
2020  * This will be very wrong for most widgets that support native scrolling;
2021  * for example, if you add a widget such as #GtkTreeView with a viewport,
2022  * the whole widget will scroll, including the column headings. Thus, 
2023  * widgets with native scrolling support should not be used with the 
2024  * #GtkViewport proxy.
2025  *
2026  * A widget supports scrolling natively if it implements the
2027  * #GtkScrollable interface.
2028  */
2029 void
2030 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
2031                                        GtkWidget         *child)
2032 {
2033   GtkBin *bin;
2034   GtkWidget *viewport;
2035   GtkWidget *child_widget;
2036
2037   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2038   g_return_if_fail (GTK_IS_WIDGET (child));
2039   g_return_if_fail (gtk_widget_get_parent (child) == NULL);
2040
2041   bin = GTK_BIN (scrolled_window);
2042   child_widget = gtk_bin_get_child (bin);
2043
2044   if (child_widget)
2045     {
2046       g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
2047       g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
2048
2049       viewport = child_widget;
2050     }
2051   else
2052     {
2053       viewport =
2054         gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
2055                           gtk_scrolled_window_get_vadjustment (scrolled_window));
2056       gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
2057     }
2058
2059   gtk_widget_show (viewport);
2060   gtk_container_add (GTK_CONTAINER (viewport), child);
2061 }
2062
2063 /*
2064  * _gtk_scrolled_window_get_spacing:
2065  * @scrolled_window: a scrolled window
2066  * 
2067  * Gets the spacing between the scrolled window's scrollbars and
2068  * the scrolled widget. Used by GtkCombo
2069  * 
2070  * Return value: the spacing, in pixels.
2071  */
2072 gint
2073 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
2074 {
2075   GtkScrolledWindowClass *class;
2076     
2077   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2078
2079   class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
2080
2081   if (class->scrollbar_spacing >= 0)
2082     return class->scrollbar_spacing;
2083   else
2084     {
2085       gint scrollbar_spacing;
2086       
2087       gtk_widget_style_get (GTK_WIDGET (scrolled_window),
2088                             "scrollbar-spacing", &scrollbar_spacing,
2089                             NULL);
2090
2091       return scrollbar_spacing;
2092     }
2093 }
2094
2095
2096 static void
2097 gtk_scrolled_window_get_preferred_size (GtkWidget      *widget,
2098                                         GtkOrientation  orientation,
2099                                         gint           *minimum_size,
2100                                         gint           *natural_size)
2101 {
2102   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
2103   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
2104   GtkBin *bin = GTK_BIN (scrolled_window);
2105   gint extra_width;
2106   gint extra_height;
2107   gint scrollbar_spacing;
2108   GtkRequisition hscrollbar_requisition;
2109   GtkRequisition vscrollbar_requisition;
2110   GtkRequisition minimum_req, natural_req;
2111   GtkWidget *child;
2112   gint min_child_size, nat_child_size;
2113
2114   scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
2115
2116   extra_width = 0;
2117   extra_height = 0;
2118   minimum_req.width = 0;
2119   minimum_req.height = 0;
2120   natural_req.width = 0;
2121   natural_req.height = 0;
2122
2123   gtk_widget_get_preferred_size (priv->hscrollbar,
2124                                  &hscrollbar_requisition, NULL);
2125   gtk_widget_get_preferred_size (priv->vscrollbar,
2126                                  &vscrollbar_requisition, NULL);
2127
2128   child = gtk_bin_get_child (bin);
2129   if (child && gtk_widget_get_visible (child))
2130     {
2131       if (orientation == GTK_ORIENTATION_HORIZONTAL)
2132         {
2133           gtk_widget_get_preferred_width (child,
2134                                           &min_child_size,
2135                                           &nat_child_size);
2136
2137           if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2138             {
2139               minimum_req.width += min_child_size;
2140               natural_req.width += nat_child_size;
2141             }
2142           else
2143             {
2144               gint min_content_width = priv->min_content_width;
2145
2146               if (min_content_width >= 0)
2147                 {
2148                   minimum_req.width = MAX (minimum_req.width, min_content_width);
2149                   natural_req.width = MAX (natural_req.width, min_content_width);
2150                   extra_width = -1;
2151                 }
2152               else
2153                 {
2154                   minimum_req.width += vscrollbar_requisition.width;
2155                   natural_req.width += vscrollbar_requisition.width;
2156                 }
2157             }
2158         }
2159       else /* GTK_ORIENTATION_VERTICAL */
2160         {
2161           gtk_widget_get_preferred_height (child,
2162                                            &min_child_size,
2163                                            &nat_child_size);
2164
2165           if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2166             {
2167               minimum_req.height += min_child_size;
2168               natural_req.height += nat_child_size;
2169             }
2170           else
2171             {
2172               gint min_content_height = priv->min_content_height;
2173
2174               if (min_content_height >= 0)
2175                 {
2176                   minimum_req.height = MAX (minimum_req.height, min_content_height);
2177                   natural_req.height = MAX (natural_req.height, min_content_height);
2178                   extra_height = -1;
2179                 }
2180               else
2181                 {
2182                   minimum_req.height += vscrollbar_requisition.height;
2183                   natural_req.height += vscrollbar_requisition.height;
2184                 }
2185             }
2186         }
2187     }
2188
2189   if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2190       priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2191     {
2192       minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2193       natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2194       if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2195         extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2196     }
2197
2198   if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2199       priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2200     {
2201       minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2202       natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2203       if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2204         extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2205     }
2206
2207   minimum_req.width  += MAX (0, extra_width);
2208   minimum_req.height += MAX (0, extra_height);
2209   natural_req.width  += MAX (0, extra_width);
2210   natural_req.height += MAX (0, extra_height);
2211
2212   if (priv->shadow_type != GTK_SHADOW_NONE)
2213     {
2214       GtkStyleContext *context;
2215       GtkStateFlags state;
2216       GtkBorder padding, border;
2217
2218       context = gtk_widget_get_style_context (GTK_WIDGET (widget));
2219       state = gtk_widget_get_state_flags (GTK_WIDGET (widget));
2220
2221       gtk_style_context_save (context);
2222       gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
2223
2224       gtk_style_context_get_padding (context, state, &padding);
2225       gtk_style_context_get_border (context, state, &border);
2226
2227       minimum_req.width += padding.left + padding.right + border.left + border.right;
2228       minimum_req.height += padding.top + padding.bottom + border.top + border.bottom;
2229       natural_req.width += padding.left + padding.right + border.left + border.right;
2230       natural_req.height += padding.top + padding.bottom + border.top + border.bottom;
2231
2232       gtk_style_context_restore (context);
2233     }
2234
2235   if (orientation == GTK_ORIENTATION_HORIZONTAL)
2236     {
2237       if (minimum_size)
2238         *minimum_size = minimum_req.width;
2239       if (natural_size)
2240         *natural_size = natural_req.width;
2241     }
2242   else
2243     {
2244       if (minimum_size)
2245         *minimum_size = minimum_req.height;
2246       if (natural_size)
2247         *natural_size = natural_req.height;
2248     }
2249 }
2250
2251 static void     
2252 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2253                                          gint      *minimum_size,
2254                                          gint      *natural_size)
2255 {
2256   gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2257 }
2258
2259 static void
2260 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2261                                           gint      *minimum_size,
2262                                           gint      *natural_size)
2263 {  
2264   gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2265 }
2266
2267 static void
2268 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2269                                                     gint       width,
2270                                                     gint      *minimum_height,
2271                                                     gint      *natural_height)
2272 {
2273   g_return_if_fail (GTK_IS_WIDGET (widget));
2274
2275   GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2276 }
2277
2278 static void
2279 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2280                                                     gint       height,
2281                                                     gint      *minimum_width,
2282                                                     gint      *natural_width)
2283 {
2284   g_return_if_fail (GTK_IS_WIDGET (widget));
2285
2286   GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
2287 }
2288
2289 /**
2290  * gtk_scrolled_window_get_min_content_width:
2291  * @scrolled_window: a #GtkScrolledWindow
2292  *
2293  * Gets the minimum content width of @scrolled_window, or -1 if not set.
2294  *
2295  * Returns: the minimum content width
2296  *
2297  * Since: 3.0
2298  */
2299 gint
2300 gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
2301 {
2302   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2303
2304   return scrolled_window->priv->min_content_width;
2305 }
2306
2307 /**
2308  * gtk_scrolled_window_set_min_content_width:
2309  * @scrolled_window: a #GtkScrolledWindow
2310  * @width: the minimal content width
2311  *
2312  * Sets the minimum width that @scrolled_window should keep visible.
2313  * Note that this can and (usually will) be smaller than the minimum
2314  * size of the content.
2315  *
2316  * Since: 3.0
2317  */
2318 void
2319 gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
2320                                            gint               width)
2321 {
2322   GtkScrolledWindowPrivate *priv;
2323
2324   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2325
2326   priv = scrolled_window->priv;
2327
2328   if (priv->min_content_width != width)
2329     {
2330       priv->min_content_width = width;
2331
2332       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2333
2334       g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
2335     }
2336 }
2337
2338 /**
2339  * gtk_scrolled_window_get_min_content_height:
2340  * @scrolled_window: a #GtkScrolledWindow
2341  *
2342  * Gets the minimal content height of @scrolled_window, or -1 if not set.
2343  *
2344  * Returns: the minimal content height
2345  *
2346  * Since: 3.0
2347  */
2348 gint
2349 gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
2350 {
2351   g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2352
2353   return scrolled_window->priv->min_content_height;
2354 }
2355
2356 /**
2357  * gtk_scrolled_window_set_min_content_height:
2358  * @scrolled_window: a #GtkScrolledWindow
2359  * @height: the minimal content height
2360  *
2361  * Sets the minimum height that @scrolled_window should keep visible.
2362  * Note that this can and (usually will) be smaller than the minimum
2363  * size of the content.
2364  *
2365  * Since: 3.0
2366  */
2367 void
2368 gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
2369                                             gint               height)
2370 {
2371   GtkScrolledWindowPrivate *priv;
2372
2373   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2374
2375   priv = scrolled_window->priv;
2376
2377   if (priv->min_content_height != height)
2378     {
2379       priv->min_content_height = height;
2380
2381       gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2382
2383       g_object_notify (G_OBJECT (scrolled_window), "min-content-height");
2384     }
2385 }