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 inside_allocate : 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;
495 * gtk_scrolled_window_new:
496 * @hadjustment: (allow-none): horizontal adjustment
497 * @vadjustment: (allow-none): vertical adjustment
499 * Creates a new scrolled window.
501 * The two arguments are the scrolled window's adjustments; these will be
502 * shared with the scrollbars and the child widget to keep the bars in sync
503 * with the child. Usually you want to pass %NULL for the adjustments, which
504 * will cause the scrolled window to create them for you.
506 * Returns: a new scrolled window
509 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
510 GtkAdjustment *vadjustment)
512 GtkWidget *scrolled_window;
515 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
518 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
520 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
521 "hadjustment", hadjustment,
522 "vadjustment", vadjustment,
525 return scrolled_window;
529 * gtk_scrolled_window_set_hadjustment:
530 * @scrolled_window: a #GtkScrolledWindow
531 * @hadjustment: horizontal scroll adjustment
533 * Sets the #GtkAdjustment for the horizontal scrollbar.
536 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
537 GtkAdjustment *hadjustment)
539 GtkScrolledWindowPrivate *priv;
543 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
545 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
547 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
549 bin = GTK_BIN (scrolled_window);
550 priv = scrolled_window->priv;
552 if (!priv->hscrollbar)
554 gtk_widget_push_composite_child ();
555 priv->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
556 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
557 gtk_widget_pop_composite_child ();
559 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
560 g_object_ref (priv->hscrollbar);
561 gtk_widget_show (priv->hscrollbar);
565 GtkAdjustment *old_adjustment;
567 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
568 if (old_adjustment == hadjustment)
571 g_signal_handlers_disconnect_by_func (old_adjustment,
572 gtk_scrolled_window_adjustment_changed,
574 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
577 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
578 g_signal_connect (hadjustment,
580 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
582 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
584 child = gtk_bin_get_child (bin);
585 if (GTK_IS_SCROLLABLE (child))
586 gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (child), hadjustment);
588 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
592 * gtk_scrolled_window_set_vadjustment:
593 * @scrolled_window: a #GtkScrolledWindow
594 * @vadjustment: vertical scroll adjustment
596 * Sets the #GtkAdjustment for the vertical scrollbar.
599 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
600 GtkAdjustment *vadjustment)
602 GtkScrolledWindowPrivate *priv;
606 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
608 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
610 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
612 bin = GTK_BIN (scrolled_window);
613 priv = scrolled_window->priv;
615 if (!priv->vscrollbar)
617 gtk_widget_push_composite_child ();
618 priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
619 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
620 gtk_widget_pop_composite_child ();
622 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
623 g_object_ref (priv->vscrollbar);
624 gtk_widget_show (priv->vscrollbar);
628 GtkAdjustment *old_adjustment;
630 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
631 if (old_adjustment == vadjustment)
634 g_signal_handlers_disconnect_by_func (old_adjustment,
635 gtk_scrolled_window_adjustment_changed,
637 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
640 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
641 g_signal_connect (vadjustment,
643 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
645 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
647 child = gtk_bin_get_child (bin);
648 if (GTK_IS_SCROLLABLE (child))
649 gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (child), vadjustment);
651 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
655 * gtk_scrolled_window_get_hadjustment:
656 * @scrolled_window: a #GtkScrolledWindow
658 * Returns the horizontal scrollbar's adjustment, used to connect the
659 * horizontal scrollbar to the child widget's horizontal scroll
662 * Returns: (transfer none): the horizontal #GtkAdjustment
665 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
667 GtkScrolledWindowPrivate *priv;
669 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
671 priv = scrolled_window->priv;
673 return (priv->hscrollbar ?
674 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
679 * gtk_scrolled_window_get_vadjustment:
680 * @scrolled_window: a #GtkScrolledWindow
682 * Returns the vertical scrollbar's adjustment, used to connect the
683 * vertical scrollbar to the child widget's vertical scroll functionality.
685 * Returns: (transfer none): the vertical #GtkAdjustment
688 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
690 GtkScrolledWindowPrivate *priv;
692 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
694 priv = scrolled_window->priv;
696 return (priv->vscrollbar ?
697 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
702 * gtk_scrolled_window_get_hscrollbar:
703 * @scrolled_window: a #GtkScrolledWindow
705 * Returns the horizontal scrollbar of @scrolled_window.
707 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
708 * or %NULL if it does not have one.
713 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
715 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
717 return scrolled_window->priv->hscrollbar;
721 * gtk_scrolled_window_get_vscrollbar:
722 * @scrolled_window: a #GtkScrolledWindow
724 * Returns the vertical scrollbar of @scrolled_window.
726 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
727 * or %NULL if it does not have one.
732 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
734 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
736 return scrolled_window->priv->vscrollbar;
740 * gtk_scrolled_window_set_policy:
741 * @scrolled_window: a #GtkScrolledWindow
742 * @hscrollbar_policy: policy for horizontal bar
743 * @vscrollbar_policy: policy for vertical bar
745 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
747 * The policy determines when the scrollbar should appear; it is a value
748 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
749 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
750 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
751 * if needed (that is, if the slider part of the bar would be smaller
752 * than the trough - the display is larger than the page size).
755 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
756 GtkPolicyType hscrollbar_policy,
757 GtkPolicyType vscrollbar_policy)
759 GtkScrolledWindowPrivate *priv;
760 GObject *object = G_OBJECT (scrolled_window);
762 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
764 priv = scrolled_window->priv;
766 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
767 (priv->vscrollbar_policy != vscrollbar_policy))
769 priv->hscrollbar_policy = hscrollbar_policy;
770 priv->vscrollbar_policy = vscrollbar_policy;
772 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
774 g_object_freeze_notify (object);
775 g_object_notify (object, "hscrollbar-policy");
776 g_object_notify (object, "vscrollbar-policy");
777 g_object_thaw_notify (object);
782 * gtk_scrolled_window_get_policy:
783 * @scrolled_window: a #GtkScrolledWindow
784 * @hscrollbar_policy: location to store the policy for the horizontal
785 * scrollbar, or %NULL.
786 * @vscrollbar_policy: location to store the policy for the vertical
787 * scrollbar, or %NULL.
789 * Retrieves the current policy values for the horizontal and vertical
790 * scrollbars. See gtk_scrolled_window_set_policy().
793 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
794 GtkPolicyType *hscrollbar_policy,
795 GtkPolicyType *vscrollbar_policy)
797 GtkScrolledWindowPrivate *priv;
799 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
801 priv = scrolled_window->priv;
803 if (hscrollbar_policy)
804 *hscrollbar_policy = priv->hscrollbar_policy;
805 if (vscrollbar_policy)
806 *vscrollbar_policy = priv->vscrollbar_policy;
810 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
812 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
813 GtkSettings *settings;
815 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
817 if (priv->window_placement_set || settings == NULL)
818 priv->real_window_placement = priv->window_placement;
820 g_object_get (settings,
821 "gtk-scrolled-window-placement",
822 &priv->real_window_placement,
827 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
828 GtkCornerType window_placement)
830 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
832 if (priv->window_placement != window_placement)
834 priv->window_placement = window_placement;
836 gtk_scrolled_window_update_real_placement (scrolled_window);
837 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
839 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
844 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
845 gboolean placement_set,
846 gboolean emit_resize)
848 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
850 if (priv->window_placement_set != placement_set)
852 priv->window_placement_set = placement_set;
854 gtk_scrolled_window_update_real_placement (scrolled_window);
856 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
858 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
863 * gtk_scrolled_window_set_placement:
864 * @scrolled_window: a #GtkScrolledWindow
865 * @window_placement: position of the child window
867 * Sets the placement of the contents with respect to the scrollbars
868 * for the scrolled window.
870 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
871 * in the top left, with the scrollbars underneath and to the right.
872 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
873 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
875 * See also gtk_scrolled_window_get_placement() and
876 * gtk_scrolled_window_unset_placement().
879 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
880 GtkCornerType window_placement)
882 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
884 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
885 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
889 * gtk_scrolled_window_get_placement:
890 * @scrolled_window: a #GtkScrolledWindow
892 * Gets the placement of the contents with respect to the scrollbars
893 * for the scrolled window. See gtk_scrolled_window_set_placement().
895 * Return value: the current placement value.
897 * See also gtk_scrolled_window_set_placement() and
898 * gtk_scrolled_window_unset_placement().
901 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
903 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
905 return scrolled_window->priv->window_placement;
909 * gtk_scrolled_window_unset_placement:
910 * @scrolled_window: a #GtkScrolledWindow
912 * Unsets the placement of the contents with respect to the scrollbars
913 * for the scrolled window. If no window placement is set for a scrolled
914 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
916 * See also gtk_scrolled_window_set_placement() and
917 * gtk_scrolled_window_get_placement().
922 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
924 GtkScrolledWindowPrivate *priv;
926 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
928 priv = scrolled_window->priv;
930 if (priv->window_placement_set)
932 priv->window_placement_set = FALSE;
934 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
936 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
941 * gtk_scrolled_window_set_shadow_type:
942 * @scrolled_window: a #GtkScrolledWindow
943 * @type: kind of shadow to draw around scrolled window contents
945 * Changes the type of shadow drawn around the contents of
950 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
953 GtkScrolledWindowPrivate *priv;
955 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
956 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
958 priv = scrolled_window->priv;
960 if (priv->shadow_type != type)
962 priv->shadow_type = type;
964 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
965 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
967 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
969 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
974 * gtk_scrolled_window_get_shadow_type:
975 * @scrolled_window: a #GtkScrolledWindow
977 * Gets the shadow type of the scrolled window. See
978 * gtk_scrolled_window_set_shadow_type().
980 * Return value: the current shadow type
983 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
985 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
987 return scrolled_window->priv->shadow_type;
991 gtk_scrolled_window_destroy (GtkWidget *widget)
993 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
994 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
996 if (priv->hscrollbar)
998 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
999 gtk_scrolled_window_adjustment_changed,
1001 gtk_widget_unparent (priv->hscrollbar);
1002 gtk_widget_destroy (priv->hscrollbar);
1003 g_object_unref (priv->hscrollbar);
1004 priv->hscrollbar = NULL;
1006 if (priv->vscrollbar)
1008 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
1009 gtk_scrolled_window_adjustment_changed,
1011 gtk_widget_unparent (priv->vscrollbar);
1012 gtk_widget_destroy (priv->vscrollbar);
1013 g_object_unref (priv->vscrollbar);
1014 priv->vscrollbar = NULL;
1017 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
1021 gtk_scrolled_window_set_property (GObject *object,
1023 const GValue *value,
1026 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1027 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1031 case PROP_HADJUSTMENT:
1032 gtk_scrolled_window_set_hadjustment (scrolled_window,
1033 g_value_get_object (value));
1035 case PROP_VADJUSTMENT:
1036 gtk_scrolled_window_set_vadjustment (scrolled_window,
1037 g_value_get_object (value));
1039 case PROP_HSCROLLBAR_POLICY:
1040 gtk_scrolled_window_set_policy (scrolled_window,
1041 g_value_get_enum (value),
1042 priv->vscrollbar_policy);
1044 case PROP_VSCROLLBAR_POLICY:
1045 gtk_scrolled_window_set_policy (scrolled_window,
1046 priv->hscrollbar_policy,
1047 g_value_get_enum (value));
1049 case PROP_WINDOW_PLACEMENT:
1050 gtk_scrolled_window_set_placement_internal (scrolled_window,
1051 g_value_get_enum (value));
1053 case PROP_WINDOW_PLACEMENT_SET:
1054 gtk_scrolled_window_set_placement_set (scrolled_window,
1055 g_value_get_boolean (value),
1058 case PROP_SHADOW_TYPE:
1059 gtk_scrolled_window_set_shadow_type (scrolled_window,
1060 g_value_get_enum (value));
1062 case PROP_MIN_CONTENT_WIDTH:
1063 gtk_scrolled_window_set_min_content_width (scrolled_window,
1064 g_value_get_int (value));
1066 case PROP_MIN_CONTENT_HEIGHT:
1067 gtk_scrolled_window_set_min_content_height (scrolled_window,
1068 g_value_get_int (value));
1071 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1077 gtk_scrolled_window_get_property (GObject *object,
1082 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
1083 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1087 case PROP_HADJUSTMENT:
1088 g_value_set_object (value,
1089 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1091 case PROP_VADJUSTMENT:
1092 g_value_set_object (value,
1093 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1095 case PROP_WINDOW_PLACEMENT:
1096 g_value_set_enum (value, priv->window_placement);
1098 case PROP_WINDOW_PLACEMENT_SET:
1099 g_value_set_boolean (value, priv->window_placement_set);
1101 case PROP_SHADOW_TYPE:
1102 g_value_set_enum (value, priv->shadow_type);
1104 case PROP_HSCROLLBAR_POLICY:
1105 g_value_set_enum (value, priv->hscrollbar_policy);
1107 case PROP_VSCROLLBAR_POLICY:
1108 g_value_set_enum (value, priv->vscrollbar_policy);
1110 case PROP_MIN_CONTENT_WIDTH:
1111 g_value_set_int (value, priv->min_content_width);
1113 case PROP_MIN_CONTENT_HEIGHT:
1114 g_value_set_int (value, priv->min_content_height);
1117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1123 traverse_container (GtkWidget *widget,
1126 if (GTK_IS_SCROLLED_WINDOW (widget))
1128 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1129 gtk_widget_queue_resize (widget);
1131 else if (GTK_IS_CONTAINER (widget))
1132 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1136 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1140 list = gtk_window_list_toplevels ();
1142 for (l = list; l; l = l->next)
1143 gtk_container_forall (GTK_CONTAINER (l->data),
1144 traverse_container, NULL);
1150 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1151 GdkScreen *previous_screen)
1153 GtkSettings *settings;
1154 guint window_placement_connection;
1156 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1158 if (!gtk_widget_has_screen (widget))
1161 settings = gtk_widget_get_settings (widget);
1163 window_placement_connection =
1164 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1165 "gtk-scrolled-window-connection"));
1167 if (window_placement_connection)
1170 window_placement_connection =
1171 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1172 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1173 g_object_set_data (G_OBJECT (settings),
1174 I_("gtk-scrolled-window-connection"),
1175 GUINT_TO_POINTER (window_placement_connection));
1179 gtk_scrolled_window_draw (GtkWidget *widget,
1182 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1183 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1185 if (priv->shadow_type != GTK_SHADOW_NONE)
1187 GtkAllocation relative_allocation;
1189 gboolean scrollbars_within_bevel;
1191 style = gtk_widget_get_style (widget);
1192 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1194 if (!scrollbars_within_bevel)
1196 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1198 relative_allocation.x -= style->xthickness;
1199 relative_allocation.y -= style->ythickness;
1200 relative_allocation.width += 2 * style->xthickness;
1201 relative_allocation.height += 2 * style->ythickness;
1205 relative_allocation.x = 0;
1206 relative_allocation.y = 0;
1207 relative_allocation.width = gtk_widget_get_allocated_width (widget);
1208 relative_allocation.height = gtk_widget_get_allocated_height (widget);
1211 gtk_paint_shadow (style,
1213 GTK_STATE_NORMAL, priv->shadow_type,
1214 widget, "scrolled_window",
1215 relative_allocation.x,
1216 relative_allocation.y,
1217 relative_allocation.width,
1218 relative_allocation.height);
1221 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
1227 gtk_scrolled_window_forall (GtkContainer *container,
1228 gboolean include_internals,
1229 GtkCallback callback,
1230 gpointer callback_data)
1232 GtkScrolledWindowPrivate *priv;
1233 GtkScrolledWindow *scrolled_window;
1235 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1236 g_return_if_fail (callback != NULL);
1238 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1242 if (include_internals)
1244 scrolled_window = GTK_SCROLLED_WINDOW (container);
1245 priv = scrolled_window->priv;
1247 if (priv->vscrollbar)
1248 callback (priv->vscrollbar, callback_data);
1249 if (priv->hscrollbar)
1250 callback (priv->hscrollbar, callback_data);
1255 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1256 GtkScrollType scroll,
1257 gboolean horizontal)
1259 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1260 GtkAdjustment *adjustment = NULL;
1264 case GTK_SCROLL_STEP_UP:
1265 scroll = GTK_SCROLL_STEP_BACKWARD;
1268 case GTK_SCROLL_STEP_DOWN:
1269 scroll = GTK_SCROLL_STEP_FORWARD;
1272 case GTK_SCROLL_STEP_LEFT:
1273 scroll = GTK_SCROLL_STEP_BACKWARD;
1276 case GTK_SCROLL_STEP_RIGHT:
1277 scroll = GTK_SCROLL_STEP_FORWARD;
1280 case GTK_SCROLL_PAGE_UP:
1281 scroll = GTK_SCROLL_PAGE_BACKWARD;
1284 case GTK_SCROLL_PAGE_DOWN:
1285 scroll = GTK_SCROLL_PAGE_FORWARD;
1288 case GTK_SCROLL_PAGE_LEFT:
1289 scroll = GTK_SCROLL_STEP_BACKWARD;
1292 case GTK_SCROLL_PAGE_RIGHT:
1293 scroll = GTK_SCROLL_STEP_FORWARD;
1296 case GTK_SCROLL_STEP_BACKWARD:
1297 case GTK_SCROLL_STEP_FORWARD:
1298 case GTK_SCROLL_PAGE_BACKWARD:
1299 case GTK_SCROLL_PAGE_FORWARD:
1300 case GTK_SCROLL_START:
1301 case GTK_SCROLL_END:
1304 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1308 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1309 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1314 if (priv->hscrollbar)
1315 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1319 if (priv->vscrollbar)
1320 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1325 gdouble value = adjustment->value;
1329 case GTK_SCROLL_STEP_FORWARD:
1330 value += adjustment->step_increment;
1332 case GTK_SCROLL_STEP_BACKWARD:
1333 value -= adjustment->step_increment;
1335 case GTK_SCROLL_PAGE_FORWARD:
1336 value += adjustment->page_increment;
1338 case GTK_SCROLL_PAGE_BACKWARD:
1339 value -= adjustment->page_increment;
1341 case GTK_SCROLL_START:
1342 value = adjustment->lower;
1344 case GTK_SCROLL_END:
1345 value = adjustment->upper;
1348 g_assert_not_reached ();
1352 gtk_adjustment_set_value (adjustment, value);
1361 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1362 GtkDirectionType direction_type)
1364 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1365 GtkWidget *toplevel;
1367 /* Focus out of the scrolled window entirely. We do this by setting
1368 * a flag, then propagating the focus motion to the notebook.
1370 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1371 if (!gtk_widget_is_toplevel (toplevel))
1374 g_object_ref (scrolled_window);
1376 priv->focus_out = TRUE;
1377 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1378 priv->focus_out = FALSE;
1380 g_object_unref (scrolled_window);
1384 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1385 GtkAllocation *allocation)
1387 GtkAllocation widget_allocation;
1388 GtkScrolledWindow *scrolled_window;
1389 GtkScrolledWindowPrivate *priv;
1395 g_return_if_fail (widget != NULL);
1396 g_return_if_fail (allocation != NULL);
1398 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1399 priv = scrolled_window->priv;
1401 /* Get possible scrollbar dimensions */
1402 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1403 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1404 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1406 /* Subtract some things from our available allocation size */
1410 if (priv->shadow_type != GTK_SHADOW_NONE)
1412 style = gtk_widget_get_style (widget);
1413 allocation->x += style->xthickness;
1414 allocation->y += style->ythickness;
1417 gtk_widget_get_allocation (widget, &widget_allocation);
1418 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1419 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1421 if (priv->vscrollbar_visible)
1425 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1428 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1429 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1431 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1432 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1433 allocation->x += (sb_width + sb_spacing);
1435 allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
1437 if (priv->hscrollbar_visible)
1440 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1441 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1442 allocation->y += (sb_height + sb_spacing);
1444 allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
1449 gtk_scrolled_window_allocate_child (GtkScrolledWindow *swindow,
1450 GtkAllocation *relative_allocation)
1452 GtkScrolledWindowPrivate *priv = swindow->priv;
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 priv->inside_allocate = TRUE;
1468 gtk_widget_size_allocate (child, &child_allocation);
1469 priv->inside_allocate = FALSE;
1473 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1474 GtkAllocation *allocation)
1476 GtkScrolledWindow *scrolled_window;
1477 GtkScrolledWindowPrivate *priv;
1480 GtkAllocation relative_allocation;
1481 GtkAllocation child_allocation;
1483 gboolean scrollbars_within_bevel;
1488 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1489 g_return_if_fail (allocation != NULL);
1491 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1492 bin = GTK_BIN (scrolled_window);
1493 priv = scrolled_window->priv;
1495 /* Get possible scrollbar dimensions */
1496 sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1497 gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
1498 gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
1500 style = gtk_widget_get_style (widget);
1501 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1503 gtk_widget_set_allocation (widget, allocation);
1505 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1506 priv->hscrollbar_visible = TRUE;
1507 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1508 priv->hscrollbar_visible = FALSE;
1509 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1510 priv->vscrollbar_visible = TRUE;
1511 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1512 priv->vscrollbar_visible = FALSE;
1514 child = gtk_bin_get_child (bin);
1515 if (child && gtk_widget_get_visible (child))
1517 gint child_scroll_width;
1518 gint child_scroll_height;
1519 gboolean previous_hvis;
1520 gboolean previous_vvis;
1523 /* Determine scrollbar visibility first via hfw apis */
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 fit the height
1534 * given the extra width of the scrollbar */
1535 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1536 gtk_widget_get_preferred_height_for_width (child,
1537 MAX (allocation->width, child_scroll_width),
1538 &child_scroll_height, NULL);
1540 gtk_widget_get_preferred_height_for_width (child,
1541 MAX (allocation->width, child_scroll_width),
1542 NULL, &child_scroll_height);
1544 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1546 /* Does the content height fit the allocation height ? */
1547 priv->vscrollbar_visible = child_scroll_height > allocation->height;
1549 /* Does the content width fit the allocation with minus a possible scrollbar ? */
1550 priv->hscrollbar_visible =
1551 child_scroll_width > allocation->width -
1552 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1554 /* Now that we've guessed the hscrollbar, does the content height fit
1555 * the possible new allocation height ? */
1556 priv->vscrollbar_visible =
1557 child_scroll_height > allocation->height -
1558 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1560 /* Now that we've guessed the vscrollbar, does the content width fit
1561 * the possible new allocation width ? */
1562 priv->hscrollbar_visible =
1563 child_scroll_width > allocation->width -
1564 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1566 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1568 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1569 priv->vscrollbar_visible = child_scroll_height > allocation->height -
1570 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1573 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1575 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1577 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1578 priv->hscrollbar_visible =
1579 child_scroll_width > allocation->width -
1580 (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
1582 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1585 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
1587 if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1588 gtk_widget_get_preferred_height (child, &child_scroll_height, NULL);
1590 gtk_widget_get_preferred_height (child, NULL, &child_scroll_height);
1592 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1594 /* First try without a horizontal scrollbar if the content will fit the width
1595 * given the extra height of the scrollbar */
1596 if (gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (child)) == GTK_SCROLL_MINIMUM)
1597 gtk_widget_get_preferred_width_for_height (child,
1598 MAX (allocation->height, child_scroll_height),
1599 &child_scroll_width, NULL);
1601 gtk_widget_get_preferred_width_for_height (child,
1602 MAX (allocation->height, child_scroll_height),
1603 NULL, &child_scroll_width);
1605 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1607 /* Does the content width fit the allocation width ? */
1608 priv->hscrollbar_visible = child_scroll_width > allocation->width;
1610 /* Does the content height fit the allocation with minus a possible scrollbar ? */
1611 priv->vscrollbar_visible =
1612 child_scroll_height > allocation->height -
1613 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1615 /* Now that we've guessed the vscrollbar, does the content width fit
1616 * the possible new allocation width ? */
1617 priv->hscrollbar_visible =
1618 child_scroll_width > allocation->width -
1619 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1621 /* Now that we've guessed the hscrollbar, does the content height fit
1622 * the possible new allocation height ? */
1623 priv->vscrollbar_visible =
1624 child_scroll_height > allocation->height -
1625 (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
1627 else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
1629 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1630 priv->hscrollbar_visible = child_scroll_width > allocation->width -
1631 (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
1634 else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
1636 priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
1638 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1639 priv->vscrollbar_visible =
1640 child_scroll_height > allocation->height -
1641 (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
1643 priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
1647 /* Now after guessing scrollbar visibility; fall back on the allocation loop which
1648 * observes the adjustments to detect scrollbar visibility and also avoids
1649 * infinite recursion
1653 previous_hvis = priv->hscrollbar_visible;
1654 previous_vvis = priv->vscrollbar_visible;
1655 gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
1657 /* If, after the first iteration, the hscrollbar and the
1658 * vscrollbar flip visiblity, then we need both.
1661 previous_hvis != priv->hscrollbar_visible &&
1662 previous_vvis != priv->vscrollbar_visible)
1664 priv->hscrollbar_visible = TRUE;
1665 priv->vscrollbar_visible = TRUE;
1667 gtk_scrolled_window_allocate_child (scrolled_window, &relative_allocation);
1674 while (previous_hvis != priv->hscrollbar_visible ||
1675 previous_vvis != priv->vscrollbar_visible);
1679 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1680 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1681 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1684 if (priv->hscrollbar_visible)
1686 if (!gtk_widget_get_visible (priv->hscrollbar))
1687 gtk_widget_show (priv->hscrollbar);
1689 child_allocation.x = relative_allocation.x;
1690 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1691 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1692 child_allocation.y = (relative_allocation.y +
1693 relative_allocation.height +
1695 (priv->shadow_type == GTK_SHADOW_NONE ?
1696 0 : style->ythickness));
1698 child_allocation.y = 0;
1700 child_allocation.width = relative_allocation.width;
1701 child_allocation.height = sb_height;
1702 child_allocation.x += allocation->x;
1703 child_allocation.y += allocation->y;
1705 if (priv->shadow_type != GTK_SHADOW_NONE)
1707 if (!scrollbars_within_bevel)
1709 child_allocation.x -= style->xthickness;
1710 child_allocation.width += 2 * style->xthickness;
1712 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1713 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1715 child_allocation.y -= style->ythickness;
1719 child_allocation.y += style->ythickness;
1723 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1725 else if (gtk_widget_get_visible (priv->hscrollbar))
1726 gtk_widget_hide (priv->hscrollbar);
1728 if (priv->vscrollbar_visible)
1730 if (!gtk_widget_get_visible (priv->vscrollbar))
1731 gtk_widget_show (priv->vscrollbar);
1733 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1734 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1735 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1736 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1737 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1738 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1739 child_allocation.x = (relative_allocation.x +
1740 relative_allocation.width +
1742 (priv->shadow_type == GTK_SHADOW_NONE ?
1743 0 : style->xthickness));
1745 child_allocation.x = 0;
1747 child_allocation.y = relative_allocation.y;
1748 child_allocation.width = sb_width;
1749 child_allocation.height = relative_allocation.height;
1750 child_allocation.x += allocation->x;
1751 child_allocation.y += allocation->y;
1753 if (priv->shadow_type != GTK_SHADOW_NONE)
1755 if (!scrollbars_within_bevel)
1757 child_allocation.y -= style->ythickness;
1758 child_allocation.height += 2 * style->ythickness;
1760 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1761 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1763 child_allocation.x -= style->xthickness;
1767 child_allocation.x += style->xthickness;
1771 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1773 else if (gtk_widget_get_visible (priv->vscrollbar))
1774 gtk_widget_hide (priv->vscrollbar);
1778 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1779 GdkEventScroll *event)
1781 GtkScrolledWindowPrivate *priv;
1782 GtkScrolledWindow *scrolled_window;
1785 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1786 g_return_val_if_fail (event != NULL, FALSE);
1788 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1789 priv = scrolled_window->priv;
1791 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1792 range = priv->vscrollbar;
1794 range = priv->hscrollbar;
1796 if (range && gtk_widget_get_visible (range))
1798 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1801 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1803 gtk_adjustment_set_value (adj, adj->value + delta);
1812 gtk_scrolled_window_focus (GtkWidget *widget,
1813 GtkDirectionType direction)
1815 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1816 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1818 gboolean had_focus_child;
1820 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1822 if (priv->focus_out)
1824 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1828 if (gtk_widget_is_focus (widget))
1831 /* We only put the scrolled window itself in the focus chain if it
1832 * isn't possible to focus any children.
1834 child = gtk_bin_get_child (GTK_BIN (widget));
1837 if (gtk_widget_child_focus (child, direction))
1841 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1843 gtk_widget_grab_focus (widget);
1851 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1854 GtkScrolledWindowPrivate *priv;
1855 GtkScrolledWindow *scrolled_window;
1857 g_return_if_fail (adjustment != NULL);
1858 g_return_if_fail (data != NULL);
1860 scrolled_window = GTK_SCROLLED_WINDOW (data);
1861 priv = scrolled_window->priv;
1863 if (priv->hscrollbar &&
1864 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1866 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1870 visible = priv->hscrollbar_visible;
1871 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1872 adjustment->page_size);
1873 if (!priv->inside_allocate && priv->hscrollbar_visible != visible)
1874 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1877 else if (priv->vscrollbar &&
1878 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1880 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1884 visible = priv->vscrollbar_visible;
1885 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1886 adjustment->page_size);
1887 if (!priv->inside_allocate && priv->vscrollbar_visible != visible)
1888 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1894 gtk_scrolled_window_add (GtkContainer *container,
1897 GtkScrolledWindowPrivate *priv;
1898 GtkScrolledWindow *scrolled_window;
1900 GtkWidget *child_widget;
1901 GtkAdjustment *hadj, *vadj;
1903 bin = GTK_BIN (container);
1904 child_widget = gtk_bin_get_child (bin);
1905 g_return_if_fail (child_widget == NULL);
1907 scrolled_window = GTK_SCROLLED_WINDOW (container);
1908 priv = scrolled_window->priv;
1910 _gtk_bin_set_child (bin, child);
1911 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1913 hadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->hscrollbar));
1914 vadj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->priv->vscrollbar));
1916 if (GTK_IS_SCROLLABLE (child))
1917 g_object_set (child, "hadjustment", hadj, "vadjustment", vadj, NULL);
1919 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1920 "use gtk_scrolled_window_add_with_viewport() instead");
1924 gtk_scrolled_window_remove (GtkContainer *container,
1927 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1928 g_return_if_fail (child != NULL);
1929 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1931 g_object_set (child, "hadjustment", NULL, "vadjustment", NULL, NULL);
1933 /* chain parent class handler to remove child */
1934 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1938 * gtk_scrolled_window_add_with_viewport:
1939 * @scrolled_window: a #GtkScrolledWindow
1940 * @child: the widget you want to scroll
1942 * Used to add children without native scrolling capabilities. This
1943 * is simply a convenience function; it is equivalent to adding the
1944 * unscrollable child to a viewport, then adding the viewport to the
1945 * scrolled window. If a child has native scrolling, use
1946 * gtk_container_add() instead of this function.
1948 * The viewport scrolls the child by moving its #GdkWindow, and takes
1949 * the size of the child to be the size of its toplevel #GdkWindow.
1950 * This will be very wrong for most widgets that support native scrolling;
1951 * for example, if you add a widget such as #GtkTreeView with a viewport,
1952 * the whole widget will scroll, including the column headings. Thus,
1953 * widgets with native scrolling support should not be used with the
1954 * #GtkViewport proxy.
1956 * A widget supports scrolling natively if it implements the
1957 * #GtkScrollable interface.
1960 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1964 GtkWidget *viewport;
1965 GtkWidget *child_widget;
1967 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1968 g_return_if_fail (GTK_IS_WIDGET (child));
1969 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1971 bin = GTK_BIN (scrolled_window);
1972 child_widget = gtk_bin_get_child (bin);
1976 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1977 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1979 viewport = child_widget;
1984 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1985 gtk_scrolled_window_get_vadjustment (scrolled_window));
1986 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1989 gtk_widget_show (viewport);
1990 gtk_container_add (GTK_CONTAINER (viewport), child);
1994 * _gtk_scrolled_window_get_spacing:
1995 * @scrolled_window: a scrolled window
1997 * Gets the spacing between the scrolled window's scrollbars and
1998 * the scrolled widget. Used by GtkCombo
2000 * Return value: the spacing, in pixels.
2003 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
2005 GtkScrolledWindowClass *class;
2007 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2009 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
2011 if (class->scrollbar_spacing >= 0)
2012 return class->scrollbar_spacing;
2015 gint scrollbar_spacing;
2017 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
2018 "scrollbar-spacing", &scrollbar_spacing,
2021 return scrollbar_spacing;
2027 gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
2028 GtkOrientation orientation,
2032 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
2033 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
2034 GtkBin *bin = GTK_BIN (scrolled_window);
2037 gint scrollbar_spacing;
2038 GtkRequisition hscrollbar_requisition;
2039 GtkRequisition vscrollbar_requisition;
2040 GtkRequisition minimum_req, natural_req;
2043 gint min_child_size, nat_child_size;
2045 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
2049 minimum_req.width = 0;
2050 minimum_req.height = 0;
2051 natural_req.width = 0;
2052 natural_req.height = 0;
2054 gtk_widget_get_preferred_size (priv->hscrollbar,
2055 &hscrollbar_requisition, NULL);
2056 gtk_widget_get_preferred_size (priv->vscrollbar,
2057 &vscrollbar_requisition, NULL);
2059 child = gtk_bin_get_child (bin);
2060 if (child && gtk_widget_get_visible (child))
2062 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2064 gtk_widget_get_preferred_width (child,
2068 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
2070 minimum_req.width += min_child_size;
2071 natural_req.width += nat_child_size;
2075 gint min_content_width = priv->min_content_width;
2077 if (min_content_width >= 0)
2079 minimum_req.width = MAX (minimum_req.width, min_content_width);
2080 natural_req.width = MAX (natural_req.width, min_content_width);
2085 minimum_req.width += vscrollbar_requisition.width;
2086 natural_req.width += vscrollbar_requisition.width;
2090 else /* GTK_ORIENTATION_VERTICAL */
2092 gtk_widget_get_preferred_height (child,
2096 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
2098 minimum_req.height += min_child_size;
2099 natural_req.height += nat_child_size;
2103 gint min_content_height = priv->min_content_height;
2105 if (min_content_height >= 0)
2107 minimum_req.height = MAX (minimum_req.height, min_content_height);
2108 natural_req.height = MAX (natural_req.height, min_content_height);
2113 minimum_req.height += vscrollbar_requisition.height;
2114 natural_req.height += vscrollbar_requisition.height;
2120 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2121 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2123 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
2124 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
2125 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
2126 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
2129 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
2130 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2132 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
2133 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
2134 if (!extra_width || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
2135 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
2138 minimum_req.width += MAX (0, extra_width);
2139 minimum_req.height += MAX (0, extra_height);
2140 natural_req.width += MAX (0, extra_width);
2141 natural_req.height += MAX (0, extra_height);
2143 if (priv->shadow_type != GTK_SHADOW_NONE)
2145 style = gtk_widget_get_style (GTK_WIDGET (widget));
2146 minimum_req.width += 2 * style->xthickness;
2147 minimum_req.height += 2 * style->ythickness;
2148 natural_req.width += 2 * style->xthickness;
2149 natural_req.height += 2 * style->ythickness;
2152 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2155 *minimum_size = minimum_req.width;
2157 *natural_size = natural_req.width;
2162 *minimum_size = minimum_req.height;
2164 *natural_size = natural_req.height;
2169 gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
2173 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2177 gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
2181 gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2185 gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
2187 gint *minimum_height,
2188 gint *natural_height)
2190 g_return_if_fail (GTK_IS_WIDGET (widget));
2192 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
2196 gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
2198 gint *minimum_width,
2199 gint *natural_width)
2201 g_return_if_fail (GTK_IS_WIDGET (widget));
2203 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
2207 * gtk_scrolled_window_get_min_content_width:
2208 * @scrolled_window: a #GtkScrolledWindow
2210 * Gets the minimum content width of @scrolled_window, or -1 if not set.
2212 * Returns: the minimum content width
2217 gtk_scrolled_window_get_min_content_width (GtkScrolledWindow *scrolled_window)
2219 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2221 return scrolled_window->priv->min_content_width;
2225 * gtk_scrolled_window_set_min_content_width:
2226 * @scrolled_window: a #GtkScrolledWindow
2227 * @width: the minimal content width
2229 * Sets the minimum width that @scrolled_window should keep visible.
2230 * Note that this can and (usually will) be smaller than the minimum
2231 * size of the content.
2236 gtk_scrolled_window_set_min_content_width (GtkScrolledWindow *scrolled_window,
2239 GtkScrolledWindowPrivate *priv;
2241 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2243 priv = scrolled_window->priv;
2245 if (priv->min_content_width != width)
2247 priv->min_content_width = width;
2249 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2251 g_object_notify (G_OBJECT (scrolled_window), "min-content-width");
2256 * gtk_scrolled_window_get_min_content_height:
2257 * @scrolled_window: a #GtkScrolledWindow
2259 * Gets the minimal content height of @scrolled_window, or -1 if not set.
2261 * Returns: the minimal content height
2266 gtk_scrolled_window_get_min_content_height (GtkScrolledWindow *scrolled_window)
2268 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
2270 return scrolled_window->priv->min_content_height;
2274 * gtk_scrolled_window_set_min_content_height:
2275 * @scrolled_window: a #GtkScrolledWindow
2276 * @height: the minimal content height
2278 * Sets the minimum height that @scrolled_window should keep visible.
2279 * Note that this can and (usually will) be smaller than the minimum
2280 * size of the content.
2285 gtk_scrolled_window_set_min_content_height (GtkScrolledWindow *scrolled_window,
2288 GtkScrolledWindowPrivate *priv;
2290 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
2292 priv = scrolled_window->priv;
2294 if (priv->min_content_height != height)
2296 priv->min_content_height = height;
2298 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
2300 g_object_notify (G_OBJECT (scrolled_window), "min-content-height");