#include "gtkmarshalers.h"
#include "gtkscrolledwindow.h"
#include "gtkwindow.h"
+#include "gtktypeutils.h"
#include "gtkprivate.h"
#include "gtkintl.h"
-#include "gtkalias.h"
+
+
+/**
+ * SECTION:gtkscrolledwindow
+ * @Short_description: Adds scrollbars to its child widget
+ * @Title: GtkScrolledWindow
+ * @See_also: #GtkViewport, #GtkAdjustment, #GtkWidgetClass
+ *
+ * #GtkScrolledWindow is a #GtkBin subclass: it's a container
+ * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
+ * to the child widget and optionally draws a beveled frame around the
+ * child widget.
+ *
+ * The scrolled window can work in two ways. Some widgets have native
+ * scrolling support; these widgets have "slots" for #GtkAdjustment
+ * objects.
+ * <footnote><para>The scrolled window installs #GtkAdjustment objects in
+ * the child window's slots using the set_scroll_adjustments_signal,
+ * found in #GtkWidgetClass. (Conceptually, these widgets implement a
+ * "Scrollable" interface; because GTK+ 1.2 lacked interface support in
+ * the object system, this interface is hackily implemented as a signal
+ * in #GtkWidgetClass. The GTK+ 2.0 object system would allow a clean
+ * implementation, but it wasn't worth breaking the
+ * API.)</para></footnote>
+ * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
+ * and #GtkLayout.
+ *
+ * For widgets that lack native scrolling support, the #GtkViewport
+ * widget acts as an adaptor class, implementing scrollability for child
+ * widgets that lack their own scrolling capabilities. Use #GtkViewport
+ * to scroll child widgets such as #GtkTable, #GtkBox, and so on.
+ *
+ * If a widget has native scrolling abilities, it can be added to the
+ * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
+ * must first add the widget to a #GtkViewport, then add the #GtkViewport
+ * to the scrolled window. The convenience function
+ * gtk_scrolled_window_add_with_viewport() does exactly this, so you can
+ * ignore the presence of the viewport.
+ *
+ * The position of the scrollbars is controlled by the scroll
+ * adjustments. See #GtkAdjustment for the fields in an adjustment - for
+ * #GtkScrollbar, used by #GtkScrolledWindow, the "value" field
+ * represents the position of the scrollbar, which must be between the
+ * "lower" field and "upper - page_size." The "page_size" field
+ * represents the size of the visible scrollable area. The
+ * "step_increment" and "page_increment" fields are used when the user
+ * asks to step down (using the small stepper arrows) or page down (using
+ * for example the PageDown key).
+ *
+ * If a #GtkScrolledWindow doesn't behave quite as you would like, or
+ * doesn't have exactly the right layout, it's very possible to set up
+ * your own scrolling with #GtkScrollbar and for example a #GtkTable.
+ */
/* scrolled window policy and size requisition handling:
#define DEFAULT_SCROLLBAR_SPACING 3
-typedef struct {
- gboolean window_placement_set;
- GtkCornerType real_window_placement;
-} GtkScrolledWindowPrivate;
+struct _GtkScrolledWindowPrivate
+{
+ GtkCornerType real_window_placement;
+ GtkWidget *hscrollbar;
+ GtkWidget *vscrollbar;
+
+ gboolean window_placement_set;
+
+ guint16 shadow_type;
+
+ guint hscrollbar_policy : 2;
+ guint vscrollbar_policy : 2;
+ guint hscrollbar_visible : 1;
+ guint vscrollbar_visible : 1;
+ guint window_placement : 2;
+ guint focus_out : 1; /* Flag used by ::move-focus-out implementation */
+};
-#define GTK_SCROLLED_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCROLLED_WINDOW, GtkScrolledWindowPrivate))
enum {
PROP_0,
LAST_SIGNAL
};
-static void gtk_scrolled_window_destroy (GtkObject *object);
static void gtk_scrolled_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
GValue *value,
GParamSpec *pspec);
+static void gtk_scrolled_window_destroy (GtkWidget *widget);
static void gtk_scrolled_window_screen_changed (GtkWidget *widget,
GdkScreen *previous_screen);
-static gboolean gtk_scrolled_window_expose (GtkWidget *widget,
- GdkEventExpose *event);
-static void gtk_scrolled_window_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static gboolean gtk_scrolled_window_draw (GtkWidget *widget,
+ cairo_t *cr);
static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
+static void gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *layout,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height);
+static void gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *layout,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height);
+
static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
+
static void
add_scroll_binding (GtkBindingSet *binding_set,
guint keyval,
GtkScrollType scroll,
gboolean horizontal)
{
- guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
+ guint keypad_keyval = keyval - GDK_KEY_Left + GDK_KEY_KP_Left;
gtk_binding_entry_add_signal (binding_set, keyval, mask,
"scroll-child", 2,
GdkModifierType modifiers,
GtkDirectionType direction)
{
- gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
"move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
}
gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkBindingSet *binding_set;
- object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
gobject_class->set_property = gtk_scrolled_window_set_property;
gobject_class->get_property = gtk_scrolled_window_get_property;
- object_class->destroy = gtk_scrolled_window_destroy;
-
+ widget_class->destroy = gtk_scrolled_window_destroy;
widget_class->screen_changed = gtk_scrolled_window_screen_changed;
- widget_class->expose_event = gtk_scrolled_window_expose;
- widget_class->size_request = gtk_scrolled_window_size_request;
+ widget_class->draw = gtk_scrolled_window_draw;
widget_class->size_allocate = gtk_scrolled_window_size_allocate;
widget_class->scroll_event = gtk_scrolled_window_scroll_event;
widget_class->focus = gtk_scrolled_window_focus;
+ widget_class->get_preferred_width = gtk_scrolled_window_get_preferred_width;
+ widget_class->get_preferred_height = gtk_scrolled_window_get_preferred_height;
+ widget_class->get_preferred_height_for_width = gtk_scrolled_window_get_preferred_height_for_width;
+ widget_class->get_preferred_width_for_height = gtk_scrolled_window_get_preferred_width_for_height;
container_class->add = gtk_scrolled_window_add;
container_class->remove = gtk_scrolled_window_remove;
container_class->forall = gtk_scrolled_window_forall;
+ gtk_container_class_handle_border_width (container_class);
class->scrollbar_spacing = -1;
P_("Horizontal Scrollbar Policy"),
P_("When the horizontal scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
- GTK_POLICY_ALWAYS,
+ GTK_POLICY_AUTOMATIC,
GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_VSCROLLBAR_POLICY,
P_("Vertical Scrollbar Policy"),
P_("When the vertical scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
- GTK_POLICY_ALWAYS,
+ GTK_POLICY_AUTOMATIC,
GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
GTK_PARAM_READABLE));
/**
- * GtkSettings:gtk-scrolled-window-placement:
+ * GtkScrolledWindow::scroll-child:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @scroll: a #GtkScrollType describing how much to scroll
+ * @horizontal: whether the keybinding scrolls the child
+ * horizontally or not
*
- * Where the contents of scrolled windows are located with respect to the
- * scrollbars, if not overridden by the scrolled window's own placement.
- *
- * Since: 2.10
+ * The ::scroll-child signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted when a keybinding that scrolls is pressed.
+ * The horizontal or vertical adjustment is updated which triggers a
+ * signal that the scrolled windows child may listen to and scroll itself.
*/
- gtk_settings_install_property (g_param_spec_enum ("gtk-scrolled-window-placement",
- P_("Scrolled Window Placement"),
- P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
- GTK_TYPE_CORNER_TYPE,
- GTK_CORNER_TOP_LEFT,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
-
-
signals[SCROLL_CHILD] =
g_signal_new (I_("scroll-child"),
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
NULL, NULL,
G_TYPE_BOOLEAN, 2,
GTK_TYPE_SCROLL_TYPE,
G_TYPE_BOOLEAN);
+
+ /**
+ * GtkScrolledWindow::move-focus-out:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @direction_type: either %GTK_DIR_TAB_FORWARD or
+ * %GTK_DIR_TAB_BACKWARD
+ *
+ * The ::move-focus-out signal is a
+ * <link linkend="keybinding-signals">keybinding signal</link>
+ * which gets emitted when focus is moved away from the scrolled
+ * window by a keybinding.
+ * The #GtkWidget::move-focus signal is emitted with @direction_type
+ * on this scrolled windows toplevel parent in the container hierarchy.
+ * The default bindings for this signal are
+ * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap></keycombo>
+ * and
+ * <keycombo><keycap>Tab</keycap><keycap>Ctrl</keycap><keycap>Shift</keycap></keycombo>.
+ */
signals[MOVE_FOCUS_OUT] =
g_signal_new (I_("move-focus-out"),
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
NULL, NULL,
binding_set = gtk_binding_set_by_class (class);
- add_scroll_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
- add_scroll_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_STEP_BACKWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_STEP_FORWARD, FALSE);
- add_scroll_binding (binding_set, GDK_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
- add_scroll_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_BACKWARD, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_FORWARD, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_BACKWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_FORWARD, FALSE);
- add_scroll_binding (binding_set, GDK_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
- add_scroll_binding (binding_set, GDK_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
- add_scroll_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START, FALSE);
- add_scroll_binding (binding_set, GDK_End, 0, GTK_SCROLL_END, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK, GTK_SCROLL_START, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK, GTK_SCROLL_END, TRUE);
+ add_scroll_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START, FALSE);
+ add_scroll_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END, FALSE);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
static void
gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
{
- GTK_WIDGET_SET_FLAGS (scrolled_window, GTK_NO_WINDOW | GTK_CAN_FOCUS);
-
- scrolled_window->hscrollbar = NULL;
- scrolled_window->vscrollbar = NULL;
- scrolled_window->hscrollbar_policy = GTK_POLICY_ALWAYS;
- scrolled_window->vscrollbar_policy = GTK_POLICY_ALWAYS;
- scrolled_window->hscrollbar_visible = FALSE;
- scrolled_window->vscrollbar_visible = FALSE;
- scrolled_window->focus_out = FALSE;
- scrolled_window->window_placement = GTK_CORNER_TOP_LEFT;
+ GtkScrolledWindowPrivate *priv;
+
+ scrolled_window->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (scrolled_window,
+ GTK_TYPE_SCROLLED_WINDOW,
+ GtkScrolledWindowPrivate);
+
+ gtk_widget_set_has_window (GTK_WIDGET (scrolled_window), FALSE);
+ gtk_widget_set_can_focus (GTK_WIDGET (scrolled_window), TRUE);
+
+ priv->hscrollbar = NULL;
+ priv->vscrollbar = NULL;
+ priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
+ priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
+ priv->hscrollbar_visible = FALSE;
+ priv->vscrollbar_visible = FALSE;
+ priv->focus_out = FALSE;
+ priv->window_placement = GTK_CORNER_TOP_LEFT;
gtk_scrolled_window_update_real_placement (scrolled_window);
}
/**
* gtk_scrolled_window_new:
- * @hadjustment: horizontal adjustment
- * @vadjustment: vertical adjustment
- *
- * Creates a new scrolled window.
+ * @hadjustment: (allow-none): horizontal adjustment
+ * @vadjustment: (allow-none): vertical adjustment
+ *
+ * Creates a new scrolled window.
*
- * The two arguments are the scrolled window's adjustments; these will be
+ * The two arguments are the scrolled window's adjustments; these will be
* shared with the scrollbars and the child widget to keep the bars in sync
* with the child. Usually you want to pass %NULL for the adjustments, which
* will cause the scrolled window to create them for you.
gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment)
{
+ GtkScrolledWindowPrivate *priv;
GtkBin *bin;
+ GtkWidget *child;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
if (hadjustment)
hadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
bin = GTK_BIN (scrolled_window);
+ priv = scrolled_window->priv;
- if (!scrolled_window->hscrollbar)
+ if (!priv->hscrollbar)
{
gtk_widget_push_composite_child ();
- scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
- gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
+ priv->hscrollbar = gtk_hscrollbar_new (hadjustment);
+ gtk_widget_set_composite_name (priv->hscrollbar, "hscrollbar");
gtk_widget_pop_composite_child ();
- gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window));
- g_object_ref (scrolled_window->hscrollbar);
- gtk_widget_show (scrolled_window->hscrollbar);
+ gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
+ g_object_ref (priv->hscrollbar);
+ gtk_widget_show (priv->hscrollbar);
}
else
{
GtkAdjustment *old_adjustment;
- old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
+ old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
if (old_adjustment == hadjustment)
return;
g_signal_handlers_disconnect_by_func (old_adjustment,
gtk_scrolled_window_adjustment_changed,
scrolled_window);
- gtk_range_set_adjustment (GTK_RANGE (scrolled_window->hscrollbar),
+ gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar),
hadjustment);
}
- hadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
+ hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
g_signal_connect (hadjustment,
"changed",
G_CALLBACK (gtk_scrolled_window_adjustment_changed),
scrolled_window);
gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window);
-
- if (bin->child)
- gtk_widget_set_scroll_adjustments (bin->child,
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)));
+
+ child = gtk_bin_get_child (bin);
+ if (child)
+ gtk_widget_set_scroll_adjustments (child,
+ gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
}
gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *vadjustment)
{
+ GtkScrolledWindowPrivate *priv;
GtkBin *bin;
+ GtkWidget *child;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
if (vadjustment)
vadjustment = (GtkAdjustment*) g_object_new (GTK_TYPE_ADJUSTMENT, NULL);
bin = GTK_BIN (scrolled_window);
+ priv = scrolled_window->priv;
- if (!scrolled_window->vscrollbar)
+ if (!priv->vscrollbar)
{
gtk_widget_push_composite_child ();
- scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment);
- gtk_widget_set_composite_name (scrolled_window->vscrollbar, "vscrollbar");
+ priv->vscrollbar = gtk_vscrollbar_new (vadjustment);
+ gtk_widget_set_composite_name (priv->vscrollbar, "vscrollbar");
gtk_widget_pop_composite_child ();
- gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window));
- g_object_ref (scrolled_window->vscrollbar);
- gtk_widget_show (scrolled_window->vscrollbar);
+ gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
+ g_object_ref (priv->vscrollbar);
+ gtk_widget_show (priv->vscrollbar);
}
else
{
GtkAdjustment *old_adjustment;
- old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ old_adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
if (old_adjustment == vadjustment)
return;
g_signal_handlers_disconnect_by_func (old_adjustment,
gtk_scrolled_window_adjustment_changed,
scrolled_window);
- gtk_range_set_adjustment (GTK_RANGE (scrolled_window->vscrollbar),
+ gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar),
vadjustment);
}
- vadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
g_signal_connect (vadjustment,
"changed",
G_CALLBACK (gtk_scrolled_window_adjustment_changed),
scrolled_window);
gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window);
- if (bin->child)
- gtk_widget_set_scroll_adjustments (bin->child,
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)));
+ child = gtk_bin_get_child (bin);
+ if (child)
+ gtk_widget_set_scroll_adjustments (child,
+ gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)));
g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
}
* horizontal scrollbar to the child widget's horizontal scroll
* functionality.
*
- * Returns: the horizontal #GtkAdjustment
+ * Returns: (transfer none): the horizontal #GtkAdjustment
*/
GtkAdjustment*
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
{
+ GtkScrolledWindowPrivate *priv;
+
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
- return (scrolled_window->hscrollbar ?
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)) :
+ priv = scrolled_window->priv;
+
+ return (priv->hscrollbar ?
+ gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)) :
NULL);
}
* @scrolled_window: a #GtkScrolledWindow
*
* Returns the vertical scrollbar's adjustment, used to connect the
- * vertical scrollbar to the child widget's vertical scroll
- * functionality.
+ * vertical scrollbar to the child widget's vertical scroll functionality.
*
- * Returns: the vertical #GtkAdjustment
+ * Returns: (transfer none): the vertical #GtkAdjustment
*/
GtkAdjustment*
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
{
+ GtkScrolledWindowPrivate *priv;
+
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
- return (scrolled_window->vscrollbar ?
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)) :
+ priv = scrolled_window->priv;
+
+ return (priv->vscrollbar ?
+ gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)) :
NULL);
}
/**
* gtk_scrolled_window_get_hscrollbar:
* @scrolled_window: a #GtkScrolledWindow
- *
+ *
* Returns the horizontal scrollbar of @scrolled_window.
*
- * Returns: the horizontal scrollbar of the scrolled window, or
- * %NULL if it does not have one.
+ * Returns: (transfer none): the horizontal scrollbar of the scrolled window,
+ * or %NULL if it does not have one.
*
* Since: 2.8
*/
gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
-
- return scrolled_window->hscrollbar;
+
+ return scrolled_window->priv->hscrollbar;
}
/**
*
* Returns the vertical scrollbar of @scrolled_window.
*
- * Returns: the vertical scrollbar of the scrolled window, or
- * %NULL if it does not have one.
+ * Returns: (transfer none): the vertical scrollbar of the scrolled window,
+ * or %NULL if it does not have one.
*
* Since: 2.8
*/
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
- return scrolled_window->vscrollbar;
+ return scrolled_window->priv->vscrollbar;
}
/**
GtkPolicyType hscrollbar_policy,
GtkPolicyType vscrollbar_policy)
{
+ GtkScrolledWindowPrivate *priv;
GObject *object = G_OBJECT (scrolled_window);
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
- if ((scrolled_window->hscrollbar_policy != hscrollbar_policy) ||
- (scrolled_window->vscrollbar_policy != vscrollbar_policy))
+ priv = scrolled_window->priv;
+
+ if ((priv->hscrollbar_policy != hscrollbar_policy) ||
+ (priv->vscrollbar_policy != vscrollbar_policy))
{
- scrolled_window->hscrollbar_policy = hscrollbar_policy;
- scrolled_window->vscrollbar_policy = vscrollbar_policy;
+ priv->hscrollbar_policy = hscrollbar_policy;
+ priv->vscrollbar_policy = vscrollbar_policy;
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
GtkPolicyType *hscrollbar_policy,
GtkPolicyType *vscrollbar_policy)
{
+ GtkScrolledWindowPrivate *priv;
+
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+ priv = scrolled_window->priv;
+
if (hscrollbar_policy)
- *hscrollbar_policy = scrolled_window->hscrollbar_policy;
+ *hscrollbar_policy = priv->hscrollbar_policy;
if (vscrollbar_policy)
- *vscrollbar_policy = scrolled_window->vscrollbar_policy;
+ *vscrollbar_policy = priv->vscrollbar_policy;
}
static void
gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
{
- GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkSettings *settings;
settings = gtk_widget_get_settings (GTK_WIDGET (scrolled_window));
if (priv->window_placement_set || settings == NULL)
- priv->real_window_placement = scrolled_window->window_placement;
+ priv->real_window_placement = priv->window_placement;
else
g_object_get (settings,
"gtk-scrolled-window-placement",
gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
GtkCornerType window_placement)
{
- if (scrolled_window->window_placement != window_placement)
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+
+ if (priv->window_placement != window_placement)
{
- scrolled_window->window_placement = window_placement;
+ priv->window_placement = window_placement;
gtk_scrolled_window_update_real_placement (scrolled_window);
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
gboolean placement_set,
gboolean emit_resize)
{
- GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
if (priv->window_placement_set != placement_set)
{
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_CORNER_TOP_LEFT);
- return scrolled_window->window_placement;
+ return scrolled_window->priv->window_placement;
}
/**
void
gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
{
- GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ GtkScrolledWindowPrivate *priv;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+ priv = scrolled_window->priv;
+
if (priv->window_placement_set)
{
priv->window_placement_set = FALSE;
gtk_scrolled_window_set_shadow_type (GtkScrolledWindow *scrolled_window,
GtkShadowType type)
{
+ GtkScrolledWindowPrivate *priv;
+
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
g_return_if_fail (type >= GTK_SHADOW_NONE && type <= GTK_SHADOW_ETCHED_OUT);
-
- if (scrolled_window->shadow_type != type)
+
+ priv = scrolled_window->priv;
+
+ if (priv->shadow_type != type)
{
- scrolled_window->shadow_type = type;
+ priv->shadow_type = type;
- if (GTK_WIDGET_DRAWABLE (scrolled_window))
+ if (gtk_widget_is_drawable (GTK_WIDGET (scrolled_window)))
gtk_widget_queue_draw (GTK_WIDGET (scrolled_window));
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
{
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE);
- return scrolled_window->shadow_type;
+ return scrolled_window->priv->shadow_type;
}
static void
-gtk_scrolled_window_destroy (GtkObject *object)
+gtk_scrolled_window_destroy (GtkWidget *widget)
{
- GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
+ GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
- if (scrolled_window->hscrollbar)
+ if (priv->hscrollbar)
{
- gtk_widget_unparent (scrolled_window->hscrollbar);
- gtk_widget_destroy (scrolled_window->hscrollbar);
- g_object_unref (scrolled_window->hscrollbar);
- scrolled_window->hscrollbar = NULL;
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (priv->hscrollbar);
+ gtk_widget_destroy (priv->hscrollbar);
+ g_object_unref (priv->hscrollbar);
+ priv->hscrollbar = NULL;
}
- if (scrolled_window->vscrollbar)
+ if (priv->vscrollbar)
{
- gtk_widget_unparent (scrolled_window->vscrollbar);
- gtk_widget_destroy (scrolled_window->vscrollbar);
- g_object_unref (scrolled_window->vscrollbar);
- scrolled_window->vscrollbar = NULL;
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (priv->vscrollbar);
+ gtk_widget_destroy (priv->vscrollbar);
+ g_object_unref (priv->vscrollbar);
+ priv->vscrollbar = NULL;
}
- GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
}
static void
GParamSpec *pspec)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
-
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+
switch (prop_id)
{
case PROP_HADJUSTMENT:
case PROP_HSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
g_value_get_enum (value),
- scrolled_window->vscrollbar_policy);
+ priv->vscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
gtk_scrolled_window_set_policy (scrolled_window,
- scrolled_window->hscrollbar_policy,
+ priv->hscrollbar_policy,
g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT:
GParamSpec *pspec)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
- GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
-
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+
switch (prop_id)
{
case PROP_HADJUSTMENT:
G_OBJECT (gtk_scrolled_window_get_vadjustment (scrolled_window)));
break;
case PROP_HSCROLLBAR_POLICY:
- g_value_set_enum (value, scrolled_window->hscrollbar_policy);
+ g_value_set_enum (value, priv->hscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
- g_value_set_enum (value, scrolled_window->vscrollbar_policy);
+ g_value_set_enum (value, priv->vscrollbar_policy);
break;
case PROP_WINDOW_PLACEMENT:
- g_value_set_enum (value, scrolled_window->window_placement);
+ g_value_set_enum (value, priv->window_placement);
break;
case PROP_WINDOW_PLACEMENT_SET:
g_value_set_boolean (value, priv->window_placement_set);
break;
case PROP_SHADOW_TYPE:
- g_value_set_enum (value, scrolled_window->shadow_type);
+ g_value_set_enum (value, priv->shadow_type);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
GUINT_TO_POINTER (window_placement_connection));
}
-static void
-gtk_scrolled_window_paint (GtkWidget *widget,
- GdkRectangle *area)
+static gboolean
+gtk_scrolled_window_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
- if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
+ if (priv->shadow_type != GTK_SHADOW_NONE)
{
GtkAllocation relative_allocation;
+ GtkStyle *style;
gboolean scrollbars_within_bevel;
+ style = gtk_widget_get_style (widget);
gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
-
+
if (!scrollbars_within_bevel)
{
gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
- relative_allocation.x -= widget->style->xthickness;
- relative_allocation.y -= widget->style->ythickness;
- relative_allocation.width += 2 * widget->style->xthickness;
- relative_allocation.height += 2 * widget->style->ythickness;
+ relative_allocation.x -= style->xthickness;
+ relative_allocation.y -= style->ythickness;
+ relative_allocation.width += 2 * style->xthickness;
+ relative_allocation.height += 2 * style->ythickness;
}
else
{
- GtkContainer *container = GTK_CONTAINER (widget);
-
- relative_allocation.x = container->border_width;
- relative_allocation.y = container->border_width;
- relative_allocation.width = widget->allocation.width - 2 * container->border_width;
- relative_allocation.height = widget->allocation.height - 2 * container->border_width;
+ relative_allocation.x = 0;
+ relative_allocation.y = 0;
+ relative_allocation.width = gtk_widget_get_allocated_width (widget);
+ relative_allocation.height = gtk_widget_get_allocated_height (widget);
}
- gtk_paint_shadow (widget->style, widget->window,
- GTK_STATE_NORMAL, scrolled_window->shadow_type,
- area, widget, "scrolled_window",
- widget->allocation.x + relative_allocation.x,
- widget->allocation.y + relative_allocation.y,
+ gtk_paint_shadow (style,
+ cr,
+ GTK_STATE_NORMAL, priv->shadow_type,
+ widget, "scrolled_window",
+ relative_allocation.x,
+ relative_allocation.y,
relative_allocation.width,
relative_allocation.height);
}
-}
-
-static gboolean
-gtk_scrolled_window_expose (GtkWidget *widget,
- GdkEventExpose *event)
-{
- if (GTK_WIDGET_DRAWABLE (widget))
- {
- gtk_scrolled_window_paint (widget, &event->area);
- GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event (widget, event);
- }
+ GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->draw (widget, cr);
return FALSE;
}
GtkCallback callback,
gpointer callback_data)
{
+ GtkScrolledWindowPrivate *priv;
+ GtkScrolledWindow *scrolled_window;
+
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (callback != NULL);
callback_data);
if (include_internals)
{
- GtkScrolledWindow *scrolled_window;
-
scrolled_window = GTK_SCROLLED_WINDOW (container);
-
- if (scrolled_window->vscrollbar)
- callback (scrolled_window->vscrollbar, callback_data);
- if (scrolled_window->hscrollbar)
- callback (scrolled_window->hscrollbar, callback_data);
+ priv = scrolled_window->priv;
+
+ if (priv->vscrollbar)
+ callback (priv->vscrollbar, callback_data);
+ if (priv->hscrollbar)
+ callback (priv->hscrollbar, callback_data);
}
}
GtkScrollType scroll,
gboolean horizontal)
{
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkAdjustment *adjustment = NULL;
switch (scroll)
return FALSE;
}
- if ((horizontal && (!scrolled_window->hscrollbar || !scrolled_window->hscrollbar_visible)) ||
- (!horizontal && (!scrolled_window->vscrollbar || !scrolled_window->vscrollbar_visible)))
+ if ((horizontal && (!priv->hscrollbar || !priv->hscrollbar_visible)) ||
+ (!horizontal && (!priv->vscrollbar || !priv->vscrollbar_visible)))
return FALSE;
if (horizontal)
{
- if (scrolled_window->hscrollbar)
- adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar));
+ if (priv->hscrollbar)
+ adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
}
else
{
- if (scrolled_window->vscrollbar)
- adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar));
+ if (priv->vscrollbar)
+ adjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
}
if (adjustment)
break;
}
- value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
-
gtk_adjustment_set_value (adjustment, value);
return TRUE;
gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
GtkDirectionType direction_type)
{
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkWidget *toplevel;
/* Focus out of the scrolled window entirely. We do this by setting
* a flag, then propagating the focus motion to the notebook.
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
- if (!GTK_WIDGET_TOPLEVEL (toplevel))
+ if (!gtk_widget_is_toplevel (toplevel))
return;
g_object_ref (scrolled_window);
-
- scrolled_window->focus_out = TRUE;
- g_signal_emit_by_name (toplevel, "move-focus", direction_type);
- scrolled_window->focus_out = FALSE;
-
- g_object_unref (scrolled_window);
-}
-
-static void
-gtk_scrolled_window_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkScrolledWindow *scrolled_window;
- GtkBin *bin;
- gint extra_width;
- gint extra_height;
- gint scrollbar_spacing;
- GtkRequisition hscrollbar_requisition;
- GtkRequisition vscrollbar_requisition;
- GtkRequisition child_requisition;
-
- g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
- g_return_if_fail (requisition != NULL);
-
- scrolled_window = GTK_SCROLLED_WINDOW (widget);
- bin = GTK_BIN (scrolled_window);
-
- scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
-
- extra_width = 0;
- extra_height = 0;
- requisition->width = 0;
- requisition->height = 0;
-
- gtk_widget_size_request (scrolled_window->hscrollbar,
- &hscrollbar_requisition);
- gtk_widget_size_request (scrolled_window->vscrollbar,
- &vscrollbar_requisition);
-
- if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
- {
- gtk_widget_size_request (bin->child, &child_requisition);
-
- if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER)
- requisition->width += child_requisition.width;
- else
- {
- GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (bin->child, FALSE);
-
- if (aux_info && aux_info->width > 0)
- {
- requisition->width += aux_info->width;
- extra_width = -1;
- }
- else
- requisition->width += vscrollbar_requisition.width;
- }
-
- if (scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
- requisition->height += child_requisition.height;
- else
- {
- GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (bin->child, FALSE);
-
- if (aux_info && aux_info->height > 0)
- {
- requisition->height += aux_info->height;
- extra_height = -1;
- }
- else
- requisition->height += hscrollbar_requisition.height;
- }
- }
-
- if (scrolled_window->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
- scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
- {
- requisition->width = MAX (requisition->width, hscrollbar_requisition.width);
- if (!extra_height || scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
- extra_height = scrollbar_spacing + hscrollbar_requisition.height;
- }
-
- if (scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
- scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
- {
- requisition->height = MAX (requisition->height, vscrollbar_requisition.height);
- if (!extra_height || scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
- extra_width = scrollbar_spacing + vscrollbar_requisition.width;
- }
- requisition->width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
- requisition->height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);
+ priv->focus_out = TRUE;
+ g_signal_emit_by_name (toplevel, "move-focus", direction_type);
+ priv->focus_out = FALSE;
- if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
- {
- requisition->width += 2 * widget->style->xthickness;
- requisition->height += 2 * widget->style->ythickness;
- }
+ g_object_unref (scrolled_window);
}
static void
gtk_scrolled_window_relative_allocation (GtkWidget *widget,
GtkAllocation *allocation)
{
+ GtkAllocation widget_allocation;
GtkScrolledWindow *scrolled_window;
GtkScrolledWindowPrivate *priv;
- gint scrollbar_spacing;
+ GtkStyle *style;
+ gint sb_spacing;
+ gint sb_width;
+ gint sb_height;
g_return_if_fail (widget != NULL);
g_return_if_fail (allocation != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
- scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+ priv = scrolled_window->priv;
- priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ /* Get possible scrollbar dimensions */
+ sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+ gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
+ gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
- allocation->x = GTK_CONTAINER (widget)->border_width;
- allocation->y = GTK_CONTAINER (widget)->border_width;
+ /* Subtract some things from our available allocation size */
+ allocation->x = 0;
+ allocation->y = 0;
- if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
+ if (priv->shadow_type != GTK_SHADOW_NONE)
{
- allocation->x += widget->style->xthickness;
- allocation->y += widget->style->ythickness;
+ style = gtk_widget_get_style (widget);
+ allocation->x += style->xthickness;
+ allocation->y += style->ythickness;
}
-
- allocation->width = MAX (1, (gint)widget->allocation.width - allocation->x * 2);
- allocation->height = MAX (1, (gint)widget->allocation.height - allocation->y * 2);
- if (scrolled_window->vscrollbar_visible)
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ allocation->width = MAX (1, (gint) widget_allocation.width - allocation->x * 2);
+ allocation->height = MAX (1, (gint) widget_allocation.height - allocation->y * 2);
+
+ if (priv->vscrollbar_visible)
{
- GtkRequisition vscrollbar_requisition;
gboolean is_rtl;
- gtk_widget_get_child_requisition (scrolled_window->vscrollbar,
- &vscrollbar_requisition);
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
if ((!is_rtl &&
(is_rtl &&
(priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
- allocation->x += (vscrollbar_requisition.width + scrollbar_spacing);
+ allocation->x += (sb_width + sb_spacing);
- allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
+ allocation->width = MAX (1, allocation->width - (sb_width + sb_spacing));
}
- if (scrolled_window->hscrollbar_visible)
+ if (priv->hscrollbar_visible)
{
- GtkRequisition hscrollbar_requisition;
- gtk_widget_get_child_requisition (scrolled_window->hscrollbar,
- &hscrollbar_requisition);
-
+
if (priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT ||
priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)
- allocation->y += (hscrollbar_requisition.height + scrollbar_spacing);
+ allocation->y += (sb_height + sb_spacing);
- allocation->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
+ allocation->height = MAX (1, allocation->height - (sb_height + sb_spacing));
}
}
{
GtkScrolledWindow *scrolled_window;
GtkScrolledWindowPrivate *priv;
+ GtkStyle *style;
GtkBin *bin;
GtkAllocation relative_allocation;
GtkAllocation child_allocation;
+ GtkWidget *child;
gboolean scrollbars_within_bevel;
- gint scrollbar_spacing;
-
+ gint sb_spacing;
+ gint sb_width;
+ gint sb_height;
+
+
+
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
g_return_if_fail (allocation != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
bin = GTK_BIN (scrolled_window);
+ priv = scrolled_window->priv;
- scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
- gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
+ /* Get possible scrollbar dimensions */
+ sb_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+ gtk_widget_get_preferred_height (priv->hscrollbar, &sb_height, NULL);
+ gtk_widget_get_preferred_width (priv->vscrollbar, &sb_width, NULL);
- priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ style = gtk_widget_get_style (widget);
+ gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
- if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
- scrolled_window->hscrollbar_visible = TRUE;
- else if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER)
- scrolled_window->hscrollbar_visible = FALSE;
- if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
- scrolled_window->vscrollbar_visible = TRUE;
- else if (scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
- scrolled_window->vscrollbar_visible = FALSE;
+ if (priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ priv->hscrollbar_visible = TRUE;
+ else if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
+ priv->hscrollbar_visible = FALSE;
+ if (priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ priv->vscrollbar_visible = TRUE;
+ else if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
+ priv->vscrollbar_visible = FALSE;
- if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+ child = gtk_bin_get_child (bin);
+ if (child && gtk_widget_get_visible (child))
{
+ gint child_min_width;
+ gint child_min_height;
gboolean previous_hvis;
gboolean previous_vvis;
guint count = 0;
-
+
+ /* In the case that both scrollbars are visible in the previous round,
+ * we dont do our guess-work before hand because it's possible some
+ * infinite recursion was detected (leave it up to the child scrollable
+ * widget in this case to drive the scrollbar visibility completely
+ * with the adjustment values).
+ */
+ if (!priv->vscrollbar_visible || !priv->hscrollbar_visible)
+ {
+
+ /* Determine scrollbar visibility first via hfw apis */
+ if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ {
+ gtk_widget_get_preferred_width (child, &child_min_width, NULL);
+
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ /* First try without a vertical scrollbar if the content will fit the height
+ * given the extra width of the scrollbar */
+ gtk_widget_get_preferred_height_for_width (child, allocation->width,
+ &child_min_height, NULL);
+
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ /* Does the content height fit the allocation height ? */
+ priv->vscrollbar_visible = child_min_height > allocation->height;
+
+ /* Does the content width fit the allocation with minus a possible scrollbar ? */
+ priv->hscrollbar_visible =
+ child_min_width > allocation->width -
+ (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+
+ /* Now that we've guessed the hscrollbar, does the content height fit
+ * the possible new allocation height ? */
+ priv->vscrollbar_visible =
+ child_min_height > allocation->height -
+ (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+
+ /* Now that we've guessed the vscrollbar, does the content width fit
+ * the possible new allocation width ? */
+ priv->hscrollbar_visible =
+ child_min_width > allocation->width -
+ (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+ }
+ else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
+ {
+ priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+ priv->vscrollbar_visible = child_min_height > allocation->height -
+ (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+ }
+ }
+ else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
+ {
+ priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ priv->hscrollbar_visible =
+ child_min_width > allocation->width -
+ (priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
+ else
+ priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+ }
+ }
+ else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
+ {
+ gtk_widget_get_preferred_height (child, &child_min_height, NULL);
+
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ /* First try without a horizontal scrollbar if the content will fit the width
+ * given the extra height of the scrollbar */
+ gtk_widget_get_preferred_width_for_height (child, allocation->height,
+ &child_min_width, NULL);
+
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ {
+ /* Does the content width fit the allocation width ? */
+ priv->hscrollbar_visible = child_min_width > allocation->width;
+
+ /* Does the content height fit the allocation with minus a possible scrollbar ? */
+ priv->vscrollbar_visible =
+ child_min_height > allocation->height -
+ (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+
+ /* Now that we've guessed the vscrollbar, does the content width fit
+ * the possible new allocation width ? */
+ priv->hscrollbar_visible =
+ child_min_width > allocation->width -
+ (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+
+ /* Now that we've guessed the hscrollbar, does the content height fit
+ * the possible new allocation height ? */
+ priv->vscrollbar_visible =
+ child_min_height > allocation->height -
+ (priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
+ }
+ else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
+ {
+ priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+ priv->hscrollbar_visible = child_min_width > allocation->width -
+ (priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
+ }
+ }
+ else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
+ {
+ priv->hscrollbar_visible = priv->hscrollbar_policy != GTK_POLICY_NEVER;
+
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ priv->vscrollbar_visible =
+ child_min_height > allocation->height -
+ (priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
+ else
+ priv->vscrollbar_visible = priv->vscrollbar_policy != GTK_POLICY_NEVER;
+ }
+ }
+ }
+
+ /* Now after guessing scrollbar visibility; fall back on the allocation loop which
+ * observes the adjustments to detect scrollbar visibility and also avoids
+ * infinite recursion
+ */
do
{
gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
child_allocation.y = relative_allocation.y + allocation->y;
child_allocation.width = relative_allocation.width;
child_allocation.height = relative_allocation.height;
-
- previous_hvis = scrolled_window->hscrollbar_visible;
- previous_vvis = scrolled_window->vscrollbar_visible;
-
- gtk_widget_size_allocate (bin->child, &child_allocation);
+
+ previous_hvis = priv->hscrollbar_visible;
+ previous_vvis = priv->vscrollbar_visible;
+
+ gtk_widget_size_allocate (child, &child_allocation);
/* If, after the first iteration, the hscrollbar and the
* vscrollbar flip visiblity, then we need both.
*/
if (count &&
- previous_hvis != scrolled_window->hscrollbar_visible &&
- previous_vvis != scrolled_window->vscrollbar_visible)
+ previous_hvis != priv->hscrollbar_visible &&
+ previous_vvis != priv->vscrollbar_visible)
{
- scrolled_window->hscrollbar_visible = TRUE;
- scrolled_window->vscrollbar_visible = TRUE;
+ priv->hscrollbar_visible = TRUE;
+ priv->vscrollbar_visible = TRUE;
/* a new resize is already queued at this point,
* so we will immediatedly get reinvoked
count++;
}
- while (previous_hvis != scrolled_window->hscrollbar_visible ||
- previous_vvis != scrolled_window->vscrollbar_visible);
+ while (previous_hvis != priv->hscrollbar_visible ||
+ previous_vvis != priv->vscrollbar_visible);
}
else
{
- scrolled_window->hscrollbar_visible = scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS;
- scrolled_window->vscrollbar_visible = scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS;
+ priv->hscrollbar_visible = priv->hscrollbar_policy == GTK_POLICY_ALWAYS;
+ priv->vscrollbar_visible = priv->vscrollbar_policy == GTK_POLICY_ALWAYS;
gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
}
-
- if (scrolled_window->hscrollbar_visible)
+
+ if (priv->hscrollbar_visible)
{
- GtkRequisition hscrollbar_requisition;
- gtk_widget_get_child_requisition (scrolled_window->hscrollbar,
- &hscrollbar_requisition);
-
- if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
- gtk_widget_show (scrolled_window->hscrollbar);
+ if (!gtk_widget_get_visible (priv->hscrollbar))
+ gtk_widget_show (priv->hscrollbar);
child_allocation.x = relative_allocation.x;
if (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
priv->real_window_placement == GTK_CORNER_TOP_RIGHT)
child_allocation.y = (relative_allocation.y +
relative_allocation.height +
- scrollbar_spacing +
- (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
- 0 : widget->style->ythickness));
+ sb_spacing +
+ (priv->shadow_type == GTK_SHADOW_NONE ?
+ 0 : style->ythickness));
else
- child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width;
+ child_allocation.y = 0;
child_allocation.width = relative_allocation.width;
- child_allocation.height = hscrollbar_requisition.height;
+ child_allocation.height = sb_height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
- if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
+ if (priv->shadow_type != GTK_SHADOW_NONE)
{
if (!scrollbars_within_bevel)
{
- child_allocation.x -= widget->style->xthickness;
- child_allocation.width += 2 * widget->style->xthickness;
+ child_allocation.x -= style->xthickness;
+ child_allocation.width += 2 * style->xthickness;
}
else if (GTK_CORNER_TOP_RIGHT == priv->real_window_placement ||
GTK_CORNER_TOP_LEFT == priv->real_window_placement)
{
- child_allocation.y -= widget->style->ythickness;
+ child_allocation.y -= style->ythickness;
}
else
{
- child_allocation.y += widget->style->ythickness;
+ child_allocation.y += style->ythickness;
}
}
- gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation);
+ gtk_widget_size_allocate (priv->hscrollbar, &child_allocation);
}
- else if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar))
- gtk_widget_hide (scrolled_window->hscrollbar);
+ else if (gtk_widget_get_visible (priv->hscrollbar))
+ gtk_widget_hide (priv->hscrollbar);
- if (scrolled_window->vscrollbar_visible)
+ if (priv->vscrollbar_visible)
{
- GtkRequisition vscrollbar_requisition;
- if (!GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
- gtk_widget_show (scrolled_window->vscrollbar);
-
- gtk_widget_get_child_requisition (scrolled_window->vscrollbar,
- &vscrollbar_requisition);
+ if (!gtk_widget_get_visible (priv->vscrollbar))
+ gtk_widget_show (priv->vscrollbar);
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
(priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
child_allocation.x = (relative_allocation.x +
relative_allocation.width +
- scrollbar_spacing +
- (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
- 0 : widget->style->xthickness));
+ sb_spacing +
+ (priv->shadow_type == GTK_SHADOW_NONE ?
+ 0 : style->xthickness));
else
- child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width;
+ child_allocation.x = 0;
child_allocation.y = relative_allocation.y;
- child_allocation.width = vscrollbar_requisition.width;
+ child_allocation.width = sb_width;
child_allocation.height = relative_allocation.height;
child_allocation.x += allocation->x;
child_allocation.y += allocation->y;
- if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
+ if (priv->shadow_type != GTK_SHADOW_NONE)
{
if (!scrollbars_within_bevel)
{
- child_allocation.y -= widget->style->ythickness;
- child_allocation.height += 2 * widget->style->ythickness;
+ child_allocation.y -= style->ythickness;
+ child_allocation.height += 2 * style->ythickness;
}
else if (GTK_CORNER_BOTTOM_LEFT == priv->real_window_placement ||
GTK_CORNER_TOP_LEFT == priv->real_window_placement)
{
- child_allocation.x -= widget->style->xthickness;
+ child_allocation.x -= style->xthickness;
}
else
{
- child_allocation.x += widget->style->xthickness;
+ child_allocation.x += style->xthickness;
}
}
- gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation);
+ gtk_widget_size_allocate (priv->vscrollbar, &child_allocation);
}
- else if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
- gtk_widget_hide (scrolled_window->vscrollbar);
+ else if (gtk_widget_get_visible (priv->vscrollbar))
+ gtk_widget_hide (priv->vscrollbar);
}
static gboolean
gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event)
{
+ GtkScrolledWindowPrivate *priv;
+ GtkScrolledWindow *scrolled_window;
GtkWidget *range;
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
+ scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ priv = scrolled_window->priv;
+
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
- range = GTK_SCROLLED_WINDOW (widget)->vscrollbar;
+ range = priv->vscrollbar;
else
- range = GTK_SCROLLED_WINDOW (widget)->hscrollbar;
+ range = priv->hscrollbar;
- if (range && GTK_WIDGET_VISIBLE (range))
+ if (range && gtk_widget_get_visible (range))
{
- GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
- gdouble delta, new_value;
+ GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
+ gdouble delta;
delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event->direction);
- new_value = CLAMP (adj->value + delta, adj->lower, adj->upper - adj->page_size);
-
- gtk_adjustment_set_value (adj, new_value);
+ gtk_adjustment_set_value (adj, adj->value + delta);
return TRUE;
}
GtkDirectionType direction)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
- gboolean had_focus_child = GTK_CONTAINER (widget)->focus_child != NULL;
-
- if (scrolled_window->focus_out)
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+ GtkWidget *child;
+ gboolean had_focus_child;
+
+ had_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget)) != NULL;
+
+ if (priv->focus_out)
{
- scrolled_window->focus_out = FALSE; /* Clear this to catch the wrap-around case */
+ priv->focus_out = FALSE; /* Clear this to catch the wrap-around case */
return FALSE;
}
/* We only put the scrolled window itself in the focus chain if it
* isn't possible to focus any children.
*/
- if (GTK_BIN (widget)->child)
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child)
{
- if (gtk_widget_child_focus (GTK_BIN (widget)->child, direction))
+ if (gtk_widget_child_focus (child, direction))
return TRUE;
}
- if (!had_focus_child && GTK_WIDGET_CAN_FOCUS (widget))
+ if (!had_focus_child && gtk_widget_get_can_focus (widget))
{
gtk_widget_grab_focus (widget);
return TRUE;
gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
gpointer data)
{
- GtkScrolledWindow *scrolled_win;
+ GtkScrolledWindowPrivate *priv;;
+ GtkScrolledWindow *scrolled_window;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (data != NULL);
- scrolled_win = GTK_SCROLLED_WINDOW (data);
+ scrolled_window = GTK_SCROLLED_WINDOW (data);
+ priv = scrolled_window->priv;
- if (scrolled_win->hscrollbar &&
- adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->hscrollbar)))
+ if (priv->hscrollbar &&
+ adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)))
{
- if (scrolled_win->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
gboolean visible;
-
- visible = scrolled_win->hscrollbar_visible;
- scrolled_win->hscrollbar_visible = (adjustment->upper - adjustment->lower >
+
+ visible = priv->hscrollbar_visible;
+ priv->hscrollbar_visible = (adjustment->upper - adjustment->lower >
adjustment->page_size);
- if (scrolled_win->hscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
+ if (priv->hscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
- else if (scrolled_win->vscrollbar &&
- adjustment == gtk_range_get_adjustment (GTK_RANGE (scrolled_win->vscrollbar)))
+ else if (priv->vscrollbar &&
+ adjustment == gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar)))
{
- if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
{
gboolean visible;
- visible = scrolled_win->vscrollbar_visible;
- scrolled_win->vscrollbar_visible = (adjustment->upper - adjustment->lower >
+ visible = priv->vscrollbar_visible;
+ priv->vscrollbar_visible = (adjustment->upper - adjustment->lower >
adjustment->page_size);
- if (scrolled_win->vscrollbar_visible != visible)
- gtk_widget_queue_resize (GTK_WIDGET (scrolled_win));
+ if (priv->vscrollbar_visible != visible)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
}
}
}
gtk_scrolled_window_add (GtkContainer *container,
GtkWidget *child)
{
+ GtkScrolledWindowPrivate *priv;
GtkScrolledWindow *scrolled_window;
GtkBin *bin;
+ GtkWidget *child_widget;
bin = GTK_BIN (container);
- g_return_if_fail (bin->child == NULL);
+ child_widget = gtk_bin_get_child (bin);
+ g_return_if_fail (child_widget == NULL);
scrolled_window = GTK_SCROLLED_WINDOW (container);
+ priv = scrolled_window->priv;
- bin->child = child;
+ _gtk_bin_set_child (bin, child);
gtk_widget_set_parent (child, GTK_WIDGET (bin));
/* this is a temporary message */
if (!gtk_widget_set_scroll_adjustments (child,
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
- gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar))))
+ gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar)),
+ gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar))))
g_warning ("gtk_scrolled_window_add(): cannot add non scrollable widget "
"use gtk_scrolled_window_add_with_viewport() instead");
}
{
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (child != NULL);
- g_return_if_fail (GTK_BIN (container)->child == child);
+ g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == child);
gtk_widget_set_scroll_adjustments (child, NULL, NULL);
{
GtkBin *bin;
GtkWidget *viewport;
+ GtkWidget *child_widget;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
g_return_if_fail (GTK_IS_WIDGET (child));
- g_return_if_fail (child->parent == NULL);
+ g_return_if_fail (gtk_widget_get_parent (child) == NULL);
bin = GTK_BIN (scrolled_window);
+ child_widget = gtk_bin_get_child (bin);
- if (bin->child != NULL)
+ if (child_widget)
{
- g_return_if_fail (GTK_IS_VIEWPORT (bin->child));
- g_return_if_fail (GTK_BIN (bin->child)->child == NULL);
+ g_return_if_fail (GTK_IS_VIEWPORT (child_widget));
+ g_return_if_fail (gtk_bin_get_child (GTK_BIN (child_widget)) == NULL);
- viewport = bin->child;
+ viewport = child_widget;
}
else
{
}
}
-#define __GTK_SCROLLED_WINDOW_C__
-#include "gtkaliasdef.c"
+
+static void
+gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+ GtkBin *bin = GTK_BIN (scrolled_window);
+ gint extra_width;
+ gint extra_height;
+ gint scrollbar_spacing;
+ GtkRequisition hscrollbar_requisition;
+ GtkRequisition vscrollbar_requisition;
+ GtkRequisition minimum_req, natural_req;
+ GtkStyle *style;
+ GtkWidget *child;
+ gint min_child_size, nat_child_size;
+
+ scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+
+ extra_width = 0;
+ extra_height = 0;
+ minimum_req.width = 0;
+ minimum_req.height = 0;
+ natural_req.width = 0;
+ natural_req.height = 0;
+
+ gtk_widget_get_preferred_size (priv->hscrollbar,
+ &hscrollbar_requisition, NULL);
+ gtk_widget_get_preferred_size (priv->vscrollbar,
+ &vscrollbar_requisition, NULL);
+
+ child = gtk_bin_get_child (bin);
+ if (child && gtk_widget_get_visible (child))
+ {
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_widget_get_preferred_width (child,
+ &min_child_size,
+ &nat_child_size);
+
+ if (priv->hscrollbar_policy == GTK_POLICY_NEVER)
+ {
+ minimum_req.width += min_child_size;
+ natural_req.width += nat_child_size;
+ }
+ else
+ {
+ /* Always ask for at least enough to fit the scrollbars */
+ minimum_req.width += vscrollbar_requisition.width;
+ natural_req.width += vscrollbar_requisition.width;
+ }
+ }
+ else /* GTK_ORIENTATION_VERTICAL */
+ {
+ gtk_widget_get_preferred_height (child,
+ &min_child_size,
+ &nat_child_size);
+
+ if (priv->vscrollbar_policy == GTK_POLICY_NEVER)
+ {
+ minimum_req.height += min_child_size;
+ natural_req.height += nat_child_size;
+ }
+ else
+ {
+ /* Always ask for at least enough to fit the scrollbars */
+ minimum_req.height += hscrollbar_requisition.height;
+ natural_req.height += hscrollbar_requisition.height;
+ }
+ }
+ }
+
+ if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
+ priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ {
+ minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
+ natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
+ if (!extra_height || priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ extra_height = scrollbar_spacing + hscrollbar_requisition.height;
+ }
+
+ if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
+ priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ {
+ minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
+ natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
+ if (!extra_height || priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ extra_width = scrollbar_spacing + vscrollbar_requisition.width;
+ }
+
+ minimum_req.width += extra_width;
+ minimum_req.height += extra_height;
+ natural_req.width += extra_width;
+ natural_req.height += extra_height;
+
+ if (priv->shadow_type != GTK_SHADOW_NONE)
+ {
+ style = gtk_widget_get_style (GTK_WIDGET (widget));
+ minimum_req.width += 2 * style->xthickness;
+ minimum_req.height += 2 * style->ythickness;
+ natural_req.width += 2 * style->xthickness;
+ natural_req.height += 2 * style->ythickness;
+ }
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ if (minimum_size)
+ *minimum_size = minimum_req.width;
+ if (natural_size)
+ *natural_size = natural_req.width;
+ }
+ else
+ {
+ if (minimum_size)
+ *minimum_size = minimum_req.height;
+ if (natural_size)
+ *natural_size = natural_req.height;
+ }
+}
+
+static void
+gtk_scrolled_window_get_preferred_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+}
+
+static void
+gtk_scrolled_window_get_preferred_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gtk_scrolled_window_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+}
+
+static void
+gtk_scrolled_window_get_preferred_height_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
+}
+
+static void
+gtk_scrolled_window_get_preferred_width_for_height (GtkWidget *widget,
+ gint height,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
+}