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) 2005-2006 Mirco "MacSlow" Müller <macslow@bangang.de>
8 ** This library is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU Lesser General Public
10 ** License as published by the Free Software Foundation; either
11 ** version 2.1 of the License, or (at your option) any later version.
13 ** This library is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** Lesser General Public License for more details.
18 ** You should have received a copy of the GNU Lesser General Public
19 ** License along with this library; if not, write to the Free Software
20 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ** GtkXPaned is based on GtkPaned which was done by...
24 ** "Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald"
26 ** and later modified by...
28 ** "the GTK+ Team and others 1997-2000"
30 *******************************************************************************/
33 #include "gtkxpaned.h"
34 #include <ui/gui/psppire-marshal.h>
35 #include <gtk/gtkbindings.h>
36 #include <gtk/gtksignal.h>
37 #include <gdk/gdkkeysyms.h>
38 #include <gtk/gtkwindow.h>
39 #include <gtk/gtkmain.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);
78 static void gtk_xpaned_size_allocate (GtkWidget* widget,
79 GtkAllocation* allocation);
81 static void gtk_xpaned_set_property (GObject* object,
86 static void gtk_xpaned_get_property (GObject* object,
91 static void gtk_xpaned_set_child_property (GtkContainer* container,
97 static void gtk_xpaned_get_child_property (GtkContainer* container,
103 static void gtk_xpaned_finalize (GObject* object);
105 static void gtk_xpaned_realize (GtkWidget* widget);
107 static void gtk_xpaned_unrealize (GtkWidget* widget);
109 static void gtk_xpaned_map (GtkWidget* widget);
111 static void gtk_xpaned_unmap (GtkWidget* widget);
113 static gboolean gtk_xpaned_expose (GtkWidget* widget, GdkEventExpose* event);
115 static gboolean gtk_xpaned_enter (GtkWidget* widget, GdkEventCrossing* event);
117 static gboolean gtk_xpaned_leave (GtkWidget* widget, GdkEventCrossing* event);
119 static gboolean gtk_xpaned_button_press (GtkWidget* widget,
120 GdkEventButton* event);
122 static gboolean gtk_xpaned_button_release (GtkWidget* widget,
123 GdkEventButton* event);
125 static gboolean gtk_xpaned_motion (GtkWidget* widget, GdkEventMotion* event);
127 static gboolean gtk_xpaned_focus (GtkWidget* widget,
128 GtkDirectionType direction);
130 static void gtk_xpaned_add (GtkContainer* container, GtkWidget* widget);
132 static void gtk_xpaned_remove (GtkContainer* container, GtkWidget* widget);
134 static void gtk_xpaned_forall (GtkContainer* container,
135 gboolean include_internals,
136 GtkCallback callback,
137 gpointer callback_data);
139 static void gtk_xpaned_set_focus_child (GtkContainer* container,
142 static void gtk_xpaned_set_saved_focus (GtkXPaned* xpaned, GtkWidget* widget);
144 static void gtk_xpaned_set_first_xpaned (GtkXPaned* xpaned,
145 GtkXPaned* first_xpaned);
147 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned* xpaned,
150 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned* xpaned,
153 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned* xpaned,
156 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned* xpaned,
159 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned* xpaned,
162 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned* xpaned,
165 static gboolean gtk_xpaned_move_handle (GtkXPaned* xpaned,
166 GtkScrollType scroll);
168 static gboolean gtk_xpaned_accept_position (GtkXPaned* xpaned);
170 static gboolean gtk_xpaned_cancel_position (GtkXPaned* xpaned);
172 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned* xpaned);
174 static GType gtk_xpaned_child_type (GtkContainer* container);
176 static GtkContainerClass* parent_class = NULL;
178 struct _GtkXPanedPrivate
180 GtkWidget *saved_focus;
181 GtkXPaned *first_xpaned;
184 GType gtk_xpaned_get_type (void)
186 static GType xpaned_type = 0;
190 static const GTypeInfo xpaned_info =
192 sizeof (GtkXPanedClass),
193 NULL, /* base_init */
194 NULL, /* base_finalize */
195 (GClassInitFunc) gtk_xpaned_class_init,
196 NULL, /* class_finalize */
197 NULL, /* class_data */
200 (GInstanceInitFunc) gtk_xpaned_init
203 xpaned_type = g_type_register_static (GTK_TYPE_CONTAINER,
212 GtkWidget* gtk_xpaned_new (void)
216 xpaned = g_object_new (GTK_TYPE_XPANED, NULL);
218 return GTK_WIDGET (xpaned);
221 static guint signals[LAST_SIGNAL] = { 0 };
223 static void add_tab_bindings (GtkBindingSet* binding_set,
224 GdkModifierType modifiers)
226 gtk_binding_entry_add_signal (binding_set,
229 "toggle_handle_focus",
232 gtk_binding_entry_add_signal (binding_set,
235 "toggle_handle_focus",
239 static void add_move_binding (GtkBindingSet* binding_set,
241 GdkModifierType mask,
242 GtkScrollType scroll)
244 gtk_binding_entry_add_signal (binding_set,
249 GTK_TYPE_SCROLL_TYPE,
253 static void gtk_xpaned_class_init (GtkXPanedClass* class)
255 GObjectClass* object_class;
256 GtkWidgetClass* widget_class;
257 GtkContainerClass* container_class;
258 GtkXPanedClass* xpaned_class;
259 GtkBindingSet* binding_set;
261 object_class = (GObjectClass *) class;
262 widget_class = (GtkWidgetClass *) class;
263 container_class = (GtkContainerClass *) class;
264 xpaned_class = (GtkXPanedClass *) class;
266 parent_class = g_type_class_peek_parent (class);
268 object_class->set_property = gtk_xpaned_set_property;
269 object_class->get_property = gtk_xpaned_get_property;
270 object_class->finalize = gtk_xpaned_finalize;
272 widget_class->realize = gtk_xpaned_realize;
273 widget_class->unrealize = gtk_xpaned_unrealize;
274 widget_class->map = gtk_xpaned_map;
275 widget_class->unmap = gtk_xpaned_unmap;
276 widget_class->expose_event = gtk_xpaned_expose;
277 widget_class->focus = gtk_xpaned_focus;
278 widget_class->enter_notify_event = gtk_xpaned_enter;
279 widget_class->leave_notify_event = gtk_xpaned_leave;
280 widget_class->button_press_event = gtk_xpaned_button_press;
281 widget_class->button_release_event = gtk_xpaned_button_release;
282 widget_class->motion_notify_event = gtk_xpaned_motion;
283 widget_class->size_request = gtk_xpaned_size_request;
284 widget_class->size_allocate = gtk_xpaned_size_allocate;
286 container_class->add = gtk_xpaned_add;
287 container_class->remove = gtk_xpaned_remove;
288 container_class->forall = gtk_xpaned_forall;
289 container_class->child_type = gtk_xpaned_child_type;
290 container_class->set_focus_child = gtk_xpaned_set_focus_child;
291 container_class->set_child_property = gtk_xpaned_set_child_property;
292 container_class->get_child_property = gtk_xpaned_get_child_property;
294 xpaned_class->cycle_child_focus = gtk_xpaned_cycle_child_focus;
295 xpaned_class->toggle_handle_focus = gtk_xpaned_toggle_handle_focus;
296 xpaned_class->move_handle = gtk_xpaned_move_handle;
297 xpaned_class->cycle_handle_focus = gtk_xpaned_cycle_handle_focus;
298 xpaned_class->accept_position = gtk_xpaned_accept_position;
299 xpaned_class->cancel_position = gtk_xpaned_cancel_position;
301 g_object_class_install_property (object_class,
303 g_param_spec_int ("x-position",
305 ("x-Position of paned separator in pixels (0 means all the way to the left)"),
309 G_PARAM_READABLE | G_PARAM_WRITABLE));
311 g_object_class_install_property (object_class,
313 g_param_spec_int ("y-position",
315 "y-Position of paned separator in pixels (0 means all the way to the top)",
319 G_PARAM_READABLE | G_PARAM_WRITABLE));
321 g_object_class_install_property (object_class,
323 g_param_spec_boolean ("position-set",
325 "TRUE if the Position property should be used",
327 G_PARAM_READABLE | G_PARAM_WRITABLE));
329 gtk_widget_class_install_style_property (widget_class,
330 g_param_spec_int ("handle-size",
338 * GtkXPaned:min-x-position:
340 * The smallest possible value for the x-position property. This property is derived from the
341 * size and shrinkability of the widget's children.
345 g_object_class_install_property (object_class,
347 g_param_spec_int ("min-x-position",
348 "Minimal x-Position",
349 "Smallest possible value for the \"x-position\" property",
356 * GtkXPaned:min-y-position:
358 * The smallest possible value for the y-position property. This property is derived from the
359 * size and shrinkability of the widget's children.
363 g_object_class_install_property (object_class,
365 g_param_spec_int ("min-y-position",
366 "Minimal y-Position",
367 "Smallest possible value for the \"y-position\" property",
374 * GtkPaned:max-x-position:
376 * The largest possible value for the x-position property. This property is derived from the
377 * size and shrinkability of the widget's children.
381 g_object_class_install_property (object_class,
383 g_param_spec_int ("max-x-position",
384 "Maximal x-Position",
385 "Largest possible value for the \"x-position\" property",
392 * GtkPaned:max-y-position:
394 * The largest possible value for the y-position property. This property is derived from the
395 * size and shrinkability of the widget's children.
399 g_object_class_install_property (object_class,
401 g_param_spec_int ("max-y-position",
402 "Maximal y-Position",
403 "Largest possible value for the \"y-position\" property",
412 * The "resize" child property determines whether the child expands and
413 * shrinks along with the paned widget.
417 gtk_container_class_install_child_property (container_class,
419 g_param_spec_boolean ("resize",
421 "If TRUE, the child expands and shrinks along with the paned widget",
428 * The "shrink" child property determines whether the child can be made
429 * smaller than its requisition.
433 gtk_container_class_install_child_property (container_class,
435 g_param_spec_boolean ("shrink",
437 "If TRUE, the child can be made smaller than its requisition",
441 signals [CYCLE_CHILD_FOCUS] = g_signal_new ("cycle-child-focus",
442 G_TYPE_FROM_CLASS (object_class),
443 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
444 G_STRUCT_OFFSET (GtkXPanedClass, cycle_child_focus),
446 psppire_marshal_BOOLEAN__BOOLEAN,
450 signals [TOGGLE_HANDLE_FOCUS] = g_signal_new ("toggle-handle-focus",
451 G_TYPE_FROM_CLASS (object_class),
452 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
453 G_STRUCT_OFFSET (GtkXPanedClass, toggle_handle_focus),
455 psppire_marshal_BOOLEAN__VOID,
458 signals[MOVE_HANDLE] = g_signal_new ("move-handle",
459 G_TYPE_FROM_CLASS (object_class),
460 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
461 G_STRUCT_OFFSET (GtkXPanedClass, move_handle),
463 psppire_marshal_BOOLEAN__ENUM,
465 GTK_TYPE_SCROLL_TYPE);
467 signals [CYCLE_HANDLE_FOCUS] = g_signal_new ("cycle-handle-focus",
468 G_TYPE_FROM_CLASS (object_class),
469 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
470 G_STRUCT_OFFSET (GtkXPanedClass, cycle_handle_focus),
472 psppire_marshal_BOOLEAN__BOOLEAN,
476 signals [ACCEPT_POSITION] = g_signal_new ("accept-position",
477 G_TYPE_FROM_CLASS (object_class),
478 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
479 G_STRUCT_OFFSET (GtkXPanedClass, accept_position),
481 psppire_marshal_BOOLEAN__VOID,
484 signals [CANCEL_POSITION] = g_signal_new ("cancel-position",
485 G_TYPE_FROM_CLASS (object_class),
486 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
487 G_STRUCT_OFFSET (GtkXPanedClass, cancel_position),
489 psppire_marshal_BOOLEAN__VOID,
492 binding_set = gtk_binding_set_by_class (class);
495 gtk_binding_entry_add_signal (binding_set,
497 "cycle-child-focus", 1,
498 G_TYPE_BOOLEAN, FALSE);
500 gtk_binding_entry_add_signal (binding_set,
501 GDK_F6, GDK_SHIFT_MASK,
502 "cycle-child-focus", 1,
503 G_TYPE_BOOLEAN, TRUE);
506 gtk_binding_entry_add_signal (binding_set,
508 "cycle-handle-focus", 1,
509 G_TYPE_BOOLEAN, FALSE);
511 gtk_binding_entry_add_signal (binding_set,
512 GDK_F8, GDK_SHIFT_MASK,
513 "cycle-handle-focus", 1,
514 G_TYPE_BOOLEAN, TRUE);
516 add_tab_bindings (binding_set, 0);
517 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
518 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
519 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
521 /* accept and cancel positions */
522 gtk_binding_entry_add_signal (binding_set,
524 "cancel-position", 0);
526 gtk_binding_entry_add_signal (binding_set,
528 "accept-position", 0);
530 gtk_binding_entry_add_signal (binding_set,
532 "accept-position", 0);
534 gtk_binding_entry_add_signal (binding_set,
536 "accept-position", 0);
538 gtk_binding_entry_add_signal (binding_set,
540 "accept-position", 0);
543 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
544 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
545 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
546 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
548 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
549 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
550 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
551 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
553 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
554 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
555 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
556 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
557 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
558 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
560 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
561 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
562 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
563 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
564 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
565 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
567 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
568 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
569 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
570 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
573 static GType gtk_xpaned_child_type (GtkContainer* container)
575 if (!GTK_XPANED (container)->top_left_child ||
576 !GTK_XPANED (container)->top_right_child ||
577 !GTK_XPANED (container)->bottom_left_child ||
578 !GTK_XPANED (container)->bottom_right_child)
579 return GTK_TYPE_WIDGET;
584 static void gtk_xpaned_init (GtkXPaned* xpaned)
586 GTK_WIDGET_SET_FLAGS (xpaned, GTK_NO_WINDOW | GTK_CAN_FOCUS);
588 xpaned->top_left_child = NULL;
589 xpaned->top_right_child = NULL;
590 xpaned->bottom_left_child = NULL;
591 xpaned->bottom_right_child = NULL;
592 xpaned->handle_east = NULL;
593 xpaned->handle_west = NULL;
594 xpaned->handle_north = NULL;
595 xpaned->handle_south = NULL;
596 xpaned->handle_middle = NULL;
597 xpaned->xor_gc = NULL;
598 xpaned->cursor_type_east = GDK_SB_V_DOUBLE_ARROW;
599 xpaned->cursor_type_west = GDK_SB_V_DOUBLE_ARROW;
600 xpaned->cursor_type_north = GDK_SB_H_DOUBLE_ARROW;
601 xpaned->cursor_type_south = GDK_SB_H_DOUBLE_ARROW;
602 xpaned->cursor_type_middle = GDK_FLEUR;
604 xpaned->handle_pos_east.width = 5;
605 xpaned->handle_pos_east.height = 5;
606 xpaned->handle_pos_west.width = 5;
607 xpaned->handle_pos_west.height = 5;
608 xpaned->handle_pos_north.width = 5;
609 xpaned->handle_pos_north.height = 5;
610 xpaned->handle_pos_south.width = 5;
611 xpaned->handle_pos_south.height = 5;
612 xpaned->handle_pos_middle.width = 5;
613 xpaned->handle_pos_middle.height = 5;
615 xpaned->position_set = FALSE;
616 xpaned->last_allocation.width = -1;
617 xpaned->last_allocation.height = -1;
618 xpaned->in_drag_vert = FALSE;
619 xpaned->in_drag_horiz = FALSE;
620 xpaned->in_drag_vert_and_horiz = FALSE;
622 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
623 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
624 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
625 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
627 xpaned->priv = g_new0 (GtkXPanedPrivate, 1);
628 xpaned->last_top_left_child_focus = NULL;
629 xpaned->last_top_right_child_focus = NULL;
630 xpaned->last_bottom_left_child_focus = NULL;
631 xpaned->last_bottom_right_child_focus = NULL;
632 xpaned->in_recursion = FALSE;
633 xpaned->handle_prelit = FALSE;
634 xpaned->original_position.x = -1;
635 xpaned->original_position.y = -1;
636 xpaned->unmaximized_position.x = -1;
637 xpaned->unmaximized_position.y = -1;
639 xpaned->handle_pos_east.x = -1;
640 xpaned->handle_pos_east.y = -1;
641 xpaned->handle_pos_west.x = -1;
642 xpaned->handle_pos_west.y = -1;
643 xpaned->handle_pos_north.x = -1;
644 xpaned->handle_pos_north.y = -1;
645 xpaned->handle_pos_south.x = -1;
646 xpaned->handle_pos_south.y = -1;
647 xpaned->handle_pos_middle.x = -1;
648 xpaned->handle_pos_middle.y = -1;
650 xpaned->drag_pos.x = -1;
651 xpaned->drag_pos.y = -1;
654 static void gtk_xpaned_size_request (GtkWidget* widget,
655 GtkRequisition* requisition)
657 GtkXPaned* xpaned = GTK_XPANED (widget);
658 GtkRequisition child_requisition;
660 requisition->width = 0;
661 requisition->height = 0;
663 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child))
665 gtk_widget_size_request (xpaned->top_left_child, &child_requisition);
667 requisition->width = child_requisition.width;
668 requisition->height = child_requisition.height;
671 if (xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child))
673 gtk_widget_size_request (xpaned->top_right_child, &child_requisition);
675 requisition->width += child_requisition.width;
676 requisition->height = MAX (requisition->height, child_requisition.height);
679 if (xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child))
681 gtk_widget_size_request (xpaned->bottom_left_child, &child_requisition);
683 requisition->width = MAX (requisition->width, child_requisition.width);
684 requisition->height += child_requisition.height;
687 if (xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
689 gtk_widget_size_request (xpaned->bottom_right_child, &child_requisition);
691 requisition->width = MAX (requisition->width, child_requisition.width);
692 requisition->height = MAX (requisition->height, child_requisition.height);
695 /* add 2 times the set border-width to the GtkXPaneds requisition */
696 requisition->width += GTK_CONTAINER (xpaned)->border_width * 2;
697 requisition->height += GTK_CONTAINER (xpaned)->border_width * 2;
699 /* also add the handle "thickness" to GtkXPaneds width- and height-requisitions */
700 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
701 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
702 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
703 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
707 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
708 requisition->width += handle_size;
709 requisition->height += handle_size;
714 gtk_xpaned_compute_position (GtkXPaned* xpaned,
715 const GtkAllocation* allocation,
716 GtkRequisition* top_left_child_req,
717 GtkRequisition* top_right_child_req,
718 GtkRequisition* bottom_left_child_req,
719 GtkRequisition* bottom_right_child_req);
722 static void gtk_xpaned_size_allocate (GtkWidget* widget,
723 GtkAllocation* allocation)
725 GtkXPaned* xpaned = GTK_XPANED (widget);
726 gint border_width = GTK_CONTAINER (xpaned)->border_width;
727 GtkAllocation top_left_child_allocation;
728 GtkAllocation top_right_child_allocation;
729 GtkAllocation bottom_left_child_allocation;
730 GtkAllocation bottom_right_child_allocation;
731 GtkRequisition top_left_child_requisition;
732 GtkRequisition top_right_child_requisition;
733 GtkRequisition bottom_left_child_requisition;
734 GtkRequisition bottom_right_child_requisition;
737 /* determine size of handle(s) */
738 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
740 widget->allocation = *allocation;
742 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
743 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
744 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
745 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
747 /* what sizes do the children want to be at least at */
748 gtk_widget_get_child_requisition (xpaned->top_left_child,
749 &top_left_child_requisition);
750 gtk_widget_get_child_requisition (xpaned->top_right_child,
751 &top_right_child_requisition);
752 gtk_widget_get_child_requisition (xpaned->bottom_left_child,
753 &bottom_left_child_requisition);
754 gtk_widget_get_child_requisition (xpaned->bottom_right_child,
755 &bottom_right_child_requisition);
757 /* determine the total requisition-sum of all requisitions of borders,
758 * handles, children etc. */
759 gtk_xpaned_compute_position (xpaned,
761 &top_left_child_requisition,
762 &top_right_child_requisition,
763 &bottom_left_child_requisition,
764 &bottom_right_child_requisition);
766 /* calculate the current positions and sizes of the handles */
767 xpaned->handle_pos_east.x = widget->allocation.x + border_width + xpaned->top_left_child_size.width + handle_size;
768 xpaned->handle_pos_east.y = widget->allocation.y + border_width + xpaned->top_left_child_size.height;
769 xpaned->handle_pos_east.width = widget->allocation.width - xpaned->top_left_child_size.width - 2 * border_width - handle_size;
770 xpaned->handle_pos_east.height = handle_size;
772 xpaned->handle_pos_west.x = widget->allocation.x + border_width;
773 xpaned->handle_pos_west.y = xpaned->handle_pos_east.y;
774 xpaned->handle_pos_west.width = widget->allocation.width - xpaned->handle_pos_east.width - 2 * border_width - handle_size;
775 xpaned->handle_pos_west.height = handle_size;
777 xpaned->handle_pos_north.x = xpaned->handle_pos_east.x - handle_size;
778 xpaned->handle_pos_north.y = widget->allocation.y + border_width;
779 xpaned->handle_pos_north.width = handle_size;
780 xpaned->handle_pos_north.height = xpaned->handle_pos_east.y - widget->allocation.y - border_width;
782 xpaned->handle_pos_south.x = xpaned->handle_pos_north.x;
783 xpaned->handle_pos_south.y = xpaned->handle_pos_east.y + handle_size;
784 xpaned->handle_pos_south.width = handle_size;
785 xpaned->handle_pos_south.height = widget->allocation.height - xpaned->handle_pos_north.height - 2 * border_width - handle_size;
789 xpaned->handle_pos_middle.x = xpaned->handle_pos_north.x ;
790 xpaned->handle_pos_middle.y = xpaned->handle_pos_east.y ;
791 xpaned->handle_pos_middle.width = handle_size + CENTRUM ;
792 xpaned->handle_pos_middle.height = handle_size + CENTRUM;
794 /* set allocation for top-left child */
795 top_left_child_allocation.x = widget->allocation.x + border_width;
796 top_left_child_allocation.y = widget->allocation.y + border_width;
797 top_left_child_allocation.width = xpaned->handle_pos_west.width;
798 top_left_child_allocation.height = xpaned->handle_pos_north.height;
800 /* set allocation for top-right child */
801 top_right_child_allocation.x = widget->allocation.x + border_width + handle_size + top_left_child_allocation.width;
802 top_right_child_allocation.y = widget->allocation.y + border_width;
803 top_right_child_allocation.width = xpaned->handle_pos_east.width;
804 top_right_child_allocation.height = xpaned->handle_pos_north.height;
806 /* set allocation for bottom-left child */
807 bottom_left_child_allocation.x = xpaned->handle_pos_west.x;
808 bottom_left_child_allocation.y = xpaned->handle_pos_south.y;
809 bottom_left_child_allocation.width = xpaned->handle_pos_west.width;
810 bottom_left_child_allocation.height = xpaned->handle_pos_south.height;
812 /* set allocation for bottom-right child */
813 bottom_right_child_allocation.x = top_right_child_allocation.x;
814 bottom_right_child_allocation.y = bottom_left_child_allocation.y;
815 bottom_right_child_allocation.width = xpaned->handle_pos_east.width;
816 bottom_right_child_allocation.height = xpaned->handle_pos_south.height;
818 if (GTK_WIDGET_REALIZED (widget))
820 if (GTK_WIDGET_MAPPED (widget))
822 gdk_window_show (xpaned->handle_east);
823 gdk_window_show (xpaned->handle_west);
824 gdk_window_show (xpaned->handle_north);
825 gdk_window_show (xpaned->handle_south);
826 gdk_window_show (xpaned->handle_middle);
829 gdk_window_move_resize (xpaned->handle_east,
830 xpaned->handle_pos_east.x,
831 xpaned->handle_pos_east.y,
832 xpaned->handle_pos_east.width,
833 xpaned->handle_pos_east.height);
835 gdk_window_move_resize (xpaned->handle_west,
836 xpaned->handle_pos_west.x,
837 xpaned->handle_pos_west.y,
838 xpaned->handle_pos_west.width,
839 xpaned->handle_pos_west.height);
841 gdk_window_move_resize (xpaned->handle_north,
842 xpaned->handle_pos_north.x,
843 xpaned->handle_pos_north.y,
844 xpaned->handle_pos_north.width,
845 xpaned->handle_pos_north.height);
847 gdk_window_move_resize (xpaned->handle_south,
848 xpaned->handle_pos_south.x,
849 xpaned->handle_pos_south.y,
850 xpaned->handle_pos_south.width,
851 xpaned->handle_pos_south.height);
853 gdk_window_move_resize (xpaned->handle_middle,
854 xpaned->handle_pos_middle.x,
855 xpaned->handle_pos_middle.y,
856 xpaned->handle_pos_middle.width,
857 xpaned->handle_pos_middle.height);
860 /* Now allocate the childen, making sure, when resizing not to
861 * overlap the windows
863 if (GTK_WIDGET_MAPPED (widget))
865 gtk_widget_size_allocate (xpaned->top_right_child, &top_right_child_allocation);
866 gtk_widget_size_allocate (xpaned->top_left_child, &top_left_child_allocation);
867 gtk_widget_size_allocate (xpaned->bottom_left_child, &bottom_left_child_allocation);
868 gtk_widget_size_allocate (xpaned->bottom_right_child, &bottom_right_child_allocation);
873 static void gtk_xpaned_set_property (GObject* object,
878 GtkXPaned* xpaned = GTK_XPANED (object);
882 case PROP_X_POSITION:
883 gtk_xpaned_set_position_x (xpaned, g_value_get_int (value));
886 case PROP_Y_POSITION:
887 gtk_xpaned_set_position_y (xpaned, g_value_get_int (value));
890 case PROP_POSITION_SET:
891 xpaned->position_set = g_value_get_boolean (value);
892 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
896 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
901 static void gtk_xpaned_get_property (GObject* object,
906 GtkXPaned* xpaned = GTK_XPANED (object);
910 case PROP_X_POSITION:
911 g_value_set_int (value, xpaned->top_left_child_size.width);
914 case PROP_Y_POSITION:
915 g_value_set_int (value, xpaned->top_left_child_size.height);
918 case PROP_POSITION_SET:
919 g_value_set_boolean (value, xpaned->position_set);
922 case PROP_MIN_X_POSITION:
923 g_value_set_int (value, xpaned->min_position.x);
926 case PROP_MIN_Y_POSITION:
927 g_value_set_int (value, xpaned->min_position.y);
930 case PROP_MAX_X_POSITION:
931 g_value_set_int (value, xpaned->max_position.x);
934 case PROP_MAX_Y_POSITION:
935 g_value_set_int (value, xpaned->max_position.y);
939 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
944 static void gtk_xpaned_set_child_property (GtkContainer* container,
950 GtkXPaned* xpaned = GTK_XPANED (container);
951 gboolean old_value = FALSE;
952 gboolean new_value = FALSE;
954 g_assert (child == xpaned->top_left_child ||
955 child == xpaned->top_right_child ||
956 child == xpaned->bottom_left_child ||
957 child == xpaned->bottom_right_child);
959 new_value = g_value_get_boolean (value);
963 case CHILD_PROP_RESIZE:
964 if (child == xpaned->top_left_child)
966 old_value = xpaned->top_left_child_resize;
967 xpaned->top_left_child_resize = new_value;
969 else if (child == xpaned->top_right_child)
971 old_value = xpaned->top_right_child_resize;
972 xpaned->top_right_child_resize = new_value;
974 else if (child == xpaned->bottom_left_child)
976 old_value = xpaned->bottom_left_child_resize;
977 xpaned->bottom_left_child_resize = new_value;
979 else if (child == xpaned->bottom_right_child)
981 old_value = xpaned->bottom_right_child_resize;
982 xpaned->bottom_right_child_resize = new_value;
986 case CHILD_PROP_SHRINK :
987 if (child == xpaned->top_left_child)
989 old_value = xpaned->top_left_child_shrink;
990 xpaned->top_left_child_shrink = new_value;
992 else if (child == xpaned->top_right_child)
994 old_value = xpaned->top_right_child_shrink;
995 xpaned->top_right_child_shrink = new_value;
997 else if (child == xpaned->bottom_left_child)
999 old_value = xpaned->bottom_left_child_shrink;
1000 xpaned->bottom_left_child_shrink = new_value;
1002 else if (child == xpaned->bottom_right_child)
1004 old_value = xpaned->bottom_right_child_shrink;
1005 xpaned->bottom_right_child_shrink = new_value;
1010 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1013 old_value = -1; /* quiet gcc */
1017 if (old_value != new_value)
1018 gtk_widget_queue_resize (GTK_WIDGET (container));
1021 static void gtk_xpaned_get_child_property (GtkContainer* container,
1027 GtkXPaned* xpaned = GTK_XPANED (container);
1029 g_assert (child == xpaned->top_left_child ||
1030 child == xpaned->top_right_child ||
1031 child == xpaned->bottom_left_child ||
1032 child == xpaned->bottom_right_child);
1034 switch (property_id)
1036 case CHILD_PROP_RESIZE :
1037 if (child == xpaned->top_left_child)
1038 g_value_set_boolean (value, xpaned->top_left_child_resize);
1039 else if (child == xpaned->top_right_child)
1040 g_value_set_boolean (value, xpaned->top_right_child_resize);
1041 else if (child == xpaned->bottom_left_child)
1042 g_value_set_boolean (value, xpaned->bottom_left_child_resize);
1043 else if (child == xpaned->bottom_right_child)
1044 g_value_set_boolean (value, xpaned->bottom_right_child_resize);
1047 case CHILD_PROP_SHRINK :
1048 if (child == xpaned->top_left_child)
1049 g_value_set_boolean (value, xpaned->top_left_child_shrink);
1050 else if (child == xpaned->top_right_child)
1051 g_value_set_boolean (value, xpaned->top_right_child_shrink);
1052 else if (child == xpaned->bottom_left_child)
1053 g_value_set_boolean (value, xpaned->bottom_left_child_shrink);
1054 else if (child == xpaned->bottom_right_child)
1055 g_value_set_boolean (value, xpaned->bottom_right_child_shrink);
1059 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1066 static void gtk_xpaned_finalize (GObject* object)
1068 GtkXPaned* xpaned = GTK_XPANED (object);
1070 gtk_xpaned_set_saved_focus (xpaned, NULL);
1071 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1073 g_free (xpaned->priv);
1075 G_OBJECT_CLASS (parent_class)->finalize (object);
1078 static void gtk_xpaned_realize (GtkWidget* widget)
1081 GdkWindowAttr attributes_east;
1082 GdkWindowAttr attributes_west;
1083 GdkWindowAttr attributes_north;
1084 GdkWindowAttr attributes_south;
1085 GdkWindowAttr attributes_middle;
1086 gint attributes_mask_east;
1087 gint attributes_mask_west;
1088 gint attributes_mask_north;
1089 gint attributes_mask_south;
1090 gint attributes_mask_middle;
1092 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1093 xpaned = GTK_XPANED (widget);
1095 widget->window = gtk_widget_get_parent_window (widget);
1096 g_object_ref (widget->window);
1098 attributes_east.window_type = GDK_WINDOW_CHILD;
1099 attributes_west.window_type = GDK_WINDOW_CHILD;
1100 attributes_north.window_type = GDK_WINDOW_CHILD;
1101 attributes_south.window_type = GDK_WINDOW_CHILD;
1102 attributes_middle.window_type = GDK_WINDOW_CHILD;
1104 attributes_east.wclass = GDK_INPUT_ONLY;
1105 attributes_west.wclass = GDK_INPUT_ONLY;
1106 attributes_north.wclass = GDK_INPUT_ONLY;
1107 attributes_south.wclass = GDK_INPUT_ONLY;
1108 attributes_middle.wclass = GDK_INPUT_ONLY;
1110 attributes_east.x = xpaned->handle_pos_east.x;
1111 attributes_east.y = xpaned->handle_pos_east.y;
1112 attributes_east.width = xpaned->handle_pos_east.width;
1113 attributes_east.height = xpaned->handle_pos_east.height;
1115 attributes_west.x = xpaned->handle_pos_west.x;
1116 attributes_west.y = xpaned->handle_pos_west.y;
1117 attributes_west.width = xpaned->handle_pos_west.width;
1118 attributes_west.height = xpaned->handle_pos_west.height;
1120 attributes_north.x = xpaned->handle_pos_north.x;
1121 attributes_north.y = xpaned->handle_pos_north.y;
1122 attributes_north.width = xpaned->handle_pos_north.width;
1123 attributes_north.height = xpaned->handle_pos_north.height;
1125 attributes_south.x = xpaned->handle_pos_south.x;
1126 attributes_south.y = xpaned->handle_pos_south.y;
1127 attributes_south.width = xpaned->handle_pos_south.width;
1128 attributes_south.height = xpaned->handle_pos_south.height;
1130 attributes_middle.x = xpaned->handle_pos_middle.x;
1131 attributes_middle.y = xpaned->handle_pos_middle.y;
1132 attributes_middle.width = xpaned->handle_pos_middle.width;
1133 attributes_middle.height = xpaned->handle_pos_middle.height;
1135 attributes_east.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1136 xpaned->cursor_type_east);
1137 attributes_west.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1138 xpaned->cursor_type_west);
1139 attributes_north.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1140 xpaned->cursor_type_north);
1141 attributes_south.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1142 xpaned->cursor_type_south);
1143 attributes_middle.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1144 xpaned->cursor_type_middle);
1146 attributes_east.event_mask = gtk_widget_get_events (widget);
1147 attributes_west.event_mask = gtk_widget_get_events (widget);
1148 attributes_north.event_mask = gtk_widget_get_events (widget);
1149 attributes_south.event_mask = gtk_widget_get_events (widget);
1150 attributes_middle.event_mask = gtk_widget_get_events (widget);
1152 attributes_east.event_mask |= (GDK_BUTTON_PRESS_MASK |
1153 GDK_BUTTON_RELEASE_MASK |
1154 GDK_ENTER_NOTIFY_MASK |
1155 GDK_LEAVE_NOTIFY_MASK |
1156 GDK_POINTER_MOTION_MASK |
1157 GDK_POINTER_MOTION_HINT_MASK);
1158 attributes_west.event_mask |= (GDK_BUTTON_PRESS_MASK |
1159 GDK_BUTTON_RELEASE_MASK |
1160 GDK_ENTER_NOTIFY_MASK |
1161 GDK_LEAVE_NOTIFY_MASK |
1162 GDK_POINTER_MOTION_MASK |
1163 GDK_POINTER_MOTION_HINT_MASK);
1164 attributes_north.event_mask |= (GDK_BUTTON_PRESS_MASK |
1165 GDK_BUTTON_RELEASE_MASK |
1166 GDK_ENTER_NOTIFY_MASK |
1167 GDK_LEAVE_NOTIFY_MASK |
1168 GDK_POINTER_MOTION_MASK |
1169 GDK_POINTER_MOTION_HINT_MASK);
1170 attributes_south.event_mask |= (GDK_BUTTON_PRESS_MASK |
1171 GDK_BUTTON_RELEASE_MASK |
1172 GDK_ENTER_NOTIFY_MASK |
1173 GDK_LEAVE_NOTIFY_MASK |
1174 GDK_POINTER_MOTION_MASK |
1175 GDK_POINTER_MOTION_HINT_MASK);
1176 attributes_middle.event_mask |= (GDK_BUTTON_PRESS_MASK |
1177 GDK_BUTTON_RELEASE_MASK |
1178 GDK_ENTER_NOTIFY_MASK |
1179 GDK_LEAVE_NOTIFY_MASK |
1180 GDK_POINTER_MOTION_MASK |
1181 GDK_POINTER_MOTION_HINT_MASK);
1183 attributes_mask_east = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1184 attributes_mask_west = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1185 attributes_mask_north = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1186 attributes_mask_south = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1187 attributes_mask_middle = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1189 xpaned->handle_east = gdk_window_new (widget->window,
1191 attributes_mask_east);
1192 xpaned->handle_west = gdk_window_new (widget->window,
1194 attributes_mask_west);
1195 xpaned->handle_north = gdk_window_new (widget->window,
1197 attributes_mask_north);
1198 xpaned->handle_south = gdk_window_new (widget->window,
1200 attributes_mask_south);
1201 xpaned->handle_middle = gdk_window_new (widget->window,
1203 attributes_mask_middle);
1205 gdk_window_set_user_data (xpaned->handle_east, xpaned);
1206 gdk_window_set_user_data (xpaned->handle_west, xpaned);
1207 gdk_window_set_user_data (xpaned->handle_north, xpaned);
1208 gdk_window_set_user_data (xpaned->handle_south, xpaned);
1209 gdk_window_set_user_data (xpaned->handle_middle, xpaned);
1211 gdk_cursor_unref (attributes_east.cursor);
1212 gdk_cursor_unref (attributes_west.cursor);
1213 gdk_cursor_unref (attributes_north.cursor);
1214 gdk_cursor_unref (attributes_south.cursor);
1215 gdk_cursor_unref (attributes_middle.cursor);
1217 widget->style = gtk_style_attach (widget->style, widget->window);
1219 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
1220 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
1221 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
1222 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
1224 gdk_window_show (xpaned->handle_east);
1225 gdk_window_show (xpaned->handle_west);
1226 gdk_window_show (xpaned->handle_north);
1227 gdk_window_show (xpaned->handle_south);
1228 gdk_window_show (xpaned->handle_middle);
1232 static void gtk_xpaned_unrealize (GtkWidget *widget)
1234 GtkXPaned* xpaned = GTK_XPANED (widget);
1238 g_object_unref (xpaned->xor_gc);
1239 xpaned->xor_gc = NULL;
1242 if (xpaned->handle_east)
1244 gdk_window_set_user_data (xpaned->handle_east, NULL);
1245 gdk_window_destroy (xpaned->handle_east);
1246 xpaned->handle_east = NULL;
1249 if (xpaned->handle_west)
1251 gdk_window_set_user_data (xpaned->handle_west, NULL);
1252 gdk_window_destroy (xpaned->handle_west);
1253 xpaned->handle_west = NULL;
1256 if (xpaned->handle_north)
1258 gdk_window_set_user_data (xpaned->handle_north, NULL);
1259 gdk_window_destroy (xpaned->handle_north);
1260 xpaned->handle_north = NULL;
1263 if (xpaned->handle_south)
1265 gdk_window_set_user_data (xpaned->handle_south, NULL);
1266 gdk_window_destroy (xpaned->handle_south);
1267 xpaned->handle_south = NULL;
1270 if (xpaned->handle_middle)
1272 gdk_window_set_user_data (xpaned->handle_middle, NULL);
1273 gdk_window_destroy (xpaned->handle_middle);
1274 xpaned->handle_middle = NULL;
1277 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
1278 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
1279 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
1280 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
1281 gtk_xpaned_set_saved_focus (xpaned, NULL);
1282 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1284 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1285 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1288 static void gtk_xpaned_map (GtkWidget* widget)
1290 GtkXPaned* xpaned = GTK_XPANED (widget);
1292 gdk_window_show (xpaned->handle_east);
1293 gdk_window_show (xpaned->handle_west);
1294 gdk_window_show (xpaned->handle_north);
1295 gdk_window_show (xpaned->handle_south);
1296 gdk_window_show (xpaned->handle_middle);
1298 GTK_WIDGET_CLASS (parent_class)->map (widget);
1301 static void gtk_xpaned_unmap (GtkWidget* widget)
1303 GtkXPaned* xpaned = GTK_XPANED (widget);
1305 gdk_window_hide (xpaned->handle_east);
1306 gdk_window_hide (xpaned->handle_west);
1307 gdk_window_hide (xpaned->handle_north);
1308 gdk_window_hide (xpaned->handle_south);
1309 gdk_window_hide (xpaned->handle_middle);
1311 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1314 static gboolean gtk_xpaned_expose (GtkWidget* widget,
1315 GdkEventExpose* event)
1317 GtkXPaned* xpaned = GTK_XPANED (widget);
1319 GdkRectangle horizontalClipArea;
1320 GdkRectangle verticalClipArea;
1322 /* determine size of handle(s) */
1323 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1325 /* I want the handle-"thickness" to be at least 3 */
1326 g_assert (handle_size >= 3);
1328 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget) &&
1329 xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
1330 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
1331 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
1332 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
1336 if (gtk_widget_is_focus (widget))
1337 state = GTK_STATE_SELECTED;
1338 else if (xpaned->handle_prelit)
1339 state = GTK_STATE_PRELIGHT;
1341 state = GTK_WIDGET_STATE (widget);
1343 horizontalClipArea.x = xpaned->handle_pos_west.x;
1344 horizontalClipArea.y = xpaned->handle_pos_west.y;
1345 horizontalClipArea.width = xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width;
1346 horizontalClipArea.height = handle_size;
1348 verticalClipArea.x = xpaned->handle_pos_north.x;
1349 verticalClipArea.y = xpaned->handle_pos_north.y;
1350 verticalClipArea.width = handle_size;
1351 verticalClipArea.height = xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height;
1353 gtk_paint_handle (widget->style,
1357 &horizontalClipArea,
1360 xpaned->handle_pos_east.x - handle_size - 256 / 2,
1361 xpaned->handle_pos_west.y + 1,
1364 /*xpaned->handle_pos_west.x,
1365 xpaned->handle_pos_west.y + 1,
1366 xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width,
1368 GTK_ORIENTATION_HORIZONTAL);
1369 gtk_paint_handle (widget->style,
1376 xpaned->handle_pos_north.x + 1,
1377 xpaned->handle_pos_south.y - handle_size - 256 / 2,
1380 /*xpaned->handle_pos_north.x + 1,
1381 xpaned->handle_pos_north.y,
1383 xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height,*/
1384 GTK_ORIENTATION_VERTICAL);
1387 /* Chain up to draw children */
1388 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
1393 static gboolean is_rtl (GtkXPaned* xpaned)
1395 if (gtk_widget_get_direction (GTK_WIDGET (xpaned)) == GTK_TEXT_DIR_RTL)
1401 static void update_drag (GtkXPaned* xpaned)
1405 GtkRequisition size;
1407 gtk_widget_get_pointer (GTK_WIDGET (xpaned), &pos.x, &pos.y);
1409 if (xpaned->in_drag_vert)
1411 pos.y -= xpaned->drag_pos.y;
1413 if (is_rtl (xpaned))
1415 gtk_widget_style_get (GTK_WIDGET (xpaned),
1416 "handle-size", &handle_size,
1419 size.height = GTK_WIDGET (xpaned)->allocation.height - pos.y - handle_size;
1423 size.height = pos.y;
1426 size.height -= GTK_CONTAINER (xpaned)->border_width;
1428 size.height = CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1430 if (size.height != xpaned->top_left_child_size.height)
1431 gtk_xpaned_set_position_y (xpaned, size.height);
1434 if (xpaned->in_drag_horiz)
1436 pos.x -= xpaned->drag_pos.x;
1438 if (is_rtl (xpaned))
1440 gtk_widget_style_get (GTK_WIDGET (xpaned),
1441 "handle-size", &handle_size,
1444 size.width = GTK_WIDGET (xpaned)->allocation.width - pos.x - handle_size;
1451 size.width -= GTK_CONTAINER (xpaned)->border_width;
1453 size.width = CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1455 if (size.width != xpaned->top_left_child_size.width)
1456 gtk_xpaned_set_position_x (xpaned, size.width);
1459 if (xpaned->in_drag_vert_and_horiz)
1461 pos.x -= xpaned->drag_pos.x;
1462 pos.y -= xpaned->drag_pos.y;
1464 if (is_rtl (xpaned))
1466 gtk_widget_style_get (GTK_WIDGET (xpaned),
1467 "handle-size", &handle_size,
1470 size.width = GTK_WIDGET (xpaned)->allocation.width - pos.x - handle_size;
1471 size.height = GTK_WIDGET (xpaned)->allocation.height - pos.y - handle_size;
1476 size.height = pos.y;
1479 size.width -= GTK_CONTAINER (xpaned)->border_width;
1480 size.height -= GTK_CONTAINER (xpaned)->border_width;
1482 size.width = CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1483 size.height = CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1485 if (size.width != xpaned->top_left_child_size.width)
1486 gtk_xpaned_set_position_x (xpaned, size.width);
1488 if (size.height != xpaned->top_left_child_size.height)
1489 gtk_xpaned_set_position_y (xpaned, size.height);
1493 static gboolean gtk_xpaned_enter (GtkWidget* widget, GdkEventCrossing* event)
1495 GtkXPaned* xpaned = GTK_XPANED (widget);
1497 if (xpaned->in_drag_vert ||
1498 xpaned->in_drag_horiz ||
1499 xpaned->in_drag_vert_and_horiz)
1500 update_drag (xpaned);
1503 xpaned->handle_prelit = TRUE;
1505 gtk_widget_queue_draw_area (widget,
1506 xpaned->handle_pos_east.x,
1507 xpaned->handle_pos_east.y,
1508 xpaned->handle_pos_east.width,
1509 xpaned->handle_pos_east.height);
1511 gtk_widget_queue_draw_area (widget,
1512 xpaned->handle_pos_west.x,
1513 xpaned->handle_pos_west.y,
1514 xpaned->handle_pos_west.width,
1515 xpaned->handle_pos_west.height);
1517 gtk_widget_queue_draw_area (widget,
1518 xpaned->handle_pos_north.x,
1519 xpaned->handle_pos_north.y,
1520 xpaned->handle_pos_north.width,
1521 xpaned->handle_pos_north.height);
1523 gtk_widget_queue_draw_area (widget,
1524 xpaned->handle_pos_south.x,
1525 xpaned->handle_pos_south.y,
1526 xpaned->handle_pos_south.width,
1527 xpaned->handle_pos_south.height);
1529 gtk_widget_queue_draw_area (widget,
1530 xpaned->handle_pos_middle.x,
1531 xpaned->handle_pos_middle.y,
1532 xpaned->handle_pos_middle.width,
1533 xpaned->handle_pos_middle.height);
1539 static gboolean gtk_xpaned_leave (GtkWidget* widget, GdkEventCrossing* event)
1541 GtkXPaned* xpaned = GTK_XPANED (widget);
1543 if (xpaned->in_drag_vert ||
1544 xpaned->in_drag_horiz ||
1545 xpaned->in_drag_vert_and_horiz)
1546 update_drag (xpaned);
1549 xpaned->handle_prelit = FALSE;
1551 gtk_widget_queue_draw_area (widget,
1552 xpaned->handle_pos_east.x,
1553 xpaned->handle_pos_east.y,
1554 xpaned->handle_pos_east.width,
1555 xpaned->handle_pos_east.height);
1557 gtk_widget_queue_draw_area (widget,
1558 xpaned->handle_pos_west.x,
1559 xpaned->handle_pos_west.y,
1560 xpaned->handle_pos_west.width,
1561 xpaned->handle_pos_west.height);
1563 gtk_widget_queue_draw_area (widget,
1564 xpaned->handle_pos_north.x,
1565 xpaned->handle_pos_north.y,
1566 xpaned->handle_pos_north.width,
1567 xpaned->handle_pos_north.height);
1569 gtk_widget_queue_draw_area (widget,
1570 xpaned->handle_pos_south.x,
1571 xpaned->handle_pos_south.y,
1572 xpaned->handle_pos_south.width,
1573 xpaned->handle_pos_south.height);
1575 gtk_widget_queue_draw_area (widget,
1576 xpaned->handle_pos_middle.x,
1577 xpaned->handle_pos_middle.y,
1578 xpaned->handle_pos_middle.width,
1579 xpaned->handle_pos_middle.height);
1585 static gboolean gtk_xpaned_focus (GtkWidget* widget, GtkDirectionType direction)
1589 /* This is a hack, but how can this be done without
1590 * excessive cut-and-paste from gtkcontainer.c?
1593 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1594 retval = (* GTK_WIDGET_CLASS (parent_class)->focus) (widget, direction);
1595 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1600 static gboolean gtk_xpaned_button_press (GtkWidget* widget,
1601 GdkEventButton* event)
1603 GtkXPaned* xpaned = GTK_XPANED (widget);
1605 /* if any child is currently maximized, jump right back */
1606 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
1607 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
1608 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
1609 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
1612 /* if user is dragging the handles around */
1613 if (!xpaned->in_drag_vert_and_horiz &&
1614 event->window != xpaned->handle_east &&
1615 event->window != xpaned->handle_west &&
1616 event->window != xpaned->handle_north &&
1617 event->window != xpaned->handle_south &&
1618 event->window == xpaned->handle_middle &&
1621 xpaned->in_drag_vert_and_horiz = TRUE;
1623 /* We need a server grab here, not gtk_grab_add(), since
1624 * we don't want to pass events on to the widget's children */
1625 if (gdk_pointer_grab (xpaned->handle_middle,
1627 GDK_POINTER_MOTION_HINT_MASK
1628 | GDK_BUTTON1_MOTION_MASK
1629 | GDK_BUTTON_RELEASE_MASK
1630 | GDK_ENTER_NOTIFY_MASK
1631 | GDK_LEAVE_NOTIFY_MASK,
1634 event->time) == GDK_GRAB_SUCCESS)
1638 xpaned->drag_pos.x = event->x;
1639 xpaned->drag_pos.y = event->y;
1643 else if (!xpaned->in_drag_vert &&
1644 event->window == xpaned->handle_east &&
1645 event->window != xpaned->handle_west &&
1646 event->window != xpaned->handle_north &&
1647 event->window != xpaned->handle_south &&
1648 event->window != xpaned->handle_middle &&
1651 xpaned->in_drag_vert = TRUE;
1653 /* We need a server grab here, not gtk_grab_add(), since
1654 * we don't want to pass events on to the widget's children */
1655 if (gdk_pointer_grab (xpaned->handle_east,
1657 GDK_POINTER_MOTION_HINT_MASK
1658 | GDK_BUTTON1_MOTION_MASK
1659 | GDK_BUTTON_RELEASE_MASK
1660 | GDK_ENTER_NOTIFY_MASK
1661 | GDK_LEAVE_NOTIFY_MASK,
1664 event->time) == GDK_GRAB_SUCCESS)
1668 xpaned->drag_pos.y = event->y;
1672 else if (!xpaned->in_drag_vert &&
1673 event->window != xpaned->handle_east &&
1674 event->window == xpaned->handle_west &&
1675 event->window != xpaned->handle_north &&
1676 event->window != xpaned->handle_south &&
1677 event->window != xpaned->handle_middle &&
1680 xpaned->in_drag_vert = TRUE;
1682 /* We need a server grab here, not gtk_grab_add(), since
1683 * we don't want to pass events on to the widget's children */
1684 if (gdk_pointer_grab (xpaned->handle_west,
1686 GDK_POINTER_MOTION_HINT_MASK
1687 | GDK_BUTTON1_MOTION_MASK
1688 | GDK_BUTTON_RELEASE_MASK
1689 | GDK_ENTER_NOTIFY_MASK
1690 | GDK_LEAVE_NOTIFY_MASK,
1693 event->time) == GDK_GRAB_SUCCESS)
1697 xpaned->drag_pos.y = event->y;
1701 else if (!xpaned->in_drag_horiz &&
1702 event->window != xpaned->handle_east &&
1703 event->window != xpaned->handle_west &&
1704 event->window == xpaned->handle_north &&
1705 event->window != xpaned->handle_south &&
1706 event->window != xpaned->handle_middle &&
1709 xpaned->in_drag_horiz = TRUE;
1711 /* We need a server grab here, not gtk_grab_add(), since
1712 * we don't want to pass events on to the widget's children */
1713 if (gdk_pointer_grab (xpaned->handle_north,
1715 GDK_POINTER_MOTION_HINT_MASK
1716 | GDK_BUTTON1_MOTION_MASK
1717 | GDK_BUTTON_RELEASE_MASK
1718 | GDK_ENTER_NOTIFY_MASK
1719 | GDK_LEAVE_NOTIFY_MASK,
1722 event->time) == GDK_GRAB_SUCCESS)
1726 xpaned->drag_pos.x = event->x;
1730 else if (!xpaned->in_drag_horiz &&
1731 event->window != xpaned->handle_east &&
1732 event->window != xpaned->handle_west &&
1733 event->window != xpaned->handle_north &&
1734 event->window == xpaned->handle_south &&
1735 event->window != xpaned->handle_middle &&
1738 xpaned->in_drag_horiz = 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_south,
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,
1751 event->time) == GDK_GRAB_SUCCESS)
1755 xpaned->drag_pos.x = event->x;
1762 static gboolean gtk_xpaned_button_release (GtkWidget* widget,
1763 GdkEventButton* event)
1765 GtkXPaned* xpaned = GTK_XPANED (widget);
1767 if (xpaned->in_drag_vert && (event->button == 1))
1769 xpaned->in_drag_vert = FALSE;
1770 xpaned->drag_pos.y = -1;
1771 xpaned->position_set = TRUE;
1772 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1776 else if (xpaned->in_drag_horiz && (event->button == 1))
1778 xpaned->in_drag_horiz = FALSE;
1779 xpaned->drag_pos.x = -1;
1780 xpaned->position_set = TRUE;
1781 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1785 else if (xpaned->in_drag_vert_and_horiz && (event->button == 1))
1787 xpaned->in_drag_vert_and_horiz = FALSE;
1788 xpaned->drag_pos.x = -1;
1789 xpaned->drag_pos.y = -1;
1790 xpaned->position_set = TRUE;
1791 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1799 static gboolean gtk_xpaned_motion (GtkWidget* widget, GdkEventMotion* event)
1801 GtkXPaned* xpaned = GTK_XPANED (widget);
1803 if (xpaned->in_drag_vert ||
1804 xpaned->in_drag_horiz ||
1805 xpaned->in_drag_vert_and_horiz)
1808 update_drag (xpaned);
1815 void gtk_xpaned_add_top_left (GtkXPaned* xpaned, GtkWidget *widget)
1817 gtk_xpaned_pack_top_left (xpaned, widget, FALSE, TRUE);
1820 void gtk_xpaned_add_top_right (GtkXPaned* xpaned, GtkWidget *widget)
1822 gtk_xpaned_pack_top_right (xpaned, widget, FALSE, TRUE);
1825 void gtk_xpaned_add_bottom_left (GtkXPaned* xpaned, GtkWidget *widget)
1827 gtk_xpaned_pack_bottom_left (xpaned, widget, FALSE, TRUE);
1830 void gtk_xpaned_add_bottom_right (GtkXPaned* xpaned, GtkWidget *widget)
1832 gtk_xpaned_pack_bottom_right (xpaned, widget, FALSE, TRUE);
1835 void gtk_xpaned_pack_top_left (GtkXPaned* xpaned,
1840 g_return_if_fail (GTK_IS_XPANED (xpaned));
1841 g_return_if_fail (GTK_IS_WIDGET (child));
1843 if (!xpaned->top_left_child)
1845 xpaned->top_left_child = child;
1846 xpaned->top_left_child_resize = resize;
1847 xpaned->top_left_child_shrink = shrink;
1849 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1853 void gtk_xpaned_pack_top_right (GtkXPaned* xpaned,
1858 g_return_if_fail (GTK_IS_XPANED (xpaned));
1859 g_return_if_fail (GTK_IS_WIDGET (child));
1861 if (!xpaned->top_right_child)
1863 xpaned->top_right_child = child;
1864 xpaned->top_right_child_resize = resize;
1865 xpaned->top_right_child_shrink = shrink;
1867 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1871 void gtk_xpaned_pack_bottom_left (GtkXPaned* xpaned,
1876 g_return_if_fail (GTK_IS_XPANED (xpaned));
1877 g_return_if_fail (GTK_IS_WIDGET (child));
1879 if (!xpaned->bottom_left_child)
1881 xpaned->bottom_left_child = child;
1882 xpaned->bottom_left_child_resize = resize;
1883 xpaned->bottom_left_child_shrink = shrink;
1885 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1889 void gtk_xpaned_pack_bottom_right (GtkXPaned* xpaned,
1894 g_return_if_fail (GTK_IS_XPANED (xpaned));
1895 g_return_if_fail (GTK_IS_WIDGET (child));
1897 if (!xpaned->bottom_right_child)
1899 xpaned->bottom_right_child = child;
1900 xpaned->bottom_right_child_resize = resize;
1901 xpaned->bottom_right_child_shrink = shrink;
1903 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1907 static void gtk_xpaned_add (GtkContainer* container, GtkWidget* widget)
1911 g_return_if_fail (GTK_IS_XPANED (container));
1913 xpaned = GTK_XPANED (container);
1915 if (!xpaned->top_left_child)
1916 gtk_xpaned_add_top_left (xpaned, widget);
1917 else if (!xpaned->top_right_child)
1918 gtk_xpaned_add_top_right (xpaned, widget);
1919 else if (!xpaned->bottom_left_child)
1920 gtk_xpaned_add_bottom_left (xpaned, widget);
1921 else if (!xpaned->bottom_right_child)
1922 gtk_xpaned_add_bottom_right (xpaned, widget);
1924 g_warning ("GtkXPaned cannot have more than 4 children\n");
1927 static void gtk_xpaned_remove (GtkContainer* container, GtkWidget* widget)
1930 gboolean was_visible;
1932 xpaned = GTK_XPANED (container);
1933 was_visible = GTK_WIDGET_VISIBLE (widget);
1935 if (xpaned->top_left_child == widget)
1937 gtk_widget_unparent (widget);
1939 xpaned->top_left_child = NULL;
1941 if (was_visible && GTK_WIDGET_VISIBLE (container))
1942 gtk_widget_queue_resize (GTK_WIDGET (container));
1944 else if (xpaned->top_right_child == widget)
1946 gtk_widget_unparent (widget);
1948 xpaned->top_right_child = NULL;
1950 if (was_visible && GTK_WIDGET_VISIBLE (container))
1951 gtk_widget_queue_resize (GTK_WIDGET (container));
1953 else if (xpaned->bottom_left_child == widget)
1955 gtk_widget_unparent (widget);
1957 xpaned->bottom_left_child = NULL;
1959 if (was_visible && GTK_WIDGET_VISIBLE (container))
1960 gtk_widget_queue_resize (GTK_WIDGET (container));
1962 else if (xpaned->bottom_right_child == widget)
1964 gtk_widget_unparent (widget);
1966 xpaned->bottom_right_child = NULL;
1968 if (was_visible && GTK_WIDGET_VISIBLE (container))
1969 gtk_widget_queue_resize (GTK_WIDGET (container));
1972 g_warning ("GtkXPaned has no more children attached\n");
1976 static void gtk_xpaned_forall (GtkContainer* container,
1977 gboolean include_internals,
1978 GtkCallback callback,
1979 gpointer callback_data)
1983 g_return_if_fail (callback != NULL);
1985 xpaned = GTK_XPANED (container);
1987 if (xpaned->top_left_child)
1988 (*callback) (xpaned->top_left_child, callback_data);
1989 if (xpaned->top_right_child)
1990 (*callback) (xpaned->top_right_child, callback_data);
1991 if (xpaned->bottom_left_child)
1992 (*callback) (xpaned->bottom_left_child, callback_data);
1993 if (xpaned->bottom_right_child)
1994 (*callback) (xpaned->bottom_right_child, callback_data);
1998 * gtk_xpaned_get_position_x:
1999 * @paned: a #GtkXPaned widget
2001 * Obtains the x-position of the divider.
2003 * Return value: x-position of the divider
2005 gint gtk_xpaned_get_position_x (GtkXPaned* xpaned)
2007 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2009 return xpaned->top_left_child_size.width;
2013 * gtk_xpaned_get_position_y:
2014 * @paned: a #GtkXPaned widget
2016 * Obtains the y-position of the divider.
2018 * Return value: y-position of the divider
2020 gint gtk_xpaned_get_position_y (GtkXPaned* xpaned)
2022 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2024 return xpaned->top_left_child_size.height;
2028 * gtk_xpaned_set_position_x:
2029 * @paned: a #GtkXPaned widget
2030 * @xposition: pixel x-position of divider, a negative values
2031 * of a component mean that the position is unset.
2033 * Sets the x-position of the divider between the four panes.
2035 void gtk_xpaned_set_position_x (GtkXPaned* xpaned, gint xposition)
2039 g_return_if_fail (GTK_IS_XPANED (xpaned));
2041 /* if any child is currently maximized, jump right back */
2042 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2043 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2044 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2045 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2048 object = G_OBJECT (xpaned);
2052 /* We don't clamp here - the assumption is that
2053 * if the total allocation changes at the same time
2054 * as the position, the position set is with reference
2055 * to the new total size. If only the position changes,
2056 * then clamping will occur in gtk_paned_compute_position()
2059 xpaned->top_left_child_size.width = xposition;
2060 xpaned->position_set = TRUE;
2064 xpaned->position_set = FALSE;
2067 g_object_freeze_notify (object);
2068 g_object_notify (object, "x-position");
2069 g_object_notify (object, "position-set");
2070 g_object_thaw_notify (object);
2072 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2076 * gtk_xpaned_set_position_y:
2077 * @paned: a #GtkXPaned widget
2078 * @yposition: pixel y-position of divider, a negative values
2079 * of a component mean that the position is unset.
2081 * Sets the y-position of the divider between the four panes.
2083 void gtk_xpaned_set_position_y (GtkXPaned* xpaned, gint yposition)
2087 g_return_if_fail (GTK_IS_XPANED (xpaned));
2089 /* if any child is currently maximized, jump right back */
2090 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2091 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2092 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2093 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2096 object = G_OBJECT (xpaned);
2100 /* We don't clamp here - the assumption is that
2101 * if the total allocation changes at the same time
2102 * as the position, the position set is with reference
2103 * to the new total size. If only the position changes,
2104 * then clamping will occur in gtk_paned_compute_position()
2107 xpaned->top_left_child_size.height = yposition;
2108 xpaned->position_set = TRUE;
2112 xpaned->position_set = FALSE;
2115 g_object_freeze_notify (object);
2116 g_object_notify (object, "y-position");
2117 g_object_notify (object, "position-set");
2118 g_object_thaw_notify (object);
2120 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2123 /* this call is private and only intended for internal use! */
2124 void gtk_xpaned_save_unmaximized_x (GtkXPaned* xpaned)
2126 xpaned->unmaximized_position.x = gtk_xpaned_get_position_x (xpaned);
2129 /* this call is private and only intended for internal use! */
2130 void gtk_xpaned_save_unmaximized_y (GtkXPaned* xpaned)
2132 xpaned->unmaximized_position.y = gtk_xpaned_get_position_y (xpaned);
2135 /* this call is private and only intended for internal use! */
2136 gint gtk_xpaned_fetch_unmaximized_x (GtkXPaned* xpaned)
2138 return xpaned->unmaximized_position.x;
2141 /* this call is private and only intended for internal use! */
2142 gint gtk_xpaned_fetch_unmaximized_y (GtkXPaned* xpaned)
2144 return xpaned->unmaximized_position.y;
2148 * gtk_xpaned_get_top_left_child:
2149 * @xpaned: a #GtkXPaned widget
2151 * Obtains the top-left child of the xpaned widget.
2153 * Return value: top-left child, or %NULL if it is not set.
2157 GtkWidget* gtk_xpaned_get_top_left_child (GtkXPaned* xpaned)
2159 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2161 return xpaned->top_left_child;
2165 * gtk_xpaned_get_top_right_child:
2166 * @xpaned: a #GtkXPaned widget
2168 * Obtains the top-right child of the xpaned widget.
2170 * Return value: top-right child, or %NULL if it is not set.
2174 GtkWidget* gtk_xpaned_get_top_right_child (GtkXPaned* xpaned)
2176 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2178 return xpaned->top_right_child;
2182 * gtk_xpaned_get_bottom_left_child:
2183 * @xpaned: a #GtkXPaned widget
2185 * Obtains the bottom-left child of the xpaned widget.
2187 * Return value: bottom-left child, or %NULL if it is not set.
2191 GtkWidget* gtk_xpaned_get_bottom_left_child (GtkXPaned* xpaned)
2193 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2195 return xpaned->bottom_left_child;
2199 * gtk_xpaned_get_bottom_right_child:
2200 * @xpaned: a #GtkXPaned widget
2202 * Obtains the bottom-right child of the xpaned widget.
2204 * Return value: bottom-right child, or %NULL if it is not set.
2208 GtkWidget* gtk_xpaned_get_bottom_right_child (GtkXPaned* xpaned)
2210 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2212 return xpaned->bottom_right_child;
2215 gboolean gtk_xpaned_maximize_top_left (GtkXPaned* xpaned, gboolean maximize)
2219 /* see if any child is already maximized */
2220 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2221 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2222 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2223 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2225 /* save current position */
2226 gtk_xpaned_save_unmaximized_x (xpaned);
2227 gtk_xpaned_save_unmaximized_y (xpaned);
2229 /* set new maximized position */
2230 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2231 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2233 /* mark maximized flag for top-left child */
2234 xpaned->maximized[GTK_XPANED_TOP_LEFT] = TRUE;
2238 /* already one child maximized, report error */
2244 /* verify that top-left child is really currently maximized */
2245 if (xpaned->maximized[GTK_XPANED_TOP_LEFT])
2247 /* clear maximized flat for top-left child */
2248 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
2250 /* restore unmaximized position */
2251 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2252 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2256 /* top-left child is currently not maximized, report error */
2262 gboolean gtk_xpaned_maximize_top_right (GtkXPaned* xpaned, gboolean maximize)
2266 /* see if any child is already maximized */
2267 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2268 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2269 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2270 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2272 /* save current position */
2273 gtk_xpaned_save_unmaximized_x (xpaned);
2274 gtk_xpaned_save_unmaximized_y (xpaned);
2276 /* set new maximized position */
2277 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2278 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2280 /* mark maximized flag for top-right child */
2281 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = TRUE;
2285 /* already one child maximized, report error */
2291 /* verify that top-right child is really currently maximized */
2292 if (xpaned->maximized[GTK_XPANED_TOP_RIGHT])
2294 /* clear maximized flat for top-right child */
2295 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
2297 /* restore unmaximized position */
2298 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2299 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2303 /* top-right child is currently not maximized, report error */
2309 gboolean gtk_xpaned_maximize_bottom_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->min_position.y);
2327 /* mark maximized flag for bottom-left child */
2328 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = TRUE;
2332 /* already one child maximized, report error */
2338 /* verify that bottom-left child is really currently maximized */
2339 if (xpaned->maximized[GTK_XPANED_BOTTOM_LEFT])
2341 /* clear maximized flat for bottom-left child */
2342 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
2344 /* restore unmaximized position */
2345 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2346 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2350 /* bottom-left child is currently not maximized, report error */
2356 gboolean gtk_xpaned_maximize_bottom_right (GtkXPaned* xpaned, gboolean maximize)
2360 /* see if any child is already maximized */
2361 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2362 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2363 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2364 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2366 /* save current position */
2367 gtk_xpaned_save_unmaximized_x (xpaned);
2368 gtk_xpaned_save_unmaximized_y (xpaned);
2370 /* set new maximized position */
2371 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2372 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2374 /* mark maximized flag for bottom-right child */
2375 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = TRUE;
2379 /* already one child maximized, report error */
2385 /* verify that bottom-right child is really currently maximized */
2386 if (xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2388 /* clear maximized flat for bottom-right child */
2389 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
2391 /* restore unmaximized position */
2392 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2393 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2397 /* bottom-right child is currently not maximized, report error */
2404 gtk_xpaned_compute_position (GtkXPaned* xpaned,
2405 const GtkAllocation* allocation,
2406 GtkRequisition* top_left_child_req,
2407 GtkRequisition* top_right_child_req,
2408 GtkRequisition* bottom_left_child_req,
2409 GtkRequisition* bottom_right_child_req)
2411 GdkPoint old_position;
2412 GdkPoint old_min_position;
2413 GdkPoint old_max_position;
2415 gint border_width = GTK_CONTAINER (xpaned)->border_width;
2419 g_return_if_fail (GTK_IS_XPANED (xpaned));
2421 old_position.x = xpaned->top_left_child_size.width;
2422 old_position.y = xpaned->top_left_child_size.height;
2423 old_min_position.x = xpaned->min_position.x;
2424 old_min_position.y = xpaned->min_position.y;
2425 old_max_position.x = xpaned->max_position.x;
2426 old_max_position.y = xpaned->max_position.y;
2428 fX = 100.0f * (float) old_position.x / (float) allocation->width;
2429 fY = 100.0f * (float) old_position.y / (float) allocation->height;
2431 xpaned->min_position.x = xpaned->top_left_child_shrink ? 0 : top_left_child_req->width;
2432 xpaned->min_position.y = xpaned->top_left_child_shrink ? 0 : top_left_child_req->height;
2434 gtk_widget_style_get (GTK_WIDGET (xpaned), "handle-size", &handle_size, NULL);
2436 xpaned->max_position.x = allocation->width - 2 * border_width - handle_size;
2437 xpaned->max_position.y = allocation->height - 2 * border_width - handle_size;
2438 if (!xpaned->top_left_child_shrink)
2439 xpaned->max_position.x = MAX (1, xpaned->max_position.x - top_left_child_req->width);
2440 xpaned->max_position.x = MAX (xpaned->min_position.x, xpaned->max_position.x);
2442 if (!xpaned->position_set)
2444 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2446 xpaned->top_left_child_size.width = MAX (0, allocation->width - top_right_child_req->width);
2447 xpaned->top_left_child_size.height = MAX (0, allocation->height - top_right_child_req->height);
2449 else if (!xpaned->top_left_child_resize && xpaned->top_right_child_resize)
2451 xpaned->top_left_child_size.width = top_left_child_req->width;
2452 xpaned->top_left_child_size.height = top_left_child_req->height;
2454 else if (top_left_child_req->width + top_right_child_req->width != 0)
2456 xpaned->top_left_child_size.width = allocation->width * ((gdouble)top_left_child_req->width / (top_left_child_req->width + top_right_child_req->width)) + 0.5;
2458 else if (top_left_child_req->height + top_right_child_req->height != 0)
2460 xpaned->top_left_child_size.height = allocation->height * ((gdouble)top_left_child_req->height / (top_left_child_req->height + top_right_child_req->height)) + 0.5;
2464 xpaned->top_left_child_size.width = allocation->width * 0.5 + 0.5;
2465 xpaned->top_left_child_size.height = allocation->height * 0.5 + 0.5;
2470 /* If the position was set before the initial allocation.
2471 ** (paned->last_allocation <= 0) just clamp it and leave it. */
2472 if (xpaned->last_allocation.width > 0)
2474 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2476 xpaned->top_left_child_size.width += allocation->width
2477 - xpaned->last_allocation.width;
2479 xpaned->top_left_child_size.height += allocation->height
2480 - xpaned->last_allocation.height;
2482 else if (!(!xpaned->top_left_child_resize && xpaned->top_right_child_resize))
2484 xpaned->top_left_child_size.width = allocation->width
2485 * ((gdouble) xpaned->top_left_child_size.width / (xpaned->last_allocation.width))
2488 xpaned->top_left_child_size.height = allocation->height
2489 * ((gdouble) xpaned->top_left_child_size.height / (xpaned->last_allocation.height))
2493 if (xpaned->last_allocation.height > 0)
2495 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2497 xpaned->top_left_child_size.width += allocation->width - xpaned->last_allocation.width;
2498 xpaned->top_left_child_size.height += allocation->height - xpaned->last_allocation.height;
2500 else if (!(!xpaned->top_left_child_resize && xpaned->top_right_child_resize))
2502 xpaned->top_left_child_size.width = allocation->width * ((gdouble) xpaned->top_left_child_size.width / (xpaned->last_allocation.width)) + 0.5;
2503 xpaned->top_left_child_size.height = allocation->height * ((gdouble) xpaned->top_left_child_size.height / (xpaned->last_allocation.height)) + 0.5;
2509 xpaned->top_left_child_size.width = CLAMP (xpaned->top_left_child_size.width,
2510 xpaned->min_position.x,
2511 xpaned->max_position.x);
2512 xpaned->top_left_child_size.height = CLAMP (xpaned->top_left_child_size.height,
2513 xpaned->min_position.y,
2514 xpaned->max_position.y);
2516 xpaned->top_right_child_size.width = CLAMP (xpaned->top_right_child_size.width,
2517 xpaned->min_position.x,
2518 xpaned->max_position.x);
2519 xpaned->top_right_child_size.height = CLAMP (xpaned->top_right_child_size.height,
2520 xpaned->min_position.y,
2521 xpaned->max_position.y);
2523 xpaned->bottom_left_child_size.width = CLAMP (xpaned->bottom_left_child_size.width,
2524 xpaned->min_position.x,
2525 xpaned->max_position.x);
2526 xpaned->bottom_left_child_size.height = CLAMP (xpaned->bottom_left_child_size.height,
2527 xpaned->min_position.y,
2528 xpaned->max_position.y);
2530 xpaned->bottom_right_child_size.width = CLAMP (xpaned->bottom_right_child_size.width,
2531 xpaned->min_position.x,
2532 xpaned->max_position.x);
2533 xpaned->bottom_right_child_size.height = CLAMP (xpaned->bottom_right_child_size.height,
2534 xpaned->min_position.y,
2535 xpaned->max_position.y);
2537 gtk_widget_set_child_visible (xpaned->top_left_child, TRUE);
2538 gtk_widget_set_child_visible (xpaned->top_right_child, TRUE);
2539 gtk_widget_set_child_visible (xpaned->bottom_left_child, TRUE);
2540 gtk_widget_set_child_visible (xpaned->bottom_right_child, TRUE);
2542 g_object_freeze_notify (G_OBJECT (xpaned));
2544 if (xpaned->top_left_child_size.width != old_position.x)
2545 g_object_notify (G_OBJECT (xpaned), "x-position");
2546 if (xpaned->top_left_child_size.height != old_position.y)
2547 g_object_notify (G_OBJECT (xpaned), "y-position");
2549 if (xpaned->top_right_child_size.width != old_position.x)
2550 g_object_notify (G_OBJECT (xpaned), "x-position");
2551 if (xpaned->top_right_child_size.height != old_position.y)
2552 g_object_notify (G_OBJECT (xpaned), "y-position");
2554 if (xpaned->bottom_left_child_size.width != old_position.x)
2555 g_object_notify (G_OBJECT (xpaned), "x-position");
2556 if (xpaned->bottom_left_child_size.height != old_position.y)
2557 g_object_notify (G_OBJECT (xpaned), "y-position");
2559 if (xpaned->bottom_right_child_size.width != old_position.x)
2560 g_object_notify (G_OBJECT (xpaned), "x-position");
2561 if (xpaned->bottom_right_child_size.height != old_position.y)
2562 g_object_notify (G_OBJECT (xpaned), "y-position");
2564 if (xpaned->min_position.x != old_min_position.x)
2565 g_object_notify (G_OBJECT (xpaned), "min-x-position");
2566 if (xpaned->min_position.y != old_min_position.y)
2567 g_object_notify (G_OBJECT (xpaned), "min-y-position");
2569 if (xpaned->max_position.x != old_max_position.x)
2570 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2571 if (xpaned->max_position.y != old_max_position.y)
2572 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2574 g_object_thaw_notify (G_OBJECT (xpaned));
2576 xpaned->last_allocation.width = allocation->width;
2577 xpaned->last_allocation.height = allocation->height;
2579 fX = 100.0f * (float) old_position.x / (float) allocation->width;
2580 fY = 100.0f * (float) old_position.y / (float) allocation->height;
2583 static void gtk_xpaned_set_saved_focus (GtkXPaned* xpaned, GtkWidget* widget)
2585 if (xpaned->priv->saved_focus)
2586 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2587 (gpointer *)&(xpaned->priv->saved_focus));
2589 xpaned->priv->saved_focus = widget;
2591 if (xpaned->priv->saved_focus)
2592 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2593 (gpointer *)&(xpaned->priv->saved_focus));
2596 static void gtk_xpaned_set_first_xpaned (GtkXPaned* xpaned,
2597 GtkXPaned* first_xpaned)
2599 if (xpaned->priv->first_xpaned)
2600 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2601 (gpointer *)&(xpaned->priv->first_xpaned));
2603 xpaned->priv->first_xpaned = first_xpaned;
2605 if (xpaned->priv->first_xpaned)
2606 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2607 (gpointer *)&(xpaned->priv->first_xpaned));
2610 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned* xpaned,
2613 if (xpaned->last_top_left_child_focus)
2614 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2615 (gpointer *)&(xpaned->last_top_left_child_focus));
2617 xpaned->last_top_left_child_focus = widget;
2619 if (xpaned->last_top_left_child_focus)
2620 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2621 (gpointer *)&(xpaned->last_top_left_child_focus));
2624 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned* xpaned,
2627 if (xpaned->last_top_right_child_focus)
2628 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2629 (gpointer *)&(xpaned->last_top_right_child_focus));
2631 xpaned->last_top_right_child_focus = widget;
2633 if (xpaned->last_top_right_child_focus)
2634 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2635 (gpointer *)&(xpaned->last_top_right_child_focus));
2638 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned* xpaned,
2641 if (xpaned->last_bottom_left_child_focus)
2642 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_bottom_left_child_focus),
2643 (gpointer *)&(xpaned->last_bottom_left_child_focus));
2645 xpaned->last_bottom_left_child_focus = widget;
2647 if (xpaned->last_bottom_left_child_focus)
2648 g_object_add_weak_pointer (G_OBJECT (xpaned->last_bottom_left_child_focus),
2649 (gpointer *)&(xpaned->last_bottom_left_child_focus));
2652 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned* xpaned,
2655 if (xpaned->last_bottom_right_child_focus)
2656 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_bottom_right_child_focus),
2657 (gpointer *)&(xpaned->last_bottom_right_child_focus));
2659 xpaned->last_bottom_right_child_focus = widget;
2661 if (xpaned->last_bottom_right_child_focus)
2662 g_object_add_weak_pointer (G_OBJECT (xpaned->last_bottom_right_child_focus),
2663 (gpointer *)&(xpaned->last_bottom_right_child_focus));
2666 static GtkWidget* xpaned_get_focus_widget (GtkXPaned* xpaned)
2668 GtkWidget* toplevel;
2670 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
2671 if (GTK_WIDGET_TOPLEVEL (toplevel))
2672 return GTK_WINDOW (toplevel)->focus_widget;
2677 static void gtk_xpaned_set_focus_child (GtkContainer* container,
2678 GtkWidget* focus_child)
2682 g_return_if_fail (GTK_IS_XPANED (container));
2684 xpaned = GTK_XPANED (container);
2686 if (focus_child == NULL)
2688 GtkWidget* last_focus;
2691 last_focus = xpaned_get_focus_widget (xpaned);
2695 /* If there is one or more paned widgets between us and the
2696 * focus widget, we want the topmost of those as last_focus
2698 for (w = last_focus; w != GTK_WIDGET (xpaned); w = w->parent)
2699 if (GTK_IS_XPANED (w))
2702 if (container->focus_child == xpaned->top_left_child)
2703 gtk_xpaned_set_last_top_left_child_focus (xpaned, last_focus);
2704 else if (container->focus_child == xpaned->top_right_child)
2705 gtk_xpaned_set_last_top_right_child_focus (xpaned, last_focus);
2706 else if (container->focus_child == xpaned->bottom_left_child)
2707 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, last_focus);
2708 else if (container->focus_child == xpaned->bottom_right_child)
2709 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, last_focus);
2713 if (parent_class->set_focus_child)
2714 (* parent_class->set_focus_child) (container, focus_child);
2717 static void gtk_xpaned_get_cycle_chain (GtkXPaned* xpaned,
2718 GtkDirectionType direction,
2721 GtkContainer* container = GTK_CONTAINER (xpaned);
2722 GtkWidget* ancestor = NULL;
2723 GList* temp_list = NULL;
2726 if (xpaned->in_recursion)
2729 g_assert (widgets != NULL);
2731 if (xpaned->last_top_left_child_focus &&
2732 !gtk_widget_is_ancestor (xpaned->last_top_left_child_focus,
2733 GTK_WIDGET (xpaned)))
2735 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
2738 if (xpaned->last_top_right_child_focus &&
2739 !gtk_widget_is_ancestor (xpaned->last_top_right_child_focus,
2740 GTK_WIDGET (xpaned)))
2742 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
2745 if (xpaned->last_bottom_left_child_focus &&
2746 !gtk_widget_is_ancestor (xpaned->last_bottom_left_child_focus,
2747 GTK_WIDGET (xpaned)))
2749 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
2752 if (xpaned->last_bottom_right_child_focus &&
2753 !gtk_widget_is_ancestor (xpaned->last_bottom_right_child_focus,
2754 GTK_WIDGET (xpaned)))
2756 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
2759 if (GTK_WIDGET (xpaned)->parent)
2760 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (xpaned)->parent,
2763 /* The idea here is that temp_list is a list of widgets we want to cycle
2764 * to. The list is prioritized so that the first element is our first
2765 * choice, the next our second, and so on.
2767 * We can't just use g_list_reverse(), because we want to try
2768 * paned->last_child?_focus before paned->child?, both when we
2769 * are going forward and backward.
2771 if (direction == GTK_DIR_TAB_FORWARD)
2773 if (container->focus_child == xpaned->top_left_child)
2775 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2776 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2777 temp_list = g_list_append (temp_list, ancestor);
2779 else if (container->focus_child == xpaned->top_right_child)
2781 temp_list = g_list_append (temp_list, ancestor);
2782 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2783 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2785 else if (container->focus_child == xpaned->bottom_left_child)
2787 temp_list = g_list_append (temp_list, ancestor);
2788 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2789 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2791 else if (container->focus_child == xpaned->bottom_right_child)
2793 temp_list = g_list_append (temp_list, ancestor);
2794 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2795 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2799 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2800 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2801 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2802 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2803 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2804 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2805 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2806 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2807 temp_list = g_list_append (temp_list, ancestor);
2812 if (container->focus_child == xpaned->top_left_child)
2814 temp_list = g_list_append (temp_list, ancestor);
2815 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2816 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2818 else if (container->focus_child == xpaned->top_right_child)
2820 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2821 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2822 temp_list = g_list_append (temp_list, ancestor);
2824 else if (container->focus_child == xpaned->bottom_right_child)
2826 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2827 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2828 temp_list = g_list_append (temp_list, ancestor);
2830 else if (container->focus_child == xpaned->top_right_child)
2832 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2833 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2834 temp_list = g_list_append (temp_list, ancestor);
2838 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2839 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2840 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2841 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2842 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2843 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2844 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2845 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2846 temp_list = g_list_append (temp_list, ancestor);
2850 /* Walk the list and expand all the paned widgets. */
2851 for (list = temp_list; list != NULL; list = list->next)
2853 GtkWidget *widget = list->data;
2857 if (GTK_IS_XPANED (widget))
2859 xpaned->in_recursion = TRUE;
2860 gtk_xpaned_get_cycle_chain (GTK_XPANED (widget),
2863 xpaned->in_recursion = FALSE;
2867 *widgets = g_list_append (*widgets, widget);
2872 g_list_free (temp_list);
2875 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned* xpaned,
2878 GList* cycle_chain = NULL;
2881 GtkDirectionType direction = reversed ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2883 /* ignore f6 if the handle is focused */
2884 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
2887 /* we can't just let the event propagate up the hierarchy,
2888 * because the paned will want to cycle focus _unless_ an
2889 * ancestor paned handles the event
2891 gtk_xpaned_get_cycle_chain (xpaned, direction, &cycle_chain);
2893 for (list = cycle_chain; list != NULL; list = list->next)
2894 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2897 g_list_free (cycle_chain);
2902 static void get_child_xpanes (GtkWidget* widget, GList** xpanes)
2904 if (GTK_IS_XPANED (widget))
2906 GtkXPaned* xpaned = GTK_XPANED (widget);
2908 get_child_xpanes (xpaned->top_left_child, xpanes);
2909 *xpanes = g_list_prepend (*xpanes, widget);
2910 get_child_xpanes (xpaned->top_right_child, xpanes);
2911 *xpanes = g_list_prepend (*xpanes, widget);
2912 get_child_xpanes (xpaned->bottom_left_child, xpanes);
2913 *xpanes = g_list_prepend (*xpanes, widget);
2914 get_child_xpanes (xpaned->bottom_right_child, xpanes);
2916 else if (GTK_IS_CONTAINER (widget))
2918 gtk_container_foreach (GTK_CONTAINER (widget),
2919 (GtkCallback)get_child_xpanes,
2924 static GList* get_all_xpanes (GtkXPaned* xpaned)
2926 GtkXPaned* topmost = NULL;
2927 GList* result = NULL;
2930 for (w = GTK_WIDGET (xpaned); w != NULL; w = w->parent)
2932 if (GTK_IS_XPANED (w))
2933 topmost = GTK_XPANED (w);
2938 get_child_xpanes (GTK_WIDGET (topmost), &result);
2940 return g_list_reverse (result);
2943 static void gtk_xpaned_find_neighbours (GtkXPaned* xpaned,
2950 all_xpanes = get_all_xpanes (xpaned);
2951 g_assert (all_xpanes);
2953 this_link = g_list_find (all_xpanes, xpaned);
2955 g_assert (this_link);
2957 if (this_link->next)
2958 *next = this_link->next->data;
2960 *next = all_xpanes->data;
2962 if (this_link->prev)
2963 *prev = this_link->prev->data;
2965 *prev = g_list_last (all_xpanes)->data;
2967 g_list_free (all_xpanes);
2970 static gboolean gtk_xpaned_move_handle (GtkXPaned* xpaned, GtkScrollType scroll)
2972 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
2974 GdkPoint old_position;
2975 GdkPoint new_position;
2980 SINGLE_STEP_SIZE = 1,
2984 new_position.x = old_position.x = gtk_xpaned_get_position_x (xpaned);
2985 new_position.y = old_position.y = gtk_xpaned_get_position_y (xpaned);
2990 case GTK_SCROLL_STEP_LEFT:
2991 case GTK_SCROLL_STEP_UP:
2992 case GTK_SCROLL_STEP_BACKWARD:
2993 increment = - SINGLE_STEP_SIZE;
2996 case GTK_SCROLL_STEP_RIGHT:
2997 case GTK_SCROLL_STEP_DOWN:
2998 case GTK_SCROLL_STEP_FORWARD:
2999 increment = SINGLE_STEP_SIZE;
3002 case GTK_SCROLL_PAGE_LEFT:
3003 case GTK_SCROLL_PAGE_UP:
3004 case GTK_SCROLL_PAGE_BACKWARD:
3005 increment = - PAGE_STEP_SIZE;
3008 case GTK_SCROLL_PAGE_RIGHT:
3009 case GTK_SCROLL_PAGE_DOWN:
3010 case GTK_SCROLL_PAGE_FORWARD:
3011 increment = PAGE_STEP_SIZE;
3014 case GTK_SCROLL_START:
3015 new_position.x = xpaned->min_position.x;
3016 new_position.y = xpaned->min_position.y;
3019 case GTK_SCROLL_END:
3020 new_position.x = xpaned->max_position.x;
3021 new_position.y = xpaned->max_position.y;
3030 if (is_rtl (xpaned))
3031 increment = -increment;
3033 new_position.x = old_position.x + increment;
3034 new_position.y = old_position.y + increment;
3037 new_position.x = CLAMP (new_position.x,
3038 xpaned->min_position.x,
3039 xpaned->max_position.x);
3041 new_position.y = CLAMP (new_position.y,
3042 xpaned->min_position.y,
3043 xpaned->max_position.y);
3045 if (old_position.x != new_position.x)
3046 gtk_xpaned_set_position_x (xpaned, new_position.x);
3048 if (old_position.y != new_position.y)
3049 gtk_xpaned_set_position_y (xpaned, new_position.y);
3057 static void gtk_xpaned_restore_focus (GtkXPaned* xpaned)
3059 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3061 if (xpaned->priv->saved_focus &&
3062 GTK_WIDGET_SENSITIVE (xpaned->priv->saved_focus))
3064 gtk_widget_grab_focus (xpaned->priv->saved_focus);
3068 /* the saved focus is somehow not available for focusing,
3070 * 1) tabbing into the paned widget
3071 * if that didn't work,
3072 * 2) unset focus for the window if there is one
3075 if (!gtk_widget_child_focus (GTK_WIDGET (xpaned), GTK_DIR_TAB_FORWARD))
3077 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3079 if (GTK_IS_WINDOW (toplevel))
3080 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
3084 gtk_xpaned_set_saved_focus (xpaned, NULL);
3085 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3089 static gboolean gtk_xpaned_accept_position (GtkXPaned* xpaned)
3091 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3093 xpaned->original_position.x = -1;
3094 xpaned->original_position.y = -1;
3095 gtk_xpaned_restore_focus (xpaned);
3103 static gboolean gtk_xpaned_cancel_position (GtkXPaned* xpaned)
3105 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3107 if (xpaned->original_position.x != -1)
3109 gtk_xpaned_set_position_x (xpaned, xpaned->original_position.x);
3110 xpaned->original_position.x = -1;
3113 if (xpaned->original_position.y != -1)
3115 gtk_xpaned_set_position_y (xpaned, xpaned->original_position.y);
3116 xpaned->original_position.y = -1;
3119 gtk_xpaned_restore_focus (xpaned);
3126 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned* xpaned,
3132 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3134 GtkXPaned* focus = NULL;
3136 if (!xpaned->priv->first_xpaned)
3138 /* The first_pane has disappeared. As an ad-hoc solution,
3139 * we make the currently focused paned the first_paned. To the
3140 * user this will seem like the paned cycling has been reset.
3142 gtk_xpaned_set_first_xpaned (xpaned, xpaned);
3145 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3147 if (reversed && prev &&
3148 prev != xpaned && xpaned != xpaned->priv->first_xpaned)
3152 else if (!reversed &&
3155 next != xpaned->priv->first_xpaned)
3161 gtk_xpaned_accept_position (xpaned);
3167 gtk_xpaned_set_saved_focus (focus, xpaned->priv->saved_focus);
3168 gtk_xpaned_set_first_xpaned (focus, xpaned->priv->first_xpaned);
3170 gtk_xpaned_set_saved_focus (xpaned, NULL);
3171 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3173 gtk_widget_grab_focus (GTK_WIDGET (focus));
3175 if (!gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3177 xpaned->original_position.x = -1;
3178 xpaned->original_position.y = -1;
3179 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3180 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3185 GtkContainer* container = GTK_CONTAINER (xpaned);
3190 GtkWidget* toplevel;
3192 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3194 if (container->focus_child == xpaned->top_left_child)
3207 else if (container->focus_child == xpaned->top_right_child)
3222 /* Focus is not inside this xpaned, and we don't have focus.
3223 * Presumably this happened because the application wants us
3224 * to start keyboard navigating.
3234 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3236 if (GTK_IS_WINDOW (toplevel))
3237 gtk_xpaned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
3238 gtk_xpaned_set_first_xpaned (focus, first);
3239 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3240 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3242 gtk_widget_grab_focus (GTK_WIDGET (focus));
3248 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned* xpaned)
3250 /* This function/signal has the wrong name. It is called when you
3251 * press Tab or Shift-Tab and what we do is act as if
3252 * the user pressed Return and then Tab or Shift-Tab
3254 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3255 gtk_xpaned_accept_position (xpaned);
3260 /*#define __GTK_XPANED_C__*/
3261 /*#include "gtkaliasdef.c"*/