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 */
137 guint trust_sb_visibility : 1;
139 gint min_content_width;
140 gint min_content_height;
148 PROP_HSCROLLBAR_POLICY,
149 PROP_VSCROLLBAR_POLICY,
150 PROP_WINDOW_PLACEMENT,
151 PROP_WINDOW_PLACEMENT_SET,
153 PROP_MIN_CONTENT_WIDTH,
154 PROP_MIN_CONTENT_HEIGHT
165 static void gtk_scrolled_window_set_property (GObject *object,
169 static void gtk_scrolled_window_get_property (GObject *object,
174 static void gtk_scrolled_window_destroy (GtkWidget *widget);
175 static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
176 GdkScreen *previous_screen);
177 static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
179 static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
180 GtkAllocation *allocation);
181 static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
182 GdkEventScroll *event);
183 static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
184 GtkDirectionType direction);
185 static void gtk_scrolled_window_add (GtkContainer *container,
187 static void gtk_scrolled_window_remove (GtkContainer *container,
189 static void gtk_scrolled_window_forall (GtkContainer *container,
190 gboolean include_internals,
191 GtkCallback callback,
192 gpointer callback_data);
193 static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
194 GtkScrollType scroll,
195 gboolean horizontal);
196 static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
197 GtkDirectionType direction_type);
199 static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
200 GtkAllocation *allocation);
201 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
204 static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
206 static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
209 static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
212 static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
214 gint *minimum_height,
215 gint *natural_height);
216 static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
218 gint *minimum_height,
219 gint *natural_height);
221 static guint signals[LAST_SIGNAL] = {0};
223 G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
227 add_scroll_binding (GtkBindingSet *binding_set,
229 GdkModifierType mask,
230 GtkScrollType scroll,
233 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
235 gtk_binding_entry_add_signal (binding_set, keyval, mask,
237 GTK_TYPE_SCROLL_TYPE, scroll,
238 G_TYPE_BOOLEAN, horizontal);
239 gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
241 GTK_TYPE_SCROLL_TYPE, scroll,
242 G_TYPE_BOOLEAN, horizontal);
246 add_tab_bindings (GtkBindingSet *binding_set,
247 GdkModifierType modifiers,
248 GtkDirectionType direction)
250 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
252 GTK_TYPE_DIRECTION_TYPE, direction);
253 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
255 GTK_TYPE_DIRECTION_TYPE, direction);
259 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
261 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
262 GtkWidgetClass *widget_class;
263 GtkContainerClass *container_class;
264 GtkBindingSet *binding_set;
266 widget_class = (GtkWidgetClass*) class;
267 container_class = (GtkContainerClass*) class;
269 gobject_class->set_property = gtk_scrolled_window_set_property;
270 gobject_class->get_property = gtk_scrolled_window_get_property;
272 widget_class->destroy = gtk_scrolled_window_destroy;
273 widget_class->screen_changed = gtk_scrolled_window_screen_changed;
274 widget_class->draw = gtk_scrolled_window_draw;
275 widget_class->size_allocate = gtk_scrolled_window_size_allocate;
276 widget_class->scroll_event = gtk_scrolled_window_scroll_event;
277 widget_class->focus = gtk_scrolled_window_focus;
278 widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
279 widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
280 widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
281 widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
283 container_class->add = gtk_scrolled_window_add;
284 container_class->remove = gtk_scrolled_window_remove;
285 container_class->forall = gtk_scrolled_window_forall;
286 gtk_container_class_handle_border_width (container_class);
288 class->scrollbar_spacing = -1;
290 class->scroll_child = gtk_scrolled_window_scroll_child;
291 class->move_focus_out = gtk_scrolled_window_move_focus_out;
293 g_object_class_install_property (gobject_class,
295 g_param_spec_object ("hadjustment",
296 P_("Horizontal Adjustment"),
297 P_("The GtkAdjustment for the horizontal position"),
299 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
300 g_object_class_install_property (gobject_class,
302 g_param_spec_object ("vadjustment",
303 P_("Vertical Adjustment"),
304 P_("The GtkAdjustment for the vertical position"),
306 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
307 g_object_class_install_property (gobject_class,
308 PROP_HSCROLLBAR_POLICY,
309 g_param_spec_enum ("hscrollbar-policy",
310 P_("Horizontal Scrollbar Policy"),
311 P_("When the horizontal scrollbar is displayed"),
312 GTK_TYPE_POLICY_TYPE,
313 GTK_POLICY_AUTOMATIC,
314 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
315 g_object_class_install_property (gobject_class,
316 PROP_VSCROLLBAR_POLICY,
317 g_param_spec_enum ("vscrollbar-policy",
318 P_("Vertical Scrollbar Policy"),
319 P_("When the vertical scrollbar is displayed"),
320 GTK_TYPE_POLICY_TYPE,
321 GTK_POLICY_AUTOMATIC,
322 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
324 g_object_class_install_property (gobject_class,
325 PROP_WINDOW_PLACEMENT,
326 g_param_spec_enum ("window-placement",
327 P_("Window Placement"),
328 P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
329 GTK_TYPE_CORNER_TYPE,
331 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
334 * GtkScrolledWindow:window-placement-set:
336 * Whether "window-placement" should be used to determine the location
337 * of the contents with respect to the scrollbars. Otherwise, the
338 * "gtk-scrolled-window-placement" setting is used.
342 g_object_class_install_property (gobject_class,
343 PROP_WINDOW_PLACEMENT_SET,
344 g_param_spec_boolean ("window-placement-set",
345 P_("Window Placement Set"),
346 P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
348 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
349 g_object_class_install_property (gobject_class,
351 g_param_spec_enum ("shadow-type",
353 P_("Style of bevel around the contents"),
354 GTK_TYPE_SHADOW_TYPE,
356 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
359 * GtkScrolledWindow:scrollbars-within-bevel:
361 * Whether to place scrollbars within the scrolled window's bevel.
365 gtk_widget_class_install_style_property (widget_class,
366 g_param_spec_boolean ("scrollbars-within-bevel",
367 P_("Scrollbars within bevel"),
368 P_("Place scrollbars within the scrolled window's bevel"),
370 GTK_PARAM_READABLE));
372 gtk_widget_class_install_style_property (widget_class,
373 g_param_spec_int ("scrollbar-spacing",
374 P_("Scrollbar spacing"),
375 P_("Number of pixels between the scrollbars and the scrolled window"),
378 DEFAULT_SCROLLBAR_SPACING,
379 GTK_PARAM_READABLE));
381 g_object_class_install_property (gobject_class,
382 PROP_MIN_CONTENT_WIDTH,
383 g_param_spec_int ("min-content-width",
384 P_("Minimum Content Width"),
385 P_("The minimum width that the scrolled window will allocate to its content"),
387 GTK_PARAM_READWRITE));
388 g_object_class_install_property (gobject_class,
389 PROP_MIN_CONTENT_HEIGHT,
390 g_param_spec_int ("min-content-height",
391 P_("Minimum Content Height"),
392 P_("The minimum height that the scrolled window will allocate to its content"),
394 GTK_PARAM_READWRITE));
396 * GtkScrolledWindow::scroll-child:
397 * @scrolled_window: a #GtkScrolledWindow
398 * @scroll: a #GtkScrollType describing how much to scroll
399 * @horizontal: whether the keybinding scrolls the child
400 * horizontally or not
402 * The ::scroll-child signal is a
403 * <link linkend="keybinding-signals">keybinding signal</link>
404 * which gets emitted when a keybinding that scrolls is pressed.
405 * The horizontal or vertical adjustment is updated which triggers a
406 * signal that the scrolled windows child may listen to and scroll itself.
408 signals[SCROLL_CHILD] =
409 g_signal_new (I_("scroll-child"),
410 G_TYPE_FROM_CLASS (gobject_class),
411 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
412 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
414 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
416 GTK_TYPE_SCROLL_TYPE,
420 * GtkScrolledWindow::move-focus-out:
421 * @scrolled_window: a #GtkScrolledWindow
422 * @direction_type: either %GTK_DIR_TAB_FORWARD or
423 * %GTK_DIR_TAB_BACKWARD
425 * The ::move-focus-out signal is a
426 * <link linkend="keybinding-signals">keybinding signal</link>
427 * which gets emitted when focus is moved away from the scrolled
428 * window by a keybinding.
429 * The #GtkWidget::move-focus signal is emitted with @direction_type
430 * on this scrolled windows toplevel parent in the container hierarchy.
431 * The default bindings for this signal are
432 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
434 * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
436 signals[MOVE_FOCUS_OUT] =
437 g_signal_new (I_("move-focus-out"),
438 G_TYPE_FROM_CLASS (gobject_class),
439 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
440 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
442 _gtk_marshal_VOID__ENUM,
444 GTK_TYPE_DIRECTION_TYPE);
446 binding_set = gtk_binding_set_by_class (class);
448 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
449 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
450 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
451 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
453 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
454 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
455 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
456 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
458 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
459 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
460 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
461 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
463 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
464 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
466 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
470 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
472 GtkScrolledWindowPrivate *priv;
474 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
475 GTK_TYPE_SCROLLED_WINDOW,
476 GtkScrolledWindowPrivate);
478 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
479 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
481 priv->hscrollbar = NULL;
482 priv->vscrollbar = NULL;
483 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
484 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
485 priv->hscrollbar_visible = FALSE;
486 priv->vscrollbar_visible = FALSE;
487 priv->focus_out = FALSE;
488 priv->window_placement = GTK_CORNER_TOP_LEFT;
489 gtk_scrolled_window_update_real_placement (scrolled_window);
490 priv->min_content_width = -1;
491 priv->min_content_height = -1;
492 priv->trust_sb_visibility = FALSE;
496 * gtk_scrolled_window_new:
497 * @hadjustment: (allow-none): horizontal adjustment
498 * @vadjustment: (allow-none): vertical adjustment
500 * Creates a new scrolled window.
502 * The two arguments are the scrolled window's adjustments; these will be
503 * shared with the scrollbars and the child widget to keep the bars in sync
504 * with the child. Usually you want to pass %NULL for the adjustments, which
505 * will cause the scrolled window to create them for you.
507 * Returns: a new scrolled window
510 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
511 GtkAdjustment *vadjustment)
513 GtkWidget *scrolled_window;
516 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
519 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
521 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
522 "hadjustment", hadjustment,
523 "vadjustment", vadjustment,
526 return scrolled_window;
530 * gtk_scrolled_window_set_hadjustment:
531 * @scrolled_window: a #GtkScrolledWindow
532 * @hadjustment: horizontal scroll adjustment
534 * Sets the #GtkAdjustment for the horizontal scrollbar.
537 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
538 GtkAdjustment *hadjustment)
540 GtkScrolledWindowPrivate *priv;
544 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
546 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
548 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
550 bin = GTK_BIN (scrolled_window);
551 priv = scrolled_window->priv;
553 if (!priv->hscrollbar)
555 gtk_widget_push_composite_child ();
556 priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
557 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
558 gtk_widget_pop_composite_child ();
560 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
561 g_object_ref (priv->hscrollbar);
562 gtk_widget_show (priv->hscrollbar);
566 GtkAdjustment *old_adjustment;
568 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
569 if (old_adjustment == hadjustment)
572 g_signal_handlers_disconnect_by_func (old_adjustment,
573 gtk_scrolled_window_adjustment_changed,
575 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
578 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
579 g_signal_connect (hadjustment,
581 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
583 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
585 child = gtk_bin_get_child (bin);
586 if (GTK_IS_SCROLLABLE (child))
587 gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (child), hadjustment);
589 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
593 * gtk_scrolled_window_set_vadjustment:
594 * @scrolled_window: a #GtkScrolledWindow
595 * @vadjustment: vertical scroll adjustment
597 * Sets the #GtkAdjustment for the vertical scrollbar.
600 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
601 GtkAdjustment *vadjustment)
603 GtkScrolledWindowPrivate *priv;
607 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
609 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
611 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
613 bin = GTK_BIN (scrolled_window);
614 priv = scrolled_window->priv;
616 if (!priv->vscrollbar)
618 gtk_widget_push_composite_child ();
619 priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
620 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
621 gtk_widget_pop_composite_child ();
623 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
624 g_object_ref (priv->vscrollbar);
625 gtk_widget_show (priv->vscrollbar);
629 GtkAdjustment *old_adjustment;
631 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
632 if (old_adjustment == vadjustment)
635 g_signal_handlers_disconnect_by_func (old_adjustment,
636 gtk_scrolled_window_adjustment_changed,
638 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
641 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
642 g_signal_connect (vadjustment,
644 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
646 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
648 child = gtk_bin_get_child (bin);
649 if (GTK_IS_SCROLLABLE (child))
650 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
652 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
656 * gtk_scrolled_window_get_hadjustment:
657 * @scrolled_window: a #GtkScrolledWindow
659 * Returns the horizontal scrollbar's adjustment, used to connect the
660 * horizontal scrollbar to the child widget's horizontal scroll
663 * Returns: (transfer none): the horizontal #GtkAdjustment
666 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
668 GtkScrolledWindowPrivate *priv;
670 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
672 priv = scrolled_window->priv;
674 return (priv->hscrollbar ?
675 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
680 * gtk_scrolled_window_get_vadjustment:
681 * @scrolled_window: a #GtkScrolledWindow
683 * Returns the vertical scrollbar's adjustment, used to connect the
684 * vertical scrollbar to the child widget's vertical scroll functionality.
686 * Returns: (transfer none): the vertical #GtkAdjustment
689 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
691 GtkScrolledWindowPrivate *priv;
693 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
695 priv = scrolled_window->priv;
697 return (priv->vscrollbar ?
698 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
703 * gtk_scrolled_window_get_hscrollbar:
704 * @scrolled_window: a #GtkScrolledWindow
706 * Returns the horizontal scrollbar of @scrolled_window.
708 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
709 * or %NULL if it does not have one.
714 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
716 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
718 return scrolled_window->priv->hscrollbar;
722 * gtk_scrolled_window_get_vscrollbar:
723 * @scrolled_window: a #GtkScrolledWindow
725 * Returns the vertical scrollbar of @scrolled_window.
727 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
728 * or %NULL if it does not have one.
733 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
735 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
737 return scrolled_window->priv->vscrollbar;
741 * gtk_scrolled_window_set_policy:
742 * @scrolled_window: a #GtkScrolledWindow
743 * @hscrollbar_policy: policy for horizontal bar
744 * @vscrollbar_policy: policy for vertical bar
746 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
748 * The policy determines when the scrollbar should appear; it is a value
749 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
750 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
751 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
752 * if needed (that is, if the slider part of the bar would be smaller
753 * than the trough - the display is larger than the page size).
756 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
757 GtkPolicyType hscrollbar_policy,
758 GtkPolicyType vscrollbar_policy)
760 GtkScrolledWindowPrivate *priv;
761 GObject *object = G_OBJECT (scrolled_window);
763 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
765 priv = scrolled_window->priv;
767 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
768 (priv->vscrollbar_policy != vscrollbar_policy))
770 priv->hscrollbar_policy = hscrollbar_policy;
771 priv->vscrollbar_policy = vscrollbar_policy;
773 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
775 g_object_freeze_notify (object);
776 g_object_notify (object, "hscrollbar-policy");
777 g_object_notify (object, "vscrollbar-policy");
778 g_object_thaw_notify (object);
783 * gtk_scrolled_window_get_policy:
784 * @scrolled_window: a #GtkScrolledWindow
785 * @hscrollbar_policy: location to store the policy for the horizontal
786 * scrollbar, or %NULL.
787 * @vscrollbar_policy: location to store the policy for the vertical
788 * scrollbar, or %NULL.
790 * Retrieves the current policy values for the horizontal and vertical
791 * scrollbars. See gtk_scrolled_window_set_policy().
794 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
795 GtkPolicyType *hscrollbar_policy,
796 GtkPolicyType *vscrollbar_policy)
798 GtkScrolledWindowPrivate *priv;
800 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
802 priv = scrolled_window->priv;
804 if (hscrollbar_policy)
805 *hscrollbar_policy = priv->hscrollbar_policy;
806 if (vscrollbar_policy)
807 *vscrollbar_policy = priv->vscrollbar_policy;
811 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
813 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
814 GtkSettings *settings;
816 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
818 if (priv->window_placement_set || settings == NULL)
819 priv->real_window_placement = priv->window_placement;
821 g_object_get (settings,
822 "gtk-scrolled-window-placement",
823 &priv->real_window_placement,
828 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
829 GtkCornerType window_placement)
831 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
833 if (priv->window_placement != window_placement)
835 priv->window_placement = window_placement;
837 gtk_scrolled_window_update_real_placement (scrolled_window);
838 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
840 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
845 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
846 gboolean placement_set,
847 gboolean emit_resize)
849 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
851 if (priv->window_placement_set != placement_set)
853 priv->window_placement_set = placement_set;
855 gtk_scrolled_window_update_real_placement (scrolled_window);
857 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
859 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
864 * gtk_scrolled_window_set_placement:
865 * @scrolled_window: a #GtkScrolledWindow
866 * @window_placement: position of the child window
868 * Sets the placement of the contents with respect to the scrollbars
869 * for the scrolled window.
871 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
872 * in the top left, with the scrollbars underneath and to the right.
873 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
874 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
876 * See also gtk_scrolled_window_get_placement() and
877 * gtk_scrolled_window_unset_placement().
880 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
881 GtkCornerType window_placement)
883 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
885 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
886 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
890 * gtk_scrolled_window_get_placement:
891 * @scrolled_window: a #GtkScrolledWindow
893 * Gets the placement of the contents with respect to the scrollbars
894 * for the scrolled window. See gtk_scrolled_window_set_placement().
896 * Return value: the current placement value.
898 * See also gtk_scrolled_window_set_placement() and
899 * gtk_scrolled_window_unset_placement().
902 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
904 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
906 return scrolled_window->priv->window_placement;
910 * gtk_scrolled_window_unset_placement:
911 * @scrolled_window: a #GtkScrolledWindow
913 * Unsets the placement of the contents with respect to the scrollbars
914 * for the scrolled window. If no window placement is set for a scrolled
915 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
917 * See also gtk_scrolled_window_set_placement() and
918 * gtk_scrolled_window_get_placement().
923 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
925 GtkScrolledWindowPrivate *priv;
927 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
929 priv = scrolled_window->priv;
931 if (priv->window_placement_set)
933 priv->window_placement_set = FALSE;
935 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
937 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
942 * gtk_scrolled_window_set_shadow_type:
943 * @scrolled_window: a #GtkScrolledWindow
944 * @type: kind of shadow to draw around scrolled window contents
946 * Changes the type of shadow drawn around the contents of
951 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
954 GtkScrolledWindowPrivate *priv;
956 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
957 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
959 priv = scrolled_window->priv;
961 if (priv->shadow_type != type)
963 priv->shadow_type = type;
965 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
966 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
968 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
970 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
975 * gtk_scrolled_window_get_shadow_type:
976 * @scrolled_window: a #GtkScrolledWindow
978 * Gets the shadow type of the scrolled window. See
979 * gtk_scrolled_window_set_shadow_type().
981 * Return value: the current shadow type
984 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
986 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
988 return scrolled_window->priv->shadow_type;
992 gtk_scrolled_window_destroy (GtkWidget *widget)
994 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
995 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
997 if (priv->hscrollbar)
999 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
1000 gtk_scrolled_window_adjustment_changed,
1002 gtk_widget_unparent (priv->hscrollbar);
1003 gtk_widget_destroy (priv->hscrollbar);
1004 g_object_unref (priv->hscrollbar);
1005 priv->hscrollbar = NULL;
1007 if (priv->vscrollbar)
1009 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
1010 gtk_scrolled_window_adjustment_changed,
1012 gtk_widget_unparent (priv->vscrollbar);
1013 gtk_widget_destroy (priv->vscrollbar);
1014 g_object_unref (priv->vscrollbar);
1015 priv->vscrollbar = NULL;
1018 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
1022 gtk_scrolled_window_set_property (GObject *object,
1024 const GValue *value,
1027 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1028 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1032 case PROP_HADJUSTMENT:
1033 gtk_scrolled_window_set_hadjustment (scrolled_window,
1034 g_value_get_object (value));
1036 case PROP_VADJUSTMENT:
1037 gtk_scrolled_window_set_vadjustment (scrolled_window,
1038 g_value_get_object (value));
1040 case PROP_HSCROLLBAR_POLICY:
1041 gtk_scrolled_window_set_policy (scrolled_window,
1042 g_value_get_enum (value),
1043 priv->vscrollbar_policy);
1045 case PROP_VSCROLLBAR_POLICY:
1046 gtk_scrolled_window_set_policy (scrolled_window,
1047 priv->hscrollbar_policy,
1048 g_value_get_enum (value));
1050 case PROP_WINDOW_PLACEMENT:
1051 gtk_scrolled_window_set_placement_internal (scrolled_window,
1052 g_value_get_enum (value));
1054 case PROP_WINDOW_PLACEMENT_SET:
1055 gtk_scrolled_window_set_placement_set (scrolled_window,
1056 g_value_get_boolean (value),
1059 case PROP_SHADOW_TYPE:
1060 gtk_scrolled_window_set_shadow_type (scrolled_window,
1061 g_value_get_enum (value));
1063 case PROP_MIN_CONTENT_WIDTH:
1064 gtk_scrolled_window_set_min_content_width (scrolled_window,
1065 g_value_get_int (value));
1067 case PROP_MIN_CONTENT_HEIGHT:
1068 gtk_scrolled_window_set_min_content_height (scrolled_window,
1069 g_value_get_int (value));
1072 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1078 gtk_scrolled_window_get_property (GObject *object,
1083 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1084 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1088 case PROP_HADJUSTMENT:
1089 g_value_set_object (value,
1090 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1092 case PROP_VADJUSTMENT:
1093 g_value_set_object (value,
1094 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1096 case PROP_WINDOW_PLACEMENT:
1097 g_value_set_enum (value, priv->window_placement);
1099 case PROP_WINDOW_PLACEMENT_SET:
1100 g_value_set_boolean (value, priv->window_placement_set);
1102 case PROP_SHADOW_TYPE:
1103 g_value_set_enum (value, priv->shadow_type);
1105 case PROP_HSCROLLBAR_POLICY:
1106 g_value_set_enum (value, priv->hscrollbar_policy);
1108 case PROP_VSCROLLBAR_POLICY:
1109 g_value_set_enum (value, priv->vscrollbar_policy);
1111 case PROP_MIN_CONTENT_WIDTH:
1112 g_value_set_int (value, priv->min_content_width);
1114 case PROP_MIN_CONTENT_HEIGHT:
1115 g_value_set_int (value, priv->min_content_height);
1118 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1124 traverse_container (GtkWidget *widget,
1127 if (GTK_IS_SCROLLED_WINDOW (widget))
1129 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1130 gtk_widget_queue_resize (widget);
1132 else if (GTK_IS_CONTAINER (widget))
1133 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1137 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1141 list = gtk_window_list_toplevels ();
1143 for (l = list; l; l = l->next)
1144 gtk_container_forall (GTK_CONTAINER (l->data),
1145 traverse_container, NULL);
1151 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1152 GdkScreen *previous_screen)
1154 GtkSettings *settings;
1155 guint window_placement_connection;
1157 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1159 if (!gtk_widget_has_screen (widget))
1162 settings = gtk_widget_get_settings (widget);
1164 window_placement_connection =
1165 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1166 "gtk-scrolled-window-connection"));
1168 if (window_placement_connection)
1171 window_placement_connection =
1172 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1173 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1174 g_object_set_data (G_OBJECT (settings),
1175 I_("gtk-scrolled-window-connection"),
1176 GUINT_TO_POINTER (window_placement_connection));
1180 gtk_scrolled_window_draw (GtkWidget *widget,
1183 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1184 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1186 if (priv->shadow_type != GTK_SHADOW_NONE)
1188 GtkAllocation relative_allocation;
1190 gboolean scrollbars_within_bevel;
1192 style = gtk_widget_get_style (widget);
1193 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1195 if (!scrollbars_within_bevel)
1197 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1199 relative_allocation.x -= style->xthickness;
1200 relative_allocation.y -= style->ythickness;
1201 relative_allocation.width += 2 * style->xthickness;
1202 relative_allocation.height += 2 * style->ythickness;
1206 relative_allocation.x = 0;
1207 relative_allocation.y = 0;
1208 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1209 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1212 gtk_paint_shadow (style,
1214 GTK_STATE_NORMAL, priv->shadow_type,
1215 widget, "scrolled_window",
1216 relative_allocation.x,
1217 relative_allocation.y,
1218 relative_allocation.width,
1219 relative_allocation.height);
1222 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1228 gtk_scrolled_window_forall (GtkContainer *container,
1229 gboolean include_internals,
1230 GtkCallback callback,
1231 gpointer callback_data)
1233 GtkScrolledWindowPrivate *priv;
1234 GtkScrolledWindow *scrolled_window;
1236 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1237 g_return_if_fail (callback != NULL);
1239 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1243 if (include_internals)
1245 scrolled_window = GTK_SCROLLED_WINDOW (container);
1246 priv = scrolled_window->priv;
1248 if (priv->vscrollbar)
1249 callback (priv->vscrollbar, callback_data);
1250 if (priv->hscrollbar)
1251 callback (priv->hscrollbar, callback_data);
1256 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1257 GtkScrollType scroll,
1258 gboolean horizontal)
1260 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1261 GtkAdjustment *adjustment = NULL;
1265 case GTK_SCROLL_STEP_UP:
1266 scroll = GTK_SCROLL_STEP_BACKWARD;
1269 case GTK_SCROLL_STEP_DOWN:
1270 scroll = GTK_SCROLL_STEP_FORWARD;
1273 case GTK_SCROLL_STEP_LEFT:
1274 scroll = GTK_SCROLL_STEP_BACKWARD;
1277 case GTK_SCROLL_STEP_RIGHT:
1278 scroll = GTK_SCROLL_STEP_FORWARD;
1281 case GTK_SCROLL_PAGE_UP:
1282 scroll = GTK_SCROLL_PAGE_BACKWARD;
1285 case GTK_SCROLL_PAGE_DOWN:
1286 scroll = GTK_SCROLL_PAGE_FORWARD;
1289 case GTK_SCROLL_PAGE_LEFT:
1290 scroll = GTK_SCROLL_STEP_BACKWARD;
1293 case GTK_SCROLL_PAGE_RIGHT:
1294 scroll = GTK_SCROLL_STEP_FORWARD;
1297 case GTK_SCROLL_STEP_BACKWARD:
1298 case GTK_SCROLL_STEP_FORWARD:
1299 case GTK_SCROLL_PAGE_BACKWARD:
1300 case GTK_SCROLL_PAGE_FORWARD:
1301 case GTK_SCROLL_START:
1302 case GTK_SCROLL_END:
1305 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1309 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1310 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1315 if (priv->hscrollbar)
1316 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1320 if (priv->vscrollbar)
1321 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1326 gdouble value = adjustment->value;
1330 case GTK_SCROLL_STEP_FORWARD:
1331 value += adjustment->step_increment;
1333 case GTK_SCROLL_STEP_BACKWARD:
1334 value -= adjustment->step_increment;
1336 case GTK_SCROLL_PAGE_FORWARD:
1337 value += adjustment->page_increment;
1339 case GTK_SCROLL_PAGE_BACKWARD:
1340 value -= adjustment->page_increment;
1342 case GTK_SCROLL_START:
1343 value = adjustment->lower;
1345 case GTK_SCROLL_END:
1346 value = adjustment->upper;
1349 g_assert_not_reached ();
1353 gtk_adjustment_set_value (adjustment, value);
1362 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1363 GtkDirectionType direction_type)
1365 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1366 GtkWidget *toplevel;
1368 /* Focus out of the scrolled window entirely. We do this by setting
1369 * a flag, then propagating the focus motion to the notebook.
1371 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1372 if (!gtk_widget_is_toplevel (toplevel))
1375 g_object_ref (scrolled_window);
1377 priv->focus_out = TRUE;
1378 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1379 priv->focus_out = FALSE;
1381 g_object_unref (scrolled_window);
1385 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1386 GtkAllocation *allocation)
1388 GtkAllocation widget_allocation;
1389 GtkScrolledWindow *scrolled_window;
1390 GtkScrolledWindowPrivate *priv;
1396 g_return_if_fail (widget != NULL);
1397 g_return_if_fail (allocation != NULL);
1399 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1400 priv = scrolled_window->priv;
1402 /* Get possible scrollbar dimensions */
1403 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1404 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1405 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1407 /* Subtract some things from our available allocation size */
1411 if (priv->shadow_type != GTK_SHADOW_NONE)
1413 style = gtk_widget_get_style (widget);
1414 allocation->x += style->xthickness;
1415 allocation->y += style->ythickness;
1418 gtk_widget_get_allocation (widget, &widget_allocation);
1419 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1420 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1422 if (priv->vscrollbar_visible)
1426 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1429 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1430 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1432 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1433 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1434 allocation->x += (sb_width + sb_spacing);
1436 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1438 if (priv->hscrollbar_visible)
1441 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1442 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1443 allocation->y += (sb_height + sb_spacing);
1445 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1450 gtk_scrolled_window_allocate_child (GtkScrolledWindow *swindow,
1451 GtkAllocation *relative_allocation)
1453 GtkWidget *widget = GTK_WIDGET (swindow), *child;
1454 GtkAllocation allocation;
1455 GtkAllocation child_allocation;
1457 child = gtk_bin_get_child (GTK_BIN (widget));
1459 gtk_widget_get_allocation (widget, &allocation);
1461 gtk_scrolled_window_relative_allocation (widget, relative_allocation);
1462 child_allocation.x = relative_allocation->x + allocation.x;
1463 child_allocation.y = relative_allocation->y + allocation.y;
1464 child_allocation.width = relative_allocation->width;
1465 child_allocation.height = relative_allocation->height;
1467 gtk_widget_size_allocate (child, &child_allocation);
1471 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1472 GtkAllocation *allocation)
1474 GtkScrolledWindow *scrolled_window;
1475 GtkScrolledWindowPrivate *priv;
1478 GtkAllocation relative_allocation;
1479 GtkAllocation child_allocation;
1481 gboolean scrollbars_within_bevel;
1487 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1488 g_return_if_fail (allocation != NULL);
1490 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1491 bin = GTK_BIN (scrolled_window);
1492 priv = scrolled_window->priv;
1494 /* Get possible scrollbar dimensions */
1495 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1496 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1497 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1499 style = gtk_widget_get_style (widget);
1500 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1502 gtk_widget_set_allocation (widget, allocation);
1504 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1505 priv->hscrollbar_visible = TRUE;
1506 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1507 priv->hscrollbar_visible = FALSE;
1508 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1509 priv->vscrollbar_visible = TRUE;
1510 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1511 priv->vscrollbar_visible = FALSE;
1513 child = gtk_bin_get_child (bin);
1514 if (child && gtk_widget_get_visible (child))
1516 gint child_scroll_width;
1517 gint child_scroll_height;
1518 gboolean previous_hvis;
1519 gboolean previous_vvis;
1521 /* Determine scrollbar visibility first via hfw apis */
1522 if (!priv->trust_sb_visibility)
1524 if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
1526 if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1527 gtk_widget_get_preferred_width (child, &child_scroll_width, NULL);
1529 gtk_widget_get_preferred_width (child, NULL, &child_scroll_width);
1531 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1533 /* First try without a vertical scrollbar if the content will
1534 * fit the height given the extra width of the scrollbar
1536 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1537 gtk_widget_get_preferred_height_for_width (child,
1538 MAX (allocation->width, child_scroll_width),
1539 &child_scroll_height, NULL);
1541 gtk_widget_get_preferred_height_for_width (child,
1542 MAX (allocation->width, child_scroll_width),
1543 NULL, &child_scroll_height);
1545 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1547 /* Does the content height fit the allocation height ? */
1548 priv->vscrollbar_visible = child_scroll_height > allocation->height;
1550 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1551 priv->hscrollbar_visible =
1552 child_scroll_width > allocation->width -
1553 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1555 /* Now that we've guessed the hscrollbar, does the
1556 * content height fit the possible new allocation height ?
1558 priv->vscrollbar_visible =
1559 child_scroll_height > allocation->height -
1560 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1562 /* Now that we've guessed the vscrollbar, does the
1563 * content width fit the possible new allocation width ?
1565 priv->hscrollbar_visible =
1566 child_scroll_width > allocation->width -
1567 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1569 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1571 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1572 priv->vscrollbar_visible = child_scroll_height > allocation->height -
1573 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1576 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1578 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1580 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1581 priv->hscrollbar_visible =
1582 child_scroll_width > allocation->width -
1583 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1585 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1588 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1590 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1591 gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
1593 gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
1595 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1597 /* First try without a horizontal scrollbar if the content
1598 * will fit the width given the extra height of the scrollbar
1600 if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1601 gtk_widget_get_preferred_width_for_height (child,
1602 MAX (allocation->height, child_scroll_height),
1603 &child_scroll_width, NULL);
1605 gtk_widget_get_preferred_width_for_height (child,
1606 MAX (allocation->height, child_scroll_height),
1607 NULL, &child_scroll_width);
1609 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1611 /* Does the content width fit the allocation width ? */
1612 priv->hscrollbar_visible = child_scroll_width > allocation->width;
1614 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1615 priv->vscrollbar_visible =
1616 child_scroll_height > allocation->height -
1617 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1619 /* Now that we've guessed the vscrollbar, does the content
1620 * width fit the possible new allocation width ?
1622 priv->hscrollbar_visible =
1623 child_scroll_width > allocation->width -
1624 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1626 /* Now that we've guessed the hscrollbar, does the content
1627 * height fit the possible new allocation height ?
1629 priv->vscrollbar_visible =
1630 child_scroll_height > allocation->height -
1631 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1633 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1635 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1636 priv->hscrollbar_visible = child_scroll_width > allocation->width -
1637 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1640 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1642 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1644 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1645 priv->vscrollbar_visible =
1646 child_scroll_height > allocation->height -
1647 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1649 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1654 /* Now after guessing scrollbar visibility; fall back on the allocation
1655 * loop which observes the adjustments to detect scrollbar visibility
1656 * and also avoids infinite recursion
1660 previous_hvis = priv->hscrollbar_visible;
1661 previous_vvis = priv->vscrollbar_visible;
1662 gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
1664 /* If, after the first iteration, the hscrollbar and the
1665 * vscrollbar flip visiblity, then we need both.
1668 previous_hvis != priv->hscrollbar_visible &&
1669 previous_vvis != priv->vscrollbar_visible)
1671 priv->hscrollbar_visible = TRUE;
1672 priv->vscrollbar_visible = TRUE;
1674 /* Make sure we dont do the height-for-width guess on the
1677 priv->trust_sb_visibility = TRUE;
1679 /* A queue resize is incoming so we will be immediately reinvoked */
1685 while (previous_hvis != priv->hscrollbar_visible ||
1686 previous_vvis != priv->vscrollbar_visible);
1690 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1691 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1692 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1696 /* If the scrollbars have flipped visibility, showing/hiding them will
1697 * cause a resize to be queued, we need to blindly trust those visibility
1698 * states on the next incoming allocate() and avoid guessing the visibility
1699 * with height-for-width apis.
1701 priv->trust_sb_visibility = TRUE;
1703 priv->trust_sb_visibility = FALSE;
1705 if (priv->hscrollbar_visible)
1707 if (!gtk_widget_get_visible (priv->hscrollbar))
1708 gtk_widget_show (priv->hscrollbar);
1710 child_allocation.x = relative_allocation.x;
1711 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1712 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1713 child_allocation.y = (relative_allocation.y +
1714 relative_allocation.height +
1716 (priv->shadow_type == GTK_SHADOW_NONE ?
1717 0 : style->ythickness));
1719 child_allocation.y = 0;
1721 child_allocation.width = relative_allocation.width;
1722 child_allocation.height = sb_height;
1723 child_allocation.x += allocation->x;
1724 child_allocation.y += allocation->y;
1726 if (priv->shadow_type != GTK_SHADOW_NONE)
1728 if (!scrollbars_within_bevel)
1730 child_allocation.x -= style->xthickness;
1731 child_allocation.width += 2 * style->xthickness;
1733 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1734 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1736 child_allocation.y -= style->ythickness;
1740 child_allocation.y += style->ythickness;
1744 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1746 else if (gtk_widget_get_visible (priv->hscrollbar))
1747 gtk_widget_hide (priv->hscrollbar);
1749 if (priv->vscrollbar_visible)
1751 if (!gtk_widget_get_visible (priv->vscrollbar))
1752 gtk_widget_show (priv->vscrollbar);
1754 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1755 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1756 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1757 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1758 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1759 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1760 child_allocation.x = (relative_allocation.x +
1761 relative_allocation.width +
1763 (priv->shadow_type == GTK_SHADOW_NONE ?
1764 0 : style->xthickness));
1766 child_allocation.x = 0;
1768 child_allocation.y = relative_allocation.y;
1769 child_allocation.width = sb_width;
1770 child_allocation.height = relative_allocation.height;
1771 child_allocation.x += allocation->x;
1772 child_allocation.y += allocation->y;
1774 if (priv->shadow_type != GTK_SHADOW_NONE)
1776 if (!scrollbars_within_bevel)
1778 child_allocation.y -= style->ythickness;
1779 child_allocation.height += 2 * style->ythickness;
1781 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1782 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1784 child_allocation.x -= style->xthickness;
1788 child_allocation.x += style->xthickness;
1792 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1794 else if (gtk_widget_get_visible (priv->vscrollbar))
1795 gtk_widget_hide (priv->vscrollbar);
1799 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1800 GdkEventScroll *event)
1802 GtkScrolledWindowPrivate *priv;
1803 GtkScrolledWindow *scrolled_window;
1806 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1807 g_return_val_if_fail (event != NULL, FALSE);
1809 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1810 priv = scrolled_window->priv;
1812 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1813 range = priv->vscrollbar;
1815 range = priv->hscrollbar;
1817 if (range && gtk_widget_get_visible (range))
1819 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1822 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1824 gtk_adjustment_set_value (adj, adj->value + delta);
1833 gtk_scrolled_window_focus (GtkWidget *widget,
1834 GtkDirectionType direction)
1836 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1837 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1839 gboolean had_focus_child;
1841 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1843 if (priv->focus_out)
1845 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1849 if (gtk_widget_is_focus (widget))
1852 /* We only put the scrolled window itself in the focus chain if it
1853 * isn't possible to focus any children.
1855 child = gtk_bin_get_child (GTK_BIN (widget));
1858 if (gtk_widget_child_focus (child, direction))
1862 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1864 gtk_widget_grab_focus (widget);
1872 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1875 GtkScrolledWindowPrivate *priv;;
1876 GtkScrolledWindow *scrolled_window;
1878 g_return_if_fail (adjustment != NULL);
1879 g_return_if_fail (data != NULL);
1881 scrolled_window = GTK_SCROLLED_WINDOW (data);
1882 priv = scrolled_window->priv;
1884 if (priv->hscrollbar &&
1885 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1887 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1891 visible = priv->hscrollbar_visible;
1892 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1893 adjustment->page_size);
1894 if (priv->hscrollbar_visible != visible)
1896 priv->trust_sb_visibility = TRUE;
1897 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1901 else if (priv->vscrollbar &&
1902 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1904 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1908 visible = priv->vscrollbar_visible;
1909 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1910 adjustment->page_size);
1911 if (priv->vscrollbar_visible != visible)
1913 priv->trust_sb_visibility = TRUE;
1914 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1921 gtk_scrolled_window_add (GtkContainer *container,
1924 GtkScrolledWindowPrivate *priv;
1925 GtkScrolledWindow *scrolled_window;
1927 GtkWidget *child_widget;
1928 GtkAdjustment *hadj, *vadj;
1930 bin = GTK_BIN (container);
1931 child_widget = gtk_bin_get_child (bin);
1932 g_return_if_fail (child_widget == NULL);
1934 scrolled_window = GTK_SCROLLED_WINDOW (container);
1935 priv = scrolled_window->priv;
1937 _gtk_bin_set_child (bin, child);
1938 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1940 hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar));
1941 vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar));
1943 if (GTK_IS_SCROLLABLE (child))
1944 g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL);
1946 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1947 "use gtk_scrolled_window_add_with_viewport() instead");
1951 gtk_scrolled_window_remove (GtkContainer *container,
1954 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1955 g_return_if_fail (child != NULL);
1956 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1958 g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
1960 /* chain parent class handler to remove child */
1961 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1965 * gtk_scrolled_window_add_with_viewport:
1966 * @scrolled_window: a #GtkScrolledWindow
1967 * @child: the widget you want to scroll
1969 * Used to add children without native scrolling capabilities. This
1970 * is simply a convenience function; it is equivalent to adding the
1971 * unscrollable child to a viewport, then adding the viewport to the
1972 * scrolled window. If a child has native scrolling, use
1973 * gtk_container_add() instead of this function.
1975 * The viewport scrolls the child by moving its #GdkWindow, and takes
1976 * the size of the child to be the size of its toplevel #GdkWindow.
1977 * This will be very wrong for most widgets that support native scrolling;
1978 * for example, if you add a widget such as #GtkTreeView with a viewport,
1979 * the whole widget will scroll, including the column headings. Thus,
1980 * widgets with native scrolling support should not be used with the
1981 * #GtkViewport proxy.
1983 * A widget supports scrolling natively if it implements the
1984 * #GtkScrollable interface.
1987 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1991 GtkWidget *viewport;
1992 GtkWidget *child_widget;
1994 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1995 g_return_if_fail (GTK_IS_WIDGET (child));
1996 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1998 bin = GTK_BIN (scrolled_window);
1999 child_widget = gtk_bin_get_child (bin);
2003 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
2004 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
2006 viewport = child_widget;
2011 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
2012 gtk_scrolled_window_get_vadjustment (scrolled_window));
2013 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
2016 gtk_widget_show (viewport);
2017 gtk_container_add (GTK_CONTAINER (viewport), child);
2021 * _gtk_scrolled_window_get_spacing:
2022 * @scrolled_window: a scrolled window
2024 * Gets the spacing between the scrolled window's scrollbars and
2025 * the scrolled widget. Used by GtkCombo
2027 * Return value: the spacing, in pixels.
2030 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
2032 GtkScrolledWindowClass *class;
2034 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2036 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
2038 if (class->scrollbar_spacing >= 0)
2039 return class->scrollbar_spacing;
2042 gint scrollbar_spacing;
2044 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
2045 "scrollbar-spacing", &scrollbar_spacing,
2048 return scrollbar_spacing;
2054 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
2055 GtkOrientation orientation,
2059 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
2060 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
2061 GtkBin *bin = GTK_BIN (scrolled_window);
2064 gint scrollbar_spacing;
2065 GtkRequisition hscrollbar_requisition;
2066 GtkRequisition vscrollbar_requisition;
2067 GtkRequisition minimum_req, natural_req;
2070 gint min_child_size, nat_child_size;
2072 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
2076 minimum_req.width = 0;
2077 minimum_req.height = 0;
2078 natural_req.width = 0;
2079 natural_req.height = 0;
2081 gtk_widget_get_preferred_size (priv->hscrollbar,
2082 &hscrollbar_requisition, NULL);
2083 gtk_widget_get_preferred_size (priv->vscrollbar,
2084 &vscrollbar_requisition, NULL);
2086 child = gtk_bin_get_child (bin);
2087 if (child && gtk_widget_get_visible (child))
2089 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2091 gtk_widget_get_preferred_width (child,
2095 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2097 minimum_req.width += min_child_size;
2098 natural_req.width += nat_child_size;
2102 gint min_content_width = priv->min_content_width;
2104 if (min_content_width >= 0)
2106 minimum_req.width = MAX (minimum_req.width, min_content_width);
2107 natural_req.width = MAX (natural_req.width, min_content_width);
2112 minimum_req.width += vscrollbar_requisition.width;
2113 natural_req.width += vscrollbar_requisition.width;
2117 else /* GTK_ORIENTATION_VERTICAL */
2119 gtk_widget_get_preferred_height (child,
2123 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2125 minimum_req.height += min_child_size;
2126 natural_req.height += nat_child_size;
2130 gint min_content_height = priv->min_content_height;
2132 if (min_content_height >= 0)
2134 minimum_req.height = MAX (minimum_req.height, min_content_height);
2135 natural_req.height = MAX (natural_req.height, min_content_height);
2140 minimum_req.height += vscrollbar_requisition.height;
2141 natural_req.height += vscrollbar_requisition.height;
2147 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2148 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2150 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2151 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2152 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2153 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2156 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2157 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2159 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2160 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2161 if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2162 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2165 minimum_req.width += MAX (0, extra_width);
2166 minimum_req.height += MAX (0, extra_height);
2167 natural_req.width += MAX (0, extra_width);
2168 natural_req.height += MAX (0, extra_height);
2170 if (priv->shadow_type != GTK_SHADOW_NONE)
2172 style = gtk_widget_get_style (GTK_WIDGET (widget));
2173 minimum_req.width += 2 * style->xthickness;
2174 minimum_req.height += 2 * style->ythickness;
2175 natural_req.width += 2 * style->xthickness;
2176 natural_req.height += 2 * style->ythickness;
2179 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2182 *minimum_size = minimum_req.width;
2184 *natural_size = natural_req.width;
2189 *minimum_size = minimum_req.height;
2191 *natural_size = natural_req.height;
2196 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2200 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2204 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2208 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2212 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2214 gint *minimum_height,
2215 gint *natural_height)
2217 g_return_if_fail (GTK_IS_WIDGET (widget));
2219 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2223 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2225 gint *minimum_width,
2226 gint *natural_width)
2228 g_return_if_fail (GTK_IS_WIDGET (widget));
2230 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
2234 * gtk_scrolled_window_get_min_content_width:
2235 * @scrolled_window: a #GtkScrolledWindow
2237 * Gets the minimum content width of @scrolled_window, or -1 if not set.
2239 * Returns: the minimum content width
2244 gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
2246 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2248 return scrolled_window->priv->min_content_width;
2252 * gtk_scrolled_window_set_min_content_width:
2253 * @scrolled_window: a #GtkScrolledWindow
2254 * @width: the minimal content width
2256 * Sets the minimum width that @scrolled_window should keep visible.
2257 * Note that this can and (usually will) be smaller than the minimum
2258 * size of the content.
2263 gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
2266 GtkScrolledWindowPrivate *priv;
2268 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2270 priv = scrolled_window->priv;
2272 if (priv->min_content_width != width)
2274 priv->min_content_width = width;
2276 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2278 g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
2283 * gtk_scrolled_window_get_min_content_height:
2284 * @scrolled_window: a #GtkScrolledWindow
2286 * Gets the minimal content height of @scrolled_window, or -1 if not set.
2288 * Returns: the minimal content height
2293 gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
2295 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2297 return scrolled_window->priv->min_content_height;
2301 * gtk_scrolled_window_set_min_content_height:
2302 * @scrolled_window: a #GtkScrolledWindow
2303 * @height: the minimal content height
2305 * Sets the minimum height that @scrolled_window should keep visible.
2306 * Note that this can and (usually will) be smaller than the minimum
2307 * size of the content.
2312 gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
2315 GtkScrolledWindowPrivate *priv;
2317 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2319 priv = scrolled_window->priv;
2321 if (priv->min_content_height != height)
2323 priv->min_content_height = height;
2325 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2327 g_object_notify (G_OBJECT (scrolled_window), "min-content-height");