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;
156 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
157 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
160 static guint signals[LAST_SIGNAL] = { 0 };
164 add_tab_bindings (GtkBindingSet *binding_set,
165 GdkModifierType modifiers)
167 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
168 "toggle-handle-focus", 0);
169 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
170 "toggle-handle-focus", 0);
174 add_move_binding (GtkBindingSet *binding_set,
176 GdkModifierType mask,
177 GtkScrollType scroll)
179 gtk_binding_entry_add_signal (binding_set, keyval, mask,
181 GTK_TYPE_SCROLL_TYPE, scroll);
185 gtk_paned_class_init (GtkPanedClass *class)
187 GObjectClass *object_class;
188 GtkWidgetClass *widget_class;
189 GtkContainerClass *container_class;
190 GtkPanedClass *paned_class;
191 GtkBindingSet *binding_set;
193 object_class = (GObjectClass *) class;
194 widget_class = (GtkWidgetClass *) class;
195 container_class = (GtkContainerClass *) class;
196 paned_class = (GtkPanedClass *) class;
198 object_class->set_property = gtk_paned_set_property;
199 object_class->get_property = gtk_paned_get_property;
200 object_class->finalize = gtk_paned_finalize;
202 widget_class->size_request = gtk_paned_size_request;
203 widget_class->size_allocate = gtk_paned_size_allocate;
204 widget_class->realize = gtk_paned_realize;
205 widget_class->unrealize = gtk_paned_unrealize;
206 widget_class->map = gtk_paned_map;
207 widget_class->unmap = gtk_paned_unmap;
208 widget_class->expose_event = gtk_paned_expose;
209 widget_class->focus = gtk_paned_focus;
210 widget_class->enter_notify_event = gtk_paned_enter;
211 widget_class->leave_notify_event = gtk_paned_leave;
212 widget_class->button_press_event = gtk_paned_button_press;
213 widget_class->button_release_event = gtk_paned_button_release;
214 widget_class->motion_notify_event = gtk_paned_motion;
215 widget_class->grab_broken_event = gtk_paned_grab_broken;
216 widget_class->grab_notify = gtk_paned_grab_notify;
217 widget_class->state_changed = gtk_paned_state_changed;
219 container_class->add = gtk_paned_add;
220 container_class->remove = gtk_paned_remove;
221 container_class->forall = gtk_paned_forall;
222 container_class->child_type = gtk_paned_child_type;
223 container_class->set_focus_child = gtk_paned_set_focus_child;
224 container_class->set_child_property = gtk_paned_set_child_property;
225 container_class->get_child_property = gtk_paned_get_child_property;
227 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
228 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
229 paned_class->move_handle = gtk_paned_move_handle;
230 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
231 paned_class->accept_position = gtk_paned_accept_position;
232 paned_class->cancel_position = gtk_paned_cancel_position;
234 g_object_class_override_property (object_class,
238 g_object_class_install_property (object_class,
240 g_param_spec_int ("position",
242 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
246 GTK_PARAM_READWRITE));
248 g_object_class_install_property (object_class,
250 g_param_spec_boolean ("position-set",
252 P_("TRUE if the Position property should be used"),
254 GTK_PARAM_READWRITE));
256 gtk_widget_class_install_style_property (widget_class,
257 g_param_spec_int ("handle-size",
259 P_("Width of handle"),
263 GTK_PARAM_READABLE));
265 * GtkPaned:min-position:
267 * The smallest possible value for the position property. This property is derived from the
268 * size and shrinkability of the widget's children.
272 g_object_class_install_property (object_class,
274 g_param_spec_int ("min-position",
275 P_("Minimal Position"),
276 P_("Smallest possible value for the \"position\" property"),
280 GTK_PARAM_READABLE));
283 * GtkPaned:max-position:
285 * The largest possible value for the position property. This property is derived from the
286 * size and shrinkability of the widget's children.
290 g_object_class_install_property (object_class,
292 g_param_spec_int ("max-position",
293 P_("Maximal Position"),
294 P_("Largest possible value for the \"position\" property"),
298 GTK_PARAM_READABLE));
303 * The "resize" child property determines whether the child expands and
304 * shrinks along with the paned widget.
308 gtk_container_class_install_child_property (container_class,
310 g_param_spec_boolean ("resize",
312 P_("If TRUE, the child expands and shrinks along with the paned widget"),
314 GTK_PARAM_READWRITE));
319 * The "shrink" child property determines whether the child can be made
320 * smaller than its requisition.
324 gtk_container_class_install_child_property (container_class,
326 g_param_spec_boolean ("shrink",
328 P_("If TRUE, the child can be made smaller than its requisition"),
330 GTK_PARAM_READWRITE));
333 * GtkPaned::cycle-child-focus:
334 * @widget: the object that received the signal
335 * @reversed: whether cycling backward or forward
337 * The ::cycle-child-focus signal is a
338 * <link linkend="keybinding-signals">keybinding signal</link>
339 * which gets emitted to cycle the focus between the children of the paned.
341 * The default binding is f6.
345 signals [CYCLE_CHILD_FOCUS] =
346 g_signal_new (I_("cycle-child-focus"),
347 G_TYPE_FROM_CLASS (object_class),
348 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
349 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
351 _gtk_marshal_BOOLEAN__BOOLEAN,
356 * GtkPaned::toggle-handle-focus:
357 * @widget: the object that received the signal
359 * The ::toggle-handle-focus is a
360 * <link linkend="keybinding-signals">keybinding signal</link>
361 * which gets emitted to accept the current position of the handle and then
362 * move focus to the next widget in the focus chain.
364 * The default binding is Tab.
368 signals [TOGGLE_HANDLE_FOCUS] =
369 g_signal_new (I_("toggle-handle-focus"),
370 G_TYPE_FROM_CLASS (object_class),
371 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
372 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
374 _gtk_marshal_BOOLEAN__VOID,
378 * GtkPaned::move-handle:
379 * @widget: the object that received the signal
380 * @scroll_type: a #GtkScrollType
382 * The ::move-handle signal is a
383 * <link linkend="keybinding-signals">keybinding signal</link>
384 * which gets emitted to move the handle when the user is using key bindings
389 signals[MOVE_HANDLE] =
390 g_signal_new (I_("move-handle"),
391 G_TYPE_FROM_CLASS (object_class),
392 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
393 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
395 _gtk_marshal_BOOLEAN__ENUM,
397 GTK_TYPE_SCROLL_TYPE);
400 * GtkPaned::cycle-handle-focus:
401 * @widget: the object that received the signal
402 * @reversed: whether cycling backward or forward
404 * The ::cycle-handle-focus signal is a
405 * <link linkend="keybinding-signals">keybinding signal</link>
406 * which gets emitted to cycle whether the paned should grab focus to allow
407 * the user to change position of the handle by using key bindings.
409 * The default binding for this signal is f8.
413 signals [CYCLE_HANDLE_FOCUS] =
414 g_signal_new (I_("cycle-handle-focus"),
415 G_TYPE_FROM_CLASS (object_class),
416 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
417 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
419 _gtk_marshal_BOOLEAN__BOOLEAN,
424 * GtkPaned::accept-position:
425 * @widget: the object that received the signal
427 * The ::accept-position signal is a
428 * <link linkend="keybinding-signals">keybinding signal</link>
429 * which gets emitted to accept the current position of the handle when
430 * moving it using key bindings.
432 * The default binding for this signal is Return or Space.
436 signals [ACCEPT_POSITION] =
437 g_signal_new (I_("accept-position"),
438 G_TYPE_FROM_CLASS (object_class),
439 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
440 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
442 _gtk_marshal_BOOLEAN__VOID,
446 * GtkPaned::cancel-position:
447 * @widget: the object that received the signal
449 * The ::cancel-position signal is a
450 * <link linkend="keybinding-signals">keybinding signal</link>
451 * which gets emitted to cancel moving the position of the handle using key
452 * bindings. The position of the handle will be reset to the value prior to
455 * The default binding for this signal is Escape.
459 signals [CANCEL_POSITION] =
460 g_signal_new (I_("cancel-position"),
461 G_TYPE_FROM_CLASS (object_class),
462 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
463 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
465 _gtk_marshal_BOOLEAN__VOID,
468 binding_set = gtk_binding_set_by_class (class);
471 gtk_binding_entry_add_signal (binding_set,
473 "cycle-child-focus", 1,
474 G_TYPE_BOOLEAN, FALSE);
475 gtk_binding_entry_add_signal (binding_set,
476 GDK_F6, GDK_SHIFT_MASK,
477 "cycle-child-focus", 1,
478 G_TYPE_BOOLEAN, TRUE);
481 gtk_binding_entry_add_signal (binding_set,
483 "cycle-handle-focus", 1,
484 G_TYPE_BOOLEAN, FALSE);
486 gtk_binding_entry_add_signal (binding_set,
487 GDK_F8, GDK_SHIFT_MASK,
488 "cycle-handle-focus", 1,
489 G_TYPE_BOOLEAN, TRUE);
491 add_tab_bindings (binding_set, 0);
492 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
493 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
494 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
496 /* accept and cancel positions */
497 gtk_binding_entry_add_signal (binding_set,
499 "cancel-position", 0);
501 gtk_binding_entry_add_signal (binding_set,
503 "accept-position", 0);
504 gtk_binding_entry_add_signal (binding_set,
506 "accept-position", 0);
507 gtk_binding_entry_add_signal (binding_set,
509 "accept-position", 0);
510 gtk_binding_entry_add_signal (binding_set,
512 "accept-position", 0);
513 gtk_binding_entry_add_signal (binding_set,
515 "accept-position", 0);
518 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
519 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
520 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
521 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
523 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
524 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
525 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
526 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
528 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
529 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
530 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
531 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
532 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
533 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
535 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
536 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
537 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
538 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
539 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
540 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
542 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
543 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
544 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
545 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
547 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
551 gtk_paned_child_type (GtkContainer *container)
553 if (!GTK_PANED (container)->child1 || !GTK_PANED (container)->child2)
554 return GTK_TYPE_WIDGET;
560 gtk_paned_init (GtkPaned *paned)
562 GTK_WIDGET_SET_FLAGS (paned, GTK_NO_WINDOW);
563 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
565 /* We only need to redraw when the handle position moves, which is
566 * independent of the overall allocation of the GtkPaned
568 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
570 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
572 paned->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
573 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
575 paned->child1 = NULL;
576 paned->child2 = NULL;
577 paned->handle = NULL;
578 paned->xor_gc = NULL;
579 paned->cursor_type = GDK_CROSS;
581 paned->handle_pos.width = 5;
582 paned->handle_pos.height = 5;
583 paned->position_set = FALSE;
584 paned->last_allocation = -1;
585 paned->in_drag = FALSE;
587 paned->last_child1_focus = NULL;
588 paned->last_child2_focus = NULL;
589 paned->in_recursion = FALSE;
590 paned->handle_prelit = FALSE;
591 paned->original_position = -1;
593 paned->handle_pos.x = -1;
594 paned->handle_pos.y = -1;
596 paned->drag_pos = -1;
600 gtk_paned_set_property (GObject *object,
605 GtkPaned *paned = GTK_PANED (object);
609 case PROP_ORIENTATION:
610 paned->priv->orientation = g_value_get_enum (value);
611 paned->orientation = !paned->priv->orientation;
613 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
614 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
616 paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
618 /* state_changed updates the cursor */
619 gtk_paned_state_changed (GTK_WIDGET (paned), GTK_WIDGET (paned)->state);
620 gtk_widget_queue_resize (GTK_WIDGET (paned));
623 gtk_paned_set_position (paned, g_value_get_int (value));
625 case PROP_POSITION_SET:
626 paned->position_set = g_value_get_boolean (value);
627 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
630 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
636 gtk_paned_get_property (GObject *object,
641 GtkPaned *paned = GTK_PANED (object);
645 case PROP_ORIENTATION:
646 g_value_set_enum (value, paned->priv->orientation);
649 g_value_set_int (value, paned->child1_size);
651 case PROP_POSITION_SET:
652 g_value_set_boolean (value, paned->position_set);
654 case PROP_MIN_POSITION:
655 g_value_set_int (value, paned->min_position);
657 case PROP_MAX_POSITION:
658 g_value_set_int (value, paned->max_position);
661 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
667 gtk_paned_set_child_property (GtkContainer *container,
673 GtkPaned *paned = GTK_PANED (container);
674 gboolean old_value, new_value;
676 g_assert (child == paned->child1 || child == paned->child2);
678 new_value = g_value_get_boolean (value);
681 case CHILD_PROP_RESIZE:
682 if (child == paned->child1)
684 old_value = paned->child1_resize;
685 paned->child1_resize = new_value;
689 old_value = paned->child2_resize;
690 paned->child2_resize = new_value;
693 case CHILD_PROP_SHRINK:
694 if (child == paned->child1)
696 old_value = paned->child1_shrink;
697 paned->child1_shrink = new_value;
701 old_value = paned->child2_shrink;
702 paned->child2_shrink = new_value;
706 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
707 old_value = -1; /* quiet gcc */
710 if (old_value != new_value)
711 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
715 gtk_paned_get_child_property (GtkContainer *container,
721 GtkPaned *paned = GTK_PANED (container);
723 g_assert (child == paned->child1 || child == paned->child2);
727 case CHILD_PROP_RESIZE:
728 if (child == paned->child1)
729 g_value_set_boolean (value, paned->child1_resize);
731 g_value_set_boolean (value, paned->child2_resize);
733 case CHILD_PROP_SHRINK:
734 if (child == paned->child1)
735 g_value_set_boolean (value, paned->child1_shrink);
737 g_value_set_boolean (value, paned->child2_shrink);
740 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
746 gtk_paned_finalize (GObject *object)
748 GtkPaned *paned = GTK_PANED (object);
750 gtk_paned_set_saved_focus (paned, NULL);
751 gtk_paned_set_first_paned (paned, NULL);
753 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
757 gtk_paned_size_request (GtkWidget *widget,
758 GtkRequisition *requisition)
760 GtkPaned *paned = GTK_PANED (widget);
761 GtkRequisition child_requisition;
763 requisition->width = 0;
764 requisition->height = 0;
766 if (paned->child1 && gtk_widget_get_visible (paned->child1))
768 gtk_widget_size_request (paned->child1, &child_requisition);
770 requisition->height = child_requisition.height;
771 requisition->width = child_requisition.width;
774 if (paned->child2 && gtk_widget_get_visible (paned->child2))
776 gtk_widget_size_request (paned->child2, &child_requisition);
778 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
780 requisition->height = MAX (requisition->height,
781 child_requisition.height);
782 requisition->width += child_requisition.width;
786 requisition->width = MAX (requisition->width,
787 child_requisition.width);
788 requisition->height += child_requisition.height;
792 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
793 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
795 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
796 paned->child2 && gtk_widget_get_visible (paned->child2))
800 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
802 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
803 requisition->width += handle_size;
805 requisition->height += handle_size;
810 flip_child (GtkWidget *widget,
811 GtkAllocation *child_pos)
813 gint x = widget->allocation.x;
814 gint width = widget->allocation.width;
816 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
820 gtk_paned_size_allocate (GtkWidget *widget,
821 GtkAllocation *allocation)
823 GtkPaned *paned = GTK_PANED (widget);
824 gint border_width = GTK_CONTAINER (paned)->border_width;
826 widget->allocation = *allocation;
828 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
829 paned->child2 && gtk_widget_get_visible (paned->child2))
831 GtkRequisition child1_requisition;
832 GtkRequisition child2_requisition;
833 GtkAllocation child1_allocation;
834 GtkAllocation child2_allocation;
835 GdkRectangle old_handle_pos;
838 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
840 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
841 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
843 old_handle_pos = paned->handle_pos;
845 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
847 gtk_paned_calc_position (paned,
848 MAX (1, widget->allocation.width
851 child1_requisition.width,
852 child2_requisition.width);
854 paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
855 paned->handle_pos.y = widget->allocation.y + border_width;
856 paned->handle_pos.width = handle_size;
857 paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
859 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
860 child1_allocation.width = MAX (1, paned->child1_size);
861 child1_allocation.x = widget->allocation.x + border_width;
862 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
864 child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
865 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
867 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
869 flip_child (widget, &(child2_allocation));
870 flip_child (widget, &(child1_allocation));
871 flip_child (widget, &(paned->handle_pos));
876 gtk_paned_calc_position (paned,
877 MAX (1, widget->allocation.height
880 child1_requisition.height,
881 child2_requisition.height);
883 paned->handle_pos.x = widget->allocation.x + border_width;
884 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
885 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
886 paned->handle_pos.height = handle_size;
888 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
889 child1_allocation.height = MAX (1, paned->child1_size);
890 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
891 child1_allocation.y = widget->allocation.y + border_width;
893 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
894 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
897 if (gtk_widget_get_mapped (widget) &&
898 (old_handle_pos.x != paned->handle_pos.x ||
899 old_handle_pos.y != paned->handle_pos.y ||
900 old_handle_pos.width != paned->handle_pos.width ||
901 old_handle_pos.height != paned->handle_pos.height))
903 gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
904 gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
907 if (GTK_WIDGET_REALIZED (widget))
909 if (gtk_widget_get_mapped (widget))
910 gdk_window_show (paned->handle);
912 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
914 gdk_window_move_resize (paned->handle,
918 paned->handle_pos.height);
922 gdk_window_move_resize (paned->handle,
925 paned->handle_pos.width,
930 /* Now allocate the childen, making sure, when resizing not to
931 * overlap the windows
933 if (gtk_widget_get_mapped (widget) &&
935 ((paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
936 paned->child1->allocation.width < child1_allocation.width) ||
938 (paned->priv->orientation == GTK_ORIENTATION_VERTICAL &&
939 paned->child1->allocation.height < child1_allocation.height)))
941 gtk_widget_size_allocate (paned->child2, &child2_allocation);
942 gtk_widget_size_allocate (paned->child1, &child1_allocation);
946 gtk_widget_size_allocate (paned->child1, &child1_allocation);
947 gtk_widget_size_allocate (paned->child2, &child2_allocation);
952 GtkAllocation child_allocation;
954 if (GTK_WIDGET_REALIZED (widget))
955 gdk_window_hide (paned->handle);
958 gtk_widget_set_child_visible (paned->child1, TRUE);
960 gtk_widget_set_child_visible (paned->child2, TRUE);
962 child_allocation.x = widget->allocation.x + border_width;
963 child_allocation.y = widget->allocation.y + border_width;
964 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
965 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
967 if (paned->child1 && gtk_widget_get_visible (paned->child1))
968 gtk_widget_size_allocate (paned->child1, &child_allocation);
969 else if (paned->child2 && gtk_widget_get_visible (paned->child2))
970 gtk_widget_size_allocate (paned->child2, &child_allocation);
975 gtk_paned_realize (GtkWidget *widget)
978 GdkWindowAttr attributes;
979 gint attributes_mask;
981 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
982 paned = GTK_PANED (widget);
984 widget->window = gtk_widget_get_parent_window (widget);
985 g_object_ref (widget->window);
987 attributes.window_type = GDK_WINDOW_CHILD;
988 attributes.wclass = GDK_INPUT_ONLY;
989 attributes.x = paned->handle_pos.x;
990 attributes.y = paned->handle_pos.y;
991 attributes.width = paned->handle_pos.width;
992 attributes.height = paned->handle_pos.height;
993 attributes.event_mask = gtk_widget_get_events (widget);
994 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
995 GDK_BUTTON_RELEASE_MASK |
996 GDK_ENTER_NOTIFY_MASK |
997 GDK_LEAVE_NOTIFY_MASK |
998 GDK_POINTER_MOTION_MASK |
999 GDK_POINTER_MOTION_HINT_MASK);
1000 attributes_mask = GDK_WA_X | GDK_WA_Y;
1001 if (gtk_widget_is_sensitive (widget))
1003 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1004 paned->cursor_type);
1005 attributes_mask |= GDK_WA_CURSOR;
1008 paned->handle = gdk_window_new (widget->window,
1009 &attributes, attributes_mask);
1010 gdk_window_set_user_data (paned->handle, paned);
1011 if (attributes_mask & GDK_WA_CURSOR)
1012 gdk_cursor_unref (attributes.cursor);
1014 widget->style = gtk_style_attach (widget->style, widget->window);
1016 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
1017 paned->child2 && gtk_widget_get_visible (paned->child2))
1018 gdk_window_show (paned->handle);
1022 gtk_paned_unrealize (GtkWidget *widget)
1024 GtkPaned *paned = GTK_PANED (widget);
1028 g_object_unref (paned->xor_gc);
1029 paned->xor_gc = NULL;
1034 gdk_window_set_user_data (paned->handle, NULL);
1035 gdk_window_destroy (paned->handle);
1036 paned->handle = NULL;
1039 gtk_paned_set_last_child1_focus (paned, NULL);
1040 gtk_paned_set_last_child2_focus (paned, NULL);
1041 gtk_paned_set_saved_focus (paned, NULL);
1042 gtk_paned_set_first_paned (paned, NULL);
1044 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1048 gtk_paned_map (GtkWidget *widget)
1050 GtkPaned *paned = GTK_PANED (widget);
1052 gdk_window_show (paned->handle);
1054 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1058 gtk_paned_unmap (GtkWidget *widget)
1060 GtkPaned *paned = GTK_PANED (widget);
1062 gdk_window_hide (paned->handle);
1064 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1068 gtk_paned_expose (GtkWidget *widget,
1069 GdkEventExpose *event)
1071 GtkPaned *paned = GTK_PANED (widget);
1073 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1074 paned->child1 && gtk_widget_get_visible (paned->child1) &&
1075 paned->child2 && gtk_widget_get_visible (paned->child2))
1079 if (gtk_widget_is_focus (widget))
1080 state = GTK_STATE_SELECTED;
1081 else if (paned->handle_prelit)
1082 state = GTK_STATE_PRELIGHT;
1084 state = GTK_WIDGET_STATE (widget);
1086 gtk_paint_handle (widget->style, widget->window,
1087 state, GTK_SHADOW_NONE,
1088 &paned->handle_pos, widget, "paned",
1089 paned->handle_pos.x, paned->handle_pos.y,
1090 paned->handle_pos.width, paned->handle_pos.height,
1091 !paned->priv->orientation);
1094 /* Chain up to draw children */
1095 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1101 is_rtl (GtkPaned *paned)
1103 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1104 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1113 update_drag (GtkPaned *paned)
1119 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1120 gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
1122 gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
1124 pos -= paned->drag_pos;
1128 gtk_widget_style_get (GTK_WIDGET (paned),
1129 "handle-size", &handle_size,
1132 size = GTK_WIDGET (paned)->allocation.width - pos - handle_size;
1139 size -= GTK_CONTAINER (paned)->border_width;
1141 size = CLAMP (size, paned->min_position, paned->max_position);
1143 if (size != paned->child1_size)
1144 gtk_paned_set_position (paned, size);
1148 gtk_paned_enter (GtkWidget *widget,
1149 GdkEventCrossing *event)
1151 GtkPaned *paned = GTK_PANED (widget);
1154 update_drag (paned);
1157 paned->handle_prelit = TRUE;
1158 gtk_widget_queue_draw_area (widget,
1159 paned->handle_pos.x,
1160 paned->handle_pos.y,
1161 paned->handle_pos.width,
1162 paned->handle_pos.height);
1169 gtk_paned_leave (GtkWidget *widget,
1170 GdkEventCrossing *event)
1172 GtkPaned *paned = GTK_PANED (widget);
1175 update_drag (paned);
1178 paned->handle_prelit = FALSE;
1179 gtk_widget_queue_draw_area (widget,
1180 paned->handle_pos.x,
1181 paned->handle_pos.y,
1182 paned->handle_pos.width,
1183 paned->handle_pos.height);
1190 gtk_paned_focus (GtkWidget *widget,
1191 GtkDirectionType direction)
1196 /* This is a hack, but how can this be done without
1197 * excessive cut-and-paste from gtkcontainer.c?
1200 gtk_widget_set_can_focus (widget, FALSE);
1201 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1202 gtk_widget_set_can_focus (widget, TRUE);
1208 gtk_paned_button_press (GtkWidget *widget,
1209 GdkEventButton *event)
1211 GtkPaned *paned = GTK_PANED (widget);
1213 if (!paned->in_drag &&
1214 (event->window == paned->handle) && (event->button == 1))
1216 /* We need a server grab here, not gtk_grab_add(), since
1217 * we don't want to pass events on to the widget's children */
1218 if (gdk_pointer_grab (paned->handle, FALSE,
1219 GDK_POINTER_MOTION_HINT_MASK
1220 | GDK_BUTTON1_MOTION_MASK
1221 | GDK_BUTTON_RELEASE_MASK
1222 | GDK_ENTER_NOTIFY_MASK
1223 | GDK_LEAVE_NOTIFY_MASK,
1225 event->time) != GDK_GRAB_SUCCESS)
1228 paned->in_drag = TRUE;
1229 paned->priv->grab_time = event->time;
1231 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1232 paned->drag_pos = event->x;
1234 paned->drag_pos = event->y;
1243 gtk_paned_grab_broken (GtkWidget *widget,
1244 GdkEventGrabBroken *event)
1246 GtkPaned *paned = GTK_PANED (widget);
1248 paned->in_drag = FALSE;
1249 paned->drag_pos = -1;
1250 paned->position_set = TRUE;
1256 stop_drag (GtkPaned *paned)
1258 paned->in_drag = FALSE;
1259 paned->drag_pos = -1;
1260 paned->position_set = TRUE;
1261 gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (paned)),
1262 paned->priv->grab_time);
1266 gtk_paned_grab_notify (GtkWidget *widget,
1267 gboolean was_grabbed)
1269 GtkPaned *paned = GTK_PANED (widget);
1271 if (!was_grabbed && paned->in_drag)
1276 gtk_paned_state_changed (GtkWidget *widget,
1277 GtkStateType previous_state)
1279 GtkPaned *paned = GTK_PANED (widget);
1282 if (GTK_WIDGET_REALIZED (paned))
1284 if (gtk_widget_is_sensitive (widget))
1285 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1286 paned->cursor_type);
1290 gdk_window_set_cursor (paned->handle, cursor);
1293 gdk_cursor_unref (cursor);
1298 gtk_paned_button_release (GtkWidget *widget,
1299 GdkEventButton *event)
1301 GtkPaned *paned = GTK_PANED (widget);
1303 if (paned->in_drag && (event->button == 1))
1314 gtk_paned_motion (GtkWidget *widget,
1315 GdkEventMotion *event)
1317 GtkPaned *paned = GTK_PANED (widget);
1321 update_drag (paned);
1331 * @orientation: the paned's orientation.
1333 * Creates a new #GtkPaned widget.
1335 * Return value: a new #GtkPaned.
1340 gtk_paned_new (GtkOrientation orientation)
1342 return g_object_new (GTK_TYPE_PANED,
1343 "orientation", orientation,
1349 gtk_paned_add1 (GtkPaned *paned,
1352 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1356 gtk_paned_add2 (GtkPaned *paned,
1359 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1363 gtk_paned_pack1 (GtkPaned *paned,
1368 g_return_if_fail (GTK_IS_PANED (paned));
1369 g_return_if_fail (GTK_IS_WIDGET (child));
1373 paned->child1 = child;
1374 paned->child1_resize = resize;
1375 paned->child1_shrink = shrink;
1377 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1382 gtk_paned_pack2 (GtkPaned *paned,
1387 g_return_if_fail (GTK_IS_PANED (paned));
1388 g_return_if_fail (GTK_IS_WIDGET (child));
1392 paned->child2 = child;
1393 paned->child2_resize = resize;
1394 paned->child2_shrink = shrink;
1396 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1402 gtk_paned_add (GtkContainer *container,
1407 g_return_if_fail (GTK_IS_PANED (container));
1409 paned = GTK_PANED (container);
1412 gtk_paned_add1 (paned, widget);
1413 else if (!paned->child2)
1414 gtk_paned_add2 (paned, widget);
1416 g_warning ("GtkPaned cannot have more than 2 children\n");
1420 gtk_paned_remove (GtkContainer *container,
1424 gboolean was_visible;
1426 paned = GTK_PANED (container);
1427 was_visible = gtk_widget_get_visible (widget);
1429 if (paned->child1 == widget)
1431 gtk_widget_unparent (widget);
1433 paned->child1 = NULL;
1435 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1436 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1438 else if (paned->child2 == widget)
1440 gtk_widget_unparent (widget);
1442 paned->child2 = NULL;
1444 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1445 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1450 gtk_paned_forall (GtkContainer *container,
1451 gboolean include_internals,
1452 GtkCallback callback,
1453 gpointer callback_data)
1457 g_return_if_fail (callback != NULL);
1459 paned = GTK_PANED (container);
1462 (*callback) (paned->child1, callback_data);
1464 (*callback) (paned->child2, callback_data);
1468 * gtk_paned_get_position:
1469 * @paned: a #GtkPaned widget
1471 * Obtains the position of the divider between the two panes.
1473 * Return value: position of the divider
1476 gtk_paned_get_position (GtkPaned *paned)
1478 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1480 return paned->child1_size;
1484 * gtk_paned_set_position:
1485 * @paned: a #GtkPaned widget
1486 * @position: pixel position of divider, a negative value means that the position
1489 * Sets the position of the divider between the two panes.
1492 gtk_paned_set_position (GtkPaned *paned,
1497 g_return_if_fail (GTK_IS_PANED (paned));
1499 if (paned->child1_size == position)
1502 object = G_OBJECT (paned);
1506 /* We don't clamp here - the assumption is that
1507 * if the total allocation changes at the same time
1508 * as the position, the position set is with reference
1509 * to the new total size. If only the position changes,
1510 * then clamping will occur in gtk_paned_calc_position()
1513 paned->child1_size = position;
1514 paned->position_set = TRUE;
1518 paned->position_set = FALSE;
1521 g_object_freeze_notify (object);
1522 g_object_notify (object, "position");
1523 g_object_notify (object, "position-set");
1524 g_object_thaw_notify (object);
1526 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1529 /* Hacky work-around for bug #144269 */
1530 if (paned->child2 != NULL)
1532 gtk_widget_queue_draw (paned->child2);
1538 * gtk_paned_get_child1:
1539 * @paned: a #GtkPaned widget
1541 * Obtains the first child of the paned widget.
1543 * Return value: first child, or %NULL if it is not set.
1548 gtk_paned_get_child1 (GtkPaned *paned)
1550 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1552 return paned->child1;
1556 * gtk_paned_get_child2:
1557 * @paned: a #GtkPaned widget
1559 * Obtains the second child of the paned widget.
1561 * Return value: second child, or %NULL if it is not set.
1566 gtk_paned_get_child2 (GtkPaned *paned)
1568 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1570 return paned->child2;
1574 gtk_paned_compute_position (GtkPaned *paned,
1579 g_return_if_fail (GTK_IS_PANED (paned));
1581 gtk_paned_calc_position (paned, allocation, child1_req, child2_req);
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)
1726 g_return_if_fail (GTK_IS_PANED (container));
1728 paned = GTK_PANED (container);
1730 if (focus_child == NULL)
1732 GtkWidget *last_focus;
1735 last_focus = paned_get_focus_widget (paned);
1739 /* If there is one or more paned widgets between us and the
1740 * focus widget, we want the topmost of those as last_focus
1742 for (w = last_focus; w != GTK_WIDGET (paned); w = w->parent)
1743 if (GTK_IS_PANED (w))
1746 if (container->focus_child == paned->child1)
1747 gtk_paned_set_last_child1_focus (paned, last_focus);
1748 else if (container->focus_child == paned->child2)
1749 gtk_paned_set_last_child2_focus (paned, last_focus);
1753 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1754 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1758 gtk_paned_get_cycle_chain (GtkPaned *paned,
1759 GtkDirectionType direction,
1762 GtkContainer *container = GTK_CONTAINER (paned);
1763 GtkWidget *ancestor = NULL;
1764 GList *temp_list = NULL;
1767 if (paned->in_recursion)
1770 g_assert (widgets != NULL);
1772 if (paned->last_child1_focus &&
1773 !gtk_widget_is_ancestor (paned->last_child1_focus, GTK_WIDGET (paned)))
1775 gtk_paned_set_last_child1_focus (paned, NULL);
1778 if (paned->last_child2_focus &&
1779 !gtk_widget_is_ancestor (paned->last_child2_focus, GTK_WIDGET (paned)))
1781 gtk_paned_set_last_child2_focus (paned, NULL);
1784 if (GTK_WIDGET (paned)->parent)
1785 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (paned)->parent, GTK_TYPE_PANED);
1787 /* The idea here is that temp_list is a list of widgets we want to cycle
1788 * to. The list is prioritized so that the first element is our first
1789 * choice, the next our second, and so on.
1791 * We can't just use g_list_reverse(), because we want to try
1792 * paned->last_child?_focus before paned->child?, both when we
1793 * are going forward and backward.
1795 if (direction == GTK_DIR_TAB_FORWARD)
1797 if (container->focus_child == paned->child1)
1799 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1800 temp_list = g_list_append (temp_list, paned->child2);
1801 temp_list = g_list_append (temp_list, ancestor);
1803 else if (container->focus_child == paned->child2)
1805 temp_list = g_list_append (temp_list, ancestor);
1806 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1807 temp_list = g_list_append (temp_list, paned->child1);
1811 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1812 temp_list = g_list_append (temp_list, paned->child1);
1813 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1814 temp_list = g_list_append (temp_list, paned->child2);
1815 temp_list = g_list_append (temp_list, ancestor);
1820 if (container->focus_child == paned->child1)
1822 temp_list = g_list_append (temp_list, ancestor);
1823 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1824 temp_list = g_list_append (temp_list, paned->child2);
1826 else if (container->focus_child == paned->child2)
1828 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1829 temp_list = g_list_append (temp_list, paned->child1);
1830 temp_list = g_list_append (temp_list, ancestor);
1834 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1835 temp_list = g_list_append (temp_list, paned->child2);
1836 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1837 temp_list = g_list_append (temp_list, paned->child1);
1838 temp_list = g_list_append (temp_list, ancestor);
1842 /* Walk the list and expand all the paned widgets. */
1843 for (list = temp_list; list != NULL; list = list->next)
1845 GtkWidget *widget = list->data;
1849 if (GTK_IS_PANED (widget))
1851 paned->in_recursion = TRUE;
1852 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1853 paned->in_recursion = FALSE;
1857 *widgets = g_list_append (*widgets, widget);
1862 g_list_free (temp_list);
1866 gtk_paned_cycle_child_focus (GtkPaned *paned,
1869 GList *cycle_chain = NULL;
1872 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1874 /* ignore f6 if the handle is focused */
1875 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1878 /* we can't just let the event propagate up the hierarchy,
1879 * because the paned will want to cycle focus _unless_ an
1880 * ancestor paned handles the event
1882 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1884 for (list = cycle_chain; list != NULL; list = list->next)
1885 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1888 g_list_free (cycle_chain);
1894 get_child_panes (GtkWidget *widget,
1897 if (!widget || !GTK_WIDGET_REALIZED (widget))
1900 if (GTK_IS_PANED (widget))
1902 GtkPaned *paned = GTK_PANED (widget);
1904 get_child_panes (paned->child1, panes);
1905 *panes = g_list_prepend (*panes, widget);
1906 get_child_panes (paned->child2, panes);
1908 else if (GTK_IS_CONTAINER (widget))
1910 gtk_container_forall (GTK_CONTAINER (widget),
1911 (GtkCallback)get_child_panes, panes);
1916 get_all_panes (GtkPaned *paned)
1918 GtkPaned *topmost = NULL;
1919 GList *result = NULL;
1922 for (w = GTK_WIDGET (paned); w != NULL; w = w->parent)
1924 if (GTK_IS_PANED (w))
1925 topmost = GTK_PANED (w);
1930 get_child_panes (GTK_WIDGET (topmost), &result);
1932 return g_list_reverse (result);
1936 gtk_paned_find_neighbours (GtkPaned *paned,
1943 all_panes = get_all_panes (paned);
1944 g_assert (all_panes);
1946 this_link = g_list_find (all_panes, paned);
1948 g_assert (this_link);
1950 if (this_link->next)
1951 *next = this_link->next->data;
1953 *next = all_panes->data;
1955 if (this_link->prev)
1956 *prev = this_link->prev->data;
1958 *prev = g_list_last (all_panes)->data;
1960 g_list_free (all_panes);
1964 gtk_paned_move_handle (GtkPaned *paned,
1965 GtkScrollType scroll)
1967 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1974 SINGLE_STEP_SIZE = 1,
1978 new_position = old_position = gtk_paned_get_position (paned);
1983 case GTK_SCROLL_STEP_LEFT:
1984 case GTK_SCROLL_STEP_UP:
1985 case GTK_SCROLL_STEP_BACKWARD:
1986 increment = - SINGLE_STEP_SIZE;
1989 case GTK_SCROLL_STEP_RIGHT:
1990 case GTK_SCROLL_STEP_DOWN:
1991 case GTK_SCROLL_STEP_FORWARD:
1992 increment = SINGLE_STEP_SIZE;
1995 case GTK_SCROLL_PAGE_LEFT:
1996 case GTK_SCROLL_PAGE_UP:
1997 case GTK_SCROLL_PAGE_BACKWARD:
1998 increment = - PAGE_STEP_SIZE;
2001 case GTK_SCROLL_PAGE_RIGHT:
2002 case GTK_SCROLL_PAGE_DOWN:
2003 case GTK_SCROLL_PAGE_FORWARD:
2004 increment = PAGE_STEP_SIZE;
2007 case GTK_SCROLL_START:
2008 new_position = paned->min_position;
2011 case GTK_SCROLL_END:
2012 new_position = paned->max_position;
2022 increment = -increment;
2024 new_position = old_position + increment;
2027 new_position = CLAMP (new_position, paned->min_position, paned->max_position);
2029 if (old_position != new_position)
2030 gtk_paned_set_position (paned, new_position);
2039 gtk_paned_restore_focus (GtkPaned *paned)
2041 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2043 if (paned->priv->saved_focus &&
2044 gtk_widget_get_sensitive (paned->priv->saved_focus))
2046 gtk_widget_grab_focus (paned->priv->saved_focus);
2050 /* the saved focus is somehow not available for focusing,
2052 * 1) tabbing into the paned widget
2053 * if that didn't work,
2054 * 2) unset focus for the window if there is one
2057 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2059 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2061 if (GTK_IS_WINDOW (toplevel))
2062 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2066 gtk_paned_set_saved_focus (paned, NULL);
2067 gtk_paned_set_first_paned (paned, NULL);
2072 gtk_paned_accept_position (GtkPaned *paned)
2074 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2076 paned->original_position = -1;
2077 gtk_paned_restore_focus (paned);
2087 gtk_paned_cancel_position (GtkPaned *paned)
2089 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2091 if (paned->original_position != -1)
2093 gtk_paned_set_position (paned, paned->original_position);
2094 paned->original_position = -1;
2097 gtk_paned_restore_focus (paned);
2105 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2108 GtkPaned *next, *prev;
2110 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2112 GtkPaned *focus = NULL;
2114 if (!paned->priv->first_paned)
2116 /* The first_pane has disappeared. As an ad-hoc solution,
2117 * we make the currently focused paned the first_paned. To the
2118 * user this will seem like the paned cycling has been reset.
2121 gtk_paned_set_first_paned (paned, paned);
2124 gtk_paned_find_neighbours (paned, &next, &prev);
2126 if (reversed && prev &&
2127 prev != paned && paned != paned->priv->first_paned)
2131 else if (!reversed && next &&
2132 next != paned && next != paned->priv->first_paned)
2138 gtk_paned_accept_position (paned);
2144 gtk_paned_set_saved_focus (focus, paned->priv->saved_focus);
2145 gtk_paned_set_first_paned (focus, paned->priv->first_paned);
2147 gtk_paned_set_saved_focus (paned, NULL);
2148 gtk_paned_set_first_paned (paned, NULL);
2150 gtk_widget_grab_focus (GTK_WIDGET (focus));
2152 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2154 paned->original_position = -1;
2155 focus->original_position = gtk_paned_get_position (focus);
2160 GtkContainer *container = GTK_CONTAINER (paned);
2163 GtkPaned *prev, *next;
2164 GtkWidget *toplevel;
2166 gtk_paned_find_neighbours (paned, &next, &prev);
2168 if (container->focus_child == paned->child1)
2181 else if (container->focus_child == paned->child2)
2196 /* Focus is not inside this paned, and we don't have focus.
2197 * Presumably this happened because the application wants us
2198 * to start keyboard navigating.
2208 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2210 if (GTK_IS_WINDOW (toplevel))
2211 gtk_paned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
2212 gtk_paned_set_first_paned (focus, first);
2213 focus->original_position = gtk_paned_get_position (focus);
2215 gtk_widget_grab_focus (GTK_WIDGET (focus));
2222 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2224 /* This function/signal has the wrong name. It is called when you
2225 * press Tab or Shift-Tab and what we do is act as if
2226 * the user pressed Return and then Tab or Shift-Tab
2228 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2229 gtk_paned_accept_position (paned);
2235 * gtk_paned_get_handle_window:
2236 * @panede: a #GtkPaned
2238 * Returns the #GdkWindow of the handle. This function is
2239 * useful when handling button or motion events because it
2240 * enables the callback to distinguish between the window
2241 * of the paned, a child and the handle.
2243 * Return value: the paned's handle window.
2248 gtk_paned_get_handle_window (GtkPaned *paned)
2250 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2252 return paned->handle;
2255 #define __GTK_PANED_C__
2256 #include "gtkaliasdef.c"