1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include <gdk/gdkkeysyms.h>
30 #include "gtkbindings.h"
31 #include "gtkmarshalers.h"
32 #include "gtkscrollable.h"
33 #include "gtkscrolledwindow.h"
34 #include "gtkwindow.h"
35 #include "gtktypeutils.h"
36 #include "gtkprivate.h"
41 * SECTION:gtkscrolledwindow
42 * @Short_description: Adds scrollbars to its child widget
43 * @Title: GtkScrolledWindow
44 * @See_also: #GtkScrollable, #GtkViewport, #GtkAdjustment
46 * #GtkScrolledWindow is a #GtkBin subclass: it's a container
47 * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
48 * to the child widget and optionally draws a beveled frame around the
51 * The scrolled window can work in two ways. Some widgets have native
52 * scrolling support; these widgets implement the #GtkScrollable interface.
53 * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
56 * For widgets that lack native scrolling support, the #GtkViewport
57 * widget acts as an adaptor class, implementing scrollability for child
58 * widgets that lack their own scrolling capabilities. Use #GtkViewport
59 * to scroll child widgets such as #GtkTable, #GtkBox, and so on.
61 * If a widget has native scrolling abilities, it can be added to the
62 * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
63 * must first add the widget to a #GtkViewport, then add the #GtkViewport
64 * to the scrolled window. The convenience function
65 * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
66 * ignore the presence of the viewport.
68 * The position of the scrollbars is controlled by the scroll
69 * adjustments. See #GtkAdjustment for the fields in an adjustment - for
70 * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
71 * represents the position of the scrollbar, which must be between the
72 * "lower" field and "upper - page_size." The "page_size" field
73 * represents the size of the visible scrollable area. The
74 * "step_increment" and "page_increment" fields are used when the user
75 * asks to step down (using the small stepper arrows) or page down (using
76 * for example the PageDown key).
78 * If a #GtkScrolledWindow doesn't behave quite as you would like, or
79 * doesn't have exactly the right layout, it's very possible to set up
80 * your own scrolling with #GtkScrollbar and for example a #GtkTable.
84 /* scrolled window policy and size requisition handling:
86 * gtk size requisition works as follows:
87 * a widget upon size-request reports the width and height that it finds
88 * to be best suited to display its contents, including children.
89 * the width and/or height reported from a widget upon size requisition
90 * may be overidden by the user by specifying a width and/or height
91 * other than 0 through gtk_widget_set_size_request().
93 * a scrolled window needs (for implementing all three policy types) to
94 * request its width and height based on two different rationales.
95 * 1) the user wants the scrolled window to just fit into the space
96 * that it gets allocated for a specifc dimension.
97 * 1.1) this does not apply if the user specified a concrete value
98 * value for that specific dimension by either specifying usize for the
99 * scrolled window or for its child.
100 * 2) the user wants the scrolled window to take as much space up as
101 * is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
103 * also, kinda obvious:
104 * 3) a user would certainly not have choosen a scrolled window as a container
105 * for the child, if the resulting allocation takes up more space than the
106 * child would have allocated without the scrolled window.
109 * A) from 1) follows: the scrolled window shouldn't request more space for a
110 * specifc dimension than is required at minimum.
111 * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
112 * window (done automatically) or by usize of the child (needs to be checked).
113 * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
115 * D) from 3) follows: the scrolled window child's minimum width and minimum height
116 * under A) at least correspond to the space taken up by its scrollbars.
119 #define DEFAULT_SCROLLBAR_SPACING 3
121 struct _GtkScrolledWindowPrivate
123 GtkCornerType real_window_placement;
124 GtkWidget *hscrollbar;
125 GtkWidget *vscrollbar;
127 gboolean window_placement_set;
131 guint hscrollbar_policy : 2;
132 guint vscrollbar_policy : 2;
133 guint hscrollbar_visible : 1;
134 guint vscrollbar_visible : 1;
135 guint window_placement : 2;
136 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
138 gint min_content_width;
139 gint min_content_height;
147 PROP_HSCROLLBAR_POLICY,
148 PROP_VSCROLLBAR_POLICY,
149 PROP_WINDOW_PLACEMENT,
150 PROP_WINDOW_PLACEMENT_SET,
152 PROP_MIN_CONTENT_WIDTH,
153 PROP_MIN_CONTENT_HEIGHT
164 static void gtk_scrolled_window_set_property (GObject *object,
168 static void gtk_scrolled_window_get_property (GObject *object,
173 static void gtk_scrolled_window_destroy (GtkWidget *widget);
174 static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
175 GdkScreen *previous_screen);
176 static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
178 static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
179 GtkAllocation *allocation);
180 static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
181 GdkEventScroll *event);
182 static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
183 GtkDirectionType direction);
184 static void gtk_scrolled_window_add (GtkContainer *container,
186 static void gtk_scrolled_window_remove (GtkContainer *container,
188 static void gtk_scrolled_window_forall (GtkContainer *container,
189 gboolean include_internals,
190 GtkCallback callback,
191 gpointer callback_data);
192 static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
193 GtkScrollType scroll,
194 gboolean horizontal);
195 static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
196 GtkDirectionType direction_type);
198 static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
199 GtkAllocation *allocation);
200 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
203 static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
205 static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
208 static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
211 static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
213 gint *minimum_height,
214 gint *natural_height);
215 static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
217 gint *minimum_height,
218 gint *natural_height);
220 static guint signals[LAST_SIGNAL] = {0};
222 G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
226 add_scroll_binding (GtkBindingSet *binding_set,
228 GdkModifierType mask,
229 GtkScrollType scroll,
232 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
234 gtk_binding_entry_add_signal (binding_set, keyval, mask,
236 GTK_TYPE_SCROLL_TYPE, scroll,
237 G_TYPE_BOOLEAN, horizontal);
238 gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
240 GTK_TYPE_SCROLL_TYPE, scroll,
241 G_TYPE_BOOLEAN, horizontal);
245 add_tab_bindings (GtkBindingSet *binding_set,
246 GdkModifierType modifiers,
247 GtkDirectionType direction)
249 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
251 GTK_TYPE_DIRECTION_TYPE, direction);
252 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
254 GTK_TYPE_DIRECTION_TYPE, direction);
258 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
260 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
261 GtkWidgetClass *widget_class;
262 GtkContainerClass *container_class;
263 GtkBindingSet *binding_set;
265 widget_class = (GtkWidgetClass*) class;
266 container_class = (GtkContainerClass*) class;
268 gobject_class->set_property = gtk_scrolled_window_set_property;
269 gobject_class->get_property = gtk_scrolled_window_get_property;
271 widget_class->destroy = gtk_scrolled_window_destroy;
272 widget_class->screen_changed = gtk_scrolled_window_screen_changed;
273 widget_class->draw = gtk_scrolled_window_draw;
274 widget_class->size_allocate = gtk_scrolled_window_size_allocate;
275 widget_class->scroll_event = gtk_scrolled_window_scroll_event;
276 widget_class->focus = gtk_scrolled_window_focus;
277 widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
278 widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
279 widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
280 widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
282 container_class->add = gtk_scrolled_window_add;
283 container_class->remove = gtk_scrolled_window_remove;
284 container_class->forall = gtk_scrolled_window_forall;
285 gtk_container_class_handle_border_width (container_class);
287 class->scrollbar_spacing = -1;
289 class->scroll_child = gtk_scrolled_window_scroll_child;
290 class->move_focus_out = gtk_scrolled_window_move_focus_out;
292 g_object_class_install_property (gobject_class,
294 g_param_spec_object ("hadjustment",
295 P_("Horizontal Adjustment"),
296 P_("The GtkAdjustment for the horizontal position"),
298 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
299 g_object_class_install_property (gobject_class,
301 g_param_spec_object ("vadjustment",
302 P_("Vertical Adjustment"),
303 P_("The GtkAdjustment for the vertical position"),
305 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
306 g_object_class_install_property (gobject_class,
307 PROP_HSCROLLBAR_POLICY,
308 g_param_spec_enum ("hscrollbar-policy",
309 P_("Horizontal Scrollbar Policy"),
310 P_("When the horizontal scrollbar is displayed"),
311 GTK_TYPE_POLICY_TYPE,
312 GTK_POLICY_AUTOMATIC,
313 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
314 g_object_class_install_property (gobject_class,
315 PROP_VSCROLLBAR_POLICY,
316 g_param_spec_enum ("vscrollbar-policy",
317 P_("Vertical Scrollbar Policy"),
318 P_("When the vertical scrollbar is displayed"),
319 GTK_TYPE_POLICY_TYPE,
320 GTK_POLICY_AUTOMATIC,
321 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
323 g_object_class_install_property (gobject_class,
324 PROP_WINDOW_PLACEMENT,
325 g_param_spec_enum ("window-placement",
326 P_("Window Placement"),
327 P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
328 GTK_TYPE_CORNER_TYPE,
330 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
333 * GtkScrolledWindow:window-placement-set:
335 * Whether "window-placement" should be used to determine the location
336 * of the contents with respect to the scrollbars. Otherwise, the
337 * "gtk-scrolled-window-placement" setting is used.
341 g_object_class_install_property (gobject_class,
342 PROP_WINDOW_PLACEMENT_SET,
343 g_param_spec_boolean ("window-placement-set",
344 P_("Window Placement Set"),
345 P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
347 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
348 g_object_class_install_property (gobject_class,
350 g_param_spec_enum ("shadow-type",
352 P_("Style of bevel around the contents"),
353 GTK_TYPE_SHADOW_TYPE,
355 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
358 * GtkScrolledWindow:scrollbars-within-bevel:
360 * Whether to place scrollbars within the scrolled window's bevel.
364 gtk_widget_class_install_style_property (widget_class,
365 g_param_spec_boolean ("scrollbars-within-bevel",
366 P_("Scrollbars within bevel"),
367 P_("Place scrollbars within the scrolled window's bevel"),
369 GTK_PARAM_READABLE));
371 gtk_widget_class_install_style_property (widget_class,
372 g_param_spec_int ("scrollbar-spacing",
373 P_("Scrollbar spacing"),
374 P_("Number of pixels between the scrollbars and the scrolled window"),
377 DEFAULT_SCROLLBAR_SPACING,
378 GTK_PARAM_READABLE));
380 g_object_class_install_property (gobject_class,
381 PROP_MIN_CONTENT_WIDTH,
382 g_param_spec_int ("min-content-width",
383 P_("Minimum Content Width"),
384 P_("The minimum width that the scrolled window will allocate to its content"),
386 GTK_PARAM_READWRITE));
387 g_object_class_install_property (gobject_class,
388 PROP_MIN_CONTENT_HEIGHT,
389 g_param_spec_int ("min-content-height",
390 P_("Minimum Content Height"),
391 P_("The minimum height that the scrolled window will allocate to its content"),
393 GTK_PARAM_READWRITE));
395 * GtkScrolledWindow::scroll-child:
396 * @scrolled_window: a #GtkScrolledWindow
397 * @scroll: a #GtkScrollType describing how much to scroll
398 * @horizontal: whether the keybinding scrolls the child
399 * horizontally or not
401 * The ::scroll-child signal is a
402 * <link linkend="keybinding-signals">keybinding signal</link>
403 * which gets emitted when a keybinding that scrolls is pressed.
404 * The horizontal or vertical adjustment is updated which triggers a
405 * signal that the scrolled windows child may listen to and scroll itself.
407 signals[SCROLL_CHILD] =
408 g_signal_new (I_("scroll-child"),
409 G_TYPE_FROM_CLASS (gobject_class),
410 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
411 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
413 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
415 GTK_TYPE_SCROLL_TYPE,
419 * GtkScrolledWindow::move-focus-out:
420 * @scrolled_window: a #GtkScrolledWindow
421 * @direction_type: either %GTK_DIR_TAB_FORWARD or
422 * %GTK_DIR_TAB_BACKWARD
424 * The ::move-focus-out signal is a
425 * <link linkend="keybinding-signals">keybinding signal</link>
426 * which gets emitted when focus is moved away from the scrolled
427 * window by a keybinding.
428 * The #GtkWidget::move-focus signal is emitted with @direction_type
429 * on this scrolled windows toplevel parent in the container hierarchy.
430 * The default bindings for this signal are
431 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
433 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
435 signals[MOVE_FOCUS_OUT] =
436 g_signal_new (I_("move-focus-out"),
437 G_TYPE_FROM_CLASS (gobject_class),
438 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
439 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
441 _gtk_marshal_VOID__ENUM,
443 GTK_TYPE_DIRECTION_TYPE);
445 binding_set = gtk_binding_set_by_class (class);
447 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
448 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
449 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
450 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
452 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
453 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
454 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
455 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
457 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
458 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
459 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
460 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
462 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
463 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
465 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
469 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
471 GtkScrolledWindowPrivate *priv;
473 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
474 GTK_TYPE_SCROLLED_WINDOW,
475 GtkScrolledWindowPrivate);
477 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
478 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
480 priv->hscrollbar = NULL;
481 priv->vscrollbar = NULL;
482 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
483 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
484 priv->hscrollbar_visible = FALSE;
485 priv->vscrollbar_visible = FALSE;
486 priv->focus_out = FALSE;
487 priv->window_placement = GTK_CORNER_TOP_LEFT;
488 gtk_scrolled_window_update_real_placement (scrolled_window);
489 priv->min_content_width = -1;
490 priv->min_content_height = -1;
494 * gtk_scrolled_window_new:
495 * @hadjustment: (allow-none): horizontal adjustment
496 * @vadjustment: (allow-none): vertical adjustment
498 * Creates a new scrolled window.
500 * The two arguments are the scrolled window's adjustments; these will be
501 * shared with the scrollbars and the child widget to keep the bars in sync
502 * with the child. Usually you want to pass %NULL for the adjustments, which
503 * will cause the scrolled window to create them for you.
505 * Returns: a new scrolled window
508 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
509 GtkAdjustment *vadjustment)
511 GtkWidget *scrolled_window;
514 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
517 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
519 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
520 "hadjustment", hadjustment,
521 "vadjustment", vadjustment,
524 return scrolled_window;
528 * gtk_scrolled_window_set_hadjustment:
529 * @scrolled_window: a #GtkScrolledWindow
530 * @hadjustment: horizontal scroll adjustment
532 * Sets the #GtkAdjustment for the horizontal scrollbar.
535 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
536 GtkAdjustment *hadjustment)
538 GtkScrolledWindowPrivate *priv;
542 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
544 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
546 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
548 bin = GTK_BIN (scrolled_window);
549 priv = scrolled_window->priv;
551 if (!priv->hscrollbar)
553 gtk_widget_push_composite_child ();
554 priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
555 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
556 gtk_widget_pop_composite_child ();
558 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
559 g_object_ref (priv->hscrollbar);
560 gtk_widget_show (priv->hscrollbar);
564 GtkAdjustment *old_adjustment;
566 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
567 if (old_adjustment == hadjustment)
570 g_signal_handlers_disconnect_by_func (old_adjustment,
571 gtk_scrolled_window_adjustment_changed,
573 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
576 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
577 g_signal_connect (hadjustment,
579 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
581 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
583 child = gtk_bin_get_child (bin);
584 if (GTK_IS_SCROLLABLE (child))
585 gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (child), hadjustment);
587 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
591 * gtk_scrolled_window_set_vadjustment:
592 * @scrolled_window: a #GtkScrolledWindow
593 * @vadjustment: vertical scroll adjustment
595 * Sets the #GtkAdjustment for the vertical scrollbar.
598 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
599 GtkAdjustment *vadjustment)
601 GtkScrolledWindowPrivate *priv;
605 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
607 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
609 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
611 bin = GTK_BIN (scrolled_window);
612 priv = scrolled_window->priv;
614 if (!priv->vscrollbar)
616 gtk_widget_push_composite_child ();
617 priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
618 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
619 gtk_widget_pop_composite_child ();
621 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
622 g_object_ref (priv->vscrollbar);
623 gtk_widget_show (priv->vscrollbar);
627 GtkAdjustment *old_adjustment;
629 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
630 if (old_adjustment == vadjustment)
633 g_signal_handlers_disconnect_by_func (old_adjustment,
634 gtk_scrolled_window_adjustment_changed,
636 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
639 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
640 g_signal_connect (vadjustment,
642 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
644 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
646 child = gtk_bin_get_child (bin);
647 if (GTK_IS_SCROLLABLE (child))
648 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
650 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
654 * gtk_scrolled_window_get_hadjustment:
655 * @scrolled_window: a #GtkScrolledWindow
657 * Returns the horizontal scrollbar's adjustment, used to connect the
658 * horizontal scrollbar to the child widget's horizontal scroll
661 * Returns: (transfer none): the horizontal #GtkAdjustment
664 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
666 GtkScrolledWindowPrivate *priv;
668 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
670 priv = scrolled_window->priv;
672 return (priv->hscrollbar ?
673 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
678 * gtk_scrolled_window_get_vadjustment:
679 * @scrolled_window: a #GtkScrolledWindow
681 * Returns the vertical scrollbar's adjustment, used to connect the
682 * vertical scrollbar to the child widget's vertical scroll functionality.
684 * Returns: (transfer none): the vertical #GtkAdjustment
687 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
689 GtkScrolledWindowPrivate *priv;
691 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
693 priv = scrolled_window->priv;
695 return (priv->vscrollbar ?
696 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
701 * gtk_scrolled_window_get_hscrollbar:
702 * @scrolled_window: a #GtkScrolledWindow
704 * Returns the horizontal scrollbar of @scrolled_window.
706 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
707 * or %NULL if it does not have one.
712 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
714 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
716 return scrolled_window->priv->hscrollbar;
720 * gtk_scrolled_window_get_vscrollbar:
721 * @scrolled_window: a #GtkScrolledWindow
723 * Returns the vertical scrollbar of @scrolled_window.
725 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
726 * or %NULL if it does not have one.
731 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
733 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
735 return scrolled_window->priv->vscrollbar;
739 * gtk_scrolled_window_set_policy:
740 * @scrolled_window: a #GtkScrolledWindow
741 * @hscrollbar_policy: policy for horizontal bar
742 * @vscrollbar_policy: policy for vertical bar
744 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
746 * The policy determines when the scrollbar should appear; it is a value
747 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
748 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
749 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
750 * if needed (that is, if the slider part of the bar would be smaller
751 * than the trough - the display is larger than the page size).
754 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
755 GtkPolicyType hscrollbar_policy,
756 GtkPolicyType vscrollbar_policy)
758 GtkScrolledWindowPrivate *priv;
759 GObject *object = G_OBJECT (scrolled_window);
761 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
763 priv = scrolled_window->priv;
765 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
766 (priv->vscrollbar_policy != vscrollbar_policy))
768 priv->hscrollbar_policy = hscrollbar_policy;
769 priv->vscrollbar_policy = vscrollbar_policy;
771 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
773 g_object_freeze_notify (object);
774 g_object_notify (object, "hscrollbar-policy");
775 g_object_notify (object, "vscrollbar-policy");
776 g_object_thaw_notify (object);
781 * gtk_scrolled_window_get_policy:
782 * @scrolled_window: a #GtkScrolledWindow
783 * @hscrollbar_policy: location to store the policy for the horizontal
784 * scrollbar, or %NULL.
785 * @vscrollbar_policy: location to store the policy for the vertical
786 * scrollbar, or %NULL.
788 * Retrieves the current policy values for the horizontal and vertical
789 * scrollbars. See gtk_scrolled_window_set_policy().
792 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
793 GtkPolicyType *hscrollbar_policy,
794 GtkPolicyType *vscrollbar_policy)
796 GtkScrolledWindowPrivate *priv;
798 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
800 priv = scrolled_window->priv;
802 if (hscrollbar_policy)
803 *hscrollbar_policy = priv->hscrollbar_policy;
804 if (vscrollbar_policy)
805 *vscrollbar_policy = priv->vscrollbar_policy;
809 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
811 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
812 GtkSettings *settings;
814 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
816 if (priv->window_placement_set || settings == NULL)
817 priv->real_window_placement = priv->window_placement;
819 g_object_get (settings,
820 "gtk-scrolled-window-placement",
821 &priv->real_window_placement,
826 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
827 GtkCornerType window_placement)
829 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
831 if (priv->window_placement != window_placement)
833 priv->window_placement = window_placement;
835 gtk_scrolled_window_update_real_placement (scrolled_window);
836 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
838 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
843 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
844 gboolean placement_set,
845 gboolean emit_resize)
847 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
849 if (priv->window_placement_set != placement_set)
851 priv->window_placement_set = placement_set;
853 gtk_scrolled_window_update_real_placement (scrolled_window);
855 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
857 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
862 * gtk_scrolled_window_set_placement:
863 * @scrolled_window: a #GtkScrolledWindow
864 * @window_placement: position of the child window
866 * Sets the placement of the contents with respect to the scrollbars
867 * for the scrolled window.
869 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
870 * in the top left, with the scrollbars underneath and to the right.
871 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
872 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
874 * See also gtk_scrolled_window_get_placement() and
875 * gtk_scrolled_window_unset_placement().
878 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
879 GtkCornerType window_placement)
881 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
883 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
884 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
888 * gtk_scrolled_window_get_placement:
889 * @scrolled_window: a #GtkScrolledWindow
891 * Gets the placement of the contents with respect to the scrollbars
892 * for the scrolled window. See gtk_scrolled_window_set_placement().
894 * Return value: the current placement value.
896 * See also gtk_scrolled_window_set_placement() and
897 * gtk_scrolled_window_unset_placement().
900 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
902 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
904 return scrolled_window->priv->window_placement;
908 * gtk_scrolled_window_unset_placement:
909 * @scrolled_window: a #GtkScrolledWindow
911 * Unsets the placement of the contents with respect to the scrollbars
912 * for the scrolled window. If no window placement is set for a scrolled
913 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
915 * See also gtk_scrolled_window_set_placement() and
916 * gtk_scrolled_window_get_placement().
921 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
923 GtkScrolledWindowPrivate *priv;
925 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
927 priv = scrolled_window->priv;
929 if (priv->window_placement_set)
931 priv->window_placement_set = FALSE;
933 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
935 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
940 * gtk_scrolled_window_set_shadow_type:
941 * @scrolled_window: a #GtkScrolledWindow
942 * @type: kind of shadow to draw around scrolled window contents
944 * Changes the type of shadow drawn around the contents of
949 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
952 GtkScrolledWindowPrivate *priv;
954 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
955 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
957 priv = scrolled_window->priv;
959 if (priv->shadow_type != type)
961 priv->shadow_type = type;
963 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
964 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
966 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
968 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
973 * gtk_scrolled_window_get_shadow_type:
974 * @scrolled_window: a #GtkScrolledWindow
976 * Gets the shadow type of the scrolled window. See
977 * gtk_scrolled_window_set_shadow_type().
979 * Return value: the current shadow type
982 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
984 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
986 return scrolled_window->priv->shadow_type;
990 gtk_scrolled_window_destroy (GtkWidget *widget)
992 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
993 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
995 if (priv->hscrollbar)
997 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
998 gtk_scrolled_window_adjustment_changed,
1000 gtk_widget_unparent (priv->hscrollbar);
1001 gtk_widget_destroy (priv->hscrollbar);
1002 g_object_unref (priv->hscrollbar);
1003 priv->hscrollbar = NULL;
1005 if (priv->vscrollbar)
1007 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
1008 gtk_scrolled_window_adjustment_changed,
1010 gtk_widget_unparent (priv->vscrollbar);
1011 gtk_widget_destroy (priv->vscrollbar);
1012 g_object_unref (priv->vscrollbar);
1013 priv->vscrollbar = NULL;
1016 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
1020 gtk_scrolled_window_set_property (GObject *object,
1022 const GValue *value,
1025 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1026 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1030 case PROP_HADJUSTMENT:
1031 gtk_scrolled_window_set_hadjustment (scrolled_window,
1032 g_value_get_object (value));
1034 case PROP_VADJUSTMENT:
1035 gtk_scrolled_window_set_vadjustment (scrolled_window,
1036 g_value_get_object (value));
1038 case PROP_HSCROLLBAR_POLICY:
1039 gtk_scrolled_window_set_policy (scrolled_window,
1040 g_value_get_enum (value),
1041 priv->vscrollbar_policy);
1043 case PROP_VSCROLLBAR_POLICY:
1044 gtk_scrolled_window_set_policy (scrolled_window,
1045 priv->hscrollbar_policy,
1046 g_value_get_enum (value));
1048 case PROP_WINDOW_PLACEMENT:
1049 gtk_scrolled_window_set_placement_internal (scrolled_window,
1050 g_value_get_enum (value));
1052 case PROP_WINDOW_PLACEMENT_SET:
1053 gtk_scrolled_window_set_placement_set (scrolled_window,
1054 g_value_get_boolean (value),
1057 case PROP_SHADOW_TYPE:
1058 gtk_scrolled_window_set_shadow_type (scrolled_window,
1059 g_value_get_enum (value));
1061 case PROP_MIN_CONTENT_WIDTH:
1062 gtk_scrolled_window_set_min_content_width (scrolled_window,
1063 g_value_get_int (value));
1065 case PROP_MIN_CONTENT_HEIGHT:
1066 gtk_scrolled_window_set_min_content_height (scrolled_window,
1067 g_value_get_int (value));
1070 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1076 gtk_scrolled_window_get_property (GObject *object,
1081 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1082 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1086 case PROP_HADJUSTMENT:
1087 g_value_set_object (value,
1088 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1090 case PROP_VADJUSTMENT:
1091 g_value_set_object (value,
1092 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1094 case PROP_WINDOW_PLACEMENT:
1095 g_value_set_enum (value, priv->window_placement);
1097 case PROP_WINDOW_PLACEMENT_SET:
1098 g_value_set_boolean (value, priv->window_placement_set);
1100 case PROP_SHADOW_TYPE:
1101 g_value_set_enum (value, priv->shadow_type);
1103 case PROP_HSCROLLBAR_POLICY:
1104 g_value_set_enum (value, priv->hscrollbar_policy);
1106 case PROP_VSCROLLBAR_POLICY:
1107 g_value_set_enum (value, priv->vscrollbar_policy);
1109 case PROP_MIN_CONTENT_WIDTH:
1110 g_value_set_int (value, priv->min_content_width);
1112 case PROP_MIN_CONTENT_HEIGHT:
1113 g_value_set_int (value, priv->min_content_height);
1116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1122 traverse_container (GtkWidget *widget,
1125 if (GTK_IS_SCROLLED_WINDOW (widget))
1127 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1128 gtk_widget_queue_resize (widget);
1130 else if (GTK_IS_CONTAINER (widget))
1131 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1135 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1139 list = gtk_window_list_toplevels ();
1141 for (l = list; l; l = l->next)
1142 gtk_container_forall (GTK_CONTAINER (l->data),
1143 traverse_container, NULL);
1149 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1150 GdkScreen *previous_screen)
1152 GtkSettings *settings;
1153 guint window_placement_connection;
1155 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1157 if (!gtk_widget_has_screen (widget))
1160 settings = gtk_widget_get_settings (widget);
1162 window_placement_connection =
1163 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1164 "gtk-scrolled-window-connection"));
1166 if (window_placement_connection)
1169 window_placement_connection =
1170 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1171 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1172 g_object_set_data (G_OBJECT (settings),
1173 I_("gtk-scrolled-window-connection"),
1174 GUINT_TO_POINTER (window_placement_connection));
1178 gtk_scrolled_window_draw (GtkWidget *widget,
1181 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1182 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1184 if (priv->shadow_type != GTK_SHADOW_NONE)
1186 GtkAllocation relative_allocation;
1188 gboolean scrollbars_within_bevel;
1190 style = gtk_widget_get_style (widget);
1191 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1193 if (!scrollbars_within_bevel)
1195 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1197 relative_allocation.x -= style->xthickness;
1198 relative_allocation.y -= style->ythickness;
1199 relative_allocation.width += 2 * style->xthickness;
1200 relative_allocation.height += 2 * style->ythickness;
1204 relative_allocation.x = 0;
1205 relative_allocation.y = 0;
1206 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1207 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1210 gtk_paint_shadow (style,
1212 GTK_STATE_NORMAL, priv->shadow_type,
1213 widget, "scrolled_window",
1214 relative_allocation.x,
1215 relative_allocation.y,
1216 relative_allocation.width,
1217 relative_allocation.height);
1220 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1226 gtk_scrolled_window_forall (GtkContainer *container,
1227 gboolean include_internals,
1228 GtkCallback callback,
1229 gpointer callback_data)
1231 GtkScrolledWindowPrivate *priv;
1232 GtkScrolledWindow *scrolled_window;
1234 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1235 g_return_if_fail (callback != NULL);
1237 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1241 if (include_internals)
1243 scrolled_window = GTK_SCROLLED_WINDOW (container);
1244 priv = scrolled_window->priv;
1246 if (priv->vscrollbar)
1247 callback (priv->vscrollbar, callback_data);
1248 if (priv->hscrollbar)
1249 callback (priv->hscrollbar, callback_data);
1254 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1255 GtkScrollType scroll,
1256 gboolean horizontal)
1258 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1259 GtkAdjustment *adjustment = NULL;
1263 case GTK_SCROLL_STEP_UP:
1264 scroll = GTK_SCROLL_STEP_BACKWARD;
1267 case GTK_SCROLL_STEP_DOWN:
1268 scroll = GTK_SCROLL_STEP_FORWARD;
1271 case GTK_SCROLL_STEP_LEFT:
1272 scroll = GTK_SCROLL_STEP_BACKWARD;
1275 case GTK_SCROLL_STEP_RIGHT:
1276 scroll = GTK_SCROLL_STEP_FORWARD;
1279 case GTK_SCROLL_PAGE_UP:
1280 scroll = GTK_SCROLL_PAGE_BACKWARD;
1283 case GTK_SCROLL_PAGE_DOWN:
1284 scroll = GTK_SCROLL_PAGE_FORWARD;
1287 case GTK_SCROLL_PAGE_LEFT:
1288 scroll = GTK_SCROLL_STEP_BACKWARD;
1291 case GTK_SCROLL_PAGE_RIGHT:
1292 scroll = GTK_SCROLL_STEP_FORWARD;
1295 case GTK_SCROLL_STEP_BACKWARD:
1296 case GTK_SCROLL_STEP_FORWARD:
1297 case GTK_SCROLL_PAGE_BACKWARD:
1298 case GTK_SCROLL_PAGE_FORWARD:
1299 case GTK_SCROLL_START:
1300 case GTK_SCROLL_END:
1303 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1307 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1308 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1313 if (priv->hscrollbar)
1314 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1318 if (priv->vscrollbar)
1319 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1324 gdouble value = adjustment->value;
1328 case GTK_SCROLL_STEP_FORWARD:
1329 value += adjustment->step_increment;
1331 case GTK_SCROLL_STEP_BACKWARD:
1332 value -= adjustment->step_increment;
1334 case GTK_SCROLL_PAGE_FORWARD:
1335 value += adjustment->page_increment;
1337 case GTK_SCROLL_PAGE_BACKWARD:
1338 value -= adjustment->page_increment;
1340 case GTK_SCROLL_START:
1341 value = adjustment->lower;
1343 case GTK_SCROLL_END:
1344 value = adjustment->upper;
1347 g_assert_not_reached ();
1351 gtk_adjustment_set_value (adjustment, value);
1360 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1361 GtkDirectionType direction_type)
1363 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1364 GtkWidget *toplevel;
1366 /* Focus out of the scrolled window entirely. We do this by setting
1367 * a flag, then propagating the focus motion to the notebook.
1369 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1370 if (!gtk_widget_is_toplevel (toplevel))
1373 g_object_ref (scrolled_window);
1375 priv->focus_out = TRUE;
1376 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1377 priv->focus_out = FALSE;
1379 g_object_unref (scrolled_window);
1383 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1384 GtkAllocation *allocation)
1386 GtkAllocation widget_allocation;
1387 GtkScrolledWindow *scrolled_window;
1388 GtkScrolledWindowPrivate *priv;
1394 g_return_if_fail (widget != NULL);
1395 g_return_if_fail (allocation != NULL);
1397 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1398 priv = scrolled_window->priv;
1400 /* Get possible scrollbar dimensions */
1401 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1402 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1403 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1405 /* Subtract some things from our available allocation size */
1409 if (priv->shadow_type != GTK_SHADOW_NONE)
1411 style = gtk_widget_get_style (widget);
1412 allocation->x += style->xthickness;
1413 allocation->y += style->ythickness;
1416 gtk_widget_get_allocation (widget, &widget_allocation);
1417 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1418 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1420 if (priv->vscrollbar_visible)
1424 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1427 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1428 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1430 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1431 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1432 allocation->x += (sb_width + sb_spacing);
1434 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1436 if (priv->hscrollbar_visible)
1439 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1440 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1441 allocation->y += (sb_height + sb_spacing);
1443 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1448 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1449 GtkAllocation *allocation)
1451 GtkScrolledWindow *scrolled_window;
1452 GtkScrolledWindowPrivate *priv;
1455 GtkAllocation relative_allocation;
1456 GtkAllocation child_allocation;
1458 gboolean scrollbars_within_bevel;
1463 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1464 g_return_if_fail (allocation != NULL);
1466 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1467 bin = GTK_BIN (scrolled_window);
1468 priv = scrolled_window->priv;
1470 /* Get possible scrollbar dimensions */
1471 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1472 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1473 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1475 style = gtk_widget_get_style (widget);
1476 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1478 gtk_widget_set_allocation (widget, allocation);
1480 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1481 priv->hscrollbar_visible = TRUE;
1482 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1483 priv->hscrollbar_visible = FALSE;
1484 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1485 priv->vscrollbar_visible = TRUE;
1486 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1487 priv->vscrollbar_visible = FALSE;
1489 child = gtk_bin_get_child (bin);
1490 if (child && gtk_widget_get_visible (child))
1492 gint child_scroll_width;
1493 gint child_scroll_height;
1494 gboolean previous_hvis;
1495 gboolean previous_vvis;
1498 /* In the case that both scrollbars are visible in the previous round,
1499 * we dont do our guess-work before hand because it's possible some
1500 * infinite recursion was detected (leave it up to the child scrollable
1501 * widget in this case to drive the scrollbar visibility completely
1502 * with the adjustment values).
1504 if (!priv->vscrollbar_visible || !priv->hscrollbar_visible)
1507 /* Determine scrollbar visibility first via hfw apis */
1508 if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1510 if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1511 gtk_widget_get_preferred_width (child, &child_scroll_width, NULL);
1513 gtk_widget_get_preferred_width (child, NULL, &child_scroll_width);
1515 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1517 /* First try without a vertical scrollbar if the content will fit the height
1518 * given the extra width of the scrollbar */
1519 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1520 gtk_widget_get_preferred_height_for_width (child,
1521 MAX (allocation->width, child_scroll_width),
1522 &child_scroll_height, NULL);
1524 gtk_widget_get_preferred_height_for_width (child,
1525 MAX (allocation->width, child_scroll_width),
1526 NULL, &child_scroll_height);
1528 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1530 /* Does the content height fit the allocation height ? */
1531 priv->vscrollbar_visible = child_scroll_height > allocation->height;
1533 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1534 priv->hscrollbar_visible =
1535 child_scroll_width > allocation->width -
1536 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1538 /* Now that we've guessed the hscrollbar, does the content height fit
1539 * the possible new allocation height ? */
1540 priv->vscrollbar_visible =
1541 child_scroll_height > allocation->height -
1542 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1544 /* Now that we've guessed the vscrollbar, does the content width fit
1545 * the possible new allocation width ? */
1546 priv->hscrollbar_visible =
1547 child_scroll_width > allocation->width -
1548 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1550 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1552 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1553 priv->vscrollbar_visible = child_scroll_height > allocation->height -
1554 (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;
1561 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1562 priv->hscrollbar_visible =
1563 child_scroll_width > allocation->width -
1564 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1566 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1569 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1571 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1572 gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
1574 gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
1576 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1578 /* First try without a horizontal scrollbar if the content will fit the width
1579 * given the extra height of the scrollbar */
1580 if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1581 gtk_widget_get_preferred_width_for_height (child,
1582 MAX (allocation->height, child_scroll_height),
1583 &child_scroll_width, NULL);
1585 gtk_widget_get_preferred_width_for_height (child,
1586 MAX (allocation->height, child_scroll_height),
1587 NULL, &child_scroll_width);
1589 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1591 /* Does the content width fit the allocation width ? */
1592 priv->hscrollbar_visible = child_scroll_width > allocation->width;
1594 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1595 priv->vscrollbar_visible =
1596 child_scroll_height > allocation->height -
1597 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1599 /* Now that we've guessed the vscrollbar, does the content width fit
1600 * the possible new allocation width ? */
1601 priv->hscrollbar_visible =
1602 child_scroll_width > allocation->width -
1603 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1605 /* Now that we've guessed the hscrollbar, does the content height fit
1606 * the possible new allocation height ? */
1607 priv->vscrollbar_visible =
1608 child_scroll_height > allocation->height -
1609 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1611 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1613 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1614 priv->hscrollbar_visible = child_scroll_width > allocation->width -
1615 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1618 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1620 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1622 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1623 priv->vscrollbar_visible =
1624 child_scroll_height > allocation->height -
1625 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1627 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1632 /* Now after guessing scrollbar visibility; fall back on the allocation loop which
1633 * observes the adjustments to detect scrollbar visibility and also avoids
1634 * infinite recursion
1638 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1640 child_allocation.x = relative_allocation.x + allocation->x;
1641 child_allocation.y = relative_allocation.y + allocation->y;
1642 child_allocation.width = relative_allocation.width;
1643 child_allocation.height = relative_allocation.height;
1645 previous_hvis = priv->hscrollbar_visible;
1646 previous_vvis = priv->vscrollbar_visible;
1648 gtk_widget_size_allocate (child, &child_allocation);
1650 /* If, after the first iteration, the hscrollbar and the
1651 * vscrollbar flip visiblity, then we need both.
1654 previous_hvis != priv->hscrollbar_visible &&
1655 previous_vvis != priv->vscrollbar_visible)
1657 priv->hscrollbar_visible = TRUE;
1658 priv->vscrollbar_visible = TRUE;
1660 /* a new resize is already queued at this point,
1661 * so we will immediatedly get reinvoked
1668 while (previous_hvis != priv->hscrollbar_visible ||
1669 previous_vvis != priv->vscrollbar_visible);
1673 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1674 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1675 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1678 if (priv->hscrollbar_visible)
1680 if (!gtk_widget_get_visible (priv->hscrollbar))
1681 gtk_widget_show (priv->hscrollbar);
1683 child_allocation.x = relative_allocation.x;
1684 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1685 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1686 child_allocation.y = (relative_allocation.y +
1687 relative_allocation.height +
1689 (priv->shadow_type == GTK_SHADOW_NONE ?
1690 0 : style->ythickness));
1692 child_allocation.y = 0;
1694 child_allocation.width = relative_allocation.width;
1695 child_allocation.height = sb_height;
1696 child_allocation.x += allocation->x;
1697 child_allocation.y += allocation->y;
1699 if (priv->shadow_type != GTK_SHADOW_NONE)
1701 if (!scrollbars_within_bevel)
1703 child_allocation.x -= style->xthickness;
1704 child_allocation.width += 2 * style->xthickness;
1706 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1707 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1709 child_allocation.y -= style->ythickness;
1713 child_allocation.y += style->ythickness;
1717 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1719 else if (gtk_widget_get_visible (priv->hscrollbar))
1720 gtk_widget_hide (priv->hscrollbar);
1722 if (priv->vscrollbar_visible)
1724 if (!gtk_widget_get_visible (priv->vscrollbar))
1725 gtk_widget_show (priv->vscrollbar);
1727 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1728 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1729 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1730 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1731 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1732 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1733 child_allocation.x = (relative_allocation.x +
1734 relative_allocation.width +
1736 (priv->shadow_type == GTK_SHADOW_NONE ?
1737 0 : style->xthickness));
1739 child_allocation.x = 0;
1741 child_allocation.y = relative_allocation.y;
1742 child_allocation.width = sb_width;
1743 child_allocation.height = relative_allocation.height;
1744 child_allocation.x += allocation->x;
1745 child_allocation.y += allocation->y;
1747 if (priv->shadow_type != GTK_SHADOW_NONE)
1749 if (!scrollbars_within_bevel)
1751 child_allocation.y -= style->ythickness;
1752 child_allocation.height += 2 * style->ythickness;
1754 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1755 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1757 child_allocation.x -= style->xthickness;
1761 child_allocation.x += style->xthickness;
1765 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1767 else if (gtk_widget_get_visible (priv->vscrollbar))
1768 gtk_widget_hide (priv->vscrollbar);
1772 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1773 GdkEventScroll *event)
1775 GtkScrolledWindowPrivate *priv;
1776 GtkScrolledWindow *scrolled_window;
1779 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1780 g_return_val_if_fail (event != NULL, FALSE);
1782 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1783 priv = scrolled_window->priv;
1785 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1786 range = priv->vscrollbar;
1788 range = priv->hscrollbar;
1790 if (range && gtk_widget_get_visible (range))
1792 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1795 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1797 gtk_adjustment_set_value (adj, adj->value + delta);
1806 gtk_scrolled_window_focus (GtkWidget *widget,
1807 GtkDirectionType direction)
1809 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1810 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1812 gboolean had_focus_child;
1814 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1816 if (priv->focus_out)
1818 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1822 if (gtk_widget_is_focus (widget))
1825 /* We only put the scrolled window itself in the focus chain if it
1826 * isn't possible to focus any children.
1828 child = gtk_bin_get_child (GTK_BIN (widget));
1831 if (gtk_widget_child_focus (child, direction))
1835 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1837 gtk_widget_grab_focus (widget);
1845 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1848 GtkScrolledWindowPrivate *priv;;
1849 GtkScrolledWindow *scrolled_window;
1851 g_return_if_fail (adjustment != NULL);
1852 g_return_if_fail (data != NULL);
1854 scrolled_window = GTK_SCROLLED_WINDOW (data);
1855 priv = scrolled_window->priv;
1857 if (priv->hscrollbar &&
1858 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1860 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1864 visible = priv->hscrollbar_visible;
1865 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1866 adjustment->page_size);
1867 if (priv->hscrollbar_visible != visible)
1868 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1871 else if (priv->vscrollbar &&
1872 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1874 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1878 visible = priv->vscrollbar_visible;
1879 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1880 adjustment->page_size);
1881 if (priv->vscrollbar_visible != visible)
1882 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1888 gtk_scrolled_window_add (GtkContainer *container,
1891 GtkScrolledWindowPrivate *priv;
1892 GtkScrolledWindow *scrolled_window;
1894 GtkWidget *child_widget;
1895 GtkAdjustment *hadj, *vadj;
1897 bin = GTK_BIN (container);
1898 child_widget = gtk_bin_get_child (bin);
1899 g_return_if_fail (child_widget == NULL);
1901 scrolled_window = GTK_SCROLLED_WINDOW (container);
1902 priv = scrolled_window->priv;
1904 _gtk_bin_set_child (bin, child);
1905 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1907 hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar));
1908 vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar));
1910 if (GTK_IS_SCROLLABLE (child))
1911 g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL);
1913 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1914 "use gtk_scrolled_window_add_with_viewport() instead");
1918 gtk_scrolled_window_remove (GtkContainer *container,
1921 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1922 g_return_if_fail (child != NULL);
1923 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1925 g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
1927 /* chain parent class handler to remove child */
1928 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1932 * gtk_scrolled_window_add_with_viewport:
1933 * @scrolled_window: a #GtkScrolledWindow
1934 * @child: the widget you want to scroll
1936 * Used to add children without native scrolling capabilities. This
1937 * is simply a convenience function; it is equivalent to adding the
1938 * unscrollable child to a viewport, then adding the viewport to the
1939 * scrolled window. If a child has native scrolling, use
1940 * gtk_container_add() instead of this function.
1942 * The viewport scrolls the child by moving its #GdkWindow, and takes
1943 * the size of the child to be the size of its toplevel #GdkWindow.
1944 * This will be very wrong for most widgets that support native scrolling;
1945 * for example, if you add a widget such as #GtkTreeView with a viewport,
1946 * the whole widget will scroll, including the column headings. Thus,
1947 * widgets with native scrolling support should not be used with the
1948 * #GtkViewport proxy.
1950 * A widget supports scrolling natively if it implements the
1951 * #GtkScrollable interface.
1954 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1958 GtkWidget *viewport;
1959 GtkWidget *child_widget;
1961 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1962 g_return_if_fail (GTK_IS_WIDGET (child));
1963 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1965 bin = GTK_BIN (scrolled_window);
1966 child_widget = gtk_bin_get_child (bin);
1970 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1971 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1973 viewport = child_widget;
1978 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1979 gtk_scrolled_window_get_vadjustment (scrolled_window));
1980 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1983 gtk_widget_show (viewport);
1984 gtk_container_add (GTK_CONTAINER (viewport), child);
1988 * _gtk_scrolled_window_get_spacing:
1989 * @scrolled_window: a scrolled window
1991 * Gets the spacing between the scrolled window's scrollbars and
1992 * the scrolled widget. Used by GtkCombo
1994 * Return value: the spacing, in pixels.
1997 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
1999 GtkScrolledWindowClass *class;
2001 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2003 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
2005 if (class->scrollbar_spacing >= 0)
2006 return class->scrollbar_spacing;
2009 gint scrollbar_spacing;
2011 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
2012 "scrollbar-spacing", &scrollbar_spacing,
2015 return scrollbar_spacing;
2021 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
2022 GtkOrientation orientation,
2026 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
2027 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
2028 GtkBin *bin = GTK_BIN (scrolled_window);
2031 gint scrollbar_spacing;
2032 GtkRequisition hscrollbar_requisition;
2033 GtkRequisition vscrollbar_requisition;
2034 GtkRequisition minimum_req, natural_req;
2037 gint min_child_size, nat_child_size;
2039 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
2043 minimum_req.width = 0;
2044 minimum_req.height = 0;
2045 natural_req.width = 0;
2046 natural_req.height = 0;
2048 gtk_widget_get_preferred_size (priv->hscrollbar,
2049 &hscrollbar_requisition, NULL);
2050 gtk_widget_get_preferred_size (priv->vscrollbar,
2051 &vscrollbar_requisition, NULL);
2053 child = gtk_bin_get_child (bin);
2054 if (child && gtk_widget_get_visible (child))
2056 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2058 gtk_widget_get_preferred_width (child,
2062 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2064 minimum_req.width += min_child_size;
2065 natural_req.width += nat_child_size;
2069 gint min_content_width = priv->min_content_width;
2071 if (min_content_width >= 0)
2073 minimum_req.width = MAX (minimum_req.width, min_content_width);
2074 natural_req.width = MAX (natural_req.width, min_content_width);
2079 minimum_req.width += vscrollbar_requisition.width;
2080 natural_req.width += vscrollbar_requisition.width;
2084 else /* GTK_ORIENTATION_VERTICAL */
2086 gtk_widget_get_preferred_height (child,
2090 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2092 minimum_req.height += min_child_size;
2093 natural_req.height += nat_child_size;
2097 gint min_content_height = priv->min_content_height;
2099 if (min_content_height >= 0)
2101 minimum_req.height = MAX (minimum_req.height, min_content_height);
2102 natural_req.height = MAX (natural_req.height, min_content_height);
2107 minimum_req.height += vscrollbar_requisition.height;
2108 natural_req.height += vscrollbar_requisition.height;
2114 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2115 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2117 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2118 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2119 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2120 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2123 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2124 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2126 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2127 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2128 if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2129 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2132 minimum_req.width += MAX (0, extra_width);
2133 minimum_req.height += MAX (0, extra_height);
2134 natural_req.width += MAX (0, extra_width);
2135 natural_req.height += MAX (0, extra_height);
2137 if (priv->shadow_type != GTK_SHADOW_NONE)
2139 style = gtk_widget_get_style (GTK_WIDGET (widget));
2140 minimum_req.width += 2 * style->xthickness;
2141 minimum_req.height += 2 * style->ythickness;
2142 natural_req.width += 2 * style->xthickness;
2143 natural_req.height += 2 * style->ythickness;
2146 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2149 *minimum_size = minimum_req.width;
2151 *natural_size = natural_req.width;
2156 *minimum_size = minimum_req.height;
2158 *natural_size = natural_req.height;
2163 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2167 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2171 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2175 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2179 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2181 gint *minimum_height,
2182 gint *natural_height)
2184 g_return_if_fail (GTK_IS_WIDGET (widget));
2186 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2190 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2192 gint *minimum_width,
2193 gint *natural_width)
2195 g_return_if_fail (GTK_IS_WIDGET (widget));
2197 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
2201 * gtk_scrolled_window_get_min_content_width:
2202 * @scrolled_window: a #GtkScrolledWindow
2204 * Gets the minimum content width of @scrolled_window, or -1 if not set.
2206 * Returns: the minimum content width
2211 gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
2213 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2215 return scrolled_window->priv->min_content_width;
2219 * gtk_scrolled_window_set_min_content_width:
2220 * @scrolled_window: a #GtkScrolledWindow
2221 * @width: the minimal content width
2223 * Sets the minimum width that @scrolled_window should keep visible.
2224 * Note that this can and (usually will) be smaller than the minimum
2225 * size of the content.
2230 gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
2233 GtkScrolledWindowPrivate *priv;
2235 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2237 priv = scrolled_window->priv;
2239 if (priv->min_content_width != width)
2241 priv->min_content_width = width;
2243 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2245 g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
2250 * gtk_scrolled_window_get_min_content_height:
2251 * @scrolled_window: a #GtkScrolledWindow
2253 * Gets the minimal content height of @scrolled_window, or -1 if not set.
2255 * Returns: the minimal content height
2260 gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
2262 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2264 return scrolled_window->priv->min_content_height;
2268 * gtk_scrolled_window_set_min_content_height:
2269 * @scrolled_window: a #GtkScrolledWindow
2270 * @height: the minimal content height
2272 * Sets the minimum height that @scrolled_window should keep visible.
2273 * Note that this can and (usually will) be smaller than the minimum
2274 * size of the content.
2279 gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
2282 GtkScrolledWindowPrivate *priv;
2284 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2286 priv = scrolled_window->priv;
2288 if (priv->min_content_height != height)
2290 priv->min_content_height = height;
2292 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2294 g_object_notify (G_OBJECT (scrolled_window), "min-content-height");