* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include <math.h>
#include <gdk/gdkkeysyms.h>
-#include "gtkalias.h"
#include "gtkbindings.h"
#include "gtkmarshalers.h"
#include "gtkscrolledwindow.h"
+#include "gtkwindow.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkalias.h"
/* scrolled window policy and size requisition handling:
* to be best suited to display its contents, including children.
* the width and/or height reported from a widget upon size requisition
* may be overidden by the user by specifying a width and/or height
- * other than 0 through gtk_widget_set_usize().
+ * other than 0 through gtk_widget_set_size_request().
*
- * a scrolled window needs (for imlementing all three policy types) to
+ * a scrolled window needs (for implementing all three policy types) to
* request its width and height based on two different rationales.
* 1) the user wants the scrolled window to just fit into the space
* that it gets allocated for a specifc dimension.
#define DEFAULT_SCROLLBAR_SPACING 3
+typedef struct {
+ gboolean window_placement_set;
+ GtkCornerType real_window_placement;
+} GtkScrolledWindowPrivate;
+
+#define GTK_SCROLLED_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SCROLLED_WINDOW, GtkScrolledWindowPrivate))
+
enum {
PROP_0,
PROP_HADJUSTMENT,
PROP_HSCROLLBAR_POLICY,
PROP_VSCROLLBAR_POLICY,
PROP_WINDOW_PLACEMENT,
- PROP_SHADOW_TYPE,
- PROP_LAST
+ PROP_WINDOW_PLACEMENT_SET,
+ PROP_SHADOW_TYPE
};
/* Signals */
LAST_SIGNAL
};
-static void gtk_scrolled_window_class_init (GtkScrolledWindowClass *klass);
-static void gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window);
-static void gtk_scrolled_window_destroy (GtkObject *object);
-static void gtk_scrolled_window_finalize (GObject *object);
-static void gtk_scrolled_window_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_scrolled_window_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static gint gtk_scrolled_window_expose (GtkWidget *widget,
- GdkEventExpose *event);
-static void gtk_scrolled_window_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_scrolled_window_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gint gtk_scrolled_window_scroll_event (GtkWidget *widget,
- GdkEventScroll *event);
-static gint gtk_scrolled_window_focus (GtkWidget *widget,
- GtkDirectionType direction);
-static void gtk_scrolled_window_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_scrolled_window_remove (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_scrolled_window_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data);
-static void gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
- GtkScrollType scroll,
- gboolean horizontal);
-static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
- GtkDirectionType direction_type);
-
-static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
- GtkAllocation *allocation);
-static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
- gpointer data);
-
-static GtkContainerClass *parent_class = NULL;
+static void gtk_scrolled_window_destroy (GtkObject *object);
+static void gtk_scrolled_window_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_scrolled_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+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 void gtk_scrolled_window_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
+ GdkEventScroll *event);
+static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
+ GtkDirectionType direction);
+static void gtk_scrolled_window_add (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_scrolled_window_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_scrolled_window_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
+static gboolean gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
+ GtkScrollType scroll,
+ gboolean horizontal);
+static void gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
+ GtkDirectionType direction_type);
+
+static void gtk_scrolled_window_relative_allocation(GtkWidget *widget,
+ GtkAllocation *allocation);
+static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment,
+ gpointer data);
+
+static void gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window);
static guint signals[LAST_SIGNAL] = {0};
-GType
-gtk_scrolled_window_get_type (void)
-{
- static GType scrolled_window_type = 0;
-
- if (!scrolled_window_type)
- {
- static const GTypeInfo scrolled_window_info =
- {
- sizeof (GtkScrolledWindowClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_scrolled_window_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkScrolledWindow),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_scrolled_window_init,
- };
-
- scrolled_window_type =
- g_type_register_static (GTK_TYPE_BIN, "GtkScrolledWindow",
- &scrolled_window_info, 0);
- }
-
- return scrolled_window_type;
-}
+G_DEFINE_TYPE (GtkScrolledWindow, gtk_scrolled_window, GTK_TYPE_BIN)
static void
add_scroll_binding (GtkBindingSet *binding_set,
guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
gtk_binding_entry_add_signal (binding_set, keyval, mask,
- "scroll_child", 2,
+ "scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
gtk_binding_entry_add_signal (binding_set, keypad_keyval, mask,
- "scroll_child", 2,
+ "scroll-child", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
}
GtkDirectionType direction)
{
gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
- "move_focus_out", 1,
+ "move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
- "move_focus_out", 1,
+ "move-focus-out", 1,
GTK_TYPE_DIRECTION_TYPE, direction);
}
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
- parent_class = g_type_class_peek_parent (class);
-
- gobject_class->finalize = gtk_scrolled_window_finalize;
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->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->size_allocate = gtk_scrolled_window_size_allocate;
P_("Horizontal Adjustment"),
P_("The GtkAdjustment for the horizontal position"),
GTK_TYPE_ADJUSTMENT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_VADJUSTMENT,
g_param_spec_object ("vadjustment",
P_("Vertical Adjustment"),
P_("The GtkAdjustment for the vertical position"),
GTK_TYPE_ADJUSTMENT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class,
PROP_HSCROLLBAR_POLICY,
g_param_spec_enum ("hscrollbar-policy",
P_("When the horizontal scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_ALWAYS,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_VSCROLLBAR_POLICY,
g_param_spec_enum ("vscrollbar-policy",
P_("When the vertical scrollbar is displayed"),
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_ALWAYS,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_WINDOW_PLACEMENT,
g_param_spec_enum ("window-placement",
P_("Window Placement"),
- P_("Where the contents are located with respect to the scrollbars"),
+ P_("Where the contents are located with respect to the scrollbars. This property only takes effect if \"window-placement-set\" is TRUE."),
GTK_TYPE_CORNER_TYPE,
GTK_CORNER_TOP_LEFT,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
+
+ /**
+ * GtkScrolledWindow:window-placement-set:
+ *
+ * Whether "window-placement" should be used to determine the location
+ * of the contents with respect to the scrollbars. Otherwise, the
+ * "gtk-scrolled-window-placement" setting is used.
+ *
+ * Since: 2.10
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_WINDOW_PLACEMENT_SET,
+ g_param_spec_boolean ("window-placement-set",
+ P_("Window Placement Set"),
+ P_("Whether \"window-placement\" should be used to determine the location of the contents with respect to the scrollbars."),
+ FALSE,
+ GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE,
g_param_spec_enum ("shadow-type",
P_("Style of bevel around the contents"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_NONE,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READABLE | GTK_PARAM_WRITABLE));
+
+ /**
+ * GtkScrolledWindow:scrollbars-within-bevel:
+ *
+ * Whether to place scrollbars within the scrolled window's bevel.
+ *
+ * Since: 2.12
+ */
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boolean ("scrollbars-within-bevel",
+ P_("Scrollbars within bevel"),
+ P_("Place scrollbars within the scrolled window's bevel"),
+ FALSE,
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("scrollbar-spacing",
0,
G_MAXINT,
DEFAULT_SCROLLBAR_SPACING,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
+
+ /**
+ * GtkSettings:gtk-scrolled-window-placement:
+ *
+ * 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
+ */
+ 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 ("scroll_child",
+ g_signal_new (I_("scroll-child"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, scroll_child),
NULL, NULL,
- _gtk_marshal_VOID__ENUM_BOOLEAN,
- G_TYPE_NONE, 2,
+ _gtk_marshal_BOOLEAN__ENUM_BOOLEAN,
+ G_TYPE_BOOLEAN, 2,
GTK_TYPE_SCROLL_TYPE,
G_TYPE_BOOLEAN);
signals[MOVE_FOCUS_OUT] =
- g_signal_new ("move_focus_out",
+ g_signal_new (I_("move-focus-out"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkScrolledWindowClass, move_focus_out),
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);
+
+ g_type_class_add_private (class, sizeof (GtkScrolledWindowPrivate));
}
static void
scrolled_window->vscrollbar_visible = FALSE;
scrolled_window->focus_out = FALSE;
scrolled_window->window_placement = GTK_CORNER_TOP_LEFT;
-
+ gtk_scrolled_window_update_real_placement (scrolled_window);
}
+/**
+ * gtk_scrolled_window_new:
+ * @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
+ * 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.
+ *
+ * Returns: a new scrolled window
+ */
GtkWidget*
gtk_scrolled_window_new (GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment)
if (vadjustment)
g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL);
- scrolled_window = gtk_widget_new (GTK_TYPE_SCROLLED_WINDOW,
+ scrolled_window = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
"hadjustment", hadjustment,
"vadjustment", vadjustment,
NULL);
return scrolled_window;
}
+/**
+ * gtk_scrolled_window_set_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hadjustment: horizontal scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the horizontal scrollbar.
+ */
void
gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *hadjustment)
g_object_notify (G_OBJECT (scrolled_window), "hadjustment");
}
+/**
+ * gtk_scrolled_window_set_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @vadjustment: vertical scroll adjustment
+ *
+ * Sets the #GtkAdjustment for the vertical scrollbar.
+ */
void
gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
GtkAdjustment *vadjustment)
g_object_notify (G_OBJECT (scrolled_window), "vadjustment");
}
+/**
+ * gtk_scrolled_window_get_hadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the horizontal scrollbar's adjustment, used to connect the
+ * horizontal scrollbar to the child widget's horizontal scroll
+ * functionality.
+ *
+ * Returns: the horizontal #GtkAdjustment
+ */
GtkAdjustment*
gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window)
{
NULL);
}
+/**
+ * gtk_scrolled_window_get_vadjustment:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the vertical scrollbar's adjustment, used to connect the
+ * vertical scrollbar to the child widget's vertical scroll
+ * functionality.
+ *
+ * Returns: the vertical #GtkAdjustment
+ */
GtkAdjustment*
gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window)
{
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.
+ *
+ * Since: 2.8
+ */
+GtkWidget*
+gtk_scrolled_window_get_hscrollbar (GtkScrolledWindow *scrolled_window)
+{
+ g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
+
+ return scrolled_window->hscrollbar;
+}
+
+/**
+ * gtk_scrolled_window_get_vscrollbar:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Returns the vertical scrollbar of @scrolled_window.
+ *
+ * Returns: the vertical scrollbar of the scrolled window, or
+ * %NULL if it does not have one.
+ *
+ * Since: 2.8
+ */
+GtkWidget*
+gtk_scrolled_window_get_vscrollbar (GtkScrolledWindow *scrolled_window)
+{
+ g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL);
+
+ return scrolled_window->vscrollbar;
+}
+
+/**
+ * gtk_scrolled_window_set_policy:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @hscrollbar_policy: policy for horizontal bar
+ * @vscrollbar_policy: policy for vertical bar
+ *
+ * Sets the scrollbar policy for the horizontal and vertical scrollbars.
+ *
+ * The policy determines when the scrollbar should appear; it is a value
+ * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
+ * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
+ * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
+ * if needed (that is, if the slider part of the bar would be smaller
+ * than the trough - the display is larger than the page size).
+ */
void
gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType hscrollbar_policy,
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
g_object_freeze_notify (object);
- g_object_notify (object, "hscrollbar_policy");
- g_object_notify (object, "vscrollbar_policy");
+ g_object_notify (object, "hscrollbar-policy");
+ g_object_notify (object, "vscrollbar-policy");
g_object_thaw_notify (object);
}
}
/**
* gtk_scrolled_window_get_policy:
* @scrolled_window: a #GtkScrolledWindow
- * @hscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
- * @vscrollbar_policy: location to store the policy for the horizontal scrollbar, or %NULL.
+ * @hscrollbar_policy: location to store the policy for the horizontal
+ * scrollbar, or %NULL.
+ * @vscrollbar_policy: location to store the policy for the vertical
+ * scrollbar, or %NULL.
*
* Retrieves the current policy values for the horizontal and vertical
* scrollbars. See gtk_scrolled_window_set_policy().
- **/
+ */
void
gtk_scrolled_window_get_policy (GtkScrolledWindow *scrolled_window,
GtkPolicyType *hscrollbar_policy,
*vscrollbar_policy = scrolled_window->vscrollbar_policy;
}
-void
-gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
- GtkCornerType window_placement)
+static void
+gtk_scrolled_window_update_real_placement (GtkScrolledWindow *scrolled_window)
{
- g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+ 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;
+ else
+ g_object_get (settings,
+ "gtk-scrolled-window-placement",
+ &priv->real_window_placement,
+ NULL);
+}
+static void
+gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
+ GtkCornerType window_placement)
+{
if (scrolled_window->window_placement != window_placement)
{
scrolled_window->window_placement = window_placement;
+ gtk_scrolled_window_update_real_placement (scrolled_window);
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
- g_object_notify (G_OBJECT (scrolled_window), "window_placement");
+ g_object_notify (G_OBJECT (scrolled_window), "window-placement");
}
}
+static void
+gtk_scrolled_window_set_placement_set (GtkScrolledWindow *scrolled_window,
+ gboolean placement_set,
+ gboolean emit_resize)
+{
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
+ if (priv->window_placement_set != placement_set)
+ {
+ priv->window_placement_set = placement_set;
+
+ gtk_scrolled_window_update_real_placement (scrolled_window);
+ if (emit_resize)
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+ g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
+ }
+}
+
+/**
+ * gtk_scrolled_window_set_placement:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @window_placement: position of the child window
+ *
+ * Sets the placement of the contents with respect to the scrollbars
+ * for the scrolled window.
+ *
+ * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
+ * in the top left, with the scrollbars underneath and to the right.
+ * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
+ * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
+ *
+ * See also gtk_scrolled_window_get_placement() and
+ * gtk_scrolled_window_unset_placement().
+ */
+void
+gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window,
+ GtkCornerType window_placement)
+{
+ g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+ gtk_scrolled_window_set_placement_set (scrolled_window, TRUE, FALSE);
+ gtk_scrolled_window_set_placement_internal (scrolled_window, window_placement);
+}
+
/**
* gtk_scrolled_window_get_placement:
* @scrolled_window: a #GtkScrolledWindow
*
- * Gets the placement of the scrollbars for the scrolled window. See
- * gtk_scrolled_window_set_placement().
+ * Gets the placement of the contents with respect to the scrollbars
+ * for the scrolled window. See gtk_scrolled_window_set_placement().
*
* Return value: the current placement value.
+ *
+ * See also gtk_scrolled_window_set_placement() and
+ * gtk_scrolled_window_unset_placement().
**/
GtkCornerType
gtk_scrolled_window_get_placement (GtkScrolledWindow *scrolled_window)
return scrolled_window->window_placement;
}
+/**
+ * gtk_scrolled_window_unset_placement:
+ * @scrolled_window: a #GtkScrolledWindow
+ *
+ * Unsets the placement of the contents with respect to the scrollbars
+ * for the scrolled window. If no window placement is set for a scrolled
+ * window, it obeys the "gtk-scrolled-window-placement" XSETTING.
+ *
+ * See also gtk_scrolled_window_set_placement() and
+ * gtk_scrolled_window_get_placement().
+ *
+ * Since: 2.10
+ **/
+void
+gtk_scrolled_window_unset_placement (GtkScrolledWindow *scrolled_window)
+{
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
+ g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+ if (priv->window_placement_set)
+ {
+ priv->window_placement_set = FALSE;
+
+ gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
+
+ g_object_notify (G_OBJECT (scrolled_window), "window-placement-set");
+ }
+}
+
/**
* gtk_scrolled_window_set_shadow_type:
* @scrolled_window: a #GtkScrolledWindow
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));
- g_object_notify (G_OBJECT (scrolled_window), "shadow_type");
+ g_object_notify (G_OBJECT (scrolled_window), "shadow-type");
}
}
static void
gtk_scrolled_window_destroy (GtkObject *object)
-{
- GtkScrolledWindow *scrolled_window;
-
- g_return_if_fail (GTK_IS_SCROLLED_WINDOW (object));
-
- scrolled_window = GTK_SCROLLED_WINDOW (object);
-
- gtk_widget_unparent (scrolled_window->hscrollbar);
- gtk_widget_unparent (scrolled_window->vscrollbar);
- gtk_widget_destroy (scrolled_window->hscrollbar);
- gtk_widget_destroy (scrolled_window->vscrollbar);
-
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
-}
-
-static void
-gtk_scrolled_window_finalize (GObject *object)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
- g_object_unref (scrolled_window->hscrollbar);
- g_object_unref (scrolled_window->vscrollbar);
+ if (scrolled_window->hscrollbar)
+ {
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (scrolled_window->hscrollbar);
+ gtk_widget_destroy (scrolled_window->hscrollbar);
+ g_object_unref (scrolled_window->hscrollbar);
+ scrolled_window->hscrollbar = NULL;
+ }
+ if (scrolled_window->vscrollbar)
+ {
+ g_signal_handlers_disconnect_by_func (gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)),
+ gtk_scrolled_window_adjustment_changed,
+ scrolled_window);
+ gtk_widget_unparent (scrolled_window->vscrollbar);
+ gtk_widget_destroy (scrolled_window->vscrollbar);
+ g_object_unref (scrolled_window->vscrollbar);
+ scrolled_window->vscrollbar = NULL;
+ }
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ GTK_OBJECT_CLASS (gtk_scrolled_window_parent_class)->destroy (object);
}
static void
g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT:
- gtk_scrolled_window_set_placement (scrolled_window,
- g_value_get_enum (value));
+ gtk_scrolled_window_set_placement_internal (scrolled_window,
+ g_value_get_enum (value));
+ break;
+ case PROP_WINDOW_PLACEMENT_SET:
+ gtk_scrolled_window_set_placement_set (scrolled_window,
+ g_value_get_boolean (value),
+ TRUE);
break;
case PROP_SHADOW_TYPE:
gtk_scrolled_window_set_shadow_type (scrolled_window,
GParamSpec *pspec)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
switch (prop_id)
{
case PROP_WINDOW_PLACEMENT:
g_value_set_enum (value, scrolled_window->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);
break;
}
}
+static void
+traverse_container (GtkWidget *widget,
+ gpointer data)
+{
+ if (GTK_IS_SCROLLED_WINDOW (widget))
+ {
+ gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
+ gtk_widget_queue_resize (widget);
+ }
+ else if (GTK_IS_CONTAINER (widget))
+ gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
+}
+
+static void
+gtk_scrolled_window_settings_changed (GtkSettings *settings)
+{
+ GList *list, *l;
+
+ list = gtk_window_list_toplevels ();
+
+ for (l = list; l; l = l->next)
+ gtk_container_forall (GTK_CONTAINER (l->data),
+ traverse_container, NULL);
+
+ g_list_free (list);
+}
+
+static void
+gtk_scrolled_window_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen)
+{
+ GtkSettings *settings;
+ guint window_placement_connection;
+
+ gtk_scrolled_window_update_real_placement (GTK_SCROLLED_WINDOW (widget));
+
+ if (!gtk_widget_has_screen (widget))
+ return;
+
+ settings = gtk_widget_get_settings (widget);
+
+ window_placement_connection =
+ GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
+ "gtk-scrolled-window-connection"));
+
+ if (window_placement_connection)
+ return;
+
+ window_placement_connection =
+ g_signal_connect (settings, "notify::gtk-scrolled-window-placement",
+ G_CALLBACK (gtk_scrolled_window_settings_changed), NULL);
+ g_object_set_data (G_OBJECT (settings),
+ I_("gtk-scrolled-window-connection"),
+ GUINT_TO_POINTER (window_placement_connection));
+}
+
static void
gtk_scrolled_window_paint (GtkWidget *widget,
GdkRectangle *area)
{
- GtkAllocation relative_allocation;
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
{
- 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;
+ GtkAllocation relative_allocation;
+ gboolean scrollbars_within_bevel;
+
+ 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;
+ }
+ 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;
+ }
+
gtk_paint_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, scrolled_window->shadow_type,
area, widget, "scrolled_window",
}
}
-static gint
+static gboolean
gtk_scrolled_window_expose (GtkWidget *widget,
GdkEventExpose *event)
{
{
gtk_scrolled_window_paint (widget, &event->area);
- (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+ GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->expose_event (widget, event);
}
return FALSE;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container));
g_return_if_fail (callback != NULL);
- GTK_CONTAINER_CLASS (parent_class)->forall (container,
+ GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->forall (container,
include_internals,
callback,
callback_data);
}
}
-static void
+static gboolean
gtk_scrolled_window_scroll_child (GtkScrolledWindow *scrolled_window,
GtkScrollType scroll,
gboolean horizontal)
case GTK_SCROLL_END:
break;
default:
- g_warning ("Invalid scroll type %d for GtkSpinButton::change-value", scroll);
- return;
+ g_warning ("Invalid scroll type %u for GtkScrolledWindow::scroll-child", scroll);
+ return FALSE;
}
+ if ((horizontal && (!scrolled_window->hscrollbar || !scrolled_window->hscrollbar_visible)) ||
+ (!horizontal && (!scrolled_window->vscrollbar || !scrolled_window->vscrollbar_visible)))
+ return FALSE;
+
if (horizontal)
{
if (scrolled_window->hscrollbar)
value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
gtk_adjustment_set_value (adjustment, value);
+
+ return TRUE;
}
+
+ return FALSE;
}
static void
* 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);
+ g_signal_emit_by_name (toplevel, "move-focus", direction_type);
scrolled_window->focus_out = FALSE;
g_object_unref (scrolled_window);
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
+ GtkScrolledWindowPrivate *priv;
gint scrollbar_spacing;
g_return_if_fail (widget != NULL);
scrolled_window = GTK_SCROLLED_WINDOW (widget);
scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+ priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
+
allocation->x = GTK_CONTAINER (widget)->border_width;
allocation->y = GTK_CONTAINER (widget)->border_width;
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
if ((!is_rtl &&
- (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
+ (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
+ priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(is_rtl &&
- (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)))
+ (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
+ priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
allocation->x += (vscrollbar_requisition.width + scrollbar_spacing);
allocation->width = MAX (1, allocation->width - (vscrollbar_requisition.width + scrollbar_spacing));
gtk_widget_get_child_requisition (scrolled_window->hscrollbar,
&hscrollbar_requisition);
- if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+ 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->height = MAX (1, allocation->height - (hscrollbar_requisition.height + scrollbar_spacing));
GtkAllocation *allocation)
{
GtkScrolledWindow *scrolled_window;
+ GtkScrolledWindowPrivate *priv;
GtkBin *bin;
GtkAllocation relative_allocation;
GtkAllocation child_allocation;
+ gboolean scrollbars_within_bevel;
gint scrollbar_spacing;
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
bin = GTK_BIN (scrolled_window);
scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+ gtk_widget_style_get (widget, "scrollbars-within-bevel", &scrollbars_within_bevel, NULL);
+
+ priv = GTK_SCROLLED_WINDOW_GET_PRIVATE (scrolled_window);
widget->allocation = *allocation;
previous_vvis != scrolled_window->vscrollbar_visible);
}
else
- gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+ {
+ scrolled_window->hscrollbar_visible = scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS;
+ scrolled_window->vscrollbar_visible = scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS;
+ gtk_scrolled_window_relative_allocation (widget, &relative_allocation);
+ }
if (scrolled_window->hscrollbar_visible)
{
gtk_widget_show (scrolled_window->hscrollbar);
child_allocation.x = relative_allocation.x;
- if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
- scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT)
+ 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 +
if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
{
- child_allocation.x -= widget->style->xthickness;
- child_allocation.width += 2 * widget->style->xthickness;
+ if (!scrollbars_within_bevel)
+ {
+ child_allocation.x -= widget->style->xthickness;
+ child_allocation.width += 2 * widget->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;
+ }
+ else
+ {
+ child_allocation.y += widget->style->ythickness;
+ }
}
gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation);
&vscrollbar_requisition);
if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL &&
- (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
+ (priv->real_window_placement == GTK_CORNER_TOP_RIGHT ||
+ priv->real_window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
(gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR &&
- (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
- scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)))
+ (priv->real_window_placement == GTK_CORNER_TOP_LEFT ||
+ priv->real_window_placement == GTK_CORNER_BOTTOM_LEFT)))
child_allocation.x = (relative_allocation.x +
relative_allocation.width +
scrollbar_spacing +
if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
{
- child_allocation.y -= widget->style->ythickness;
- child_allocation.height += 2 * widget->style->ythickness;
+ if (!scrollbars_within_bevel)
+ {
+ child_allocation.y -= widget->style->ythickness;
+ child_allocation.height += 2 * widget->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;
+ }
+ else
+ {
+ child_allocation.x += widget->style->xthickness;
+ }
}
gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation);
gtk_widget_hide (scrolled_window->vscrollbar);
}
-static gint
-gtk_scrolled_window_scroll_event (GtkWidget *widget,
+static gboolean
+gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event)
{
GtkWidget *range;
return FALSE;
}
-static gint
+static gboolean
gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction)
{
return TRUE;
}
- if (!had_focus_child)
+ if (!had_focus_child && GTK_WIDGET_CAN_FOCUS (widget))
{
gtk_widget_grab_focus (widget);
return TRUE;
gtk_widget_set_scroll_adjustments (child, NULL, NULL);
/* chain parent class handler to remove child */
- GTK_CONTAINER_CLASS (parent_class)->remove (container, child);
+ GTK_CONTAINER_CLASS (gtk_scrolled_window_parent_class)->remove (container, child);
}
+/**
+ * gtk_scrolled_window_add_with_viewport:
+ * @scrolled_window: a #GtkScrolledWindow
+ * @child: the widget you want to scroll
+ *
+ * Used to add children without native scrolling capabilities. This
+ * is simply a convenience function; it is equivalent to adding the
+ * unscrollable child to a viewport, then adding the viewport to the
+ * scrolled window. If a child has native scrolling, use
+ * gtk_container_add() instead of this function.
+ *
+ * The viewport scrolls the child by moving its #GdkWindow, and takes
+ * the size of the child to be the size of its toplevel #GdkWindow.
+ * This will be very wrong for most widgets that support native scrolling;
+ * for example, if you add a widget such as #GtkTreeView with a viewport,
+ * the whole widget will scroll, including the column headings. Thus,
+ * widgets with native scrolling support should not be used with the
+ * #GtkViewport proxy.
+ *
+ * A widget supports scrolling natively if the
+ * set_scroll_adjustments_signal field in #GtkWidgetClass is non-zero,
+ * i.e. has been filled in with a valid signal identifier.
+ */
void
gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window,
GtkWidget *child)
gtk_container_add (GTK_CONTAINER (viewport), child);
}
-/**
+/*
* _gtk_scrolled_window_get_spacing:
* @scrolled_window: a scrolled window
*
* the scrolled widget. Used by GtkCombo
*
* Return value: the spacing, in pixels.
- **/
+ */
gint
_gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
{
gint scrollbar_spacing;
gtk_widget_style_get (GTK_WIDGET (scrolled_window),
- "scrollbar_spacing", &scrollbar_spacing,
+ "scrollbar-spacing", &scrollbar_spacing,
NULL);
return scrollbar_spacing;
}
}
+
+#define __GTK_SCROLLED_WINDOW_C__
+#include "gtkaliasdef.c"