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 "gtksizerequest.h"
32 #include "gtkmarshalers.h"
33 #include "gtkscrolledwindow.h"
34 #include "gtkwindow.h"
35 #include "gtkprivate.h"
38 /* scrolled window policy and size requisition handling:
40 * gtk size requisition works as follows:
41 * a widget upon size-request reports the width and height that it finds
42 * to be best suited to display its contents, including children.
43 * the width and/or height reported from a widget upon size requisition
44 * may be overidden by the user by specifying a width and/or height
45 * other than 0 through gtk_widget_set_size_request().
47 * a scrolled window needs (for implementing all three policy types) to
48 * request its width and height based on two different rationales.
49 * 1) the user wants the scrolled window to just fit into the space
50 * that it gets allocated for a specifc dimension.
51 * 1.1) this does not apply if the user specified a concrete value
52 * value for that specific dimension by either specifying usize for the
53 * scrolled window or for its child.
54 * 2) the user wants the scrolled window to take as much space up as
55 * is desired by the child for a specifc dimension (i.e. POLICY_NEVER).
57 * also, kinda obvious:
58 * 3) a user would certainly not have choosen a scrolled window as a container
59 * for the child, if the resulting allocation takes up more space than the
60 * child would have allocated without the scrolled window.
63 * A) from 1) follows: the scrolled window shouldn't request more space for a
64 * specifc dimension than is required at minimum.
65 * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled
66 * window (done automatically) or by usize of the child (needs to be checked).
67 * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the
69 * D) from 3) follows: the scrolled window child's minimum width and minimum height
70 * under A) at least correspond to the space taken up by its scrollbars.
73 #define DEFAULT_SCROLLBAR_SPACING 3
75 struct _GtkScrolledWindowPrivate
77 GtkCornerType real_window_placement;
78 GtkWidget *hscrollbar;
79 GtkWidget *vscrollbar;
81 gboolean window_placement_set;
85 guint hscrollbar_policy : 2;
86 guint vscrollbar_policy : 2;
87 guint hscrollbar_visible : 1;
88 guint vscrollbar_visible : 1;
89 guint window_placement : 2;
90 guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
98 PROP_HSCROLLBAR_POLICY,
99 PROP_VSCROLLBAR_POLICY,
100 PROP_WINDOW_PLACEMENT,
101 PROP_WINDOW_PLACEMENT_SET,
113 static void gtk_scrolled_window_destroy (GtkObject *object);
114 static void gtk_scrolled_window_set_property (GObject *object,
118 static void gtk_scrolled_window_get_property (GObject *object,
123 static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
124 GdkScreen *previous_screen);
125 static gboolean gtk_scrolled_window_expose (GtkWidget *widget,
126 GdkEventExpose *event);
127 static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
128 GtkAllocation *allocation);
129 static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
130 GdkEventScroll *event);
131 static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
132 GtkDirectionType direction);
133 static void gtk_scrolled_window_add (GtkContainer *container,
135 static void gtk_scrolled_window_remove (GtkContainer *container,
137 static void gtk_scrolled_window_forall (GtkContainer *container,
138 gboolean include_internals,
139 GtkCallback callback,
140 gpointer callback_data);
141 static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
142 GtkScrollType scroll,
143 gboolean horizontal);
144 static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
145 GtkDirectionType direction_type);
147 static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
148 GtkAllocation *allocation);
149 static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
152 static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
154 static void gtk_scrolled_window_size_request_init (GtkSizeRequestIface *iface);
155 static void gtk_scrolled_window_get_width (GtkSizeRequest *widget,
158 static void gtk_scrolled_window_get_height (GtkSizeRequest *widget,
161 static void gtk_scrolled_window_get_height_for_width (GtkSizeRequest *layout,
163 gint *minimum_height,
164 gint *natural_height);
165 static void gtk_scrolled_window_get_width_for_height (GtkSizeRequest *layout,
167 gint *minimum_height,
168 gint *natural_height);
170 static guint signals[LAST_SIGNAL] = {0};
172 G_DEFINE_TYPE_WITH_CODE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN,
173 G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
174 gtk_scrolled_window_size_request_init))
178 add_scroll_binding (GtkBindingSet *binding_set,
180 GdkModifierType mask,
181 GtkScrollType scroll,
184 guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
186 gtk_binding_entry_add_signal (binding_set, keyval, mask,
188 GTK_TYPE_SCROLL_TYPE, scroll,
189 G_TYPE_BOOLEAN, horizontal);
190 gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
192 GTK_TYPE_SCROLL_TYPE, scroll,
193 G_TYPE_BOOLEAN, horizontal);
197 add_tab_bindings (GtkBindingSet *binding_set,
198 GdkModifierType modifiers,
199 GtkDirectionType direction)
201 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
203 GTK_TYPE_DIRECTION_TYPE, direction);
204 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
206 GTK_TYPE_DIRECTION_TYPE, direction);
210 gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
212 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
213 GtkObjectClass *object_class;
214 GtkWidgetClass *widget_class;
215 GtkContainerClass *container_class;
216 GtkBindingSet *binding_set;
218 object_class = (GtkObjectClass*) class;
219 widget_class = (GtkWidgetClass*) class;
220 container_class = (GtkContainerClass*) class;
222 gobject_class->set_property = gtk_scrolled_window_set_property;
223 gobject_class->get_property = gtk_scrolled_window_get_property;
225 object_class->destroy = gtk_scrolled_window_destroy;
227 widget_class->screen_changed = gtk_scrolled_window_screen_changed;
228 widget_class->expose_event = gtk_scrolled_window_expose;
229 widget_class->size_allocate = gtk_scrolled_window_size_allocate;
230 widget_class->scroll_event = gtk_scrolled_window_scroll_event;
231 widget_class->focus = gtk_scrolled_window_focus;
233 container_class->add = gtk_scrolled_window_add;
234 container_class->remove = gtk_scrolled_window_remove;
235 container_class->forall = gtk_scrolled_window_forall;
237 class->scrollbar_spacing = -1;
239 class->scroll_child = gtk_scrolled_window_scroll_child;
240 class->move_focus_out = gtk_scrolled_window_move_focus_out;
242 g_object_class_install_property (gobject_class,
244 g_param_spec_object ("hadjustment",
245 P_("Horizontal Adjustment"),
246 P_("The GtkAdjustment for the horizontal position"),
248 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
249 g_object_class_install_property (gobject_class,
251 g_param_spec_object ("vadjustment",
252 P_("Vertical Adjustment"),
253 P_("The GtkAdjustment for the vertical position"),
255 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
256 g_object_class_install_property (gobject_class,
257 PROP_HSCROLLBAR_POLICY,
258 g_param_spec_enum ("hscrollbar-policy",
259 P_("Horizontal Scrollbar Policy"),
260 P_("When the horizontal scrollbar is displayed"),
261 GTK_TYPE_POLICY_TYPE,
262 GTK_POLICY_AUTOMATIC,
263 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
264 g_object_class_install_property (gobject_class,
265 PROP_VSCROLLBAR_POLICY,
266 g_param_spec_enum ("vscrollbar-policy",
267 P_("Vertical Scrollbar Policy"),
268 P_("When the vertical scrollbar is displayed"),
269 GTK_TYPE_POLICY_TYPE,
270 GTK_POLICY_AUTOMATIC,
271 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
273 g_object_class_install_property (gobject_class,
274 PROP_WINDOW_PLACEMENT,
275 g_param_spec_enum ("window-placement",
276 P_("Window Placement"),
277 P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
278 GTK_TYPE_CORNER_TYPE,
280 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
283 * GtkScrolledWindow:window-placement-set:
285 * Whether "window-placement" should be used to determine the location
286 * of the contents with respect to the scrollbars. Otherwise, the
287 * "gtk-scrolled-window-placement" setting is used.
291 g_object_class_install_property (gobject_class,
292 PROP_WINDOW_PLACEMENT_SET,
293 g_param_spec_boolean ("window-placement-set",
294 P_("Window Placement Set"),
295 P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
297 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
298 g_object_class_install_property (gobject_class,
300 g_param_spec_enum ("shadow-type",
302 P_("Style of bevel around the contents"),
303 GTK_TYPE_SHADOW_TYPE,
305 GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
308 * GtkScrolledWindow:scrollbars-within-bevel:
310 * Whether to place scrollbars within the scrolled window's bevel.
314 gtk_widget_class_install_style_property (widget_class,
315 g_param_spec_boolean ("scrollbars-within-bevel",
316 P_("Scrollbars within bevel"),
317 P_("Place scrollbars within the scrolled window's bevel"),
319 GTK_PARAM_READABLE));
321 gtk_widget_class_install_style_property (widget_class,
322 g_param_spec_int ("scrollbar-spacing",
323 P_("Scrollbar spacing"),
324 P_("Number of pixels between the scrollbars and the scrolled window"),
327 DEFAULT_SCROLLBAR_SPACING,
328 GTK_PARAM_READABLE));
331 * GtkSettings:gtk-scrolled-window-placement:
333 * Where the contents of scrolled windows are located with respect to the
334 * scrollbars, if not overridden by the scrolled window's own placement.
338 gtk_settings_install_property (g_param_spec_enum ("gtk-scrolled-window-placement",
339 P_("Scrolled Window Placement"),
340 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
341 GTK_TYPE_CORNER_TYPE,
343 G_PARAM_READABLE | G_PARAM_WRITABLE));
346 signals[SCROLL_CHILD] =
347 g_signal_new (I_("scroll-child"),
348 G_TYPE_FROM_CLASS (object_class),
349 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
350 G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
352 _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
354 GTK_TYPE_SCROLL_TYPE,
356 signals[MOVE_FOCUS_OUT] =
357 g_signal_new (I_("move-focus-out"),
358 G_TYPE_FROM_CLASS (object_class),
359 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
360 G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
362 _gtk_marshal_VOID__ENUM,
364 GTK_TYPE_DIRECTION_TYPE);
366 binding_set = gtk_binding_set_by_class (class);
368 add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
369 add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
370 add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
371 add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
373 add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
374 add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
375 add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
376 add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
378 add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
379 add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
380 add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
381 add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
383 add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
384 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
386 g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
390 gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
392 GtkScrolledWindowPrivate *priv;
394 scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
395 GTK_TYPE_SCROLLED_WINDOW,
396 GtkScrolledWindowPrivate);
398 gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
399 gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
401 priv->hscrollbar = NULL;
402 priv->vscrollbar = NULL;
403 priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
404 priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
405 priv->hscrollbar_visible = FALSE;
406 priv->vscrollbar_visible = FALSE;
407 priv->focus_out = FALSE;
408 priv->window_placement = GTK_CORNER_TOP_LEFT;
409 gtk_scrolled_window_update_real_placement (scrolled_window);
413 * gtk_scrolled_window_new:
414 * @hadjustment: (allow-none): horizontal adjustment
415 * @vadjustment: (allow-none): vertical adjustment
417 * Creates a new scrolled window.
419 * The two arguments are the scrolled window's adjustments; these will be
420 * shared with the scrollbars and the child widget to keep the bars in sync
421 * with the child. Usually you want to pass %NULL for the adjustments, which
422 * will cause the scrolled window to create them for you.
424 * Returns: a new scrolled window
427 gtk_scrolled_window_new (GtkAdjustment *hadjustment,
428 GtkAdjustment *vadjustment)
430 GtkWidget *scrolled_window;
433 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL);
436 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
438 scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
439 "hadjustment", hadjustment,
440 "vadjustment", vadjustment,
443 return scrolled_window;
447 * gtk_scrolled_window_set_hadjustment:
448 * @scrolled_window: a #GtkScrolledWindow
449 * @hadjustment: horizontal scroll adjustment
451 * Sets the #GtkAdjustment for the horizontal scrollbar.
454 gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
455 GtkAdjustment *hadjustment)
457 GtkScrolledWindowPrivate *priv;
461 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
463 g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment));
465 hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
467 bin = GTK_BIN (scrolled_window);
468 priv = scrolled_window->priv;
470 if (!priv->hscrollbar)
472 gtk_widget_push_composite_child ();
473 priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
474 gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
475 gtk_widget_pop_composite_child ();
477 gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
478 g_object_ref (priv->hscrollbar);
479 gtk_widget_show (priv->hscrollbar);
483 GtkAdjustment *old_adjustment;
485 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
486 if (old_adjustment == hadjustment)
489 g_signal_handlers_disconnect_by_func (old_adjustment,
490 gtk_scrolled_window_adjustment_changed,
492 gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
495 hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
496 g_signal_connect (hadjustment,
498 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
500 gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
502 child = gtk_bin_get_child (bin);
504 gtk_widget_set_scroll_adjustments (child,
505 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
506 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
508 g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
512 * gtk_scrolled_window_set_vadjustment:
513 * @scrolled_window: a #GtkScrolledWindow
514 * @vadjustment: vertical scroll adjustment
516 * Sets the #GtkAdjustment for the vertical scrollbar.
519 gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
520 GtkAdjustment *vadjustment)
522 GtkScrolledWindowPrivate *priv;
526 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
528 g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment));
530 vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
532 bin = GTK_BIN (scrolled_window);
533 priv = scrolled_window->priv;
535 if (!priv->vscrollbar)
537 gtk_widget_push_composite_child ();
538 priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
539 gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
540 gtk_widget_pop_composite_child ();
542 gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
543 g_object_ref (priv->vscrollbar);
544 gtk_widget_show (priv->vscrollbar);
548 GtkAdjustment *old_adjustment;
550 old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
551 if (old_adjustment == vadjustment)
554 g_signal_handlers_disconnect_by_func (old_adjustment,
555 gtk_scrolled_window_adjustment_changed,
557 gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
560 vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
561 g_signal_connect (vadjustment,
563 G_CALLBACK (gtk_scrolled_window_adjustment_changed),
565 gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
567 child = gtk_bin_get_child (bin);
569 gtk_widget_set_scroll_adjustments (child,
570 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
571 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
573 g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
577 * gtk_scrolled_window_get_hadjustment:
578 * @scrolled_window: a #GtkScrolledWindow
580 * Returns the horizontal scrollbar's adjustment, used to connect the
581 * horizontal scrollbar to the child widget's horizontal scroll
584 * Returns: (transfer none): the horizontal #GtkAdjustment
587 gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
589 GtkScrolledWindowPrivate *priv;
591 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
593 priv = scrolled_window->priv;
595 return (priv->hscrollbar ?
596 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
601 * gtk_scrolled_window_get_vadjustment:
602 * @scrolled_window: a #GtkScrolledWindow
604 * Returns the vertical scrollbar's adjustment, used to connect the
605 * vertical scrollbar to the child widget's vertical scroll functionality.
607 * Returns: (transfer none): the vertical #GtkAdjustment
610 gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
612 GtkScrolledWindowPrivate *priv;
614 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
616 priv = scrolled_window->priv;
618 return (priv->vscrollbar ?
619 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
624 * gtk_scrolled_window_get_hscrollbar:
625 * @scrolled_window: a #GtkScrolledWindow
627 * Returns the horizontal scrollbar of @scrolled_window.
629 * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
630 * or %NULL if it does not have one.
635 gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
637 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
639 return scrolled_window->priv->hscrollbar;
643 * gtk_scrolled_window_get_vscrollbar:
644 * @scrolled_window: a #GtkScrolledWindow
646 * Returns the vertical scrollbar of @scrolled_window.
648 * Returns: (transfer none): the vertical scrollbar of the scrolled window,
649 * or %NULL if it does not have one.
654 gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
656 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
658 return scrolled_window->priv->vscrollbar;
662 * gtk_scrolled_window_set_policy:
663 * @scrolled_window: a #GtkScrolledWindow
664 * @hscrollbar_policy: policy for horizontal bar
665 * @vscrollbar_policy: policy for vertical bar
667 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
669 * The policy determines when the scrollbar should appear; it is a value
670 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
671 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
672 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
673 * if needed (that is, if the slider part of the bar would be smaller
674 * than the trough - the display is larger than the page size).
677 gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
678 GtkPolicyType hscrollbar_policy,
679 GtkPolicyType vscrollbar_policy)
681 GtkScrolledWindowPrivate *priv;
682 GObject *object = G_OBJECT (scrolled_window);
684 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
686 priv = scrolled_window->priv;
688 if ((priv->hscrollbar_policy != hscrollbar_policy) ||
689 (priv->vscrollbar_policy != vscrollbar_policy))
691 priv->hscrollbar_policy = hscrollbar_policy;
692 priv->vscrollbar_policy = vscrollbar_policy;
694 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
696 g_object_freeze_notify (object);
697 g_object_notify (object, "hscrollbar-policy");
698 g_object_notify (object, "vscrollbar-policy");
699 g_object_thaw_notify (object);
704 * gtk_scrolled_window_get_policy:
705 * @scrolled_window: a #GtkScrolledWindow
706 * @hscrollbar_policy: location to store the policy for the horizontal
707 * scrollbar, or %NULL.
708 * @vscrollbar_policy: location to store the policy for the vertical
709 * scrollbar, or %NULL.
711 * Retrieves the current policy values for the horizontal and vertical
712 * scrollbars. See gtk_scrolled_window_set_policy().
715 gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
716 GtkPolicyType *hscrollbar_policy,
717 GtkPolicyType *vscrollbar_policy)
719 GtkScrolledWindowPrivate *priv;
721 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
723 priv = scrolled_window->priv;
725 if (hscrollbar_policy)
726 *hscrollbar_policy = priv->hscrollbar_policy;
727 if (vscrollbar_policy)
728 *vscrollbar_policy = priv->vscrollbar_policy;
732 gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
734 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
735 GtkSettings *settings;
737 settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
739 if (priv->window_placement_set || settings == NULL)
740 priv->real_window_placement = priv->window_placement;
742 g_object_get (settings,
743 "gtk-scrolled-window-placement",
744 &priv->real_window_placement,
749 gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
750 GtkCornerType window_placement)
752 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
754 if (priv->window_placement != window_placement)
756 priv->window_placement = window_placement;
758 gtk_scrolled_window_update_real_placement (scrolled_window);
759 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
761 g_object_notify (G_OBJECT (scrolled_window), "window-placement");
766 gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
767 gboolean placement_set,
768 gboolean emit_resize)
770 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
772 if (priv->window_placement_set != placement_set)
774 priv->window_placement_set = placement_set;
776 gtk_scrolled_window_update_real_placement (scrolled_window);
778 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
780 g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
785 * gtk_scrolled_window_set_placement:
786 * @scrolled_window: a #GtkScrolledWindow
787 * @window_placement: position of the child window
789 * Sets the placement of the contents with respect to the scrollbars
790 * for the scrolled window.
792 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
793 * in the top left, with the scrollbars underneath and to the right.
794 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
795 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
797 * See also gtk_scrolled_window_get_placement() and
798 * gtk_scrolled_window_unset_placement().
801 gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
802 GtkCornerType window_placement)
804 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
806 gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
807 gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
811 * gtk_scrolled_window_get_placement:
812 * @scrolled_window: a #GtkScrolledWindow
814 * Gets the placement of the contents with respect to the scrollbars
815 * for the scrolled window. See gtk_scrolled_window_set_placement().
817 * Return value: the current placement value.
819 * See also gtk_scrolled_window_set_placement() and
820 * gtk_scrolled_window_unset_placement().
823 gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
825 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
827 return scrolled_window->priv->window_placement;
831 * gtk_scrolled_window_unset_placement:
832 * @scrolled_window: a #GtkScrolledWindow
834 * Unsets the placement of the contents with respect to the scrollbars
835 * for the scrolled window. If no window placement is set for a scrolled
836 * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
838 * See also gtk_scrolled_window_set_placement() and
839 * gtk_scrolled_window_get_placement().
844 gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
846 GtkScrolledWindowPrivate *priv;
848 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
850 priv = scrolled_window->priv;
852 if (priv->window_placement_set)
854 priv->window_placement_set = FALSE;
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_shadow_type:
864 * @scrolled_window: a #GtkScrolledWindow
865 * @type: kind of shadow to draw around scrolled window contents
867 * Changes the type of shadow drawn around the contents of
872 gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
875 GtkScrolledWindowPrivate *priv;
877 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
878 g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
880 priv = scrolled_window->priv;
882 if (priv->shadow_type != type)
884 priv->shadow_type = type;
886 if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
887 gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
889 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
891 g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
896 * gtk_scrolled_window_get_shadow_type:
897 * @scrolled_window: a #GtkScrolledWindow
899 * Gets the shadow type of the scrolled window. See
900 * gtk_scrolled_window_set_shadow_type().
902 * Return value: the current shadow type
905 gtk_scrolled_window_get_shadow_type (GtkScrolledWindow *scrolled_window)
907 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
909 return scrolled_window->priv->shadow_type;
913 gtk_scrolled_window_destroy (GtkObject *object)
915 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
916 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
918 if (priv->hscrollbar)
920 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
921 gtk_scrolled_window_adjustment_changed,
923 gtk_widget_unparent (priv->hscrollbar);
924 gtk_widget_destroy (priv->hscrollbar);
925 g_object_unref (priv->hscrollbar);
926 priv->hscrollbar = NULL;
928 if (priv->vscrollbar)
930 g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
931 gtk_scrolled_window_adjustment_changed,
933 gtk_widget_unparent (priv->vscrollbar);
934 gtk_widget_destroy (priv->vscrollbar);
935 g_object_unref (priv->vscrollbar);
936 priv->vscrollbar = NULL;
939 GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
943 gtk_scrolled_window_set_property (GObject *object,
948 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
949 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
953 case PROP_HADJUSTMENT:
954 gtk_scrolled_window_set_hadjustment (scrolled_window,
955 g_value_get_object (value));
957 case PROP_VADJUSTMENT:
958 gtk_scrolled_window_set_vadjustment (scrolled_window,
959 g_value_get_object (value));
961 case PROP_HSCROLLBAR_POLICY:
962 gtk_scrolled_window_set_policy (scrolled_window,
963 g_value_get_enum (value),
964 priv->vscrollbar_policy);
966 case PROP_VSCROLLBAR_POLICY:
967 gtk_scrolled_window_set_policy (scrolled_window,
968 priv->hscrollbar_policy,
969 g_value_get_enum (value));
971 case PROP_WINDOW_PLACEMENT:
972 gtk_scrolled_window_set_placement_internal (scrolled_window,
973 g_value_get_enum (value));
975 case PROP_WINDOW_PLACEMENT_SET:
976 gtk_scrolled_window_set_placement_set (scrolled_window,
977 g_value_get_boolean (value),
980 case PROP_SHADOW_TYPE:
981 gtk_scrolled_window_set_shadow_type (scrolled_window,
982 g_value_get_enum (value));
985 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
991 gtk_scrolled_window_get_property (GObject *object,
996 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
997 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1001 case PROP_HADJUSTMENT:
1002 g_value_set_object (value,
1003 G_OBJECT (gtk_scrolled_window_get_hadjustment (scrolled_window)));
1005 case PROP_VADJUSTMENT:
1006 g_value_set_object (value,
1007 G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
1009 case PROP_HSCROLLBAR_POLICY:
1010 g_value_set_enum (value, priv->hscrollbar_policy);
1012 case PROP_VSCROLLBAR_POLICY:
1013 g_value_set_enum (value, priv->vscrollbar_policy);
1015 case PROP_WINDOW_PLACEMENT:
1016 g_value_set_enum (value, priv->window_placement);
1018 case PROP_WINDOW_PLACEMENT_SET:
1019 g_value_set_boolean (value, priv->window_placement_set);
1021 case PROP_SHADOW_TYPE:
1022 g_value_set_enum (value, priv->shadow_type);
1025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1031 traverse_container (GtkWidget *widget,
1034 if (GTK_IS_SCROLLED_WINDOW (widget))
1036 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1037 gtk_widget_queue_resize (widget);
1039 else if (GTK_IS_CONTAINER (widget))
1040 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1044 gtk_scrolled_window_settings_changed (GtkSettings *settings)
1048 list = gtk_window_list_toplevels ();
1050 for (l = list; l; l = l->next)
1051 gtk_container_forall (GTK_CONTAINER (l->data),
1052 traverse_container, NULL);
1058 gtk_scrolled_window_screen_changed (GtkWidget *widget,
1059 GdkScreen *previous_screen)
1061 GtkSettings *settings;
1062 guint window_placement_connection;
1064 gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
1066 if (!gtk_widget_has_screen (widget))
1069 settings = gtk_widget_get_settings (widget);
1071 window_placement_connection =
1072 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1073 "gtk-scrolled-window-connection"));
1075 if (window_placement_connection)
1078 window_placement_connection =
1079 g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
1080 G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
1081 g_object_set_data (G_OBJECT (settings),
1082 I_("gtk-scrolled-window-connection"),
1083 GUINT_TO_POINTER (window_placement_connection));
1087 gtk_scrolled_window_expose (GtkWidget *widget,
1088 GdkEventExpose *event)
1090 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1091 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1093 if (priv->shadow_type != GTK_SHADOW_NONE)
1095 GtkAllocation allocation;
1096 GtkAllocation relative_allocation;
1098 gboolean scrollbars_within_bevel;
1100 style = gtk_widget_get_style (widget);
1101 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1103 gtk_widget_get_allocation (widget, &allocation);
1105 if (!scrollbars_within_bevel)
1107 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1109 relative_allocation.x -= style->xthickness;
1110 relative_allocation.y -= style->ythickness;
1111 relative_allocation.width += 2 * style->xthickness;
1112 relative_allocation.height += 2 * style->ythickness;
1116 GtkContainer *container = GTK_CONTAINER (widget);
1119 border_width = gtk_container_get_border_width (container);
1121 relative_allocation.x = border_width;
1122 relative_allocation.y = border_width;
1123 relative_allocation.width = allocation.width - 2 * border_width;
1124 relative_allocation.height = allocation.height - 2 * border_width;
1127 gtk_paint_shadow (style,
1128 gtk_widget_get_window (widget),
1129 GTK_STATE_NORMAL, priv->shadow_type,
1130 &event->area, widget, "scrolled_window",
1131 allocation.x + relative_allocation.x,
1132 allocation.y + relative_allocation.y,
1133 relative_allocation.width,
1134 relative_allocation.height);
1137 GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event (widget, event);
1143 gtk_scrolled_window_forall (GtkContainer *container,
1144 gboolean include_internals,
1145 GtkCallback callback,
1146 gpointer callback_data)
1148 GtkScrolledWindowPrivate *priv;
1149 GtkScrolledWindow *scrolled_window;
1151 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1152 g_return_if_fail (callback != NULL);
1154 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
1158 if (include_internals)
1160 scrolled_window = GTK_SCROLLED_WINDOW (container);
1161 priv = scrolled_window->priv;
1163 if (priv->vscrollbar)
1164 callback (priv->vscrollbar, callback_data);
1165 if (priv->hscrollbar)
1166 callback (priv->hscrollbar, callback_data);
1171 gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
1172 GtkScrollType scroll,
1173 gboolean horizontal)
1175 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1176 GtkAdjustment *adjustment = NULL;
1180 case GTK_SCROLL_STEP_UP:
1181 scroll = GTK_SCROLL_STEP_BACKWARD;
1184 case GTK_SCROLL_STEP_DOWN:
1185 scroll = GTK_SCROLL_STEP_FORWARD;
1188 case GTK_SCROLL_STEP_LEFT:
1189 scroll = GTK_SCROLL_STEP_BACKWARD;
1192 case GTK_SCROLL_STEP_RIGHT:
1193 scroll = GTK_SCROLL_STEP_FORWARD;
1196 case GTK_SCROLL_PAGE_UP:
1197 scroll = GTK_SCROLL_PAGE_BACKWARD;
1200 case GTK_SCROLL_PAGE_DOWN:
1201 scroll = GTK_SCROLL_PAGE_FORWARD;
1204 case GTK_SCROLL_PAGE_LEFT:
1205 scroll = GTK_SCROLL_STEP_BACKWARD;
1208 case GTK_SCROLL_PAGE_RIGHT:
1209 scroll = GTK_SCROLL_STEP_FORWARD;
1212 case GTK_SCROLL_STEP_BACKWARD:
1213 case GTK_SCROLL_STEP_FORWARD:
1214 case GTK_SCROLL_PAGE_BACKWARD:
1215 case GTK_SCROLL_PAGE_FORWARD:
1216 case GTK_SCROLL_START:
1217 case GTK_SCROLL_END:
1220 g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
1224 if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
1225 (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
1230 if (priv->hscrollbar)
1231 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
1235 if (priv->vscrollbar)
1236 adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
1241 gdouble value = adjustment->value;
1245 case GTK_SCROLL_STEP_FORWARD:
1246 value += adjustment->step_increment;
1248 case GTK_SCROLL_STEP_BACKWARD:
1249 value -= adjustment->step_increment;
1251 case GTK_SCROLL_PAGE_FORWARD:
1252 value += adjustment->page_increment;
1254 case GTK_SCROLL_PAGE_BACKWARD:
1255 value -= adjustment->page_increment;
1257 case GTK_SCROLL_START:
1258 value = adjustment->lower;
1260 case GTK_SCROLL_END:
1261 value = adjustment->upper;
1264 g_assert_not_reached ();
1268 gtk_adjustment_set_value (adjustment, value);
1277 gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
1278 GtkDirectionType direction_type)
1280 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1281 GtkWidget *toplevel;
1283 /* Focus out of the scrolled window entirely. We do this by setting
1284 * a flag, then propagating the focus motion to the notebook.
1286 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
1287 if (!gtk_widget_is_toplevel (toplevel))
1290 g_object_ref (scrolled_window);
1292 priv->focus_out = TRUE;
1293 g_signal_emit_by_name (toplevel, "move-focus", direction_type);
1294 priv->focus_out = FALSE;
1296 g_object_unref (scrolled_window);
1300 gtk_scrolled_window_relative_allocation (GtkWidget *widget,
1301 GtkAllocation *allocation)
1303 GtkAllocation widget_allocation;
1304 GtkScrolledWindow *scrolled_window;
1305 GtkScrolledWindowPrivate *priv;
1307 gint scrollbar_spacing;
1310 g_return_if_fail (widget != NULL);
1311 g_return_if_fail (allocation != NULL);
1313 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1314 priv = scrolled_window->priv;
1316 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1318 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1319 allocation->x = border_width;
1320 allocation->y = border_width;
1322 if (priv->shadow_type != GTK_SHADOW_NONE)
1324 style = gtk_widget_get_style (widget);
1325 allocation->x += style->xthickness;
1326 allocation->y += style->ythickness;
1329 gtk_widget_get_allocation (widget, &widget_allocation);
1330 allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
1331 allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
1333 if (priv->vscrollbar_visible)
1335 GtkRequisition vscrollbar_requisition;
1338 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
1339 &vscrollbar_requisition, NULL);
1340 is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
1343 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1344 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1346 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1347 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1348 allocation->x += (vscrollbar_requisition.width + scrollbar_spacing);
1350 allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
1352 if (priv->hscrollbar_visible)
1354 GtkRequisition hscrollbar_requisition;
1356 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
1357 &hscrollbar_requisition, NULL);
1359 if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
1360 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
1361 allocation->y += (hscrollbar_requisition.height + scrollbar_spacing);
1363 allocation->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
1368 gtk_scrolled_window_size_allocate (GtkWidget *widget,
1369 GtkAllocation *allocation)
1371 GtkScrolledWindow *scrolled_window;
1372 GtkScrolledWindowPrivate *priv;
1375 GtkAllocation relative_allocation;
1376 GtkAllocation child_allocation;
1378 gboolean scrollbars_within_bevel;
1379 gint scrollbar_spacing;
1382 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
1383 g_return_if_fail (allocation != NULL);
1385 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1386 bin = GTK_BIN (scrolled_window);
1387 priv = scrolled_window->priv;
1389 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1391 style = gtk_widget_get_style (widget);
1392 gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
1394 border_width = gtk_container_get_border_width (GTK_CONTAINER (scrolled_window));
1396 gtk_widget_set_allocation (widget, allocation);
1398 if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1399 priv->hscrollbar_visible = TRUE;
1400 else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1401 priv->hscrollbar_visible = FALSE;
1402 if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1403 priv->vscrollbar_visible = TRUE;
1404 else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1405 priv->vscrollbar_visible = FALSE;
1407 child = gtk_bin_get_child (bin);
1408 if (child && gtk_widget_get_visible (child))
1410 gboolean previous_hvis;
1411 gboolean previous_vvis;
1416 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1418 child_allocation.x = relative_allocation.x + allocation->x;
1419 child_allocation.y = relative_allocation.y + allocation->y;
1420 child_allocation.width = relative_allocation.width;
1421 child_allocation.height = relative_allocation.height;
1423 previous_hvis = priv->hscrollbar_visible;
1424 previous_vvis = priv->vscrollbar_visible;
1426 gtk_widget_size_allocate (child, &child_allocation);
1428 /* If, after the first iteration, the hscrollbar and the
1429 * vscrollbar flip visiblity, then we need both.
1432 previous_hvis != priv->hscrollbar_visible &&
1433 previous_vvis != priv->vscrollbar_visible)
1435 priv->hscrollbar_visible = TRUE;
1436 priv->vscrollbar_visible = TRUE;
1438 /* a new resize is already queued at this point,
1439 * so we will immediatedly get reinvoked
1446 while (previous_hvis != priv->hscrollbar_visible ||
1447 previous_vvis != priv->vscrollbar_visible);
1451 priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
1452 priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
1453 gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
1456 if (priv->hscrollbar_visible)
1458 GtkRequisition hscrollbar_requisition;
1460 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
1461 &hscrollbar_requisition, NULL);
1463 if (!gtk_widget_get_visible (priv->hscrollbar))
1464 gtk_widget_show (priv->hscrollbar);
1466 child_allocation.x = relative_allocation.x;
1467 if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1468 priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
1469 child_allocation.y = (relative_allocation.y +
1470 relative_allocation.height +
1472 (priv->shadow_type == GTK_SHADOW_NONE ?
1473 0 : style->ythickness));
1475 child_allocation.y = border_width;
1477 child_allocation.width = relative_allocation.width;
1478 child_allocation.height = hscrollbar_requisition.height;
1479 child_allocation.x += allocation->x;
1480 child_allocation.y += allocation->y;
1482 if (priv->shadow_type != GTK_SHADOW_NONE)
1484 if (!scrollbars_within_bevel)
1486 child_allocation.x -= style->xthickness;
1487 child_allocation.width += 2 * style->xthickness;
1489 else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
1490 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1492 child_allocation.y -= style->ythickness;
1496 child_allocation.y += style->ythickness;
1500 gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
1502 else if (gtk_widget_get_visible (priv->hscrollbar))
1503 gtk_widget_hide (priv->hscrollbar);
1505 if (priv->vscrollbar_visible)
1507 GtkRequisition vscrollbar_requisition;
1508 if (!gtk_widget_get_visible (priv->vscrollbar))
1509 gtk_widget_show (priv->vscrollbar);
1511 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
1512 &vscrollbar_requisition, NULL);
1514 if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
1515 (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
1516 priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
1517 (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
1518 (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
1519 priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
1520 child_allocation.x = (relative_allocation.x +
1521 relative_allocation.width +
1523 (priv->shadow_type == GTK_SHADOW_NONE ?
1524 0 : style->xthickness));
1526 child_allocation.x = border_width;
1528 child_allocation.y = relative_allocation.y;
1529 child_allocation.width = vscrollbar_requisition.width;
1530 child_allocation.height = relative_allocation.height;
1531 child_allocation.x += allocation->x;
1532 child_allocation.y += allocation->y;
1534 if (priv->shadow_type != GTK_SHADOW_NONE)
1536 if (!scrollbars_within_bevel)
1538 child_allocation.y -= style->ythickness;
1539 child_allocation.height += 2 * style->ythickness;
1541 else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
1542 GTK_CORNER_TOP_LEFT == priv->real_window_placement)
1544 child_allocation.x -= style->xthickness;
1548 child_allocation.x += style->xthickness;
1552 gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
1554 else if (gtk_widget_get_visible (priv->vscrollbar))
1555 gtk_widget_hide (priv->vscrollbar);
1559 gtk_scrolled_window_scroll_event (GtkWidget *widget,
1560 GdkEventScroll *event)
1562 GtkScrolledWindowPrivate *priv;
1563 GtkScrolledWindow *scrolled_window;
1566 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
1567 g_return_val_if_fail (event != NULL, FALSE);
1569 scrolled_window = GTK_SCROLLED_WINDOW (widget);
1570 priv = scrolled_window->priv;
1572 if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
1573 range = priv->vscrollbar;
1575 range = priv->hscrollbar;
1577 if (range && gtk_widget_get_visible (range))
1579 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
1582 delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
1584 gtk_adjustment_set_value (adj, adj->value + delta);
1593 gtk_scrolled_window_focus (GtkWidget *widget,
1594 GtkDirectionType direction)
1596 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1597 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1599 gboolean had_focus_child;
1601 had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
1603 if (priv->focus_out)
1605 priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
1609 if (gtk_widget_is_focus (widget))
1612 /* We only put the scrolled window itself in the focus chain if it
1613 * isn't possible to focus any children.
1615 child = gtk_bin_get_child (GTK_BIN (widget));
1618 if (gtk_widget_child_focus (child, direction))
1622 if (!had_focus_child && gtk_widget_get_can_focus (widget))
1624 gtk_widget_grab_focus (widget);
1632 gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
1635 GtkScrolledWindowPrivate *priv;;
1636 GtkScrolledWindow *scrolled_window;
1638 g_return_if_fail (adjustment != NULL);
1639 g_return_if_fail (data != NULL);
1641 scrolled_window = GTK_SCROLLED_WINDOW (data);
1642 priv = scrolled_window->priv;
1644 if (priv->hscrollbar &&
1645 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
1647 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
1651 visible = priv->hscrollbar_visible;
1652 priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
1653 adjustment->page_size);
1654 if (priv->hscrollbar_visible != visible)
1655 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1658 else if (priv->vscrollbar &&
1659 adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
1661 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
1665 visible = priv->vscrollbar_visible;
1666 priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
1667 adjustment->page_size);
1668 if (priv->vscrollbar_visible != visible)
1669 gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
1675 gtk_scrolled_window_add (GtkContainer *container,
1678 GtkScrolledWindowPrivate *priv;
1679 GtkScrolledWindow *scrolled_window;
1681 GtkWidget *child_widget;
1683 bin = GTK_BIN (container);
1684 child_widget = gtk_bin_get_child (bin);
1685 g_return_if_fail (child_widget == NULL);
1687 scrolled_window = GTK_SCROLLED_WINDOW (container);
1688 priv = scrolled_window->priv;
1690 _gtk_bin_set_child (bin, child);
1691 gtk_widget_set_parent (child, GTK_WIDGET (bin));
1693 /* this is a temporary message */
1694 if (!gtk_widget_set_scroll_adjustments (child,
1695 gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
1696 gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))))
1697 g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
1698 "use gtk_scrolled_window_add_with_viewport() instead");
1702 gtk_scrolled_window_remove (GtkContainer *container,
1705 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
1706 g_return_if_fail (child != NULL);
1707 g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
1709 gtk_widget_set_scroll_adjustments (child, NULL, NULL);
1711 /* chain parent class handler to remove child */
1712 GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
1716 * gtk_scrolled_window_add_with_viewport:
1717 * @scrolled_window: a #GtkScrolledWindow
1718 * @child: the widget you want to scroll
1720 * Used to add children without native scrolling capabilities. This
1721 * is simply a convenience function; it is equivalent to adding the
1722 * unscrollable child to a viewport, then adding the viewport to the
1723 * scrolled window. If a child has native scrolling, use
1724 * gtk_container_add() instead of this function.
1726 * The viewport scrolls the child by moving its #GdkWindow, and takes
1727 * the size of the child to be the size of its toplevel #GdkWindow.
1728 * This will be very wrong for most widgets that support native scrolling;
1729 * for example, if you add a widget such as #GtkTreeView with a viewport,
1730 * the whole widget will scroll, including the column headings. Thus,
1731 * widgets with native scrolling support should not be used with the
1732 * #GtkViewport proxy.
1734 * A widget supports scrolling natively if the
1735 * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
1736 * i.e. has been filled in with a valid signal identifier.
1739 gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
1743 GtkWidget *viewport;
1744 GtkWidget *child_widget;
1746 g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
1747 g_return_if_fail (GTK_IS_WIDGET (child));
1748 g_return_if_fail (gtk_widget_get_parent (child) == NULL);
1750 bin = GTK_BIN (scrolled_window);
1751 child_widget = gtk_bin_get_child (bin);
1755 g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
1756 g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
1758 viewport = child_widget;
1763 gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window),
1764 gtk_scrolled_window_get_vadjustment (scrolled_window));
1765 gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
1768 gtk_widget_show (viewport);
1769 gtk_container_add (GTK_CONTAINER (viewport), child);
1773 * _gtk_scrolled_window_get_spacing:
1774 * @scrolled_window: a scrolled window
1776 * Gets the spacing between the scrolled window's scrollbars and
1777 * the scrolled widget. Used by GtkCombo
1779 * Return value: the spacing, in pixels.
1782 _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
1784 GtkScrolledWindowClass *class;
1786 g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), 0);
1788 class = GTK_SCROLLED_WINDOW_GET_CLASS (scrolled_window);
1790 if (class->scrollbar_spacing >= 0)
1791 return class->scrollbar_spacing;
1794 gint scrollbar_spacing;
1796 gtk_widget_style_get (GTK_WIDGET (scrolled_window),
1797 "scrollbar-spacing", &scrollbar_spacing,
1800 return scrollbar_spacing;
1806 gtk_scrolled_window_size_request_init (GtkSizeRequestIface *iface)
1808 iface->get_width = gtk_scrolled_window_get_width;
1809 iface->get_height = gtk_scrolled_window_get_height;
1810 iface->get_height_for_width = gtk_scrolled_window_get_height_for_width;
1811 iface->get_width_for_height = gtk_scrolled_window_get_width_for_height;
1815 gtk_scrolled_window_get_size (GtkSizeRequest *widget,
1816 GtkOrientation orientation,
1820 GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
1821 GtkScrolledWindowPrivate *priv = scrolled_window->priv;
1822 GtkBin *bin = GTK_BIN (scrolled_window);
1825 gint scrollbar_spacing;
1826 GtkRequisition hscrollbar_requisition;
1827 GtkRequisition vscrollbar_requisition;
1828 GtkRequisition minimum_req, natural_req;
1831 gint min_child_size, nat_child_size;
1834 scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
1838 minimum_req.width = 0;
1839 minimum_req.height = 0;
1840 natural_req.width = 0;
1841 natural_req.height = 0;
1843 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->hscrollbar),
1844 &hscrollbar_requisition, NULL);
1845 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->vscrollbar),
1846 &vscrollbar_requisition, NULL);
1848 child = gtk_bin_get_child (bin);
1849 if (child && gtk_widget_get_visible (child))
1851 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1853 gtk_size_request_get_width (GTK_SIZE_REQUEST (child),
1857 if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
1859 minimum_req.width += min_child_size;
1860 natural_req.width += nat_child_size;
1864 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
1866 if (aux_info && aux_info->width > 0)
1868 minimum_req.width += aux_info->width;
1869 natural_req.width += aux_info->width;
1874 minimum_req.width += vscrollbar_requisition.width;
1875 natural_req.width += vscrollbar_requisition.width;
1879 else /* GTK_ORIENTATION_VERTICAL */
1881 gtk_size_request_get_height (GTK_SIZE_REQUEST (child),
1885 if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
1887 minimum_req.height += min_child_size;
1888 natural_req.height += nat_child_size;
1892 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
1894 if (aux_info && aux_info->height > 0)
1896 minimum_req.height += aux_info->height;
1897 natural_req.height += aux_info->height;
1902 minimum_req.height += hscrollbar_requisition.height;
1903 natural_req.height += hscrollbar_requisition.height;
1909 if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
1910 priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1912 minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
1913 natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
1914 if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
1915 extra_height = scrollbar_spacing + hscrollbar_requisition.height;
1918 if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
1919 priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1921 minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
1922 natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
1923 if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
1924 extra_width = scrollbar_spacing + vscrollbar_requisition.width;
1927 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1928 minimum_req.width += border_width * 2 + MAX (0, extra_width);
1929 minimum_req.height += border_width * 2 + MAX (0, extra_height);
1930 natural_req.width += border_width * 2 + MAX (0, extra_width);
1931 natural_req.height += border_width * 2 + MAX (0, extra_height);
1933 if (priv->shadow_type != GTK_SHADOW_NONE)
1935 style = gtk_widget_get_style (GTK_WIDGET (widget));
1936 minimum_req.width += 2 * style->xthickness;
1937 minimum_req.height += 2 * style->ythickness;
1938 natural_req.width += 2 * style->xthickness;
1939 natural_req.height += 2 * style->ythickness;
1942 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1945 *minimum_size = minimum_req.width;
1947 *natural_size = natural_req.width;
1952 *minimum_size = minimum_req.height;
1954 *natural_size = natural_req.height;
1959 gtk_scrolled_window_get_width (GtkSizeRequest *widget,
1963 gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
1967 gtk_scrolled_window_get_height (GtkSizeRequest *widget,
1971 gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
1975 gtk_scrolled_window_get_height_for_width (GtkSizeRequest *widget,
1977 gint *minimum_height,
1978 gint *natural_height)
1980 g_return_if_fail (GTK_IS_WIDGET (widget));
1982 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height (widget, minimum_height, natural_height);
1986 gtk_scrolled_window_get_width_for_height (GtkSizeRequest *widget,
1988 gint *minimum_width,
1989 gint *natural_width)
1991 g_return_if_fail (GTK_IS_WIDGET (widget));
1993 GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_width, natural_width);