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/.
31 #include "gdk/gdkkeysyms.h"
32 #include "gtkbindings.h"
34 #include "gtkmarshalers.h"
35 #include "gtkorientable.h"
36 #include "gtksizerequest.h"
37 #include "gtkwindow.h"
39 #include "gtkprivate.h"
44 struct _GtkPanedPrivate
46 GtkOrientation orientation;
47 GtkPaned *first_paned;
50 GtkWidget *last_child1_focus;
51 GtkWidget *last_child2_focus;
52 GtkWidget *saved_focus;
54 GdkCursorType cursor_type;
55 GdkDevice *grab_device;
56 GdkRectangle handle_pos;
64 gint original_position;
66 guint handle_prelit : 1;
68 guint in_recursion : 1;
69 guint child1_resize : 1;
70 guint child1_shrink : 1;
71 guint child2_resize : 1;
72 guint child2_shrink : 1;
73 guint position_set : 1;
103 static void gtk_paned_set_property (GObject *object,
107 static void gtk_paned_get_property (GObject *object,
111 static void gtk_paned_set_child_property (GtkContainer *container,
116 static void gtk_paned_get_child_property (GtkContainer *container,
121 static void gtk_paned_finalize (GObject *object);
123 static void gtk_paned_size_request (GtkWidget *widget,
124 GtkRequisition *requisition);
125 static void gtk_paned_size_allocate (GtkWidget *widget,
126 GtkAllocation *allocation);
127 static void gtk_paned_realize (GtkWidget *widget);
128 static void gtk_paned_unrealize (GtkWidget *widget);
129 static void gtk_paned_map (GtkWidget *widget);
130 static void gtk_paned_unmap (GtkWidget *widget);
131 static void gtk_paned_state_changed (GtkWidget *widget,
132 GtkStateType previous_state);
133 static gboolean gtk_paned_expose (GtkWidget *widget,
134 GdkEventExpose *event);
135 static gboolean gtk_paned_enter (GtkWidget *widget,
136 GdkEventCrossing *event);
137 static gboolean gtk_paned_leave (GtkWidget *widget,
138 GdkEventCrossing *event);
139 static gboolean gtk_paned_button_press (GtkWidget *widget,
140 GdkEventButton *event);
141 static gboolean gtk_paned_button_release (GtkWidget *widget,
142 GdkEventButton *event);
143 static gboolean gtk_paned_motion (GtkWidget *widget,
144 GdkEventMotion *event);
145 static gboolean gtk_paned_focus (GtkWidget *widget,
146 GtkDirectionType direction);
147 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
148 GdkEventGrabBroken *event);
149 static void gtk_paned_add (GtkContainer *container,
151 static void gtk_paned_remove (GtkContainer *container,
153 static void gtk_paned_forall (GtkContainer *container,
154 gboolean include_internals,
155 GtkCallback callback,
156 gpointer callback_data);
157 static void gtk_paned_calc_position (GtkPaned *paned,
161 static void gtk_paned_set_focus_child (GtkContainer *container,
163 static void gtk_paned_set_saved_focus (GtkPaned *paned,
165 static void gtk_paned_set_first_paned (GtkPaned *paned,
166 GtkPaned *first_paned);
167 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
169 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
171 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
173 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
175 static gboolean gtk_paned_move_handle (GtkPaned *paned,
176 GtkScrollType scroll);
177 static gboolean gtk_paned_accept_position (GtkPaned *paned);
178 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
179 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
181 static GType gtk_paned_child_type (GtkContainer *container);
182 static void gtk_paned_grab_notify (GtkWidget *widget,
183 gboolean was_grabbed);
186 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
187 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
190 static guint signals[LAST_SIGNAL] = { 0 };
194 add_tab_bindings (GtkBindingSet *binding_set,
195 GdkModifierType modifiers)
197 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
198 "toggle-handle-focus", 0);
199 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
200 "toggle-handle-focus", 0);
204 add_move_binding (GtkBindingSet *binding_set,
206 GdkModifierType mask,
207 GtkScrollType scroll)
209 gtk_binding_entry_add_signal (binding_set, keyval, mask,
211 GTK_TYPE_SCROLL_TYPE, scroll);
215 gtk_paned_class_init (GtkPanedClass *class)
217 GObjectClass *object_class;
218 GtkWidgetClass *widget_class;
219 GtkContainerClass *container_class;
220 GtkPanedClass *paned_class;
221 GtkBindingSet *binding_set;
223 object_class = (GObjectClass *) class;
224 widget_class = (GtkWidgetClass *) class;
225 container_class = (GtkContainerClass *) class;
226 paned_class = (GtkPanedClass *) class;
228 object_class->set_property = gtk_paned_set_property;
229 object_class->get_property = gtk_paned_get_property;
230 object_class->finalize = gtk_paned_finalize;
232 widget_class->size_request = gtk_paned_size_request;
233 widget_class->size_allocate = gtk_paned_size_allocate;
234 widget_class->realize = gtk_paned_realize;
235 widget_class->unrealize = gtk_paned_unrealize;
236 widget_class->map = gtk_paned_map;
237 widget_class->unmap = gtk_paned_unmap;
238 widget_class->expose_event = gtk_paned_expose;
239 widget_class->focus = gtk_paned_focus;
240 widget_class->enter_notify_event = gtk_paned_enter;
241 widget_class->leave_notify_event = gtk_paned_leave;
242 widget_class->button_press_event = gtk_paned_button_press;
243 widget_class->button_release_event = gtk_paned_button_release;
244 widget_class->motion_notify_event = gtk_paned_motion;
245 widget_class->grab_broken_event = gtk_paned_grab_broken;
246 widget_class->grab_notify = gtk_paned_grab_notify;
247 widget_class->state_changed = gtk_paned_state_changed;
249 container_class->add = gtk_paned_add;
250 container_class->remove = gtk_paned_remove;
251 container_class->forall = gtk_paned_forall;
252 container_class->child_type = gtk_paned_child_type;
253 container_class->set_focus_child = gtk_paned_set_focus_child;
254 container_class->set_child_property = gtk_paned_set_child_property;
255 container_class->get_child_property = gtk_paned_get_child_property;
257 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
258 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
259 paned_class->move_handle = gtk_paned_move_handle;
260 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
261 paned_class->accept_position = gtk_paned_accept_position;
262 paned_class->cancel_position = gtk_paned_cancel_position;
264 g_object_class_override_property (object_class,
268 g_object_class_install_property (object_class,
270 g_param_spec_int ("position",
272 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
276 GTK_PARAM_READWRITE));
278 g_object_class_install_property (object_class,
280 g_param_spec_boolean ("position-set",
282 P_("TRUE if the Position property should be used"),
284 GTK_PARAM_READWRITE));
286 gtk_widget_class_install_style_property (widget_class,
287 g_param_spec_int ("handle-size",
289 P_("Width of handle"),
293 GTK_PARAM_READABLE));
295 * GtkPaned:min-position:
297 * The smallest possible value for the position property. This property is derived from the
298 * size and shrinkability of the widget's children.
302 g_object_class_install_property (object_class,
304 g_param_spec_int ("min-position",
305 P_("Minimal Position"),
306 P_("Smallest possible value for the \"position\" property"),
310 GTK_PARAM_READABLE));
313 * GtkPaned:max-position:
315 * The largest possible value for the position property. This property is derived from the
316 * size and shrinkability of the widget's children.
320 g_object_class_install_property (object_class,
322 g_param_spec_int ("max-position",
323 P_("Maximal Position"),
324 P_("Largest possible value for the \"position\" property"),
328 GTK_PARAM_READABLE));
333 * The "resize" child property determines whether the child expands and
334 * shrinks along with the paned widget.
338 gtk_container_class_install_child_property (container_class,
340 g_param_spec_boolean ("resize",
342 P_("If TRUE, the child expands and shrinks along with the paned widget"),
344 GTK_PARAM_READWRITE));
349 * The "shrink" child property determines whether the child can be made
350 * smaller than its requisition.
354 gtk_container_class_install_child_property (container_class,
356 g_param_spec_boolean ("shrink",
358 P_("If TRUE, the child can be made smaller than its requisition"),
360 GTK_PARAM_READWRITE));
363 * GtkPaned::cycle-child-focus:
364 * @widget: the object that received the signal
365 * @reversed: whether cycling backward or forward
367 * The ::cycle-child-focus signal is a
368 * <link linkend="keybinding-signals">keybinding signal</link>
369 * which gets emitted to cycle the focus between the children of the paned.
371 * The default binding is f6.
375 signals [CYCLE_CHILD_FOCUS] =
376 g_signal_new (I_("cycle-child-focus"),
377 G_TYPE_FROM_CLASS (object_class),
378 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
379 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
381 _gtk_marshal_BOOLEAN__BOOLEAN,
386 * GtkPaned::toggle-handle-focus:
387 * @widget: the object that received the signal
389 * The ::toggle-handle-focus is a
390 * <link linkend="keybinding-signals">keybinding signal</link>
391 * which gets emitted to accept the current position of the handle and then
392 * move focus to the next widget in the focus chain.
394 * The default binding is Tab.
398 signals [TOGGLE_HANDLE_FOCUS] =
399 g_signal_new (I_("toggle-handle-focus"),
400 G_TYPE_FROM_CLASS (object_class),
401 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
402 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
404 _gtk_marshal_BOOLEAN__VOID,
408 * GtkPaned::move-handle:
409 * @widget: the object that received the signal
410 * @scroll_type: a #GtkScrollType
412 * The ::move-handle signal is a
413 * <link linkend="keybinding-signals">keybinding signal</link>
414 * which gets emitted to move the handle when the user is using key bindings
419 signals[MOVE_HANDLE] =
420 g_signal_new (I_("move-handle"),
421 G_TYPE_FROM_CLASS (object_class),
422 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
423 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
425 _gtk_marshal_BOOLEAN__ENUM,
427 GTK_TYPE_SCROLL_TYPE);
430 * GtkPaned::cycle-handle-focus:
431 * @widget: the object that received the signal
432 * @reversed: whether cycling backward or forward
434 * The ::cycle-handle-focus signal is a
435 * <link linkend="keybinding-signals">keybinding signal</link>
436 * which gets emitted to cycle whether the paned should grab focus to allow
437 * the user to change position of the handle by using key bindings.
439 * The default binding for this signal is f8.
443 signals [CYCLE_HANDLE_FOCUS] =
444 g_signal_new (I_("cycle-handle-focus"),
445 G_TYPE_FROM_CLASS (object_class),
446 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
447 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
449 _gtk_marshal_BOOLEAN__BOOLEAN,
454 * GtkPaned::accept-position:
455 * @widget: the object that received the signal
457 * The ::accept-position signal is a
458 * <link linkend="keybinding-signals">keybinding signal</link>
459 * which gets emitted to accept the current position of the handle when
460 * moving it using key bindings.
462 * The default binding for this signal is Return or Space.
466 signals [ACCEPT_POSITION] =
467 g_signal_new (I_("accept-position"),
468 G_TYPE_FROM_CLASS (object_class),
469 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
470 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
472 _gtk_marshal_BOOLEAN__VOID,
476 * GtkPaned::cancel-position:
477 * @widget: the object that received the signal
479 * The ::cancel-position signal is a
480 * <link linkend="keybinding-signals">keybinding signal</link>
481 * which gets emitted to cancel moving the position of the handle using key
482 * bindings. The position of the handle will be reset to the value prior to
485 * The default binding for this signal is Escape.
489 signals [CANCEL_POSITION] =
490 g_signal_new (I_("cancel-position"),
491 G_TYPE_FROM_CLASS (object_class),
492 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
493 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
495 _gtk_marshal_BOOLEAN__VOID,
498 binding_set = gtk_binding_set_by_class (class);
501 gtk_binding_entry_add_signal (binding_set,
503 "cycle-child-focus", 1,
504 G_TYPE_BOOLEAN, FALSE);
505 gtk_binding_entry_add_signal (binding_set,
506 GDK_KEY_F6, GDK_SHIFT_MASK,
507 "cycle-child-focus", 1,
508 G_TYPE_BOOLEAN, TRUE);
511 gtk_binding_entry_add_signal (binding_set,
513 "cycle-handle-focus", 1,
514 G_TYPE_BOOLEAN, FALSE);
516 gtk_binding_entry_add_signal (binding_set,
517 GDK_KEY_F8, GDK_SHIFT_MASK,
518 "cycle-handle-focus", 1,
519 G_TYPE_BOOLEAN, TRUE);
521 add_tab_bindings (binding_set, 0);
522 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
523 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
524 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
526 /* accept and cancel positions */
527 gtk_binding_entry_add_signal (binding_set,
529 "cancel-position", 0);
531 gtk_binding_entry_add_signal (binding_set,
533 "accept-position", 0);
534 gtk_binding_entry_add_signal (binding_set,
535 GDK_KEY_ISO_Enter, 0,
536 "accept-position", 0);
537 gtk_binding_entry_add_signal (binding_set,
539 "accept-position", 0);
540 gtk_binding_entry_add_signal (binding_set,
542 "accept-position", 0);
543 gtk_binding_entry_add_signal (binding_set,
545 "accept-position", 0);
548 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
549 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
550 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
551 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
553 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
554 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
555 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
556 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
558 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
559 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
560 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
561 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
562 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
563 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
565 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
566 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
567 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
568 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
569 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
570 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
572 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
573 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
574 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
575 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
577 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
581 gtk_paned_child_type (GtkContainer *container)
583 GtkPaned *paned = GTK_PANED (container);
584 GtkPanedPrivate *priv = paned->priv;
586 if (!priv->child1 || !priv->child2)
587 return GTK_TYPE_WIDGET;
593 gtk_paned_init (GtkPaned *paned)
595 GtkPanedPrivate *priv;
597 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
598 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
600 /* We only need to redraw when the handle position moves, which is
601 * independent of the overall allocation of the GtkPaned
603 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
605 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
608 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
609 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
614 priv->cursor_type = GDK_CROSS;
616 priv->handle_pos.width = 5;
617 priv->handle_pos.height = 5;
618 priv->position_set = FALSE;
619 priv->last_allocation = -1;
620 priv->in_drag = FALSE;
622 priv->last_child1_focus = NULL;
623 priv->last_child2_focus = NULL;
624 priv->in_recursion = FALSE;
625 priv->handle_prelit = FALSE;
626 priv->original_position = -1;
628 priv->handle_pos.x = -1;
629 priv->handle_pos.y = -1;
635 gtk_paned_set_property (GObject *object,
640 GtkPaned *paned = GTK_PANED (object);
641 GtkPanedPrivate *priv = paned->priv;
645 case PROP_ORIENTATION:
646 priv->orientation = g_value_get_enum (value);
648 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
649 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
651 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
653 /* state_changed updates the cursor */
654 gtk_paned_state_changed (GTK_WIDGET (paned), gtk_widget_get_state (GTK_WIDGET (paned)));
655 gtk_widget_queue_resize (GTK_WIDGET (paned));
658 gtk_paned_set_position (paned, g_value_get_int (value));
660 case PROP_POSITION_SET:
661 priv->position_set = g_value_get_boolean (value);
662 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
665 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
671 gtk_paned_get_property (GObject *object,
676 GtkPaned *paned = GTK_PANED (object);
677 GtkPanedPrivate *priv = paned->priv;
681 case PROP_ORIENTATION:
682 g_value_set_enum (value, priv->orientation);
685 g_value_set_int (value, priv->child1_size);
687 case PROP_POSITION_SET:
688 g_value_set_boolean (value, priv->position_set);
690 case PROP_MIN_POSITION:
691 g_value_set_int (value, priv->min_position);
693 case PROP_MAX_POSITION:
694 g_value_set_int (value, priv->max_position);
697 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
703 gtk_paned_set_child_property (GtkContainer *container,
709 GtkPaned *paned = GTK_PANED (container);
710 GtkPanedPrivate *priv = paned->priv;
711 gboolean old_value, new_value;
713 g_assert (child == priv->child1 || child == priv->child2);
715 new_value = g_value_get_boolean (value);
718 case CHILD_PROP_RESIZE:
719 if (child == priv->child1)
721 old_value = priv->child1_resize;
722 priv->child1_resize = new_value;
726 old_value = priv->child2_resize;
727 priv->child2_resize = new_value;
730 case CHILD_PROP_SHRINK:
731 if (child == priv->child1)
733 old_value = priv->child1_shrink;
734 priv->child1_shrink = new_value;
738 old_value = priv->child2_shrink;
739 priv->child2_shrink = new_value;
743 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
744 old_value = -1; /* quiet gcc */
747 if (old_value != new_value)
748 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
752 gtk_paned_get_child_property (GtkContainer *container,
758 GtkPaned *paned = GTK_PANED (container);
759 GtkPanedPrivate *priv = paned->priv;
761 g_assert (child == priv->child1 || child == priv->child2);
765 case CHILD_PROP_RESIZE:
766 if (child == priv->child1)
767 g_value_set_boolean (value, priv->child1_resize);
769 g_value_set_boolean (value, priv->child2_resize);
771 case CHILD_PROP_SHRINK:
772 if (child == priv->child1)
773 g_value_set_boolean (value, priv->child1_shrink);
775 g_value_set_boolean (value, priv->child2_shrink);
778 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
784 gtk_paned_finalize (GObject *object)
786 GtkPaned *paned = GTK_PANED (object);
788 gtk_paned_set_saved_focus (paned, NULL);
789 gtk_paned_set_first_paned (paned, NULL);
791 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
795 gtk_paned_size_request (GtkWidget *widget,
796 GtkRequisition *requisition)
798 GtkPaned *paned = GTK_PANED (widget);
799 GtkPanedPrivate *priv = paned->priv;
800 GtkRequisition child_requisition;
803 requisition->width = 0;
804 requisition->height = 0;
806 if (priv->child1 && gtk_widget_get_visible (priv->child1))
808 gtk_widget_size_request (priv->child1, &child_requisition);
810 requisition->height = child_requisition.height;
811 requisition->width = child_requisition.width;
814 if (priv->child2 && gtk_widget_get_visible (priv->child2))
816 gtk_widget_size_request (priv->child2, &child_requisition);
818 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
820 requisition->height = MAX (requisition->height,
821 child_requisition.height);
822 requisition->width += child_requisition.width;
826 requisition->width = MAX (requisition->width,
827 child_requisition.width);
828 requisition->height += child_requisition.height;
832 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
833 requisition->width += border_width * 2;
834 requisition->height += border_width * 2;
836 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
837 priv->child2 && gtk_widget_get_visible (priv->child2))
841 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
843 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
844 requisition->width += handle_size;
846 requisition->height += handle_size;
851 flip_child (GtkWidget *widget,
852 GtkAllocation *child_pos)
854 GtkAllocation allocation;
857 gtk_widget_get_allocation (widget, &allocation);
859 width = allocation.width;
861 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
865 gtk_paned_size_allocate (GtkWidget *widget,
866 GtkAllocation *allocation)
868 GtkPaned *paned = GTK_PANED (widget);
869 GtkPanedPrivate *priv = paned->priv;
870 GtkAllocation widget_allocation;
873 border_width = gtk_container_get_border_width (GTK_CONTAINER (paned));
875 gtk_widget_set_allocation (widget, allocation);
877 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
878 priv->child2 && gtk_widget_get_visible (priv->child2))
880 GtkRequisition child1_requisition;
881 GtkRequisition child2_requisition;
882 GtkAllocation child1_allocation;
883 GtkAllocation child2_allocation;
884 GtkAllocation priv_child1_allocation;
885 GdkRectangle old_handle_pos;
888 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
890 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->child1),
891 &child1_requisition, NULL);
892 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->child2),
893 &child2_requisition, NULL);
895 old_handle_pos = priv->handle_pos;
897 gtk_widget_get_allocation (widget, &widget_allocation);
899 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
901 gtk_paned_calc_position (paned,
902 MAX (1, widget_allocation.width
905 child1_requisition.width,
906 child2_requisition.width);
908 priv->handle_pos.x = widget_allocation.x + priv->child1_size + border_width;
909 priv->handle_pos.y = widget_allocation.y + border_width;
910 priv->handle_pos.width = handle_size;
911 priv->handle_pos.height = MAX (1, widget_allocation.height - 2 * border_width);
913 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
914 child1_allocation.width = MAX (1, priv->child1_size);
915 child1_allocation.x = widget_allocation.x + border_width;
916 child1_allocation.y = child2_allocation.y = widget_allocation.y + border_width;
918 child2_allocation.x = child1_allocation.x + priv->child1_size + priv->handle_pos.width;
919 child2_allocation.width = MAX (1, widget_allocation.x + widget_allocation.width - child2_allocation.x - border_width);
921 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
923 flip_child (widget, &(child2_allocation));
924 flip_child (widget, &(child1_allocation));
925 flip_child (widget, &(priv->handle_pos));
930 gtk_paned_calc_position (paned,
931 MAX (1, widget_allocation.height
934 child1_requisition.height,
935 child2_requisition.height);
937 priv->handle_pos.x = widget_allocation.x + border_width;
938 priv->handle_pos.y = widget_allocation.y + priv->child1_size + border_width;
939 priv->handle_pos.width = MAX (1, (gint) widget_allocation.width - 2 * border_width);
940 priv->handle_pos.height = handle_size;
942 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
943 child1_allocation.height = MAX (1, priv->child1_size);
944 child1_allocation.x = child2_allocation.x = widget_allocation.x + border_width;
945 child1_allocation.y = widget_allocation.y + border_width;
947 child2_allocation.y = child1_allocation.y + priv->child1_size + priv->handle_pos.height;
948 child2_allocation.height = MAX (1, widget_allocation.y + widget_allocation.height - child2_allocation.y - border_width);
951 if (gtk_widget_get_mapped (widget) &&
952 (old_handle_pos.x != priv->handle_pos.x ||
953 old_handle_pos.y != priv->handle_pos.y ||
954 old_handle_pos.width != priv->handle_pos.width ||
955 old_handle_pos.height != priv->handle_pos.height))
959 window = gtk_widget_get_window (widget);
960 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
961 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
964 if (gtk_widget_get_realized (widget))
966 if (gtk_widget_get_mapped (widget))
967 gdk_window_show (priv->handle);
969 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
971 gdk_window_move_resize (priv->handle,
975 priv->handle_pos.height);
979 gdk_window_move_resize (priv->handle,
982 priv->handle_pos.width,
987 /* Now allocate the childen, making sure, when resizing not to
988 * overlap the windows
990 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
991 if (gtk_widget_get_mapped (widget) &&
992 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
993 priv_child1_allocation.width < child1_allocation.width) ||
995 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
996 priv_child1_allocation.height < child1_allocation.height)))
998 gtk_widget_size_allocate (priv->child2, &child2_allocation);
999 gtk_widget_size_allocate (priv->child1, &child1_allocation);
1003 gtk_widget_size_allocate (priv->child1, &child1_allocation);
1004 gtk_widget_size_allocate (priv->child2, &child2_allocation);
1009 GtkAllocation child_allocation;
1011 if (gtk_widget_get_realized (widget))
1012 gdk_window_hide (priv->handle);
1015 gtk_widget_set_child_visible (priv->child1, TRUE);
1017 gtk_widget_set_child_visible (priv->child2, TRUE);
1019 gtk_widget_get_allocation (widget, &widget_allocation);
1021 child_allocation.x = widget_allocation.x + border_width;
1022 child_allocation.y = widget_allocation.y + border_width;
1023 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
1024 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
1026 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1027 gtk_widget_size_allocate (priv->child1, &child_allocation);
1028 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1029 gtk_widget_size_allocate (priv->child2, &child_allocation);
1034 gtk_paned_realize (GtkWidget *widget)
1036 GtkPaned *paned = GTK_PANED (widget);
1037 GtkPanedPrivate *priv = paned->priv;
1039 GdkWindowAttr attributes;
1040 gint attributes_mask;
1042 gtk_widget_set_realized (widget, TRUE);
1044 window = gtk_widget_get_parent_window (widget);
1045 gtk_widget_set_window (widget, window);
1046 g_object_ref (window);
1048 attributes.window_type = GDK_WINDOW_CHILD;
1049 attributes.wclass = GDK_INPUT_ONLY;
1050 attributes.x = priv->handle_pos.x;
1051 attributes.y = priv->handle_pos.y;
1052 attributes.width = priv->handle_pos.width;
1053 attributes.height = priv->handle_pos.height;
1054 attributes.event_mask = gtk_widget_get_events (widget);
1055 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1056 GDK_BUTTON_RELEASE_MASK |
1057 GDK_ENTER_NOTIFY_MASK |
1058 GDK_LEAVE_NOTIFY_MASK |
1059 GDK_POINTER_MOTION_MASK |
1060 GDK_POINTER_MOTION_HINT_MASK);
1061 attributes_mask = GDK_WA_X | GDK_WA_Y;
1062 if (gtk_widget_is_sensitive (widget))
1064 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1066 attributes_mask |= GDK_WA_CURSOR;
1069 priv->handle = gdk_window_new (window,
1070 &attributes, attributes_mask);
1071 gdk_window_set_user_data (priv->handle, paned);
1072 if (attributes_mask & GDK_WA_CURSOR)
1073 gdk_cursor_unref (attributes.cursor);
1075 gtk_widget_style_attach (widget);
1077 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1078 priv->child2 && gtk_widget_get_visible (priv->child2))
1079 gdk_window_show (priv->handle);
1083 gtk_paned_unrealize (GtkWidget *widget)
1085 GtkPaned *paned = GTK_PANED (widget);
1086 GtkPanedPrivate *priv = paned->priv;
1090 gdk_window_set_user_data (priv->handle, NULL);
1091 gdk_window_destroy (priv->handle);
1092 priv->handle = NULL;
1095 gtk_paned_set_last_child1_focus (paned, NULL);
1096 gtk_paned_set_last_child2_focus (paned, NULL);
1097 gtk_paned_set_saved_focus (paned, NULL);
1098 gtk_paned_set_first_paned (paned, NULL);
1100 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1104 gtk_paned_map (GtkWidget *widget)
1106 GtkPaned *paned = GTK_PANED (widget);
1107 GtkPanedPrivate *priv = paned->priv;
1109 gdk_window_show (priv->handle);
1111 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1115 gtk_paned_unmap (GtkWidget *widget)
1117 GtkPaned *paned = GTK_PANED (widget);
1118 GtkPanedPrivate *priv = paned->priv;
1120 gdk_window_hide (priv->handle);
1122 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1126 gtk_paned_expose (GtkWidget *widget,
1127 GdkEventExpose *event)
1129 GtkPaned *paned = GTK_PANED (widget);
1130 GtkPanedPrivate *priv = paned->priv;
1132 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1133 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1134 priv->child2 && gtk_widget_get_visible (priv->child2))
1138 if (gtk_widget_is_focus (widget))
1139 state = GTK_STATE_SELECTED;
1140 else if (priv->handle_prelit)
1141 state = GTK_STATE_PRELIGHT;
1143 state = gtk_widget_get_state (widget);
1145 gtk_paint_handle (gtk_widget_get_style (widget),
1146 gtk_widget_get_window (widget),
1147 state, GTK_SHADOW_NONE,
1148 &priv->handle_pos, widget, "paned",
1149 priv->handle_pos.x, priv->handle_pos.y,
1150 priv->handle_pos.width, priv->handle_pos.height,
1151 !priv->orientation);
1154 /* Chain up to draw children */
1155 GTK_WIDGET_CLASS (gtk_paned_parent_class)->expose_event (widget, event);
1161 is_rtl (GtkPaned *paned)
1163 GtkPanedPrivate *priv = paned->priv;
1165 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1166 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1175 update_drag (GtkPaned *paned)
1177 GtkPanedPrivate *priv = paned->priv;
1178 GtkAllocation allocation;
1179 GtkWidget *widget = GTK_WIDGET (paned);
1184 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1185 gtk_widget_get_pointer (widget, &pos, NULL);
1187 gtk_widget_get_pointer (widget, NULL, &pos);
1189 pos -= priv->drag_pos;
1193 gtk_widget_style_get (widget,
1194 "handle-size", &handle_size,
1197 gtk_widget_get_allocation (widget, &allocation);
1198 size = allocation.width - pos - handle_size;
1205 size -= gtk_container_get_border_width (GTK_CONTAINER (paned));
1207 size = CLAMP (size, priv->min_position, priv->max_position);
1209 if (size != priv->child1_size)
1210 gtk_paned_set_position (paned, size);
1214 gtk_paned_enter (GtkWidget *widget,
1215 GdkEventCrossing *event)
1217 GtkPaned *paned = GTK_PANED (widget);
1218 GtkPanedPrivate *priv = paned->priv;
1221 update_drag (paned);
1224 priv->handle_prelit = TRUE;
1225 gtk_widget_queue_draw_area (widget,
1228 priv->handle_pos.width,
1229 priv->handle_pos.height);
1236 gtk_paned_leave (GtkWidget *widget,
1237 GdkEventCrossing *event)
1239 GtkPaned *paned = GTK_PANED (widget);
1240 GtkPanedPrivate *priv = paned->priv;
1243 update_drag (paned);
1246 priv->handle_prelit = FALSE;
1247 gtk_widget_queue_draw_area (widget,
1250 priv->handle_pos.width,
1251 priv->handle_pos.height);
1258 gtk_paned_focus (GtkWidget *widget,
1259 GtkDirectionType direction)
1264 /* This is a hack, but how can this be done without
1265 * excessive cut-and-paste from gtkcontainer.c?
1268 gtk_widget_set_can_focus (widget, FALSE);
1269 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1270 gtk_widget_set_can_focus (widget, TRUE);
1276 gtk_paned_button_press (GtkWidget *widget,
1277 GdkEventButton *event)
1279 GtkPaned *paned = GTK_PANED (widget);
1280 GtkPanedPrivate *priv = paned->priv;
1282 if (!priv->in_drag &&
1283 (event->window == priv->handle) && (event->button == 1))
1285 /* We need a server grab here, not gtk_grab_add(), since
1286 * we don't want to pass events on to the widget's children */
1287 if (gdk_device_grab (event->device,
1289 GDK_OWNERSHIP_WINDOW, FALSE,
1290 GDK_POINTER_MOTION_HINT_MASK
1291 | GDK_BUTTON1_MOTION_MASK
1292 | GDK_BUTTON_RELEASE_MASK
1293 | GDK_ENTER_NOTIFY_MASK
1294 | GDK_LEAVE_NOTIFY_MASK,
1295 NULL, event->time) != GDK_GRAB_SUCCESS)
1298 priv->in_drag = TRUE;
1299 priv->grab_time = event->time;
1300 priv->grab_device = event->device;
1302 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1303 priv->drag_pos = event->x;
1305 priv->drag_pos = event->y;
1314 gtk_paned_grab_broken (GtkWidget *widget,
1315 GdkEventGrabBroken *event)
1317 GtkPaned *paned = GTK_PANED (widget);
1318 GtkPanedPrivate *priv = paned->priv;
1320 priv->in_drag = FALSE;
1321 priv->drag_pos = -1;
1322 priv->position_set = TRUE;
1328 stop_drag (GtkPaned *paned)
1330 GtkPanedPrivate *priv = paned->priv;
1332 priv->in_drag = FALSE;
1333 priv->drag_pos = -1;
1334 priv->position_set = TRUE;
1336 gdk_device_ungrab (priv->grab_device,
1338 priv->grab_device = NULL;
1342 gtk_paned_grab_notify (GtkWidget *widget,
1343 gboolean was_grabbed)
1345 GtkPaned *paned = GTK_PANED (widget);
1346 GtkPanedPrivate *priv = paned->priv;
1347 GdkDevice *grab_device;
1349 grab_device = priv->grab_device;
1351 if (priv->in_drag && grab_device &&
1352 gtk_widget_device_is_shadowed (widget, grab_device))
1357 gtk_paned_state_changed (GtkWidget *widget,
1358 GtkStateType previous_state)
1360 GtkPaned *paned = GTK_PANED (widget);
1361 GtkPanedPrivate *priv = paned->priv;
1364 if (gtk_widget_get_realized (widget))
1366 if (gtk_widget_is_sensitive (widget))
1367 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1372 gdk_window_set_cursor (priv->handle, cursor);
1375 gdk_cursor_unref (cursor);
1380 gtk_paned_button_release (GtkWidget *widget,
1381 GdkEventButton *event)
1383 GtkPaned *paned = GTK_PANED (widget);
1384 GtkPanedPrivate *priv = paned->priv;
1386 if (priv->in_drag && (event->button == 1))
1397 gtk_paned_motion (GtkWidget *widget,
1398 GdkEventMotion *event)
1400 GtkPaned *paned = GTK_PANED (widget);
1401 GtkPanedPrivate *priv = paned->priv;
1405 update_drag (paned);
1414 * @orientation: the paned's orientation.
1416 * Creates a new #GtkPaned widget.
1418 * Return value: a new #GtkPaned.
1423 gtk_paned_new (GtkOrientation orientation)
1425 return g_object_new (GTK_TYPE_PANED,
1426 "orientation", orientation,
1431 gtk_paned_add1 (GtkPaned *paned,
1434 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1438 gtk_paned_add2 (GtkPaned *paned,
1441 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1445 gtk_paned_pack1 (GtkPaned *paned,
1450 GtkPanedPrivate *priv;
1452 g_return_if_fail (GTK_IS_PANED (paned));
1453 g_return_if_fail (GTK_IS_WIDGET (child));
1459 priv->child1 = child;
1460 priv->child1_resize = resize;
1461 priv->child1_shrink = shrink;
1463 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1468 gtk_paned_pack2 (GtkPaned *paned,
1473 GtkPanedPrivate *priv;
1475 g_return_if_fail (GTK_IS_PANED (paned));
1476 g_return_if_fail (GTK_IS_WIDGET (child));
1482 priv->child2 = child;
1483 priv->child2_resize = resize;
1484 priv->child2_shrink = shrink;
1486 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1492 gtk_paned_add (GtkContainer *container,
1495 GtkPanedPrivate *priv;
1498 g_return_if_fail (GTK_IS_PANED (container));
1500 paned = GTK_PANED (container);
1504 gtk_paned_add1 (paned, widget);
1505 else if (!priv->child2)
1506 gtk_paned_add2 (paned, widget);
1508 g_warning ("GtkPaned cannot have more than 2 children\n");
1512 gtk_paned_remove (GtkContainer *container,
1515 GtkPaned *paned = GTK_PANED (container);
1516 GtkPanedPrivate *priv = paned->priv;
1517 gboolean was_visible;
1519 was_visible = gtk_widget_get_visible (widget);
1521 if (priv->child1 == widget)
1523 gtk_widget_unparent (widget);
1525 priv->child1 = NULL;
1527 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1528 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1530 else if (priv->child2 == widget)
1532 gtk_widget_unparent (widget);
1534 priv->child2 = NULL;
1536 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1537 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1542 gtk_paned_forall (GtkContainer *container,
1543 gboolean include_internals,
1544 GtkCallback callback,
1545 gpointer callback_data)
1547 GtkPanedPrivate *priv;
1550 g_return_if_fail (callback != NULL);
1552 paned = GTK_PANED (container);
1556 (*callback) (priv->child1, callback_data);
1558 (*callback) (priv->child2, callback_data);
1562 * gtk_paned_get_position:
1563 * @paned: a #GtkPaned widget
1565 * Obtains the position of the divider between the two panes.
1567 * Return value: position of the divider
1570 gtk_paned_get_position (GtkPaned *paned)
1572 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1574 return paned->priv->child1_size;
1578 * gtk_paned_set_position:
1579 * @paned: a #GtkPaned widget
1580 * @position: pixel position of divider, a negative value means that the position
1583 * Sets the position of the divider between the two panes.
1586 gtk_paned_set_position (GtkPaned *paned,
1589 GtkPanedPrivate *priv;
1592 g_return_if_fail (GTK_IS_PANED (paned));
1596 if (priv->child1_size == position)
1599 object = G_OBJECT (paned);
1603 /* We don't clamp here - the assumption is that
1604 * if the total allocation changes at the same time
1605 * as the position, the position set is with reference
1606 * to the new total size. If only the position changes,
1607 * then clamping will occur in gtk_paned_calc_position()
1610 priv->child1_size = position;
1611 priv->position_set = TRUE;
1615 priv->position_set = FALSE;
1618 g_object_freeze_notify (object);
1619 g_object_notify (object, "position");
1620 g_object_notify (object, "position-set");
1621 g_object_thaw_notify (object);
1623 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1626 /* Hacky work-around for bug #144269 */
1627 if (priv->child2 != NULL)
1629 gtk_widget_queue_draw (priv->child2);
1635 * gtk_paned_get_child1:
1636 * @paned: a #GtkPaned widget
1638 * Obtains the first child of the paned widget.
1640 * Return value: first child, or %NULL if it is not set.
1645 gtk_paned_get_child1 (GtkPaned *paned)
1647 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1649 return paned->priv->child1;
1653 * gtk_paned_get_child2:
1654 * @paned: a #GtkPaned widget
1656 * Obtains the second child of the paned widget.
1658 * Return value: second child, or %NULL if it is not set.
1663 gtk_paned_get_child2 (GtkPaned *paned)
1665 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1667 return paned->priv->child2;
1671 gtk_paned_calc_position (GtkPaned *paned,
1676 GtkPanedPrivate *priv = paned->priv;
1678 gint old_min_position;
1679 gint old_max_position;
1681 old_position = priv->child1_size;
1682 old_min_position = priv->min_position;
1683 old_max_position = priv->max_position;
1685 priv->min_position = priv->child1_shrink ? 0 : child1_req;
1687 priv->max_position = allocation;
1688 if (!priv->child2_shrink)
1689 priv->max_position = MAX (1, priv->max_position - child2_req);
1690 priv->max_position = MAX (priv->min_position, priv->max_position);
1692 if (!priv->position_set)
1694 if (priv->child1_resize && !priv->child2_resize)
1695 priv->child1_size = MAX (0, allocation - child2_req);
1696 else if (!priv->child1_resize && priv->child2_resize)
1697 priv->child1_size = child1_req;
1698 else if (child1_req + child2_req != 0)
1699 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1701 priv->child1_size = allocation * 0.5 + 0.5;
1705 /* If the position was set before the initial allocation.
1706 * (priv->last_allocation <= 0) just clamp it and leave it.
1708 if (priv->last_allocation > 0)
1710 if (priv->child1_resize && !priv->child2_resize)
1711 priv->child1_size += allocation - priv->last_allocation;
1712 else if (!(!priv->child1_resize && priv->child2_resize))
1713 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
1717 priv->child1_size = CLAMP (priv->child1_size,
1719 priv->max_position);
1722 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
1725 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
1727 g_object_freeze_notify (G_OBJECT (paned));
1728 if (priv->child1_size != old_position)
1729 g_object_notify (G_OBJECT (paned), "position");
1730 if (priv->min_position != old_min_position)
1731 g_object_notify (G_OBJECT (paned), "min-position");
1732 if (priv->max_position != old_max_position)
1733 g_object_notify (G_OBJECT (paned), "max-position");
1734 g_object_thaw_notify (G_OBJECT (paned));
1736 priv->last_allocation = allocation;
1740 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1742 GtkPanedPrivate *priv = paned->priv;
1744 if (priv->saved_focus)
1745 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
1746 (gpointer *)&(priv->saved_focus));
1748 priv->saved_focus = widget;
1750 if (priv->saved_focus)
1751 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
1752 (gpointer *)&(priv->saved_focus));
1756 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1758 GtkPanedPrivate *priv = paned->priv;
1760 if (priv->first_paned)
1761 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
1762 (gpointer *)&(priv->first_paned));
1764 priv->first_paned = first_paned;
1766 if (priv->first_paned)
1767 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
1768 (gpointer *)&(priv->first_paned));
1772 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1774 GtkPanedPrivate *priv = paned->priv;
1776 if (priv->last_child1_focus)
1777 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
1778 (gpointer *)&(priv->last_child1_focus));
1780 priv->last_child1_focus = widget;
1782 if (priv->last_child1_focus)
1783 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
1784 (gpointer *)&(priv->last_child1_focus));
1788 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1790 GtkPanedPrivate *priv = paned->priv;
1792 if (priv->last_child2_focus)
1793 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
1794 (gpointer *)&(priv->last_child2_focus));
1796 priv->last_child2_focus = widget;
1798 if (priv->last_child2_focus)
1799 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
1800 (gpointer *)&(priv->last_child2_focus));
1804 paned_get_focus_widget (GtkPaned *paned)
1806 GtkWidget *toplevel;
1808 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1809 if (gtk_widget_is_toplevel (toplevel))
1810 return gtk_window_get_focus (GTK_WINDOW (toplevel));
1816 gtk_paned_set_focus_child (GtkContainer *container,
1817 GtkWidget *focus_child)
1820 GtkPanedPrivate *priv;
1821 GtkWidget *container_focus_child;
1823 g_return_if_fail (GTK_IS_PANED (container));
1825 paned = GTK_PANED (container);
1828 if (focus_child == NULL)
1830 GtkWidget *last_focus;
1833 last_focus = paned_get_focus_widget (paned);
1837 /* If there is one or more paned widgets between us and the
1838 * focus widget, we want the topmost of those as last_focus
1840 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
1841 if (GTK_IS_PANED (w))
1844 container_focus_child = gtk_container_get_focus_child (container);
1845 if (container_focus_child == priv->child1)
1846 gtk_paned_set_last_child1_focus (paned, last_focus);
1847 else if (container_focus_child == priv->child2)
1848 gtk_paned_set_last_child2_focus (paned, last_focus);
1852 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
1853 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
1857 gtk_paned_get_cycle_chain (GtkPaned *paned,
1858 GtkDirectionType direction,
1861 GtkPanedPrivate *priv = paned->priv;
1862 GtkContainer *container = GTK_CONTAINER (paned);
1863 GtkWidget *ancestor = NULL;
1864 GtkWidget *focus_child;
1866 GtkWidget *widget = GTK_WIDGET (paned);
1867 GList *temp_list = NULL;
1870 if (priv->in_recursion)
1873 g_assert (widgets != NULL);
1875 if (priv->last_child1_focus &&
1876 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
1878 gtk_paned_set_last_child1_focus (paned, NULL);
1881 if (priv->last_child2_focus &&
1882 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
1884 gtk_paned_set_last_child2_focus (paned, NULL);
1887 parent = gtk_widget_get_parent (widget);
1889 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
1891 /* The idea here is that temp_list is a list of widgets we want to cycle
1892 * to. The list is prioritized so that the first element is our first
1893 * choice, the next our second, and so on.
1895 * We can't just use g_list_reverse(), because we want to try
1896 * priv->last_child?_focus before priv->child?, both when we
1897 * are going forward and backward.
1899 focus_child = gtk_container_get_focus_child (container);
1900 if (direction == GTK_DIR_TAB_FORWARD)
1902 if (focus_child == priv->child1)
1904 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1905 temp_list = g_list_append (temp_list, priv->child2);
1906 temp_list = g_list_append (temp_list, ancestor);
1908 else if (focus_child == priv->child2)
1910 temp_list = g_list_append (temp_list, ancestor);
1911 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1912 temp_list = g_list_append (temp_list, priv->child1);
1916 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1917 temp_list = g_list_append (temp_list, priv->child1);
1918 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1919 temp_list = g_list_append (temp_list, priv->child2);
1920 temp_list = g_list_append (temp_list, ancestor);
1925 if (focus_child == priv->child1)
1927 temp_list = g_list_append (temp_list, ancestor);
1928 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1929 temp_list = g_list_append (temp_list, priv->child2);
1931 else if (focus_child == priv->child2)
1933 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1934 temp_list = g_list_append (temp_list, priv->child1);
1935 temp_list = g_list_append (temp_list, ancestor);
1939 temp_list = g_list_append (temp_list, priv->last_child2_focus);
1940 temp_list = g_list_append (temp_list, priv->child2);
1941 temp_list = g_list_append (temp_list, priv->last_child1_focus);
1942 temp_list = g_list_append (temp_list, priv->child1);
1943 temp_list = g_list_append (temp_list, ancestor);
1947 /* Walk the list and expand all the paned widgets. */
1948 for (list = temp_list; list != NULL; list = list->next)
1950 GtkWidget *widget = list->data;
1954 if (GTK_IS_PANED (widget))
1956 priv->in_recursion = TRUE;
1957 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
1958 priv->in_recursion = FALSE;
1962 *widgets = g_list_append (*widgets, widget);
1967 g_list_free (temp_list);
1971 gtk_paned_cycle_child_focus (GtkPaned *paned,
1974 GList *cycle_chain = NULL;
1977 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
1979 /* ignore f6 if the handle is focused */
1980 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
1983 /* we can't just let the event propagate up the hierarchy,
1984 * because the paned will want to cycle focus _unless_ an
1985 * ancestor paned handles the event
1987 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
1989 for (list = cycle_chain; list != NULL; list = list->next)
1990 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
1993 g_list_free (cycle_chain);
1999 get_child_panes (GtkWidget *widget,
2002 if (!widget || !gtk_widget_get_realized (widget))
2005 if (GTK_IS_PANED (widget))
2007 GtkPaned *paned = GTK_PANED (widget);
2008 GtkPanedPrivate *priv = paned->priv;
2010 get_child_panes (priv->child1, panes);
2011 *panes = g_list_prepend (*panes, widget);
2012 get_child_panes (priv->child2, panes);
2014 else if (GTK_IS_CONTAINER (widget))
2016 gtk_container_forall (GTK_CONTAINER (widget),
2017 (GtkCallback)get_child_panes, panes);
2022 get_all_panes (GtkPaned *paned)
2024 GtkPaned *topmost = NULL;
2025 GList *result = NULL;
2028 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2030 if (GTK_IS_PANED (w))
2031 topmost = GTK_PANED (w);
2036 get_child_panes (GTK_WIDGET (topmost), &result);
2038 return g_list_reverse (result);
2042 gtk_paned_find_neighbours (GtkPaned *paned,
2049 all_panes = get_all_panes (paned);
2050 g_assert (all_panes);
2052 this_link = g_list_find (all_panes, paned);
2054 g_assert (this_link);
2056 if (this_link->next)
2057 *next = this_link->next->data;
2059 *next = all_panes->data;
2061 if (this_link->prev)
2062 *prev = this_link->prev->data;
2064 *prev = g_list_last (all_panes)->data;
2066 g_list_free (all_panes);
2070 gtk_paned_move_handle (GtkPaned *paned,
2071 GtkScrollType scroll)
2073 GtkPanedPrivate *priv = paned->priv;
2075 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2082 SINGLE_STEP_SIZE = 1,
2086 new_position = old_position = gtk_paned_get_position (paned);
2091 case GTK_SCROLL_STEP_LEFT:
2092 case GTK_SCROLL_STEP_UP:
2093 case GTK_SCROLL_STEP_BACKWARD:
2094 increment = - SINGLE_STEP_SIZE;
2097 case GTK_SCROLL_STEP_RIGHT:
2098 case GTK_SCROLL_STEP_DOWN:
2099 case GTK_SCROLL_STEP_FORWARD:
2100 increment = SINGLE_STEP_SIZE;
2103 case GTK_SCROLL_PAGE_LEFT:
2104 case GTK_SCROLL_PAGE_UP:
2105 case GTK_SCROLL_PAGE_BACKWARD:
2106 increment = - PAGE_STEP_SIZE;
2109 case GTK_SCROLL_PAGE_RIGHT:
2110 case GTK_SCROLL_PAGE_DOWN:
2111 case GTK_SCROLL_PAGE_FORWARD:
2112 increment = PAGE_STEP_SIZE;
2115 case GTK_SCROLL_START:
2116 new_position = priv->min_position;
2119 case GTK_SCROLL_END:
2120 new_position = priv->max_position;
2130 increment = -increment;
2132 new_position = old_position + increment;
2135 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2137 if (old_position != new_position)
2138 gtk_paned_set_position (paned, new_position);
2147 gtk_paned_restore_focus (GtkPaned *paned)
2149 GtkPanedPrivate *priv = paned->priv;
2151 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2153 if (priv->saved_focus &&
2154 gtk_widget_get_sensitive (priv->saved_focus))
2156 gtk_widget_grab_focus (priv->saved_focus);
2160 /* the saved focus is somehow not available for focusing,
2162 * 1) tabbing into the paned widget
2163 * if that didn't work,
2164 * 2) unset focus for the window if there is one
2167 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2169 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2171 if (GTK_IS_WINDOW (toplevel))
2172 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2176 gtk_paned_set_saved_focus (paned, NULL);
2177 gtk_paned_set_first_paned (paned, NULL);
2182 gtk_paned_accept_position (GtkPaned *paned)
2184 GtkPanedPrivate *priv = paned->priv;
2186 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2188 priv->original_position = -1;
2189 gtk_paned_restore_focus (paned);
2199 gtk_paned_cancel_position (GtkPaned *paned)
2201 GtkPanedPrivate *priv = paned->priv;
2203 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2205 if (priv->original_position != -1)
2207 gtk_paned_set_position (paned, priv->original_position);
2208 priv->original_position = -1;
2211 gtk_paned_restore_focus (paned);
2219 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2222 GtkPanedPrivate *priv = paned->priv;
2223 GtkPaned *next, *prev;
2225 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2227 GtkPaned *focus = NULL;
2229 if (!priv->first_paned)
2231 /* The first_pane has disappeared. As an ad-hoc solution,
2232 * we make the currently focused paned the first_paned. To the
2233 * user this will seem like the paned cycling has been reset.
2236 gtk_paned_set_first_paned (paned, paned);
2239 gtk_paned_find_neighbours (paned, &next, &prev);
2241 if (reversed && prev &&
2242 prev != paned && paned != priv->first_paned)
2246 else if (!reversed && next &&
2247 next != paned && next != priv->first_paned)
2253 gtk_paned_accept_position (paned);
2259 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2260 gtk_paned_set_first_paned (focus, priv->first_paned);
2262 gtk_paned_set_saved_focus (paned, NULL);
2263 gtk_paned_set_first_paned (paned, NULL);
2265 gtk_widget_grab_focus (GTK_WIDGET (focus));
2267 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2269 priv->original_position = -1;
2270 focus->priv->original_position = gtk_paned_get_position (focus);
2275 GtkContainer *container = GTK_CONTAINER (paned);
2278 GtkPaned *prev, *next;
2279 GtkWidget *toplevel;
2280 GtkWidget *focus_child;
2282 gtk_paned_find_neighbours (paned, &next, &prev);
2283 focus_child = gtk_container_get_focus_child (container);
2285 if (focus_child == priv->child1)
2298 else if (focus_child == priv->child2)
2313 /* Focus is not inside this paned, and we don't have focus.
2314 * Presumably this happened because the application wants us
2315 * to start keyboard navigating.
2325 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2327 if (GTK_IS_WINDOW (toplevel))
2328 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2329 gtk_paned_set_first_paned (focus, first);
2330 focus->priv->original_position = gtk_paned_get_position (focus);
2332 gtk_widget_grab_focus (GTK_WIDGET (focus));
2339 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2341 /* This function/signal has the wrong name. It is called when you
2342 * press Tab or Shift-Tab and what we do is act as if
2343 * the user pressed Return and then Tab or Shift-Tab
2345 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2346 gtk_paned_accept_position (paned);
2352 * gtk_paned_get_handle_window:
2353 * @paned: a #GtkPaned
2355 * Returns the #GdkWindow of the handle. This function is
2356 * useful when handling button or motion events because it
2357 * enables the callback to distinguish between the window
2358 * of the paned, a child and the handle.
2360 * Return value: the paned's handle window.
2365 gtk_paned_get_handle_window (GtkPaned *paned)
2367 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2369 return paned->priv->handle;