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;
764 requisition->width = 0;
765 requisition->height = 0;
767 if (paned->child1 && gtk_widget_get_visible (paned->child1))
769 gtk_widget_size_request (paned->child1, &child_requisition);
771 requisition->height = child_requisition.height;
772 requisition->width = child_requisition.width;
775 if (paned->child2 && gtk_widget_get_visible (paned->child2))
777 gtk_widget_size_request (paned->child2, &child_requisition);
779 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
781 requisition->height = MAX (requisition->height,
782 child_requisition.height);
783 requisition->width += child_requisition.width;
787 requisition->width = MAX (requisition->width,
788 child_requisition.width);
789 requisition->height += child_requisition.height;
793 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
794 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
796 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
797 paned->child2 && gtk_widget_get_visible (paned->child2))
801 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
803 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
804 requisition->width += handle_size;
806 requisition->height += handle_size;
811 flip_child (GtkWidget *widget,
812 GtkAllocation *child_pos)
814 gint x = widget->allocation.x;
815 gint width = widget->allocation.width;
817 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
821 gtk_paned_size_allocate (GtkWidget *widget,
822 GtkAllocation *allocation)
824 GtkPaned *paned = GTK_PANED (widget);
825 gint border_width = GTK_CONTAINER (paned)->border_width;
827 widget->allocation = *allocation;
829 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
830 paned->child2 && gtk_widget_get_visible (paned->child2))
832 GtkRequisition child1_requisition;
833 GtkRequisition child2_requisition;
834 GtkAllocation child1_allocation;
835 GtkAllocation child2_allocation;
836 GdkRectangle old_handle_pos;
839 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
841 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
842 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
844 old_handle_pos = paned->handle_pos;
846 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
848 gtk_paned_calc_position (paned,
849 MAX (1, widget->allocation.width
852 child1_requisition.width,
853 child2_requisition.width);
855 paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
856 paned->handle_pos.y = widget->allocation.y + border_width;
857 paned->handle_pos.width = handle_size;
858 paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
860 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
861 child1_allocation.width = MAX (1, paned->child1_size);
862 child1_allocation.x = widget->allocation.x + border_width;
863 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
865 child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
866 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
868 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
870 flip_child (widget, &(child2_allocation));
871 flip_child (widget, &(child1_allocation));
872 flip_child (widget, &(paned->handle_pos));
877 gtk_paned_calc_position (paned,
878 MAX (1, widget->allocation.height
881 child1_requisition.height,
882 child2_requisition.height);
884 paned->handle_pos.x = widget->allocation.x + border_width;
885 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
886 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
887 paned->handle_pos.height = handle_size;
889 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
890 child1_allocation.height = MAX (1, paned->child1_size);
891 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
892 child1_allocation.y = widget->allocation.y + border_width;
894 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
895 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
898 if (gtk_widget_get_mapped (widget) &&
899 (old_handle_pos.x != paned->handle_pos.x ||
900 old_handle_pos.y != paned->handle_pos.y ||
901 old_handle_pos.width != paned->handle_pos.width ||
902 old_handle_pos.height != paned->handle_pos.height))
904 gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
905 gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
908 if (gtk_widget_get_realized (widget))
910 if (gtk_widget_get_mapped (widget))
911 gdk_window_show (paned->handle);
913 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
915 gdk_window_move_resize (paned->handle,
919 paned->handle_pos.height);
923 gdk_window_move_resize (paned->handle,
926 paned->handle_pos.width,
931 /* Now allocate the childen, making sure, when resizing not to
932 * overlap the windows
934 if (gtk_widget_get_mapped (widget) &&
936 ((paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
937 paned->child1->allocation.width < child1_allocation.width) ||
939 (paned->priv->orientation == GTK_ORIENTATION_VERTICAL &&
940 paned->child1->allocation.height < child1_allocation.height)))
942 gtk_widget_size_allocate (paned->child2, &child2_allocation);
943 gtk_widget_size_allocate (paned->child1, &child1_allocation);
947 gtk_widget_size_allocate (paned->child1, &child1_allocation);
948 gtk_widget_size_allocate (paned->child2, &child2_allocation);
953 GtkAllocation child_allocation;
955 if (gtk_widget_get_realized (widget))
956 gdk_window_hide (paned->handle);
959 gtk_widget_set_child_visible (paned->child1, TRUE);
961 gtk_widget_set_child_visible (paned->child2, TRUE);
963 child_allocation.x = widget->allocation.x + border_width;
964 child_allocation.y = widget->allocation.y + border_width;
965 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
966 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
968 if (paned->child1 && gtk_widget_get_visible (paned->child1))
969 gtk_widget_size_allocate (paned->child1, &child_allocation);
970 else if (paned->child2 && gtk_widget_get_visible (paned->child2))
971 gtk_widget_size_allocate (paned->child2, &child_allocation);
976 gtk_paned_realize (GtkWidget *widget)
979 GdkWindowAttr attributes;
980 gint attributes_mask;
982 gtk_widget_set_realized (widget, TRUE);
983 paned = GTK_PANED (widget);
985 widget->window = gtk_widget_get_parent_window (widget);
986 g_object_ref (widget->window);
988 attributes.window_type = GDK_WINDOW_CHILD;
989 attributes.wclass = GDK_INPUT_ONLY;
990 attributes.x = paned->handle_pos.x;
991 attributes.y = paned->handle_pos.y;
992 attributes.width = paned->handle_pos.width;
993 attributes.height = paned->handle_pos.height;
994 attributes.event_mask = gtk_widget_get_events (widget);
995 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
996 GDK_BUTTON_RELEASE_MASK |
997 GDK_ENTER_NOTIFY_MASK |
998 GDK_LEAVE_NOTIFY_MASK |
999 GDK_POINTER_MOTION_MASK |
1000 GDK_POINTER_MOTION_HINT_MASK);
1001 attributes_mask = GDK_WA_X | GDK_WA_Y;
1002 if (gtk_widget_is_sensitive (widget))
1004 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1005 paned->cursor_type);
1006 attributes_mask |= GDK_WA_CURSOR;
1009 paned->handle = gdk_window_new (widget->window,
1010 &attributes, attributes_mask);
1011 gdk_window_set_user_data (paned->handle, paned);
1012 if (attributes_mask & GDK_WA_CURSOR)
1013 gdk_cursor_unref (attributes.cursor);
1015 widget->style = gtk_style_attach (widget->style, widget->window);
1017 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
1018 paned->child2 && gtk_widget_get_visible (paned->child2))
1019 gdk_window_show (paned->handle);
1023 gtk_paned_unrealize (GtkWidget *widget)
1025 GtkPaned *paned = GTK_PANED (widget);
1029 g_object_unref (paned->xor_gc);
1030 paned->xor_gc = NULL;
1035 gdk_window_set_user_data (paned->handle, NULL);
1036 gdk_window_destroy (paned->handle);
1037 paned->handle = NULL;
1040 gtk_paned_set_last_child1_focus (paned, NULL);
1041 gtk_paned_set_last_child2_focus (paned, NULL);
1042 gtk_paned_set_saved_focus (paned, NULL);
1043 gtk_paned_set_first_paned (paned, NULL);
1045 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1049 gtk_paned_map (GtkWidget *widget)
1051 GtkPaned *paned = GTK_PANED (widget);
1053 gdk_window_show (paned->handle);
1055 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1059 gtk_paned_unmap (GtkWidget *widget)
1061 GtkPaned *paned = GTK_PANED (widget);
1063 gdk_window_hide (paned->handle);
1065 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1069 gtk_paned_expose (GtkWidget *widget,
1070 GdkEventExpose *event)
1072 GtkPaned *paned = GTK_PANED (widget);
1074 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1075 paned->child1 && gtk_widget_get_visible (paned->child1) &&
1076 paned->child2 && gtk_widget_get_visible (paned->child2))
1080 if (gtk_widget_is_focus (widget))
1081 state = GTK_STATE_SELECTED;
1082 else if (paned->handle_prelit)
1083 state = GTK_STATE_PRELIGHT;
1085 state = gtk_widget_get_state (widget);
1087 gtk_paint_handle (widget->style, widget->window,
1088 state, GTK_SHADOW_NONE,
1089 &paned->handle_pos, widget, "paned",
1090 paned->handle_pos.x, paned->handle_pos.y,
1091 paned->handle_pos.width, paned->handle_pos.height,
1092 !paned->priv->orientation);
1095 /* Chain up to draw children */
1096 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1102 is_rtl (GtkPaned *paned)
1104 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1105 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1114 update_drag (GtkPaned *paned)
1120 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1121 gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
1123 gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
1125 pos -= paned->drag_pos;
1129 gtk_widget_style_get (GTK_WIDGET (paned),
1130 "handle-size", &handle_size,
1133 size = GTK_WIDGET (paned)->allocation.width - pos - handle_size;
1140 size -= GTK_CONTAINER (paned)->border_width;
1142 size = CLAMP (size, paned->min_position, paned->max_position);
1144 if (size != paned->child1_size)
1145 gtk_paned_set_position (paned, size);
1149 gtk_paned_enter (GtkWidget *widget,
1150 GdkEventCrossing *event)
1152 GtkPaned *paned = GTK_PANED (widget);
1155 update_drag (paned);
1158 paned->handle_prelit = TRUE;
1159 gtk_widget_queue_draw_area (widget,
1160 paned->handle_pos.x,
1161 paned->handle_pos.y,
1162 paned->handle_pos.width,
1163 paned->handle_pos.height);
1170 gtk_paned_leave (GtkWidget *widget,
1171 GdkEventCrossing *event)
1173 GtkPaned *paned = GTK_PANED (widget);
1176 update_drag (paned);
1179 paned->handle_prelit = FALSE;
1180 gtk_widget_queue_draw_area (widget,
1181 paned->handle_pos.x,
1182 paned->handle_pos.y,
1183 paned->handle_pos.width,
1184 paned->handle_pos.height);
1191 gtk_paned_focus (GtkWidget *widget,
1192 GtkDirectionType direction)
1197 /* This is a hack, but how can this be done without
1198 * excessive cut-and-paste from gtkcontainer.c?
1201 gtk_widget_set_can_focus (widget, FALSE);
1202 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1203 gtk_widget_set_can_focus (widget, TRUE);
1209 gtk_paned_button_press (GtkWidget *widget,
1210 GdkEventButton *event)
1212 GtkPaned *paned = GTK_PANED (widget);
1214 if (!paned->in_drag &&
1215 (event->window == paned->handle) && (event->button == 1))
1217 /* We need a server grab here, not gtk_grab_add(), since
1218 * we don't want to pass events on to the widget's children */
1219 if (gdk_device_grab (event->device,
1221 GDK_OWNERSHIP_WINDOW, FALSE,
1222 GDK_POINTER_MOTION_HINT_MASK
1223 | GDK_BUTTON1_MOTION_MASK
1224 | GDK_BUTTON_RELEASE_MASK
1225 | GDK_ENTER_NOTIFY_MASK
1226 | GDK_LEAVE_NOTIFY_MASK,
1227 NULL, event->time) != GDK_GRAB_SUCCESS)
1230 paned->in_drag = TRUE;
1231 paned->priv->grab_time = event->time;
1232 paned->priv->grab_device = event->device;
1234 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1235 paned->drag_pos = event->x;
1237 paned->drag_pos = event->y;
1246 gtk_paned_grab_broken (GtkWidget *widget,
1247 GdkEventGrabBroken *event)
1249 GtkPaned *paned = GTK_PANED (widget);
1251 paned->in_drag = FALSE;
1252 paned->drag_pos = -1;
1253 paned->position_set = TRUE;
1259 stop_drag (GtkPaned *paned)
1261 paned->in_drag = FALSE;
1262 paned->drag_pos = -1;
1263 paned->position_set = TRUE;
1265 gdk_device_ungrab (paned->priv->grab_device,
1266 paned->priv->grab_time);
1267 paned->priv->grab_device = NULL;
1271 gtk_paned_grab_notify (GtkWidget *widget,
1272 gboolean was_grabbed)
1274 GtkPaned *paned = GTK_PANED (widget);
1275 GdkDevice *grab_device;
1277 grab_device = paned->priv->grab_device;
1279 if (paned->in_drag && grab_device &&
1280 gtk_widget_device_is_shadowed (widget, grab_device))
1285 gtk_paned_state_changed (GtkWidget *widget,
1286 GtkStateType previous_state)
1288 GtkPaned *paned = GTK_PANED (widget);
1291 if (gtk_widget_get_realized (widget))
1293 if (gtk_widget_is_sensitive (widget))
1294 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1295 paned->cursor_type);
1299 gdk_window_set_cursor (paned->handle, cursor);
1302 gdk_cursor_unref (cursor);
1307 gtk_paned_button_release (GtkWidget *widget,
1308 GdkEventButton *event)
1310 GtkPaned *paned = GTK_PANED (widget);
1312 if (paned->in_drag && (event->button == 1))
1323 gtk_paned_motion (GtkWidget *widget,
1324 GdkEventMotion *event)
1326 GtkPaned *paned = GTK_PANED (widget);
1330 update_drag (paned);
1339 * @orientation: the paned's orientation.
1341 * Creates a new #GtkPaned widget.
1343 * Return value: a new #GtkPaned.
1348 gtk_paned_new (GtkOrientation orientation)
1350 return g_object_new (GTK_TYPE_PANED,
1351 "orientation", orientation,
1356 gtk_paned_add1 (GtkPaned *paned,
1359 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1363 gtk_paned_add2 (GtkPaned *paned,
1366 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1370 gtk_paned_pack1 (GtkPaned *paned,
1375 g_return_if_fail (GTK_IS_PANED (paned));
1376 g_return_if_fail (GTK_IS_WIDGET (child));
1380 paned->child1 = child;
1381 paned->child1_resize = resize;
1382 paned->child1_shrink = shrink;
1384 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1389 gtk_paned_pack2 (GtkPaned *paned,
1394 g_return_if_fail (GTK_IS_PANED (paned));
1395 g_return_if_fail (GTK_IS_WIDGET (child));
1399 paned->child2 = child;
1400 paned->child2_resize = resize;
1401 paned->child2_shrink = shrink;
1403 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1409 gtk_paned_add (GtkContainer *container,
1414 g_return_if_fail (GTK_IS_PANED (container));
1416 paned = GTK_PANED (container);
1419 gtk_paned_add1 (paned, widget);
1420 else if (!paned->child2)
1421 gtk_paned_add2 (paned, widget);
1423 g_warning ("GtkPaned cannot have more than 2 children\n");
1427 gtk_paned_remove (GtkContainer *container,
1431 gboolean was_visible;
1433 paned = GTK_PANED (container);
1434 was_visible = gtk_widget_get_visible (widget);
1436 if (paned->child1 == widget)
1438 gtk_widget_unparent (widget);
1440 paned->child1 = NULL;
1442 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1443 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1445 else if (paned->child2 == widget)
1447 gtk_widget_unparent (widget);
1449 paned->child2 = NULL;
1451 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1452 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1457 gtk_paned_forall (GtkContainer *container,
1458 gboolean include_internals,
1459 GtkCallback callback,
1460 gpointer callback_data)
1464 g_return_if_fail (callback != NULL);
1466 paned = GTK_PANED (container);
1469 (*callback) (paned->child1, callback_data);
1471 (*callback) (paned->child2, callback_data);
1475 * gtk_paned_get_position:
1476 * @paned: a #GtkPaned widget
1478 * Obtains the position of the divider between the two panes.
1480 * Return value: position of the divider
1483 gtk_paned_get_position (GtkPaned *paned)
1485 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1487 return paned->child1_size;
1491 * gtk_paned_set_position:
1492 * @paned: a #GtkPaned widget
1493 * @position: pixel position of divider, a negative value means that the position
1496 * Sets the position of the divider between the two panes.
1499 gtk_paned_set_position (GtkPaned *paned,
1504 g_return_if_fail (GTK_IS_PANED (paned));
1506 if (paned->child1_size == position)
1509 object = G_OBJECT (paned);
1513 /* We don't clamp here - the assumption is that
1514 * if the total allocation changes at the same time
1515 * as the position, the position set is with reference
1516 * to the new total size. If only the position changes,
1517 * then clamping will occur in gtk_paned_calc_position()
1520 paned->child1_size = position;
1521 paned->position_set = TRUE;
1525 paned->position_set = FALSE;
1528 g_object_freeze_notify (object);
1529 g_object_notify (object, "position");
1530 g_object_notify (object, "position-set");
1531 g_object_thaw_notify (object);
1533 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1536 /* Hacky work-around for bug #144269 */
1537 if (paned->child2 != NULL)
1539 gtk_widget_queue_draw (paned->child2);
1545 * gtk_paned_get_child1:
1546 * @paned: a #GtkPaned widget
1548 * Obtains the first child of the paned widget.
1550 * Return value: first child, or %NULL if it is not set.
1555 gtk_paned_get_child1 (GtkPaned *paned)
1557 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1559 return paned->child1;
1563 * gtk_paned_get_child2:
1564 * @paned: a #GtkPaned widget
1566 * Obtains the second child of the paned widget.
1568 * Return value: second child, or %NULL if it is not set.
1573 gtk_paned_get_child2 (GtkPaned *paned)
1575 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1577 return paned->child2;
1581 gtk_paned_calc_position (GtkPaned *paned,
1587 gint old_min_position;
1588 gint old_max_position;
1590 old_position = paned->child1_size;
1591 old_min_position = paned->min_position;
1592 old_max_position = paned->max_position;
1594 paned->min_position = paned->child1_shrink ? 0 : child1_req;
1596 paned->max_position = allocation;
1597 if (!paned->child2_shrink)
1598 paned->max_position = MAX (1, paned->max_position - child2_req);
1599 paned->max_position = MAX (paned->min_position, paned->max_position);
1601 if (!paned->position_set)
1603 if (paned->child1_resize && !paned->child2_resize)
1604 paned->child1_size = MAX (0, allocation - child2_req);
1605 else if (!paned->child1_resize && paned->child2_resize)
1606 paned->child1_size = child1_req;
1607 else if (child1_req + child2_req != 0)
1608 paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1610 paned->child1_size = allocation * 0.5 + 0.5;
1614 /* If the position was set before the initial allocation.
1615 * (paned->last_allocation <= 0) just clamp it and leave it.
1617 if (paned->last_allocation > 0)
1619 if (paned->child1_resize && !paned->child2_resize)
1620 paned->child1_size += allocation - paned->last_allocation;
1621 else if (!(!paned->child1_resize && paned->child2_resize))
1622 paned->child1_size = allocation * ((gdouble) paned->child1_size / (paned->last_allocation)) + 0.5;
1626 paned->child1_size = CLAMP (paned->child1_size,
1627 paned->min_position,
1628 paned->max_position);
1631 gtk_widget_set_child_visible (paned->child1, paned->child1_size != 0);
1634 gtk_widget_set_child_visible (paned->child2, paned->child1_size != allocation);
1636 g_object_freeze_notify (G_OBJECT (paned));
1637 if (paned->child1_size != old_position)
1638 g_object_notify (G_OBJECT (paned), "position");
1639 if (paned->min_position != old_min_position)
1640 g_object_notify (G_OBJECT (paned), "min-position");
1641 if (paned->max_position != old_max_position)
1642 g_object_notify (G_OBJECT (paned), "max-position");
1643 g_object_thaw_notify (G_OBJECT (paned));
1645 paned->last_allocation = allocation;
1649 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1651 if (paned->priv->saved_focus)
1652 g_object_remove_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1653 (gpointer *)&(paned->priv->saved_focus));
1655 paned->priv->saved_focus = widget;
1657 if (paned->priv->saved_focus)
1658 g_object_add_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1659 (gpointer *)&(paned->priv->saved_focus));
1663 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1665 if (paned->priv->first_paned)
1666 g_object_remove_weak_pointer (G_OBJECT (paned->priv->first_paned),
1667 (gpointer *)&(paned->priv->first_paned));
1669 paned->priv->first_paned = first_paned;
1671 if (paned->priv->first_paned)
1672 g_object_add_weak_pointer (G_OBJECT (paned->priv->first_paned),
1673 (gpointer *)&(paned->priv->first_paned));
1677 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1679 if (paned->last_child1_focus)
1680 g_object_remove_weak_pointer (G_OBJECT (paned->last_child1_focus),
1681 (gpointer *)&(paned->last_child1_focus));
1683 paned->last_child1_focus = widget;
1685 if (paned->last_child1_focus)
1686 g_object_add_weak_pointer (G_OBJECT (paned->last_child1_focus),
1687 (gpointer *)&(paned->last_child1_focus));
1691 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1693 if (paned->last_child2_focus)
1694 g_object_remove_weak_pointer (G_OBJECT (paned->last_child2_focus),
1695 (gpointer *)&(paned->last_child2_focus));
1697 paned->last_child2_focus = widget;
1699 if (paned->last_child2_focus)
1700 g_object_add_weak_pointer (G_OBJECT (paned->last_child2_focus),
1701 (gpointer *)&(paned->last_child2_focus));
1705 paned_get_focus_widget (GtkPaned *paned)
1707 GtkWidget *toplevel;
1709 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1710 if (gtk_widget_is_toplevel (toplevel))
1711 return GTK_WINDOW (toplevel)->focus_widget;
1717 gtk_paned_set_focus_child (GtkContainer *container,
1718 GtkWidget *focus_child)
1722 g_return_if_fail (GTK_IS_PANED (container));
1724 paned = GTK_PANED (container);
1726 if (focus_child == NULL)
1728 GtkWidget *last_focus;
1731 last_focus = paned_get_focus_widget (paned);
1735 /* If there is one or more paned widgets between us and the
1736 * focus widget, we want the topmost of those as last_focus
1738 for (w = last_focus; w != GTK_WIDGET (paned); w = w->parent)
1739 if (GTK_IS_PANED (w))
1742 if (container->focus_child == paned->child1)
1743 gtk_paned_set_last_child1_focus (paned, last_focus);
1744 else if (container->focus_child == paned->child2)
1745 gtk_paned_set_last_child2_focus (paned, last_focus);
1749 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1750 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1754 gtk_paned_get_cycle_chain (GtkPaned *paned,
1755 GtkDirectionType direction,
1758 GtkContainer *container = GTK_CONTAINER (paned);
1759 GtkWidget *ancestor = NULL;
1760 GList *temp_list = NULL;
1763 if (paned->in_recursion)
1766 g_assert (widgets != NULL);
1768 if (paned->last_child1_focus &&
1769 !gtk_widget_is_ancestor (paned->last_child1_focus, GTK_WIDGET (paned)))
1771 gtk_paned_set_last_child1_focus (paned, NULL);
1774 if (paned->last_child2_focus &&
1775 !gtk_widget_is_ancestor (paned->last_child2_focus, GTK_WIDGET (paned)))
1777 gtk_paned_set_last_child2_focus (paned, NULL);
1780 if (GTK_WIDGET (paned)->parent)
1781 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (paned)->parent, GTK_TYPE_PANED);
1783 /* The idea here is that temp_list is a list of widgets we want to cycle
1784 * to. The list is prioritized so that the first element is our first
1785 * choice, the next our second, and so on.
1787 * We can't just use g_list_reverse(), because we want to try
1788 * paned->last_child?_focus before paned->child?, both when we
1789 * are going forward and backward.
1791 if (direction == GTK_DIR_TAB_FORWARD)
1793 if (container->focus_child == paned->child1)
1795 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1796 temp_list = g_list_append (temp_list, paned->child2);
1797 temp_list = g_list_append (temp_list, ancestor);
1799 else if (container->focus_child == paned->child2)
1801 temp_list = g_list_append (temp_list, ancestor);
1802 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1803 temp_list = g_list_append (temp_list, paned->child1);
1807 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1808 temp_list = g_list_append (temp_list, paned->child1);
1809 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1810 temp_list = g_list_append (temp_list, paned->child2);
1811 temp_list = g_list_append (temp_list, ancestor);
1816 if (container->focus_child == paned->child1)
1818 temp_list = g_list_append (temp_list, ancestor);
1819 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1820 temp_list = g_list_append (temp_list, paned->child2);
1822 else if (container->focus_child == paned->child2)
1824 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1825 temp_list = g_list_append (temp_list, paned->child1);
1826 temp_list = g_list_append (temp_list, ancestor);
1830 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1831 temp_list = g_list_append (temp_list, 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 /* Walk the list and expand all the paned widgets. */
1839 for (list = temp_list; list != NULL; list = list->next)
1841 GtkWidget *widget = list->data;
1845 if (GTK_IS_PANED (widget))
1847 paned->in_recursion = TRUE;
1848 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1849 paned->in_recursion = FALSE;
1853 *widgets = g_list_append (*widgets, widget);
1858 g_list_free (temp_list);
1862 gtk_paned_cycle_child_focus (GtkPaned *paned,
1865 GList *cycle_chain = NULL;
1868 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1870 /* ignore f6 if the handle is focused */
1871 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1874 /* we can't just let the event propagate up the hierarchy,
1875 * because the paned will want to cycle focus _unless_ an
1876 * ancestor paned handles the event
1878 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1880 for (list = cycle_chain; list != NULL; list = list->next)
1881 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1884 g_list_free (cycle_chain);
1890 get_child_panes (GtkWidget *widget,
1893 if (!widget || !gtk_widget_get_realized (widget))
1896 if (GTK_IS_PANED (widget))
1898 GtkPaned *paned = GTK_PANED (widget);
1900 get_child_panes (paned->child1, panes);
1901 *panes = g_list_prepend (*panes, widget);
1902 get_child_panes (paned->child2, panes);
1904 else if (GTK_IS_CONTAINER (widget))
1906 gtk_container_forall (GTK_CONTAINER (widget),
1907 (GtkCallback)get_child_panes, panes);
1912 get_all_panes (GtkPaned *paned)
1914 GtkPaned *topmost = NULL;
1915 GList *result = NULL;
1918 for (w = GTK_WIDGET (paned); w != NULL; w = w->parent)
1920 if (GTK_IS_PANED (w))
1921 topmost = GTK_PANED (w);
1926 get_child_panes (GTK_WIDGET (topmost), &result);
1928 return g_list_reverse (result);
1932 gtk_paned_find_neighbours (GtkPaned *paned,
1939 all_panes = get_all_panes (paned);
1940 g_assert (all_panes);
1942 this_link = g_list_find (all_panes, paned);
1944 g_assert (this_link);
1946 if (this_link->next)
1947 *next = this_link->next->data;
1949 *next = all_panes->data;
1951 if (this_link->prev)
1952 *prev = this_link->prev->data;
1954 *prev = g_list_last (all_panes)->data;
1956 g_list_free (all_panes);
1960 gtk_paned_move_handle (GtkPaned *paned,
1961 GtkScrollType scroll)
1963 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1970 SINGLE_STEP_SIZE = 1,
1974 new_position = old_position = gtk_paned_get_position (paned);
1979 case GTK_SCROLL_STEP_LEFT:
1980 case GTK_SCROLL_STEP_UP:
1981 case GTK_SCROLL_STEP_BACKWARD:
1982 increment = - SINGLE_STEP_SIZE;
1985 case GTK_SCROLL_STEP_RIGHT:
1986 case GTK_SCROLL_STEP_DOWN:
1987 case GTK_SCROLL_STEP_FORWARD:
1988 increment = SINGLE_STEP_SIZE;
1991 case GTK_SCROLL_PAGE_LEFT:
1992 case GTK_SCROLL_PAGE_UP:
1993 case GTK_SCROLL_PAGE_BACKWARD:
1994 increment = - PAGE_STEP_SIZE;
1997 case GTK_SCROLL_PAGE_RIGHT:
1998 case GTK_SCROLL_PAGE_DOWN:
1999 case GTK_SCROLL_PAGE_FORWARD:
2000 increment = PAGE_STEP_SIZE;
2003 case GTK_SCROLL_START:
2004 new_position = paned->min_position;
2007 case GTK_SCROLL_END:
2008 new_position = paned->max_position;
2018 increment = -increment;
2020 new_position = old_position + increment;
2023 new_position = CLAMP (new_position, paned->min_position, paned->max_position);
2025 if (old_position != new_position)
2026 gtk_paned_set_position (paned, new_position);
2035 gtk_paned_restore_focus (GtkPaned *paned)
2037 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2039 if (paned->priv->saved_focus &&
2040 gtk_widget_get_sensitive (paned->priv->saved_focus))
2042 gtk_widget_grab_focus (paned->priv->saved_focus);
2046 /* the saved focus is somehow not available for focusing,
2048 * 1) tabbing into the paned widget
2049 * if that didn't work,
2050 * 2) unset focus for the window if there is one
2053 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2055 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2057 if (GTK_IS_WINDOW (toplevel))
2058 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2062 gtk_paned_set_saved_focus (paned, NULL);
2063 gtk_paned_set_first_paned (paned, NULL);
2068 gtk_paned_accept_position (GtkPaned *paned)
2070 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2072 paned->original_position = -1;
2073 gtk_paned_restore_focus (paned);
2083 gtk_paned_cancel_position (GtkPaned *paned)
2085 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2087 if (paned->original_position != -1)
2089 gtk_paned_set_position (paned, paned->original_position);
2090 paned->original_position = -1;
2093 gtk_paned_restore_focus (paned);
2101 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2104 GtkPaned *next, *prev;
2106 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2108 GtkPaned *focus = NULL;
2110 if (!paned->priv->first_paned)
2112 /* The first_pane has disappeared. As an ad-hoc solution,
2113 * we make the currently focused paned the first_paned. To the
2114 * user this will seem like the paned cycling has been reset.
2117 gtk_paned_set_first_paned (paned, paned);
2120 gtk_paned_find_neighbours (paned, &next, &prev);
2122 if (reversed && prev &&
2123 prev != paned && paned != paned->priv->first_paned)
2127 else if (!reversed && next &&
2128 next != paned && next != paned->priv->first_paned)
2134 gtk_paned_accept_position (paned);
2140 gtk_paned_set_saved_focus (focus, paned->priv->saved_focus);
2141 gtk_paned_set_first_paned (focus, paned->priv->first_paned);
2143 gtk_paned_set_saved_focus (paned, NULL);
2144 gtk_paned_set_first_paned (paned, NULL);
2146 gtk_widget_grab_focus (GTK_WIDGET (focus));
2148 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2150 paned->original_position = -1;
2151 focus->original_position = gtk_paned_get_position (focus);
2156 GtkContainer *container = GTK_CONTAINER (paned);
2159 GtkPaned *prev, *next;
2160 GtkWidget *toplevel;
2162 gtk_paned_find_neighbours (paned, &next, &prev);
2164 if (container->focus_child == paned->child1)
2177 else if (container->focus_child == paned->child2)
2192 /* Focus is not inside this paned, and we don't have focus.
2193 * Presumably this happened because the application wants us
2194 * to start keyboard navigating.
2204 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2206 if (GTK_IS_WINDOW (toplevel))
2207 gtk_paned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
2208 gtk_paned_set_first_paned (focus, first);
2209 focus->original_position = gtk_paned_get_position (focus);
2211 gtk_widget_grab_focus (GTK_WIDGET (focus));
2218 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2220 /* This function/signal has the wrong name. It is called when you
2221 * press Tab or Shift-Tab and what we do is act as if
2222 * the user pressed Return and then Tab or Shift-Tab
2224 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2225 gtk_paned_accept_position (paned);
2231 * gtk_paned_get_handle_window:
2232 * @paned: a #GtkPaned
2234 * Returns the #GdkWindow of the handle. This function is
2235 * useful when handling button or motion events because it
2236 * enables the callback to distinguish between the window
2237 * of the paned, a child and the handle.
2239 * Return value: the paned's handle window.
2244 gtk_paned_get_handle_window (GtkPaned *paned)
2246 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2248 return paned->handle;