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 * GtkSettings:gtk-scrolled-window-placement:
386 * Where the contents of scrolled windows are located with respect to the
387 * scrollbars, if not overridden by the scrolled window's own placement.
391 gtk_settings_install_property (g_param_spec_enum ("gtk-scrolled-window-placement",
392 P_("Scrolled Window Placement"),
393 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
394 GTK_TYPE_CORNER_TYPE,
396 G_PARAM_READABLE | G_PARAM_WRITABLE));
399 signals[SCROLL_CHILD] =
400 g_signal_new (I_("scroll-child"),
401 G_TYPE_FROM_CLASS (gobject_class),
402 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
403 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
405 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
407 GTK_TYPE_SCROLL_TYPE,
409 signals[MOVE_FOCUS_OUT] =
410 g_signal_new (I_("move-focus-out"),
411 G_TYPE_FROM_CLASS (gobject_class),
412 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
413 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
415 _gtk_marshal_VOID__ENUM,
417 GTK_TYPE_DIRECTION_TYPE);
419 binding_set = gtk_binding_set_by_class (class);
421 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
422 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
423 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
424 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
426 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
427 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
428 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
429 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
431 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
432 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
433 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
434 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
436 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
437 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
439 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
443 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
445 GtkScrolledWindowPrivate *priv;
447 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
448 GTK_TYPE_SCROLLED_WINDOW,
449 GtkScrolledWindowPrivate);
451 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
452 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
454 priv->hscrollbar = NULL;
455 priv->vscrollbar = NULL;
456 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
457 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
458 priv->hscrollbar_visible = FALSE;
459 priv->vscrollbar_visible = FALSE;
460 priv->focus_out = FALSE;
461 priv->window_placement = GTK_CORNER_TOP_LEFT;
462 gtk_scrolled_window_update_real_placement (scrolled_window);
466 * gtk_scrolled_window_new:
467 * @hadjustment: (allow-none): horizontal adjustment
468 * @vadjustment: (allow-none): vertical adjustment
470 * Creates a new scrolled window.
472 * The two arguments are the scrolled window's adjustments; these will be
473 * shared with the scrollbars and the child widget to keep the bars in sync
474 * with the child. Usually you want to pass %NULL for the adjustments, which
475 * will cause the scrolled window to create them for you.
477 * Returns: a new scrolled window
480 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
481 GtkAdjustment *vadjustment)
483 GtkWidget *scrolled_window;
486 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
489 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
491 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
492 "hadjustment", hadjustment,
493 "vadjustment", vadjustment,
496 return scrolled_window;
500 * gtk_scrolled_window_set_hadjustment:
501 * @scrolled_window: a #GtkScrolledWindow
502 * @hadjustment: horizontal scroll adjustment
504 * Sets the #GtkAdjustment for the horizontal scrollbar.
507 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
508 GtkAdjustment *hadjustment)
510 GtkScrolledWindowPrivate *priv;
514 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
516 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
518 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
520 bin = GTK_BIN (scrolled_window);
521 priv = scrolled_window->priv;
523 if (!priv->hscrollbar)
525 gtk_widget_push_composite_child ();
526 priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
527 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
528 gtk_widget_pop_composite_child ();
530 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
531 g_object_ref (priv->hscrollbar);
532 gtk_widget_show (priv->hscrollbar);
536 GtkAdjustment *old_adjustment;
538 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
539 if (old_adjustment == hadjustment)
542 g_signal_handlers_disconnect_by_func (old_adjustment,
543 gtk_scrolled_window_adjustment_changed,
545 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
548 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
549 g_signal_connect (hadjustment,
551 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
553 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
555 child = gtk_bin_get_child (bin);
557 gtk_widget_set_scroll_adjustments (child,
558 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
559 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
561 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
565 * gtk_scrolled_window_set_vadjustment:
566 * @scrolled_window: a #GtkScrolledWindow
567 * @vadjustment: vertical scroll adjustment
569 * Sets the #GtkAdjustment for the vertical scrollbar.
572 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
573 GtkAdjustment *vadjustment)
575 GtkScrolledWindowPrivate *priv;
579 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
581 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
583 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
585 bin = GTK_BIN (scrolled_window);
586 priv = scrolled_window->priv;
588 if (!priv->vscrollbar)
590 gtk_widget_push_composite_child ();
591 priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
592 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
593 gtk_widget_pop_composite_child ();
595 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
596 g_object_ref (priv->vscrollbar);
597 gtk_widget_show (priv->vscrollbar);
601 GtkAdjustment *old_adjustment;
603 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
604 if (old_adjustment == vadjustment)
607 g_signal_handlers_disconnect_by_func (old_adjustment,
608 gtk_scrolled_window_adjustment_changed,
610 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
613 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
614 g_signal_connect (vadjustment,
616 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
618 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
620 child = gtk_bin_get_child (bin);
622 gtk_widget_set_scroll_adjustments (child,
623 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
624 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
626 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
630 * gtk_scrolled_window_get_hadjustment:
631 * @scrolled_window: a #GtkScrolledWindow
633 * Returns the horizontal scrollbar's adjustment, used to connect the
634 * horizontal scrollbar to the child widget's horizontal scroll
637 * Returns: (transfer none): the horizontal #GtkAdjustment
640 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
642 GtkScrolledWindowPrivate *priv;
644 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
646 priv = scrolled_window->priv;
648 return (priv->hscrollbar ?
649 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
654 * gtk_scrolled_window_get_vadjustment:
655 * @scrolled_window: a #GtkScrolledWindow
657 * Returns the vertical scrollbar's adjustment, used to connect the
658 * vertical scrollbar to the child widget's vertical scroll functionality.
660 * Returns: (transfer none): the vertical #GtkAdjustment
663 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
665 GtkScrolledWindowPrivate *priv;
667 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
669 priv = scrolled_window->priv;
671 return (priv->vscrollbar ?
672 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
677 * gtk_scrolled_window_get_hscrollbar:
678 * @scrolled_window: a #GtkScrolledWindow
680 * Returns the horizontal scrollbar of @scrolled_window.
682 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
683 * or %NULL if it does not have one.
688 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
690 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
692 return scrolled_window->priv->hscrollbar;
696 * gtk_scrolled_window_get_vscrollbar:
697 * @scrolled_window: a #GtkScrolledWindow
699 * Returns the vertical scrollbar of @scrolled_window.
701 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
702 * or %NULL if it does not have one.
707 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
709 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
711 return scrolled_window->priv->vscrollbar;
715 * gtk_scrolled_window_set_policy:
716 * @scrolled_window: a #GtkScrolledWindow
717 * @hscrollbar_policy: policy for horizontal bar
718 * @vscrollbar_policy: policy for vertical bar
720 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
722 * The policy determines when the scrollbar should appear; it is a value
723 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
724 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
725 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
726 * if needed (that is, if the slider part of the bar would be smaller
727 * than the trough - the display is larger than the page size).
730 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
731 GtkPolicyType hscrollbar_policy,
732 GtkPolicyType vscrollbar_policy)
734 GtkScrolledWindowPrivate *priv;
735 GObject *object = G_OBJECT (scrolled_window);
737 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
739 priv = scrolled_window->priv;
741 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
742 (priv->vscrollbar_policy != vscrollbar_policy))
744 priv->hscrollbar_policy = hscrollbar_policy;
745 priv->vscrollbar_policy = vscrollbar_policy;
747 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
749 g_object_freeze_notify (object);
750 g_object_notify (object, "hscrollbar-policy");
751 g_object_notify (object, "vscrollbar-policy");
752 g_object_thaw_notify (object);
757 * gtk_scrolled_window_get_policy:
758 * @scrolled_window: a #GtkScrolledWindow
759 * @hscrollbar_policy: location to store the policy for the horizontal
760 * scrollbar, or %NULL.
761 * @vscrollbar_policy: location to store the policy for the vertical
762 * scrollbar, or %NULL.
764 * Retrieves the current policy values for the horizontal and vertical
765 * scrollbars. See gtk_scrolled_window_set_policy().
768 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
769 GtkPolicyType *hscrollbar_policy,
770 GtkPolicyType *vscrollbar_policy)
772 GtkScrolledWindowPrivate *priv;
774 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
776 priv = scrolled_window->priv;
778 if (hscrollbar_policy)
779 *hscrollbar_policy = priv->hscrollbar_policy;
780 if (vscrollbar_policy)
781 *vscrollbar_policy = priv->vscrollbar_policy;
785 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
787 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
788 GtkSettings *settings;
790 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
792 if (priv->window_placement_set || settings == NULL)
793 priv->real_window_placement = priv->window_placement;
795 g_object_get (settings,
796 "gtk-scrolled-window-placement",
797 &priv->real_window_placement,
802 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
803 GtkCornerType window_placement)
805 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
807 if (priv->window_placement != window_placement)
809 priv->window_placement = window_placement;
811 gtk_scrolled_window_update_real_placement (scrolled_window);
812 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
814 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
819 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
820 gboolean placement_set,
821 gboolean emit_resize)
823 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
825 if (priv->window_placement_set != placement_set)
827 priv->window_placement_set = placement_set;
829 gtk_scrolled_window_update_real_placement (scrolled_window);
831 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
833 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
838 * gtk_scrolled_window_set_placement:
839 * @scrolled_window: a #GtkScrolledWindow
840 * @window_placement: position of the child window
842 * Sets the placement of the contents with respect to the scrollbars
843 * for the scrolled window.
845 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
846 * in the top left, with the scrollbars underneath and to the right.
847 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
848 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
850 * See also gtk_scrolled_window_get_placement() and
851 * gtk_scrolled_window_unset_placement().
854 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
855 GtkCornerType window_placement)
857 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
859 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
860 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
864 * gtk_scrolled_window_get_placement:
865 * @scrolled_window: a #GtkScrolledWindow
867 * Gets the placement of the contents with respect to the scrollbars
868 * for the scrolled window. See gtk_scrolled_window_set_placement().
870 * Return value: the current placement value.
872 * See also gtk_scrolled_window_set_placement() and
873 * gtk_scrolled_window_unset_placement().
876 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
878 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
880 return scrolled_window->priv->window_placement;
884 * gtk_scrolled_window_unset_placement:
885 * @scrolled_window: a #GtkScrolledWindow
887 * Unsets the placement of the contents with respect to the scrollbars
888 * for the scrolled window. If no window placement is set for a scrolled
889 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
891 * See also gtk_scrolled_window_set_placement() and
892 * gtk_scrolled_window_get_placement().
897 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
899 GtkScrolledWindowPrivate *priv;
901 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
903 priv = scrolled_window->priv;
905 if (priv->window_placement_set)
907 priv->window_placement_set = FALSE;
909 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
911 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
916 * gtk_scrolled_window_set_shadow_type:
917 * @scrolled_window: a #GtkScrolledWindow
918 * @type: kind of shadow to draw around scrolled window contents
920 * Changes the type of shadow drawn around the contents of
925 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
928 GtkScrolledWindowPrivate *priv;
930 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
931 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
933 priv = scrolled_window->priv;
935 if (priv->shadow_type != type)
937 priv->shadow_type = type;
939 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
940 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
942 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
944 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
949 * gtk_scrolled_window_get_shadow_type:
950 * @scrolled_window: a #GtkScrolledWindow
952 * Gets the shadow type of the scrolled window. See
953 * gtk_scrolled_window_set_shadow_type().
955 * Return value: the current shadow type
958 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
960 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
962 return scrolled_window->priv->shadow_type;
966 gtk_scrolled_window_destroy (GtkWidget *widget)
968 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
969 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
971 if (priv->hscrollbar)
973 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
974 gtk_scrolled_window_adjustment_changed,
976 gtk_widget_unparent (priv->hscrollbar);
977 gtk_widget_destroy (priv->hscrollbar);
978 g_object_unref (priv->hscrollbar);
979 priv->hscrollbar = NULL;
981 if (priv->vscrollbar)
983 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
984 gtk_scrolled_window_adjustment_changed,
986 gtk_widget_unparent (priv->vscrollbar);
987 gtk_widget_destroy (priv->vscrollbar);
988 g_object_unref (priv->vscrollbar);
989 priv->vscrollbar = NULL;
992 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
996 gtk_scrolled_window_set_property (GObject *object,
1001 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1002 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1006 case PROP_HADJUSTMENT:
1007 gtk_scrolled_window_set_hadjustment (scrolled_window,
1008 g_value_get_object (value));
1010 case PROP_VADJUSTMENT:
1011 gtk_scrolled_window_set_vadjustment (scrolled_window,
1012 g_value_get_object (value));
1014 case PROP_HSCROLLBAR_POLICY:
1015 gtk_scrolled_window_set_policy (scrolled_window,
1016 g_value_get_enum (value),
1017 priv->vscrollbar_policy);
1019 case PROP_VSCROLLBAR_POLICY:
1020 gtk_scrolled_window_set_policy (scrolled_window,
1021 priv->hscrollbar_policy,
1022 g_value_get_enum (value));
1024 case PROP_WINDOW_PLACEMENT:
1025 gtk_scrolled_window_set_placement_internal (scrolled_window,
1026 g_value_get_enum (value));
1028 case PROP_WINDOW_PLACEMENT_SET:
1029 gtk_scrolled_window_set_placement_set (scrolled_window,
1030 g_value_get_boolean (value),
1033 case PROP_SHADOW_TYPE:
1034 gtk_scrolled_window_set_shadow_type (scrolled_window,
1035 g_value_get_enum (value));
1038 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1044 gtk_scrolled_window_get_property (GObject *object,
1049 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1050 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1054 case PROP_HADJUSTMENT:
1055 g_value_set_object (value,
1056 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1058 case PROP_VADJUSTMENT:
1059 g_value_set_object (value,
1060 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1062 case PROP_HSCROLLBAR_POLICY:
1063 g_value_set_enum (value, priv->hscrollbar_policy);
1065 case PROP_VSCROLLBAR_POLICY:
1066 g_value_set_enum (value, priv->vscrollbar_policy);
1068 case PROP_WINDOW_PLACEMENT:
1069 g_value_set_enum (value, priv->window_placement);
1071 case PROP_WINDOW_PLACEMENT_SET:
1072 g_value_set_boolean (value, priv->window_placement_set);
1074 case PROP_SHADOW_TYPE:
1075 g_value_set_enum (value, priv->shadow_type);
1078 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1084 traverse_container (GtkWidget *widget,
1087 if (GTK_IS_SCROLLED_WINDOW (widget))
1089 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1090 gtk_widget_queue_resize (widget);
1092 else if (GTK_IS_CONTAINER (widget))
1093 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1097 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1101 list = gtk_window_list_toplevels ();
1103 for (l = list; l; l = l->next)
1104 gtk_container_forall (GTK_CONTAINER (l->data),
1105 traverse_container, NULL);
1111 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1112 GdkScreen *previous_screen)
1114 GtkSettings *settings;
1115 guint window_placement_connection;
1117 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1119 if (!gtk_widget_has_screen (widget))
1122 settings = gtk_widget_get_settings (widget);
1124 window_placement_connection =
1125 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1126 "gtk-scrolled-window-connection"));
1128 if (window_placement_connection)
1131 window_placement_connection =
1132 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1133 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1134 g_object_set_data (G_OBJECT (settings),
1135 I_("gtk-scrolled-window-connection"),
1136 GUINT_TO_POINTER (window_placement_connection));
1140 gtk_scrolled_window_draw (GtkWidget *widget,
1143 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1144 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1146 if (priv->shadow_type != GTK_SHADOW_NONE)
1148 GtkAllocation relative_allocation;
1150 gboolean scrollbars_within_bevel;
1152 style = gtk_widget_get_style (widget);
1153 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1155 if (!scrollbars_within_bevel)
1157 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1159 relative_allocation.x -= style->xthickness;
1160 relative_allocation.y -= style->ythickness;
1161 relative_allocation.width += 2 * style->xthickness;
1162 relative_allocation.height += 2 * style->ythickness;
1166 relative_allocation.x = 0;
1167 relative_allocation.y = 0;
1168 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1169 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1172 gtk_paint_shadow (style,
1174 GTK_STATE_NORMAL, priv->shadow_type,
1175 widget, "scrolled_window",
1176 relative_allocation.x,
1177 relative_allocation.y,
1178 relative_allocation.width,
1179 relative_allocation.height);
1182 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1188 gtk_scrolled_window_forall (GtkContainer *container,
1189 gboolean include_internals,
1190 GtkCallback callback,
1191 gpointer callback_data)
1193 GtkScrolledWindowPrivate *priv;
1194 GtkScrolledWindow *scrolled_window;
1196 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1197 g_return_if_fail (callback != NULL);
1199 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1203 if (include_internals)
1205 scrolled_window = GTK_SCROLLED_WINDOW (container);
1206 priv = scrolled_window->priv;
1208 if (priv->vscrollbar)
1209 callback (priv->vscrollbar, callback_data);
1210 if (priv->hscrollbar)
1211 callback (priv->hscrollbar, callback_data);
1216 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1217 GtkScrollType scroll,
1218 gboolean horizontal)
1220 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1221 GtkAdjustment *adjustment = NULL;
1225 case GTK_SCROLL_STEP_UP:
1226 scroll = GTK_SCROLL_STEP_BACKWARD;
1229 case GTK_SCROLL_STEP_DOWN:
1230 scroll = GTK_SCROLL_STEP_FORWARD;
1233 case GTK_SCROLL_STEP_LEFT:
1234 scroll = GTK_SCROLL_STEP_BACKWARD;
1237 case GTK_SCROLL_STEP_RIGHT:
1238 scroll = GTK_SCROLL_STEP_FORWARD;
1241 case GTK_SCROLL_PAGE_UP:
1242 scroll = GTK_SCROLL_PAGE_BACKWARD;
1245 case GTK_SCROLL_PAGE_DOWN:
1246 scroll = GTK_SCROLL_PAGE_FORWARD;
1249 case GTK_SCROLL_PAGE_LEFT:
1250 scroll = GTK_SCROLL_STEP_BACKWARD;
1253 case GTK_SCROLL_PAGE_RIGHT:
1254 scroll = GTK_SCROLL_STEP_FORWARD;
1257 case GTK_SCROLL_STEP_BACKWARD:
1258 case GTK_SCROLL_STEP_FORWARD:
1259 case GTK_SCROLL_PAGE_BACKWARD:
1260 case GTK_SCROLL_PAGE_FORWARD:
1261 case GTK_SCROLL_START:
1262 case GTK_SCROLL_END:
1265 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1269 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1270 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1275 if (priv->hscrollbar)
1276 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1280 if (priv->vscrollbar)
1281 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1286 gdouble value = adjustment->value;
1290 case GTK_SCROLL_STEP_FORWARD:
1291 value += adjustment->step_increment;
1293 case GTK_SCROLL_STEP_BACKWARD:
1294 value -= adjustment->step_increment;
1296 case GTK_SCROLL_PAGE_FORWARD:
1297 value += adjustment->page_increment;
1299 case GTK_SCROLL_PAGE_BACKWARD:
1300 value -= adjustment->page_increment;
1302 case GTK_SCROLL_START:
1303 value = adjustment->lower;
1305 case GTK_SCROLL_END:
1306 value = adjustment->upper;
1309 g_assert_not_reached ();
1313 gtk_adjustment_set_value (adjustment, value);
1322 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1323 GtkDirectionType direction_type)
1325 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1326 GtkWidget *toplevel;
1328 /* Focus out of the scrolled window entirely. We do this by setting
1329 * a flag, then propagating the focus motion to the notebook.
1331 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1332 if (!gtk_widget_is_toplevel (toplevel))
1335 g_object_ref (scrolled_window);
1337 priv->focus_out = TRUE;
1338 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1339 priv->focus_out = FALSE;
1341 g_object_unref (scrolled_window);
1345 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1346 GtkAllocation *allocation)
1348 GtkAllocation widget_allocation;
1349 GtkScrolledWindow *scrolled_window;
1350 GtkScrolledWindowPrivate *priv;
1356 g_return_if_fail (widget != NULL);
1357 g_return_if_fail (allocation != NULL);
1359 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1360 priv = scrolled_window->priv;
1362 /* Get possible scrollbar dimensions */
1363 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1364 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1365 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1367 /* Subtract some things from our available allocation size */
1371 if (priv->shadow_type != GTK_SHADOW_NONE)
1373 style = gtk_widget_get_style (widget);
1374 allocation->x += style->xthickness;
1375 allocation->y += style->ythickness;
1378 gtk_widget_get_allocation (widget, &widget_allocation);
1379 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1380 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1382 if (priv->vscrollbar_visible)
1386 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1389 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1390 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1392 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1393 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1394 allocation->x += (sb_width + sb_spacing);
1396 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1398 if (priv->hscrollbar_visible)
1401 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1402 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1403 allocation->y += (sb_height + sb_spacing);
1405 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1410 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1411 GtkAllocation *allocation)
1413 GtkScrolledWindow *scrolled_window;
1414 GtkScrolledWindowPrivate *priv;
1417 GtkAllocation relative_allocation;
1418 GtkAllocation child_allocation;
1420 gboolean scrollbars_within_bevel;
1427 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1428 g_return_if_fail (allocation != NULL);
1430 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1431 bin = GTK_BIN (scrolled_window);
1432 priv = scrolled_window->priv;
1434 /* Get possible scrollbar dimensions */
1435 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1436 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1437 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1439 style = gtk_widget_get_style (widget);
1440 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1442 gtk_widget_set_allocation (widget, allocation);
1444 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1445 priv->hscrollbar_visible = TRUE;
1446 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1447 priv->hscrollbar_visible = FALSE;
1448 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1449 priv->vscrollbar_visible = TRUE;
1450 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1451 priv->vscrollbar_visible = FALSE;
1453 child = gtk_bin_get_child (bin);
1454 if (child && gtk_widget_get_visible (child))
1456 gint child_min_width;
1457 gint child_min_height;
1458 gboolean previous_hvis;
1459 gboolean previous_vvis;
1462 /* In the case that both scrollbars are visible in the previous round,
1463 * we dont do our guess-work before hand because it's possible some
1464 * infinite recursion was detected (leave it up to the child scrollable
1465 * widget in this case to drive the scrollbar visibility completely
1466 * with the adjustment values).
1468 if (!priv->vscrollbar_visible || !priv->hscrollbar_visible)
1471 /* Determine scrollbar visibility first via hfw apis */
1472 if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1474 gtk_widget_get_preferred_width (child, &child_min_width, NULL);
1476 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1478 /* First try without a vertical scrollbar if the content will fit the height
1479 * given the extra width of the scrollbar */
1480 gtk_widget_get_preferred_height_for_width (child, allocation->width,
1481 &child_min_height, NULL);
1483 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1485 /* Does the content height fit the allocation height ? */
1486 priv->vscrollbar_visible = child_min_height > allocation->height;
1488 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1489 priv->hscrollbar_visible =
1490 child_min_width > allocation->width -
1491 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1493 /* Now that we've guessed the hscrollbar, does the content height fit
1494 * the possible new allocation height ? */
1495 priv->vscrollbar_visible =
1496 child_min_height > allocation->height -
1497 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1499 /* Now that we've guessed the vscrollbar, does the content width fit
1500 * the possible new allocation width ? */
1501 priv->hscrollbar_visible =
1502 child_min_width > allocation->width -
1503 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1505 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1507 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1508 priv->vscrollbar_visible = child_min_height > allocation->height -
1509 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1512 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1514 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1516 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1517 priv->hscrollbar_visible =
1518 child_min_width > allocation->width -
1519 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1521 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1524 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1526 gtk_widget_get_preferred_height (child, &child_min_height, NULL);
1528 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1530 /* First try without a horizontal scrollbar if the content will fit the width
1531 * given the extra height of the scrollbar */
1532 gtk_widget_get_preferred_width_for_height (child, allocation->height,
1533 &child_min_width, NULL);
1535 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1537 /* Does the content width fit the allocation width ? */
1538 priv->hscrollbar_visible = child_min_width > allocation->width;
1540 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1541 priv->vscrollbar_visible =
1542 child_min_height > allocation->height -
1543 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1545 /* Now that we've guessed the vscrollbar, does the content width fit
1546 * the possible new allocation width ? */
1547 priv->hscrollbar_visible =
1548 child_min_width > allocation->width -
1549 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1551 /* Now that we've guessed the hscrollbar, does the content height fit
1552 * the possible new allocation height ? */
1553 priv->vscrollbar_visible =
1554 child_min_height > allocation->height -
1555 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1557 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1559 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1560 priv->hscrollbar_visible = child_min_width > allocation->width -
1561 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1564 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1566 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1568 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1569 priv->vscrollbar_visible =
1570 child_min_height > allocation->height -
1571 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1573 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1578 /* Now after guessing scrollbar visibility; fall back on the allocation loop which
1579 * observes the adjustments to detect scrollbar visibility and also avoids
1580 * infinite recursion
1584 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1586 child_allocation.x = relative_allocation.x + allocation->x;
1587 child_allocation.y = relative_allocation.y + allocation->y;
1588 child_allocation.width = relative_allocation.width;
1589 child_allocation.height = relative_allocation.height;
1591 previous_hvis = priv->hscrollbar_visible;
1592 previous_vvis = priv->vscrollbar_visible;
1594 gtk_widget_size_allocate (child, &child_allocation);
1596 /* If, after the first iteration, the hscrollbar and the
1597 * vscrollbar flip visiblity, then we need both.
1600 previous_hvis != priv->hscrollbar_visible &&
1601 previous_vvis != priv->vscrollbar_visible)
1603 priv->hscrollbar_visible = TRUE;
1604 priv->vscrollbar_visible = TRUE;
1606 /* a new resize is already queued at this point,
1607 * so we will immediatedly get reinvoked
1614 while (previous_hvis != priv->hscrollbar_visible ||
1615 previous_vvis != priv->vscrollbar_visible);
1619 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1620 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1621 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1624 if (priv->hscrollbar_visible)
1626 if (!gtk_widget_get_visible (priv->hscrollbar))
1627 gtk_widget_show (priv->hscrollbar);
1629 child_allocation.x = relative_allocation.x;
1630 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1631 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1632 child_allocation.y = (relative_allocation.y +
1633 relative_allocation.height +
1635 (priv->shadow_type == GTK_SHADOW_NONE ?
1636 0 : style->ythickness));
1638 child_allocation.y = 0;
1640 child_allocation.width = relative_allocation.width;
1641 child_allocation.height = sb_height;
1642 child_allocation.x += allocation->x;
1643 child_allocation.y += allocation->y;
1645 if (priv->shadow_type != GTK_SHADOW_NONE)
1647 if (!scrollbars_within_bevel)
1649 child_allocation.x -= style->xthickness;
1650 child_allocation.width += 2 * style->xthickness;
1652 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1653 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1655 child_allocation.y -= style->ythickness;
1659 child_allocation.y += style->ythickness;
1663 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1665 else if (gtk_widget_get_visible (priv->hscrollbar))
1666 gtk_widget_hide (priv->hscrollbar);
1668 if (priv->vscrollbar_visible)
1670 if (!gtk_widget_get_visible (priv->vscrollbar))
1671 gtk_widget_show (priv->vscrollbar);
1673 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1674 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1675 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1676 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1677 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1678 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1679 child_allocation.x = (relative_allocation.x +
1680 relative_allocation.width +
1682 (priv->shadow_type == GTK_SHADOW_NONE ?
1683 0 : style->xthickness));
1685 child_allocation.x = 0;
1687 child_allocation.y = relative_allocation.y;
1688 child_allocation.width = sb_width;
1689 child_allocation.height = relative_allocation.height;
1690 child_allocation.x += allocation->x;
1691 child_allocation.y += allocation->y;
1693 if (priv->shadow_type != GTK_SHADOW_NONE)
1695 if (!scrollbars_within_bevel)
1697 child_allocation.y -= style->ythickness;
1698 child_allocation.height += 2 * style->ythickness;
1700 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1701 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1703 child_allocation.x -= style->xthickness;
1707 child_allocation.x += style->xthickness;
1711 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1713 else if (gtk_widget_get_visible (priv->vscrollbar))
1714 gtk_widget_hide (priv->vscrollbar);
1718 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1719 GdkEventScroll *event)
1721 GtkScrolledWindowPrivate *priv;
1722 GtkScrolledWindow *scrolled_window;
1725 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1726 g_return_val_if_fail (event != NULL, FALSE);
1728 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1729 priv = scrolled_window->priv;
1731 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1732 range = priv->vscrollbar;
1734 range = priv->hscrollbar;
1736 if (range && gtk_widget_get_visible (range))
1738 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1741 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1743 gtk_adjustment_set_value (adj, adj->value + delta);
1752 gtk_scrolled_window_focus (GtkWidget *widget,
1753 GtkDirectionType direction)
1755 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1756 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1758 gboolean had_focus_child;
1760 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1762 if (priv->focus_out)
1764 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1768 if (gtk_widget_is_focus (widget))
1771 /* We only put the scrolled window itself in the focus chain if it
1772 * isn't possible to focus any children.
1774 child = gtk_bin_get_child (GTK_BIN (widget));
1777 if (gtk_widget_child_focus (child, direction))
1781 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1783 gtk_widget_grab_focus (widget);
1791 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1794 GtkScrolledWindowPrivate *priv;;
1795 GtkScrolledWindow *scrolled_window;
1797 g_return_if_fail (adjustment != NULL);
1798 g_return_if_fail (data != NULL);
1800 scrolled_window = GTK_SCROLLED_WINDOW (data);
1801 priv = scrolled_window->priv;
1803 if (priv->hscrollbar &&
1804 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1806 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1810 visible = priv->hscrollbar_visible;
1811 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1812 adjustment->page_size);
1813 if (priv->hscrollbar_visible != visible)
1814 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1817 else if (priv->vscrollbar &&
1818 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1820 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1824 visible = priv->vscrollbar_visible;
1825 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1826 adjustment->page_size);
1827 if (priv->vscrollbar_visible != visible)
1828 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1834 gtk_scrolled_window_add (GtkContainer *container,
1837 GtkScrolledWindowPrivate *priv;
1838 GtkScrolledWindow *scrolled_window;
1840 GtkWidget *child_widget;
1842 bin = GTK_BIN (container);
1843 child_widget = gtk_bin_get_child (bin);
1844 g_return_if_fail (child_widget == NULL);
1846 scrolled_window = GTK_SCROLLED_WINDOW (container);
1847 priv = scrolled_window->priv;
1849 _gtk_bin_set_child (bin, child);
1850 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1852 /* this is a temporary message */
1853 if (!gtk_widget_set_scroll_adjustments (child,
1854 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
1855 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))))
1856 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1857 "use gtk_scrolled_window_add_with_viewport() instead");
1861 gtk_scrolled_window_remove (GtkContainer *container,
1864 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1865 g_return_if_fail (child != NULL);
1866 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1868 gtk_widget_set_scroll_adjustments (child, NULL, NULL);
1870 /* chain parent class handler to remove child */
1871 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1875 * gtk_scrolled_window_add_with_viewport:
1876 * @scrolled_window: a #GtkScrolledWindow
1877 * @child: the widget you want to scroll
1879 * Used to add children without native scrolling capabilities. This
1880 * is simply a convenience function; it is equivalent to adding the
1881 * unscrollable child to a viewport, then adding the viewport to the
1882 * scrolled window. If a child has native scrolling, use
1883 * gtk_container_add() instead of this function.
1885 * The viewport scrolls the child by moving its #GdkWindow, and takes
1886 * the size of the child to be the size of its toplevel #GdkWindow.
1887 * This will be very wrong for most widgets that support native scrolling;
1888 * for example, if you add a widget such as #GtkTreeView with a viewport,
1889 * the whole widget will scroll, including the column headings. Thus,
1890 * widgets with native scrolling support should not be used with the
1891 * #GtkViewport proxy.
1893 * A widget supports scrolling natively if the
1894 * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
1895 * i.e. has been filled in with a valid signal identifier.
1898 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1902 GtkWidget *viewport;
1903 GtkWidget *child_widget;
1905 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1906 g_return_if_fail (GTK_IS_WIDGET (child));
1907 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1909 bin = GTK_BIN (scrolled_window);
1910 child_widget = gtk_bin_get_child (bin);
1914 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1915 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1917 viewport = child_widget;
1922 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1923 gtk_scrolled_window_get_vadjustment (scrolled_window));
1924 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1927 gtk_widget_show (viewport);
1928 gtk_container_add (GTK_CONTAINER (viewport), child);
1932 * _gtk_scrolled_window_get_spacing:
1933 * @scrolled_window: a scrolled window
1935 * Gets the spacing between the scrolled window's scrollbars and
1936 * the scrolled widget. Used by GtkCombo
1938 * Return value: the spacing, in pixels.
1941 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
1943 GtkScrolledWindowClass *class;
1945 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
1947 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
1949 if (class->scrollbar_spacing >= 0)
1950 return class->scrollbar_spacing;
1953 gint scrollbar_spacing;
1955 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
1956 "scrollbar-spacing", &scrollbar_spacing,
1959 return scrollbar_spacing;
1965 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
1966 GtkOrientation orientation,
1970 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1971 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1972 GtkBin *bin = GTK_BIN (scrolled_window);
1975 gint scrollbar_spacing;
1976 GtkRequisition hscrollbar_requisition;
1977 GtkRequisition vscrollbar_requisition;
1978 GtkRequisition minimum_req, natural_req;
1981 gint min_child_size, nat_child_size;
1983 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1987 minimum_req.width = 0;
1988 minimum_req.height = 0;
1989 natural_req.width = 0;
1990 natural_req.height = 0;
1992 gtk_widget_get_preferred_size (priv->hscrollbar,
1993 &hscrollbar_requisition, NULL);
1994 gtk_widget_get_preferred_size (priv->vscrollbar,
1995 &vscrollbar_requisition, NULL);
1997 child = gtk_bin_get_child (bin);
1998 if (child && gtk_widget_get_visible (child))
2000 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2002 gtk_widget_get_preferred_width (child,
2006 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2008 minimum_req.width += min_child_size;
2009 natural_req.width += nat_child_size;
2013 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
2015 if (aux_info && aux_info->width > 0)
2017 minimum_req.width += aux_info->width;
2018 natural_req.width += aux_info->width;
2023 minimum_req.width += vscrollbar_requisition.width;
2024 natural_req.width += vscrollbar_requisition.width;
2028 else /* GTK_ORIENTATION_VERTICAL */
2030 gtk_widget_get_preferred_height (child,
2034 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2036 minimum_req.height += min_child_size;
2037 natural_req.height += nat_child_size;
2041 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
2043 if (aux_info && aux_info->height > 0)
2045 minimum_req.height += aux_info->height;
2046 natural_req.height += aux_info->height;
2051 minimum_req.height += hscrollbar_requisition.height;
2052 natural_req.height += hscrollbar_requisition.height;
2058 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2059 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2061 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2062 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2063 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2064 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2067 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2068 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2070 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2071 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2072 if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2073 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2076 minimum_req.width += MAX (0, extra_width);
2077 minimum_req.height += MAX (0, extra_height);
2078 natural_req.width += MAX (0, extra_width);
2079 natural_req.height += MAX (0, extra_height);
2081 if (priv->shadow_type != GTK_SHADOW_NONE)
2083 style = gtk_widget_get_style (GTK_WIDGET (widget));
2084 minimum_req.width += 2 * style->xthickness;
2085 minimum_req.height += 2 * style->ythickness;
2086 natural_req.width += 2 * style->xthickness;
2087 natural_req.height += 2 * style->ythickness;
2090 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2093 *minimum_size = minimum_req.width;
2095 *natural_size = natural_req.width;
2100 *minimum_size = minimum_req.height;
2102 *natural_size = natural_req.height;
2107 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2111 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2115 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2119 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2123 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2125 gint *minimum_height,
2126 gint *natural_height)
2128 g_return_if_fail (GTK_IS_WIDGET (widget));
2130 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2134 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2136 gint *minimum_width,
2137 gint *natural_width)
2139 g_return_if_fail (GTK_IS_WIDGET (widget));
2141 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);