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);
75 static void gtk_xpaned_size_request (GtkWidget * widget,
76 GtkRequisition * requisition);
79 gtk_xpaned_get_preferred_width (GtkWidget *widget,
83 GtkRequisition requisition;
85 gtk_xpaned_size_request (widget, &requisition);
87 *minimal_width = *natural_width = requisition.width;
91 gtk_xpaned_get_preferred_height (GtkWidget *widget,
95 GtkRequisition requisition;
97 gtk_xpaned_size_request (widget, &requisition);
99 *minimal_height = *natural_height = requisition.height;
102 static void gtk_xpaned_size_allocate (GtkWidget * widget,
103 GtkAllocation * allocation);
105 static void gtk_xpaned_set_property (GObject * object,
107 const GValue * value,
110 static void gtk_xpaned_get_property (GObject * object,
112 GValue * value, GParamSpec * pspec);
114 static void gtk_xpaned_set_child_property (GtkContainer * container,
117 const GValue * value,
120 static void gtk_xpaned_get_child_property (GtkContainer * container,
126 static void gtk_xpaned_finalize (GObject * object);
128 static void gtk_xpaned_realize (GtkWidget * widget);
130 static void gtk_xpaned_unrealize (GtkWidget * widget);
132 static void gtk_xpaned_map (GtkWidget * widget);
134 static void gtk_xpaned_unmap (GtkWidget * widget);
136 static gboolean gtk_xpaned_draw (GtkWidget * widget,
139 static gboolean gtk_xpaned_enter (GtkWidget * widget,
140 GdkEventCrossing * event);
142 static gboolean gtk_xpaned_leave (GtkWidget * widget,
143 GdkEventCrossing * event);
145 static gboolean gtk_xpaned_button_press (GtkWidget * widget,
146 GdkEventButton * event);
148 static gboolean gtk_xpaned_button_release (GtkWidget * widget,
149 GdkEventButton * event);
151 static gboolean gtk_xpaned_motion (GtkWidget * widget,
152 GdkEventMotion * event);
154 static gboolean gtk_xpaned_focus (GtkWidget * widget,
155 GtkDirectionType direction);
157 static void gtk_xpaned_add (GtkContainer * container, GtkWidget * widget);
159 static void gtk_xpaned_remove (GtkContainer * container, GtkWidget * widget);
161 static void gtk_xpaned_forall (GtkContainer * container,
162 gboolean include_internals,
163 GtkCallback callback, gpointer callback_data);
165 static void gtk_xpaned_set_focus_child (GtkContainer * container,
168 static void gtk_xpaned_set_saved_focus (GtkXPaned * xpaned,
171 static void gtk_xpaned_set_first_xpaned (GtkXPaned * xpaned,
172 GtkXPaned * first_xpaned);
174 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned * xpaned,
177 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned * xpaned,
180 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned * xpaned,
183 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned * xpaned,
186 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned * xpaned,
189 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned * xpaned,
192 static gboolean gtk_xpaned_move_handle (GtkXPaned * xpaned,
193 GtkScrollType scroll);
195 static gboolean gtk_xpaned_accept_position (GtkXPaned * xpaned);
197 static gboolean gtk_xpaned_cancel_position (GtkXPaned * xpaned);
199 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned * xpaned);
201 static GType gtk_xpaned_child_type (GtkContainer * container);
203 static GtkContainerClass *parent_class = NULL;
205 struct _GtkXPanedPrivate
207 GtkWidget *saved_focus;
208 GtkXPaned *first_xpaned;
212 gtk_xpaned_get_type (void)
214 static GType xpaned_type = 0;
218 static const GTypeInfo xpaned_info = {
219 sizeof (GtkXPanedClass),
220 NULL, /* base_init */
221 NULL, /* base_finalize */
222 (GClassInitFunc) gtk_xpaned_class_init,
223 NULL, /* class_finalize */
224 NULL, /* class_data */
227 (GInstanceInitFunc) gtk_xpaned_init
230 xpaned_type = g_type_register_static (GTK_TYPE_CONTAINER,
231 "GtkXPaned", &xpaned_info, 0);
238 gtk_xpaned_new (void)
242 xpaned = g_object_new (GTK_TYPE_XPANED, NULL);
244 return GTK_WIDGET (xpaned);
247 static guint signals[LAST_SIGNAL] = { 0 };
250 add_tab_bindings (GtkBindingSet * binding_set, GdkModifierType modifiers)
252 gtk_binding_entry_add_signal (binding_set,
253 GDK_Tab, modifiers, "toggle_handle_focus", 0);
255 gtk_binding_entry_add_signal (binding_set,
257 modifiers, "toggle_handle_focus", 0);
261 add_move_binding (GtkBindingSet * binding_set,
262 guint keyval, GdkModifierType mask, GtkScrollType scroll)
264 gtk_binding_entry_add_signal (binding_set,
268 1, GTK_TYPE_SCROLL_TYPE, scroll);
272 gtk_xpaned_class_init (GtkXPanedClass * class)
274 GObjectClass *object_class;
275 GtkWidgetClass *widget_class;
276 GtkContainerClass *container_class;
277 GtkXPanedClass *xpaned_class;
278 GtkBindingSet *binding_set;
280 object_class = (GObjectClass *) class;
281 widget_class = (GtkWidgetClass *) class;
282 container_class = (GtkContainerClass *) class;
283 xpaned_class = (GtkXPanedClass *) class;
285 parent_class = g_type_class_peek_parent (class);
287 object_class->set_property = gtk_xpaned_set_property;
288 object_class->get_property = gtk_xpaned_get_property;
289 object_class->finalize = gtk_xpaned_finalize;
291 widget_class->realize = gtk_xpaned_realize;
292 widget_class->unrealize = gtk_xpaned_unrealize;
293 widget_class->map = gtk_xpaned_map;
294 widget_class->unmap = gtk_xpaned_unmap;
295 widget_class->draw = gtk_xpaned_draw;
296 widget_class->focus = gtk_xpaned_focus;
297 widget_class->enter_notify_event = gtk_xpaned_enter;
298 widget_class->leave_notify_event = gtk_xpaned_leave;
299 widget_class->button_press_event = gtk_xpaned_button_press;
300 widget_class->button_release_event = gtk_xpaned_button_release;
301 widget_class->motion_notify_event = gtk_xpaned_motion;
302 widget_class->get_preferred_width = gtk_xpaned_get_preferred_width;
303 widget_class->get_preferred_height = gtk_xpaned_get_preferred_height;
305 widget_class->size_allocate = gtk_xpaned_size_allocate;
307 container_class->add = gtk_xpaned_add;
308 container_class->remove = gtk_xpaned_remove;
309 container_class->forall = gtk_xpaned_forall;
310 container_class->child_type = gtk_xpaned_child_type;
311 container_class->set_focus_child = gtk_xpaned_set_focus_child;
312 container_class->set_child_property = gtk_xpaned_set_child_property;
313 container_class->get_child_property = gtk_xpaned_get_child_property;
315 xpaned_class->cycle_child_focus = gtk_xpaned_cycle_child_focus;
316 xpaned_class->toggle_handle_focus = gtk_xpaned_toggle_handle_focus;
317 xpaned_class->move_handle = gtk_xpaned_move_handle;
318 xpaned_class->cycle_handle_focus = gtk_xpaned_cycle_handle_focus;
319 xpaned_class->accept_position = gtk_xpaned_accept_position;
320 xpaned_class->cancel_position = gtk_xpaned_cancel_position;
322 g_object_class_install_property (object_class,
324 g_param_spec_int ("x-position",
326 ("x-Position of paned separator in pixels (0 means all the way to the left)"),
333 g_object_class_install_property (object_class,
335 g_param_spec_int ("y-position",
337 "y-Position of paned separator in pixels (0 means all the way to the top)",
344 g_object_class_install_property (object_class,
346 g_param_spec_boolean ("position-set",
348 "TRUE if the Position property should be used",
353 gtk_widget_class_install_style_property (widget_class,
354 g_param_spec_int ("handle-size",
362 * GtkXPaned:min-x-position:
364 * The smallest possible value for the x-position property. This property is derived from the
365 * size and shrinkability of the widget's children.
369 g_object_class_install_property (object_class,
371 g_param_spec_int ("min-x-position",
372 "Minimal x-Position",
373 "Smallest possible value for the \"x-position\" property",
376 0, G_PARAM_READABLE));
379 * GtkXPaned:min-y-position:
381 * The smallest possible value for the y-position property. This property is derived from the
382 * size and shrinkability of the widget's children.
386 g_object_class_install_property (object_class,
388 g_param_spec_int ("min-y-position",
389 "Minimal y-Position",
390 "Smallest possible value for the \"y-position\" property",
393 0, G_PARAM_READABLE));
396 * GtkPaned:max-x-position:
398 * The largest possible value for the x-position property. This property is derived from the
399 * size and shrinkability of the widget's children.
403 g_object_class_install_property (object_class,
405 g_param_spec_int ("max-x-position",
406 "Maximal x-Position",
407 "Largest possible value for the \"x-position\" property",
414 * GtkPaned:max-y-position:
416 * The largest possible value for the y-position property. This property is derived from the
417 * size and shrinkability of the widget's children.
421 g_object_class_install_property (object_class,
423 g_param_spec_int ("max-y-position",
424 "Maximal y-Position",
425 "Largest possible value for the \"y-position\" property",
434 * The "resize" child property determines whether the child expands and
435 * shrinks along with the paned widget.
439 gtk_container_class_install_child_property (container_class,
441 g_param_spec_boolean ("resize",
443 "If TRUE, the child expands and shrinks along with the paned widget",
450 * The "shrink" child property determines whether the child can be made
451 * smaller than its requisition.
455 gtk_container_class_install_child_property (container_class,
457 g_param_spec_boolean ("shrink",
459 "If TRUE, the child can be made smaller than its requisition",
463 signals[CYCLE_CHILD_FOCUS] = g_signal_new ("cycle-child-focus",
464 G_TYPE_FROM_CLASS (object_class),
467 G_STRUCT_OFFSET (GtkXPanedClass,
470 psppire_marshal_BOOLEAN__BOOLEAN,
474 signals[TOGGLE_HANDLE_FOCUS] = g_signal_new ("toggle-handle-focus",
481 toggle_handle_focus), NULL,
483 psppire_marshal_BOOLEAN__VOID,
486 signals[MOVE_HANDLE] = g_signal_new ("move-handle",
487 G_TYPE_FROM_CLASS (object_class),
488 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
489 G_STRUCT_OFFSET (GtkXPanedClass,
491 NULL, psppire_marshal_BOOLEAN__ENUM,
493 GTK_TYPE_SCROLL_TYPE);
495 signals[CYCLE_HANDLE_FOCUS] = g_signal_new ("cycle-handle-focus",
500 G_STRUCT_OFFSET (GtkXPanedClass,
503 psppire_marshal_BOOLEAN__BOOLEAN,
507 signals[ACCEPT_POSITION] = g_signal_new ("accept-position",
508 G_TYPE_FROM_CLASS (object_class),
511 G_STRUCT_OFFSET (GtkXPanedClass,
514 psppire_marshal_BOOLEAN__VOID,
517 signals[CANCEL_POSITION] = g_signal_new ("cancel-position",
518 G_TYPE_FROM_CLASS (object_class),
521 G_STRUCT_OFFSET (GtkXPanedClass,
524 psppire_marshal_BOOLEAN__VOID,
527 binding_set = gtk_binding_set_by_class (class);
530 gtk_binding_entry_add_signal (binding_set,
532 "cycle-child-focus", 1,
533 G_TYPE_BOOLEAN, FALSE);
535 gtk_binding_entry_add_signal (binding_set,
536 GDK_F6, GDK_SHIFT_MASK,
537 "cycle-child-focus", 1, G_TYPE_BOOLEAN, TRUE);
540 gtk_binding_entry_add_signal (binding_set,
542 "cycle-handle-focus", 1,
543 G_TYPE_BOOLEAN, FALSE);
545 gtk_binding_entry_add_signal (binding_set,
546 GDK_F8, GDK_SHIFT_MASK,
547 "cycle-handle-focus", 1,
548 G_TYPE_BOOLEAN, TRUE);
550 add_tab_bindings (binding_set, 0);
551 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
552 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
553 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
555 /* accept and cancel positions */
556 gtk_binding_entry_add_signal (binding_set,
557 GDK_Escape, 0, "cancel-position", 0);
559 gtk_binding_entry_add_signal (binding_set,
560 GDK_Return, 0, "accept-position", 0);
562 gtk_binding_entry_add_signal (binding_set,
563 GDK_KP_Enter, 0, "accept-position", 0);
565 gtk_binding_entry_add_signal (binding_set,
566 GDK_space, 0, "accept-position", 0);
568 gtk_binding_entry_add_signal (binding_set,
569 GDK_KP_Space, 0, "accept-position", 0);
572 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
573 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
574 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
575 GTK_SCROLL_PAGE_LEFT);
576 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
577 GTK_SCROLL_PAGE_LEFT);
579 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
580 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
581 GTK_SCROLL_PAGE_RIGHT);
582 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
583 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
584 GTK_SCROLL_PAGE_RIGHT);
586 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
587 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK,
589 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
590 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK,
592 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
593 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
595 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
596 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK,
597 GTK_SCROLL_PAGE_DOWN);
598 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
599 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK,
600 GTK_SCROLL_PAGE_DOWN);
601 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
602 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
604 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
605 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
606 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
607 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
611 gtk_xpaned_child_type (GtkContainer * container)
613 if (!GTK_XPANED (container)->top_left_child ||
614 !GTK_XPANED (container)->top_right_child ||
615 !GTK_XPANED (container)->bottom_left_child ||
616 !GTK_XPANED (container)->bottom_right_child)
617 return GTK_TYPE_WIDGET;
623 gtk_xpaned_init (GtkXPaned * xpaned)
625 gtk_widget_set_can_focus (GTK_WIDGET (xpaned), TRUE);
626 gtk_widget_set_has_window (GTK_WIDGET (xpaned), FALSE);
628 xpaned->top_left_child = NULL;
629 xpaned->top_right_child = NULL;
630 xpaned->bottom_left_child = NULL;
631 xpaned->bottom_right_child = NULL;
632 xpaned->handle_east = NULL;
633 xpaned->handle_west = NULL;
634 xpaned->handle_north = NULL;
635 xpaned->handle_south = NULL;
636 xpaned->handle_middle = NULL;
637 xpaned->cursor_type_east = GDK_SB_V_DOUBLE_ARROW;
638 xpaned->cursor_type_west = GDK_SB_V_DOUBLE_ARROW;
639 xpaned->cursor_type_north = GDK_SB_H_DOUBLE_ARROW;
640 xpaned->cursor_type_south = GDK_SB_H_DOUBLE_ARROW;
641 xpaned->cursor_type_middle = GDK_FLEUR;
643 xpaned->handle_pos_east.width = 5;
644 xpaned->handle_pos_east.height = 5;
645 xpaned->handle_pos_west.width = 5;
646 xpaned->handle_pos_west.height = 5;
647 xpaned->handle_pos_north.width = 5;
648 xpaned->handle_pos_north.height = 5;
649 xpaned->handle_pos_south.width = 5;
650 xpaned->handle_pos_south.height = 5;
651 xpaned->handle_pos_middle.width = 5;
652 xpaned->handle_pos_middle.height = 5;
654 xpaned->position_set = FALSE;
655 xpaned->last_allocation.width = -1;
656 xpaned->last_allocation.height = -1;
657 xpaned->in_drag_vert = FALSE;
658 xpaned->in_drag_horiz = FALSE;
659 xpaned->in_drag_vert_and_horiz = FALSE;
661 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
662 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
663 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
664 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
666 xpaned->priv = g_new0 (GtkXPanedPrivate, 1);
667 xpaned->last_top_left_child_focus = NULL;
668 xpaned->last_top_right_child_focus = NULL;
669 xpaned->last_bottom_left_child_focus = NULL;
670 xpaned->last_bottom_right_child_focus = NULL;
671 xpaned->in_recursion = FALSE;
672 xpaned->handle_prelit = FALSE;
673 xpaned->original_position.x = -1;
674 xpaned->original_position.y = -1;
675 xpaned->unmaximized_position.x = -1;
676 xpaned->unmaximized_position.y = -1;
678 xpaned->handle_pos_east.x = -1;
679 xpaned->handle_pos_east.y = -1;
680 xpaned->handle_pos_west.x = -1;
681 xpaned->handle_pos_west.y = -1;
682 xpaned->handle_pos_north.x = -1;
683 xpaned->handle_pos_north.y = -1;
684 xpaned->handle_pos_south.x = -1;
685 xpaned->handle_pos_south.y = -1;
686 xpaned->handle_pos_middle.x = -1;
687 xpaned->handle_pos_middle.y = -1;
689 xpaned->drag_pos.x = -1;
690 xpaned->drag_pos.y = -1;
694 gtk_xpaned_size_request (GtkWidget * widget, GtkRequisition * requisition)
696 GtkXPaned *xpaned = GTK_XPANED (widget);
697 GtkRequisition child_requisition;
699 requisition->width = 0;
700 requisition->height = 0;
702 if (xpaned->top_left_child
703 && gtk_widget_get_visible (xpaned->top_left_child))
705 gtk_widget_size_request (xpaned->top_left_child, &child_requisition);
707 requisition->width = child_requisition.width;
708 requisition->height = child_requisition.height;
711 if (xpaned->top_right_child
712 && gtk_widget_get_visible (xpaned->top_right_child))
714 gtk_widget_size_request (xpaned->top_right_child, &child_requisition);
716 requisition->width += child_requisition.width;
717 requisition->height =
718 MAX (requisition->height, child_requisition.height);
721 if (xpaned->bottom_left_child
722 && gtk_widget_get_visible (xpaned->bottom_left_child))
724 gtk_widget_size_request (xpaned->bottom_left_child, &child_requisition);
726 requisition->width = MAX (requisition->width, child_requisition.width);
727 requisition->height += child_requisition.height;
730 if (xpaned->bottom_right_child
731 && gtk_widget_get_visible (xpaned->bottom_right_child))
733 gtk_widget_size_request (xpaned->bottom_right_child,
736 requisition->width = child_requisition.width;
737 requisition->height = child_requisition.height;
740 /* add 2 times the set border-width to the GtkXPaneds requisition */
741 requisition->width += gtk_container_get_border_width (GTK_CONTAINER (xpaned)) * 2;
742 requisition->height += gtk_container_get_border_width (GTK_CONTAINER (xpaned)) * 2;
744 /* also add the handle "thickness" to GtkXPaneds width- and height-requisitions */
745 if (xpaned->top_left_child
746 && gtk_widget_get_visible (xpaned->top_left_child)
747 && xpaned->top_right_child
748 && gtk_widget_get_visible (xpaned->top_right_child)
749 && xpaned->bottom_left_child
750 && gtk_widget_get_visible (xpaned->bottom_left_child)
751 && xpaned->bottom_right_child
752 && gtk_widget_get_visible (xpaned->bottom_right_child))
756 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
757 requisition->width += handle_size;
758 requisition->height += handle_size;
763 gtk_xpaned_compute_position (GtkXPaned * xpaned,
764 const GtkAllocation * allocation,
765 GtkRequisition * top_left_child_req,
766 GtkRequisition * top_right_child_req,
767 GtkRequisition * bottom_left_child_req,
768 GtkRequisition * bottom_right_child_req);
772 gtk_xpaned_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
774 GtkXPaned *xpaned = GTK_XPANED (widget);
775 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (xpaned));
776 GtkAllocation top_left_child_allocation;
777 GtkAllocation top_right_child_allocation;
778 GtkAllocation bottom_left_child_allocation;
779 GtkAllocation bottom_right_child_allocation;
780 GtkRequisition top_left_child_requisition;
781 GtkRequisition top_right_child_requisition;
782 GtkRequisition bottom_left_child_requisition;
783 GtkRequisition bottom_right_child_requisition;
786 /* determine size of handle(s) */
787 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
789 gtk_widget_set_allocation (widget, allocation);
791 if (xpaned->top_left_child
792 && gtk_widget_get_visible (xpaned->top_left_child)
793 && xpaned->top_right_child
794 && gtk_widget_get_visible (xpaned->top_right_child)
795 && xpaned->bottom_left_child
796 && gtk_widget_get_visible (xpaned->bottom_left_child)
797 && xpaned->bottom_right_child
798 && gtk_widget_get_visible (xpaned->bottom_right_child))
800 /* what sizes do the children want to be at least at */
801 gtk_widget_get_child_requisition (xpaned->top_left_child,
802 &top_left_child_requisition);
803 gtk_widget_get_child_requisition (xpaned->top_right_child,
804 &top_right_child_requisition);
805 gtk_widget_get_child_requisition (xpaned->bottom_left_child,
806 &bottom_left_child_requisition);
807 gtk_widget_get_child_requisition (xpaned->bottom_right_child,
808 &bottom_right_child_requisition);
810 /* determine the total requisition-sum of all requisitions of borders,
811 * handles, children etc. */
812 gtk_xpaned_compute_position (xpaned,
814 &top_left_child_requisition,
815 &top_right_child_requisition,
816 &bottom_left_child_requisition,
817 &bottom_right_child_requisition);
819 /* calculate the current positions and sizes of the handles */
820 xpaned->handle_pos_east.x =
821 allocation->x + border_width +
822 xpaned->top_left_child_size.width + handle_size;
823 xpaned->handle_pos_east.y =
824 allocation->y + border_width +
825 xpaned->top_left_child_size.height;
826 xpaned->handle_pos_east.width =
827 allocation->width - xpaned->top_left_child_size.width -
828 2 * border_width - handle_size;
829 xpaned->handle_pos_east.height = handle_size;
831 xpaned->handle_pos_west.x = allocation->x + border_width;
832 xpaned->handle_pos_west.y = xpaned->handle_pos_east.y;
833 xpaned->handle_pos_west.width =
834 allocation->width - xpaned->handle_pos_east.width -
835 2 * border_width - handle_size;
836 xpaned->handle_pos_west.height = handle_size;
838 xpaned->handle_pos_north.x = xpaned->handle_pos_east.x - handle_size;
839 xpaned->handle_pos_north.y = allocation->y + border_width;
840 xpaned->handle_pos_north.width = handle_size;
841 xpaned->handle_pos_north.height =
842 xpaned->handle_pos_east.y - allocation->y - border_width;
844 xpaned->handle_pos_south.x = xpaned->handle_pos_north.x;
845 xpaned->handle_pos_south.y = xpaned->handle_pos_east.y + handle_size;
846 xpaned->handle_pos_south.width = handle_size;
847 xpaned->handle_pos_south.height =
848 allocation->height - xpaned->handle_pos_north.height -
849 2 * border_width - handle_size;
853 xpaned->handle_pos_middle.x = xpaned->handle_pos_north.x;
854 xpaned->handle_pos_middle.y = xpaned->handle_pos_east.y;
855 xpaned->handle_pos_middle.width = handle_size + CENTRUM;
856 xpaned->handle_pos_middle.height = handle_size + CENTRUM;
858 /* set allocation for top-left child */
859 top_left_child_allocation.x = allocation->x + border_width;
860 top_left_child_allocation.y = allocation->y + border_width;
861 top_left_child_allocation.width = xpaned->handle_pos_west.width;
862 top_left_child_allocation.height = xpaned->handle_pos_north.height;
864 /* set allocation for top-right child */
865 top_right_child_allocation.x =
866 allocation->x + border_width + handle_size +
867 top_left_child_allocation.width;
868 top_right_child_allocation.y = allocation->y + border_width;
869 top_right_child_allocation.width = xpaned->handle_pos_east.width;
870 top_right_child_allocation.height = xpaned->handle_pos_north.height;
872 /* set allocation for bottom-left child */
873 bottom_left_child_allocation.x = xpaned->handle_pos_west.x;
874 bottom_left_child_allocation.y = xpaned->handle_pos_south.y;
875 bottom_left_child_allocation.width = xpaned->handle_pos_west.width;
876 bottom_left_child_allocation.height = xpaned->handle_pos_south.height;
878 /* set allocation for bottom-right child */
879 bottom_right_child_allocation.x = top_right_child_allocation.x;
880 bottom_right_child_allocation.y = bottom_left_child_allocation.y;
881 bottom_right_child_allocation.width = xpaned->handle_pos_east.width;
882 bottom_right_child_allocation.height = xpaned->handle_pos_south.height;
884 if (gtk_widget_get_realized (widget))
886 if (gtk_widget_get_mapped (widget))
888 gdk_window_show (xpaned->handle_east);
889 gdk_window_show (xpaned->handle_west);
890 gdk_window_show (xpaned->handle_north);
891 gdk_window_show (xpaned->handle_south);
892 gdk_window_show (xpaned->handle_middle);
895 gdk_window_move_resize (xpaned->handle_east,
896 xpaned->handle_pos_east.x,
897 xpaned->handle_pos_east.y,
898 xpaned->handle_pos_east.width,
899 xpaned->handle_pos_east.height);
901 gdk_window_move_resize (xpaned->handle_west,
902 xpaned->handle_pos_west.x,
903 xpaned->handle_pos_west.y,
904 xpaned->handle_pos_west.width,
905 xpaned->handle_pos_west.height);
907 gdk_window_move_resize (xpaned->handle_north,
908 xpaned->handle_pos_north.x,
909 xpaned->handle_pos_north.y,
910 xpaned->handle_pos_north.width,
911 xpaned->handle_pos_north.height);
913 gdk_window_move_resize (xpaned->handle_south,
914 xpaned->handle_pos_south.x,
915 xpaned->handle_pos_south.y,
916 xpaned->handle_pos_south.width,
917 xpaned->handle_pos_south.height);
919 gdk_window_move_resize (xpaned->handle_middle,
920 xpaned->handle_pos_middle.x,
921 xpaned->handle_pos_middle.y,
922 xpaned->handle_pos_middle.width,
923 xpaned->handle_pos_middle.height);
926 /* Now allocate the childen, making sure, when resizing not to
927 * overlap the windows
929 if (gtk_widget_get_mapped (widget))
931 gtk_widget_size_allocate (xpaned->top_right_child,
932 &top_right_child_allocation);
933 gtk_widget_size_allocate (xpaned->top_left_child,
934 &top_left_child_allocation);
935 gtk_widget_size_allocate (xpaned->bottom_left_child,
936 &bottom_left_child_allocation);
937 gtk_widget_size_allocate (xpaned->bottom_right_child,
938 &bottom_right_child_allocation);
944 gtk_xpaned_set_property (GObject * object,
946 const GValue * value, GParamSpec * pspec)
948 GtkXPaned *xpaned = GTK_XPANED (object);
952 case PROP_X_POSITION:
953 gtk_xpaned_set_position_x (xpaned, g_value_get_int (value));
956 case PROP_Y_POSITION:
957 gtk_xpaned_set_position_y (xpaned, g_value_get_int (value));
960 case PROP_POSITION_SET:
961 xpaned->position_set = g_value_get_boolean (value);
962 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
966 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
972 gtk_xpaned_get_property (GObject * object,
973 guint prop_id, GValue * value, GParamSpec * pspec)
975 GtkXPaned *xpaned = GTK_XPANED (object);
979 case PROP_X_POSITION:
980 g_value_set_int (value, xpaned->top_left_child_size.width);
983 case PROP_Y_POSITION:
984 g_value_set_int (value, xpaned->top_left_child_size.height);
987 case PROP_POSITION_SET:
988 g_value_set_boolean (value, xpaned->position_set);
991 case PROP_MIN_X_POSITION:
992 g_value_set_int (value, xpaned->min_position.x);
995 case PROP_MIN_Y_POSITION:
996 g_value_set_int (value, xpaned->min_position.y);
999 case PROP_MAX_X_POSITION:
1000 g_value_set_int (value, xpaned->max_position.x);
1003 case PROP_MAX_Y_POSITION:
1004 g_value_set_int (value, xpaned->max_position.y);
1008 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1014 gtk_xpaned_set_child_property (GtkContainer * container,
1017 const GValue * value, GParamSpec * pspec)
1019 GtkXPaned *xpaned = GTK_XPANED (container);
1020 gboolean old_value = FALSE;
1021 gboolean new_value = FALSE;
1023 g_assert (child == xpaned->top_left_child ||
1024 child == xpaned->top_right_child ||
1025 child == xpaned->bottom_left_child ||
1026 child == xpaned->bottom_right_child);
1028 new_value = g_value_get_boolean (value);
1030 switch (property_id)
1032 case CHILD_PROP_RESIZE:
1033 if (child == xpaned->top_left_child)
1035 old_value = xpaned->top_left_child_resize;
1036 xpaned->top_left_child_resize = new_value;
1038 else if (child == xpaned->top_right_child)
1040 old_value = xpaned->top_right_child_resize;
1041 xpaned->top_right_child_resize = new_value;
1043 else if (child == xpaned->bottom_left_child)
1045 old_value = xpaned->bottom_left_child_resize;
1046 xpaned->bottom_left_child_resize = new_value;
1048 else if (child == xpaned->bottom_right_child)
1050 old_value = xpaned->bottom_right_child_resize;
1051 xpaned->bottom_right_child_resize = new_value;
1055 case CHILD_PROP_SHRINK:
1056 if (child == xpaned->top_left_child)
1058 old_value = xpaned->top_left_child_shrink;
1059 xpaned->top_left_child_shrink = new_value;
1061 else if (child == xpaned->top_right_child)
1063 old_value = xpaned->top_right_child_shrink;
1064 xpaned->top_right_child_shrink = new_value;
1066 else if (child == xpaned->bottom_left_child)
1068 old_value = xpaned->bottom_left_child_shrink;
1069 xpaned->bottom_left_child_shrink = new_value;
1071 else if (child == xpaned->bottom_right_child)
1073 old_value = xpaned->bottom_right_child_shrink;
1074 xpaned->bottom_right_child_shrink = new_value;
1079 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1080 property_id, pspec);
1081 old_value = -1; /* quiet gcc */
1085 if (old_value != new_value)
1086 gtk_widget_queue_resize (GTK_WIDGET (container));
1090 gtk_xpaned_get_child_property (GtkContainer * container,
1093 GValue * value, GParamSpec * pspec)
1095 GtkXPaned *xpaned = GTK_XPANED (container);
1097 g_assert (child == xpaned->top_left_child ||
1098 child == xpaned->top_right_child ||
1099 child == xpaned->bottom_left_child ||
1100 child == xpaned->bottom_right_child);
1102 switch (property_id)
1104 case CHILD_PROP_RESIZE:
1105 if (child == xpaned->top_left_child)
1106 g_value_set_boolean (value, xpaned->top_left_child_resize);
1107 else if (child == xpaned->top_right_child)
1108 g_value_set_boolean (value, xpaned->top_right_child_resize);
1109 else if (child == xpaned->bottom_left_child)
1110 g_value_set_boolean (value, xpaned->bottom_left_child_resize);
1111 else if (child == xpaned->bottom_right_child)
1112 g_value_set_boolean (value, xpaned->bottom_right_child_resize);
1115 case CHILD_PROP_SHRINK:
1116 if (child == xpaned->top_left_child)
1117 g_value_set_boolean (value, xpaned->top_left_child_shrink);
1118 else if (child == xpaned->top_right_child)
1119 g_value_set_boolean (value, xpaned->top_right_child_shrink);
1120 else if (child == xpaned->bottom_left_child)
1121 g_value_set_boolean (value, xpaned->bottom_left_child_shrink);
1122 else if (child == xpaned->bottom_right_child)
1123 g_value_set_boolean (value, xpaned->bottom_right_child_shrink);
1127 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1128 property_id, pspec);
1134 gtk_xpaned_finalize (GObject * object)
1136 GtkXPaned *xpaned = GTK_XPANED (object);
1138 gtk_xpaned_set_saved_focus (xpaned, NULL);
1139 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1141 g_free (xpaned->priv);
1143 G_OBJECT_CLASS (parent_class)->finalize (object);
1147 gtk_xpaned_realize (GtkWidget * widget)
1150 GdkWindowAttr attributes_east;
1151 GdkWindowAttr attributes_west;
1152 GdkWindowAttr attributes_north;
1153 GdkWindowAttr attributes_south;
1154 GdkWindowAttr attributes_middle;
1155 gint attributes_mask_east;
1156 gint attributes_mask_west;
1157 gint attributes_mask_north;
1158 gint attributes_mask_south;
1159 gint attributes_mask_middle;
1161 gtk_widget_set_realized (widget, TRUE);
1162 xpaned = GTK_XPANED (widget);
1164 gtk_widget_set_window (widget, gtk_widget_get_parent_window (widget));
1165 // g_object_ref (widget->window);
1167 attributes_east.window_type = GDK_WINDOW_CHILD;
1168 attributes_west.window_type = GDK_WINDOW_CHILD;
1169 attributes_north.window_type = GDK_WINDOW_CHILD;
1170 attributes_south.window_type = GDK_WINDOW_CHILD;
1171 attributes_middle.window_type = GDK_WINDOW_CHILD;
1173 attributes_east.wclass = GDK_INPUT_ONLY;
1174 attributes_west.wclass = GDK_INPUT_ONLY;
1175 attributes_north.wclass = GDK_INPUT_ONLY;
1176 attributes_south.wclass = GDK_INPUT_ONLY;
1177 attributes_middle.wclass = GDK_INPUT_ONLY;
1179 attributes_east.x = xpaned->handle_pos_east.x;
1180 attributes_east.y = xpaned->handle_pos_east.y;
1181 attributes_east.width = xpaned->handle_pos_east.width;
1182 attributes_east.height = xpaned->handle_pos_east.height;
1184 attributes_west.x = xpaned->handle_pos_west.x;
1185 attributes_west.y = xpaned->handle_pos_west.y;
1186 attributes_west.width = xpaned->handle_pos_west.width;
1187 attributes_west.height = xpaned->handle_pos_west.height;
1189 attributes_north.x = xpaned->handle_pos_north.x;
1190 attributes_north.y = xpaned->handle_pos_north.y;
1191 attributes_north.width = xpaned->handle_pos_north.width;
1192 attributes_north.height = xpaned->handle_pos_north.height;
1194 attributes_south.x = xpaned->handle_pos_south.x;
1195 attributes_south.y = xpaned->handle_pos_south.y;
1196 attributes_south.width = xpaned->handle_pos_south.width;
1197 attributes_south.height = xpaned->handle_pos_south.height;
1199 attributes_middle.x = xpaned->handle_pos_middle.x;
1200 attributes_middle.y = xpaned->handle_pos_middle.y;
1201 attributes_middle.width = xpaned->handle_pos_middle.width;
1202 attributes_middle.height = xpaned->handle_pos_middle.height;
1204 attributes_east.cursor =
1205 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1206 xpaned->cursor_type_east);
1207 attributes_west.cursor =
1208 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1209 xpaned->cursor_type_west);
1210 attributes_north.cursor =
1211 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1212 xpaned->cursor_type_north);
1213 attributes_south.cursor =
1214 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1215 xpaned->cursor_type_south);
1216 attributes_middle.cursor =
1217 gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1218 xpaned->cursor_type_middle);
1220 attributes_east.event_mask = gtk_widget_get_events (widget);
1221 attributes_west.event_mask = gtk_widget_get_events (widget);
1222 attributes_north.event_mask = gtk_widget_get_events (widget);
1223 attributes_south.event_mask = gtk_widget_get_events (widget);
1224 attributes_middle.event_mask = gtk_widget_get_events (widget);
1226 attributes_east.event_mask |= (GDK_BUTTON_PRESS_MASK |
1227 GDK_BUTTON_RELEASE_MASK |
1228 GDK_ENTER_NOTIFY_MASK |
1229 GDK_LEAVE_NOTIFY_MASK |
1230 GDK_POINTER_MOTION_MASK |
1231 GDK_POINTER_MOTION_HINT_MASK);
1232 attributes_west.event_mask |= (GDK_BUTTON_PRESS_MASK |
1233 GDK_BUTTON_RELEASE_MASK |
1234 GDK_ENTER_NOTIFY_MASK |
1235 GDK_LEAVE_NOTIFY_MASK |
1236 GDK_POINTER_MOTION_MASK |
1237 GDK_POINTER_MOTION_HINT_MASK);
1238 attributes_north.event_mask |= (GDK_BUTTON_PRESS_MASK |
1239 GDK_BUTTON_RELEASE_MASK |
1240 GDK_ENTER_NOTIFY_MASK |
1241 GDK_LEAVE_NOTIFY_MASK |
1242 GDK_POINTER_MOTION_MASK |
1243 GDK_POINTER_MOTION_HINT_MASK);
1244 attributes_south.event_mask |= (GDK_BUTTON_PRESS_MASK |
1245 GDK_BUTTON_RELEASE_MASK |
1246 GDK_ENTER_NOTIFY_MASK |
1247 GDK_LEAVE_NOTIFY_MASK |
1248 GDK_POINTER_MOTION_MASK |
1249 GDK_POINTER_MOTION_HINT_MASK);
1250 attributes_middle.event_mask |= (GDK_BUTTON_PRESS_MASK |
1251 GDK_BUTTON_RELEASE_MASK |
1252 GDK_ENTER_NOTIFY_MASK |
1253 GDK_LEAVE_NOTIFY_MASK |
1254 GDK_POINTER_MOTION_MASK |
1255 GDK_POINTER_MOTION_HINT_MASK);
1257 attributes_mask_east = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1258 attributes_mask_west = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1259 attributes_mask_north = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1260 attributes_mask_south = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1261 attributes_mask_middle = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1263 xpaned->handle_east = gdk_window_new (gtk_widget_get_window (widget),
1265 attributes_mask_east);
1266 xpaned->handle_west = gdk_window_new (gtk_widget_get_window (widget),
1268 attributes_mask_west);
1269 xpaned->handle_north = gdk_window_new (gtk_widget_get_window (widget),
1271 attributes_mask_north);
1272 xpaned->handle_south = gdk_window_new (gtk_widget_get_window (widget),
1274 attributes_mask_south);
1275 xpaned->handle_middle = gdk_window_new (gtk_widget_get_window (widget),
1277 attributes_mask_middle);
1279 gdk_window_set_user_data (xpaned->handle_east, xpaned);
1280 gdk_window_set_user_data (xpaned->handle_west, xpaned);
1281 gdk_window_set_user_data (xpaned->handle_north, xpaned);
1282 gdk_window_set_user_data (xpaned->handle_south, xpaned);
1283 gdk_window_set_user_data (xpaned->handle_middle, xpaned);
1285 gdk_cursor_unref (attributes_east.cursor);
1286 gdk_cursor_unref (attributes_west.cursor);
1287 gdk_cursor_unref (attributes_north.cursor);
1288 gdk_cursor_unref (attributes_south.cursor);
1289 gdk_cursor_unref (attributes_middle.cursor);
1292 GtkStyle *style = gtk_widget_get_style (widget);
1293 style = gtk_style_attach (style, gtk_widget_get_window (widget));
1294 gtk_widget_set_style (widget, style);
1298 if (xpaned->top_left_child
1299 && gtk_widget_get_visible (xpaned->top_left_child)
1300 && xpaned->top_right_child
1301 && gtk_widget_get_visible (xpaned->top_right_child)
1302 && xpaned->bottom_left_child
1303 && gtk_widget_get_visible (xpaned->bottom_left_child)
1304 && xpaned->bottom_right_child
1305 && gtk_widget_get_visible (xpaned->bottom_right_child))
1307 gdk_window_show (xpaned->handle_east);
1308 gdk_window_show (xpaned->handle_west);
1309 gdk_window_show (xpaned->handle_north);
1310 gdk_window_show (xpaned->handle_south);
1311 gdk_window_show (xpaned->handle_middle);
1316 gtk_xpaned_unrealize (GtkWidget * widget)
1318 GtkXPaned *xpaned = GTK_XPANED (widget);
1320 if (xpaned->handle_east)
1322 gdk_window_set_user_data (xpaned->handle_east, NULL);
1323 gdk_window_destroy (xpaned->handle_east);
1324 xpaned->handle_east = NULL;
1327 if (xpaned->handle_west)
1329 gdk_window_set_user_data (xpaned->handle_west, NULL);
1330 gdk_window_destroy (xpaned->handle_west);
1331 xpaned->handle_west = NULL;
1334 if (xpaned->handle_north)
1336 gdk_window_set_user_data (xpaned->handle_north, NULL);
1337 gdk_window_destroy (xpaned->handle_north);
1338 xpaned->handle_north = NULL;
1341 if (xpaned->handle_south)
1343 gdk_window_set_user_data (xpaned->handle_south, NULL);
1344 gdk_window_destroy (xpaned->handle_south);
1345 xpaned->handle_south = NULL;
1348 if (xpaned->handle_middle)
1350 gdk_window_set_user_data (xpaned->handle_middle, NULL);
1351 gdk_window_destroy (xpaned->handle_middle);
1352 xpaned->handle_middle = NULL;
1355 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
1356 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
1357 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
1358 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
1359 gtk_xpaned_set_saved_focus (xpaned, NULL);
1360 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1362 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1363 (*GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1367 gtk_xpaned_map (GtkWidget * widget)
1369 GtkXPaned *xpaned = GTK_XPANED (widget);
1371 gdk_window_show (xpaned->handle_east);
1372 gdk_window_show (xpaned->handle_west);
1373 gdk_window_show (xpaned->handle_north);
1374 gdk_window_show (xpaned->handle_south);
1375 gdk_window_show (xpaned->handle_middle);
1377 GTK_WIDGET_CLASS (parent_class)->map (widget);
1381 gtk_xpaned_unmap (GtkWidget * widget)
1383 GtkXPaned *xpaned = GTK_XPANED (widget);
1385 gdk_window_hide (xpaned->handle_east);
1386 gdk_window_hide (xpaned->handle_west);
1387 gdk_window_hide (xpaned->handle_north);
1388 gdk_window_hide (xpaned->handle_south);
1389 gdk_window_hide (xpaned->handle_middle);
1391 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1395 gtk_xpaned_draw (GtkWidget * widget, cairo_t *cr)
1397 GtkXPaned *xpaned = GTK_XPANED (widget);
1400 /* determine size of handle(s) */
1401 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1403 /* I want the handle-"thickness" to be at least 3 */
1404 g_assert (handle_size >= 3);
1406 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1407 xpaned->top_left_child
1408 && gtk_widget_get_visible (xpaned->top_left_child)
1409 && xpaned->top_right_child
1410 && gtk_widget_get_visible (xpaned->top_right_child)
1411 && xpaned->bottom_left_child
1412 && gtk_widget_get_visible (xpaned->bottom_left_child)
1413 && xpaned->bottom_right_child
1414 && gtk_widget_get_visible (xpaned->bottom_right_child))
1418 if (gtk_widget_is_focus (widget))
1419 state = GTK_STATE_SELECTED;
1420 else if (xpaned->handle_prelit)
1421 state = GTK_STATE_PRELIGHT;
1423 state = gtk_widget_get_state (widget);
1425 gtk_paint_handle (gtk_widget_get_style (widget),
1431 xpaned->handle_pos_east.x - handle_size - 256 / 2,
1432 xpaned->handle_pos_west.y + 1,
1433 256 + handle_size, handle_size - 2,
1434 /*xpaned->handle_pos_west.x,
1435 xpaned->handle_pos_west.y + 1,
1436 xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width,
1438 GTK_ORIENTATION_HORIZONTAL);
1440 gtk_paint_handle (gtk_widget_get_style (widget),
1446 xpaned->handle_pos_north.x + 1,
1447 xpaned->handle_pos_south.y - handle_size - 256 / 2,
1448 handle_size - 2, 256 + handle_size,
1449 /*xpaned->handle_pos_north.x + 1,
1450 xpaned->handle_pos_north.y,
1452 xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height, */
1453 GTK_ORIENTATION_VERTICAL);
1456 /* Chain up to draw children */
1457 GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
1463 is_rtl (GtkXPaned * xpaned)
1465 if (gtk_widget_get_direction (GTK_WIDGET (xpaned)) == GTK_TEXT_DIR_RTL)
1472 update_drag (GtkXPaned * xpaned)
1476 GtkRequisition size;
1477 GtkAllocation allocation;
1478 gtk_widget_get_allocation (GTK_WIDGET (xpaned), &allocation);
1480 gtk_widget_get_pointer (GTK_WIDGET (xpaned), &pos.x, &pos.y);
1482 if (xpaned->in_drag_vert)
1484 pos.y -= xpaned->drag_pos.y;
1486 if (is_rtl (xpaned))
1488 gtk_widget_style_get (GTK_WIDGET (xpaned),
1489 "handle-size", &handle_size, NULL);
1491 size.height = allocation.height - pos.y - handle_size;
1495 size.height = pos.y;
1498 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1501 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1503 if (size.height != xpaned->top_left_child_size.height)
1504 gtk_xpaned_set_position_y (xpaned, size.height);
1507 if (xpaned->in_drag_horiz)
1509 pos.x -= xpaned->drag_pos.x;
1511 if (is_rtl (xpaned))
1513 gtk_widget_style_get (GTK_WIDGET (xpaned),
1514 "handle-size", &handle_size, NULL);
1516 size.width = allocation.width - pos.x - handle_size;
1523 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1526 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1528 if (size.width != xpaned->top_left_child_size.width)
1529 gtk_xpaned_set_position_x (xpaned, size.width);
1532 if (xpaned->in_drag_vert_and_horiz)
1534 pos.x -= xpaned->drag_pos.x;
1535 pos.y -= xpaned->drag_pos.y;
1537 if (is_rtl (xpaned))
1539 gtk_widget_style_get (GTK_WIDGET (xpaned),
1540 "handle-size", &handle_size, NULL);
1542 size.width = allocation.width - pos.x - handle_size;
1543 size.height = allocation.height - pos.y - handle_size;
1548 size.height = pos.y;
1551 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1552 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1555 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1557 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1559 if (size.width != xpaned->top_left_child_size.width)
1560 gtk_xpaned_set_position_x (xpaned, size.width);
1562 if (size.height != xpaned->top_left_child_size.height)
1563 gtk_xpaned_set_position_y (xpaned, size.height);
1568 gtk_xpaned_enter (GtkWidget * widget, GdkEventCrossing * event)
1570 GtkXPaned *xpaned = GTK_XPANED (widget);
1572 if (xpaned->in_drag_vert ||
1573 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1574 update_drag (xpaned);
1577 xpaned->handle_prelit = TRUE;
1579 gtk_widget_queue_draw_area (widget,
1580 xpaned->handle_pos_east.x,
1581 xpaned->handle_pos_east.y,
1582 xpaned->handle_pos_east.width,
1583 xpaned->handle_pos_east.height);
1585 gtk_widget_queue_draw_area (widget,
1586 xpaned->handle_pos_west.x,
1587 xpaned->handle_pos_west.y,
1588 xpaned->handle_pos_west.width,
1589 xpaned->handle_pos_west.height);
1591 gtk_widget_queue_draw_area (widget,
1592 xpaned->handle_pos_north.x,
1593 xpaned->handle_pos_north.y,
1594 xpaned->handle_pos_north.width,
1595 xpaned->handle_pos_north.height);
1597 gtk_widget_queue_draw_area (widget,
1598 xpaned->handle_pos_south.x,
1599 xpaned->handle_pos_south.y,
1600 xpaned->handle_pos_south.width,
1601 xpaned->handle_pos_south.height);
1603 gtk_widget_queue_draw_area (widget,
1604 xpaned->handle_pos_middle.x,
1605 xpaned->handle_pos_middle.y,
1606 xpaned->handle_pos_middle.width,
1607 xpaned->handle_pos_middle.height);
1614 gtk_xpaned_leave (GtkWidget * widget, GdkEventCrossing * event)
1616 GtkXPaned *xpaned = GTK_XPANED (widget);
1618 if (xpaned->in_drag_vert ||
1619 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1620 update_drag (xpaned);
1623 xpaned->handle_prelit = FALSE;
1625 gtk_widget_queue_draw_area (widget,
1626 xpaned->handle_pos_east.x,
1627 xpaned->handle_pos_east.y,
1628 xpaned->handle_pos_east.width,
1629 xpaned->handle_pos_east.height);
1631 gtk_widget_queue_draw_area (widget,
1632 xpaned->handle_pos_west.x,
1633 xpaned->handle_pos_west.y,
1634 xpaned->handle_pos_west.width,
1635 xpaned->handle_pos_west.height);
1637 gtk_widget_queue_draw_area (widget,
1638 xpaned->handle_pos_north.x,
1639 xpaned->handle_pos_north.y,
1640 xpaned->handle_pos_north.width,
1641 xpaned->handle_pos_north.height);
1643 gtk_widget_queue_draw_area (widget,
1644 xpaned->handle_pos_south.x,
1645 xpaned->handle_pos_south.y,
1646 xpaned->handle_pos_south.width,
1647 xpaned->handle_pos_south.height);
1649 gtk_widget_queue_draw_area (widget,
1650 xpaned->handle_pos_middle.x,
1651 xpaned->handle_pos_middle.y,
1652 xpaned->handle_pos_middle.width,
1653 xpaned->handle_pos_middle.height);
1660 gtk_xpaned_focus (GtkWidget * widget, GtkDirectionType direction)
1664 /* This is a hack, but how can this be done without
1665 * excessive cut-and-paste from gtkcontainer.c?
1668 gtk_widget_set_can_focus (GTK_WIDGET (widget), FALSE);
1669 retval = (*GTK_WIDGET_CLASS (parent_class)->focus) (widget, direction);
1670 gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE);
1676 gtk_xpaned_button_press (GtkWidget * widget, GdkEventButton * event)
1678 GtkXPaned *xpaned = GTK_XPANED (widget);
1680 /* if any child is currently maximized, jump right back */
1681 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
1682 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
1683 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
1684 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
1687 /* if user is dragging the handles around */
1688 if (!xpaned->in_drag_vert_and_horiz &&
1689 event->window != xpaned->handle_east &&
1690 event->window != xpaned->handle_west &&
1691 event->window != xpaned->handle_north &&
1692 event->window != xpaned->handle_south &&
1693 event->window == xpaned->handle_middle && event->button == 1)
1695 xpaned->in_drag_vert_and_horiz = TRUE;
1697 /* We need a server grab here, not gtk_grab_add(), since
1698 * we don't want to pass events on to the widget's children */
1699 if (gdk_pointer_grab (xpaned->handle_middle,
1701 GDK_POINTER_MOTION_HINT_MASK
1702 | GDK_BUTTON1_MOTION_MASK
1703 | GDK_BUTTON_RELEASE_MASK
1704 | GDK_ENTER_NOTIFY_MASK
1705 | GDK_LEAVE_NOTIFY_MASK,
1706 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1710 xpaned->drag_pos.x = event->x;
1711 xpaned->drag_pos.y = event->y;
1715 else if (!xpaned->in_drag_vert &&
1716 event->window == xpaned->handle_east &&
1717 event->window != xpaned->handle_west &&
1718 event->window != xpaned->handle_north &&
1719 event->window != xpaned->handle_south &&
1720 event->window != xpaned->handle_middle && event->button == 1)
1722 xpaned->in_drag_vert = TRUE;
1724 /* We need a server grab here, not gtk_grab_add(), since
1725 * we don't want to pass events on to the widget's children */
1726 if (gdk_pointer_grab (xpaned->handle_east,
1728 GDK_POINTER_MOTION_HINT_MASK
1729 | GDK_BUTTON1_MOTION_MASK
1730 | GDK_BUTTON_RELEASE_MASK
1731 | GDK_ENTER_NOTIFY_MASK
1732 | GDK_LEAVE_NOTIFY_MASK,
1733 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1737 xpaned->drag_pos.y = event->y;
1741 else if (!xpaned->in_drag_vert &&
1742 event->window != xpaned->handle_east &&
1743 event->window == xpaned->handle_west &&
1744 event->window != xpaned->handle_north &&
1745 event->window != xpaned->handle_south &&
1746 event->window != xpaned->handle_middle && event->button == 1)
1748 xpaned->in_drag_vert = TRUE;
1750 /* We need a server grab here, not gtk_grab_add(), since
1751 * we don't want to pass events on to the widget's children */
1752 if (gdk_pointer_grab (xpaned->handle_west,
1754 GDK_POINTER_MOTION_HINT_MASK
1755 | GDK_BUTTON1_MOTION_MASK
1756 | GDK_BUTTON_RELEASE_MASK
1757 | GDK_ENTER_NOTIFY_MASK
1758 | GDK_LEAVE_NOTIFY_MASK,
1759 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1763 xpaned->drag_pos.y = event->y;
1767 else if (!xpaned->in_drag_horiz &&
1768 event->window != xpaned->handle_east &&
1769 event->window != xpaned->handle_west &&
1770 event->window == xpaned->handle_north &&
1771 event->window != xpaned->handle_south &&
1772 event->window != xpaned->handle_middle && event->button == 1)
1774 xpaned->in_drag_horiz = TRUE;
1776 /* We need a server grab here, not gtk_grab_add(), since
1777 * we don't want to pass events on to the widget's children */
1778 if (gdk_pointer_grab (xpaned->handle_north,
1780 GDK_POINTER_MOTION_HINT_MASK
1781 | GDK_BUTTON1_MOTION_MASK
1782 | GDK_BUTTON_RELEASE_MASK
1783 | GDK_ENTER_NOTIFY_MASK
1784 | GDK_LEAVE_NOTIFY_MASK,
1785 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1789 xpaned->drag_pos.x = event->x;
1793 else if (!xpaned->in_drag_horiz &&
1794 event->window != xpaned->handle_east &&
1795 event->window != xpaned->handle_west &&
1796 event->window != xpaned->handle_north &&
1797 event->window == xpaned->handle_south &&
1798 event->window != xpaned->handle_middle && event->button == 1)
1800 xpaned->in_drag_horiz = TRUE;
1802 /* We need a server grab here, not gtk_grab_add(), since
1803 * we don't want to pass events on to the widget's children */
1804 if (gdk_pointer_grab (xpaned->handle_south,
1806 GDK_POINTER_MOTION_HINT_MASK
1807 | GDK_BUTTON1_MOTION_MASK
1808 | GDK_BUTTON_RELEASE_MASK
1809 | GDK_ENTER_NOTIFY_MASK
1810 | GDK_LEAVE_NOTIFY_MASK,
1811 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1815 xpaned->drag_pos.x = event->x;
1823 gtk_xpaned_button_release (GtkWidget * widget, GdkEventButton * event)
1825 GtkXPaned *xpaned = GTK_XPANED (widget);
1827 if (xpaned->in_drag_vert && (event->button == 1))
1829 xpaned->in_drag_vert = FALSE;
1830 xpaned->drag_pos.y = -1;
1831 xpaned->position_set = TRUE;
1832 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1836 else if (xpaned->in_drag_horiz && (event->button == 1))
1838 xpaned->in_drag_horiz = FALSE;
1839 xpaned->drag_pos.x = -1;
1840 xpaned->position_set = TRUE;
1841 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1845 else if (xpaned->in_drag_vert_and_horiz && (event->button == 1))
1847 xpaned->in_drag_vert_and_horiz = FALSE;
1848 xpaned->drag_pos.x = -1;
1849 xpaned->drag_pos.y = -1;
1850 xpaned->position_set = TRUE;
1851 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1860 gtk_xpaned_motion (GtkWidget * widget, GdkEventMotion * event)
1862 GtkXPaned *xpaned = GTK_XPANED (widget);
1864 if (xpaned->in_drag_vert ||
1865 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1868 update_drag (xpaned);
1876 gtk_xpaned_add_top_left (GtkXPaned * xpaned, GtkWidget * widget)
1878 gtk_xpaned_pack_top_left (xpaned, widget, FALSE, TRUE);
1882 gtk_xpaned_add_top_right (GtkXPaned * xpaned, GtkWidget * widget)
1884 gtk_xpaned_pack_top_right (xpaned, widget, FALSE, TRUE);
1888 gtk_xpaned_add_bottom_left (GtkXPaned * xpaned, GtkWidget * widget)
1890 gtk_xpaned_pack_bottom_left (xpaned, widget, FALSE, TRUE);
1894 gtk_xpaned_add_bottom_right (GtkXPaned * xpaned, GtkWidget * widget)
1896 gtk_xpaned_pack_bottom_right (xpaned, widget, FALSE, TRUE);
1900 gtk_xpaned_pack_top_left (GtkXPaned * xpaned,
1901 GtkWidget * child, gboolean resize, gboolean shrink)
1903 g_return_if_fail (GTK_IS_XPANED (xpaned));
1904 g_return_if_fail (GTK_IS_WIDGET (child));
1906 if (!xpaned->top_left_child)
1908 xpaned->top_left_child = child;
1909 xpaned->top_left_child_resize = resize;
1910 xpaned->top_left_child_shrink = shrink;
1912 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1917 gtk_xpaned_pack_top_right (GtkXPaned * xpaned,
1919 gboolean resize, gboolean shrink)
1921 g_return_if_fail (GTK_IS_XPANED (xpaned));
1922 g_return_if_fail (GTK_IS_WIDGET (child));
1924 if (!xpaned->top_right_child)
1926 xpaned->top_right_child = child;
1927 xpaned->top_right_child_resize = resize;
1928 xpaned->top_right_child_shrink = shrink;
1930 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1935 gtk_xpaned_pack_bottom_left (GtkXPaned * xpaned,
1937 gboolean resize, gboolean shrink)
1939 g_return_if_fail (GTK_IS_XPANED (xpaned));
1940 g_return_if_fail (GTK_IS_WIDGET (child));
1942 if (!xpaned->bottom_left_child)
1944 xpaned->bottom_left_child = child;
1945 xpaned->bottom_left_child_resize = resize;
1946 xpaned->bottom_left_child_shrink = shrink;
1948 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1953 gtk_xpaned_pack_bottom_right (GtkXPaned * xpaned,
1955 gboolean resize, gboolean shrink)
1957 g_return_if_fail (GTK_IS_XPANED (xpaned));
1958 g_return_if_fail (GTK_IS_WIDGET (child));
1960 if (!xpaned->bottom_right_child)
1962 xpaned->bottom_right_child = child;
1963 xpaned->bottom_right_child_resize = resize;
1964 xpaned->bottom_right_child_shrink = shrink;
1966 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1971 gtk_xpaned_add (GtkContainer * container, GtkWidget * widget)
1975 g_return_if_fail (GTK_IS_XPANED (container));
1977 xpaned = GTK_XPANED (container);
1979 if (!xpaned->top_left_child)
1980 gtk_xpaned_add_top_left (xpaned, widget);
1981 else if (!xpaned->top_right_child)
1982 gtk_xpaned_add_top_right (xpaned, widget);
1983 else if (!xpaned->bottom_left_child)
1984 gtk_xpaned_add_bottom_left (xpaned, widget);
1985 else if (!xpaned->bottom_right_child)
1986 gtk_xpaned_add_bottom_right (xpaned, widget);
1988 g_warning ("GtkXPaned cannot have more than 4 children\n");
1992 gtk_xpaned_remove (GtkContainer * container, GtkWidget * widget)
1995 gboolean was_visible;
1997 xpaned = GTK_XPANED (container);
1998 was_visible = gtk_widget_get_visible (widget);
2000 if (xpaned->top_left_child == widget)
2002 gtk_widget_unparent (widget);
2004 xpaned->top_left_child = NULL;
2006 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2007 gtk_widget_queue_resize (GTK_WIDGET (container));
2009 else if (xpaned->top_right_child == widget)
2011 gtk_widget_unparent (widget);
2013 xpaned->top_right_child = NULL;
2015 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2016 gtk_widget_queue_resize (GTK_WIDGET (container));
2018 else if (xpaned->bottom_left_child == widget)
2020 gtk_widget_unparent (widget);
2022 xpaned->bottom_left_child = NULL;
2024 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2025 gtk_widget_queue_resize (GTK_WIDGET (container));
2027 else if (xpaned->bottom_right_child == widget)
2029 gtk_widget_unparent (widget);
2031 xpaned->bottom_right_child = NULL;
2033 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2034 gtk_widget_queue_resize (GTK_WIDGET (container));
2037 g_warning ("GtkXPaned has no more children attached\n");
2042 gtk_xpaned_forall (GtkContainer * container,
2043 gboolean include_internals,
2044 GtkCallback callback, gpointer callback_data)
2048 g_return_if_fail (callback != NULL);
2050 xpaned = GTK_XPANED (container);
2052 if (xpaned->top_left_child)
2053 (*callback) (xpaned->top_left_child, callback_data);
2054 if (xpaned->top_right_child)
2055 (*callback) (xpaned->top_right_child, callback_data);
2056 if (xpaned->bottom_left_child)
2057 (*callback) (xpaned->bottom_left_child, callback_data);
2058 if (xpaned->bottom_right_child)
2059 (*callback) (xpaned->bottom_right_child, callback_data);
2063 * gtk_xpaned_get_position_x:
2064 * @paned: a #GtkXPaned widget
2066 * Obtains the x-position of the divider.
2068 * Return value: x-position of the divider
2071 gtk_xpaned_get_position_x (GtkXPaned * xpaned)
2073 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2075 return xpaned->top_left_child_size.width;
2079 * gtk_xpaned_get_position_y:
2080 * @paned: a #GtkXPaned widget
2082 * Obtains the y-position of the divider.
2084 * Return value: y-position of the divider
2087 gtk_xpaned_get_position_y (GtkXPaned * xpaned)
2089 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2091 return xpaned->top_left_child_size.height;
2095 * gtk_xpaned_set_position_x:
2096 * @paned: a #GtkXPaned widget
2097 * @xposition: pixel x-position of divider, a negative values
2098 * of a component mean that the position is unset.
2100 * Sets the x-position of the divider between the four panes.
2103 gtk_xpaned_set_position_x (GtkXPaned * xpaned, gint xposition)
2107 g_return_if_fail (GTK_IS_XPANED (xpaned));
2109 /* if any child is currently maximized, jump right back */
2110 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2111 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2112 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2113 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2116 object = G_OBJECT (xpaned);
2120 /* We don't clamp here - the assumption is that
2121 * if the total allocation changes at the same time
2122 * as the position, the position set is with reference
2123 * to the new total size. If only the position changes,
2124 * then clamping will occur in gtk_paned_compute_position()
2127 xpaned->top_left_child_size.width = xposition;
2128 xpaned->position_set = TRUE;
2132 xpaned->position_set = FALSE;
2135 g_object_freeze_notify (object);
2136 g_object_notify (object, "x-position");
2137 g_object_notify (object, "position-set");
2138 g_object_thaw_notify (object);
2140 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2144 * gtk_xpaned_set_position_y:
2145 * @paned: a #GtkXPaned widget
2146 * @yposition: pixel y-position of divider, a negative values
2147 * of a component mean that the position is unset.
2149 * Sets the y-position of the divider between the four panes.
2152 gtk_xpaned_set_position_y (GtkXPaned * xpaned, gint yposition)
2156 g_return_if_fail (GTK_IS_XPANED (xpaned));
2158 /* if any child is currently maximized, jump right back */
2159 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2160 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2161 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2162 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2165 object = G_OBJECT (xpaned);
2169 /* We don't clamp here - the assumption is that
2170 * if the total allocation changes at the same time
2171 * as the position, the position set is with reference
2172 * to the new total size. If only the position changes,
2173 * then clamping will occur in gtk_paned_compute_position()
2176 xpaned->top_left_child_size.height = yposition;
2177 xpaned->position_set = TRUE;
2181 xpaned->position_set = FALSE;
2184 g_object_freeze_notify (object);
2185 g_object_notify (object, "y-position");
2186 g_object_notify (object, "position-set");
2187 g_object_thaw_notify (object);
2189 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2192 /* this call is private and only intended for internal use! */
2194 gtk_xpaned_save_unmaximized_x (GtkXPaned * xpaned)
2196 xpaned->unmaximized_position.x = gtk_xpaned_get_position_x (xpaned);
2199 /* this call is private and only intended for internal use! */
2201 gtk_xpaned_save_unmaximized_y (GtkXPaned * xpaned)
2203 xpaned->unmaximized_position.y = gtk_xpaned_get_position_y (xpaned);
2206 /* this call is private and only intended for internal use! */
2208 gtk_xpaned_fetch_unmaximized_x (GtkXPaned * xpaned)
2210 return xpaned->unmaximized_position.x;
2213 /* this call is private and only intended for internal use! */
2215 gtk_xpaned_fetch_unmaximized_y (GtkXPaned * xpaned)
2217 return xpaned->unmaximized_position.y;
2221 * gtk_xpaned_get_top_left_child:
2222 * @xpaned: a #GtkXPaned widget
2224 * Obtains the top-left child of the xpaned widget.
2226 * Return value: top-left child, or %NULL if it is not set.
2231 gtk_xpaned_get_top_left_child (GtkXPaned * xpaned)
2233 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2235 return xpaned->top_left_child;
2239 * gtk_xpaned_get_top_right_child:
2240 * @xpaned: a #GtkXPaned widget
2242 * Obtains the top-right child of the xpaned widget.
2244 * Return value: top-right child, or %NULL if it is not set.
2249 gtk_xpaned_get_top_right_child (GtkXPaned * xpaned)
2251 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2253 return xpaned->top_right_child;
2257 * gtk_xpaned_get_bottom_left_child:
2258 * @xpaned: a #GtkXPaned widget
2260 * Obtains the bottom-left child of the xpaned widget.
2262 * Return value: bottom-left child, or %NULL if it is not set.
2267 gtk_xpaned_get_bottom_left_child (GtkXPaned * xpaned)
2269 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2271 return xpaned->bottom_left_child;
2275 * gtk_xpaned_get_bottom_right_child:
2276 * @xpaned: a #GtkXPaned widget
2278 * Obtains the bottom-right child of the xpaned widget.
2280 * Return value: bottom-right child, or %NULL if it is not set.
2285 gtk_xpaned_get_bottom_right_child (GtkXPaned * xpaned)
2287 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2289 return xpaned->bottom_right_child;
2293 gtk_xpaned_maximize_top_left (GtkXPaned * xpaned, gboolean maximize)
2297 /* see if any child is already maximized */
2298 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2299 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2300 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2301 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2303 /* save current position */
2304 gtk_xpaned_save_unmaximized_x (xpaned);
2305 gtk_xpaned_save_unmaximized_y (xpaned);
2307 /* set new maximized position */
2308 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2309 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2311 /* mark maximized flag for top-left child */
2312 xpaned->maximized[GTK_XPANED_TOP_LEFT] = TRUE;
2316 /* already one child maximized, report error */
2322 /* verify that top-left child is really currently maximized */
2323 if (xpaned->maximized[GTK_XPANED_TOP_LEFT])
2325 /* clear maximized flat for top-left child */
2326 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
2328 /* restore unmaximized position */
2329 gtk_xpaned_set_position_x (xpaned,
2330 gtk_xpaned_fetch_unmaximized_x (xpaned));
2331 gtk_xpaned_set_position_y (xpaned,
2332 gtk_xpaned_fetch_unmaximized_y (xpaned));
2336 /* top-left child is currently not maximized, report error */
2343 gtk_xpaned_maximize_top_right (GtkXPaned * xpaned, gboolean maximize)
2347 /* see if any child is already maximized */
2348 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2349 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2350 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2351 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2353 /* save current position */
2354 gtk_xpaned_save_unmaximized_x (xpaned);
2355 gtk_xpaned_save_unmaximized_y (xpaned);
2357 /* set new maximized position */
2358 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2359 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2361 /* mark maximized flag for top-right child */
2362 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = TRUE;
2366 /* already one child maximized, report error */
2372 /* verify that top-right child is really currently maximized */
2373 if (xpaned->maximized[GTK_XPANED_TOP_RIGHT])
2375 /* clear maximized flat for top-right child */
2376 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
2378 /* restore unmaximized position */
2379 gtk_xpaned_set_position_x (xpaned,
2380 gtk_xpaned_fetch_unmaximized_x (xpaned));
2381 gtk_xpaned_set_position_y (xpaned,
2382 gtk_xpaned_fetch_unmaximized_y (xpaned));
2386 /* top-right child is currently not maximized, report error */
2393 gtk_xpaned_maximize_bottom_left (GtkXPaned * xpaned, gboolean maximize)
2397 /* see if any child is already maximized */
2398 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2399 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2400 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2401 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2403 /* save current position */
2404 gtk_xpaned_save_unmaximized_x (xpaned);
2405 gtk_xpaned_save_unmaximized_y (xpaned);
2407 /* set new maximized position */
2408 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2409 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2411 /* mark maximized flag for bottom-left child */
2412 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = TRUE;
2416 /* already one child maximized, report error */
2422 /* verify that bottom-left child is really currently maximized */
2423 if (xpaned->maximized[GTK_XPANED_BOTTOM_LEFT])
2425 /* clear maximized flat for bottom-left child */
2426 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
2428 /* restore unmaximized position */
2429 gtk_xpaned_set_position_x (xpaned,
2430 gtk_xpaned_fetch_unmaximized_x (xpaned));
2431 gtk_xpaned_set_position_y (xpaned,
2432 gtk_xpaned_fetch_unmaximized_y (xpaned));
2436 /* bottom-left child is currently not maximized, report error */
2443 gtk_xpaned_maximize_bottom_right (GtkXPaned * xpaned, gboolean maximize)
2447 /* see if any child is already maximized */
2448 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2449 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2450 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2451 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2453 /* save current position */
2454 gtk_xpaned_save_unmaximized_x (xpaned);
2455 gtk_xpaned_save_unmaximized_y (xpaned);
2457 /* set new maximized position */
2458 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2459 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2461 /* mark maximized flag for bottom-right child */
2462 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = TRUE;
2466 /* already one child maximized, report error */
2472 /* verify that bottom-right child is really currently maximized */
2473 if (xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2475 /* clear maximized flat for bottom-right child */
2476 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
2478 /* restore unmaximized position */
2479 gtk_xpaned_set_position_x (xpaned,
2480 gtk_xpaned_fetch_unmaximized_x (xpaned));
2481 gtk_xpaned_set_position_y (xpaned,
2482 gtk_xpaned_fetch_unmaximized_y (xpaned));
2486 /* bottom-right child is currently not maximized, report error */
2493 gtk_xpaned_compute_position (GtkXPaned * xpaned,
2494 const GtkAllocation * allocation,
2495 GtkRequisition * top_left_child_req,
2496 GtkRequisition * top_right_child_req,
2497 GtkRequisition * bottom_left_child_req,
2498 GtkRequisition * bottom_right_child_req)
2500 GdkPoint old_position;
2501 GdkPoint old_min_position;
2502 GdkPoint old_max_position;
2504 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (xpaned));
2506 g_return_if_fail (GTK_IS_XPANED (xpaned));
2508 old_position.x = xpaned->top_left_child_size.width;
2509 old_position.y = xpaned->top_left_child_size.height;
2510 old_min_position.x = xpaned->min_position.x;
2511 old_min_position.y = xpaned->min_position.y;
2512 old_max_position.x = xpaned->max_position.x;
2513 old_max_position.y = xpaned->max_position.y;
2515 xpaned->min_position.x =
2516 xpaned->top_left_child_shrink ? 0 : top_left_child_req->width;
2517 xpaned->min_position.y =
2518 xpaned->top_left_child_shrink ? 0 : top_left_child_req->height;
2520 gtk_widget_style_get (GTK_WIDGET (xpaned), "handle-size", &handle_size,
2523 xpaned->max_position.x = allocation->width - 2 * border_width - handle_size;
2524 xpaned->max_position.y =
2525 allocation->height - 2 * border_width - handle_size;
2526 if (!xpaned->top_left_child_shrink)
2527 xpaned->max_position.x =
2528 MAX (1, xpaned->max_position.x - top_left_child_req->width);
2529 xpaned->max_position.x =
2530 MAX (xpaned->min_position.x, xpaned->max_position.x);
2532 if (!xpaned->position_set)
2534 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2536 xpaned->top_left_child_size.width =
2537 MAX (0, allocation->width - top_right_child_req->width);
2538 xpaned->top_left_child_size.height =
2539 MAX (0, allocation->height - top_right_child_req->height);
2541 else if (!xpaned->top_left_child_resize
2542 && xpaned->top_right_child_resize)
2544 xpaned->top_left_child_size.width = top_left_child_req->width;
2545 xpaned->top_left_child_size.height = top_left_child_req->height;
2549 xpaned->top_left_child_size.width = allocation->width * 0.5 + 0.5;
2550 xpaned->top_left_child_size.height = allocation->height * 0.5 + 0.5;
2555 /* If the position was set before the initial allocation.
2556 ** (paned->last_allocation <= 0) just clamp it and leave it. */
2557 if (xpaned->last_allocation.width > 0)
2559 if (xpaned->top_left_child_resize
2560 && !xpaned->top_right_child_resize)
2562 xpaned->top_left_child_size.width += allocation->width
2563 - xpaned->last_allocation.width;
2565 xpaned->top_left_child_size.height += allocation->height
2566 - xpaned->last_allocation.height;
2570 (!xpaned->top_left_child_resize
2571 && xpaned->top_right_child_resize))
2573 xpaned->top_left_child_size.width = allocation->width
2574 * ((gdouble) xpaned->top_left_child_size.width /
2575 (xpaned->last_allocation.width)) + 0.5;
2577 xpaned->top_left_child_size.height = allocation->height
2578 * ((gdouble) xpaned->top_left_child_size.height /
2579 (xpaned->last_allocation.height)) + 0.5;
2582 if (xpaned->last_allocation.height > 0)
2584 if (xpaned->top_left_child_resize
2585 && !xpaned->top_right_child_resize)
2587 xpaned->top_left_child_size.width +=
2588 allocation->width - xpaned->last_allocation.width;
2589 xpaned->top_left_child_size.height +=
2590 allocation->height - xpaned->last_allocation.height;
2594 (!xpaned->top_left_child_resize
2595 && xpaned->top_right_child_resize))
2597 xpaned->top_left_child_size.width =
2599 ((gdouble) xpaned->top_left_child_size.width /
2600 (xpaned->last_allocation.width)) + 0.5;
2601 xpaned->top_left_child_size.height =
2602 allocation->height *
2603 ((gdouble) xpaned->top_left_child_size.height /
2604 (xpaned->last_allocation.height)) + 0.5;
2610 xpaned->top_left_child_size.width =
2611 CLAMP (xpaned->top_left_child_size.width, xpaned->min_position.x,
2612 xpaned->max_position.x);
2613 xpaned->top_left_child_size.height =
2614 CLAMP (xpaned->top_left_child_size.height, xpaned->min_position.y,
2615 xpaned->max_position.y);
2617 xpaned->top_right_child_size.width =
2618 CLAMP (xpaned->top_right_child_size.width, xpaned->min_position.x,
2619 xpaned->max_position.x);
2620 xpaned->top_right_child_size.height =
2621 CLAMP (xpaned->top_right_child_size.height, xpaned->min_position.y,
2622 xpaned->max_position.y);
2624 xpaned->bottom_left_child_size.width =
2625 CLAMP (xpaned->bottom_left_child_size.width, xpaned->min_position.x,
2626 xpaned->max_position.x);
2627 xpaned->bottom_left_child_size.height =
2628 CLAMP (xpaned->bottom_left_child_size.height, xpaned->min_position.y,
2629 xpaned->max_position.y);
2631 xpaned->bottom_right_child_size.width =
2632 CLAMP (xpaned->bottom_right_child_size.width, xpaned->min_position.x,
2633 xpaned->max_position.x);
2634 xpaned->bottom_right_child_size.height =
2635 CLAMP (xpaned->bottom_right_child_size.height, xpaned->min_position.y,
2636 xpaned->max_position.y);
2638 gtk_widget_set_child_visible (xpaned->top_left_child, TRUE);
2639 gtk_widget_set_child_visible (xpaned->top_right_child, TRUE);
2640 gtk_widget_set_child_visible (xpaned->bottom_left_child, TRUE);
2641 gtk_widget_set_child_visible (xpaned->bottom_right_child, TRUE);
2643 g_object_freeze_notify (G_OBJECT (xpaned));
2645 if (xpaned->top_left_child_size.width != old_position.x)
2646 g_object_notify (G_OBJECT (xpaned), "x-position");
2647 if (xpaned->top_left_child_size.height != old_position.y)
2648 g_object_notify (G_OBJECT (xpaned), "y-position");
2650 if (xpaned->top_right_child_size.width != old_position.x)
2651 g_object_notify (G_OBJECT (xpaned), "x-position");
2652 if (xpaned->top_right_child_size.height != old_position.y)
2653 g_object_notify (G_OBJECT (xpaned), "y-position");
2655 if (xpaned->bottom_left_child_size.width != old_position.x)
2656 g_object_notify (G_OBJECT (xpaned), "x-position");
2657 if (xpaned->bottom_left_child_size.height != old_position.y)
2658 g_object_notify (G_OBJECT (xpaned), "y-position");
2660 if (xpaned->bottom_right_child_size.width != old_position.x)
2661 g_object_notify (G_OBJECT (xpaned), "x-position");
2662 if (xpaned->bottom_right_child_size.height != old_position.y)
2663 g_object_notify (G_OBJECT (xpaned), "y-position");
2665 if (xpaned->min_position.x != old_min_position.x)
2666 g_object_notify (G_OBJECT (xpaned), "min-x-position");
2667 if (xpaned->min_position.y != old_min_position.y)
2668 g_object_notify (G_OBJECT (xpaned), "min-y-position");
2670 if (xpaned->max_position.x != old_max_position.x)
2671 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2672 if (xpaned->max_position.y != old_max_position.y)
2673 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2675 g_object_thaw_notify (G_OBJECT (xpaned));
2677 xpaned->last_allocation.width = allocation->width;
2678 xpaned->last_allocation.height = allocation->height;
2682 gtk_xpaned_set_saved_focus (GtkXPaned * xpaned, GtkWidget * widget)
2684 if (xpaned->priv->saved_focus)
2685 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2686 (gpointer *) & (xpaned->priv->saved_focus));
2688 xpaned->priv->saved_focus = widget;
2690 if (xpaned->priv->saved_focus)
2691 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2692 (gpointer *) & (xpaned->priv->saved_focus));
2696 gtk_xpaned_set_first_xpaned (GtkXPaned * xpaned, GtkXPaned * first_xpaned)
2698 if (xpaned->priv->first_xpaned)
2699 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2700 (gpointer *) & (xpaned->priv->
2703 xpaned->priv->first_xpaned = first_xpaned;
2705 if (xpaned->priv->first_xpaned)
2706 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2707 (gpointer *) & (xpaned->priv->first_xpaned));
2711 gtk_xpaned_set_last_top_left_child_focus (GtkXPaned * xpaned,
2714 if (xpaned->last_top_left_child_focus)
2715 g_object_remove_weak_pointer (G_OBJECT
2716 (xpaned->last_top_left_child_focus),
2717 (gpointer *) & (xpaned->
2718 last_top_left_child_focus));
2720 xpaned->last_top_left_child_focus = widget;
2722 if (xpaned->last_top_left_child_focus)
2723 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2724 (gpointer *) & (xpaned->
2725 last_top_left_child_focus));
2729 gtk_xpaned_set_last_top_right_child_focus (GtkXPaned * xpaned,
2732 if (xpaned->last_top_right_child_focus)
2733 g_object_remove_weak_pointer (G_OBJECT
2734 (xpaned->last_top_right_child_focus),
2735 (gpointer *) & (xpaned->
2736 last_top_right_child_focus));
2738 xpaned->last_top_right_child_focus = widget;
2740 if (xpaned->last_top_right_child_focus)
2741 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2742 (gpointer *) & (xpaned->
2743 last_top_right_child_focus));
2747 gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned * xpaned,
2750 if (xpaned->last_bottom_left_child_focus)
2751 g_object_remove_weak_pointer (G_OBJECT
2752 (xpaned->last_bottom_left_child_focus),
2753 (gpointer *) & (xpaned->
2754 last_bottom_left_child_focus));
2756 xpaned->last_bottom_left_child_focus = widget;
2758 if (xpaned->last_bottom_left_child_focus)
2759 g_object_add_weak_pointer (G_OBJECT
2760 (xpaned->last_bottom_left_child_focus),
2761 (gpointer *) & (xpaned->
2762 last_bottom_left_child_focus));
2766 gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned * xpaned,
2769 if (xpaned->last_bottom_right_child_focus)
2770 g_object_remove_weak_pointer (G_OBJECT
2771 (xpaned->last_bottom_right_child_focus),
2772 (gpointer *) & (xpaned->
2773 last_bottom_right_child_focus));
2775 xpaned->last_bottom_right_child_focus = widget;
2777 if (xpaned->last_bottom_right_child_focus)
2778 g_object_add_weak_pointer (G_OBJECT
2779 (xpaned->last_bottom_right_child_focus),
2780 (gpointer *) & (xpaned->
2781 last_bottom_right_child_focus));
2785 xpaned_get_focus_widget (GtkXPaned * xpaned)
2787 GtkWidget *toplevel;
2789 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
2790 if (gtk_widget_is_toplevel (toplevel))
2791 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2797 gtk_xpaned_set_focus_child (GtkContainer * container, GtkWidget * focus_child)
2801 g_return_if_fail (GTK_IS_XPANED (container));
2803 xpaned = GTK_XPANED (container);
2805 if (focus_child == NULL)
2807 GtkWidget *last_focus;
2810 last_focus = xpaned_get_focus_widget (xpaned);
2814 /* If there is one or more paned widgets between us and the
2815 * focus widget, we want the topmost of those as last_focus
2817 for (w = last_focus; w != GTK_WIDGET (xpaned); w = gtk_widget_get_parent (w))
2818 if (GTK_IS_XPANED (w))
2821 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2822 gtk_xpaned_set_last_top_left_child_focus (xpaned, last_focus);
2823 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2824 gtk_xpaned_set_last_top_right_child_focus (xpaned, last_focus);
2825 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2826 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, last_focus);
2827 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2828 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, last_focus);
2832 if (parent_class->set_focus_child)
2833 (*parent_class->set_focus_child) (container, focus_child);
2837 gtk_xpaned_get_cycle_chain (GtkXPaned * xpaned,
2838 GtkDirectionType direction, GList ** widgets)
2840 GtkContainer *container = GTK_CONTAINER (xpaned);
2841 GtkWidget *ancestor = NULL;
2842 GList *temp_list = NULL;
2845 if (xpaned->in_recursion)
2848 g_assert (widgets != NULL);
2850 if (xpaned->last_top_left_child_focus &&
2851 !gtk_widget_is_ancestor (xpaned->last_top_left_child_focus,
2852 GTK_WIDGET (xpaned)))
2854 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
2857 if (xpaned->last_top_right_child_focus &&
2858 !gtk_widget_is_ancestor (xpaned->last_top_right_child_focus,
2859 GTK_WIDGET (xpaned)))
2861 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
2864 if (xpaned->last_bottom_left_child_focus &&
2865 !gtk_widget_is_ancestor (xpaned->last_bottom_left_child_focus,
2866 GTK_WIDGET (xpaned)))
2868 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
2871 if (xpaned->last_bottom_right_child_focus &&
2872 !gtk_widget_is_ancestor (xpaned->last_bottom_right_child_focus,
2873 GTK_WIDGET (xpaned)))
2875 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
2878 if (gtk_widget_get_parent (GTK_WIDGET (xpaned)))
2879 ancestor = gtk_widget_get_ancestor (gtk_widget_get_parent (GTK_WIDGET (xpaned)),
2882 /* The idea here is that temp_list is a list of widgets we want to cycle
2883 * to. The list is prioritized so that the first element is our first
2884 * choice, the next our second, and so on.
2886 * We can't just use g_list_reverse(), because we want to try
2887 * paned->last_child?_focus before paned->child?, both when we
2888 * are going forward and backward.
2890 if (direction == GTK_DIR_TAB_FORWARD)
2892 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2895 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2896 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2897 temp_list = g_list_append (temp_list, ancestor);
2899 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2901 temp_list = g_list_append (temp_list, ancestor);
2903 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2904 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2906 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2908 temp_list = g_list_append (temp_list, ancestor);
2910 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2911 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2913 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2915 temp_list = g_list_append (temp_list, ancestor);
2917 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2918 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2923 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2924 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2926 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2927 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2929 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2930 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2932 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2933 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2934 temp_list = g_list_append (temp_list, ancestor);
2939 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2941 temp_list = g_list_append (temp_list, ancestor);
2943 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2944 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2946 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2949 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2950 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2951 temp_list = g_list_append (temp_list, ancestor);
2953 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2956 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2957 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2958 temp_list = g_list_append (temp_list, ancestor);
2960 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2963 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2964 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2965 temp_list = g_list_append (temp_list, ancestor);
2970 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2971 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2973 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2974 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2976 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2977 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2979 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2980 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2981 temp_list = g_list_append (temp_list, ancestor);
2985 /* Walk the list and expand all the paned widgets. */
2986 for (list = temp_list; list != NULL; list = list->next)
2988 GtkWidget *widget = list->data;
2992 if (GTK_IS_XPANED (widget))
2994 xpaned->in_recursion = TRUE;
2995 gtk_xpaned_get_cycle_chain (GTK_XPANED (widget),
2996 direction, widgets);
2997 xpaned->in_recursion = FALSE;
3001 *widgets = g_list_append (*widgets, widget);
3006 g_list_free (temp_list);
3010 gtk_xpaned_cycle_child_focus (GtkXPaned * xpaned, gboolean reversed)
3012 GList *cycle_chain = NULL;
3015 GtkDirectionType direction =
3016 reversed ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
3018 /* ignore f6 if the handle is focused */
3019 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3022 /* we can't just let the event propagate up the hierarchy,
3023 * because the paned will want to cycle focus _unless_ an
3024 * ancestor paned handles the event
3026 gtk_xpaned_get_cycle_chain (xpaned, direction, &cycle_chain);
3028 for (list = cycle_chain; list != NULL; list = list->next)
3029 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
3032 g_list_free (cycle_chain);
3038 get_child_xpanes (GtkWidget * widget, GList ** xpanes)
3040 if (GTK_IS_XPANED (widget))
3042 GtkXPaned *xpaned = GTK_XPANED (widget);
3044 get_child_xpanes (xpaned->top_left_child, xpanes);
3045 *xpanes = g_list_prepend (*xpanes, widget);
3046 get_child_xpanes (xpaned->top_right_child, xpanes);
3047 *xpanes = g_list_prepend (*xpanes, widget);
3048 get_child_xpanes (xpaned->bottom_left_child, xpanes);
3049 *xpanes = g_list_prepend (*xpanes, widget);
3050 get_child_xpanes (xpaned->bottom_right_child, xpanes);
3052 else if (GTK_IS_CONTAINER (widget))
3054 gtk_container_foreach (GTK_CONTAINER (widget),
3055 (GtkCallback) get_child_xpanes, xpanes);
3060 get_all_xpanes (GtkXPaned * xpaned)
3062 GtkXPaned *topmost = NULL;
3063 GList *result = NULL;
3066 for (w = GTK_WIDGET (xpaned); w != NULL; w = gtk_widget_get_parent (w))
3068 if (GTK_IS_XPANED (w))
3069 topmost = GTK_XPANED (w);
3074 get_child_xpanes (GTK_WIDGET (topmost), &result);
3076 return g_list_reverse (result);
3080 gtk_xpaned_find_neighbours (GtkXPaned * xpaned,
3081 GtkXPaned ** next, GtkXPaned ** prev)
3086 all_xpanes = get_all_xpanes (xpaned);
3087 g_assert (all_xpanes);
3089 this_link = g_list_find (all_xpanes, xpaned);
3091 g_assert (this_link);
3093 if (this_link->next)
3094 *next = this_link->next->data;
3096 *next = all_xpanes->data;
3098 if (this_link->prev)
3099 *prev = this_link->prev->data;
3101 *prev = g_list_last (all_xpanes)->data;
3103 g_list_free (all_xpanes);
3107 gtk_xpaned_move_handle (GtkXPaned * xpaned, GtkScrollType scroll)
3109 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3111 GdkPoint old_position;
3112 GdkPoint new_position;
3117 SINGLE_STEP_SIZE = 1,
3121 new_position.x = old_position.x = gtk_xpaned_get_position_x (xpaned);
3122 new_position.y = old_position.y = gtk_xpaned_get_position_y (xpaned);
3127 case GTK_SCROLL_STEP_LEFT:
3128 case GTK_SCROLL_STEP_UP:
3129 case GTK_SCROLL_STEP_BACKWARD:
3130 increment = -SINGLE_STEP_SIZE;
3133 case GTK_SCROLL_STEP_RIGHT:
3134 case GTK_SCROLL_STEP_DOWN:
3135 case GTK_SCROLL_STEP_FORWARD:
3136 increment = SINGLE_STEP_SIZE;
3139 case GTK_SCROLL_PAGE_LEFT:
3140 case GTK_SCROLL_PAGE_UP:
3141 case GTK_SCROLL_PAGE_BACKWARD:
3142 increment = -PAGE_STEP_SIZE;
3145 case GTK_SCROLL_PAGE_RIGHT:
3146 case GTK_SCROLL_PAGE_DOWN:
3147 case GTK_SCROLL_PAGE_FORWARD:
3148 increment = PAGE_STEP_SIZE;
3151 case GTK_SCROLL_START:
3152 new_position.x = xpaned->min_position.x;
3153 new_position.y = xpaned->min_position.y;
3156 case GTK_SCROLL_END:
3157 new_position.x = xpaned->max_position.x;
3158 new_position.y = xpaned->max_position.y;
3167 if (is_rtl (xpaned))
3168 increment = -increment;
3170 new_position.x = old_position.x + increment;
3171 new_position.y = old_position.y + increment;
3174 new_position.x = CLAMP (new_position.x,
3175 xpaned->min_position.x, xpaned->max_position.x);
3177 new_position.y = CLAMP (new_position.y,
3178 xpaned->min_position.y, xpaned->max_position.y);
3180 if (old_position.x != new_position.x)
3181 gtk_xpaned_set_position_x (xpaned, new_position.x);
3183 if (old_position.y != new_position.y)
3184 gtk_xpaned_set_position_y (xpaned, new_position.y);
3193 gtk_xpaned_restore_focus (GtkXPaned * xpaned)
3195 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3197 if (xpaned->priv->saved_focus &&
3198 gtk_widget_get_sensitive (xpaned->priv->saved_focus))
3200 gtk_widget_grab_focus (xpaned->priv->saved_focus);
3204 /* the saved focus is somehow not available for focusing,
3206 * 1) tabbing into the paned widget
3207 * if that didn't work,
3208 * 2) unset focus for the window if there is one
3211 if (!gtk_widget_child_focus
3212 (GTK_WIDGET (xpaned), GTK_DIR_TAB_FORWARD))
3214 GtkWidget *toplevel =
3215 gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3217 if (GTK_IS_WINDOW (toplevel))
3218 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
3222 gtk_xpaned_set_saved_focus (xpaned, NULL);
3223 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3228 gtk_xpaned_accept_position (GtkXPaned * xpaned)
3230 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3232 xpaned->original_position.x = -1;
3233 xpaned->original_position.y = -1;
3234 gtk_xpaned_restore_focus (xpaned);
3243 gtk_xpaned_cancel_position (GtkXPaned * xpaned)
3245 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3247 if (xpaned->original_position.x != -1)
3249 gtk_xpaned_set_position_x (xpaned, xpaned->original_position.x);
3250 xpaned->original_position.x = -1;
3253 if (xpaned->original_position.y != -1)
3255 gtk_xpaned_set_position_y (xpaned, xpaned->original_position.y);
3256 xpaned->original_position.y = -1;
3259 gtk_xpaned_restore_focus (xpaned);
3267 gtk_xpaned_cycle_handle_focus (GtkXPaned * xpaned, gboolean reversed)
3272 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3274 GtkXPaned *focus = NULL;
3276 if (!xpaned->priv->first_xpaned)
3278 /* The first_pane has disappeared. As an ad-hoc solution,
3279 * we make the currently focused paned the first_paned. To the
3280 * user this will seem like the paned cycling has been reset.
3282 gtk_xpaned_set_first_xpaned (xpaned, xpaned);
3285 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3287 if (reversed && prev &&
3288 prev != xpaned && xpaned != xpaned->priv->first_xpaned)
3292 else if (!reversed &&
3293 next && next != xpaned && next != xpaned->priv->first_xpaned)
3299 gtk_xpaned_accept_position (xpaned);
3305 gtk_xpaned_set_saved_focus (focus, xpaned->priv->saved_focus);
3306 gtk_xpaned_set_first_xpaned (focus, xpaned->priv->first_xpaned);
3308 gtk_xpaned_set_saved_focus (xpaned, NULL);
3309 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3311 gtk_widget_grab_focus (GTK_WIDGET (focus));
3313 if (!gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3315 xpaned->original_position.x = -1;
3316 xpaned->original_position.y = -1;
3317 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3318 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3323 GtkContainer *container = GTK_CONTAINER (xpaned);
3328 GtkWidget *toplevel;
3330 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3332 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
3345 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
3360 /* Focus is not inside this xpaned, and we don't have focus.
3361 * Presumably this happened because the application wants us
3362 * to start keyboard navigating.
3372 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3374 if (GTK_IS_WINDOW (toplevel))
3375 gtk_xpaned_set_saved_focus (focus,
3376 gtk_window_get_focus (GTK_WINDOW (toplevel)));
3377 gtk_xpaned_set_first_xpaned (focus, first);
3378 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3379 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3381 gtk_widget_grab_focus (GTK_WIDGET (focus));
3388 gtk_xpaned_toggle_handle_focus (GtkXPaned * xpaned)
3390 /* This function/signal has the wrong name. It is called when you
3391 * press Tab or Shift-Tab and what we do is act as if
3392 * the user pressed Return and then Tab or Shift-Tab
3394 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3395 gtk_xpaned_accept_position (xpaned);
3400 /*#define __GTK_XPANED_C__*/
3401 /*#include "gtkaliasdef.c"*/