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 GdkWindow *child1_window;
98 GdkWindow *child2_window;
99 GtkWidget *last_child1_focus;
100 GtkWidget *last_child2_focus;
101 GtkWidget *saved_focus;
102 GtkOrientation orientation;
104 GdkCursorType cursor_type;
105 GdkDevice *grab_device;
106 GdkRectangle handle_pos;
111 gint last_allocation;
114 gint original_position;
118 guint handle_prelit : 1;
120 guint in_recursion : 1;
121 guint child1_resize : 1;
122 guint child1_shrink : 1;
123 guint child2_resize : 1;
124 guint child2_shrink : 1;
125 guint position_set : 1;
153 static void gtk_paned_set_property (GObject *object,
157 static void gtk_paned_get_property (GObject *object,
161 static void gtk_paned_set_child_property (GtkContainer *container,
166 static void gtk_paned_get_child_property (GtkContainer *container,
171 static void gtk_paned_finalize (GObject *object);
173 static void gtk_paned_get_preferred_width (GtkWidget *widget,
176 static void gtk_paned_get_preferred_height (GtkWidget *widget,
179 static void gtk_paned_get_preferred_width_for_height
184 static void gtk_paned_get_preferred_height_for_width
190 static void gtk_paned_size_allocate (GtkWidget *widget,
191 GtkAllocation *allocation);
192 static void gtk_paned_realize (GtkWidget *widget);
193 static void gtk_paned_unrealize (GtkWidget *widget);
194 static void gtk_paned_map (GtkWidget *widget);
195 static void gtk_paned_unmap (GtkWidget *widget);
196 static void gtk_paned_state_flags_changed (GtkWidget *widget,
197 GtkStateFlags previous_state);
198 static gboolean gtk_paned_draw (GtkWidget *widget,
200 static gboolean gtk_paned_enter (GtkWidget *widget,
201 GdkEventCrossing *event);
202 static gboolean gtk_paned_leave (GtkWidget *widget,
203 GdkEventCrossing *event);
204 static gboolean gtk_paned_button_press (GtkWidget *widget,
205 GdkEventButton *event);
206 static gboolean gtk_paned_button_release (GtkWidget *widget,
207 GdkEventButton *event);
208 static gboolean gtk_paned_motion (GtkWidget *widget,
209 GdkEventMotion *event);
210 static gboolean gtk_paned_focus (GtkWidget *widget,
211 GtkDirectionType direction);
212 static gboolean gtk_paned_grab_broken (GtkWidget *widget,
213 GdkEventGrabBroken *event);
214 static void gtk_paned_add (GtkContainer *container,
216 static void gtk_paned_remove (GtkContainer *container,
218 static void gtk_paned_forall (GtkContainer *container,
219 gboolean include_internals,
220 GtkCallback callback,
221 gpointer callback_data);
222 static void gtk_paned_calc_position (GtkPaned *paned,
226 static void gtk_paned_set_focus_child (GtkContainer *container,
228 static void gtk_paned_set_saved_focus (GtkPaned *paned,
230 static void gtk_paned_set_first_paned (GtkPaned *paned,
231 GtkPaned *first_paned);
232 static void gtk_paned_set_last_child1_focus (GtkPaned *paned,
234 static void gtk_paned_set_last_child2_focus (GtkPaned *paned,
236 static gboolean gtk_paned_cycle_child_focus (GtkPaned *paned,
238 static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned,
240 static gboolean gtk_paned_move_handle (GtkPaned *paned,
241 GtkScrollType scroll);
242 static gboolean gtk_paned_accept_position (GtkPaned *paned);
243 static gboolean gtk_paned_cancel_position (GtkPaned *paned);
244 static gboolean gtk_paned_toggle_handle_focus (GtkPaned *paned);
246 static GType gtk_paned_child_type (GtkContainer *container);
247 static void gtk_paned_grab_notify (GtkWidget *widget,
248 gboolean was_grabbed);
251 G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
252 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
255 static guint signals[LAST_SIGNAL] = { 0 };
259 add_tab_bindings (GtkBindingSet *binding_set,
260 GdkModifierType modifiers)
262 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
263 "toggle-handle-focus", 0);
264 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
265 "toggle-handle-focus", 0);
269 add_move_binding (GtkBindingSet *binding_set,
271 GdkModifierType mask,
272 GtkScrollType scroll)
274 gtk_binding_entry_add_signal (binding_set, keyval, mask,
276 GTK_TYPE_SCROLL_TYPE, scroll);
280 gtk_paned_class_init (GtkPanedClass *class)
282 GObjectClass *object_class;
283 GtkWidgetClass *widget_class;
284 GtkContainerClass *container_class;
285 GtkPanedClass *paned_class;
286 GtkBindingSet *binding_set;
288 object_class = (GObjectClass *) class;
289 widget_class = (GtkWidgetClass *) class;
290 container_class = (GtkContainerClass *) class;
291 paned_class = (GtkPanedClass *) class;
293 object_class->set_property = gtk_paned_set_property;
294 object_class->get_property = gtk_paned_get_property;
295 object_class->finalize = gtk_paned_finalize;
297 widget_class->get_preferred_width = gtk_paned_get_preferred_width;
298 widget_class->get_preferred_height = gtk_paned_get_preferred_height;
299 widget_class->get_preferred_width_for_height = gtk_paned_get_preferred_width_for_height;
300 widget_class->get_preferred_height_for_width = gtk_paned_get_preferred_height_for_width;
301 widget_class->size_allocate = gtk_paned_size_allocate;
302 widget_class->realize = gtk_paned_realize;
303 widget_class->unrealize = gtk_paned_unrealize;
304 widget_class->map = gtk_paned_map;
305 widget_class->unmap = gtk_paned_unmap;
306 widget_class->draw = gtk_paned_draw;
307 widget_class->focus = gtk_paned_focus;
308 widget_class->enter_notify_event = gtk_paned_enter;
309 widget_class->leave_notify_event = gtk_paned_leave;
310 widget_class->button_press_event = gtk_paned_button_press;
311 widget_class->button_release_event = gtk_paned_button_release;
312 widget_class->motion_notify_event = gtk_paned_motion;
313 widget_class->grab_broken_event = gtk_paned_grab_broken;
314 widget_class->grab_notify = gtk_paned_grab_notify;
315 widget_class->state_flags_changed = gtk_paned_state_flags_changed;
317 container_class->add = gtk_paned_add;
318 container_class->remove = gtk_paned_remove;
319 container_class->forall = gtk_paned_forall;
320 container_class->child_type = gtk_paned_child_type;
321 container_class->set_focus_child = gtk_paned_set_focus_child;
322 container_class->set_child_property = gtk_paned_set_child_property;
323 container_class->get_child_property = gtk_paned_get_child_property;
324 gtk_container_class_handle_border_width (container_class);
326 paned_class->cycle_child_focus = gtk_paned_cycle_child_focus;
327 paned_class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
328 paned_class->move_handle = gtk_paned_move_handle;
329 paned_class->cycle_handle_focus = gtk_paned_cycle_handle_focus;
330 paned_class->accept_position = gtk_paned_accept_position;
331 paned_class->cancel_position = gtk_paned_cancel_position;
333 g_object_class_override_property (object_class,
337 g_object_class_install_property (object_class,
339 g_param_spec_int ("position",
341 P_("Position of paned separator in pixels (0 means all the way to the left/top)"),
345 GTK_PARAM_READWRITE));
347 g_object_class_install_property (object_class,
349 g_param_spec_boolean ("position-set",
351 P_("TRUE if the Position property should be used"),
353 GTK_PARAM_READWRITE));
355 gtk_widget_class_install_style_property (widget_class,
356 g_param_spec_int ("handle-size",
358 P_("Width of handle"),
362 GTK_PARAM_READABLE));
364 * GtkPaned:min-position:
366 * The smallest possible value for the position property. This property is derived from the
367 * size and shrinkability of the widget's children.
371 g_object_class_install_property (object_class,
373 g_param_spec_int ("min-position",
374 P_("Minimal Position"),
375 P_("Smallest possible value for the \"position\" property"),
379 GTK_PARAM_READABLE));
382 * GtkPaned:max-position:
384 * The largest possible value for the position property. This property is derived from the
385 * size and shrinkability of the widget's children.
389 g_object_class_install_property (object_class,
391 g_param_spec_int ("max-position",
392 P_("Maximal Position"),
393 P_("Largest possible value for the \"position\" property"),
397 GTK_PARAM_READABLE));
402 * The "resize" child property determines whether the child expands and
403 * shrinks along with the paned widget.
407 gtk_container_class_install_child_property (container_class,
409 g_param_spec_boolean ("resize",
411 P_("If TRUE, the child expands and shrinks along with the paned widget"),
413 GTK_PARAM_READWRITE));
418 * The "shrink" child property determines whether the child can be made
419 * smaller than its requisition.
423 gtk_container_class_install_child_property (container_class,
425 g_param_spec_boolean ("shrink",
427 P_("If TRUE, the child can be made smaller than its requisition"),
429 GTK_PARAM_READWRITE));
432 * GtkPaned::cycle-child-focus:
433 * @widget: the object that received the signal
434 * @reversed: whether cycling backward or forward
436 * The ::cycle-child-focus signal is a
437 * <link linkend="keybinding-signals">keybinding signal</link>
438 * which gets emitted to cycle the focus between the children of the paned.
440 * The default binding is f6.
444 signals [CYCLE_CHILD_FOCUS] =
445 g_signal_new (I_("cycle-child-focus"),
446 G_TYPE_FROM_CLASS (object_class),
447 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
448 G_STRUCT_OFFSET (GtkPanedClass, cycle_child_focus),
450 _gtk_marshal_BOOLEAN__BOOLEAN,
455 * GtkPaned::toggle-handle-focus:
456 * @widget: the object that received the signal
458 * The ::toggle-handle-focus is a
459 * <link linkend="keybinding-signals">keybinding signal</link>
460 * which gets emitted to accept the current position of the handle and then
461 * move focus to the next widget in the focus chain.
463 * The default binding is Tab.
467 signals [TOGGLE_HANDLE_FOCUS] =
468 g_signal_new (I_("toggle-handle-focus"),
469 G_TYPE_FROM_CLASS (object_class),
470 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
471 G_STRUCT_OFFSET (GtkPanedClass, toggle_handle_focus),
473 _gtk_marshal_BOOLEAN__VOID,
477 * GtkPaned::move-handle:
478 * @widget: the object that received the signal
479 * @scroll_type: a #GtkScrollType
481 * The ::move-handle signal is a
482 * <link linkend="keybinding-signals">keybinding signal</link>
483 * which gets emitted to move the handle when the user is using key bindings
488 signals[MOVE_HANDLE] =
489 g_signal_new (I_("move-handle"),
490 G_TYPE_FROM_CLASS (object_class),
491 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
492 G_STRUCT_OFFSET (GtkPanedClass, move_handle),
494 _gtk_marshal_BOOLEAN__ENUM,
496 GTK_TYPE_SCROLL_TYPE);
499 * GtkPaned::cycle-handle-focus:
500 * @widget: the object that received the signal
501 * @reversed: whether cycling backward or forward
503 * The ::cycle-handle-focus signal is a
504 * <link linkend="keybinding-signals">keybinding signal</link>
505 * which gets emitted to cycle whether the paned should grab focus to allow
506 * the user to change position of the handle by using key bindings.
508 * The default binding for this signal is f8.
512 signals [CYCLE_HANDLE_FOCUS] =
513 g_signal_new (I_("cycle-handle-focus"),
514 G_TYPE_FROM_CLASS (object_class),
515 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
516 G_STRUCT_OFFSET (GtkPanedClass, cycle_handle_focus),
518 _gtk_marshal_BOOLEAN__BOOLEAN,
523 * GtkPaned::accept-position:
524 * @widget: the object that received the signal
526 * The ::accept-position signal is a
527 * <link linkend="keybinding-signals">keybinding signal</link>
528 * which gets emitted to accept the current position of the handle when
529 * moving it using key bindings.
531 * The default binding for this signal is Return or Space.
535 signals [ACCEPT_POSITION] =
536 g_signal_new (I_("accept-position"),
537 G_TYPE_FROM_CLASS (object_class),
538 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
539 G_STRUCT_OFFSET (GtkPanedClass, accept_position),
541 _gtk_marshal_BOOLEAN__VOID,
545 * GtkPaned::cancel-position:
546 * @widget: the object that received the signal
548 * The ::cancel-position signal is a
549 * <link linkend="keybinding-signals">keybinding signal</link>
550 * which gets emitted to cancel moving the position of the handle using key
551 * bindings. The position of the handle will be reset to the value prior to
554 * The default binding for this signal is Escape.
558 signals [CANCEL_POSITION] =
559 g_signal_new (I_("cancel-position"),
560 G_TYPE_FROM_CLASS (object_class),
561 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
562 G_STRUCT_OFFSET (GtkPanedClass, cancel_position),
564 _gtk_marshal_BOOLEAN__VOID,
567 binding_set = gtk_binding_set_by_class (class);
570 gtk_binding_entry_add_signal (binding_set,
572 "cycle-child-focus", 1,
573 G_TYPE_BOOLEAN, FALSE);
574 gtk_binding_entry_add_signal (binding_set,
575 GDK_KEY_F6, GDK_SHIFT_MASK,
576 "cycle-child-focus", 1,
577 G_TYPE_BOOLEAN, TRUE);
580 gtk_binding_entry_add_signal (binding_set,
582 "cycle-handle-focus", 1,
583 G_TYPE_BOOLEAN, FALSE);
585 gtk_binding_entry_add_signal (binding_set,
586 GDK_KEY_F8, GDK_SHIFT_MASK,
587 "cycle-handle-focus", 1,
588 G_TYPE_BOOLEAN, TRUE);
590 add_tab_bindings (binding_set, 0);
591 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
592 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
593 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
595 /* accept and cancel positions */
596 gtk_binding_entry_add_signal (binding_set,
598 "cancel-position", 0);
600 gtk_binding_entry_add_signal (binding_set,
602 "accept-position", 0);
603 gtk_binding_entry_add_signal (binding_set,
604 GDK_KEY_ISO_Enter, 0,
605 "accept-position", 0);
606 gtk_binding_entry_add_signal (binding_set,
608 "accept-position", 0);
609 gtk_binding_entry_add_signal (binding_set,
611 "accept-position", 0);
612 gtk_binding_entry_add_signal (binding_set,
614 "accept-position", 0);
617 add_move_binding (binding_set, GDK_KEY_Left, 0, GTK_SCROLL_STEP_LEFT);
618 add_move_binding (binding_set, GDK_KEY_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
619 add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
620 add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
622 add_move_binding (binding_set, GDK_KEY_Right, 0, GTK_SCROLL_STEP_RIGHT);
623 add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
624 add_move_binding (binding_set, GDK_KEY_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
625 add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
627 add_move_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
628 add_move_binding (binding_set, GDK_KEY_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
629 add_move_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
630 add_move_binding (binding_set, GDK_KEY_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
631 add_move_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
632 add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
634 add_move_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
635 add_move_binding (binding_set, GDK_KEY_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
636 add_move_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
637 add_move_binding (binding_set, GDK_KEY_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
638 add_move_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
639 add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
641 add_move_binding (binding_set, GDK_KEY_Home, 0, GTK_SCROLL_START);
642 add_move_binding (binding_set, GDK_KEY_KP_Home, 0, GTK_SCROLL_START);
643 add_move_binding (binding_set, GDK_KEY_End, 0, GTK_SCROLL_END);
644 add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
646 g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
650 gtk_paned_child_type (GtkContainer *container)
652 GtkPaned *paned = GTK_PANED (container);
653 GtkPanedPrivate *priv = paned->priv;
655 if (!priv->child1 || !priv->child2)
656 return GTK_TYPE_WIDGET;
662 gtk_paned_init (GtkPaned *paned)
664 GtkPanedPrivate *priv;
666 gtk_widget_set_has_window (GTK_WIDGET (paned), FALSE);
667 gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE);
669 /* We only need to redraw when the handle position moves, which is
670 * independent of the overall allocation of the GtkPaned
672 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
674 paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
677 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
678 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
683 priv->cursor_type = GDK_CROSS;
685 priv->handle_pos.width = 5;
686 priv->handle_pos.height = 5;
687 priv->position_set = FALSE;
688 priv->last_allocation = -1;
689 priv->in_drag = FALSE;
691 priv->last_child1_focus = NULL;
692 priv->last_child2_focus = NULL;
693 priv->in_recursion = FALSE;
694 priv->handle_prelit = FALSE;
695 priv->original_position = -1;
697 priv->handle_pos.x = -1;
698 priv->handle_pos.y = -1;
704 gtk_paned_set_property (GObject *object,
709 GtkPaned *paned = GTK_PANED (object);
710 GtkPanedPrivate *priv = paned->priv;
714 case PROP_ORIENTATION:
715 priv->orientation = g_value_get_enum (value);
717 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
718 priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
720 priv->cursor_type = GDK_SB_V_DOUBLE_ARROW;
722 /* state_flags_changed updates the cursor */
723 gtk_paned_state_flags_changed (GTK_WIDGET (paned), 0);
724 gtk_widget_queue_resize (GTK_WIDGET (paned));
727 gtk_paned_set_position (paned, g_value_get_int (value));
729 case PROP_POSITION_SET:
730 priv->position_set = g_value_get_boolean (value);
731 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
734 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
740 gtk_paned_get_property (GObject *object,
745 GtkPaned *paned = GTK_PANED (object);
746 GtkPanedPrivate *priv = paned->priv;
750 case PROP_ORIENTATION:
751 g_value_set_enum (value, priv->orientation);
754 g_value_set_int (value, priv->child1_size);
756 case PROP_POSITION_SET:
757 g_value_set_boolean (value, priv->position_set);
759 case PROP_MIN_POSITION:
760 g_value_set_int (value, priv->min_position);
762 case PROP_MAX_POSITION:
763 g_value_set_int (value, priv->max_position);
766 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
772 gtk_paned_set_child_property (GtkContainer *container,
778 GtkPaned *paned = GTK_PANED (container);
779 GtkPanedPrivate *priv = paned->priv;
780 gboolean old_value, new_value;
782 g_assert (child == priv->child1 || child == priv->child2);
784 new_value = g_value_get_boolean (value);
787 case CHILD_PROP_RESIZE:
788 if (child == priv->child1)
790 old_value = priv->child1_resize;
791 priv->child1_resize = new_value;
795 old_value = priv->child2_resize;
796 priv->child2_resize = new_value;
799 case CHILD_PROP_SHRINK:
800 if (child == priv->child1)
802 old_value = priv->child1_shrink;
803 priv->child1_shrink = new_value;
807 old_value = priv->child2_shrink;
808 priv->child2_shrink = new_value;
812 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
813 old_value = -1; /* quiet gcc */
816 if (old_value != new_value)
817 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
821 gtk_paned_get_child_property (GtkContainer *container,
827 GtkPaned *paned = GTK_PANED (container);
828 GtkPanedPrivate *priv = paned->priv;
830 g_assert (child == priv->child1 || child == priv->child2);
834 case CHILD_PROP_RESIZE:
835 if (child == priv->child1)
836 g_value_set_boolean (value, priv->child1_resize);
838 g_value_set_boolean (value, priv->child2_resize);
840 case CHILD_PROP_SHRINK:
841 if (child == priv->child1)
842 g_value_set_boolean (value, priv->child1_shrink);
844 g_value_set_boolean (value, priv->child2_shrink);
847 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
853 gtk_paned_finalize (GObject *object)
855 GtkPaned *paned = GTK_PANED (object);
857 gtk_paned_set_saved_focus (paned, NULL);
858 gtk_paned_set_first_paned (paned, NULL);
860 G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
864 get_preferred_size_for_size (GtkWidget *widget,
865 GtkOrientation orientation,
870 if (orientation == GTK_ORIENTATION_HORIZONTAL)
872 gtk_widget_get_preferred_width (widget, minimum, natural);
874 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
877 gtk_widget_get_preferred_height (widget, minimum, natural);
879 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
883 gtk_paned_get_preferred_size (GtkWidget *widget,
884 GtkOrientation orientation,
889 GtkPaned *paned = GTK_PANED (widget);
890 GtkPanedPrivate *priv = paned->priv;
891 gint child_min, child_nat;
893 *minimum = *natural = 0;
895 if (priv->child1 && gtk_widget_get_visible (priv->child1))
897 get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
898 *minimum = child_min;
899 *natural = child_nat;
902 if (priv->child2 && gtk_widget_get_visible (priv->child2))
904 get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
906 if (priv->orientation == orientation)
908 *minimum += child_min;
909 *natural += child_nat;
913 *minimum = MAX (*minimum, child_min);
914 *natural = MAX (*natural, child_nat);
918 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
919 priv->child2 && gtk_widget_get_visible (priv->child2))
923 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
925 if (priv->orientation == orientation)
927 *minimum += handle_size;
928 *natural += handle_size;
934 gtk_paned_get_preferred_width (GtkWidget *widget,
938 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
942 gtk_paned_get_preferred_height (GtkWidget *widget,
946 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
950 gtk_paned_get_preferred_width_for_height (GtkWidget *widget,
955 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
959 gtk_paned_get_preferred_height_for_width (GtkWidget *widget,
964 gtk_paned_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
968 flip_child (GtkWidget *widget,
969 GtkAllocation *child_pos)
971 GtkAllocation allocation;
974 gtk_widget_get_allocation (widget, &allocation);
976 width = allocation.width;
978 child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
982 gtk_paned_child_allocate (GtkWidget *child,
983 GdkWindow *child_window, /* can be NULL */
984 const GtkAllocation *window_allocation,
985 GtkAllocation *child_allocation)
988 gdk_window_move_resize (child_window,
989 window_allocation->x, window_allocation->y,
990 window_allocation->width, window_allocation->height);
992 gtk_widget_size_allocate (child, child_allocation);
996 gtk_paned_size_allocate (GtkWidget *widget,
997 GtkAllocation *allocation)
999 GtkPaned *paned = GTK_PANED (widget);
1000 GtkPanedPrivate *priv = paned->priv;
1002 gtk_widget_set_allocation (widget, allocation);
1004 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1005 priv->child2 && gtk_widget_get_visible (priv->child2))
1007 GtkAllocation child1_allocation, window1_allocation;
1008 GtkAllocation child2_allocation, window2_allocation;
1009 GtkAllocation priv_child1_allocation;
1010 GdkRectangle old_handle_pos;
1013 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1015 old_handle_pos = priv->handle_pos;
1017 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1019 gint child1_width, child2_width;
1021 gtk_widget_get_preferred_width_for_height (priv->child1,
1023 &child1_width, NULL);
1024 gtk_widget_get_preferred_width_for_height (priv->child2,
1026 &child2_width, NULL);
1028 gtk_paned_calc_position (paned,
1029 MAX (1, allocation->width - handle_size),
1033 priv->handle_pos.x = allocation->x + priv->child1_size;
1034 priv->handle_pos.y = allocation->y;
1035 priv->handle_pos.width = handle_size;
1036 priv->handle_pos.height = allocation->height;
1038 window1_allocation.height = window2_allocation.height = allocation->height;
1039 window1_allocation.width = MAX (1, priv->child1_size);
1040 window1_allocation.x = allocation->x;
1041 window1_allocation.y = window2_allocation.y = allocation->y;
1043 window2_allocation.x = window1_allocation.x + priv->child1_size + priv->handle_pos.width;
1044 window2_allocation.width = MAX (1, allocation->x + allocation->width - window2_allocation.x);
1046 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1048 flip_child (widget, &(window2_allocation));
1049 flip_child (widget, &(window1_allocation));
1050 flip_child (widget, &(priv->handle_pos));
1053 child1_allocation.x = child1_allocation.y = 0;
1054 child1_allocation.width = window1_allocation.width;
1055 child1_allocation.height = window1_allocation.height;
1056 if (child1_width > child1_allocation.width)
1058 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_LTR)
1059 child1_allocation.x -= child1_width - child1_allocation.width;
1060 child1_allocation.width = child1_width;
1063 child2_allocation.x = child2_allocation.y = 0;
1064 child2_allocation.width = window2_allocation.width;
1065 child2_allocation.height = window2_allocation.height;
1066 if (child2_width > child2_allocation.width)
1068 if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
1069 child2_allocation.x -= child2_width - child2_allocation.width;
1070 child2_allocation.width = child2_width;
1075 gint child1_height, child2_height;
1077 gtk_widget_get_preferred_height_for_width (priv->child1,
1079 &child1_height, NULL);
1080 gtk_widget_get_preferred_height_for_width (priv->child2,
1082 &child2_height, NULL);
1084 gtk_paned_calc_position (paned,
1085 MAX (1, allocation->height - handle_size),
1089 priv->handle_pos.x = allocation->x;
1090 priv->handle_pos.y = allocation->y + priv->child1_size;
1091 priv->handle_pos.width = allocation->width;
1092 priv->handle_pos.height = handle_size;
1094 window1_allocation.width = window2_allocation.width = allocation->width;
1095 window1_allocation.height = MAX (1, priv->child1_size);
1096 window1_allocation.x = window2_allocation.x = allocation->x;
1097 window1_allocation.y = allocation->y;
1099 window2_allocation.y = window1_allocation.y + priv->child1_size + priv->handle_pos.height;
1100 window2_allocation.height = MAX (1, allocation->y + allocation->height - window2_allocation.y);
1102 child1_allocation.x = child1_allocation.y = 0;
1103 child1_allocation.width = window1_allocation.width;
1104 child1_allocation.height = window1_allocation.height;
1105 if (child1_height > child1_allocation.height)
1107 child1_allocation.y -= child1_height - child1_allocation.height;
1108 child1_allocation.height = child1_height;
1111 child2_allocation.x = child2_allocation.y = 0;
1112 child2_allocation.width = window2_allocation.width;
1113 child2_allocation.height = window2_allocation.height;
1114 if (child2_height > child2_allocation.height)
1115 child2_allocation.height = child2_height;
1118 if (gtk_widget_get_mapped (widget) &&
1119 (old_handle_pos.x != priv->handle_pos.x ||
1120 old_handle_pos.y != priv->handle_pos.y ||
1121 old_handle_pos.width != priv->handle_pos.width ||
1122 old_handle_pos.height != priv->handle_pos.height))
1126 window = gtk_widget_get_window (widget);
1127 gdk_window_invalidate_rect (window, &old_handle_pos, FALSE);
1128 gdk_window_invalidate_rect (window, &priv->handle_pos, FALSE);
1131 if (gtk_widget_get_realized (widget))
1133 if (gtk_widget_get_mapped (widget))
1134 gdk_window_show (priv->handle);
1136 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1138 gdk_window_move_resize (priv->handle,
1142 priv->handle_pos.height);
1146 gdk_window_move_resize (priv->handle,
1149 priv->handle_pos.width,
1154 /* Now allocate the childen, making sure, when resizing not to
1155 * overlap the windows
1157 gtk_widget_get_allocation (priv->child1, &priv_child1_allocation);
1158 if (gtk_widget_get_mapped (widget) &&
1159 ((priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1160 priv_child1_allocation.width < child1_allocation.width) ||
1162 (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1163 priv_child1_allocation.height < child1_allocation.height)))
1165 gtk_paned_child_allocate (priv->child2,
1166 priv->child2_window,
1167 &window2_allocation,
1168 &child2_allocation);
1169 gtk_paned_child_allocate (priv->child1,
1170 priv->child1_window,
1171 &window1_allocation,
1172 &child1_allocation);
1176 gtk_paned_child_allocate (priv->child1,
1177 priv->child1_window,
1178 &window1_allocation,
1179 &child1_allocation);
1180 gtk_paned_child_allocate (priv->child2,
1181 priv->child2_window,
1182 &window2_allocation,
1183 &child2_allocation);
1185 if (priv->child1_window)
1186 gdk_window_show (priv->child1_window);
1187 if (priv->child2_window)
1188 gdk_window_show (priv->child2_window);
1192 GtkAllocation window_allocation, child_allocation;
1194 if (gtk_widget_get_realized (widget))
1195 gdk_window_hide (priv->handle);
1198 gtk_widget_set_child_visible (priv->child1, TRUE);
1200 gtk_widget_set_child_visible (priv->child2, TRUE);
1202 window_allocation.x = allocation->x;
1203 window_allocation.y = allocation->y;
1204 window_allocation.width = allocation->width;
1205 window_allocation.height = allocation->height;
1206 child_allocation.x = child_allocation.y = 0;
1207 child_allocation.width = allocation->width;
1208 child_allocation.height = allocation->height;
1210 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1212 gtk_paned_child_allocate (priv->child1,
1213 priv->child1_window,
1216 if (priv->child1_window)
1217 gdk_window_show (priv->child1_window);
1218 if (priv->child2_window)
1219 gdk_window_hide (priv->child2_window);
1221 else if (priv->child2 && gtk_widget_get_visible (priv->child2))
1223 gtk_paned_child_allocate (priv->child2,
1224 priv->child2_window,
1227 if (priv->child2_window)
1228 gdk_window_show (priv->child2_window);
1229 if (priv->child1_window)
1230 gdk_window_hide (priv->child1_window);
1236 gtk_paned_create_child_window (GtkPaned *paned,
1237 GtkWidget *child) /* may be NULL */
1239 GtkWidget *widget = GTK_WIDGET (paned);
1240 GtkPanedPrivate *priv = paned->priv;
1242 GdkWindowAttr attributes;
1243 gint attributes_mask;
1245 attributes.window_type = GDK_WINDOW_CHILD;
1246 attributes.wclass = GDK_INPUT_OUTPUT;
1247 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1250 GtkAllocation allocation;
1253 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1255 gtk_widget_get_allocation (widget, &allocation);
1256 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1257 child == priv->child2)
1258 attributes.x = priv->handle_pos.x + handle_size;
1260 attributes.x = allocation.x;
1261 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
1262 child == priv->child2)
1263 attributes.y = priv->handle_pos.y + handle_size;
1265 attributes.y = allocation.y;
1267 gtk_widget_get_allocation (child, &allocation);
1268 attributes.width = allocation.width;
1269 attributes.height = allocation.height;
1270 attributes_mask = GDK_WA_X | GDK_WA_Y;
1274 attributes.width = 1;
1275 attributes.height = 1;
1276 attributes_mask = 0;
1279 window = gdk_window_new (gtk_widget_get_window (widget),
1280 &attributes, attributes_mask);
1281 gdk_window_set_user_data (window, paned);
1282 gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
1285 gtk_widget_set_parent_window (child, window);
1291 gtk_paned_realize (GtkWidget *widget)
1293 GtkPaned *paned = GTK_PANED (widget);
1294 GtkPanedPrivate *priv = paned->priv;
1296 GdkWindowAttr attributes;
1297 gint attributes_mask;
1299 gtk_widget_set_realized (widget, TRUE);
1301 window = gtk_widget_get_parent_window (widget);
1302 gtk_widget_set_window (widget, window);
1303 g_object_ref (window);
1305 attributes.window_type = GDK_WINDOW_CHILD;
1306 attributes.wclass = GDK_INPUT_ONLY;
1307 attributes.x = priv->handle_pos.x;
1308 attributes.y = priv->handle_pos.y;
1309 attributes.width = priv->handle_pos.width;
1310 attributes.height = priv->handle_pos.height;
1311 attributes.event_mask = gtk_widget_get_events (widget);
1312 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1313 GDK_BUTTON_RELEASE_MASK |
1314 GDK_ENTER_NOTIFY_MASK |
1315 GDK_LEAVE_NOTIFY_MASK |
1316 GDK_POINTER_MOTION_MASK |
1317 GDK_POINTER_MOTION_HINT_MASK);
1318 attributes_mask = GDK_WA_X | GDK_WA_Y;
1319 if (gtk_widget_is_sensitive (widget))
1321 attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1323 attributes_mask |= GDK_WA_CURSOR;
1326 priv->handle = gdk_window_new (window,
1327 &attributes, attributes_mask);
1328 gdk_window_set_user_data (priv->handle, paned);
1329 if (attributes_mask & GDK_WA_CURSOR)
1330 g_object_unref (attributes.cursor);
1332 priv->child1_window = gtk_paned_create_child_window (paned, priv->child1);
1333 priv->child2_window = gtk_paned_create_child_window (paned, priv->child2);
1337 gtk_paned_unrealize (GtkWidget *widget)
1339 GtkPaned *paned = GTK_PANED (widget);
1340 GtkPanedPrivate *priv = paned->priv;
1343 gtk_widget_set_parent_window (priv->child2, NULL);
1344 gdk_window_set_user_data (priv->child2_window, NULL);
1345 gdk_window_destroy (priv->child2_window);
1346 priv->child2_window = NULL;
1349 gtk_widget_set_parent_window (priv->child1, NULL);
1350 gdk_window_set_user_data (priv->child1_window, NULL);
1351 gdk_window_destroy (priv->child1_window);
1352 priv->child1_window = NULL;
1356 gdk_window_set_user_data (priv->handle, NULL);
1357 gdk_window_destroy (priv->handle);
1358 priv->handle = NULL;
1361 gtk_paned_set_last_child1_focus (paned, NULL);
1362 gtk_paned_set_last_child2_focus (paned, NULL);
1363 gtk_paned_set_saved_focus (paned, NULL);
1364 gtk_paned_set_first_paned (paned, NULL);
1366 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
1370 gtk_paned_map (GtkWidget *widget)
1372 GtkPaned *paned = GTK_PANED (widget);
1373 GtkPanedPrivate *priv = paned->priv;
1375 if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
1376 priv->child2 && gtk_widget_get_visible (priv->child2))
1377 gdk_window_show (priv->handle);
1379 if (priv->child1 && gtk_widget_get_visible (priv->child1))
1380 gdk_window_show (priv->child1_window);
1381 if (priv->child2 && gtk_widget_get_visible (priv->child2))
1382 gdk_window_show (priv->child2_window);
1384 GTK_WIDGET_CLASS (gtk_paned_parent_class)->map (widget);
1388 gtk_paned_unmap (GtkWidget *widget)
1390 GtkPaned *paned = GTK_PANED (widget);
1391 GtkPanedPrivate *priv = paned->priv;
1393 gdk_window_hide (priv->handle);
1395 gdk_window_hide (priv->child1_window);
1396 gdk_window_hide (priv->child2_window);
1398 GTK_WIDGET_CLASS (gtk_paned_parent_class)->unmap (widget);
1402 gtk_paned_draw (GtkWidget *widget,
1405 GtkPaned *paned = GTK_PANED (widget);
1406 GtkPanedPrivate *priv = paned->priv;
1408 if (gtk_cairo_should_draw_window (cr, priv->child1_window))
1411 gtk_cairo_transform_to_window (cr, widget, priv->child1_window);
1412 gtk_render_background (gtk_widget_get_style_context (widget),
1415 gdk_window_get_width (priv->child1_window),
1416 gdk_window_get_height (priv->child1_window));
1420 if (gtk_cairo_should_draw_window (cr, priv->child2_window))
1423 gtk_cairo_transform_to_window (cr, widget, priv->child2_window);
1424 gtk_render_background (gtk_widget_get_style_context (widget),
1427 gdk_window_get_width (priv->child2_window),
1428 gdk_window_get_height (priv->child2_window));
1432 if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)) &&
1433 priv->child1 && gtk_widget_get_visible (priv->child1) &&
1434 priv->child2 && gtk_widget_get_visible (priv->child2))
1436 GtkStyleContext *context;
1437 GtkStateFlags state;
1438 GtkAllocation allocation;
1440 gtk_widget_get_allocation (widget, &allocation);
1441 context = gtk_widget_get_style_context (widget);
1442 state = gtk_widget_get_state_flags (widget);
1444 if (gtk_widget_is_focus (widget))
1445 state |= GTK_STATE_FLAG_SELECTED;
1446 if (priv->handle_prelit)
1447 state |= GTK_STATE_FLAG_PRELIGHT;
1449 gtk_style_context_save (context);
1450 gtk_style_context_set_state (context, state);
1451 gtk_style_context_add_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR);
1452 gtk_render_handle (context, cr,
1453 priv->handle_pos.x - allocation.x,
1454 priv->handle_pos.y - allocation.y,
1455 priv->handle_pos.width,
1456 priv->handle_pos.height);
1458 gtk_style_context_restore (context);
1461 /* Chain up to draw children */
1462 GTK_WIDGET_CLASS (gtk_paned_parent_class)->draw (widget, cr);
1468 is_rtl (GtkPaned *paned)
1470 GtkPanedPrivate *priv = paned->priv;
1472 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
1473 gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
1482 update_drag (GtkPaned *paned)
1484 GtkPanedPrivate *priv = paned->priv;
1485 GtkAllocation allocation;
1486 GtkWidget *widget = GTK_WIDGET (paned);
1491 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1492 gtk_widget_get_pointer (widget, &pos, NULL);
1494 gtk_widget_get_pointer (widget, NULL, &pos);
1496 pos -= priv->drag_pos;
1500 gtk_widget_style_get (widget,
1501 "handle-size", &handle_size,
1504 gtk_widget_get_allocation (widget, &allocation);
1505 size = allocation.width - pos - handle_size;
1512 size = CLAMP (size, priv->min_position, priv->max_position);
1514 if (size != priv->child1_size)
1515 gtk_paned_set_position (paned, size);
1519 gtk_paned_enter (GtkWidget *widget,
1520 GdkEventCrossing *event)
1522 GtkPaned *paned = GTK_PANED (widget);
1523 GtkPanedPrivate *priv = paned->priv;
1526 update_drag (paned);
1529 priv->handle_prelit = TRUE;
1530 gtk_widget_queue_draw_area (widget,
1533 priv->handle_pos.width,
1534 priv->handle_pos.height);
1541 gtk_paned_leave (GtkWidget *widget,
1542 GdkEventCrossing *event)
1544 GtkPaned *paned = GTK_PANED (widget);
1545 GtkPanedPrivate *priv = paned->priv;
1548 update_drag (paned);
1551 priv->handle_prelit = FALSE;
1552 gtk_widget_queue_draw_area (widget,
1555 priv->handle_pos.width,
1556 priv->handle_pos.height);
1563 gtk_paned_focus (GtkWidget *widget,
1564 GtkDirectionType direction)
1569 /* This is a hack, but how can this be done without
1570 * excessive cut-and-paste from gtkcontainer.c?
1573 gtk_widget_set_can_focus (widget, FALSE);
1574 retval = GTK_WIDGET_CLASS (gtk_paned_parent_class)->focus (widget, direction);
1575 gtk_widget_set_can_focus (widget, TRUE);
1581 gtk_paned_button_press (GtkWidget *widget,
1582 GdkEventButton *event)
1584 GtkPaned *paned = GTK_PANED (widget);
1585 GtkPanedPrivate *priv = paned->priv;
1587 if (!priv->in_drag &&
1588 (event->window == priv->handle) && (event->button == 1))
1590 /* We need a server grab here, not gtk_grab_add(), since
1591 * we don't want to pass events on to the widget's children */
1592 if (gdk_device_grab (event->device,
1594 GDK_OWNERSHIP_WINDOW, FALSE,
1595 GDK_POINTER_MOTION_HINT_MASK
1596 | GDK_BUTTON1_MOTION_MASK
1597 | GDK_BUTTON_RELEASE_MASK
1598 | GDK_ENTER_NOTIFY_MASK
1599 | GDK_LEAVE_NOTIFY_MASK,
1600 NULL, event->time) != GDK_GRAB_SUCCESS)
1603 priv->in_drag = TRUE;
1604 priv->grab_time = event->time;
1605 priv->grab_device = event->device;
1607 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1608 priv->drag_pos = event->x;
1610 priv->drag_pos = event->y;
1619 gtk_paned_grab_broken (GtkWidget *widget,
1620 GdkEventGrabBroken *event)
1622 GtkPaned *paned = GTK_PANED (widget);
1623 GtkPanedPrivate *priv = paned->priv;
1625 priv->in_drag = FALSE;
1626 priv->drag_pos = -1;
1627 priv->position_set = TRUE;
1633 stop_drag (GtkPaned *paned)
1635 GtkPanedPrivate *priv = paned->priv;
1637 priv->in_drag = FALSE;
1638 priv->drag_pos = -1;
1639 priv->position_set = TRUE;
1641 gdk_device_ungrab (priv->grab_device,
1643 priv->grab_device = NULL;
1647 gtk_paned_grab_notify (GtkWidget *widget,
1648 gboolean was_grabbed)
1650 GtkPaned *paned = GTK_PANED (widget);
1651 GtkPanedPrivate *priv = paned->priv;
1652 GdkDevice *grab_device;
1654 grab_device = priv->grab_device;
1656 if (priv->in_drag && grab_device &&
1657 gtk_widget_device_is_shadowed (widget, grab_device))
1662 gtk_paned_state_flags_changed (GtkWidget *widget,
1663 GtkStateFlags previous_state)
1665 GtkPaned *paned = GTK_PANED (widget);
1666 GtkPanedPrivate *priv = paned->priv;
1669 if (gtk_widget_get_realized (widget))
1671 if (gtk_widget_is_sensitive (widget))
1672 cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1677 gdk_window_set_cursor (priv->handle, cursor);
1680 g_object_unref (cursor);
1685 gtk_paned_button_release (GtkWidget *widget,
1686 GdkEventButton *event)
1688 GtkPaned *paned = GTK_PANED (widget);
1689 GtkPanedPrivate *priv = paned->priv;
1691 if (priv->in_drag && (event->button == 1))
1702 gtk_paned_motion (GtkWidget *widget,
1703 GdkEventMotion *event)
1705 GtkPaned *paned = GTK_PANED (widget);
1706 GtkPanedPrivate *priv = paned->priv;
1710 update_drag (paned);
1719 * @orientation: the paned's orientation.
1721 * Creates a new #GtkPaned widget.
1723 * Return value: a new #GtkPaned.
1728 gtk_paned_new (GtkOrientation orientation)
1730 return g_object_new (GTK_TYPE_PANED,
1731 "orientation", orientation,
1737 * @paned: a paned widget
1738 * @child: the child to add
1740 * Adds a child to the top or left pane with default parameters. This is
1742 * <literal>gtk_paned_pack1 (paned, child, FALSE, TRUE)</literal>.
1745 gtk_paned_add1 (GtkPaned *paned,
1748 gtk_paned_pack1 (paned, widget, FALSE, TRUE);
1753 * @paned: a paned widget
1754 * @child: the child to add
1756 * Adds a child to the bottom or right pane with default parameters. This
1758 * <literal>gtk_paned_pack2 (paned, child, TRUE, TRUE)</literal>.
1761 gtk_paned_add2 (GtkPaned *paned,
1764 gtk_paned_pack2 (paned, widget, TRUE, TRUE);
1769 * @paned: a paned widget
1770 * @child: the child to add
1771 * @resize: should this child expand when the paned widget is resized.
1772 * @shrink: can this child be made smaller than its requisition.
1774 * Adds a child to the top or left pane.
1777 gtk_paned_pack1 (GtkPaned *paned,
1782 GtkPanedPrivate *priv;
1784 g_return_if_fail (GTK_IS_PANED (paned));
1785 g_return_if_fail (GTK_IS_WIDGET (child));
1791 priv->child1 = child;
1792 priv->child1_resize = resize;
1793 priv->child1_shrink = shrink;
1795 gtk_widget_set_parent_window (child, priv->child1_window);
1796 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1802 * @paned: a paned widget
1803 * @child: the child to add
1804 * @resize: should this child expand when the paned widget is resized.
1805 * @shrink: can this child be made smaller than its requisition.
1807 * Adds a child to the bottom or right pane.
1810 gtk_paned_pack2 (GtkPaned *paned,
1815 GtkPanedPrivate *priv;
1817 g_return_if_fail (GTK_IS_PANED (paned));
1818 g_return_if_fail (GTK_IS_WIDGET (child));
1824 priv->child2 = child;
1825 priv->child2_resize = resize;
1826 priv->child2_shrink = shrink;
1828 gtk_widget_set_parent_window (child, priv->child2_window);
1829 gtk_widget_set_parent (child, GTK_WIDGET (paned));
1835 gtk_paned_add (GtkContainer *container,
1838 GtkPanedPrivate *priv;
1841 g_return_if_fail (GTK_IS_PANED (container));
1843 paned = GTK_PANED (container);
1847 gtk_paned_add1 (paned, widget);
1848 else if (!priv->child2)
1849 gtk_paned_add2 (paned, widget);
1851 g_warning ("GtkPaned cannot have more than 2 children\n");
1855 gtk_paned_remove (GtkContainer *container,
1858 GtkPaned *paned = GTK_PANED (container);
1859 GtkPanedPrivate *priv = paned->priv;
1860 gboolean was_visible;
1862 was_visible = gtk_widget_get_visible (widget);
1864 if (priv->child1 == widget)
1866 gtk_widget_unparent (widget);
1868 priv->child1 = NULL;
1870 if (priv->child1_window)
1871 gdk_window_hide (priv->child1_window);
1873 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1874 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1876 else if (priv->child2 == widget)
1878 gtk_widget_unparent (widget);
1880 priv->child2 = NULL;
1882 if (priv->child2_window)
1883 gdk_window_hide (priv->child2_window);
1885 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
1886 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (container));
1891 gtk_paned_forall (GtkContainer *container,
1892 gboolean include_internals,
1893 GtkCallback callback,
1894 gpointer callback_data)
1896 GtkPanedPrivate *priv;
1899 g_return_if_fail (callback != NULL);
1901 paned = GTK_PANED (container);
1905 (*callback) (priv->child1, callback_data);
1907 (*callback) (priv->child2, callback_data);
1911 * gtk_paned_get_position:
1912 * @paned: a #GtkPaned widget
1914 * Obtains the position of the divider between the two panes.
1916 * Return value: position of the divider
1919 gtk_paned_get_position (GtkPaned *paned)
1921 g_return_val_if_fail (GTK_IS_PANED (paned), 0);
1923 return paned->priv->child1_size;
1927 * gtk_paned_set_position:
1928 * @paned: a #GtkPaned widget
1929 * @position: pixel position of divider, a negative value means that the position
1932 * Sets the position of the divider between the two panes.
1935 gtk_paned_set_position (GtkPaned *paned,
1938 GtkPanedPrivate *priv;
1941 g_return_if_fail (GTK_IS_PANED (paned));
1945 if (priv->child1_size == position)
1948 object = G_OBJECT (paned);
1952 /* We don't clamp here - the assumption is that
1953 * if the total allocation changes at the same time
1954 * as the position, the position set is with reference
1955 * to the new total size. If only the position changes,
1956 * then clamping will occur in gtk_paned_calc_position()
1959 priv->child1_size = position;
1960 priv->position_set = TRUE;
1964 priv->position_set = FALSE;
1967 g_object_freeze_notify (object);
1968 g_object_notify (object, "position");
1969 g_object_notify (object, "position-set");
1970 g_object_thaw_notify (object);
1972 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (paned));
1975 /* Hacky work-around for bug #144269 */
1976 if (priv->child2 != NULL)
1978 gtk_widget_queue_draw (priv->child2);
1984 * gtk_paned_get_child1:
1985 * @paned: a #GtkPaned widget
1987 * Obtains the first child of the paned widget.
1989 * Return value: (transfer none): first child, or %NULL if it is not set.
1994 gtk_paned_get_child1 (GtkPaned *paned)
1996 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
1998 return paned->priv->child1;
2002 * gtk_paned_get_child2:
2003 * @paned: a #GtkPaned widget
2005 * Obtains the second child of the paned widget.
2007 * Return value: (transfer none): second child, or %NULL if it is not set.
2012 gtk_paned_get_child2 (GtkPaned *paned)
2014 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2016 return paned->priv->child2;
2020 gtk_paned_calc_position (GtkPaned *paned,
2025 GtkPanedPrivate *priv = paned->priv;
2027 gint old_min_position;
2028 gint old_max_position;
2030 old_position = priv->child1_size;
2031 old_min_position = priv->min_position;
2032 old_max_position = priv->max_position;
2034 priv->min_position = priv->child1_shrink ? 0 : child1_req;
2036 priv->max_position = allocation;
2037 if (!priv->child2_shrink)
2038 priv->max_position = MAX (1, priv->max_position - child2_req);
2039 priv->max_position = MAX (priv->min_position, priv->max_position);
2041 if (!priv->position_set)
2043 if (priv->child1_resize && !priv->child2_resize)
2044 priv->child1_size = MAX (0, allocation - child2_req);
2045 else if (!priv->child1_resize && priv->child2_resize)
2046 priv->child1_size = child1_req;
2047 else if (child1_req + child2_req != 0)
2048 priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
2050 priv->child1_size = allocation * 0.5 + 0.5;
2054 /* If the position was set before the initial allocation.
2055 * (priv->last_allocation <= 0) just clamp it and leave it.
2057 if (priv->last_allocation > 0)
2059 if (priv->child1_resize && !priv->child2_resize)
2060 priv->child1_size += allocation - priv->last_allocation;
2061 else if (!(!priv->child1_resize && priv->child2_resize))
2062 priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
2066 priv->child1_size = CLAMP (priv->child1_size,
2068 priv->max_position);
2071 gtk_widget_set_child_visible (priv->child1, priv->child1_size != 0);
2074 gtk_widget_set_child_visible (priv->child2, priv->child1_size != allocation);
2076 g_object_freeze_notify (G_OBJECT (paned));
2077 if (priv->child1_size != old_position)
2078 g_object_notify (G_OBJECT (paned), "position");
2079 if (priv->min_position != old_min_position)
2080 g_object_notify (G_OBJECT (paned), "min-position");
2081 if (priv->max_position != old_max_position)
2082 g_object_notify (G_OBJECT (paned), "max-position");
2083 g_object_thaw_notify (G_OBJECT (paned));
2085 priv->last_allocation = allocation;
2089 gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget)
2091 GtkPanedPrivate *priv = paned->priv;
2093 if (priv->saved_focus)
2094 g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus),
2095 (gpointer *)&(priv->saved_focus));
2097 priv->saved_focus = widget;
2099 if (priv->saved_focus)
2100 g_object_add_weak_pointer (G_OBJECT (priv->saved_focus),
2101 (gpointer *)&(priv->saved_focus));
2105 gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned)
2107 GtkPanedPrivate *priv = paned->priv;
2109 if (priv->first_paned)
2110 g_object_remove_weak_pointer (G_OBJECT (priv->first_paned),
2111 (gpointer *)&(priv->first_paned));
2113 priv->first_paned = first_paned;
2115 if (priv->first_paned)
2116 g_object_add_weak_pointer (G_OBJECT (priv->first_paned),
2117 (gpointer *)&(priv->first_paned));
2121 gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget)
2123 GtkPanedPrivate *priv = paned->priv;
2125 if (priv->last_child1_focus)
2126 g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus),
2127 (gpointer *)&(priv->last_child1_focus));
2129 priv->last_child1_focus = widget;
2131 if (priv->last_child1_focus)
2132 g_object_add_weak_pointer (G_OBJECT (priv->last_child1_focus),
2133 (gpointer *)&(priv->last_child1_focus));
2137 gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget)
2139 GtkPanedPrivate *priv = paned->priv;
2141 if (priv->last_child2_focus)
2142 g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus),
2143 (gpointer *)&(priv->last_child2_focus));
2145 priv->last_child2_focus = widget;
2147 if (priv->last_child2_focus)
2148 g_object_add_weak_pointer (G_OBJECT (priv->last_child2_focus),
2149 (gpointer *)&(priv->last_child2_focus));
2153 paned_get_focus_widget (GtkPaned *paned)
2155 GtkWidget *toplevel;
2157 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2158 if (gtk_widget_is_toplevel (toplevel))
2159 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2165 gtk_paned_set_focus_child (GtkContainer *container,
2166 GtkWidget *focus_child)
2169 GtkPanedPrivate *priv;
2170 GtkWidget *container_focus_child;
2172 g_return_if_fail (GTK_IS_PANED (container));
2174 paned = GTK_PANED (container);
2177 if (focus_child == NULL)
2179 GtkWidget *last_focus;
2182 last_focus = paned_get_focus_widget (paned);
2186 /* If there is one or more paned widgets between us and the
2187 * focus widget, we want the topmost of those as last_focus
2189 for (w = last_focus; w != GTK_WIDGET (paned); w = gtk_widget_get_parent (w))
2190 if (GTK_IS_PANED (w))
2193 container_focus_child = gtk_container_get_focus_child (container);
2194 if (container_focus_child == priv->child1)
2195 gtk_paned_set_last_child1_focus (paned, last_focus);
2196 else if (container_focus_child == priv->child2)
2197 gtk_paned_set_last_child2_focus (paned, last_focus);
2201 if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
2202 GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
2206 gtk_paned_get_cycle_chain (GtkPaned *paned,
2207 GtkDirectionType direction,
2210 GtkPanedPrivate *priv = paned->priv;
2211 GtkContainer *container = GTK_CONTAINER (paned);
2212 GtkWidget *ancestor = NULL;
2213 GtkWidget *focus_child;
2215 GtkWidget *widget = GTK_WIDGET (paned);
2216 GList *temp_list = NULL;
2219 if (priv->in_recursion)
2222 g_assert (widgets != NULL);
2224 if (priv->last_child1_focus &&
2225 !gtk_widget_is_ancestor (priv->last_child1_focus, widget))
2227 gtk_paned_set_last_child1_focus (paned, NULL);
2230 if (priv->last_child2_focus &&
2231 !gtk_widget_is_ancestor (priv->last_child2_focus, widget))
2233 gtk_paned_set_last_child2_focus (paned, NULL);
2236 parent = gtk_widget_get_parent (widget);
2238 ancestor = gtk_widget_get_ancestor (parent, GTK_TYPE_PANED);
2240 /* The idea here is that temp_list is a list of widgets we want to cycle
2241 * to. The list is prioritized so that the first element is our first
2242 * choice, the next our second, and so on.
2244 * We can't just use g_list_reverse(), because we want to try
2245 * priv->last_child?_focus before priv->child?, both when we
2246 * are going forward and backward.
2248 focus_child = gtk_container_get_focus_child (container);
2249 if (direction == GTK_DIR_TAB_FORWARD)
2251 if (focus_child == priv->child1)
2253 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2254 temp_list = g_list_append (temp_list, priv->child2);
2255 temp_list = g_list_append (temp_list, ancestor);
2257 else if (focus_child == priv->child2)
2259 temp_list = g_list_append (temp_list, ancestor);
2260 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2261 temp_list = g_list_append (temp_list, priv->child1);
2265 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2266 temp_list = g_list_append (temp_list, priv->child1);
2267 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2268 temp_list = g_list_append (temp_list, priv->child2);
2269 temp_list = g_list_append (temp_list, ancestor);
2274 if (focus_child == priv->child1)
2276 temp_list = g_list_append (temp_list, ancestor);
2277 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2278 temp_list = g_list_append (temp_list, priv->child2);
2280 else if (focus_child == priv->child2)
2282 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2283 temp_list = g_list_append (temp_list, priv->child1);
2284 temp_list = g_list_append (temp_list, ancestor);
2288 temp_list = g_list_append (temp_list, priv->last_child2_focus);
2289 temp_list = g_list_append (temp_list, priv->child2);
2290 temp_list = g_list_append (temp_list, priv->last_child1_focus);
2291 temp_list = g_list_append (temp_list, priv->child1);
2292 temp_list = g_list_append (temp_list, ancestor);
2296 /* Walk the list and expand all the paned widgets. */
2297 for (list = temp_list; list != NULL; list = list->next)
2299 GtkWidget *widget = list->data;
2303 if (GTK_IS_PANED (widget))
2305 priv->in_recursion = TRUE;
2306 gtk_paned_get_cycle_chain (GTK_PANED (widget), direction, widgets);
2307 priv->in_recursion = FALSE;
2311 *widgets = g_list_append (*widgets, widget);
2316 g_list_free (temp_list);
2320 gtk_paned_cycle_child_focus (GtkPaned *paned,
2323 GList *cycle_chain = NULL;
2326 GtkDirectionType direction = reversed? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2328 /* ignore f6 if the handle is focused */
2329 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2332 /* we can't just let the event propagate up the hierarchy,
2333 * because the paned will want to cycle focus _unless_ an
2334 * ancestor paned handles the event
2336 gtk_paned_get_cycle_chain (paned, direction, &cycle_chain);
2338 for (list = cycle_chain; list != NULL; list = list->next)
2339 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2342 g_list_free (cycle_chain);
2348 get_child_panes (GtkWidget *widget,
2351 if (!widget || !gtk_widget_get_realized (widget))
2354 if (GTK_IS_PANED (widget))
2356 GtkPaned *paned = GTK_PANED (widget);
2357 GtkPanedPrivate *priv = paned->priv;
2359 get_child_panes (priv->child1, panes);
2360 *panes = g_list_prepend (*panes, widget);
2361 get_child_panes (priv->child2, panes);
2363 else if (GTK_IS_CONTAINER (widget))
2365 gtk_container_forall (GTK_CONTAINER (widget),
2366 (GtkCallback)get_child_panes, panes);
2371 get_all_panes (GtkPaned *paned)
2373 GtkPaned *topmost = NULL;
2374 GList *result = NULL;
2377 for (w = GTK_WIDGET (paned); w != NULL; w = gtk_widget_get_parent (w))
2379 if (GTK_IS_PANED (w))
2380 topmost = GTK_PANED (w);
2385 get_child_panes (GTK_WIDGET (topmost), &result);
2387 return g_list_reverse (result);
2391 gtk_paned_find_neighbours (GtkPaned *paned,
2398 all_panes = get_all_panes (paned);
2399 g_assert (all_panes);
2401 this_link = g_list_find (all_panes, paned);
2403 g_assert (this_link);
2405 if (this_link->next)
2406 *next = this_link->next->data;
2408 *next = all_panes->data;
2410 if (this_link->prev)
2411 *prev = this_link->prev->data;
2413 *prev = g_list_last (all_panes)->data;
2415 g_list_free (all_panes);
2419 gtk_paned_move_handle (GtkPaned *paned,
2420 GtkScrollType scroll)
2422 GtkPanedPrivate *priv = paned->priv;
2424 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2431 SINGLE_STEP_SIZE = 1,
2435 new_position = old_position = gtk_paned_get_position (paned);
2440 case GTK_SCROLL_STEP_LEFT:
2441 case GTK_SCROLL_STEP_UP:
2442 case GTK_SCROLL_STEP_BACKWARD:
2443 increment = - SINGLE_STEP_SIZE;
2446 case GTK_SCROLL_STEP_RIGHT:
2447 case GTK_SCROLL_STEP_DOWN:
2448 case GTK_SCROLL_STEP_FORWARD:
2449 increment = SINGLE_STEP_SIZE;
2452 case GTK_SCROLL_PAGE_LEFT:
2453 case GTK_SCROLL_PAGE_UP:
2454 case GTK_SCROLL_PAGE_BACKWARD:
2455 increment = - PAGE_STEP_SIZE;
2458 case GTK_SCROLL_PAGE_RIGHT:
2459 case GTK_SCROLL_PAGE_DOWN:
2460 case GTK_SCROLL_PAGE_FORWARD:
2461 increment = PAGE_STEP_SIZE;
2464 case GTK_SCROLL_START:
2465 new_position = priv->min_position;
2468 case GTK_SCROLL_END:
2469 new_position = priv->max_position;
2479 increment = -increment;
2481 new_position = old_position + increment;
2484 new_position = CLAMP (new_position, priv->min_position, priv->max_position);
2486 if (old_position != new_position)
2487 gtk_paned_set_position (paned, new_position);
2496 gtk_paned_restore_focus (GtkPaned *paned)
2498 GtkPanedPrivate *priv = paned->priv;
2500 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2502 if (priv->saved_focus &&
2503 gtk_widget_get_sensitive (priv->saved_focus))
2505 gtk_widget_grab_focus (priv->saved_focus);
2509 /* the saved focus is somehow not available for focusing,
2511 * 1) tabbing into the paned widget
2512 * if that didn't work,
2513 * 2) unset focus for the window if there is one
2516 if (!gtk_widget_child_focus (GTK_WIDGET (paned), GTK_DIR_TAB_FORWARD))
2518 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2520 if (GTK_IS_WINDOW (toplevel))
2521 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
2525 gtk_paned_set_saved_focus (paned, NULL);
2526 gtk_paned_set_first_paned (paned, NULL);
2531 gtk_paned_accept_position (GtkPaned *paned)
2533 GtkPanedPrivate *priv = paned->priv;
2535 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2537 priv->original_position = -1;
2538 gtk_paned_restore_focus (paned);
2548 gtk_paned_cancel_position (GtkPaned *paned)
2550 GtkPanedPrivate *priv = paned->priv;
2552 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2554 if (priv->original_position != -1)
2556 gtk_paned_set_position (paned, priv->original_position);
2557 priv->original_position = -1;
2560 gtk_paned_restore_focus (paned);
2568 gtk_paned_cycle_handle_focus (GtkPaned *paned,
2571 GtkPanedPrivate *priv = paned->priv;
2572 GtkPaned *next, *prev;
2574 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2576 GtkPaned *focus = NULL;
2578 if (!priv->first_paned)
2580 /* The first_pane has disappeared. As an ad-hoc solution,
2581 * we make the currently focused paned the first_paned. To the
2582 * user this will seem like the paned cycling has been reset.
2585 gtk_paned_set_first_paned (paned, paned);
2588 gtk_paned_find_neighbours (paned, &next, &prev);
2590 if (reversed && prev &&
2591 prev != paned && paned != priv->first_paned)
2595 else if (!reversed && next &&
2596 next != paned && next != priv->first_paned)
2602 gtk_paned_accept_position (paned);
2608 gtk_paned_set_saved_focus (focus, priv->saved_focus);
2609 gtk_paned_set_first_paned (focus, priv->first_paned);
2611 gtk_paned_set_saved_focus (paned, NULL);
2612 gtk_paned_set_first_paned (paned, NULL);
2614 gtk_widget_grab_focus (GTK_WIDGET (focus));
2616 if (!gtk_widget_is_focus (GTK_WIDGET (paned)))
2618 priv->original_position = -1;
2619 focus->priv->original_position = gtk_paned_get_position (focus);
2624 GtkContainer *container = GTK_CONTAINER (paned);
2627 GtkPaned *prev, *next;
2628 GtkWidget *toplevel;
2629 GtkWidget *focus_child;
2631 gtk_paned_find_neighbours (paned, &next, &prev);
2632 focus_child = gtk_container_get_focus_child (container);
2634 if (focus_child == priv->child1)
2647 else if (focus_child == priv->child2)
2662 /* Focus is not inside this paned, and we don't have focus.
2663 * Presumably this happened because the application wants us
2664 * to start keyboard navigating.
2674 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
2676 if (GTK_IS_WINDOW (toplevel))
2677 gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
2678 gtk_paned_set_first_paned (focus, first);
2679 focus->priv->original_position = gtk_paned_get_position (focus);
2681 gtk_widget_grab_focus (GTK_WIDGET (focus));
2688 gtk_paned_toggle_handle_focus (GtkPaned *paned)
2690 /* This function/signal has the wrong name. It is called when you
2691 * press Tab or Shift-Tab and what we do is act as if
2692 * the user pressed Return and then Tab or Shift-Tab
2694 if (gtk_widget_is_focus (GTK_WIDGET (paned)))
2695 gtk_paned_accept_position (paned);
2701 * gtk_paned_get_handle_window:
2702 * @paned: a #GtkPaned
2704 * Returns the #GdkWindow of the handle. This function is
2705 * useful when handling button or motion events because it
2706 * enables the callback to distinguish between the window
2707 * of the paned, a child and the handle.
2709 * Return value: (transfer none): the paned's handle window.
2714 gtk_paned_get_handle_window (GtkPaned *paned)
2716 g_return_val_if_fail (GTK_IS_PANED (paned), NULL);
2718 return paned->priv->handle;