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 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);
1399 GdkRectangle horizontalClipArea;
1400 GdkRectangle verticalClipArea;
1402 /* determine size of handle(s) */
1403 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1405 /* I want the handle-"thickness" to be at least 3 */
1406 g_assert (handle_size >= 3);
1408 if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
1409 xpaned->top_left_child
1410 && gtk_widget_get_visible (xpaned->top_left_child)
1411 && xpaned->top_right_child
1412 && gtk_widget_get_visible (xpaned->top_right_child)
1413 && xpaned->bottom_left_child
1414 && gtk_widget_get_visible (xpaned->bottom_left_child)
1415 && xpaned->bottom_right_child
1416 && gtk_widget_get_visible (xpaned->bottom_right_child))
1420 if (gtk_widget_is_focus (widget))
1421 state = GTK_STATE_SELECTED;
1422 else if (xpaned->handle_prelit)
1423 state = GTK_STATE_PRELIGHT;
1425 state = gtk_widget_get_state (widget);
1427 horizontalClipArea.x = xpaned->handle_pos_west.x;
1428 horizontalClipArea.y = xpaned->handle_pos_west.y;
1429 horizontalClipArea.width =
1430 xpaned->handle_pos_west.width + handle_size +
1431 xpaned->handle_pos_east.width;
1432 horizontalClipArea.height = handle_size;
1434 verticalClipArea.x = xpaned->handle_pos_north.x;
1435 verticalClipArea.y = xpaned->handle_pos_north.y;
1436 verticalClipArea.width = handle_size;
1437 verticalClipArea.height =
1438 xpaned->handle_pos_north.height + handle_size +
1439 xpaned->handle_pos_south.height;
1441 gtk_paint_handle (gtk_widget_get_style (widget),
1447 xpaned->handle_pos_east.x - handle_size - 256 / 2,
1448 xpaned->handle_pos_west.y + 1,
1449 256 + handle_size, handle_size - 2,
1450 /*xpaned->handle_pos_west.x,
1451 xpaned->handle_pos_west.y + 1,
1452 xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width,
1454 GTK_ORIENTATION_HORIZONTAL);
1456 gtk_paint_handle (gtk_widget_get_style (widget),
1462 xpaned->handle_pos_north.x + 1,
1463 xpaned->handle_pos_south.y - handle_size - 256 / 2,
1464 handle_size - 2, 256 + handle_size,
1465 /*xpaned->handle_pos_north.x + 1,
1466 xpaned->handle_pos_north.y,
1468 xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height, */
1469 GTK_ORIENTATION_VERTICAL);
1472 /* Chain up to draw children */
1473 GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
1479 is_rtl (GtkXPaned * xpaned)
1481 if (gtk_widget_get_direction (GTK_WIDGET (xpaned)) == GTK_TEXT_DIR_RTL)
1488 update_drag (GtkXPaned * xpaned)
1492 GtkRequisition size;
1493 GtkAllocation allocation;
1494 gtk_widget_get_allocation (GTK_WIDGET (xpaned), &allocation);
1496 gtk_widget_get_pointer (GTK_WIDGET (xpaned), &pos.x, &pos.y);
1498 if (xpaned->in_drag_vert)
1500 pos.y -= xpaned->drag_pos.y;
1502 if (is_rtl (xpaned))
1504 gtk_widget_style_get (GTK_WIDGET (xpaned),
1505 "handle-size", &handle_size, NULL);
1507 size.height = allocation.height - pos.y - handle_size;
1511 size.height = pos.y;
1514 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1517 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1519 if (size.height != xpaned->top_left_child_size.height)
1520 gtk_xpaned_set_position_y (xpaned, size.height);
1523 if (xpaned->in_drag_horiz)
1525 pos.x -= xpaned->drag_pos.x;
1527 if (is_rtl (xpaned))
1529 gtk_widget_style_get (GTK_WIDGET (xpaned),
1530 "handle-size", &handle_size, NULL);
1532 size.width = allocation.width - pos.x - handle_size;
1539 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1542 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1544 if (size.width != xpaned->top_left_child_size.width)
1545 gtk_xpaned_set_position_x (xpaned, size.width);
1548 if (xpaned->in_drag_vert_and_horiz)
1550 pos.x -= xpaned->drag_pos.x;
1551 pos.y -= xpaned->drag_pos.y;
1553 if (is_rtl (xpaned))
1555 gtk_widget_style_get (GTK_WIDGET (xpaned),
1556 "handle-size", &handle_size, NULL);
1558 size.width = allocation.width - pos.x - handle_size;
1559 size.height = allocation.height - pos.y - handle_size;
1564 size.height = pos.y;
1567 size.width -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1568 size.height -= gtk_container_get_border_width (GTK_CONTAINER (xpaned));
1571 CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1573 CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1575 if (size.width != xpaned->top_left_child_size.width)
1576 gtk_xpaned_set_position_x (xpaned, size.width);
1578 if (size.height != xpaned->top_left_child_size.height)
1579 gtk_xpaned_set_position_y (xpaned, size.height);
1584 gtk_xpaned_enter (GtkWidget * widget, GdkEventCrossing * event)
1586 GtkXPaned *xpaned = GTK_XPANED (widget);
1588 if (xpaned->in_drag_vert ||
1589 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1590 update_drag (xpaned);
1593 xpaned->handle_prelit = TRUE;
1595 gtk_widget_queue_draw_area (widget,
1596 xpaned->handle_pos_east.x,
1597 xpaned->handle_pos_east.y,
1598 xpaned->handle_pos_east.width,
1599 xpaned->handle_pos_east.height);
1601 gtk_widget_queue_draw_area (widget,
1602 xpaned->handle_pos_west.x,
1603 xpaned->handle_pos_west.y,
1604 xpaned->handle_pos_west.width,
1605 xpaned->handle_pos_west.height);
1607 gtk_widget_queue_draw_area (widget,
1608 xpaned->handle_pos_north.x,
1609 xpaned->handle_pos_north.y,
1610 xpaned->handle_pos_north.width,
1611 xpaned->handle_pos_north.height);
1613 gtk_widget_queue_draw_area (widget,
1614 xpaned->handle_pos_south.x,
1615 xpaned->handle_pos_south.y,
1616 xpaned->handle_pos_south.width,
1617 xpaned->handle_pos_south.height);
1619 gtk_widget_queue_draw_area (widget,
1620 xpaned->handle_pos_middle.x,
1621 xpaned->handle_pos_middle.y,
1622 xpaned->handle_pos_middle.width,
1623 xpaned->handle_pos_middle.height);
1630 gtk_xpaned_leave (GtkWidget * widget, GdkEventCrossing * event)
1632 GtkXPaned *xpaned = GTK_XPANED (widget);
1634 if (xpaned->in_drag_vert ||
1635 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1636 update_drag (xpaned);
1639 xpaned->handle_prelit = FALSE;
1641 gtk_widget_queue_draw_area (widget,
1642 xpaned->handle_pos_east.x,
1643 xpaned->handle_pos_east.y,
1644 xpaned->handle_pos_east.width,
1645 xpaned->handle_pos_east.height);
1647 gtk_widget_queue_draw_area (widget,
1648 xpaned->handle_pos_west.x,
1649 xpaned->handle_pos_west.y,
1650 xpaned->handle_pos_west.width,
1651 xpaned->handle_pos_west.height);
1653 gtk_widget_queue_draw_area (widget,
1654 xpaned->handle_pos_north.x,
1655 xpaned->handle_pos_north.y,
1656 xpaned->handle_pos_north.width,
1657 xpaned->handle_pos_north.height);
1659 gtk_widget_queue_draw_area (widget,
1660 xpaned->handle_pos_south.x,
1661 xpaned->handle_pos_south.y,
1662 xpaned->handle_pos_south.width,
1663 xpaned->handle_pos_south.height);
1665 gtk_widget_queue_draw_area (widget,
1666 xpaned->handle_pos_middle.x,
1667 xpaned->handle_pos_middle.y,
1668 xpaned->handle_pos_middle.width,
1669 xpaned->handle_pos_middle.height);
1676 gtk_xpaned_focus (GtkWidget * widget, GtkDirectionType direction)
1680 /* This is a hack, but how can this be done without
1681 * excessive cut-and-paste from gtkcontainer.c?
1684 gtk_widget_set_can_focus (GTK_WIDGET (widget), FALSE);
1685 retval = (*GTK_WIDGET_CLASS (parent_class)->focus) (widget, direction);
1686 gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE);
1692 gtk_xpaned_button_press (GtkWidget * widget, GdkEventButton * event)
1694 GtkXPaned *xpaned = GTK_XPANED (widget);
1696 /* if any child is currently maximized, jump right back */
1697 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
1698 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
1699 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
1700 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
1703 /* if user is dragging the handles around */
1704 if (!xpaned->in_drag_vert_and_horiz &&
1705 event->window != xpaned->handle_east &&
1706 event->window != xpaned->handle_west &&
1707 event->window != xpaned->handle_north &&
1708 event->window != xpaned->handle_south &&
1709 event->window == xpaned->handle_middle && event->button == 1)
1711 xpaned->in_drag_vert_and_horiz = TRUE;
1713 /* We need a server grab here, not gtk_grab_add(), since
1714 * we don't want to pass events on to the widget's children */
1715 if (gdk_pointer_grab (xpaned->handle_middle,
1717 GDK_POINTER_MOTION_HINT_MASK
1718 | GDK_BUTTON1_MOTION_MASK
1719 | GDK_BUTTON_RELEASE_MASK
1720 | GDK_ENTER_NOTIFY_MASK
1721 | GDK_LEAVE_NOTIFY_MASK,
1722 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1726 xpaned->drag_pos.x = event->x;
1727 xpaned->drag_pos.y = event->y;
1731 else if (!xpaned->in_drag_vert &&
1732 event->window == xpaned->handle_east &&
1733 event->window != xpaned->handle_west &&
1734 event->window != xpaned->handle_north &&
1735 event->window != xpaned->handle_south &&
1736 event->window != xpaned->handle_middle && event->button == 1)
1738 xpaned->in_drag_vert = TRUE;
1740 /* We need a server grab here, not gtk_grab_add(), since
1741 * we don't want to pass events on to the widget's children */
1742 if (gdk_pointer_grab (xpaned->handle_east,
1744 GDK_POINTER_MOTION_HINT_MASK
1745 | GDK_BUTTON1_MOTION_MASK
1746 | GDK_BUTTON_RELEASE_MASK
1747 | GDK_ENTER_NOTIFY_MASK
1748 | GDK_LEAVE_NOTIFY_MASK,
1749 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1753 xpaned->drag_pos.y = event->y;
1757 else if (!xpaned->in_drag_vert &&
1758 event->window != xpaned->handle_east &&
1759 event->window == xpaned->handle_west &&
1760 event->window != xpaned->handle_north &&
1761 event->window != xpaned->handle_south &&
1762 event->window != xpaned->handle_middle && event->button == 1)
1764 xpaned->in_drag_vert = TRUE;
1766 /* We need a server grab here, not gtk_grab_add(), since
1767 * we don't want to pass events on to the widget's children */
1768 if (gdk_pointer_grab (xpaned->handle_west,
1770 GDK_POINTER_MOTION_HINT_MASK
1771 | GDK_BUTTON1_MOTION_MASK
1772 | GDK_BUTTON_RELEASE_MASK
1773 | GDK_ENTER_NOTIFY_MASK
1774 | GDK_LEAVE_NOTIFY_MASK,
1775 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1779 xpaned->drag_pos.y = event->y;
1783 else if (!xpaned->in_drag_horiz &&
1784 event->window != xpaned->handle_east &&
1785 event->window != xpaned->handle_west &&
1786 event->window == xpaned->handle_north &&
1787 event->window != xpaned->handle_south &&
1788 event->window != xpaned->handle_middle && event->button == 1)
1790 xpaned->in_drag_horiz = TRUE;
1792 /* We need a server grab here, not gtk_grab_add(), since
1793 * we don't want to pass events on to the widget's children */
1794 if (gdk_pointer_grab (xpaned->handle_north,
1796 GDK_POINTER_MOTION_HINT_MASK
1797 | GDK_BUTTON1_MOTION_MASK
1798 | GDK_BUTTON_RELEASE_MASK
1799 | GDK_ENTER_NOTIFY_MASK
1800 | GDK_LEAVE_NOTIFY_MASK,
1801 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1805 xpaned->drag_pos.x = event->x;
1809 else if (!xpaned->in_drag_horiz &&
1810 event->window != xpaned->handle_east &&
1811 event->window != xpaned->handle_west &&
1812 event->window != xpaned->handle_north &&
1813 event->window == xpaned->handle_south &&
1814 event->window != xpaned->handle_middle && event->button == 1)
1816 xpaned->in_drag_horiz = TRUE;
1818 /* We need a server grab here, not gtk_grab_add(), since
1819 * we don't want to pass events on to the widget's children */
1820 if (gdk_pointer_grab (xpaned->handle_south,
1822 GDK_POINTER_MOTION_HINT_MASK
1823 | GDK_BUTTON1_MOTION_MASK
1824 | GDK_BUTTON_RELEASE_MASK
1825 | GDK_ENTER_NOTIFY_MASK
1826 | GDK_LEAVE_NOTIFY_MASK,
1827 NULL, NULL, event->time) == GDK_GRAB_SUCCESS)
1831 xpaned->drag_pos.x = event->x;
1839 gtk_xpaned_button_release (GtkWidget * widget, GdkEventButton * event)
1841 GtkXPaned *xpaned = GTK_XPANED (widget);
1843 if (xpaned->in_drag_vert && (event->button == 1))
1845 xpaned->in_drag_vert = FALSE;
1846 xpaned->drag_pos.y = -1;
1847 xpaned->position_set = TRUE;
1848 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1852 else if (xpaned->in_drag_horiz && (event->button == 1))
1854 xpaned->in_drag_horiz = FALSE;
1855 xpaned->drag_pos.x = -1;
1856 xpaned->position_set = TRUE;
1857 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1861 else if (xpaned->in_drag_vert_and_horiz && (event->button == 1))
1863 xpaned->in_drag_vert_and_horiz = FALSE;
1864 xpaned->drag_pos.x = -1;
1865 xpaned->drag_pos.y = -1;
1866 xpaned->position_set = TRUE;
1867 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1876 gtk_xpaned_motion (GtkWidget * widget, GdkEventMotion * event)
1878 GtkXPaned *xpaned = GTK_XPANED (widget);
1880 if (xpaned->in_drag_vert ||
1881 xpaned->in_drag_horiz || xpaned->in_drag_vert_and_horiz)
1884 update_drag (xpaned);
1892 gtk_xpaned_add_top_left (GtkXPaned * xpaned, GtkWidget * widget)
1894 gtk_xpaned_pack_top_left (xpaned, widget, FALSE, TRUE);
1898 gtk_xpaned_add_top_right (GtkXPaned * xpaned, GtkWidget * widget)
1900 gtk_xpaned_pack_top_right (xpaned, widget, FALSE, TRUE);
1904 gtk_xpaned_add_bottom_left (GtkXPaned * xpaned, GtkWidget * widget)
1906 gtk_xpaned_pack_bottom_left (xpaned, widget, FALSE, TRUE);
1910 gtk_xpaned_add_bottom_right (GtkXPaned * xpaned, GtkWidget * widget)
1912 gtk_xpaned_pack_bottom_right (xpaned, widget, FALSE, TRUE);
1916 gtk_xpaned_pack_top_left (GtkXPaned * xpaned,
1917 GtkWidget * child, gboolean resize, gboolean shrink)
1919 g_return_if_fail (GTK_IS_XPANED (xpaned));
1920 g_return_if_fail (GTK_IS_WIDGET (child));
1922 if (!xpaned->top_left_child)
1924 xpaned->top_left_child = child;
1925 xpaned->top_left_child_resize = resize;
1926 xpaned->top_left_child_shrink = shrink;
1928 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1933 gtk_xpaned_pack_top_right (GtkXPaned * xpaned,
1935 gboolean resize, gboolean shrink)
1937 g_return_if_fail (GTK_IS_XPANED (xpaned));
1938 g_return_if_fail (GTK_IS_WIDGET (child));
1940 if (!xpaned->top_right_child)
1942 xpaned->top_right_child = child;
1943 xpaned->top_right_child_resize = resize;
1944 xpaned->top_right_child_shrink = shrink;
1946 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1951 gtk_xpaned_pack_bottom_left (GtkXPaned * xpaned,
1953 gboolean resize, gboolean shrink)
1955 g_return_if_fail (GTK_IS_XPANED (xpaned));
1956 g_return_if_fail (GTK_IS_WIDGET (child));
1958 if (!xpaned->bottom_left_child)
1960 xpaned->bottom_left_child = child;
1961 xpaned->bottom_left_child_resize = resize;
1962 xpaned->bottom_left_child_shrink = shrink;
1964 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1969 gtk_xpaned_pack_bottom_right (GtkXPaned * xpaned,
1971 gboolean resize, gboolean shrink)
1973 g_return_if_fail (GTK_IS_XPANED (xpaned));
1974 g_return_if_fail (GTK_IS_WIDGET (child));
1976 if (!xpaned->bottom_right_child)
1978 xpaned->bottom_right_child = child;
1979 xpaned->bottom_right_child_resize = resize;
1980 xpaned->bottom_right_child_shrink = shrink;
1982 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1987 gtk_xpaned_add (GtkContainer * container, GtkWidget * widget)
1991 g_return_if_fail (GTK_IS_XPANED (container));
1993 xpaned = GTK_XPANED (container);
1995 if (!xpaned->top_left_child)
1996 gtk_xpaned_add_top_left (xpaned, widget);
1997 else if (!xpaned->top_right_child)
1998 gtk_xpaned_add_top_right (xpaned, widget);
1999 else if (!xpaned->bottom_left_child)
2000 gtk_xpaned_add_bottom_left (xpaned, widget);
2001 else if (!xpaned->bottom_right_child)
2002 gtk_xpaned_add_bottom_right (xpaned, widget);
2004 g_warning ("GtkXPaned cannot have more than 4 children\n");
2008 gtk_xpaned_remove (GtkContainer * container, GtkWidget * widget)
2011 gboolean was_visible;
2013 xpaned = GTK_XPANED (container);
2014 was_visible = gtk_widget_get_visible (widget);
2016 if (xpaned->top_left_child == widget)
2018 gtk_widget_unparent (widget);
2020 xpaned->top_left_child = NULL;
2022 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2023 gtk_widget_queue_resize (GTK_WIDGET (container));
2025 else if (xpaned->top_right_child == widget)
2027 gtk_widget_unparent (widget);
2029 xpaned->top_right_child = NULL;
2031 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2032 gtk_widget_queue_resize (GTK_WIDGET (container));
2034 else if (xpaned->bottom_left_child == widget)
2036 gtk_widget_unparent (widget);
2038 xpaned->bottom_left_child = NULL;
2040 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2041 gtk_widget_queue_resize (GTK_WIDGET (container));
2043 else if (xpaned->bottom_right_child == widget)
2045 gtk_widget_unparent (widget);
2047 xpaned->bottom_right_child = NULL;
2049 if (was_visible && gtk_widget_get_visible (GTK_WIDGET (container)))
2050 gtk_widget_queue_resize (GTK_WIDGET (container));
2053 g_warning ("GtkXPaned has no more children attached\n");
2058 gtk_xpaned_forall (GtkContainer * container,
2059 gboolean include_internals,
2060 GtkCallback callback, gpointer callback_data)
2064 g_return_if_fail (callback != NULL);
2066 xpaned = GTK_XPANED (container);
2068 if (xpaned->top_left_child)
2069 (*callback) (xpaned->top_left_child, callback_data);
2070 if (xpaned->top_right_child)
2071 (*callback) (xpaned->top_right_child, callback_data);
2072 if (xpaned->bottom_left_child)
2073 (*callback) (xpaned->bottom_left_child, callback_data);
2074 if (xpaned->bottom_right_child)
2075 (*callback) (xpaned->bottom_right_child, callback_data);
2079 * gtk_xpaned_get_position_x:
2080 * @paned: a #GtkXPaned widget
2082 * Obtains the x-position of the divider.
2084 * Return value: x-position of the divider
2087 gtk_xpaned_get_position_x (GtkXPaned * xpaned)
2089 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2091 return xpaned->top_left_child_size.width;
2095 * gtk_xpaned_get_position_y:
2096 * @paned: a #GtkXPaned widget
2098 * Obtains the y-position of the divider.
2100 * Return value: y-position of the divider
2103 gtk_xpaned_get_position_y (GtkXPaned * xpaned)
2105 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2107 return xpaned->top_left_child_size.height;
2111 * gtk_xpaned_set_position_x:
2112 * @paned: a #GtkXPaned widget
2113 * @xposition: pixel x-position of divider, a negative values
2114 * of a component mean that the position is unset.
2116 * Sets the x-position of the divider between the four panes.
2119 gtk_xpaned_set_position_x (GtkXPaned * xpaned, gint xposition)
2123 g_return_if_fail (GTK_IS_XPANED (xpaned));
2125 /* if any child is currently maximized, jump right back */
2126 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2127 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2128 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2129 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2132 object = G_OBJECT (xpaned);
2136 /* We don't clamp here - the assumption is that
2137 * if the total allocation changes at the same time
2138 * as the position, the position set is with reference
2139 * to the new total size. If only the position changes,
2140 * then clamping will occur in gtk_paned_compute_position()
2143 xpaned->top_left_child_size.width = xposition;
2144 xpaned->position_set = TRUE;
2148 xpaned->position_set = FALSE;
2151 g_object_freeze_notify (object);
2152 g_object_notify (object, "x-position");
2153 g_object_notify (object, "position-set");
2154 g_object_thaw_notify (object);
2156 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2160 * gtk_xpaned_set_position_y:
2161 * @paned: a #GtkXPaned widget
2162 * @yposition: pixel y-position of divider, a negative values
2163 * of a component mean that the position is unset.
2165 * Sets the y-position of the divider between the four panes.
2168 gtk_xpaned_set_position_y (GtkXPaned * xpaned, gint yposition)
2172 g_return_if_fail (GTK_IS_XPANED (xpaned));
2174 /* if any child is currently maximized, jump right back */
2175 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2176 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2177 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2178 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2181 object = G_OBJECT (xpaned);
2185 /* We don't clamp here - the assumption is that
2186 * if the total allocation changes at the same time
2187 * as the position, the position set is with reference
2188 * to the new total size. If only the position changes,
2189 * then clamping will occur in gtk_paned_compute_position()
2192 xpaned->top_left_child_size.height = yposition;
2193 xpaned->position_set = TRUE;
2197 xpaned->position_set = FALSE;
2200 g_object_freeze_notify (object);
2201 g_object_notify (object, "y-position");
2202 g_object_notify (object, "position-set");
2203 g_object_thaw_notify (object);
2205 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2208 /* this call is private and only intended for internal use! */
2210 gtk_xpaned_save_unmaximized_x (GtkXPaned * xpaned)
2212 xpaned->unmaximized_position.x = gtk_xpaned_get_position_x (xpaned);
2215 /* this call is private and only intended for internal use! */
2217 gtk_xpaned_save_unmaximized_y (GtkXPaned * xpaned)
2219 xpaned->unmaximized_position.y = gtk_xpaned_get_position_y (xpaned);
2222 /* this call is private and only intended for internal use! */
2224 gtk_xpaned_fetch_unmaximized_x (GtkXPaned * xpaned)
2226 return xpaned->unmaximized_position.x;
2229 /* this call is private and only intended for internal use! */
2231 gtk_xpaned_fetch_unmaximized_y (GtkXPaned * xpaned)
2233 return xpaned->unmaximized_position.y;
2237 * gtk_xpaned_get_top_left_child:
2238 * @xpaned: a #GtkXPaned widget
2240 * Obtains the top-left child of the xpaned widget.
2242 * Return value: top-left child, or %NULL if it is not set.
2247 gtk_xpaned_get_top_left_child (GtkXPaned * xpaned)
2249 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2251 return xpaned->top_left_child;
2255 * gtk_xpaned_get_top_right_child:
2256 * @xpaned: a #GtkXPaned widget
2258 * Obtains the top-right child of the xpaned widget.
2260 * Return value: top-right child, or %NULL if it is not set.
2265 gtk_xpaned_get_top_right_child (GtkXPaned * xpaned)
2267 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2269 return xpaned->top_right_child;
2273 * gtk_xpaned_get_bottom_left_child:
2274 * @xpaned: a #GtkXPaned widget
2276 * Obtains the bottom-left child of the xpaned widget.
2278 * Return value: bottom-left child, or %NULL if it is not set.
2283 gtk_xpaned_get_bottom_left_child (GtkXPaned * xpaned)
2285 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2287 return xpaned->bottom_left_child;
2291 * gtk_xpaned_get_bottom_right_child:
2292 * @xpaned: a #GtkXPaned widget
2294 * Obtains the bottom-right child of the xpaned widget.
2296 * Return value: bottom-right child, or %NULL if it is not set.
2301 gtk_xpaned_get_bottom_right_child (GtkXPaned * xpaned)
2303 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2305 return xpaned->bottom_right_child;
2309 gtk_xpaned_maximize_top_left (GtkXPaned * xpaned, gboolean maximize)
2313 /* see if any child is already maximized */
2314 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2315 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2316 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2317 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2319 /* save current position */
2320 gtk_xpaned_save_unmaximized_x (xpaned);
2321 gtk_xpaned_save_unmaximized_y (xpaned);
2323 /* set new maximized position */
2324 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2325 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2327 /* mark maximized flag for top-left child */
2328 xpaned->maximized[GTK_XPANED_TOP_LEFT] = TRUE;
2332 /* already one child maximized, report error */
2338 /* verify that top-left child is really currently maximized */
2339 if (xpaned->maximized[GTK_XPANED_TOP_LEFT])
2341 /* clear maximized flat for top-left child */
2342 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
2344 /* restore unmaximized position */
2345 gtk_xpaned_set_position_x (xpaned,
2346 gtk_xpaned_fetch_unmaximized_x (xpaned));
2347 gtk_xpaned_set_position_y (xpaned,
2348 gtk_xpaned_fetch_unmaximized_y (xpaned));
2352 /* top-left child is currently not maximized, report error */
2359 gtk_xpaned_maximize_top_right (GtkXPaned * xpaned, gboolean maximize)
2363 /* see if any child is already maximized */
2364 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2365 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2366 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2367 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2369 /* save current position */
2370 gtk_xpaned_save_unmaximized_x (xpaned);
2371 gtk_xpaned_save_unmaximized_y (xpaned);
2373 /* set new maximized position */
2374 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2375 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2377 /* mark maximized flag for top-right child */
2378 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = TRUE;
2382 /* already one child maximized, report error */
2388 /* verify that top-right child is really currently maximized */
2389 if (xpaned->maximized[GTK_XPANED_TOP_RIGHT])
2391 /* clear maximized flat for top-right child */
2392 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
2394 /* restore unmaximized position */
2395 gtk_xpaned_set_position_x (xpaned,
2396 gtk_xpaned_fetch_unmaximized_x (xpaned));
2397 gtk_xpaned_set_position_y (xpaned,
2398 gtk_xpaned_fetch_unmaximized_y (xpaned));
2402 /* top-right child is currently not maximized, report error */
2409 gtk_xpaned_maximize_bottom_left (GtkXPaned * xpaned, gboolean maximize)
2413 /* see if any child is already maximized */
2414 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2415 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2416 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2417 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2419 /* save current position */
2420 gtk_xpaned_save_unmaximized_x (xpaned);
2421 gtk_xpaned_save_unmaximized_y (xpaned);
2423 /* set new maximized position */
2424 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2425 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2427 /* mark maximized flag for bottom-left child */
2428 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = TRUE;
2432 /* already one child maximized, report error */
2438 /* verify that bottom-left child is really currently maximized */
2439 if (xpaned->maximized[GTK_XPANED_BOTTOM_LEFT])
2441 /* clear maximized flat for bottom-left child */
2442 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
2444 /* restore unmaximized position */
2445 gtk_xpaned_set_position_x (xpaned,
2446 gtk_xpaned_fetch_unmaximized_x (xpaned));
2447 gtk_xpaned_set_position_y (xpaned,
2448 gtk_xpaned_fetch_unmaximized_y (xpaned));
2452 /* bottom-left child is currently not maximized, report error */
2459 gtk_xpaned_maximize_bottom_right (GtkXPaned * xpaned, gboolean maximize)
2463 /* see if any child is already maximized */
2464 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2465 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2466 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2467 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2469 /* save current position */
2470 gtk_xpaned_save_unmaximized_x (xpaned);
2471 gtk_xpaned_save_unmaximized_y (xpaned);
2473 /* set new maximized position */
2474 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2475 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2477 /* mark maximized flag for bottom-right child */
2478 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = TRUE;
2482 /* already one child maximized, report error */
2488 /* verify that bottom-right child is really currently maximized */
2489 if (xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2491 /* clear maximized flat for bottom-right child */
2492 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
2494 /* restore unmaximized position */
2495 gtk_xpaned_set_position_x (xpaned,
2496 gtk_xpaned_fetch_unmaximized_x (xpaned));
2497 gtk_xpaned_set_position_y (xpaned,
2498 gtk_xpaned_fetch_unmaximized_y (xpaned));
2502 /* bottom-right child is currently not maximized, report error */
2509 gtk_xpaned_compute_position (GtkXPaned * xpaned,
2510 const GtkAllocation * allocation,
2511 GtkRequisition * top_left_child_req,
2512 GtkRequisition * top_right_child_req,
2513 GtkRequisition * bottom_left_child_req,
2514 GtkRequisition * bottom_right_child_req)
2516 GdkPoint old_position;
2517 GdkPoint old_min_position;
2518 GdkPoint old_max_position;
2520 gint border_width = gtk_container_get_border_width (GTK_CONTAINER (xpaned));
2522 g_return_if_fail (GTK_IS_XPANED (xpaned));
2524 old_position.x = xpaned->top_left_child_size.width;
2525 old_position.y = xpaned->top_left_child_size.height;
2526 old_min_position.x = xpaned->min_position.x;
2527 old_min_position.y = xpaned->min_position.y;
2528 old_max_position.x = xpaned->max_position.x;
2529 old_max_position.y = xpaned->max_position.y;
2531 xpaned->min_position.x =
2532 xpaned->top_left_child_shrink ? 0 : top_left_child_req->width;
2533 xpaned->min_position.y =
2534 xpaned->top_left_child_shrink ? 0 : top_left_child_req->height;
2536 gtk_widget_style_get (GTK_WIDGET (xpaned), "handle-size", &handle_size,
2539 xpaned->max_position.x = allocation->width - 2 * border_width - handle_size;
2540 xpaned->max_position.y =
2541 allocation->height - 2 * border_width - handle_size;
2542 if (!xpaned->top_left_child_shrink)
2543 xpaned->max_position.x =
2544 MAX (1, xpaned->max_position.x - top_left_child_req->width);
2545 xpaned->max_position.x =
2546 MAX (xpaned->min_position.x, xpaned->max_position.x);
2548 if (!xpaned->position_set)
2550 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2552 xpaned->top_left_child_size.width =
2553 MAX (0, allocation->width - top_right_child_req->width);
2554 xpaned->top_left_child_size.height =
2555 MAX (0, allocation->height - top_right_child_req->height);
2557 else if (!xpaned->top_left_child_resize
2558 && xpaned->top_right_child_resize)
2560 xpaned->top_left_child_size.width = top_left_child_req->width;
2561 xpaned->top_left_child_size.height = top_left_child_req->height;
2565 xpaned->top_left_child_size.width = allocation->width * 0.5 + 0.5;
2566 xpaned->top_left_child_size.height = allocation->height * 0.5 + 0.5;
2571 /* If the position was set before the initial allocation.
2572 ** (paned->last_allocation <= 0) just clamp it and leave it. */
2573 if (xpaned->last_allocation.width > 0)
2575 if (xpaned->top_left_child_resize
2576 && !xpaned->top_right_child_resize)
2578 xpaned->top_left_child_size.width += allocation->width
2579 - xpaned->last_allocation.width;
2581 xpaned->top_left_child_size.height += allocation->height
2582 - xpaned->last_allocation.height;
2586 (!xpaned->top_left_child_resize
2587 && xpaned->top_right_child_resize))
2589 xpaned->top_left_child_size.width = allocation->width
2590 * ((gdouble) xpaned->top_left_child_size.width /
2591 (xpaned->last_allocation.width)) + 0.5;
2593 xpaned->top_left_child_size.height = allocation->height
2594 * ((gdouble) xpaned->top_left_child_size.height /
2595 (xpaned->last_allocation.height)) + 0.5;
2598 if (xpaned->last_allocation.height > 0)
2600 if (xpaned->top_left_child_resize
2601 && !xpaned->top_right_child_resize)
2603 xpaned->top_left_child_size.width +=
2604 allocation->width - xpaned->last_allocation.width;
2605 xpaned->top_left_child_size.height +=
2606 allocation->height - xpaned->last_allocation.height;
2610 (!xpaned->top_left_child_resize
2611 && xpaned->top_right_child_resize))
2613 xpaned->top_left_child_size.width =
2615 ((gdouble) xpaned->top_left_child_size.width /
2616 (xpaned->last_allocation.width)) + 0.5;
2617 xpaned->top_left_child_size.height =
2618 allocation->height *
2619 ((gdouble) xpaned->top_left_child_size.height /
2620 (xpaned->last_allocation.height)) + 0.5;
2626 xpaned->top_left_child_size.width =
2627 CLAMP (xpaned->top_left_child_size.width, xpaned->min_position.x,
2628 xpaned->max_position.x);
2629 xpaned->top_left_child_size.height =
2630 CLAMP (xpaned->top_left_child_size.height, xpaned->min_position.y,
2631 xpaned->max_position.y);
2633 xpaned->top_right_child_size.width =
2634 CLAMP (xpaned->top_right_child_size.width, xpaned->min_position.x,
2635 xpaned->max_position.x);
2636 xpaned->top_right_child_size.height =
2637 CLAMP (xpaned->top_right_child_size.height, xpaned->min_position.y,
2638 xpaned->max_position.y);
2640 xpaned->bottom_left_child_size.width =
2641 CLAMP (xpaned->bottom_left_child_size.width, xpaned->min_position.x,
2642 xpaned->max_position.x);
2643 xpaned->bottom_left_child_size.height =
2644 CLAMP (xpaned->bottom_left_child_size.height, xpaned->min_position.y,
2645 xpaned->max_position.y);
2647 xpaned->bottom_right_child_size.width =
2648 CLAMP (xpaned->bottom_right_child_size.width, xpaned->min_position.x,
2649 xpaned->max_position.x);
2650 xpaned->bottom_right_child_size.height =
2651 CLAMP (xpaned->bottom_right_child_size.height, xpaned->min_position.y,
2652 xpaned->max_position.y);
2654 gtk_widget_set_child_visible (xpaned->top_left_child, TRUE);
2655 gtk_widget_set_child_visible (xpaned->top_right_child, TRUE);
2656 gtk_widget_set_child_visible (xpaned->bottom_left_child, TRUE);
2657 gtk_widget_set_child_visible (xpaned->bottom_right_child, TRUE);
2659 g_object_freeze_notify (G_OBJECT (xpaned));
2661 if (xpaned->top_left_child_size.width != old_position.x)
2662 g_object_notify (G_OBJECT (xpaned), "x-position");
2663 if (xpaned->top_left_child_size.height != old_position.y)
2664 g_object_notify (G_OBJECT (xpaned), "y-position");
2666 if (xpaned->top_right_child_size.width != old_position.x)
2667 g_object_notify (G_OBJECT (xpaned), "x-position");
2668 if (xpaned->top_right_child_size.height != old_position.y)
2669 g_object_notify (G_OBJECT (xpaned), "y-position");
2671 if (xpaned->bottom_left_child_size.width != old_position.x)
2672 g_object_notify (G_OBJECT (xpaned), "x-position");
2673 if (xpaned->bottom_left_child_size.height != old_position.y)
2674 g_object_notify (G_OBJECT (xpaned), "y-position");
2676 if (xpaned->bottom_right_child_size.width != old_position.x)
2677 g_object_notify (G_OBJECT (xpaned), "x-position");
2678 if (xpaned->bottom_right_child_size.height != old_position.y)
2679 g_object_notify (G_OBJECT (xpaned), "y-position");
2681 if (xpaned->min_position.x != old_min_position.x)
2682 g_object_notify (G_OBJECT (xpaned), "min-x-position");
2683 if (xpaned->min_position.y != old_min_position.y)
2684 g_object_notify (G_OBJECT (xpaned), "min-y-position");
2686 if (xpaned->max_position.x != old_max_position.x)
2687 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2688 if (xpaned->max_position.y != old_max_position.y)
2689 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2691 g_object_thaw_notify (G_OBJECT (xpaned));
2693 xpaned->last_allocation.width = allocation->width;
2694 xpaned->last_allocation.height = allocation->height;
2698 gtk_xpaned_set_saved_focus (GtkXPaned * xpaned, GtkWidget * widget)
2700 if (xpaned->priv->saved_focus)
2701 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2702 (gpointer *) & (xpaned->priv->saved_focus));
2704 xpaned->priv->saved_focus = widget;
2706 if (xpaned->priv->saved_focus)
2707 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2708 (gpointer *) & (xpaned->priv->saved_focus));
2712 gtk_xpaned_set_first_xpaned (GtkXPaned * xpaned, GtkXPaned * first_xpaned)
2714 if (xpaned->priv->first_xpaned)
2715 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2716 (gpointer *) & (xpaned->priv->
2719 xpaned->priv->first_xpaned = first_xpaned;
2721 if (xpaned->priv->first_xpaned)
2722 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2723 (gpointer *) & (xpaned->priv->first_xpaned));
2727 gtk_xpaned_set_last_top_left_child_focus (GtkXPaned * xpaned,
2730 if (xpaned->last_top_left_child_focus)
2731 g_object_remove_weak_pointer (G_OBJECT
2732 (xpaned->last_top_left_child_focus),
2733 (gpointer *) & (xpaned->
2734 last_top_left_child_focus));
2736 xpaned->last_top_left_child_focus = widget;
2738 if (xpaned->last_top_left_child_focus)
2739 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2740 (gpointer *) & (xpaned->
2741 last_top_left_child_focus));
2745 gtk_xpaned_set_last_top_right_child_focus (GtkXPaned * xpaned,
2748 if (xpaned->last_top_right_child_focus)
2749 g_object_remove_weak_pointer (G_OBJECT
2750 (xpaned->last_top_right_child_focus),
2751 (gpointer *) & (xpaned->
2752 last_top_right_child_focus));
2754 xpaned->last_top_right_child_focus = widget;
2756 if (xpaned->last_top_right_child_focus)
2757 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2758 (gpointer *) & (xpaned->
2759 last_top_right_child_focus));
2763 gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned * xpaned,
2766 if (xpaned->last_bottom_left_child_focus)
2767 g_object_remove_weak_pointer (G_OBJECT
2768 (xpaned->last_bottom_left_child_focus),
2769 (gpointer *) & (xpaned->
2770 last_bottom_left_child_focus));
2772 xpaned->last_bottom_left_child_focus = widget;
2774 if (xpaned->last_bottom_left_child_focus)
2775 g_object_add_weak_pointer (G_OBJECT
2776 (xpaned->last_bottom_left_child_focus),
2777 (gpointer *) & (xpaned->
2778 last_bottom_left_child_focus));
2782 gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned * xpaned,
2785 if (xpaned->last_bottom_right_child_focus)
2786 g_object_remove_weak_pointer (G_OBJECT
2787 (xpaned->last_bottom_right_child_focus),
2788 (gpointer *) & (xpaned->
2789 last_bottom_right_child_focus));
2791 xpaned->last_bottom_right_child_focus = widget;
2793 if (xpaned->last_bottom_right_child_focus)
2794 g_object_add_weak_pointer (G_OBJECT
2795 (xpaned->last_bottom_right_child_focus),
2796 (gpointer *) & (xpaned->
2797 last_bottom_right_child_focus));
2801 xpaned_get_focus_widget (GtkXPaned * xpaned)
2803 GtkWidget *toplevel;
2805 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
2806 if (gtk_widget_is_toplevel (toplevel))
2807 return gtk_window_get_focus (GTK_WINDOW (toplevel));
2813 gtk_xpaned_set_focus_child (GtkContainer * container, GtkWidget * focus_child)
2817 g_return_if_fail (GTK_IS_XPANED (container));
2819 xpaned = GTK_XPANED (container);
2821 if (focus_child == NULL)
2823 GtkWidget *last_focus;
2826 last_focus = xpaned_get_focus_widget (xpaned);
2830 /* If there is one or more paned widgets between us and the
2831 * focus widget, we want the topmost of those as last_focus
2833 for (w = last_focus; w != GTK_WIDGET (xpaned); w = gtk_widget_get_parent (w))
2834 if (GTK_IS_XPANED (w))
2837 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2838 gtk_xpaned_set_last_top_left_child_focus (xpaned, last_focus);
2839 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2840 gtk_xpaned_set_last_top_right_child_focus (xpaned, last_focus);
2841 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2842 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, last_focus);
2843 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2844 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, last_focus);
2848 if (parent_class->set_focus_child)
2849 (*parent_class->set_focus_child) (container, focus_child);
2853 gtk_xpaned_get_cycle_chain (GtkXPaned * xpaned,
2854 GtkDirectionType direction, GList ** widgets)
2856 GtkContainer *container = GTK_CONTAINER (xpaned);
2857 GtkWidget *ancestor = NULL;
2858 GList *temp_list = NULL;
2861 if (xpaned->in_recursion)
2864 g_assert (widgets != NULL);
2866 if (xpaned->last_top_left_child_focus &&
2867 !gtk_widget_is_ancestor (xpaned->last_top_left_child_focus,
2868 GTK_WIDGET (xpaned)))
2870 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
2873 if (xpaned->last_top_right_child_focus &&
2874 !gtk_widget_is_ancestor (xpaned->last_top_right_child_focus,
2875 GTK_WIDGET (xpaned)))
2877 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
2880 if (xpaned->last_bottom_left_child_focus &&
2881 !gtk_widget_is_ancestor (xpaned->last_bottom_left_child_focus,
2882 GTK_WIDGET (xpaned)))
2884 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
2887 if (xpaned->last_bottom_right_child_focus &&
2888 !gtk_widget_is_ancestor (xpaned->last_bottom_right_child_focus,
2889 GTK_WIDGET (xpaned)))
2891 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
2894 if (gtk_widget_get_parent (GTK_WIDGET (xpaned)))
2895 ancestor = gtk_widget_get_ancestor (gtk_widget_get_parent (GTK_WIDGET (xpaned)),
2898 /* The idea here is that temp_list is a list of widgets we want to cycle
2899 * to. The list is prioritized so that the first element is our first
2900 * choice, the next our second, and so on.
2902 * We can't just use g_list_reverse(), because we want to try
2903 * paned->last_child?_focus before paned->child?, both when we
2904 * are going forward and backward.
2906 if (direction == GTK_DIR_TAB_FORWARD)
2908 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2911 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2912 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2913 temp_list = g_list_append (temp_list, ancestor);
2915 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2917 temp_list = g_list_append (temp_list, ancestor);
2919 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2920 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2922 else if (gtk_container_get_focus_child (container) == xpaned->bottom_left_child)
2924 temp_list = g_list_append (temp_list, ancestor);
2926 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2927 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2929 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2931 temp_list = g_list_append (temp_list, ancestor);
2933 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2934 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2939 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2940 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2942 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2943 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2945 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2946 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2948 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2949 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2950 temp_list = g_list_append (temp_list, ancestor);
2955 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
2957 temp_list = g_list_append (temp_list, ancestor);
2959 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2960 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2962 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2965 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2966 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2967 temp_list = g_list_append (temp_list, ancestor);
2969 else if (gtk_container_get_focus_child (container) == xpaned->bottom_right_child)
2972 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2973 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2974 temp_list = g_list_append (temp_list, ancestor);
2976 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
2979 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2980 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2981 temp_list = g_list_append (temp_list, ancestor);
2986 g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2987 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2989 g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2990 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2992 g_list_append (temp_list, xpaned->last_top_right_child_focus);
2993 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2995 g_list_append (temp_list, xpaned->last_top_left_child_focus);
2996 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2997 temp_list = g_list_append (temp_list, ancestor);
3001 /* Walk the list and expand all the paned widgets. */
3002 for (list = temp_list; list != NULL; list = list->next)
3004 GtkWidget *widget = list->data;
3008 if (GTK_IS_XPANED (widget))
3010 xpaned->in_recursion = TRUE;
3011 gtk_xpaned_get_cycle_chain (GTK_XPANED (widget),
3012 direction, widgets);
3013 xpaned->in_recursion = FALSE;
3017 *widgets = g_list_append (*widgets, widget);
3022 g_list_free (temp_list);
3026 gtk_xpaned_cycle_child_focus (GtkXPaned * xpaned, gboolean reversed)
3028 GList *cycle_chain = NULL;
3031 GtkDirectionType direction =
3032 reversed ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
3034 /* ignore f6 if the handle is focused */
3035 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3038 /* we can't just let the event propagate up the hierarchy,
3039 * because the paned will want to cycle focus _unless_ an
3040 * ancestor paned handles the event
3042 gtk_xpaned_get_cycle_chain (xpaned, direction, &cycle_chain);
3044 for (list = cycle_chain; list != NULL; list = list->next)
3045 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
3048 g_list_free (cycle_chain);
3054 get_child_xpanes (GtkWidget * widget, GList ** xpanes)
3056 if (GTK_IS_XPANED (widget))
3058 GtkXPaned *xpaned = GTK_XPANED (widget);
3060 get_child_xpanes (xpaned->top_left_child, xpanes);
3061 *xpanes = g_list_prepend (*xpanes, widget);
3062 get_child_xpanes (xpaned->top_right_child, xpanes);
3063 *xpanes = g_list_prepend (*xpanes, widget);
3064 get_child_xpanes (xpaned->bottom_left_child, xpanes);
3065 *xpanes = g_list_prepend (*xpanes, widget);
3066 get_child_xpanes (xpaned->bottom_right_child, xpanes);
3068 else if (GTK_IS_CONTAINER (widget))
3070 gtk_container_foreach (GTK_CONTAINER (widget),
3071 (GtkCallback) get_child_xpanes, xpanes);
3076 get_all_xpanes (GtkXPaned * xpaned)
3078 GtkXPaned *topmost = NULL;
3079 GList *result = NULL;
3082 for (w = GTK_WIDGET (xpaned); w != NULL; w = gtk_widget_get_parent (w))
3084 if (GTK_IS_XPANED (w))
3085 topmost = GTK_XPANED (w);
3090 get_child_xpanes (GTK_WIDGET (topmost), &result);
3092 return g_list_reverse (result);
3096 gtk_xpaned_find_neighbours (GtkXPaned * xpaned,
3097 GtkXPaned ** next, GtkXPaned ** prev)
3102 all_xpanes = get_all_xpanes (xpaned);
3103 g_assert (all_xpanes);
3105 this_link = g_list_find (all_xpanes, xpaned);
3107 g_assert (this_link);
3109 if (this_link->next)
3110 *next = this_link->next->data;
3112 *next = all_xpanes->data;
3114 if (this_link->prev)
3115 *prev = this_link->prev->data;
3117 *prev = g_list_last (all_xpanes)->data;
3119 g_list_free (all_xpanes);
3123 gtk_xpaned_move_handle (GtkXPaned * xpaned, GtkScrollType scroll)
3125 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3127 GdkPoint old_position;
3128 GdkPoint new_position;
3133 SINGLE_STEP_SIZE = 1,
3137 new_position.x = old_position.x = gtk_xpaned_get_position_x (xpaned);
3138 new_position.y = old_position.y = gtk_xpaned_get_position_y (xpaned);
3143 case GTK_SCROLL_STEP_LEFT:
3144 case GTK_SCROLL_STEP_UP:
3145 case GTK_SCROLL_STEP_BACKWARD:
3146 increment = -SINGLE_STEP_SIZE;
3149 case GTK_SCROLL_STEP_RIGHT:
3150 case GTK_SCROLL_STEP_DOWN:
3151 case GTK_SCROLL_STEP_FORWARD:
3152 increment = SINGLE_STEP_SIZE;
3155 case GTK_SCROLL_PAGE_LEFT:
3156 case GTK_SCROLL_PAGE_UP:
3157 case GTK_SCROLL_PAGE_BACKWARD:
3158 increment = -PAGE_STEP_SIZE;
3161 case GTK_SCROLL_PAGE_RIGHT:
3162 case GTK_SCROLL_PAGE_DOWN:
3163 case GTK_SCROLL_PAGE_FORWARD:
3164 increment = PAGE_STEP_SIZE;
3167 case GTK_SCROLL_START:
3168 new_position.x = xpaned->min_position.x;
3169 new_position.y = xpaned->min_position.y;
3172 case GTK_SCROLL_END:
3173 new_position.x = xpaned->max_position.x;
3174 new_position.y = xpaned->max_position.y;
3183 if (is_rtl (xpaned))
3184 increment = -increment;
3186 new_position.x = old_position.x + increment;
3187 new_position.y = old_position.y + increment;
3190 new_position.x = CLAMP (new_position.x,
3191 xpaned->min_position.x, xpaned->max_position.x);
3193 new_position.y = CLAMP (new_position.y,
3194 xpaned->min_position.y, xpaned->max_position.y);
3196 if (old_position.x != new_position.x)
3197 gtk_xpaned_set_position_x (xpaned, new_position.x);
3199 if (old_position.y != new_position.y)
3200 gtk_xpaned_set_position_y (xpaned, new_position.y);
3209 gtk_xpaned_restore_focus (GtkXPaned * xpaned)
3211 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3213 if (xpaned->priv->saved_focus &&
3214 gtk_widget_get_sensitive (xpaned->priv->saved_focus))
3216 gtk_widget_grab_focus (xpaned->priv->saved_focus);
3220 /* the saved focus is somehow not available for focusing,
3222 * 1) tabbing into the paned widget
3223 * if that didn't work,
3224 * 2) unset focus for the window if there is one
3227 if (!gtk_widget_child_focus
3228 (GTK_WIDGET (xpaned), GTK_DIR_TAB_FORWARD))
3230 GtkWidget *toplevel =
3231 gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3233 if (GTK_IS_WINDOW (toplevel))
3234 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
3238 gtk_xpaned_set_saved_focus (xpaned, NULL);
3239 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3244 gtk_xpaned_accept_position (GtkXPaned * xpaned)
3246 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3248 xpaned->original_position.x = -1;
3249 xpaned->original_position.y = -1;
3250 gtk_xpaned_restore_focus (xpaned);
3259 gtk_xpaned_cancel_position (GtkXPaned * xpaned)
3261 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3263 if (xpaned->original_position.x != -1)
3265 gtk_xpaned_set_position_x (xpaned, xpaned->original_position.x);
3266 xpaned->original_position.x = -1;
3269 if (xpaned->original_position.y != -1)
3271 gtk_xpaned_set_position_y (xpaned, xpaned->original_position.y);
3272 xpaned->original_position.y = -1;
3275 gtk_xpaned_restore_focus (xpaned);
3283 gtk_xpaned_cycle_handle_focus (GtkXPaned * xpaned, gboolean reversed)
3288 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3290 GtkXPaned *focus = NULL;
3292 if (!xpaned->priv->first_xpaned)
3294 /* The first_pane has disappeared. As an ad-hoc solution,
3295 * we make the currently focused paned the first_paned. To the
3296 * user this will seem like the paned cycling has been reset.
3298 gtk_xpaned_set_first_xpaned (xpaned, xpaned);
3301 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3303 if (reversed && prev &&
3304 prev != xpaned && xpaned != xpaned->priv->first_xpaned)
3308 else if (!reversed &&
3309 next && next != xpaned && next != xpaned->priv->first_xpaned)
3315 gtk_xpaned_accept_position (xpaned);
3321 gtk_xpaned_set_saved_focus (focus, xpaned->priv->saved_focus);
3322 gtk_xpaned_set_first_xpaned (focus, xpaned->priv->first_xpaned);
3324 gtk_xpaned_set_saved_focus (xpaned, NULL);
3325 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3327 gtk_widget_grab_focus (GTK_WIDGET (focus));
3329 if (!gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3331 xpaned->original_position.x = -1;
3332 xpaned->original_position.y = -1;
3333 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3334 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3339 GtkContainer *container = GTK_CONTAINER (xpaned);
3344 GtkWidget *toplevel;
3346 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3348 if (gtk_container_get_focus_child (container) == xpaned->top_left_child)
3361 else if (gtk_container_get_focus_child (container) == xpaned->top_right_child)
3376 /* Focus is not inside this xpaned, and we don't have focus.
3377 * Presumably this happened because the application wants us
3378 * to start keyboard navigating.
3388 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3390 if (GTK_IS_WINDOW (toplevel))
3391 gtk_xpaned_set_saved_focus (focus,
3392 gtk_window_get_focus (GTK_WINDOW (toplevel)));
3393 gtk_xpaned_set_first_xpaned (focus, first);
3394 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3395 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3397 gtk_widget_grab_focus (GTK_WIDGET (focus));
3404 gtk_xpaned_toggle_handle_focus (GtkXPaned * xpaned)
3406 /* This function/signal has the wrong name. It is called when you
3407 * press Tab or Shift-Tab and what we do is act as if
3408 * the user pressed Return and then Tab or Shift-Tab
3410 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3411 gtk_xpaned_accept_position (xpaned);
3416 /*#define __GTK_XPANED_C__*/
3417 /*#include "gtkaliasdef.c"*/