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"
43 * @Short_description: Base class for widgets with two adjustable panes
46 * #GtkPaned is the base class for widgets with two panes, arranged either
47 * horizontally (#GtkHPaned) or vertically (#GtkVPaned). Child widgets are
48 * added to the panes of the widget with gtk_paned_pack1() and
49 * gtk_paned_pack2(). The division between the two children is set by default
50 * from the size requests of the children, but it can be adjusted by the
53 * A paned widget draws a separator between the two child widgets and a
54 * small handle that the user can drag to adjust the division. It does not
55 * draw any relief around the children or around the separator. (The space
56 * in which the separator is called the gutter.) Often, it is useful to put
57 * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
58 * so that the gutter appears as a ridge. No separator is drawn if one of
59 * the children is missing.
61 * Each child has two options that can be set, @resize and @shrink. If
62 * @resize is true, then when the #GtkPaned is resized, that child will
63 * expand or shrink along with the paned widget. If @shrink is true, then
64 * that child can be made smaller than its requisition by the user.
65 * Setting @shrink to %FALSE allows the application to set a minimum size.
66 * If @resize is false for both children, then this is treated as if
67 * @resize is true for both children.
69 * The application can set the position of the slider as if it were set
70 * by the user, by calling gtk_paned_set_position().
73 * <title>Creating a paned widget with minimum sizes.</title>
75 * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
76 * GtkWidget *frame1 = gtk_frame_new (NULL);
77 * GtkWidget *frame2 = gtk_frame_new (NULL);
78 * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
79 * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
81 * gtk_widget_set_size_request (hpaned, 200, -1);
83 * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
84 * gtk_widget_set_size_request (frame1, 50, -1);
86 * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
87 * gtk_widget_set_size_request (frame2, 50, -1);
97 struct _GtkPanedPrivate
99 GtkPaned *first_paned;
102 GdkWindow *child1_window;
103 GdkWindow *child2_window;
104 GtkWidget *last_child1_focus;
105 GtkWidget *last_child2_focus;
106 GtkWidget *saved_focus;
107 GtkOrientation orientation;
109 GdkCursorType cursor_type;
110 GdkDevice *grab_device;
111 GdkRectangle handle_pos;
116 gint last_allocation;
119 gint original_position;
123 guint handle_prelit : 1;
125 guint in_recursion : 1;
126 guint child1_resize : 1;
127 guint child1_shrink : 1;
128 guint child2_resize : 1;
129 guint child2_shrink : 1;
130 guint position_set : 1;
158 static void gtk_paned_set_property (GObject *object,
162 static void gtk_paned_get_property (GObject *object,
166 static void gtk_paned_set_child_property (GtkContainer *container,
171 static void gtk_paned_get_child_property (GtkContainer *container,
176 static void gtk_paned_finalize (GObject *object);
178 static void gtk_paned_get_preferred_width (GtkWidget *widget,
181 static void gtk_paned_get_preferred_height (GtkWidget *widget,
184 static void gtk_paned_get_preferred_width_for_height
189 static void gtk_paned_get_preferred_height_for_width
195 static void gtk_paned_size_allocate (GtkWidget *widget,
196 GtkAllocation *allocation);
197 static void gtk_paned_realize (GtkWidget *widget);
198 static void gtk_paned_unrealize (GtkWidget *widget);
199 static void gtk_paned_map (GtkWidget *widget);
200 static void gtk_paned_unmap (GtkWidget *widget);
201 static void gtk_paned_state_flags_changed (GtkWidget *widget,
202 GtkStateFlags previous_state);
203 static gboolean gtk_paned_draw (GtkWidget *widget,
205 static gboolean gtk_paned_enter (GtkWidget *widget,
206 GdkEventCrossing *event);
207 static gboolean gtk_paned_leave (GtkWidget *widget,
208 GdkEventCrossing *event);
209 static gboolean gtk_paned_button_press (GtkWidget *widget,
210 GdkEventButton *event);
211 static gboolean gtk_paned_button_release (GtkWidget *widget,
212 GdkEventButton *event);
213 static gboolean gtk_paned_motion (GtkWidget *widget,
214 GdkEventMotion *event);
215 static gboolean gtk_paned_focus (GtkWidget *widget,
216 GtkDirectionType direction);
217 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
218 GdkEventGrabBroken *event);
219 static void gtk_paned_add (GtkContainer *container,
221 static void gtk_paned_remove (GtkContainer *container,
223 static void gtk_paned_forall (GtkContainer *container,
224 gboolean include_internals,
225 GtkCallback callback,
226 gpointer callback_data);
227 static void gtk_paned_calc_position (GtkPaned *paned,
231 static void gtk_paned_set_focus_child (GtkContainer *container,
233 static void gtk_paned_set_saved_focus (GtkPaned *paned,
235 static void gtk_paned_set_first_paned (GtkPaned *paned,
236 GtkPaned *first_paned);
237 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
239 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
241 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
243 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
245 static gboolean gtk_paned_move_handle (GtkPaned *paned,
246 GtkScrollType scroll);
247 static gboolean gtk_paned_accept_position (GtkPaned *paned);
248 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
249 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
251 static GType gtk_paned_child_type (GtkContainer *container);
252 static void gtk_paned_grab_notify (GtkWidget *widget,
253 gboolean was_grabbed);
256 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
257 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
260 static guint signals[LAST_SIGNAL] = { 0 };
264 add_tab_bindings (GtkBindingSet *binding_set,
265 GdkModifierType modifiers)
267 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
268 "toggle-handle-focus", 0);
269 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
270 "toggle-handle-focus", 0);
274 add_move_binding (GtkBindingSet *binding_set,
276 GdkModifierType mask,
277 GtkScrollType scroll)
279 gtk_binding_entry_add_signal (binding_set, keyval, mask,
281 GTK_TYPE_SCROLL_TYPE, scroll);
285 gtk_paned_class_init (GtkPanedClass *class)
287 GObjectClass *object_class;
288 GtkWidgetClass *widget_class;
289 GtkContainerClass *container_class;
290 GtkPanedClass *paned_class;
291 GtkBindingSet *binding_set;
293 object_class = (GObjectClass *) class;
294 widget_class = (GtkWidgetClass *) class;
295 container_class = (GtkContainerClass *) class;
296 paned_class = (GtkPanedClass *) class;
298 object_class->set_property = gtk_paned_set_property;
299 object_class->get_property = gtk_paned_get_property;
300 object_class->finalize = gtk_paned_finalize;
302 widget_class->get_preferred_width = gtk_paned_get_preferred_width;
303 widget_class->get_preferred_height = gtk_paned_get_preferred_height;
304 widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
305 widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
306 widget_class->size_allocate = gtk_paned_size_allocate;
307 widget_class->realize = gtk_paned_realize;
308 widget_class->unrealize = gtk_paned_unrealize;
309 widget_class->map = gtk_paned_map;
310 widget_class->unmap = gtk_paned_unmap;
311 widget_class->draw = gtk_paned_draw;
312 widget_class->focus = gtk_paned_focus;
313 widget_class->enter_notify_event = gtk_paned_enter;
314 widget_class->leave_notify_event = gtk_paned_leave;
315 widget_class->button_press_event = gtk_paned_button_press;
316 widget_class->button_release_event = gtk_paned_button_release;
317 widget_class->motion_notify_event = gtk_paned_motion;
318 widget_class->grab_broken_event = gtk_paned_grab_broken;
319 widget_class->grab_notify = gtk_paned_grab_notify;
320 widget_class->state_flags_changed = gtk_paned_state_flags_changed;
322 container_class->add = gtk_paned_add;
323 container_class->remove = gtk_paned_remove;
324 container_class->forall = gtk_paned_forall;
325 container_class->child_type = gtk_paned_child_type;
326 container_class->set_focus_child = gtk_paned_set_focus_child;
327 container_class->set_child_property = gtk_paned_set_child_property;
328 container_class->get_child_property = gtk_paned_get_child_property;
329 gtk_container_class_handle_border_width (container_class);
331 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
332 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
333 paned_class->move_handle = gtk_paned_move_handle;
334 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
335 paned_class->accept_position = gtk_paned_accept_position;
336 paned_class->cancel_position = gtk_paned_cancel_position;
338 g_object_class_override_property (object_class,
342 g_object_class_install_property (object_class,
344 g_param_spec_int ("position",
346 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
350 GTK_PARAM_READWRITE));
352 g_object_class_install_property (object_class,
354 g_param_spec_boolean ("position-set",
356 P_("TRUE if the Position property should be used"),
358 GTK_PARAM_READWRITE));
360 gtk_widget_class_install_style_property (widget_class,
361 g_param_spec_int ("handle-size",
363 P_("Width of handle"),
367 GTK_PARAM_READABLE));
369 * GtkPaned:min-position:
371 * The smallest possible value for the position property. This property is derived from the
372 * size and shrinkability of the widget's children.
376 g_object_class_install_property (object_class,
378 g_param_spec_int ("min-position",
379 P_("Minimal Position"),
380 P_("Smallest possible value for the \"position\" property"),
384 GTK_PARAM_READABLE));
387 * GtkPaned:max-position:
389 * The largest possible value for the position property. This property is derived from the
390 * size and shrinkability of the widget's children.
394 g_object_class_install_property (object_class,
396 g_param_spec_int ("max-position",
397 P_("Maximal Position"),
398 P_("Largest possible value for the \"position\" property"),
402 GTK_PARAM_READABLE));
407 * The "resize" child property determines whether the child expands and
408 * shrinks along with the paned widget.
412 gtk_container_class_install_child_property (container_class,
414 g_param_spec_boolean ("resize",
416 P_("If TRUE, the child expands and shrinks along with the paned widget"),
418 GTK_PARAM_READWRITE));
423 * The "shrink" child property determines whether the child can be made
424 * smaller than its requisition.
428 gtk_container_class_install_child_property (container_class,
430 g_param_spec_boolean ("shrink",
432 P_("If TRUE, the child can be made smaller than its requisition"),
434 GTK_PARAM_READWRITE));
437 * GtkPaned::cycle-child-focus:
438 * @widget: the object that received the signal
439 * @reversed: whether cycling backward or forward
441 * The ::cycle-child-focus signal is a
442 * <link linkend="keybinding-signals">keybinding signal</link>
443 * which gets emitted to cycle the focus between the children of the paned.
445 * The default binding is f6.
449 signals [CYCLE_CHILD_FOCUS] =
450 g_signal_new (I_("cycle-child-focus"),
451 G_TYPE_FROM_CLASS (object_class),
452 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
453 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
455 _gtk_marshal_BOOLEAN__BOOLEAN,
460 * GtkPaned::toggle-handle-focus:
461 * @widget: the object that received the signal
463 * The ::toggle-handle-focus is a
464 * <link linkend="keybinding-signals">keybinding signal</link>
465 * which gets emitted to accept the current position of the handle and then
466 * move focus to the next widget in the focus chain.
468 * The default binding is Tab.
472 signals [TOGGLE_HANDLE_FOCUS] =
473 g_signal_new (I_("toggle-handle-focus"),
474 G_TYPE_FROM_CLASS (object_class),
475 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
476 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
478 _gtk_marshal_BOOLEAN__VOID,
482 * GtkPaned::move-handle:
483 * @widget: the object that received the signal
484 * @scroll_type: a #GtkScrollType
486 * The ::move-handle signal is a
487 * <link linkend="keybinding-signals">keybinding signal</link>
488 * which gets emitted to move the handle when the user is using key bindings
493 signals[MOVE_HANDLE] =
494 g_signal_new (I_("move-handle"),
495 G_TYPE_FROM_CLASS (object_class),
496 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
497 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
499 _gtk_marshal_BOOLEAN__ENUM,
501 GTK_TYPE_SCROLL_TYPE);
504 * GtkPaned::cycle-handle-focus:
505 * @widget: the object that received the signal
506 * @reversed: whether cycling backward or forward
508 * The ::cycle-handle-focus signal is a
509 * <link linkend="keybinding-signals">keybinding signal</link>
510 * which gets emitted to cycle whether the paned should grab focus to allow
511 * the user to change position of the handle by using key bindings.
513 * The default binding for this signal is f8.
517 signals [CYCLE_HANDLE_FOCUS] =
518 g_signal_new (I_("cycle-handle-focus"),
519 G_TYPE_FROM_CLASS (object_class),
520 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
521 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
523 _gtk_marshal_BOOLEAN__BOOLEAN,
528 * GtkPaned::accept-position:
529 * @widget: the object that received the signal
531 * The ::accept-position signal is a
532 * <link linkend="keybinding-signals">keybinding signal</link>
533 * which gets emitted to accept the current position of the handle when
534 * moving it using key bindings.
536 * The default binding for this signal is Return or Space.
540 signals [ACCEPT_POSITION] =
541 g_signal_new (I_("accept-position"),
542 G_TYPE_FROM_CLASS (object_class),
543 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
544 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
546 _gtk_marshal_BOOLEAN__VOID,
550 * GtkPaned::cancel-position:
551 * @widget: the object that received the signal
553 * The ::cancel-position signal is a
554 * <link linkend="keybinding-signals">keybinding signal</link>
555 * which gets emitted to cancel moving the position of the handle using key
556 * bindings. The position of the handle will be reset to the value prior to
559 * The default binding for this signal is Escape.
563 signals [CANCEL_POSITION] =
564 g_signal_new (I_("cancel-position"),
565 G_TYPE_FROM_CLASS (object_class),
566 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
567 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
569 _gtk_marshal_BOOLEAN__VOID,
572 binding_set = gtk_binding_set_by_class (class);
575 gtk_binding_entry_add_signal (binding_set,
577 "cycle-child-focus", 1,
578 G_TYPE_BOOLEAN, FALSE);
579 gtk_binding_entry_add_signal (binding_set,
580 GDK_KEY_F6, GDK_SHIFT_MASK,
581 "cycle-child-focus", 1,
582 G_TYPE_BOOLEAN, TRUE);
585 gtk_binding_entry_add_signal (binding_set,
587 "cycle-handle-focus", 1,
588 G_TYPE_BOOLEAN, FALSE);
590 gtk_binding_entry_add_signal (binding_set,
591 GDK_KEY_F8, GDK_SHIFT_MASK,
592 "cycle-handle-focus", 1,
593 G_TYPE_BOOLEAN, TRUE);
595 add_tab_bindings (binding_set, 0);
596 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
597 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
598 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
600 /* accept and cancel positions */
601 gtk_binding_entry_add_signal (binding_set,
603 "cancel-position", 0);
605 gtk_binding_entry_add_signal (binding_set,
607 "accept-position", 0);
608 gtk_binding_entry_add_signal (binding_set,
609 GDK_KEY_ISO_Enter, 0,
610 "accept-position", 0);
611 gtk_binding_entry_add_signal (binding_set,
613 "accept-position", 0);
614 gtk_binding_entry_add_signal (binding_set,
616 "accept-position", 0);
617 gtk_binding_entry_add_signal (binding_set,
619 "accept-position", 0);
622 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
623 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
624 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
625 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
627 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
628 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
629 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
630 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
632 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
633 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
634 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
635 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
636 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
637 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
639 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
640 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
641 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
642 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
643 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
644 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
646 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
647 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
648 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
649 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
651 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
655 gtk_paned_child_type (GtkContainer *container)
657 GtkPaned *paned = GTK_PANED (container);
658 GtkPanedPrivate *priv = paned->priv;
660 if (!priv->child1 || !priv->child2)
661 return GTK_TYPE_WIDGET;
667 gtk_paned_init (GtkPaned *paned)
669 GtkPanedPrivate *priv;
671 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
672 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
674 /* We only need to redraw when the handle position moves, which is
675 * independent of the overall allocation of the GtkPaned
677 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
679 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
682 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
683 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
688 priv->cursor_type = GDK_CROSS;
690 priv->handle_pos.width = 5;
691 priv->handle_pos.height = 5;
692 priv->position_set = FALSE;
693 priv->last_allocation = -1;
694 priv->in_drag = FALSE;
696 priv->last_child1_focus = NULL;
697 priv->last_child2_focus = NULL;
698 priv->in_recursion = FALSE;
699 priv->handle_prelit = FALSE;
700 priv->original_position = -1;
702 priv->handle_pos.x = -1;
703 priv->handle_pos.y = -1;
709 gtk_paned_set_property (GObject *object,
714 GtkPaned *paned = GTK_PANED (object);
715 GtkPanedPrivate *priv = paned->priv;
719 case PROP_ORIENTATION:
720 priv->orientation = g_value_get_enum (value);
722 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
723 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
725 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
727 /* state_flags_changed updates the cursor */
728 gtk_paned_state_flags_changed (GTK_WIDGET (paned), 0);
729 gtk_widget_queue_resize (GTK_WIDGET (paned));
732 gtk_paned_set_position (paned, g_value_get_int (value));
734 case PROP_POSITION_SET:
735 priv->position_set = g_value_get_boolean (value);
736 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
739 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
745 gtk_paned_get_property (GObject *object,
750 GtkPaned *paned = GTK_PANED (object);
751 GtkPanedPrivate *priv = paned->priv;
755 case PROP_ORIENTATION:
756 g_value_set_enum (value, priv->orientation);
759 g_value_set_int (value, priv->child1_size);
761 case PROP_POSITION_SET:
762 g_value_set_boolean (value, priv->position_set);
764 case PROP_MIN_POSITION:
765 g_value_set_int (value, priv->min_position);
767 case PROP_MAX_POSITION:
768 g_value_set_int (value, priv->max_position);
771 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
777 gtk_paned_set_child_property (GtkContainer *container,
783 GtkPaned *paned = GTK_PANED (container);
784 GtkPanedPrivate *priv = paned->priv;
785 gboolean old_value, new_value;
787 g_assert (child == priv->child1 || child == priv->child2);
789 new_value = g_value_get_boolean (value);
792 case CHILD_PROP_RESIZE:
793 if (child == priv->child1)
795 old_value = priv->child1_resize;
796 priv->child1_resize = new_value;
800 old_value = priv->child2_resize;
801 priv->child2_resize = new_value;
804 case CHILD_PROP_SHRINK:
805 if (child == priv->child1)
807 old_value = priv->child1_shrink;
808 priv->child1_shrink = new_value;
812 old_value = priv->child2_shrink;
813 priv->child2_shrink = new_value;
817 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
818 old_value = -1; /* quiet gcc */
821 if (old_value != new_value)
822 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
826 gtk_paned_get_child_property (GtkContainer *container,
832 GtkPaned *paned = GTK_PANED (container);
833 GtkPanedPrivate *priv = paned->priv;
835 g_assert (child == priv->child1 || child == priv->child2);
839 case CHILD_PROP_RESIZE:
840 if (child == priv->child1)
841 g_value_set_boolean (value, priv->child1_resize);
843 g_value_set_boolean (value, priv->child2_resize);
845 case CHILD_PROP_SHRINK:
846 if (child == priv->child1)
847 g_value_set_boolean (value, priv->child1_shrink);
849 g_value_set_boolean (value, priv->child2_shrink);
852 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
858 gtk_paned_finalize (GObject *object)
860 GtkPaned *paned = GTK_PANED (object);
862 gtk_paned_set_saved_focus (paned, NULL);
863 gtk_paned_set_first_paned (paned, NULL);
865 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
869 get_preferred_size_for_size (GtkWidget *widget,
870 GtkOrientation orientation,
875 if (orientation == GTK_ORIENTATION_HORIZONTAL)
877 gtk_widget_get_preferred_width (widget, minimum, natural);
879 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
882 gtk_widget_get_preferred_height (widget, minimum, natural);
884 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
888 gtk_paned_get_preferred_size (GtkWidget *widget,
889 GtkOrientation orientation,
894 GtkPaned *paned = GTK_PANED (widget);
895 GtkPanedPrivate *priv = paned->priv;
896 gint child_min, child_nat;
898 *minimum = *natural = 0;
900 if (priv->child1 && gtk_widget_get_visible (priv->child1))
902 get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
903 *minimum = child_min;
904 *natural = child_nat;
907 if (priv->child2 && gtk_widget_get_visible (priv->child2))
909 get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
911 if (priv->orientation == orientation)
913 *minimum += child_min;
914 *natural += child_nat;
918 *minimum = MAX (*minimum, child_min);
919 *natural = MAX (*natural, child_nat);
923 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
924 priv->child2 && gtk_widget_get_visible (priv->child2))
928 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
930 if (priv->orientation == orientation)
932 *minimum += handle_size;
933 *natural += handle_size;
939 gtk_paned_get_preferred_width (GtkWidget *widget,
943 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
947 gtk_paned_get_preferred_height (GtkWidget *widget,
951 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
955 gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
960 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
964 gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
969 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
973 flip_child (GtkWidget *widget,
974 GtkAllocation *child_pos)
976 GtkAllocation allocation;
979 gtk_widget_get_allocation (widget, &allocation);
981 width = allocation.width;
983 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
987 gtk_paned_set_child_visible (GtkPaned *paned,
991 GtkPanedPrivate *priv = paned->priv;
994 child = id == CHILD1 ? priv->child1 : priv->child2;
999 gtk_widget_set_child_visible (child, visible);
1001 if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
1003 GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
1005 if (visible != gdk_window_is_visible (window))
1008 gdk_window_show (window);
1010 gdk_window_hide (window);
1016 gtk_paned_child_allocate (GtkWidget *child,
1017 GdkWindow *child_window, /* can be NULL */
1018 const GtkAllocation *window_allocation,
1019 GtkAllocation *child_allocation)
1022 gdk_window_move_resize (child_window,
1023 window_allocation->x, window_allocation->y,
1024 window_allocation->width, window_allocation->height);
1026 gtk_widget_size_allocate (child, child_allocation);
1030 gtk_paned_size_allocate (GtkWidget *widget,
1031 GtkAllocation *allocation)
1033 GtkPaned *paned = GTK_PANED (widget);
1034 GtkPanedPrivate *priv = paned->priv;
1036 gtk_widget_set_allocation (widget, allocation);
1038 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1039 priv->child2 && gtk_widget_get_visible (priv->child2))
1041 GtkAllocation child1_allocation, window1_allocation;
1042 GtkAllocation child2_allocation, window2_allocation;
1043 GtkAllocation priv_child1_allocation;
1044 GdkRectangle old_handle_pos;
1047 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1049 old_handle_pos = priv->handle_pos;
1051 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1053 gint child1_width, child2_width;
1055 gtk_widget_get_preferred_width_for_height (priv->child1,
1057 &child1_width, NULL);
1058 gtk_widget_get_preferred_width_for_height (priv->child2,
1060 &child2_width, NULL);
1062 gtk_paned_calc_position (paned,
1063 MAX (1, allocation->width - handle_size),
1067 priv->handle_pos.x = allocation->x + priv->child1_size;
1068 priv->handle_pos.y = allocation->y;
1069 priv->handle_pos.width = handle_size;
1070 priv->handle_pos.height = allocation->height;
1072 window1_allocation.height = window2_allocation.height = allocation->height;
1073 window1_allocation.width = MAX (1, priv->child1_size);
1074 window1_allocation.x = allocation->x;
1075 window1_allocation.y = window2_allocation.y = allocation->y;
1077 window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
1078 window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
1080 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1082 flip_child (widget, &(window2_allocation));
1083 flip_child (widget, &(window1_allocation));
1084 flip_child (widget, &(priv->handle_pos));
1087 child1_allocation.x = child1_allocation.y = 0;
1088 child1_allocation.width = window1_allocation.width;
1089 child1_allocation.height = window1_allocation.height;
1090 if (child1_width > child1_allocation.width)
1092 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
1093 child1_allocation.x -= child1_width - child1_allocation.width;
1094 child1_allocation.width = child1_width;
1097 child2_allocation.x = child2_allocation.y = 0;
1098 child2_allocation.width = window2_allocation.width;
1099 child2_allocation.height = window2_allocation.height;
1100 if (child2_width > child2_allocation.width)
1102 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1103 child2_allocation.x -= child2_width - child2_allocation.width;
1104 child2_allocation.width = child2_width;
1109 gint child1_height, child2_height;
1111 gtk_widget_get_preferred_height_for_width (priv->child1,
1113 &child1_height, NULL);
1114 gtk_widget_get_preferred_height_for_width (priv->child2,
1116 &child2_height, NULL);
1118 gtk_paned_calc_position (paned,
1119 MAX (1, allocation->height - handle_size),
1123 priv->handle_pos.x = allocation->x;
1124 priv->handle_pos.y = allocation->y + priv->child1_size;
1125 priv->handle_pos.width = allocation->width;
1126 priv->handle_pos.height = handle_size;
1128 window1_allocation.width = window2_allocation.width = allocation->width;
1129 window1_allocation.height = MAX (1, priv->child1_size);
1130 window1_allocation.x = window2_allocation.x = allocation->x;
1131 window1_allocation.y = allocation->y;
1133 window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
1134 window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
1136 child1_allocation.x = child1_allocation.y = 0;
1137 child1_allocation.width = window1_allocation.width;
1138 child1_allocation.height = window1_allocation.height;
1139 if (child1_height > child1_allocation.height)
1141 child1_allocation.y -= child1_height - child1_allocation.height;
1142 child1_allocation.height = child1_height;
1145 child2_allocation.x = child2_allocation.y = 0;
1146 child2_allocation.width = window2_allocation.width;
1147 child2_allocation.height = window2_allocation.height;
1148 if (child2_height > child2_allocation.height)
1149 child2_allocation.height = child2_height;
1152 if (gtk_widget_get_mapped (widget) &&
1153 (old_handle_pos.x != priv->handle_pos.x ||
1154 old_handle_pos.y != priv->handle_pos.y ||
1155 old_handle_pos.width != priv->handle_pos.width ||
1156 old_handle_pos.height != priv->handle_pos.height))
1160 window = gtk_widget_get_window (widget);
1161 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
1162 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
1165 if (gtk_widget_get_realized (widget))
1167 if (gtk_widget_get_mapped (widget))
1168 gdk_window_show (priv->handle);
1170 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1172 gdk_window_move_resize (priv->handle,
1176 priv->handle_pos.height);
1180 gdk_window_move_resize (priv->handle,
1183 priv->handle_pos.width,
1188 /* Now allocate the childen, making sure, when resizing not to
1189 * overlap the windows
1191 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
1192 if (gtk_widget_get_mapped (widget) &&
1193 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1194 priv_child1_allocation.width < child1_allocation.width) ||
1196 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1197 priv_child1_allocation.height < child1_allocation.height)))
1199 gtk_paned_child_allocate (priv->child2,
1200 priv->child2_window,
1201 &window2_allocation,
1202 &child2_allocation);
1203 gtk_paned_child_allocate (priv->child1,
1204 priv->child1_window,
1205 &window1_allocation,
1206 &child1_allocation);
1210 gtk_paned_child_allocate (priv->child1,
1211 priv->child1_window,
1212 &window1_allocation,
1213 &child1_allocation);
1214 gtk_paned_child_allocate (priv->child2,
1215 priv->child2_window,
1216 &window2_allocation,
1217 &child2_allocation);
1222 GtkAllocation window_allocation, child_allocation;
1224 if (gtk_widget_get_realized (widget))
1225 gdk_window_hide (priv->handle);
1228 gtk_paned_set_child_visible (paned, 0, TRUE);
1230 gtk_paned_set_child_visible (paned, 1, TRUE);
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_child_allocate (priv->child1,
1243 priv->child1_window,
1247 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1249 gtk_paned_child_allocate (priv->child2,
1250 priv->child2_window,
1258 gtk_paned_create_child_window (GtkPaned *paned,
1259 GtkWidget *child) /* may be NULL */
1261 GtkWidget *widget = GTK_WIDGET (paned);
1262 GtkPanedPrivate *priv = paned->priv;
1264 GdkWindowAttr attributes;
1265 gint attributes_mask;
1267 attributes.window_type = GDK_WINDOW_CHILD;
1268 attributes.wclass = GDK_INPUT_OUTPUT;
1269 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1272 GtkAllocation allocation;
1275 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1277 gtk_widget_get_allocation (widget, &allocation);
1278 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1279 child == priv->child2)
1280 attributes.x = priv->handle_pos.x + handle_size;
1282 attributes.x = allocation.x;
1283 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1284 child == priv->child2)
1285 attributes.y = priv->handle_pos.y + handle_size;
1287 attributes.y = allocation.y;
1289 gtk_widget_get_allocation (child, &allocation);
1290 attributes.width = allocation.width;
1291 attributes.height = allocation.height;
1292 attributes_mask = GDK_WA_X | GDK_WA_Y;
1296 attributes.width = 1;
1297 attributes.height = 1;
1298 attributes_mask = 0;
1301 window = gdk_window_new (gtk_widget_get_window (widget),
1302 &attributes, attributes_mask);
1303 gdk_window_set_user_data (window, paned);
1304 gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
1307 gtk_widget_set_parent_window (child, window);
1313 gtk_paned_realize (GtkWidget *widget)
1315 GtkPaned *paned = GTK_PANED (widget);
1316 GtkPanedPrivate *priv = paned->priv;
1318 GdkWindowAttr attributes;
1319 gint attributes_mask;
1321 gtk_widget_set_realized (widget, TRUE);
1323 window = gtk_widget_get_parent_window (widget);
1324 gtk_widget_set_window (widget, window);
1325 g_object_ref (window);
1327 attributes.window_type = GDK_WINDOW_CHILD;
1328 attributes.wclass = GDK_INPUT_ONLY;
1329 attributes.x = priv->handle_pos.x;
1330 attributes.y = priv->handle_pos.y;
1331 attributes.width = priv->handle_pos.width;
1332 attributes.height = priv->handle_pos.height;
1333 attributes.event_mask = gtk_widget_get_events (widget);
1334 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1335 GDK_BUTTON_RELEASE_MASK |
1336 GDK_ENTER_NOTIFY_MASK |
1337 GDK_LEAVE_NOTIFY_MASK |
1338 GDK_POINTER_MOTION_MASK |
1339 GDK_POINTER_MOTION_HINT_MASK);
1340 attributes_mask = GDK_WA_X | GDK_WA_Y;
1341 if (gtk_widget_is_sensitive (widget))
1343 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1345 attributes_mask |= GDK_WA_CURSOR;
1348 priv->handle = gdk_window_new (window,
1349 &attributes, attributes_mask);
1350 gdk_window_set_user_data (priv->handle, paned);
1351 if (attributes_mask & GDK_WA_CURSOR)
1352 g_object_unref (attributes.cursor);
1354 priv->child1_window = gtk_paned_create_child_window (paned, priv->child1);
1355 priv->child2_window = gtk_paned_create_child_window (paned, priv->child2);
1359 gtk_paned_unrealize (GtkWidget *widget)
1361 GtkPaned *paned = GTK_PANED (widget);
1362 GtkPanedPrivate *priv = paned->priv;
1365 gtk_widget_set_parent_window (priv->child2, NULL);
1366 gdk_window_set_user_data (priv->child2_window, NULL);
1367 gdk_window_destroy (priv->child2_window);
1368 priv->child2_window = NULL;
1371 gtk_widget_set_parent_window (priv->child1, NULL);
1372 gdk_window_set_user_data (priv->child1_window, NULL);
1373 gdk_window_destroy (priv->child1_window);
1374 priv->child1_window = NULL;
1378 gdk_window_set_user_data (priv->handle, NULL);
1379 gdk_window_destroy (priv->handle);
1380 priv->handle = NULL;
1383 gtk_paned_set_last_child1_focus (paned, NULL);
1384 gtk_paned_set_last_child2_focus (paned, NULL);
1385 gtk_paned_set_saved_focus (paned, NULL);
1386 gtk_paned_set_first_paned (paned, NULL);
1388 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1392 gtk_paned_map (GtkWidget *widget)
1394 GtkPaned *paned = GTK_PANED (widget);
1395 GtkPanedPrivate *priv = paned->priv;
1397 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1398 priv->child2 && gtk_widget_get_visible (priv->child2))
1399 gdk_window_show (priv->handle);
1401 if (priv->child1 && gtk_widget_get_visible (priv->child1) && gtk_widget_get_child_visible (priv->child1))
1402 gdk_window_show (priv->child1_window);
1403 if (priv->child2 && gtk_widget_get_visible (priv->child2) && gtk_widget_get_child_visible (priv->child2))
1404 gdk_window_show (priv->child2_window);
1406 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1410 gtk_paned_unmap (GtkWidget *widget)
1412 GtkPaned *paned = GTK_PANED (widget);
1413 GtkPanedPrivate *priv = paned->priv;
1415 gdk_window_hide (priv->handle);
1417 if (gdk_window_is_visible (priv->child1_window))
1418 gdk_window_hide (priv->child1_window);
1419 if (gdk_window_is_visible (priv->child2_window))
1420 gdk_window_hide (priv->child2_window);
1422 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1426 gtk_paned_draw (GtkWidget *widget,
1429 GtkPaned *paned = GTK_PANED (widget);
1430 GtkPanedPrivate *priv = paned->priv;
1432 if (gtk_cairo_should_draw_window (cr, priv->child1_window))
1435 gtk_cairo_transform_to_window (cr, widget, priv->child1_window);
1436 gtk_render_background (gtk_widget_get_style_context (widget),
1439 gdk_window_get_width (priv->child1_window),
1440 gdk_window_get_height (priv->child1_window));
1444 if (gtk_cairo_should_draw_window (cr, priv->child2_window))
1447 gtk_cairo_transform_to_window (cr, widget, priv->child2_window);
1448 gtk_render_background (gtk_widget_get_style_context (widget),
1451 gdk_window_get_width (priv->child2_window),
1452 gdk_window_get_height (priv->child2_window));
1456 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)) &&
1457 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1458 priv->child2 && gtk_widget_get_visible (priv->child2))
1460 GtkStyleContext *context;
1461 GtkStateFlags state;
1462 GtkAllocation allocation;
1464 gtk_widget_get_allocation (widget, &allocation);
1465 context = gtk_widget_get_style_context (widget);
1466 state = gtk_widget_get_state_flags (widget);
1468 if (gtk_widget_is_focus (widget))
1469 state |= GTK_STATE_FLAG_SELECTED;
1470 if (priv->handle_prelit)
1471 state |= GTK_STATE_FLAG_PRELIGHT;
1473 gtk_style_context_save (context);
1474 gtk_style_context_set_state (context, state);
1475 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1476 gtk_render_handle (context, cr,
1477 priv->handle_pos.x - allocation.x,
1478 priv->handle_pos.y - allocation.y,
1479 priv->handle_pos.width,
1480 priv->handle_pos.height);
1482 gtk_style_context_restore (context);
1485 /* Chain up to draw children */
1486 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1492 is_rtl (GtkPaned *paned)
1494 GtkPanedPrivate *priv = paned->priv;
1496 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1497 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1506 update_drag (GtkPaned *paned)
1508 GtkPanedPrivate *priv = paned->priv;
1509 GtkAllocation allocation;
1510 GtkWidget *widget = GTK_WIDGET (paned);
1515 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1516 gtk_widget_get_pointer (widget, &pos, NULL);
1518 gtk_widget_get_pointer (widget, NULL, &pos);
1520 pos -= priv->drag_pos;
1524 gtk_widget_style_get (widget,
1525 "handle-size", &handle_size,
1528 gtk_widget_get_allocation (widget, &allocation);
1529 size = allocation.width - pos - handle_size;
1536 size = CLAMP (size, priv->min_position, priv->max_position);
1538 if (size != priv->child1_size)
1539 gtk_paned_set_position (paned, size);
1543 gtk_paned_enter (GtkWidget *widget,
1544 GdkEventCrossing *event)
1546 GtkPaned *paned = GTK_PANED (widget);
1547 GtkPanedPrivate *priv = paned->priv;
1550 update_drag (paned);
1553 priv->handle_prelit = TRUE;
1554 gtk_widget_queue_draw_area (widget,
1557 priv->handle_pos.width,
1558 priv->handle_pos.height);
1565 gtk_paned_leave (GtkWidget *widget,
1566 GdkEventCrossing *event)
1568 GtkPaned *paned = GTK_PANED (widget);
1569 GtkPanedPrivate *priv = paned->priv;
1572 update_drag (paned);
1575 priv->handle_prelit = FALSE;
1576 gtk_widget_queue_draw_area (widget,
1579 priv->handle_pos.width,
1580 priv->handle_pos.height);
1587 gtk_paned_focus (GtkWidget *widget,
1588 GtkDirectionType direction)
1593 /* This is a hack, but how can this be done without
1594 * excessive cut-and-paste from gtkcontainer.c?
1597 gtk_widget_set_can_focus (widget, FALSE);
1598 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1599 gtk_widget_set_can_focus (widget, TRUE);
1605 gtk_paned_button_press (GtkWidget *widget,
1606 GdkEventButton *event)
1608 GtkPaned *paned = GTK_PANED (widget);
1609 GtkPanedPrivate *priv = paned->priv;
1611 if (!priv->in_drag &&
1612 (event->window == priv->handle) && (event->button == 1))
1614 /* We need a server grab here, not gtk_grab_add(), since
1615 * we don't want to pass events on to the widget's children */
1616 if (gdk_device_grab (event->device,
1618 GDK_OWNERSHIP_WINDOW, FALSE,
1619 GDK_POINTER_MOTION_HINT_MASK
1620 | GDK_BUTTON1_MOTION_MASK
1621 | GDK_BUTTON_RELEASE_MASK
1622 | GDK_ENTER_NOTIFY_MASK
1623 | GDK_LEAVE_NOTIFY_MASK,
1624 NULL, event->time) != GDK_GRAB_SUCCESS)
1627 priv->in_drag = TRUE;
1628 priv->grab_time = event->time;
1629 priv->grab_device = event->device;
1631 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1632 priv->drag_pos = event->x;
1634 priv->drag_pos = event->y;
1643 gtk_paned_grab_broken (GtkWidget *widget,
1644 GdkEventGrabBroken *event)
1646 GtkPaned *paned = GTK_PANED (widget);
1647 GtkPanedPrivate *priv = paned->priv;
1649 priv->in_drag = FALSE;
1650 priv->drag_pos = -1;
1651 priv->position_set = TRUE;
1657 stop_drag (GtkPaned *paned)
1659 GtkPanedPrivate *priv = paned->priv;
1661 priv->in_drag = FALSE;
1662 priv->drag_pos = -1;
1663 priv->position_set = TRUE;
1665 gdk_device_ungrab (priv->grab_device,
1667 priv->grab_device = NULL;
1671 gtk_paned_grab_notify (GtkWidget *widget,
1672 gboolean was_grabbed)
1674 GtkPaned *paned = GTK_PANED (widget);
1675 GtkPanedPrivate *priv = paned->priv;
1676 GdkDevice *grab_device;
1678 grab_device = priv->grab_device;
1680 if (priv->in_drag && grab_device &&
1681 gtk_widget_device_is_shadowed (widget, grab_device))
1686 gtk_paned_state_flags_changed (GtkWidget *widget,
1687 GtkStateFlags previous_state)
1689 GtkPaned *paned = GTK_PANED (widget);
1690 GtkPanedPrivate *priv = paned->priv;
1693 if (gtk_widget_get_realized (widget))
1695 if (gtk_widget_is_sensitive (widget))
1696 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1701 gdk_window_set_cursor (priv->handle, cursor);
1704 g_object_unref (cursor);
1709 gtk_paned_button_release (GtkWidget *widget,
1710 GdkEventButton *event)
1712 GtkPaned *paned = GTK_PANED (widget);
1713 GtkPanedPrivate *priv = paned->priv;
1715 if (priv->in_drag && (event->button == 1))
1726 gtk_paned_motion (GtkWidget *widget,
1727 GdkEventMotion *event)
1729 GtkPaned *paned = GTK_PANED (widget);
1730 GtkPanedPrivate *priv = paned->priv;
1734 update_drag (paned);
1743 * @orientation: the paned's orientation.
1745 * Creates a new #GtkPaned widget.
1747 * Return value: a new #GtkPaned.
1752 gtk_paned_new (GtkOrientation orientation)
1754 return g_object_new (GTK_TYPE_PANED,
1755 "orientation", orientation,
1761 * @paned: a paned widget
1762 * @child: the child to add
1764 * Adds a child to the top or left pane with default parameters. This is
1766 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1769 gtk_paned_add1 (GtkPaned *paned,
1772 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1777 * @paned: a paned widget
1778 * @child: the child to add
1780 * Adds a child to the bottom or right pane with default parameters. This
1782 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1785 gtk_paned_add2 (GtkPaned *paned,
1788 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1793 * @paned: a paned widget
1794 * @child: the child to add
1795 * @resize: should this child expand when the paned widget is resized.
1796 * @shrink: can this child be made smaller than its requisition.
1798 * Adds a child to the top or left pane.
1801 gtk_paned_pack1 (GtkPaned *paned,
1806 GtkPanedPrivate *priv;
1808 g_return_if_fail (GTK_IS_PANED (paned));
1809 g_return_if_fail (GTK_IS_WIDGET (child));
1815 priv->child1 = child;
1816 priv->child1_resize = resize;
1817 priv->child1_shrink = shrink;
1819 gtk_widget_set_parent_window (child, priv->child1_window);
1820 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1826 * @paned: a paned widget
1827 * @child: the child to add
1828 * @resize: should this child expand when the paned widget is resized.
1829 * @shrink: can this child be made smaller than its requisition.
1831 * Adds a child to the bottom or right pane.
1834 gtk_paned_pack2 (GtkPaned *paned,
1839 GtkPanedPrivate *priv;
1841 g_return_if_fail (GTK_IS_PANED (paned));
1842 g_return_if_fail (GTK_IS_WIDGET (child));
1848 priv->child2 = child;
1849 priv->child2_resize = resize;
1850 priv->child2_shrink = shrink;
1852 gtk_widget_set_parent_window (child, priv->child2_window);
1853 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1859 gtk_paned_add (GtkContainer *container,
1862 GtkPanedPrivate *priv;
1865 g_return_if_fail (GTK_IS_PANED (container));
1867 paned = GTK_PANED (container);
1871 gtk_paned_add1 (paned, widget);
1872 else if (!priv->child2)
1873 gtk_paned_add2 (paned, widget);
1875 g_warning ("GtkPaned cannot have more than 2 children\n");
1879 gtk_paned_remove (GtkContainer *container,
1882 GtkPaned *paned = GTK_PANED (container);
1883 GtkPanedPrivate *priv = paned->priv;
1884 gboolean was_visible;
1886 was_visible = gtk_widget_get_visible (widget);
1888 if (priv->child1 == widget)
1890 if (priv->child1_window && gdk_window_is_visible (priv->child1_window))
1891 gdk_window_hide (priv->child1_window);
1893 gtk_widget_unparent (widget);
1895 priv->child1 = NULL;
1897 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1898 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1900 else if (priv->child2 == widget)
1902 if (priv->child2_window && gdk_window_is_visible (priv->child2_window))
1903 gdk_window_hide (priv->child2_window);
1905 gtk_widget_unparent (widget);
1907 priv->child2 = NULL;
1909 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1910 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1915 gtk_paned_forall (GtkContainer *container,
1916 gboolean include_internals,
1917 GtkCallback callback,
1918 gpointer callback_data)
1920 GtkPanedPrivate *priv;
1923 g_return_if_fail (callback != NULL);
1925 paned = GTK_PANED (container);
1929 (*callback) (priv->child1, callback_data);
1931 (*callback) (priv->child2, callback_data);
1935 * gtk_paned_get_position:
1936 * @paned: a #GtkPaned widget
1938 * Obtains the position of the divider between the two panes.
1940 * Return value: position of the divider
1943 gtk_paned_get_position (GtkPaned *paned)
1945 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1947 return paned->priv->child1_size;
1951 * gtk_paned_set_position:
1952 * @paned: a #GtkPaned widget
1953 * @position: pixel position of divider, a negative value means that the position
1956 * Sets the position of the divider between the two panes.
1959 gtk_paned_set_position (GtkPaned *paned,
1962 GtkPanedPrivate *priv;
1965 g_return_if_fail (GTK_IS_PANED (paned));
1969 if (priv->child1_size == position)
1972 object = G_OBJECT (paned);
1976 /* We don't clamp here - the assumption is that
1977 * if the total allocation changes at the same time
1978 * as the position, the position set is with reference
1979 * to the new total size. If only the position changes,
1980 * then clamping will occur in gtk_paned_calc_position()
1983 priv->child1_size = position;
1984 priv->position_set = TRUE;
1988 priv->position_set = FALSE;
1991 g_object_freeze_notify (object);
1992 g_object_notify (object, "position");
1993 g_object_notify (object, "position-set");
1994 g_object_thaw_notify (object);
1996 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1999 /* Hacky work-around for bug #144269 */
2000 if (priv->child2 != NULL)
2002 gtk_widget_queue_draw (priv->child2);
2008 * gtk_paned_get_child1:
2009 * @paned: a #GtkPaned widget
2011 * Obtains the first child of the paned widget.
2013 * Return value: (transfer none): first child, or %NULL if it is not set.
2018 gtk_paned_get_child1 (GtkPaned *paned)
2020 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2022 return paned->priv->child1;
2026 * gtk_paned_get_child2:
2027 * @paned: a #GtkPaned widget
2029 * Obtains the second child of the paned widget.
2031 * Return value: (transfer none): second child, or %NULL if it is not set.
2036 gtk_paned_get_child2 (GtkPaned *paned)
2038 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2040 return paned->priv->child2;
2044 gtk_paned_calc_position (GtkPaned *paned,
2049 GtkPanedPrivate *priv = paned->priv;
2051 gint old_min_position;
2052 gint old_max_position;
2054 old_position = priv->child1_size;
2055 old_min_position = priv->min_position;
2056 old_max_position = priv->max_position;
2058 priv->min_position = priv->child1_shrink ? 0 : child1_req;
2060 priv->max_position = allocation;
2061 if (!priv->child2_shrink)
2062 priv->max_position = MAX (1, priv->max_position - child2_req);
2063 priv->max_position = MAX (priv->min_position, priv->max_position);
2065 if (!priv->position_set)
2067 if (priv->child1_resize && !priv->child2_resize)
2068 priv->child1_size = MAX (0, allocation - child2_req);
2069 else if (!priv->child1_resize && priv->child2_resize)
2070 priv->child1_size = child1_req;
2071 else if (child1_req + child2_req != 0)
2072 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
2074 priv->child1_size = allocation * 0.5 + 0.5;
2078 /* If the position was set before the initial allocation.
2079 * (priv->last_allocation <= 0) just clamp it and leave it.
2081 if (priv->last_allocation > 0)
2083 if (priv->child1_resize && !priv->child2_resize)
2084 priv->child1_size += allocation - priv->last_allocation;
2085 else if (!(!priv->child1_resize && priv->child2_resize))
2086 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
2090 priv->child1_size = CLAMP (priv->child1_size,
2092 priv->max_position);
2095 gtk_paned_set_child_visible (paned, 0, priv->child1_size != 0);
2098 gtk_paned_set_child_visible (paned, 1, priv->child1_size != allocation);
2100 g_object_freeze_notify (G_OBJECT (paned));
2101 if (priv->child1_size != old_position)
2102 g_object_notify (G_OBJECT (paned), "position");
2103 if (priv->min_position != old_min_position)
2104 g_object_notify (G_OBJECT (paned), "min-position");
2105 if (priv->max_position != old_max_position)
2106 g_object_notify (G_OBJECT (paned), "max-position");
2107 g_object_thaw_notify (G_OBJECT (paned));
2109 priv->last_allocation = allocation;
2113 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
2115 GtkPanedPrivate *priv = paned->priv;
2117 if (priv->saved_focus)
2118 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
2119 (gpointer *)&(priv->saved_focus));
2121 priv->saved_focus = widget;
2123 if (priv->saved_focus)
2124 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
2125 (gpointer *)&(priv->saved_focus));
2129 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
2131 GtkPanedPrivate *priv = paned->priv;
2133 if (priv->first_paned)
2134 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
2135 (gpointer *)&(priv->first_paned));
2137 priv->first_paned = first_paned;
2139 if (priv->first_paned)
2140 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
2141 (gpointer *)&(priv->first_paned));
2145 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
2147 GtkPanedPrivate *priv = paned->priv;
2149 if (priv->last_child1_focus)
2150 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
2151 (gpointer *)&(priv->last_child1_focus));
2153 priv->last_child1_focus = widget;
2155 if (priv->last_child1_focus)
2156 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
2157 (gpointer *)&(priv->last_child1_focus));
2161 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
2163 GtkPanedPrivate *priv = paned->priv;
2165 if (priv->last_child2_focus)
2166 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
2167 (gpointer *)&(priv->last_child2_focus));
2169 priv->last_child2_focus = widget;
2171 if (priv->last_child2_focus)
2172 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
2173 (gpointer *)&(priv->last_child2_focus));
2177 paned_get_focus_widget (GtkPaned *paned)
2179 GtkWidget *toplevel;
2181 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2182 if (gtk_widget_is_toplevel (toplevel))
2183 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2189 gtk_paned_set_focus_child (GtkContainer *container,
2190 GtkWidget *focus_child)
2193 GtkPanedPrivate *priv;
2194 GtkWidget *container_focus_child;
2196 g_return_if_fail (GTK_IS_PANED (container));
2198 paned = GTK_PANED (container);
2201 if (focus_child == NULL)
2203 GtkWidget *last_focus;
2206 last_focus = paned_get_focus_widget (paned);
2210 /* If there is one or more paned widgets between us and the
2211 * focus widget, we want the topmost of those as last_focus
2213 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
2214 if (GTK_IS_PANED (w))
2217 container_focus_child = gtk_container_get_focus_child (container);
2218 if (container_focus_child == priv->child1)
2219 gtk_paned_set_last_child1_focus (paned, last_focus);
2220 else if (container_focus_child == priv->child2)
2221 gtk_paned_set_last_child2_focus (paned, last_focus);
2225 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2226 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2230 gtk_paned_get_cycle_chain (GtkPaned *paned,
2231 GtkDirectionType direction,
2234 GtkPanedPrivate *priv = paned->priv;
2235 GtkContainer *container = GTK_CONTAINER (paned);
2236 GtkWidget *ancestor = NULL;
2237 GtkWidget *focus_child;
2239 GtkWidget *widget = GTK_WIDGET (paned);
2240 GList *temp_list = NULL;
2243 if (priv->in_recursion)
2246 g_assert (widgets != NULL);
2248 if (priv->last_child1_focus &&
2249 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2251 gtk_paned_set_last_child1_focus (paned, NULL);
2254 if (priv->last_child2_focus &&
2255 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2257 gtk_paned_set_last_child2_focus (paned, NULL);
2260 parent = gtk_widget_get_parent (widget);
2262 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2264 /* The idea here is that temp_list is a list of widgets we want to cycle
2265 * to. The list is prioritized so that the first element is our first
2266 * choice, the next our second, and so on.
2268 * We can't just use g_list_reverse(), because we want to try
2269 * priv->last_child?_focus before priv->child?, both when we
2270 * are going forward and backward.
2272 focus_child = gtk_container_get_focus_child (container);
2273 if (direction == GTK_DIR_TAB_FORWARD)
2275 if (focus_child == priv->child1)
2277 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2278 temp_list = g_list_append (temp_list, priv->child2);
2279 temp_list = g_list_append (temp_list, ancestor);
2281 else if (focus_child == priv->child2)
2283 temp_list = g_list_append (temp_list, ancestor);
2284 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2285 temp_list = g_list_append (temp_list, priv->child1);
2289 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2290 temp_list = g_list_append (temp_list, priv->child1);
2291 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2292 temp_list = g_list_append (temp_list, priv->child2);
2293 temp_list = g_list_append (temp_list, ancestor);
2298 if (focus_child == priv->child1)
2300 temp_list = g_list_append (temp_list, ancestor);
2301 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2302 temp_list = g_list_append (temp_list, priv->child2);
2304 else if (focus_child == priv->child2)
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, ancestor);
2312 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2313 temp_list = g_list_append (temp_list, priv->child2);
2314 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2315 temp_list = g_list_append (temp_list, priv->child1);
2316 temp_list = g_list_append (temp_list, ancestor);
2320 /* Walk the list and expand all the paned widgets. */
2321 for (list = temp_list; list != NULL; list = list->next)
2323 GtkWidget *widget = list->data;
2327 if (GTK_IS_PANED (widget))
2329 priv->in_recursion = TRUE;
2330 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2331 priv->in_recursion = FALSE;
2335 *widgets = g_list_append (*widgets, widget);
2340 g_list_free (temp_list);
2344 gtk_paned_cycle_child_focus (GtkPaned *paned,
2347 GList *cycle_chain = NULL;
2350 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2352 /* ignore f6 if the handle is focused */
2353 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2356 /* we can't just let the event propagate up the hierarchy,
2357 * because the paned will want to cycle focus _unless_ an
2358 * ancestor paned handles the event
2360 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2362 for (list = cycle_chain; list != NULL; list = list->next)
2363 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2366 g_list_free (cycle_chain);
2372 get_child_panes (GtkWidget *widget,
2375 if (!widget || !gtk_widget_get_realized (widget))
2378 if (GTK_IS_PANED (widget))
2380 GtkPaned *paned = GTK_PANED (widget);
2381 GtkPanedPrivate *priv = paned->priv;
2383 get_child_panes (priv->child1, panes);
2384 *panes = g_list_prepend (*panes, widget);
2385 get_child_panes (priv->child2, panes);
2387 else if (GTK_IS_CONTAINER (widget))
2389 gtk_container_forall (GTK_CONTAINER (widget),
2390 (GtkCallback)get_child_panes, panes);
2395 get_all_panes (GtkPaned *paned)
2397 GtkPaned *topmost = NULL;
2398 GList *result = NULL;
2401 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2403 if (GTK_IS_PANED (w))
2404 topmost = GTK_PANED (w);
2409 get_child_panes (GTK_WIDGET (topmost), &result);
2411 return g_list_reverse (result);
2415 gtk_paned_find_neighbours (GtkPaned *paned,
2422 all_panes = get_all_panes (paned);
2423 g_assert (all_panes);
2425 this_link = g_list_find (all_panes, paned);
2427 g_assert (this_link);
2429 if (this_link->next)
2430 *next = this_link->next->data;
2432 *next = all_panes->data;
2434 if (this_link->prev)
2435 *prev = this_link->prev->data;
2437 *prev = g_list_last (all_panes)->data;
2439 g_list_free (all_panes);
2443 gtk_paned_move_handle (GtkPaned *paned,
2444 GtkScrollType scroll)
2446 GtkPanedPrivate *priv = paned->priv;
2448 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2455 SINGLE_STEP_SIZE = 1,
2459 new_position = old_position = gtk_paned_get_position (paned);
2464 case GTK_SCROLL_STEP_LEFT:
2465 case GTK_SCROLL_STEP_UP:
2466 case GTK_SCROLL_STEP_BACKWARD:
2467 increment = - SINGLE_STEP_SIZE;
2470 case GTK_SCROLL_STEP_RIGHT:
2471 case GTK_SCROLL_STEP_DOWN:
2472 case GTK_SCROLL_STEP_FORWARD:
2473 increment = SINGLE_STEP_SIZE;
2476 case GTK_SCROLL_PAGE_LEFT:
2477 case GTK_SCROLL_PAGE_UP:
2478 case GTK_SCROLL_PAGE_BACKWARD:
2479 increment = - PAGE_STEP_SIZE;
2482 case GTK_SCROLL_PAGE_RIGHT:
2483 case GTK_SCROLL_PAGE_DOWN:
2484 case GTK_SCROLL_PAGE_FORWARD:
2485 increment = PAGE_STEP_SIZE;
2488 case GTK_SCROLL_START:
2489 new_position = priv->min_position;
2492 case GTK_SCROLL_END:
2493 new_position = priv->max_position;
2503 increment = -increment;
2505 new_position = old_position + increment;
2508 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2510 if (old_position != new_position)
2511 gtk_paned_set_position (paned, new_position);
2520 gtk_paned_restore_focus (GtkPaned *paned)
2522 GtkPanedPrivate *priv = paned->priv;
2524 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2526 if (priv->saved_focus &&
2527 gtk_widget_get_sensitive (priv->saved_focus))
2529 gtk_widget_grab_focus (priv->saved_focus);
2533 /* the saved focus is somehow not available for focusing,
2535 * 1) tabbing into the paned widget
2536 * if that didn't work,
2537 * 2) unset focus for the window if there is one
2540 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2542 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2544 if (GTK_IS_WINDOW (toplevel))
2545 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2549 gtk_paned_set_saved_focus (paned, NULL);
2550 gtk_paned_set_first_paned (paned, NULL);
2555 gtk_paned_accept_position (GtkPaned *paned)
2557 GtkPanedPrivate *priv = paned->priv;
2559 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2561 priv->original_position = -1;
2562 gtk_paned_restore_focus (paned);
2572 gtk_paned_cancel_position (GtkPaned *paned)
2574 GtkPanedPrivate *priv = paned->priv;
2576 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2578 if (priv->original_position != -1)
2580 gtk_paned_set_position (paned, priv->original_position);
2581 priv->original_position = -1;
2584 gtk_paned_restore_focus (paned);
2592 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2595 GtkPanedPrivate *priv = paned->priv;
2596 GtkPaned *next, *prev;
2598 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2600 GtkPaned *focus = NULL;
2602 if (!priv->first_paned)
2604 /* The first_pane has disappeared. As an ad-hoc solution,
2605 * we make the currently focused paned the first_paned. To the
2606 * user this will seem like the paned cycling has been reset.
2609 gtk_paned_set_first_paned (paned, paned);
2612 gtk_paned_find_neighbours (paned, &next, &prev);
2614 if (reversed && prev &&
2615 prev != paned && paned != priv->first_paned)
2619 else if (!reversed && next &&
2620 next != paned && next != priv->first_paned)
2626 gtk_paned_accept_position (paned);
2632 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2633 gtk_paned_set_first_paned (focus, priv->first_paned);
2635 gtk_paned_set_saved_focus (paned, NULL);
2636 gtk_paned_set_first_paned (paned, NULL);
2638 gtk_widget_grab_focus (GTK_WIDGET (focus));
2640 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2642 priv->original_position = -1;
2643 focus->priv->original_position = gtk_paned_get_position (focus);
2648 GtkContainer *container = GTK_CONTAINER (paned);
2651 GtkPaned *prev, *next;
2652 GtkWidget *toplevel;
2653 GtkWidget *focus_child;
2655 gtk_paned_find_neighbours (paned, &next, &prev);
2656 focus_child = gtk_container_get_focus_child (container);
2658 if (focus_child == priv->child1)
2671 else if (focus_child == priv->child2)
2686 /* Focus is not inside this paned, and we don't have focus.
2687 * Presumably this happened because the application wants us
2688 * to start keyboard navigating.
2698 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2700 if (GTK_IS_WINDOW (toplevel))
2701 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2702 gtk_paned_set_first_paned (focus, first);
2703 focus->priv->original_position = gtk_paned_get_position (focus);
2705 gtk_widget_grab_focus (GTK_WIDGET (focus));
2712 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2714 /* This function/signal has the wrong name. It is called when you
2715 * press Tab or Shift-Tab and what we do is act as if
2716 * the user pressed Return and then Tab or Shift-Tab
2718 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2719 gtk_paned_accept_position (paned);
2725 * gtk_paned_get_handle_window:
2726 * @paned: a #GtkPaned
2728 * Returns the #GdkWindow of the handle. This function is
2729 * useful when handling button or motion events because it
2730 * enables the callback to distinguish between the window
2731 * of the paned, a child and the handle.
2733 * Return value: (transfer none): the paned's handle window.
2738 gtk_paned_get_handle_window (GtkPaned *paned)
2740 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2742 return paned->priv->handle;