1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdk/gdkkeysyms.h"
30 #include "gtkbindings.h"
32 #include "gtkmarshalers.h"
33 #include "gtkorientable.h"
35 #include "gtkwindow.h"
36 #include "gtkprivate.h"
41 struct _GtkPanedPrivate
43 GtkOrientation orientation;
44 GtkPaned *first_paned;
47 GtkWidget *last_child1_focus;
48 GtkWidget *last_child2_focus;
49 GtkWidget *saved_focus;
51 GdkCursorType cursor_type;
52 GdkDevice *grab_device;
54 GdkRectangle handle_pos;
62 gint original_position;
64 guint handle_prelit : 1;
66 guint in_recursion : 1;
67 guint child1_resize : 1;
68 guint child1_shrink : 1;
69 guint child2_resize : 1;
70 guint child2_shrink : 1;
71 guint position_set : 1;
101 static void gtk_paned_set_property (GObject *object,
105 static void gtk_paned_get_property (GObject *object,
109 static void gtk_paned_set_child_property (GtkContainer *container,
114 static void gtk_paned_get_child_property (GtkContainer *container,
119 static void gtk_paned_finalize (GObject *object);
121 static void gtk_paned_size_request (GtkWidget *widget,
122 GtkRequisition *requisition);
123 static void gtk_paned_size_allocate (GtkWidget *widget,
124 GtkAllocation *allocation);
125 static void gtk_paned_realize (GtkWidget *widget);
126 static void gtk_paned_unrealize (GtkWidget *widget);
127 static void gtk_paned_map (GtkWidget *widget);
128 static void gtk_paned_unmap (GtkWidget *widget);
129 static void gtk_paned_state_changed (GtkWidget *widget,
130 GtkStateType previous_state);
131 static gboolean gtk_paned_expose (GtkWidget *widget,
132 GdkEventExpose *event);
133 static gboolean gtk_paned_enter (GtkWidget *widget,
134 GdkEventCrossing *event);
135 static gboolean gtk_paned_leave (GtkWidget *widget,
136 GdkEventCrossing *event);
137 static gboolean gtk_paned_button_press (GtkWidget *widget,
138 GdkEventButton *event);
139 static gboolean gtk_paned_button_release (GtkWidget *widget,
140 GdkEventButton *event);
141 static gboolean gtk_paned_motion (GtkWidget *widget,
142 GdkEventMotion *event);
143 static gboolean gtk_paned_focus (GtkWidget *widget,
144 GtkDirectionType direction);
145 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
146 GdkEventGrabBroken *event);
147 static void gtk_paned_add (GtkContainer *container,
149 static void gtk_paned_remove (GtkContainer *container,
151 static void gtk_paned_forall (GtkContainer *container,
152 gboolean include_internals,
153 GtkCallback callback,
154 gpointer callback_data);
155 static void gtk_paned_calc_position (GtkPaned *paned,
159 static void gtk_paned_set_focus_child (GtkContainer *container,
161 static void gtk_paned_set_saved_focus (GtkPaned *paned,
163 static void gtk_paned_set_first_paned (GtkPaned *paned,
164 GtkPaned *first_paned);
165 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
167 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
169 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
171 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
173 static gboolean gtk_paned_move_handle (GtkPaned *paned,
174 GtkScrollType scroll);
175 static gboolean gtk_paned_accept_position (GtkPaned *paned);
176 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
177 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
179 static GType gtk_paned_child_type (GtkContainer *container);
180 static void gtk_paned_grab_notify (GtkWidget *widget,
181 gboolean was_grabbed);
184 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
185 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
188 static guint signals[LAST_SIGNAL] = { 0 };
192 add_tab_bindings (GtkBindingSet *binding_set,
193 GdkModifierType modifiers)
195 gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
196 "toggle-handle-focus", 0);
197 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
198 "toggle-handle-focus", 0);
202 add_move_binding (GtkBindingSet *binding_set,
204 GdkModifierType mask,
205 GtkScrollType scroll)
207 gtk_binding_entry_add_signal (binding_set, keyval, mask,
209 GTK_TYPE_SCROLL_TYPE, scroll);
213 gtk_paned_class_init (GtkPanedClass *class)
215 GObjectClass *object_class;
216 GtkWidgetClass *widget_class;
217 GtkContainerClass *container_class;
218 GtkPanedClass *paned_class;
219 GtkBindingSet *binding_set;
221 object_class = (GObjectClass *) class;
222 widget_class = (GtkWidgetClass *) class;
223 container_class = (GtkContainerClass *) class;
224 paned_class = (GtkPanedClass *) class;
226 object_class->set_property = gtk_paned_set_property;
227 object_class->get_property = gtk_paned_get_property;
228 object_class->finalize = gtk_paned_finalize;
230 widget_class->size_request = gtk_paned_size_request;
231 widget_class->size_allocate = gtk_paned_size_allocate;
232 widget_class->realize = gtk_paned_realize;
233 widget_class->unrealize = gtk_paned_unrealize;
234 widget_class->map = gtk_paned_map;
235 widget_class->unmap = gtk_paned_unmap;
236 widget_class->expose_event = gtk_paned_expose;
237 widget_class->focus = gtk_paned_focus;
238 widget_class->enter_notify_event = gtk_paned_enter;
239 widget_class->leave_notify_event = gtk_paned_leave;
240 widget_class->button_press_event = gtk_paned_button_press;
241 widget_class->button_release_event = gtk_paned_button_release;
242 widget_class->motion_notify_event = gtk_paned_motion;
243 widget_class->grab_broken_event = gtk_paned_grab_broken;
244 widget_class->grab_notify = gtk_paned_grab_notify;
245 widget_class->state_changed = gtk_paned_state_changed;
247 container_class->add = gtk_paned_add;
248 container_class->remove = gtk_paned_remove;
249 container_class->forall = gtk_paned_forall;
250 container_class->child_type = gtk_paned_child_type;
251 container_class->set_focus_child = gtk_paned_set_focus_child;
252 container_class->set_child_property = gtk_paned_set_child_property;
253 container_class->get_child_property = gtk_paned_get_child_property;
255 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
256 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
257 paned_class->move_handle = gtk_paned_move_handle;
258 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
259 paned_class->accept_position = gtk_paned_accept_position;
260 paned_class->cancel_position = gtk_paned_cancel_position;
262 g_object_class_override_property (object_class,
266 g_object_class_install_property (object_class,
268 g_param_spec_int ("position",
270 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
274 GTK_PARAM_READWRITE));
276 g_object_class_install_property (object_class,
278 g_param_spec_boolean ("position-set",
280 P_("TRUE if the Position property should be used"),
282 GTK_PARAM_READWRITE));
284 gtk_widget_class_install_style_property (widget_class,
285 g_param_spec_int ("handle-size",
287 P_("Width of handle"),
291 GTK_PARAM_READABLE));
293 * GtkPaned:min-position:
295 * The smallest possible value for the position property. This property is derived from the
296 * size and shrinkability of the widget's children.
300 g_object_class_install_property (object_class,
302 g_param_spec_int ("min-position",
303 P_("Minimal Position"),
304 P_("Smallest possible value for the \"position\" property"),
308 GTK_PARAM_READABLE));
311 * GtkPaned:max-position:
313 * The largest possible value for the position property. This property is derived from the
314 * size and shrinkability of the widget's children.
318 g_object_class_install_property (object_class,
320 g_param_spec_int ("max-position",
321 P_("Maximal Position"),
322 P_("Largest possible value for the \"position\" property"),
326 GTK_PARAM_READABLE));
331 * The "resize" child property determines whether the child expands and
332 * shrinks along with the paned widget.
336 gtk_container_class_install_child_property (container_class,
338 g_param_spec_boolean ("resize",
340 P_("If TRUE, the child expands and shrinks along with the paned widget"),
342 GTK_PARAM_READWRITE));
347 * The "shrink" child property determines whether the child can be made
348 * smaller than its requisition.
352 gtk_container_class_install_child_property (container_class,
354 g_param_spec_boolean ("shrink",
356 P_("If TRUE, the child can be made smaller than its requisition"),
358 GTK_PARAM_READWRITE));
361 * GtkPaned::cycle-child-focus:
362 * @widget: the object that received the signal
363 * @reversed: whether cycling backward or forward
365 * The ::cycle-child-focus signal is a
366 * <link linkend="keybinding-signals">keybinding signal</link>
367 * which gets emitted to cycle the focus between the children of the paned.
369 * The default binding is f6.
373 signals [CYCLE_CHILD_FOCUS] =
374 g_signal_new (I_("cycle-child-focus"),
375 G_TYPE_FROM_CLASS (object_class),
376 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
377 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
379 _gtk_marshal_BOOLEAN__BOOLEAN,
384 * GtkPaned::toggle-handle-focus:
385 * @widget: the object that received the signal
387 * The ::toggle-handle-focus is a
388 * <link linkend="keybinding-signals">keybinding signal</link>
389 * which gets emitted to accept the current position of the handle and then
390 * move focus to the next widget in the focus chain.
392 * The default binding is Tab.
396 signals [TOGGLE_HANDLE_FOCUS] =
397 g_signal_new (I_("toggle-handle-focus"),
398 G_TYPE_FROM_CLASS (object_class),
399 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
400 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
402 _gtk_marshal_BOOLEAN__VOID,
406 * GtkPaned::move-handle:
407 * @widget: the object that received the signal
408 * @scroll_type: a #GtkScrollType
410 * The ::move-handle signal is a
411 * <link linkend="keybinding-signals">keybinding signal</link>
412 * which gets emitted to move the handle when the user is using key bindings
417 signals[MOVE_HANDLE] =
418 g_signal_new (I_("move-handle"),
419 G_TYPE_FROM_CLASS (object_class),
420 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
421 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
423 _gtk_marshal_BOOLEAN__ENUM,
425 GTK_TYPE_SCROLL_TYPE);
428 * GtkPaned::cycle-handle-focus:
429 * @widget: the object that received the signal
430 * @reversed: whether cycling backward or forward
432 * The ::cycle-handle-focus signal is a
433 * <link linkend="keybinding-signals">keybinding signal</link>
434 * which gets emitted to cycle whether the paned should grab focus to allow
435 * the user to change position of the handle by using key bindings.
437 * The default binding for this signal is f8.
441 signals [CYCLE_HANDLE_FOCUS] =
442 g_signal_new (I_("cycle-handle-focus"),
443 G_TYPE_FROM_CLASS (object_class),
444 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
445 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
447 _gtk_marshal_BOOLEAN__BOOLEAN,
452 * GtkPaned::accept-position:
453 * @widget: the object that received the signal
455 * The ::accept-position signal is a
456 * <link linkend="keybinding-signals">keybinding signal</link>
457 * which gets emitted to accept the current position of the handle when
458 * moving it using key bindings.
460 * The default binding for this signal is Return or Space.
464 signals [ACCEPT_POSITION] =
465 g_signal_new (I_("accept-position"),
466 G_TYPE_FROM_CLASS (object_class),
467 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
468 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
470 _gtk_marshal_BOOLEAN__VOID,
474 * GtkPaned::cancel-position:
475 * @widget: the object that received the signal
477 * The ::cancel-position signal is a
478 * <link linkend="keybinding-signals">keybinding signal</link>
479 * which gets emitted to cancel moving the position of the handle using key
480 * bindings. The position of the handle will be reset to the value prior to
483 * The default binding for this signal is Escape.
487 signals [CANCEL_POSITION] =
488 g_signal_new (I_("cancel-position"),
489 G_TYPE_FROM_CLASS (object_class),
490 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
491 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
493 _gtk_marshal_BOOLEAN__VOID,
496 binding_set = gtk_binding_set_by_class (class);
499 gtk_binding_entry_add_signal (binding_set,
501 "cycle-child-focus", 1,
502 G_TYPE_BOOLEAN, FALSE);
503 gtk_binding_entry_add_signal (binding_set,
504 GDK_F6, GDK_SHIFT_MASK,
505 "cycle-child-focus", 1,
506 G_TYPE_BOOLEAN, TRUE);
509 gtk_binding_entry_add_signal (binding_set,
511 "cycle-handle-focus", 1,
512 G_TYPE_BOOLEAN, FALSE);
514 gtk_binding_entry_add_signal (binding_set,
515 GDK_F8, GDK_SHIFT_MASK,
516 "cycle-handle-focus", 1,
517 G_TYPE_BOOLEAN, TRUE);
519 add_tab_bindings (binding_set, 0);
520 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
521 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
522 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
524 /* accept and cancel positions */
525 gtk_binding_entry_add_signal (binding_set,
527 "cancel-position", 0);
529 gtk_binding_entry_add_signal (binding_set,
531 "accept-position", 0);
532 gtk_binding_entry_add_signal (binding_set,
534 "accept-position", 0);
535 gtk_binding_entry_add_signal (binding_set,
537 "accept-position", 0);
538 gtk_binding_entry_add_signal (binding_set,
540 "accept-position", 0);
541 gtk_binding_entry_add_signal (binding_set,
543 "accept-position", 0);
546 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
547 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
548 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
549 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
551 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
552 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
553 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
554 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
556 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
557 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
558 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
559 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
560 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
561 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
563 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
564 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
565 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
566 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
567 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
568 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
570 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
571 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
572 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
573 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
575 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
579 gtk_paned_child_type (GtkContainer *container)
581 GtkPaned *paned = GTK_PANED (container);
582 GtkPanedPrivate *priv = paned->priv;
584 if (!priv->child1 || !priv->child2)
585 return GTK_TYPE_WIDGET;
591 gtk_paned_init (GtkPaned *paned)
593 GtkPanedPrivate *priv;
595 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
596 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
598 /* We only need to redraw when the handle position moves, which is
599 * independent of the overall allocation of the GtkPaned
601 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
603 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
606 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
607 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
613 priv->cursor_type = GDK_CROSS;
615 priv->handle_pos.width = 5;
616 priv->handle_pos.height = 5;
617 priv->position_set = FALSE;
618 priv->last_allocation = -1;
619 priv->in_drag = FALSE;
621 priv->last_child1_focus = NULL;
622 priv->last_child2_focus = NULL;
623 priv->in_recursion = FALSE;
624 priv->handle_prelit = FALSE;
625 priv->original_position = -1;
627 priv->handle_pos.x = -1;
628 priv->handle_pos.y = -1;
634 gtk_paned_set_property (GObject *object,
639 GtkPaned *paned = GTK_PANED (object);
640 GtkPanedPrivate *priv = paned->priv;
644 case PROP_ORIENTATION:
645 priv->orientation = g_value_get_enum (value);
647 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
648 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
650 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
652 /* state_changed updates the cursor */
653 gtk_paned_state_changed (GTK_WIDGET (paned), GTK_WIDGET (paned)->state);
654 gtk_widget_queue_resize (GTK_WIDGET (paned));
657 gtk_paned_set_position (paned, g_value_get_int (value));
659 case PROP_POSITION_SET:
660 priv->position_set = g_value_get_boolean (value);
661 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
664 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
670 gtk_paned_get_property (GObject *object,
675 GtkPaned *paned = GTK_PANED (object);
676 GtkPanedPrivate *priv = paned->priv;
680 case PROP_ORIENTATION:
681 g_value_set_enum (value, priv->orientation);
684 g_value_set_int (value, priv->child1_size);
686 case PROP_POSITION_SET:
687 g_value_set_boolean (value, priv->position_set);
689 case PROP_MIN_POSITION:
690 g_value_set_int (value, priv->min_position);
692 case PROP_MAX_POSITION:
693 g_value_set_int (value, priv->max_position);
696 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
702 gtk_paned_set_child_property (GtkContainer *container,
708 GtkPaned *paned = GTK_PANED (container);
709 GtkPanedPrivate *priv = paned->priv;
710 gboolean old_value, new_value;
712 g_assert (child == priv->child1 || child == priv->child2);
714 new_value = g_value_get_boolean (value);
717 case CHILD_PROP_RESIZE:
718 if (child == priv->child1)
720 old_value = priv->child1_resize;
721 priv->child1_resize = new_value;
725 old_value = priv->child2_resize;
726 priv->child2_resize = new_value;
729 case CHILD_PROP_SHRINK:
730 if (child == priv->child1)
732 old_value = priv->child1_shrink;
733 priv->child1_shrink = new_value;
737 old_value = priv->child2_shrink;
738 priv->child2_shrink = new_value;
742 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
743 old_value = -1; /* quiet gcc */
746 if (old_value != new_value)
747 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
751 gtk_paned_get_child_property (GtkContainer *container,
757 GtkPaned *paned = GTK_PANED (container);
758 GtkPanedPrivate *priv = paned->priv;
760 g_assert (child == priv->child1 || child == priv->child2);
764 case CHILD_PROP_RESIZE:
765 if (child == priv->child1)
766 g_value_set_boolean (value, priv->child1_resize);
768 g_value_set_boolean (value, priv->child2_resize);
770 case CHILD_PROP_SHRINK:
771 if (child == priv->child1)
772 g_value_set_boolean (value, priv->child1_shrink);
774 g_value_set_boolean (value, priv->child2_shrink);
777 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
783 gtk_paned_finalize (GObject *object)
785 GtkPaned *paned = GTK_PANED (object);
787 gtk_paned_set_saved_focus (paned, NULL);
788 gtk_paned_set_first_paned (paned, NULL);
790 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
794 gtk_paned_size_request (GtkWidget *widget,
795 GtkRequisition *requisition)
797 GtkPaned *paned = GTK_PANED (widget);
798 GtkPanedPrivate *priv = paned->priv;
799 GtkRequisition child_requisition;
802 requisition->width = 0;
803 requisition->height = 0;
805 if (priv->child1 && gtk_widget_get_visible (priv->child1))
807 gtk_widget_size_request (priv->child1, &child_requisition);
809 requisition->height = child_requisition.height;
810 requisition->width = child_requisition.width;
813 if (priv->child2 && gtk_widget_get_visible (priv->child2))
815 gtk_widget_size_request (priv->child2, &child_requisition);
817 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
819 requisition->height = MAX (requisition->height,
820 child_requisition.height);
821 requisition->width += child_requisition.width;
825 requisition->width = MAX (requisition->width,
826 child_requisition.width);
827 requisition->height += child_requisition.height;
831 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
832 requisition->width += border_width * 2;
833 requisition->height += border_width * 2;
835 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
836 priv->child2 && gtk_widget_get_visible (priv->child2))
840 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
842 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
843 requisition->width += handle_size;
845 requisition->height += handle_size;
850 flip_child (GtkWidget *widget,
851 GtkAllocation *child_pos)
853 gint x = widget->allocation.x;
854 gint width = widget->allocation.width;
856 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
860 gtk_paned_size_allocate (GtkWidget *widget,
861 GtkAllocation *allocation)
863 GtkPaned *paned = GTK_PANED (widget);
864 GtkPanedPrivate *priv = paned->priv;
867 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
869 widget->allocation = *allocation;
871 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
872 priv->child2 && gtk_widget_get_visible (priv->child2))
874 GtkRequisition child1_requisition;
875 GtkRequisition child2_requisition;
876 GtkAllocation child1_allocation;
877 GtkAllocation child2_allocation;
878 GdkRectangle old_handle_pos;
881 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
883 gtk_widget_get_child_requisition (priv->child1, &child1_requisition);
884 gtk_widget_get_child_requisition (priv->child2, &child2_requisition);
886 old_handle_pos = priv->handle_pos;
888 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
890 gtk_paned_calc_position (paned,
891 MAX (1, widget->allocation.width
894 child1_requisition.width,
895 child2_requisition.width);
897 priv->handle_pos.x = widget->allocation.x + priv->child1_size + border_width;
898 priv->handle_pos.y = widget->allocation.y + border_width;
899 priv->handle_pos.width = handle_size;
900 priv->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
902 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
903 child1_allocation.width = MAX (1, priv->child1_size);
904 child1_allocation.x = widget->allocation.x + border_width;
905 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
907 child2_allocation.x = child1_allocation.x + priv->child1_size + priv->handle_pos.width;
908 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
910 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
912 flip_child (widget, &(child2_allocation));
913 flip_child (widget, &(child1_allocation));
914 flip_child (widget, &(priv->handle_pos));
919 gtk_paned_calc_position (paned,
920 MAX (1, widget->allocation.height
923 child1_requisition.height,
924 child2_requisition.height);
926 priv->handle_pos.x = widget->allocation.x + border_width;
927 priv->handle_pos.y = widget->allocation.y + priv->child1_size + border_width;
928 priv->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
929 priv->handle_pos.height = handle_size;
931 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
932 child1_allocation.height = MAX (1, priv->child1_size);
933 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
934 child1_allocation.y = widget->allocation.y + border_width;
936 child2_allocation.y = child1_allocation.y + priv->child1_size + priv->handle_pos.height;
937 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
940 if (gtk_widget_get_mapped (widget) &&
941 (old_handle_pos.x != priv->handle_pos.x ||
942 old_handle_pos.y != priv->handle_pos.y ||
943 old_handle_pos.width != priv->handle_pos.width ||
944 old_handle_pos.height != priv->handle_pos.height))
946 gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
947 gdk_window_invalidate_rect (widget->window, &priv->handle_pos, FALSE);
950 if (gtk_widget_get_realized (widget))
952 if (gtk_widget_get_mapped (widget))
953 gdk_window_show (priv->handle);
955 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
957 gdk_window_move_resize (priv->handle,
961 priv->handle_pos.height);
965 gdk_window_move_resize (priv->handle,
968 priv->handle_pos.width,
973 /* Now allocate the childen, making sure, when resizing not to
974 * overlap the windows
976 if (gtk_widget_get_mapped (widget) &&
978 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
979 priv->child1->allocation.width < child1_allocation.width) ||
981 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
982 priv->child1->allocation.height < child1_allocation.height)))
984 gtk_widget_size_allocate (priv->child2, &child2_allocation);
985 gtk_widget_size_allocate (priv->child1, &child1_allocation);
989 gtk_widget_size_allocate (priv->child1, &child1_allocation);
990 gtk_widget_size_allocate (priv->child2, &child2_allocation);
995 GtkAllocation child_allocation;
997 if (gtk_widget_get_realized (widget))
998 gdk_window_hide (priv->handle);
1001 gtk_widget_set_child_visible (priv->child1, TRUE);
1003 gtk_widget_set_child_visible (priv->child2, TRUE);
1005 child_allocation.x = widget->allocation.x + border_width;
1006 child_allocation.y = widget->allocation.y + border_width;
1007 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
1008 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
1010 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1011 gtk_widget_size_allocate (priv->child1, &child_allocation);
1012 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1013 gtk_widget_size_allocate (priv->child2, &child_allocation);
1018 gtk_paned_realize (GtkWidget *widget)
1020 GtkPaned *paned = GTK_PANED (widget);
1021 GtkPanedPrivate *priv = paned->priv;
1022 GdkWindowAttr attributes;
1023 gint attributes_mask;
1025 gtk_widget_set_realized (widget, TRUE);
1027 widget->window = gtk_widget_get_parent_window (widget);
1028 g_object_ref (widget->window);
1030 attributes.window_type = GDK_WINDOW_CHILD;
1031 attributes.wclass = GDK_INPUT_ONLY;
1032 attributes.x = priv->handle_pos.x;
1033 attributes.y = priv->handle_pos.y;
1034 attributes.width = priv->handle_pos.width;
1035 attributes.height = priv->handle_pos.height;
1036 attributes.event_mask = gtk_widget_get_events (widget);
1037 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1038 GDK_BUTTON_RELEASE_MASK |
1039 GDK_ENTER_NOTIFY_MASK |
1040 GDK_LEAVE_NOTIFY_MASK |
1041 GDK_POINTER_MOTION_MASK |
1042 GDK_POINTER_MOTION_HINT_MASK);
1043 attributes_mask = GDK_WA_X | GDK_WA_Y;
1044 if (gtk_widget_is_sensitive (widget))
1046 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1048 attributes_mask |= GDK_WA_CURSOR;
1051 priv->handle = gdk_window_new (widget->window,
1052 &attributes, attributes_mask);
1053 gdk_window_set_user_data (priv->handle, paned);
1054 if (attributes_mask & GDK_WA_CURSOR)
1055 gdk_cursor_unref (attributes.cursor);
1057 widget->style = gtk_style_attach (widget->style, widget->window);
1059 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1060 priv->child2 && gtk_widget_get_visible (priv->child2))
1061 gdk_window_show (priv->handle);
1065 gtk_paned_unrealize (GtkWidget *widget)
1067 GtkPaned *paned = GTK_PANED (widget);
1068 GtkPanedPrivate *priv = paned->priv;
1072 g_object_unref (priv->xor_gc);
1073 priv->xor_gc = NULL;
1078 gdk_window_set_user_data (priv->handle, NULL);
1079 gdk_window_destroy (priv->handle);
1080 priv->handle = NULL;
1083 gtk_paned_set_last_child1_focus (paned, NULL);
1084 gtk_paned_set_last_child2_focus (paned, NULL);
1085 gtk_paned_set_saved_focus (paned, NULL);
1086 gtk_paned_set_first_paned (paned, NULL);
1088 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1092 gtk_paned_map (GtkWidget *widget)
1094 GtkPaned *paned = GTK_PANED (widget);
1095 GtkPanedPrivate *priv = paned->priv;
1097 gdk_window_show (priv->handle);
1099 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1103 gtk_paned_unmap (GtkWidget *widget)
1105 GtkPaned *paned = GTK_PANED (widget);
1106 GtkPanedPrivate *priv = paned->priv;
1108 gdk_window_hide (priv->handle);
1110 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1114 gtk_paned_expose (GtkWidget *widget,
1115 GdkEventExpose *event)
1117 GtkPaned *paned = GTK_PANED (widget);
1118 GtkPanedPrivate *priv = paned->priv;
1120 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1121 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1122 priv->child2 && gtk_widget_get_visible (priv->child2))
1126 if (gtk_widget_is_focus (widget))
1127 state = GTK_STATE_SELECTED;
1128 else if (priv->handle_prelit)
1129 state = GTK_STATE_PRELIGHT;
1131 state = gtk_widget_get_state (widget);
1133 gtk_paint_handle (widget->style, widget->window,
1134 state, GTK_SHADOW_NONE,
1135 &priv->handle_pos, widget, "paned",
1136 priv->handle_pos.x, priv->handle_pos.y,
1137 priv->handle_pos.width, priv->handle_pos.height,
1138 !priv->orientation);
1141 /* Chain up to draw children */
1142 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1148 is_rtl (GtkPaned *paned)
1150 GtkPanedPrivate *priv = paned->priv;
1152 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1153 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1162 update_drag (GtkPaned *paned)
1164 GtkPanedPrivate *priv = paned->priv;
1169 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1170 gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
1172 gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
1174 pos -= priv->drag_pos;
1178 gtk_widget_style_get (GTK_WIDGET (paned),
1179 "handle-size", &handle_size,
1182 size = GTK_WIDGET (paned)->allocation.width - pos - handle_size;
1189 size -= gtk_container_get_border_width (GTK_CONTAINER (paned));
1191 size = CLAMP (size, priv->min_position, priv->max_position);
1193 if (size != priv->child1_size)
1194 gtk_paned_set_position (paned, size);
1198 gtk_paned_enter (GtkWidget *widget,
1199 GdkEventCrossing *event)
1201 GtkPaned *paned = GTK_PANED (widget);
1202 GtkPanedPrivate *priv = paned->priv;
1205 update_drag (paned);
1208 priv->handle_prelit = TRUE;
1209 gtk_widget_queue_draw_area (widget,
1212 priv->handle_pos.width,
1213 priv->handle_pos.height);
1220 gtk_paned_leave (GtkWidget *widget,
1221 GdkEventCrossing *event)
1223 GtkPaned *paned = GTK_PANED (widget);
1224 GtkPanedPrivate *priv = paned->priv;
1227 update_drag (paned);
1230 priv->handle_prelit = FALSE;
1231 gtk_widget_queue_draw_area (widget,
1234 priv->handle_pos.width,
1235 priv->handle_pos.height);
1242 gtk_paned_focus (GtkWidget *widget,
1243 GtkDirectionType direction)
1248 /* This is a hack, but how can this be done without
1249 * excessive cut-and-paste from gtkcontainer.c?
1252 gtk_widget_set_can_focus (widget, FALSE);
1253 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1254 gtk_widget_set_can_focus (widget, TRUE);
1260 gtk_paned_button_press (GtkWidget *widget,
1261 GdkEventButton *event)
1263 GtkPaned *paned = GTK_PANED (widget);
1264 GtkPanedPrivate *priv = paned->priv;
1266 if (!priv->in_drag &&
1267 (event->window == priv->handle) && (event->button == 1))
1269 /* We need a server grab here, not gtk_grab_add(), since
1270 * we don't want to pass events on to the widget's children */
1271 if (gdk_device_grab (event->device,
1273 GDK_OWNERSHIP_WINDOW, FALSE,
1274 GDK_POINTER_MOTION_HINT_MASK
1275 | GDK_BUTTON1_MOTION_MASK
1276 | GDK_BUTTON_RELEASE_MASK
1277 | GDK_ENTER_NOTIFY_MASK
1278 | GDK_LEAVE_NOTIFY_MASK,
1279 NULL, event->time) != GDK_GRAB_SUCCESS)
1282 priv->in_drag = TRUE;
1283 priv->grab_time = event->time;
1284 priv->grab_device = event->device;
1286 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1287 priv->drag_pos = event->x;
1289 priv->drag_pos = event->y;
1298 gtk_paned_grab_broken (GtkWidget *widget,
1299 GdkEventGrabBroken *event)
1301 GtkPaned *paned = GTK_PANED (widget);
1302 GtkPanedPrivate *priv = paned->priv;
1304 priv->in_drag = FALSE;
1305 priv->drag_pos = -1;
1306 priv->position_set = TRUE;
1312 stop_drag (GtkPaned *paned)
1314 GtkPanedPrivate *priv = paned->priv;
1316 priv->in_drag = FALSE;
1317 priv->drag_pos = -1;
1318 priv->position_set = TRUE;
1320 gdk_device_ungrab (priv->grab_device,
1322 priv->grab_device = NULL;
1326 gtk_paned_grab_notify (GtkWidget *widget,
1327 gboolean was_grabbed)
1329 GtkPaned *paned = GTK_PANED (widget);
1330 GtkPanedPrivate *priv = paned->priv;
1331 GdkDevice *grab_device;
1333 grab_device = priv->grab_device;
1335 if (priv->in_drag && grab_device &&
1336 gtk_widget_device_is_shadowed (widget, grab_device))
1341 gtk_paned_state_changed (GtkWidget *widget,
1342 GtkStateType previous_state)
1344 GtkPaned *paned = GTK_PANED (widget);
1345 GtkPanedPrivate *priv = paned->priv;
1348 if (gtk_widget_get_realized (widget))
1350 if (gtk_widget_is_sensitive (widget))
1351 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1356 gdk_window_set_cursor (priv->handle, cursor);
1359 gdk_cursor_unref (cursor);
1364 gtk_paned_button_release (GtkWidget *widget,
1365 GdkEventButton *event)
1367 GtkPaned *paned = GTK_PANED (widget);
1368 GtkPanedPrivate *priv = paned->priv;
1370 if (priv->in_drag && (event->button == 1))
1381 gtk_paned_motion (GtkWidget *widget,
1382 GdkEventMotion *event)
1384 GtkPaned *paned = GTK_PANED (widget);
1385 GtkPanedPrivate *priv = paned->priv;
1389 update_drag (paned);
1398 * @orientation: the paned's orientation.
1400 * Creates a new #GtkPaned widget.
1402 * Return value: a new #GtkPaned.
1407 gtk_paned_new (GtkOrientation orientation)
1409 return g_object_new (GTK_TYPE_PANED,
1410 "orientation", orientation,
1415 gtk_paned_add1 (GtkPaned *paned,
1418 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1422 gtk_paned_add2 (GtkPaned *paned,
1425 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1429 gtk_paned_pack1 (GtkPaned *paned,
1434 GtkPanedPrivate *priv;
1436 g_return_if_fail (GTK_IS_PANED (paned));
1437 g_return_if_fail (GTK_IS_WIDGET (child));
1443 priv->child1 = child;
1444 priv->child1_resize = resize;
1445 priv->child1_shrink = shrink;
1447 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1452 gtk_paned_pack2 (GtkPaned *paned,
1457 GtkPanedPrivate *priv;
1459 g_return_if_fail (GTK_IS_PANED (paned));
1460 g_return_if_fail (GTK_IS_WIDGET (child));
1466 priv->child2 = child;
1467 priv->child2_resize = resize;
1468 priv->child2_shrink = shrink;
1470 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1476 gtk_paned_add (GtkContainer *container,
1479 GtkPanedPrivate *priv;
1482 g_return_if_fail (GTK_IS_PANED (container));
1484 paned = GTK_PANED (container);
1488 gtk_paned_add1 (paned, widget);
1489 else if (!priv->child2)
1490 gtk_paned_add2 (paned, widget);
1492 g_warning ("GtkPaned cannot have more than 2 children\n");
1496 gtk_paned_remove (GtkContainer *container,
1499 GtkPaned *paned = GTK_PANED (container);
1500 GtkPanedPrivate *priv = paned->priv;
1501 gboolean was_visible;
1503 was_visible = gtk_widget_get_visible (widget);
1505 if (priv->child1 == widget)
1507 gtk_widget_unparent (widget);
1509 priv->child1 = NULL;
1511 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1512 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1514 else if (priv->child2 == widget)
1516 gtk_widget_unparent (widget);
1518 priv->child2 = NULL;
1520 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1521 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1526 gtk_paned_forall (GtkContainer *container,
1527 gboolean include_internals,
1528 GtkCallback callback,
1529 gpointer callback_data)
1531 GtkPanedPrivate *priv;
1534 g_return_if_fail (callback != NULL);
1536 paned = GTK_PANED (container);
1540 (*callback) (priv->child1, callback_data);
1542 (*callback) (priv->child2, callback_data);
1546 * gtk_paned_get_position:
1547 * @paned: a #GtkPaned widget
1549 * Obtains the position of the divider between the two panes.
1551 * Return value: position of the divider
1554 gtk_paned_get_position (GtkPaned *paned)
1556 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1558 return paned->priv->child1_size;
1562 * gtk_paned_set_position:
1563 * @paned: a #GtkPaned widget
1564 * @position: pixel position of divider, a negative value means that the position
1567 * Sets the position of the divider between the two panes.
1570 gtk_paned_set_position (GtkPaned *paned,
1573 GtkPanedPrivate *priv;
1576 g_return_if_fail (GTK_IS_PANED (paned));
1580 if (priv->child1_size == position)
1583 object = G_OBJECT (paned);
1587 /* We don't clamp here - the assumption is that
1588 * if the total allocation changes at the same time
1589 * as the position, the position set is with reference
1590 * to the new total size. If only the position changes,
1591 * then clamping will occur in gtk_paned_calc_position()
1594 priv->child1_size = position;
1595 priv->position_set = TRUE;
1599 priv->position_set = FALSE;
1602 g_object_freeze_notify (object);
1603 g_object_notify (object, "position");
1604 g_object_notify (object, "position-set");
1605 g_object_thaw_notify (object);
1607 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1610 /* Hacky work-around for bug #144269 */
1611 if (priv->child2 != NULL)
1613 gtk_widget_queue_draw (priv->child2);
1619 * gtk_paned_get_child1:
1620 * @paned: a #GtkPaned widget
1622 * Obtains the first child of the paned widget.
1624 * Return value: first child, or %NULL if it is not set.
1629 gtk_paned_get_child1 (GtkPaned *paned)
1631 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1633 return paned->priv->child1;
1637 * gtk_paned_get_child2:
1638 * @paned: a #GtkPaned widget
1640 * Obtains the second child of the paned widget.
1642 * Return value: second child, or %NULL if it is not set.
1647 gtk_paned_get_child2 (GtkPaned *paned)
1649 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1651 return paned->priv->child2;
1655 gtk_paned_calc_position (GtkPaned *paned,
1660 GtkPanedPrivate *priv = paned->priv;
1662 gint old_min_position;
1663 gint old_max_position;
1665 old_position = priv->child1_size;
1666 old_min_position = priv->min_position;
1667 old_max_position = priv->max_position;
1669 priv->min_position = priv->child1_shrink ? 0 : child1_req;
1671 priv->max_position = allocation;
1672 if (!priv->child2_shrink)
1673 priv->max_position = MAX (1, priv->max_position - child2_req);
1674 priv->max_position = MAX (priv->min_position, priv->max_position);
1676 if (!priv->position_set)
1678 if (priv->child1_resize && !priv->child2_resize)
1679 priv->child1_size = MAX (0, allocation - child2_req);
1680 else if (!priv->child1_resize && priv->child2_resize)
1681 priv->child1_size = child1_req;
1682 else if (child1_req + child2_req != 0)
1683 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1685 priv->child1_size = allocation * 0.5 + 0.5;
1689 /* If the position was set before the initial allocation.
1690 * (priv->last_allocation <= 0) just clamp it and leave it.
1692 if (priv->last_allocation > 0)
1694 if (priv->child1_resize && !priv->child2_resize)
1695 priv->child1_size += allocation - priv->last_allocation;
1696 else if (!(!priv->child1_resize && priv->child2_resize))
1697 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
1701 priv->child1_size = CLAMP (priv->child1_size,
1703 priv->max_position);
1706 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
1709 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
1711 g_object_freeze_notify (G_OBJECT (paned));
1712 if (priv->child1_size != old_position)
1713 g_object_notify (G_OBJECT (paned), "position");
1714 if (priv->min_position != old_min_position)
1715 g_object_notify (G_OBJECT (paned), "min-position");
1716 if (priv->max_position != old_max_position)
1717 g_object_notify (G_OBJECT (paned), "max-position");
1718 g_object_thaw_notify (G_OBJECT (paned));
1720 priv->last_allocation = allocation;
1724 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1726 GtkPanedPrivate *priv = paned->priv;
1728 if (priv->saved_focus)
1729 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
1730 (gpointer *)&(priv->saved_focus));
1732 priv->saved_focus = widget;
1734 if (priv->saved_focus)
1735 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
1736 (gpointer *)&(priv->saved_focus));
1740 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1742 GtkPanedPrivate *priv = paned->priv;
1744 if (priv->first_paned)
1745 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
1746 (gpointer *)&(priv->first_paned));
1748 priv->first_paned = first_paned;
1750 if (priv->first_paned)
1751 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
1752 (gpointer *)&(priv->first_paned));
1756 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1758 GtkPanedPrivate *priv = paned->priv;
1760 if (priv->last_child1_focus)
1761 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
1762 (gpointer *)&(priv->last_child1_focus));
1764 priv->last_child1_focus = widget;
1766 if (priv->last_child1_focus)
1767 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
1768 (gpointer *)&(priv->last_child1_focus));
1772 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1774 GtkPanedPrivate *priv = paned->priv;
1776 if (priv->last_child2_focus)
1777 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
1778 (gpointer *)&(priv->last_child2_focus));
1780 priv->last_child2_focus = widget;
1782 if (priv->last_child2_focus)
1783 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
1784 (gpointer *)&(priv->last_child2_focus));
1788 paned_get_focus_widget (GtkPaned *paned)
1790 GtkWidget *toplevel;
1792 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1793 if (gtk_widget_is_toplevel (toplevel))
1794 return GTK_WINDOW (toplevel)->focus_widget;
1800 gtk_paned_set_focus_child (GtkContainer *container,
1801 GtkWidget *focus_child)
1804 GtkPanedPrivate *priv;
1805 GtkWidget *container_focus_child;
1807 g_return_if_fail (GTK_IS_PANED (container));
1809 paned = GTK_PANED (container);
1812 if (focus_child == NULL)
1814 GtkWidget *last_focus;
1817 last_focus = paned_get_focus_widget (paned);
1821 /* If there is one or more paned widgets between us and the
1822 * focus widget, we want the topmost of those as last_focus
1824 for (w = last_focus; w != GTK_WIDGET (paned); w = w->parent)
1825 if (GTK_IS_PANED (w))
1828 container_focus_child = gtk_container_get_focus_child (container);
1829 if (container_focus_child == priv->child1)
1830 gtk_paned_set_last_child1_focus (paned, last_focus);
1831 else if (container_focus_child == priv->child2)
1832 gtk_paned_set_last_child2_focus (paned, last_focus);
1836 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1837 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1841 gtk_paned_get_cycle_chain (GtkPaned *paned,
1842 GtkDirectionType direction,
1845 GtkPanedPrivate *priv = paned->priv;
1846 GtkContainer *container = GTK_CONTAINER (paned);
1847 GtkWidget *ancestor = NULL;
1848 GtkWidget *focus_child;
1849 GList *temp_list = NULL;
1852 if (priv->in_recursion)
1855 g_assert (widgets != NULL);
1857 if (priv->last_child1_focus &&
1858 !gtk_widget_is_ancestor (priv->last_child1_focus, GTK_WIDGET (paned)))
1860 gtk_paned_set_last_child1_focus (paned, NULL);
1863 if (priv->last_child2_focus &&
1864 !gtk_widget_is_ancestor (priv->last_child2_focus, GTK_WIDGET (paned)))
1866 gtk_paned_set_last_child2_focus (paned, NULL);
1869 if (GTK_WIDGET (paned)->parent)
1870 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (paned)->parent, GTK_TYPE_PANED);
1872 /* The idea here is that temp_list is a list of widgets we want to cycle
1873 * to. The list is prioritized so that the first element is our first
1874 * choice, the next our second, and so on.
1876 * We can't just use g_list_reverse(), because we want to try
1877 * priv->last_child?_focus before priv->child?, both when we
1878 * are going forward and backward.
1880 focus_child = gtk_container_get_focus_child (container);
1881 if (direction == GTK_DIR_TAB_FORWARD)
1883 if (focus_child == priv->child1)
1885 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1886 temp_list = g_list_append (temp_list, priv->child2);
1887 temp_list = g_list_append (temp_list, ancestor);
1889 else if (focus_child == priv->child2)
1891 temp_list = g_list_append (temp_list, ancestor);
1892 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1893 temp_list = g_list_append (temp_list, priv->child1);
1897 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1898 temp_list = g_list_append (temp_list, priv->child1);
1899 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1900 temp_list = g_list_append (temp_list, priv->child2);
1901 temp_list = g_list_append (temp_list, ancestor);
1906 if (focus_child == priv->child1)
1908 temp_list = g_list_append (temp_list, ancestor);
1909 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1910 temp_list = g_list_append (temp_list, priv->child2);
1912 else if (focus_child == priv->child2)
1914 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1915 temp_list = g_list_append (temp_list, priv->child1);
1916 temp_list = g_list_append (temp_list, ancestor);
1920 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1921 temp_list = g_list_append (temp_list, priv->child2);
1922 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1923 temp_list = g_list_append (temp_list, priv->child1);
1924 temp_list = g_list_append (temp_list, ancestor);
1928 /* Walk the list and expand all the paned widgets. */
1929 for (list = temp_list; list != NULL; list = list->next)
1931 GtkWidget *widget = list->data;
1935 if (GTK_IS_PANED (widget))
1937 priv->in_recursion = TRUE;
1938 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1939 priv->in_recursion = FALSE;
1943 *widgets = g_list_append (*widgets, widget);
1948 g_list_free (temp_list);
1952 gtk_paned_cycle_child_focus (GtkPaned *paned,
1955 GList *cycle_chain = NULL;
1958 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1960 /* ignore f6 if the handle is focused */
1961 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1964 /* we can't just let the event propagate up the hierarchy,
1965 * because the paned will want to cycle focus _unless_ an
1966 * ancestor paned handles the event
1968 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1970 for (list = cycle_chain; list != NULL; list = list->next)
1971 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1974 g_list_free (cycle_chain);
1980 get_child_panes (GtkWidget *widget,
1983 if (!widget || !gtk_widget_get_realized (widget))
1986 if (GTK_IS_PANED (widget))
1988 GtkPaned *paned = GTK_PANED (widget);
1989 GtkPanedPrivate *priv = paned->priv;
1991 get_child_panes (priv->child1, panes);
1992 *panes = g_list_prepend (*panes, widget);
1993 get_child_panes (priv->child2, panes);
1995 else if (GTK_IS_CONTAINER (widget))
1997 gtk_container_forall (GTK_CONTAINER (widget),
1998 (GtkCallback)get_child_panes, panes);
2003 get_all_panes (GtkPaned *paned)
2005 GtkPaned *topmost = NULL;
2006 GList *result = NULL;
2009 for (w = GTK_WIDGET (paned); w != NULL; w = w->parent)
2011 if (GTK_IS_PANED (w))
2012 topmost = GTK_PANED (w);
2017 get_child_panes (GTK_WIDGET (topmost), &result);
2019 return g_list_reverse (result);
2023 gtk_paned_find_neighbours (GtkPaned *paned,
2030 all_panes = get_all_panes (paned);
2031 g_assert (all_panes);
2033 this_link = g_list_find (all_panes, paned);
2035 g_assert (this_link);
2037 if (this_link->next)
2038 *next = this_link->next->data;
2040 *next = all_panes->data;
2042 if (this_link->prev)
2043 *prev = this_link->prev->data;
2045 *prev = g_list_last (all_panes)->data;
2047 g_list_free (all_panes);
2051 gtk_paned_move_handle (GtkPaned *paned,
2052 GtkScrollType scroll)
2054 GtkPanedPrivate *priv = paned->priv;
2056 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2063 SINGLE_STEP_SIZE = 1,
2067 new_position = old_position = gtk_paned_get_position (paned);
2072 case GTK_SCROLL_STEP_LEFT:
2073 case GTK_SCROLL_STEP_UP:
2074 case GTK_SCROLL_STEP_BACKWARD:
2075 increment = - SINGLE_STEP_SIZE;
2078 case GTK_SCROLL_STEP_RIGHT:
2079 case GTK_SCROLL_STEP_DOWN:
2080 case GTK_SCROLL_STEP_FORWARD:
2081 increment = SINGLE_STEP_SIZE;
2084 case GTK_SCROLL_PAGE_LEFT:
2085 case GTK_SCROLL_PAGE_UP:
2086 case GTK_SCROLL_PAGE_BACKWARD:
2087 increment = - PAGE_STEP_SIZE;
2090 case GTK_SCROLL_PAGE_RIGHT:
2091 case GTK_SCROLL_PAGE_DOWN:
2092 case GTK_SCROLL_PAGE_FORWARD:
2093 increment = PAGE_STEP_SIZE;
2096 case GTK_SCROLL_START:
2097 new_position = priv->min_position;
2100 case GTK_SCROLL_END:
2101 new_position = priv->max_position;
2111 increment = -increment;
2113 new_position = old_position + increment;
2116 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2118 if (old_position != new_position)
2119 gtk_paned_set_position (paned, new_position);
2128 gtk_paned_restore_focus (GtkPaned *paned)
2130 GtkPanedPrivate *priv = paned->priv;
2132 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2134 if (priv->saved_focus &&
2135 gtk_widget_get_sensitive (priv->saved_focus))
2137 gtk_widget_grab_focus (priv->saved_focus);
2141 /* the saved focus is somehow not available for focusing,
2143 * 1) tabbing into the paned widget
2144 * if that didn't work,
2145 * 2) unset focus for the window if there is one
2148 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2150 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2152 if (GTK_IS_WINDOW (toplevel))
2153 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2157 gtk_paned_set_saved_focus (paned, NULL);
2158 gtk_paned_set_first_paned (paned, NULL);
2163 gtk_paned_accept_position (GtkPaned *paned)
2165 GtkPanedPrivate *priv = paned->priv;
2167 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2169 priv->original_position = -1;
2170 gtk_paned_restore_focus (paned);
2180 gtk_paned_cancel_position (GtkPaned *paned)
2182 GtkPanedPrivate *priv = paned->priv;
2184 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2186 if (priv->original_position != -1)
2188 gtk_paned_set_position (paned, priv->original_position);
2189 priv->original_position = -1;
2192 gtk_paned_restore_focus (paned);
2200 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2203 GtkPanedPrivate *priv = paned->priv;
2204 GtkPaned *next, *prev;
2206 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2208 GtkPaned *focus = NULL;
2210 if (!priv->first_paned)
2212 /* The first_pane has disappeared. As an ad-hoc solution,
2213 * we make the currently focused paned the first_paned. To the
2214 * user this will seem like the paned cycling has been reset.
2217 gtk_paned_set_first_paned (paned, paned);
2220 gtk_paned_find_neighbours (paned, &next, &prev);
2222 if (reversed && prev &&
2223 prev != paned && paned != priv->first_paned)
2227 else if (!reversed && next &&
2228 next != paned && next != priv->first_paned)
2234 gtk_paned_accept_position (paned);
2240 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2241 gtk_paned_set_first_paned (focus, priv->first_paned);
2243 gtk_paned_set_saved_focus (paned, NULL);
2244 gtk_paned_set_first_paned (paned, NULL);
2246 gtk_widget_grab_focus (GTK_WIDGET (focus));
2248 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2250 priv->original_position = -1;
2251 focus->priv->original_position = gtk_paned_get_position (focus);
2256 GtkContainer *container = GTK_CONTAINER (paned);
2259 GtkPaned *prev, *next;
2260 GtkWidget *toplevel;
2261 GtkWidget *focus_child;
2263 gtk_paned_find_neighbours (paned, &next, &prev);
2264 focus_child = gtk_container_get_focus_child (container);
2266 if (focus_child == priv->child1)
2279 else if (focus_child == priv->child2)
2294 /* Focus is not inside this paned, and we don't have focus.
2295 * Presumably this happened because the application wants us
2296 * to start keyboard navigating.
2306 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2308 if (GTK_IS_WINDOW (toplevel))
2309 gtk_paned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
2310 gtk_paned_set_first_paned (focus, first);
2311 focus->priv->original_position = gtk_paned_get_position (focus);
2313 gtk_widget_grab_focus (GTK_WIDGET (focus));
2320 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2322 /* This function/signal has the wrong name. It is called when you
2323 * press Tab or Shift-Tab and what we do is act as if
2324 * the user pressed Return and then Tab or Shift-Tab
2326 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2327 gtk_paned_accept_position (paned);
2333 * gtk_paned_get_handle_window:
2334 * @paned: a #GtkPaned
2336 * Returns the #GdkWindow of the handle. This function is
2337 * useful when handling button or motion events because it
2338 * enables the callback to distinguish between the window
2339 * of the paned, a child and the handle.
2341 * Return value: the paned's handle window.
2346 gtk_paned_get_handle_window (GtkPaned *paned)
2348 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2350 return paned->priv->handle;