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