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"
65 static void gtk_paned_set_property (GObject *object,
69 static void gtk_paned_get_property (GObject *object,
73 static void gtk_paned_set_child_property (GtkContainer *container,
78 static void gtk_paned_get_child_property (GtkContainer *container,
83 static void gtk_paned_finalize (GObject *object);
85 static void gtk_paned_size_request (GtkWidget *widget,
86 GtkRequisition *requisition);
87 static void gtk_paned_size_allocate (GtkWidget *widget,
88 GtkAllocation *allocation);
89 static void gtk_paned_realize (GtkWidget *widget);
90 static void gtk_paned_unrealize (GtkWidget *widget);
91 static void gtk_paned_map (GtkWidget *widget);
92 static void gtk_paned_unmap (GtkWidget *widget);
93 static void gtk_paned_state_changed (GtkWidget *widget,
94 GtkStateType previous_state);
95 static gboolean gtk_paned_expose (GtkWidget *widget,
96 GdkEventExpose *event);
97 static gboolean gtk_paned_enter (GtkWidget *widget,
98 GdkEventCrossing *event);
99 static gboolean gtk_paned_leave (GtkWidget *widget,
100 GdkEventCrossing *event);
101 static gboolean gtk_paned_button_press (GtkWidget *widget,
102 GdkEventButton *event);
103 static gboolean gtk_paned_button_release (GtkWidget *widget,
104 GdkEventButton *event);
105 static gboolean gtk_paned_motion (GtkWidget *widget,
106 GdkEventMotion *event);
107 static gboolean gtk_paned_focus (GtkWidget *widget,
108 GtkDirectionType direction);
109 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
110 GdkEventGrabBroken *event);
111 static void gtk_paned_add (GtkContainer *container,
113 static void gtk_paned_remove (GtkContainer *container,
115 static void gtk_paned_forall (GtkContainer *container,
116 gboolean include_internals,
117 GtkCallback callback,
118 gpointer callback_data);
119 static void gtk_paned_calc_position (GtkPaned *paned,
123 static void gtk_paned_set_focus_child (GtkContainer *container,
125 static void gtk_paned_set_saved_focus (GtkPaned *paned,
127 static void gtk_paned_set_first_paned (GtkPaned *paned,
128 GtkPaned *first_paned);
129 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
131 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
133 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
135 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
137 static gboolean gtk_paned_move_handle (GtkPaned *paned,
138 GtkScrollType scroll);
139 static gboolean gtk_paned_accept_position (GtkPaned *paned);
140 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
141 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
143 static GType gtk_paned_child_type (GtkContainer *container);
144 static void gtk_paned_grab_notify (GtkWidget *widget,
145 gboolean was_grabbed);
147 struct _GtkPanedPrivate
149 GtkOrientation orientation;
150 GtkWidget *saved_focus;
151 GtkPaned *first_paned;
153 GdkDevice *grab_device;
157 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
158 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
161 static guint signals[LAST_SIGNAL] = { 0 };
165 add_tab_bindings (GtkBindingSet *binding_set,
166 GdkModifierType modifiers)
168 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
169 "toggle-handle-focus", 0);
170 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
171 "toggle-handle-focus", 0);
175 add_move_binding (GtkBindingSet *binding_set,
177 GdkModifierType mask,
178 GtkScrollType scroll)
180 gtk_binding_entry_add_signal (binding_set, keyval, mask,
182 GTK_TYPE_SCROLL_TYPE, scroll);
186 gtk_paned_class_init (GtkPanedClass *class)
188 GObjectClass *object_class;
189 GtkWidgetClass *widget_class;
190 GtkContainerClass *container_class;
191 GtkPanedClass *paned_class;
192 GtkBindingSet *binding_set;
194 object_class = (GObjectClass *) class;
195 widget_class = (GtkWidgetClass *) class;
196 container_class = (GtkContainerClass *) class;
197 paned_class = (GtkPanedClass *) class;
199 object_class->set_property = gtk_paned_set_property;
200 object_class->get_property = gtk_paned_get_property;
201 object_class->finalize = gtk_paned_finalize;
203 widget_class->size_request = gtk_paned_size_request;
204 widget_class->size_allocate = gtk_paned_size_allocate;
205 widget_class->realize = gtk_paned_realize;
206 widget_class->unrealize = gtk_paned_unrealize;
207 widget_class->map = gtk_paned_map;
208 widget_class->unmap = gtk_paned_unmap;
209 widget_class->expose_event = gtk_paned_expose;
210 widget_class->focus = gtk_paned_focus;
211 widget_class->enter_notify_event = gtk_paned_enter;
212 widget_class->leave_notify_event = gtk_paned_leave;
213 widget_class->button_press_event = gtk_paned_button_press;
214 widget_class->button_release_event = gtk_paned_button_release;
215 widget_class->motion_notify_event = gtk_paned_motion;
216 widget_class->grab_broken_event = gtk_paned_grab_broken;
217 widget_class->grab_notify = gtk_paned_grab_notify;
218 widget_class->state_changed = gtk_paned_state_changed;
220 container_class->add = gtk_paned_add;
221 container_class->remove = gtk_paned_remove;
222 container_class->forall = gtk_paned_forall;
223 container_class->child_type = gtk_paned_child_type;
224 container_class->set_focus_child = gtk_paned_set_focus_child;
225 container_class->set_child_property = gtk_paned_set_child_property;
226 container_class->get_child_property = gtk_paned_get_child_property;
228 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
229 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
230 paned_class->move_handle = gtk_paned_move_handle;
231 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
232 paned_class->accept_position = gtk_paned_accept_position;
233 paned_class->cancel_position = gtk_paned_cancel_position;
235 g_object_class_override_property (object_class,
239 g_object_class_install_property (object_class,
241 g_param_spec_int ("position",
243 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
247 GTK_PARAM_READWRITE));
249 g_object_class_install_property (object_class,
251 g_param_spec_boolean ("position-set",
253 P_("TRUE if the Position property should be used"),
255 GTK_PARAM_READWRITE));
257 gtk_widget_class_install_style_property (widget_class,
258 g_param_spec_int ("handle-size",
260 P_("Width of handle"),
264 GTK_PARAM_READABLE));
266 * GtkPaned:min-position:
268 * The smallest possible value for the position property. This property is derived from the
269 * size and shrinkability of the widget's children.
273 g_object_class_install_property (object_class,
275 g_param_spec_int ("min-position",
276 P_("Minimal Position"),
277 P_("Smallest possible value for the \"position\" property"),
281 GTK_PARAM_READABLE));
284 * GtkPaned:max-position:
286 * The largest possible value for the position property. This property is derived from the
287 * size and shrinkability of the widget's children.
291 g_object_class_install_property (object_class,
293 g_param_spec_int ("max-position",
294 P_("Maximal Position"),
295 P_("Largest possible value for the \"position\" property"),
299 GTK_PARAM_READABLE));
304 * The "resize" child property determines whether the child expands and
305 * shrinks along with the paned widget.
309 gtk_container_class_install_child_property (container_class,
311 g_param_spec_boolean ("resize",
313 P_("If TRUE, the child expands and shrinks along with the paned widget"),
315 GTK_PARAM_READWRITE));
320 * The "shrink" child property determines whether the child can be made
321 * smaller than its requisition.
325 gtk_container_class_install_child_property (container_class,
327 g_param_spec_boolean ("shrink",
329 P_("If TRUE, the child can be made smaller than its requisition"),
331 GTK_PARAM_READWRITE));
334 * GtkPaned::cycle-child-focus:
335 * @widget: the object that received the signal
336 * @reversed: whether cycling backward or forward
338 * The ::cycle-child-focus signal is a
339 * <link linkend="keybinding-signals">keybinding signal</link>
340 * which gets emitted to cycle the focus between the children of the paned.
342 * The default binding is f6.
346 signals [CYCLE_CHILD_FOCUS] =
347 g_signal_new (I_("cycle-child-focus"),
348 G_TYPE_FROM_CLASS (object_class),
349 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
350 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
352 _gtk_marshal_BOOLEAN__BOOLEAN,
357 * GtkPaned::toggle-handle-focus:
358 * @widget: the object that received the signal
360 * The ::toggle-handle-focus is a
361 * <link linkend="keybinding-signals">keybinding signal</link>
362 * which gets emitted to accept the current position of the handle and then
363 * move focus to the next widget in the focus chain.
365 * The default binding is Tab.
369 signals [TOGGLE_HANDLE_FOCUS] =
370 g_signal_new (I_("toggle-handle-focus"),
371 G_TYPE_FROM_CLASS (object_class),
372 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
373 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
375 _gtk_marshal_BOOLEAN__VOID,
379 * GtkPaned::move-handle:
380 * @widget: the object that received the signal
381 * @scroll_type: a #GtkScrollType
383 * The ::move-handle signal is a
384 * <link linkend="keybinding-signals">keybinding signal</link>
385 * which gets emitted to move the handle when the user is using key bindings
390 signals[MOVE_HANDLE] =
391 g_signal_new (I_("move-handle"),
392 G_TYPE_FROM_CLASS (object_class),
393 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
394 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
396 _gtk_marshal_BOOLEAN__ENUM,
398 GTK_TYPE_SCROLL_TYPE);
401 * GtkPaned::cycle-handle-focus:
402 * @widget: the object that received the signal
403 * @reversed: whether cycling backward or forward
405 * The ::cycle-handle-focus signal is a
406 * <link linkend="keybinding-signals">keybinding signal</link>
407 * which gets emitted to cycle whether the paned should grab focus to allow
408 * the user to change position of the handle by using key bindings.
410 * The default binding for this signal is f8.
414 signals [CYCLE_HANDLE_FOCUS] =
415 g_signal_new (I_("cycle-handle-focus"),
416 G_TYPE_FROM_CLASS (object_class),
417 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
418 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
420 _gtk_marshal_BOOLEAN__BOOLEAN,
425 * GtkPaned::accept-position:
426 * @widget: the object that received the signal
428 * The ::accept-position signal is a
429 * <link linkend="keybinding-signals">keybinding signal</link>
430 * which gets emitted to accept the current position of the handle when
431 * moving it using key bindings.
433 * The default binding for this signal is Return or Space.
437 signals [ACCEPT_POSITION] =
438 g_signal_new (I_("accept-position"),
439 G_TYPE_FROM_CLASS (object_class),
440 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
441 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
443 _gtk_marshal_BOOLEAN__VOID,
447 * GtkPaned::cancel-position:
448 * @widget: the object that received the signal
450 * The ::cancel-position signal is a
451 * <link linkend="keybinding-signals">keybinding signal</link>
452 * which gets emitted to cancel moving the position of the handle using key
453 * bindings. The position of the handle will be reset to the value prior to
456 * The default binding for this signal is Escape.
460 signals [CANCEL_POSITION] =
461 g_signal_new (I_("cancel-position"),
462 G_TYPE_FROM_CLASS (object_class),
463 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
464 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
466 _gtk_marshal_BOOLEAN__VOID,
469 binding_set = gtk_binding_set_by_class (class);
472 gtk_binding_entry_add_signal (binding_set,
474 "cycle-child-focus", 1,
475 G_TYPE_BOOLEAN, FALSE);
476 gtk_binding_entry_add_signal (binding_set,
477 GDK_F6, GDK_SHIFT_MASK,
478 "cycle-child-focus", 1,
479 G_TYPE_BOOLEAN, TRUE);
482 gtk_binding_entry_add_signal (binding_set,
484 "cycle-handle-focus", 1,
485 G_TYPE_BOOLEAN, FALSE);
487 gtk_binding_entry_add_signal (binding_set,
488 GDK_F8, GDK_SHIFT_MASK,
489 "cycle-handle-focus", 1,
490 G_TYPE_BOOLEAN, TRUE);
492 add_tab_bindings (binding_set, 0);
493 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
494 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
495 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
497 /* accept and cancel positions */
498 gtk_binding_entry_add_signal (binding_set,
500 "cancel-position", 0);
502 gtk_binding_entry_add_signal (binding_set,
504 "accept-position", 0);
505 gtk_binding_entry_add_signal (binding_set,
507 "accept-position", 0);
508 gtk_binding_entry_add_signal (binding_set,
510 "accept-position", 0);
511 gtk_binding_entry_add_signal (binding_set,
513 "accept-position", 0);
514 gtk_binding_entry_add_signal (binding_set,
516 "accept-position", 0);
519 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
520 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
521 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
522 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
524 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
525 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
526 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
527 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
529 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
530 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
531 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
532 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
533 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
534 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
536 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
537 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
538 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
539 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
540 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
541 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
543 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
544 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
545 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
546 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
548 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
552 gtk_paned_child_type (GtkContainer *container)
554 if (!GTK_PANED (container)->child1 || !GTK_PANED (container)->child2)
555 return GTK_TYPE_WIDGET;
561 gtk_paned_init (GtkPaned *paned)
563 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
564 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
566 /* We only need to redraw when the handle position moves, which is
567 * independent of the overall allocation of the GtkPaned
569 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
571 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
573 paned->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
574 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
576 paned->child1 = NULL;
577 paned->child2 = NULL;
578 paned->handle = NULL;
579 paned->xor_gc = NULL;
580 paned->cursor_type = GDK_CROSS;
582 paned->handle_pos.width = 5;
583 paned->handle_pos.height = 5;
584 paned->position_set = FALSE;
585 paned->last_allocation = -1;
586 paned->in_drag = FALSE;
588 paned->last_child1_focus = NULL;
589 paned->last_child2_focus = NULL;
590 paned->in_recursion = FALSE;
591 paned->handle_prelit = FALSE;
592 paned->original_position = -1;
594 paned->handle_pos.x = -1;
595 paned->handle_pos.y = -1;
597 paned->drag_pos = -1;
601 gtk_paned_set_property (GObject *object,
606 GtkPaned *paned = GTK_PANED (object);
610 case PROP_ORIENTATION:
611 paned->priv->orientation = g_value_get_enum (value);
612 paned->orientation = !paned->priv->orientation;
614 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
615 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
617 paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
619 /* state_changed updates the cursor */
620 gtk_paned_state_changed (GTK_WIDGET (paned), GTK_WIDGET (paned)->state);
621 gtk_widget_queue_resize (GTK_WIDGET (paned));
624 gtk_paned_set_position (paned, g_value_get_int (value));
626 case PROP_POSITION_SET:
627 paned->position_set = g_value_get_boolean (value);
628 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
631 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
637 gtk_paned_get_property (GObject *object,
642 GtkPaned *paned = GTK_PANED (object);
646 case PROP_ORIENTATION:
647 g_value_set_enum (value, paned->priv->orientation);
650 g_value_set_int (value, paned->child1_size);
652 case PROP_POSITION_SET:
653 g_value_set_boolean (value, paned->position_set);
655 case PROP_MIN_POSITION:
656 g_value_set_int (value, paned->min_position);
658 case PROP_MAX_POSITION:
659 g_value_set_int (value, paned->max_position);
662 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668 gtk_paned_set_child_property (GtkContainer *container,
674 GtkPaned *paned = GTK_PANED (container);
675 gboolean old_value, new_value;
677 g_assert (child == paned->child1 || child == paned->child2);
679 new_value = g_value_get_boolean (value);
682 case CHILD_PROP_RESIZE:
683 if (child == paned->child1)
685 old_value = paned->child1_resize;
686 paned->child1_resize = new_value;
690 old_value = paned->child2_resize;
691 paned->child2_resize = new_value;
694 case CHILD_PROP_SHRINK:
695 if (child == paned->child1)
697 old_value = paned->child1_shrink;
698 paned->child1_shrink = new_value;
702 old_value = paned->child2_shrink;
703 paned->child2_shrink = new_value;
707 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
708 old_value = -1; /* quiet gcc */
711 if (old_value != new_value)
712 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
716 gtk_paned_get_child_property (GtkContainer *container,
722 GtkPaned *paned = GTK_PANED (container);
724 g_assert (child == paned->child1 || child == paned->child2);
728 case CHILD_PROP_RESIZE:
729 if (child == paned->child1)
730 g_value_set_boolean (value, paned->child1_resize);
732 g_value_set_boolean (value, paned->child2_resize);
734 case CHILD_PROP_SHRINK:
735 if (child == paned->child1)
736 g_value_set_boolean (value, paned->child1_shrink);
738 g_value_set_boolean (value, paned->child2_shrink);
741 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
747 gtk_paned_finalize (GObject *object)
749 GtkPaned *paned = GTK_PANED (object);
751 gtk_paned_set_saved_focus (paned, NULL);
752 gtk_paned_set_first_paned (paned, NULL);
754 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
758 gtk_paned_size_request (GtkWidget *widget,
759 GtkRequisition *requisition)
761 GtkPaned *paned = GTK_PANED (widget);
762 GtkRequisition child_requisition;
765 requisition->width = 0;
766 requisition->height = 0;
768 if (paned->child1 && gtk_widget_get_visible (paned->child1))
770 gtk_widget_size_request (paned->child1, &child_requisition);
772 requisition->height = child_requisition.height;
773 requisition->width = child_requisition.width;
776 if (paned->child2 && gtk_widget_get_visible (paned->child2))
778 gtk_widget_size_request (paned->child2, &child_requisition);
780 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
782 requisition->height = MAX (requisition->height,
783 child_requisition.height);
784 requisition->width += child_requisition.width;
788 requisition->width = MAX (requisition->width,
789 child_requisition.width);
790 requisition->height += child_requisition.height;
794 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
795 requisition->width += border_width * 2;
796 requisition->height += border_width * 2;
798 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
799 paned->child2 && gtk_widget_get_visible (paned->child2))
803 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
805 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
806 requisition->width += handle_size;
808 requisition->height += handle_size;
813 flip_child (GtkWidget *widget,
814 GtkAllocation *child_pos)
816 gint x = widget->allocation.x;
817 gint width = widget->allocation.width;
819 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
823 gtk_paned_size_allocate (GtkWidget *widget,
824 GtkAllocation *allocation)
826 GtkPaned *paned = GTK_PANED (widget);
829 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
831 widget->allocation = *allocation;
833 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
834 paned->child2 && gtk_widget_get_visible (paned->child2))
836 GtkRequisition child1_requisition;
837 GtkRequisition child2_requisition;
838 GtkAllocation child1_allocation;
839 GtkAllocation child2_allocation;
840 GdkRectangle old_handle_pos;
843 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
845 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
846 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
848 old_handle_pos = paned->handle_pos;
850 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
852 gtk_paned_calc_position (paned,
853 MAX (1, widget->allocation.width
856 child1_requisition.width,
857 child2_requisition.width);
859 paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
860 paned->handle_pos.y = widget->allocation.y + border_width;
861 paned->handle_pos.width = handle_size;
862 paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
864 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
865 child1_allocation.width = MAX (1, paned->child1_size);
866 child1_allocation.x = widget->allocation.x + border_width;
867 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
869 child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
870 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
872 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
874 flip_child (widget, &(child2_allocation));
875 flip_child (widget, &(child1_allocation));
876 flip_child (widget, &(paned->handle_pos));
881 gtk_paned_calc_position (paned,
882 MAX (1, widget->allocation.height
885 child1_requisition.height,
886 child2_requisition.height);
888 paned->handle_pos.x = widget->allocation.x + border_width;
889 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
890 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
891 paned->handle_pos.height = handle_size;
893 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
894 child1_allocation.height = MAX (1, paned->child1_size);
895 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
896 child1_allocation.y = widget->allocation.y + border_width;
898 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
899 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
902 if (gtk_widget_get_mapped (widget) &&
903 (old_handle_pos.x != paned->handle_pos.x ||
904 old_handle_pos.y != paned->handle_pos.y ||
905 old_handle_pos.width != paned->handle_pos.width ||
906 old_handle_pos.height != paned->handle_pos.height))
908 gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
909 gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
912 if (gtk_widget_get_realized (widget))
914 if (gtk_widget_get_mapped (widget))
915 gdk_window_show (paned->handle);
917 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
919 gdk_window_move_resize (paned->handle,
923 paned->handle_pos.height);
927 gdk_window_move_resize (paned->handle,
930 paned->handle_pos.width,
935 /* Now allocate the childen, making sure, when resizing not to
936 * overlap the windows
938 if (gtk_widget_get_mapped (widget) &&
940 ((paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
941 paned->child1->allocation.width < child1_allocation.width) ||
943 (paned->priv->orientation == GTK_ORIENTATION_VERTICAL &&
944 paned->child1->allocation.height < child1_allocation.height)))
946 gtk_widget_size_allocate (paned->child2, &child2_allocation);
947 gtk_widget_size_allocate (paned->child1, &child1_allocation);
951 gtk_widget_size_allocate (paned->child1, &child1_allocation);
952 gtk_widget_size_allocate (paned->child2, &child2_allocation);
957 GtkAllocation child_allocation;
959 if (gtk_widget_get_realized (widget))
960 gdk_window_hide (paned->handle);
963 gtk_widget_set_child_visible (paned->child1, TRUE);
965 gtk_widget_set_child_visible (paned->child2, TRUE);
967 child_allocation.x = widget->allocation.x + border_width;
968 child_allocation.y = widget->allocation.y + border_width;
969 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
970 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
972 if (paned->child1 && gtk_widget_get_visible (paned->child1))
973 gtk_widget_size_allocate (paned->child1, &child_allocation);
974 else if (paned->child2 && gtk_widget_get_visible (paned->child2))
975 gtk_widget_size_allocate (paned->child2, &child_allocation);
980 gtk_paned_realize (GtkWidget *widget)
983 GdkWindowAttr attributes;
984 gint attributes_mask;
986 gtk_widget_set_realized (widget, TRUE);
987 paned = GTK_PANED (widget);
989 widget->window = gtk_widget_get_parent_window (widget);
990 g_object_ref (widget->window);
992 attributes.window_type = GDK_WINDOW_CHILD;
993 attributes.wclass = GDK_INPUT_ONLY;
994 attributes.x = paned->handle_pos.x;
995 attributes.y = paned->handle_pos.y;
996 attributes.width = paned->handle_pos.width;
997 attributes.height = paned->handle_pos.height;
998 attributes.event_mask = gtk_widget_get_events (widget);
999 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1000 GDK_BUTTON_RELEASE_MASK |
1001 GDK_ENTER_NOTIFY_MASK |
1002 GDK_LEAVE_NOTIFY_MASK |
1003 GDK_POINTER_MOTION_MASK |
1004 GDK_POINTER_MOTION_HINT_MASK);
1005 attributes_mask = GDK_WA_X | GDK_WA_Y;
1006 if (gtk_widget_is_sensitive (widget))
1008 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1009 paned->cursor_type);
1010 attributes_mask |= GDK_WA_CURSOR;
1013 paned->handle = gdk_window_new (widget->window,
1014 &attributes, attributes_mask);
1015 gdk_window_set_user_data (paned->handle, paned);
1016 if (attributes_mask & GDK_WA_CURSOR)
1017 gdk_cursor_unref (attributes.cursor);
1019 widget->style = gtk_style_attach (widget->style, widget->window);
1021 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
1022 paned->child2 && gtk_widget_get_visible (paned->child2))
1023 gdk_window_show (paned->handle);
1027 gtk_paned_unrealize (GtkWidget *widget)
1029 GtkPaned *paned = GTK_PANED (widget);
1033 g_object_unref (paned->xor_gc);
1034 paned->xor_gc = NULL;
1039 gdk_window_set_user_data (paned->handle, NULL);
1040 gdk_window_destroy (paned->handle);
1041 paned->handle = NULL;
1044 gtk_paned_set_last_child1_focus (paned, NULL);
1045 gtk_paned_set_last_child2_focus (paned, NULL);
1046 gtk_paned_set_saved_focus (paned, NULL);
1047 gtk_paned_set_first_paned (paned, NULL);
1049 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1053 gtk_paned_map (GtkWidget *widget)
1055 GtkPaned *paned = GTK_PANED (widget);
1057 gdk_window_show (paned->handle);
1059 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1063 gtk_paned_unmap (GtkWidget *widget)
1065 GtkPaned *paned = GTK_PANED (widget);
1067 gdk_window_hide (paned->handle);
1069 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1073 gtk_paned_expose (GtkWidget *widget,
1074 GdkEventExpose *event)
1076 GtkPaned *paned = GTK_PANED (widget);
1078 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1079 paned->child1 && gtk_widget_get_visible (paned->child1) &&
1080 paned->child2 && gtk_widget_get_visible (paned->child2))
1084 if (gtk_widget_is_focus (widget))
1085 state = GTK_STATE_SELECTED;
1086 else if (paned->handle_prelit)
1087 state = GTK_STATE_PRELIGHT;
1089 state = gtk_widget_get_state (widget);
1091 gtk_paint_handle (widget->style, widget->window,
1092 state, GTK_SHADOW_NONE,
1093 &paned->handle_pos, widget, "paned",
1094 paned->handle_pos.x, paned->handle_pos.y,
1095 paned->handle_pos.width, paned->handle_pos.height,
1096 !paned->priv->orientation);
1099 /* Chain up to draw children */
1100 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1106 is_rtl (GtkPaned *paned)
1108 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1109 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1118 update_drag (GtkPaned *paned)
1124 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1125 gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
1127 gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
1129 pos -= paned->drag_pos;
1133 gtk_widget_style_get (GTK_WIDGET (paned),
1134 "handle-size", &handle_size,
1137 size = GTK_WIDGET (paned)->allocation.width - pos - handle_size;
1144 size -= gtk_container_get_border_width (GTK_CONTAINER (paned));
1146 size = CLAMP (size, paned->min_position, paned->max_position);
1148 if (size != paned->child1_size)
1149 gtk_paned_set_position (paned, size);
1153 gtk_paned_enter (GtkWidget *widget,
1154 GdkEventCrossing *event)
1156 GtkPaned *paned = GTK_PANED (widget);
1159 update_drag (paned);
1162 paned->handle_prelit = TRUE;
1163 gtk_widget_queue_draw_area (widget,
1164 paned->handle_pos.x,
1165 paned->handle_pos.y,
1166 paned->handle_pos.width,
1167 paned->handle_pos.height);
1174 gtk_paned_leave (GtkWidget *widget,
1175 GdkEventCrossing *event)
1177 GtkPaned *paned = GTK_PANED (widget);
1180 update_drag (paned);
1183 paned->handle_prelit = FALSE;
1184 gtk_widget_queue_draw_area (widget,
1185 paned->handle_pos.x,
1186 paned->handle_pos.y,
1187 paned->handle_pos.width,
1188 paned->handle_pos.height);
1195 gtk_paned_focus (GtkWidget *widget,
1196 GtkDirectionType direction)
1201 /* This is a hack, but how can this be done without
1202 * excessive cut-and-paste from gtkcontainer.c?
1205 gtk_widget_set_can_focus (widget, FALSE);
1206 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1207 gtk_widget_set_can_focus (widget, TRUE);
1213 gtk_paned_button_press (GtkWidget *widget,
1214 GdkEventButton *event)
1216 GtkPaned *paned = GTK_PANED (widget);
1218 if (!paned->in_drag &&
1219 (event->window == paned->handle) && (event->button == 1))
1221 /* We need a server grab here, not gtk_grab_add(), since
1222 * we don't want to pass events on to the widget's children */
1223 if (gdk_device_grab (event->device,
1225 GDK_OWNERSHIP_WINDOW, FALSE,
1226 GDK_POINTER_MOTION_HINT_MASK
1227 | GDK_BUTTON1_MOTION_MASK
1228 | GDK_BUTTON_RELEASE_MASK
1229 | GDK_ENTER_NOTIFY_MASK
1230 | GDK_LEAVE_NOTIFY_MASK,
1231 NULL, event->time) != GDK_GRAB_SUCCESS)
1234 paned->in_drag = TRUE;
1235 paned->priv->grab_time = event->time;
1236 paned->priv->grab_device = event->device;
1238 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1239 paned->drag_pos = event->x;
1241 paned->drag_pos = event->y;
1250 gtk_paned_grab_broken (GtkWidget *widget,
1251 GdkEventGrabBroken *event)
1253 GtkPaned *paned = GTK_PANED (widget);
1255 paned->in_drag = FALSE;
1256 paned->drag_pos = -1;
1257 paned->position_set = TRUE;
1263 stop_drag (GtkPaned *paned)
1265 paned->in_drag = FALSE;
1266 paned->drag_pos = -1;
1267 paned->position_set = TRUE;
1269 gdk_device_ungrab (paned->priv->grab_device,
1270 paned->priv->grab_time);
1271 paned->priv->grab_device = NULL;
1275 gtk_paned_grab_notify (GtkWidget *widget,
1276 gboolean was_grabbed)
1278 GtkPaned *paned = GTK_PANED (widget);
1279 GdkDevice *grab_device;
1281 grab_device = paned->priv->grab_device;
1283 if (paned->in_drag && grab_device &&
1284 gtk_widget_device_is_shadowed (widget, grab_device))
1289 gtk_paned_state_changed (GtkWidget *widget,
1290 GtkStateType previous_state)
1292 GtkPaned *paned = GTK_PANED (widget);
1295 if (gtk_widget_get_realized (widget))
1297 if (gtk_widget_is_sensitive (widget))
1298 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1299 paned->cursor_type);
1303 gdk_window_set_cursor (paned->handle, cursor);
1306 gdk_cursor_unref (cursor);
1311 gtk_paned_button_release (GtkWidget *widget,
1312 GdkEventButton *event)
1314 GtkPaned *paned = GTK_PANED (widget);
1316 if (paned->in_drag && (event->button == 1))
1327 gtk_paned_motion (GtkWidget *widget,
1328 GdkEventMotion *event)
1330 GtkPaned *paned = GTK_PANED (widget);
1334 update_drag (paned);
1343 * @orientation: the paned's orientation.
1345 * Creates a new #GtkPaned widget.
1347 * Return value: a new #GtkPaned.
1352 gtk_paned_new (GtkOrientation orientation)
1354 return g_object_new (GTK_TYPE_PANED,
1355 "orientation", orientation,
1360 gtk_paned_add1 (GtkPaned *paned,
1363 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1367 gtk_paned_add2 (GtkPaned *paned,
1370 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1374 gtk_paned_pack1 (GtkPaned *paned,
1379 g_return_if_fail (GTK_IS_PANED (paned));
1380 g_return_if_fail (GTK_IS_WIDGET (child));
1384 paned->child1 = child;
1385 paned->child1_resize = resize;
1386 paned->child1_shrink = shrink;
1388 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1393 gtk_paned_pack2 (GtkPaned *paned,
1398 g_return_if_fail (GTK_IS_PANED (paned));
1399 g_return_if_fail (GTK_IS_WIDGET (child));
1403 paned->child2 = child;
1404 paned->child2_resize = resize;
1405 paned->child2_shrink = shrink;
1407 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1413 gtk_paned_add (GtkContainer *container,
1418 g_return_if_fail (GTK_IS_PANED (container));
1420 paned = GTK_PANED (container);
1423 gtk_paned_add1 (paned, widget);
1424 else if (!paned->child2)
1425 gtk_paned_add2 (paned, widget);
1427 g_warning ("GtkPaned cannot have more than 2 children\n");
1431 gtk_paned_remove (GtkContainer *container,
1435 gboolean was_visible;
1437 paned = GTK_PANED (container);
1438 was_visible = gtk_widget_get_visible (widget);
1440 if (paned->child1 == widget)
1442 gtk_widget_unparent (widget);
1444 paned->child1 = NULL;
1446 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1447 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1449 else if (paned->child2 == widget)
1451 gtk_widget_unparent (widget);
1453 paned->child2 = NULL;
1455 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1456 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1461 gtk_paned_forall (GtkContainer *container,
1462 gboolean include_internals,
1463 GtkCallback callback,
1464 gpointer callback_data)
1468 g_return_if_fail (callback != NULL);
1470 paned = GTK_PANED (container);
1473 (*callback) (paned->child1, callback_data);
1475 (*callback) (paned->child2, callback_data);
1479 * gtk_paned_get_position:
1480 * @paned: a #GtkPaned widget
1482 * Obtains the position of the divider between the two panes.
1484 * Return value: position of the divider
1487 gtk_paned_get_position (GtkPaned *paned)
1489 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1491 return paned->child1_size;
1495 * gtk_paned_set_position:
1496 * @paned: a #GtkPaned widget
1497 * @position: pixel position of divider, a negative value means that the position
1500 * Sets the position of the divider between the two panes.
1503 gtk_paned_set_position (GtkPaned *paned,
1508 g_return_if_fail (GTK_IS_PANED (paned));
1510 if (paned->child1_size == position)
1513 object = G_OBJECT (paned);
1517 /* We don't clamp here - the assumption is that
1518 * if the total allocation changes at the same time
1519 * as the position, the position set is with reference
1520 * to the new total size. If only the position changes,
1521 * then clamping will occur in gtk_paned_calc_position()
1524 paned->child1_size = position;
1525 paned->position_set = TRUE;
1529 paned->position_set = FALSE;
1532 g_object_freeze_notify (object);
1533 g_object_notify (object, "position");
1534 g_object_notify (object, "position-set");
1535 g_object_thaw_notify (object);
1537 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1540 /* Hacky work-around for bug #144269 */
1541 if (paned->child2 != NULL)
1543 gtk_widget_queue_draw (paned->child2);
1549 * gtk_paned_get_child1:
1550 * @paned: a #GtkPaned widget
1552 * Obtains the first child of the paned widget.
1554 * Return value: first child, or %NULL if it is not set.
1559 gtk_paned_get_child1 (GtkPaned *paned)
1561 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1563 return paned->child1;
1567 * gtk_paned_get_child2:
1568 * @paned: a #GtkPaned widget
1570 * Obtains the second child of the paned widget.
1572 * Return value: second child, or %NULL if it is not set.
1577 gtk_paned_get_child2 (GtkPaned *paned)
1579 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1581 return paned->child2;
1585 gtk_paned_calc_position (GtkPaned *paned,
1591 gint old_min_position;
1592 gint old_max_position;
1594 old_position = paned->child1_size;
1595 old_min_position = paned->min_position;
1596 old_max_position = paned->max_position;
1598 paned->min_position = paned->child1_shrink ? 0 : child1_req;
1600 paned->max_position = allocation;
1601 if (!paned->child2_shrink)
1602 paned->max_position = MAX (1, paned->max_position - child2_req);
1603 paned->max_position = MAX (paned->min_position, paned->max_position);
1605 if (!paned->position_set)
1607 if (paned->child1_resize && !paned->child2_resize)
1608 paned->child1_size = MAX (0, allocation - child2_req);
1609 else if (!paned->child1_resize && paned->child2_resize)
1610 paned->child1_size = child1_req;
1611 else if (child1_req + child2_req != 0)
1612 paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1614 paned->child1_size = allocation * 0.5 + 0.5;
1618 /* If the position was set before the initial allocation.
1619 * (paned->last_allocation <= 0) just clamp it and leave it.
1621 if (paned->last_allocation > 0)
1623 if (paned->child1_resize && !paned->child2_resize)
1624 paned->child1_size += allocation - paned->last_allocation;
1625 else if (!(!paned->child1_resize && paned->child2_resize))
1626 paned->child1_size = allocation * ((gdouble) paned->child1_size / (paned->last_allocation)) + 0.5;
1630 paned->child1_size = CLAMP (paned->child1_size,
1631 paned->min_position,
1632 paned->max_position);
1635 gtk_widget_set_child_visible (paned->child1, paned->child1_size != 0);
1638 gtk_widget_set_child_visible (paned->child2, paned->child1_size != allocation);
1640 g_object_freeze_notify (G_OBJECT (paned));
1641 if (paned->child1_size != old_position)
1642 g_object_notify (G_OBJECT (paned), "position");
1643 if (paned->min_position != old_min_position)
1644 g_object_notify (G_OBJECT (paned), "min-position");
1645 if (paned->max_position != old_max_position)
1646 g_object_notify (G_OBJECT (paned), "max-position");
1647 g_object_thaw_notify (G_OBJECT (paned));
1649 paned->last_allocation = allocation;
1653 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1655 if (paned->priv->saved_focus)
1656 g_object_remove_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1657 (gpointer *)&(paned->priv->saved_focus));
1659 paned->priv->saved_focus = widget;
1661 if (paned->priv->saved_focus)
1662 g_object_add_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1663 (gpointer *)&(paned->priv->saved_focus));
1667 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1669 if (paned->priv->first_paned)
1670 g_object_remove_weak_pointer (G_OBJECT (paned->priv->first_paned),
1671 (gpointer *)&(paned->priv->first_paned));
1673 paned->priv->first_paned = first_paned;
1675 if (paned->priv->first_paned)
1676 g_object_add_weak_pointer (G_OBJECT (paned->priv->first_paned),
1677 (gpointer *)&(paned->priv->first_paned));
1681 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1683 if (paned->last_child1_focus)
1684 g_object_remove_weak_pointer (G_OBJECT (paned->last_child1_focus),
1685 (gpointer *)&(paned->last_child1_focus));
1687 paned->last_child1_focus = widget;
1689 if (paned->last_child1_focus)
1690 g_object_add_weak_pointer (G_OBJECT (paned->last_child1_focus),
1691 (gpointer *)&(paned->last_child1_focus));
1695 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1697 if (paned->last_child2_focus)
1698 g_object_remove_weak_pointer (G_OBJECT (paned->last_child2_focus),
1699 (gpointer *)&(paned->last_child2_focus));
1701 paned->last_child2_focus = widget;
1703 if (paned->last_child2_focus)
1704 g_object_add_weak_pointer (G_OBJECT (paned->last_child2_focus),
1705 (gpointer *)&(paned->last_child2_focus));
1709 paned_get_focus_widget (GtkPaned *paned)
1711 GtkWidget *toplevel;
1713 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1714 if (gtk_widget_is_toplevel (toplevel))
1715 return GTK_WINDOW (toplevel)->focus_widget;
1721 gtk_paned_set_focus_child (GtkContainer *container,
1722 GtkWidget *focus_child)
1725 GtkWidget *container_focus_child;
1727 g_return_if_fail (GTK_IS_PANED (container));
1729 paned = GTK_PANED (container);
1731 if (focus_child == NULL)
1733 GtkWidget *last_focus;
1736 last_focus = paned_get_focus_widget (paned);
1740 /* If there is one or more paned widgets between us and the
1741 * focus widget, we want the topmost of those as last_focus
1743 for (w = last_focus; w != GTK_WIDGET (paned); w = w->parent)
1744 if (GTK_IS_PANED (w))
1747 container_focus_child = gtk_container_get_focus_child (container);
1748 if (container_focus_child == paned->child1)
1749 gtk_paned_set_last_child1_focus (paned, last_focus);
1750 else if (container_focus_child == paned->child2)
1751 gtk_paned_set_last_child2_focus (paned, last_focus);
1755 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1756 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1760 gtk_paned_get_cycle_chain (GtkPaned *paned,
1761 GtkDirectionType direction,
1764 GtkContainer *container = GTK_CONTAINER (paned);
1765 GtkWidget *ancestor = NULL;
1766 GtkWidget *focus_child;
1767 GList *temp_list = NULL;
1770 if (paned->in_recursion)
1773 g_assert (widgets != NULL);
1775 if (paned->last_child1_focus &&
1776 !gtk_widget_is_ancestor (paned->last_child1_focus, GTK_WIDGET (paned)))
1778 gtk_paned_set_last_child1_focus (paned, NULL);
1781 if (paned->last_child2_focus &&
1782 !gtk_widget_is_ancestor (paned->last_child2_focus, GTK_WIDGET (paned)))
1784 gtk_paned_set_last_child2_focus (paned, NULL);
1787 if (GTK_WIDGET (paned)->parent)
1788 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (paned)->parent, GTK_TYPE_PANED);
1790 /* The idea here is that temp_list is a list of widgets we want to cycle
1791 * to. The list is prioritized so that the first element is our first
1792 * choice, the next our second, and so on.
1794 * We can't just use g_list_reverse(), because we want to try
1795 * paned->last_child?_focus before paned->child?, both when we
1796 * are going forward and backward.
1798 focus_child = gtk_container_get_focus_child (container);
1799 if (direction == GTK_DIR_TAB_FORWARD)
1801 if (focus_child == paned->child1)
1803 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1804 temp_list = g_list_append (temp_list, paned->child2);
1805 temp_list = g_list_append (temp_list, ancestor);
1807 else if (focus_child == paned->child2)
1809 temp_list = g_list_append (temp_list, ancestor);
1810 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1811 temp_list = g_list_append (temp_list, paned->child1);
1815 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1816 temp_list = g_list_append (temp_list, paned->child1);
1817 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1818 temp_list = g_list_append (temp_list, paned->child2);
1819 temp_list = g_list_append (temp_list, ancestor);
1824 if (focus_child == paned->child1)
1826 temp_list = g_list_append (temp_list, ancestor);
1827 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1828 temp_list = g_list_append (temp_list, paned->child2);
1830 else if (focus_child == paned->child2)
1832 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1833 temp_list = g_list_append (temp_list, paned->child1);
1834 temp_list = g_list_append (temp_list, ancestor);
1838 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1839 temp_list = g_list_append (temp_list, paned->child2);
1840 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1841 temp_list = g_list_append (temp_list, paned->child1);
1842 temp_list = g_list_append (temp_list, ancestor);
1846 /* Walk the list and expand all the paned widgets. */
1847 for (list = temp_list; list != NULL; list = list->next)
1849 GtkWidget *widget = list->data;
1853 if (GTK_IS_PANED (widget))
1855 paned->in_recursion = TRUE;
1856 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1857 paned->in_recursion = FALSE;
1861 *widgets = g_list_append (*widgets, widget);
1866 g_list_free (temp_list);
1870 gtk_paned_cycle_child_focus (GtkPaned *paned,
1873 GList *cycle_chain = NULL;
1876 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1878 /* ignore f6 if the handle is focused */
1879 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1882 /* we can't just let the event propagate up the hierarchy,
1883 * because the paned will want to cycle focus _unless_ an
1884 * ancestor paned handles the event
1886 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1888 for (list = cycle_chain; list != NULL; list = list->next)
1889 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1892 g_list_free (cycle_chain);
1898 get_child_panes (GtkWidget *widget,
1901 if (!widget || !gtk_widget_get_realized (widget))
1904 if (GTK_IS_PANED (widget))
1906 GtkPaned *paned = GTK_PANED (widget);
1908 get_child_panes (paned->child1, panes);
1909 *panes = g_list_prepend (*panes, widget);
1910 get_child_panes (paned->child2, panes);
1912 else if (GTK_IS_CONTAINER (widget))
1914 gtk_container_forall (GTK_CONTAINER (widget),
1915 (GtkCallback)get_child_panes, panes);
1920 get_all_panes (GtkPaned *paned)
1922 GtkPaned *topmost = NULL;
1923 GList *result = NULL;
1926 for (w = GTK_WIDGET (paned); w != NULL; w = w->parent)
1928 if (GTK_IS_PANED (w))
1929 topmost = GTK_PANED (w);
1934 get_child_panes (GTK_WIDGET (topmost), &result);
1936 return g_list_reverse (result);
1940 gtk_paned_find_neighbours (GtkPaned *paned,
1947 all_panes = get_all_panes (paned);
1948 g_assert (all_panes);
1950 this_link = g_list_find (all_panes, paned);
1952 g_assert (this_link);
1954 if (this_link->next)
1955 *next = this_link->next->data;
1957 *next = all_panes->data;
1959 if (this_link->prev)
1960 *prev = this_link->prev->data;
1962 *prev = g_list_last (all_panes)->data;
1964 g_list_free (all_panes);
1968 gtk_paned_move_handle (GtkPaned *paned,
1969 GtkScrollType scroll)
1971 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1978 SINGLE_STEP_SIZE = 1,
1982 new_position = old_position = gtk_paned_get_position (paned);
1987 case GTK_SCROLL_STEP_LEFT:
1988 case GTK_SCROLL_STEP_UP:
1989 case GTK_SCROLL_STEP_BACKWARD:
1990 increment = - SINGLE_STEP_SIZE;
1993 case GTK_SCROLL_STEP_RIGHT:
1994 case GTK_SCROLL_STEP_DOWN:
1995 case GTK_SCROLL_STEP_FORWARD:
1996 increment = SINGLE_STEP_SIZE;
1999 case GTK_SCROLL_PAGE_LEFT:
2000 case GTK_SCROLL_PAGE_UP:
2001 case GTK_SCROLL_PAGE_BACKWARD:
2002 increment = - PAGE_STEP_SIZE;
2005 case GTK_SCROLL_PAGE_RIGHT:
2006 case GTK_SCROLL_PAGE_DOWN:
2007 case GTK_SCROLL_PAGE_FORWARD:
2008 increment = PAGE_STEP_SIZE;
2011 case GTK_SCROLL_START:
2012 new_position = paned->min_position;
2015 case GTK_SCROLL_END:
2016 new_position = paned->max_position;
2026 increment = -increment;
2028 new_position = old_position + increment;
2031 new_position = CLAMP (new_position, paned->min_position, paned->max_position);
2033 if (old_position != new_position)
2034 gtk_paned_set_position (paned, new_position);
2043 gtk_paned_restore_focus (GtkPaned *paned)
2045 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2047 if (paned->priv->saved_focus &&
2048 gtk_widget_get_sensitive (paned->priv->saved_focus))
2050 gtk_widget_grab_focus (paned->priv->saved_focus);
2054 /* the saved focus is somehow not available for focusing,
2056 * 1) tabbing into the paned widget
2057 * if that didn't work,
2058 * 2) unset focus for the window if there is one
2061 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2063 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2065 if (GTK_IS_WINDOW (toplevel))
2066 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2070 gtk_paned_set_saved_focus (paned, NULL);
2071 gtk_paned_set_first_paned (paned, NULL);
2076 gtk_paned_accept_position (GtkPaned *paned)
2078 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2080 paned->original_position = -1;
2081 gtk_paned_restore_focus (paned);
2091 gtk_paned_cancel_position (GtkPaned *paned)
2093 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2095 if (paned->original_position != -1)
2097 gtk_paned_set_position (paned, paned->original_position);
2098 paned->original_position = -1;
2101 gtk_paned_restore_focus (paned);
2109 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2112 GtkPaned *next, *prev;
2114 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2116 GtkPaned *focus = NULL;
2118 if (!paned->priv->first_paned)
2120 /* The first_pane has disappeared. As an ad-hoc solution,
2121 * we make the currently focused paned the first_paned. To the
2122 * user this will seem like the paned cycling has been reset.
2125 gtk_paned_set_first_paned (paned, paned);
2128 gtk_paned_find_neighbours (paned, &next, &prev);
2130 if (reversed && prev &&
2131 prev != paned && paned != paned->priv->first_paned)
2135 else if (!reversed && next &&
2136 next != paned && next != paned->priv->first_paned)
2142 gtk_paned_accept_position (paned);
2148 gtk_paned_set_saved_focus (focus, paned->priv->saved_focus);
2149 gtk_paned_set_first_paned (focus, paned->priv->first_paned);
2151 gtk_paned_set_saved_focus (paned, NULL);
2152 gtk_paned_set_first_paned (paned, NULL);
2154 gtk_widget_grab_focus (GTK_WIDGET (focus));
2156 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2158 paned->original_position = -1;
2159 focus->original_position = gtk_paned_get_position (focus);
2164 GtkContainer *container = GTK_CONTAINER (paned);
2167 GtkPaned *prev, *next;
2168 GtkWidget *toplevel;
2169 GtkWidget *focus_child;
2171 gtk_paned_find_neighbours (paned, &next, &prev);
2172 focus_child = gtk_container_get_focus_child (container);
2174 if (focus_child == paned->child1)
2187 else if (focus_child == paned->child2)
2202 /* Focus is not inside this paned, and we don't have focus.
2203 * Presumably this happened because the application wants us
2204 * to start keyboard navigating.
2214 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2216 if (GTK_IS_WINDOW (toplevel))
2217 gtk_paned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
2218 gtk_paned_set_first_paned (focus, first);
2219 focus->original_position = gtk_paned_get_position (focus);
2221 gtk_widget_grab_focus (GTK_WIDGET (focus));
2228 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2230 /* This function/signal has the wrong name. It is called when you
2231 * press Tab or Shift-Tab and what we do is act as if
2232 * the user pressed Return and then Tab or Shift-Tab
2234 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2235 gtk_paned_accept_position (paned);
2241 * gtk_paned_get_handle_window:
2242 * @paned: a #GtkPaned
2244 * Returns the #GdkWindow of the handle. This function is
2245 * useful when handling button or motion events because it
2246 * enables the callback to distinguish between the window
2247 * of the paned, a child and the handle.
2249 * Return value: the paned's handle window.
2254 gtk_paned_get_handle_window (GtkPaned *paned)
2256 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2258 return paned->handle;