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 "gtkscrolledwindow.h"
33 #include "gtkwindow.h"
34 #include "gtktypeutils.h"
35 #include "gtkprivate.h"
40 * SECTION:gtkscrolledwindow
41 * @Short_description: Adds scrollbars to its child widget
42 * @Title: GtkScrolledWindow
43 * @See_also: #GtkViewport, #GtkAdjustment, #GtkWidgetClass
45 * #GtkScrolledWindow is a #GtkBin subclass: it's a container
46 * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
47 * to the child widget and optionally draws a beveled frame around the
50 * The scrolled window can work in two ways. Some widgets have native
51 * scrolling support; these widgets have "slots" for #GtkAdjustment
53 * <footnote><para>The scrolled window installs #GtkAdjustment objects in
54 * the child window's slots using the set_scroll_adjustments_signal,
55 * found in #GtkWidgetClass. (Conceptually, these widgets implement a
56 * "Scrollable" interface; because GTK+ 1.2 lacked interface support in
57 * the object system, this interface is hackily implemented as a signal
58 * in #GtkWidgetClass. The GTK+ 2.0 object system would allow a clean
59 * implementation, but it wasn't worth breaking the
60 * API.)</para></footnote>
61 * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
64 * For widgets that lack native scrolling support, the #GtkViewport
65 * widget acts as an adaptor class, implementing scrollability for child
66 * widgets that lack their own scrolling capabilities. Use #GtkViewport
67 * to scroll child widgets such as #GtkTable, #GtkBox, and so on.
69 * If a widget has native scrolling abilities, it can be added to the
70 * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
71 * must first add the widget to a #GtkViewport, then add the #GtkViewport
72 * to the scrolled window. The convenience function
73 * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
74 * ignore the presence of the viewport.
76 * The position of the scrollbars is controlled by the scroll
77 * adjustments. See #GtkAdjustment for the fields in an adjustment - for
78 * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
79 * represents the position of the scrollbar, which must be between the
80 * "lower" field and "upper - page_size." The "page_size" field
81 * represents the size of the visible scrollable area. The
82 * "step_increment" and "page_increment" fields are used when the user
83 * asks to step down (using the small stepper arrows) or page down (using
84 * for example the PageDown key).
86 * If a #GtkScrolledWindow doesn't behave quite as you would like, or
87 * doesn't have exactly the right layout, it's very possible to set up
88 * your own scrolling with #GtkScrollbar and for example a #GtkTable.
92 /* scrolled window policy and size requisition handling:
94 * gtk size requisition works as follows:
95 * a widget upon size-request reports the width and height that it finds
96 * to be best suited to display its contents, including children.
97 * the width and/or height reported from a widget upon size requisition
98 * may be overidden by the user by specifying a width and/or height
99 * other than 0 through gtk_widget_set_size_request().
101 * a scrolled window needs (for implementing all three policy types) to
102 * request its width and height based on two different rationales.
103 * 1) the user wants the scrolled window to just fit into the space
104 * that it gets allocated for a specifc dimension.
105 * 1.1) this does not apply if the user specified a concrete value
106 * value for that specific dimension by either specifying usize for the
107 * scrolled window or for its child.
108 * 2) the user wants the scrolled window to take as much space up as
109 * is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
111 * also, kinda obvious:
112 * 3) a user would certainly not have choosen a scrolled window as a container
113 * for the child, if the resulting allocation takes up more space than the
114 * child would have allocated without the scrolled window.
117 * A) from 1) follows: the scrolled window shouldn't request more space for a
118 * specifc dimension than is required at minimum.
119 * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
120 * window (done automatically) or by usize of the child (needs to be checked).
121 * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
123 * D) from 3) follows: the scrolled window child's minimum width and minimum height
124 * under A) at least correspond to the space taken up by its scrollbars.
127 #define DEFAULT_SCROLLBAR_SPACING 3
129 struct _GtkScrolledWindowPrivate
131 GtkCornerType real_window_placement;
132 GtkWidget *hscrollbar;
133 GtkWidget *vscrollbar;
135 gboolean window_placement_set;
139 guint hscrollbar_policy : 2;
140 guint vscrollbar_policy : 2;
141 guint hscrollbar_visible : 1;
142 guint vscrollbar_visible : 1;
143 guint window_placement : 2;
144 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
152 PROP_HSCROLLBAR_POLICY,
153 PROP_VSCROLLBAR_POLICY,
154 PROP_WINDOW_PLACEMENT,
155 PROP_WINDOW_PLACEMENT_SET,
167 static void gtk_scrolled_window_set_property (GObject *object,
171 static void gtk_scrolled_window_get_property (GObject *object,
176 static void gtk_scrolled_window_destroy (GtkWidget *widget);
177 static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
178 GdkScreen *previous_screen);
179 static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
181 static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
182 GtkAllocation *allocation);
183 static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
184 GdkEventScroll *event);
185 static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
186 GtkDirectionType direction);
187 static void gtk_scrolled_window_add (GtkContainer *container,
189 static void gtk_scrolled_window_remove (GtkContainer *container,
191 static void gtk_scrolled_window_forall (GtkContainer *container,
192 gboolean include_internals,
193 GtkCallback callback,
194 gpointer callback_data);
195 static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
196 GtkScrollType scroll,
197 gboolean horizontal);
198 static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
199 GtkDirectionType direction_type);
201 static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
202 GtkAllocation *allocation);
203 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
206 static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
208 static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
211 static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
214 static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
216 gint *minimum_height,
217 gint *natural_height);
218 static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
220 gint *minimum_height,
221 gint *natural_height);
223 static guint signals[LAST_SIGNAL] = {0};
225 G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
229 add_scroll_binding (GtkBindingSet *binding_set,
231 GdkModifierType mask,
232 GtkScrollType scroll,
235 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
237 gtk_binding_entry_add_signal (binding_set, keyval, mask,
239 GTK_TYPE_SCROLL_TYPE, scroll,
240 G_TYPE_BOOLEAN, horizontal);
241 gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
243 GTK_TYPE_SCROLL_TYPE, scroll,
244 G_TYPE_BOOLEAN, horizontal);
248 add_tab_bindings (GtkBindingSet *binding_set,
249 GdkModifierType modifiers,
250 GtkDirectionType direction)
252 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
254 GTK_TYPE_DIRECTION_TYPE, direction);
255 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
257 GTK_TYPE_DIRECTION_TYPE, direction);
261 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
263 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
264 GtkWidgetClass *widget_class;
265 GtkContainerClass *container_class;
266 GtkBindingSet *binding_set;
268 widget_class = (GtkWidgetClass*) class;
269 container_class = (GtkContainerClass*) class;
271 gobject_class->set_property = gtk_scrolled_window_set_property;
272 gobject_class->get_property = gtk_scrolled_window_get_property;
274 widget_class->destroy = gtk_scrolled_window_destroy;
275 widget_class->screen_changed = gtk_scrolled_window_screen_changed;
276 widget_class->draw = gtk_scrolled_window_draw;
277 widget_class->size_allocate = gtk_scrolled_window_size_allocate;
278 widget_class->scroll_event = gtk_scrolled_window_scroll_event;
279 widget_class->focus = gtk_scrolled_window_focus;
280 widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
281 widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
282 widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
283 widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
285 container_class->add = gtk_scrolled_window_add;
286 container_class->remove = gtk_scrolled_window_remove;
287 container_class->forall = gtk_scrolled_window_forall;
288 gtk_container_class_handle_border_width (container_class);
290 class->scrollbar_spacing = -1;
292 class->scroll_child = gtk_scrolled_window_scroll_child;
293 class->move_focus_out = gtk_scrolled_window_move_focus_out;
295 g_object_class_install_property (gobject_class,
297 g_param_spec_object ("hadjustment",
298 P_("Horizontal Adjustment"),
299 P_("The GtkAdjustment for the horizontal position"),
301 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
302 g_object_class_install_property (gobject_class,
304 g_param_spec_object ("vadjustment",
305 P_("Vertical Adjustment"),
306 P_("The GtkAdjustment for the vertical position"),
308 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
309 g_object_class_install_property (gobject_class,
310 PROP_HSCROLLBAR_POLICY,
311 g_param_spec_enum ("hscrollbar-policy",
312 P_("Horizontal Scrollbar Policy"),
313 P_("When the horizontal scrollbar is displayed"),
314 GTK_TYPE_POLICY_TYPE,
315 GTK_POLICY_AUTOMATIC,
316 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
317 g_object_class_install_property (gobject_class,
318 PROP_VSCROLLBAR_POLICY,
319 g_param_spec_enum ("vscrollbar-policy",
320 P_("Vertical Scrollbar Policy"),
321 P_("When the vertical scrollbar is displayed"),
322 GTK_TYPE_POLICY_TYPE,
323 GTK_POLICY_AUTOMATIC,
324 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
326 g_object_class_install_property (gobject_class,
327 PROP_WINDOW_PLACEMENT,
328 g_param_spec_enum ("window-placement",
329 P_("Window Placement"),
330 P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
331 GTK_TYPE_CORNER_TYPE,
333 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
336 * GtkScrolledWindow:window-placement-set:
338 * Whether "window-placement" should be used to determine the location
339 * of the contents with respect to the scrollbars. Otherwise, the
340 * "gtk-scrolled-window-placement" setting is used.
344 g_object_class_install_property (gobject_class,
345 PROP_WINDOW_PLACEMENT_SET,
346 g_param_spec_boolean ("window-placement-set",
347 P_("Window Placement Set"),
348 P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
350 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
351 g_object_class_install_property (gobject_class,
353 g_param_spec_enum ("shadow-type",
355 P_("Style of bevel around the contents"),
356 GTK_TYPE_SHADOW_TYPE,
358 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
361 * GtkScrolledWindow:scrollbars-within-bevel:
363 * Whether to place scrollbars within the scrolled window's bevel.
367 gtk_widget_class_install_style_property (widget_class,
368 g_param_spec_boolean ("scrollbars-within-bevel",
369 P_("Scrollbars within bevel"),
370 P_("Place scrollbars within the scrolled window's bevel"),
372 GTK_PARAM_READABLE));
374 gtk_widget_class_install_style_property (widget_class,
375 g_param_spec_int ("scrollbar-spacing",
376 P_("Scrollbar spacing"),
377 P_("Number of pixels between the scrollbars and the scrolled window"),
380 DEFAULT_SCROLLBAR_SPACING,
381 GTK_PARAM_READABLE));
384 * GtkScrolledWindow::scroll-child:
385 * @scrolled_window: a #GtkScrolledWindow
386 * @scroll: a #GtkScrollType describing how much to scroll
387 * @horizontal: whether the keybinding scrolls the child
388 * horizontally or not
390 * The ::scroll-child signal is a
391 * <link linkend="keybinding-signals">keybinding signal</link>
392 * which gets emitted when a keybinding that scrolls is pressed.
393 * The horizontal or vertical adjustment is updated which triggers a
394 * signal that the scrolled windows child may listen to and scroll itself.
396 signals[SCROLL_CHILD] =
397 g_signal_new (I_("scroll-child"),
398 G_TYPE_FROM_CLASS (gobject_class),
399 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
400 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
402 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
404 GTK_TYPE_SCROLL_TYPE,
408 * GtkScrolledWindow::move-focus-out:
409 * @scrolled_window: a #GtkScrolledWindow
410 * @direction_type: either %GTK_DIR_TAB_FORWARD or
411 * %GTK_DIR_TAB_BACKWARD
413 * The ::move-focus-out signal is a
414 * <link linkend="keybinding-signals">keybinding signal</link>
415 * which gets emitted when focus is moved away from the scrolled
416 * window by a keybinding.
417 * The #GtkWidget::move-focus signal is emitted with @direction_type
418 * on this scrolled windows toplevel parent in the container hierarchy.
419 * The default bindings for this signal are
420 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
422 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
424 signals[MOVE_FOCUS_OUT] =
425 g_signal_new (I_("move-focus-out"),
426 G_TYPE_FROM_CLASS (gobject_class),
427 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
428 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
430 _gtk_marshal_VOID__ENUM,
432 GTK_TYPE_DIRECTION_TYPE);
434 binding_set = gtk_binding_set_by_class (class);
436 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
437 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
438 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
439 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
441 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
442 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
443 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
444 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
446 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
447 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
448 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
449 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
451 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
452 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
454 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
458 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
460 GtkScrolledWindowPrivate *priv;
462 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
463 GTK_TYPE_SCROLLED_WINDOW,
464 GtkScrolledWindowPrivate);
466 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
467 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
469 priv->hscrollbar = NULL;
470 priv->vscrollbar = NULL;
471 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
472 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
473 priv->hscrollbar_visible = FALSE;
474 priv->vscrollbar_visible = FALSE;
475 priv->focus_out = FALSE;
476 priv->window_placement = GTK_CORNER_TOP_LEFT;
477 gtk_scrolled_window_update_real_placement (scrolled_window);
481 * gtk_scrolled_window_new:
482 * @hadjustment: (allow-none): horizontal adjustment
483 * @vadjustment: (allow-none): vertical adjustment
485 * Creates a new scrolled window.
487 * The two arguments are the scrolled window's adjustments; these will be
488 * shared with the scrollbars and the child widget to keep the bars in sync
489 * with the child. Usually you want to pass %NULL for the adjustments, which
490 * will cause the scrolled window to create them for you.
492 * Returns: a new scrolled window
495 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
496 GtkAdjustment *vadjustment)
498 GtkWidget *scrolled_window;
501 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
504 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
506 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
507 "hadjustment", hadjustment,
508 "vadjustment", vadjustment,
511 return scrolled_window;
515 * gtk_scrolled_window_set_hadjustment:
516 * @scrolled_window: a #GtkScrolledWindow
517 * @hadjustment: horizontal scroll adjustment
519 * Sets the #GtkAdjustment for the horizontal scrollbar.
522 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
523 GtkAdjustment *hadjustment)
525 GtkScrolledWindowPrivate *priv;
529 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
531 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
533 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
535 bin = GTK_BIN (scrolled_window);
536 priv = scrolled_window->priv;
538 if (!priv->hscrollbar)
540 gtk_widget_push_composite_child ();
541 priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
542 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
543 gtk_widget_pop_composite_child ();
545 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
546 g_object_ref (priv->hscrollbar);
547 gtk_widget_show (priv->hscrollbar);
551 GtkAdjustment *old_adjustment;
553 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
554 if (old_adjustment == hadjustment)
557 g_signal_handlers_disconnect_by_func (old_adjustment,
558 gtk_scrolled_window_adjustment_changed,
560 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
563 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
564 g_signal_connect (hadjustment,
566 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
568 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
570 child = gtk_bin_get_child (bin);
572 gtk_widget_set_scroll_adjustments (child,
573 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
574 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
576 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
580 * gtk_scrolled_window_set_vadjustment:
581 * @scrolled_window: a #GtkScrolledWindow
582 * @vadjustment: vertical scroll adjustment
584 * Sets the #GtkAdjustment for the vertical scrollbar.
587 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
588 GtkAdjustment *vadjustment)
590 GtkScrolledWindowPrivate *priv;
594 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
596 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
598 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
600 bin = GTK_BIN (scrolled_window);
601 priv = scrolled_window->priv;
603 if (!priv->vscrollbar)
605 gtk_widget_push_composite_child ();
606 priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
607 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
608 gtk_widget_pop_composite_child ();
610 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
611 g_object_ref (priv->vscrollbar);
612 gtk_widget_show (priv->vscrollbar);
616 GtkAdjustment *old_adjustment;
618 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
619 if (old_adjustment == vadjustment)
622 g_signal_handlers_disconnect_by_func (old_adjustment,
623 gtk_scrolled_window_adjustment_changed,
625 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
628 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
629 g_signal_connect (vadjustment,
631 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
633 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
635 child = gtk_bin_get_child (bin);
637 gtk_widget_set_scroll_adjustments (child,
638 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
639 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
641 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
645 * gtk_scrolled_window_get_hadjustment:
646 * @scrolled_window: a #GtkScrolledWindow
648 * Returns the horizontal scrollbar's adjustment, used to connect the
649 * horizontal scrollbar to the child widget's horizontal scroll
652 * Returns: (transfer none): the horizontal #GtkAdjustment
655 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
657 GtkScrolledWindowPrivate *priv;
659 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
661 priv = scrolled_window->priv;
663 return (priv->hscrollbar ?
664 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
669 * gtk_scrolled_window_get_vadjustment:
670 * @scrolled_window: a #GtkScrolledWindow
672 * Returns the vertical scrollbar's adjustment, used to connect the
673 * vertical scrollbar to the child widget's vertical scroll functionality.
675 * Returns: (transfer none): the vertical #GtkAdjustment
678 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
680 GtkScrolledWindowPrivate *priv;
682 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
684 priv = scrolled_window->priv;
686 return (priv->vscrollbar ?
687 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
692 * gtk_scrolled_window_get_hscrollbar:
693 * @scrolled_window: a #GtkScrolledWindow
695 * Returns the horizontal scrollbar of @scrolled_window.
697 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
698 * or %NULL if it does not have one.
703 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
705 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
707 return scrolled_window->priv->hscrollbar;
711 * gtk_scrolled_window_get_vscrollbar:
712 * @scrolled_window: a #GtkScrolledWindow
714 * Returns the vertical scrollbar of @scrolled_window.
716 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
717 * or %NULL if it does not have one.
722 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
724 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
726 return scrolled_window->priv->vscrollbar;
730 * gtk_scrolled_window_set_policy:
731 * @scrolled_window: a #GtkScrolledWindow
732 * @hscrollbar_policy: policy for horizontal bar
733 * @vscrollbar_policy: policy for vertical bar
735 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
737 * The policy determines when the scrollbar should appear; it is a value
738 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
739 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
740 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
741 * if needed (that is, if the slider part of the bar would be smaller
742 * than the trough - the display is larger than the page size).
745 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
746 GtkPolicyType hscrollbar_policy,
747 GtkPolicyType vscrollbar_policy)
749 GtkScrolledWindowPrivate *priv;
750 GObject *object = G_OBJECT (scrolled_window);
752 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
754 priv = scrolled_window->priv;
756 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
757 (priv->vscrollbar_policy != vscrollbar_policy))
759 priv->hscrollbar_policy = hscrollbar_policy;
760 priv->vscrollbar_policy = vscrollbar_policy;
762 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
764 g_object_freeze_notify (object);
765 g_object_notify (object, "hscrollbar-policy");
766 g_object_notify (object, "vscrollbar-policy");
767 g_object_thaw_notify (object);
772 * gtk_scrolled_window_get_policy:
773 * @scrolled_window: a #GtkScrolledWindow
774 * @hscrollbar_policy: location to store the policy for the horizontal
775 * scrollbar, or %NULL.
776 * @vscrollbar_policy: location to store the policy for the vertical
777 * scrollbar, or %NULL.
779 * Retrieves the current policy values for the horizontal and vertical
780 * scrollbars. See gtk_scrolled_window_set_policy().
783 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
784 GtkPolicyType *hscrollbar_policy,
785 GtkPolicyType *vscrollbar_policy)
787 GtkScrolledWindowPrivate *priv;
789 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
791 priv = scrolled_window->priv;
793 if (hscrollbar_policy)
794 *hscrollbar_policy = priv->hscrollbar_policy;
795 if (vscrollbar_policy)
796 *vscrollbar_policy = priv->vscrollbar_policy;
800 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
802 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
803 GtkSettings *settings;
805 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
807 if (priv->window_placement_set || settings == NULL)
808 priv->real_window_placement = priv->window_placement;
810 g_object_get (settings,
811 "gtk-scrolled-window-placement",
812 &priv->real_window_placement,
817 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
818 GtkCornerType window_placement)
820 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
822 if (priv->window_placement != window_placement)
824 priv->window_placement = window_placement;
826 gtk_scrolled_window_update_real_placement (scrolled_window);
827 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
829 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
834 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
835 gboolean placement_set,
836 gboolean emit_resize)
838 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
840 if (priv->window_placement_set != placement_set)
842 priv->window_placement_set = placement_set;
844 gtk_scrolled_window_update_real_placement (scrolled_window);
846 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
848 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
853 * gtk_scrolled_window_set_placement:
854 * @scrolled_window: a #GtkScrolledWindow
855 * @window_placement: position of the child window
857 * Sets the placement of the contents with respect to the scrollbars
858 * for the scrolled window.
860 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
861 * in the top left, with the scrollbars underneath and to the right.
862 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
863 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
865 * See also gtk_scrolled_window_get_placement() and
866 * gtk_scrolled_window_unset_placement().
869 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
870 GtkCornerType window_placement)
872 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
874 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
875 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
879 * gtk_scrolled_window_get_placement:
880 * @scrolled_window: a #GtkScrolledWindow
882 * Gets the placement of the contents with respect to the scrollbars
883 * for the scrolled window. See gtk_scrolled_window_set_placement().
885 * Return value: the current placement value.
887 * See also gtk_scrolled_window_set_placement() and
888 * gtk_scrolled_window_unset_placement().
891 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
893 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
895 return scrolled_window->priv->window_placement;
899 * gtk_scrolled_window_unset_placement:
900 * @scrolled_window: a #GtkScrolledWindow
902 * Unsets the placement of the contents with respect to the scrollbars
903 * for the scrolled window. If no window placement is set for a scrolled
904 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
906 * See also gtk_scrolled_window_set_placement() and
907 * gtk_scrolled_window_get_placement().
912 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
914 GtkScrolledWindowPrivate *priv;
916 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
918 priv = scrolled_window->priv;
920 if (priv->window_placement_set)
922 priv->window_placement_set = FALSE;
924 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
926 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
931 * gtk_scrolled_window_set_shadow_type:
932 * @scrolled_window: a #GtkScrolledWindow
933 * @type: kind of shadow to draw around scrolled window contents
935 * Changes the type of shadow drawn around the contents of
940 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
943 GtkScrolledWindowPrivate *priv;
945 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
946 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
948 priv = scrolled_window->priv;
950 if (priv->shadow_type != type)
952 priv->shadow_type = type;
954 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
955 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
957 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
959 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
964 * gtk_scrolled_window_get_shadow_type:
965 * @scrolled_window: a #GtkScrolledWindow
967 * Gets the shadow type of the scrolled window. See
968 * gtk_scrolled_window_set_shadow_type().
970 * Return value: the current shadow type
973 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
975 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
977 return scrolled_window->priv->shadow_type;
981 gtk_scrolled_window_destroy (GtkWidget *widget)
983 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
984 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
986 if (priv->hscrollbar)
988 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
989 gtk_scrolled_window_adjustment_changed,
991 gtk_widget_unparent (priv->hscrollbar);
992 gtk_widget_destroy (priv->hscrollbar);
993 g_object_unref (priv->hscrollbar);
994 priv->hscrollbar = NULL;
996 if (priv->vscrollbar)
998 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
999 gtk_scrolled_window_adjustment_changed,
1001 gtk_widget_unparent (priv->vscrollbar);
1002 gtk_widget_destroy (priv->vscrollbar);
1003 g_object_unref (priv->vscrollbar);
1004 priv->vscrollbar = NULL;
1007 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
1011 gtk_scrolled_window_set_property (GObject *object,
1013 const GValue *value,
1016 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1017 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1021 case PROP_HADJUSTMENT:
1022 gtk_scrolled_window_set_hadjustment (scrolled_window,
1023 g_value_get_object (value));
1025 case PROP_VADJUSTMENT:
1026 gtk_scrolled_window_set_vadjustment (scrolled_window,
1027 g_value_get_object (value));
1029 case PROP_HSCROLLBAR_POLICY:
1030 gtk_scrolled_window_set_policy (scrolled_window,
1031 g_value_get_enum (value),
1032 priv->vscrollbar_policy);
1034 case PROP_VSCROLLBAR_POLICY:
1035 gtk_scrolled_window_set_policy (scrolled_window,
1036 priv->hscrollbar_policy,
1037 g_value_get_enum (value));
1039 case PROP_WINDOW_PLACEMENT:
1040 gtk_scrolled_window_set_placement_internal (scrolled_window,
1041 g_value_get_enum (value));
1043 case PROP_WINDOW_PLACEMENT_SET:
1044 gtk_scrolled_window_set_placement_set (scrolled_window,
1045 g_value_get_boolean (value),
1048 case PROP_SHADOW_TYPE:
1049 gtk_scrolled_window_set_shadow_type (scrolled_window,
1050 g_value_get_enum (value));
1053 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1059 gtk_scrolled_window_get_property (GObject *object,
1064 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1065 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1069 case PROP_HADJUSTMENT:
1070 g_value_set_object (value,
1071 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1073 case PROP_VADJUSTMENT:
1074 g_value_set_object (value,
1075 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1077 case PROP_HSCROLLBAR_POLICY:
1078 g_value_set_enum (value, priv->hscrollbar_policy);
1080 case PROP_VSCROLLBAR_POLICY:
1081 g_value_set_enum (value, priv->vscrollbar_policy);
1083 case PROP_WINDOW_PLACEMENT:
1084 g_value_set_enum (value, priv->window_placement);
1086 case PROP_WINDOW_PLACEMENT_SET:
1087 g_value_set_boolean (value, priv->window_placement_set);
1089 case PROP_SHADOW_TYPE:
1090 g_value_set_enum (value, priv->shadow_type);
1093 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1099 traverse_container (GtkWidget *widget,
1102 if (GTK_IS_SCROLLED_WINDOW (widget))
1104 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1105 gtk_widget_queue_resize (widget);
1107 else if (GTK_IS_CONTAINER (widget))
1108 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1112 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1116 list = gtk_window_list_toplevels ();
1118 for (l = list; l; l = l->next)
1119 gtk_container_forall (GTK_CONTAINER (l->data),
1120 traverse_container, NULL);
1126 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1127 GdkScreen *previous_screen)
1129 GtkSettings *settings;
1130 guint window_placement_connection;
1132 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1134 if (!gtk_widget_has_screen (widget))
1137 settings = gtk_widget_get_settings (widget);
1139 window_placement_connection =
1140 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1141 "gtk-scrolled-window-connection"));
1143 if (window_placement_connection)
1146 window_placement_connection =
1147 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1148 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1149 g_object_set_data (G_OBJECT (settings),
1150 I_("gtk-scrolled-window-connection"),
1151 GUINT_TO_POINTER (window_placement_connection));
1155 gtk_scrolled_window_draw (GtkWidget *widget,
1158 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1159 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1161 if (priv->shadow_type != GTK_SHADOW_NONE)
1163 GtkAllocation relative_allocation;
1165 gboolean scrollbars_within_bevel;
1167 style = gtk_widget_get_style (widget);
1168 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1170 if (!scrollbars_within_bevel)
1172 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1174 relative_allocation.x -= style->xthickness;
1175 relative_allocation.y -= style->ythickness;
1176 relative_allocation.width += 2 * style->xthickness;
1177 relative_allocation.height += 2 * style->ythickness;
1181 relative_allocation.x = 0;
1182 relative_allocation.y = 0;
1183 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1184 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1187 gtk_paint_shadow (style,
1189 GTK_STATE_NORMAL, priv->shadow_type,
1190 widget, "scrolled_window",
1191 relative_allocation.x,
1192 relative_allocation.y,
1193 relative_allocation.width,
1194 relative_allocation.height);
1197 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1203 gtk_scrolled_window_forall (GtkContainer *container,
1204 gboolean include_internals,
1205 GtkCallback callback,
1206 gpointer callback_data)
1208 GtkScrolledWindowPrivate *priv;
1209 GtkScrolledWindow *scrolled_window;
1211 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1212 g_return_if_fail (callback != NULL);
1214 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1218 if (include_internals)
1220 scrolled_window = GTK_SCROLLED_WINDOW (container);
1221 priv = scrolled_window->priv;
1223 if (priv->vscrollbar)
1224 callback (priv->vscrollbar, callback_data);
1225 if (priv->hscrollbar)
1226 callback (priv->hscrollbar, callback_data);
1231 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1232 GtkScrollType scroll,
1233 gboolean horizontal)
1235 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1236 GtkAdjustment *adjustment = NULL;
1240 case GTK_SCROLL_STEP_UP:
1241 scroll = GTK_SCROLL_STEP_BACKWARD;
1244 case GTK_SCROLL_STEP_DOWN:
1245 scroll = GTK_SCROLL_STEP_FORWARD;
1248 case GTK_SCROLL_STEP_LEFT:
1249 scroll = GTK_SCROLL_STEP_BACKWARD;
1252 case GTK_SCROLL_STEP_RIGHT:
1253 scroll = GTK_SCROLL_STEP_FORWARD;
1256 case GTK_SCROLL_PAGE_UP:
1257 scroll = GTK_SCROLL_PAGE_BACKWARD;
1260 case GTK_SCROLL_PAGE_DOWN:
1261 scroll = GTK_SCROLL_PAGE_FORWARD;
1264 case GTK_SCROLL_PAGE_LEFT:
1265 scroll = GTK_SCROLL_STEP_BACKWARD;
1268 case GTK_SCROLL_PAGE_RIGHT:
1269 scroll = GTK_SCROLL_STEP_FORWARD;
1272 case GTK_SCROLL_STEP_BACKWARD:
1273 case GTK_SCROLL_STEP_FORWARD:
1274 case GTK_SCROLL_PAGE_BACKWARD:
1275 case GTK_SCROLL_PAGE_FORWARD:
1276 case GTK_SCROLL_START:
1277 case GTK_SCROLL_END:
1280 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1284 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1285 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1290 if (priv->hscrollbar)
1291 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1295 if (priv->vscrollbar)
1296 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1301 gdouble value = adjustment->value;
1305 case GTK_SCROLL_STEP_FORWARD:
1306 value += adjustment->step_increment;
1308 case GTK_SCROLL_STEP_BACKWARD:
1309 value -= adjustment->step_increment;
1311 case GTK_SCROLL_PAGE_FORWARD:
1312 value += adjustment->page_increment;
1314 case GTK_SCROLL_PAGE_BACKWARD:
1315 value -= adjustment->page_increment;
1317 case GTK_SCROLL_START:
1318 value = adjustment->lower;
1320 case GTK_SCROLL_END:
1321 value = adjustment->upper;
1324 g_assert_not_reached ();
1328 gtk_adjustment_set_value (adjustment, value);
1337 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1338 GtkDirectionType direction_type)
1340 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1341 GtkWidget *toplevel;
1343 /* Focus out of the scrolled window entirely. We do this by setting
1344 * a flag, then propagating the focus motion to the notebook.
1346 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1347 if (!gtk_widget_is_toplevel (toplevel))
1350 g_object_ref (scrolled_window);
1352 priv->focus_out = TRUE;
1353 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1354 priv->focus_out = FALSE;
1356 g_object_unref (scrolled_window);
1360 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1361 GtkAllocation *allocation)
1363 GtkAllocation widget_allocation;
1364 GtkScrolledWindow *scrolled_window;
1365 GtkScrolledWindowPrivate *priv;
1371 g_return_if_fail (widget != NULL);
1372 g_return_if_fail (allocation != NULL);
1374 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1375 priv = scrolled_window->priv;
1377 /* Get possible scrollbar dimensions */
1378 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1379 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1380 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1382 /* Subtract some things from our available allocation size */
1386 if (priv->shadow_type != GTK_SHADOW_NONE)
1388 style = gtk_widget_get_style (widget);
1389 allocation->x += style->xthickness;
1390 allocation->y += style->ythickness;
1393 gtk_widget_get_allocation (widget, &widget_allocation);
1394 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1395 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1397 if (priv->vscrollbar_visible)
1401 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1404 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1405 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1407 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1408 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1409 allocation->x += (sb_width + sb_spacing);
1411 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1413 if (priv->hscrollbar_visible)
1416 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1417 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1418 allocation->y += (sb_height + sb_spacing);
1420 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1425 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1426 GtkAllocation *allocation)
1428 GtkScrolledWindow *scrolled_window;
1429 GtkScrolledWindowPrivate *priv;
1432 GtkAllocation relative_allocation;
1433 GtkAllocation child_allocation;
1435 gboolean scrollbars_within_bevel;
1442 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1443 g_return_if_fail (allocation != NULL);
1445 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1446 bin = GTK_BIN (scrolled_window);
1447 priv = scrolled_window->priv;
1449 /* Get possible scrollbar dimensions */
1450 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1451 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1452 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1454 style = gtk_widget_get_style (widget);
1455 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1457 gtk_widget_set_allocation (widget, allocation);
1459 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1460 priv->hscrollbar_visible = TRUE;
1461 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1462 priv->hscrollbar_visible = FALSE;
1463 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1464 priv->vscrollbar_visible = TRUE;
1465 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1466 priv->vscrollbar_visible = FALSE;
1468 child = gtk_bin_get_child (bin);
1469 if (child && gtk_widget_get_visible (child))
1471 gint child_min_width;
1472 gint child_min_height;
1473 gboolean previous_hvis;
1474 gboolean previous_vvis;
1477 /* In the case that both scrollbars are visible in the previous round,
1478 * we dont do our guess-work before hand because it's possible some
1479 * infinite recursion was detected (leave it up to the child scrollable
1480 * widget in this case to drive the scrollbar visibility completely
1481 * with the adjustment values).
1483 if (!priv->vscrollbar_visible || !priv->hscrollbar_visible)
1486 /* Determine scrollbar visibility first via hfw apis */
1487 if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1489 gtk_widget_get_preferred_width (child, &child_min_width, NULL);
1491 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1493 /* First try without a vertical scrollbar if the content will fit the height
1494 * given the extra width of the scrollbar */
1495 gtk_widget_get_preferred_height_for_width (child, allocation->width,
1496 &child_min_height, NULL);
1498 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1500 /* Does the content height fit the allocation height ? */
1501 priv->vscrollbar_visible = child_min_height > allocation->height;
1503 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1504 priv->hscrollbar_visible =
1505 child_min_width > allocation->width -
1506 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1508 /* Now that we've guessed the hscrollbar, does the content height fit
1509 * the possible new allocation height ? */
1510 priv->vscrollbar_visible =
1511 child_min_height > allocation->height -
1512 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1514 /* Now that we've guessed the vscrollbar, does the content width fit
1515 * the possible new allocation width ? */
1516 priv->hscrollbar_visible =
1517 child_min_width > allocation->width -
1518 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1520 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1522 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1523 priv->vscrollbar_visible = child_min_height > allocation->height -
1524 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1527 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1529 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1531 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1532 priv->hscrollbar_visible =
1533 child_min_width > allocation->width -
1534 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1536 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1539 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1541 gtk_widget_get_preferred_height (child, &child_min_height, NULL);
1543 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1545 /* First try without a horizontal scrollbar if the content will fit the width
1546 * given the extra height of the scrollbar */
1547 gtk_widget_get_preferred_width_for_height (child, allocation->height,
1548 &child_min_width, NULL);
1550 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1552 /* Does the content width fit the allocation width ? */
1553 priv->hscrollbar_visible = child_min_width > allocation->width;
1555 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1556 priv->vscrollbar_visible =
1557 child_min_height > allocation->height -
1558 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1560 /* Now that we've guessed the vscrollbar, does the content width fit
1561 * the possible new allocation width ? */
1562 priv->hscrollbar_visible =
1563 child_min_width > allocation->width -
1564 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1566 /* Now that we've guessed the hscrollbar, does the content height fit
1567 * the possible new allocation height ? */
1568 priv->vscrollbar_visible =
1569 child_min_height > allocation->height -
1570 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1572 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1574 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1575 priv->hscrollbar_visible = child_min_width > allocation->width -
1576 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1579 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1581 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1583 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1584 priv->vscrollbar_visible =
1585 child_min_height > allocation->height -
1586 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1588 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1593 /* Now after guessing scrollbar visibility; fall back on the allocation loop which
1594 * observes the adjustments to detect scrollbar visibility and also avoids
1595 * infinite recursion
1599 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1601 child_allocation.x = relative_allocation.x + allocation->x;
1602 child_allocation.y = relative_allocation.y + allocation->y;
1603 child_allocation.width = relative_allocation.width;
1604 child_allocation.height = relative_allocation.height;
1606 previous_hvis = priv->hscrollbar_visible;
1607 previous_vvis = priv->vscrollbar_visible;
1609 gtk_widget_size_allocate (child, &child_allocation);
1611 /* If, after the first iteration, the hscrollbar and the
1612 * vscrollbar flip visiblity, then we need both.
1615 previous_hvis != priv->hscrollbar_visible &&
1616 previous_vvis != priv->vscrollbar_visible)
1618 priv->hscrollbar_visible = TRUE;
1619 priv->vscrollbar_visible = TRUE;
1621 /* a new resize is already queued at this point,
1622 * so we will immediatedly get reinvoked
1629 while (previous_hvis != priv->hscrollbar_visible ||
1630 previous_vvis != priv->vscrollbar_visible);
1634 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1635 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1636 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1639 if (priv->hscrollbar_visible)
1641 if (!gtk_widget_get_visible (priv->hscrollbar))
1642 gtk_widget_show (priv->hscrollbar);
1644 child_allocation.x = relative_allocation.x;
1645 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1646 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1647 child_allocation.y = (relative_allocation.y +
1648 relative_allocation.height +
1650 (priv->shadow_type == GTK_SHADOW_NONE ?
1651 0 : style->ythickness));
1653 child_allocation.y = 0;
1655 child_allocation.width = relative_allocation.width;
1656 child_allocation.height = sb_height;
1657 child_allocation.x += allocation->x;
1658 child_allocation.y += allocation->y;
1660 if (priv->shadow_type != GTK_SHADOW_NONE)
1662 if (!scrollbars_within_bevel)
1664 child_allocation.x -= style->xthickness;
1665 child_allocation.width += 2 * style->xthickness;
1667 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1668 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1670 child_allocation.y -= style->ythickness;
1674 child_allocation.y += style->ythickness;
1678 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1680 else if (gtk_widget_get_visible (priv->hscrollbar))
1681 gtk_widget_hide (priv->hscrollbar);
1683 if (priv->vscrollbar_visible)
1685 if (!gtk_widget_get_visible (priv->vscrollbar))
1686 gtk_widget_show (priv->vscrollbar);
1688 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1689 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1690 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1691 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1692 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1693 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1694 child_allocation.x = (relative_allocation.x +
1695 relative_allocation.width +
1697 (priv->shadow_type == GTK_SHADOW_NONE ?
1698 0 : style->xthickness));
1700 child_allocation.x = 0;
1702 child_allocation.y = relative_allocation.y;
1703 child_allocation.width = sb_width;
1704 child_allocation.height = relative_allocation.height;
1705 child_allocation.x += allocation->x;
1706 child_allocation.y += allocation->y;
1708 if (priv->shadow_type != GTK_SHADOW_NONE)
1710 if (!scrollbars_within_bevel)
1712 child_allocation.y -= style->ythickness;
1713 child_allocation.height += 2 * style->ythickness;
1715 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1716 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1718 child_allocation.x -= style->xthickness;
1722 child_allocation.x += style->xthickness;
1726 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1728 else if (gtk_widget_get_visible (priv->vscrollbar))
1729 gtk_widget_hide (priv->vscrollbar);
1733 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1734 GdkEventScroll *event)
1736 GtkScrolledWindowPrivate *priv;
1737 GtkScrolledWindow *scrolled_window;
1740 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1741 g_return_val_if_fail (event != NULL, FALSE);
1743 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1744 priv = scrolled_window->priv;
1746 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1747 range = priv->vscrollbar;
1749 range = priv->hscrollbar;
1751 if (range && gtk_widget_get_visible (range))
1753 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1756 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1758 gtk_adjustment_set_value (adj, adj->value + delta);
1767 gtk_scrolled_window_focus (GtkWidget *widget,
1768 GtkDirectionType direction)
1770 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1771 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1773 gboolean had_focus_child;
1775 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1777 if (priv->focus_out)
1779 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1783 if (gtk_widget_is_focus (widget))
1786 /* We only put the scrolled window itself in the focus chain if it
1787 * isn't possible to focus any children.
1789 child = gtk_bin_get_child (GTK_BIN (widget));
1792 if (gtk_widget_child_focus (child, direction))
1796 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1798 gtk_widget_grab_focus (widget);
1806 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1809 GtkScrolledWindowPrivate *priv;;
1810 GtkScrolledWindow *scrolled_window;
1812 g_return_if_fail (adjustment != NULL);
1813 g_return_if_fail (data != NULL);
1815 scrolled_window = GTK_SCROLLED_WINDOW (data);
1816 priv = scrolled_window->priv;
1818 if (priv->hscrollbar &&
1819 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1821 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1825 visible = priv->hscrollbar_visible;
1826 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1827 adjustment->page_size);
1828 if (priv->hscrollbar_visible != visible)
1829 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1832 else if (priv->vscrollbar &&
1833 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1835 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1839 visible = priv->vscrollbar_visible;
1840 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1841 adjustment->page_size);
1842 if (priv->vscrollbar_visible != visible)
1843 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1849 gtk_scrolled_window_add (GtkContainer *container,
1852 GtkScrolledWindowPrivate *priv;
1853 GtkScrolledWindow *scrolled_window;
1855 GtkWidget *child_widget;
1857 bin = GTK_BIN (container);
1858 child_widget = gtk_bin_get_child (bin);
1859 g_return_if_fail (child_widget == NULL);
1861 scrolled_window = GTK_SCROLLED_WINDOW (container);
1862 priv = scrolled_window->priv;
1864 _gtk_bin_set_child (bin, child);
1865 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1867 /* this is a temporary message */
1868 if (!gtk_widget_set_scroll_adjustments (child,
1869 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
1870 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))))
1871 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1872 "use gtk_scrolled_window_add_with_viewport() instead");
1876 gtk_scrolled_window_remove (GtkContainer *container,
1879 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1880 g_return_if_fail (child != NULL);
1881 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1883 gtk_widget_set_scroll_adjustments (child, NULL, NULL);
1885 /* chain parent class handler to remove child */
1886 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1890 * gtk_scrolled_window_add_with_viewport:
1891 * @scrolled_window: a #GtkScrolledWindow
1892 * @child: the widget you want to scroll
1894 * Used to add children without native scrolling capabilities. This
1895 * is simply a convenience function; it is equivalent to adding the
1896 * unscrollable child to a viewport, then adding the viewport to the
1897 * scrolled window. If a child has native scrolling, use
1898 * gtk_container_add() instead of this function.
1900 * The viewport scrolls the child by moving its #GdkWindow, and takes
1901 * the size of the child to be the size of its toplevel #GdkWindow.
1902 * This will be very wrong for most widgets that support native scrolling;
1903 * for example, if you add a widget such as #GtkTreeView with a viewport,
1904 * the whole widget will scroll, including the column headings. Thus,
1905 * widgets with native scrolling support should not be used with the
1906 * #GtkViewport proxy.
1908 * A widget supports scrolling natively if the
1909 * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
1910 * i.e. has been filled in with a valid signal identifier.
1913 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1917 GtkWidget *viewport;
1918 GtkWidget *child_widget;
1920 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1921 g_return_if_fail (GTK_IS_WIDGET (child));
1922 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1924 bin = GTK_BIN (scrolled_window);
1925 child_widget = gtk_bin_get_child (bin);
1929 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1930 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1932 viewport = child_widget;
1937 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1938 gtk_scrolled_window_get_vadjustment (scrolled_window));
1939 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1942 gtk_widget_show (viewport);
1943 gtk_container_add (GTK_CONTAINER (viewport), child);
1947 * _gtk_scrolled_window_get_spacing:
1948 * @scrolled_window: a scrolled window
1950 * Gets the spacing between the scrolled window's scrollbars and
1951 * the scrolled widget. Used by GtkCombo
1953 * Return value: the spacing, in pixels.
1956 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
1958 GtkScrolledWindowClass *class;
1960 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
1962 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
1964 if (class->scrollbar_spacing >= 0)
1965 return class->scrollbar_spacing;
1968 gint scrollbar_spacing;
1970 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
1971 "scrollbar-spacing", &scrollbar_spacing,
1974 return scrollbar_spacing;
1980 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
1981 GtkOrientation orientation,
1985 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1986 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1987 GtkBin *bin = GTK_BIN (scrolled_window);
1990 gint scrollbar_spacing;
1991 GtkRequisition hscrollbar_requisition;
1992 GtkRequisition vscrollbar_requisition;
1993 GtkRequisition minimum_req, natural_req;
1996 gint min_child_size, nat_child_size;
1998 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
2002 minimum_req.width = 0;
2003 minimum_req.height = 0;
2004 natural_req.width = 0;
2005 natural_req.height = 0;
2007 gtk_widget_get_preferred_size (priv->hscrollbar,
2008 &hscrollbar_requisition, NULL);
2009 gtk_widget_get_preferred_size (priv->vscrollbar,
2010 &vscrollbar_requisition, NULL);
2012 child = gtk_bin_get_child (bin);
2013 if (child && gtk_widget_get_visible (child))
2015 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2017 gtk_widget_get_preferred_width (child,
2021 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2023 minimum_req.width += min_child_size;
2024 natural_req.width += nat_child_size;
2028 /* Always ask for at least enough to fit the scrollbars */
2029 minimum_req.width += vscrollbar_requisition.width;
2030 natural_req.width += vscrollbar_requisition.width;
2033 else /* GTK_ORIENTATION_VERTICAL */
2035 gtk_widget_get_preferred_height (child,
2039 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2041 minimum_req.height += min_child_size;
2042 natural_req.height += nat_child_size;
2046 /* Always ask for at least enough to fit the scrollbars */
2047 minimum_req.height += hscrollbar_requisition.height;
2048 natural_req.height += hscrollbar_requisition.height;
2053 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2054 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2056 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2057 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2058 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2059 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2062 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2063 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2065 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2066 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2067 if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2068 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2071 minimum_req.width += extra_width;
2072 minimum_req.height += extra_height;
2073 natural_req.width += extra_width;
2074 natural_req.height += extra_height;
2076 if (priv->shadow_type != GTK_SHADOW_NONE)
2078 style = gtk_widget_get_style (GTK_WIDGET (widget));
2079 minimum_req.width += 2 * style->xthickness;
2080 minimum_req.height += 2 * style->ythickness;
2081 natural_req.width += 2 * style->xthickness;
2082 natural_req.height += 2 * style->ythickness;
2085 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2088 *minimum_size = minimum_req.width;
2090 *natural_size = natural_req.width;
2095 *minimum_size = minimum_req.height;
2097 *natural_size = natural_req.height;
2102 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2106 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2110 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2114 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2118 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2120 gint *minimum_height,
2121 gint *natural_height)
2123 g_return_if_fail (GTK_IS_WIDGET (widget));
2125 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2129 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2131 gint *minimum_width,
2132 gint *natural_width)
2134 g_return_if_fail (GTK_IS_WIDGET (widget));
2136 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);