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