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/.
29 #include "gdk/gdkkeysyms.h"
30 #include "gtkbindings.h"
32 #include "gtkmarshalers.h"
33 #include "gtkorientable.h"
35 #include "gtkwindow.h"
36 #include "gtkprivate.h"
41 struct _GtkPanedPrivate
43 GtkOrientation orientation;
44 GtkPaned *first_paned;
47 GtkWidget *last_child1_focus;
48 GtkWidget *last_child2_focus;
49 GtkWidget *saved_focus;
51 GdkCursorType cursor_type;
52 GdkDevice *grab_device;
53 GdkRectangle handle_pos;
61 gint original_position;
63 guint handle_prelit : 1;
65 guint in_recursion : 1;
66 guint child1_resize : 1;
67 guint child1_shrink : 1;
68 guint child2_resize : 1;
69 guint child2_shrink : 1;
70 guint position_set : 1;
100 static void gtk_paned_set_property (GObject *object,
104 static void gtk_paned_get_property (GObject *object,
108 static void gtk_paned_set_child_property (GtkContainer *container,
113 static void gtk_paned_get_child_property (GtkContainer *container,
118 static void gtk_paned_finalize (GObject *object);
120 static void gtk_paned_size_request (GtkWidget *widget,
121 GtkRequisition *requisition);
122 static void gtk_paned_size_allocate (GtkWidget *widget,
123 GtkAllocation *allocation);
124 static void gtk_paned_realize (GtkWidget *widget);
125 static void gtk_paned_unrealize (GtkWidget *widget);
126 static void gtk_paned_map (GtkWidget *widget);
127 static void gtk_paned_unmap (GtkWidget *widget);
128 static void gtk_paned_state_changed (GtkWidget *widget,
129 GtkStateType previous_state);
130 static gboolean gtk_paned_expose (GtkWidget *widget,
131 GdkEventExpose *event);
132 static gboolean gtk_paned_enter (GtkWidget *widget,
133 GdkEventCrossing *event);
134 static gboolean gtk_paned_leave (GtkWidget *widget,
135 GdkEventCrossing *event);
136 static gboolean gtk_paned_button_press (GtkWidget *widget,
137 GdkEventButton *event);
138 static gboolean gtk_paned_button_release (GtkWidget *widget,
139 GdkEventButton *event);
140 static gboolean gtk_paned_motion (GtkWidget *widget,
141 GdkEventMotion *event);
142 static gboolean gtk_paned_focus (GtkWidget *widget,
143 GtkDirectionType direction);
144 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
145 GdkEventGrabBroken *event);
146 static void gtk_paned_add (GtkContainer *container,
148 static void gtk_paned_remove (GtkContainer *container,
150 static void gtk_paned_forall (GtkContainer *container,
151 gboolean include_internals,
152 GtkCallback callback,
153 gpointer callback_data);
154 static void gtk_paned_calc_position (GtkPaned *paned,
158 static void gtk_paned_set_focus_child (GtkContainer *container,
160 static void gtk_paned_set_saved_focus (GtkPaned *paned,
162 static void gtk_paned_set_first_paned (GtkPaned *paned,
163 GtkPaned *first_paned);
164 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
166 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
168 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
170 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
172 static gboolean gtk_paned_move_handle (GtkPaned *paned,
173 GtkScrollType scroll);
174 static gboolean gtk_paned_accept_position (GtkPaned *paned);
175 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
176 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
178 static GType gtk_paned_child_type (GtkContainer *container);
179 static void gtk_paned_grab_notify (GtkWidget *widget,
180 gboolean was_grabbed);
183 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
184 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
187 static guint signals[LAST_SIGNAL] = { 0 };
191 add_tab_bindings (GtkBindingSet *binding_set,
192 GdkModifierType modifiers)
194 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
195 "toggle-handle-focus", 0);
196 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
197 "toggle-handle-focus", 0);
201 add_move_binding (GtkBindingSet *binding_set,
203 GdkModifierType mask,
204 GtkScrollType scroll)
206 gtk_binding_entry_add_signal (binding_set, keyval, mask,
208 GTK_TYPE_SCROLL_TYPE, scroll);
212 gtk_paned_class_init (GtkPanedClass *class)
214 GObjectClass *object_class;
215 GtkWidgetClass *widget_class;
216 GtkContainerClass *container_class;
217 GtkPanedClass *paned_class;
218 GtkBindingSet *binding_set;
220 object_class = (GObjectClass *) class;
221 widget_class = (GtkWidgetClass *) class;
222 container_class = (GtkContainerClass *) class;
223 paned_class = (GtkPanedClass *) class;
225 object_class->set_property = gtk_paned_set_property;
226 object_class->get_property = gtk_paned_get_property;
227 object_class->finalize = gtk_paned_finalize;
229 widget_class->size_request = gtk_paned_size_request;
230 widget_class->size_allocate = gtk_paned_size_allocate;
231 widget_class->realize = gtk_paned_realize;
232 widget_class->unrealize = gtk_paned_unrealize;
233 widget_class->map = gtk_paned_map;
234 widget_class->unmap = gtk_paned_unmap;
235 widget_class->expose_event = gtk_paned_expose;
236 widget_class->focus = gtk_paned_focus;
237 widget_class->enter_notify_event = gtk_paned_enter;
238 widget_class->leave_notify_event = gtk_paned_leave;
239 widget_class->button_press_event = gtk_paned_button_press;
240 widget_class->button_release_event = gtk_paned_button_release;
241 widget_class->motion_notify_event = gtk_paned_motion;
242 widget_class->grab_broken_event = gtk_paned_grab_broken;
243 widget_class->grab_notify = gtk_paned_grab_notify;
244 widget_class->state_changed = gtk_paned_state_changed;
246 container_class->add = gtk_paned_add;
247 container_class->remove = gtk_paned_remove;
248 container_class->forall = gtk_paned_forall;
249 container_class->child_type = gtk_paned_child_type;
250 container_class->set_focus_child = gtk_paned_set_focus_child;
251 container_class->set_child_property = gtk_paned_set_child_property;
252 container_class->get_child_property = gtk_paned_get_child_property;
254 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
255 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
256 paned_class->move_handle = gtk_paned_move_handle;
257 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
258 paned_class->accept_position = gtk_paned_accept_position;
259 paned_class->cancel_position = gtk_paned_cancel_position;
261 g_object_class_override_property (object_class,
265 g_object_class_install_property (object_class,
267 g_param_spec_int ("position",
269 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
273 GTK_PARAM_READWRITE));
275 g_object_class_install_property (object_class,
277 g_param_spec_boolean ("position-set",
279 P_("TRUE if the Position property should be used"),
281 GTK_PARAM_READWRITE));
283 gtk_widget_class_install_style_property (widget_class,
284 g_param_spec_int ("handle-size",
286 P_("Width of handle"),
290 GTK_PARAM_READABLE));
292 * GtkPaned:min-position:
294 * The smallest possible value for the position property. This property is derived from the
295 * size and shrinkability of the widget's children.
299 g_object_class_install_property (object_class,
301 g_param_spec_int ("min-position",
302 P_("Minimal Position"),
303 P_("Smallest possible value for the \"position\" property"),
307 GTK_PARAM_READABLE));
310 * GtkPaned:max-position:
312 * The largest possible value for the position property. This property is derived from the
313 * size and shrinkability of the widget's children.
317 g_object_class_install_property (object_class,
319 g_param_spec_int ("max-position",
320 P_("Maximal Position"),
321 P_("Largest possible value for the \"position\" property"),
325 GTK_PARAM_READABLE));
330 * The "resize" child property determines whether the child expands and
331 * shrinks along with the paned widget.
335 gtk_container_class_install_child_property (container_class,
337 g_param_spec_boolean ("resize",
339 P_("If TRUE, the child expands and shrinks along with the paned widget"),
341 GTK_PARAM_READWRITE));
346 * The "shrink" child property determines whether the child can be made
347 * smaller than its requisition.
351 gtk_container_class_install_child_property (container_class,
353 g_param_spec_boolean ("shrink",
355 P_("If TRUE, the child can be made smaller than its requisition"),
357 GTK_PARAM_READWRITE));
360 * GtkPaned::cycle-child-focus:
361 * @widget: the object that received the signal
362 * @reversed: whether cycling backward or forward
364 * The ::cycle-child-focus signal is a
365 * <link linkend="keybinding-signals">keybinding signal</link>
366 * which gets emitted to cycle the focus between the children of the paned.
368 * The default binding is f6.
372 signals [CYCLE_CHILD_FOCUS] =
373 g_signal_new (I_("cycle-child-focus"),
374 G_TYPE_FROM_CLASS (object_class),
375 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
376 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
378 _gtk_marshal_BOOLEAN__BOOLEAN,
383 * GtkPaned::toggle-handle-focus:
384 * @widget: the object that received the signal
386 * The ::toggle-handle-focus is a
387 * <link linkend="keybinding-signals">keybinding signal</link>
388 * which gets emitted to accept the current position of the handle and then
389 * move focus to the next widget in the focus chain.
391 * The default binding is Tab.
395 signals [TOGGLE_HANDLE_FOCUS] =
396 g_signal_new (I_("toggle-handle-focus"),
397 G_TYPE_FROM_CLASS (object_class),
398 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
399 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
401 _gtk_marshal_BOOLEAN__VOID,
405 * GtkPaned::move-handle:
406 * @widget: the object that received the signal
407 * @scroll_type: a #GtkScrollType
409 * The ::move-handle signal is a
410 * <link linkend="keybinding-signals">keybinding signal</link>
411 * which gets emitted to move the handle when the user is using key bindings
416 signals[MOVE_HANDLE] =
417 g_signal_new (I_("move-handle"),
418 G_TYPE_FROM_CLASS (object_class),
419 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
420 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
422 _gtk_marshal_BOOLEAN__ENUM,
424 GTK_TYPE_SCROLL_TYPE);
427 * GtkPaned::cycle-handle-focus:
428 * @widget: the object that received the signal
429 * @reversed: whether cycling backward or forward
431 * The ::cycle-handle-focus signal is a
432 * <link linkend="keybinding-signals">keybinding signal</link>
433 * which gets emitted to cycle whether the paned should grab focus to allow
434 * the user to change position of the handle by using key bindings.
436 * The default binding for this signal is f8.
440 signals [CYCLE_HANDLE_FOCUS] =
441 g_signal_new (I_("cycle-handle-focus"),
442 G_TYPE_FROM_CLASS (object_class),
443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
444 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
446 _gtk_marshal_BOOLEAN__BOOLEAN,
451 * GtkPaned::accept-position:
452 * @widget: the object that received the signal
454 * The ::accept-position signal is a
455 * <link linkend="keybinding-signals">keybinding signal</link>
456 * which gets emitted to accept the current position of the handle when
457 * moving it using key bindings.
459 * The default binding for this signal is Return or Space.
463 signals [ACCEPT_POSITION] =
464 g_signal_new (I_("accept-position"),
465 G_TYPE_FROM_CLASS (object_class),
466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
467 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
469 _gtk_marshal_BOOLEAN__VOID,
473 * GtkPaned::cancel-position:
474 * @widget: the object that received the signal
476 * The ::cancel-position signal is a
477 * <link linkend="keybinding-signals">keybinding signal</link>
478 * which gets emitted to cancel moving the position of the handle using key
479 * bindings. The position of the handle will be reset to the value prior to
482 * The default binding for this signal is Escape.
486 signals [CANCEL_POSITION] =
487 g_signal_new (I_("cancel-position"),
488 G_TYPE_FROM_CLASS (object_class),
489 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
490 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
492 _gtk_marshal_BOOLEAN__VOID,
495 binding_set = gtk_binding_set_by_class (class);
498 gtk_binding_entry_add_signal (binding_set,
500 "cycle-child-focus", 1,
501 G_TYPE_BOOLEAN, FALSE);
502 gtk_binding_entry_add_signal (binding_set,
503 GDK_F6, GDK_SHIFT_MASK,
504 "cycle-child-focus", 1,
505 G_TYPE_BOOLEAN, TRUE);
508 gtk_binding_entry_add_signal (binding_set,
510 "cycle-handle-focus", 1,
511 G_TYPE_BOOLEAN, FALSE);
513 gtk_binding_entry_add_signal (binding_set,
514 GDK_F8, GDK_SHIFT_MASK,
515 "cycle-handle-focus", 1,
516 G_TYPE_BOOLEAN, TRUE);
518 add_tab_bindings (binding_set, 0);
519 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
520 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
521 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
523 /* accept and cancel positions */
524 gtk_binding_entry_add_signal (binding_set,
526 "cancel-position", 0);
528 gtk_binding_entry_add_signal (binding_set,
530 "accept-position", 0);
531 gtk_binding_entry_add_signal (binding_set,
533 "accept-position", 0);
534 gtk_binding_entry_add_signal (binding_set,
536 "accept-position", 0);
537 gtk_binding_entry_add_signal (binding_set,
539 "accept-position", 0);
540 gtk_binding_entry_add_signal (binding_set,
542 "accept-position", 0);
545 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
546 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
547 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
548 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
550 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
551 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
552 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
553 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
555 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
556 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
557 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
558 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
559 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
560 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
562 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
563 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
564 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
565 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
566 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
567 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
569 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
570 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
571 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
572 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
574 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
578 gtk_paned_child_type (GtkContainer *container)
580 GtkPaned *paned = GTK_PANED (container);
581 GtkPanedPrivate *priv = paned->priv;
583 if (!priv->child1 || !priv->child2)
584 return GTK_TYPE_WIDGET;
590 gtk_paned_init (GtkPaned *paned)
592 GtkPanedPrivate *priv;
594 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
595 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
597 /* We only need to redraw when the handle position moves, which is
598 * independent of the overall allocation of the GtkPaned
600 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
602 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
605 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
606 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
611 priv->cursor_type = GDK_CROSS;
613 priv->handle_pos.width = 5;
614 priv->handle_pos.height = 5;
615 priv->position_set = FALSE;
616 priv->last_allocation = -1;
617 priv->in_drag = FALSE;
619 priv->last_child1_focus = NULL;
620 priv->last_child2_focus = NULL;
621 priv->in_recursion = FALSE;
622 priv->handle_prelit = FALSE;
623 priv->original_position = -1;
625 priv->handle_pos.x = -1;
626 priv->handle_pos.y = -1;
632 gtk_paned_set_property (GObject *object,
637 GtkPaned *paned = GTK_PANED (object);
638 GtkPanedPrivate *priv = paned->priv;
642 case PROP_ORIENTATION:
643 priv->orientation = g_value_get_enum (value);
645 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
646 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
648 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
650 /* state_changed updates the cursor */
651 gtk_paned_state_changed (GTK_WIDGET (paned), gtk_widget_get_state (GTK_WIDGET (paned)));
652 gtk_widget_queue_resize (GTK_WIDGET (paned));
655 gtk_paned_set_position (paned, g_value_get_int (value));
657 case PROP_POSITION_SET:
658 priv->position_set = g_value_get_boolean (value);
659 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
662 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668 gtk_paned_get_property (GObject *object,
673 GtkPaned *paned = GTK_PANED (object);
674 GtkPanedPrivate *priv = paned->priv;
678 case PROP_ORIENTATION:
679 g_value_set_enum (value, priv->orientation);
682 g_value_set_int (value, priv->child1_size);
684 case PROP_POSITION_SET:
685 g_value_set_boolean (value, priv->position_set);
687 case PROP_MIN_POSITION:
688 g_value_set_int (value, priv->min_position);
690 case PROP_MAX_POSITION:
691 g_value_set_int (value, priv->max_position);
694 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
700 gtk_paned_set_child_property (GtkContainer *container,
706 GtkPaned *paned = GTK_PANED (container);
707 GtkPanedPrivate *priv = paned->priv;
708 gboolean old_value, new_value;
710 g_assert (child == priv->child1 || child == priv->child2);
712 new_value = g_value_get_boolean (value);
715 case CHILD_PROP_RESIZE:
716 if (child == priv->child1)
718 old_value = priv->child1_resize;
719 priv->child1_resize = new_value;
723 old_value = priv->child2_resize;
724 priv->child2_resize = new_value;
727 case CHILD_PROP_SHRINK:
728 if (child == priv->child1)
730 old_value = priv->child1_shrink;
731 priv->child1_shrink = new_value;
735 old_value = priv->child2_shrink;
736 priv->child2_shrink = new_value;
740 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
741 old_value = -1; /* quiet gcc */
744 if (old_value != new_value)
745 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
749 gtk_paned_get_child_property (GtkContainer *container,
755 GtkPaned *paned = GTK_PANED (container);
756 GtkPanedPrivate *priv = paned->priv;
758 g_assert (child == priv->child1 || child == priv->child2);
762 case CHILD_PROP_RESIZE:
763 if (child == priv->child1)
764 g_value_set_boolean (value, priv->child1_resize);
766 g_value_set_boolean (value, priv->child2_resize);
768 case CHILD_PROP_SHRINK:
769 if (child == priv->child1)
770 g_value_set_boolean (value, priv->child1_shrink);
772 g_value_set_boolean (value, priv->child2_shrink);
775 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
781 gtk_paned_finalize (GObject *object)
783 GtkPaned *paned = GTK_PANED (object);
785 gtk_paned_set_saved_focus (paned, NULL);
786 gtk_paned_set_first_paned (paned, NULL);
788 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
792 gtk_paned_size_request (GtkWidget *widget,
793 GtkRequisition *requisition)
795 GtkPaned *paned = GTK_PANED (widget);
796 GtkPanedPrivate *priv = paned->priv;
797 GtkRequisition child_requisition;
800 requisition->width = 0;
801 requisition->height = 0;
803 if (priv->child1 && gtk_widget_get_visible (priv->child1))
805 gtk_widget_size_request (priv->child1, &child_requisition);
807 requisition->height = child_requisition.height;
808 requisition->width = child_requisition.width;
811 if (priv->child2 && gtk_widget_get_visible (priv->child2))
813 gtk_widget_size_request (priv->child2, &child_requisition);
815 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
817 requisition->height = MAX (requisition->height,
818 child_requisition.height);
819 requisition->width += child_requisition.width;
823 requisition->width = MAX (requisition->width,
824 child_requisition.width);
825 requisition->height += child_requisition.height;
829 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
830 requisition->width += border_width * 2;
831 requisition->height += border_width * 2;
833 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
834 priv->child2 && gtk_widget_get_visible (priv->child2))
838 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
840 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
841 requisition->width += handle_size;
843 requisition->height += handle_size;
848 flip_child (GtkWidget *widget,
849 GtkAllocation *child_pos)
851 GtkAllocation allocation;
854 gtk_widget_get_allocation (widget, &allocation);
856 width = allocation.width;
858 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
862 gtk_paned_size_allocate (GtkWidget *widget,
863 GtkAllocation *allocation)
865 GtkPaned *paned = GTK_PANED (widget);
866 GtkPanedPrivate *priv = paned->priv;
867 GtkAllocation widget_allocation;
870 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
872 gtk_widget_set_allocation (widget, allocation);
874 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
875 priv->child2 && gtk_widget_get_visible (priv->child2))
877 GtkRequisition child1_requisition;
878 GtkRequisition child2_requisition;
879 GtkAllocation child1_allocation;
880 GtkAllocation child2_allocation;
881 GtkAllocation priv_child1_allocation;
882 GdkRectangle old_handle_pos;
885 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
887 gtk_widget_get_child_requisition (priv->child1, &child1_requisition);
888 gtk_widget_get_child_requisition (priv->child2, &child2_requisition);
890 old_handle_pos = priv->handle_pos;
892 gtk_widget_get_allocation (widget, &widget_allocation);
894 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
896 gtk_paned_calc_position (paned,
897 MAX (1, widget_allocation.width
900 child1_requisition.width,
901 child2_requisition.width);
903 priv->handle_pos.x = widget_allocation.x + priv->child1_size + border_width;
904 priv->handle_pos.y = widget_allocation.y + border_width;
905 priv->handle_pos.width = handle_size;
906 priv->handle_pos.height = MAX (1, widget_allocation.height - 2 * border_width);
908 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
909 child1_allocation.width = MAX (1, priv->child1_size);
910 child1_allocation.x = widget_allocation.x + border_width;
911 child1_allocation.y = child2_allocation.y = widget_allocation.y + border_width;
913 child2_allocation.x = child1_allocation.x + priv->child1_size + priv->handle_pos.width;
914 child2_allocation.width = MAX (1, widget_allocation.x + widget_allocation.width - child2_allocation.x - border_width);
916 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
918 flip_child (widget, &(child2_allocation));
919 flip_child (widget, &(child1_allocation));
920 flip_child (widget, &(priv->handle_pos));
925 gtk_paned_calc_position (paned,
926 MAX (1, widget_allocation.height
929 child1_requisition.height,
930 child2_requisition.height);
932 priv->handle_pos.x = widget_allocation.x + border_width;
933 priv->handle_pos.y = widget_allocation.y + priv->child1_size + border_width;
934 priv->handle_pos.width = MAX (1, (gint) widget_allocation.width - 2 * border_width);
935 priv->handle_pos.height = handle_size;
937 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
938 child1_allocation.height = MAX (1, priv->child1_size);
939 child1_allocation.x = child2_allocation.x = widget_allocation.x + border_width;
940 child1_allocation.y = widget_allocation.y + border_width;
942 child2_allocation.y = child1_allocation.y + priv->child1_size + priv->handle_pos.height;
943 child2_allocation.height = MAX (1, widget_allocation.y + widget_allocation.height - child2_allocation.y - border_width);
946 if (gtk_widget_get_mapped (widget) &&
947 (old_handle_pos.x != priv->handle_pos.x ||
948 old_handle_pos.y != priv->handle_pos.y ||
949 old_handle_pos.width != priv->handle_pos.width ||
950 old_handle_pos.height != priv->handle_pos.height))
954 window = gtk_widget_get_window (widget);
955 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
956 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
959 if (gtk_widget_get_realized (widget))
961 if (gtk_widget_get_mapped (widget))
962 gdk_window_show (priv->handle);
964 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
966 gdk_window_move_resize (priv->handle,
970 priv->handle_pos.height);
974 gdk_window_move_resize (priv->handle,
977 priv->handle_pos.width,
982 /* Now allocate the childen, making sure, when resizing not to
983 * overlap the windows
985 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
986 if (gtk_widget_get_mapped (widget) &&
987 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
988 priv_child1_allocation.width < child1_allocation.width) ||
990 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
991 priv_child1_allocation.height < child1_allocation.height)))
993 gtk_widget_size_allocate (priv->child2, &child2_allocation);
994 gtk_widget_size_allocate (priv->child1, &child1_allocation);
998 gtk_widget_size_allocate (priv->child1, &child1_allocation);
999 gtk_widget_size_allocate (priv->child2, &child2_allocation);
1004 GtkAllocation child_allocation;
1006 if (gtk_widget_get_realized (widget))
1007 gdk_window_hide (priv->handle);
1010 gtk_widget_set_child_visible (priv->child1, TRUE);
1012 gtk_widget_set_child_visible (priv->child2, TRUE);
1014 gtk_widget_get_allocation (widget, &widget_allocation);
1016 child_allocation.x = widget_allocation.x + border_width;
1017 child_allocation.y = widget_allocation.y + border_width;
1018 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
1019 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
1021 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1022 gtk_widget_size_allocate (priv->child1, &child_allocation);
1023 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1024 gtk_widget_size_allocate (priv->child2, &child_allocation);
1029 gtk_paned_realize (GtkWidget *widget)
1031 GtkPaned *paned = GTK_PANED (widget);
1032 GtkPanedPrivate *priv = paned->priv;
1034 GdkWindowAttr attributes;
1035 gint attributes_mask;
1037 gtk_widget_set_realized (widget, TRUE);
1039 window = gtk_widget_get_parent_window (widget);
1040 gtk_widget_set_window (widget, window);
1041 g_object_ref (window);
1043 attributes.window_type = GDK_WINDOW_CHILD;
1044 attributes.wclass = GDK_INPUT_ONLY;
1045 attributes.x = priv->handle_pos.x;
1046 attributes.y = priv->handle_pos.y;
1047 attributes.width = priv->handle_pos.width;
1048 attributes.height = priv->handle_pos.height;
1049 attributes.event_mask = gtk_widget_get_events (widget);
1050 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1051 GDK_BUTTON_RELEASE_MASK |
1052 GDK_ENTER_NOTIFY_MASK |
1053 GDK_LEAVE_NOTIFY_MASK |
1054 GDK_POINTER_MOTION_MASK |
1055 GDK_POINTER_MOTION_HINT_MASK);
1056 attributes_mask = GDK_WA_X | GDK_WA_Y;
1057 if (gtk_widget_is_sensitive (widget))
1059 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1061 attributes_mask |= GDK_WA_CURSOR;
1064 priv->handle = gdk_window_new (window,
1065 &attributes, attributes_mask);
1066 gdk_window_set_user_data (priv->handle, paned);
1067 if (attributes_mask & GDK_WA_CURSOR)
1068 gdk_cursor_unref (attributes.cursor);
1070 gtk_widget_style_attach (widget);
1072 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1073 priv->child2 && gtk_widget_get_visible (priv->child2))
1074 gdk_window_show (priv->handle);
1078 gtk_paned_unrealize (GtkWidget *widget)
1080 GtkPaned *paned = GTK_PANED (widget);
1081 GtkPanedPrivate *priv = paned->priv;
1085 gdk_window_set_user_data (priv->handle, NULL);
1086 gdk_window_destroy (priv->handle);
1087 priv->handle = NULL;
1090 gtk_paned_set_last_child1_focus (paned, NULL);
1091 gtk_paned_set_last_child2_focus (paned, NULL);
1092 gtk_paned_set_saved_focus (paned, NULL);
1093 gtk_paned_set_first_paned (paned, NULL);
1095 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1099 gtk_paned_map (GtkWidget *widget)
1101 GtkPaned *paned = GTK_PANED (widget);
1102 GtkPanedPrivate *priv = paned->priv;
1104 gdk_window_show (priv->handle);
1106 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1110 gtk_paned_unmap (GtkWidget *widget)
1112 GtkPaned *paned = GTK_PANED (widget);
1113 GtkPanedPrivate *priv = paned->priv;
1115 gdk_window_hide (priv->handle);
1117 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1121 gtk_paned_expose (GtkWidget *widget,
1122 GdkEventExpose *event)
1124 GtkPaned *paned = GTK_PANED (widget);
1125 GtkPanedPrivate *priv = paned->priv;
1127 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1128 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1129 priv->child2 && gtk_widget_get_visible (priv->child2))
1133 if (gtk_widget_is_focus (widget))
1134 state = GTK_STATE_SELECTED;
1135 else if (priv->handle_prelit)
1136 state = GTK_STATE_PRELIGHT;
1138 state = gtk_widget_get_state (widget);
1140 gtk_paint_handle (gtk_widget_get_style (widget),
1141 gtk_widget_get_window (widget),
1142 state, GTK_SHADOW_NONE,
1143 &priv->handle_pos, widget, "paned",
1144 priv->handle_pos.x, priv->handle_pos.y,
1145 priv->handle_pos.width, priv->handle_pos.height,
1146 !priv->orientation);
1149 /* Chain up to draw children */
1150 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1156 is_rtl (GtkPaned *paned)
1158 GtkPanedPrivate *priv = paned->priv;
1160 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1161 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1170 update_drag (GtkPaned *paned)
1172 GtkPanedPrivate *priv = paned->priv;
1173 GtkAllocation allocation;
1174 GtkWidget *widget = GTK_WIDGET (paned);
1179 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1180 gtk_widget_get_pointer (widget, &pos, NULL);
1182 gtk_widget_get_pointer (widget, NULL, &pos);
1184 pos -= priv->drag_pos;
1188 gtk_widget_style_get (widget,
1189 "handle-size", &handle_size,
1192 gtk_widget_get_allocation (widget, &allocation);
1193 size = allocation.width - pos - handle_size;
1200 size -= gtk_container_get_border_width (GTK_CONTAINER (paned));
1202 size = CLAMP (size, priv->min_position, priv->max_position);
1204 if (size != priv->child1_size)
1205 gtk_paned_set_position (paned, size);
1209 gtk_paned_enter (GtkWidget *widget,
1210 GdkEventCrossing *event)
1212 GtkPaned *paned = GTK_PANED (widget);
1213 GtkPanedPrivate *priv = paned->priv;
1216 update_drag (paned);
1219 priv->handle_prelit = TRUE;
1220 gtk_widget_queue_draw_area (widget,
1223 priv->handle_pos.width,
1224 priv->handle_pos.height);
1231 gtk_paned_leave (GtkWidget *widget,
1232 GdkEventCrossing *event)
1234 GtkPaned *paned = GTK_PANED (widget);
1235 GtkPanedPrivate *priv = paned->priv;
1238 update_drag (paned);
1241 priv->handle_prelit = FALSE;
1242 gtk_widget_queue_draw_area (widget,
1245 priv->handle_pos.width,
1246 priv->handle_pos.height);
1253 gtk_paned_focus (GtkWidget *widget,
1254 GtkDirectionType direction)
1259 /* This is a hack, but how can this be done without
1260 * excessive cut-and-paste from gtkcontainer.c?
1263 gtk_widget_set_can_focus (widget, FALSE);
1264 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1265 gtk_widget_set_can_focus (widget, TRUE);
1271 gtk_paned_button_press (GtkWidget *widget,
1272 GdkEventButton *event)
1274 GtkPaned *paned = GTK_PANED (widget);
1275 GtkPanedPrivate *priv = paned->priv;
1277 if (!priv->in_drag &&
1278 (event->window == priv->handle) && (event->button == 1))
1280 /* We need a server grab here, not gtk_grab_add(), since
1281 * we don't want to pass events on to the widget's children */
1282 if (gdk_device_grab (event->device,
1284 GDK_OWNERSHIP_WINDOW, FALSE,
1285 GDK_POINTER_MOTION_HINT_MASK
1286 | GDK_BUTTON1_MOTION_MASK
1287 | GDK_BUTTON_RELEASE_MASK
1288 | GDK_ENTER_NOTIFY_MASK
1289 | GDK_LEAVE_NOTIFY_MASK,
1290 NULL, event->time) != GDK_GRAB_SUCCESS)
1293 priv->in_drag = TRUE;
1294 priv->grab_time = event->time;
1295 priv->grab_device = event->device;
1297 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1298 priv->drag_pos = event->x;
1300 priv->drag_pos = event->y;
1309 gtk_paned_grab_broken (GtkWidget *widget,
1310 GdkEventGrabBroken *event)
1312 GtkPaned *paned = GTK_PANED (widget);
1313 GtkPanedPrivate *priv = paned->priv;
1315 priv->in_drag = FALSE;
1316 priv->drag_pos = -1;
1317 priv->position_set = TRUE;
1323 stop_drag (GtkPaned *paned)
1325 GtkPanedPrivate *priv = paned->priv;
1327 priv->in_drag = FALSE;
1328 priv->drag_pos = -1;
1329 priv->position_set = TRUE;
1331 gdk_device_ungrab (priv->grab_device,
1333 priv->grab_device = NULL;
1337 gtk_paned_grab_notify (GtkWidget *widget,
1338 gboolean was_grabbed)
1340 GtkPaned *paned = GTK_PANED (widget);
1341 GtkPanedPrivate *priv = paned->priv;
1342 GdkDevice *grab_device;
1344 grab_device = priv->grab_device;
1346 if (priv->in_drag && grab_device &&
1347 gtk_widget_device_is_shadowed (widget, grab_device))
1352 gtk_paned_state_changed (GtkWidget *widget,
1353 GtkStateType previous_state)
1355 GtkPaned *paned = GTK_PANED (widget);
1356 GtkPanedPrivate *priv = paned->priv;
1359 if (gtk_widget_get_realized (widget))
1361 if (gtk_widget_is_sensitive (widget))
1362 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1367 gdk_window_set_cursor (priv->handle, cursor);
1370 gdk_cursor_unref (cursor);
1375 gtk_paned_button_release (GtkWidget *widget,
1376 GdkEventButton *event)
1378 GtkPaned *paned = GTK_PANED (widget);
1379 GtkPanedPrivate *priv = paned->priv;
1381 if (priv->in_drag && (event->button == 1))
1392 gtk_paned_motion (GtkWidget *widget,
1393 GdkEventMotion *event)
1395 GtkPaned *paned = GTK_PANED (widget);
1396 GtkPanedPrivate *priv = paned->priv;
1400 update_drag (paned);
1409 * @orientation: the paned's orientation.
1411 * Creates a new #GtkPaned widget.
1413 * Return value: a new #GtkPaned.
1418 gtk_paned_new (GtkOrientation orientation)
1420 return g_object_new (GTK_TYPE_PANED,
1421 "orientation", orientation,
1426 gtk_paned_add1 (GtkPaned *paned,
1429 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1433 gtk_paned_add2 (GtkPaned *paned,
1436 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1440 gtk_paned_pack1 (GtkPaned *paned,
1445 GtkPanedPrivate *priv;
1447 g_return_if_fail (GTK_IS_PANED (paned));
1448 g_return_if_fail (GTK_IS_WIDGET (child));
1454 priv->child1 = child;
1455 priv->child1_resize = resize;
1456 priv->child1_shrink = shrink;
1458 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1463 gtk_paned_pack2 (GtkPaned *paned,
1468 GtkPanedPrivate *priv;
1470 g_return_if_fail (GTK_IS_PANED (paned));
1471 g_return_if_fail (GTK_IS_WIDGET (child));
1477 priv->child2 = child;
1478 priv->child2_resize = resize;
1479 priv->child2_shrink = shrink;
1481 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1487 gtk_paned_add (GtkContainer *container,
1490 GtkPanedPrivate *priv;
1493 g_return_if_fail (GTK_IS_PANED (container));
1495 paned = GTK_PANED (container);
1499 gtk_paned_add1 (paned, widget);
1500 else if (!priv->child2)
1501 gtk_paned_add2 (paned, widget);
1503 g_warning ("GtkPaned cannot have more than 2 children\n");
1507 gtk_paned_remove (GtkContainer *container,
1510 GtkPaned *paned = GTK_PANED (container);
1511 GtkPanedPrivate *priv = paned->priv;
1512 gboolean was_visible;
1514 was_visible = gtk_widget_get_visible (widget);
1516 if (priv->child1 == widget)
1518 gtk_widget_unparent (widget);
1520 priv->child1 = NULL;
1522 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1523 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1525 else if (priv->child2 == widget)
1527 gtk_widget_unparent (widget);
1529 priv->child2 = NULL;
1531 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1532 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1537 gtk_paned_forall (GtkContainer *container,
1538 gboolean include_internals,
1539 GtkCallback callback,
1540 gpointer callback_data)
1542 GtkPanedPrivate *priv;
1545 g_return_if_fail (callback != NULL);
1547 paned = GTK_PANED (container);
1551 (*callback) (priv->child1, callback_data);
1553 (*callback) (priv->child2, callback_data);
1557 * gtk_paned_get_position:
1558 * @paned: a #GtkPaned widget
1560 * Obtains the position of the divider between the two panes.
1562 * Return value: position of the divider
1565 gtk_paned_get_position (GtkPaned *paned)
1567 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1569 return paned->priv->child1_size;
1573 * gtk_paned_set_position:
1574 * @paned: a #GtkPaned widget
1575 * @position: pixel position of divider, a negative value means that the position
1578 * Sets the position of the divider between the two panes.
1581 gtk_paned_set_position (GtkPaned *paned,
1584 GtkPanedPrivate *priv;
1587 g_return_if_fail (GTK_IS_PANED (paned));
1591 if (priv->child1_size == position)
1594 object = G_OBJECT (paned);
1598 /* We don't clamp here - the assumption is that
1599 * if the total allocation changes at the same time
1600 * as the position, the position set is with reference
1601 * to the new total size. If only the position changes,
1602 * then clamping will occur in gtk_paned_calc_position()
1605 priv->child1_size = position;
1606 priv->position_set = TRUE;
1610 priv->position_set = FALSE;
1613 g_object_freeze_notify (object);
1614 g_object_notify (object, "position");
1615 g_object_notify (object, "position-set");
1616 g_object_thaw_notify (object);
1618 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1621 /* Hacky work-around for bug #144269 */
1622 if (priv->child2 != NULL)
1624 gtk_widget_queue_draw (priv->child2);
1630 * gtk_paned_get_child1:
1631 * @paned: a #GtkPaned widget
1633 * Obtains the first child of the paned widget.
1635 * Return value: first child, or %NULL if it is not set.
1640 gtk_paned_get_child1 (GtkPaned *paned)
1642 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1644 return paned->priv->child1;
1648 * gtk_paned_get_child2:
1649 * @paned: a #GtkPaned widget
1651 * Obtains the second child of the paned widget.
1653 * Return value: second child, or %NULL if it is not set.
1658 gtk_paned_get_child2 (GtkPaned *paned)
1660 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1662 return paned->priv->child2;
1666 gtk_paned_calc_position (GtkPaned *paned,
1671 GtkPanedPrivate *priv = paned->priv;
1673 gint old_min_position;
1674 gint old_max_position;
1676 old_position = priv->child1_size;
1677 old_min_position = priv->min_position;
1678 old_max_position = priv->max_position;
1680 priv->min_position = priv->child1_shrink ? 0 : child1_req;
1682 priv->max_position = allocation;
1683 if (!priv->child2_shrink)
1684 priv->max_position = MAX (1, priv->max_position - child2_req);
1685 priv->max_position = MAX (priv->min_position, priv->max_position);
1687 if (!priv->position_set)
1689 if (priv->child1_resize && !priv->child2_resize)
1690 priv->child1_size = MAX (0, allocation - child2_req);
1691 else if (!priv->child1_resize && priv->child2_resize)
1692 priv->child1_size = child1_req;
1693 else if (child1_req + child2_req != 0)
1694 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1696 priv->child1_size = allocation * 0.5 + 0.5;
1700 /* If the position was set before the initial allocation.
1701 * (priv->last_allocation <= 0) just clamp it and leave it.
1703 if (priv->last_allocation > 0)
1705 if (priv->child1_resize && !priv->child2_resize)
1706 priv->child1_size += allocation - priv->last_allocation;
1707 else if (!(!priv->child1_resize && priv->child2_resize))
1708 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
1712 priv->child1_size = CLAMP (priv->child1_size,
1714 priv->max_position);
1717 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
1720 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
1722 g_object_freeze_notify (G_OBJECT (paned));
1723 if (priv->child1_size != old_position)
1724 g_object_notify (G_OBJECT (paned), "position");
1725 if (priv->min_position != old_min_position)
1726 g_object_notify (G_OBJECT (paned), "min-position");
1727 if (priv->max_position != old_max_position)
1728 g_object_notify (G_OBJECT (paned), "max-position");
1729 g_object_thaw_notify (G_OBJECT (paned));
1731 priv->last_allocation = allocation;
1735 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1737 GtkPanedPrivate *priv = paned->priv;
1739 if (priv->saved_focus)
1740 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
1741 (gpointer *)&(priv->saved_focus));
1743 priv->saved_focus = widget;
1745 if (priv->saved_focus)
1746 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
1747 (gpointer *)&(priv->saved_focus));
1751 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1753 GtkPanedPrivate *priv = paned->priv;
1755 if (priv->first_paned)
1756 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
1757 (gpointer *)&(priv->first_paned));
1759 priv->first_paned = first_paned;
1761 if (priv->first_paned)
1762 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
1763 (gpointer *)&(priv->first_paned));
1767 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1769 GtkPanedPrivate *priv = paned->priv;
1771 if (priv->last_child1_focus)
1772 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
1773 (gpointer *)&(priv->last_child1_focus));
1775 priv->last_child1_focus = widget;
1777 if (priv->last_child1_focus)
1778 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
1779 (gpointer *)&(priv->last_child1_focus));
1783 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1785 GtkPanedPrivate *priv = paned->priv;
1787 if (priv->last_child2_focus)
1788 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
1789 (gpointer *)&(priv->last_child2_focus));
1791 priv->last_child2_focus = widget;
1793 if (priv->last_child2_focus)
1794 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
1795 (gpointer *)&(priv->last_child2_focus));
1799 paned_get_focus_widget (GtkPaned *paned)
1801 GtkWidget *toplevel;
1803 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1804 if (gtk_widget_is_toplevel (toplevel))
1805 return gtk_window_get_focus (GTK_WINDOW (toplevel));
1811 gtk_paned_set_focus_child (GtkContainer *container,
1812 GtkWidget *focus_child)
1815 GtkPanedPrivate *priv;
1816 GtkWidget *container_focus_child;
1818 g_return_if_fail (GTK_IS_PANED (container));
1820 paned = GTK_PANED (container);
1823 if (focus_child == NULL)
1825 GtkWidget *last_focus;
1828 last_focus = paned_get_focus_widget (paned);
1832 /* If there is one or more paned widgets between us and the
1833 * focus widget, we want the topmost of those as last_focus
1835 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
1836 if (GTK_IS_PANED (w))
1839 container_focus_child = gtk_container_get_focus_child (container);
1840 if (container_focus_child == priv->child1)
1841 gtk_paned_set_last_child1_focus (paned, last_focus);
1842 else if (container_focus_child == priv->child2)
1843 gtk_paned_set_last_child2_focus (paned, last_focus);
1847 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1848 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1852 gtk_paned_get_cycle_chain (GtkPaned *paned,
1853 GtkDirectionType direction,
1856 GtkPanedPrivate *priv = paned->priv;
1857 GtkContainer *container = GTK_CONTAINER (paned);
1858 GtkWidget *ancestor = NULL;
1859 GtkWidget *focus_child;
1861 GtkWidget *widget = GTK_WIDGET (paned);
1862 GList *temp_list = NULL;
1865 if (priv->in_recursion)
1868 g_assert (widgets != NULL);
1870 if (priv->last_child1_focus &&
1871 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
1873 gtk_paned_set_last_child1_focus (paned, NULL);
1876 if (priv->last_child2_focus &&
1877 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
1879 gtk_paned_set_last_child2_focus (paned, NULL);
1882 parent = gtk_widget_get_parent (widget);
1884 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
1886 /* The idea here is that temp_list is a list of widgets we want to cycle
1887 * to. The list is prioritized so that the first element is our first
1888 * choice, the next our second, and so on.
1890 * We can't just use g_list_reverse(), because we want to try
1891 * priv->last_child?_focus before priv->child?, both when we
1892 * are going forward and backward.
1894 focus_child = gtk_container_get_focus_child (container);
1895 if (direction == GTK_DIR_TAB_FORWARD)
1897 if (focus_child == priv->child1)
1899 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1900 temp_list = g_list_append (temp_list, priv->child2);
1901 temp_list = g_list_append (temp_list, ancestor);
1903 else if (focus_child == priv->child2)
1905 temp_list = g_list_append (temp_list, ancestor);
1906 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1907 temp_list = g_list_append (temp_list, priv->child1);
1911 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1912 temp_list = g_list_append (temp_list, priv->child1);
1913 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1914 temp_list = g_list_append (temp_list, priv->child2);
1915 temp_list = g_list_append (temp_list, ancestor);
1920 if (focus_child == priv->child1)
1922 temp_list = g_list_append (temp_list, ancestor);
1923 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1924 temp_list = g_list_append (temp_list, priv->child2);
1926 else if (focus_child == priv->child2)
1928 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1929 temp_list = g_list_append (temp_list, priv->child1);
1930 temp_list = g_list_append (temp_list, ancestor);
1934 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1935 temp_list = g_list_append (temp_list, priv->child2);
1936 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1937 temp_list = g_list_append (temp_list, priv->child1);
1938 temp_list = g_list_append (temp_list, ancestor);
1942 /* Walk the list and expand all the paned widgets. */
1943 for (list = temp_list; list != NULL; list = list->next)
1945 GtkWidget *widget = list->data;
1949 if (GTK_IS_PANED (widget))
1951 priv->in_recursion = TRUE;
1952 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1953 priv->in_recursion = FALSE;
1957 *widgets = g_list_append (*widgets, widget);
1962 g_list_free (temp_list);
1966 gtk_paned_cycle_child_focus (GtkPaned *paned,
1969 GList *cycle_chain = NULL;
1972 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1974 /* ignore f6 if the handle is focused */
1975 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1978 /* we can't just let the event propagate up the hierarchy,
1979 * because the paned will want to cycle focus _unless_ an
1980 * ancestor paned handles the event
1982 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1984 for (list = cycle_chain; list != NULL; list = list->next)
1985 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1988 g_list_free (cycle_chain);
1994 get_child_panes (GtkWidget *widget,
1997 if (!widget || !gtk_widget_get_realized (widget))
2000 if (GTK_IS_PANED (widget))
2002 GtkPaned *paned = GTK_PANED (widget);
2003 GtkPanedPrivate *priv = paned->priv;
2005 get_child_panes (priv->child1, panes);
2006 *panes = g_list_prepend (*panes, widget);
2007 get_child_panes (priv->child2, panes);
2009 else if (GTK_IS_CONTAINER (widget))
2011 gtk_container_forall (GTK_CONTAINER (widget),
2012 (GtkCallback)get_child_panes, panes);
2017 get_all_panes (GtkPaned *paned)
2019 GtkPaned *topmost = NULL;
2020 GList *result = NULL;
2023 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2025 if (GTK_IS_PANED (w))
2026 topmost = GTK_PANED (w);
2031 get_child_panes (GTK_WIDGET (topmost), &result);
2033 return g_list_reverse (result);
2037 gtk_paned_find_neighbours (GtkPaned *paned,
2044 all_panes = get_all_panes (paned);
2045 g_assert (all_panes);
2047 this_link = g_list_find (all_panes, paned);
2049 g_assert (this_link);
2051 if (this_link->next)
2052 *next = this_link->next->data;
2054 *next = all_panes->data;
2056 if (this_link->prev)
2057 *prev = this_link->prev->data;
2059 *prev = g_list_last (all_panes)->data;
2061 g_list_free (all_panes);
2065 gtk_paned_move_handle (GtkPaned *paned,
2066 GtkScrollType scroll)
2068 GtkPanedPrivate *priv = paned->priv;
2070 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2077 SINGLE_STEP_SIZE = 1,
2081 new_position = old_position = gtk_paned_get_position (paned);
2086 case GTK_SCROLL_STEP_LEFT:
2087 case GTK_SCROLL_STEP_UP:
2088 case GTK_SCROLL_STEP_BACKWARD:
2089 increment = - SINGLE_STEP_SIZE;
2092 case GTK_SCROLL_STEP_RIGHT:
2093 case GTK_SCROLL_STEP_DOWN:
2094 case GTK_SCROLL_STEP_FORWARD:
2095 increment = SINGLE_STEP_SIZE;
2098 case GTK_SCROLL_PAGE_LEFT:
2099 case GTK_SCROLL_PAGE_UP:
2100 case GTK_SCROLL_PAGE_BACKWARD:
2101 increment = - PAGE_STEP_SIZE;
2104 case GTK_SCROLL_PAGE_RIGHT:
2105 case GTK_SCROLL_PAGE_DOWN:
2106 case GTK_SCROLL_PAGE_FORWARD:
2107 increment = PAGE_STEP_SIZE;
2110 case GTK_SCROLL_START:
2111 new_position = priv->min_position;
2114 case GTK_SCROLL_END:
2115 new_position = priv->max_position;
2125 increment = -increment;
2127 new_position = old_position + increment;
2130 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2132 if (old_position != new_position)
2133 gtk_paned_set_position (paned, new_position);
2142 gtk_paned_restore_focus (GtkPaned *paned)
2144 GtkPanedPrivate *priv = paned->priv;
2146 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2148 if (priv->saved_focus &&
2149 gtk_widget_get_sensitive (priv->saved_focus))
2151 gtk_widget_grab_focus (priv->saved_focus);
2155 /* the saved focus is somehow not available for focusing,
2157 * 1) tabbing into the paned widget
2158 * if that didn't work,
2159 * 2) unset focus for the window if there is one
2162 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2164 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2166 if (GTK_IS_WINDOW (toplevel))
2167 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2171 gtk_paned_set_saved_focus (paned, NULL);
2172 gtk_paned_set_first_paned (paned, NULL);
2177 gtk_paned_accept_position (GtkPaned *paned)
2179 GtkPanedPrivate *priv = paned->priv;
2181 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2183 priv->original_position = -1;
2184 gtk_paned_restore_focus (paned);
2194 gtk_paned_cancel_position (GtkPaned *paned)
2196 GtkPanedPrivate *priv = paned->priv;
2198 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2200 if (priv->original_position != -1)
2202 gtk_paned_set_position (paned, priv->original_position);
2203 priv->original_position = -1;
2206 gtk_paned_restore_focus (paned);
2214 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2217 GtkPanedPrivate *priv = paned->priv;
2218 GtkPaned *next, *prev;
2220 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2222 GtkPaned *focus = NULL;
2224 if (!priv->first_paned)
2226 /* The first_pane has disappeared. As an ad-hoc solution,
2227 * we make the currently focused paned the first_paned. To the
2228 * user this will seem like the paned cycling has been reset.
2231 gtk_paned_set_first_paned (paned, paned);
2234 gtk_paned_find_neighbours (paned, &next, &prev);
2236 if (reversed && prev &&
2237 prev != paned && paned != priv->first_paned)
2241 else if (!reversed && next &&
2242 next != paned && next != priv->first_paned)
2248 gtk_paned_accept_position (paned);
2254 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2255 gtk_paned_set_first_paned (focus, priv->first_paned);
2257 gtk_paned_set_saved_focus (paned, NULL);
2258 gtk_paned_set_first_paned (paned, NULL);
2260 gtk_widget_grab_focus (GTK_WIDGET (focus));
2262 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2264 priv->original_position = -1;
2265 focus->priv->original_position = gtk_paned_get_position (focus);
2270 GtkContainer *container = GTK_CONTAINER (paned);
2273 GtkPaned *prev, *next;
2274 GtkWidget *toplevel;
2275 GtkWidget *focus_child;
2277 gtk_paned_find_neighbours (paned, &next, &prev);
2278 focus_child = gtk_container_get_focus_child (container);
2280 if (focus_child == priv->child1)
2293 else if (focus_child == priv->child2)
2308 /* Focus is not inside this paned, and we don't have focus.
2309 * Presumably this happened because the application wants us
2310 * to start keyboard navigating.
2320 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2322 if (GTK_IS_WINDOW (toplevel))
2323 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2324 gtk_paned_set_first_paned (focus, first);
2325 focus->priv->original_position = gtk_paned_get_position (focus);
2327 gtk_widget_grab_focus (GTK_WIDGET (focus));
2334 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2336 /* This function/signal has the wrong name. It is called when you
2337 * press Tab or Shift-Tab and what we do is act as if
2338 * the user pressed Return and then Tab or Shift-Tab
2340 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2341 gtk_paned_accept_position (paned);
2347 * gtk_paned_get_handle_window:
2348 * @paned: a #GtkPaned
2350 * Returns the #GdkWindow of the handle. This function is
2351 * useful when handling button or motion events because it
2352 * enables the callback to distinguish between the window
2353 * of the paned, a child and the handle.
2355 * Return value: the paned's handle window.
2360 gtk_paned_get_handle_window (GtkPaned *paned)
2362 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2364 return paned->priv->handle;