1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
29 #include <gdk/gdkkeysyms.h>
30 #include "gtkbindings.h"
31 #include "gtkmarshalers.h"
32 #include "gtkscrollable.h"
33 #include "gtkscrolledwindow.h"
34 #include "gtkwindow.h"
35 #include "gtktypeutils.h"
36 #include "gtkprivate.h"
41 * SECTION:gtkscrolledwindow
42 * @Short_description: Adds scrollbars to its child widget
43 * @Title: GtkScrolledWindow
44 * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment
46 * #GtkScrolledWindow is a #GtkBin subclass: it's a container
47 * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
48 * to the child widget and optionally draws a beveled frame around the
51 * The scrolled window can work in two ways. Some widgets have native
52 * scrolling support; these widgets implement the #GtkScrollable interface.
53 * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
56 * For widgets that lack native scrolling support, the #GtkViewport
57 * widget acts as an adaptor class, implementing scrollability for child
58 * widgets that lack their own scrolling capabilities. Use #GtkViewport
59 * to scroll child widgets such as #GtkTable, #GtkBox, and so on.
61 * If a widget has native scrolling abilities, it can be added to the
62 * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
63 * must first add the widget to a #GtkViewport, then add the #GtkViewport
64 * to the scrolled window. The convenience function
65 * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
66 * ignore the presence of the viewport.
68 * The position of the scrollbars is controlled by the scroll
69 * adjustments. See #GtkAdjustment for the fields in an adjustment - for
70 * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
71 * represents the position of the scrollbar, which must be between the
72 * "lower" field and "upper - page_size." The "page_size" field
73 * represents the size of the visible scrollable area. The
74 * "step_increment" and "page_increment" fields are used when the user
75 * asks to step down (using the small stepper arrows) or page down (using
76 * for example the PageDown key).
78 * If a #GtkScrolledWindow doesn't behave quite as you would like, or
79 * doesn't have exactly the right layout, it's very possible to set up
80 * your own scrolling with #GtkScrollbar and for example a #GtkTable.
84 /* scrolled window policy and size requisition handling:
86 * gtk size requisition works as follows:
87 * a widget upon size-request reports the width and height that it finds
88 * to be best suited to display its contents, including children.
89 * the width and/or height reported from a widget upon size requisition
90 * may be overidden by the user by specifying a width and/or height
91 * other than 0 through gtk_widget_set_size_request().
93 * a scrolled window needs (for implementing all three policy types) to
94 * request its width and height based on two different rationales.
95 * 1) the user wants the scrolled window to just fit into the space
96 * that it gets allocated for a specifc dimension.
97 * 1.1) this does not apply if the user specified a concrete value
98 * value for that specific dimension by either specifying usize for the
99 * scrolled window or for its child.
100 * 2) the user wants the scrolled window to take as much space up as
101 * is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
103 * also, kinda obvious:
104 * 3) a user would certainly not have choosen a scrolled window as a container
105 * for the child, if the resulting allocation takes up more space than the
106 * child would have allocated without the scrolled window.
109 * A) from 1) follows: the scrolled window shouldn't request more space for a
110 * specifc dimension than is required at minimum.
111 * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
112 * window (done automatically) or by usize of the child (needs to be checked).
113 * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
115 * D) from 3) follows: the scrolled window child's minimum width and minimum height
116 * under A) at least correspond to the space taken up by its scrollbars.
119 #define DEFAULT_SCROLLBAR_SPACING 3
121 struct _GtkScrolledWindowPrivate
123 GtkCornerType real_window_placement;
124 GtkWidget *hscrollbar;
125 GtkWidget *vscrollbar;
127 gboolean window_placement_set;
131 guint hscrollbar_policy : 2;
132 guint vscrollbar_policy : 2;
133 guint hscrollbar_visible : 1;
134 guint vscrollbar_visible : 1;
135 guint window_placement : 2;
136 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
144 PROP_HSCROLLBAR_POLICY,
145 PROP_VSCROLLBAR_POLICY,
146 PROP_WINDOW_PLACEMENT,
147 PROP_WINDOW_PLACEMENT_SET,
159 static void gtk_scrolled_window_set_property (GObject *object,
163 static void gtk_scrolled_window_get_property (GObject *object,
168 static void gtk_scrolled_window_destroy (GtkWidget *widget);
169 static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
170 GdkScreen *previous_screen);
171 static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
173 static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
176 GdkEventScroll *event);
177 static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
178 GtkDirectionType direction);
179 static void gtk_scrolled_window_add (GtkContainer *container,
181 static void gtk_scrolled_window_remove (GtkContainer *container,
183 static void gtk_scrolled_window_forall (GtkContainer *container,
184 gboolean include_internals,
185 GtkCallback callback,
186 gpointer callback_data);
187 static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
188 GtkScrollType scroll,
189 gboolean horizontal);
190 static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
191 GtkDirectionType direction_type);
193 static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
194 GtkAllocation *allocation);
195 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
198 static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
200 static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
203 static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
206 static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
208 gint *minimum_height,
209 gint *natural_height);
210 static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
212 gint *minimum_height,
213 gint *natural_height);
215 static guint signals[LAST_SIGNAL] = {0};
217 G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
221 add_scroll_binding (GtkBindingSet *binding_set,
223 GdkModifierType mask,
224 GtkScrollType scroll,
227 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
229 gtk_binding_entry_add_signal (binding_set, keyval, mask,
231 GTK_TYPE_SCROLL_TYPE, scroll,
232 G_TYPE_BOOLEAN, horizontal);
233 gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
235 GTK_TYPE_SCROLL_TYPE, scroll,
236 G_TYPE_BOOLEAN, horizontal);
240 add_tab_bindings (GtkBindingSet *binding_set,
241 GdkModifierType modifiers,
242 GtkDirectionType direction)
244 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
246 GTK_TYPE_DIRECTION_TYPE, direction);
247 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
249 GTK_TYPE_DIRECTION_TYPE, direction);
253 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
255 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
256 GtkWidgetClass *widget_class;
257 GtkContainerClass *container_class;
258 GtkBindingSet *binding_set;
260 widget_class = (GtkWidgetClass*) class;
261 container_class = (GtkContainerClass*) class;
263 gobject_class->set_property = gtk_scrolled_window_set_property;
264 gobject_class->get_property = gtk_scrolled_window_get_property;
266 widget_class->destroy = gtk_scrolled_window_destroy;
267 widget_class->screen_changed = gtk_scrolled_window_screen_changed;
268 widget_class->draw = gtk_scrolled_window_draw;
269 widget_class->size_allocate = gtk_scrolled_window_size_allocate;
270 widget_class->scroll_event = gtk_scrolled_window_scroll_event;
271 widget_class->focus = gtk_scrolled_window_focus;
272 widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
273 widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
274 widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
275 widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
277 container_class->add = gtk_scrolled_window_add;
278 container_class->remove = gtk_scrolled_window_remove;
279 container_class->forall = gtk_scrolled_window_forall;
280 gtk_container_class_handle_border_width (container_class);
282 class->scrollbar_spacing = -1;
284 class->scroll_child = gtk_scrolled_window_scroll_child;
285 class->move_focus_out = gtk_scrolled_window_move_focus_out;
287 g_object_class_install_property (gobject_class,
289 g_param_spec_object ("hadjustment",
290 P_("Horizontal Adjustment"),
291 P_("The GtkAdjustment for the horizontal position"),
293 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
294 g_object_class_install_property (gobject_class,
296 g_param_spec_object ("vadjustment",
297 P_("Vertical Adjustment"),
298 P_("The GtkAdjustment for the vertical position"),
300 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
301 g_object_class_install_property (gobject_class,
302 PROP_HSCROLLBAR_POLICY,
303 g_param_spec_enum ("hscrollbar-policy",
304 P_("Horizontal Scrollbar Policy"),
305 P_("When the horizontal scrollbar is displayed"),
306 GTK_TYPE_POLICY_TYPE,
307 GTK_POLICY_AUTOMATIC,
308 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
309 g_object_class_install_property (gobject_class,
310 PROP_VSCROLLBAR_POLICY,
311 g_param_spec_enum ("vscrollbar-policy",
312 P_("Vertical Scrollbar Policy"),
313 P_("When the vertical scrollbar is displayed"),
314 GTK_TYPE_POLICY_TYPE,
315 GTK_POLICY_AUTOMATIC,
316 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
318 g_object_class_install_property (gobject_class,
319 PROP_WINDOW_PLACEMENT,
320 g_param_spec_enum ("window-placement",
321 P_("Window Placement"),
322 P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
323 GTK_TYPE_CORNER_TYPE,
325 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
328 * GtkScrolledWindow:window-placement-set:
330 * Whether "window-placement" should be used to determine the location
331 * of the contents with respect to the scrollbars. Otherwise, the
332 * "gtk-scrolled-window-placement" setting is used.
336 g_object_class_install_property (gobject_class,
337 PROP_WINDOW_PLACEMENT_SET,
338 g_param_spec_boolean ("window-placement-set",
339 P_("Window Placement Set"),
340 P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
342 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
343 g_object_class_install_property (gobject_class,
345 g_param_spec_enum ("shadow-type",
347 P_("Style of bevel around the contents"),
348 GTK_TYPE_SHADOW_TYPE,
350 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
353 * GtkScrolledWindow:scrollbars-within-bevel:
355 * Whether to place scrollbars within the scrolled window's bevel.
359 gtk_widget_class_install_style_property (widget_class,
360 g_param_spec_boolean ("scrollbars-within-bevel",
361 P_("Scrollbars within bevel"),
362 P_("Place scrollbars within the scrolled window's bevel"),
364 GTK_PARAM_READABLE));
366 gtk_widget_class_install_style_property (widget_class,
367 g_param_spec_int ("scrollbar-spacing",
368 P_("Scrollbar spacing"),
369 P_("Number of pixels between the scrollbars and the scrolled window"),
372 DEFAULT_SCROLLBAR_SPACING,
373 GTK_PARAM_READABLE));
376 * GtkScrolledWindow::scroll-child:
377 * @scrolled_window: a #GtkScrolledWindow
378 * @scroll: a #GtkScrollType describing how much to scroll
379 * @horizontal: whether the keybinding scrolls the child
380 * horizontally or not
382 * The ::scroll-child signal is a
383 * <link linkend="keybinding-signals">keybinding signal</link>
384 * which gets emitted when a keybinding that scrolls is pressed.
385 * The horizontal or vertical adjustment is updated which triggers a
386 * signal that the scrolled windows child may listen to and scroll itself.
388 signals[SCROLL_CHILD] =
389 g_signal_new (I_("scroll-child"),
390 G_TYPE_FROM_CLASS (gobject_class),
391 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
392 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
394 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
396 GTK_TYPE_SCROLL_TYPE,
400 * GtkScrolledWindow::move-focus-out:
401 * @scrolled_window: a #GtkScrolledWindow
402 * @direction_type: either %GTK_DIR_TAB_FORWARD or
403 * %GTK_DIR_TAB_BACKWARD
405 * The ::move-focus-out signal is a
406 * <link linkend="keybinding-signals">keybinding signal</link>
407 * which gets emitted when focus is moved away from the scrolled
408 * window by a keybinding.
409 * The #GtkWidget::move-focus signal is emitted with @direction_type
410 * on this scrolled windows toplevel parent in the container hierarchy.
411 * The default bindings for this signal are
412 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
414 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
416 signals[MOVE_FOCUS_OUT] =
417 g_signal_new (I_("move-focus-out"),
418 G_TYPE_FROM_CLASS (gobject_class),
419 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
420 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
422 _gtk_marshal_VOID__ENUM,
424 GTK_TYPE_DIRECTION_TYPE);
426 binding_set = gtk_binding_set_by_class (class);
428 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
429 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
430 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
431 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
433 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
434 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
435 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
436 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
438 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
439 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
440 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
441 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
443 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
444 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
446 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
450 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
452 GtkScrolledWindowPrivate *priv;
454 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
455 GTK_TYPE_SCROLLED_WINDOW,
456 GtkScrolledWindowPrivate);
458 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
459 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
461 priv->hscrollbar = NULL;
462 priv->vscrollbar = NULL;
463 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
464 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
465 priv->hscrollbar_visible = FALSE;
466 priv->vscrollbar_visible = FALSE;
467 priv->focus_out = FALSE;
468 priv->window_placement = GTK_CORNER_TOP_LEFT;
469 gtk_scrolled_window_update_real_placement (scrolled_window);
473 * gtk_scrolled_window_new:
474 * @hadjustment: (allow-none): horizontal adjustment
475 * @vadjustment: (allow-none): vertical adjustment
477 * Creates a new scrolled window.
479 * The two arguments are the scrolled window's adjustments; these will be
480 * shared with the scrollbars and the child widget to keep the bars in sync
481 * with the child. Usually you want to pass %NULL for the adjustments, which
482 * will cause the scrolled window to create them for you.
484 * Returns: a new scrolled window
487 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
488 GtkAdjustment *vadjustment)
490 GtkWidget *scrolled_window;
493 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
496 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
498 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
499 "hadjustment", hadjustment,
500 "vadjustment", vadjustment,
503 return scrolled_window;
507 * gtk_scrolled_window_set_hadjustment:
508 * @scrolled_window: a #GtkScrolledWindow
509 * @hadjustment: horizontal scroll adjustment
511 * Sets the #GtkAdjustment for the horizontal scrollbar.
514 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
515 GtkAdjustment *hadjustment)
517 GtkScrolledWindowPrivate *priv;
521 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
523 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
525 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
527 bin = GTK_BIN (scrolled_window);
528 priv = scrolled_window->priv;
530 if (!priv->hscrollbar)
532 gtk_widget_push_composite_child ();
533 priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
534 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
535 gtk_widget_pop_composite_child ();
537 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
538 g_object_ref (priv->hscrollbar);
539 gtk_widget_show (priv->hscrollbar);
543 GtkAdjustment *old_adjustment;
545 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
546 if (old_adjustment == hadjustment)
549 g_signal_handlers_disconnect_by_func (old_adjustment,
550 gtk_scrolled_window_adjustment_changed,
552 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
555 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
556 g_signal_connect (hadjustment,
558 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
560 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
562 child = gtk_bin_get_child (bin);
563 if (GTK_IS_SCROLLABLE (child))
564 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), hadjustment);
566 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
570 * gtk_scrolled_window_set_vadjustment:
571 * @scrolled_window: a #GtkScrolledWindow
572 * @vadjustment: vertical scroll adjustment
574 * Sets the #GtkAdjustment for the vertical scrollbar.
577 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
578 GtkAdjustment *vadjustment)
580 GtkScrolledWindowPrivate *priv;
584 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
586 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
588 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
590 bin = GTK_BIN (scrolled_window);
591 priv = scrolled_window->priv;
593 if (!priv->vscrollbar)
595 gtk_widget_push_composite_child ();
596 priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
597 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
598 gtk_widget_pop_composite_child ();
600 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
601 g_object_ref (priv->vscrollbar);
602 gtk_widget_show (priv->vscrollbar);
606 GtkAdjustment *old_adjustment;
608 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
609 if (old_adjustment == vadjustment)
612 g_signal_handlers_disconnect_by_func (old_adjustment,
613 gtk_scrolled_window_adjustment_changed,
615 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
618 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
619 g_signal_connect (vadjustment,
621 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
623 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
625 child = gtk_bin_get_child (bin);
626 if (GTK_IS_SCROLLABLE (child))
627 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
629 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
633 * gtk_scrolled_window_get_hadjustment:
634 * @scrolled_window: a #GtkScrolledWindow
636 * Returns the horizontal scrollbar's adjustment, used to connect the
637 * horizontal scrollbar to the child widget's horizontal scroll
640 * Returns: (transfer none): the horizontal #GtkAdjustment
643 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
645 GtkScrolledWindowPrivate *priv;
647 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
649 priv = scrolled_window->priv;
651 return (priv->hscrollbar ?
652 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
657 * gtk_scrolled_window_get_vadjustment:
658 * @scrolled_window: a #GtkScrolledWindow
660 * Returns the vertical scrollbar's adjustment, used to connect the
661 * vertical scrollbar to the child widget's vertical scroll functionality.
663 * Returns: (transfer none): the vertical #GtkAdjustment
666 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
668 GtkScrolledWindowPrivate *priv;
670 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
672 priv = scrolled_window->priv;
674 return (priv->vscrollbar ?
675 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
680 * gtk_scrolled_window_get_hscrollbar:
681 * @scrolled_window: a #GtkScrolledWindow
683 * Returns the horizontal scrollbar of @scrolled_window.
685 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
686 * or %NULL if it does not have one.
691 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
693 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
695 return scrolled_window->priv->hscrollbar;
699 * gtk_scrolled_window_get_vscrollbar:
700 * @scrolled_window: a #GtkScrolledWindow
702 * Returns the vertical scrollbar of @scrolled_window.
704 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
705 * or %NULL if it does not have one.
710 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
712 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
714 return scrolled_window->priv->vscrollbar;
718 * gtk_scrolled_window_set_policy:
719 * @scrolled_window: a #GtkScrolledWindow
720 * @hscrollbar_policy: policy for horizontal bar
721 * @vscrollbar_policy: policy for vertical bar
723 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
725 * The policy determines when the scrollbar should appear; it is a value
726 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
727 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
728 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
729 * if needed (that is, if the slider part of the bar would be smaller
730 * than the trough - the display is larger than the page size).
733 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
734 GtkPolicyType hscrollbar_policy,
735 GtkPolicyType vscrollbar_policy)
737 GtkScrolledWindowPrivate *priv;
738 GObject *object = G_OBJECT (scrolled_window);
740 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
742 priv = scrolled_window->priv;
744 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
745 (priv->vscrollbar_policy != vscrollbar_policy))
747 priv->hscrollbar_policy = hscrollbar_policy;
748 priv->vscrollbar_policy = vscrollbar_policy;
750 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
752 g_object_freeze_notify (object);
753 g_object_notify (object, "hscrollbar-policy");
754 g_object_notify (object, "vscrollbar-policy");
755 g_object_thaw_notify (object);
760 * gtk_scrolled_window_get_policy:
761 * @scrolled_window: a #GtkScrolledWindow
762 * @hscrollbar_policy: location to store the policy for the horizontal
763 * scrollbar, or %NULL.
764 * @vscrollbar_policy: location to store the policy for the vertical
765 * scrollbar, or %NULL.
767 * Retrieves the current policy values for the horizontal and vertical
768 * scrollbars. See gtk_scrolled_window_set_policy().
771 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
772 GtkPolicyType *hscrollbar_policy,
773 GtkPolicyType *vscrollbar_policy)
775 GtkScrolledWindowPrivate *priv;
777 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
779 priv = scrolled_window->priv;
781 if (hscrollbar_policy)
782 *hscrollbar_policy = priv->hscrollbar_policy;
783 if (vscrollbar_policy)
784 *vscrollbar_policy = priv->vscrollbar_policy;
788 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
790 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
791 GtkSettings *settings;
793 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
795 if (priv->window_placement_set || settings == NULL)
796 priv->real_window_placement = priv->window_placement;
798 g_object_get (settings,
799 "gtk-scrolled-window-placement",
800 &priv->real_window_placement,
805 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
806 GtkCornerType window_placement)
808 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
810 if (priv->window_placement != window_placement)
812 priv->window_placement = window_placement;
814 gtk_scrolled_window_update_real_placement (scrolled_window);
815 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
817 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
822 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
823 gboolean placement_set,
824 gboolean emit_resize)
826 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
828 if (priv->window_placement_set != placement_set)
830 priv->window_placement_set = placement_set;
832 gtk_scrolled_window_update_real_placement (scrolled_window);
834 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
836 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
841 * gtk_scrolled_window_set_placement:
842 * @scrolled_window: a #GtkScrolledWindow
843 * @window_placement: position of the child window
845 * Sets the placement of the contents with respect to the scrollbars
846 * for the scrolled window.
848 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
849 * in the top left, with the scrollbars underneath and to the right.
850 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
851 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
853 * See also gtk_scrolled_window_get_placement() and
854 * gtk_scrolled_window_unset_placement().
857 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
858 GtkCornerType window_placement)
860 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
862 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
863 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
867 * gtk_scrolled_window_get_placement:
868 * @scrolled_window: a #GtkScrolledWindow
870 * Gets the placement of the contents with respect to the scrollbars
871 * for the scrolled window. See gtk_scrolled_window_set_placement().
873 * Return value: the current placement value.
875 * See also gtk_scrolled_window_set_placement() and
876 * gtk_scrolled_window_unset_placement().
879 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
881 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
883 return scrolled_window->priv->window_placement;
887 * gtk_scrolled_window_unset_placement:
888 * @scrolled_window: a #GtkScrolledWindow
890 * Unsets the placement of the contents with respect to the scrollbars
891 * for the scrolled window. If no window placement is set for a scrolled
892 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
894 * See also gtk_scrolled_window_set_placement() and
895 * gtk_scrolled_window_get_placement().
900 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
902 GtkScrolledWindowPrivate *priv;
904 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
906 priv = scrolled_window->priv;
908 if (priv->window_placement_set)
910 priv->window_placement_set = FALSE;
912 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
914 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
919 * gtk_scrolled_window_set_shadow_type:
920 * @scrolled_window: a #GtkScrolledWindow
921 * @type: kind of shadow to draw around scrolled window contents
923 * Changes the type of shadow drawn around the contents of
928 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
931 GtkScrolledWindowPrivate *priv;
933 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
934 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
936 priv = scrolled_window->priv;
938 if (priv->shadow_type != type)
940 priv->shadow_type = type;
942 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
943 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
945 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
947 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
952 * gtk_scrolled_window_get_shadow_type:
953 * @scrolled_window: a #GtkScrolledWindow
955 * Gets the shadow type of the scrolled window. See
956 * gtk_scrolled_window_set_shadow_type().
958 * Return value: the current shadow type
961 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
963 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
965 return scrolled_window->priv->shadow_type;
969 gtk_scrolled_window_destroy (GtkWidget *widget)
971 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
972 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
974 if (priv->hscrollbar)
976 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
977 gtk_scrolled_window_adjustment_changed,
979 gtk_widget_unparent (priv->hscrollbar);
980 gtk_widget_destroy (priv->hscrollbar);
981 g_object_unref (priv->hscrollbar);
982 priv->hscrollbar = NULL;
984 if (priv->vscrollbar)
986 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
987 gtk_scrolled_window_adjustment_changed,
989 gtk_widget_unparent (priv->vscrollbar);
990 gtk_widget_destroy (priv->vscrollbar);
991 g_object_unref (priv->vscrollbar);
992 priv->vscrollbar = NULL;
995 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
999 gtk_scrolled_window_set_property (GObject *object,
1001 const GValue *value,
1004 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1005 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1009 case PROP_HADJUSTMENT:
1010 gtk_scrolled_window_set_hadjustment (scrolled_window,
1011 g_value_get_object (value));
1013 case PROP_VADJUSTMENT:
1014 gtk_scrolled_window_set_vadjustment (scrolled_window,
1015 g_value_get_object (value));
1017 case PROP_HSCROLLBAR_POLICY:
1018 gtk_scrolled_window_set_policy (scrolled_window,
1019 g_value_get_enum (value),
1020 priv->vscrollbar_policy);
1022 case PROP_VSCROLLBAR_POLICY:
1023 gtk_scrolled_window_set_policy (scrolled_window,
1024 priv->hscrollbar_policy,
1025 g_value_get_enum (value));
1027 case PROP_WINDOW_PLACEMENT:
1028 gtk_scrolled_window_set_placement_internal (scrolled_window,
1029 g_value_get_enum (value));
1031 case PROP_WINDOW_PLACEMENT_SET:
1032 gtk_scrolled_window_set_placement_set (scrolled_window,
1033 g_value_get_boolean (value),
1036 case PROP_SHADOW_TYPE:
1037 gtk_scrolled_window_set_shadow_type (scrolled_window,
1038 g_value_get_enum (value));
1041 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1047 gtk_scrolled_window_get_property (GObject *object,
1052 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1053 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1057 case PROP_HADJUSTMENT:
1058 g_value_set_object (value,
1059 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1061 case PROP_VADJUSTMENT:
1062 g_value_set_object (value,
1063 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1065 case PROP_HSCROLLBAR_POLICY:
1066 g_value_set_enum (value, priv->hscrollbar_policy);
1068 case PROP_VSCROLLBAR_POLICY:
1069 g_value_set_enum (value, priv->vscrollbar_policy);
1071 case PROP_WINDOW_PLACEMENT:
1072 g_value_set_enum (value, priv->window_placement);
1074 case PROP_WINDOW_PLACEMENT_SET:
1075 g_value_set_boolean (value, priv->window_placement_set);
1077 case PROP_SHADOW_TYPE:
1078 g_value_set_enum (value, priv->shadow_type);
1081 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1087 traverse_container (GtkWidget *widget,
1090 if (GTK_IS_SCROLLED_WINDOW (widget))
1092 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1093 gtk_widget_queue_resize (widget);
1095 else if (GTK_IS_CONTAINER (widget))
1096 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1100 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1104 list = gtk_window_list_toplevels ();
1106 for (l = list; l; l = l->next)
1107 gtk_container_forall (GTK_CONTAINER (l->data),
1108 traverse_container, NULL);
1114 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1115 GdkScreen *previous_screen)
1117 GtkSettings *settings;
1118 guint window_placement_connection;
1120 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1122 if (!gtk_widget_has_screen (widget))
1125 settings = gtk_widget_get_settings (widget);
1127 window_placement_connection =
1128 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1129 "gtk-scrolled-window-connection"));
1131 if (window_placement_connection)
1134 window_placement_connection =
1135 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1136 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1137 g_object_set_data (G_OBJECT (settings),
1138 I_("gtk-scrolled-window-connection"),
1139 GUINT_TO_POINTER (window_placement_connection));
1143 gtk_scrolled_window_draw (GtkWidget *widget,
1146 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1147 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1149 if (priv->shadow_type != GTK_SHADOW_NONE)
1151 GtkAllocation relative_allocation;
1153 gboolean scrollbars_within_bevel;
1155 style = gtk_widget_get_style (widget);
1156 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1158 if (!scrollbars_within_bevel)
1160 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1162 relative_allocation.x -= style->xthickness;
1163 relative_allocation.y -= style->ythickness;
1164 relative_allocation.width += 2 * style->xthickness;
1165 relative_allocation.height += 2 * style->ythickness;
1169 relative_allocation.x = 0;
1170 relative_allocation.y = 0;
1171 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1172 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1175 gtk_paint_shadow (style,
1177 GTK_STATE_NORMAL, priv->shadow_type,
1178 widget, "scrolled_window",
1179 relative_allocation.x,
1180 relative_allocation.y,
1181 relative_allocation.width,
1182 relative_allocation.height);
1185 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1191 gtk_scrolled_window_forall (GtkContainer *container,
1192 gboolean include_internals,
1193 GtkCallback callback,
1194 gpointer callback_data)
1196 GtkScrolledWindowPrivate *priv;
1197 GtkScrolledWindow *scrolled_window;
1199 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1200 g_return_if_fail (callback != NULL);
1202 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1206 if (include_internals)
1208 scrolled_window = GTK_SCROLLED_WINDOW (container);
1209 priv = scrolled_window->priv;
1211 if (priv->vscrollbar)
1212 callback (priv->vscrollbar, callback_data);
1213 if (priv->hscrollbar)
1214 callback (priv->hscrollbar, callback_data);
1219 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1220 GtkScrollType scroll,
1221 gboolean horizontal)
1223 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1224 GtkAdjustment *adjustment = NULL;
1228 case GTK_SCROLL_STEP_UP:
1229 scroll = GTK_SCROLL_STEP_BACKWARD;
1232 case GTK_SCROLL_STEP_DOWN:
1233 scroll = GTK_SCROLL_STEP_FORWARD;
1236 case GTK_SCROLL_STEP_LEFT:
1237 scroll = GTK_SCROLL_STEP_BACKWARD;
1240 case GTK_SCROLL_STEP_RIGHT:
1241 scroll = GTK_SCROLL_STEP_FORWARD;
1244 case GTK_SCROLL_PAGE_UP:
1245 scroll = GTK_SCROLL_PAGE_BACKWARD;
1248 case GTK_SCROLL_PAGE_DOWN:
1249 scroll = GTK_SCROLL_PAGE_FORWARD;
1252 case GTK_SCROLL_PAGE_LEFT:
1253 scroll = GTK_SCROLL_STEP_BACKWARD;
1256 case GTK_SCROLL_PAGE_RIGHT:
1257 scroll = GTK_SCROLL_STEP_FORWARD;
1260 case GTK_SCROLL_STEP_BACKWARD:
1261 case GTK_SCROLL_STEP_FORWARD:
1262 case GTK_SCROLL_PAGE_BACKWARD:
1263 case GTK_SCROLL_PAGE_FORWARD:
1264 case GTK_SCROLL_START:
1265 case GTK_SCROLL_END:
1268 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1272 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1273 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1278 if (priv->hscrollbar)
1279 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1283 if (priv->vscrollbar)
1284 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1289 gdouble value = adjustment->value;
1293 case GTK_SCROLL_STEP_FORWARD:
1294 value += adjustment->step_increment;
1296 case GTK_SCROLL_STEP_BACKWARD:
1297 value -= adjustment->step_increment;
1299 case GTK_SCROLL_PAGE_FORWARD:
1300 value += adjustment->page_increment;
1302 case GTK_SCROLL_PAGE_BACKWARD:
1303 value -= adjustment->page_increment;
1305 case GTK_SCROLL_START:
1306 value = adjustment->lower;
1308 case GTK_SCROLL_END:
1309 value = adjustment->upper;
1312 g_assert_not_reached ();
1316 gtk_adjustment_set_value (adjustment, value);
1325 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1326 GtkDirectionType direction_type)
1328 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1329 GtkWidget *toplevel;
1331 /* Focus out of the scrolled window entirely. We do this by setting
1332 * a flag, then propagating the focus motion to the notebook.
1334 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1335 if (!gtk_widget_is_toplevel (toplevel))
1338 g_object_ref (scrolled_window);
1340 priv->focus_out = TRUE;
1341 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1342 priv->focus_out = FALSE;
1344 g_object_unref (scrolled_window);
1348 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1349 GtkAllocation *allocation)
1351 GtkAllocation widget_allocation;
1352 GtkScrolledWindow *scrolled_window;
1353 GtkScrolledWindowPrivate *priv;
1359 g_return_if_fail (widget != NULL);
1360 g_return_if_fail (allocation != NULL);
1362 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1363 priv = scrolled_window->priv;
1365 /* Get possible scrollbar dimensions */
1366 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1367 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1368 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1370 /* Subtract some things from our available allocation size */
1374 if (priv->shadow_type != GTK_SHADOW_NONE)
1376 style = gtk_widget_get_style (widget);
1377 allocation->x += style->xthickness;
1378 allocation->y += style->ythickness;
1381 gtk_widget_get_allocation (widget, &widget_allocation);
1382 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1383 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1385 if (priv->vscrollbar_visible)
1389 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1392 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1393 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1395 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1396 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1397 allocation->x += (sb_width + sb_spacing);
1399 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1401 if (priv->hscrollbar_visible)
1404 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1405 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1406 allocation->y += (sb_height + sb_spacing);
1408 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1413 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1414 GtkAllocation *allocation)
1416 GtkScrolledWindow *scrolled_window;
1417 GtkScrolledWindowPrivate *priv;
1420 GtkAllocation relative_allocation;
1421 GtkAllocation child_allocation;
1423 gboolean scrollbars_within_bevel;
1430 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1431 g_return_if_fail (allocation != NULL);
1433 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1434 bin = GTK_BIN (scrolled_window);
1435 priv = scrolled_window->priv;
1437 /* Get possible scrollbar dimensions */
1438 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1439 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1440 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1442 style = gtk_widget_get_style (widget);
1443 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1445 gtk_widget_set_allocation (widget, allocation);
1447 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1448 priv->hscrollbar_visible = TRUE;
1449 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1450 priv->hscrollbar_visible = FALSE;
1451 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1452 priv->vscrollbar_visible = TRUE;
1453 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1454 priv->vscrollbar_visible = FALSE;
1456 child = gtk_bin_get_child (bin);
1457 if (child && gtk_widget_get_visible (child))
1459 gint child_min_width;
1460 gint child_min_height;
1461 gboolean previous_hvis;
1462 gboolean previous_vvis;
1465 /* In the case that both scrollbars are visible in the previous round,
1466 * we dont do our guess-work before hand because it's possible some
1467 * infinite recursion was detected (leave it up to the child scrollable
1468 * widget in this case to drive the scrollbar visibility completely
1469 * with the adjustment values).
1471 if (!priv->vscrollbar_visible || !priv->hscrollbar_visible)
1474 /* Determine scrollbar visibility first via hfw apis */
1475 if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1477 gtk_widget_get_preferred_width (child, &child_min_width, NULL);
1479 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1481 /* First try without a vertical scrollbar if the content will fit the height
1482 * given the extra width of the scrollbar */
1483 gtk_widget_get_preferred_height_for_width (child, allocation->width,
1484 &child_min_height, NULL);
1486 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1488 /* Does the content height fit the allocation height ? */
1489 priv->vscrollbar_visible = child_min_height > allocation->height;
1491 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1492 priv->hscrollbar_visible =
1493 child_min_width > allocation->width -
1494 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1496 /* Now that we've guessed the hscrollbar, does the content height fit
1497 * the possible new allocation height ? */
1498 priv->vscrollbar_visible =
1499 child_min_height > allocation->height -
1500 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1502 /* Now that we've guessed the vscrollbar, does the content width fit
1503 * the possible new allocation width ? */
1504 priv->hscrollbar_visible =
1505 child_min_width > allocation->width -
1506 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1508 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1510 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1511 priv->vscrollbar_visible = child_min_height > allocation->height -
1512 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1515 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1517 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1519 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1520 priv->hscrollbar_visible =
1521 child_min_width > allocation->width -
1522 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1524 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1527 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1529 gtk_widget_get_preferred_height (child, &child_min_height, NULL);
1531 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1533 /* First try without a horizontal scrollbar if the content will fit the width
1534 * given the extra height of the scrollbar */
1535 gtk_widget_get_preferred_width_for_height (child, allocation->height,
1536 &child_min_width, NULL);
1538 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1540 /* Does the content width fit the allocation width ? */
1541 priv->hscrollbar_visible = child_min_width > allocation->width;
1543 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1544 priv->vscrollbar_visible =
1545 child_min_height > allocation->height -
1546 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1548 /* Now that we've guessed the vscrollbar, does the content width fit
1549 * the possible new allocation width ? */
1550 priv->hscrollbar_visible =
1551 child_min_width > allocation->width -
1552 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1554 /* Now that we've guessed the hscrollbar, does the content height fit
1555 * the possible new allocation height ? */
1556 priv->vscrollbar_visible =
1557 child_min_height > allocation->height -
1558 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1560 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1562 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1563 priv->hscrollbar_visible = child_min_width > allocation->width -
1564 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1567 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1569 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1571 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1572 priv->vscrollbar_visible =
1573 child_min_height > allocation->height -
1574 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1576 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1581 /* Now after guessing scrollbar visibility; fall back on the allocation loop which
1582 * observes the adjustments to detect scrollbar visibility and also avoids
1583 * infinite recursion
1587 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1589 child_allocation.x = relative_allocation.x + allocation->x;
1590 child_allocation.y = relative_allocation.y + allocation->y;
1591 child_allocation.width = relative_allocation.width;
1592 child_allocation.height = relative_allocation.height;
1594 previous_hvis = priv->hscrollbar_visible;
1595 previous_vvis = priv->vscrollbar_visible;
1597 gtk_widget_size_allocate (child, &child_allocation);
1599 /* If, after the first iteration, the hscrollbar and the
1600 * vscrollbar flip visiblity, then we need both.
1603 previous_hvis != priv->hscrollbar_visible &&
1604 previous_vvis != priv->vscrollbar_visible)
1606 priv->hscrollbar_visible = TRUE;
1607 priv->vscrollbar_visible = TRUE;
1609 /* a new resize is already queued at this point,
1610 * so we will immediatedly get reinvoked
1617 while (previous_hvis != priv->hscrollbar_visible ||
1618 previous_vvis != priv->vscrollbar_visible);
1622 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1623 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1624 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1627 if (priv->hscrollbar_visible)
1629 if (!gtk_widget_get_visible (priv->hscrollbar))
1630 gtk_widget_show (priv->hscrollbar);
1632 child_allocation.x = relative_allocation.x;
1633 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1634 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1635 child_allocation.y = (relative_allocation.y +
1636 relative_allocation.height +
1638 (priv->shadow_type == GTK_SHADOW_NONE ?
1639 0 : style->ythickness));
1641 child_allocation.y = 0;
1643 child_allocation.width = relative_allocation.width;
1644 child_allocation.height = sb_height;
1645 child_allocation.x += allocation->x;
1646 child_allocation.y += allocation->y;
1648 if (priv->shadow_type != GTK_SHADOW_NONE)
1650 if (!scrollbars_within_bevel)
1652 child_allocation.x -= style->xthickness;
1653 child_allocation.width += 2 * style->xthickness;
1655 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1656 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1658 child_allocation.y -= style->ythickness;
1662 child_allocation.y += style->ythickness;
1666 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1668 else if (gtk_widget_get_visible (priv->hscrollbar))
1669 gtk_widget_hide (priv->hscrollbar);
1671 if (priv->vscrollbar_visible)
1673 if (!gtk_widget_get_visible (priv->vscrollbar))
1674 gtk_widget_show (priv->vscrollbar);
1676 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1677 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1678 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1679 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1680 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1681 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1682 child_allocation.x = (relative_allocation.x +
1683 relative_allocation.width +
1685 (priv->shadow_type == GTK_SHADOW_NONE ?
1686 0 : style->xthickness));
1688 child_allocation.x = 0;
1690 child_allocation.y = relative_allocation.y;
1691 child_allocation.width = sb_width;
1692 child_allocation.height = relative_allocation.height;
1693 child_allocation.x += allocation->x;
1694 child_allocation.y += allocation->y;
1696 if (priv->shadow_type != GTK_SHADOW_NONE)
1698 if (!scrollbars_within_bevel)
1700 child_allocation.y -= style->ythickness;
1701 child_allocation.height += 2 * style->ythickness;
1703 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1704 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1706 child_allocation.x -= style->xthickness;
1710 child_allocation.x += style->xthickness;
1714 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1716 else if (gtk_widget_get_visible (priv->vscrollbar))
1717 gtk_widget_hide (priv->vscrollbar);
1721 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1722 GdkEventScroll *event)
1724 GtkScrolledWindowPrivate *priv;
1725 GtkScrolledWindow *scrolled_window;
1728 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1729 g_return_val_if_fail (event != NULL, FALSE);
1731 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1732 priv = scrolled_window->priv;
1734 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1735 range = priv->vscrollbar;
1737 range = priv->hscrollbar;
1739 if (range && gtk_widget_get_visible (range))
1741 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1744 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1746 gtk_adjustment_set_value (adj, adj->value + delta);
1755 gtk_scrolled_window_focus (GtkWidget *widget,
1756 GtkDirectionType direction)
1758 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1759 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1761 gboolean had_focus_child;
1763 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1765 if (priv->focus_out)
1767 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1771 if (gtk_widget_is_focus (widget))
1774 /* We only put the scrolled window itself in the focus chain if it
1775 * isn't possible to focus any children.
1777 child = gtk_bin_get_child (GTK_BIN (widget));
1780 if (gtk_widget_child_focus (child, direction))
1784 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1786 gtk_widget_grab_focus (widget);
1794 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1797 GtkScrolledWindowPrivate *priv;;
1798 GtkScrolledWindow *scrolled_window;
1800 g_return_if_fail (adjustment != NULL);
1801 g_return_if_fail (data != NULL);
1803 scrolled_window = GTK_SCROLLED_WINDOW (data);
1804 priv = scrolled_window->priv;
1806 if (priv->hscrollbar &&
1807 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1809 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1813 visible = priv->hscrollbar_visible;
1814 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1815 adjustment->page_size);
1816 if (priv->hscrollbar_visible != visible)
1817 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1820 else if (priv->vscrollbar &&
1821 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1823 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1827 visible = priv->vscrollbar_visible;
1828 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1829 adjustment->page_size);
1830 if (priv->vscrollbar_visible != visible)
1831 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1837 gtk_scrolled_window_add (GtkContainer *container,
1840 GtkScrolledWindowPrivate *priv;
1841 GtkScrolledWindow *scrolled_window;
1843 GtkWidget *child_widget;
1844 GtkAdjustment *hadj, *vadj;
1846 bin = GTK_BIN (container);
1847 child_widget = gtk_bin_get_child (bin);
1848 g_return_if_fail (child_widget == NULL);
1850 scrolled_window = GTK_SCROLLED_WINDOW (container);
1851 priv = scrolled_window->priv;
1853 _gtk_bin_set_child (bin, child);
1854 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1856 hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar));
1857 vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar));
1859 if (GTK_IS_SCROLLABLE (child))
1860 g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL);
1862 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1863 "use gtk_scrolled_window_add_with_viewport() instead");
1867 gtk_scrolled_window_remove (GtkContainer *container,
1870 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1871 g_return_if_fail (child != NULL);
1872 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1874 g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
1876 /* chain parent class handler to remove child */
1877 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1881 * gtk_scrolled_window_add_with_viewport:
1882 * @scrolled_window: a #GtkScrolledWindow
1883 * @child: the widget you want to scroll
1885 * Used to add children without native scrolling capabilities. This
1886 * is simply a convenience function; it is equivalent to adding the
1887 * unscrollable child to a viewport, then adding the viewport to the
1888 * scrolled window. If a child has native scrolling, use
1889 * gtk_container_add() instead of this function.
1891 * The viewport scrolls the child by moving its #GdkWindow, and takes
1892 * the size of the child to be the size of its toplevel #GdkWindow.
1893 * This will be very wrong for most widgets that support native scrolling;
1894 * for example, if you add a widget such as #GtkTreeView with a viewport,
1895 * the whole widget will scroll, including the column headings. Thus,
1896 * widgets with native scrolling support should not be used with the
1897 * #GtkViewport proxy.
1899 * A widget supports scrolling natively if it implements the
1900 * #GtkScrollable interface.
1903 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1907 GtkWidget *viewport;
1908 GtkWidget *child_widget;
1910 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1911 g_return_if_fail (GTK_IS_WIDGET (child));
1912 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1914 bin = GTK_BIN (scrolled_window);
1915 child_widget = gtk_bin_get_child (bin);
1919 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1920 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1922 viewport = child_widget;
1927 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1928 gtk_scrolled_window_get_vadjustment (scrolled_window));
1929 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1932 gtk_widget_show (viewport);
1933 gtk_container_add (GTK_CONTAINER (viewport), child);
1937 * _gtk_scrolled_window_get_spacing:
1938 * @scrolled_window: a scrolled window
1940 * Gets the spacing between the scrolled window's scrollbars and
1941 * the scrolled widget. Used by GtkCombo
1943 * Return value: the spacing, in pixels.
1946 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
1948 GtkScrolledWindowClass *class;
1950 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
1952 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
1954 if (class->scrollbar_spacing >= 0)
1955 return class->scrollbar_spacing;
1958 gint scrollbar_spacing;
1960 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
1961 "scrollbar-spacing", &scrollbar_spacing,
1964 return scrollbar_spacing;
1970 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
1971 GtkOrientation orientation,
1975 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1976 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1977 GtkBin *bin = GTK_BIN (scrolled_window);
1980 gint scrollbar_spacing;
1981 GtkRequisition hscrollbar_requisition;
1982 GtkRequisition vscrollbar_requisition;
1983 GtkRequisition minimum_req, natural_req;
1986 gint min_child_size, nat_child_size;
1988 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1992 minimum_req.width = 0;
1993 minimum_req.height = 0;
1994 natural_req.width = 0;
1995 natural_req.height = 0;
1997 gtk_widget_get_preferred_size (priv->hscrollbar,
1998 &hscrollbar_requisition, NULL);
1999 gtk_widget_get_preferred_size (priv->vscrollbar,
2000 &vscrollbar_requisition, NULL);
2002 child = gtk_bin_get_child (bin);
2003 if (child && gtk_widget_get_visible (child))
2005 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2007 gtk_widget_get_preferred_width (child,
2011 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2013 minimum_req.width += min_child_size;
2014 natural_req.width += nat_child_size;
2018 gint min_display_width =
2019 gtk_scrollable_get_min_display_width (GTK_SCROLLABLE (child));
2021 if (min_display_width > 0)
2023 minimum_req.width += min_display_width;
2024 natural_req.width += min_display_width;
2029 minimum_req.width += vscrollbar_requisition.width;
2030 natural_req.width += vscrollbar_requisition.width;
2034 else /* GTK_ORIENTATION_VERTICAL */
2036 gtk_widget_get_preferred_height (child,
2040 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2042 minimum_req.height += min_child_size;
2043 natural_req.height += nat_child_size;
2047 gint min_display_height =
2048 gtk_scrollable_get_min_display_height (GTK_SCROLLABLE (child));
2050 if (min_display_height > 0)
2052 minimum_req.height += min_display_height;
2053 natural_req.height += min_display_height;
2058 minimum_req.height += vscrollbar_requisition.height;
2059 natural_req.height += vscrollbar_requisition.height;
2065 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2066 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2068 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2069 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2070 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2071 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2074 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2075 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2077 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2078 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2079 if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2080 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2083 minimum_req.width += MAX (0, extra_width);
2084 minimum_req.height += MAX (0, extra_height);
2085 natural_req.width += MAX (0, extra_width);
2086 natural_req.height += MAX (0, extra_height);
2088 if (priv->shadow_type != GTK_SHADOW_NONE)
2090 style = gtk_widget_get_style (GTK_WIDGET (widget));
2091 minimum_req.width += 2 * style->xthickness;
2092 minimum_req.height += 2 * style->ythickness;
2093 natural_req.width += 2 * style->xthickness;
2094 natural_req.height += 2 * style->ythickness;
2097 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2100 *minimum_size = minimum_req.width;
2102 *natural_size = natural_req.width;
2107 *minimum_size = minimum_req.height;
2109 *natural_size = natural_req.height;
2114 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2118 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2122 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2126 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2130 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2132 gint *minimum_height,
2133 gint *natural_height)
2135 g_return_if_fail (GTK_IS_WIDGET (widget));
2137 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2141 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2143 gint *minimum_width,
2144 gint *natural_width)
2146 g_return_if_fail (GTK_IS_WIDGET (widget));
2148 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);