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 "gtkbindings.h"
33 #include "gtkmarshalers.h"
34 #include "gtkorientable.h"
35 #include "gtkwindow.h"
36 #include "gtktypebuiltins.h"
37 #include "gtkprivate.h"
43 * @Short_description: Base class for widgets with two adjustable panes
46 * #GtkPaned is the base class for widgets with two panes, arranged either
47 * horizontally (#GtkHPaned) or vertically (#GtkVPaned). Child widgets are
48 * added to the panes of the widget with gtk_paned_pack1() and
49 * gtk_paned_pack2(). The division between the two children is set by default
50 * from the size requests of the children, but it can be adjusted by the
53 * A paned widget draws a separator between the two child widgets and a
54 * small handle that the user can drag to adjust the division. It does not
55 * draw any relief around the children or around the separator. (The space
56 * in which the separator is called the gutter.) Often, it is useful to put
57 * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
58 * so that the gutter appears as a ridge. No separator is drawn if one of
59 * the children is missing.
61 * Each child has two options that can be set, @resize and @shrink. If
62 * @resize is true, then when the #GtkPaned is resized, that child will
63 * expand or shrink along with the paned widget. If @shrink is true, then
64 * that child can be made smaller than its requisition by the user.
65 * Setting @shrink to %FALSE allows the application to set a minimum size.
66 * If @resize is false for both children, then this is treated as if
67 * @resize is true for both children.
69 * The application can set the position of the slider as if it were set
70 * by the user, by calling gtk_paned_set_position().
73 * <title>Creating a paned widget with minimum sizes.</title>
75 * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
76 * GtkWidget *frame1 = gtk_frame_new (NULL);
77 * GtkWidget *frame2 = gtk_frame_new (NULL);
78 * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
79 * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
81 * gtk_widget_set_size_request (hpaned, 200, -1);
83 * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
84 * gtk_widget_set_size_request (frame1, 50, -1);
86 * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
87 * gtk_widget_set_size_request (frame2, 50, -1);
92 struct _GtkPanedPrivate
94 GtkPaned *first_paned;
97 GtkWidget *last_child1_focus;
98 GtkWidget *last_child2_focus;
99 GtkWidget *saved_focus;
100 GtkOrientation orientation;
102 GdkCursorType cursor_type;
103 GdkDevice *grab_device;
104 GdkRectangle handle_pos;
109 gint last_allocation;
112 gint original_position;
116 guint handle_prelit : 1;
118 guint in_recursion : 1;
119 guint child1_resize : 1;
120 guint child1_shrink : 1;
121 guint child2_resize : 1;
122 guint child2_shrink : 1;
123 guint position_set : 1;
151 static void gtk_paned_set_property (GObject *object,
155 static void gtk_paned_get_property (GObject *object,
159 static void gtk_paned_set_child_property (GtkContainer *container,
164 static void gtk_paned_get_child_property (GtkContainer *container,
169 static void gtk_paned_finalize (GObject *object);
171 static void gtk_paned_get_preferred_width (GtkWidget *widget,
174 static void gtk_paned_get_preferred_height (GtkWidget *widget,
177 static void gtk_paned_get_preferred_width_for_height
182 static void gtk_paned_get_preferred_height_for_width
188 static void gtk_paned_size_allocate (GtkWidget *widget,
189 GtkAllocation *allocation);
190 static void gtk_paned_realize (GtkWidget *widget);
191 static void gtk_paned_unrealize (GtkWidget *widget);
192 static void gtk_paned_map (GtkWidget *widget);
193 static void gtk_paned_unmap (GtkWidget *widget);
194 static void gtk_paned_state_flags_changed (GtkWidget *widget,
195 GtkStateFlags previous_state);
196 static gboolean gtk_paned_draw (GtkWidget *widget,
198 static gboolean gtk_paned_enter (GtkWidget *widget,
199 GdkEventCrossing *event);
200 static gboolean gtk_paned_leave (GtkWidget *widget,
201 GdkEventCrossing *event);
202 static gboolean gtk_paned_button_press (GtkWidget *widget,
203 GdkEventButton *event);
204 static gboolean gtk_paned_button_release (GtkWidget *widget,
205 GdkEventButton *event);
206 static gboolean gtk_paned_motion (GtkWidget *widget,
207 GdkEventMotion *event);
208 static gboolean gtk_paned_focus (GtkWidget *widget,
209 GtkDirectionType direction);
210 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
211 GdkEventGrabBroken *event);
212 static void gtk_paned_add (GtkContainer *container,
214 static void gtk_paned_remove (GtkContainer *container,
216 static void gtk_paned_forall (GtkContainer *container,
217 gboolean include_internals,
218 GtkCallback callback,
219 gpointer callback_data);
220 static void gtk_paned_calc_position (GtkPaned *paned,
224 static void gtk_paned_set_focus_child (GtkContainer *container,
226 static void gtk_paned_set_saved_focus (GtkPaned *paned,
228 static void gtk_paned_set_first_paned (GtkPaned *paned,
229 GtkPaned *first_paned);
230 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
232 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
234 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
236 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
238 static gboolean gtk_paned_move_handle (GtkPaned *paned,
239 GtkScrollType scroll);
240 static gboolean gtk_paned_accept_position (GtkPaned *paned);
241 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
242 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
244 static GType gtk_paned_child_type (GtkContainer *container);
245 static void gtk_paned_grab_notify (GtkWidget *widget,
246 gboolean was_grabbed);
249 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
250 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
253 static guint signals[LAST_SIGNAL] = { 0 };
257 add_tab_bindings (GtkBindingSet *binding_set,
258 GdkModifierType modifiers)
260 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
261 "toggle-handle-focus", 0);
262 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
263 "toggle-handle-focus", 0);
267 add_move_binding (GtkBindingSet *binding_set,
269 GdkModifierType mask,
270 GtkScrollType scroll)
272 gtk_binding_entry_add_signal (binding_set, keyval, mask,
274 GTK_TYPE_SCROLL_TYPE, scroll);
278 gtk_paned_class_init (GtkPanedClass *class)
280 GObjectClass *object_class;
281 GtkWidgetClass *widget_class;
282 GtkContainerClass *container_class;
283 GtkPanedClass *paned_class;
284 GtkBindingSet *binding_set;
286 object_class = (GObjectClass *) class;
287 widget_class = (GtkWidgetClass *) class;
288 container_class = (GtkContainerClass *) class;
289 paned_class = (GtkPanedClass *) class;
291 object_class->set_property = gtk_paned_set_property;
292 object_class->get_property = gtk_paned_get_property;
293 object_class->finalize = gtk_paned_finalize;
295 widget_class->get_preferred_width = gtk_paned_get_preferred_width;
296 widget_class->get_preferred_height = gtk_paned_get_preferred_height;
297 widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
298 widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
299 widget_class->size_allocate = gtk_paned_size_allocate;
300 widget_class->realize = gtk_paned_realize;
301 widget_class->unrealize = gtk_paned_unrealize;
302 widget_class->map = gtk_paned_map;
303 widget_class->unmap = gtk_paned_unmap;
304 widget_class->draw = gtk_paned_draw;
305 widget_class->focus = gtk_paned_focus;
306 widget_class->enter_notify_event = gtk_paned_enter;
307 widget_class->leave_notify_event = gtk_paned_leave;
308 widget_class->button_press_event = gtk_paned_button_press;
309 widget_class->button_release_event = gtk_paned_button_release;
310 widget_class->motion_notify_event = gtk_paned_motion;
311 widget_class->grab_broken_event = gtk_paned_grab_broken;
312 widget_class->grab_notify = gtk_paned_grab_notify;
313 widget_class->state_flags_changed = gtk_paned_state_flags_changed;
315 container_class->add = gtk_paned_add;
316 container_class->remove = gtk_paned_remove;
317 container_class->forall = gtk_paned_forall;
318 container_class->child_type = gtk_paned_child_type;
319 container_class->set_focus_child = gtk_paned_set_focus_child;
320 container_class->set_child_property = gtk_paned_set_child_property;
321 container_class->get_child_property = gtk_paned_get_child_property;
322 gtk_container_class_handle_border_width (container_class);
324 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
325 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
326 paned_class->move_handle = gtk_paned_move_handle;
327 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
328 paned_class->accept_position = gtk_paned_accept_position;
329 paned_class->cancel_position = gtk_paned_cancel_position;
331 g_object_class_override_property (object_class,
335 g_object_class_install_property (object_class,
337 g_param_spec_int ("position",
339 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
343 GTK_PARAM_READWRITE));
345 g_object_class_install_property (object_class,
347 g_param_spec_boolean ("position-set",
349 P_("TRUE if the Position property should be used"),
351 GTK_PARAM_READWRITE));
353 gtk_widget_class_install_style_property (widget_class,
354 g_param_spec_int ("handle-size",
356 P_("Width of handle"),
360 GTK_PARAM_READABLE));
362 * GtkPaned:min-position:
364 * The smallest possible value for the position property. This property is derived from the
365 * size and shrinkability of the widget's children.
369 g_object_class_install_property (object_class,
371 g_param_spec_int ("min-position",
372 P_("Minimal Position"),
373 P_("Smallest possible value for the \"position\" property"),
377 GTK_PARAM_READABLE));
380 * GtkPaned:max-position:
382 * The largest possible value for the position property. This property is derived from the
383 * size and shrinkability of the widget's children.
387 g_object_class_install_property (object_class,
389 g_param_spec_int ("max-position",
390 P_("Maximal Position"),
391 P_("Largest possible value for the \"position\" property"),
395 GTK_PARAM_READABLE));
400 * The "resize" child property determines whether the child expands and
401 * shrinks along with the paned widget.
405 gtk_container_class_install_child_property (container_class,
407 g_param_spec_boolean ("resize",
409 P_("If TRUE, the child expands and shrinks along with the paned widget"),
411 GTK_PARAM_READWRITE));
416 * The "shrink" child property determines whether the child can be made
417 * smaller than its requisition.
421 gtk_container_class_install_child_property (container_class,
423 g_param_spec_boolean ("shrink",
425 P_("If TRUE, the child can be made smaller than its requisition"),
427 GTK_PARAM_READWRITE));
430 * GtkPaned::cycle-child-focus:
431 * @widget: the object that received the signal
432 * @reversed: whether cycling backward or forward
434 * The ::cycle-child-focus signal is a
435 * <link linkend="keybinding-signals">keybinding signal</link>
436 * which gets emitted to cycle the focus between the children of the paned.
438 * The default binding is f6.
442 signals [CYCLE_CHILD_FOCUS] =
443 g_signal_new (I_("cycle-child-focus"),
444 G_TYPE_FROM_CLASS (object_class),
445 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
446 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
448 _gtk_marshal_BOOLEAN__BOOLEAN,
453 * GtkPaned::toggle-handle-focus:
454 * @widget: the object that received the signal
456 * The ::toggle-handle-focus is a
457 * <link linkend="keybinding-signals">keybinding signal</link>
458 * which gets emitted to accept the current position of the handle and then
459 * move focus to the next widget in the focus chain.
461 * The default binding is Tab.
465 signals [TOGGLE_HANDLE_FOCUS] =
466 g_signal_new (I_("toggle-handle-focus"),
467 G_TYPE_FROM_CLASS (object_class),
468 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
469 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
471 _gtk_marshal_BOOLEAN__VOID,
475 * GtkPaned::move-handle:
476 * @widget: the object that received the signal
477 * @scroll_type: a #GtkScrollType
479 * The ::move-handle signal is a
480 * <link linkend="keybinding-signals">keybinding signal</link>
481 * which gets emitted to move the handle when the user is using key bindings
486 signals[MOVE_HANDLE] =
487 g_signal_new (I_("move-handle"),
488 G_TYPE_FROM_CLASS (object_class),
489 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
490 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
492 _gtk_marshal_BOOLEAN__ENUM,
494 GTK_TYPE_SCROLL_TYPE);
497 * GtkPaned::cycle-handle-focus:
498 * @widget: the object that received the signal
499 * @reversed: whether cycling backward or forward
501 * The ::cycle-handle-focus signal is a
502 * <link linkend="keybinding-signals">keybinding signal</link>
503 * which gets emitted to cycle whether the paned should grab focus to allow
504 * the user to change position of the handle by using key bindings.
506 * The default binding for this signal is f8.
510 signals [CYCLE_HANDLE_FOCUS] =
511 g_signal_new (I_("cycle-handle-focus"),
512 G_TYPE_FROM_CLASS (object_class),
513 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
514 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
516 _gtk_marshal_BOOLEAN__BOOLEAN,
521 * GtkPaned::accept-position:
522 * @widget: the object that received the signal
524 * The ::accept-position signal is a
525 * <link linkend="keybinding-signals">keybinding signal</link>
526 * which gets emitted to accept the current position of the handle when
527 * moving it using key bindings.
529 * The default binding for this signal is Return or Space.
533 signals [ACCEPT_POSITION] =
534 g_signal_new (I_("accept-position"),
535 G_TYPE_FROM_CLASS (object_class),
536 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
537 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
539 _gtk_marshal_BOOLEAN__VOID,
543 * GtkPaned::cancel-position:
544 * @widget: the object that received the signal
546 * The ::cancel-position signal is a
547 * <link linkend="keybinding-signals">keybinding signal</link>
548 * which gets emitted to cancel moving the position of the handle using key
549 * bindings. The position of the handle will be reset to the value prior to
552 * The default binding for this signal is Escape.
556 signals [CANCEL_POSITION] =
557 g_signal_new (I_("cancel-position"),
558 G_TYPE_FROM_CLASS (object_class),
559 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
560 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
562 _gtk_marshal_BOOLEAN__VOID,
565 binding_set = gtk_binding_set_by_class (class);
568 gtk_binding_entry_add_signal (binding_set,
570 "cycle-child-focus", 1,
571 G_TYPE_BOOLEAN, FALSE);
572 gtk_binding_entry_add_signal (binding_set,
573 GDK_KEY_F6, GDK_SHIFT_MASK,
574 "cycle-child-focus", 1,
575 G_TYPE_BOOLEAN, TRUE);
578 gtk_binding_entry_add_signal (binding_set,
580 "cycle-handle-focus", 1,
581 G_TYPE_BOOLEAN, FALSE);
583 gtk_binding_entry_add_signal (binding_set,
584 GDK_KEY_F8, GDK_SHIFT_MASK,
585 "cycle-handle-focus", 1,
586 G_TYPE_BOOLEAN, TRUE);
588 add_tab_bindings (binding_set, 0);
589 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
590 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
591 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
593 /* accept and cancel positions */
594 gtk_binding_entry_add_signal (binding_set,
596 "cancel-position", 0);
598 gtk_binding_entry_add_signal (binding_set,
600 "accept-position", 0);
601 gtk_binding_entry_add_signal (binding_set,
602 GDK_KEY_ISO_Enter, 0,
603 "accept-position", 0);
604 gtk_binding_entry_add_signal (binding_set,
606 "accept-position", 0);
607 gtk_binding_entry_add_signal (binding_set,
609 "accept-position", 0);
610 gtk_binding_entry_add_signal (binding_set,
612 "accept-position", 0);
615 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
616 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
617 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
618 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
620 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
621 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
622 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
623 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
625 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
626 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
627 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
628 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
629 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
630 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
632 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
633 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
634 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
635 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
636 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
637 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
639 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
640 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
641 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
642 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
644 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
648 gtk_paned_child_type (GtkContainer *container)
650 GtkPaned *paned = GTK_PANED (container);
651 GtkPanedPrivate *priv = paned->priv;
653 if (!priv->child1 || !priv->child2)
654 return GTK_TYPE_WIDGET;
660 gtk_paned_init (GtkPaned *paned)
662 GtkPanedPrivate *priv;
664 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
665 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
667 /* We only need to redraw when the handle position moves, which is
668 * independent of the overall allocation of the GtkPaned
670 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
672 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
675 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
676 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
681 priv->cursor_type = GDK_CROSS;
683 priv->handle_pos.width = 5;
684 priv->handle_pos.height = 5;
685 priv->position_set = FALSE;
686 priv->last_allocation = -1;
687 priv->in_drag = FALSE;
689 priv->last_child1_focus = NULL;
690 priv->last_child2_focus = NULL;
691 priv->in_recursion = FALSE;
692 priv->handle_prelit = FALSE;
693 priv->original_position = -1;
695 priv->handle_pos.x = -1;
696 priv->handle_pos.y = -1;
702 gtk_paned_set_property (GObject *object,
707 GtkPaned *paned = GTK_PANED (object);
708 GtkPanedPrivate *priv = paned->priv;
712 case PROP_ORIENTATION:
713 priv->orientation = g_value_get_enum (value);
715 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
716 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
718 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
720 /* state_flags_changed updates the cursor */
721 gtk_paned_state_flags_changed (GTK_WIDGET (paned), 0);
722 gtk_widget_queue_resize (GTK_WIDGET (paned));
725 gtk_paned_set_position (paned, g_value_get_int (value));
727 case PROP_POSITION_SET:
728 priv->position_set = g_value_get_boolean (value);
729 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
732 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
738 gtk_paned_get_property (GObject *object,
743 GtkPaned *paned = GTK_PANED (object);
744 GtkPanedPrivate *priv = paned->priv;
748 case PROP_ORIENTATION:
749 g_value_set_enum (value, priv->orientation);
752 g_value_set_int (value, priv->child1_size);
754 case PROP_POSITION_SET:
755 g_value_set_boolean (value, priv->position_set);
757 case PROP_MIN_POSITION:
758 g_value_set_int (value, priv->min_position);
760 case PROP_MAX_POSITION:
761 g_value_set_int (value, priv->max_position);
764 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
770 gtk_paned_set_child_property (GtkContainer *container,
776 GtkPaned *paned = GTK_PANED (container);
777 GtkPanedPrivate *priv = paned->priv;
778 gboolean old_value, new_value;
780 g_assert (child == priv->child1 || child == priv->child2);
782 new_value = g_value_get_boolean (value);
785 case CHILD_PROP_RESIZE:
786 if (child == priv->child1)
788 old_value = priv->child1_resize;
789 priv->child1_resize = new_value;
793 old_value = priv->child2_resize;
794 priv->child2_resize = new_value;
797 case CHILD_PROP_SHRINK:
798 if (child == priv->child1)
800 old_value = priv->child1_shrink;
801 priv->child1_shrink = new_value;
805 old_value = priv->child2_shrink;
806 priv->child2_shrink = new_value;
810 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
811 old_value = -1; /* quiet gcc */
814 if (old_value != new_value)
815 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
819 gtk_paned_get_child_property (GtkContainer *container,
825 GtkPaned *paned = GTK_PANED (container);
826 GtkPanedPrivate *priv = paned->priv;
828 g_assert (child == priv->child1 || child == priv->child2);
832 case CHILD_PROP_RESIZE:
833 if (child == priv->child1)
834 g_value_set_boolean (value, priv->child1_resize);
836 g_value_set_boolean (value, priv->child2_resize);
838 case CHILD_PROP_SHRINK:
839 if (child == priv->child1)
840 g_value_set_boolean (value, priv->child1_shrink);
842 g_value_set_boolean (value, priv->child2_shrink);
845 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
851 gtk_paned_finalize (GObject *object)
853 GtkPaned *paned = GTK_PANED (object);
855 gtk_paned_set_saved_focus (paned, NULL);
856 gtk_paned_set_first_paned (paned, NULL);
858 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
862 get_preferred_size_for_size (GtkWidget *widget,
863 GtkOrientation orientation,
868 if (orientation == GTK_ORIENTATION_HORIZONTAL)
870 gtk_widget_get_preferred_width (widget, minimum, natural);
872 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
875 gtk_widget_get_preferred_height (widget, minimum, natural);
877 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
881 gtk_paned_get_preferred_size (GtkWidget *widget,
882 GtkOrientation orientation,
887 GtkPaned *paned = GTK_PANED (widget);
888 GtkPanedPrivate *priv = paned->priv;
889 gint child_min, child_nat;
891 *minimum = *natural = 0;
893 if (priv->child1 && gtk_widget_get_visible (priv->child1))
895 get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
896 *minimum = child_min;
897 *natural = child_nat;
900 if (priv->child2 && gtk_widget_get_visible (priv->child2))
902 get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
904 if (priv->orientation == orientation)
906 *minimum += child_min;
907 *natural += child_nat;
911 *minimum = MAX (*minimum, child_min);
912 *natural = MAX (*natural, child_nat);
916 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
917 priv->child2 && gtk_widget_get_visible (priv->child2))
921 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
923 if (priv->orientation == orientation)
925 *minimum += handle_size;
926 *natural += handle_size;
932 gtk_paned_get_preferred_width (GtkWidget *widget,
936 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
940 gtk_paned_get_preferred_height (GtkWidget *widget,
944 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
948 gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
953 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
957 gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
962 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
966 flip_child (GtkWidget *widget,
967 GtkAllocation *child_pos)
969 GtkAllocation allocation;
972 gtk_widget_get_allocation (widget, &allocation);
974 width = allocation.width;
976 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
980 gtk_paned_size_allocate (GtkWidget *widget,
981 GtkAllocation *allocation)
983 GtkPaned *paned = GTK_PANED (widget);
984 GtkPanedPrivate *priv = paned->priv;
986 gtk_widget_set_allocation (widget, allocation);
988 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
989 priv->child2 && gtk_widget_get_visible (priv->child2))
991 GtkAllocation child1_allocation;
992 GtkAllocation child2_allocation;
993 GtkAllocation priv_child1_allocation;
994 GdkRectangle old_handle_pos;
997 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
999 old_handle_pos = priv->handle_pos;
1001 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1003 gint child1_width, child2_width;
1005 gtk_widget_get_preferred_width_for_height (priv->child1,
1007 &child1_width, NULL);
1008 gtk_widget_get_preferred_width_for_height (priv->child2,
1010 &child2_width, NULL);
1012 gtk_paned_calc_position (paned,
1013 MAX (1, allocation->width - handle_size),
1017 priv->handle_pos.x = allocation->x + priv->child1_size;
1018 priv->handle_pos.y = allocation->y;
1019 priv->handle_pos.width = handle_size;
1020 priv->handle_pos.height = allocation->height;
1022 child1_allocation.height = child2_allocation.height = allocation->height;
1023 child1_allocation.width = MAX (1, priv->child1_size);
1024 child1_allocation.x = allocation->x;
1025 child1_allocation.y = child2_allocation.y = allocation->y;
1027 child2_allocation.x = child1_allocation.x + priv->child1_size + priv->handle_pos.width;
1028 child2_allocation.width = MAX (1, allocation->x + allocation->width - child2_allocation.x);
1030 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1032 flip_child (widget, &(child2_allocation));
1033 flip_child (widget, &(child1_allocation));
1034 flip_child (widget, &(priv->handle_pos));
1039 gint child1_height, child2_height;
1041 gtk_widget_get_preferred_height_for_width (priv->child1,
1043 &child1_height, NULL);
1044 gtk_widget_get_preferred_height_for_width (priv->child2,
1046 &child2_height, NULL);
1048 gtk_paned_calc_position (paned,
1049 MAX (1, allocation->height - handle_size),
1053 priv->handle_pos.x = allocation->x;
1054 priv->handle_pos.y = allocation->y + priv->child1_size;
1055 priv->handle_pos.width = allocation->width;
1056 priv->handle_pos.height = handle_size;
1058 child1_allocation.width = child2_allocation.width = allocation->width;
1059 child1_allocation.height = MAX (1, priv->child1_size);
1060 child1_allocation.x = child2_allocation.x = allocation->x;
1061 child1_allocation.y = allocation->y;
1063 child2_allocation.y = child1_allocation.y + priv->child1_size + priv->handle_pos.height;
1064 child2_allocation.height = MAX (1, allocation->y + allocation->height - child2_allocation.y);
1067 if (gtk_widget_get_mapped (widget) &&
1068 (old_handle_pos.x != priv->handle_pos.x ||
1069 old_handle_pos.y != priv->handle_pos.y ||
1070 old_handle_pos.width != priv->handle_pos.width ||
1071 old_handle_pos.height != priv->handle_pos.height))
1075 window = gtk_widget_get_window (widget);
1076 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
1077 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
1080 if (gtk_widget_get_realized (widget))
1082 if (gtk_widget_get_mapped (widget))
1083 gdk_window_show (priv->handle);
1085 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1087 gdk_window_move_resize (priv->handle,
1091 priv->handle_pos.height);
1095 gdk_window_move_resize (priv->handle,
1098 priv->handle_pos.width,
1103 /* Now allocate the childen, making sure, when resizing not to
1104 * overlap the windows
1106 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
1107 if (gtk_widget_get_mapped (widget) &&
1108 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1109 priv_child1_allocation.width < child1_allocation.width) ||
1111 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1112 priv_child1_allocation.height < child1_allocation.height)))
1114 gtk_widget_size_allocate (priv->child2, &child2_allocation);
1115 gtk_widget_size_allocate (priv->child1, &child1_allocation);
1119 gtk_widget_size_allocate (priv->child1, &child1_allocation);
1120 gtk_widget_size_allocate (priv->child2, &child2_allocation);
1125 GtkAllocation child_allocation;
1127 if (gtk_widget_get_realized (widget))
1128 gdk_window_hide (priv->handle);
1131 gtk_widget_set_child_visible (priv->child1, TRUE);
1133 gtk_widget_set_child_visible (priv->child2, TRUE);
1135 child_allocation.x = allocation->x;
1136 child_allocation.y = allocation->y;
1137 child_allocation.width = allocation->width;
1138 child_allocation.height = allocation->height;
1140 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1141 gtk_widget_size_allocate (priv->child1, &child_allocation);
1142 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1143 gtk_widget_size_allocate (priv->child2, &child_allocation);
1148 gtk_paned_realize (GtkWidget *widget)
1150 GtkPaned *paned = GTK_PANED (widget);
1151 GtkPanedPrivate *priv = paned->priv;
1153 GdkWindowAttr attributes;
1154 gint attributes_mask;
1156 gtk_widget_set_realized (widget, TRUE);
1158 window = gtk_widget_get_parent_window (widget);
1159 gtk_widget_set_window (widget, window);
1160 g_object_ref (window);
1162 attributes.window_type = GDK_WINDOW_CHILD;
1163 attributes.wclass = GDK_INPUT_ONLY;
1164 attributes.x = priv->handle_pos.x;
1165 attributes.y = priv->handle_pos.y;
1166 attributes.width = priv->handle_pos.width;
1167 attributes.height = priv->handle_pos.height;
1168 attributes.event_mask = gtk_widget_get_events (widget);
1169 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1170 GDK_BUTTON_RELEASE_MASK |
1171 GDK_ENTER_NOTIFY_MASK |
1172 GDK_LEAVE_NOTIFY_MASK |
1173 GDK_POINTER_MOTION_MASK |
1174 GDK_POINTER_MOTION_HINT_MASK);
1175 attributes_mask = GDK_WA_X | GDK_WA_Y;
1176 if (gtk_widget_is_sensitive (widget))
1178 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1180 attributes_mask |= GDK_WA_CURSOR;
1183 priv->handle = gdk_window_new (window,
1184 &attributes, attributes_mask);
1185 gdk_window_set_user_data (priv->handle, paned);
1186 if (attributes_mask & GDK_WA_CURSOR)
1187 g_object_unref (attributes.cursor);
1189 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1190 priv->child2 && gtk_widget_get_visible (priv->child2))
1191 gdk_window_show (priv->handle);
1195 gtk_paned_unrealize (GtkWidget *widget)
1197 GtkPaned *paned = GTK_PANED (widget);
1198 GtkPanedPrivate *priv = paned->priv;
1202 gdk_window_set_user_data (priv->handle, NULL);
1203 gdk_window_destroy (priv->handle);
1204 priv->handle = NULL;
1207 gtk_paned_set_last_child1_focus (paned, NULL);
1208 gtk_paned_set_last_child2_focus (paned, NULL);
1209 gtk_paned_set_saved_focus (paned, NULL);
1210 gtk_paned_set_first_paned (paned, NULL);
1212 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1216 gtk_paned_map (GtkWidget *widget)
1218 GtkPaned *paned = GTK_PANED (widget);
1219 GtkPanedPrivate *priv = paned->priv;
1221 gdk_window_show (priv->handle);
1223 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1227 gtk_paned_unmap (GtkWidget *widget)
1229 GtkPaned *paned = GTK_PANED (widget);
1230 GtkPanedPrivate *priv = paned->priv;
1232 gdk_window_hide (priv->handle);
1234 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1238 gtk_paned_draw (GtkWidget *widget,
1241 GtkPaned *paned = GTK_PANED (widget);
1242 GtkPanedPrivate *priv = paned->priv;
1244 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1245 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1246 priv->child2 && gtk_widget_get_visible (priv->child2))
1248 GtkStyleContext *context;
1249 GtkStateFlags state;
1250 GtkAllocation allocation;
1252 gtk_widget_get_allocation (widget, &allocation);
1253 context = gtk_widget_get_style_context (widget);
1254 state = gtk_widget_get_state_flags (widget);
1256 if (gtk_widget_is_focus (widget))
1257 state |= GTK_STATE_FLAG_SELECTED;
1258 if (priv->handle_prelit)
1259 state |= GTK_STATE_FLAG_PRELIGHT;
1261 gtk_style_context_save (context);
1262 gtk_style_context_set_state (context, state);
1263 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1264 gtk_render_handle (context, cr,
1265 priv->handle_pos.x - allocation.x,
1266 priv->handle_pos.y - allocation.y,
1267 priv->handle_pos.width,
1268 priv->handle_pos.height);
1270 gtk_style_context_restore (context);
1273 /* Chain up to draw children */
1274 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1280 is_rtl (GtkPaned *paned)
1282 GtkPanedPrivate *priv = paned->priv;
1284 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1285 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1294 update_drag (GtkPaned *paned)
1296 GtkPanedPrivate *priv = paned->priv;
1297 GtkAllocation allocation;
1298 GtkWidget *widget = GTK_WIDGET (paned);
1303 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1304 gtk_widget_get_pointer (widget, &pos, NULL);
1306 gtk_widget_get_pointer (widget, NULL, &pos);
1308 pos -= priv->drag_pos;
1312 gtk_widget_style_get (widget,
1313 "handle-size", &handle_size,
1316 gtk_widget_get_allocation (widget, &allocation);
1317 size = allocation.width - pos - handle_size;
1324 size = CLAMP (size, priv->min_position, priv->max_position);
1326 if (size != priv->child1_size)
1327 gtk_paned_set_position (paned, size);
1331 gtk_paned_enter (GtkWidget *widget,
1332 GdkEventCrossing *event)
1334 GtkPaned *paned = GTK_PANED (widget);
1335 GtkPanedPrivate *priv = paned->priv;
1338 update_drag (paned);
1341 priv->handle_prelit = TRUE;
1342 gtk_widget_queue_draw_area (widget,
1345 priv->handle_pos.width,
1346 priv->handle_pos.height);
1353 gtk_paned_leave (GtkWidget *widget,
1354 GdkEventCrossing *event)
1356 GtkPaned *paned = GTK_PANED (widget);
1357 GtkPanedPrivate *priv = paned->priv;
1360 update_drag (paned);
1363 priv->handle_prelit = FALSE;
1364 gtk_widget_queue_draw_area (widget,
1367 priv->handle_pos.width,
1368 priv->handle_pos.height);
1375 gtk_paned_focus (GtkWidget *widget,
1376 GtkDirectionType direction)
1381 /* This is a hack, but how can this be done without
1382 * excessive cut-and-paste from gtkcontainer.c?
1385 gtk_widget_set_can_focus (widget, FALSE);
1386 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1387 gtk_widget_set_can_focus (widget, TRUE);
1393 gtk_paned_button_press (GtkWidget *widget,
1394 GdkEventButton *event)
1396 GtkPaned *paned = GTK_PANED (widget);
1397 GtkPanedPrivate *priv = paned->priv;
1399 if (!priv->in_drag &&
1400 (event->window == priv->handle) && (event->button == 1))
1402 /* We need a server grab here, not gtk_grab_add(), since
1403 * we don't want to pass events on to the widget's children */
1404 if (gdk_device_grab (event->device,
1406 GDK_OWNERSHIP_WINDOW, FALSE,
1407 GDK_POINTER_MOTION_HINT_MASK
1408 | GDK_BUTTON1_MOTION_MASK
1409 | GDK_BUTTON_RELEASE_MASK
1410 | GDK_ENTER_NOTIFY_MASK
1411 | GDK_LEAVE_NOTIFY_MASK,
1412 NULL, event->time) != GDK_GRAB_SUCCESS)
1415 priv->in_drag = TRUE;
1416 priv->grab_time = event->time;
1417 priv->grab_device = event->device;
1419 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1420 priv->drag_pos = event->x;
1422 priv->drag_pos = event->y;
1431 gtk_paned_grab_broken (GtkWidget *widget,
1432 GdkEventGrabBroken *event)
1434 GtkPaned *paned = GTK_PANED (widget);
1435 GtkPanedPrivate *priv = paned->priv;
1437 priv->in_drag = FALSE;
1438 priv->drag_pos = -1;
1439 priv->position_set = TRUE;
1445 stop_drag (GtkPaned *paned)
1447 GtkPanedPrivate *priv = paned->priv;
1449 priv->in_drag = FALSE;
1450 priv->drag_pos = -1;
1451 priv->position_set = TRUE;
1453 gdk_device_ungrab (priv->grab_device,
1455 priv->grab_device = NULL;
1459 gtk_paned_grab_notify (GtkWidget *widget,
1460 gboolean was_grabbed)
1462 GtkPaned *paned = GTK_PANED (widget);
1463 GtkPanedPrivate *priv = paned->priv;
1464 GdkDevice *grab_device;
1466 grab_device = priv->grab_device;
1468 if (priv->in_drag && grab_device &&
1469 gtk_widget_device_is_shadowed (widget, grab_device))
1474 gtk_paned_state_flags_changed (GtkWidget *widget,
1475 GtkStateFlags previous_state)
1477 GtkPaned *paned = GTK_PANED (widget);
1478 GtkPanedPrivate *priv = paned->priv;
1481 if (gtk_widget_get_realized (widget))
1483 if (gtk_widget_is_sensitive (widget))
1484 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1489 gdk_window_set_cursor (priv->handle, cursor);
1492 g_object_unref (cursor);
1497 gtk_paned_button_release (GtkWidget *widget,
1498 GdkEventButton *event)
1500 GtkPaned *paned = GTK_PANED (widget);
1501 GtkPanedPrivate *priv = paned->priv;
1503 if (priv->in_drag && (event->button == 1))
1514 gtk_paned_motion (GtkWidget *widget,
1515 GdkEventMotion *event)
1517 GtkPaned *paned = GTK_PANED (widget);
1518 GtkPanedPrivate *priv = paned->priv;
1522 update_drag (paned);
1531 * @orientation: the paned's orientation.
1533 * Creates a new #GtkPaned widget.
1535 * Return value: a new #GtkPaned.
1540 gtk_paned_new (GtkOrientation orientation)
1542 return g_object_new (GTK_TYPE_PANED,
1543 "orientation", orientation,
1549 * @paned: a paned widget
1550 * @child: the child to add
1552 * Adds a child to the top or left pane with default parameters. This is
1554 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1557 gtk_paned_add1 (GtkPaned *paned,
1560 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1565 * @paned: a paned widget
1566 * @child: the child to add
1568 * Adds a child to the bottom or right pane with default parameters. This
1570 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1573 gtk_paned_add2 (GtkPaned *paned,
1576 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1581 * @paned: a paned widget
1582 * @child: the child to add
1583 * @resize: should this child expand when the paned widget is resized.
1584 * @shrink: can this child be made smaller than its requisition.
1586 * Adds a child to the top or left pane.
1589 gtk_paned_pack1 (GtkPaned *paned,
1594 GtkPanedPrivate *priv;
1596 g_return_if_fail (GTK_IS_PANED (paned));
1597 g_return_if_fail (GTK_IS_WIDGET (child));
1603 priv->child1 = child;
1604 priv->child1_resize = resize;
1605 priv->child1_shrink = shrink;
1607 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1613 * @paned: a paned widget
1614 * @child: the child to add
1615 * @resize: should this child expand when the paned widget is resized.
1616 * @shrink: can this child be made smaller than its requisition.
1618 * Adds a child to the bottom or right pane.
1621 gtk_paned_pack2 (GtkPaned *paned,
1626 GtkPanedPrivate *priv;
1628 g_return_if_fail (GTK_IS_PANED (paned));
1629 g_return_if_fail (GTK_IS_WIDGET (child));
1635 priv->child2 = child;
1636 priv->child2_resize = resize;
1637 priv->child2_shrink = shrink;
1639 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1645 gtk_paned_add (GtkContainer *container,
1648 GtkPanedPrivate *priv;
1651 g_return_if_fail (GTK_IS_PANED (container));
1653 paned = GTK_PANED (container);
1657 gtk_paned_add1 (paned, widget);
1658 else if (!priv->child2)
1659 gtk_paned_add2 (paned, widget);
1661 g_warning ("GtkPaned cannot have more than 2 children\n");
1665 gtk_paned_remove (GtkContainer *container,
1668 GtkPaned *paned = GTK_PANED (container);
1669 GtkPanedPrivate *priv = paned->priv;
1670 gboolean was_visible;
1672 was_visible = gtk_widget_get_visible (widget);
1674 if (priv->child1 == widget)
1676 gtk_widget_unparent (widget);
1678 priv->child1 = NULL;
1680 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1681 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1683 else if (priv->child2 == widget)
1685 gtk_widget_unparent (widget);
1687 priv->child2 = NULL;
1689 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1690 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1695 gtk_paned_forall (GtkContainer *container,
1696 gboolean include_internals,
1697 GtkCallback callback,
1698 gpointer callback_data)
1700 GtkPanedPrivate *priv;
1703 g_return_if_fail (callback != NULL);
1705 paned = GTK_PANED (container);
1709 (*callback) (priv->child1, callback_data);
1711 (*callback) (priv->child2, callback_data);
1715 * gtk_paned_get_position:
1716 * @paned: a #GtkPaned widget
1718 * Obtains the position of the divider between the two panes.
1720 * Return value: position of the divider
1723 gtk_paned_get_position (GtkPaned *paned)
1725 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1727 return paned->priv->child1_size;
1731 * gtk_paned_set_position:
1732 * @paned: a #GtkPaned widget
1733 * @position: pixel position of divider, a negative value means that the position
1736 * Sets the position of the divider between the two panes.
1739 gtk_paned_set_position (GtkPaned *paned,
1742 GtkPanedPrivate *priv;
1745 g_return_if_fail (GTK_IS_PANED (paned));
1749 if (priv->child1_size == position)
1752 object = G_OBJECT (paned);
1756 /* We don't clamp here - the assumption is that
1757 * if the total allocation changes at the same time
1758 * as the position, the position set is with reference
1759 * to the new total size. If only the position changes,
1760 * then clamping will occur in gtk_paned_calc_position()
1763 priv->child1_size = position;
1764 priv->position_set = TRUE;
1768 priv->position_set = FALSE;
1771 g_object_freeze_notify (object);
1772 g_object_notify (object, "position");
1773 g_object_notify (object, "position-set");
1774 g_object_thaw_notify (object);
1776 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1779 /* Hacky work-around for bug #144269 */
1780 if (priv->child2 != NULL)
1782 gtk_widget_queue_draw (priv->child2);
1788 * gtk_paned_get_child1:
1789 * @paned: a #GtkPaned widget
1791 * Obtains the first child of the paned widget.
1793 * Return value: (transfer none): first child, or %NULL if it is not set.
1798 gtk_paned_get_child1 (GtkPaned *paned)
1800 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1802 return paned->priv->child1;
1806 * gtk_paned_get_child2:
1807 * @paned: a #GtkPaned widget
1809 * Obtains the second child of the paned widget.
1811 * Return value: (transfer none): second child, or %NULL if it is not set.
1816 gtk_paned_get_child2 (GtkPaned *paned)
1818 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1820 return paned->priv->child2;
1824 gtk_paned_calc_position (GtkPaned *paned,
1829 GtkPanedPrivate *priv = paned->priv;
1831 gint old_min_position;
1832 gint old_max_position;
1834 old_position = priv->child1_size;
1835 old_min_position = priv->min_position;
1836 old_max_position = priv->max_position;
1838 priv->min_position = priv->child1_shrink ? 0 : child1_req;
1840 priv->max_position = allocation;
1841 if (!priv->child2_shrink)
1842 priv->max_position = MAX (1, priv->max_position - child2_req);
1843 priv->max_position = MAX (priv->min_position, priv->max_position);
1845 if (!priv->position_set)
1847 if (priv->child1_resize && !priv->child2_resize)
1848 priv->child1_size = MAX (0, allocation - child2_req);
1849 else if (!priv->child1_resize && priv->child2_resize)
1850 priv->child1_size = child1_req;
1851 else if (child1_req + child2_req != 0)
1852 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1854 priv->child1_size = allocation * 0.5 + 0.5;
1858 /* If the position was set before the initial allocation.
1859 * (priv->last_allocation <= 0) just clamp it and leave it.
1861 if (priv->last_allocation > 0)
1863 if (priv->child1_resize && !priv->child2_resize)
1864 priv->child1_size += allocation - priv->last_allocation;
1865 else if (!(!priv->child1_resize && priv->child2_resize))
1866 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
1870 priv->child1_size = CLAMP (priv->child1_size,
1872 priv->max_position);
1875 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
1878 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
1880 g_object_freeze_notify (G_OBJECT (paned));
1881 if (priv->child1_size != old_position)
1882 g_object_notify (G_OBJECT (paned), "position");
1883 if (priv->min_position != old_min_position)
1884 g_object_notify (G_OBJECT (paned), "min-position");
1885 if (priv->max_position != old_max_position)
1886 g_object_notify (G_OBJECT (paned), "max-position");
1887 g_object_thaw_notify (G_OBJECT (paned));
1889 priv->last_allocation = allocation;
1893 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1895 GtkPanedPrivate *priv = paned->priv;
1897 if (priv->saved_focus)
1898 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
1899 (gpointer *)&(priv->saved_focus));
1901 priv->saved_focus = widget;
1903 if (priv->saved_focus)
1904 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
1905 (gpointer *)&(priv->saved_focus));
1909 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1911 GtkPanedPrivate *priv = paned->priv;
1913 if (priv->first_paned)
1914 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
1915 (gpointer *)&(priv->first_paned));
1917 priv->first_paned = first_paned;
1919 if (priv->first_paned)
1920 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
1921 (gpointer *)&(priv->first_paned));
1925 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1927 GtkPanedPrivate *priv = paned->priv;
1929 if (priv->last_child1_focus)
1930 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
1931 (gpointer *)&(priv->last_child1_focus));
1933 priv->last_child1_focus = widget;
1935 if (priv->last_child1_focus)
1936 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
1937 (gpointer *)&(priv->last_child1_focus));
1941 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1943 GtkPanedPrivate *priv = paned->priv;
1945 if (priv->last_child2_focus)
1946 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
1947 (gpointer *)&(priv->last_child2_focus));
1949 priv->last_child2_focus = widget;
1951 if (priv->last_child2_focus)
1952 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
1953 (gpointer *)&(priv->last_child2_focus));
1957 paned_get_focus_widget (GtkPaned *paned)
1959 GtkWidget *toplevel;
1961 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1962 if (gtk_widget_is_toplevel (toplevel))
1963 return gtk_window_get_focus (GTK_WINDOW (toplevel));
1969 gtk_paned_set_focus_child (GtkContainer *container,
1970 GtkWidget *focus_child)
1973 GtkPanedPrivate *priv;
1974 GtkWidget *container_focus_child;
1976 g_return_if_fail (GTK_IS_PANED (container));
1978 paned = GTK_PANED (container);
1981 if (focus_child == NULL)
1983 GtkWidget *last_focus;
1986 last_focus = paned_get_focus_widget (paned);
1990 /* If there is one or more paned widgets between us and the
1991 * focus widget, we want the topmost of those as last_focus
1993 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
1994 if (GTK_IS_PANED (w))
1997 container_focus_child = gtk_container_get_focus_child (container);
1998 if (container_focus_child == priv->child1)
1999 gtk_paned_set_last_child1_focus (paned, last_focus);
2000 else if (container_focus_child == priv->child2)
2001 gtk_paned_set_last_child2_focus (paned, last_focus);
2005 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2006 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2010 gtk_paned_get_cycle_chain (GtkPaned *paned,
2011 GtkDirectionType direction,
2014 GtkPanedPrivate *priv = paned->priv;
2015 GtkContainer *container = GTK_CONTAINER (paned);
2016 GtkWidget *ancestor = NULL;
2017 GtkWidget *focus_child;
2019 GtkWidget *widget = GTK_WIDGET (paned);
2020 GList *temp_list = NULL;
2023 if (priv->in_recursion)
2026 g_assert (widgets != NULL);
2028 if (priv->last_child1_focus &&
2029 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2031 gtk_paned_set_last_child1_focus (paned, NULL);
2034 if (priv->last_child2_focus &&
2035 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2037 gtk_paned_set_last_child2_focus (paned, NULL);
2040 parent = gtk_widget_get_parent (widget);
2042 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2044 /* The idea here is that temp_list is a list of widgets we want to cycle
2045 * to. The list is prioritized so that the first element is our first
2046 * choice, the next our second, and so on.
2048 * We can't just use g_list_reverse(), because we want to try
2049 * priv->last_child?_focus before priv->child?, both when we
2050 * are going forward and backward.
2052 focus_child = gtk_container_get_focus_child (container);
2053 if (direction == GTK_DIR_TAB_FORWARD)
2055 if (focus_child == priv->child1)
2057 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2058 temp_list = g_list_append (temp_list, priv->child2);
2059 temp_list = g_list_append (temp_list, ancestor);
2061 else if (focus_child == priv->child2)
2063 temp_list = g_list_append (temp_list, ancestor);
2064 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2065 temp_list = g_list_append (temp_list, priv->child1);
2069 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2070 temp_list = g_list_append (temp_list, priv->child1);
2071 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2072 temp_list = g_list_append (temp_list, priv->child2);
2073 temp_list = g_list_append (temp_list, ancestor);
2078 if (focus_child == priv->child1)
2080 temp_list = g_list_append (temp_list, ancestor);
2081 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2082 temp_list = g_list_append (temp_list, priv->child2);
2084 else if (focus_child == priv->child2)
2086 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2087 temp_list = g_list_append (temp_list, priv->child1);
2088 temp_list = g_list_append (temp_list, ancestor);
2092 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2093 temp_list = g_list_append (temp_list, priv->child2);
2094 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2095 temp_list = g_list_append (temp_list, priv->child1);
2096 temp_list = g_list_append (temp_list, ancestor);
2100 /* Walk the list and expand all the paned widgets. */
2101 for (list = temp_list; list != NULL; list = list->next)
2103 GtkWidget *widget = list->data;
2107 if (GTK_IS_PANED (widget))
2109 priv->in_recursion = TRUE;
2110 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2111 priv->in_recursion = FALSE;
2115 *widgets = g_list_append (*widgets, widget);
2120 g_list_free (temp_list);
2124 gtk_paned_cycle_child_focus (GtkPaned *paned,
2127 GList *cycle_chain = NULL;
2130 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2132 /* ignore f6 if the handle is focused */
2133 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2136 /* we can't just let the event propagate up the hierarchy,
2137 * because the paned will want to cycle focus _unless_ an
2138 * ancestor paned handles the event
2140 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2142 for (list = cycle_chain; list != NULL; list = list->next)
2143 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2146 g_list_free (cycle_chain);
2152 get_child_panes (GtkWidget *widget,
2155 if (!widget || !gtk_widget_get_realized (widget))
2158 if (GTK_IS_PANED (widget))
2160 GtkPaned *paned = GTK_PANED (widget);
2161 GtkPanedPrivate *priv = paned->priv;
2163 get_child_panes (priv->child1, panes);
2164 *panes = g_list_prepend (*panes, widget);
2165 get_child_panes (priv->child2, panes);
2167 else if (GTK_IS_CONTAINER (widget))
2169 gtk_container_forall (GTK_CONTAINER (widget),
2170 (GtkCallback)get_child_panes, panes);
2175 get_all_panes (GtkPaned *paned)
2177 GtkPaned *topmost = NULL;
2178 GList *result = NULL;
2181 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2183 if (GTK_IS_PANED (w))
2184 topmost = GTK_PANED (w);
2189 get_child_panes (GTK_WIDGET (topmost), &result);
2191 return g_list_reverse (result);
2195 gtk_paned_find_neighbours (GtkPaned *paned,
2202 all_panes = get_all_panes (paned);
2203 g_assert (all_panes);
2205 this_link = g_list_find (all_panes, paned);
2207 g_assert (this_link);
2209 if (this_link->next)
2210 *next = this_link->next->data;
2212 *next = all_panes->data;
2214 if (this_link->prev)
2215 *prev = this_link->prev->data;
2217 *prev = g_list_last (all_panes)->data;
2219 g_list_free (all_panes);
2223 gtk_paned_move_handle (GtkPaned *paned,
2224 GtkScrollType scroll)
2226 GtkPanedPrivate *priv = paned->priv;
2228 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2235 SINGLE_STEP_SIZE = 1,
2239 new_position = old_position = gtk_paned_get_position (paned);
2244 case GTK_SCROLL_STEP_LEFT:
2245 case GTK_SCROLL_STEP_UP:
2246 case GTK_SCROLL_STEP_BACKWARD:
2247 increment = - SINGLE_STEP_SIZE;
2250 case GTK_SCROLL_STEP_RIGHT:
2251 case GTK_SCROLL_STEP_DOWN:
2252 case GTK_SCROLL_STEP_FORWARD:
2253 increment = SINGLE_STEP_SIZE;
2256 case GTK_SCROLL_PAGE_LEFT:
2257 case GTK_SCROLL_PAGE_UP:
2258 case GTK_SCROLL_PAGE_BACKWARD:
2259 increment = - PAGE_STEP_SIZE;
2262 case GTK_SCROLL_PAGE_RIGHT:
2263 case GTK_SCROLL_PAGE_DOWN:
2264 case GTK_SCROLL_PAGE_FORWARD:
2265 increment = PAGE_STEP_SIZE;
2268 case GTK_SCROLL_START:
2269 new_position = priv->min_position;
2272 case GTK_SCROLL_END:
2273 new_position = priv->max_position;
2283 increment = -increment;
2285 new_position = old_position + increment;
2288 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2290 if (old_position != new_position)
2291 gtk_paned_set_position (paned, new_position);
2300 gtk_paned_restore_focus (GtkPaned *paned)
2302 GtkPanedPrivate *priv = paned->priv;
2304 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2306 if (priv->saved_focus &&
2307 gtk_widget_get_sensitive (priv->saved_focus))
2309 gtk_widget_grab_focus (priv->saved_focus);
2313 /* the saved focus is somehow not available for focusing,
2315 * 1) tabbing into the paned widget
2316 * if that didn't work,
2317 * 2) unset focus for the window if there is one
2320 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2322 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2324 if (GTK_IS_WINDOW (toplevel))
2325 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2329 gtk_paned_set_saved_focus (paned, NULL);
2330 gtk_paned_set_first_paned (paned, NULL);
2335 gtk_paned_accept_position (GtkPaned *paned)
2337 GtkPanedPrivate *priv = paned->priv;
2339 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2341 priv->original_position = -1;
2342 gtk_paned_restore_focus (paned);
2352 gtk_paned_cancel_position (GtkPaned *paned)
2354 GtkPanedPrivate *priv = paned->priv;
2356 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2358 if (priv->original_position != -1)
2360 gtk_paned_set_position (paned, priv->original_position);
2361 priv->original_position = -1;
2364 gtk_paned_restore_focus (paned);
2372 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2375 GtkPanedPrivate *priv = paned->priv;
2376 GtkPaned *next, *prev;
2378 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2380 GtkPaned *focus = NULL;
2382 if (!priv->first_paned)
2384 /* The first_pane has disappeared. As an ad-hoc solution,
2385 * we make the currently focused paned the first_paned. To the
2386 * user this will seem like the paned cycling has been reset.
2389 gtk_paned_set_first_paned (paned, paned);
2392 gtk_paned_find_neighbours (paned, &next, &prev);
2394 if (reversed && prev &&
2395 prev != paned && paned != priv->first_paned)
2399 else if (!reversed && next &&
2400 next != paned && next != priv->first_paned)
2406 gtk_paned_accept_position (paned);
2412 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2413 gtk_paned_set_first_paned (focus, priv->first_paned);
2415 gtk_paned_set_saved_focus (paned, NULL);
2416 gtk_paned_set_first_paned (paned, NULL);
2418 gtk_widget_grab_focus (GTK_WIDGET (focus));
2420 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2422 priv->original_position = -1;
2423 focus->priv->original_position = gtk_paned_get_position (focus);
2428 GtkContainer *container = GTK_CONTAINER (paned);
2431 GtkPaned *prev, *next;
2432 GtkWidget *toplevel;
2433 GtkWidget *focus_child;
2435 gtk_paned_find_neighbours (paned, &next, &prev);
2436 focus_child = gtk_container_get_focus_child (container);
2438 if (focus_child == priv->child1)
2451 else if (focus_child == priv->child2)
2466 /* Focus is not inside this paned, and we don't have focus.
2467 * Presumably this happened because the application wants us
2468 * to start keyboard navigating.
2478 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2480 if (GTK_IS_WINDOW (toplevel))
2481 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2482 gtk_paned_set_first_paned (focus, first);
2483 focus->priv->original_position = gtk_paned_get_position (focus);
2485 gtk_widget_grab_focus (GTK_WIDGET (focus));
2492 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2494 /* This function/signal has the wrong name. It is called when you
2495 * press Tab or Shift-Tab and what we do is act as if
2496 * the user pressed Return and then Tab or Shift-Tab
2498 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2499 gtk_paned_accept_position (paned);
2505 * gtk_paned_get_handle_window:
2506 * @paned: a #GtkPaned
2508 * Returns the #GdkWindow of the handle. This function is
2509 * useful when handling button or motion events because it
2510 * enables the callback to distinguish between the window
2511 * of the paned, a child and the handle.
2513 * Return value: (transfer none): the paned's handle window.
2518 gtk_paned_get_handle_window (GtkPaned *paned)
2520 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2522 return paned->priv->handle;