1 /*******************************************************************************
2 **3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
3 ** 10 20 30 40 50 60 70 80
5 ** library for GtkXPaned-widget, a 2x2 grid-like variation of GtkPaned of gtk+
6 ** Copyright (C) 2012, 2013 Free Software Foundation, Inc.
7 ** Copyright (C) 2005-2006 Mirco "MacSlow" Müller <macslow@bangang.de>
9 ** This library is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU Lesser General Public
11 ** License as published by the Free Software Foundation; either
12 ** version 2.1 of the License, or (at your option) any later version.
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ** Lesser General Public License for more details.
19 ** You should have received a copy of the GNU Lesser General Public
20 ** License along with this library; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ** GtkXPaned is based on GtkPaned which was done by...
25 ** "Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald"
27 ** and later modified by...
29 ** "the GTK+ Team and others 1997-2000"
31 *******************************************************************************/
34 #include "gtkxpaned.h"
37 #include <ui/gui/psppire-marshal.h>
38 #include <gdk/gdkkeysyms.h>
39 #include <gdk/gdkkeysyms-compat.h>
71 static void gtk_xpaned_class_init (GtkXPanedClass * klass);
73 static void gtk_xpaned_init (GtkXPaned * xpaned);
76 gtk_xpaned_get_preferred_width (GtkWidget *widget,
80 GtkXPaned *xpaned = GTK_XPANED (widget);
81 gint tl[2], tr[2], bl[2], br[2];
86 if (xpaned->top_left_child
87 && gtk_widget_get_visible (xpaned->top_left_child))
88 gtk_widget_get_preferred_width (xpaned->top_left_child, &tl[0], &tl[1]);
92 if (xpaned->top_right_child
93 && gtk_widget_get_visible (xpaned->top_right_child))
94 gtk_widget_get_preferred_width (xpaned->top_right_child, &tr[0], &tr[1]);
98 if (xpaned->bottom_left_child
99 && gtk_widget_get_visible (xpaned->bottom_left_child))
100 gtk_widget_get_preferred_width (xpaned->bottom_left_child, &bl[0], &bl[1]);
104 if (xpaned->bottom_right_child
105 && gtk_widget_get_visible (xpaned->bottom_right_child))
106 gtk_widget_get_preferred_width (xpaned->bottom_right_child,
111 /* add 2 times the set border-width to the GtkXPaneds requisition */
112 overhead = gtk_container_get_border_width (GTK_CONTAINER (xpaned)) * 2;
114 /* also add the handle "thickness" to GtkXPaned's width requisition */
115 if (xpaned->top_left_child
116 && gtk_widget_get_visible (xpaned->top_left_child)
117 && xpaned->top_right_child
118 && gtk_widget_get_visible (xpaned->top_right_child)
119 && xpaned->bottom_left_child
120 && gtk_widget_get_visible (xpaned->bottom_left_child)
121 && xpaned->bottom_right_child
122 && gtk_widget_get_visible (xpaned->bottom_right_child))
126 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
127 overhead += handle_size;
130 for (i = 0; i < 2; i++)
131 w[i] = (br[i] ? br[i] : MAX (tl[i] + tr[i], bl[i])) + overhead;
133 *minimal_width = w[0];
134 *natural_width = w[1];
138 gtk_xpaned_get_preferred_height (GtkWidget *widget,
139 gint *minimal_height,
140 gint *natural_height)
142 GtkXPaned *xpaned = GTK_XPANED (widget);
143 gint tl[2], tr[2], bl[2], br[2];
148 if (xpaned->top_left_child
149 && gtk_widget_get_visible (xpaned->top_left_child))
150 gtk_widget_get_preferred_height (xpaned->top_left_child, &tl[0], &tl[1]);
154 if (xpaned->top_right_child
155 && gtk_widget_get_visible (xpaned->top_right_child))
156 gtk_widget_get_preferred_height (xpaned->top_right_child, &tr[0], &tr[1]);
160 if (xpaned->bottom_left_child
161 && gtk_widget_get_visible (xpaned->bottom_left_child))
162 gtk_widget_get_preferred_height (xpaned->bottom_left_child,
167 if (xpaned->bottom_right_child
168 && gtk_widget_get_visible (xpaned->bottom_right_child))
169 gtk_widget_get_preferred_height (xpaned->bottom_right_child,
174 /* add 2 times the set border-width to the GtkXPaneds requisition */
175 overhead = gtk_container_get_border_width (GTK_CONTAINER (xpaned)) * 2;
177 /* also add the handle "thickness" to GtkXPaned's height-requisition */
178 if (xpaned->top_left_child
179 && gtk_widget_get_visible (xpaned->top_left_child)
180 && xpaned->top_right_child
181 && gtk_widget_get_visible (xpaned->top_right_child)
182 && xpaned->bottom_left_child
183 && gtk_widget_get_visible (xpaned->bottom_left_child)
184 && xpaned->bottom_right_child
185 && gtk_widget_get_visible (xpaned->bottom_right_child))
189 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
190 overhead += handle_size;
193 for (i = 0; i < 2; i++)
194 h[i] = (br[i] ? br[i] : bl[i] + MAX (tl[i], tr[i])) + overhead;
196 *minimal_height = h[0];
197 *natural_height = h[1];
200 static void gtk_xpaned_size_allocate (GtkWidget * widget,
201 GtkAllocation * allocation);
203 static void gtk_xpaned_set_property (GObject * object,
205 const GValue * value,
208 static void gtk_xpaned_get_property (GObject * object,
210 GValue * value, GParamSpec * pspec);
212 static void gtk_xpaned_set_child_property (GtkContainer * container,
215 const GValue * value,
218 static void gtk_xpaned_get_child_property (GtkContainer * container,
224 static void gtk_xpaned_finalize (GObject * object);
226 static void gtk_xpaned_realize (GtkWidget * widget);
228 static void gtk_xpaned_unrealize (GtkWidget * widget);
230 static void gtk_xpaned_map (GtkWidget * widget);
232 static void gtk_xpaned_unmap (GtkWidget * widget);
234 static gboolean gtk_xpaned_draw (GtkWidget * widget,
237 static gboolean gtk_xpaned_enter (GtkWidget * widget,
238 GdkEventCrossing * event);
240 static gboolean gtk_xpaned_leave (GtkWidget * widget,
241 GdkEventCrossing * event);
243 static gboolean gtk_xpaned_button_press (GtkWidget * widget,
244 GdkEventButton * event);
246 static gboolean gtk_xpaned_button_release (GtkWidget * widget,
247 GdkEventButton * event);
249 static gboolean gtk_xpaned_motion (GtkWidget * widget,
250 GdkEventMotion * event);
252 static gboolean gtk_xpaned_focus (GtkWidget * widget,
253 GtkDirectionType direction);
255 static void gtk_xpaned_add (GtkContainer * container, GtkWidget * widget);
257 static void gtk_xpaned_remove (GtkContainer * container, GtkWidget * widget);
259 static void gtk_xpaned_forall (GtkContainer * container,
260 gboolean include_internals,
261 GtkCallback callback, gpointer callback_data);
263 static void gtk_xpaned_set_focus_child (GtkContainer * container,
266 static void gtk_xpaned_set_saved_focus (GtkXPaned * xpaned,
269 static void gtk_xpaned_set_first_xpaned (GtkXPaned * xpaned,
270 GtkXPaned * first_xpaned);
272 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned * xpaned,
275 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned * xpaned,
278 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned * xpaned,
281 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned * xpaned,
284 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned * xpaned,
287 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned * xpaned,
290 static gboolean gtk_xpaned_move_handle (GtkXPaned * xpaned,
291 GtkScrollType scroll);
293 static gboolean gtk_xpaned_accept_position (GtkXPaned * xpaned);
295 static gboolean gtk_xpaned_cancel_position (GtkXPaned * xpaned);
297 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned * xpaned);
299 static GType gtk_xpaned_child_type (GtkContainer * container);
301 static GtkContainerClass *parent_class = NULL;
303 struct _GtkXPanedPrivate
305 GtkWidget *saved_focus;
306 GtkXPaned *first_xpaned;
310 gtk_xpaned_get_type (void)
312 static GType xpaned_type = 0;
316 static const GTypeInfo xpaned_info = {
317 sizeof (GtkXPanedClass),
318 NULL, /* base_init */
319 NULL, /* base_finalize */
320 (GClassInitFunc) gtk_xpaned_class_init,
321 NULL, /* class_finalize */
322 NULL, /* class_data */
325 (GInstanceInitFunc) gtk_xpaned_init
328 xpaned_type = g_type_register_static (GTK_TYPE_CONTAINER,
329 "GtkXPaned", &xpaned_info, 0);
336 gtk_xpaned_new (void)
340 xpaned = g_object_new (GTK_TYPE_XPANED, NULL);
342 return GTK_WIDGET (xpaned);
345 static guint signals[LAST_SIGNAL] = { 0 };
348 add_tab_bindings (GtkBindingSet * binding_set, GdkModifierType modifiers)
350 gtk_binding_entry_add_signal (binding_set,
351 GDK_Tab, modifiers, "toggle_handle_focus", 0);
353 gtk_binding_entry_add_signal (binding_set,
355 modifiers, "toggle_handle_focus", 0);
359 add_move_binding (GtkBindingSet * binding_set,
360 guint keyval, GdkModifierType mask, GtkScrollType scroll)
362 gtk_binding_entry_add_signal (binding_set,
366 1, GTK_TYPE_SCROLL_TYPE, scroll);
370 gtk_xpaned_class_init (GtkXPanedClass * class)
372 GObjectClass *object_class;
373 GtkWidgetClass *widget_class;
374 GtkContainerClass *container_class;
375 GtkXPanedClass *xpaned_class;
376 GtkBindingSet *binding_set;
378 object_class = (GObjectClass *) class;
379 widget_class = (GtkWidgetClass *) class;
380 container_class = (GtkContainerClass *) class;
381 xpaned_class = (GtkXPanedClass *) class;
383 parent_class = g_type_class_peek_parent (class);
385 object_class->set_property = gtk_xpaned_set_property;
386 object_class->get_property = gtk_xpaned_get_property;
387 object_class->finalize = gtk_xpaned_finalize;
389 widget_class->realize = gtk_xpaned_realize;
390 widget_class->unrealize = gtk_xpaned_unrealize;
391 widget_class->map = gtk_xpaned_map;
392 widget_class->unmap = gtk_xpaned_unmap;
393 widget_class->draw = gtk_xpaned_draw;
394 widget_class->focus = gtk_xpaned_focus;
395 widget_class->enter_notify_event = gtk_xpaned_enter;
396 widget_class->leave_notify_event = gtk_xpaned_leave;
397 widget_class->button_press_event = gtk_xpaned_button_press;
398 widget_class->button_release_event = gtk_xpaned_button_release;
399 widget_class->motion_notify_event = gtk_xpaned_motion;
400 widget_class->get_preferred_width = gtk_xpaned_get_preferred_width;
401 widget_class->get_preferred_height = gtk_xpaned_get_preferred_height;
403 widget_class->size_allocate = gtk_xpaned_size_allocate;
405 container_class->add = gtk_xpaned_add;
406 container_class->remove = gtk_xpaned_remove;
407 container_class->forall = gtk_xpaned_forall;
408 container_class->child_type = gtk_xpaned_child_type;
409 container_class->set_focus_child = gtk_xpaned_set_focus_child;
410 container_class->set_child_property = gtk_xpaned_set_child_property;
411 container_class->get_child_property = gtk_xpaned_get_child_property;
413 xpaned_class->cycle_child_focus = gtk_xpaned_cycle_child_focus;
414 xpaned_class->toggle_handle_focus = gtk_xpaned_toggle_handle_focus;
415 xpaned_class->move_handle = gtk_xpaned_move_handle;
416 xpaned_class->cycle_handle_focus = gtk_xpaned_cycle_handle_focus;
417 xpaned_class->accept_position = gtk_xpaned_accept_position;
418 xpaned_class->cancel_position = gtk_xpaned_cancel_position;
420 g_object_class_install_property (object_class,
422 g_param_spec_int ("x-position",
424 ("x-Position of paned separator in pixels (0 means all the way to the left)"),
431 g_object_class_install_property (object_class,
433 g_param_spec_int ("y-position",
435 "y-Position of paned separator in pixels (0 means all the way to the top)",
442 g_object_class_install_property (object_class,
444 g_param_spec_boolean ("position-set",
446 "TRUE if the Position property should be used",
451 gtk_widget_class_install_style_property (widget_class,
452 g_param_spec_int ("handle-size",
460 * GtkXPaned:min-x-position:
462 * The smallest possible value for the x-position property. This property is derived from the
463 * size and shrinkability of the widget's children.
467 g_object_class_install_property (object_class,
469 g_param_spec_int ("min-x-position",
470 "Minimal x-Position",
471 "Smallest possible value for the \"x-position\" property",
474 0, G_PARAM_READABLE));
477 * GtkXPaned:min-y-position:
479 * The smallest possible value for the y-position property. This property is derived from the
480 * size and shrinkability of the widget's children.
484 g_object_class_install_property (object_class,
486 g_param_spec_int ("min-y-position",
487 "Minimal y-Position",
488 "Smallest possible value for the \"y-position\" property",
491 0, G_PARAM_READABLE));
494 * GtkPaned:max-x-position:
496 * The largest possible value for the x-position property. This property is derived from the
497 * size and shrinkability of the widget's children.
501 g_object_class_install_property (object_class,
503 g_param_spec_int ("max-x-position",
504 "Maximal x-Position",
505 "Largest possible value for the \"x-position\" property",
512 * GtkPaned:max-y-position:
514 * The largest possible value for the y-position property. This property is derived from the
515 * size and shrinkability of the widget's children.
519 g_object_class_install_property (object_class,
521 g_param_spec_int ("max-y-position",
522 "Maximal y-Position",
523 "Largest possible value for the \"y-position\" property",
532 * The "resize" child property determines whether the child expands and
533 * shrinks along with the paned widget.
537 gtk_container_class_install_child_property (container_class,
539 g_param_spec_boolean ("resize",
541 "If TRUE, the child expands and shrinks along with the paned widget",
548 * The "shrink" child property determines whether the child can be made
549 * smaller than its requisition.
553 gtk_container_class_install_child_property (container_class,
555 g_param_spec_boolean ("shrink",
557 "If TRUE, the child can be made smaller than its requisition",
561 signals[CYCLE_CHILD_FOCUS] = g_signal_new ("cycle-child-focus",
562 G_TYPE_FROM_CLASS (object_class),
565 G_STRUCT_OFFSET (GtkXPanedClass,
568 psppire_marshal_BOOLEAN__BOOLEAN,
572 signals[TOGGLE_HANDLE_FOCUS] = g_signal_new ("toggle-handle-focus",
579 toggle_handle_focus), NULL,
581 psppire_marshal_BOOLEAN__VOID,
584 signals[MOVE_HANDLE] = g_signal_new ("move-handle",
585 G_TYPE_FROM_CLASS (object_class),
586 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
587 G_STRUCT_OFFSET (GtkXPanedClass,
589 NULL, psppire_marshal_BOOLEAN__ENUM,
591 GTK_TYPE_SCROLL_TYPE);
593 signals[CYCLE_HANDLE_FOCUS] = g_signal_new ("cycle-handle-focus",
598 G_STRUCT_OFFSET (GtkXPanedClass,
601 psppire_marshal_BOOLEAN__BOOLEAN,
605 signals[ACCEPT_POSITION] = g_signal_new ("accept-position",
606 G_TYPE_FROM_CLASS (object_class),
609 G_STRUCT_OFFSET (GtkXPanedClass,
612 psppire_marshal_BOOLEAN__VOID,
615 signals[CANCEL_POSITION] = g_signal_new ("cancel-position",
616 G_TYPE_FROM_CLASS (object_class),
619 G_STRUCT_OFFSET (GtkXPanedClass,
622 psppire_marshal_BOOLEAN__VOID,
625 binding_set = gtk_binding_set_by_class (class);
628 gtk_binding_entry_add_signal (binding_set,
630 "cycle-child-focus", 1,
631 G_TYPE_BOOLEAN, FALSE);
633 gtk_binding_entry_add_signal (binding_set,
634 GDK_F6, GDK_SHIFT_MASK,
635 "cycle-child-focus", 1, G_TYPE_BOOLEAN, TRUE);
638 gtk_binding_entry_add_signal (binding_set,
640 "cycle-handle-focus", 1,
641 G_TYPE_BOOLEAN, FALSE);
643 gtk_binding_entry_add_signal (binding_set,
644 GDK_F8, GDK_SHIFT_MASK,
645 "cycle-handle-focus", 1,
646 G_TYPE_BOOLEAN, TRUE);
648 add_tab_bindings (binding_set, 0);
649 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
650 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
651 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
653 /* accept and cancel positions */
654 gtk_binding_entry_add_signal (binding_set,
655 GDK_Escape, 0, "cancel-position", 0);
657 gtk_binding_entry_add_signal (binding_set,
658 GDK_Return, 0, "accept-position", 0);
660 gtk_binding_entry_add_signal (binding_set,
661 GDK_KP_Enter, 0, "accept-position", 0);
663 gtk_binding_entry_add_signal (binding_set,
664 GDK_space, 0, "accept-position", 0);
666 gtk_binding_entry_add_signal (binding_set,
667 GDK_KP_Space, 0, "accept-position", 0);
670 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
671 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
672 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
673 GTK_SCROLL_PAGE_LEFT);
674 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
675 GTK_SCROLL_PAGE_LEFT);
677 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
678 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
679 GTK_SCROLL_PAGE_RIGHT);
680 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
681 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
682 GTK_SCROLL_PAGE_RIGHT);
684 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
685 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK,
687 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
688 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK,
690 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
691 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
693 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
694 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK,
695 GTK_SCROLL_PAGE_DOWN);
696 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
697 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK,
698 GTK_SCROLL_PAGE_DOWN);
699 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
700 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
702 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
703 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
704 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
705 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
709 gtk_xpaned_child_type (GtkContainer * container)
711 if (!GTK_XPANED (container)->top_left_child ||
712 !GTK_XPANED (container)->top_right_child ||
713 !GTK_XPANED (container)->bottom_left_child ||
714 !GTK_XPANED (container)->bottom_right_child)
715 return GTK_TYPE_WIDGET;
721 gtk_xpaned_init (GtkXPaned * xpaned)
723 gtk_widget_set_can_focus (GTK_WIDGET (xpaned), TRUE);
724 gtk_widget_set_has_window (GTK_WIDGET (xpaned), FALSE);
726 xpaned->top_left_child = NULL;
727 xpaned->top_right_child = NULL;
728 xpaned->bottom_left_child = NULL;
729 xpaned->bottom_right_child = NULL;
730 xpaned->handle_east = NULL;
731 xpaned->handle_west = NULL;
732 xpaned->handle_north = NULL;
733 xpaned->handle_south = NULL;
734 xpaned->handle_middle = NULL;
735 xpaned->cursor_type_east = GDK_SB_V_DOUBLE_ARROW;
736 xpaned->cursor_type_west = GDK_SB_V_DOUBLE_ARROW;
737 xpaned->cursor_type_north = GDK_SB_H_DOUBLE_ARROW;
738 xpaned->cursor_type_south = GDK_SB_H_DOUBLE_ARROW;
739 xpaned->cursor_type_middle = GDK_FLEUR;
741 xpaned->handle_pos_east.width = 5;
742 xpaned->handle_pos_east.height = 5;
743 xpaned->handle_pos_west.width = 5;
744 xpaned->handle_pos_west.height = 5;
745 xpaned->handle_pos_north.width = 5;
746 xpaned->handle_pos_north.height = 5;
747 xpaned->handle_pos_south.width = 5;
748 xpaned->handle_pos_south.height = 5;
749 xpaned->handle_pos_middle.width = 5;
750 xpaned->handle_pos_middle.height = 5;
752 xpaned->position_set = FALSE;
753 xpaned->last_allocation.width = -1;
754 xpaned->last_allocation.height = -1;
755 xpaned->in_drag_vert = FALSE;
756 xpaned->in_drag_horiz = FALSE;
757 xpaned->in_drag_vert_and_horiz = FALSE;
759 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
760 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
761 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
762 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
764 xpaned->priv = g_new0 (GtkXPanedPrivate, 1);
765 xpaned->last_top_left_child_focus = NULL;
766 xpaned->last_top_right_child_focus = NULL;
767 xpaned->last_bottom_left_child_focus = NULL;
768 xpaned->last_bottom_right_child_focus = NULL;
769 xpaned->in_recursion = FALSE;
770 xpaned->handle_prelit = FALSE;
771 xpaned->original_position.x = -1;
772 xpaned->original_position.y = -1;
773 xpaned->unmaximized_position.x = -1;
774 xpaned->unmaximized_position.y = -1;
776 xpaned->handle_pos_east.x = -1;
777 xpaned->handle_pos_east.y = -1;
778 xpaned->handle_pos_west.x = -1;
779 xpaned->handle_pos_west.y = -1;
780 xpaned->handle_pos_north.x = -1;
781 xpaned->handle_pos_north.y = -1;
782 xpaned->handle_pos_south.x = -1;
783 xpaned->handle_pos_south.y = -1;
784 xpaned->handle_pos_middle.x = -1;
785 xpaned->handle_pos_middle.y = -1;
787 xpaned->drag_pos.x = -1;
788 xpaned->drag_pos.y = -1;
792 gtk_xpaned_compute_position (GtkXPaned * xpaned,
793 const GtkAllocation * allocation,
794 GtkRequisition * top_left_child_req,
795 GtkRequisition * top_right_child_req,
796 GtkRequisition * bottom_left_child_req,
797 GtkRequisition * bottom_right_child_req);
801 gtk_xpaned_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
803 GtkXPaned *xpaned = GTK_XPANED (widget);
804 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (xpaned));
805 GtkAllocation top_left_child_allocation;
806 GtkAllocation top_right_child_allocation;
807 GtkAllocation bottom_left_child_allocation;
808 GtkAllocation bottom_right_child_allocation;
809 GtkRequisition top_left_child_requisition;
810 GtkRequisition top_right_child_requisition;
811 GtkRequisition bottom_left_child_requisition;
812 GtkRequisition bottom_right_child_requisition;
815 /* determine size of handle(s) */
816 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
818 gtk_widget_set_allocation (widget, allocation);
820 if (xpaned->top_left_child
821 && gtk_widget_get_visible (xpaned->top_left_child)
822 && xpaned->top_right_child
823 && gtk_widget_get_visible (xpaned->top_right_child)
824 && xpaned->bottom_left_child
825 && gtk_widget_get_visible (xpaned->bottom_left_child)
826 && xpaned->bottom_right_child
827 && gtk_widget_get_visible (xpaned->bottom_right_child))
829 /* what sizes do the children want to be at least at */
830 gtk_widget_get_preferred_size (xpaned->top_left_child,
831 &top_left_child_requisition, NULL);
832 gtk_widget_get_preferred_size (xpaned->top_right_child,
833 &top_right_child_requisition, NULL);
834 gtk_widget_get_preferred_size (xpaned->bottom_left_child,
835 &bottom_left_child_requisition, NULL);
836 gtk_widget_get_preferred_size (xpaned->bottom_right_child,
837 &bottom_right_child_requisition, NULL);
839 /* determine the total requisition-sum of all requisitions of borders,
840 * handles, children etc. */
841 gtk_xpaned_compute_position (xpaned,
843 &top_left_child_requisition,
844 &top_right_child_requisition,
845 &bottom_left_child_requisition,
846 &bottom_right_child_requisition);
848 /* calculate the current positions and sizes of the handles */
849 xpaned->handle_pos_east.x =
850 allocation->x + border_width +
851 xpaned->top_left_child_size.width + handle_size;
852 xpaned->handle_pos_east.y =
853 allocation->y + border_width +
854 xpaned->top_left_child_size.height;
855 xpaned->handle_pos_east.width =
856 allocation->width - xpaned->top_left_child_size.width -
857 2 * border_width - handle_size;
858 xpaned->handle_pos_east.height = handle_size;
860 xpaned->handle_pos_west.x = allocation->x + border_width;
861 xpaned->handle_pos_west.y = xpaned->handle_pos_east.y;
862 xpaned->handle_pos_west.width =
863 allocation->width - xpaned->handle_pos_east.width -
864 2 * border_width - handle_size;
865 xpaned->handle_pos_west.height = handle_size;
867 xpaned->handle_pos_north.x = xpaned->handle_pos_east.x - handle_size;
868 xpaned->handle_pos_north.y = allocation->y + border_width;
869 xpaned->handle_pos_north.width = handle_size;
870 xpaned->handle_pos_north.height =
871 xpaned->handle_pos_east.y - allocation->y - border_width;
873 xpaned->handle_pos_south.x = xpaned->handle_pos_north.x;
874 xpaned->handle_pos_south.y = xpaned->handle_pos_east.y + handle_size;
875 xpaned->handle_pos_south.width = handle_size;
876 xpaned->handle_pos_south.height =
877 allocation->height - xpaned->handle_pos_north.height -
878 2 * border_width - handle_size;
882 xpaned->handle_pos_middle.x = xpaned->handle_pos_north.x;
883 xpaned->handle_pos_middle.y = xpaned->handle_pos_east.y;
884 xpaned->handle_pos_middle.width = handle_size + CENTRUM;
885 xpaned->handle_pos_middle.height = handle_size + CENTRUM;
887 /* set allocation for top-left child */
888 top_left_child_allocation.x = allocation->x + border_width;
889 top_left_child_allocation.y = allocation->y + border_width;
890 top_left_child_allocation.width = xpaned->handle_pos_west.width;
891 top_left_child_allocation.height = xpaned->handle_pos_north.height;
893 /* set allocation for top-right child */
894 top_right_child_allocation.x =
895 allocation->x + border_width + handle_size +
896 top_left_child_allocation.width;
897 top_right_child_allocation.y = allocation->y + border_width;
898 top_right_child_allocation.width = xpaned->handle_pos_east.width;
899 top_right_child_allocation.height = xpaned->handle_pos_north.height;
901 /* set allocation for bottom-left child */
902 bottom_left_child_allocation.x = xpaned->handle_pos_west.x;
903 bottom_left_child_allocation.y = xpaned->handle_pos_south.y;
904 bottom_left_child_allocation.width = xpaned->handle_pos_west.width;
905 bottom_left_child_allocation.height = xpaned->handle_pos_south.height;
907 /* set allocation for bottom-right child */
908 bottom_right_child_allocation.x = top_right_child_allocation.x;
909 bottom_right_child_allocation.y = bottom_left_child_allocation.y;
910 bottom_right_child_allocation.width = xpaned->handle_pos_east.width;
911 bottom_right_child_allocation.height = xpaned->handle_pos_south.height;
913 if (gtk_widget_get_realized (widget))
915 if (gtk_widget_get_mapped (widget))
917 gdk_window_show (xpaned->handle_east);
918 gdk_window_show (xpaned->handle_west);
919 gdk_window_show (xpaned->handle_north);
920 gdk_window_show (xpaned->handle_south);
921 gdk_window_show (xpaned->handle_middle);
924 gdk_window_move_resize (xpaned->handle_east,
925 xpaned->handle_pos_east.x,
926 xpaned->handle_pos_east.y,
927 xpaned->handle_pos_east.width,
928 xpaned->handle_pos_east.height);
930 gdk_window_move_resize (xpaned->handle_west,
931 xpaned->handle_pos_west.x,
932 xpaned->handle_pos_west.y,
933 xpaned->handle_pos_west.width,
934 xpaned->handle_pos_west.height);
936 gdk_window_move_resize (xpaned->handle_north,
937 xpaned->handle_pos_north.x,
938 xpaned->handle_pos_north.y,
939 xpaned->handle_pos_north.width,
940 xpaned->handle_pos_north.height);
942 gdk_window_move_resize (xpaned->handle_south,
943 xpaned->handle_pos_south.x,
944 xpaned->handle_pos_south.y,
945 xpaned->handle_pos_south.width,
946 xpaned->handle_pos_south.height);
948 gdk_window_move_resize (xpaned->handle_middle,
949 xpaned->handle_pos_middle.x,
950 xpaned->handle_pos_middle.y,
951 xpaned->handle_pos_middle.width,
952 xpaned->handle_pos_middle.height);
955 /* Now allocate the childen, making sure, when resizing not to
956 * overlap the windows
958 if (gtk_widget_get_mapped (widget))
960 gtk_widget_size_allocate (xpaned->top_right_child,
961 &top_right_child_allocation);
962 gtk_widget_size_allocate (xpaned->top_left_child,
963 &top_left_child_allocation);
964 gtk_widget_size_allocate (xpaned->bottom_left_child,
965 &bottom_left_child_allocation);
966 gtk_widget_size_allocate (xpaned->bottom_right_child,
967 &bottom_right_child_allocation);
973 gtk_xpaned_set_property (GObject * object,
975 const GValue * value, GParamSpec * pspec)
977 GtkXPaned *xpaned = GTK_XPANED (object);
981 case PROP_X_POSITION:
982 gtk_xpaned_set_position_x (xpaned, g_value_get_int (value));
985 case PROP_Y_POSITION:
986 gtk_xpaned_set_position_y (xpaned, g_value_get_int (value));
989 case PROP_POSITION_SET:
990 xpaned->position_set = g_value_get_boolean (value);
991 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
995 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1001 gtk_xpaned_get_property (GObject * object,
1002 guint prop_id, GValue * value, GParamSpec * pspec)
1004 GtkXPaned *xpaned = GTK_XPANED (object);
1008 case PROP_X_POSITION:
1009 g_value_set_int (value, xpaned->top_left_child_size.width);
1012 case PROP_Y_POSITION:
1013 g_value_set_int (value, xpaned->top_left_child_size.height);
1016 case PROP_POSITION_SET:
1017 g_value_set_boolean (value, xpaned->position_set);
1020 case PROP_MIN_X_POSITION:
1021 g_value_set_int (value, xpaned->min_position.x);
1024 case PROP_MIN_Y_POSITION:
1025 g_value_set_int (value, xpaned->min_position.y);
1028 case PROP_MAX_X_POSITION:
1029 g_value_set_int (value, xpaned->max_position.x);
1032 case PROP_MAX_Y_POSITION:
1033 g_value_set_int (value, xpaned->max_position.y);
1037 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1043 gtk_xpaned_set_child_property (GtkContainer * container,
1046 const GValue * value, GParamSpec * pspec)
1048 GtkXPaned *xpaned = GTK_XPANED (container);
1049 gboolean old_value = FALSE;
1050 gboolean new_value = FALSE;
1052 g_assert (child == xpaned->top_left_child ||
1053 child == xpaned->top_right_child ||
1054 child == xpaned->bottom_left_child ||
1055 child == xpaned->bottom_right_child);
1057 new_value = g_value_get_boolean (value);
1059 switch (property_id)
1061 case CHILD_PROP_RESIZE:
1062 if (child == xpaned->top_left_child)
1064 old_value = xpaned->top_left_child_resize;
1065 xpaned->top_left_child_resize = new_value;
1067 else if (child == xpaned->top_right_child)
1069 old_value = xpaned->top_right_child_resize;
1070 xpaned->top_right_child_resize = new_value;
1072 else if (child == xpaned->bottom_left_child)
1074 old_value = xpaned->bottom_left_child_resize;
1075 xpaned->bottom_left_child_resize = new_value;
1077 else if (child == xpaned->bottom_right_child)
1079 old_value = xpaned->bottom_right_child_resize;
1080 xpaned->bottom_right_child_resize = new_value;
1084 case CHILD_PROP_SHRINK:
1085 if (child == xpaned->top_left_child)
1087 old_value = xpaned->top_left_child_shrink;
1088 xpaned->top_left_child_shrink = new_value;
1090 else if (child == xpaned->top_right_child)
1092 old_value = xpaned->top_right_child_shrink;
1093 xpaned->top_right_child_shrink = new_value;
1095 else if (child == xpaned->bottom_left_child)
1097 old_value = xpaned->bottom_left_child_shrink;
1098 xpaned->bottom_left_child_shrink = new_value;
1100 else if (child == xpaned->bottom_right_child)
1102 old_value = xpaned->bottom_right_child_shrink;
1103 xpaned->bottom_right_child_shrink = new_value;
1108 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1109 property_id, pspec);
1110 old_value = -1; /* quiet gcc */
1114 if (old_value != new_value)
1115 gtk_widget_queue_resize (GTK_WIDGET (container));
1119 gtk_xpaned_get_child_property (GtkContainer * container,
1122 GValue * value, GParamSpec * pspec)
1124 GtkXPaned *xpaned = GTK_XPANED (container);
1126 g_assert (child == xpaned->top_left_child ||
1127 child == xpaned->top_right_child ||
1128 child == xpaned->bottom_left_child ||
1129 child == xpaned->bottom_right_child);
1131 switch (property_id)
1133 case CHILD_PROP_RESIZE:
1134 if (child == xpaned->top_left_child)
1135 g_value_set_boolean (value, xpaned->top_left_child_resize);
1136 else if (child == xpaned->top_right_child)
1137 g_value_set_boolean (value, xpaned->top_right_child_resize);
1138 else if (child == xpaned->bottom_left_child)
1139 g_value_set_boolean (value, xpaned->bottom_left_child_resize);
1140 else if (child == xpaned->bottom_right_child)
1141 g_value_set_boolean (value, xpaned->bottom_right_child_resize);
1144 case CHILD_PROP_SHRINK:
1145 if (child == xpaned->top_left_child)
1146 g_value_set_boolean (value, xpaned->top_left_child_shrink);
1147 else if (child == xpaned->top_right_child)
1148 g_value_set_boolean (value, xpaned->top_right_child_shrink);
1149 else if (child == xpaned->bottom_left_child)
1150 g_value_set_boolean (value, xpaned->bottom_left_child_shrink);
1151 else if (child == xpaned->bottom_right_child)
1152 g_value_set_boolean (value, xpaned->bottom_right_child_shrink);
1156 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1157 property_id, pspec);
1163 gtk_xpaned_finalize (GObject * object)
1165 GtkXPaned *xpaned = GTK_XPANED (object);
1167 gtk_xpaned_set_saved_focus (xpaned, NULL);
1168 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1170 g_free (xpaned->priv);
1172 G_OBJECT_CLASS (parent_class)->finalize (object);
1176 gtk_xpaned_realize (GtkWidget * widget)
1179 GdkWindowAttr attributes_east;
1180 GdkWindowAttr attributes_west;
1181 GdkWindowAttr attributes_north;
1182 GdkWindowAttr attributes_south;
1183 GdkWindowAttr attributes_middle;
1184 gint attributes_mask_east;
1185 gint attributes_mask_west;
1186 gint attributes_mask_north;
1187 gint attributes_mask_south;
1188 gint attributes_mask_middle;
1190 gtk_widget_set_realized (widget, TRUE);
1191 xpaned = GTK_XPANED (widget);
1193 gtk_widget_set_window (widget, gtk_widget_get_parent_window (widget));
1194 // g_object_ref (widget->window);
1196 attributes_east.window_type = GDK_WINDOW_CHILD;
1197 attributes_west.window_type = GDK_WINDOW_CHILD;
1198 attributes_north.window_type = GDK_WINDOW_CHILD;
1199 attributes_south.window_type = GDK_WINDOW_CHILD;
1200 attributes_middle.window_type = GDK_WINDOW_CHILD;
1202 attributes_east.wclass = GDK_INPUT_ONLY;
1203 attributes_west.wclass = GDK_INPUT_ONLY;
1204 attributes_north.wclass = GDK_INPUT_ONLY;
1205 attributes_south.wclass = GDK_INPUT_ONLY;
1206 attributes_middle.wclass = GDK_INPUT_ONLY;
1208 attributes_east.x = xpaned->handle_pos_east.x;
1209 attributes_east.y = xpaned->handle_pos_east.y;
1210 attributes_east.width = xpaned->handle_pos_east.width;
1211 attributes_east.height = xpaned->handle_pos_east.height;
1213 attributes_west.x = xpaned->handle_pos_west.x;
1214 attributes_west.y = xpaned->handle_pos_west.y;
1215 attributes_west.width = xpaned->handle_pos_west.width;
1216 attributes_west.height = xpaned->handle_pos_west.height;
1218 attributes_north.x = xpaned->handle_pos_north.x;
1219 attributes_north.y = xpaned->handle_pos_north.y;
1220 attributes_north.width = xpaned->handle_pos_north.width;
1221 attributes_north.height = xpaned->handle_pos_north.height;
1223 attributes_south.x = xpaned->handle_pos_south.x;
1224 attributes_south.y = xpaned->handle_pos_south.y;
1225 attributes_south.width = xpaned->handle_pos_south.width;
1226 attributes_south.height = xpaned->handle_pos_south.height;
1228 attributes_middle.x = xpaned->handle_pos_middle.x;
1229 attributes_middle.y = xpaned->handle_pos_middle.y;
1230 attributes_middle.width = xpaned->handle_pos_middle.width;
1231 attributes_middle.height = xpaned->handle_pos_middle.height;
1233 attributes_east.cursor =
1234 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1235 xpaned->cursor_type_east);
1236 attributes_west.cursor =
1237 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1238 xpaned->cursor_type_west);
1239 attributes_north.cursor =
1240 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1241 xpaned->cursor_type_north);
1242 attributes_south.cursor =
1243 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1244 xpaned->cursor_type_south);
1245 attributes_middle.cursor =
1246 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1247 xpaned->cursor_type_middle);
1249 attributes_east.event_mask = gtk_widget_get_events (widget);
1250 attributes_west.event_mask = gtk_widget_get_events (widget);
1251 attributes_north.event_mask = gtk_widget_get_events (widget);
1252 attributes_south.event_mask = gtk_widget_get_events (widget);
1253 attributes_middle.event_mask = gtk_widget_get_events (widget);
1255 attributes_east.event_mask |= (GDK_BUTTON_PRESS_MASK |
1256 GDK_BUTTON_RELEASE_MASK |
1257 GDK_ENTER_NOTIFY_MASK |
1258 GDK_LEAVE_NOTIFY_MASK |
1259 GDK_POINTER_MOTION_MASK |
1260 GDK_POINTER_MOTION_HINT_MASK);
1261 attributes_west.event_mask |= (GDK_BUTTON_PRESS_MASK |
1262 GDK_BUTTON_RELEASE_MASK |
1263 GDK_ENTER_NOTIFY_MASK |
1264 GDK_LEAVE_NOTIFY_MASK |
1265 GDK_POINTER_MOTION_MASK |
1266 GDK_POINTER_MOTION_HINT_MASK);
1267 attributes_north.event_mask |= (GDK_BUTTON_PRESS_MASK |
1268 GDK_BUTTON_RELEASE_MASK |
1269 GDK_ENTER_NOTIFY_MASK |
1270 GDK_LEAVE_NOTIFY_MASK |
1271 GDK_POINTER_MOTION_MASK |
1272 GDK_POINTER_MOTION_HINT_MASK);
1273 attributes_south.event_mask |= (GDK_BUTTON_PRESS_MASK |
1274 GDK_BUTTON_RELEASE_MASK |
1275 GDK_ENTER_NOTIFY_MASK |
1276 GDK_LEAVE_NOTIFY_MASK |
1277 GDK_POINTER_MOTION_MASK |
1278 GDK_POINTER_MOTION_HINT_MASK);
1279 attributes_middle.event_mask |= (GDK_BUTTON_PRESS_MASK |
1280 GDK_BUTTON_RELEASE_MASK |
1281 GDK_ENTER_NOTIFY_MASK |
1282 GDK_LEAVE_NOTIFY_MASK |
1283 GDK_POINTER_MOTION_MASK |
1284 GDK_POINTER_MOTION_HINT_MASK);
1286 attributes_mask_east = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1287 attributes_mask_west = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1288 attributes_mask_north = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1289 attributes_mask_south = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1290 attributes_mask_middle = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1292 xpaned->handle_east = gdk_window_new (gtk_widget_get_window (widget),
1294 attributes_mask_east);
1295 xpaned->handle_west = gdk_window_new (gtk_widget_get_window (widget),
1297 attributes_mask_west);
1298 xpaned->handle_north = gdk_window_new (gtk_widget_get_window (widget),
1300 attributes_mask_north);
1301 xpaned->handle_south = gdk_window_new (gtk_widget_get_window (widget),
1303 attributes_mask_south);
1304 xpaned->handle_middle = gdk_window_new (gtk_widget_get_window (widget),
1306 attributes_mask_middle);
1308 gdk_window_set_user_data (xpaned->handle_east, xpaned);
1309 gdk_window_set_user_data (xpaned->handle_west, xpaned);
1310 gdk_window_set_user_data (xpaned->handle_north, xpaned);
1311 gdk_window_set_user_data (xpaned->handle_south, xpaned);
1312 gdk_window_set_user_data (xpaned->handle_middle, xpaned);
1314 g_object_unref (attributes_east.cursor);
1315 g_object_unref (attributes_west.cursor);
1316 g_object_unref (attributes_north.cursor);
1317 g_object_unref (attributes_south.cursor);
1318 g_object_unref (attributes_middle.cursor);
1320 if (xpaned->top_left_child
1321 && gtk_widget_get_visible (xpaned->top_left_child)
1322 && xpaned->top_right_child
1323 && gtk_widget_get_visible (xpaned->top_right_child)
1324 && xpaned->bottom_left_child
1325 && gtk_widget_get_visible (xpaned->bottom_left_child)
1326 && xpaned->bottom_right_child
1327 && gtk_widget_get_visible (xpaned->bottom_right_child))
1329 gdk_window_show (xpaned->handle_east);
1330 gdk_window_show (xpaned->handle_west);
1331 gdk_window_show (xpaned->handle_north);
1332 gdk_window_show (xpaned->handle_south);
1333 gdk_window_show (xpaned->handle_middle);
1338 gtk_xpaned_unrealize (GtkWidget * widget)
1340 GtkXPaned *xpaned = GTK_XPANED (widget);
1342 if (xpaned->handle_east)
1344 gdk_window_set_user_data (xpaned->handle_east, NULL);
1345 gdk_window_destroy (xpaned->handle_east);
1346 xpaned->handle_east = NULL;
1349 if (xpaned->handle_west)
1351 gdk_window_set_user_data (xpaned->handle_west, NULL);
1352 gdk_window_destroy (xpaned->handle_west);
1353 xpaned->handle_west = NULL;
1356 if (xpaned->handle_north)
1358 gdk_window_set_user_data (xpaned->handle_north, NULL);
1359 gdk_window_destroy (xpaned->handle_north);
1360 xpaned->handle_north = NULL;
1363 if (xpaned->handle_south)
1365 gdk_window_set_user_data (xpaned->handle_south, NULL);
1366 gdk_window_destroy (xpaned->handle_south);
1367 xpaned->handle_south = NULL;
1370 if (xpaned->handle_middle)
1372 gdk_window_set_user_data (xpaned->handle_middle, NULL);
1373 gdk_window_destroy (xpaned->handle_middle);
1374 xpaned->handle_middle = NULL;
1377 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
1378 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
1379 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
1380 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
1381 gtk_xpaned_set_saved_focus (xpaned, NULL);
1382 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1384 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1385 (*GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1389 gtk_xpaned_map (GtkWidget * widget)
1391 GtkXPaned *xpaned = GTK_XPANED (widget);
1393 gdk_window_show (xpaned->handle_east);
1394 gdk_window_show (xpaned->handle_west);
1395 gdk_window_show (xpaned->handle_north);
1396 gdk_window_show (xpaned->handle_south);
1397 gdk_window_show (xpaned->handle_middle);
1399 GTK_WIDGET_CLASS (parent_class)->map (widget);
1403 gtk_xpaned_unmap (GtkWidget * widget)
1405 GtkXPaned *xpaned = GTK_XPANED (widget);
1407 gdk_window_hide (xpaned->handle_east);
1408 gdk_window_hide (xpaned->handle_west);
1409 gdk_window_hide (xpaned->handle_north);
1410 gdk_window_hide (xpaned->handle_south);
1411 gdk_window_hide (xpaned->handle_middle);
1413 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1417 gtk_xpaned_draw (GtkWidget * widget, cairo_t *cr)
1419 GtkXPaned *xpaned = GTK_XPANED (widget);
1422 /* determine size of handle(s) */
1423 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1425 /* I want the handle-"thickness" to be at least 3 */
1426 g_assert (handle_size >= 3);
1428 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1429 xpaned->top_left_child
1430 && gtk_widget_get_visible (xpaned->top_left_child)
1431 && xpaned->top_right_child
1432 && gtk_widget_get_visible (xpaned->top_right_child)
1433 && xpaned->bottom_left_child
1434 && gtk_widget_get_visible (xpaned->bottom_left_child)
1435 && xpaned->bottom_right_child
1436 && gtk_widget_get_visible (xpaned->bottom_right_child))
1440 if (gtk_widget_is_focus (widget))
1441 state = GTK_STATE_SELECTED;
1442 else if (xpaned->handle_prelit)
1443 state = GTK_STATE_PRELIGHT;
1445 state = gtk_widget_get_state (widget);
1447 gtk_paint_handle (gtk_widget_get_style (widget),
1453 xpaned->handle_pos_east.x - handle_size - 256 / 2,
1454 xpaned->handle_pos_west.y + 1,
1455 256 + handle_size, handle_size - 2,
1456 /*xpaned->handle_pos_west.x,
1457 xpaned->handle_pos_west.y + 1,
1458 xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width,
1460 GTK_ORIENTATION_HORIZONTAL);
1462 gtk_paint_handle (gtk_widget_get_style (widget),
1468 xpaned->handle_pos_north.x + 1,
1469 xpaned->handle_pos_south.y - handle_size - 256 / 2,
1470 handle_size - 2, 256 + handle_size,
1471 /*xpaned->handle_pos_north.x + 1,
1472 xpaned->handle_pos_north.y,
1474 xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height, */
1475 GTK_ORIENTATION_VERTICAL);
1478 /* Chain up to draw children */
1479 GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
1485 is_rtl (GtkXPaned * xpaned)
1487 if (gtk_widget_get_direction (GTK_WIDGET (xpaned)) == GTK_TEXT_DIR_RTL)
1494 update_drag (GtkXPaned * xpaned)
1498 GtkRequisition size;
1499 GtkAllocation allocation;
1500 gtk_widget_get_allocation (GTK_WIDGET (xpaned), &allocation);
1502 gtk_widget_get_pointer (GTK_WIDGET (xpaned), &pos.x, &pos.y);
1504 if (xpaned->in_drag_vert)
1506 pos.y -= xpaned->drag_pos.y;
1508 if (is_rtl (xpaned))
1510 gtk_widget_style_get (GTK_WIDGET (xpaned),
1511 "handle-size", &handle_size, NULL);
1513 size.height = allocation.height - pos.y - handle_size;
1517 size.height = pos.y;
1520 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1523 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1525 if (size.height != xpaned->top_left_child_size.height)
1526 gtk_xpaned_set_position_y (xpaned, size.height);
1529 if (xpaned->in_drag_horiz)
1531 pos.x -= xpaned->drag_pos.x;
1533 if (is_rtl (xpaned))
1535 gtk_widget_style_get (GTK_WIDGET (xpaned),
1536 "handle-size", &handle_size, NULL);
1538 size.width = allocation.width - pos.x - handle_size;
1545 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1548 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1550 if (size.width != xpaned->top_left_child_size.width)
1551 gtk_xpaned_set_position_x (xpaned, size.width);
1554 if (xpaned->in_drag_vert_and_horiz)
1556 pos.x -= xpaned->drag_pos.x;
1557 pos.y -= xpaned->drag_pos.y;
1559 if (is_rtl (xpaned))
1561 gtk_widget_style_get (GTK_WIDGET (xpaned),
1562 "handle-size", &handle_size, NULL);
1564 size.width = allocation.width - pos.x - handle_size;
1565 size.height = allocation.height - pos.y - handle_size;
1570 size.height = pos.y;
1573 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1574 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1577 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1579 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1581 if (size.width != xpaned->top_left_child_size.width)
1582 gtk_xpaned_set_position_x (xpaned, size.width);
1584 if (size.height != xpaned->top_left_child_size.height)
1585 gtk_xpaned_set_position_y (xpaned, size.height);
1590 gtk_xpaned_enter (GtkWidget * widget, GdkEventCrossing * event)
1592 GtkXPaned *xpaned = GTK_XPANED (widget);
1594 if (xpaned->in_drag_vert ||
1595 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1596 update_drag (xpaned);
1599 xpaned->handle_prelit = TRUE;
1601 gtk_widget_queue_draw_area (widget,
1602 xpaned->handle_pos_east.x,
1603 xpaned->handle_pos_east.y,
1604 xpaned->handle_pos_east.width,
1605 xpaned->handle_pos_east.height);
1607 gtk_widget_queue_draw_area (widget,
1608 xpaned->handle_pos_west.x,
1609 xpaned->handle_pos_west.y,
1610 xpaned->handle_pos_west.width,
1611 xpaned->handle_pos_west.height);
1613 gtk_widget_queue_draw_area (widget,
1614 xpaned->handle_pos_north.x,
1615 xpaned->handle_pos_north.y,
1616 xpaned->handle_pos_north.width,
1617 xpaned->handle_pos_north.height);
1619 gtk_widget_queue_draw_area (widget,
1620 xpaned->handle_pos_south.x,
1621 xpaned->handle_pos_south.y,
1622 xpaned->handle_pos_south.width,
1623 xpaned->handle_pos_south.height);
1625 gtk_widget_queue_draw_area (widget,
1626 xpaned->handle_pos_middle.x,
1627 xpaned->handle_pos_middle.y,
1628 xpaned->handle_pos_middle.width,
1629 xpaned->handle_pos_middle.height);
1636 gtk_xpaned_leave (GtkWidget * widget, GdkEventCrossing * event)
1638 GtkXPaned *xpaned = GTK_XPANED (widget);
1640 if (xpaned->in_drag_vert ||
1641 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1642 update_drag (xpaned);
1645 xpaned->handle_prelit = FALSE;
1647 gtk_widget_queue_draw_area (widget,
1648 xpaned->handle_pos_east.x,
1649 xpaned->handle_pos_east.y,
1650 xpaned->handle_pos_east.width,
1651 xpaned->handle_pos_east.height);
1653 gtk_widget_queue_draw_area (widget,
1654 xpaned->handle_pos_west.x,
1655 xpaned->handle_pos_west.y,
1656 xpaned->handle_pos_west.width,
1657 xpaned->handle_pos_west.height);
1659 gtk_widget_queue_draw_area (widget,
1660 xpaned->handle_pos_north.x,
1661 xpaned->handle_pos_north.y,
1662 xpaned->handle_pos_north.width,
1663 xpaned->handle_pos_north.height);
1665 gtk_widget_queue_draw_area (widget,
1666 xpaned->handle_pos_south.x,
1667 xpaned->handle_pos_south.y,
1668 xpaned->handle_pos_south.width,
1669 xpaned->handle_pos_south.height);
1671 gtk_widget_queue_draw_area (widget,
1672 xpaned->handle_pos_middle.x,
1673 xpaned->handle_pos_middle.y,
1674 xpaned->handle_pos_middle.width,
1675 xpaned->handle_pos_middle.height);
1682 gtk_xpaned_focus (GtkWidget * widget, GtkDirectionType direction)
1686 /* This is a hack, but how can this be done without
1687 * excessive cut-and-paste from gtkcontainer.c?
1690 gtk_widget_set_can_focus (GTK_WIDGET (widget), FALSE);
1691 retval = (*GTK_WIDGET_CLASS (parent_class)->focus) (widget, direction);
1692 gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE);
1698 gtk_xpaned_button_press (GtkWidget * widget, GdkEventButton * event)
1700 GtkXPaned *xpaned = GTK_XPANED (widget);
1702 /* if any child is currently maximized, jump right back */
1703 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
1704 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
1705 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
1706 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
1709 /* if user is dragging the handles around */
1710 if (!xpaned->in_drag_vert_and_horiz &&
1711 event->window != xpaned->handle_east &&
1712 event->window != xpaned->handle_west &&
1713 event->window != xpaned->handle_north &&
1714 event->window != xpaned->handle_south &&
1715 event->window == xpaned->handle_middle && event->button == 1)
1717 xpaned->in_drag_vert_and_horiz = TRUE;
1719 /* We need a server grab here, not gtk_grab_add(), since
1720 * we don't want to pass events on to the widget's children */
1721 if (gdk_pointer_grab (xpaned->handle_middle,
1723 GDK_POINTER_MOTION_HINT_MASK
1724 | GDK_BUTTON1_MOTION_MASK
1725 | GDK_BUTTON_RELEASE_MASK
1726 | GDK_ENTER_NOTIFY_MASK
1727 | GDK_LEAVE_NOTIFY_MASK,
1728 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1732 xpaned->drag_pos.x = event->x;
1733 xpaned->drag_pos.y = event->y;
1737 else if (!xpaned->in_drag_vert &&
1738 event->window == xpaned->handle_east &&
1739 event->window != xpaned->handle_west &&
1740 event->window != xpaned->handle_north &&
1741 event->window != xpaned->handle_south &&
1742 event->window != xpaned->handle_middle && event->button == 1)
1744 xpaned->in_drag_vert = TRUE;
1746 /* We need a server grab here, not gtk_grab_add(), since
1747 * we don't want to pass events on to the widget's children */
1748 if (gdk_pointer_grab (xpaned->handle_east,
1750 GDK_POINTER_MOTION_HINT_MASK
1751 | GDK_BUTTON1_MOTION_MASK
1752 | GDK_BUTTON_RELEASE_MASK
1753 | GDK_ENTER_NOTIFY_MASK
1754 | GDK_LEAVE_NOTIFY_MASK,
1755 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1759 xpaned->drag_pos.y = event->y;
1763 else if (!xpaned->in_drag_vert &&
1764 event->window != xpaned->handle_east &&
1765 event->window == xpaned->handle_west &&
1766 event->window != xpaned->handle_north &&
1767 event->window != xpaned->handle_south &&
1768 event->window != xpaned->handle_middle && event->button == 1)
1770 xpaned->in_drag_vert = TRUE;
1772 /* We need a server grab here, not gtk_grab_add(), since
1773 * we don't want to pass events on to the widget's children */
1774 if (gdk_pointer_grab (xpaned->handle_west,
1776 GDK_POINTER_MOTION_HINT_MASK
1777 | GDK_BUTTON1_MOTION_MASK
1778 | GDK_BUTTON_RELEASE_MASK
1779 | GDK_ENTER_NOTIFY_MASK
1780 | GDK_LEAVE_NOTIFY_MASK,
1781 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1785 xpaned->drag_pos.y = event->y;
1789 else if (!xpaned->in_drag_horiz &&
1790 event->window != xpaned->handle_east &&
1791 event->window != xpaned->handle_west &&
1792 event->window == xpaned->handle_north &&
1793 event->window != xpaned->handle_south &&
1794 event->window != xpaned->handle_middle && event->button == 1)
1796 xpaned->in_drag_horiz = TRUE;
1798 /* We need a server grab here, not gtk_grab_add(), since
1799 * we don't want to pass events on to the widget's children */
1800 if (gdk_pointer_grab (xpaned->handle_north,
1802 GDK_POINTER_MOTION_HINT_MASK
1803 | GDK_BUTTON1_MOTION_MASK
1804 | GDK_BUTTON_RELEASE_MASK
1805 | GDK_ENTER_NOTIFY_MASK
1806 | GDK_LEAVE_NOTIFY_MASK,
1807 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1811 xpaned->drag_pos.x = event->x;
1815 else if (!xpaned->in_drag_horiz &&
1816 event->window != xpaned->handle_east &&
1817 event->window != xpaned->handle_west &&
1818 event->window != xpaned->handle_north &&
1819 event->window == xpaned->handle_south &&
1820 event->window != xpaned->handle_middle && event->button == 1)
1822 xpaned->in_drag_horiz = TRUE;
1824 /* We need a server grab here, not gtk_grab_add(), since
1825 * we don't want to pass events on to the widget's children */
1826 if (gdk_pointer_grab (xpaned->handle_south,
1828 GDK_POINTER_MOTION_HINT_MASK
1829 | GDK_BUTTON1_MOTION_MASK
1830 | GDK_BUTTON_RELEASE_MASK
1831 | GDK_ENTER_NOTIFY_MASK
1832 | GDK_LEAVE_NOTIFY_MASK,
1833 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1837 xpaned->drag_pos.x = event->x;
1845 gtk_xpaned_button_release (GtkWidget * widget, GdkEventButton * event)
1847 GtkXPaned *xpaned = GTK_XPANED (widget);
1849 if (xpaned->in_drag_vert && (event->button == 1))
1851 xpaned->in_drag_vert = FALSE;
1852 xpaned->drag_pos.y = -1;
1853 xpaned->position_set = TRUE;
1854 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1858 else if (xpaned->in_drag_horiz && (event->button == 1))
1860 xpaned->in_drag_horiz = FALSE;
1861 xpaned->drag_pos.x = -1;
1862 xpaned->position_set = TRUE;
1863 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1867 else if (xpaned->in_drag_vert_and_horiz && (event->button == 1))
1869 xpaned->in_drag_vert_and_horiz = FALSE;
1870 xpaned->drag_pos.x = -1;
1871 xpaned->drag_pos.y = -1;
1872 xpaned->position_set = TRUE;
1873 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1882 gtk_xpaned_motion (GtkWidget * widget, GdkEventMotion * event)
1884 GtkXPaned *xpaned = GTK_XPANED (widget);
1886 if (xpaned->in_drag_vert ||
1887 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1890 update_drag (xpaned);
1898 gtk_xpaned_add_top_left (GtkXPaned * xpaned, GtkWidget * widget)
1900 gtk_xpaned_pack_top_left (xpaned, widget, FALSE, TRUE);
1904 gtk_xpaned_add_top_right (GtkXPaned * xpaned, GtkWidget * widget)
1906 gtk_xpaned_pack_top_right (xpaned, widget, FALSE, TRUE);
1910 gtk_xpaned_add_bottom_left (GtkXPaned * xpaned, GtkWidget * widget)
1912 gtk_xpaned_pack_bottom_left (xpaned, widget, FALSE, TRUE);
1916 gtk_xpaned_add_bottom_right (GtkXPaned * xpaned, GtkWidget * widget)
1918 gtk_xpaned_pack_bottom_right (xpaned, widget, FALSE, TRUE);
1922 gtk_xpaned_pack_top_left (GtkXPaned * xpaned,
1923 GtkWidget * child, gboolean resize, gboolean shrink)
1925 g_return_if_fail (GTK_IS_XPANED (xpaned));
1926 g_return_if_fail (GTK_IS_WIDGET (child));
1928 if (!xpaned->top_left_child)
1930 xpaned->top_left_child = child;
1931 xpaned->top_left_child_resize = resize;
1932 xpaned->top_left_child_shrink = shrink;
1934 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1939 gtk_xpaned_pack_top_right (GtkXPaned * xpaned,
1941 gboolean resize, gboolean shrink)
1943 g_return_if_fail (GTK_IS_XPANED (xpaned));
1944 g_return_if_fail (GTK_IS_WIDGET (child));
1946 if (!xpaned->top_right_child)
1948 xpaned->top_right_child = child;
1949 xpaned->top_right_child_resize = resize;
1950 xpaned->top_right_child_shrink = shrink;
1952 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1957 gtk_xpaned_pack_bottom_left (GtkXPaned * xpaned,
1959 gboolean resize, gboolean shrink)
1961 g_return_if_fail (GTK_IS_XPANED (xpaned));
1962 g_return_if_fail (GTK_IS_WIDGET (child));
1964 if (!xpaned->bottom_left_child)
1966 xpaned->bottom_left_child = child;
1967 xpaned->bottom_left_child_resize = resize;
1968 xpaned->bottom_left_child_shrink = shrink;
1970 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1975 gtk_xpaned_pack_bottom_right (GtkXPaned * xpaned,
1977 gboolean resize, gboolean shrink)
1979 g_return_if_fail (GTK_IS_XPANED (xpaned));
1980 g_return_if_fail (GTK_IS_WIDGET (child));
1982 if (!xpaned->bottom_right_child)
1984 xpaned->bottom_right_child = child;
1985 xpaned->bottom_right_child_resize = resize;
1986 xpaned->bottom_right_child_shrink = shrink;
1988 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1993 gtk_xpaned_add (GtkContainer * container, GtkWidget * widget)
1997 g_return_if_fail (GTK_IS_XPANED (container));
1999 xpaned = GTK_XPANED (container);
2001 if (!xpaned->top_left_child)
2002 gtk_xpaned_add_top_left (xpaned, widget);
2003 else if (!xpaned->top_right_child)
2004 gtk_xpaned_add_top_right (xpaned, widget);
2005 else if (!xpaned->bottom_left_child)
2006 gtk_xpaned_add_bottom_left (xpaned, widget);
2007 else if (!xpaned->bottom_right_child)
2008 gtk_xpaned_add_bottom_right (xpaned, widget);
2010 g_warning ("GtkXPaned cannot have more than 4 children\n");
2014 gtk_xpaned_remove (GtkContainer * container, GtkWidget * widget)
2017 gboolean was_visible;
2019 xpaned = GTK_XPANED (container);
2020 was_visible = gtk_widget_get_visible (widget);
2022 if (xpaned->top_left_child == widget)
2024 gtk_widget_unparent (widget);
2026 xpaned->top_left_child = NULL;
2028 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2029 gtk_widget_queue_resize (GTK_WIDGET (container));
2031 else if (xpaned->top_right_child == widget)
2033 gtk_widget_unparent (widget);
2035 xpaned->top_right_child = NULL;
2037 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2038 gtk_widget_queue_resize (GTK_WIDGET (container));
2040 else if (xpaned->bottom_left_child == widget)
2042 gtk_widget_unparent (widget);
2044 xpaned->bottom_left_child = NULL;
2046 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2047 gtk_widget_queue_resize (GTK_WIDGET (container));
2049 else if (xpaned->bottom_right_child == widget)
2051 gtk_widget_unparent (widget);
2053 xpaned->bottom_right_child = NULL;
2055 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2056 gtk_widget_queue_resize (GTK_WIDGET (container));
2059 g_warning ("GtkXPaned has no more children attached\n");
2064 gtk_xpaned_forall (GtkContainer * container,
2065 gboolean include_internals,
2066 GtkCallback callback, gpointer callback_data)
2070 g_return_if_fail (callback != NULL);
2072 xpaned = GTK_XPANED (container);
2074 if (xpaned->top_left_child)
2075 (*callback) (xpaned->top_left_child, callback_data);
2076 if (xpaned->top_right_child)
2077 (*callback) (xpaned->top_right_child, callback_data);
2078 if (xpaned->bottom_left_child)
2079 (*callback) (xpaned->bottom_left_child, callback_data);
2080 if (xpaned->bottom_right_child)
2081 (*callback) (xpaned->bottom_right_child, callback_data);
2085 * gtk_xpaned_get_position_x:
2086 * @paned: a #GtkXPaned widget
2088 * Obtains the x-position of the divider.
2090 * Return value: x-position of the divider
2093 gtk_xpaned_get_position_x (GtkXPaned * xpaned)
2095 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2097 return xpaned->top_left_child_size.width;
2101 * gtk_xpaned_get_position_y:
2102 * @paned: a #GtkXPaned widget
2104 * Obtains the y-position of the divider.
2106 * Return value: y-position of the divider
2109 gtk_xpaned_get_position_y (GtkXPaned * xpaned)
2111 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2113 return xpaned->top_left_child_size.height;
2117 * gtk_xpaned_set_position_x:
2118 * @paned: a #GtkXPaned widget
2119 * @xposition: pixel x-position of divider, a negative values
2120 * of a component mean that the position is unset.
2122 * Sets the x-position of the divider between the four panes.
2125 gtk_xpaned_set_position_x (GtkXPaned * xpaned, gint xposition)
2129 g_return_if_fail (GTK_IS_XPANED (xpaned));
2131 /* if any child is currently maximized, jump right back */
2132 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2133 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2134 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2135 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2138 object = G_OBJECT (xpaned);
2142 /* We don't clamp here - the assumption is that
2143 * if the total allocation changes at the same time
2144 * as the position, the position set is with reference
2145 * to the new total size. If only the position changes,
2146 * then clamping will occur in gtk_paned_compute_position()
2149 xpaned->top_left_child_size.width = xposition;
2150 xpaned->position_set = TRUE;
2154 xpaned->position_set = FALSE;
2157 g_object_freeze_notify (object);
2158 g_object_notify (object, "x-position");
2159 g_object_notify (object, "position-set");
2160 g_object_thaw_notify (object);
2162 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2166 * gtk_xpaned_set_position_y:
2167 * @paned: a #GtkXPaned widget
2168 * @yposition: pixel y-position of divider, a negative values
2169 * of a component mean that the position is unset.
2171 * Sets the y-position of the divider between the four panes.
2174 gtk_xpaned_set_position_y (GtkXPaned * xpaned, gint yposition)
2178 g_return_if_fail (GTK_IS_XPANED (xpaned));
2180 /* if any child is currently maximized, jump right back */
2181 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2182 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2183 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2184 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2187 object = G_OBJECT (xpaned);
2191 /* We don't clamp here - the assumption is that
2192 * if the total allocation changes at the same time
2193 * as the position, the position set is with reference
2194 * to the new total size. If only the position changes,
2195 * then clamping will occur in gtk_paned_compute_position()
2198 xpaned->top_left_child_size.height = yposition;
2199 xpaned->position_set = TRUE;
2203 xpaned->position_set = FALSE;
2206 g_object_freeze_notify (object);
2207 g_object_notify (object, "y-position");
2208 g_object_notify (object, "position-set");
2209 g_object_thaw_notify (object);
2211 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2214 /* this call is private and only intended for internal use! */
2216 gtk_xpaned_save_unmaximized_x (GtkXPaned * xpaned)
2218 xpaned->unmaximized_position.x = gtk_xpaned_get_position_x (xpaned);
2221 /* this call is private and only intended for internal use! */
2223 gtk_xpaned_save_unmaximized_y (GtkXPaned * xpaned)
2225 xpaned->unmaximized_position.y = gtk_xpaned_get_position_y (xpaned);
2228 /* this call is private and only intended for internal use! */
2230 gtk_xpaned_fetch_unmaximized_x (GtkXPaned * xpaned)
2232 return xpaned->unmaximized_position.x;
2235 /* this call is private and only intended for internal use! */
2237 gtk_xpaned_fetch_unmaximized_y (GtkXPaned * xpaned)
2239 return xpaned->unmaximized_position.y;
2243 * gtk_xpaned_get_top_left_child:
2244 * @xpaned: a #GtkXPaned widget
2246 * Obtains the top-left child of the xpaned widget.
2248 * Return value: top-left child, or %NULL if it is not set.
2253 gtk_xpaned_get_top_left_child (GtkXPaned * xpaned)
2255 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2257 return xpaned->top_left_child;
2261 * gtk_xpaned_get_top_right_child:
2262 * @xpaned: a #GtkXPaned widget
2264 * Obtains the top-right child of the xpaned widget.
2266 * Return value: top-right child, or %NULL if it is not set.
2271 gtk_xpaned_get_top_right_child (GtkXPaned * xpaned)
2273 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2275 return xpaned->top_right_child;
2279 * gtk_xpaned_get_bottom_left_child:
2280 * @xpaned: a #GtkXPaned widget
2282 * Obtains the bottom-left child of the xpaned widget.
2284 * Return value: bottom-left child, or %NULL if it is not set.
2289 gtk_xpaned_get_bottom_left_child (GtkXPaned * xpaned)
2291 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2293 return xpaned->bottom_left_child;
2297 * gtk_xpaned_get_bottom_right_child:
2298 * @xpaned: a #GtkXPaned widget
2300 * Obtains the bottom-right child of the xpaned widget.
2302 * Return value: bottom-right child, or %NULL if it is not set.
2307 gtk_xpaned_get_bottom_right_child (GtkXPaned * xpaned)
2309 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2311 return xpaned->bottom_right_child;
2315 gtk_xpaned_maximize_top_left (GtkXPaned * xpaned, gboolean maximize)
2319 /* see if any child is already maximized */
2320 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2321 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2322 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2323 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2325 /* save current position */
2326 gtk_xpaned_save_unmaximized_x (xpaned);
2327 gtk_xpaned_save_unmaximized_y (xpaned);
2329 /* set new maximized position */
2330 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2331 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2333 /* mark maximized flag for top-left child */
2334 xpaned->maximized[GTK_XPANED_TOP_LEFT] = TRUE;
2338 /* already one child maximized, report error */
2344 /* verify that top-left child is really currently maximized */
2345 if (xpaned->maximized[GTK_XPANED_TOP_LEFT])
2347 /* clear maximized flat for top-left child */
2348 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
2350 /* restore unmaximized position */
2351 gtk_xpaned_set_position_x (xpaned,
2352 gtk_xpaned_fetch_unmaximized_x (xpaned));
2353 gtk_xpaned_set_position_y (xpaned,
2354 gtk_xpaned_fetch_unmaximized_y (xpaned));
2358 /* top-left child is currently not maximized, report error */
2365 gtk_xpaned_maximize_top_right (GtkXPaned * xpaned, gboolean maximize)
2369 /* see if any child is already maximized */
2370 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2371 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2372 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2373 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2375 /* save current position */
2376 gtk_xpaned_save_unmaximized_x (xpaned);
2377 gtk_xpaned_save_unmaximized_y (xpaned);
2379 /* set new maximized position */
2380 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2381 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2383 /* mark maximized flag for top-right child */
2384 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = TRUE;
2388 /* already one child maximized, report error */
2394 /* verify that top-right child is really currently maximized */
2395 if (xpaned->maximized[GTK_XPANED_TOP_RIGHT])
2397 /* clear maximized flat for top-right child */
2398 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
2400 /* restore unmaximized position */
2401 gtk_xpaned_set_position_x (xpaned,
2402 gtk_xpaned_fetch_unmaximized_x (xpaned));
2403 gtk_xpaned_set_position_y (xpaned,
2404 gtk_xpaned_fetch_unmaximized_y (xpaned));
2408 /* top-right child is currently not maximized, report error */
2415 gtk_xpaned_maximize_bottom_left (GtkXPaned * xpaned, gboolean maximize)
2419 /* see if any child is already maximized */
2420 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2421 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2422 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2423 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2425 /* save current position */
2426 gtk_xpaned_save_unmaximized_x (xpaned);
2427 gtk_xpaned_save_unmaximized_y (xpaned);
2429 /* set new maximized position */
2430 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2431 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2433 /* mark maximized flag for bottom-left child */
2434 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = TRUE;
2438 /* already one child maximized, report error */
2444 /* verify that bottom-left child is really currently maximized */
2445 if (xpaned->maximized[GTK_XPANED_BOTTOM_LEFT])
2447 /* clear maximized flat for bottom-left child */
2448 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
2450 /* restore unmaximized position */
2451 gtk_xpaned_set_position_x (xpaned,
2452 gtk_xpaned_fetch_unmaximized_x (xpaned));
2453 gtk_xpaned_set_position_y (xpaned,
2454 gtk_xpaned_fetch_unmaximized_y (xpaned));
2458 /* bottom-left child is currently not maximized, report error */
2465 gtk_xpaned_maximize_bottom_right (GtkXPaned * xpaned, gboolean maximize)
2469 /* see if any child is already maximized */
2470 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2471 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2472 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2473 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2475 /* save current position */
2476 gtk_xpaned_save_unmaximized_x (xpaned);
2477 gtk_xpaned_save_unmaximized_y (xpaned);
2479 /* set new maximized position */
2480 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2481 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2483 /* mark maximized flag for bottom-right child */
2484 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = TRUE;
2488 /* already one child maximized, report error */
2494 /* verify that bottom-right child is really currently maximized */
2495 if (xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2497 /* clear maximized flat for bottom-right child */
2498 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
2500 /* restore unmaximized position */
2501 gtk_xpaned_set_position_x (xpaned,
2502 gtk_xpaned_fetch_unmaximized_x (xpaned));
2503 gtk_xpaned_set_position_y (xpaned,
2504 gtk_xpaned_fetch_unmaximized_y (xpaned));
2508 /* bottom-right child is currently not maximized, report error */
2515 gtk_xpaned_compute_position (GtkXPaned * xpaned,
2516 const GtkAllocation * allocation,
2517 GtkRequisition * top_left_child_req,
2518 GtkRequisition * top_right_child_req,
2519 GtkRequisition * bottom_left_child_req,
2520 GtkRequisition * bottom_right_child_req)
2522 GdkPoint old_position;
2523 GdkPoint old_min_position;
2524 GdkPoint old_max_position;
2526 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (xpaned));
2528 g_return_if_fail (GTK_IS_XPANED (xpaned));
2530 old_position.x = xpaned->top_left_child_size.width;
2531 old_position.y = xpaned->top_left_child_size.height;
2532 old_min_position.x = xpaned->min_position.x;
2533 old_min_position.y = xpaned->min_position.y;
2534 old_max_position.x = xpaned->max_position.x;
2535 old_max_position.y = xpaned->max_position.y;
2537 xpaned->min_position.x =
2538 xpaned->top_left_child_shrink ? 0 : top_left_child_req->width;
2539 xpaned->min_position.y =
2540 xpaned->top_left_child_shrink ? 0 : top_left_child_req->height;
2542 gtk_widget_style_get (GTK_WIDGET (xpaned), "handle-size", &handle_size,
2545 xpaned->max_position.x = allocation->width - 2 * border_width - handle_size;
2546 xpaned->max_position.y =
2547 allocation->height - 2 * border_width - handle_size;
2548 if (!xpaned->top_left_child_shrink)
2549 xpaned->max_position.x =
2550 MAX (1, xpaned->max_position.x - top_left_child_req->width);
2551 xpaned->max_position.x =
2552 MAX (xpaned->min_position.x, xpaned->max_position.x);
2554 if (!xpaned->position_set)
2556 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2558 xpaned->top_left_child_size.width =
2559 MAX (0, allocation->width - top_right_child_req->width);
2560 xpaned->top_left_child_size.height =
2561 MAX (0, allocation->height - top_right_child_req->height);
2563 else if (!xpaned->top_left_child_resize
2564 && xpaned->top_right_child_resize)
2566 xpaned->top_left_child_size.width = top_left_child_req->width;
2567 xpaned->top_left_child_size.height = top_left_child_req->height;
2571 xpaned->top_left_child_size.width = allocation->width * 0.5 + 0.5;
2572 xpaned->top_left_child_size.height = allocation->height * 0.5 + 0.5;
2577 /* If the position was set before the initial allocation.
2578 ** (paned->last_allocation <= 0) just clamp it and leave it. */
2579 if (xpaned->last_allocation.width > 0)
2581 if (xpaned->top_left_child_resize
2582 && !xpaned->top_right_child_resize)
2584 xpaned->top_left_child_size.width += allocation->width
2585 - xpaned->last_allocation.width;
2587 xpaned->top_left_child_size.height += allocation->height
2588 - xpaned->last_allocation.height;
2592 (!xpaned->top_left_child_resize
2593 && xpaned->top_right_child_resize))
2595 xpaned->top_left_child_size.width = allocation->width
2596 * ((gdouble) xpaned->top_left_child_size.width /
2597 (xpaned->last_allocation.width)) + 0.5;
2599 xpaned->top_left_child_size.height = allocation->height
2600 * ((gdouble) xpaned->top_left_child_size.height /
2601 (xpaned->last_allocation.height)) + 0.5;
2604 if (xpaned->last_allocation.height > 0)
2606 if (xpaned->top_left_child_resize
2607 && !xpaned->top_right_child_resize)
2609 xpaned->top_left_child_size.width +=
2610 allocation->width - xpaned->last_allocation.width;
2611 xpaned->top_left_child_size.height +=
2612 allocation->height - xpaned->last_allocation.height;
2616 (!xpaned->top_left_child_resize
2617 && xpaned->top_right_child_resize))
2619 xpaned->top_left_child_size.width =
2621 ((gdouble) xpaned->top_left_child_size.width /
2622 (xpaned->last_allocation.width)) + 0.5;
2623 xpaned->top_left_child_size.height =
2624 allocation->height *
2625 ((gdouble) xpaned->top_left_child_size.height /
2626 (xpaned->last_allocation.height)) + 0.5;
2632 xpaned->top_left_child_size.width =
2633 CLAMP (xpaned->top_left_child_size.width, xpaned->min_position.x,
2634 xpaned->max_position.x);
2635 xpaned->top_left_child_size.height =
2636 CLAMP (xpaned->top_left_child_size.height, xpaned->min_position.y,
2637 xpaned->max_position.y);
2639 xpaned->top_right_child_size.width =
2640 CLAMP (xpaned->top_right_child_size.width, xpaned->min_position.x,
2641 xpaned->max_position.x);
2642 xpaned->top_right_child_size.height =
2643 CLAMP (xpaned->top_right_child_size.height, xpaned->min_position.y,
2644 xpaned->max_position.y);
2646 xpaned->bottom_left_child_size.width =
2647 CLAMP (xpaned->bottom_left_child_size.width, xpaned->min_position.x,
2648 xpaned->max_position.x);
2649 xpaned->bottom_left_child_size.height =
2650 CLAMP (xpaned->bottom_left_child_size.height, xpaned->min_position.y,
2651 xpaned->max_position.y);
2653 xpaned->bottom_right_child_size.width =
2654 CLAMP (xpaned->bottom_right_child_size.width, xpaned->min_position.x,
2655 xpaned->max_position.x);
2656 xpaned->bottom_right_child_size.height =
2657 CLAMP (xpaned->bottom_right_child_size.height, xpaned->min_position.y,
2658 xpaned->max_position.y);
2660 gtk_widget_set_child_visible (xpaned->top_left_child, TRUE);
2661 gtk_widget_set_child_visible (xpaned->top_right_child, TRUE);
2662 gtk_widget_set_child_visible (xpaned->bottom_left_child, TRUE);
2663 gtk_widget_set_child_visible (xpaned->bottom_right_child, TRUE);
2665 g_object_freeze_notify (G_OBJECT (xpaned));
2667 if (xpaned->top_left_child_size.width != old_position.x)
2668 g_object_notify (G_OBJECT (xpaned), "x-position");
2669 if (xpaned->top_left_child_size.height != old_position.y)
2670 g_object_notify (G_OBJECT (xpaned), "y-position");
2672 if (xpaned->top_right_child_size.width != old_position.x)
2673 g_object_notify (G_OBJECT (xpaned), "x-position");
2674 if (xpaned->top_right_child_size.height != old_position.y)
2675 g_object_notify (G_OBJECT (xpaned), "y-position");
2677 if (xpaned->bottom_left_child_size.width != old_position.x)
2678 g_object_notify (G_OBJECT (xpaned), "x-position");
2679 if (xpaned->bottom_left_child_size.height != old_position.y)
2680 g_object_notify (G_OBJECT (xpaned), "y-position");
2682 if (xpaned->bottom_right_child_size.width != old_position.x)
2683 g_object_notify (G_OBJECT (xpaned), "x-position");
2684 if (xpaned->bottom_right_child_size.height != old_position.y)
2685 g_object_notify (G_OBJECT (xpaned), "y-position");
2687 if (xpaned->min_position.x != old_min_position.x)
2688 g_object_notify (G_OBJECT (xpaned), "min-x-position");
2689 if (xpaned->min_position.y != old_min_position.y)
2690 g_object_notify (G_OBJECT (xpaned), "min-y-position");
2692 if (xpaned->max_position.x != old_max_position.x)
2693 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2694 if (xpaned->max_position.y != old_max_position.y)
2695 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2697 g_object_thaw_notify (G_OBJECT (xpaned));
2699 xpaned->last_allocation.width = allocation->width;
2700 xpaned->last_allocation.height = allocation->height;
2704 gtk_xpaned_set_saved_focus (GtkXPaned * xpaned, GtkWidget * widget)
2706 if (xpaned->priv->saved_focus)
2707 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2708 (gpointer *) & (xpaned->priv->saved_focus));
2710 xpaned->priv->saved_focus = widget;
2712 if (xpaned->priv->saved_focus)
2713 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2714 (gpointer *) & (xpaned->priv->saved_focus));
2718 gtk_xpaned_set_first_xpaned (GtkXPaned * xpaned, GtkXPaned * first_xpaned)
2720 if (xpaned->priv->first_xpaned)
2721 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2722 (gpointer *) & (xpaned->priv->
2725 xpaned->priv->first_xpaned = first_xpaned;
2727 if (xpaned->priv->first_xpaned)
2728 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2729 (gpointer *) & (xpaned->priv->first_xpaned));
2733 gtk_xpaned_set_last_top_left_child_focus (GtkXPaned * xpaned,
2736 if (xpaned->last_top_left_child_focus)
2737 g_object_remove_weak_pointer (G_OBJECT
2738 (xpaned->last_top_left_child_focus),
2739 (gpointer *) & (xpaned->
2740 last_top_left_child_focus));
2742 xpaned->last_top_left_child_focus = widget;
2744 if (xpaned->last_top_left_child_focus)
2745 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2746 (gpointer *) & (xpaned->
2747 last_top_left_child_focus));
2751 gtk_xpaned_set_last_top_right_child_focus (GtkXPaned * xpaned,
2754 if (xpaned->last_top_right_child_focus)
2755 g_object_remove_weak_pointer (G_OBJECT
2756 (xpaned->last_top_right_child_focus),
2757 (gpointer *) & (xpaned->
2758 last_top_right_child_focus));
2760 xpaned->last_top_right_child_focus = widget;
2762 if (xpaned->last_top_right_child_focus)
2763 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2764 (gpointer *) & (xpaned->
2765 last_top_right_child_focus));
2769 gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned * xpaned,
2772 if (xpaned->last_bottom_left_child_focus)
2773 g_object_remove_weak_pointer (G_OBJECT
2774 (xpaned->last_bottom_left_child_focus),
2775 (gpointer *) & (xpaned->
2776 last_bottom_left_child_focus));
2778 xpaned->last_bottom_left_child_focus = widget;
2780 if (xpaned->last_bottom_left_child_focus)
2781 g_object_add_weak_pointer (G_OBJECT
2782 (xpaned->last_bottom_left_child_focus),
2783 (gpointer *) & (xpaned->
2784 last_bottom_left_child_focus));
2788 gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned * xpaned,
2791 if (xpaned->last_bottom_right_child_focus)
2792 g_object_remove_weak_pointer (G_OBJECT
2793 (xpaned->last_bottom_right_child_focus),
2794 (gpointer *) & (xpaned->
2795 last_bottom_right_child_focus));
2797 xpaned->last_bottom_right_child_focus = widget;
2799 if (xpaned->last_bottom_right_child_focus)
2800 g_object_add_weak_pointer (G_OBJECT
2801 (xpaned->last_bottom_right_child_focus),
2802 (gpointer *) & (xpaned->
2803 last_bottom_right_child_focus));
2807 xpaned_get_focus_widget (GtkXPaned * xpaned)
2809 GtkWidget *toplevel;
2811 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
2812 if (gtk_widget_is_toplevel (toplevel))
2813 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2819 gtk_xpaned_set_focus_child (GtkContainer * container, GtkWidget * focus_child)
2823 g_return_if_fail (GTK_IS_XPANED (container));
2825 xpaned = GTK_XPANED (container);
2827 if (focus_child == NULL)
2829 GtkWidget *last_focus;
2832 last_focus = xpaned_get_focus_widget (xpaned);
2836 /* If there is one or more paned widgets between us and the
2837 * focus widget, we want the topmost of those as last_focus
2839 for (w = last_focus; w != GTK_WIDGET (xpaned); w = gtk_widget_get_parent (w))
2840 if (GTK_IS_XPANED (w))
2843 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2844 gtk_xpaned_set_last_top_left_child_focus (xpaned, last_focus);
2845 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2846 gtk_xpaned_set_last_top_right_child_focus (xpaned, last_focus);
2847 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2848 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, last_focus);
2849 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2850 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, last_focus);
2854 if (parent_class->set_focus_child)
2855 (*parent_class->set_focus_child) (container, focus_child);
2859 gtk_xpaned_get_cycle_chain (GtkXPaned * xpaned,
2860 GtkDirectionType direction, GList ** widgets)
2862 GtkContainer *container = GTK_CONTAINER (xpaned);
2863 GtkWidget *ancestor = NULL;
2864 GList *temp_list = NULL;
2867 if (xpaned->in_recursion)
2870 g_assert (widgets != NULL);
2872 if (xpaned->last_top_left_child_focus &&
2873 !gtk_widget_is_ancestor (xpaned->last_top_left_child_focus,
2874 GTK_WIDGET (xpaned)))
2876 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
2879 if (xpaned->last_top_right_child_focus &&
2880 !gtk_widget_is_ancestor (xpaned->last_top_right_child_focus,
2881 GTK_WIDGET (xpaned)))
2883 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
2886 if (xpaned->last_bottom_left_child_focus &&
2887 !gtk_widget_is_ancestor (xpaned->last_bottom_left_child_focus,
2888 GTK_WIDGET (xpaned)))
2890 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
2893 if (xpaned->last_bottom_right_child_focus &&
2894 !gtk_widget_is_ancestor (xpaned->last_bottom_right_child_focus,
2895 GTK_WIDGET (xpaned)))
2897 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
2900 if (gtk_widget_get_parent (GTK_WIDGET (xpaned)))
2901 ancestor = gtk_widget_get_ancestor (gtk_widget_get_parent (GTK_WIDGET (xpaned)),
2904 /* The idea here is that temp_list is a list of widgets we want to cycle
2905 * to. The list is prioritized so that the first element is our first
2906 * choice, the next our second, and so on.
2908 * We can't just use g_list_reverse(), because we want to try
2909 * paned->last_child?_focus before paned->child?, both when we
2910 * are going forward and backward.
2912 if (direction == GTK_DIR_TAB_FORWARD)
2914 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2917 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2918 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2919 temp_list = g_list_append (temp_list, ancestor);
2921 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2923 temp_list = g_list_append (temp_list, ancestor);
2925 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2926 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2928 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2930 temp_list = g_list_append (temp_list, ancestor);
2932 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2933 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2935 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2937 temp_list = g_list_append (temp_list, ancestor);
2939 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2940 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2945 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2946 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2948 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2949 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2951 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2952 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2954 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2955 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2956 temp_list = g_list_append (temp_list, ancestor);
2961 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2963 temp_list = g_list_append (temp_list, ancestor);
2965 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2966 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2968 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2971 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2972 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2973 temp_list = g_list_append (temp_list, ancestor);
2975 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2978 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2979 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2980 temp_list = g_list_append (temp_list, ancestor);
2982 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2985 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2986 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2987 temp_list = g_list_append (temp_list, ancestor);
2992 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2993 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2995 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2996 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2998 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2999 temp_list = g_list_append (temp_list, xpaned->top_right_child);
3001 g_list_append (temp_list, xpaned->last_top_left_child_focus);
3002 temp_list = g_list_append (temp_list, xpaned->top_left_child);
3003 temp_list = g_list_append (temp_list, ancestor);
3007 /* Walk the list and expand all the paned widgets. */
3008 for (list = temp_list; list != NULL; list = list->next)
3010 GtkWidget *widget = list->data;
3014 if (GTK_IS_XPANED (widget))
3016 xpaned->in_recursion = TRUE;
3017 gtk_xpaned_get_cycle_chain (GTK_XPANED (widget),
3018 direction, widgets);
3019 xpaned->in_recursion = FALSE;
3023 *widgets = g_list_append (*widgets, widget);
3028 g_list_free (temp_list);
3032 gtk_xpaned_cycle_child_focus (GtkXPaned * xpaned, gboolean reversed)
3034 GList *cycle_chain = NULL;
3037 GtkDirectionType direction =
3038 reversed ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
3040 /* ignore f6 if the handle is focused */
3041 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3044 /* we can't just let the event propagate up the hierarchy,
3045 * because the paned will want to cycle focus _unless_ an
3046 * ancestor paned handles the event
3048 gtk_xpaned_get_cycle_chain (xpaned, direction, &cycle_chain);
3050 for (list = cycle_chain; list != NULL; list = list->next)
3051 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
3054 g_list_free (cycle_chain);
3060 get_child_xpanes (GtkWidget * widget, GList ** xpanes)
3062 if (GTK_IS_XPANED (widget))
3064 GtkXPaned *xpaned = GTK_XPANED (widget);
3066 get_child_xpanes (xpaned->top_left_child, xpanes);
3067 *xpanes = g_list_prepend (*xpanes, widget);
3068 get_child_xpanes (xpaned->top_right_child, xpanes);
3069 *xpanes = g_list_prepend (*xpanes, widget);
3070 get_child_xpanes (xpaned->bottom_left_child, xpanes);
3071 *xpanes = g_list_prepend (*xpanes, widget);
3072 get_child_xpanes (xpaned->bottom_right_child, xpanes);
3074 else if (GTK_IS_CONTAINER (widget))
3076 gtk_container_foreach (GTK_CONTAINER (widget),
3077 (GtkCallback) get_child_xpanes, xpanes);
3082 get_all_xpanes (GtkXPaned * xpaned)
3084 GtkXPaned *topmost = NULL;
3085 GList *result = NULL;
3088 for (w = GTK_WIDGET (xpaned); w != NULL; w = gtk_widget_get_parent (w))
3090 if (GTK_IS_XPANED (w))
3091 topmost = GTK_XPANED (w);
3096 get_child_xpanes (GTK_WIDGET (topmost), &result);
3098 return g_list_reverse (result);
3102 gtk_xpaned_find_neighbours (GtkXPaned * xpaned,
3103 GtkXPaned ** next, GtkXPaned ** prev)
3108 all_xpanes = get_all_xpanes (xpaned);
3109 g_assert (all_xpanes);
3111 this_link = g_list_find (all_xpanes, xpaned);
3113 g_assert (this_link);
3115 if (this_link->next)
3116 *next = this_link->next->data;
3118 *next = all_xpanes->data;
3120 if (this_link->prev)
3121 *prev = this_link->prev->data;
3123 *prev = g_list_last (all_xpanes)->data;
3125 g_list_free (all_xpanes);
3129 gtk_xpaned_move_handle (GtkXPaned * xpaned, GtkScrollType scroll)
3131 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3133 GdkPoint old_position;
3134 GdkPoint new_position;
3139 SINGLE_STEP_SIZE = 1,
3143 new_position.x = old_position.x = gtk_xpaned_get_position_x (xpaned);
3144 new_position.y = old_position.y = gtk_xpaned_get_position_y (xpaned);
3149 case GTK_SCROLL_STEP_LEFT:
3150 case GTK_SCROLL_STEP_UP:
3151 case GTK_SCROLL_STEP_BACKWARD:
3152 increment = -SINGLE_STEP_SIZE;
3155 case GTK_SCROLL_STEP_RIGHT:
3156 case GTK_SCROLL_STEP_DOWN:
3157 case GTK_SCROLL_STEP_FORWARD:
3158 increment = SINGLE_STEP_SIZE;
3161 case GTK_SCROLL_PAGE_LEFT:
3162 case GTK_SCROLL_PAGE_UP:
3163 case GTK_SCROLL_PAGE_BACKWARD:
3164 increment = -PAGE_STEP_SIZE;
3167 case GTK_SCROLL_PAGE_RIGHT:
3168 case GTK_SCROLL_PAGE_DOWN:
3169 case GTK_SCROLL_PAGE_FORWARD:
3170 increment = PAGE_STEP_SIZE;
3173 case GTK_SCROLL_START:
3174 new_position.x = xpaned->min_position.x;
3175 new_position.y = xpaned->min_position.y;
3178 case GTK_SCROLL_END:
3179 new_position.x = xpaned->max_position.x;
3180 new_position.y = xpaned->max_position.y;
3189 if (is_rtl (xpaned))
3190 increment = -increment;
3192 new_position.x = old_position.x + increment;
3193 new_position.y = old_position.y + increment;
3196 new_position.x = CLAMP (new_position.x,
3197 xpaned->min_position.x, xpaned->max_position.x);
3199 new_position.y = CLAMP (new_position.y,
3200 xpaned->min_position.y, xpaned->max_position.y);
3202 if (old_position.x != new_position.x)
3203 gtk_xpaned_set_position_x (xpaned, new_position.x);
3205 if (old_position.y != new_position.y)
3206 gtk_xpaned_set_position_y (xpaned, new_position.y);
3215 gtk_xpaned_restore_focus (GtkXPaned * xpaned)
3217 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3219 if (xpaned->priv->saved_focus &&
3220 gtk_widget_get_sensitive (xpaned->priv->saved_focus))
3222 gtk_widget_grab_focus (xpaned->priv->saved_focus);
3226 /* the saved focus is somehow not available for focusing,
3228 * 1) tabbing into the paned widget
3229 * if that didn't work,
3230 * 2) unset focus for the window if there is one
3233 if (!gtk_widget_child_focus
3234 (GTK_WIDGET (xpaned), GTK_DIR_TAB_FORWARD))
3236 GtkWidget *toplevel =
3237 gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3239 if (GTK_IS_WINDOW (toplevel))
3240 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
3244 gtk_xpaned_set_saved_focus (xpaned, NULL);
3245 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3250 gtk_xpaned_accept_position (GtkXPaned * xpaned)
3252 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3254 xpaned->original_position.x = -1;
3255 xpaned->original_position.y = -1;
3256 gtk_xpaned_restore_focus (xpaned);
3265 gtk_xpaned_cancel_position (GtkXPaned * xpaned)
3267 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3269 if (xpaned->original_position.x != -1)
3271 gtk_xpaned_set_position_x (xpaned, xpaned->original_position.x);
3272 xpaned->original_position.x = -1;
3275 if (xpaned->original_position.y != -1)
3277 gtk_xpaned_set_position_y (xpaned, xpaned->original_position.y);
3278 xpaned->original_position.y = -1;
3281 gtk_xpaned_restore_focus (xpaned);
3289 gtk_xpaned_cycle_handle_focus (GtkXPaned * xpaned, gboolean reversed)
3294 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3296 GtkXPaned *focus = NULL;
3298 if (!xpaned->priv->first_xpaned)
3300 /* The first_pane has disappeared. As an ad-hoc solution,
3301 * we make the currently focused paned the first_paned. To the
3302 * user this will seem like the paned cycling has been reset.
3304 gtk_xpaned_set_first_xpaned (xpaned, xpaned);
3307 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3309 if (reversed && prev &&
3310 prev != xpaned && xpaned != xpaned->priv->first_xpaned)
3314 else if (!reversed &&
3315 next && next != xpaned && next != xpaned->priv->first_xpaned)
3321 gtk_xpaned_accept_position (xpaned);
3327 gtk_xpaned_set_saved_focus (focus, xpaned->priv->saved_focus);
3328 gtk_xpaned_set_first_xpaned (focus, xpaned->priv->first_xpaned);
3330 gtk_xpaned_set_saved_focus (xpaned, NULL);
3331 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3333 gtk_widget_grab_focus (GTK_WIDGET (focus));
3335 if (!gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3337 xpaned->original_position.x = -1;
3338 xpaned->original_position.y = -1;
3339 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3340 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3345 GtkContainer *container = GTK_CONTAINER (xpaned);
3350 GtkWidget *toplevel;
3352 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3354 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
3367 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
3382 /* Focus is not inside this xpaned, and we don't have focus.
3383 * Presumably this happened because the application wants us
3384 * to start keyboard navigating.
3394 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3396 if (GTK_IS_WINDOW (toplevel))
3397 gtk_xpaned_set_saved_focus (focus,
3398 gtk_window_get_focus (GTK_WINDOW (toplevel)));
3399 gtk_xpaned_set_first_xpaned (focus, first);
3400 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3401 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3403 gtk_widget_grab_focus (GTK_WIDGET (focus));
3410 gtk_xpaned_toggle_handle_focus (GtkXPaned * xpaned)
3412 /* This function/signal has the wrong name. It is called when you
3413 * press Tab or Shift-Tab and what we do is act as if
3414 * the user pressed Return and then Tab or Shift-Tab
3416 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3417 gtk_xpaned_accept_position (xpaned);
3422 /*#define __GTK_XPANED_C__*/
3423 /*#include "gtkaliasdef.c"*/