1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkbindings.h"
33 #include "gtkmarshalers.h"
34 #include "gtkorientable.h"
35 #include "gtkwindow.h"
36 #include "gtktypebuiltins.h"
37 #include "gtkprivate.h"
39 #include "a11y/gtkpanedaccessible.h"
43 * @Short_description: A widget with two adjustable panes
46 * #GtkPaned has two panes, arranged either
47 * horizontally or vertically. The division between
48 * the two panes is adjustable by the user by dragging
52 * added to the panes of the widget with gtk_paned_pack1() and
53 * gtk_paned_pack2(). The division between the two children is set by default
54 * from the size requests of the children, but it can be adjusted by the
57 * A paned widget draws a separator between the two child widgets and a
58 * small handle that the user can drag to adjust the division. It does not
59 * draw any relief around the children or around the separator. (The space
60 * in which the separator is called the gutter.) Often, it is useful to put
61 * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
62 * so that the gutter appears as a ridge. No separator is drawn if one of
63 * the children is missing.
65 * Each child has two options that can be set, @resize and @shrink. If
66 * @resize is true, then when the #GtkPaned is resized, that child will
67 * expand or shrink along with the paned widget. If @shrink is true, then
68 * that child can be made smaller than its requisition by the user.
69 * Setting @shrink to %FALSE allows the application to set a minimum size.
70 * If @resize is false for both children, then this is treated as if
71 * @resize is true for both children.
73 * The application can set the position of the slider as if it were set
74 * by the user, by calling gtk_paned_set_position().
77 * <title>Creating a paned widget with minimum sizes.</title>
79 * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
80 * GtkWidget *frame1 = gtk_frame_new (NULL);
81 * GtkWidget *frame2 = gtk_frame_new (NULL);
82 * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
83 * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
85 * gtk_widget_set_size_request (hpaned, 200, -1);
87 * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
88 * gtk_widget_set_size_request (frame1, 50, -1);
90 * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
91 * gtk_widget_set_size_request (frame2, 50, -1);
101 struct _GtkPanedPrivate
103 GtkPaned *first_paned;
106 GdkWindow *child1_window;
107 GdkWindow *child2_window;
108 GtkWidget *last_child1_focus;
109 GtkWidget *last_child2_focus;
110 GtkWidget *saved_focus;
111 GtkOrientation orientation;
113 GdkCursorType cursor_type;
114 GdkDevice *grab_device;
115 GdkRectangle handle_pos;
120 gint last_allocation;
123 gint original_position;
127 guint handle_prelit : 1;
129 guint in_recursion : 1;
130 guint child1_resize : 1;
131 guint child1_shrink : 1;
132 guint child2_resize : 1;
133 guint child2_shrink : 1;
134 guint position_set : 1;
162 static void gtk_paned_set_property (GObject *object,
166 static void gtk_paned_get_property (GObject *object,
170 static void gtk_paned_set_child_property (GtkContainer *container,
175 static void gtk_paned_get_child_property (GtkContainer *container,
180 static void gtk_paned_finalize (GObject *object);
182 static void gtk_paned_get_preferred_width (GtkWidget *widget,
185 static void gtk_paned_get_preferred_height (GtkWidget *widget,
188 static void gtk_paned_get_preferred_width_for_height
193 static void gtk_paned_get_preferred_height_for_width
199 static void gtk_paned_size_allocate (GtkWidget *widget,
200 GtkAllocation *allocation);
201 static void gtk_paned_realize (GtkWidget *widget);
202 static void gtk_paned_unrealize (GtkWidget *widget);
203 static void gtk_paned_map (GtkWidget *widget);
204 static void gtk_paned_unmap (GtkWidget *widget);
205 static void gtk_paned_state_flags_changed (GtkWidget *widget,
206 GtkStateFlags previous_state);
207 static gboolean gtk_paned_draw (GtkWidget *widget,
209 static gboolean gtk_paned_enter (GtkWidget *widget,
210 GdkEventCrossing *event);
211 static gboolean gtk_paned_leave (GtkWidget *widget,
212 GdkEventCrossing *event);
213 static gboolean gtk_paned_button_press (GtkWidget *widget,
214 GdkEventButton *event);
215 static gboolean gtk_paned_button_release (GtkWidget *widget,
216 GdkEventButton *event);
217 static gboolean gtk_paned_motion (GtkWidget *widget,
218 GdkEventMotion *event);
219 static gboolean gtk_paned_focus (GtkWidget *widget,
220 GtkDirectionType direction);
221 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
222 GdkEventGrabBroken *event);
223 static void gtk_paned_add (GtkContainer *container,
225 static void gtk_paned_remove (GtkContainer *container,
227 static void gtk_paned_forall (GtkContainer *container,
228 gboolean include_internals,
229 GtkCallback callback,
230 gpointer callback_data);
231 static void gtk_paned_calc_position (GtkPaned *paned,
235 static void gtk_paned_set_focus_child (GtkContainer *container,
237 static void gtk_paned_set_saved_focus (GtkPaned *paned,
239 static void gtk_paned_set_first_paned (GtkPaned *paned,
240 GtkPaned *first_paned);
241 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
243 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
245 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
247 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
249 static gboolean gtk_paned_move_handle (GtkPaned *paned,
250 GtkScrollType scroll);
251 static gboolean gtk_paned_accept_position (GtkPaned *paned);
252 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
253 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
255 static GType gtk_paned_child_type (GtkContainer *container);
256 static void gtk_paned_grab_notify (GtkWidget *widget,
257 gboolean was_grabbed);
260 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
261 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
264 static guint signals[LAST_SIGNAL] = { 0 };
268 add_tab_bindings (GtkBindingSet *binding_set,
269 GdkModifierType modifiers)
271 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
272 "toggle-handle-focus", 0);
273 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
274 "toggle-handle-focus", 0);
278 add_move_binding (GtkBindingSet *binding_set,
280 GdkModifierType mask,
281 GtkScrollType scroll)
283 gtk_binding_entry_add_signal (binding_set, keyval, mask,
285 GTK_TYPE_SCROLL_TYPE, scroll);
289 gtk_paned_class_init (GtkPanedClass *class)
291 GObjectClass *object_class;
292 GtkWidgetClass *widget_class;
293 GtkContainerClass *container_class;
294 GtkPanedClass *paned_class;
295 GtkBindingSet *binding_set;
297 object_class = (GObjectClass *) class;
298 widget_class = (GtkWidgetClass *) class;
299 container_class = (GtkContainerClass *) class;
300 paned_class = (GtkPanedClass *) class;
302 object_class->set_property = gtk_paned_set_property;
303 object_class->get_property = gtk_paned_get_property;
304 object_class->finalize = gtk_paned_finalize;
306 widget_class->get_preferred_width = gtk_paned_get_preferred_width;
307 widget_class->get_preferred_height = gtk_paned_get_preferred_height;
308 widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
309 widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
310 widget_class->size_allocate = gtk_paned_size_allocate;
311 widget_class->realize = gtk_paned_realize;
312 widget_class->unrealize = gtk_paned_unrealize;
313 widget_class->map = gtk_paned_map;
314 widget_class->unmap = gtk_paned_unmap;
315 widget_class->draw = gtk_paned_draw;
316 widget_class->focus = gtk_paned_focus;
317 widget_class->enter_notify_event = gtk_paned_enter;
318 widget_class->leave_notify_event = gtk_paned_leave;
319 widget_class->button_press_event = gtk_paned_button_press;
320 widget_class->button_release_event = gtk_paned_button_release;
321 widget_class->motion_notify_event = gtk_paned_motion;
322 widget_class->grab_broken_event = gtk_paned_grab_broken;
323 widget_class->grab_notify = gtk_paned_grab_notify;
324 widget_class->state_flags_changed = gtk_paned_state_flags_changed;
326 container_class->add = gtk_paned_add;
327 container_class->remove = gtk_paned_remove;
328 container_class->forall = gtk_paned_forall;
329 container_class->child_type = gtk_paned_child_type;
330 container_class->set_focus_child = gtk_paned_set_focus_child;
331 container_class->set_child_property = gtk_paned_set_child_property;
332 container_class->get_child_property = gtk_paned_get_child_property;
333 gtk_container_class_handle_border_width (container_class);
335 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
336 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
337 paned_class->move_handle = gtk_paned_move_handle;
338 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
339 paned_class->accept_position = gtk_paned_accept_position;
340 paned_class->cancel_position = gtk_paned_cancel_position;
342 g_object_class_override_property (object_class,
346 g_object_class_install_property (object_class,
348 g_param_spec_int ("position",
350 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
354 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_boolean ("position-set",
360 P_("TRUE if the Position property should be used"),
362 GTK_PARAM_READWRITE));
364 gtk_widget_class_install_style_property (widget_class,
365 g_param_spec_int ("handle-size",
367 P_("Width of handle"),
371 GTK_PARAM_READABLE));
373 * GtkPaned:min-position:
375 * The smallest possible value for the position property. This property is derived from the
376 * size and shrinkability of the widget's children.
380 g_object_class_install_property (object_class,
382 g_param_spec_int ("min-position",
383 P_("Minimal Position"),
384 P_("Smallest possible value for the \"position\" property"),
388 GTK_PARAM_READABLE));
391 * GtkPaned:max-position:
393 * The largest possible value for the position property. This property is derived from the
394 * size and shrinkability of the widget's children.
398 g_object_class_install_property (object_class,
400 g_param_spec_int ("max-position",
401 P_("Maximal Position"),
402 P_("Largest possible value for the \"position\" property"),
406 GTK_PARAM_READABLE));
411 * The "resize" child property determines whether the child expands and
412 * shrinks along with the paned widget.
416 gtk_container_class_install_child_property (container_class,
418 g_param_spec_boolean ("resize",
420 P_("If TRUE, the child expands and shrinks along with the paned widget"),
422 GTK_PARAM_READWRITE));
427 * The "shrink" child property determines whether the child can be made
428 * smaller than its requisition.
432 gtk_container_class_install_child_property (container_class,
434 g_param_spec_boolean ("shrink",
436 P_("If TRUE, the child can be made smaller than its requisition"),
438 GTK_PARAM_READWRITE));
441 * GtkPaned::cycle-child-focus:
442 * @widget: the object that received the signal
443 * @reversed: whether cycling backward or forward
445 * The ::cycle-child-focus signal is a
446 * <link linkend="keybinding-signals">keybinding signal</link>
447 * which gets emitted to cycle the focus between the children of the paned.
449 * The default binding is f6.
453 signals [CYCLE_CHILD_FOCUS] =
454 g_signal_new (I_("cycle-child-focus"),
455 G_TYPE_FROM_CLASS (object_class),
456 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
457 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
459 _gtk_marshal_BOOLEAN__BOOLEAN,
464 * GtkPaned::toggle-handle-focus:
465 * @widget: the object that received the signal
467 * The ::toggle-handle-focus is a
468 * <link linkend="keybinding-signals">keybinding signal</link>
469 * which gets emitted to accept the current position of the handle and then
470 * move focus to the next widget in the focus chain.
472 * The default binding is Tab.
476 signals [TOGGLE_HANDLE_FOCUS] =
477 g_signal_new (I_("toggle-handle-focus"),
478 G_TYPE_FROM_CLASS (object_class),
479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
480 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
482 _gtk_marshal_BOOLEAN__VOID,
486 * GtkPaned::move-handle:
487 * @widget: the object that received the signal
488 * @scroll_type: a #GtkScrollType
490 * The ::move-handle signal is a
491 * <link linkend="keybinding-signals">keybinding signal</link>
492 * which gets emitted to move the handle when the user is using key bindings
497 signals[MOVE_HANDLE] =
498 g_signal_new (I_("move-handle"),
499 G_TYPE_FROM_CLASS (object_class),
500 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
501 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
503 _gtk_marshal_BOOLEAN__ENUM,
505 GTK_TYPE_SCROLL_TYPE);
508 * GtkPaned::cycle-handle-focus:
509 * @widget: the object that received the signal
510 * @reversed: whether cycling backward or forward
512 * The ::cycle-handle-focus signal is a
513 * <link linkend="keybinding-signals">keybinding signal</link>
514 * which gets emitted to cycle whether the paned should grab focus to allow
515 * the user to change position of the handle by using key bindings.
517 * The default binding for this signal is f8.
521 signals [CYCLE_HANDLE_FOCUS] =
522 g_signal_new (I_("cycle-handle-focus"),
523 G_TYPE_FROM_CLASS (object_class),
524 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
525 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
527 _gtk_marshal_BOOLEAN__BOOLEAN,
532 * GtkPaned::accept-position:
533 * @widget: the object that received the signal
535 * The ::accept-position signal is a
536 * <link linkend="keybinding-signals">keybinding signal</link>
537 * which gets emitted to accept the current position of the handle when
538 * moving it using key bindings.
540 * The default binding for this signal is Return or Space.
544 signals [ACCEPT_POSITION] =
545 g_signal_new (I_("accept-position"),
546 G_TYPE_FROM_CLASS (object_class),
547 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
548 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
550 _gtk_marshal_BOOLEAN__VOID,
554 * GtkPaned::cancel-position:
555 * @widget: the object that received the signal
557 * The ::cancel-position signal is a
558 * <link linkend="keybinding-signals">keybinding signal</link>
559 * which gets emitted to cancel moving the position of the handle using key
560 * bindings. The position of the handle will be reset to the value prior to
563 * The default binding for this signal is Escape.
567 signals [CANCEL_POSITION] =
568 g_signal_new (I_("cancel-position"),
569 G_TYPE_FROM_CLASS (object_class),
570 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
571 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
573 _gtk_marshal_BOOLEAN__VOID,
576 binding_set = gtk_binding_set_by_class (class);
579 gtk_binding_entry_add_signal (binding_set,
581 "cycle-child-focus", 1,
582 G_TYPE_BOOLEAN, FALSE);
583 gtk_binding_entry_add_signal (binding_set,
584 GDK_KEY_F6, GDK_SHIFT_MASK,
585 "cycle-child-focus", 1,
586 G_TYPE_BOOLEAN, TRUE);
589 gtk_binding_entry_add_signal (binding_set,
591 "cycle-handle-focus", 1,
592 G_TYPE_BOOLEAN, FALSE);
594 gtk_binding_entry_add_signal (binding_set,
595 GDK_KEY_F8, GDK_SHIFT_MASK,
596 "cycle-handle-focus", 1,
597 G_TYPE_BOOLEAN, TRUE);
599 add_tab_bindings (binding_set, 0);
600 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
601 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
602 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
604 /* accept and cancel positions */
605 gtk_binding_entry_add_signal (binding_set,
607 "cancel-position", 0);
609 gtk_binding_entry_add_signal (binding_set,
611 "accept-position", 0);
612 gtk_binding_entry_add_signal (binding_set,
613 GDK_KEY_ISO_Enter, 0,
614 "accept-position", 0);
615 gtk_binding_entry_add_signal (binding_set,
617 "accept-position", 0);
618 gtk_binding_entry_add_signal (binding_set,
620 "accept-position", 0);
621 gtk_binding_entry_add_signal (binding_set,
623 "accept-position", 0);
626 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
627 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
628 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
629 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
631 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
632 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
633 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
634 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
636 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
637 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
638 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
639 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
640 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
641 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
643 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
644 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
645 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
646 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
647 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
648 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
650 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
651 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
652 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
653 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
655 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
656 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PANED_ACCESSIBLE);
660 gtk_paned_child_type (GtkContainer *container)
662 GtkPaned *paned = GTK_PANED (container);
663 GtkPanedPrivate *priv = paned->priv;
665 if (!priv->child1 || !priv->child2)
666 return GTK_TYPE_WIDGET;
672 gtk_paned_init (GtkPaned *paned)
674 GtkPanedPrivate *priv;
676 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
677 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
679 /* We only need to redraw when the handle position moves, which is
680 * independent of the overall allocation of the GtkPaned
682 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
684 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
687 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
688 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
693 priv->cursor_type = GDK_CROSS;
695 priv->handle_pos.width = 5;
696 priv->handle_pos.height = 5;
697 priv->position_set = FALSE;
698 priv->last_allocation = -1;
699 priv->in_drag = FALSE;
701 priv->last_child1_focus = NULL;
702 priv->last_child2_focus = NULL;
703 priv->in_recursion = FALSE;
704 priv->handle_prelit = FALSE;
705 priv->original_position = -1;
707 priv->handle_pos.x = -1;
708 priv->handle_pos.y = -1;
714 gtk_paned_set_property (GObject *object,
719 GtkPaned *paned = GTK_PANED (object);
720 GtkPanedPrivate *priv = paned->priv;
724 case PROP_ORIENTATION:
725 priv->orientation = g_value_get_enum (value);
727 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
728 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
730 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
732 /* state_flags_changed updates the cursor */
733 gtk_paned_state_flags_changed (GTK_WIDGET (paned), 0);
734 gtk_widget_queue_resize (GTK_WIDGET (paned));
737 gtk_paned_set_position (paned, g_value_get_int (value));
739 case PROP_POSITION_SET:
740 priv->position_set = g_value_get_boolean (value);
741 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
750 gtk_paned_get_property (GObject *object,
755 GtkPaned *paned = GTK_PANED (object);
756 GtkPanedPrivate *priv = paned->priv;
760 case PROP_ORIENTATION:
761 g_value_set_enum (value, priv->orientation);
764 g_value_set_int (value, priv->child1_size);
766 case PROP_POSITION_SET:
767 g_value_set_boolean (value, priv->position_set);
769 case PROP_MIN_POSITION:
770 g_value_set_int (value, priv->min_position);
772 case PROP_MAX_POSITION:
773 g_value_set_int (value, priv->max_position);
776 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
782 gtk_paned_set_child_property (GtkContainer *container,
788 GtkPaned *paned = GTK_PANED (container);
789 GtkPanedPrivate *priv = paned->priv;
790 gboolean old_value, new_value;
792 g_assert (child == priv->child1 || child == priv->child2);
794 new_value = g_value_get_boolean (value);
797 case CHILD_PROP_RESIZE:
798 if (child == priv->child1)
800 old_value = priv->child1_resize;
801 priv->child1_resize = new_value;
805 old_value = priv->child2_resize;
806 priv->child2_resize = new_value;
809 case CHILD_PROP_SHRINK:
810 if (child == priv->child1)
812 old_value = priv->child1_shrink;
813 priv->child1_shrink = new_value;
817 old_value = priv->child2_shrink;
818 priv->child2_shrink = new_value;
822 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
823 old_value = -1; /* quiet gcc */
826 if (old_value != new_value)
827 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
831 gtk_paned_get_child_property (GtkContainer *container,
837 GtkPaned *paned = GTK_PANED (container);
838 GtkPanedPrivate *priv = paned->priv;
840 g_assert (child == priv->child1 || child == priv->child2);
844 case CHILD_PROP_RESIZE:
845 if (child == priv->child1)
846 g_value_set_boolean (value, priv->child1_resize);
848 g_value_set_boolean (value, priv->child2_resize);
850 case CHILD_PROP_SHRINK:
851 if (child == priv->child1)
852 g_value_set_boolean (value, priv->child1_shrink);
854 g_value_set_boolean (value, priv->child2_shrink);
857 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
863 gtk_paned_finalize (GObject *object)
865 GtkPaned *paned = GTK_PANED (object);
867 gtk_paned_set_saved_focus (paned, NULL);
868 gtk_paned_set_first_paned (paned, NULL);
870 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
874 get_preferred_size_for_size (GtkWidget *widget,
875 GtkOrientation orientation,
880 if (orientation == GTK_ORIENTATION_HORIZONTAL)
882 gtk_widget_get_preferred_width (widget, minimum, natural);
884 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
887 gtk_widget_get_preferred_height (widget, minimum, natural);
889 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
893 gtk_paned_get_preferred_size (GtkWidget *widget,
894 GtkOrientation orientation,
899 GtkPaned *paned = GTK_PANED (widget);
900 GtkPanedPrivate *priv = paned->priv;
901 gint child_min, child_nat;
903 *minimum = *natural = 0;
905 if (priv->child1 && gtk_widget_get_visible (priv->child1))
907 get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
908 *minimum = child_min;
909 *natural = child_nat;
912 if (priv->child2 && gtk_widget_get_visible (priv->child2))
914 get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
916 if (priv->orientation == orientation)
918 *minimum += child_min;
919 *natural += child_nat;
923 *minimum = MAX (*minimum, child_min);
924 *natural = MAX (*natural, child_nat);
928 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
929 priv->child2 && gtk_widget_get_visible (priv->child2))
933 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
935 if (priv->orientation == orientation)
937 *minimum += handle_size;
938 *natural += handle_size;
944 gtk_paned_get_preferred_width (GtkWidget *widget,
948 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
952 gtk_paned_get_preferred_height (GtkWidget *widget,
956 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
960 gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
965 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
969 gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
974 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
978 flip_child (GtkWidget *widget,
979 GtkAllocation *child_pos)
981 GtkAllocation allocation;
984 gtk_widget_get_allocation (widget, &allocation);
986 width = allocation.width;
988 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
992 gtk_paned_set_child_visible (GtkPaned *paned,
996 GtkPanedPrivate *priv = paned->priv;
999 child = id == CHILD1 ? priv->child1 : priv->child2;
1004 gtk_widget_set_child_visible (child, visible);
1006 if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
1008 GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
1010 if (visible != gdk_window_is_visible (window))
1013 gdk_window_show (window);
1015 gdk_window_hide (window);
1021 gtk_paned_child_allocate (GtkWidget *child,
1022 GdkWindow *child_window, /* can be NULL */
1023 const GtkAllocation *window_allocation,
1024 GtkAllocation *child_allocation)
1027 gdk_window_move_resize (child_window,
1028 window_allocation->x, window_allocation->y,
1029 window_allocation->width, window_allocation->height);
1031 gtk_widget_size_allocate (child, child_allocation);
1035 gtk_paned_size_allocate (GtkWidget *widget,
1036 GtkAllocation *allocation)
1038 GtkPaned *paned = GTK_PANED (widget);
1039 GtkPanedPrivate *priv = paned->priv;
1041 gtk_widget_set_allocation (widget, allocation);
1043 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1044 priv->child2 && gtk_widget_get_visible (priv->child2))
1046 GtkAllocation child1_allocation, window1_allocation;
1047 GtkAllocation child2_allocation, window2_allocation;
1048 GtkAllocation priv_child1_allocation;
1049 GdkRectangle old_handle_pos;
1052 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1054 old_handle_pos = priv->handle_pos;
1056 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1058 gint child1_width, child2_width;
1060 gtk_widget_get_preferred_width_for_height (priv->child1,
1062 &child1_width, NULL);
1063 gtk_widget_get_preferred_width_for_height (priv->child2,
1065 &child2_width, NULL);
1067 gtk_paned_calc_position (paned,
1068 MAX (1, allocation->width - handle_size),
1072 priv->handle_pos.x = allocation->x + priv->child1_size;
1073 priv->handle_pos.y = allocation->y;
1074 priv->handle_pos.width = handle_size;
1075 priv->handle_pos.height = allocation->height;
1077 window1_allocation.height = window2_allocation.height = allocation->height;
1078 window1_allocation.width = MAX (1, priv->child1_size);
1079 window1_allocation.x = allocation->x;
1080 window1_allocation.y = window2_allocation.y = allocation->y;
1082 window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
1083 window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
1085 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1087 flip_child (widget, &(window2_allocation));
1088 flip_child (widget, &(window1_allocation));
1089 flip_child (widget, &(priv->handle_pos));
1092 child1_allocation.x = child1_allocation.y = 0;
1093 child1_allocation.width = window1_allocation.width;
1094 child1_allocation.height = window1_allocation.height;
1095 if (child1_width > child1_allocation.width)
1097 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
1098 child1_allocation.x -= child1_width - child1_allocation.width;
1099 child1_allocation.width = child1_width;
1102 child2_allocation.x = child2_allocation.y = 0;
1103 child2_allocation.width = window2_allocation.width;
1104 child2_allocation.height = window2_allocation.height;
1105 if (child2_width > child2_allocation.width)
1107 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1108 child2_allocation.x -= child2_width - child2_allocation.width;
1109 child2_allocation.width = child2_width;
1114 gint child1_height, child2_height;
1116 gtk_widget_get_preferred_height_for_width (priv->child1,
1118 &child1_height, NULL);
1119 gtk_widget_get_preferred_height_for_width (priv->child2,
1121 &child2_height, NULL);
1123 gtk_paned_calc_position (paned,
1124 MAX (1, allocation->height - handle_size),
1128 priv->handle_pos.x = allocation->x;
1129 priv->handle_pos.y = allocation->y + priv->child1_size;
1130 priv->handle_pos.width = allocation->width;
1131 priv->handle_pos.height = handle_size;
1133 window1_allocation.width = window2_allocation.width = allocation->width;
1134 window1_allocation.height = MAX (1, priv->child1_size);
1135 window1_allocation.x = window2_allocation.x = allocation->x;
1136 window1_allocation.y = allocation->y;
1138 window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
1139 window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
1141 child1_allocation.x = child1_allocation.y = 0;
1142 child1_allocation.width = window1_allocation.width;
1143 child1_allocation.height = window1_allocation.height;
1144 if (child1_height > child1_allocation.height)
1146 child1_allocation.y -= child1_height - child1_allocation.height;
1147 child1_allocation.height = child1_height;
1150 child2_allocation.x = child2_allocation.y = 0;
1151 child2_allocation.width = window2_allocation.width;
1152 child2_allocation.height = window2_allocation.height;
1153 if (child2_height > child2_allocation.height)
1154 child2_allocation.height = child2_height;
1157 if (gtk_widget_get_mapped (widget) &&
1158 (old_handle_pos.x != priv->handle_pos.x ||
1159 old_handle_pos.y != priv->handle_pos.y ||
1160 old_handle_pos.width != priv->handle_pos.width ||
1161 old_handle_pos.height != priv->handle_pos.height))
1165 window = gtk_widget_get_window (widget);
1166 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
1167 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
1170 if (gtk_widget_get_realized (widget))
1172 if (gtk_widget_get_mapped (widget))
1173 gdk_window_show (priv->handle);
1175 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1177 gdk_window_move_resize (priv->handle,
1181 priv->handle_pos.height);
1185 gdk_window_move_resize (priv->handle,
1188 priv->handle_pos.width,
1193 /* Now allocate the childen, making sure, when resizing not to
1194 * overlap the windows
1196 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
1197 if (gtk_widget_get_mapped (widget) &&
1198 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1199 priv_child1_allocation.width < child1_allocation.width) ||
1201 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1202 priv_child1_allocation.height < child1_allocation.height)))
1204 gtk_paned_child_allocate (priv->child2,
1205 priv->child2_window,
1206 &window2_allocation,
1207 &child2_allocation);
1208 gtk_paned_child_allocate (priv->child1,
1209 priv->child1_window,
1210 &window1_allocation,
1211 &child1_allocation);
1215 gtk_paned_child_allocate (priv->child1,
1216 priv->child1_window,
1217 &window1_allocation,
1218 &child1_allocation);
1219 gtk_paned_child_allocate (priv->child2,
1220 priv->child2_window,
1221 &window2_allocation,
1222 &child2_allocation);
1227 GtkAllocation window_allocation, child_allocation;
1229 if (gtk_widget_get_realized (widget))
1230 gdk_window_hide (priv->handle);
1232 window_allocation.x = allocation->x;
1233 window_allocation.y = allocation->y;
1234 window_allocation.width = allocation->width;
1235 window_allocation.height = allocation->height;
1236 child_allocation.x = child_allocation.y = 0;
1237 child_allocation.width = allocation->width;
1238 child_allocation.height = allocation->height;
1240 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1242 gtk_paned_set_child_visible (paned, 0, TRUE);
1244 gtk_paned_set_child_visible (paned, 1, FALSE);
1246 gtk_paned_child_allocate (priv->child1,
1247 priv->child1_window,
1251 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1253 gtk_paned_set_child_visible (paned, 1, TRUE);
1255 gtk_paned_set_child_visible (paned, 0, FALSE);
1257 gtk_paned_child_allocate (priv->child2,
1258 priv->child2_window,
1265 gtk_paned_set_child_visible (paned, 0, FALSE);
1267 gtk_paned_set_child_visible (paned, 1, FALSE);
1273 gtk_paned_create_child_window (GtkPaned *paned,
1274 GtkWidget *child) /* may be NULL */
1276 GtkWidget *widget = GTK_WIDGET (paned);
1277 GtkPanedPrivate *priv = paned->priv;
1279 GdkWindowAttr attributes;
1280 gint attributes_mask;
1282 attributes.window_type = GDK_WINDOW_CHILD;
1283 attributes.wclass = GDK_INPUT_OUTPUT;
1284 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1287 GtkAllocation allocation;
1290 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1292 gtk_widget_get_allocation (widget, &allocation);
1293 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1294 child == priv->child2 && priv->child1 &&
1295 gtk_widget_get_visible (priv->child1))
1296 attributes.x = priv->handle_pos.x + handle_size;
1298 attributes.x = allocation.x;
1299 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1300 child == priv->child2 && priv->child1 &&
1301 gtk_widget_get_visible (priv->child1))
1302 attributes.y = priv->handle_pos.y + handle_size;
1304 attributes.y = allocation.y;
1306 gtk_widget_get_allocation (child, &allocation);
1307 attributes.width = allocation.width;
1308 attributes.height = allocation.height;
1309 attributes_mask = GDK_WA_X | GDK_WA_Y;
1313 attributes.width = 1;
1314 attributes.height = 1;
1315 attributes_mask = 0;
1318 window = gdk_window_new (gtk_widget_get_window (widget),
1319 &attributes, attributes_mask);
1320 gdk_window_set_user_data (window, paned);
1321 gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
1324 gtk_widget_set_parent_window (child, window);
1330 gtk_paned_realize (GtkWidget *widget)
1332 GtkPaned *paned = GTK_PANED (widget);
1333 GtkPanedPrivate *priv = paned->priv;
1335 GdkWindowAttr attributes;
1336 gint attributes_mask;
1338 gtk_widget_set_realized (widget, TRUE);
1340 window = gtk_widget_get_parent_window (widget);
1341 gtk_widget_set_window (widget, window);
1342 g_object_ref (window);
1344 attributes.window_type = GDK_WINDOW_CHILD;
1345 attributes.wclass = GDK_INPUT_ONLY;
1346 attributes.x = priv->handle_pos.x;
1347 attributes.y = priv->handle_pos.y;
1348 attributes.width = priv->handle_pos.width;
1349 attributes.height = priv->handle_pos.height;
1350 attributes.event_mask = gtk_widget_get_events (widget);
1351 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1352 GDK_BUTTON_RELEASE_MASK |
1353 GDK_ENTER_NOTIFY_MASK |
1354 GDK_LEAVE_NOTIFY_MASK |
1355 GDK_POINTER_MOTION_MASK |
1356 GDK_POINTER_MOTION_HINT_MASK);
1357 attributes_mask = GDK_WA_X | GDK_WA_Y;
1358 if (gtk_widget_is_sensitive (widget))
1360 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1362 attributes_mask |= GDK_WA_CURSOR;
1365 priv->handle = gdk_window_new (window,
1366 &attributes, attributes_mask);
1367 gdk_window_set_user_data (priv->handle, paned);
1368 if (attributes_mask & GDK_WA_CURSOR)
1369 g_object_unref (attributes.cursor);
1371 priv->child1_window = gtk_paned_create_child_window (paned, priv->child1);
1372 priv->child2_window = gtk_paned_create_child_window (paned, priv->child2);
1376 gtk_paned_unrealize (GtkWidget *widget)
1378 GtkPaned *paned = GTK_PANED (widget);
1379 GtkPanedPrivate *priv = paned->priv;
1382 gtk_widget_set_parent_window (priv->child2, NULL);
1383 gdk_window_set_user_data (priv->child2_window, NULL);
1384 gdk_window_destroy (priv->child2_window);
1385 priv->child2_window = NULL;
1388 gtk_widget_set_parent_window (priv->child1, NULL);
1389 gdk_window_set_user_data (priv->child1_window, NULL);
1390 gdk_window_destroy (priv->child1_window);
1391 priv->child1_window = NULL;
1395 gdk_window_set_user_data (priv->handle, NULL);
1396 gdk_window_destroy (priv->handle);
1397 priv->handle = NULL;
1400 gtk_paned_set_last_child1_focus (paned, NULL);
1401 gtk_paned_set_last_child2_focus (paned, NULL);
1402 gtk_paned_set_saved_focus (paned, NULL);
1403 gtk_paned_set_first_paned (paned, NULL);
1405 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1409 gtk_paned_map (GtkWidget *widget)
1411 GtkPaned *paned = GTK_PANED (widget);
1412 GtkPanedPrivate *priv = paned->priv;
1414 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1415 priv->child2 && gtk_widget_get_visible (priv->child2))
1416 gdk_window_show (priv->handle);
1418 if (priv->child1 && gtk_widget_get_visible (priv->child1) && gtk_widget_get_child_visible (priv->child1))
1419 gdk_window_show (priv->child1_window);
1420 if (priv->child2 && gtk_widget_get_visible (priv->child2) && gtk_widget_get_child_visible (priv->child2))
1421 gdk_window_show (priv->child2_window);
1423 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1427 gtk_paned_unmap (GtkWidget *widget)
1429 GtkPaned *paned = GTK_PANED (widget);
1430 GtkPanedPrivate *priv = paned->priv;
1432 gdk_window_hide (priv->handle);
1434 if (gdk_window_is_visible (priv->child1_window))
1435 gdk_window_hide (priv->child1_window);
1436 if (gdk_window_is_visible (priv->child2_window))
1437 gdk_window_hide (priv->child2_window);
1439 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1443 gtk_paned_draw (GtkWidget *widget,
1446 GtkPaned *paned = GTK_PANED (widget);
1447 GtkPanedPrivate *priv = paned->priv;
1449 if (gtk_cairo_should_draw_window (cr, priv->child1_window))
1452 gtk_cairo_transform_to_window (cr, widget, priv->child1_window);
1453 gtk_render_background (gtk_widget_get_style_context (widget),
1456 gdk_window_get_width (priv->child1_window),
1457 gdk_window_get_height (priv->child1_window));
1461 if (gtk_cairo_should_draw_window (cr, priv->child2_window))
1464 gtk_cairo_transform_to_window (cr, widget, priv->child2_window);
1465 gtk_render_background (gtk_widget_get_style_context (widget),
1468 gdk_window_get_width (priv->child2_window),
1469 gdk_window_get_height (priv->child2_window));
1473 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)) &&
1474 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1475 priv->child2 && gtk_widget_get_visible (priv->child2))
1477 GtkStyleContext *context;
1478 GtkStateFlags state;
1479 GtkAllocation allocation;
1481 gtk_widget_get_allocation (widget, &allocation);
1482 context = gtk_widget_get_style_context (widget);
1483 state = gtk_widget_get_state_flags (widget);
1485 if (gtk_widget_is_focus (widget))
1486 state |= GTK_STATE_FLAG_SELECTED;
1487 if (priv->handle_prelit)
1488 state |= GTK_STATE_FLAG_PRELIGHT;
1490 gtk_style_context_save (context);
1491 gtk_style_context_set_state (context, state);
1492 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1493 gtk_render_handle (context, cr,
1494 priv->handle_pos.x - allocation.x,
1495 priv->handle_pos.y - allocation.y,
1496 priv->handle_pos.width,
1497 priv->handle_pos.height);
1499 gtk_style_context_restore (context);
1502 /* Chain up to draw children */
1503 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1509 is_rtl (GtkPaned *paned)
1511 GtkPanedPrivate *priv = paned->priv;
1513 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1514 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1523 update_drag (GtkPaned *paned)
1525 GtkPanedPrivate *priv = paned->priv;
1526 GtkAllocation allocation;
1527 GtkWidget *widget = GTK_WIDGET (paned);
1532 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1533 gtk_widget_get_pointer (widget, &pos, NULL);
1535 gtk_widget_get_pointer (widget, NULL, &pos);
1537 pos -= priv->drag_pos;
1541 gtk_widget_style_get (widget,
1542 "handle-size", &handle_size,
1545 gtk_widget_get_allocation (widget, &allocation);
1546 size = allocation.width - pos - handle_size;
1553 size = CLAMP (size, priv->min_position, priv->max_position);
1555 if (size != priv->child1_size)
1556 gtk_paned_set_position (paned, size);
1560 gtk_paned_enter (GtkWidget *widget,
1561 GdkEventCrossing *event)
1563 GtkPaned *paned = GTK_PANED (widget);
1564 GtkPanedPrivate *priv = paned->priv;
1567 update_drag (paned);
1570 priv->handle_prelit = TRUE;
1571 gtk_widget_queue_draw_area (widget,
1574 priv->handle_pos.width,
1575 priv->handle_pos.height);
1582 gtk_paned_leave (GtkWidget *widget,
1583 GdkEventCrossing *event)
1585 GtkPaned *paned = GTK_PANED (widget);
1586 GtkPanedPrivate *priv = paned->priv;
1589 update_drag (paned);
1592 priv->handle_prelit = FALSE;
1593 gtk_widget_queue_draw_area (widget,
1596 priv->handle_pos.width,
1597 priv->handle_pos.height);
1604 gtk_paned_focus (GtkWidget *widget,
1605 GtkDirectionType direction)
1610 /* This is a hack, but how can this be done without
1611 * excessive cut-and-paste from gtkcontainer.c?
1614 gtk_widget_set_can_focus (widget, FALSE);
1615 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1616 gtk_widget_set_can_focus (widget, TRUE);
1622 gtk_paned_button_press (GtkWidget *widget,
1623 GdkEventButton *event)
1625 GtkPaned *paned = GTK_PANED (widget);
1626 GtkPanedPrivate *priv = paned->priv;
1628 if (!priv->in_drag &&
1629 (event->window == priv->handle) && (event->button == 1))
1631 /* We need a server grab here, not gtk_grab_add(), since
1632 * we don't want to pass events on to the widget's children */
1633 if (gdk_device_grab (event->device,
1635 GDK_OWNERSHIP_WINDOW, FALSE,
1636 GDK_POINTER_MOTION_HINT_MASK
1637 | GDK_BUTTON1_MOTION_MASK
1638 | GDK_BUTTON_RELEASE_MASK
1639 | GDK_ENTER_NOTIFY_MASK
1640 | GDK_LEAVE_NOTIFY_MASK,
1641 NULL, event->time) != GDK_GRAB_SUCCESS)
1644 priv->in_drag = TRUE;
1645 priv->grab_time = event->time;
1646 priv->grab_device = event->device;
1648 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1649 priv->drag_pos = event->x;
1651 priv->drag_pos = event->y;
1660 gtk_paned_grab_broken (GtkWidget *widget,
1661 GdkEventGrabBroken *event)
1663 GtkPaned *paned = GTK_PANED (widget);
1664 GtkPanedPrivate *priv = paned->priv;
1666 priv->in_drag = FALSE;
1667 priv->drag_pos = -1;
1668 priv->position_set = TRUE;
1674 stop_drag (GtkPaned *paned)
1676 GtkPanedPrivate *priv = paned->priv;
1678 priv->in_drag = FALSE;
1679 priv->drag_pos = -1;
1680 priv->position_set = TRUE;
1682 gdk_device_ungrab (priv->grab_device,
1684 priv->grab_device = NULL;
1688 gtk_paned_grab_notify (GtkWidget *widget,
1689 gboolean was_grabbed)
1691 GtkPaned *paned = GTK_PANED (widget);
1692 GtkPanedPrivate *priv = paned->priv;
1693 GdkDevice *grab_device;
1695 grab_device = priv->grab_device;
1697 if (priv->in_drag && grab_device &&
1698 gtk_widget_device_is_shadowed (widget, grab_device))
1703 gtk_paned_state_flags_changed (GtkWidget *widget,
1704 GtkStateFlags previous_state)
1706 GtkPaned *paned = GTK_PANED (widget);
1707 GtkPanedPrivate *priv = paned->priv;
1710 if (gtk_widget_get_realized (widget))
1712 if (gtk_widget_is_sensitive (widget))
1713 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1718 gdk_window_set_cursor (priv->handle, cursor);
1721 g_object_unref (cursor);
1726 gtk_paned_button_release (GtkWidget *widget,
1727 GdkEventButton *event)
1729 GtkPaned *paned = GTK_PANED (widget);
1730 GtkPanedPrivate *priv = paned->priv;
1732 if (priv->in_drag && (event->button == 1))
1743 gtk_paned_motion (GtkWidget *widget,
1744 GdkEventMotion *event)
1746 GtkPaned *paned = GTK_PANED (widget);
1747 GtkPanedPrivate *priv = paned->priv;
1751 update_drag (paned);
1760 * @orientation: the paned's orientation.
1762 * Creates a new #GtkPaned widget.
1764 * Return value: a new #GtkPaned.
1769 gtk_paned_new (GtkOrientation orientation)
1771 return g_object_new (GTK_TYPE_PANED,
1772 "orientation", orientation,
1778 * @paned: a paned widget
1779 * @child: the child to add
1781 * Adds a child to the top or left pane with default parameters. This is
1783 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1786 gtk_paned_add1 (GtkPaned *paned,
1789 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1794 * @paned: a paned widget
1795 * @child: the child to add
1797 * Adds a child to the bottom or right pane with default parameters. This
1799 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1802 gtk_paned_add2 (GtkPaned *paned,
1805 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1810 * @paned: a paned widget
1811 * @child: the child to add
1812 * @resize: should this child expand when the paned widget is resized.
1813 * @shrink: can this child be made smaller than its requisition.
1815 * Adds a child to the top or left pane.
1818 gtk_paned_pack1 (GtkPaned *paned,
1823 GtkPanedPrivate *priv;
1825 g_return_if_fail (GTK_IS_PANED (paned));
1826 g_return_if_fail (GTK_IS_WIDGET (child));
1832 priv->child1 = child;
1833 priv->child1_resize = resize;
1834 priv->child1_shrink = shrink;
1836 gtk_widget_set_parent_window (child, priv->child1_window);
1837 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1843 * @paned: a paned widget
1844 * @child: the child to add
1845 * @resize: should this child expand when the paned widget is resized.
1846 * @shrink: can this child be made smaller than its requisition.
1848 * Adds a child to the bottom or right pane.
1851 gtk_paned_pack2 (GtkPaned *paned,
1856 GtkPanedPrivate *priv;
1858 g_return_if_fail (GTK_IS_PANED (paned));
1859 g_return_if_fail (GTK_IS_WIDGET (child));
1865 priv->child2 = child;
1866 priv->child2_resize = resize;
1867 priv->child2_shrink = shrink;
1869 gtk_widget_set_parent_window (child, priv->child2_window);
1870 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1876 gtk_paned_add (GtkContainer *container,
1879 GtkPanedPrivate *priv;
1882 g_return_if_fail (GTK_IS_PANED (container));
1884 paned = GTK_PANED (container);
1888 gtk_paned_add1 (paned, widget);
1889 else if (!priv->child2)
1890 gtk_paned_add2 (paned, widget);
1892 g_warning ("GtkPaned cannot have more than 2 children\n");
1896 gtk_paned_remove (GtkContainer *container,
1899 GtkPaned *paned = GTK_PANED (container);
1900 GtkPanedPrivate *priv = paned->priv;
1901 gboolean was_visible;
1903 was_visible = gtk_widget_get_visible (widget);
1905 if (priv->child1 == widget)
1907 if (priv->child1_window && gdk_window_is_visible (priv->child1_window))
1908 gdk_window_hide (priv->child1_window);
1910 gtk_widget_unparent (widget);
1912 priv->child1 = NULL;
1914 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1915 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1917 else if (priv->child2 == widget)
1919 if (priv->child2_window && gdk_window_is_visible (priv->child2_window))
1920 gdk_window_hide (priv->child2_window);
1922 gtk_widget_unparent (widget);
1924 priv->child2 = NULL;
1926 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1927 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1932 gtk_paned_forall (GtkContainer *container,
1933 gboolean include_internals,
1934 GtkCallback callback,
1935 gpointer callback_data)
1937 GtkPanedPrivate *priv;
1940 g_return_if_fail (callback != NULL);
1942 paned = GTK_PANED (container);
1946 (*callback) (priv->child1, callback_data);
1948 (*callback) (priv->child2, callback_data);
1952 * gtk_paned_get_position:
1953 * @paned: a #GtkPaned widget
1955 * Obtains the position of the divider between the two panes.
1957 * Return value: position of the divider
1960 gtk_paned_get_position (GtkPaned *paned)
1962 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1964 return paned->priv->child1_size;
1968 * gtk_paned_set_position:
1969 * @paned: a #GtkPaned widget
1970 * @position: pixel position of divider, a negative value means that the position
1973 * Sets the position of the divider between the two panes.
1976 gtk_paned_set_position (GtkPaned *paned,
1979 GtkPanedPrivate *priv;
1982 g_return_if_fail (GTK_IS_PANED (paned));
1986 if (priv->child1_size == position)
1989 object = G_OBJECT (paned);
1993 /* We don't clamp here - the assumption is that
1994 * if the total allocation changes at the same time
1995 * as the position, the position set is with reference
1996 * to the new total size. If only the position changes,
1997 * then clamping will occur in gtk_paned_calc_position()
2000 priv->child1_size = position;
2001 priv->position_set = TRUE;
2005 priv->position_set = FALSE;
2008 g_object_freeze_notify (object);
2009 g_object_notify (object, "position");
2010 g_object_notify (object, "position-set");
2011 g_object_thaw_notify (object);
2013 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
2016 /* Hacky work-around for bug #144269 */
2017 if (priv->child2 != NULL)
2019 gtk_widget_queue_draw (priv->child2);
2025 * gtk_paned_get_child1:
2026 * @paned: a #GtkPaned widget
2028 * Obtains the first child of the paned widget.
2030 * Return value: (transfer none): first child, or %NULL if it is not set.
2035 gtk_paned_get_child1 (GtkPaned *paned)
2037 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2039 return paned->priv->child1;
2043 * gtk_paned_get_child2:
2044 * @paned: a #GtkPaned widget
2046 * Obtains the second child of the paned widget.
2048 * Return value: (transfer none): second child, or %NULL if it is not set.
2053 gtk_paned_get_child2 (GtkPaned *paned)
2055 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2057 return paned->priv->child2;
2061 gtk_paned_calc_position (GtkPaned *paned,
2066 GtkPanedPrivate *priv = paned->priv;
2068 gint old_min_position;
2069 gint old_max_position;
2071 old_position = priv->child1_size;
2072 old_min_position = priv->min_position;
2073 old_max_position = priv->max_position;
2075 priv->min_position = priv->child1_shrink ? 0 : child1_req;
2077 priv->max_position = allocation;
2078 if (!priv->child2_shrink)
2079 priv->max_position = MAX (1, priv->max_position - child2_req);
2080 priv->max_position = MAX (priv->min_position, priv->max_position);
2082 if (!priv->position_set)
2084 if (priv->child1_resize && !priv->child2_resize)
2085 priv->child1_size = MAX (0, allocation - child2_req);
2086 else if (!priv->child1_resize && priv->child2_resize)
2087 priv->child1_size = child1_req;
2088 else if (child1_req + child2_req != 0)
2089 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
2091 priv->child1_size = allocation * 0.5 + 0.5;
2095 /* If the position was set before the initial allocation.
2096 * (priv->last_allocation <= 0) just clamp it and leave it.
2098 if (priv->last_allocation > 0)
2100 if (priv->child1_resize && !priv->child2_resize)
2101 priv->child1_size += allocation - priv->last_allocation;
2102 else if (!(!priv->child1_resize && priv->child2_resize))
2103 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
2107 priv->child1_size = CLAMP (priv->child1_size,
2109 priv->max_position);
2112 gtk_paned_set_child_visible (paned, 0, priv->child1_size != 0);
2115 gtk_paned_set_child_visible (paned, 1, priv->child1_size != allocation);
2117 g_object_freeze_notify (G_OBJECT (paned));
2118 if (priv->child1_size != old_position)
2119 g_object_notify (G_OBJECT (paned), "position");
2120 if (priv->min_position != old_min_position)
2121 g_object_notify (G_OBJECT (paned), "min-position");
2122 if (priv->max_position != old_max_position)
2123 g_object_notify (G_OBJECT (paned), "max-position");
2124 g_object_thaw_notify (G_OBJECT (paned));
2126 priv->last_allocation = allocation;
2130 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
2132 GtkPanedPrivate *priv = paned->priv;
2134 if (priv->saved_focus)
2135 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
2136 (gpointer *)&(priv->saved_focus));
2138 priv->saved_focus = widget;
2140 if (priv->saved_focus)
2141 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
2142 (gpointer *)&(priv->saved_focus));
2146 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
2148 GtkPanedPrivate *priv = paned->priv;
2150 if (priv->first_paned)
2151 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
2152 (gpointer *)&(priv->first_paned));
2154 priv->first_paned = first_paned;
2156 if (priv->first_paned)
2157 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
2158 (gpointer *)&(priv->first_paned));
2162 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
2164 GtkPanedPrivate *priv = paned->priv;
2166 if (priv->last_child1_focus)
2167 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
2168 (gpointer *)&(priv->last_child1_focus));
2170 priv->last_child1_focus = widget;
2172 if (priv->last_child1_focus)
2173 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
2174 (gpointer *)&(priv->last_child1_focus));
2178 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
2180 GtkPanedPrivate *priv = paned->priv;
2182 if (priv->last_child2_focus)
2183 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
2184 (gpointer *)&(priv->last_child2_focus));
2186 priv->last_child2_focus = widget;
2188 if (priv->last_child2_focus)
2189 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
2190 (gpointer *)&(priv->last_child2_focus));
2194 paned_get_focus_widget (GtkPaned *paned)
2196 GtkWidget *toplevel;
2198 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2199 if (gtk_widget_is_toplevel (toplevel))
2200 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2206 gtk_paned_set_focus_child (GtkContainer *container,
2207 GtkWidget *focus_child)
2210 GtkPanedPrivate *priv;
2211 GtkWidget *container_focus_child;
2213 g_return_if_fail (GTK_IS_PANED (container));
2215 paned = GTK_PANED (container);
2218 if (focus_child == NULL)
2220 GtkWidget *last_focus;
2223 last_focus = paned_get_focus_widget (paned);
2227 /* If there is one or more paned widgets between us and the
2228 * focus widget, we want the topmost of those as last_focus
2230 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
2231 if (GTK_IS_PANED (w))
2234 container_focus_child = gtk_container_get_focus_child (container);
2235 if (container_focus_child == priv->child1)
2236 gtk_paned_set_last_child1_focus (paned, last_focus);
2237 else if (container_focus_child == priv->child2)
2238 gtk_paned_set_last_child2_focus (paned, last_focus);
2242 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2243 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2247 gtk_paned_get_cycle_chain (GtkPaned *paned,
2248 GtkDirectionType direction,
2251 GtkPanedPrivate *priv = paned->priv;
2252 GtkContainer *container = GTK_CONTAINER (paned);
2253 GtkWidget *ancestor = NULL;
2254 GtkWidget *focus_child;
2256 GtkWidget *widget = GTK_WIDGET (paned);
2257 GList *temp_list = NULL;
2260 if (priv->in_recursion)
2263 g_assert (widgets != NULL);
2265 if (priv->last_child1_focus &&
2266 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2268 gtk_paned_set_last_child1_focus (paned, NULL);
2271 if (priv->last_child2_focus &&
2272 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2274 gtk_paned_set_last_child2_focus (paned, NULL);
2277 parent = gtk_widget_get_parent (widget);
2279 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2281 /* The idea here is that temp_list is a list of widgets we want to cycle
2282 * to. The list is prioritized so that the first element is our first
2283 * choice, the next our second, and so on.
2285 * We can't just use g_list_reverse(), because we want to try
2286 * priv->last_child?_focus before priv->child?, both when we
2287 * are going forward and backward.
2289 focus_child = gtk_container_get_focus_child (container);
2290 if (direction == GTK_DIR_TAB_FORWARD)
2292 if (focus_child == priv->child1)
2294 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2295 temp_list = g_list_append (temp_list, priv->child2);
2296 temp_list = g_list_append (temp_list, ancestor);
2298 else if (focus_child == priv->child2)
2300 temp_list = g_list_append (temp_list, ancestor);
2301 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2302 temp_list = g_list_append (temp_list, priv->child1);
2306 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2307 temp_list = g_list_append (temp_list, priv->child1);
2308 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2309 temp_list = g_list_append (temp_list, priv->child2);
2310 temp_list = g_list_append (temp_list, ancestor);
2315 if (focus_child == priv->child1)
2317 temp_list = g_list_append (temp_list, ancestor);
2318 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2319 temp_list = g_list_append (temp_list, priv->child2);
2321 else if (focus_child == priv->child2)
2323 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2324 temp_list = g_list_append (temp_list, priv->child1);
2325 temp_list = g_list_append (temp_list, ancestor);
2329 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2330 temp_list = g_list_append (temp_list, priv->child2);
2331 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2332 temp_list = g_list_append (temp_list, priv->child1);
2333 temp_list = g_list_append (temp_list, ancestor);
2337 /* Walk the list and expand all the paned widgets. */
2338 for (list = temp_list; list != NULL; list = list->next)
2340 GtkWidget *widget = list->data;
2344 if (GTK_IS_PANED (widget))
2346 priv->in_recursion = TRUE;
2347 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2348 priv->in_recursion = FALSE;
2352 *widgets = g_list_append (*widgets, widget);
2357 g_list_free (temp_list);
2361 gtk_paned_cycle_child_focus (GtkPaned *paned,
2364 GList *cycle_chain = NULL;
2367 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2369 /* ignore f6 if the handle is focused */
2370 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2373 /* we can't just let the event propagate up the hierarchy,
2374 * because the paned will want to cycle focus _unless_ an
2375 * ancestor paned handles the event
2377 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2379 for (list = cycle_chain; list != NULL; list = list->next)
2380 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2383 g_list_free (cycle_chain);
2389 get_child_panes (GtkWidget *widget,
2392 if (!widget || !gtk_widget_get_realized (widget))
2395 if (GTK_IS_PANED (widget))
2397 GtkPaned *paned = GTK_PANED (widget);
2398 GtkPanedPrivate *priv = paned->priv;
2400 get_child_panes (priv->child1, panes);
2401 *panes = g_list_prepend (*panes, widget);
2402 get_child_panes (priv->child2, panes);
2404 else if (GTK_IS_CONTAINER (widget))
2406 gtk_container_forall (GTK_CONTAINER (widget),
2407 (GtkCallback)get_child_panes, panes);
2412 get_all_panes (GtkPaned *paned)
2414 GtkPaned *topmost = NULL;
2415 GList *result = NULL;
2418 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2420 if (GTK_IS_PANED (w))
2421 topmost = GTK_PANED (w);
2426 get_child_panes (GTK_WIDGET (topmost), &result);
2428 return g_list_reverse (result);
2432 gtk_paned_find_neighbours (GtkPaned *paned,
2439 all_panes = get_all_panes (paned);
2440 g_assert (all_panes);
2442 this_link = g_list_find (all_panes, paned);
2444 g_assert (this_link);
2446 if (this_link->next)
2447 *next = this_link->next->data;
2449 *next = all_panes->data;
2451 if (this_link->prev)
2452 *prev = this_link->prev->data;
2454 *prev = g_list_last (all_panes)->data;
2456 g_list_free (all_panes);
2460 gtk_paned_move_handle (GtkPaned *paned,
2461 GtkScrollType scroll)
2463 GtkPanedPrivate *priv = paned->priv;
2465 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2472 SINGLE_STEP_SIZE = 1,
2476 new_position = old_position = gtk_paned_get_position (paned);
2481 case GTK_SCROLL_STEP_LEFT:
2482 case GTK_SCROLL_STEP_UP:
2483 case GTK_SCROLL_STEP_BACKWARD:
2484 increment = - SINGLE_STEP_SIZE;
2487 case GTK_SCROLL_STEP_RIGHT:
2488 case GTK_SCROLL_STEP_DOWN:
2489 case GTK_SCROLL_STEP_FORWARD:
2490 increment = SINGLE_STEP_SIZE;
2493 case GTK_SCROLL_PAGE_LEFT:
2494 case GTK_SCROLL_PAGE_UP:
2495 case GTK_SCROLL_PAGE_BACKWARD:
2496 increment = - PAGE_STEP_SIZE;
2499 case GTK_SCROLL_PAGE_RIGHT:
2500 case GTK_SCROLL_PAGE_DOWN:
2501 case GTK_SCROLL_PAGE_FORWARD:
2502 increment = PAGE_STEP_SIZE;
2505 case GTK_SCROLL_START:
2506 new_position = priv->min_position;
2509 case GTK_SCROLL_END:
2510 new_position = priv->max_position;
2520 increment = -increment;
2522 new_position = old_position + increment;
2525 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2527 if (old_position != new_position)
2528 gtk_paned_set_position (paned, new_position);
2537 gtk_paned_restore_focus (GtkPaned *paned)
2539 GtkPanedPrivate *priv = paned->priv;
2541 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2543 if (priv->saved_focus &&
2544 gtk_widget_get_sensitive (priv->saved_focus))
2546 gtk_widget_grab_focus (priv->saved_focus);
2550 /* the saved focus is somehow not available for focusing,
2552 * 1) tabbing into the paned widget
2553 * if that didn't work,
2554 * 2) unset focus for the window if there is one
2557 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2559 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2561 if (GTK_IS_WINDOW (toplevel))
2562 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2566 gtk_paned_set_saved_focus (paned, NULL);
2567 gtk_paned_set_first_paned (paned, NULL);
2572 gtk_paned_accept_position (GtkPaned *paned)
2574 GtkPanedPrivate *priv = paned->priv;
2576 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2578 priv->original_position = -1;
2579 gtk_paned_restore_focus (paned);
2589 gtk_paned_cancel_position (GtkPaned *paned)
2591 GtkPanedPrivate *priv = paned->priv;
2593 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2595 if (priv->original_position != -1)
2597 gtk_paned_set_position (paned, priv->original_position);
2598 priv->original_position = -1;
2601 gtk_paned_restore_focus (paned);
2609 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2612 GtkPanedPrivate *priv = paned->priv;
2613 GtkPaned *next, *prev;
2615 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2617 GtkPaned *focus = NULL;
2619 if (!priv->first_paned)
2621 /* The first_pane has disappeared. As an ad-hoc solution,
2622 * we make the currently focused paned the first_paned. To the
2623 * user this will seem like the paned cycling has been reset.
2626 gtk_paned_set_first_paned (paned, paned);
2629 gtk_paned_find_neighbours (paned, &next, &prev);
2631 if (reversed && prev &&
2632 prev != paned && paned != priv->first_paned)
2636 else if (!reversed && next &&
2637 next != paned && next != priv->first_paned)
2643 gtk_paned_accept_position (paned);
2649 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2650 gtk_paned_set_first_paned (focus, priv->first_paned);
2652 gtk_paned_set_saved_focus (paned, NULL);
2653 gtk_paned_set_first_paned (paned, NULL);
2655 gtk_widget_grab_focus (GTK_WIDGET (focus));
2657 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2659 priv->original_position = -1;
2660 focus->priv->original_position = gtk_paned_get_position (focus);
2665 GtkContainer *container = GTK_CONTAINER (paned);
2668 GtkPaned *prev, *next;
2669 GtkWidget *toplevel;
2670 GtkWidget *focus_child;
2672 gtk_paned_find_neighbours (paned, &next, &prev);
2673 focus_child = gtk_container_get_focus_child (container);
2675 if (focus_child == priv->child1)
2688 else if (focus_child == priv->child2)
2703 /* Focus is not inside this paned, and we don't have focus.
2704 * Presumably this happened because the application wants us
2705 * to start keyboard navigating.
2715 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2717 if (GTK_IS_WINDOW (toplevel))
2718 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2719 gtk_paned_set_first_paned (focus, first);
2720 focus->priv->original_position = gtk_paned_get_position (focus);
2722 gtk_widget_grab_focus (GTK_WIDGET (focus));
2729 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2731 /* This function/signal has the wrong name. It is called when you
2732 * press Tab or Shift-Tab and what we do is act as if
2733 * the user pressed Return and then Tab or Shift-Tab
2735 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2736 gtk_paned_accept_position (paned);
2742 * gtk_paned_get_handle_window:
2743 * @paned: a #GtkPaned
2745 * Returns the #GdkWindow of the handle. This function is
2746 * useful when handling button or motion events because it
2747 * enables the callback to distinguish between the window
2748 * of the paned, a child and the handle.
2750 * Return value: (transfer none): the paned's handle window.
2755 gtk_paned_get_handle_window (GtkPaned *paned)
2757 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2759 return paned->priv->handle;