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);
1191 gtk_paned_unrealize (GtkWidget *widget)
1193 GtkPaned *paned = GTK_PANED (widget);
1194 GtkPanedPrivate *priv = paned->priv;
1198 gdk_window_set_user_data (priv->handle, NULL);
1199 gdk_window_destroy (priv->handle);
1200 priv->handle = NULL;
1203 gtk_paned_set_last_child1_focus (paned, NULL);
1204 gtk_paned_set_last_child2_focus (paned, NULL);
1205 gtk_paned_set_saved_focus (paned, NULL);
1206 gtk_paned_set_first_paned (paned, NULL);
1208 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1212 gtk_paned_map (GtkWidget *widget)
1214 GtkPaned *paned = GTK_PANED (widget);
1215 GtkPanedPrivate *priv = paned->priv;
1217 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1218 priv->child2 && gtk_widget_get_visible (priv->child2))
1219 gdk_window_show (priv->handle);
1221 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1225 gtk_paned_unmap (GtkWidget *widget)
1227 GtkPaned *paned = GTK_PANED (widget);
1228 GtkPanedPrivate *priv = paned->priv;
1230 gdk_window_hide (priv->handle);
1232 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1236 gtk_paned_draw (GtkWidget *widget,
1239 GtkPaned *paned = GTK_PANED (widget);
1240 GtkPanedPrivate *priv = paned->priv;
1242 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1243 priv->child2 && gtk_widget_get_visible (priv->child2))
1245 GtkStyleContext *context;
1246 GtkStateFlags state;
1247 GtkAllocation allocation;
1249 gtk_widget_get_allocation (widget, &allocation);
1250 context = gtk_widget_get_style_context (widget);
1251 state = gtk_widget_get_state_flags (widget);
1253 if (gtk_widget_is_focus (widget))
1254 state |= GTK_STATE_FLAG_SELECTED;
1255 if (priv->handle_prelit)
1256 state |= GTK_STATE_FLAG_PRELIGHT;
1258 gtk_style_context_save (context);
1259 gtk_style_context_set_state (context, state);
1260 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1261 gtk_render_handle (context, cr,
1262 priv->handle_pos.x - allocation.x,
1263 priv->handle_pos.y - allocation.y,
1264 priv->handle_pos.width,
1265 priv->handle_pos.height);
1267 gtk_style_context_restore (context);
1270 /* Chain up to draw children */
1271 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1277 is_rtl (GtkPaned *paned)
1279 GtkPanedPrivate *priv = paned->priv;
1281 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1282 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1291 update_drag (GtkPaned *paned)
1293 GtkPanedPrivate *priv = paned->priv;
1294 GtkAllocation allocation;
1295 GtkWidget *widget = GTK_WIDGET (paned);
1300 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1301 gtk_widget_get_pointer (widget, &pos, NULL);
1303 gtk_widget_get_pointer (widget, NULL, &pos);
1305 pos -= priv->drag_pos;
1309 gtk_widget_style_get (widget,
1310 "handle-size", &handle_size,
1313 gtk_widget_get_allocation (widget, &allocation);
1314 size = allocation.width - pos - handle_size;
1321 size = CLAMP (size, priv->min_position, priv->max_position);
1323 if (size != priv->child1_size)
1324 gtk_paned_set_position (paned, size);
1328 gtk_paned_enter (GtkWidget *widget,
1329 GdkEventCrossing *event)
1331 GtkPaned *paned = GTK_PANED (widget);
1332 GtkPanedPrivate *priv = paned->priv;
1335 update_drag (paned);
1338 priv->handle_prelit = TRUE;
1339 gtk_widget_queue_draw_area (widget,
1342 priv->handle_pos.width,
1343 priv->handle_pos.height);
1350 gtk_paned_leave (GtkWidget *widget,
1351 GdkEventCrossing *event)
1353 GtkPaned *paned = GTK_PANED (widget);
1354 GtkPanedPrivate *priv = paned->priv;
1357 update_drag (paned);
1360 priv->handle_prelit = FALSE;
1361 gtk_widget_queue_draw_area (widget,
1364 priv->handle_pos.width,
1365 priv->handle_pos.height);
1372 gtk_paned_focus (GtkWidget *widget,
1373 GtkDirectionType direction)
1378 /* This is a hack, but how can this be done without
1379 * excessive cut-and-paste from gtkcontainer.c?
1382 gtk_widget_set_can_focus (widget, FALSE);
1383 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1384 gtk_widget_set_can_focus (widget, TRUE);
1390 gtk_paned_button_press (GtkWidget *widget,
1391 GdkEventButton *event)
1393 GtkPaned *paned = GTK_PANED (widget);
1394 GtkPanedPrivate *priv = paned->priv;
1396 if (!priv->in_drag &&
1397 (event->window == priv->handle) && (event->button == 1))
1399 /* We need a server grab here, not gtk_grab_add(), since
1400 * we don't want to pass events on to the widget's children */
1401 if (gdk_device_grab (event->device,
1403 GDK_OWNERSHIP_WINDOW, FALSE,
1404 GDK_POINTER_MOTION_HINT_MASK
1405 | GDK_BUTTON1_MOTION_MASK
1406 | GDK_BUTTON_RELEASE_MASK
1407 | GDK_ENTER_NOTIFY_MASK
1408 | GDK_LEAVE_NOTIFY_MASK,
1409 NULL, event->time) != GDK_GRAB_SUCCESS)
1412 priv->in_drag = TRUE;
1413 priv->grab_time = event->time;
1414 priv->grab_device = event->device;
1416 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1417 priv->drag_pos = event->x;
1419 priv->drag_pos = event->y;
1428 gtk_paned_grab_broken (GtkWidget *widget,
1429 GdkEventGrabBroken *event)
1431 GtkPaned *paned = GTK_PANED (widget);
1432 GtkPanedPrivate *priv = paned->priv;
1434 priv->in_drag = FALSE;
1435 priv->drag_pos = -1;
1436 priv->position_set = TRUE;
1442 stop_drag (GtkPaned *paned)
1444 GtkPanedPrivate *priv = paned->priv;
1446 priv->in_drag = FALSE;
1447 priv->drag_pos = -1;
1448 priv->position_set = TRUE;
1450 gdk_device_ungrab (priv->grab_device,
1452 priv->grab_device = NULL;
1456 gtk_paned_grab_notify (GtkWidget *widget,
1457 gboolean was_grabbed)
1459 GtkPaned *paned = GTK_PANED (widget);
1460 GtkPanedPrivate *priv = paned->priv;
1461 GdkDevice *grab_device;
1463 grab_device = priv->grab_device;
1465 if (priv->in_drag && grab_device &&
1466 gtk_widget_device_is_shadowed (widget, grab_device))
1471 gtk_paned_state_flags_changed (GtkWidget *widget,
1472 GtkStateFlags previous_state)
1474 GtkPaned *paned = GTK_PANED (widget);
1475 GtkPanedPrivate *priv = paned->priv;
1478 if (gtk_widget_get_realized (widget))
1480 if (gtk_widget_is_sensitive (widget))
1481 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1486 gdk_window_set_cursor (priv->handle, cursor);
1489 g_object_unref (cursor);
1494 gtk_paned_button_release (GtkWidget *widget,
1495 GdkEventButton *event)
1497 GtkPaned *paned = GTK_PANED (widget);
1498 GtkPanedPrivate *priv = paned->priv;
1500 if (priv->in_drag && (event->button == 1))
1511 gtk_paned_motion (GtkWidget *widget,
1512 GdkEventMotion *event)
1514 GtkPaned *paned = GTK_PANED (widget);
1515 GtkPanedPrivate *priv = paned->priv;
1519 update_drag (paned);
1528 * @orientation: the paned's orientation.
1530 * Creates a new #GtkPaned widget.
1532 * Return value: a new #GtkPaned.
1537 gtk_paned_new (GtkOrientation orientation)
1539 return g_object_new (GTK_TYPE_PANED,
1540 "orientation", orientation,
1546 * @paned: a paned widget
1547 * @child: the child to add
1549 * Adds a child to the top or left pane with default parameters. This is
1551 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1554 gtk_paned_add1 (GtkPaned *paned,
1557 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1562 * @paned: a paned widget
1563 * @child: the child to add
1565 * Adds a child to the bottom or right pane with default parameters. This
1567 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1570 gtk_paned_add2 (GtkPaned *paned,
1573 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1578 * @paned: a paned widget
1579 * @child: the child to add
1580 * @resize: should this child expand when the paned widget is resized.
1581 * @shrink: can this child be made smaller than its requisition.
1583 * Adds a child to the top or left pane.
1586 gtk_paned_pack1 (GtkPaned *paned,
1591 GtkPanedPrivate *priv;
1593 g_return_if_fail (GTK_IS_PANED (paned));
1594 g_return_if_fail (GTK_IS_WIDGET (child));
1600 priv->child1 = child;
1601 priv->child1_resize = resize;
1602 priv->child1_shrink = shrink;
1604 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1610 * @paned: a paned widget
1611 * @child: the child to add
1612 * @resize: should this child expand when the paned widget is resized.
1613 * @shrink: can this child be made smaller than its requisition.
1615 * Adds a child to the bottom or right pane.
1618 gtk_paned_pack2 (GtkPaned *paned,
1623 GtkPanedPrivate *priv;
1625 g_return_if_fail (GTK_IS_PANED (paned));
1626 g_return_if_fail (GTK_IS_WIDGET (child));
1632 priv->child2 = child;
1633 priv->child2_resize = resize;
1634 priv->child2_shrink = shrink;
1636 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1642 gtk_paned_add (GtkContainer *container,
1645 GtkPanedPrivate *priv;
1648 g_return_if_fail (GTK_IS_PANED (container));
1650 paned = GTK_PANED (container);
1654 gtk_paned_add1 (paned, widget);
1655 else if (!priv->child2)
1656 gtk_paned_add2 (paned, widget);
1658 g_warning ("GtkPaned cannot have more than 2 children\n");
1662 gtk_paned_remove (GtkContainer *container,
1665 GtkPaned *paned = GTK_PANED (container);
1666 GtkPanedPrivate *priv = paned->priv;
1667 gboolean was_visible;
1669 was_visible = gtk_widget_get_visible (widget);
1671 if (priv->child1 == widget)
1673 gtk_widget_unparent (widget);
1675 priv->child1 = NULL;
1677 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1678 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1680 else if (priv->child2 == widget)
1682 gtk_widget_unparent (widget);
1684 priv->child2 = NULL;
1686 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1687 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1692 gtk_paned_forall (GtkContainer *container,
1693 gboolean include_internals,
1694 GtkCallback callback,
1695 gpointer callback_data)
1697 GtkPanedPrivate *priv;
1700 g_return_if_fail (callback != NULL);
1702 paned = GTK_PANED (container);
1706 (*callback) (priv->child1, callback_data);
1708 (*callback) (priv->child2, callback_data);
1712 * gtk_paned_get_position:
1713 * @paned: a #GtkPaned widget
1715 * Obtains the position of the divider between the two panes.
1717 * Return value: position of the divider
1720 gtk_paned_get_position (GtkPaned *paned)
1722 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1724 return paned->priv->child1_size;
1728 * gtk_paned_set_position:
1729 * @paned: a #GtkPaned widget
1730 * @position: pixel position of divider, a negative value means that the position
1733 * Sets the position of the divider between the two panes.
1736 gtk_paned_set_position (GtkPaned *paned,
1739 GtkPanedPrivate *priv;
1742 g_return_if_fail (GTK_IS_PANED (paned));
1746 if (priv->child1_size == position)
1749 object = G_OBJECT (paned);
1753 /* We don't clamp here - the assumption is that
1754 * if the total allocation changes at the same time
1755 * as the position, the position set is with reference
1756 * to the new total size. If only the position changes,
1757 * then clamping will occur in gtk_paned_calc_position()
1760 priv->child1_size = position;
1761 priv->position_set = TRUE;
1765 priv->position_set = FALSE;
1768 g_object_freeze_notify (object);
1769 g_object_notify (object, "position");
1770 g_object_notify (object, "position-set");
1771 g_object_thaw_notify (object);
1773 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1776 /* Hacky work-around for bug #144269 */
1777 if (priv->child2 != NULL)
1779 gtk_widget_queue_draw (priv->child2);
1785 * gtk_paned_get_child1:
1786 * @paned: a #GtkPaned widget
1788 * Obtains the first child of the paned widget.
1790 * Return value: (transfer none): first child, or %NULL if it is not set.
1795 gtk_paned_get_child1 (GtkPaned *paned)
1797 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1799 return paned->priv->child1;
1803 * gtk_paned_get_child2:
1804 * @paned: a #GtkPaned widget
1806 * Obtains the second child of the paned widget.
1808 * Return value: (transfer none): second child, or %NULL if it is not set.
1813 gtk_paned_get_child2 (GtkPaned *paned)
1815 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1817 return paned->priv->child2;
1821 gtk_paned_calc_position (GtkPaned *paned,
1826 GtkPanedPrivate *priv = paned->priv;
1828 gint old_min_position;
1829 gint old_max_position;
1831 old_position = priv->child1_size;
1832 old_min_position = priv->min_position;
1833 old_max_position = priv->max_position;
1835 priv->min_position = priv->child1_shrink ? 0 : child1_req;
1837 priv->max_position = allocation;
1838 if (!priv->child2_shrink)
1839 priv->max_position = MAX (1, priv->max_position - child2_req);
1840 priv->max_position = MAX (priv->min_position, priv->max_position);
1842 if (!priv->position_set)
1844 if (priv->child1_resize && !priv->child2_resize)
1845 priv->child1_size = MAX (0, allocation - child2_req);
1846 else if (!priv->child1_resize && priv->child2_resize)
1847 priv->child1_size = child1_req;
1848 else if (child1_req + child2_req != 0)
1849 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
1851 priv->child1_size = allocation * 0.5 + 0.5;
1855 /* If the position was set before the initial allocation.
1856 * (priv->last_allocation <= 0) just clamp it and leave it.
1858 if (priv->last_allocation > 0)
1860 if (priv->child1_resize && !priv->child2_resize)
1861 priv->child1_size += allocation - priv->last_allocation;
1862 else if (!(!priv->child1_resize && priv->child2_resize))
1863 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
1867 priv->child1_size = CLAMP (priv->child1_size,
1869 priv->max_position);
1872 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
1875 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
1877 g_object_freeze_notify (G_OBJECT (paned));
1878 if (priv->child1_size != old_position)
1879 g_object_notify (G_OBJECT (paned), "position");
1880 if (priv->min_position != old_min_position)
1881 g_object_notify (G_OBJECT (paned), "min-position");
1882 if (priv->max_position != old_max_position)
1883 g_object_notify (G_OBJECT (paned), "max-position");
1884 g_object_thaw_notify (G_OBJECT (paned));
1886 priv->last_allocation = allocation;
1890 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
1892 GtkPanedPrivate *priv = paned->priv;
1894 if (priv->saved_focus)
1895 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
1896 (gpointer *)&(priv->saved_focus));
1898 priv->saved_focus = widget;
1900 if (priv->saved_focus)
1901 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
1902 (gpointer *)&(priv->saved_focus));
1906 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
1908 GtkPanedPrivate *priv = paned->priv;
1910 if (priv->first_paned)
1911 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
1912 (gpointer *)&(priv->first_paned));
1914 priv->first_paned = first_paned;
1916 if (priv->first_paned)
1917 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
1918 (gpointer *)&(priv->first_paned));
1922 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
1924 GtkPanedPrivate *priv = paned->priv;
1926 if (priv->last_child1_focus)
1927 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
1928 (gpointer *)&(priv->last_child1_focus));
1930 priv->last_child1_focus = widget;
1932 if (priv->last_child1_focus)
1933 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
1934 (gpointer *)&(priv->last_child1_focus));
1938 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
1940 GtkPanedPrivate *priv = paned->priv;
1942 if (priv->last_child2_focus)
1943 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
1944 (gpointer *)&(priv->last_child2_focus));
1946 priv->last_child2_focus = widget;
1948 if (priv->last_child2_focus)
1949 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
1950 (gpointer *)&(priv->last_child2_focus));
1954 paned_get_focus_widget (GtkPaned *paned)
1956 GtkWidget *toplevel;
1958 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
1959 if (gtk_widget_is_toplevel (toplevel))
1960 return gtk_window_get_focus (GTK_WINDOW (toplevel));
1966 gtk_paned_set_focus_child (GtkContainer *container,
1967 GtkWidget *focus_child)
1970 GtkPanedPrivate *priv;
1971 GtkWidget *container_focus_child;
1973 g_return_if_fail (GTK_IS_PANED (container));
1975 paned = GTK_PANED (container);
1978 if (focus_child == NULL)
1980 GtkWidget *last_focus;
1983 last_focus = paned_get_focus_widget (paned);
1987 /* If there is one or more paned widgets between us and the
1988 * focus widget, we want the topmost of those as last_focus
1990 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
1991 if (GTK_IS_PANED (w))
1994 container_focus_child = gtk_container_get_focus_child (container);
1995 if (container_focus_child == priv->child1)
1996 gtk_paned_set_last_child1_focus (paned, last_focus);
1997 else if (container_focus_child == priv->child2)
1998 gtk_paned_set_last_child2_focus (paned, last_focus);
2002 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2003 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2007 gtk_paned_get_cycle_chain (GtkPaned *paned,
2008 GtkDirectionType direction,
2011 GtkPanedPrivate *priv = paned->priv;
2012 GtkContainer *container = GTK_CONTAINER (paned);
2013 GtkWidget *ancestor = NULL;
2014 GtkWidget *focus_child;
2016 GtkWidget *widget = GTK_WIDGET (paned);
2017 GList *temp_list = NULL;
2020 if (priv->in_recursion)
2023 g_assert (widgets != NULL);
2025 if (priv->last_child1_focus &&
2026 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2028 gtk_paned_set_last_child1_focus (paned, NULL);
2031 if (priv->last_child2_focus &&
2032 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2034 gtk_paned_set_last_child2_focus (paned, NULL);
2037 parent = gtk_widget_get_parent (widget);
2039 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2041 /* The idea here is that temp_list is a list of widgets we want to cycle
2042 * to. The list is prioritized so that the first element is our first
2043 * choice, the next our second, and so on.
2045 * We can't just use g_list_reverse(), because we want to try
2046 * priv->last_child?_focus before priv->child?, both when we
2047 * are going forward and backward.
2049 focus_child = gtk_container_get_focus_child (container);
2050 if (direction == GTK_DIR_TAB_FORWARD)
2052 if (focus_child == priv->child1)
2054 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2055 temp_list = g_list_append (temp_list, priv->child2);
2056 temp_list = g_list_append (temp_list, ancestor);
2058 else if (focus_child == priv->child2)
2060 temp_list = g_list_append (temp_list, ancestor);
2061 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2062 temp_list = g_list_append (temp_list, priv->child1);
2066 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2067 temp_list = g_list_append (temp_list, priv->child1);
2068 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2069 temp_list = g_list_append (temp_list, priv->child2);
2070 temp_list = g_list_append (temp_list, ancestor);
2075 if (focus_child == priv->child1)
2077 temp_list = g_list_append (temp_list, ancestor);
2078 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2079 temp_list = g_list_append (temp_list, priv->child2);
2081 else if (focus_child == priv->child2)
2083 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2084 temp_list = g_list_append (temp_list, priv->child1);
2085 temp_list = g_list_append (temp_list, ancestor);
2089 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2090 temp_list = g_list_append (temp_list, priv->child2);
2091 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2092 temp_list = g_list_append (temp_list, priv->child1);
2093 temp_list = g_list_append (temp_list, ancestor);
2097 /* Walk the list and expand all the paned widgets. */
2098 for (list = temp_list; list != NULL; list = list->next)
2100 GtkWidget *widget = list->data;
2104 if (GTK_IS_PANED (widget))
2106 priv->in_recursion = TRUE;
2107 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2108 priv->in_recursion = FALSE;
2112 *widgets = g_list_append (*widgets, widget);
2117 g_list_free (temp_list);
2121 gtk_paned_cycle_child_focus (GtkPaned *paned,
2124 GList *cycle_chain = NULL;
2127 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2129 /* ignore f6 if the handle is focused */
2130 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2133 /* we can't just let the event propagate up the hierarchy,
2134 * because the paned will want to cycle focus _unless_ an
2135 * ancestor paned handles the event
2137 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2139 for (list = cycle_chain; list != NULL; list = list->next)
2140 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2143 g_list_free (cycle_chain);
2149 get_child_panes (GtkWidget *widget,
2152 if (!widget || !gtk_widget_get_realized (widget))
2155 if (GTK_IS_PANED (widget))
2157 GtkPaned *paned = GTK_PANED (widget);
2158 GtkPanedPrivate *priv = paned->priv;
2160 get_child_panes (priv->child1, panes);
2161 *panes = g_list_prepend (*panes, widget);
2162 get_child_panes (priv->child2, panes);
2164 else if (GTK_IS_CONTAINER (widget))
2166 gtk_container_forall (GTK_CONTAINER (widget),
2167 (GtkCallback)get_child_panes, panes);
2172 get_all_panes (GtkPaned *paned)
2174 GtkPaned *topmost = NULL;
2175 GList *result = NULL;
2178 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2180 if (GTK_IS_PANED (w))
2181 topmost = GTK_PANED (w);
2186 get_child_panes (GTK_WIDGET (topmost), &result);
2188 return g_list_reverse (result);
2192 gtk_paned_find_neighbours (GtkPaned *paned,
2199 all_panes = get_all_panes (paned);
2200 g_assert (all_panes);
2202 this_link = g_list_find (all_panes, paned);
2204 g_assert (this_link);
2206 if (this_link->next)
2207 *next = this_link->next->data;
2209 *next = all_panes->data;
2211 if (this_link->prev)
2212 *prev = this_link->prev->data;
2214 *prev = g_list_last (all_panes)->data;
2216 g_list_free (all_panes);
2220 gtk_paned_move_handle (GtkPaned *paned,
2221 GtkScrollType scroll)
2223 GtkPanedPrivate *priv = paned->priv;
2225 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2232 SINGLE_STEP_SIZE = 1,
2236 new_position = old_position = gtk_paned_get_position (paned);
2241 case GTK_SCROLL_STEP_LEFT:
2242 case GTK_SCROLL_STEP_UP:
2243 case GTK_SCROLL_STEP_BACKWARD:
2244 increment = - SINGLE_STEP_SIZE;
2247 case GTK_SCROLL_STEP_RIGHT:
2248 case GTK_SCROLL_STEP_DOWN:
2249 case GTK_SCROLL_STEP_FORWARD:
2250 increment = SINGLE_STEP_SIZE;
2253 case GTK_SCROLL_PAGE_LEFT:
2254 case GTK_SCROLL_PAGE_UP:
2255 case GTK_SCROLL_PAGE_BACKWARD:
2256 increment = - PAGE_STEP_SIZE;
2259 case GTK_SCROLL_PAGE_RIGHT:
2260 case GTK_SCROLL_PAGE_DOWN:
2261 case GTK_SCROLL_PAGE_FORWARD:
2262 increment = PAGE_STEP_SIZE;
2265 case GTK_SCROLL_START:
2266 new_position = priv->min_position;
2269 case GTK_SCROLL_END:
2270 new_position = priv->max_position;
2280 increment = -increment;
2282 new_position = old_position + increment;
2285 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2287 if (old_position != new_position)
2288 gtk_paned_set_position (paned, new_position);
2297 gtk_paned_restore_focus (GtkPaned *paned)
2299 GtkPanedPrivate *priv = paned->priv;
2301 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2303 if (priv->saved_focus &&
2304 gtk_widget_get_sensitive (priv->saved_focus))
2306 gtk_widget_grab_focus (priv->saved_focus);
2310 /* the saved focus is somehow not available for focusing,
2312 * 1) tabbing into the paned widget
2313 * if that didn't work,
2314 * 2) unset focus for the window if there is one
2317 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2319 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2321 if (GTK_IS_WINDOW (toplevel))
2322 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2326 gtk_paned_set_saved_focus (paned, NULL);
2327 gtk_paned_set_first_paned (paned, NULL);
2332 gtk_paned_accept_position (GtkPaned *paned)
2334 GtkPanedPrivate *priv = paned->priv;
2336 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2338 priv->original_position = -1;
2339 gtk_paned_restore_focus (paned);
2349 gtk_paned_cancel_position (GtkPaned *paned)
2351 GtkPanedPrivate *priv = paned->priv;
2353 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2355 if (priv->original_position != -1)
2357 gtk_paned_set_position (paned, priv->original_position);
2358 priv->original_position = -1;
2361 gtk_paned_restore_focus (paned);
2369 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2372 GtkPanedPrivate *priv = paned->priv;
2373 GtkPaned *next, *prev;
2375 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2377 GtkPaned *focus = NULL;
2379 if (!priv->first_paned)
2381 /* The first_pane has disappeared. As an ad-hoc solution,
2382 * we make the currently focused paned the first_paned. To the
2383 * user this will seem like the paned cycling has been reset.
2386 gtk_paned_set_first_paned (paned, paned);
2389 gtk_paned_find_neighbours (paned, &next, &prev);
2391 if (reversed && prev &&
2392 prev != paned && paned != priv->first_paned)
2396 else if (!reversed && next &&
2397 next != paned && next != priv->first_paned)
2403 gtk_paned_accept_position (paned);
2409 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2410 gtk_paned_set_first_paned (focus, priv->first_paned);
2412 gtk_paned_set_saved_focus (paned, NULL);
2413 gtk_paned_set_first_paned (paned, NULL);
2415 gtk_widget_grab_focus (GTK_WIDGET (focus));
2417 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2419 priv->original_position = -1;
2420 focus->priv->original_position = gtk_paned_get_position (focus);
2425 GtkContainer *container = GTK_CONTAINER (paned);
2428 GtkPaned *prev, *next;
2429 GtkWidget *toplevel;
2430 GtkWidget *focus_child;
2432 gtk_paned_find_neighbours (paned, &next, &prev);
2433 focus_child = gtk_container_get_focus_child (container);
2435 if (focus_child == priv->child1)
2448 else if (focus_child == priv->child2)
2463 /* Focus is not inside this paned, and we don't have focus.
2464 * Presumably this happened because the application wants us
2465 * to start keyboard navigating.
2475 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2477 if (GTK_IS_WINDOW (toplevel))
2478 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2479 gtk_paned_set_first_paned (focus, first);
2480 focus->priv->original_position = gtk_paned_get_position (focus);
2482 gtk_widget_grab_focus (GTK_WIDGET (focus));
2489 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2491 /* This function/signal has the wrong name. It is called when you
2492 * press Tab or Shift-Tab and what we do is act as if
2493 * the user pressed Return and then Tab or Shift-Tab
2495 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2496 gtk_paned_accept_position (paned);
2502 * gtk_paned_get_handle_window:
2503 * @paned: a #GtkPaned
2505 * Returns the #GdkWindow of the handle. This function is
2506 * useful when handling button or motion events because it
2507 * enables the callback to distinguish between the window
2508 * of the paned, a child and the handle.
2510 * Return value: (transfer none): the paned's handle window.
2515 gtk_paned_get_handle_window (GtkPaned *paned)
2517 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2519 return paned->priv->handle;