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