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 | GTK_CAN_FOCUS);
564 /* We only need to redraw when the handle position moves, which is
565 * independent of the overall allocation of the GtkPaned
567 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
569 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
571 paned->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
572 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
574 paned->child1 = NULL;
575 paned->child2 = NULL;
576 paned->handle = NULL;
577 paned->xor_gc = NULL;
578 paned->cursor_type = GDK_CROSS;
580 paned->handle_pos.width = 5;
581 paned->handle_pos.height = 5;
582 paned->position_set = FALSE;
583 paned->last_allocation = -1;
584 paned->in_drag = FALSE;
586 paned->last_child1_focus = NULL;
587 paned->last_child2_focus = NULL;
588 paned->in_recursion = FALSE;
589 paned->handle_prelit = FALSE;
590 paned->original_position = -1;
592 paned->handle_pos.x = -1;
593 paned->handle_pos.y = -1;
595 paned->drag_pos = -1;
599 gtk_paned_set_property (GObject *object,
604 GtkPaned *paned = GTK_PANED (object);
608 case PROP_ORIENTATION:
609 paned->priv->orientation = g_value_get_enum (value);
610 paned->orientation = !paned->priv->orientation;
612 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
613 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
615 paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
617 /* state_changed updates the cursor */
618 gtk_paned_state_changed (GTK_WIDGET (paned), GTK_WIDGET (paned)->state);
619 gtk_widget_queue_resize (GTK_WIDGET (paned));
622 gtk_paned_set_position (paned, g_value_get_int (value));
624 case PROP_POSITION_SET:
625 paned->position_set = g_value_get_boolean (value);
626 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
629 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
635 gtk_paned_get_property (GObject *object,
640 GtkPaned *paned = GTK_PANED (object);
644 case PROP_ORIENTATION:
645 g_value_set_enum (value, paned->priv->orientation);
648 g_value_set_int (value, paned->child1_size);
650 case PROP_POSITION_SET:
651 g_value_set_boolean (value, paned->position_set);
653 case PROP_MIN_POSITION:
654 g_value_set_int (value, paned->min_position);
656 case PROP_MAX_POSITION:
657 g_value_set_int (value, paned->max_position);
660 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
666 gtk_paned_set_child_property (GtkContainer *container,
672 GtkPaned *paned = GTK_PANED (container);
673 gboolean old_value, new_value;
675 g_assert (child == paned->child1 || child == paned->child2);
677 new_value = g_value_get_boolean (value);
680 case CHILD_PROP_RESIZE:
681 if (child == paned->child1)
683 old_value = paned->child1_resize;
684 paned->child1_resize = new_value;
688 old_value = paned->child2_resize;
689 paned->child2_resize = new_value;
692 case CHILD_PROP_SHRINK:
693 if (child == paned->child1)
695 old_value = paned->child1_shrink;
696 paned->child1_shrink = new_value;
700 old_value = paned->child2_shrink;
701 paned->child2_shrink = new_value;
705 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
706 old_value = -1; /* quiet gcc */
709 if (old_value != new_value)
710 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
714 gtk_paned_get_child_property (GtkContainer *container,
720 GtkPaned *paned = GTK_PANED (container);
722 g_assert (child == paned->child1 || child == paned->child2);
726 case CHILD_PROP_RESIZE:
727 if (child == paned->child1)
728 g_value_set_boolean (value, paned->child1_resize);
730 g_value_set_boolean (value, paned->child2_resize);
732 case CHILD_PROP_SHRINK:
733 if (child == paned->child1)
734 g_value_set_boolean (value, paned->child1_shrink);
736 g_value_set_boolean (value, paned->child2_shrink);
739 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
745 gtk_paned_finalize (GObject *object)
747 GtkPaned *paned = GTK_PANED (object);
749 gtk_paned_set_saved_focus (paned, NULL);
750 gtk_paned_set_first_paned (paned, NULL);
752 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
756 gtk_paned_size_request (GtkWidget *widget,
757 GtkRequisition *requisition)
759 GtkPaned *paned = GTK_PANED (widget);
760 GtkRequisition child_requisition;
762 requisition->width = 0;
763 requisition->height = 0;
765 if (paned->child1 && gtk_widget_get_visible (paned->child1))
767 gtk_widget_size_request (paned->child1, &child_requisition);
769 requisition->height = child_requisition.height;
770 requisition->width = child_requisition.width;
773 if (paned->child2 && gtk_widget_get_visible (paned->child2))
775 gtk_widget_size_request (paned->child2, &child_requisition);
777 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
779 requisition->height = MAX (requisition->height,
780 child_requisition.height);
781 requisition->width += child_requisition.width;
785 requisition->width = MAX (requisition->width,
786 child_requisition.width);
787 requisition->height += child_requisition.height;
791 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
792 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
794 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
795 paned->child2 && gtk_widget_get_visible (paned->child2))
799 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
801 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
802 requisition->width += handle_size;
804 requisition->height += handle_size;
809 flip_child (GtkWidget *widget,
810 GtkAllocation *child_pos)
812 gint x = widget->allocation.x;
813 gint width = widget->allocation.width;
815 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
819 gtk_paned_size_allocate (GtkWidget *widget,
820 GtkAllocation *allocation)
822 GtkPaned *paned = GTK_PANED (widget);
823 gint border_width = GTK_CONTAINER (paned)->border_width;
825 widget->allocation = *allocation;
827 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
828 paned->child2 && gtk_widget_get_visible (paned->child2))
830 GtkRequisition child1_requisition;
831 GtkRequisition child2_requisition;
832 GtkAllocation child1_allocation;
833 GtkAllocation child2_allocation;
834 GdkRectangle old_handle_pos;
837 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
839 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
840 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
842 old_handle_pos = paned->handle_pos;
844 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
846 gtk_paned_calc_position (paned,
847 MAX (1, widget->allocation.width
850 child1_requisition.width,
851 child2_requisition.width);
853 paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
854 paned->handle_pos.y = widget->allocation.y + border_width;
855 paned->handle_pos.width = handle_size;
856 paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
858 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
859 child1_allocation.width = MAX (1, paned->child1_size);
860 child1_allocation.x = widget->allocation.x + border_width;
861 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
863 child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
864 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
866 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
868 flip_child (widget, &(child2_allocation));
869 flip_child (widget, &(child1_allocation));
870 flip_child (widget, &(paned->handle_pos));
875 gtk_paned_calc_position (paned,
876 MAX (1, widget->allocation.height
879 child1_requisition.height,
880 child2_requisition.height);
882 paned->handle_pos.x = widget->allocation.x + border_width;
883 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
884 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
885 paned->handle_pos.height = handle_size;
887 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
888 child1_allocation.height = MAX (1, paned->child1_size);
889 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
890 child1_allocation.y = widget->allocation.y + border_width;
892 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
893 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
896 if (GTK_WIDGET_MAPPED (widget) &&
897 (old_handle_pos.x != paned->handle_pos.x ||
898 old_handle_pos.y != paned->handle_pos.y ||
899 old_handle_pos.width != paned->handle_pos.width ||
900 old_handle_pos.height != paned->handle_pos.height))
902 gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
903 gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
906 if (GTK_WIDGET_REALIZED (widget))
908 if (GTK_WIDGET_MAPPED (widget))
909 gdk_window_show (paned->handle);
911 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
913 gdk_window_move_resize (paned->handle,
917 paned->handle_pos.height);
921 gdk_window_move_resize (paned->handle,
924 paned->handle_pos.width,
929 /* Now allocate the childen, making sure, when resizing not to
930 * overlap the windows
932 if (GTK_WIDGET_MAPPED (widget) &&
934 ((paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
935 paned->child1->allocation.width < child1_allocation.width) ||
937 (paned->priv->orientation == GTK_ORIENTATION_VERTICAL &&
938 paned->child1->allocation.height < child1_allocation.height)))
940 gtk_widget_size_allocate (paned->child2, &child2_allocation);
941 gtk_widget_size_allocate (paned->child1, &child1_allocation);
945 gtk_widget_size_allocate (paned->child1, &child1_allocation);
946 gtk_widget_size_allocate (paned->child2, &child2_allocation);
951 GtkAllocation child_allocation;
953 if (GTK_WIDGET_REALIZED (widget))
954 gdk_window_hide (paned->handle);
957 gtk_widget_set_child_visible (paned->child1, TRUE);
959 gtk_widget_set_child_visible (paned->child2, TRUE);
961 child_allocation.x = widget->allocation.x + border_width;
962 child_allocation.y = widget->allocation.y + border_width;
963 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
964 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
966 if (paned->child1 && gtk_widget_get_visible (paned->child1))
967 gtk_widget_size_allocate (paned->child1, &child_allocation);
968 else if (paned->child2 && gtk_widget_get_visible (paned->child2))
969 gtk_widget_size_allocate (paned->child2, &child_allocation);
974 gtk_paned_realize (GtkWidget *widget)
977 GdkWindowAttr attributes;
978 gint attributes_mask;
980 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
981 paned = GTK_PANED (widget);
983 widget->window = gtk_widget_get_parent_window (widget);
984 g_object_ref (widget->window);
986 attributes.window_type = GDK_WINDOW_CHILD;
987 attributes.wclass = GDK_INPUT_ONLY;
988 attributes.x = paned->handle_pos.x;
989 attributes.y = paned->handle_pos.y;
990 attributes.width = paned->handle_pos.width;
991 attributes.height = paned->handle_pos.height;
992 attributes.event_mask = gtk_widget_get_events (widget);
993 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
994 GDK_BUTTON_RELEASE_MASK |
995 GDK_ENTER_NOTIFY_MASK |
996 GDK_LEAVE_NOTIFY_MASK |
997 GDK_POINTER_MOTION_MASK |
998 GDK_POINTER_MOTION_HINT_MASK);
999 attributes_mask = GDK_WA_X | GDK_WA_Y;
1000 if (gtk_widget_is_sensitive (widget))
1002 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1003 paned->cursor_type);
1004 attributes_mask |= GDK_WA_CURSOR;
1007 paned->handle = gdk_window_new (widget->window,
1008 &attributes, attributes_mask);
1009 gdk_window_set_user_data (paned->handle, paned);
1010 if (attributes_mask & GDK_WA_CURSOR)
1011 gdk_cursor_unref (attributes.cursor);
1013 widget->style = gtk_style_attach (widget->style, widget->window);
1015 if (paned->child1 && gtk_widget_get_visible (paned->child1) &&
1016 paned->child2 && gtk_widget_get_visible (paned->child2))
1017 gdk_window_show (paned->handle);
1021 gtk_paned_unrealize (GtkWidget *widget)
1023 GtkPaned *paned = GTK_PANED (widget);
1027 g_object_unref (paned->xor_gc);
1028 paned->xor_gc = NULL;
1033 gdk_window_set_user_data (paned->handle, NULL);
1034 gdk_window_destroy (paned->handle);
1035 paned->handle = NULL;
1038 gtk_paned_set_last_child1_focus (paned, NULL);
1039 gtk_paned_set_last_child2_focus (paned, NULL);
1040 gtk_paned_set_saved_focus (paned, NULL);
1041 gtk_paned_set_first_paned (paned, NULL);
1043 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1047 gtk_paned_map (GtkWidget *widget)
1049 GtkPaned *paned = GTK_PANED (widget);
1051 gdk_window_show (paned->handle);
1053 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1057 gtk_paned_unmap (GtkWidget *widget)
1059 GtkPaned *paned = GTK_PANED (widget);
1061 gdk_window_hide (paned->handle);
1063 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1067 gtk_paned_expose (GtkWidget *widget,
1068 GdkEventExpose *event)
1070 GtkPaned *paned = GTK_PANED (widget);
1072 if (gtk_widget_get_visible (widget) && GTK_WIDGET_MAPPED (widget) &&
1073 paned->child1 && gtk_widget_get_visible (paned->child1) &&
1074 paned->child2 && gtk_widget_get_visible (paned->child2))
1078 if (gtk_widget_is_focus (widget))
1079 state = GTK_STATE_SELECTED;
1080 else if (paned->handle_prelit)
1081 state = GTK_STATE_PRELIGHT;
1083 state = GTK_WIDGET_STATE (widget);
1085 gtk_paint_handle (widget->style, widget->window,
1086 state, GTK_SHADOW_NONE,
1087 &paned->handle_pos, widget, "paned",
1088 paned->handle_pos.x, paned->handle_pos.y,
1089 paned->handle_pos.width, paned->handle_pos.height,
1090 !paned->priv->orientation);
1093 /* Chain up to draw children */
1094 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1100 is_rtl (GtkPaned *paned)
1102 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1103 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1112 update_drag (GtkPaned *paned)
1118 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1119 gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
1121 gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
1123 pos -= paned->drag_pos;
1127 gtk_widget_style_get (GTK_WIDGET (paned),
1128 "handle-size", &handle_size,
1131 size = GTK_WIDGET (paned)->allocation.width - pos - handle_size;
1138 size -= GTK_CONTAINER (paned)->border_width;
1140 size = CLAMP (size, paned->min_position, paned->max_position);
1142 if (size != paned->child1_size)
1143 gtk_paned_set_position (paned, size);
1147 gtk_paned_enter (GtkWidget *widget,
1148 GdkEventCrossing *event)
1150 GtkPaned *paned = GTK_PANED (widget);
1153 update_drag (paned);
1156 paned->handle_prelit = TRUE;
1157 gtk_widget_queue_draw_area (widget,
1158 paned->handle_pos.x,
1159 paned->handle_pos.y,
1160 paned->handle_pos.width,
1161 paned->handle_pos.height);
1168 gtk_paned_leave (GtkWidget *widget,
1169 GdkEventCrossing *event)
1171 GtkPaned *paned = GTK_PANED (widget);
1174 update_drag (paned);
1177 paned->handle_prelit = FALSE;
1178 gtk_widget_queue_draw_area (widget,
1179 paned->handle_pos.x,
1180 paned->handle_pos.y,
1181 paned->handle_pos.width,
1182 paned->handle_pos.height);
1189 gtk_paned_focus (GtkWidget *widget,
1190 GtkDirectionType direction)
1195 /* This is a hack, but how can this be done without
1196 * excessive cut-and-paste from gtkcontainer.c?
1199 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1200 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1201 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1207 gtk_paned_button_press (GtkWidget *widget,
1208 GdkEventButton *event)
1210 GtkPaned *paned = GTK_PANED (widget);
1212 if (!paned->in_drag &&
1213 (event->window == paned->handle) && (event->button == 1))
1215 /* We need a server grab here, not gtk_grab_add(), since
1216 * we don't want to pass events on to the widget's children */
1217 if (gdk_pointer_grab (paned->handle, FALSE,
1218 GDK_POINTER_MOTION_HINT_MASK
1219 | GDK_BUTTON1_MOTION_MASK
1220 | GDK_BUTTON_RELEASE_MASK
1221 | GDK_ENTER_NOTIFY_MASK
1222 | GDK_LEAVE_NOTIFY_MASK,
1224 event->time) != GDK_GRAB_SUCCESS)
1227 paned->in_drag = TRUE;
1228 paned->priv->grab_time = event->time;
1230 if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1231 paned->drag_pos = event->x;
1233 paned->drag_pos = event->y;
1242 gtk_paned_grab_broken (GtkWidget *widget,
1243 GdkEventGrabBroken *event)
1245 GtkPaned *paned = GTK_PANED (widget);
1247 paned->in_drag = FALSE;
1248 paned->drag_pos = -1;
1249 paned->position_set = TRUE;
1255 stop_drag (GtkPaned *paned)
1257 paned->in_drag = FALSE;
1258 paned->drag_pos = -1;
1259 paned->position_set = TRUE;
1260 gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (paned)),
1261 paned->priv->grab_time);
1265 gtk_paned_grab_notify (GtkWidget *widget,
1266 gboolean was_grabbed)
1268 GtkPaned *paned = GTK_PANED (widget);
1270 if (!was_grabbed && paned->in_drag)
1275 gtk_paned_state_changed (GtkWidget *widget,
1276 GtkStateType previous_state)
1278 GtkPaned *paned = GTK_PANED (widget);
1281 if (GTK_WIDGET_REALIZED (paned))
1283 if (gtk_widget_is_sensitive (widget))
1284 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1285 paned->cursor_type);
1289 gdk_window_set_cursor (paned->handle, cursor);
1292 gdk_cursor_unref (cursor);
1297 gtk_paned_button_release (GtkWidget *widget,
1298 GdkEventButton *event)
1300 GtkPaned *paned = GTK_PANED (widget);
1302 if (paned->in_drag && (event->button == 1))
1313 gtk_paned_motion (GtkWidget *widget,
1314 GdkEventMotion *event)
1316 GtkPaned *paned = GTK_PANED (widget);
1320 update_drag (paned);
1330 * @orientation: the paned's orientation.
1332 * Creates a new #GtkPaned widget.
1334 * Return value: a new #GtkPaned.
1339 gtk_paned_new (GtkOrientation orientation)
1341 return g_object_new (GTK_TYPE_PANED,
1342 "orientation", orientation,
1348 gtk_paned_add1 (GtkPaned *paned,
1351 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1355 gtk_paned_add2 (GtkPaned *paned,
1358 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1362 gtk_paned_pack1 (GtkPaned *paned,
1367 g_return_if_fail (GTK_IS_PANED (paned));
1368 g_return_if_fail (GTK_IS_WIDGET (child));
1372 paned->child1 = child;
1373 paned->child1_resize = resize;
1374 paned->child1_shrink = shrink;
1376 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1381 gtk_paned_pack2 (GtkPaned *paned,
1386 g_return_if_fail (GTK_IS_PANED (paned));
1387 g_return_if_fail (GTK_IS_WIDGET (child));
1391 paned->child2 = child;
1392 paned->child2_resize = resize;
1393 paned->child2_shrink = shrink;
1395 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1401 gtk_paned_add (GtkContainer *container,
1406 g_return_if_fail (GTK_IS_PANED (container));
1408 paned = GTK_PANED (container);
1411 gtk_paned_add1 (paned, widget);
1412 else if (!paned->child2)
1413 gtk_paned_add2 (paned, widget);
1415 g_warning ("GtkPaned cannot have more than 2 children\n");
1419 gtk_paned_remove (GtkContainer *container,
1423 gboolean was_visible;
1425 paned = GTK_PANED (container);
1426 was_visible = gtk_widget_get_visible (widget);
1428 if (paned->child1 == widget)
1430 gtk_widget_unparent (widget);
1432 paned->child1 = NULL;
1434 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1435 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1437 else if (paned->child2 == widget)
1439 gtk_widget_unparent (widget);
1441 paned->child2 = NULL;
1443 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1444 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1449 gtk_paned_forall (GtkContainer *container,
1450 gboolean include_internals,
1451 GtkCallback callback,
1452 gpointer callback_data)
1456 g_return_if_fail (callback != NULL);
1458 paned = GTK_PANED (container);
1461 (*callback) (paned->child1, callback_data);
1463 (*callback) (paned->child2, callback_data);
1467 * gtk_paned_get_position:
1468 * @paned: a #GtkPaned widget
1470 * Obtains the position of the divider between the two panes.
1472 * Return value: position of the divider
1475 gtk_paned_get_position (GtkPaned *paned)
1477 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1479 return paned->child1_size;
1483 * gtk_paned_set_position:
1484 * @paned: a #GtkPaned widget
1485 * @position: pixel position of divider, a negative value means that the position
1488 * Sets the position of the divider between the two panes.
1491 gtk_paned_set_position (GtkPaned *paned,
1496 g_return_if_fail (GTK_IS_PANED (paned));
1498 if (paned->child1_size == position)
1501 object = G_OBJECT (paned);
1505 /* We don't clamp here - the assumption is that
1506 * if the total allocation changes at the same time
1507 * as the position, the position set is with reference
1508 * to the new total size. If only the position changes,
1509 * then clamping will occur in gtk_paned_calc_position()
1512 paned->child1_size = position;
1513 paned->position_set = TRUE;
1517 paned->position_set = FALSE;
1520 g_object_freeze_notify (object);
1521 g_object_notify (object, "position");
1522 g_object_notify (object, "position-set");
1523 g_object_thaw_notify (object);
1525 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1528 /* Hacky work-around for bug #144269 */
1529 if (paned->child2 != NULL)
1531 gtk_widget_queue_draw (paned->child2);
1537 * gtk_paned_get_child1:
1538 * @paned: a #GtkPaned widget
1540 * Obtains the first child of the paned widget.
1542 * Return value: first child, or %NULL if it is not set.
1547 gtk_paned_get_child1 (GtkPaned *paned)
1549 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1551 return paned->child1;
1555 * gtk_paned_get_child2:
1556 * @paned: a #GtkPaned widget
1558 * Obtains the second child of the paned widget.
1560 * Return value: second child, or %NULL if it is not set.
1565 gtk_paned_get_child2 (GtkPaned *paned)
1567 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1569 return paned->child2;
1573 gtk_paned_compute_position (GtkPaned *paned,
1578 g_return_if_fail (GTK_IS_PANED (paned));
1580 gtk_paned_calc_position (paned, allocation, child1_req, child2_req);
1584 gtk_paned_calc_position (GtkPaned *paned,
1590 gint old_min_position;
1591 gint old_max_position;
1593 old_position = paned->child1_size;
1594 old_min_position = paned->min_position;
1595 old_max_position = paned->max_position;
1597 paned->min_position = paned->child1_shrink ? 0 : child1_req;
1599 paned->max_position = allocation;
1600 if (!paned->child2_shrink)
1601 paned->max_position = MAX (1, paned->max_position - child2_req);
1602 paned->max_position = MAX (paned->min_position, paned->max_position);
1604 if (!paned->position_set)
1606 if (paned->child1_resize && !paned->child2_resize)
1607 paned->child1_size = MAX (0, allocation - child2_req);
1608 else if (!paned->child1_resize && paned->child2_resize)
1609 paned->child1_size = child1_req;
1610 else if (child1_req + child2_req != 0)
1611 paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1613 paned->child1_size = allocation * 0.5 + 0.5;
1617 /* If the position was set before the initial allocation.
1618 * (paned->last_allocation <= 0) just clamp it and leave it.
1620 if (paned->last_allocation > 0)
1622 if (paned->child1_resize && !paned->child2_resize)
1623 paned->child1_size += allocation - paned->last_allocation;
1624 else if (!(!paned->child1_resize && paned->child2_resize))
1625 paned->child1_size = allocation * ((gdouble) paned->child1_size / (paned->last_allocation)) + 0.5;
1629 paned->child1_size = CLAMP (paned->child1_size,
1630 paned->min_position,
1631 paned->max_position);
1634 gtk_widget_set_child_visible (paned->child1, paned->child1_size != 0);
1637 gtk_widget_set_child_visible (paned->child2, paned->child1_size != allocation);
1639 g_object_freeze_notify (G_OBJECT (paned));
1640 if (paned->child1_size != old_position)
1641 g_object_notify (G_OBJECT (paned), "position");
1642 if (paned->min_position != old_min_position)
1643 g_object_notify (G_OBJECT (paned), "min-position");
1644 if (paned->max_position != old_max_position)
1645 g_object_notify (G_OBJECT (paned), "max-position");
1646 g_object_thaw_notify (G_OBJECT (paned));
1648 paned->last_allocation = allocation;
1652 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1654 if (paned->priv->saved_focus)
1655 g_object_remove_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1656 (gpointer *)&(paned->priv->saved_focus));
1658 paned->priv->saved_focus = widget;
1660 if (paned->priv->saved_focus)
1661 g_object_add_weak_pointer (G_OBJECT (paned->priv->saved_focus),
1662 (gpointer *)&(paned->priv->saved_focus));
1666 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1668 if (paned->priv->first_paned)
1669 g_object_remove_weak_pointer (G_OBJECT (paned->priv->first_paned),
1670 (gpointer *)&(paned->priv->first_paned));
1672 paned->priv->first_paned = first_paned;
1674 if (paned->priv->first_paned)
1675 g_object_add_weak_pointer (G_OBJECT (paned->priv->first_paned),
1676 (gpointer *)&(paned->priv->first_paned));
1680 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1682 if (paned->last_child1_focus)
1683 g_object_remove_weak_pointer (G_OBJECT (paned->last_child1_focus),
1684 (gpointer *)&(paned->last_child1_focus));
1686 paned->last_child1_focus = widget;
1688 if (paned->last_child1_focus)
1689 g_object_add_weak_pointer (G_OBJECT (paned->last_child1_focus),
1690 (gpointer *)&(paned->last_child1_focus));
1694 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1696 if (paned->last_child2_focus)
1697 g_object_remove_weak_pointer (G_OBJECT (paned->last_child2_focus),
1698 (gpointer *)&(paned->last_child2_focus));
1700 paned->last_child2_focus = widget;
1702 if (paned->last_child2_focus)
1703 g_object_add_weak_pointer (G_OBJECT (paned->last_child2_focus),
1704 (gpointer *)&(paned->last_child2_focus));
1708 paned_get_focus_widget (GtkPaned *paned)
1710 GtkWidget *toplevel;
1712 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1713 if (gtk_widget_is_toplevel (toplevel))
1714 return GTK_WINDOW (toplevel)->focus_widget;
1720 gtk_paned_set_focus_child (GtkContainer *container,
1721 GtkWidget *focus_child)
1725 g_return_if_fail (GTK_IS_PANED (container));
1727 paned = GTK_PANED (container);
1729 if (focus_child == NULL)
1731 GtkWidget *last_focus;
1734 last_focus = paned_get_focus_widget (paned);
1738 /* If there is one or more paned widgets between us and the
1739 * focus widget, we want the topmost of those as last_focus
1741 for (w = last_focus; w != GTK_WIDGET (paned); w = w->parent)
1742 if (GTK_IS_PANED (w))
1745 if (container->focus_child == paned->child1)
1746 gtk_paned_set_last_child1_focus (paned, last_focus);
1747 else if (container->focus_child == paned->child2)
1748 gtk_paned_set_last_child2_focus (paned, last_focus);
1752 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1753 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1757 gtk_paned_get_cycle_chain (GtkPaned *paned,
1758 GtkDirectionType direction,
1761 GtkContainer *container = GTK_CONTAINER (paned);
1762 GtkWidget *ancestor = NULL;
1763 GList *temp_list = NULL;
1766 if (paned->in_recursion)
1769 g_assert (widgets != NULL);
1771 if (paned->last_child1_focus &&
1772 !gtk_widget_is_ancestor (paned->last_child1_focus, GTK_WIDGET (paned)))
1774 gtk_paned_set_last_child1_focus (paned, NULL);
1777 if (paned->last_child2_focus &&
1778 !gtk_widget_is_ancestor (paned->last_child2_focus, GTK_WIDGET (paned)))
1780 gtk_paned_set_last_child2_focus (paned, NULL);
1783 if (GTK_WIDGET (paned)->parent)
1784 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (paned)->parent, GTK_TYPE_PANED);
1786 /* The idea here is that temp_list is a list of widgets we want to cycle
1787 * to. The list is prioritized so that the first element is our first
1788 * choice, the next our second, and so on.
1790 * We can't just use g_list_reverse(), because we want to try
1791 * paned->last_child?_focus before paned->child?, both when we
1792 * are going forward and backward.
1794 if (direction == GTK_DIR_TAB_FORWARD)
1796 if (container->focus_child == paned->child1)
1798 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1799 temp_list = g_list_append (temp_list, paned->child2);
1800 temp_list = g_list_append (temp_list, ancestor);
1802 else if (container->focus_child == paned->child2)
1804 temp_list = g_list_append (temp_list, ancestor);
1805 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1806 temp_list = g_list_append (temp_list, paned->child1);
1810 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1811 temp_list = g_list_append (temp_list, paned->child1);
1812 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1813 temp_list = g_list_append (temp_list, paned->child2);
1814 temp_list = g_list_append (temp_list, ancestor);
1819 if (container->focus_child == paned->child1)
1821 temp_list = g_list_append (temp_list, ancestor);
1822 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1823 temp_list = g_list_append (temp_list, paned->child2);
1825 else if (container->focus_child == paned->child2)
1827 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1828 temp_list = g_list_append (temp_list, paned->child1);
1829 temp_list = g_list_append (temp_list, ancestor);
1833 temp_list = g_list_append (temp_list, paned->last_child2_focus);
1834 temp_list = g_list_append (temp_list, paned->child2);
1835 temp_list = g_list_append (temp_list, paned->last_child1_focus);
1836 temp_list = g_list_append (temp_list, paned->child1);
1837 temp_list = g_list_append (temp_list, ancestor);
1841 /* Walk the list and expand all the paned widgets. */
1842 for (list = temp_list; list != NULL; list = list->next)
1844 GtkWidget *widget = list->data;
1848 if (GTK_IS_PANED (widget))
1850 paned->in_recursion = TRUE;
1851 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1852 paned->in_recursion = FALSE;
1856 *widgets = g_list_append (*widgets, widget);
1861 g_list_free (temp_list);
1865 gtk_paned_cycle_child_focus (GtkPaned *paned,
1868 GList *cycle_chain = NULL;
1871 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1873 /* ignore f6 if the handle is focused */
1874 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1877 /* we can't just let the event propagate up the hierarchy,
1878 * because the paned will want to cycle focus _unless_ an
1879 * ancestor paned handles the event
1881 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1883 for (list = cycle_chain; list != NULL; list = list->next)
1884 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1887 g_list_free (cycle_chain);
1893 get_child_panes (GtkWidget *widget,
1896 if (!widget || !GTK_WIDGET_REALIZED (widget))
1899 if (GTK_IS_PANED (widget))
1901 GtkPaned *paned = GTK_PANED (widget);
1903 get_child_panes (paned->child1, panes);
1904 *panes = g_list_prepend (*panes, widget);
1905 get_child_panes (paned->child2, panes);
1907 else if (GTK_IS_CONTAINER (widget))
1909 gtk_container_forall (GTK_CONTAINER (widget),
1910 (GtkCallback)get_child_panes, panes);
1915 get_all_panes (GtkPaned *paned)
1917 GtkPaned *topmost = NULL;
1918 GList *result = NULL;
1921 for (w = GTK_WIDGET (paned); w != NULL; w = w->parent)
1923 if (GTK_IS_PANED (w))
1924 topmost = GTK_PANED (w);
1929 get_child_panes (GTK_WIDGET (topmost), &result);
1931 return g_list_reverse (result);
1935 gtk_paned_find_neighbours (GtkPaned *paned,
1942 all_panes = get_all_panes (paned);
1943 g_assert (all_panes);
1945 this_link = g_list_find (all_panes, paned);
1947 g_assert (this_link);
1949 if (this_link->next)
1950 *next = this_link->next->data;
1952 *next = all_panes->data;
1954 if (this_link->prev)
1955 *prev = this_link->prev->data;
1957 *prev = g_list_last (all_panes)->data;
1959 g_list_free (all_panes);
1963 gtk_paned_move_handle (GtkPaned *paned,
1964 GtkScrollType scroll)
1966 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1973 SINGLE_STEP_SIZE = 1,
1977 new_position = old_position = gtk_paned_get_position (paned);
1982 case GTK_SCROLL_STEP_LEFT:
1983 case GTK_SCROLL_STEP_UP:
1984 case GTK_SCROLL_STEP_BACKWARD:
1985 increment = - SINGLE_STEP_SIZE;
1988 case GTK_SCROLL_STEP_RIGHT:
1989 case GTK_SCROLL_STEP_DOWN:
1990 case GTK_SCROLL_STEP_FORWARD:
1991 increment = SINGLE_STEP_SIZE;
1994 case GTK_SCROLL_PAGE_LEFT:
1995 case GTK_SCROLL_PAGE_UP:
1996 case GTK_SCROLL_PAGE_BACKWARD:
1997 increment = - PAGE_STEP_SIZE;
2000 case GTK_SCROLL_PAGE_RIGHT:
2001 case GTK_SCROLL_PAGE_DOWN:
2002 case GTK_SCROLL_PAGE_FORWARD:
2003 increment = PAGE_STEP_SIZE;
2006 case GTK_SCROLL_START:
2007 new_position = paned->min_position;
2010 case GTK_SCROLL_END:
2011 new_position = paned->max_position;
2021 increment = -increment;
2023 new_position = old_position + increment;
2026 new_position = CLAMP (new_position, paned->min_position, paned->max_position);
2028 if (old_position != new_position)
2029 gtk_paned_set_position (paned, new_position);
2038 gtk_paned_restore_focus (GtkPaned *paned)
2040 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2042 if (paned->priv->saved_focus &&
2043 gtk_widget_get_sensitive (paned->priv->saved_focus))
2045 gtk_widget_grab_focus (paned->priv->saved_focus);
2049 /* the saved focus is somehow not available for focusing,
2051 * 1) tabbing into the paned widget
2052 * if that didn't work,
2053 * 2) unset focus for the window if there is one
2056 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2058 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2060 if (GTK_IS_WINDOW (toplevel))
2061 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2065 gtk_paned_set_saved_focus (paned, NULL);
2066 gtk_paned_set_first_paned (paned, NULL);
2071 gtk_paned_accept_position (GtkPaned *paned)
2073 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2075 paned->original_position = -1;
2076 gtk_paned_restore_focus (paned);
2086 gtk_paned_cancel_position (GtkPaned *paned)
2088 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2090 if (paned->original_position != -1)
2092 gtk_paned_set_position (paned, paned->original_position);
2093 paned->original_position = -1;
2096 gtk_paned_restore_focus (paned);
2104 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2107 GtkPaned *next, *prev;
2109 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2111 GtkPaned *focus = NULL;
2113 if (!paned->priv->first_paned)
2115 /* The first_pane has disappeared. As an ad-hoc solution,
2116 * we make the currently focused paned the first_paned. To the
2117 * user this will seem like the paned cycling has been reset.
2120 gtk_paned_set_first_paned (paned, paned);
2123 gtk_paned_find_neighbours (paned, &next, &prev);
2125 if (reversed && prev &&
2126 prev != paned && paned != paned->priv->first_paned)
2130 else if (!reversed && next &&
2131 next != paned && next != paned->priv->first_paned)
2137 gtk_paned_accept_position (paned);
2143 gtk_paned_set_saved_focus (focus, paned->priv->saved_focus);
2144 gtk_paned_set_first_paned (focus, paned->priv->first_paned);
2146 gtk_paned_set_saved_focus (paned, NULL);
2147 gtk_paned_set_first_paned (paned, NULL);
2149 gtk_widget_grab_focus (GTK_WIDGET (focus));
2151 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2153 paned->original_position = -1;
2154 focus->original_position = gtk_paned_get_position (focus);
2159 GtkContainer *container = GTK_CONTAINER (paned);
2162 GtkPaned *prev, *next;
2163 GtkWidget *toplevel;
2165 gtk_paned_find_neighbours (paned, &next, &prev);
2167 if (container->focus_child == paned->child1)
2180 else if (container->focus_child == paned->child2)
2195 /* Focus is not inside this paned, and we don't have focus.
2196 * Presumably this happened because the application wants us
2197 * to start keyboard navigating.
2207 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2209 if (GTK_IS_WINDOW (toplevel))
2210 gtk_paned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
2211 gtk_paned_set_first_paned (focus, first);
2212 focus->original_position = gtk_paned_get_position (focus);
2214 gtk_widget_grab_focus (GTK_WIDGET (focus));
2221 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2223 /* This function/signal has the wrong name. It is called when you
2224 * press Tab or Shift-Tab and what we do is act as if
2225 * the user pressed Return and then Tab or Shift-Tab
2227 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2228 gtk_paned_accept_position (paned);
2234 * gtk_paned_get_handle_window:
2235 * @panede: a #GtkPaned
2237 * Returns the #GdkWindow of the handle. This function is
2238 * useful when handling button or motion events because it
2239 * enables the callback to distinguish between the window
2240 * of the paned, a child and the handle.
2242 * Return value: the paned's handle window.
2247 gtk_paned_get_handle_window (GtkPaned *paned)
2249 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2251 return paned->handle;
2254 #define __GTK_PANED_C__
2255 #include "gtkaliasdef.c"