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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkbindings.h"
31 #include "gtkmarshalers.h"
32 #include "gtkorientable.h"
33 #include "gtkwindow.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkprivate.h"
37 #include "a11y/gtkpanedaccessible.h"
41 * @Short_description: A widget with two adjustable panes
44 * #GtkPaned has two panes, arranged either
45 * horizontally or vertically. The division between
46 * the two panes is adjustable by the user by dragging
50 * added to the panes of the widget with gtk_paned_pack1() and
51 * gtk_paned_pack2(). The division between the two children is set by default
52 * from the size requests of the children, but it can be adjusted by the
55 * A paned widget draws a separator between the two child widgets and a
56 * small handle that the user can drag to adjust the division. It does not
57 * draw any relief around the children or around the separator. (The space
58 * in which the separator is called the gutter.) Often, it is useful to put
59 * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
60 * so that the gutter appears as a ridge. No separator is drawn if one of
61 * the children is missing.
63 * Each child has two options that can be set, @resize and @shrink. If
64 * @resize is true, then when the #GtkPaned is resized, that child will
65 * expand or shrink along with the paned widget. If @shrink is true, then
66 * that child can be made smaller than its requisition by the user.
67 * Setting @shrink to %FALSE allows the application to set a minimum size.
68 * If @resize is false for both children, then this is treated as if
69 * @resize is true for both children.
71 * The application can set the position of the slider as if it were set
72 * by the user, by calling gtk_paned_set_position().
75 * <title>Creating a paned widget with minimum sizes.</title>
77 * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
78 * GtkWidget *frame1 = gtk_frame_new (NULL);
79 * GtkWidget *frame2 = gtk_frame_new (NULL);
80 * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
81 * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
83 * gtk_widget_set_size_request (hpaned, 200, -1);
85 * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
86 * gtk_widget_set_size_request (frame1, 50, -1);
88 * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
89 * gtk_widget_set_size_request (frame2, 50, -1);
99 struct _GtkPanedPrivate
101 GtkPaned *first_paned;
104 GdkWindow *child1_window;
105 GdkWindow *child2_window;
106 GtkWidget *last_child1_focus;
107 GtkWidget *last_child2_focus;
108 GtkWidget *saved_focus;
109 GtkOrientation orientation;
111 GdkCursorType cursor_type;
112 GdkDevice *grab_device;
113 GdkRectangle handle_pos;
118 gint last_allocation;
121 gint original_position;
125 guint handle_prelit : 1;
127 guint in_recursion : 1;
128 guint child1_resize : 1;
129 guint child1_shrink : 1;
130 guint child2_resize : 1;
131 guint child2_shrink : 1;
132 guint position_set : 1;
160 static void gtk_paned_set_property (GObject *object,
164 static void gtk_paned_get_property (GObject *object,
168 static void gtk_paned_set_child_property (GtkContainer *container,
173 static void gtk_paned_get_child_property (GtkContainer *container,
178 static void gtk_paned_finalize (GObject *object);
180 static void gtk_paned_get_preferred_width (GtkWidget *widget,
183 static void gtk_paned_get_preferred_height (GtkWidget *widget,
186 static void gtk_paned_get_preferred_width_for_height
191 static void gtk_paned_get_preferred_height_for_width
197 static void gtk_paned_size_allocate (GtkWidget *widget,
198 GtkAllocation *allocation);
199 static void gtk_paned_realize (GtkWidget *widget);
200 static void gtk_paned_unrealize (GtkWidget *widget);
201 static void gtk_paned_map (GtkWidget *widget);
202 static void gtk_paned_unmap (GtkWidget *widget);
203 static void gtk_paned_state_flags_changed (GtkWidget *widget,
204 GtkStateFlags previous_state);
205 static gboolean gtk_paned_draw (GtkWidget *widget,
207 static gboolean gtk_paned_enter (GtkWidget *widget,
208 GdkEventCrossing *event);
209 static gboolean gtk_paned_leave (GtkWidget *widget,
210 GdkEventCrossing *event);
211 static gboolean gtk_paned_button_press (GtkWidget *widget,
212 GdkEventButton *event);
213 static gboolean gtk_paned_button_release (GtkWidget *widget,
214 GdkEventButton *event);
215 static gboolean gtk_paned_motion (GtkWidget *widget,
216 GdkEventMotion *event);
217 static gboolean gtk_paned_focus (GtkWidget *widget,
218 GtkDirectionType direction);
219 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
220 GdkEventGrabBroken *event);
221 static void gtk_paned_add (GtkContainer *container,
223 static void gtk_paned_remove (GtkContainer *container,
225 static void gtk_paned_forall (GtkContainer *container,
226 gboolean include_internals,
227 GtkCallback callback,
228 gpointer callback_data);
229 static void gtk_paned_calc_position (GtkPaned *paned,
233 static void gtk_paned_set_focus_child (GtkContainer *container,
235 static void gtk_paned_set_saved_focus (GtkPaned *paned,
237 static void gtk_paned_set_first_paned (GtkPaned *paned,
238 GtkPaned *first_paned);
239 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
241 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
243 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
245 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
247 static gboolean gtk_paned_move_handle (GtkPaned *paned,
248 GtkScrollType scroll);
249 static gboolean gtk_paned_accept_position (GtkPaned *paned);
250 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
251 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
253 static GType gtk_paned_child_type (GtkContainer *container);
254 static void gtk_paned_grab_notify (GtkWidget *widget,
255 gboolean was_grabbed);
258 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
259 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
262 static guint signals[LAST_SIGNAL] = { 0 };
266 add_tab_bindings (GtkBindingSet *binding_set,
267 GdkModifierType modifiers)
269 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
270 "toggle-handle-focus", 0);
271 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
272 "toggle-handle-focus", 0);
276 add_move_binding (GtkBindingSet *binding_set,
278 GdkModifierType mask,
279 GtkScrollType scroll)
281 gtk_binding_entry_add_signal (binding_set, keyval, mask,
283 GTK_TYPE_SCROLL_TYPE, scroll);
287 gtk_paned_class_init (GtkPanedClass *class)
289 GObjectClass *object_class;
290 GtkWidgetClass *widget_class;
291 GtkContainerClass *container_class;
292 GtkPanedClass *paned_class;
293 GtkBindingSet *binding_set;
295 object_class = (GObjectClass *) class;
296 widget_class = (GtkWidgetClass *) class;
297 container_class = (GtkContainerClass *) class;
298 paned_class = (GtkPanedClass *) class;
300 object_class->set_property = gtk_paned_set_property;
301 object_class->get_property = gtk_paned_get_property;
302 object_class->finalize = gtk_paned_finalize;
304 widget_class->get_preferred_width = gtk_paned_get_preferred_width;
305 widget_class->get_preferred_height = gtk_paned_get_preferred_height;
306 widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
307 widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
308 widget_class->size_allocate = gtk_paned_size_allocate;
309 widget_class->realize = gtk_paned_realize;
310 widget_class->unrealize = gtk_paned_unrealize;
311 widget_class->map = gtk_paned_map;
312 widget_class->unmap = gtk_paned_unmap;
313 widget_class->draw = gtk_paned_draw;
314 widget_class->focus = gtk_paned_focus;
315 widget_class->enter_notify_event = gtk_paned_enter;
316 widget_class->leave_notify_event = gtk_paned_leave;
317 widget_class->button_press_event = gtk_paned_button_press;
318 widget_class->button_release_event = gtk_paned_button_release;
319 widget_class->motion_notify_event = gtk_paned_motion;
320 widget_class->grab_broken_event = gtk_paned_grab_broken;
321 widget_class->grab_notify = gtk_paned_grab_notify;
322 widget_class->state_flags_changed = gtk_paned_state_flags_changed;
324 container_class->add = gtk_paned_add;
325 container_class->remove = gtk_paned_remove;
326 container_class->forall = gtk_paned_forall;
327 container_class->child_type = gtk_paned_child_type;
328 container_class->set_focus_child = gtk_paned_set_focus_child;
329 container_class->set_child_property = gtk_paned_set_child_property;
330 container_class->get_child_property = gtk_paned_get_child_property;
331 gtk_container_class_handle_border_width (container_class);
333 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
334 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
335 paned_class->move_handle = gtk_paned_move_handle;
336 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
337 paned_class->accept_position = gtk_paned_accept_position;
338 paned_class->cancel_position = gtk_paned_cancel_position;
340 g_object_class_override_property (object_class,
344 g_object_class_install_property (object_class,
346 g_param_spec_int ("position",
348 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
352 GTK_PARAM_READWRITE));
354 g_object_class_install_property (object_class,
356 g_param_spec_boolean ("position-set",
358 P_("TRUE if the Position property should be used"),
360 GTK_PARAM_READWRITE));
362 gtk_widget_class_install_style_property (widget_class,
363 g_param_spec_int ("handle-size",
365 P_("Width of handle"),
369 GTK_PARAM_READABLE));
371 * GtkPaned:min-position:
373 * The smallest possible value for the position property. This property is derived from the
374 * size and shrinkability of the widget's children.
378 g_object_class_install_property (object_class,
380 g_param_spec_int ("min-position",
381 P_("Minimal Position"),
382 P_("Smallest possible value for the \"position\" property"),
386 GTK_PARAM_READABLE));
389 * GtkPaned:max-position:
391 * The largest possible value for the position property. This property is derived from the
392 * size and shrinkability of the widget's children.
396 g_object_class_install_property (object_class,
398 g_param_spec_int ("max-position",
399 P_("Maximal Position"),
400 P_("Largest possible value for the \"position\" property"),
404 GTK_PARAM_READABLE));
409 * The "resize" child property determines whether the child expands and
410 * shrinks along with the paned widget.
414 gtk_container_class_install_child_property (container_class,
416 g_param_spec_boolean ("resize",
418 P_("If TRUE, the child expands and shrinks along with the paned widget"),
420 GTK_PARAM_READWRITE));
425 * The "shrink" child property determines whether the child can be made
426 * smaller than its requisition.
430 gtk_container_class_install_child_property (container_class,
432 g_param_spec_boolean ("shrink",
434 P_("If TRUE, the child can be made smaller than its requisition"),
436 GTK_PARAM_READWRITE));
439 * GtkPaned::cycle-child-focus:
440 * @widget: the object that received the signal
441 * @reversed: whether cycling backward or forward
443 * The ::cycle-child-focus signal is a
444 * <link linkend="keybinding-signals">keybinding signal</link>
445 * which gets emitted to cycle the focus between the children of the paned.
447 * The default binding is f6.
451 signals [CYCLE_CHILD_FOCUS] =
452 g_signal_new (I_("cycle-child-focus"),
453 G_TYPE_FROM_CLASS (object_class),
454 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
455 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
457 _gtk_marshal_BOOLEAN__BOOLEAN,
462 * GtkPaned::toggle-handle-focus:
463 * @widget: the object that received the signal
465 * The ::toggle-handle-focus is a
466 * <link linkend="keybinding-signals">keybinding signal</link>
467 * which gets emitted to accept the current position of the handle and then
468 * move focus to the next widget in the focus chain.
470 * The default binding is Tab.
474 signals [TOGGLE_HANDLE_FOCUS] =
475 g_signal_new (I_("toggle-handle-focus"),
476 G_TYPE_FROM_CLASS (object_class),
477 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
478 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
480 _gtk_marshal_BOOLEAN__VOID,
484 * GtkPaned::move-handle:
485 * @widget: the object that received the signal
486 * @scroll_type: a #GtkScrollType
488 * The ::move-handle signal is a
489 * <link linkend="keybinding-signals">keybinding signal</link>
490 * which gets emitted to move the handle when the user is using key bindings
495 signals[MOVE_HANDLE] =
496 g_signal_new (I_("move-handle"),
497 G_TYPE_FROM_CLASS (object_class),
498 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
499 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
501 _gtk_marshal_BOOLEAN__ENUM,
503 GTK_TYPE_SCROLL_TYPE);
506 * GtkPaned::cycle-handle-focus:
507 * @widget: the object that received the signal
508 * @reversed: whether cycling backward or forward
510 * The ::cycle-handle-focus signal is a
511 * <link linkend="keybinding-signals">keybinding signal</link>
512 * which gets emitted to cycle whether the paned should grab focus to allow
513 * the user to change position of the handle by using key bindings.
515 * The default binding for this signal is f8.
519 signals [CYCLE_HANDLE_FOCUS] =
520 g_signal_new (I_("cycle-handle-focus"),
521 G_TYPE_FROM_CLASS (object_class),
522 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
523 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
525 _gtk_marshal_BOOLEAN__BOOLEAN,
530 * GtkPaned::accept-position:
531 * @widget: the object that received the signal
533 * The ::accept-position signal is a
534 * <link linkend="keybinding-signals">keybinding signal</link>
535 * which gets emitted to accept the current position of the handle when
536 * moving it using key bindings.
538 * The default binding for this signal is Return or Space.
542 signals [ACCEPT_POSITION] =
543 g_signal_new (I_("accept-position"),
544 G_TYPE_FROM_CLASS (object_class),
545 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
546 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
548 _gtk_marshal_BOOLEAN__VOID,
552 * GtkPaned::cancel-position:
553 * @widget: the object that received the signal
555 * The ::cancel-position signal is a
556 * <link linkend="keybinding-signals">keybinding signal</link>
557 * which gets emitted to cancel moving the position of the handle using key
558 * bindings. The position of the handle will be reset to the value prior to
561 * The default binding for this signal is Escape.
565 signals [CANCEL_POSITION] =
566 g_signal_new (I_("cancel-position"),
567 G_TYPE_FROM_CLASS (object_class),
568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
569 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
571 _gtk_marshal_BOOLEAN__VOID,
574 binding_set = gtk_binding_set_by_class (class);
577 gtk_binding_entry_add_signal (binding_set,
579 "cycle-child-focus", 1,
580 G_TYPE_BOOLEAN, FALSE);
581 gtk_binding_entry_add_signal (binding_set,
582 GDK_KEY_F6, GDK_SHIFT_MASK,
583 "cycle-child-focus", 1,
584 G_TYPE_BOOLEAN, TRUE);
587 gtk_binding_entry_add_signal (binding_set,
589 "cycle-handle-focus", 1,
590 G_TYPE_BOOLEAN, FALSE);
592 gtk_binding_entry_add_signal (binding_set,
593 GDK_KEY_F8, GDK_SHIFT_MASK,
594 "cycle-handle-focus", 1,
595 G_TYPE_BOOLEAN, TRUE);
597 add_tab_bindings (binding_set, 0);
598 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
599 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
600 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
602 /* accept and cancel positions */
603 gtk_binding_entry_add_signal (binding_set,
605 "cancel-position", 0);
607 gtk_binding_entry_add_signal (binding_set,
609 "accept-position", 0);
610 gtk_binding_entry_add_signal (binding_set,
611 GDK_KEY_ISO_Enter, 0,
612 "accept-position", 0);
613 gtk_binding_entry_add_signal (binding_set,
615 "accept-position", 0);
616 gtk_binding_entry_add_signal (binding_set,
618 "accept-position", 0);
619 gtk_binding_entry_add_signal (binding_set,
621 "accept-position", 0);
624 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
625 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
626 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
627 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
629 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
630 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
631 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
632 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
634 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
635 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
636 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
637 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
638 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
639 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
641 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
642 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
643 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
644 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
645 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
646 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
648 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
649 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
650 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
651 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
653 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
654 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PANED_ACCESSIBLE);
658 gtk_paned_child_type (GtkContainer *container)
660 GtkPaned *paned = GTK_PANED (container);
661 GtkPanedPrivate *priv = paned->priv;
663 if (!priv->child1 || !priv->child2)
664 return GTK_TYPE_WIDGET;
670 gtk_paned_init (GtkPaned *paned)
672 GtkPanedPrivate *priv;
674 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
675 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
677 /* We only need to redraw when the handle position moves, which is
678 * independent of the overall allocation of the GtkPaned
680 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
682 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
685 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
686 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
692 priv->handle_pos.width = 5;
693 priv->handle_pos.height = 5;
694 priv->position_set = FALSE;
695 priv->last_allocation = -1;
696 priv->in_drag = FALSE;
698 priv->last_child1_focus = NULL;
699 priv->last_child2_focus = NULL;
700 priv->in_recursion = FALSE;
701 priv->handle_prelit = FALSE;
702 priv->original_position = -1;
704 priv->handle_pos.x = -1;
705 priv->handle_pos.y = -1;
711 gtk_paned_set_property (GObject *object,
716 GtkPaned *paned = GTK_PANED (object);
717 GtkPanedPrivate *priv = paned->priv;
721 case PROP_ORIENTATION:
722 priv->orientation = g_value_get_enum (value);
724 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
725 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
727 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
729 /* state_flags_changed updates the cursor */
730 gtk_paned_state_flags_changed (GTK_WIDGET (paned), 0);
731 gtk_widget_queue_resize (GTK_WIDGET (paned));
734 gtk_paned_set_position (paned, g_value_get_int (value));
736 case PROP_POSITION_SET:
737 priv->position_set = g_value_get_boolean (value);
738 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
741 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
747 gtk_paned_get_property (GObject *object,
752 GtkPaned *paned = GTK_PANED (object);
753 GtkPanedPrivate *priv = paned->priv;
757 case PROP_ORIENTATION:
758 g_value_set_enum (value, priv->orientation);
761 g_value_set_int (value, priv->child1_size);
763 case PROP_POSITION_SET:
764 g_value_set_boolean (value, priv->position_set);
766 case PROP_MIN_POSITION:
767 g_value_set_int (value, priv->min_position);
769 case PROP_MAX_POSITION:
770 g_value_set_int (value, priv->max_position);
773 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
779 gtk_paned_set_child_property (GtkContainer *container,
785 GtkPaned *paned = GTK_PANED (container);
786 GtkPanedPrivate *priv = paned->priv;
787 gboolean old_value, new_value;
789 g_assert (child == priv->child1 || child == priv->child2);
791 new_value = g_value_get_boolean (value);
794 case CHILD_PROP_RESIZE:
795 if (child == priv->child1)
797 old_value = priv->child1_resize;
798 priv->child1_resize = new_value;
802 old_value = priv->child2_resize;
803 priv->child2_resize = new_value;
806 case CHILD_PROP_SHRINK:
807 if (child == priv->child1)
809 old_value = priv->child1_shrink;
810 priv->child1_shrink = new_value;
814 old_value = priv->child2_shrink;
815 priv->child2_shrink = new_value;
819 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
820 old_value = -1; /* quiet gcc */
823 if (old_value != new_value)
824 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
828 gtk_paned_get_child_property (GtkContainer *container,
834 GtkPaned *paned = GTK_PANED (container);
835 GtkPanedPrivate *priv = paned->priv;
837 g_assert (child == priv->child1 || child == priv->child2);
841 case CHILD_PROP_RESIZE:
842 if (child == priv->child1)
843 g_value_set_boolean (value, priv->child1_resize);
845 g_value_set_boolean (value, priv->child2_resize);
847 case CHILD_PROP_SHRINK:
848 if (child == priv->child1)
849 g_value_set_boolean (value, priv->child1_shrink);
851 g_value_set_boolean (value, priv->child2_shrink);
854 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
860 gtk_paned_finalize (GObject *object)
862 GtkPaned *paned = GTK_PANED (object);
864 gtk_paned_set_saved_focus (paned, NULL);
865 gtk_paned_set_first_paned (paned, NULL);
867 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
871 get_preferred_size_for_size (GtkWidget *widget,
872 GtkOrientation orientation,
877 if (orientation == GTK_ORIENTATION_HORIZONTAL)
879 gtk_widget_get_preferred_width (widget, minimum, natural);
881 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
884 gtk_widget_get_preferred_height (widget, minimum, natural);
886 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
890 gtk_paned_get_preferred_size (GtkWidget *widget,
891 GtkOrientation orientation,
896 GtkPaned *paned = GTK_PANED (widget);
897 GtkPanedPrivate *priv = paned->priv;
898 gint child_min, child_nat;
900 *minimum = *natural = 0;
902 if (priv->child1 && gtk_widget_get_visible (priv->child1))
904 get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
905 *minimum = child_min;
906 *natural = child_nat;
909 if (priv->child2 && gtk_widget_get_visible (priv->child2))
911 get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
913 if (priv->orientation == orientation)
915 *minimum += child_min;
916 *natural += child_nat;
920 *minimum = MAX (*minimum, child_min);
921 *natural = MAX (*natural, child_nat);
925 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
926 priv->child2 && gtk_widget_get_visible (priv->child2))
930 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
932 if (priv->orientation == orientation)
934 *minimum += handle_size;
935 *natural += handle_size;
941 gtk_paned_get_preferred_width (GtkWidget *widget,
945 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
949 gtk_paned_get_preferred_height (GtkWidget *widget,
953 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
957 gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
962 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
966 gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
971 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
975 flip_child (GtkWidget *widget,
976 GtkAllocation *child_pos)
978 GtkAllocation allocation;
981 gtk_widget_get_allocation (widget, &allocation);
983 width = allocation.width;
985 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
989 gtk_paned_set_child_visible (GtkPaned *paned,
993 GtkPanedPrivate *priv = paned->priv;
996 child = id == CHILD1 ? priv->child1 : priv->child2;
1001 gtk_widget_set_child_visible (child, visible);
1003 if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
1005 GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
1007 if (visible != gdk_window_is_visible (window))
1010 gdk_window_show (window);
1012 gdk_window_hide (window);
1018 gtk_paned_child_allocate (GtkWidget *child,
1019 GdkWindow *child_window, /* can be NULL */
1020 const GtkAllocation *window_allocation,
1021 GtkAllocation *child_allocation)
1024 gdk_window_move_resize (child_window,
1025 window_allocation->x, window_allocation->y,
1026 window_allocation->width, window_allocation->height);
1028 gtk_widget_size_allocate (child, child_allocation);
1032 gtk_paned_size_allocate (GtkWidget *widget,
1033 GtkAllocation *allocation)
1035 GtkPaned *paned = GTK_PANED (widget);
1036 GtkPanedPrivate *priv = paned->priv;
1038 gtk_widget_set_allocation (widget, allocation);
1040 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1041 priv->child2 && gtk_widget_get_visible (priv->child2))
1043 GtkAllocation child1_allocation, window1_allocation;
1044 GtkAllocation child2_allocation, window2_allocation;
1045 GtkAllocation priv_child1_allocation;
1046 GdkRectangle old_handle_pos;
1049 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1051 old_handle_pos = priv->handle_pos;
1053 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1055 gint child1_width, child2_width;
1057 gtk_widget_get_preferred_width_for_height (priv->child1,
1059 &child1_width, NULL);
1060 gtk_widget_get_preferred_width_for_height (priv->child2,
1062 &child2_width, NULL);
1064 gtk_paned_calc_position (paned,
1065 MAX (1, allocation->width - handle_size),
1069 priv->handle_pos.x = allocation->x + priv->child1_size;
1070 priv->handle_pos.y = allocation->y;
1071 priv->handle_pos.width = handle_size;
1072 priv->handle_pos.height = allocation->height;
1074 window1_allocation.height = window2_allocation.height = allocation->height;
1075 window1_allocation.width = MAX (1, priv->child1_size);
1076 window1_allocation.x = allocation->x;
1077 window1_allocation.y = window2_allocation.y = allocation->y;
1079 window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
1080 window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
1082 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1084 flip_child (widget, &(window2_allocation));
1085 flip_child (widget, &(window1_allocation));
1086 flip_child (widget, &(priv->handle_pos));
1089 child1_allocation.x = child1_allocation.y = 0;
1090 child1_allocation.width = window1_allocation.width;
1091 child1_allocation.height = window1_allocation.height;
1092 if (child1_width > child1_allocation.width)
1094 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
1095 child1_allocation.x -= child1_width - child1_allocation.width;
1096 child1_allocation.width = child1_width;
1099 child2_allocation.x = child2_allocation.y = 0;
1100 child2_allocation.width = window2_allocation.width;
1101 child2_allocation.height = window2_allocation.height;
1102 if (child2_width > child2_allocation.width)
1104 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1105 child2_allocation.x -= child2_width - child2_allocation.width;
1106 child2_allocation.width = child2_width;
1111 gint child1_height, child2_height;
1113 gtk_widget_get_preferred_height_for_width (priv->child1,
1115 &child1_height, NULL);
1116 gtk_widget_get_preferred_height_for_width (priv->child2,
1118 &child2_height, NULL);
1120 gtk_paned_calc_position (paned,
1121 MAX (1, allocation->height - handle_size),
1125 priv->handle_pos.x = allocation->x;
1126 priv->handle_pos.y = allocation->y + priv->child1_size;
1127 priv->handle_pos.width = allocation->width;
1128 priv->handle_pos.height = handle_size;
1130 window1_allocation.width = window2_allocation.width = allocation->width;
1131 window1_allocation.height = MAX (1, priv->child1_size);
1132 window1_allocation.x = window2_allocation.x = allocation->x;
1133 window1_allocation.y = allocation->y;
1135 window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
1136 window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
1138 child1_allocation.x = child1_allocation.y = 0;
1139 child1_allocation.width = window1_allocation.width;
1140 child1_allocation.height = window1_allocation.height;
1141 if (child1_height > child1_allocation.height)
1143 child1_allocation.y -= child1_height - child1_allocation.height;
1144 child1_allocation.height = child1_height;
1147 child2_allocation.x = child2_allocation.y = 0;
1148 child2_allocation.width = window2_allocation.width;
1149 child2_allocation.height = window2_allocation.height;
1150 if (child2_height > child2_allocation.height)
1151 child2_allocation.height = child2_height;
1154 if (gtk_widget_get_mapped (widget) &&
1155 (old_handle_pos.x != priv->handle_pos.x ||
1156 old_handle_pos.y != priv->handle_pos.y ||
1157 old_handle_pos.width != priv->handle_pos.width ||
1158 old_handle_pos.height != priv->handle_pos.height))
1162 window = gtk_widget_get_window (widget);
1163 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
1164 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
1167 if (gtk_widget_get_realized (widget))
1169 if (gtk_widget_get_mapped (widget))
1170 gdk_window_show (priv->handle);
1172 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1174 gdk_window_move_resize (priv->handle,
1178 priv->handle_pos.height);
1182 gdk_window_move_resize (priv->handle,
1185 priv->handle_pos.width,
1190 /* Now allocate the childen, making sure, when resizing not to
1191 * overlap the windows
1193 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
1194 if (gtk_widget_get_mapped (widget) &&
1195 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1196 priv_child1_allocation.width < child1_allocation.width) ||
1198 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1199 priv_child1_allocation.height < child1_allocation.height)))
1201 gtk_paned_child_allocate (priv->child2,
1202 priv->child2_window,
1203 &window2_allocation,
1204 &child2_allocation);
1205 gtk_paned_child_allocate (priv->child1,
1206 priv->child1_window,
1207 &window1_allocation,
1208 &child1_allocation);
1212 gtk_paned_child_allocate (priv->child1,
1213 priv->child1_window,
1214 &window1_allocation,
1215 &child1_allocation);
1216 gtk_paned_child_allocate (priv->child2,
1217 priv->child2_window,
1218 &window2_allocation,
1219 &child2_allocation);
1224 GtkAllocation window_allocation, child_allocation;
1226 if (gtk_widget_get_realized (widget))
1227 gdk_window_hide (priv->handle);
1229 window_allocation.x = allocation->x;
1230 window_allocation.y = allocation->y;
1231 window_allocation.width = allocation->width;
1232 window_allocation.height = allocation->height;
1233 child_allocation.x = child_allocation.y = 0;
1234 child_allocation.width = allocation->width;
1235 child_allocation.height = allocation->height;
1237 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1239 gtk_paned_set_child_visible (paned, 0, TRUE);
1241 gtk_paned_set_child_visible (paned, 1, FALSE);
1243 gtk_paned_child_allocate (priv->child1,
1244 priv->child1_window,
1248 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1250 gtk_paned_set_child_visible (paned, 1, TRUE);
1252 gtk_paned_set_child_visible (paned, 0, FALSE);
1254 gtk_paned_child_allocate (priv->child2,
1255 priv->child2_window,
1262 gtk_paned_set_child_visible (paned, 0, FALSE);
1264 gtk_paned_set_child_visible (paned, 1, FALSE);
1270 gtk_paned_create_child_window (GtkPaned *paned,
1271 GtkWidget *child) /* may be NULL */
1273 GtkWidget *widget = GTK_WIDGET (paned);
1274 GtkPanedPrivate *priv = paned->priv;
1276 GdkWindowAttr attributes;
1277 gint attributes_mask;
1279 attributes.window_type = GDK_WINDOW_CHILD;
1280 attributes.wclass = GDK_INPUT_OUTPUT;
1281 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1284 GtkAllocation allocation;
1287 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1289 gtk_widget_get_allocation (widget, &allocation);
1290 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1291 child == priv->child2 && priv->child1 &&
1292 gtk_widget_get_visible (priv->child1))
1293 attributes.x = priv->handle_pos.x + handle_size;
1295 attributes.x = allocation.x;
1296 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1297 child == priv->child2 && priv->child1 &&
1298 gtk_widget_get_visible (priv->child1))
1299 attributes.y = priv->handle_pos.y + handle_size;
1301 attributes.y = allocation.y;
1303 gtk_widget_get_allocation (child, &allocation);
1304 attributes.width = allocation.width;
1305 attributes.height = allocation.height;
1306 attributes_mask = GDK_WA_X | GDK_WA_Y;
1310 attributes.width = 1;
1311 attributes.height = 1;
1312 attributes_mask = 0;
1315 window = gdk_window_new (gtk_widget_get_window (widget),
1316 &attributes, attributes_mask);
1317 gdk_window_set_user_data (window, paned);
1318 gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
1321 gtk_widget_set_parent_window (child, window);
1327 gtk_paned_realize (GtkWidget *widget)
1329 GtkPaned *paned = GTK_PANED (widget);
1330 GtkPanedPrivate *priv = paned->priv;
1332 GdkWindowAttr attributes;
1333 gint attributes_mask;
1335 gtk_widget_set_realized (widget, TRUE);
1337 window = gtk_widget_get_parent_window (widget);
1338 gtk_widget_set_window (widget, window);
1339 g_object_ref (window);
1341 attributes.window_type = GDK_WINDOW_CHILD;
1342 attributes.wclass = GDK_INPUT_ONLY;
1343 attributes.x = priv->handle_pos.x;
1344 attributes.y = priv->handle_pos.y;
1345 attributes.width = priv->handle_pos.width;
1346 attributes.height = priv->handle_pos.height;
1347 attributes.event_mask = gtk_widget_get_events (widget);
1348 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1349 GDK_BUTTON_RELEASE_MASK |
1350 GDK_ENTER_NOTIFY_MASK |
1351 GDK_LEAVE_NOTIFY_MASK |
1352 GDK_POINTER_MOTION_MASK);
1353 attributes_mask = GDK_WA_X | GDK_WA_Y;
1354 if (gtk_widget_is_sensitive (widget))
1356 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1358 attributes_mask |= GDK_WA_CURSOR;
1361 priv->handle = gdk_window_new (window,
1362 &attributes, attributes_mask);
1363 gdk_window_set_user_data (priv->handle, paned);
1364 if (attributes_mask & GDK_WA_CURSOR)
1365 g_object_unref (attributes.cursor);
1367 priv->child1_window = gtk_paned_create_child_window (paned, priv->child1);
1368 priv->child2_window = gtk_paned_create_child_window (paned, priv->child2);
1372 gtk_paned_unrealize (GtkWidget *widget)
1374 GtkPaned *paned = GTK_PANED (widget);
1375 GtkPanedPrivate *priv = paned->priv;
1378 gtk_widget_set_parent_window (priv->child2, NULL);
1379 gdk_window_set_user_data (priv->child2_window, NULL);
1380 gdk_window_destroy (priv->child2_window);
1381 priv->child2_window = NULL;
1384 gtk_widget_set_parent_window (priv->child1, NULL);
1385 gdk_window_set_user_data (priv->child1_window, NULL);
1386 gdk_window_destroy (priv->child1_window);
1387 priv->child1_window = NULL;
1391 gdk_window_set_user_data (priv->handle, NULL);
1392 gdk_window_destroy (priv->handle);
1393 priv->handle = NULL;
1396 gtk_paned_set_last_child1_focus (paned, NULL);
1397 gtk_paned_set_last_child2_focus (paned, NULL);
1398 gtk_paned_set_saved_focus (paned, NULL);
1399 gtk_paned_set_first_paned (paned, NULL);
1401 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1405 gtk_paned_map (GtkWidget *widget)
1407 GtkPaned *paned = GTK_PANED (widget);
1408 GtkPanedPrivate *priv = paned->priv;
1410 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1411 priv->child2 && gtk_widget_get_visible (priv->child2))
1412 gdk_window_show (priv->handle);
1414 if (priv->child1 && gtk_widget_get_visible (priv->child1) && gtk_widget_get_child_visible (priv->child1))
1415 gdk_window_show (priv->child1_window);
1416 if (priv->child2 && gtk_widget_get_visible (priv->child2) && gtk_widget_get_child_visible (priv->child2))
1417 gdk_window_show (priv->child2_window);
1419 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1423 gtk_paned_unmap (GtkWidget *widget)
1425 GtkPaned *paned = GTK_PANED (widget);
1426 GtkPanedPrivate *priv = paned->priv;
1428 gdk_window_hide (priv->handle);
1430 if (gdk_window_is_visible (priv->child1_window))
1431 gdk_window_hide (priv->child1_window);
1432 if (gdk_window_is_visible (priv->child2_window))
1433 gdk_window_hide (priv->child2_window);
1435 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1439 gtk_paned_draw (GtkWidget *widget,
1442 GtkPaned *paned = GTK_PANED (widget);
1443 GtkPanedPrivate *priv = paned->priv;
1445 if (gtk_cairo_should_draw_window (cr, priv->child1_window))
1448 gtk_cairo_transform_to_window (cr, widget, priv->child1_window);
1449 gtk_render_background (gtk_widget_get_style_context (widget),
1452 gdk_window_get_width (priv->child1_window),
1453 gdk_window_get_height (priv->child1_window));
1457 if (gtk_cairo_should_draw_window (cr, priv->child2_window))
1460 gtk_cairo_transform_to_window (cr, widget, priv->child2_window);
1461 gtk_render_background (gtk_widget_get_style_context (widget),
1464 gdk_window_get_width (priv->child2_window),
1465 gdk_window_get_height (priv->child2_window));
1469 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)) &&
1470 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1471 priv->child2 && gtk_widget_get_visible (priv->child2))
1473 GtkStyleContext *context;
1474 GtkStateFlags state;
1475 GtkAllocation allocation;
1477 gtk_widget_get_allocation (widget, &allocation);
1478 context = gtk_widget_get_style_context (widget);
1479 state = gtk_widget_get_state_flags (widget);
1481 if (gtk_widget_is_focus (widget))
1482 state |= GTK_STATE_FLAG_SELECTED;
1483 if (priv->handle_prelit)
1484 state |= GTK_STATE_FLAG_PRELIGHT;
1486 gtk_style_context_save (context);
1487 gtk_style_context_set_state (context, state);
1488 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1489 gtk_render_handle (context, cr,
1490 priv->handle_pos.x - allocation.x,
1491 priv->handle_pos.y - allocation.y,
1492 priv->handle_pos.width,
1493 priv->handle_pos.height);
1495 gtk_style_context_restore (context);
1498 /* Chain up to draw children */
1499 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1505 is_rtl (GtkPaned *paned)
1507 GtkPanedPrivate *priv = paned->priv;
1509 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1510 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1519 update_drag (GtkPaned *paned,
1520 /* relative to priv->handle */
1524 GtkPanedPrivate *priv = paned->priv;
1525 GtkAllocation allocation;
1526 GtkWidget *widget = GTK_WIDGET (paned);
1532 gdk_window_get_position (priv->handle, &x, &y);
1533 gtk_widget_get_allocation (widget, &allocation);
1534 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1536 pos = xpos + x - allocation.x;
1540 pos = ypos + y - allocation.y;
1543 pos -= priv->drag_pos;
1547 gtk_widget_style_get (widget,
1548 "handle-size", &handle_size,
1551 size = allocation.width - pos - handle_size;
1558 size = CLAMP (size, priv->min_position, priv->max_position);
1560 if (size != priv->child1_size)
1561 gtk_paned_set_position (paned, size);
1565 gtk_paned_enter (GtkWidget *widget,
1566 GdkEventCrossing *event)
1568 GtkPaned *paned = GTK_PANED (widget);
1569 GtkPanedPrivate *priv = paned->priv;
1572 update_drag (paned, event->x, event->y);
1575 priv->handle_prelit = TRUE;
1576 gtk_widget_queue_draw_area (widget,
1579 priv->handle_pos.width,
1580 priv->handle_pos.height);
1587 gtk_paned_leave (GtkWidget *widget,
1588 GdkEventCrossing *event)
1590 GtkPaned *paned = GTK_PANED (widget);
1591 GtkPanedPrivate *priv = paned->priv;
1594 update_drag (paned, event->x, event->y);
1597 priv->handle_prelit = FALSE;
1598 gtk_widget_queue_draw_area (widget,
1601 priv->handle_pos.width,
1602 priv->handle_pos.height);
1609 gtk_paned_focus (GtkWidget *widget,
1610 GtkDirectionType direction)
1615 /* This is a hack, but how can this be done without
1616 * excessive cut-and-paste from gtkcontainer.c?
1619 gtk_widget_set_can_focus (widget, FALSE);
1620 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1621 gtk_widget_set_can_focus (widget, TRUE);
1627 gtk_paned_button_press (GtkWidget *widget,
1628 GdkEventButton *event)
1630 GtkPaned *paned = GTK_PANED (widget);
1631 GtkPanedPrivate *priv = paned->priv;
1633 if (!priv->in_drag &&
1634 (event->window == priv->handle) && (event->button == GDK_BUTTON_PRIMARY))
1636 /* We need a server grab here, not gtk_grab_add(), since
1637 * we don't want to pass events on to the widget's children */
1638 if (gdk_device_grab (event->device,
1640 GDK_OWNERSHIP_WINDOW, FALSE,
1641 GDK_BUTTON1_MOTION_MASK
1642 | GDK_BUTTON_RELEASE_MASK
1643 | GDK_ENTER_NOTIFY_MASK
1644 | GDK_LEAVE_NOTIFY_MASK,
1645 NULL, event->time) != GDK_GRAB_SUCCESS)
1648 priv->in_drag = TRUE;
1649 priv->grab_time = event->time;
1650 priv->grab_device = event->device;
1652 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1653 priv->drag_pos = event->x;
1655 priv->drag_pos = event->y;
1664 gtk_paned_grab_broken (GtkWidget *widget,
1665 GdkEventGrabBroken *event)
1667 GtkPaned *paned = GTK_PANED (widget);
1668 GtkPanedPrivate *priv = paned->priv;
1670 priv->in_drag = FALSE;
1671 priv->drag_pos = -1;
1672 priv->position_set = TRUE;
1678 stop_drag (GtkPaned *paned)
1680 GtkPanedPrivate *priv = paned->priv;
1682 priv->in_drag = FALSE;
1683 priv->drag_pos = -1;
1684 priv->position_set = TRUE;
1686 gdk_device_ungrab (priv->grab_device,
1688 priv->grab_device = NULL;
1692 gtk_paned_grab_notify (GtkWidget *widget,
1693 gboolean was_grabbed)
1695 GtkPaned *paned = GTK_PANED (widget);
1696 GtkPanedPrivate *priv = paned->priv;
1697 GdkDevice *grab_device;
1699 grab_device = priv->grab_device;
1701 if (priv->in_drag && grab_device &&
1702 gtk_widget_device_is_shadowed (widget, grab_device))
1707 gtk_paned_state_flags_changed (GtkWidget *widget,
1708 GtkStateFlags previous_state)
1710 GtkPaned *paned = GTK_PANED (widget);
1711 GtkPanedPrivate *priv = paned->priv;
1714 if (gtk_widget_get_realized (widget))
1716 if (gtk_widget_is_sensitive (widget))
1717 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1722 gdk_window_set_cursor (priv->handle, cursor);
1725 g_object_unref (cursor);
1730 gtk_paned_button_release (GtkWidget *widget,
1731 GdkEventButton *event)
1733 GtkPaned *paned = GTK_PANED (widget);
1734 GtkPanedPrivate *priv = paned->priv;
1736 if (priv->in_drag && (event->button == GDK_BUTTON_PRIMARY))
1747 gtk_paned_motion (GtkWidget *widget,
1748 GdkEventMotion *event)
1750 GtkPaned *paned = GTK_PANED (widget);
1751 GtkPanedPrivate *priv = paned->priv;
1755 update_drag (paned, event->x, event->y);
1764 * @orientation: the paned's orientation.
1766 * Creates a new #GtkPaned widget.
1768 * Return value: a new #GtkPaned.
1773 gtk_paned_new (GtkOrientation orientation)
1775 return g_object_new (GTK_TYPE_PANED,
1776 "orientation", orientation,
1782 * @paned: a paned widget
1783 * @child: the child to add
1785 * Adds a child to the top or left pane with default parameters. This is
1787 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1790 gtk_paned_add1 (GtkPaned *paned,
1793 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1798 * @paned: a paned widget
1799 * @child: the child to add
1801 * Adds a child to the bottom or right pane with default parameters. This
1803 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1806 gtk_paned_add2 (GtkPaned *paned,
1809 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1814 * @paned: a paned widget
1815 * @child: the child to add
1816 * @resize: should this child expand when the paned widget is resized.
1817 * @shrink: can this child be made smaller than its requisition.
1819 * Adds a child to the top or left pane.
1822 gtk_paned_pack1 (GtkPaned *paned,
1827 GtkPanedPrivate *priv;
1829 g_return_if_fail (GTK_IS_PANED (paned));
1830 g_return_if_fail (GTK_IS_WIDGET (child));
1836 priv->child1 = child;
1837 priv->child1_resize = resize;
1838 priv->child1_shrink = shrink;
1840 gtk_widget_set_parent_window (child, priv->child1_window);
1841 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1847 * @paned: a paned widget
1848 * @child: the child to add
1849 * @resize: should this child expand when the paned widget is resized.
1850 * @shrink: can this child be made smaller than its requisition.
1852 * Adds a child to the bottom or right pane.
1855 gtk_paned_pack2 (GtkPaned *paned,
1860 GtkPanedPrivate *priv;
1862 g_return_if_fail (GTK_IS_PANED (paned));
1863 g_return_if_fail (GTK_IS_WIDGET (child));
1869 priv->child2 = child;
1870 priv->child2_resize = resize;
1871 priv->child2_shrink = shrink;
1873 gtk_widget_set_parent_window (child, priv->child2_window);
1874 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1880 gtk_paned_add (GtkContainer *container,
1883 GtkPanedPrivate *priv;
1886 g_return_if_fail (GTK_IS_PANED (container));
1888 paned = GTK_PANED (container);
1892 gtk_paned_add1 (paned, widget);
1893 else if (!priv->child2)
1894 gtk_paned_add2 (paned, widget);
1896 g_warning ("GtkPaned cannot have more than 2 children\n");
1900 gtk_paned_remove (GtkContainer *container,
1903 GtkPaned *paned = GTK_PANED (container);
1904 GtkPanedPrivate *priv = paned->priv;
1905 gboolean was_visible;
1907 was_visible = gtk_widget_get_visible (widget);
1909 if (priv->child1 == widget)
1911 if (priv->child1_window && gdk_window_is_visible (priv->child1_window))
1912 gdk_window_hide (priv->child1_window);
1914 gtk_widget_unparent (widget);
1916 priv->child1 = NULL;
1918 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1919 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1921 else if (priv->child2 == widget)
1923 if (priv->child2_window && gdk_window_is_visible (priv->child2_window))
1924 gdk_window_hide (priv->child2_window);
1926 gtk_widget_unparent (widget);
1928 priv->child2 = NULL;
1930 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1931 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1936 gtk_paned_forall (GtkContainer *container,
1937 gboolean include_internals,
1938 GtkCallback callback,
1939 gpointer callback_data)
1941 GtkPanedPrivate *priv;
1944 g_return_if_fail (callback != NULL);
1946 paned = GTK_PANED (container);
1950 (*callback) (priv->child1, callback_data);
1952 (*callback) (priv->child2, callback_data);
1956 * gtk_paned_get_position:
1957 * @paned: a #GtkPaned widget
1959 * Obtains the position of the divider between the two panes.
1961 * Return value: position of the divider
1964 gtk_paned_get_position (GtkPaned *paned)
1966 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1968 return paned->priv->child1_size;
1972 * gtk_paned_set_position:
1973 * @paned: a #GtkPaned widget
1974 * @position: pixel position of divider, a negative value means that the position
1977 * Sets the position of the divider between the two panes.
1980 gtk_paned_set_position (GtkPaned *paned,
1983 GtkPanedPrivate *priv;
1986 g_return_if_fail (GTK_IS_PANED (paned));
1990 if (priv->child1_size == position)
1993 object = G_OBJECT (paned);
1997 /* We don't clamp here - the assumption is that
1998 * if the total allocation changes at the same time
1999 * as the position, the position set is with reference
2000 * to the new total size. If only the position changes,
2001 * then clamping will occur in gtk_paned_calc_position()
2004 priv->child1_size = position;
2005 priv->position_set = TRUE;
2009 priv->position_set = FALSE;
2012 g_object_freeze_notify (object);
2013 g_object_notify (object, "position");
2014 g_object_notify (object, "position-set");
2015 g_object_thaw_notify (object);
2017 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
2020 /* Hacky work-around for bug #144269 */
2021 if (priv->child2 != NULL)
2023 gtk_widget_queue_draw (priv->child2);
2029 * gtk_paned_get_child1:
2030 * @paned: a #GtkPaned widget
2032 * Obtains the first child of the paned widget.
2034 * Return value: (transfer none): first child, or %NULL if it is not set.
2039 gtk_paned_get_child1 (GtkPaned *paned)
2041 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2043 return paned->priv->child1;
2047 * gtk_paned_get_child2:
2048 * @paned: a #GtkPaned widget
2050 * Obtains the second child of the paned widget.
2052 * Return value: (transfer none): second child, or %NULL if it is not set.
2057 gtk_paned_get_child2 (GtkPaned *paned)
2059 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2061 return paned->priv->child2;
2065 gtk_paned_calc_position (GtkPaned *paned,
2070 GtkPanedPrivate *priv = paned->priv;
2072 gint old_min_position;
2073 gint old_max_position;
2075 old_position = priv->child1_size;
2076 old_min_position = priv->min_position;
2077 old_max_position = priv->max_position;
2079 priv->min_position = priv->child1_shrink ? 0 : child1_req;
2081 priv->max_position = allocation;
2082 if (!priv->child2_shrink)
2083 priv->max_position = MAX (1, priv->max_position - child2_req);
2084 priv->max_position = MAX (priv->min_position, priv->max_position);
2086 if (!priv->position_set)
2088 if (priv->child1_resize && !priv->child2_resize)
2089 priv->child1_size = MAX (0, allocation - child2_req);
2090 else if (!priv->child1_resize && priv->child2_resize)
2091 priv->child1_size = child1_req;
2092 else if (child1_req + child2_req != 0)
2093 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
2095 priv->child1_size = allocation * 0.5 + 0.5;
2099 /* If the position was set before the initial allocation.
2100 * (priv->last_allocation <= 0) just clamp it and leave it.
2102 if (priv->last_allocation > 0)
2104 if (priv->child1_resize && !priv->child2_resize)
2105 priv->child1_size += allocation - priv->last_allocation;
2106 else if (!(!priv->child1_resize && priv->child2_resize))
2107 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
2111 priv->child1_size = CLAMP (priv->child1_size,
2113 priv->max_position);
2116 gtk_paned_set_child_visible (paned, 0, priv->child1_size != 0);
2119 gtk_paned_set_child_visible (paned, 1, priv->child1_size != allocation);
2121 g_object_freeze_notify (G_OBJECT (paned));
2122 if (priv->child1_size != old_position)
2123 g_object_notify (G_OBJECT (paned), "position");
2124 if (priv->min_position != old_min_position)
2125 g_object_notify (G_OBJECT (paned), "min-position");
2126 if (priv->max_position != old_max_position)
2127 g_object_notify (G_OBJECT (paned), "max-position");
2128 g_object_thaw_notify (G_OBJECT (paned));
2130 priv->last_allocation = allocation;
2134 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
2136 GtkPanedPrivate *priv = paned->priv;
2138 if (priv->saved_focus)
2139 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
2140 (gpointer *)&(priv->saved_focus));
2142 priv->saved_focus = widget;
2144 if (priv->saved_focus)
2145 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
2146 (gpointer *)&(priv->saved_focus));
2150 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
2152 GtkPanedPrivate *priv = paned->priv;
2154 if (priv->first_paned)
2155 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
2156 (gpointer *)&(priv->first_paned));
2158 priv->first_paned = first_paned;
2160 if (priv->first_paned)
2161 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
2162 (gpointer *)&(priv->first_paned));
2166 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
2168 GtkPanedPrivate *priv = paned->priv;
2170 if (priv->last_child1_focus)
2171 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
2172 (gpointer *)&(priv->last_child1_focus));
2174 priv->last_child1_focus = widget;
2176 if (priv->last_child1_focus)
2177 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
2178 (gpointer *)&(priv->last_child1_focus));
2182 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
2184 GtkPanedPrivate *priv = paned->priv;
2186 if (priv->last_child2_focus)
2187 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
2188 (gpointer *)&(priv->last_child2_focus));
2190 priv->last_child2_focus = widget;
2192 if (priv->last_child2_focus)
2193 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
2194 (gpointer *)&(priv->last_child2_focus));
2198 paned_get_focus_widget (GtkPaned *paned)
2200 GtkWidget *toplevel;
2202 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2203 if (gtk_widget_is_toplevel (toplevel))
2204 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2210 gtk_paned_set_focus_child (GtkContainer *container,
2211 GtkWidget *focus_child)
2214 GtkPanedPrivate *priv;
2215 GtkWidget *container_focus_child;
2217 g_return_if_fail (GTK_IS_PANED (container));
2219 paned = GTK_PANED (container);
2222 if (focus_child == NULL)
2224 GtkWidget *last_focus;
2227 last_focus = paned_get_focus_widget (paned);
2231 /* If there is one or more paned widgets between us and the
2232 * focus widget, we want the topmost of those as last_focus
2234 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
2235 if (GTK_IS_PANED (w))
2238 container_focus_child = gtk_container_get_focus_child (container);
2239 if (container_focus_child == priv->child1)
2240 gtk_paned_set_last_child1_focus (paned, last_focus);
2241 else if (container_focus_child == priv->child2)
2242 gtk_paned_set_last_child2_focus (paned, last_focus);
2246 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2247 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2251 gtk_paned_get_cycle_chain (GtkPaned *paned,
2252 GtkDirectionType direction,
2255 GtkPanedPrivate *priv = paned->priv;
2256 GtkContainer *container = GTK_CONTAINER (paned);
2257 GtkWidget *ancestor = NULL;
2258 GtkWidget *focus_child;
2260 GtkWidget *widget = GTK_WIDGET (paned);
2261 GList *temp_list = NULL;
2264 if (priv->in_recursion)
2267 g_assert (widgets != NULL);
2269 if (priv->last_child1_focus &&
2270 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2272 gtk_paned_set_last_child1_focus (paned, NULL);
2275 if (priv->last_child2_focus &&
2276 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2278 gtk_paned_set_last_child2_focus (paned, NULL);
2281 parent = gtk_widget_get_parent (widget);
2283 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2285 /* The idea here is that temp_list is a list of widgets we want to cycle
2286 * to. The list is prioritized so that the first element is our first
2287 * choice, the next our second, and so on.
2289 * We can't just use g_list_reverse(), because we want to try
2290 * priv->last_child?_focus before priv->child?, both when we
2291 * are going forward and backward.
2293 focus_child = gtk_container_get_focus_child (container);
2294 if (direction == GTK_DIR_TAB_FORWARD)
2296 if (focus_child == priv->child1)
2298 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2299 temp_list = g_list_append (temp_list, priv->child2);
2300 temp_list = g_list_append (temp_list, ancestor);
2302 else if (focus_child == priv->child2)
2304 temp_list = g_list_append (temp_list, ancestor);
2305 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2306 temp_list = g_list_append (temp_list, priv->child1);
2310 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2311 temp_list = g_list_append (temp_list, priv->child1);
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, ancestor);
2319 if (focus_child == priv->child1)
2321 temp_list = g_list_append (temp_list, ancestor);
2322 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2323 temp_list = g_list_append (temp_list, priv->child2);
2325 else if (focus_child == priv->child2)
2327 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2328 temp_list = g_list_append (temp_list, priv->child1);
2329 temp_list = g_list_append (temp_list, ancestor);
2333 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2334 temp_list = g_list_append (temp_list, priv->child2);
2335 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2336 temp_list = g_list_append (temp_list, priv->child1);
2337 temp_list = g_list_append (temp_list, ancestor);
2341 /* Walk the list and expand all the paned widgets. */
2342 for (list = temp_list; list != NULL; list = list->next)
2344 GtkWidget *widget = list->data;
2348 if (GTK_IS_PANED (widget))
2350 priv->in_recursion = TRUE;
2351 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2352 priv->in_recursion = FALSE;
2356 *widgets = g_list_append (*widgets, widget);
2361 g_list_free (temp_list);
2365 gtk_paned_cycle_child_focus (GtkPaned *paned,
2368 GList *cycle_chain = NULL;
2371 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2373 /* ignore f6 if the handle is focused */
2374 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2377 /* we can't just let the event propagate up the hierarchy,
2378 * because the paned will want to cycle focus _unless_ an
2379 * ancestor paned handles the event
2381 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2383 for (list = cycle_chain; list != NULL; list = list->next)
2384 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2387 g_list_free (cycle_chain);
2393 get_child_panes (GtkWidget *widget,
2396 if (!widget || !gtk_widget_get_realized (widget))
2399 if (GTK_IS_PANED (widget))
2401 GtkPaned *paned = GTK_PANED (widget);
2402 GtkPanedPrivate *priv = paned->priv;
2404 get_child_panes (priv->child1, panes);
2405 *panes = g_list_prepend (*panes, widget);
2406 get_child_panes (priv->child2, panes);
2408 else if (GTK_IS_CONTAINER (widget))
2410 gtk_container_forall (GTK_CONTAINER (widget),
2411 (GtkCallback)get_child_panes, panes);
2416 get_all_panes (GtkPaned *paned)
2418 GtkPaned *topmost = NULL;
2419 GList *result = NULL;
2422 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2424 if (GTK_IS_PANED (w))
2425 topmost = GTK_PANED (w);
2430 get_child_panes (GTK_WIDGET (topmost), &result);
2432 return g_list_reverse (result);
2436 gtk_paned_find_neighbours (GtkPaned *paned,
2443 all_panes = get_all_panes (paned);
2444 g_assert (all_panes);
2446 this_link = g_list_find (all_panes, paned);
2448 g_assert (this_link);
2450 if (this_link->next)
2451 *next = this_link->next->data;
2453 *next = all_panes->data;
2455 if (this_link->prev)
2456 *prev = this_link->prev->data;
2458 *prev = g_list_last (all_panes)->data;
2460 g_list_free (all_panes);
2464 gtk_paned_move_handle (GtkPaned *paned,
2465 GtkScrollType scroll)
2467 GtkPanedPrivate *priv = paned->priv;
2469 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2476 SINGLE_STEP_SIZE = 1,
2480 new_position = old_position = gtk_paned_get_position (paned);
2485 case GTK_SCROLL_STEP_LEFT:
2486 case GTK_SCROLL_STEP_UP:
2487 case GTK_SCROLL_STEP_BACKWARD:
2488 increment = - SINGLE_STEP_SIZE;
2491 case GTK_SCROLL_STEP_RIGHT:
2492 case GTK_SCROLL_STEP_DOWN:
2493 case GTK_SCROLL_STEP_FORWARD:
2494 increment = SINGLE_STEP_SIZE;
2497 case GTK_SCROLL_PAGE_LEFT:
2498 case GTK_SCROLL_PAGE_UP:
2499 case GTK_SCROLL_PAGE_BACKWARD:
2500 increment = - PAGE_STEP_SIZE;
2503 case GTK_SCROLL_PAGE_RIGHT:
2504 case GTK_SCROLL_PAGE_DOWN:
2505 case GTK_SCROLL_PAGE_FORWARD:
2506 increment = PAGE_STEP_SIZE;
2509 case GTK_SCROLL_START:
2510 new_position = priv->min_position;
2513 case GTK_SCROLL_END:
2514 new_position = priv->max_position;
2524 increment = -increment;
2526 new_position = old_position + increment;
2529 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2531 if (old_position != new_position)
2532 gtk_paned_set_position (paned, new_position);
2541 gtk_paned_restore_focus (GtkPaned *paned)
2543 GtkPanedPrivate *priv = paned->priv;
2545 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2547 if (priv->saved_focus &&
2548 gtk_widget_get_sensitive (priv->saved_focus))
2550 gtk_widget_grab_focus (priv->saved_focus);
2554 /* the saved focus is somehow not available for focusing,
2556 * 1) tabbing into the paned widget
2557 * if that didn't work,
2558 * 2) unset focus for the window if there is one
2561 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2563 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2565 if (GTK_IS_WINDOW (toplevel))
2566 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2570 gtk_paned_set_saved_focus (paned, NULL);
2571 gtk_paned_set_first_paned (paned, NULL);
2576 gtk_paned_accept_position (GtkPaned *paned)
2578 GtkPanedPrivate *priv = paned->priv;
2580 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2582 priv->original_position = -1;
2583 gtk_paned_restore_focus (paned);
2593 gtk_paned_cancel_position (GtkPaned *paned)
2595 GtkPanedPrivate *priv = paned->priv;
2597 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2599 if (priv->original_position != -1)
2601 gtk_paned_set_position (paned, priv->original_position);
2602 priv->original_position = -1;
2605 gtk_paned_restore_focus (paned);
2613 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2616 GtkPanedPrivate *priv = paned->priv;
2617 GtkPaned *next, *prev;
2619 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2621 GtkPaned *focus = NULL;
2623 if (!priv->first_paned)
2625 /* The first_pane has disappeared. As an ad-hoc solution,
2626 * we make the currently focused paned the first_paned. To the
2627 * user this will seem like the paned cycling has been reset.
2630 gtk_paned_set_first_paned (paned, paned);
2633 gtk_paned_find_neighbours (paned, &next, &prev);
2635 if (reversed && prev &&
2636 prev != paned && paned != priv->first_paned)
2640 else if (!reversed && next &&
2641 next != paned && next != priv->first_paned)
2647 gtk_paned_accept_position (paned);
2653 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2654 gtk_paned_set_first_paned (focus, priv->first_paned);
2656 gtk_paned_set_saved_focus (paned, NULL);
2657 gtk_paned_set_first_paned (paned, NULL);
2659 gtk_widget_grab_focus (GTK_WIDGET (focus));
2661 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2663 priv->original_position = -1;
2664 focus->priv->original_position = gtk_paned_get_position (focus);
2669 GtkContainer *container = GTK_CONTAINER (paned);
2672 GtkPaned *prev, *next;
2673 GtkWidget *toplevel;
2674 GtkWidget *focus_child;
2676 gtk_paned_find_neighbours (paned, &next, &prev);
2677 focus_child = gtk_container_get_focus_child (container);
2679 if (focus_child == priv->child1)
2692 else if (focus_child == priv->child2)
2707 /* Focus is not inside this paned, and we don't have focus.
2708 * Presumably this happened because the application wants us
2709 * to start keyboard navigating.
2719 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2721 if (GTK_IS_WINDOW (toplevel))
2722 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2723 gtk_paned_set_first_paned (focus, first);
2724 focus->priv->original_position = gtk_paned_get_position (focus);
2726 gtk_widget_grab_focus (GTK_WIDGET (focus));
2733 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2735 /* This function/signal has the wrong name. It is called when you
2736 * press Tab or Shift-Tab and what we do is act as if
2737 * the user pressed Return and then Tab or Shift-Tab
2739 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2740 gtk_paned_accept_position (paned);
2746 * gtk_paned_get_handle_window:
2747 * @paned: a #GtkPaned
2749 * Returns the #GdkWindow of the handle. This function is
2750 * useful when handling button or motion events because it
2751 * enables the callback to distinguish between the window
2752 * of the paned, a child and the handle.
2754 * Return value: (transfer none): the paned's handle window.
2759 gtk_paned_get_handle_window (GtkPaned *paned)
2761 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2763 return paned->priv->handle;