diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-05-07 08:30:39 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-11 22:21:33 -0400 |
commit | bc6643f3c22a61c0ce6072cf3e2d33e552d19fe0 (patch) | |
tree | 2399d5a46a6597b4465338ed4f2ae85a25a21e2e /gtk/gtkpaned.c | |
parent | fc9873e9ef1e9a81913565335654776eeb7f5f8f (diff) | |
download | gtk+-bc6643f3c22a61c0ce6072cf3e2d33e552d19fe0.tar.gz |
paned: Redo the api
This commit is porting GtkPaned to be derived
from GtkWidget instead of GtkContainer, while adding
start-child and end-child properties. The existing
properties are renamed to follow the start/end naming
scheme, and we add proper getters and setters.
Update all users.
See #2719
Diffstat (limited to 'gtk/gtkpaned.c')
-rw-r--r-- | gtk/gtkpaned.c | 1508 |
1 files changed, 788 insertions, 720 deletions
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index 146c51d001..dd6c16acd7 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -41,6 +41,7 @@ #include "gtktypebuiltins.h" #include "gtkwidgetprivate.h" #include "gtkcssboxesprivate.h" +#include "gtkbuildable.h" #include "a11y/gtkpanedaccessible.h" @@ -56,9 +57,9 @@ * the two panes is adjustable by the user by dragging * a handle. * - * Child widgets are - * added to the panes of the widget with gtk_paned_pack1() and - * gtk_paned_pack2(). The division between the two children is set by default + * Child widgets are added to the panes of the widget with + * gtk_paned_set_start_child() and gtk_paned_set_end_child(). + * The division between the two children is set by default * from the size requests of the children, but it can be adjusted by the * user. * @@ -66,9 +67,8 @@ * small handle that the user can drag to adjust the division. It does not * draw any relief around the children or around the separator. (The space * in which the separator is called the gutter.) Often, it is useful to put - * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN - * so that the gutter appears as a ridge. No separator is drawn if one of - * the children is missing. + * each child inside a #GtkFrame so that the gutter appears as a ridge. + * No separator is drawn if one of the children is missing. * * Each child has two options that can be set, @resize and @shrink. If * @resize is true, then when the #GtkPaned is resized, that child will @@ -122,12 +122,12 @@ typedef struct _GtkPanedClass GtkPanedClass; struct _GtkPaned { - GtkContainer parent_instance; + GtkWidget parent_instance; }; struct _GtkPanedClass { - GtkContainerClass parent_class; + GtkWidgetClass parent_class; gboolean (* cycle_child_focus) (GtkPaned *paned, gboolean reverse); @@ -143,10 +143,10 @@ struct _GtkPanedClass typedef struct { GtkPaned *first_paned; - GtkWidget *child1; - GtkWidget *child2; - GtkWidget *last_child1_focus; - GtkWidget *last_child2_focus; + GtkWidget *start_child; + GtkWidget *end_child; + GtkWidget *last_start_child_focus; + GtkWidget *last_end_child_focus; GtkWidget *saved_focus; GtkOrientation orientation; @@ -155,7 +155,7 @@ typedef struct GtkGesture *pan_gesture; /* Used for touch */ GtkGesture *drag_gesture; /* Used for mice */ - gint child1_size; + gint start_child_size; gint drag_pos; gint last_allocation; gint max_position; @@ -163,10 +163,10 @@ typedef struct gint original_position; guint in_recursion : 1; - guint child1_resize : 1; - guint child1_shrink : 1; - guint child2_resize : 1; - guint child2_shrink : 1; + guint resize_start_child : 1; + guint shrink_start_child : 1; + guint resize_end_child : 1; + guint shrink_end_child : 1; guint position_set : 1; guint panning : 1; } GtkPanedPrivate; @@ -178,10 +178,12 @@ enum { PROP_MIN_POSITION, PROP_MAX_POSITION, PROP_WIDE_HANDLE, - PROP_RESIZE_CHILD1, - PROP_RESIZE_CHILD2, - PROP_SHRINK_CHILD1, - PROP_SHRINK_CHILD2, + PROP_RESIZE_START_CHILD, + PROP_RESIZE_END_CHILD, + PROP_SHRINK_START_CHILD, + PROP_SHRINK_END_CHILD, + PROP_START_CHILD, + PROP_END_CHILD, LAST_PROP, /* GtkOrientable */ @@ -199,14 +201,14 @@ enum { }; static void gtk_paned_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); + guint prop_id, + const GValue *value, + GParamSpec *pspec); static void gtk_paned_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void gtk_paned_finalize (GObject *object); + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void gtk_paned_dispose (GObject *object); static void gtk_paned_measure (GtkWidget *widget, GtkOrientation orientation, int for_size, @@ -219,58 +221,51 @@ static void gtk_paned_size_allocate (GtkWidget *widget, int height, int baseline); static void gtk_paned_unrealize (GtkWidget *widget); -static gboolean gtk_paned_focus (GtkWidget *widget, - GtkDirectionType direction); static void gtk_paned_css_changed (GtkWidget *widget, GtkCssStyleChange *change); -static void gtk_paned_add (GtkContainer *container, - GtkWidget *widget); -static void gtk_paned_remove (GtkContainer *container, - GtkWidget *widget); -static void gtk_paned_forall (GtkContainer *container, - GtkCallback callback, - gpointer callback_data); static void gtk_paned_calc_position (GtkPaned *paned, gint allocation, - gint child1_req, - gint child2_req); + gint start_child_req, + gint end_child_req); static void gtk_paned_set_focus_child (GtkWidget *widget, - GtkWidget *child); + GtkWidget *child); static void gtk_paned_set_saved_focus (GtkPaned *paned, - GtkWidget *widget); + GtkWidget *widget); static void gtk_paned_set_first_paned (GtkPaned *paned, - GtkPaned *first_paned); -static void gtk_paned_set_last_child1_focus (GtkPaned *paned, - GtkWidget *widget); -static void gtk_paned_set_last_child2_focus (GtkPaned *paned, - GtkWidget *widget); + GtkPaned *first_paned); +static void gtk_paned_set_last_start_child_focus (GtkPaned *paned, + GtkWidget *widget); +static void gtk_paned_set_last_end_child_focus (GtkPaned *paned, + GtkWidget *widget); static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned, - gboolean reverse); + gboolean reverse); static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned, - gboolean reverse); + gboolean reverse); static gboolean gtk_paned_move_handle (GtkPaned *paned, - GtkScrollType scroll); + GtkScrollType scroll); static gboolean gtk_paned_accept_position (GtkPaned *paned); static gboolean gtk_paned_cancel_position (GtkPaned *paned); static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned); -static GType gtk_paned_child_type (GtkContainer *container); - static void update_drag (GtkPaned *paned, int xpos, int ypos); -G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER, +static void gtk_paned_buildable_iface_init (GtkBuildableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_WIDGET, G_ADD_PRIVATE (GtkPaned) G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, - NULL)) + NULL) + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + gtk_paned_buildable_iface_init)) static guint signals[LAST_SIGNAL] = { 0 }; static GParamSpec *paned_props[LAST_PROP] = { NULL, }; static void add_tab_bindings (GtkWidgetClass *widget_class, - GdkModifierType modifiers) + GdkModifierType modifiers) { gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Tab, modifiers, @@ -278,19 +273,19 @@ add_tab_bindings (GtkWidgetClass *widget_class, NULL); gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Tab, modifiers, - "toggle-handle-focus", + "toggle-handle-focus", NULL); } static void add_move_binding (GtkWidgetClass *widget_class, - guint keyval, - GdkModifierType mask, - GtkScrollType scroll) + guint keyval, + GdkModifierType mask, + GtkScrollType scroll) { gtk_widget_class_add_binding_signal (widget_class, keyval, mask, - "move-handle", + "move-handle", "(i)", scroll); } @@ -331,27 +326,93 @@ gtk_paned_handle_contains (GtkGizmo *handle, } static void +gtk_paned_compute_expand (GtkWidget *widget, + gboolean *hexpand, + gboolean *vexpand) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (GTK_PANED (widget)); + gboolean h = FALSE; + gboolean v = FALSE; + + if (priv->start_child) + { + h = h || gtk_widget_compute_expand (priv->start_child, GTK_ORIENTATION_HORIZONTAL); + v = v || gtk_widget_compute_expand (priv->start_child, GTK_ORIENTATION_VERTICAL); + } + + if (priv->end_child) + { + h = h || gtk_widget_compute_expand (priv->end_child, GTK_ORIENTATION_HORIZONTAL); + v = v || gtk_widget_compute_expand (priv->end_child, GTK_ORIENTATION_VERTICAL); + } + + *hexpand = h; + *vexpand = v; +} + +static GtkSizeRequestMode +gtk_paned_get_request_mode (GtkWidget *widget) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (GTK_PANED (widget)); + int wfh = 0, hfw = 0; + + if (priv->start_child) + { + switch (gtk_widget_get_request_mode (priv->start_child)) + { + case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: + hfw++; + break; + case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: + wfh++; + break; + case GTK_SIZE_REQUEST_CONSTANT_SIZE: + default: + break; + } + } + if (priv->end_child) + { + switch (gtk_widget_get_request_mode (priv->end_child)) + { + case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: + hfw++; + break; + case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: + wfh++; + break; + case GTK_SIZE_REQUEST_CONSTANT_SIZE: + default: + break; + } + } + + if (hfw == 0 && wfh == 0) + return GTK_SIZE_REQUEST_CONSTANT_SIZE; + else + return wfh > hfw ? + GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT : + GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; +} + +static void gtk_paned_class_init (GtkPanedClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class); object_class->set_property = gtk_paned_set_property; object_class->get_property = gtk_paned_get_property; - object_class->finalize = gtk_paned_finalize; + object_class->dispose = gtk_paned_dispose; widget_class->measure = gtk_paned_measure; widget_class->size_allocate = gtk_paned_size_allocate; widget_class->unrealize = gtk_paned_unrealize; - widget_class->focus = gtk_paned_focus; + widget_class->focus = gtk_widget_focus_child; widget_class->set_focus_child = gtk_paned_set_focus_child; widget_class->css_changed = gtk_paned_css_changed; - - container_class->add = gtk_paned_add; - container_class->remove = gtk_paned_remove; - container_class->forall = gtk_paned_forall; - container_class->child_type = gtk_paned_child_type; + widget_class->get_request_mode = gtk_paned_get_request_mode; + widget_class->compute_expand = gtk_paned_compute_expand; class->cycle_child_focus = gtk_paned_cycle_child_focus; class->toggle_handle_focus = gtk_paned_toggle_handle_focus; @@ -360,7 +421,6 @@ gtk_paned_class_init (GtkPanedClass *class) class->accept_position = gtk_paned_accept_position; class->cancel_position = gtk_paned_cancel_position; - paned_props[PROP_POSITION] = g_param_spec_int ("position", P_("Position"), @@ -418,57 +478,71 @@ gtk_paned_class_init (GtkPanedClass *class) GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); /** - * GtkPaned:resize-child1: + * GtkPaned:resize-start-child: * - * The "resize-child1" property determines whether the first child expands and + * The "resize-start-child" property determines whether the first child expands and * shrinks along with the paned widget. */ - paned_props[PROP_RESIZE_CHILD1] = - g_param_spec_boolean ("resize-child1", + paned_props[PROP_RESIZE_START_CHILD] = + g_param_spec_boolean ("resize-start-child", P_("Resize first child"), P_("If TRUE, the first child expands and shrinks along with the paned widget"), TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); /** - * GtkPaned:resize-child2: + * GtkPaned:resize-end-child: * - * The "resize-child2" property determines whether the second child expands and + * The "resize-end-child" property determines whether the second child expands and * shrinks along with the paned widget. */ - paned_props[PROP_RESIZE_CHILD2] = - g_param_spec_boolean ("resize-child2", + paned_props[PROP_RESIZE_END_CHILD] = + g_param_spec_boolean ("resize-end-child", P_("Resize second child"), P_("If TRUE, the second child expands and shrinks along with the paned widget"), TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); /** - * GtkPaned:shrink-child1: + * GtkPaned:shrink-start-child: * - * The "shrink-child1" property determines whether the first child can be made + * The "shrink-start-child" property determines whether the first child can be made * smaller than its requisition. */ - paned_props[PROP_SHRINK_CHILD1] = - g_param_spec_boolean ("shrink-child1", + paned_props[PROP_SHRINK_START_CHILD] = + g_param_spec_boolean ("shrink-start-child", P_("Shrink first child"), P_("If TRUE, the first child can be made smaller than its requisition"), TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); /** - * GtkPaned:shrink-child2: + * GtkPaned:shrink-end-child: * - * The "shrink-child2" property determines whether the second child can be made + * The "shrink-end-child" property determines whether the second child can be made * smaller than its requisition. */ - paned_props[PROP_SHRINK_CHILD2] = - g_param_spec_boolean ("shrink-child2", + paned_props[PROP_SHRINK_END_CHILD] = + g_param_spec_boolean ("shrink-end-child", P_("Shrink second child"), P_("If TRUE, the second child can be made smaller than its requisition"), TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + paned_props[PROP_START_CHILD] = + g_param_spec_object ("start-child", + P_("First child"), + P_("The first child"), + GTK_TYPE_WIDGET, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + + paned_props[PROP_END_CHILD] = + g_param_spec_object ("end-child", + P_("Second child"), + P_("The second child"), + GTK_TYPE_WIDGET, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + g_object_class_install_properties (object_class, LAST_PROP, paned_props); g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation"); @@ -477,7 +551,7 @@ gtk_paned_class_init (GtkPanedClass *class) * @widget: the object that received the signal * @reversed: whether cycling backward or forward * - * The ::cycle-child-focus signal is a + * The ::cycle-child-focus signal is a * [keybinding signal][GtkBindingSignal] * which gets emitted to cycle the focus between the children of the paned. * @@ -485,47 +559,47 @@ gtk_paned_class_init (GtkPanedClass *class) */ signals [CYCLE_CHILD_FOCUS] = g_signal_new (I_("cycle-child-focus"), - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus), - NULL, NULL, - _gtk_marshal_BOOLEAN__BOOLEAN, - G_TYPE_BOOLEAN, 1, - G_TYPE_BOOLEAN); + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus), + NULL, NULL, + _gtk_marshal_BOOLEAN__BOOLEAN, + G_TYPE_BOOLEAN, 1, + G_TYPE_BOOLEAN); /** * GtkPaned::toggle-handle-focus: * @widget: the object that received the signal * - * The ::toggle-handle-focus is a + * The ::toggle-handle-focus is a * [keybinding signal][GtkBindingSignal] - * which gets emitted to accept the current position of the handle and then + * which gets emitted to accept the current position of the handle and then * move focus to the next widget in the focus chain. * * The default binding is Tab. */ signals [TOGGLE_HANDLE_FOCUS] = g_signal_new (I_("toggle-handle-focus"), - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus), - NULL, NULL, - _gtk_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus), + NULL, NULL, + _gtk_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); /** * GtkPaned::move-handle: * @widget: the object that received the signal * @scroll_type: a #GtkScrollType * - * The ::move-handle signal is a + * The ::move-handle signal is a * [keybinding signal][GtkBindingSignal] - * which gets emitted to move the handle when the user is using key bindings + * which gets emitted to move the handle when the user is using key bindings * to move it. */ signals[MOVE_HANDLE] = g_signal_new (I_("move-handle"), - G_TYPE_FROM_CLASS (object_class), + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GtkPanedClass, move_handle), NULL, NULL, @@ -538,7 +612,7 @@ gtk_paned_class_init (GtkPanedClass *class) * @widget: the object that received the signal * @reversed: whether cycling backward or forward * - * The ::cycle-handle-focus signal is a + * The ::cycle-handle-focus signal is a * [keybinding signal][GtkBindingSignal] * which gets emitted to cycle whether the paned should grab focus to allow * the user to change position of the handle by using key bindings. @@ -547,54 +621,54 @@ gtk_paned_class_init (GtkPanedClass *class) */ signals [CYCLE_HANDLE_FOCUS] = g_signal_new (I_("cycle-handle-focus"), - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus), - NULL, NULL, - _gtk_marshal_BOOLEAN__BOOLEAN, - G_TYPE_BOOLEAN, 1, - G_TYPE_BOOLEAN); + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus), + NULL, NULL, + _gtk_marshal_BOOLEAN__BOOLEAN, + G_TYPE_BOOLEAN, 1, + G_TYPE_BOOLEAN); /** * GtkPaned::accept-position: * @widget: the object that received the signal * - * The ::accept-position signal is a + * The ::accept-position signal is a * [keybinding signal][GtkBindingSignal] - * which gets emitted to accept the current position of the handle when + * which gets emitted to accept the current position of the handle when * moving it using key bindings. * * The default binding for this signal is Return or Space. */ signals [ACCEPT_POSITION] = g_signal_new (I_("accept-position"), - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkPanedClass, accept_position), - NULL, NULL, - _gtk_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkPanedClass, accept_position), + NULL, NULL, + _gtk_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); /** * GtkPaned::cancel-position: * @widget: the object that received the signal * - * The ::cancel-position signal is a + * The ::cancel-position signal is a * [keybinding signal][GtkBindingSignal] - * which gets emitted to cancel moving the position of the handle using key - * bindings. The position of the handle will be reset to the value prior to + * which gets emitted to cancel moving the position of the handle using key + * bindings. The position of the handle will be reset to the value prior to * moving it. * * The default binding for this signal is Escape. */ signals [CANCEL_POSITION] = g_signal_new (I_("cancel-position"), - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GtkPanedClass, cancel_position), - NULL, NULL, - _gtk_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GtkPanedClass, cancel_position), + NULL, NULL, + _gtk_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); /* F6 and friends */ gtk_widget_class_add_binding_signal (widget_class, @@ -602,20 +676,20 @@ gtk_paned_class_init (GtkPanedClass *class) "cycle-child-focus", "(b)", FALSE); gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_F6, GDK_SHIFT_MASK, + GDK_KEY_F6, GDK_SHIFT_MASK, "cycle-child-focus", "(b)", TRUE); /* F8 and friends */ gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_F8, 0, - "cycle-handle-focus", + GDK_KEY_F8, 0, + "cycle-handle-focus", "(b)", FALSE); gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_F8, GDK_SHIFT_MASK, - "cycle-handle-focus", + GDK_KEY_F8, GDK_SHIFT_MASK, + "cycle-handle-focus", "(b)", TRUE); - + add_tab_bindings (widget_class, 0); add_tab_bindings (widget_class, GDK_CONTROL_MASK); add_tab_bindings (widget_class, GDK_SHIFT_MASK); @@ -623,8 +697,8 @@ gtk_paned_class_init (GtkPanedClass *class) /* accept and cancel positions */ gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_Escape, 0, - "cancel-position", + GDK_KEY_Escape, 0, + "cancel-position", NULL); gtk_widget_class_add_binding_signal (widget_class, @@ -632,15 +706,15 @@ gtk_paned_class_init (GtkPanedClass *class) "accept-position", NULL); gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_ISO_Enter, 0, + GDK_KEY_ISO_Enter, 0, "accept-position", NULL); gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_KP_Enter, 0, + GDK_KEY_KP_Enter, 0, "accept-position", NULL); gtk_widget_class_add_binding_signal (widget_class, - GDK_KEY_space, 0, + GDK_KEY_space, 0, "accept-position", NULL); gtk_widget_class_add_binding_signal (widget_class, @@ -682,16 +756,55 @@ gtk_paned_class_init (GtkPanedClass *class) gtk_widget_class_set_css_name (widget_class, I_("paned")); } -static GType -gtk_paned_child_type (GtkContainer *container) +static GtkBuildableIface *parent_buildable_iface; + +static void +gtk_paned_buildable_add_child (GtkBuildable *buildable, + GtkBuilder *builder, + GObject *child, + const gchar *type) { - GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + GtkPaned *self = GTK_PANED (buildable); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (self); - if (!priv->child1 || !priv->child2) - return GTK_TYPE_WIDGET; + if (g_strcmp0 (type, "start") == 0) + { + gtk_paned_set_start_child (self, GTK_WIDGET (child)); + gtk_paned_set_resize_start_child (self, FALSE); + gtk_paned_set_shrink_start_child (self, TRUE); + } + else if (g_strcmp0 (type, "end") == 0) + { + gtk_paned_set_end_child (self, GTK_WIDGET (child)); + gtk_paned_set_resize_end_child (self, TRUE); + gtk_paned_set_shrink_end_child (self, TRUE); + } + else if (GTK_IS_WIDGET (child)) + { + if (priv->start_child == NULL) + { + gtk_paned_set_start_child (self, GTK_WIDGET (child)); + gtk_paned_set_resize_start_child (self, FALSE); + gtk_paned_set_shrink_start_child (self, TRUE); + } + else if (priv->end_child == NULL) + { + gtk_paned_set_end_child (self, GTK_WIDGET (child)); + gtk_paned_set_resize_end_child (self, TRUE); + gtk_paned_set_shrink_end_child (self, TRUE); + } + else + g_warning ("GtkPaned only accepts two widgets as children"); + } else - return G_TYPE_NONE; + parent_buildable_iface->add_child (buildable, builder, child, type); +} + +static void +gtk_paned_buildable_iface_init (GtkBuildableIface *iface) +{ + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->add_child = gtk_paned_buildable_add_child; } static gboolean @@ -808,9 +921,9 @@ gesture_drag_end_cb (GtkGestureDrag *gesture, static void gtk_paned_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (object); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); @@ -856,37 +969,23 @@ gtk_paned_set_property (GObject *object, case PROP_WIDE_HANDLE: gtk_paned_set_wide_handle (paned, g_value_get_boolean (value)); break; - case PROP_RESIZE_CHILD1: - if (priv->child1_resize != g_value_get_boolean (value)) - { - priv->child1_resize = g_value_get_boolean (value); - g_object_notify_by_pspec (object, pspec); - gtk_widget_queue_resize (GTK_WIDGET (object)); - } + case PROP_RESIZE_START_CHILD: + gtk_paned_set_resize_start_child (paned, g_value_get_boolean (value)); break; - case PROP_RESIZE_CHILD2: - if (priv->child2_resize != g_value_get_boolean (value)) - { - priv->child2_resize = g_value_get_boolean (value); - g_object_notify_by_pspec (object, pspec); - gtk_widget_queue_resize (GTK_WIDGET (object)); - } + case PROP_RESIZE_END_CHILD: + gtk_paned_set_resize_end_child (paned, g_value_get_boolean (value)); break; - case PROP_SHRINK_CHILD1: - if (priv->child1_shrink != g_value_get_boolean (value)) - { - priv->child1_shrink = g_value_get_boolean (value); - g_object_notify_by_pspec (object, pspec); - gtk_widget_queue_resize (GTK_WIDGET (object)); - } + case PROP_SHRINK_START_CHILD: + gtk_paned_set_shrink_start_child (paned, g_value_get_boolean (value)); break; - case PROP_SHRINK_CHILD2: - if (priv->child2_shrink != g_value_get_boolean (value)) - { - priv->child2_shrink = g_value_get_boolean (value); - g_object_notify_by_pspec (object, pspec); - gtk_widget_queue_resize (GTK_WIDGET (object)); - } + case PROP_SHRINK_END_CHILD: + gtk_paned_set_shrink_end_child (paned, g_value_get_boolean (value)); + break; + case PROP_START_CHILD: + gtk_paned_set_start_child (paned, g_value_get_object (value)); + break; + case PROP_END_CHILD: + gtk_paned_set_end_child (paned, g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -896,9 +995,9 @@ gtk_paned_set_property (GObject *object, static void gtk_paned_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (object); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); @@ -909,7 +1008,7 @@ gtk_paned_get_property (GObject *object, g_value_set_enum (value, priv->orientation); break; case PROP_POSITION: - g_value_set_int (value, priv->child1_size); + g_value_set_int (value, priv->start_child_size); break; case PROP_POSITION_SET: g_value_set_boolean (value, priv->position_set); @@ -923,17 +1022,23 @@ gtk_paned_get_property (GObject *object, case PROP_WIDE_HANDLE: g_value_set_boolean (value, gtk_paned_get_wide_handle (paned)); break; - case PROP_RESIZE_CHILD1: - g_value_set_boolean (value, priv->child1_resize); + case PROP_RESIZE_START_CHILD: + g_value_set_boolean (value, priv->resize_start_child); + break; + case PROP_RESIZE_END_CHILD: + g_value_set_boolean (value, priv->resize_end_child); break; - case PROP_RESIZE_CHILD2: - g_value_set_boolean (value, priv->child2_resize); + case PROP_SHRINK_START_CHILD: + g_value_set_boolean (value, priv->shrink_start_child); break; - case PROP_SHRINK_CHILD1: - g_value_set_boolean (value, priv->child1_shrink); + case PROP_SHRINK_END_CHILD: + g_value_set_boolean (value, priv->shrink_end_child); break; - case PROP_SHRINK_CHILD2: - g_value_set_boolean (value, priv->child2_shrink); + case PROP_START_CHILD: + g_value_set_object (value, gtk_paned_get_start_child (paned)); + break; + case PROP_END_CHILD: + g_value_set_object (value, gtk_paned_get_end_child (paned)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -942,24 +1047,26 @@ gtk_paned_get_property (GObject *object, } static void -gtk_paned_finalize (GObject *object) +gtk_paned_dispose (GObject *object) { GtkPaned *paned = GTK_PANED (object); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - + gtk_paned_set_saved_focus (paned, NULL); gtk_paned_set_first_paned (paned, NULL); - gtk_widget_unparent (priv->handle_widget); + g_clear_pointer (&priv->start_child, gtk_widget_unparent); + g_clear_pointer (&priv->end_child, gtk_widget_unparent); + g_clear_pointer (&priv->handle_widget, gtk_widget_unparent); - G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object); + G_OBJECT_CLASS (gtk_paned_parent_class)->dispose (object); } static void gtk_paned_compute_position (GtkPaned *paned, gint allocation, - gint child1_req, - gint child2_req, + gint start_child_req, + gint end_child_req, gint *min_pos, gint *max_pos, gint *out_pos) @@ -967,23 +1074,23 @@ gtk_paned_compute_position (GtkPaned *paned, GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint min, max, pos; - min = priv->child1_shrink ? 0 : child1_req; + min = priv->shrink_start_child ? 0 : start_child_req; max = allocation; - if (!priv->child2_shrink) - max = MAX (1, max - child2_req); + if (!priv->shrink_end_child) + max = MAX (1, max - end_child_req); max = MAX (min, max); if (!priv->position_set) { - if (priv->child1_resize && !priv->child2_resize) - pos = MAX (0, allocation - child2_req); - else if (!priv->child1_resize && priv->child2_resize) - pos = child1_req; - else if (child1_req + child2_req != 0) - pos = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5; + if (priv->resize_start_child && !priv->resize_end_child) + pos = MAX (0, allocation - end_child_req); + else if (!priv->resize_start_child && priv->resize_end_child) + pos = start_child_req; + else if (start_child_req + end_child_req != 0) + pos = allocation * ((gdouble)start_child_req / (start_child_req + end_child_req)) + 0.5; else - pos = allocation * 0.5 + 0.5; + pos = allocation * 0.5 + 0.5; } else { @@ -991,20 +1098,20 @@ gtk_paned_compute_position (GtkPaned *paned, * (priv->last_allocation <= 0) just clamp it and leave it. */ if (priv->last_allocation > 0) - { - if (priv->child1_resize && !priv->child2_resize) - pos = priv->child1_size + allocation - priv->last_allocation; - else if (!(!priv->child1_resize && priv->child2_resize)) - pos = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5; + { + if (priv->resize_start_child && !priv->resize_end_child) + pos = priv->start_child_size + allocation - priv->last_allocation; + else if (!(!priv->resize_start_child && priv->resize_end_child)) + pos = allocation * ((gdouble) priv->start_child_size / (priv->last_allocation)) + 0.5; else - pos = priv->child1_size; - } + pos = priv->start_child_size; + } else - pos = priv->child1_size; + pos = priv->start_child_size; } pos = CLAMP (pos, min, max); - + if (min_pos) *min_pos = min; if (max_pos) @@ -1025,27 +1132,27 @@ gtk_paned_get_preferred_size_for_orientation (GtkWidget *widget, *minimum = *natural = 0; - if (priv->child1 && gtk_widget_get_visible (priv->child1)) + if (priv->start_child && gtk_widget_get_visible (priv->start_child)) { - gtk_widget_measure (priv->child1, priv->orientation, size, &child_min, &child_nat, NULL, NULL); - if (priv->child1_shrink) + gtk_widget_measure (priv->start_child, priv->orientation, size, &child_min, &child_nat, NULL, NULL); + if (priv->shrink_start_child) *minimum = 0; else *minimum = child_min; *natural = child_nat; } - if (priv->child2 && gtk_widget_get_visible (priv->child2)) + if (priv->end_child && gtk_widget_get_visible (priv->end_child)) { - gtk_widget_measure (priv->child2, priv->orientation, size, &child_min, &child_nat, NULL, NULL); + gtk_widget_measure (priv->end_child, priv->orientation, size, &child_min, &child_nat, NULL, NULL); - if (!priv->child2_shrink) + if (!priv->shrink_end_child) *minimum += child_min; *natural += child_nat; } - if (priv->child1 && gtk_widget_get_visible (priv->child1) && - priv->child2 && gtk_widget_get_visible (priv->child2)) + if (priv->start_child && gtk_widget_get_visible (priv->start_child) && + priv->end_child && gtk_widget_get_visible (priv->end_child)) { gint handle_size; @@ -1068,14 +1175,14 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget, { GtkPaned *paned = GTK_PANED (widget); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - gint for_child1, for_child2; + gint for_start_child, for_end_child; gint child_min, child_nat; if (size > -1 && - priv->child1 && gtk_widget_get_visible (priv->child1) && - priv->child2 && gtk_widget_get_visible (priv->child2)) + priv->start_child && gtk_widget_get_visible (priv->start_child) && + priv->end_child && gtk_widget_get_visible (priv->end_child)) { - gint child1_req, child2_req; + gint start_child_req, end_child_req; gint handle_size; gtk_widget_measure (priv->handle_widget, @@ -1084,28 +1191,28 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget, NULL, &handle_size, NULL, NULL); - gtk_widget_measure (priv->child1, priv->orientation, -1, &child1_req, NULL, NULL, NULL); - gtk_widget_measure (priv->child2, priv->orientation, -1, &child2_req, NULL, NULL, NULL); + gtk_widget_measure (priv->start_child, priv->orientation, -1, &start_child_req, NULL, NULL, NULL); + gtk_widget_measure (priv->end_child, priv->orientation, -1, &end_child_req, NULL, NULL, NULL); gtk_paned_compute_position (paned, - size - handle_size, child1_req, child2_req, - NULL, NULL, &for_child1); + size - handle_size, start_child_req, end_child_req, + NULL, NULL, &for_start_child); - for_child2 = size - for_child1 - handle_size; + for_end_child = size - for_start_child - handle_size; } else { - for_child1 = size; - for_child2 = size; + for_start_child = size; + for_end_child = size; } *minimum = *natural = 0; - if (priv->child1 && gtk_widget_get_visible (priv->child1)) + if (priv->start_child && gtk_widget_get_visible (priv->start_child)) { - gtk_widget_measure (priv->child1, + gtk_widget_measure (priv->start_child, OPPOSITE_ORIENTATION (priv->orientation), - for_child1, + for_start_child, &child_min, &child_nat, NULL, NULL); @@ -1113,11 +1220,11 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget, *natural = child_nat; } - if (priv->child2 && gtk_widget_get_visible (priv->child2)) + if (priv->end_child && gtk_widget_get_visible (priv->end_child)) { - gtk_widget_measure (priv->child2, + gtk_widget_measure (priv->end_child, OPPOSITE_ORIENTATION (priv->orientation), - for_child2, + for_end_child, &child_min, &child_nat, NULL, NULL); @@ -1160,11 +1267,11 @@ gtk_paned_size_allocate (GtkWidget *widget, GtkPaned *paned = GTK_PANED (widget); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (priv->child1 && gtk_widget_get_visible (priv->child1) && - priv->child2 && gtk_widget_get_visible (priv->child2)) + if (priv->start_child && gtk_widget_get_visible (priv->start_child) && + priv->end_child && gtk_widget_get_visible (priv->end_child)) { - GtkAllocation child1_allocation; - GtkAllocation child2_allocation; + GtkAllocation start_child_allocation; + GtkAllocation end_child_allocation; GtkAllocation handle_allocation; gint handle_size; @@ -1176,117 +1283,117 @@ gtk_paned_size_allocate (GtkWidget *widget, if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { - gint child1_width, child2_width; + gint start_child_width, end_child_width; - gtk_widget_measure (priv->child1, GTK_ORIENTATION_HORIZONTAL, + gtk_widget_measure (priv->start_child, GTK_ORIENTATION_HORIZONTAL, height, - &child1_width, NULL, NULL, NULL); - gtk_widget_measure (priv->child2, GTK_ORIENTATION_HORIZONTAL, + &start_child_width, NULL, NULL, NULL); + gtk_widget_measure (priv->end_child, GTK_ORIENTATION_HORIZONTAL, height, - &child2_width, NULL, NULL, NULL); + &end_child_width, NULL, NULL, NULL); gtk_paned_calc_position (paned, MAX (1, width - handle_size), - child1_width, - child2_width); + start_child_width, + end_child_width); handle_allocation = (GdkRectangle){ - priv->child1_size, + priv->start_child_size, 0, handle_size, height }; - child1_allocation.height = child2_allocation.height = height; - child1_allocation.width = MAX (1, priv->child1_size); - child1_allocation.x = 0; - child1_allocation.y = child2_allocation.y = 0; + start_child_allocation.height = end_child_allocation.height = height; + start_child_allocation.width = MAX (1, priv->start_child_size); + start_child_allocation.x = 0; + start_child_allocation.y = end_child_allocation.y = 0; - child2_allocation.x = child1_allocation.x + priv->child1_size + handle_size; - child2_allocation.width = MAX (1, width - priv->child1_size - handle_size); + end_child_allocation.x = start_child_allocation.x + priv->start_child_size + handle_size; + end_child_allocation.width = MAX (1, width - priv->start_child_size - handle_size); if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL) { - flip_child (width, &(child2_allocation)); - flip_child (width, &(child1_allocation)); + flip_child (width, &(end_child_allocation)); + flip_child (width, &(start_child_allocation)); flip_child (width, &(handle_allocation)); } - if (child1_width > child1_allocation.width) + if (start_child_width > start_child_allocation.width) { if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR) - child1_allocation.x -= child1_width - child1_allocation.width; - child1_allocation.width = child1_width; + start_child_allocation.x -= start_child_width - start_child_allocation.width; + start_child_allocation.width = start_child_width; } - if (child2_width > child2_allocation.width) + if (end_child_width > end_child_allocation.width) { if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL) - child2_allocation.x -= child2_width - child2_allocation.width; - child2_allocation.width = child2_width; + end_child_allocation.x -= end_child_width - end_child_allocation.width; + end_child_allocation.width = end_child_width; } } else { - gint child1_height, child2_height; + gint start_child_height, end_child_height; - gtk_widget_measure (priv->child1, GTK_ORIENTATION_VERTICAL, + gtk_widget_measure (priv->start_child, GTK_ORIENTATION_VERTICAL, width, - &child1_height, NULL, NULL, NULL); - gtk_widget_measure (priv->child2, GTK_ORIENTATION_VERTICAL, + &start_child_height, NULL, NULL, NULL); + gtk_widget_measure (priv->end_child, GTK_ORIENTATION_VERTICAL, width, - &child2_height, NULL, NULL, NULL); + &end_child_height, NULL, NULL, NULL); gtk_paned_calc_position (paned, MAX (1, height - handle_size), - child1_height, - child2_height); + start_child_height, + end_child_height); handle_allocation = (GdkRectangle){ 0, - priv->child1_size, + priv->start_child_size, width, handle_size, }; - child1_allocation.width = child2_allocation.width = width; - child1_allocation.height = MAX (1, priv->child1_size); - child1_allocation.x = child2_allocation.x = 0; - child1_allocation.y = 0; + start_child_allocation.width = end_child_allocation.width = width; + start_child_allocation.height = MAX (1, priv->start_child_size); + start_child_allocation.x = end_child_allocation.x = 0; + start_child_allocation.y = 0; - child2_allocation.y = child1_allocation.y + priv->child1_size + handle_size; - child2_allocation.height = MAX (1, height - child2_allocation.y); + end_child_allocation.y = start_child_allocation.y + priv->start_child_size + handle_size; + end_child_allocation.height = MAX (1, height - end_child_allocation.y); - if (child1_height > child1_allocation.height) + if (start_child_height > start_child_allocation.height) { - child1_allocation.y -= child1_height - child1_allocation.height; - child1_allocation.height = child1_height; + start_child_allocation.y -= start_child_height - start_child_allocation.height; + start_child_allocation.height = start_child_height; } - if (child2_height > child2_allocation.height) - child2_allocation.height = child2_height; + if (end_child_height > end_child_allocation.height) + end_child_allocation.height = end_child_height; } gtk_widget_set_child_visible (priv->handle_widget, TRUE); gtk_widget_size_allocate (priv->handle_widget, &handle_allocation, -1); - gtk_widget_size_allocate (priv->child1, &child1_allocation, -1); - gtk_widget_size_allocate (priv->child2, &child2_allocation, -1); + gtk_widget_size_allocate (priv->start_child, &start_child_allocation, -1); + gtk_widget_size_allocate (priv->end_child, &end_child_allocation, -1); } else { - if (priv->child1 && gtk_widget_get_visible (priv->child1)) + if (priv->start_child && gtk_widget_get_visible (priv->start_child)) { - gtk_widget_set_child_visible (priv->child1, TRUE); + gtk_widget_set_child_visible (priv->start_child, TRUE); - gtk_widget_size_allocate (priv->child1, + gtk_widget_size_allocate (priv->start_child, &(GtkAllocation) {0, 0, width, height}, -1); } - else if (priv->child2 && gtk_widget_get_visible (priv->child2)) + else if (priv->end_child && gtk_widget_get_visible (priv->end_child)) { - gtk_widget_set_child_visible (priv->child2, TRUE); + gtk_widget_set_child_visible (priv->end_child, TRUE); - gtk_widget_size_allocate (priv->child2, + gtk_widget_size_allocate (priv->end_child, &(GtkAllocation) {0, 0, width, height}, -1); } @@ -1301,8 +1408,8 @@ gtk_paned_unrealize (GtkWidget *widget) { GtkPaned *paned = GTK_PANED (widget); - gtk_paned_set_last_child1_focus (paned, NULL); - gtk_paned_set_last_child2_focus (paned, NULL); + gtk_paned_set_last_start_child_focus (paned, NULL); + gtk_paned_set_last_end_child_focus (paned, NULL); gtk_paned_set_saved_focus (paned, NULL); gtk_paned_set_first_paned (paned, NULL); @@ -1347,21 +1454,21 @@ gtk_paned_init (GtkPaned *paned) priv->orientation = GTK_ORIENTATION_HORIZONTAL; - priv->child1 = NULL; - priv->child2 = NULL; + priv->start_child = NULL; + priv->end_child = NULL; priv->position_set = FALSE; priv->last_allocation = -1; - priv->last_child1_focus = NULL; - priv->last_child2_focus = NULL; + priv->last_start_child_focus = NULL; + priv->last_end_child_focus = NULL; priv->in_recursion = FALSE; priv->original_position = -1; priv->max_position = G_MAXINT; - priv->child1_resize = TRUE; - priv->child2_resize = TRUE; - priv->child1_shrink = TRUE; - priv->child2_shrink = TRUE; + priv->resize_start_child = TRUE; + priv->resize_end_child = TRUE; + priv->shrink_start_child = TRUE; + priv->shrink_end_child = TRUE; _gtk_orientable_set_style_classes (GTK_ORIENTABLE (paned)); @@ -1435,28 +1542,10 @@ update_drag (GtkPaned *paned, size = CLAMP (size, priv->min_position, priv->max_position); - if (size != priv->child1_size) + if (size != priv->start_child_size) gtk_paned_set_position (paned, size); } -static gboolean -gtk_paned_focus (GtkWidget *widget, - GtkDirectionType direction) - -{ - gboolean retval; - - /* This is a hack, but how can this be done without - * excessive cut-and-paste from gtkcontainer.c? - */ - - gtk_widget_set_can_focus (widget, FALSE); - retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction); - gtk_widget_set_can_focus (widget, TRUE); - - return retval; -} - static void gtk_paned_css_changed (GtkWidget *widget, GtkCssStyleChange *change) @@ -1491,161 +1580,176 @@ gtk_paned_new (GtkOrientation orientation) NULL); } -/** - * gtk_paned_add1: - * @paned: a paned widget - * @child: the child to add - * - * Adds a child to the top or left pane with default parameters. This is - * equivalent to - * `gtk_paned_pack1 (paned, child, FALSE, TRUE)`. - */ void -gtk_paned_add1 (GtkPaned *paned, - GtkWidget *widget) +gtk_paned_set_start_child (GtkPaned *paned, + GtkWidget *child) { - gtk_paned_pack1 (paned, widget, FALSE, TRUE); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_if_fail (GTK_IS_PANED (paned)); + g_return_if_fail (child == NULL || GTK_IS_WIDGET (child)); + + g_clear_pointer (&priv->start_child, gtk_widget_unparent); + + if (child) + { + priv->start_child = child; + gtk_widget_insert_before (child, GTK_WIDGET (paned), priv->handle_widget); + } + + g_object_notify (G_OBJECT (paned), "start-child"); +} + +GtkWidget * +gtk_paned_get_start_child (GtkPaned *paned) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_val_if_fail (GTK_IS_PANED (paned), NULL); + + return priv->start_child; } -/** - * gtk_paned_add2: - * @paned: a paned widget - * @child: the child to add - * - * Adds a child to the bottom or right pane with default parameters. This - * is equivalent to - * `gtk_paned_pack2 (paned, child, TRUE, TRUE)`. - */ void -gtk_paned_add2 (GtkPaned *paned, - GtkWidget *widget) +gtk_paned_set_resize_start_child (GtkPaned *paned, + gboolean resize) { - gtk_paned_pack2 (paned, widget, TRUE, TRUE); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_if_fail (GTK_IS_PANED (paned)); + + if (priv->resize_start_child == resize) + return; + + priv->resize_start_child = resize; + + g_object_notify (G_OBJECT (paned), "resize-start-child"); +} + +gboolean +gtk_paned_get_resize_start_child (GtkPaned *paned) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_val_if_fail (GTK_IS_PANED (paned), FALSE); + + return priv->resize_start_child; } -/** - * gtk_paned_pack1: - * @paned: a paned widget - * @child: the child to add - * @resize: should this child expand when the paned widget is resized. - * @shrink: can this child be made smaller than its requisition. - * - * Adds a child to the top or left pane. - */ void -gtk_paned_pack1 (GtkPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink) +gtk_paned_set_shrink_start_child (GtkPaned *paned, + gboolean shrink) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); g_return_if_fail (GTK_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (child)); - if (!priv->child1) - { - priv->child1 = child; - priv->child1_resize = resize; - priv->child1_shrink = shrink; + if (priv->shrink_start_child == shrink) + return; - gtk_widget_insert_before (child, GTK_WIDGET (paned), priv->handle_widget); - } + priv->shrink_start_child = shrink; + + g_object_notify (G_OBJECT (paned), "shrink-start-child"); +} + +gboolean +gtk_paned_get_shrink_start_child (GtkPaned *paned) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_val_if_fail (GTK_IS_PANED (paned), FALSE); + + return priv->shrink_start_child; } -/** - * gtk_paned_pack2: - * @paned: a paned widget - * @child: the child to add - * @resize: should this child expand when the paned widget is resized. - * @shrink: can this child be made smaller than its requisition. - * - * Adds a child to the bottom or right pane. - */ void -gtk_paned_pack2 (GtkPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink) +gtk_paned_set_end_child (GtkPaned *paned, + GtkWidget *child) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); g_return_if_fail (GTK_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (child == NULL || GTK_IS_WIDGET (child)); - if (!priv->child2) - { - priv->child2 = child; - priv->child2_resize = resize; - priv->child2_shrink = shrink; + g_clear_pointer (&priv->end_child, gtk_widget_unparent); + if (child) + { + priv->end_child = child; gtk_widget_insert_after (child, GTK_WIDGET (paned), priv->handle_widget); } + + g_object_notify (G_OBJECT (paned), "end-child"); } +GtkWidget * +gtk_paned_get_end_child (GtkPaned *paned) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); -static void -gtk_paned_add (GtkContainer *container, - GtkWidget *widget) + g_return_val_if_fail (GTK_IS_PANED (paned), NULL); + + return priv->end_child; +} + +void +gtk_paned_set_resize_end_child (GtkPaned *paned, + gboolean resize) { - GtkPanedPrivate *priv; - GtkPaned *paned; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - g_return_if_fail (GTK_IS_PANED (container)); + g_return_if_fail (GTK_IS_PANED (paned)); - paned = GTK_PANED (container); - priv = gtk_paned_get_instance_private (paned); + if (priv->resize_end_child == resize) + return; - if (!priv->child1) - gtk_paned_add1 (paned, widget); - else if (!priv->child2) - gtk_paned_add2 (paned, widget); - else - g_warning ("GtkPaned cannot have more than 2 children"); + priv->resize_end_child = resize; + + g_object_notify (G_OBJECT (paned), "resize-end-child"); } -static void -gtk_paned_remove (GtkContainer *container, - GtkWidget *widget) +gboolean +gtk_paned_get_resize_end_child (GtkPaned *paned) { - GtkPaned *paned = GTK_PANED (container); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (priv->child1 == widget) - { - gtk_widget_unparent (widget); + g_return_val_if_fail (GTK_IS_PANED (paned), FALSE); - priv->child1 = NULL; - } - else if (priv->child2 == widget) - { - gtk_widget_unparent (widget); + return priv->resize_end_child; +} - priv->child2 = NULL; - } +void +gtk_paned_set_shrink_end_child (GtkPaned *paned, + gboolean shrink) +{ + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + + g_return_if_fail (GTK_IS_PANED (paned)); + + if (priv->shrink_end_child == shrink) + return; + + priv->shrink_end_child = shrink; + + g_object_notify (G_OBJECT (paned), "shrink-end-child"); } -static void -gtk_paned_forall (GtkContainer *container, - GtkCallback callback, - gpointer callback_data) +gboolean +gtk_paned_get_shrink_end_child (GtkPaned *paned) { - GtkPanedPrivate *priv = gtk_paned_get_instance_private (GTK_PANED (container)); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - g_return_if_fail (callback != NULL); + g_return_val_if_fail (GTK_IS_PANED (paned), FALSE); - if (priv->child1) - (*callback) (priv->child1, callback_data); - if (priv->child2) - (*callback) (priv->child2, callback_data); + return priv->shrink_end_child; } /** * gtk_paned_get_position: * @paned: a #GtkPaned widget - * + * * Obtains the position of the divider between the two panes. - * + * * Returns: position of the divider **/ gint @@ -1655,7 +1759,7 @@ gtk_paned_get_position (GtkPaned *paned) g_return_val_if_fail (GTK_IS_PANED (paned), 0); - return priv->child1_size; + return priv->start_child_size; } /** @@ -1663,12 +1767,12 @@ gtk_paned_get_position (GtkPaned *paned) * @paned: a #GtkPaned widget * @position: pixel position of divider, a negative value means that the position * is unset. - * + * * Sets the position of the divider between the two panes. **/ void gtk_paned_set_position (GtkPaned *paned, - gint position) + gint position) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); @@ -1688,13 +1792,13 @@ gtk_paned_set_position (GtkPaned *paned, if (!priv->position_set) g_object_notify_by_pspec (G_OBJECT (paned), paned_props[PROP_POSITION_SET]); - if (priv->child1_size != position) + if (priv->start_child_size != position) { g_object_notify_by_pspec (G_OBJECT (paned), paned_props[PROP_POSITION]); gtk_widget_queue_allocate (GTK_WIDGET (paned)); } - priv->child1_size = position; + priv->start_child_size = position; priv->position_set = TRUE; } else @@ -1709,74 +1813,38 @@ gtk_paned_set_position (GtkPaned *paned, #ifdef G_OS_WIN32 /* Hacky work-around for bug #144269 */ - if (priv->child2 != NULL) + if (priv->end_child != NULL) { - gtk_widget_queue_draw (priv->child2); + gtk_widget_queue_draw (priv->end_child); } #endif } -/** - * gtk_paned_get_child1: - * @paned: a #GtkPaned widget - * - * Obtains the first child of the paned widget. - * - * Returns: (nullable) (transfer none): first child, or %NULL if it is not set. - **/ -GtkWidget * -gtk_paned_get_child1 (GtkPaned *paned) -{ - GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - - g_return_val_if_fail (GTK_IS_PANED (paned), NULL); - - return priv->child1; -} - -/** - * gtk_paned_get_child2: - * @paned: a #GtkPaned widget - * - * Obtains the second child of the paned widget. - * - * Returns: (nullable) (transfer none): second child, or %NULL if it is not set. - **/ -GtkWidget * -gtk_paned_get_child2 (GtkPaned *paned) -{ - GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - - g_return_val_if_fail (GTK_IS_PANED (paned), NULL); - - return priv->child2; -} - static void gtk_paned_calc_position (GtkPaned *paned, gint allocation, - gint child1_req, - gint child2_req) + gint start_child_req, + gint end_child_req) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint old_position; gint old_min_position; gint old_max_position; - old_position = priv->child1_size; + old_position = priv->start_child_size; old_min_position = priv->min_position; old_max_position = priv->max_position; gtk_paned_compute_position (paned, - allocation, child1_req, child2_req, + allocation, start_child_req, end_child_req, &priv->min_position, &priv->max_position, - &priv->child1_size); + &priv->start_child_size); - gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0); - gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation); + gtk_widget_set_child_visible (priv->start_child, priv->start_child_size != 0); + gtk_widget_set_child_visible (priv->end_child, priv->start_child_size != allocation); g_object_freeze_notify (G_OBJECT (paned)); - if (priv->child1_size != old_position) + if (priv->start_child_size != old_position) g_object_notify_by_pspec (G_OBJECT (paned), paned_props[PROP_POSITION]); if (priv->min_position != old_min_position) g_object_notify_by_pspec (G_OBJECT (paned), paned_props[PROP_MIN_POSITION]); @@ -1794,13 +1862,13 @@ gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget) if (priv->saved_focus) g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus), - (gpointer *)&(priv->saved_focus)); + (gpointer *)&(priv->saved_focus)); priv->saved_focus = widget; if (priv->saved_focus) g_object_add_weak_pointer (G_OBJECT (priv->saved_focus), - (gpointer *)&(priv->saved_focus)); + (gpointer *)&(priv->saved_focus)); } static void @@ -1810,45 +1878,45 @@ gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned) if (priv->first_paned) g_object_remove_weak_pointer (G_OBJECT (priv->first_paned), - (gpointer *)&(priv->first_paned)); + (gpointer *)&(priv->first_paned)); priv->first_paned = first_paned; if (priv->first_paned) g_object_add_weak_pointer (G_OBJECT (priv->first_paned), - (gpointer *)&(priv->first_paned)); + (gpointer *)&(priv->first_paned)); } static void -gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget) +gtk_paned_set_last_start_child_focus (GtkPaned *paned, GtkWidget *widget) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (priv->last_child1_focus) - g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus), - (gpointer *)&(priv->last_child1_focus)); + if (priv->last_start_child_focus) + g_object_remove_weak_pointer (G_OBJECT (priv->last_start_child_focus), + (gpointer *)&(priv->last_start_child_focus)); - priv->last_child1_focus = widget; + priv->last_start_child_focus = widget; - if (priv->last_child1_focus) - g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus), - (gpointer *)&(priv->last_child1_focus)); + if (priv->last_start_child_focus) + g_object_add_weak_pointer (G_OBJECT (priv->last_start_child_focus), + (gpointer *)&(priv->last_start_child_focus)); } static void -gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget) +gtk_paned_set_last_end_child_focus (GtkPaned *paned, GtkWidget *widget) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (priv->last_child2_focus) - g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus), - (gpointer *)&(priv->last_child2_focus)); + if (priv->last_end_child_focus) + g_object_remove_weak_pointer (G_OBJECT (priv->last_end_child_focus), + (gpointer *)&(priv->last_end_child_focus)); - priv->last_child2_focus = widget; + priv->last_end_child_focus = widget; - if (priv->last_child2_focus) - g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus), - (gpointer *)&(priv->last_child2_focus)); + if (priv->last_end_child_focus) + g_object_add_weak_pointer (G_OBJECT (priv->last_end_child_focus), + (gpointer *)&(priv->last_end_child_focus)); } static GtkWidget * @@ -1865,7 +1933,7 @@ paned_get_focus_widget (GtkPaned *paned) static void gtk_paned_set_focus_child (GtkWidget *widget, - GtkWidget *child) + GtkWidget *child) { GtkPaned *paned = GTK_PANED (widget); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); @@ -1879,20 +1947,20 @@ gtk_paned_set_focus_child (GtkWidget *widget, last_focus = paned_get_focus_widget (paned); if (last_focus) - { - /* If there is one or more paned widgets between us and the - * focus widget, we want the topmost of those as last_focus - */ - for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w)) - if (GTK_IS_PANED (w)) - last_focus = w; + { + /* If there is one or more paned widgets between us and the + * focus widget, we want the topmost of those as last_focus + */ + for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w)) + if (GTK_IS_PANED (w)) + last_focus = w; focus_child = gtk_widget_get_focus_child (widget); - if (focus_child == priv->child1) - gtk_paned_set_last_child1_focus (paned, last_focus); - else if (focus_child == priv->child2) - gtk_paned_set_last_child2_focus (paned, last_focus); - } + if (focus_child == priv->start_child) + gtk_paned_set_last_start_child_focus (paned, last_focus); + else if (focus_child == priv->end_child) + gtk_paned_set_last_end_child_focus (paned, last_focus); + } } GTK_WIDGET_CLASS (gtk_paned_parent_class)->set_focus_child (widget, child); @@ -1900,8 +1968,8 @@ gtk_paned_set_focus_child (GtkWidget *widget, static void gtk_paned_get_cycle_chain (GtkPaned *paned, - GtkDirectionType direction, - GList **widgets) + GtkDirectionType direction, + GList **widgets) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkWidget *ancestor = NULL; @@ -1916,16 +1984,16 @@ gtk_paned_get_cycle_chain (GtkPaned *paned, g_assert (widgets != NULL); - if (priv->last_child1_focus && - !gtk_widget_is_ancestor (priv->last_child1_focus, widget)) + if (priv->last_start_child_focus && + !gtk_widget_is_ancestor (priv->last_start_child_focus, widget)) { - gtk_paned_set_last_child1_focus (paned, NULL); + gtk_paned_set_last_start_child_focus (paned, NULL); } - if (priv->last_child2_focus && - !gtk_widget_is_ancestor (priv->last_child2_focus, widget)) + if (priv->last_end_child_focus && + !gtk_widget_is_ancestor (priv->last_end_child_focus, widget)) { - gtk_paned_set_last_child2_focus (paned, NULL); + gtk_paned_set_last_end_child_focus (paned, NULL); } parent = gtk_widget_get_parent (widget); @@ -1943,49 +2011,49 @@ gtk_paned_get_cycle_chain (GtkPaned *paned, focus_child = gtk_widget_get_focus_child (GTK_WIDGET (paned)); if (direction == GTK_DIR_TAB_FORWARD) { - if (focus_child == priv->child1) - { - temp_list = g_list_append (temp_list, priv->last_child2_focus); - temp_list = g_list_append (temp_list, priv->child2); - temp_list = g_list_append (temp_list, ancestor); - } - else if (focus_child == priv->child2) - { - temp_list = g_list_append (temp_list, ancestor); - temp_list = g_list_append (temp_list, priv->last_child1_focus); - temp_list = g_list_append (temp_list, priv->child1); - } + if (focus_child == priv->start_child) + { + temp_list = g_list_append (temp_list, priv->last_end_child_focus); + temp_list = g_list_append (temp_list, priv->end_child); + temp_list = g_list_append (temp_list, ancestor); + } + else if (focus_child == priv->end_child) + { + temp_list = g_list_append (temp_list, ancestor); + temp_list = g_list_append (temp_list, priv->last_start_child_focus); + temp_list = g_list_append (temp_list, priv->start_child); + } else - { - temp_list = g_list_append (temp_list, priv->last_child1_focus); - temp_list = g_list_append (temp_list, priv->child1); - temp_list = g_list_append (temp_list, priv->last_child2_focus); - temp_list = g_list_append (temp_list, priv->child2); - temp_list = g_list_append (temp_list, ancestor); - } + { + temp_list = g_list_append (temp_list, priv->last_start_child_focus); + temp_list = g_list_append (temp_list, priv->start_child); + temp_list = g_list_append (temp_list, priv->last_end_child_focus); + temp_list = g_list_append (temp_list, priv->end_child); + temp_list = g_list_append (temp_list, ancestor); + } } else { - if (focus_child == priv->child1) - { - temp_list = g_list_append (temp_list, ancestor); - temp_list = g_list_append (temp_list, priv->last_child2_focus); - temp_list = g_list_append (temp_list, priv->child2); - } - else if (focus_child == priv->child2) - { - temp_list = g_list_append (temp_list, priv->last_child1_focus); - temp_list = g_list_append (temp_list, priv->child1); - temp_list = g_list_append (temp_list, ancestor); - } + if (focus_child == priv->start_child) + { + temp_list = g_list_append (temp_list, ancestor); + temp_list = g_list_append (temp_list, priv->last_end_child_focus); + temp_list = g_list_append (temp_list, priv->end_child); + } + else if (focus_child == priv->end_child) + { + temp_list = g_list_append (temp_list, priv->last_start_child_focus); + temp_list = g_list_append (temp_list, priv->start_child); + temp_list = g_list_append (temp_list, ancestor); + } else - { - temp_list = g_list_append (temp_list, priv->last_child2_focus); - temp_list = g_list_append (temp_list, priv->child2); - temp_list = g_list_append (temp_list, priv->last_child1_focus); - temp_list = g_list_append (temp_list, priv->child1); - temp_list = g_list_append (temp_list, ancestor); - } + { + temp_list = g_list_append (temp_list, priv->last_end_child_focus); + temp_list = g_list_append (temp_list, priv->end_child); + temp_list = g_list_append (temp_list, priv->last_start_child_focus); + temp_list = g_list_append (temp_list, priv->start_child); + temp_list = g_list_append (temp_list, ancestor); + } } /* Walk the list and expand all the paned widgets. */ @@ -1994,18 +2062,18 @@ gtk_paned_get_cycle_chain (GtkPaned *paned, widget = list->data; if (widget) - { - if (GTK_IS_PANED (widget)) - { - priv->in_recursion = TRUE; - gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets); - priv->in_recursion = FALSE; - } - else - { - *widgets = g_list_append (*widgets, widget); - } - } + { + if (GTK_IS_PANED (widget)) + { + priv->in_recursion = TRUE; + gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets); + priv->in_recursion = FALSE; + } + else + { + *widgets = g_list_append (*widgets, widget); + } + } } g_list_free (temp_list); @@ -2013,17 +2081,17 @@ gtk_paned_get_cycle_chain (GtkPaned *paned, static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned, - gboolean reversed) + gboolean reversed) { GList *cycle_chain = NULL; GList *list; - + GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD; /* ignore f6 if the handle is focused */ if (gtk_widget_is_focus (GTK_WIDGET (paned))) return TRUE; - + /* we can't just let the event propagate up the hierarchy, * because the paned will want to cycle focus _unless_ an * ancestor paned handles the event @@ -2035,13 +2103,13 @@ gtk_paned_cycle_child_focus (GtkPaned *paned, break; g_list_free (cycle_chain); - + return TRUE; } static void get_child_panes (GtkWidget *widget, - GList **panes) + GList **panes) { if (!widget || !gtk_widget_get_realized (widget)) return; @@ -2051,9 +2119,9 @@ get_child_panes (GtkWidget *widget, GtkPaned *paned = GTK_PANED (widget); GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - get_child_panes (priv->child1, panes); + get_child_panes (priv->start_child, panes); *panes = g_list_prepend (*panes, widget); - get_child_panes (priv->child2, panes); + get_child_panes (priv->end_child, panes); } else if (GTK_IS_CONTAINER (widget)) { @@ -2072,7 +2140,7 @@ get_all_panes (GtkPaned *paned) for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w)) { if (GTK_IS_PANED (w)) - topmost = GTK_PANED (w); + topmost = GTK_PANED (w); } g_assert (topmost); @@ -2084,8 +2152,8 @@ get_all_panes (GtkPaned *paned) static void gtk_paned_find_neighbours (GtkPaned *paned, - GtkPaned **next, - GtkPaned **prev) + GtkPaned **next, + GtkPaned **prev) { GList *all_panes; GList *this_link; @@ -2096,7 +2164,7 @@ gtk_paned_find_neighbours (GtkPaned *paned, this_link = g_list_find (all_panes, paned); g_assert (this_link); - + if (this_link->next) *next = this_link->next->data; else @@ -2112,7 +2180,7 @@ gtk_paned_find_neighbours (GtkPaned *paned, static gboolean gtk_paned_move_handle (GtkPaned *paned, - GtkScrollType scroll) + GtkScrollType scroll) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); @@ -2121,67 +2189,67 @@ gtk_paned_move_handle (GtkPaned *paned, gint old_position; gint new_position; gint increment; - + enum { - SINGLE_STEP_SIZE = 1, - PAGE_STEP_SIZE = 75 + SINGLE_STEP_SIZE = 1, + PAGE_STEP_SIZE = 75 }; - + new_position = old_position = gtk_paned_get_position (paned); increment = 0; - + switch (scroll) - { - case GTK_SCROLL_STEP_LEFT: - case GTK_SCROLL_STEP_UP: - case GTK_SCROLL_STEP_BACKWARD: - increment = - SINGLE_STEP_SIZE; - break; - - case GTK_SCROLL_STEP_RIGHT: - case GTK_SCROLL_STEP_DOWN: - case GTK_SCROLL_STEP_FORWARD: - increment = SINGLE_STEP_SIZE; - break; - - case GTK_SCROLL_PAGE_LEFT: - case GTK_SCROLL_PAGE_UP: - case GTK_SCROLL_PAGE_BACKWARD: - increment = - PAGE_STEP_SIZE; - break; - - case GTK_SCROLL_PAGE_RIGHT: - case GTK_SCROLL_PAGE_DOWN: - case GTK_SCROLL_PAGE_FORWARD: - increment = PAGE_STEP_SIZE; - break; - - case GTK_SCROLL_START: - new_position = priv->min_position; - break; - - case GTK_SCROLL_END: - new_position = priv->max_position; - break; - - case GTK_SCROLL_NONE: - case GTK_SCROLL_JUMP: - default: - break; - } + { + case GTK_SCROLL_STEP_LEFT: + case GTK_SCROLL_STEP_UP: + case GTK_SCROLL_STEP_BACKWARD: + increment = - SINGLE_STEP_SIZE; + break; + + case GTK_SCROLL_STEP_RIGHT: + case GTK_SCROLL_STEP_DOWN: + case GTK_SCROLL_STEP_FORWARD: + increment = SINGLE_STEP_SIZE; + break; + + case GTK_SCROLL_PAGE_LEFT: + case GTK_SCROLL_PAGE_UP: + case GTK_SCROLL_PAGE_BACKWARD: + increment = - PAGE_STEP_SIZE; + break; + + case GTK_SCROLL_PAGE_RIGHT: + case GTK_SCROLL_PAGE_DOWN: + case GTK_SCROLL_PAGE_FORWARD: + increment = PAGE_STEP_SIZE; + break; + + case GTK_SCROLL_START: + new_position = priv->min_position; + break; + + case GTK_SCROLL_END: + new_position = priv->max_position; + break; + + case GTK_SCROLL_NONE: + case GTK_SCROLL_JUMP: + default: + break; + } if (increment) - { - if (is_rtl (paned)) - increment = -increment; - - new_position = old_position + increment; - } - + { + if (is_rtl (paned)) + increment = -increment; + + new_position = old_position + increment; + } + new_position = CLAMP (new_position, priv->min_position, priv->max_position); - + if (old_position != new_position) - gtk_paned_set_position (paned, new_position); + gtk_paned_set_position (paned, new_position); return TRUE; } @@ -2197,26 +2265,26 @@ gtk_paned_restore_focus (GtkPaned *paned) if (gtk_widget_is_focus (GTK_WIDGET (paned))) { if (priv->saved_focus && - gtk_widget_get_sensitive (priv->saved_focus)) - { - gtk_widget_grab_focus (priv->saved_focus); - } + gtk_widget_get_sensitive (priv->saved_focus)) + { + gtk_widget_grab_focus (priv->saved_focus); + } else - { - /* the saved focus is somehow not available for focusing, - * try - * 1) tabbing into the paned widget - * if that didn't work, - * 2) unset focus for the window if there is one - */ - - if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD)) - { + { + /* the saved focus is somehow not available for focusing, + * try + * 1) tabbing into the paned widget + * if that didn't work, + * 2) unset focus for the window if there is one + */ + + if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD)) + { GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (paned)); gtk_root_set_focus (root, NULL); - } - } - + } + } + gtk_paned_set_saved_focus (paned, NULL); gtk_paned_set_first_paned (paned, NULL); } @@ -2247,10 +2315,10 @@ gtk_paned_cancel_position (GtkPaned *paned) if (gtk_widget_is_focus (GTK_WIDGET (paned))) { if (priv->original_position != -1) - { - gtk_paned_set_position (paned, priv->original_position); - priv->original_position = -1; - } + { + gtk_paned_set_position (paned, priv->original_position); + priv->original_position = -1; + } gtk_paned_restore_focus (paned); return TRUE; @@ -2261,7 +2329,7 @@ gtk_paned_cancel_position (GtkPaned *paned) static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned, - gboolean reversed) + gboolean reversed) { GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkPaned *next, *prev; @@ -2271,48 +2339,48 @@ gtk_paned_cycle_handle_focus (GtkPaned *paned, GtkPaned *focus = NULL; if (!priv->first_paned) - { - /* The first_pane has disappeared. As an ad-hoc solution, - * we make the currently focused paned the first_paned. To the - * user this will seem like the paned cycling has been reset. - */ - - gtk_paned_set_first_paned (paned, paned); - } - + { + /* The first_pane has disappeared. As an ad-hoc solution, + * we make the currently focused paned the first_paned. To the + * user this will seem like the paned cycling has been reset. + */ + + gtk_paned_set_first_paned (paned, paned); + } + gtk_paned_find_neighbours (paned, &next, &prev); if (reversed && prev && - prev != paned && paned != priv->first_paned) - { - focus = prev; - } + prev != paned && paned != priv->first_paned) + { + focus = prev; + } else if (!reversed && next && - next != paned && next != priv->first_paned) - { - focus = next; - } + next != paned && next != priv->first_paned) + { + focus = next; + } else - { - gtk_paned_accept_position (paned); - return TRUE; - } + { + gtk_paned_accept_position (paned); + return TRUE; + } g_assert (focus); - + gtk_paned_set_saved_focus (focus, priv->saved_focus); gtk_paned_set_first_paned (focus, priv->first_paned); - + gtk_paned_set_saved_focus (paned, NULL); gtk_paned_set_first_paned (paned, NULL); - + gtk_widget_grab_focus (GTK_WIDGET (focus)); - + if (!gtk_widget_is_focus (GTK_WIDGET (paned))) - { - priv->original_position = -1; - priv->original_position = gtk_paned_get_position (focus); - } + { + priv->original_position = -1; + priv->original_position = gtk_paned_get_position (focus); + } } else { @@ -2323,45 +2391,45 @@ gtk_paned_cycle_handle_focus (GtkPaned *paned, gtk_paned_find_neighbours (paned, &next, &prev); focus_child = gtk_widget_get_focus_child (GTK_WIDGET (paned)); - if (focus_child == priv->child1) - { - if (reversed) - { - focus = prev; - first = paned; - } - else - { - focus = paned; - first = paned; - } - } - else if (focus_child == priv->child2) - { - if (reversed) - { - focus = paned; - first = next; - } - else - { - focus = next; - first = next; - } - } + if (focus_child == priv->start_child) + { + if (reversed) + { + focus = prev; + first = paned; + } + else + { + focus = paned; + first = paned; + } + } + else if (focus_child == priv->end_child) + { + if (reversed) + { + focus = paned; + first = next; + } + else + { + focus = next; + first = next; + } + } else - { - /* Focus is not inside this paned, and we don't have focus. - * Presumably this happened because the application wants us - * to start keyboard navigating. - */ - focus = paned; - - if (reversed) - first = paned; - else - first = next; - } + { + /* Focus is not inside this paned, and we don't have focus. + * Presumably this happened because the application wants us + * to start keyboard navigating. + */ + focus = paned; + + if (reversed) + first = paned; + else + first = next; + } gtk_paned_set_saved_focus (focus, gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (paned)))); gtk_paned_set_first_paned (focus, first); |