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 *******************************************************************************/
32 #include "gtkxpaned.h"
33 #include "gtkmarshalers.h"
34 #include <gtk/gtkbindings.h>
35 #include <gtk/gtksignal.h>
36 #include <gdk/gdkkeysyms.h>
37 #include <gtk/gtkwindow.h>
38 #include <gtk/gtkmain.h>
70 static void gtk_xpaned_class_init (GtkXPanedClass* klass);
72 static void gtk_xpaned_init (GtkXPaned* xpaned);
74 static void gtk_xpaned_size_request (GtkWidget* widget,
75 GtkRequisition* requisition);
77 static void gtk_xpaned_size_allocate (GtkWidget* widget,
78 GtkAllocation* allocation);
80 static void gtk_xpaned_set_property (GObject* object,
85 static void gtk_xpaned_get_property (GObject* object,
90 static void gtk_xpaned_set_child_property (GtkContainer* container,
96 static void gtk_xpaned_get_child_property (GtkContainer* container,
102 static void gtk_xpaned_finalize (GObject* object);
104 static void gtk_xpaned_realize (GtkWidget* widget);
106 static void gtk_xpaned_unrealize (GtkWidget* widget);
108 static void gtk_xpaned_map (GtkWidget* widget);
110 static void gtk_xpaned_unmap (GtkWidget* widget);
112 static gboolean gtk_xpaned_expose (GtkWidget* widget, GdkEventExpose* event);
114 static gboolean gtk_xpaned_enter (GtkWidget* widget, GdkEventCrossing* event);
116 static gboolean gtk_xpaned_leave (GtkWidget* widget, GdkEventCrossing* event);
118 static gboolean gtk_xpaned_button_press (GtkWidget* widget,
119 GdkEventButton* event);
121 static gboolean gtk_xpaned_button_release (GtkWidget* widget,
122 GdkEventButton* event);
124 static gboolean gtk_xpaned_motion (GtkWidget* widget, GdkEventMotion* event);
126 static gboolean gtk_xpaned_focus (GtkWidget* widget,
127 GtkDirectionType direction);
129 static void gtk_xpaned_add (GtkContainer* container, GtkWidget* widget);
131 static void gtk_xpaned_remove (GtkContainer* container, GtkWidget* widget);
133 static void gtk_xpaned_forall (GtkContainer* container,
134 gboolean include_internals,
135 GtkCallback callback,
136 gpointer callback_data);
138 static void gtk_xpaned_set_focus_child (GtkContainer* container,
141 static void gtk_xpaned_set_saved_focus (GtkXPaned* xpaned, GtkWidget* widget);
143 static void gtk_xpaned_set_first_xpaned (GtkXPaned* xpaned,
144 GtkXPaned* first_xpaned);
146 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned* xpaned,
149 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned* xpaned,
152 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned* xpaned,
155 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned* xpaned,
158 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned* xpaned,
161 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned* xpaned,
164 static gboolean gtk_xpaned_move_handle (GtkXPaned* xpaned,
165 GtkScrollType scroll);
167 static gboolean gtk_xpaned_accept_position (GtkXPaned* xpaned);
169 static gboolean gtk_xpaned_cancel_position (GtkXPaned* xpaned);
171 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned* xpaned);
173 static GType gtk_xpaned_child_type (GtkContainer* container);
175 static GtkContainerClass* parent_class = NULL;
177 struct _GtkXPanedPrivate
179 GtkWidget *saved_focus;
180 GtkXPaned *first_xpaned;
183 GType gtk_xpaned_get_type (void)
185 static GType xpaned_type = 0;
189 static const GTypeInfo xpaned_info =
191 sizeof (GtkXPanedClass),
192 NULL, /* base_init */
193 NULL, /* base_finalize */
194 (GClassInitFunc) gtk_xpaned_class_init,
195 NULL, /* class_finalize */
196 NULL, /* class_data */
199 (GInstanceInitFunc) gtk_xpaned_init
202 xpaned_type = g_type_register_static (GTK_TYPE_CONTAINER,
211 GtkWidget* gtk_xpaned_new (void)
215 xpaned = g_object_new (GTK_TYPE_XPANED, NULL);
217 return GTK_WIDGET (xpaned);
220 static guint signals[LAST_SIGNAL] = { 0 };
222 static void add_tab_bindings (GtkBindingSet* binding_set,
223 GdkModifierType modifiers)
225 gtk_binding_entry_add_signal (binding_set,
228 "toggle_handle_focus",
231 gtk_binding_entry_add_signal (binding_set,
234 "toggle_handle_focus",
238 static void add_move_binding (GtkBindingSet* binding_set,
240 GdkModifierType mask,
241 GtkScrollType scroll)
243 gtk_binding_entry_add_signal (binding_set,
248 GTK_TYPE_SCROLL_TYPE,
252 static void gtk_xpaned_class_init (GtkXPanedClass* class)
254 GObjectClass* object_class;
255 GtkWidgetClass* widget_class;
256 GtkContainerClass* container_class;
257 GtkXPanedClass* xpaned_class;
258 GtkBindingSet* binding_set;
260 object_class = (GObjectClass *) class;
261 widget_class = (GtkWidgetClass *) class;
262 container_class = (GtkContainerClass *) class;
263 xpaned_class = (GtkXPanedClass *) class;
265 parent_class = g_type_class_peek_parent (class);
267 object_class->set_property = gtk_xpaned_set_property;
268 object_class->get_property = gtk_xpaned_get_property;
269 object_class->finalize = gtk_xpaned_finalize;
271 widget_class->realize = gtk_xpaned_realize;
272 widget_class->unrealize = gtk_xpaned_unrealize;
273 widget_class->map = gtk_xpaned_map;
274 widget_class->unmap = gtk_xpaned_unmap;
275 widget_class->expose_event = gtk_xpaned_expose;
276 widget_class->focus = gtk_xpaned_focus;
277 widget_class->enter_notify_event = gtk_xpaned_enter;
278 widget_class->leave_notify_event = gtk_xpaned_leave;
279 widget_class->button_press_event = gtk_xpaned_button_press;
280 widget_class->button_release_event = gtk_xpaned_button_release;
281 widget_class->motion_notify_event = gtk_xpaned_motion;
282 widget_class->size_request = gtk_xpaned_size_request;
283 widget_class->size_allocate = gtk_xpaned_size_allocate;
285 container_class->add = gtk_xpaned_add;
286 container_class->remove = gtk_xpaned_remove;
287 container_class->forall = gtk_xpaned_forall;
288 container_class->child_type = gtk_xpaned_child_type;
289 container_class->set_focus_child = gtk_xpaned_set_focus_child;
290 container_class->set_child_property = gtk_xpaned_set_child_property;
291 container_class->get_child_property = gtk_xpaned_get_child_property;
293 xpaned_class->cycle_child_focus = gtk_xpaned_cycle_child_focus;
294 xpaned_class->toggle_handle_focus = gtk_xpaned_toggle_handle_focus;
295 xpaned_class->move_handle = gtk_xpaned_move_handle;
296 xpaned_class->cycle_handle_focus = gtk_xpaned_cycle_handle_focus;
297 xpaned_class->accept_position = gtk_xpaned_accept_position;
298 xpaned_class->cancel_position = gtk_xpaned_cancel_position;
300 g_object_class_install_property (object_class,
302 g_param_spec_int ("x-position",
304 ("x-Position of paned separator in pixels (0 means all the way to the left)"),
308 G_PARAM_READABLE | G_PARAM_WRITABLE));
310 g_object_class_install_property (object_class,
312 g_param_spec_int ("y-position",
314 "y-Position of paned separator in pixels (0 means all the way to the top)",
318 G_PARAM_READABLE | G_PARAM_WRITABLE));
320 g_object_class_install_property (object_class,
322 g_param_spec_boolean ("position-set",
324 "TRUE if the Position property should be used",
326 G_PARAM_READABLE | G_PARAM_WRITABLE));
328 gtk_widget_class_install_style_property (widget_class,
329 g_param_spec_int ("handle-size",
337 * GtkXPaned:min-x-position:
339 * The smallest possible value for the x-position property. This property is derived from the
340 * size and shrinkability of the widget's children.
344 g_object_class_install_property (object_class,
346 g_param_spec_int ("min-x-position",
347 "Minimal x-Position",
348 "Smallest possible value for the \"x-position\" property",
355 * GtkXPaned:min-y-position:
357 * The smallest possible value for the y-position property. This property is derived from the
358 * size and shrinkability of the widget's children.
362 g_object_class_install_property (object_class,
364 g_param_spec_int ("min-y-position",
365 "Minimal y-Position",
366 "Smallest possible value for the \"y-position\" property",
373 * GtkPaned:max-x-position:
375 * The largest possible value for the x-position property. This property is derived from the
376 * size and shrinkability of the widget's children.
380 g_object_class_install_property (object_class,
382 g_param_spec_int ("max-x-position",
383 "Maximal x-Position",
384 "Largest possible value for the \"x-position\" property",
391 * GtkPaned:max-y-position:
393 * The largest possible value for the y-position property. This property is derived from the
394 * size and shrinkability of the widget's children.
398 g_object_class_install_property (object_class,
400 g_param_spec_int ("max-y-position",
401 "Maximal y-Position",
402 "Largest possible value for the \"y-position\" property",
411 * The "resize" child property determines whether the child expands and
412 * shrinks along with the paned widget.
416 gtk_container_class_install_child_property (container_class,
418 g_param_spec_boolean ("resize",
420 "If TRUE, the child expands and shrinks along with the paned widget",
427 * The "shrink" child property determines whether the child can be made
428 * smaller than its requisition.
432 gtk_container_class_install_child_property (container_class,
434 g_param_spec_boolean ("shrink",
436 "If TRUE, the child can be made smaller than its requisition",
440 signals [CYCLE_CHILD_FOCUS] = g_signal_new ("cycle-child-focus",
441 G_TYPE_FROM_CLASS (object_class),
442 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
443 G_STRUCT_OFFSET (GtkXPanedClass, cycle_child_focus),
445 gtk_marshal_BOOLEAN__BOOLEAN,
449 signals [TOGGLE_HANDLE_FOCUS] = g_signal_new ("toggle-handle-focus",
450 G_TYPE_FROM_CLASS (object_class),
451 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
452 G_STRUCT_OFFSET (GtkXPanedClass, toggle_handle_focus),
454 gtk_marshal_BOOLEAN__VOID,
457 signals[MOVE_HANDLE] = g_signal_new ("move-handle",
458 G_TYPE_FROM_CLASS (object_class),
459 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
460 G_STRUCT_OFFSET (GtkXPanedClass, move_handle),
462 gtk_marshal_BOOLEAN__ENUM,
464 GTK_TYPE_SCROLL_TYPE);
466 signals [CYCLE_HANDLE_FOCUS] = g_signal_new ("cycle-handle-focus",
467 G_TYPE_FROM_CLASS (object_class),
468 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
469 G_STRUCT_OFFSET (GtkXPanedClass, cycle_handle_focus),
471 gtk_marshal_BOOLEAN__BOOLEAN,
475 signals [ACCEPT_POSITION] = g_signal_new ("accept-position",
476 G_TYPE_FROM_CLASS (object_class),
477 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
478 G_STRUCT_OFFSET (GtkXPanedClass, accept_position),
480 gtk_marshal_BOOLEAN__VOID,
483 signals [CANCEL_POSITION] = g_signal_new ("cancel-position",
484 G_TYPE_FROM_CLASS (object_class),
485 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
486 G_STRUCT_OFFSET (GtkXPanedClass, cancel_position),
488 gtk_marshal_BOOLEAN__VOID,
491 binding_set = gtk_binding_set_by_class (class);
494 gtk_binding_entry_add_signal (binding_set,
496 "cycle-child-focus", 1,
497 G_TYPE_BOOLEAN, FALSE);
499 gtk_binding_entry_add_signal (binding_set,
500 GDK_F6, GDK_SHIFT_MASK,
501 "cycle-child-focus", 1,
502 G_TYPE_BOOLEAN, TRUE);
505 gtk_binding_entry_add_signal (binding_set,
507 "cycle-handle-focus", 1,
508 G_TYPE_BOOLEAN, FALSE);
510 gtk_binding_entry_add_signal (binding_set,
511 GDK_F8, GDK_SHIFT_MASK,
512 "cycle-handle-focus", 1,
513 G_TYPE_BOOLEAN, TRUE);
515 add_tab_bindings (binding_set, 0);
516 add_tab_bindings (binding_set, GDK_CONTROL_MASK);
517 add_tab_bindings (binding_set, GDK_SHIFT_MASK);
518 add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
520 /* accept and cancel positions */
521 gtk_binding_entry_add_signal (binding_set,
523 "cancel-position", 0);
525 gtk_binding_entry_add_signal (binding_set,
527 "accept-position", 0);
529 gtk_binding_entry_add_signal (binding_set,
531 "accept-position", 0);
533 gtk_binding_entry_add_signal (binding_set,
535 "accept-position", 0);
537 gtk_binding_entry_add_signal (binding_set,
539 "accept-position", 0);
542 add_move_binding (binding_set, GDK_Left, 0, GTK_SCROLL_STEP_LEFT);
543 add_move_binding (binding_set, GDK_KP_Left, 0, GTK_SCROLL_STEP_LEFT);
544 add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
545 add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_LEFT);
547 add_move_binding (binding_set, GDK_Right, 0, GTK_SCROLL_STEP_RIGHT);
548 add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
549 add_move_binding (binding_set, GDK_KP_Right, 0, GTK_SCROLL_STEP_RIGHT);
550 add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_RIGHT);
552 add_move_binding (binding_set, GDK_Up, 0, GTK_SCROLL_STEP_UP);
553 add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
554 add_move_binding (binding_set, GDK_KP_Up, 0, GTK_SCROLL_STEP_UP);
555 add_move_binding (binding_set, GDK_KP_Up, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_UP);
556 add_move_binding (binding_set, GDK_Page_Up, 0, GTK_SCROLL_PAGE_UP);
557 add_move_binding (binding_set, GDK_KP_Page_Up, 0, GTK_SCROLL_PAGE_UP);
559 add_move_binding (binding_set, GDK_Down, 0, GTK_SCROLL_STEP_DOWN);
560 add_move_binding (binding_set, GDK_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
561 add_move_binding (binding_set, GDK_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
562 add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK, GTK_SCROLL_PAGE_DOWN);
563 add_move_binding (binding_set, GDK_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
564 add_move_binding (binding_set, GDK_KP_Page_Down, 0, GTK_SCROLL_PAGE_RIGHT);
566 add_move_binding (binding_set, GDK_Home, 0, GTK_SCROLL_START);
567 add_move_binding (binding_set, GDK_KP_Home, 0, GTK_SCROLL_START);
568 add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
569 add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
572 static GType gtk_xpaned_child_type (GtkContainer* container)
574 if (!GTK_XPANED (container)->top_left_child ||
575 !GTK_XPANED (container)->top_right_child ||
576 !GTK_XPANED (container)->bottom_left_child ||
577 !GTK_XPANED (container)->bottom_right_child)
578 return GTK_TYPE_WIDGET;
583 static void gtk_xpaned_init (GtkXPaned* xpaned)
585 GTK_WIDGET_SET_FLAGS (xpaned, GTK_NO_WINDOW | GTK_CAN_FOCUS);
587 xpaned->top_left_child = NULL;
588 xpaned->top_right_child = NULL;
589 xpaned->bottom_left_child = NULL;
590 xpaned->bottom_right_child = NULL;
591 xpaned->handle_east = NULL;
592 xpaned->handle_west = NULL;
593 xpaned->handle_north = NULL;
594 xpaned->handle_south = NULL;
595 xpaned->handle_middle = NULL;
596 xpaned->xor_gc = NULL;
597 xpaned->cursor_type_east = GDK_SB_V_DOUBLE_ARROW;
598 xpaned->cursor_type_west = GDK_SB_V_DOUBLE_ARROW;
599 xpaned->cursor_type_north = GDK_SB_H_DOUBLE_ARROW;
600 xpaned->cursor_type_south = GDK_SB_H_DOUBLE_ARROW;
601 xpaned->cursor_type_middle = GDK_FLEUR;
603 xpaned->handle_pos_east.width = 5;
604 xpaned->handle_pos_east.height = 5;
605 xpaned->handle_pos_west.width = 5;
606 xpaned->handle_pos_west.height = 5;
607 xpaned->handle_pos_north.width = 5;
608 xpaned->handle_pos_north.height = 5;
609 xpaned->handle_pos_south.width = 5;
610 xpaned->handle_pos_south.height = 5;
611 xpaned->handle_pos_middle.width = 5;
612 xpaned->handle_pos_middle.height = 5;
614 xpaned->position_set = FALSE;
615 xpaned->last_allocation.width = -1;
616 xpaned->last_allocation.height = -1;
617 xpaned->in_drag_vert = FALSE;
618 xpaned->in_drag_horiz = FALSE;
619 xpaned->in_drag_vert_and_horiz = FALSE;
621 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
622 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
623 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
624 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
626 xpaned->priv = g_new0 (GtkXPanedPrivate, 1);
627 xpaned->last_top_left_child_focus = NULL;
628 xpaned->last_top_right_child_focus = NULL;
629 xpaned->last_bottom_left_child_focus = NULL;
630 xpaned->last_bottom_right_child_focus = NULL;
631 xpaned->in_recursion = FALSE;
632 xpaned->handle_prelit = FALSE;
633 xpaned->original_position.x = -1;
634 xpaned->original_position.y = -1;
635 xpaned->unmaximized_position.x = -1;
636 xpaned->unmaximized_position.y = -1;
638 xpaned->handle_pos_east.x = -1;
639 xpaned->handle_pos_east.y = -1;
640 xpaned->handle_pos_west.x = -1;
641 xpaned->handle_pos_west.y = -1;
642 xpaned->handle_pos_north.x = -1;
643 xpaned->handle_pos_north.y = -1;
644 xpaned->handle_pos_south.x = -1;
645 xpaned->handle_pos_south.y = -1;
646 xpaned->handle_pos_middle.x = -1;
647 xpaned->handle_pos_middle.y = -1;
649 xpaned->drag_pos.x = -1;
650 xpaned->drag_pos.y = -1;
653 static void gtk_xpaned_size_request (GtkWidget* widget,
654 GtkRequisition* requisition)
656 GtkXPaned* xpaned = GTK_XPANED (widget);
657 GtkRequisition child_requisition;
659 requisition->width = 0;
660 requisition->height = 0;
662 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child))
664 gtk_widget_size_request (xpaned->top_left_child, &child_requisition);
666 requisition->width = child_requisition.width;
667 requisition->height = child_requisition.height;
670 if (xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child))
672 gtk_widget_size_request (xpaned->top_right_child, &child_requisition);
674 requisition->width += child_requisition.width;
675 requisition->height = MAX (requisition->height, child_requisition.height);
678 if (xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child))
680 gtk_widget_size_request (xpaned->bottom_left_child, &child_requisition);
682 requisition->width = MAX (requisition->width, child_requisition.width);
683 requisition->height += child_requisition.height;
686 if (xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
688 gtk_widget_size_request (xpaned->bottom_right_child, &child_requisition);
690 requisition->width = MAX (requisition->width, child_requisition.width);
691 requisition->height = MAX (requisition->height, child_requisition.height);
694 /* add 2 times the set border-width to the GtkXPaneds requisition */
695 requisition->width += GTK_CONTAINER (xpaned)->border_width * 2;
696 requisition->height += GTK_CONTAINER (xpaned)->border_width * 2;
698 /* also add the handle "thickness" to GtkXPaneds width- and height-requisitions */
699 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
700 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
701 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
702 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
706 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
707 requisition->width += handle_size;
708 requisition->height += handle_size;
712 static void gtk_xpaned_size_allocate (GtkWidget* widget,
713 GtkAllocation* allocation)
715 GtkXPaned* xpaned = GTK_XPANED (widget);
716 gint border_width = GTK_CONTAINER (xpaned)->border_width;
717 GtkAllocation top_left_child_allocation;
718 GtkAllocation top_right_child_allocation;
719 GtkAllocation bottom_left_child_allocation;
720 GtkAllocation bottom_right_child_allocation;
721 GtkRequisition top_left_child_requisition;
722 GtkRequisition top_right_child_requisition;
723 GtkRequisition bottom_left_child_requisition;
724 GtkRequisition bottom_right_child_requisition;
727 /* determine size of handle(s) */
728 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
730 widget->allocation = *allocation;
732 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
733 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
734 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
735 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
737 /* what sizes do the children want to be at least at */
738 gtk_widget_get_child_requisition (xpaned->top_left_child,
739 &top_left_child_requisition);
740 gtk_widget_get_child_requisition (xpaned->top_right_child,
741 &top_right_child_requisition);
742 gtk_widget_get_child_requisition (xpaned->bottom_left_child,
743 &bottom_left_child_requisition);
744 gtk_widget_get_child_requisition (xpaned->bottom_right_child,
745 &bottom_right_child_requisition);
747 /* determine the total requisition-sum of all requisitions of borders,
748 * handles, children etc. */
749 gtk_xpaned_compute_position (xpaned,
751 &top_left_child_requisition,
752 &top_right_child_requisition,
753 &bottom_left_child_requisition,
754 &bottom_right_child_requisition);
756 /* calculate the current positions and sizes of the handles */
757 xpaned->handle_pos_east.x = widget->allocation.x + border_width + xpaned->top_left_child_size.width + handle_size;
758 xpaned->handle_pos_east.y = widget->allocation.y + border_width + xpaned->top_left_child_size.height;
759 xpaned->handle_pos_east.width = widget->allocation.width - xpaned->top_left_child_size.width - 2 * border_width - handle_size;
760 xpaned->handle_pos_east.height = handle_size;
762 xpaned->handle_pos_west.x = widget->allocation.x + border_width;
763 xpaned->handle_pos_west.y = xpaned->handle_pos_east.y;
764 xpaned->handle_pos_west.width = widget->allocation.width - xpaned->handle_pos_east.width - 2 * border_width - handle_size;
765 xpaned->handle_pos_west.height = handle_size;
767 xpaned->handle_pos_north.x = xpaned->handle_pos_east.x - handle_size;
768 xpaned->handle_pos_north.y = widget->allocation.y + border_width;
769 xpaned->handle_pos_north.width = handle_size;
770 xpaned->handle_pos_north.height = xpaned->handle_pos_east.y - widget->allocation.y - border_width;
772 xpaned->handle_pos_south.x = xpaned->handle_pos_north.x;
773 xpaned->handle_pos_south.y = xpaned->handle_pos_east.y + handle_size;
774 xpaned->handle_pos_south.width = handle_size;
775 xpaned->handle_pos_south.height = widget->allocation.height - xpaned->handle_pos_north.height - 2 * border_width - handle_size;
779 xpaned->handle_pos_middle.x = xpaned->handle_pos_north.x ;
780 xpaned->handle_pos_middle.y = xpaned->handle_pos_east.y ;
781 xpaned->handle_pos_middle.width = handle_size + CENTRUM ;
782 xpaned->handle_pos_middle.height = handle_size + CENTRUM;
784 /* set allocation for top-left child */
785 top_left_child_allocation.x = widget->allocation.x + border_width;
786 top_left_child_allocation.y = widget->allocation.y + border_width;
787 top_left_child_allocation.width = xpaned->handle_pos_west.width;
788 top_left_child_allocation.height = xpaned->handle_pos_north.height;
790 /* set allocation for top-right child */
791 top_right_child_allocation.x = widget->allocation.x + border_width + handle_size + top_left_child_allocation.width;
792 top_right_child_allocation.y = widget->allocation.y + border_width;
793 top_right_child_allocation.width = xpaned->handle_pos_east.width;
794 top_right_child_allocation.height = xpaned->handle_pos_north.height;
796 /* set allocation for bottom-left child */
797 bottom_left_child_allocation.x = xpaned->handle_pos_west.x;
798 bottom_left_child_allocation.y = xpaned->handle_pos_south.y;
799 bottom_left_child_allocation.width = xpaned->handle_pos_west.width;
800 bottom_left_child_allocation.height = xpaned->handle_pos_south.height;
802 /* set allocation for bottom-right child */
803 bottom_right_child_allocation.x = top_right_child_allocation.x;
804 bottom_right_child_allocation.y = bottom_left_child_allocation.y;
805 bottom_right_child_allocation.width = xpaned->handle_pos_east.width;
806 bottom_right_child_allocation.height = xpaned->handle_pos_south.height;
808 if (GTK_WIDGET_REALIZED (widget))
810 if (GTK_WIDGET_MAPPED (widget))
812 gdk_window_show (xpaned->handle_east);
813 gdk_window_show (xpaned->handle_west);
814 gdk_window_show (xpaned->handle_north);
815 gdk_window_show (xpaned->handle_south);
816 gdk_window_show (xpaned->handle_middle);
819 gdk_window_move_resize (xpaned->handle_east,
820 xpaned->handle_pos_east.x,
821 xpaned->handle_pos_east.y,
822 xpaned->handle_pos_east.width,
823 xpaned->handle_pos_east.height);
825 gdk_window_move_resize (xpaned->handle_west,
826 xpaned->handle_pos_west.x,
827 xpaned->handle_pos_west.y,
828 xpaned->handle_pos_west.width,
829 xpaned->handle_pos_west.height);
831 gdk_window_move_resize (xpaned->handle_north,
832 xpaned->handle_pos_north.x,
833 xpaned->handle_pos_north.y,
834 xpaned->handle_pos_north.width,
835 xpaned->handle_pos_north.height);
837 gdk_window_move_resize (xpaned->handle_south,
838 xpaned->handle_pos_south.x,
839 xpaned->handle_pos_south.y,
840 xpaned->handle_pos_south.width,
841 xpaned->handle_pos_south.height);
843 gdk_window_move_resize (xpaned->handle_middle,
844 xpaned->handle_pos_middle.x,
845 xpaned->handle_pos_middle.y,
846 xpaned->handle_pos_middle.width,
847 xpaned->handle_pos_middle.height);
850 /* Now allocate the childen, making sure, when resizing not to
851 * overlap the windows
853 if (GTK_WIDGET_MAPPED (widget))
855 gtk_widget_size_allocate (xpaned->top_right_child, &top_right_child_allocation);
856 gtk_widget_size_allocate (xpaned->top_left_child, &top_left_child_allocation);
857 gtk_widget_size_allocate (xpaned->bottom_left_child, &bottom_left_child_allocation);
858 gtk_widget_size_allocate (xpaned->bottom_right_child, &bottom_right_child_allocation);
863 static void gtk_xpaned_set_property (GObject* object,
868 GtkXPaned* xpaned = GTK_XPANED (object);
872 case PROP_X_POSITION:
873 gtk_xpaned_set_position_x (xpaned, g_value_get_int (value));
876 case PROP_Y_POSITION:
877 gtk_xpaned_set_position_y (xpaned, g_value_get_int (value));
880 case PROP_POSITION_SET:
881 xpaned->position_set = g_value_get_boolean (value);
882 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
886 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
891 static void gtk_xpaned_get_property (GObject* object,
896 GtkXPaned* xpaned = GTK_XPANED (object);
900 case PROP_X_POSITION:
901 g_value_set_int (value, xpaned->top_left_child_size.width);
904 case PROP_Y_POSITION:
905 g_value_set_int (value, xpaned->top_left_child_size.height);
908 case PROP_POSITION_SET:
909 g_value_set_boolean (value, xpaned->position_set);
912 case PROP_MIN_X_POSITION:
913 g_value_set_int (value, xpaned->min_position.x);
916 case PROP_MIN_Y_POSITION:
917 g_value_set_int (value, xpaned->min_position.y);
920 case PROP_MAX_X_POSITION:
921 g_value_set_int (value, xpaned->max_position.x);
924 case PROP_MAX_Y_POSITION:
925 g_value_set_int (value, xpaned->max_position.y);
929 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
934 static void gtk_xpaned_set_child_property (GtkContainer* container,
940 GtkXPaned* xpaned = GTK_XPANED (container);
941 gboolean old_value = FALSE;
942 gboolean new_value = FALSE;
944 g_assert (child == xpaned->top_left_child ||
945 child == xpaned->top_right_child ||
946 child == xpaned->bottom_left_child ||
947 child == xpaned->bottom_right_child);
949 new_value = g_value_get_boolean (value);
953 case CHILD_PROP_RESIZE:
954 if (child == xpaned->top_left_child)
956 old_value = xpaned->top_left_child_resize;
957 xpaned->top_left_child_resize = new_value;
959 else if (child == xpaned->top_right_child)
961 old_value = xpaned->top_right_child_resize;
962 xpaned->top_right_child_resize = new_value;
964 else if (child == xpaned->bottom_left_child)
966 old_value = xpaned->bottom_left_child_resize;
967 xpaned->bottom_left_child_resize = new_value;
969 else if (child == xpaned->bottom_right_child)
971 old_value = xpaned->bottom_right_child_resize;
972 xpaned->bottom_right_child_resize = new_value;
976 case CHILD_PROP_SHRINK :
977 if (child == xpaned->top_left_child)
979 old_value = xpaned->top_left_child_shrink;
980 xpaned->top_left_child_shrink = new_value;
982 else if (child == xpaned->top_right_child)
984 old_value = xpaned->top_right_child_shrink;
985 xpaned->top_right_child_shrink = new_value;
987 else if (child == xpaned->bottom_left_child)
989 old_value = xpaned->bottom_left_child_shrink;
990 xpaned->bottom_left_child_shrink = new_value;
992 else if (child == xpaned->bottom_right_child)
994 old_value = xpaned->bottom_right_child_shrink;
995 xpaned->bottom_right_child_shrink = new_value;
1000 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1003 old_value = -1; /* quiet gcc */
1007 if (old_value != new_value)
1008 gtk_widget_queue_resize (GTK_WIDGET (container));
1011 static void gtk_xpaned_get_child_property (GtkContainer* container,
1017 GtkXPaned* xpaned = GTK_XPANED (container);
1019 g_assert (child == xpaned->top_left_child ||
1020 child == xpaned->top_right_child ||
1021 child == xpaned->bottom_left_child ||
1022 child == xpaned->bottom_right_child);
1024 switch (property_id)
1026 case CHILD_PROP_RESIZE :
1027 if (child == xpaned->top_left_child)
1028 g_value_set_boolean (value, xpaned->top_left_child_resize);
1029 else if (child == xpaned->top_right_child)
1030 g_value_set_boolean (value, xpaned->top_right_child_resize);
1031 else if (child == xpaned->bottom_left_child)
1032 g_value_set_boolean (value, xpaned->bottom_left_child_resize);
1033 else if (child == xpaned->bottom_right_child)
1034 g_value_set_boolean (value, xpaned->bottom_right_child_resize);
1037 case CHILD_PROP_SHRINK :
1038 if (child == xpaned->top_left_child)
1039 g_value_set_boolean (value, xpaned->top_left_child_shrink);
1040 else if (child == xpaned->top_right_child)
1041 g_value_set_boolean (value, xpaned->top_right_child_shrink);
1042 else if (child == xpaned->bottom_left_child)
1043 g_value_set_boolean (value, xpaned->bottom_left_child_shrink);
1044 else if (child == xpaned->bottom_right_child)
1045 g_value_set_boolean (value, xpaned->bottom_right_child_shrink);
1049 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container,
1056 static void gtk_xpaned_finalize (GObject* object)
1058 GtkXPaned* xpaned = GTK_XPANED (object);
1060 gtk_xpaned_set_saved_focus (xpaned, NULL);
1061 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1063 g_free (xpaned->priv);
1065 G_OBJECT_CLASS (parent_class)->finalize (object);
1068 static void gtk_xpaned_realize (GtkWidget* widget)
1071 GdkWindowAttr attributes_east;
1072 GdkWindowAttr attributes_west;
1073 GdkWindowAttr attributes_north;
1074 GdkWindowAttr attributes_south;
1075 GdkWindowAttr attributes_middle;
1076 gint attributes_mask_east;
1077 gint attributes_mask_west;
1078 gint attributes_mask_north;
1079 gint attributes_mask_south;
1080 gint attributes_mask_middle;
1082 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1083 xpaned = GTK_XPANED (widget);
1085 widget->window = gtk_widget_get_parent_window (widget);
1086 g_object_ref (widget->window);
1088 attributes_east.window_type = GDK_WINDOW_CHILD;
1089 attributes_west.window_type = GDK_WINDOW_CHILD;
1090 attributes_north.window_type = GDK_WINDOW_CHILD;
1091 attributes_south.window_type = GDK_WINDOW_CHILD;
1092 attributes_middle.window_type = GDK_WINDOW_CHILD;
1094 attributes_east.wclass = GDK_INPUT_ONLY;
1095 attributes_west.wclass = GDK_INPUT_ONLY;
1096 attributes_north.wclass = GDK_INPUT_ONLY;
1097 attributes_south.wclass = GDK_INPUT_ONLY;
1098 attributes_middle.wclass = GDK_INPUT_ONLY;
1100 attributes_east.x = xpaned->handle_pos_east.x;
1101 attributes_east.y = xpaned->handle_pos_east.y;
1102 attributes_east.width = xpaned->handle_pos_east.width;
1103 attributes_east.height = xpaned->handle_pos_east.height;
1105 attributes_west.x = xpaned->handle_pos_west.x;
1106 attributes_west.y = xpaned->handle_pos_west.y;
1107 attributes_west.width = xpaned->handle_pos_west.width;
1108 attributes_west.height = xpaned->handle_pos_west.height;
1110 attributes_north.x = xpaned->handle_pos_north.x;
1111 attributes_north.y = xpaned->handle_pos_north.y;
1112 attributes_north.width = xpaned->handle_pos_north.width;
1113 attributes_north.height = xpaned->handle_pos_north.height;
1115 attributes_south.x = xpaned->handle_pos_south.x;
1116 attributes_south.y = xpaned->handle_pos_south.y;
1117 attributes_south.width = xpaned->handle_pos_south.width;
1118 attributes_south.height = xpaned->handle_pos_south.height;
1120 attributes_middle.x = xpaned->handle_pos_middle.x;
1121 attributes_middle.y = xpaned->handle_pos_middle.y;
1122 attributes_middle.width = xpaned->handle_pos_middle.width;
1123 attributes_middle.height = xpaned->handle_pos_middle.height;
1125 attributes_east.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1126 xpaned->cursor_type_east);
1127 attributes_west.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1128 xpaned->cursor_type_west);
1129 attributes_north.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1130 xpaned->cursor_type_north);
1131 attributes_south.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1132 xpaned->cursor_type_south);
1133 attributes_middle.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
1134 xpaned->cursor_type_middle);
1136 attributes_east.event_mask = gtk_widget_get_events (widget);
1137 attributes_west.event_mask = gtk_widget_get_events (widget);
1138 attributes_north.event_mask = gtk_widget_get_events (widget);
1139 attributes_south.event_mask = gtk_widget_get_events (widget);
1140 attributes_middle.event_mask = gtk_widget_get_events (widget);
1142 attributes_east.event_mask |= (GDK_BUTTON_PRESS_MASK |
1143 GDK_BUTTON_RELEASE_MASK |
1144 GDK_ENTER_NOTIFY_MASK |
1145 GDK_LEAVE_NOTIFY_MASK |
1146 GDK_POINTER_MOTION_MASK |
1147 GDK_POINTER_MOTION_HINT_MASK);
1148 attributes_west.event_mask |= (GDK_BUTTON_PRESS_MASK |
1149 GDK_BUTTON_RELEASE_MASK |
1150 GDK_ENTER_NOTIFY_MASK |
1151 GDK_LEAVE_NOTIFY_MASK |
1152 GDK_POINTER_MOTION_MASK |
1153 GDK_POINTER_MOTION_HINT_MASK);
1154 attributes_north.event_mask |= (GDK_BUTTON_PRESS_MASK |
1155 GDK_BUTTON_RELEASE_MASK |
1156 GDK_ENTER_NOTIFY_MASK |
1157 GDK_LEAVE_NOTIFY_MASK |
1158 GDK_POINTER_MOTION_MASK |
1159 GDK_POINTER_MOTION_HINT_MASK);
1160 attributes_south.event_mask |= (GDK_BUTTON_PRESS_MASK |
1161 GDK_BUTTON_RELEASE_MASK |
1162 GDK_ENTER_NOTIFY_MASK |
1163 GDK_LEAVE_NOTIFY_MASK |
1164 GDK_POINTER_MOTION_MASK |
1165 GDK_POINTER_MOTION_HINT_MASK);
1166 attributes_middle.event_mask |= (GDK_BUTTON_PRESS_MASK |
1167 GDK_BUTTON_RELEASE_MASK |
1168 GDK_ENTER_NOTIFY_MASK |
1169 GDK_LEAVE_NOTIFY_MASK |
1170 GDK_POINTER_MOTION_MASK |
1171 GDK_POINTER_MOTION_HINT_MASK);
1173 attributes_mask_east = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1174 attributes_mask_west = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1175 attributes_mask_north = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1176 attributes_mask_south = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1177 attributes_mask_middle = GDK_WA_X | GDK_WA_Y | GDK_WA_CURSOR;
1179 xpaned->handle_east = gdk_window_new (widget->window,
1181 attributes_mask_east);
1182 xpaned->handle_west = gdk_window_new (widget->window,
1184 attributes_mask_west);
1185 xpaned->handle_north = gdk_window_new (widget->window,
1187 attributes_mask_north);
1188 xpaned->handle_south = gdk_window_new (widget->window,
1190 attributes_mask_south);
1191 xpaned->handle_middle = gdk_window_new (widget->window,
1193 attributes_mask_middle);
1195 gdk_window_set_user_data (xpaned->handle_east, xpaned);
1196 gdk_window_set_user_data (xpaned->handle_west, xpaned);
1197 gdk_window_set_user_data (xpaned->handle_north, xpaned);
1198 gdk_window_set_user_data (xpaned->handle_south, xpaned);
1199 gdk_window_set_user_data (xpaned->handle_middle, xpaned);
1201 gdk_cursor_unref (attributes_east.cursor);
1202 gdk_cursor_unref (attributes_west.cursor);
1203 gdk_cursor_unref (attributes_north.cursor);
1204 gdk_cursor_unref (attributes_south.cursor);
1205 gdk_cursor_unref (attributes_middle.cursor);
1207 widget->style = gtk_style_attach (widget->style, widget->window);
1209 if (xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
1210 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
1211 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
1212 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
1214 gdk_window_show (xpaned->handle_east);
1215 gdk_window_show (xpaned->handle_west);
1216 gdk_window_show (xpaned->handle_north);
1217 gdk_window_show (xpaned->handle_south);
1218 gdk_window_show (xpaned->handle_middle);
1222 static void gtk_xpaned_unrealize (GtkWidget *widget)
1224 GtkXPaned* xpaned = GTK_XPANED (widget);
1228 g_object_unref (xpaned->xor_gc);
1229 xpaned->xor_gc = NULL;
1232 if (xpaned->handle_east)
1234 gdk_window_set_user_data (xpaned->handle_east, NULL);
1235 gdk_window_destroy (xpaned->handle_east);
1236 xpaned->handle_east = NULL;
1239 if (xpaned->handle_west)
1241 gdk_window_set_user_data (xpaned->handle_west, NULL);
1242 gdk_window_destroy (xpaned->handle_west);
1243 xpaned->handle_west = NULL;
1246 if (xpaned->handle_north)
1248 gdk_window_set_user_data (xpaned->handle_north, NULL);
1249 gdk_window_destroy (xpaned->handle_north);
1250 xpaned->handle_north = NULL;
1253 if (xpaned->handle_south)
1255 gdk_window_set_user_data (xpaned->handle_south, NULL);
1256 gdk_window_destroy (xpaned->handle_south);
1257 xpaned->handle_south = NULL;
1260 if (xpaned->handle_middle)
1262 gdk_window_set_user_data (xpaned->handle_middle, NULL);
1263 gdk_window_destroy (xpaned->handle_middle);
1264 xpaned->handle_middle = NULL;
1267 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
1268 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
1269 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
1270 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
1271 gtk_xpaned_set_saved_focus (xpaned, NULL);
1272 gtk_xpaned_set_first_xpaned (xpaned, NULL);
1274 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1275 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1278 static void gtk_xpaned_map (GtkWidget* widget)
1280 GtkXPaned* xpaned = GTK_XPANED (widget);
1282 gdk_window_show (xpaned->handle_east);
1283 gdk_window_show (xpaned->handle_west);
1284 gdk_window_show (xpaned->handle_north);
1285 gdk_window_show (xpaned->handle_south);
1286 gdk_window_show (xpaned->handle_middle);
1288 GTK_WIDGET_CLASS (parent_class)->map (widget);
1291 static void gtk_xpaned_unmap (GtkWidget* widget)
1293 GtkXPaned* xpaned = GTK_XPANED (widget);
1295 gdk_window_hide (xpaned->handle_east);
1296 gdk_window_hide (xpaned->handle_west);
1297 gdk_window_hide (xpaned->handle_north);
1298 gdk_window_hide (xpaned->handle_south);
1299 gdk_window_hide (xpaned->handle_middle);
1301 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1304 static gboolean gtk_xpaned_expose (GtkWidget* widget,
1305 GdkEventExpose* event)
1307 GtkXPaned* xpaned = GTK_XPANED (widget);
1309 GdkRectangle horizontalClipArea;
1310 GdkRectangle verticalClipArea;
1312 /* determine size of handle(s) */
1313 gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
1315 /* I want the handle-"thickness" to be at least 3 */
1316 g_assert (handle_size >= 3);
1318 if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget) &&
1319 xpaned->top_left_child && GTK_WIDGET_VISIBLE (xpaned->top_left_child) &&
1320 xpaned->top_right_child && GTK_WIDGET_VISIBLE (xpaned->top_right_child) &&
1321 xpaned->bottom_left_child && GTK_WIDGET_VISIBLE (xpaned->bottom_left_child) &&
1322 xpaned->bottom_right_child && GTK_WIDGET_VISIBLE (xpaned->bottom_right_child))
1326 if (gtk_widget_is_focus (widget))
1327 state = GTK_STATE_SELECTED;
1328 else if (xpaned->handle_prelit)
1329 state = GTK_STATE_PRELIGHT;
1331 state = GTK_WIDGET_STATE (widget);
1333 horizontalClipArea.x = xpaned->handle_pos_west.x;
1334 horizontalClipArea.y = xpaned->handle_pos_west.y;
1335 horizontalClipArea.width = xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width;
1336 horizontalClipArea.height = handle_size;
1338 verticalClipArea.x = xpaned->handle_pos_north.x;
1339 verticalClipArea.y = xpaned->handle_pos_north.y;
1340 verticalClipArea.width = handle_size;
1341 verticalClipArea.height = xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height;
1343 gtk_paint_handle (widget->style,
1347 &horizontalClipArea,
1350 xpaned->handle_pos_east.x - handle_size - 256 / 2,
1351 xpaned->handle_pos_west.y + 1,
1354 /*xpaned->handle_pos_west.x,
1355 xpaned->handle_pos_west.y + 1,
1356 xpaned->handle_pos_west.width + handle_size + xpaned->handle_pos_east.width,
1358 GTK_ORIENTATION_HORIZONTAL);
1359 gtk_paint_handle (widget->style,
1366 xpaned->handle_pos_north.x + 1,
1367 xpaned->handle_pos_south.y - handle_size - 256 / 2,
1370 /*xpaned->handle_pos_north.x + 1,
1371 xpaned->handle_pos_north.y,
1373 xpaned->handle_pos_north.height + handle_size + xpaned->handle_pos_south.height,*/
1374 GTK_ORIENTATION_VERTICAL);
1377 /* Chain up to draw children */
1378 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
1383 static gboolean is_rtl (GtkXPaned* xpaned)
1385 if (gtk_widget_get_direction (GTK_WIDGET (xpaned)) == GTK_TEXT_DIR_RTL)
1391 static void update_drag (GtkXPaned* xpaned)
1395 GtkRequisition size;
1397 gtk_widget_get_pointer (GTK_WIDGET (xpaned), &pos.x, &pos.y);
1399 if (xpaned->in_drag_vert)
1401 pos.y -= xpaned->drag_pos.y;
1403 if (is_rtl (xpaned))
1405 gtk_widget_style_get (GTK_WIDGET (xpaned),
1406 "handle-size", &handle_size,
1409 size.height = GTK_WIDGET (xpaned)->allocation.height - pos.y - handle_size;
1413 size.height = pos.y;
1416 size.height -= GTK_CONTAINER (xpaned)->border_width;
1418 size.height = CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1420 if (size.height != xpaned->top_left_child_size.height)
1421 gtk_xpaned_set_position_y (xpaned, size.height);
1424 if (xpaned->in_drag_horiz)
1426 pos.x -= xpaned->drag_pos.x;
1428 if (is_rtl (xpaned))
1430 gtk_widget_style_get (GTK_WIDGET (xpaned),
1431 "handle-size", &handle_size,
1434 size.width = GTK_WIDGET (xpaned)->allocation.width - pos.x - handle_size;
1441 size.width -= GTK_CONTAINER (xpaned)->border_width;
1443 size.width = CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1445 if (size.width != xpaned->top_left_child_size.width)
1446 gtk_xpaned_set_position_x (xpaned, size.width);
1449 if (xpaned->in_drag_vert_and_horiz)
1451 pos.x -= xpaned->drag_pos.x;
1452 pos.y -= xpaned->drag_pos.y;
1454 if (is_rtl (xpaned))
1456 gtk_widget_style_get (GTK_WIDGET (xpaned),
1457 "handle-size", &handle_size,
1460 size.width = GTK_WIDGET (xpaned)->allocation.width - pos.x - handle_size;
1461 size.height = GTK_WIDGET (xpaned)->allocation.height - pos.y - handle_size;
1466 size.height = pos.y;
1469 size.width -= GTK_CONTAINER (xpaned)->border_width;
1470 size.height -= GTK_CONTAINER (xpaned)->border_width;
1472 size.width = CLAMP (size.width, xpaned->min_position.x, xpaned->max_position.x);
1473 size.height = CLAMP (size.height, xpaned->min_position.y, xpaned->max_position.y);
1475 if (size.width != xpaned->top_left_child_size.width)
1476 gtk_xpaned_set_position_x (xpaned, size.width);
1478 if (size.height != xpaned->top_left_child_size.height)
1479 gtk_xpaned_set_position_y (xpaned, size.height);
1483 static gboolean gtk_xpaned_enter (GtkWidget* widget, GdkEventCrossing* event)
1485 GtkXPaned* xpaned = GTK_XPANED (widget);
1487 if (xpaned->in_drag_vert ||
1488 xpaned->in_drag_horiz ||
1489 xpaned->in_drag_vert_and_horiz)
1490 update_drag (xpaned);
1493 xpaned->handle_prelit = TRUE;
1495 gtk_widget_queue_draw_area (widget,
1496 xpaned->handle_pos_east.x,
1497 xpaned->handle_pos_east.y,
1498 xpaned->handle_pos_east.width,
1499 xpaned->handle_pos_east.height);
1501 gtk_widget_queue_draw_area (widget,
1502 xpaned->handle_pos_west.x,
1503 xpaned->handle_pos_west.y,
1504 xpaned->handle_pos_west.width,
1505 xpaned->handle_pos_west.height);
1507 gtk_widget_queue_draw_area (widget,
1508 xpaned->handle_pos_north.x,
1509 xpaned->handle_pos_north.y,
1510 xpaned->handle_pos_north.width,
1511 xpaned->handle_pos_north.height);
1513 gtk_widget_queue_draw_area (widget,
1514 xpaned->handle_pos_south.x,
1515 xpaned->handle_pos_south.y,
1516 xpaned->handle_pos_south.width,
1517 xpaned->handle_pos_south.height);
1519 gtk_widget_queue_draw_area (widget,
1520 xpaned->handle_pos_middle.x,
1521 xpaned->handle_pos_middle.y,
1522 xpaned->handle_pos_middle.width,
1523 xpaned->handle_pos_middle.height);
1529 static gboolean gtk_xpaned_leave (GtkWidget* widget, GdkEventCrossing* event)
1531 GtkXPaned* xpaned = GTK_XPANED (widget);
1533 if (xpaned->in_drag_vert ||
1534 xpaned->in_drag_horiz ||
1535 xpaned->in_drag_vert_and_horiz)
1536 update_drag (xpaned);
1539 xpaned->handle_prelit = FALSE;
1541 gtk_widget_queue_draw_area (widget,
1542 xpaned->handle_pos_east.x,
1543 xpaned->handle_pos_east.y,
1544 xpaned->handle_pos_east.width,
1545 xpaned->handle_pos_east.height);
1547 gtk_widget_queue_draw_area (widget,
1548 xpaned->handle_pos_west.x,
1549 xpaned->handle_pos_west.y,
1550 xpaned->handle_pos_west.width,
1551 xpaned->handle_pos_west.height);
1553 gtk_widget_queue_draw_area (widget,
1554 xpaned->handle_pos_north.x,
1555 xpaned->handle_pos_north.y,
1556 xpaned->handle_pos_north.width,
1557 xpaned->handle_pos_north.height);
1559 gtk_widget_queue_draw_area (widget,
1560 xpaned->handle_pos_south.x,
1561 xpaned->handle_pos_south.y,
1562 xpaned->handle_pos_south.width,
1563 xpaned->handle_pos_south.height);
1565 gtk_widget_queue_draw_area (widget,
1566 xpaned->handle_pos_middle.x,
1567 xpaned->handle_pos_middle.y,
1568 xpaned->handle_pos_middle.width,
1569 xpaned->handle_pos_middle.height);
1575 static gboolean gtk_xpaned_focus (GtkWidget* widget, GtkDirectionType direction)
1579 /* This is a hack, but how can this be done without
1580 * excessive cut-and-paste from gtkcontainer.c?
1583 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1584 retval = (* GTK_WIDGET_CLASS (parent_class)->focus) (widget, direction);
1585 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1590 static gboolean gtk_xpaned_button_press (GtkWidget* widget,
1591 GdkEventButton* event)
1593 GtkXPaned* xpaned = GTK_XPANED (widget);
1595 /* if any child is currently maximized, jump right back */
1596 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
1597 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
1598 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
1599 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
1602 /* if user is dragging the handles around */
1603 if (!xpaned->in_drag_vert_and_horiz &&
1604 event->window != xpaned->handle_east &&
1605 event->window != xpaned->handle_west &&
1606 event->window != xpaned->handle_north &&
1607 event->window != xpaned->handle_south &&
1608 event->window == xpaned->handle_middle &&
1611 xpaned->in_drag_vert_and_horiz = TRUE;
1613 /* We need a server grab here, not gtk_grab_add(), since
1614 * we don't want to pass events on to the widget's children */
1615 if (gdk_pointer_grab (xpaned->handle_middle,
1617 GDK_POINTER_MOTION_HINT_MASK
1618 | GDK_BUTTON1_MOTION_MASK
1619 | GDK_BUTTON_RELEASE_MASK
1620 | GDK_ENTER_NOTIFY_MASK
1621 | GDK_LEAVE_NOTIFY_MASK,
1624 event->time) == GDK_GRAB_SUCCESS)
1628 xpaned->drag_pos.x = event->x;
1629 xpaned->drag_pos.y = event->y;
1633 else if (!xpaned->in_drag_vert &&
1634 event->window == xpaned->handle_east &&
1635 event->window != xpaned->handle_west &&
1636 event->window != xpaned->handle_north &&
1637 event->window != xpaned->handle_south &&
1638 event->window != xpaned->handle_middle &&
1641 xpaned->in_drag_vert = TRUE;
1643 /* We need a server grab here, not gtk_grab_add(), since
1644 * we don't want to pass events on to the widget's children */
1645 if (gdk_pointer_grab (xpaned->handle_east,
1647 GDK_POINTER_MOTION_HINT_MASK
1648 | GDK_BUTTON1_MOTION_MASK
1649 | GDK_BUTTON_RELEASE_MASK
1650 | GDK_ENTER_NOTIFY_MASK
1651 | GDK_LEAVE_NOTIFY_MASK,
1654 event->time) == GDK_GRAB_SUCCESS)
1658 xpaned->drag_pos.y = event->y;
1662 else if (!xpaned->in_drag_vert &&
1663 event->window != xpaned->handle_east &&
1664 event->window == xpaned->handle_west &&
1665 event->window != xpaned->handle_north &&
1666 event->window != xpaned->handle_south &&
1667 event->window != xpaned->handle_middle &&
1670 xpaned->in_drag_vert = TRUE;
1672 /* We need a server grab here, not gtk_grab_add(), since
1673 * we don't want to pass events on to the widget's children */
1674 if (gdk_pointer_grab (xpaned->handle_west,
1676 GDK_POINTER_MOTION_HINT_MASK
1677 | GDK_BUTTON1_MOTION_MASK
1678 | GDK_BUTTON_RELEASE_MASK
1679 | GDK_ENTER_NOTIFY_MASK
1680 | GDK_LEAVE_NOTIFY_MASK,
1683 event->time) == GDK_GRAB_SUCCESS)
1687 xpaned->drag_pos.y = event->y;
1691 else if (!xpaned->in_drag_horiz &&
1692 event->window != xpaned->handle_east &&
1693 event->window != xpaned->handle_west &&
1694 event->window == xpaned->handle_north &&
1695 event->window != xpaned->handle_south &&
1696 event->window != xpaned->handle_middle &&
1699 xpaned->in_drag_horiz = TRUE;
1701 /* We need a server grab here, not gtk_grab_add(), since
1702 * we don't want to pass events on to the widget's children */
1703 if (gdk_pointer_grab (xpaned->handle_north,
1705 GDK_POINTER_MOTION_HINT_MASK
1706 | GDK_BUTTON1_MOTION_MASK
1707 | GDK_BUTTON_RELEASE_MASK
1708 | GDK_ENTER_NOTIFY_MASK
1709 | GDK_LEAVE_NOTIFY_MASK,
1712 event->time) == GDK_GRAB_SUCCESS)
1716 xpaned->drag_pos.x = event->x;
1720 else if (!xpaned->in_drag_horiz &&
1721 event->window != xpaned->handle_east &&
1722 event->window != xpaned->handle_west &&
1723 event->window != xpaned->handle_north &&
1724 event->window == xpaned->handle_south &&
1725 event->window != xpaned->handle_middle &&
1728 xpaned->in_drag_horiz = TRUE;
1730 /* We need a server grab here, not gtk_grab_add(), since
1731 * we don't want to pass events on to the widget's children */
1732 if (gdk_pointer_grab (xpaned->handle_south,
1734 GDK_POINTER_MOTION_HINT_MASK
1735 | GDK_BUTTON1_MOTION_MASK
1736 | GDK_BUTTON_RELEASE_MASK
1737 | GDK_ENTER_NOTIFY_MASK
1738 | GDK_LEAVE_NOTIFY_MASK,
1741 event->time) == GDK_GRAB_SUCCESS)
1745 xpaned->drag_pos.x = event->x;
1752 static gboolean gtk_xpaned_button_release (GtkWidget* widget,
1753 GdkEventButton* event)
1755 GtkXPaned* xpaned = GTK_XPANED (widget);
1757 if (xpaned->in_drag_vert && (event->button == 1))
1759 xpaned->in_drag_vert = FALSE;
1760 xpaned->drag_pos.y = -1;
1761 xpaned->position_set = TRUE;
1762 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1766 else if (xpaned->in_drag_horiz && (event->button == 1))
1768 xpaned->in_drag_horiz = FALSE;
1769 xpaned->drag_pos.x = -1;
1770 xpaned->position_set = TRUE;
1771 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1775 else if (xpaned->in_drag_vert_and_horiz && (event->button == 1))
1777 xpaned->in_drag_vert_and_horiz = FALSE;
1778 xpaned->drag_pos.x = -1;
1779 xpaned->drag_pos.y = -1;
1780 xpaned->position_set = TRUE;
1781 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
1789 static gboolean gtk_xpaned_motion (GtkWidget* widget, GdkEventMotion* event)
1791 GtkXPaned* xpaned = GTK_XPANED (widget);
1793 if (xpaned->in_drag_vert ||
1794 xpaned->in_drag_horiz ||
1795 xpaned->in_drag_vert_and_horiz)
1798 update_drag (xpaned);
1805 void gtk_xpaned_add_top_left (GtkXPaned* xpaned, GtkWidget *widget)
1807 gtk_xpaned_pack_top_left (xpaned, widget, FALSE, TRUE);
1810 void gtk_xpaned_add_top_right (GtkXPaned* xpaned, GtkWidget *widget)
1812 gtk_xpaned_pack_top_right (xpaned, widget, FALSE, TRUE);
1815 void gtk_xpaned_add_bottom_left (GtkXPaned* xpaned, GtkWidget *widget)
1817 gtk_xpaned_pack_bottom_left (xpaned, widget, FALSE, TRUE);
1820 void gtk_xpaned_add_bottom_right (GtkXPaned* xpaned, GtkWidget *widget)
1822 gtk_xpaned_pack_bottom_right (xpaned, widget, FALSE, TRUE);
1825 void gtk_xpaned_pack_top_left (GtkXPaned* xpaned,
1830 g_return_if_fail (GTK_IS_XPANED (xpaned));
1831 g_return_if_fail (GTK_IS_WIDGET (child));
1833 if (!xpaned->top_left_child)
1835 xpaned->top_left_child = child;
1836 xpaned->top_left_child_resize = resize;
1837 xpaned->top_left_child_shrink = shrink;
1839 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1843 void gtk_xpaned_pack_top_right (GtkXPaned* xpaned,
1848 g_return_if_fail (GTK_IS_XPANED (xpaned));
1849 g_return_if_fail (GTK_IS_WIDGET (child));
1851 if (!xpaned->top_right_child)
1853 xpaned->top_right_child = child;
1854 xpaned->top_right_child_resize = resize;
1855 xpaned->top_right_child_shrink = shrink;
1857 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1861 void gtk_xpaned_pack_bottom_left (GtkXPaned* xpaned,
1866 g_return_if_fail (GTK_IS_XPANED (xpaned));
1867 g_return_if_fail (GTK_IS_WIDGET (child));
1869 if (!xpaned->bottom_left_child)
1871 xpaned->bottom_left_child = child;
1872 xpaned->bottom_left_child_resize = resize;
1873 xpaned->bottom_left_child_shrink = shrink;
1875 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1879 void gtk_xpaned_pack_bottom_right (GtkXPaned* xpaned,
1884 g_return_if_fail (GTK_IS_XPANED (xpaned));
1885 g_return_if_fail (GTK_IS_WIDGET (child));
1887 if (!xpaned->bottom_right_child)
1889 xpaned->bottom_right_child = child;
1890 xpaned->bottom_right_child_resize = resize;
1891 xpaned->bottom_right_child_shrink = shrink;
1893 gtk_widget_set_parent (child, GTK_WIDGET (xpaned));
1897 static void gtk_xpaned_add (GtkContainer* container, GtkWidget* widget)
1901 g_return_if_fail (GTK_IS_XPANED (container));
1903 xpaned = GTK_XPANED (container);
1905 if (!xpaned->top_left_child)
1906 gtk_xpaned_add_top_left (xpaned, widget);
1907 else if (!xpaned->top_right_child)
1908 gtk_xpaned_add_top_right (xpaned, widget);
1909 else if (!xpaned->bottom_left_child)
1910 gtk_xpaned_add_bottom_left (xpaned, widget);
1911 else if (!xpaned->bottom_right_child)
1912 gtk_xpaned_add_bottom_right (xpaned, widget);
1914 g_warning ("GtkXPaned cannot have more than 4 children\n");
1917 static void gtk_xpaned_remove (GtkContainer* container, GtkWidget* widget)
1920 gboolean was_visible;
1922 xpaned = GTK_XPANED (container);
1923 was_visible = GTK_WIDGET_VISIBLE (widget);
1925 if (xpaned->top_left_child == widget)
1927 gtk_widget_unparent (widget);
1929 xpaned->top_left_child = NULL;
1931 if (was_visible && GTK_WIDGET_VISIBLE (container))
1932 gtk_widget_queue_resize (GTK_WIDGET (container));
1934 else if (xpaned->top_right_child == widget)
1936 gtk_widget_unparent (widget);
1938 xpaned->top_right_child = NULL;
1940 if (was_visible && GTK_WIDGET_VISIBLE (container))
1941 gtk_widget_queue_resize (GTK_WIDGET (container));
1943 else if (xpaned->bottom_left_child == widget)
1945 gtk_widget_unparent (widget);
1947 xpaned->bottom_left_child = NULL;
1949 if (was_visible && GTK_WIDGET_VISIBLE (container))
1950 gtk_widget_queue_resize (GTK_WIDGET (container));
1952 else if (xpaned->bottom_right_child == widget)
1954 gtk_widget_unparent (widget);
1956 xpaned->bottom_right_child = NULL;
1958 if (was_visible && GTK_WIDGET_VISIBLE (container))
1959 gtk_widget_queue_resize (GTK_WIDGET (container));
1962 g_warning ("GtkXPaned has no more children attached\n");
1966 static void gtk_xpaned_forall (GtkContainer* container,
1967 gboolean include_internals,
1968 GtkCallback callback,
1969 gpointer callback_data)
1973 g_return_if_fail (callback != NULL);
1975 xpaned = GTK_XPANED (container);
1977 if (xpaned->top_left_child)
1978 (*callback) (xpaned->top_left_child, callback_data);
1979 if (xpaned->top_right_child)
1980 (*callback) (xpaned->top_right_child, callback_data);
1981 if (xpaned->bottom_left_child)
1982 (*callback) (xpaned->bottom_left_child, callback_data);
1983 if (xpaned->bottom_right_child)
1984 (*callback) (xpaned->bottom_right_child, callback_data);
1988 * gtk_xpaned_get_position_x:
1989 * @paned: a #GtkXPaned widget
1991 * Obtains the x-position of the divider.
1993 * Return value: x-position of the divider
1995 gint gtk_xpaned_get_position_x (GtkXPaned* xpaned)
1997 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
1999 return xpaned->top_left_child_size.width;
2003 * gtk_xpaned_get_position_y:
2004 * @paned: a #GtkXPaned widget
2006 * Obtains the y-position of the divider.
2008 * Return value: y-position of the divider
2010 gint gtk_xpaned_get_position_y (GtkXPaned* xpaned)
2012 g_return_val_if_fail (GTK_IS_XPANED (xpaned), 0);
2014 return xpaned->top_left_child_size.height;
2018 * gtk_xpaned_set_position_x:
2019 * @paned: a #GtkXPaned widget
2020 * @xposition: pixel x-position of divider, a negative values
2021 * of a component mean that the position is unset.
2023 * Sets the x-position of the divider between the four panes.
2025 void gtk_xpaned_set_position_x (GtkXPaned* xpaned, gint xposition)
2029 g_return_if_fail (GTK_IS_XPANED (xpaned));
2031 /* if any child is currently maximized, jump right back */
2032 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2033 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2034 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2035 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2038 object = G_OBJECT (xpaned);
2042 /* We don't clamp here - the assumption is that
2043 * if the total allocation changes at the same time
2044 * as the position, the position set is with reference
2045 * to the new total size. If only the position changes,
2046 * then clamping will occur in gtk_paned_compute_position()
2049 xpaned->top_left_child_size.width = xposition;
2050 xpaned->position_set = TRUE;
2054 xpaned->position_set = FALSE;
2057 g_object_freeze_notify (object);
2058 g_object_notify (object, "x-position");
2059 g_object_notify (object, "position-set");
2060 g_object_thaw_notify (object);
2062 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2066 * gtk_xpaned_set_position_y:
2067 * @paned: a #GtkXPaned widget
2068 * @yposition: pixel y-position of divider, a negative values
2069 * of a component mean that the position is unset.
2071 * Sets the y-position of the divider between the four panes.
2073 void gtk_xpaned_set_position_y (GtkXPaned* xpaned, gint yposition)
2077 g_return_if_fail (GTK_IS_XPANED (xpaned));
2079 /* if any child is currently maximized, jump right back */
2080 if (xpaned->maximized[GTK_XPANED_TOP_LEFT] ||
2081 xpaned->maximized[GTK_XPANED_TOP_RIGHT] ||
2082 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] ||
2083 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2086 object = G_OBJECT (xpaned);
2090 /* We don't clamp here - the assumption is that
2091 * if the total allocation changes at the same time
2092 * as the position, the position set is with reference
2093 * to the new total size. If only the position changes,
2094 * then clamping will occur in gtk_paned_compute_position()
2097 xpaned->top_left_child_size.height = yposition;
2098 xpaned->position_set = TRUE;
2102 xpaned->position_set = FALSE;
2105 g_object_freeze_notify (object);
2106 g_object_notify (object, "y-position");
2107 g_object_notify (object, "position-set");
2108 g_object_thaw_notify (object);
2110 gtk_widget_queue_resize (GTK_WIDGET (xpaned));
2113 /* this call is private and only intended for internal use! */
2114 void gtk_xpaned_save_unmaximized_x (GtkXPaned* xpaned)
2116 xpaned->unmaximized_position.x = gtk_xpaned_get_position_x (xpaned);
2119 /* this call is private and only intended for internal use! */
2120 void gtk_xpaned_save_unmaximized_y (GtkXPaned* xpaned)
2122 xpaned->unmaximized_position.y = gtk_xpaned_get_position_y (xpaned);
2125 /* this call is private and only intended for internal use! */
2126 gint gtk_xpaned_fetch_unmaximized_x (GtkXPaned* xpaned)
2128 return xpaned->unmaximized_position.x;
2131 /* this call is private and only intended for internal use! */
2132 gint gtk_xpaned_fetch_unmaximized_y (GtkXPaned* xpaned)
2134 return xpaned->unmaximized_position.y;
2138 * gtk_xpaned_get_top_left_child:
2139 * @xpaned: a #GtkXPaned widget
2141 * Obtains the top-left child of the xpaned widget.
2143 * Return value: top-left child, or %NULL if it is not set.
2147 GtkWidget* gtk_xpaned_get_top_left_child (GtkXPaned* xpaned)
2149 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2151 return xpaned->top_left_child;
2155 * gtk_xpaned_get_top_right_child:
2156 * @xpaned: a #GtkXPaned widget
2158 * Obtains the top-right child of the xpaned widget.
2160 * Return value: top-right child, or %NULL if it is not set.
2164 GtkWidget* gtk_xpaned_get_top_right_child (GtkXPaned* xpaned)
2166 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2168 return xpaned->top_right_child;
2172 * gtk_xpaned_get_bottom_left_child:
2173 * @xpaned: a #GtkXPaned widget
2175 * Obtains the bottom-left child of the xpaned widget.
2177 * Return value: bottom-left child, or %NULL if it is not set.
2181 GtkWidget* gtk_xpaned_get_bottom_left_child (GtkXPaned* xpaned)
2183 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2185 return xpaned->bottom_left_child;
2189 * gtk_xpaned_get_bottom_right_child:
2190 * @xpaned: a #GtkXPaned widget
2192 * Obtains the bottom-right child of the xpaned widget.
2194 * Return value: bottom-right child, or %NULL if it is not set.
2198 GtkWidget* gtk_xpaned_get_bottom_right_child (GtkXPaned* xpaned)
2200 g_return_val_if_fail (GTK_IS_XPANED (xpaned), NULL);
2202 return xpaned->bottom_right_child;
2205 gboolean gtk_xpaned_maximize_top_left (GtkXPaned* xpaned, gboolean maximize)
2209 /* see if any child is already maximized */
2210 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2211 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2212 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2213 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2215 /* save current position */
2216 gtk_xpaned_save_unmaximized_x (xpaned);
2217 gtk_xpaned_save_unmaximized_y (xpaned);
2219 /* set new maximized position */
2220 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2221 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2223 /* mark maximized flag for top-left child */
2224 xpaned->maximized[GTK_XPANED_TOP_LEFT] = TRUE;
2228 /* already one child maximized, report error */
2234 /* verify that top-left child is really currently maximized */
2235 if (xpaned->maximized[GTK_XPANED_TOP_LEFT])
2237 /* clear maximized flat for top-left child */
2238 xpaned->maximized[GTK_XPANED_TOP_LEFT] = FALSE;
2240 /* restore unmaximized position */
2241 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2242 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2246 /* top-left child is currently not maximized, report error */
2252 gboolean gtk_xpaned_maximize_top_right (GtkXPaned* xpaned, gboolean maximize)
2256 /* see if any child is already maximized */
2257 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2258 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2259 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2260 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2262 /* save current position */
2263 gtk_xpaned_save_unmaximized_x (xpaned);
2264 gtk_xpaned_save_unmaximized_y (xpaned);
2266 /* set new maximized position */
2267 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2268 gtk_xpaned_set_position_y (xpaned, xpaned->max_position.y);
2270 /* mark maximized flag for top-right child */
2271 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = TRUE;
2275 /* already one child maximized, report error */
2281 /* verify that top-right child is really currently maximized */
2282 if (xpaned->maximized[GTK_XPANED_TOP_RIGHT])
2284 /* clear maximized flat for top-right child */
2285 xpaned->maximized[GTK_XPANED_TOP_RIGHT] = FALSE;
2287 /* restore unmaximized position */
2288 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2289 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2293 /* top-right child is currently not maximized, report error */
2299 gboolean gtk_xpaned_maximize_bottom_left (GtkXPaned* xpaned, gboolean maximize)
2303 /* see if any child is already maximized */
2304 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2305 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2306 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2307 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2309 /* save current position */
2310 gtk_xpaned_save_unmaximized_x (xpaned);
2311 gtk_xpaned_save_unmaximized_y (xpaned);
2313 /* set new maximized position */
2314 gtk_xpaned_set_position_x (xpaned, xpaned->max_position.x);
2315 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2317 /* mark maximized flag for bottom-left child */
2318 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = TRUE;
2322 /* already one child maximized, report error */
2328 /* verify that bottom-left child is really currently maximized */
2329 if (xpaned->maximized[GTK_XPANED_BOTTOM_LEFT])
2331 /* clear maximized flat for bottom-left child */
2332 xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] = FALSE;
2334 /* restore unmaximized position */
2335 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2336 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2340 /* bottom-left child is currently not maximized, report error */
2346 gboolean gtk_xpaned_maximize_bottom_right (GtkXPaned* xpaned, gboolean maximize)
2350 /* see if any child is already maximized */
2351 if (!xpaned->maximized[GTK_XPANED_TOP_LEFT] &&
2352 !xpaned->maximized[GTK_XPANED_TOP_RIGHT] &&
2353 !xpaned->maximized[GTK_XPANED_BOTTOM_LEFT] &&
2354 !xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2356 /* save current position */
2357 gtk_xpaned_save_unmaximized_x (xpaned);
2358 gtk_xpaned_save_unmaximized_y (xpaned);
2360 /* set new maximized position */
2361 gtk_xpaned_set_position_x (xpaned, xpaned->min_position.x);
2362 gtk_xpaned_set_position_y (xpaned, xpaned->min_position.y);
2364 /* mark maximized flag for bottom-right child */
2365 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = TRUE;
2369 /* already one child maximized, report error */
2375 /* verify that bottom-right child is really currently maximized */
2376 if (xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT])
2378 /* clear maximized flat for bottom-right child */
2379 xpaned->maximized[GTK_XPANED_BOTTOM_RIGHT] = FALSE;
2381 /* restore unmaximized position */
2382 gtk_xpaned_set_position_x (xpaned, gtk_xpaned_fetch_unmaximized_x (xpaned));
2383 gtk_xpaned_set_position_y (xpaned, gtk_xpaned_fetch_unmaximized_y (xpaned));
2387 /* bottom-right child is currently not maximized, report error */
2394 gtk_xpaned_compute_position (GtkXPaned* xpaned,
2395 const GtkAllocation* allocation,
2396 GtkRequisition* top_left_child_req,
2397 GtkRequisition* top_right_child_req,
2398 GtkRequisition* bottom_left_child_req,
2399 GtkRequisition* bottom_right_child_req)
2401 GdkPoint old_position;
2402 GdkPoint old_min_position;
2403 GdkPoint old_max_position;
2405 gint border_width = GTK_CONTAINER (xpaned)->border_width;
2409 g_return_if_fail (GTK_IS_XPANED (xpaned));
2411 old_position.x = xpaned->top_left_child_size.width;
2412 old_position.y = xpaned->top_left_child_size.height;
2413 old_min_position.x = xpaned->min_position.x;
2414 old_min_position.y = xpaned->min_position.y;
2415 old_max_position.x = xpaned->max_position.x;
2416 old_max_position.y = xpaned->max_position.y;
2418 fX = 100.0f * (float) old_position.x / (float) allocation->width;
2419 fY = 100.0f * (float) old_position.y / (float) allocation->height;
2421 xpaned->min_position.x = xpaned->top_left_child_shrink ? 0 : top_left_child_req->width;
2422 xpaned->min_position.y = xpaned->top_left_child_shrink ? 0 : top_left_child_req->height;
2424 gtk_widget_style_get (GTK_WIDGET (xpaned), "handle-size", &handle_size, NULL);
2426 xpaned->max_position.x = allocation->width - 2 * border_width - handle_size;
2427 xpaned->max_position.y = allocation->height - 2 * border_width - handle_size;
2428 if (!xpaned->top_left_child_shrink)
2429 xpaned->max_position.x = MAX (1, xpaned->max_position.x - top_left_child_req->width);
2430 xpaned->max_position.x = MAX (xpaned->min_position.x, xpaned->max_position.x);
2432 if (!xpaned->position_set)
2434 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2436 xpaned->top_left_child_size.width = MAX (0, allocation->width - top_right_child_req->width);
2437 xpaned->top_left_child_size.height = MAX (0, allocation->height - top_right_child_req->height);
2439 else if (!xpaned->top_left_child_resize && xpaned->top_right_child_resize)
2441 xpaned->top_left_child_size.width = top_left_child_req->width;
2442 xpaned->top_left_child_size.height = top_left_child_req->height;
2444 else if (top_left_child_req->width + top_right_child_req->width != 0)
2446 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;
2448 else if (top_left_child_req->height + top_right_child_req->height != 0)
2450 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;
2454 xpaned->top_left_child_size.width = allocation->width * 0.5 + 0.5;
2455 xpaned->top_left_child_size.height = allocation->height * 0.5 + 0.5;
2460 /* If the position was set before the initial allocation.
2461 ** (paned->last_allocation <= 0) just clamp it and leave it. */
2462 if (xpaned->last_allocation.width > 0)
2464 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2466 xpaned->top_left_child_size.width += allocation->width
2467 - xpaned->last_allocation.width;
2469 xpaned->top_left_child_size.height += allocation->height
2470 - xpaned->last_allocation.height;
2472 else if (!(!xpaned->top_left_child_resize && xpaned->top_right_child_resize))
2474 xpaned->top_left_child_size.width = allocation->width
2475 * ((gdouble) xpaned->top_left_child_size.width / (xpaned->last_allocation.width))
2478 xpaned->top_left_child_size.height = allocation->height
2479 * ((gdouble) xpaned->top_left_child_size.height / (xpaned->last_allocation.height))
2483 if (xpaned->last_allocation.height > 0)
2485 if (xpaned->top_left_child_resize && !xpaned->top_right_child_resize)
2487 xpaned->top_left_child_size.width += allocation->width - xpaned->last_allocation.width;
2488 xpaned->top_left_child_size.height += allocation->height - xpaned->last_allocation.height;
2490 else if (!(!xpaned->top_left_child_resize && xpaned->top_right_child_resize))
2492 xpaned->top_left_child_size.width = allocation->width * ((gdouble) xpaned->top_left_child_size.width / (xpaned->last_allocation.width)) + 0.5;
2493 xpaned->top_left_child_size.height = allocation->height * ((gdouble) xpaned->top_left_child_size.height / (xpaned->last_allocation.height)) + 0.5;
2499 xpaned->top_left_child_size.width = CLAMP (xpaned->top_left_child_size.width,
2500 xpaned->min_position.x,
2501 xpaned->max_position.x);
2502 xpaned->top_left_child_size.height = CLAMP (xpaned->top_left_child_size.height,
2503 xpaned->min_position.y,
2504 xpaned->max_position.y);
2506 xpaned->top_right_child_size.width = CLAMP (xpaned->top_right_child_size.width,
2507 xpaned->min_position.x,
2508 xpaned->max_position.x);
2509 xpaned->top_right_child_size.height = CLAMP (xpaned->top_right_child_size.height,
2510 xpaned->min_position.y,
2511 xpaned->max_position.y);
2513 xpaned->bottom_left_child_size.width = CLAMP (xpaned->bottom_left_child_size.width,
2514 xpaned->min_position.x,
2515 xpaned->max_position.x);
2516 xpaned->bottom_left_child_size.height = CLAMP (xpaned->bottom_left_child_size.height,
2517 xpaned->min_position.y,
2518 xpaned->max_position.y);
2520 xpaned->bottom_right_child_size.width = CLAMP (xpaned->bottom_right_child_size.width,
2521 xpaned->min_position.x,
2522 xpaned->max_position.x);
2523 xpaned->bottom_right_child_size.height = CLAMP (xpaned->bottom_right_child_size.height,
2524 xpaned->min_position.y,
2525 xpaned->max_position.y);
2527 gtk_widget_set_child_visible (xpaned->top_left_child, TRUE);
2528 gtk_widget_set_child_visible (xpaned->top_right_child, TRUE);
2529 gtk_widget_set_child_visible (xpaned->bottom_left_child, TRUE);
2530 gtk_widget_set_child_visible (xpaned->bottom_right_child, TRUE);
2532 g_object_freeze_notify (G_OBJECT (xpaned));
2534 if (xpaned->top_left_child_size.width != old_position.x)
2535 g_object_notify (G_OBJECT (xpaned), "x-position");
2536 if (xpaned->top_left_child_size.height != old_position.y)
2537 g_object_notify (G_OBJECT (xpaned), "y-position");
2539 if (xpaned->top_right_child_size.width != old_position.x)
2540 g_object_notify (G_OBJECT (xpaned), "x-position");
2541 if (xpaned->top_right_child_size.height != old_position.y)
2542 g_object_notify (G_OBJECT (xpaned), "y-position");
2544 if (xpaned->bottom_left_child_size.width != old_position.x)
2545 g_object_notify (G_OBJECT (xpaned), "x-position");
2546 if (xpaned->bottom_left_child_size.height != old_position.y)
2547 g_object_notify (G_OBJECT (xpaned), "y-position");
2549 if (xpaned->bottom_right_child_size.width != old_position.x)
2550 g_object_notify (G_OBJECT (xpaned), "x-position");
2551 if (xpaned->bottom_right_child_size.height != old_position.y)
2552 g_object_notify (G_OBJECT (xpaned), "y-position");
2554 if (xpaned->min_position.x != old_min_position.x)
2555 g_object_notify (G_OBJECT (xpaned), "min-x-position");
2556 if (xpaned->min_position.y != old_min_position.y)
2557 g_object_notify (G_OBJECT (xpaned), "min-y-position");
2559 if (xpaned->max_position.x != old_max_position.x)
2560 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2561 if (xpaned->max_position.y != old_max_position.y)
2562 g_object_notify (G_OBJECT (xpaned), "max-y-position");
2564 g_object_thaw_notify (G_OBJECT (xpaned));
2566 xpaned->last_allocation.width = allocation->width;
2567 xpaned->last_allocation.height = allocation->height;
2569 fX = 100.0f * (float) old_position.x / (float) allocation->width;
2570 fY = 100.0f * (float) old_position.y / (float) allocation->height;
2573 static void gtk_xpaned_set_saved_focus (GtkXPaned* xpaned, GtkWidget* widget)
2575 if (xpaned->priv->saved_focus)
2576 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2577 (gpointer *)&(xpaned->priv->saved_focus));
2579 xpaned->priv->saved_focus = widget;
2581 if (xpaned->priv->saved_focus)
2582 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->saved_focus),
2583 (gpointer *)&(xpaned->priv->saved_focus));
2586 static void gtk_xpaned_set_first_xpaned (GtkXPaned* xpaned,
2587 GtkXPaned* first_xpaned)
2589 if (xpaned->priv->first_xpaned)
2590 g_object_remove_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2591 (gpointer *)&(xpaned->priv->first_xpaned));
2593 xpaned->priv->first_xpaned = first_xpaned;
2595 if (xpaned->priv->first_xpaned)
2596 g_object_add_weak_pointer (G_OBJECT (xpaned->priv->first_xpaned),
2597 (gpointer *)&(xpaned->priv->first_xpaned));
2600 static void gtk_xpaned_set_last_top_left_child_focus (GtkXPaned* xpaned,
2603 if (xpaned->last_top_left_child_focus)
2604 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2605 (gpointer *)&(xpaned->last_top_left_child_focus));
2607 xpaned->last_top_left_child_focus = widget;
2609 if (xpaned->last_top_left_child_focus)
2610 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_left_child_focus),
2611 (gpointer *)&(xpaned->last_top_left_child_focus));
2614 static void gtk_xpaned_set_last_top_right_child_focus (GtkXPaned* xpaned,
2617 if (xpaned->last_top_right_child_focus)
2618 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2619 (gpointer *)&(xpaned->last_top_right_child_focus));
2621 xpaned->last_top_right_child_focus = widget;
2623 if (xpaned->last_top_right_child_focus)
2624 g_object_add_weak_pointer (G_OBJECT (xpaned->last_top_right_child_focus),
2625 (gpointer *)&(xpaned->last_top_right_child_focus));
2628 static void gtk_xpaned_set_last_bottom_left_child_focus (GtkXPaned* xpaned,
2631 if (xpaned->last_bottom_left_child_focus)
2632 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_bottom_left_child_focus),
2633 (gpointer *)&(xpaned->last_bottom_left_child_focus));
2635 xpaned->last_bottom_left_child_focus = widget;
2637 if (xpaned->last_bottom_left_child_focus)
2638 g_object_add_weak_pointer (G_OBJECT (xpaned->last_bottom_left_child_focus),
2639 (gpointer *)&(xpaned->last_bottom_left_child_focus));
2642 static void gtk_xpaned_set_last_bottom_right_child_focus (GtkXPaned* xpaned,
2645 if (xpaned->last_bottom_right_child_focus)
2646 g_object_remove_weak_pointer (G_OBJECT (xpaned->last_bottom_right_child_focus),
2647 (gpointer *)&(xpaned->last_bottom_right_child_focus));
2649 xpaned->last_bottom_right_child_focus = widget;
2651 if (xpaned->last_bottom_right_child_focus)
2652 g_object_add_weak_pointer (G_OBJECT (xpaned->last_bottom_right_child_focus),
2653 (gpointer *)&(xpaned->last_bottom_right_child_focus));
2656 static GtkWidget* xpaned_get_focus_widget (GtkXPaned* xpaned)
2658 GtkWidget* toplevel;
2660 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
2661 if (GTK_WIDGET_TOPLEVEL (toplevel))
2662 return GTK_WINDOW (toplevel)->focus_widget;
2667 static void gtk_xpaned_set_focus_child (GtkContainer* container,
2668 GtkWidget* focus_child)
2672 g_return_if_fail (GTK_IS_XPANED (container));
2674 xpaned = GTK_XPANED (container);
2676 if (focus_child == NULL)
2678 GtkWidget* last_focus;
2681 last_focus = xpaned_get_focus_widget (xpaned);
2685 /* If there is one or more paned widgets between us and the
2686 * focus widget, we want the topmost of those as last_focus
2688 for (w = last_focus; w != GTK_WIDGET (xpaned); w = w->parent)
2689 if (GTK_IS_XPANED (w))
2692 if (container->focus_child == xpaned->top_left_child)
2693 gtk_xpaned_set_last_top_left_child_focus (xpaned, last_focus);
2694 else if (container->focus_child == xpaned->top_right_child)
2695 gtk_xpaned_set_last_top_right_child_focus (xpaned, last_focus);
2696 else if (container->focus_child == xpaned->bottom_left_child)
2697 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, last_focus);
2698 else if (container->focus_child == xpaned->bottom_right_child)
2699 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, last_focus);
2703 if (parent_class->set_focus_child)
2704 (* parent_class->set_focus_child) (container, focus_child);
2707 static void gtk_xpaned_get_cycle_chain (GtkXPaned* xpaned,
2708 GtkDirectionType direction,
2711 GtkContainer* container = GTK_CONTAINER (xpaned);
2712 GtkWidget* ancestor = NULL;
2713 GList* temp_list = NULL;
2716 if (xpaned->in_recursion)
2719 g_assert (widgets != NULL);
2721 if (xpaned->last_top_left_child_focus &&
2722 !gtk_widget_is_ancestor (xpaned->last_top_left_child_focus,
2723 GTK_WIDGET (xpaned)))
2725 gtk_xpaned_set_last_top_left_child_focus (xpaned, NULL);
2728 if (xpaned->last_top_right_child_focus &&
2729 !gtk_widget_is_ancestor (xpaned->last_top_right_child_focus,
2730 GTK_WIDGET (xpaned)))
2732 gtk_xpaned_set_last_top_right_child_focus (xpaned, NULL);
2735 if (xpaned->last_bottom_left_child_focus &&
2736 !gtk_widget_is_ancestor (xpaned->last_bottom_left_child_focus,
2737 GTK_WIDGET (xpaned)))
2739 gtk_xpaned_set_last_bottom_left_child_focus (xpaned, NULL);
2742 if (xpaned->last_bottom_right_child_focus &&
2743 !gtk_widget_is_ancestor (xpaned->last_bottom_right_child_focus,
2744 GTK_WIDGET (xpaned)))
2746 gtk_xpaned_set_last_bottom_right_child_focus (xpaned, NULL);
2749 if (GTK_WIDGET (xpaned)->parent)
2750 ancestor = gtk_widget_get_ancestor (GTK_WIDGET (xpaned)->parent,
2753 /* The idea here is that temp_list is a list of widgets we want to cycle
2754 * to. The list is prioritized so that the first element is our first
2755 * choice, the next our second, and so on.
2757 * We can't just use g_list_reverse(), because we want to try
2758 * paned->last_child?_focus before paned->child?, both when we
2759 * are going forward and backward.
2761 if (direction == GTK_DIR_TAB_FORWARD)
2763 if (container->focus_child == xpaned->top_left_child)
2765 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2766 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2767 temp_list = g_list_append (temp_list, ancestor);
2769 else if (container->focus_child == xpaned->top_right_child)
2771 temp_list = g_list_append (temp_list, ancestor);
2772 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2773 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2775 else if (container->focus_child == xpaned->bottom_left_child)
2777 temp_list = g_list_append (temp_list, ancestor);
2778 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2779 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2781 else if (container->focus_child == xpaned->bottom_right_child)
2783 temp_list = g_list_append (temp_list, ancestor);
2784 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2785 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2789 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2790 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2791 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2792 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2793 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2794 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2795 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2796 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2797 temp_list = g_list_append (temp_list, ancestor);
2802 if (container->focus_child == xpaned->top_left_child)
2804 temp_list = g_list_append (temp_list, ancestor);
2805 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2806 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2808 else if (container->focus_child == xpaned->top_right_child)
2810 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2811 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2812 temp_list = g_list_append (temp_list, ancestor);
2814 else if (container->focus_child == xpaned->bottom_right_child)
2816 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2817 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2818 temp_list = g_list_append (temp_list, ancestor);
2820 else if (container->focus_child == xpaned->top_right_child)
2822 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2823 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2824 temp_list = g_list_append (temp_list, ancestor);
2828 temp_list = g_list_append (temp_list, xpaned->last_bottom_right_child_focus);
2829 temp_list = g_list_append (temp_list, xpaned->bottom_right_child);
2830 temp_list = g_list_append (temp_list, xpaned->last_bottom_left_child_focus);
2831 temp_list = g_list_append (temp_list, xpaned->bottom_left_child);
2832 temp_list = g_list_append (temp_list, xpaned->last_top_right_child_focus);
2833 temp_list = g_list_append (temp_list, xpaned->top_right_child);
2834 temp_list = g_list_append (temp_list, xpaned->last_top_left_child_focus);
2835 temp_list = g_list_append (temp_list, xpaned->top_left_child);
2836 temp_list = g_list_append (temp_list, ancestor);
2840 /* Walk the list and expand all the paned widgets. */
2841 for (list = temp_list; list != NULL; list = list->next)
2843 GtkWidget *widget = list->data;
2847 if (GTK_IS_XPANED (widget))
2849 xpaned->in_recursion = TRUE;
2850 gtk_xpaned_get_cycle_chain (GTK_XPANED (widget),
2853 xpaned->in_recursion = FALSE;
2857 *widgets = g_list_append (*widgets, widget);
2862 g_list_free (temp_list);
2865 static gboolean gtk_xpaned_cycle_child_focus (GtkXPaned* xpaned,
2868 GList* cycle_chain = NULL;
2871 GtkDirectionType direction = reversed ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
2873 /* ignore f6 if the handle is focused */
2874 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
2877 /* we can't just let the event propagate up the hierarchy,
2878 * because the paned will want to cycle focus _unless_ an
2879 * ancestor paned handles the event
2881 gtk_xpaned_get_cycle_chain (xpaned, direction, &cycle_chain);
2883 for (list = cycle_chain; list != NULL; list = list->next)
2884 if (gtk_widget_child_focus (GTK_WIDGET (list->data), direction))
2887 g_list_free (cycle_chain);
2892 static void get_child_xpanes (GtkWidget* widget, GList** xpanes)
2894 if (GTK_IS_XPANED (widget))
2896 GtkXPaned* xpaned = GTK_XPANED (widget);
2898 get_child_xpanes (xpaned->top_left_child, xpanes);
2899 *xpanes = g_list_prepend (*xpanes, widget);
2900 get_child_xpanes (xpaned->top_right_child, xpanes);
2901 *xpanes = g_list_prepend (*xpanes, widget);
2902 get_child_xpanes (xpaned->bottom_left_child, xpanes);
2903 *xpanes = g_list_prepend (*xpanes, widget);
2904 get_child_xpanes (xpaned->bottom_right_child, xpanes);
2906 else if (GTK_IS_CONTAINER (widget))
2908 gtk_container_foreach (GTK_CONTAINER (widget),
2909 (GtkCallback)get_child_xpanes,
2914 static GList* get_all_xpanes (GtkXPaned* xpaned)
2916 GtkXPaned* topmost = NULL;
2917 GList* result = NULL;
2920 for (w = GTK_WIDGET (xpaned); w != NULL; w = w->parent)
2922 if (GTK_IS_XPANED (w))
2923 topmost = GTK_XPANED (w);
2928 get_child_xpanes (GTK_WIDGET (topmost), &result);
2930 return g_list_reverse (result);
2933 static void gtk_xpaned_find_neighbours (GtkXPaned* xpaned,
2940 all_xpanes = get_all_xpanes (xpaned);
2941 g_assert (all_xpanes);
2943 this_link = g_list_find (all_xpanes, xpaned);
2945 g_assert (this_link);
2947 if (this_link->next)
2948 *next = this_link->next->data;
2950 *next = all_xpanes->data;
2952 if (this_link->prev)
2953 *prev = this_link->prev->data;
2955 *prev = g_list_last (all_xpanes)->data;
2957 g_list_free (all_xpanes);
2960 static gboolean gtk_xpaned_move_handle (GtkXPaned* xpaned, GtkScrollType scroll)
2962 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
2964 GdkPoint old_position;
2965 GdkPoint new_position;
2970 SINGLE_STEP_SIZE = 1,
2974 new_position.x = old_position.x = gtk_xpaned_get_position_x (xpaned);
2975 new_position.y = old_position.y = gtk_xpaned_get_position_y (xpaned);
2980 case GTK_SCROLL_STEP_LEFT:
2981 case GTK_SCROLL_STEP_UP:
2982 case GTK_SCROLL_STEP_BACKWARD:
2983 increment = - SINGLE_STEP_SIZE;
2986 case GTK_SCROLL_STEP_RIGHT:
2987 case GTK_SCROLL_STEP_DOWN:
2988 case GTK_SCROLL_STEP_FORWARD:
2989 increment = SINGLE_STEP_SIZE;
2992 case GTK_SCROLL_PAGE_LEFT:
2993 case GTK_SCROLL_PAGE_UP:
2994 case GTK_SCROLL_PAGE_BACKWARD:
2995 increment = - PAGE_STEP_SIZE;
2998 case GTK_SCROLL_PAGE_RIGHT:
2999 case GTK_SCROLL_PAGE_DOWN:
3000 case GTK_SCROLL_PAGE_FORWARD:
3001 increment = PAGE_STEP_SIZE;
3004 case GTK_SCROLL_START:
3005 new_position.x = xpaned->min_position.x;
3006 new_position.y = xpaned->min_position.y;
3009 case GTK_SCROLL_END:
3010 new_position.x = xpaned->max_position.x;
3011 new_position.y = xpaned->max_position.y;
3020 if (is_rtl (xpaned))
3021 increment = -increment;
3023 new_position.x = old_position.x + increment;
3024 new_position.y = old_position.y + increment;
3027 new_position.x = CLAMP (new_position.x,
3028 xpaned->min_position.x,
3029 xpaned->max_position.x);
3031 new_position.y = CLAMP (new_position.y,
3032 xpaned->min_position.y,
3033 xpaned->max_position.y);
3035 if (old_position.x != new_position.x)
3036 gtk_xpaned_set_position_x (xpaned, new_position.x);
3038 if (old_position.y != new_position.y)
3039 gtk_xpaned_set_position_y (xpaned, new_position.y);
3047 static void gtk_xpaned_restore_focus (GtkXPaned* xpaned)
3049 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3051 if (xpaned->priv->saved_focus &&
3052 GTK_WIDGET_SENSITIVE (xpaned->priv->saved_focus))
3054 gtk_widget_grab_focus (xpaned->priv->saved_focus);
3058 /* the saved focus is somehow not available for focusing,
3060 * 1) tabbing into the paned widget
3061 * if that didn't work,
3062 * 2) unset focus for the window if there is one
3065 if (!gtk_widget_child_focus (GTK_WIDGET (xpaned), GTK_DIR_TAB_FORWARD))
3067 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3069 if (GTK_IS_WINDOW (toplevel))
3070 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
3074 gtk_xpaned_set_saved_focus (xpaned, NULL);
3075 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3079 static gboolean gtk_xpaned_accept_position (GtkXPaned* xpaned)
3081 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3083 xpaned->original_position.x = -1;
3084 xpaned->original_position.y = -1;
3085 gtk_xpaned_restore_focus (xpaned);
3093 static gboolean gtk_xpaned_cancel_position (GtkXPaned* xpaned)
3095 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3097 if (xpaned->original_position.x != -1)
3099 gtk_xpaned_set_position_x (xpaned, xpaned->original_position.x);
3100 xpaned->original_position.x = -1;
3103 if (xpaned->original_position.y != -1)
3105 gtk_xpaned_set_position_y (xpaned, xpaned->original_position.y);
3106 xpaned->original_position.y = -1;
3109 gtk_xpaned_restore_focus (xpaned);
3116 static gboolean gtk_xpaned_cycle_handle_focus (GtkXPaned* xpaned,
3122 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3124 GtkXPaned* focus = NULL;
3126 if (!xpaned->priv->first_xpaned)
3128 /* The first_pane has disappeared. As an ad-hoc solution,
3129 * we make the currently focused paned the first_paned. To the
3130 * user this will seem like the paned cycling has been reset.
3132 gtk_xpaned_set_first_xpaned (xpaned, xpaned);
3135 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3137 if (reversed && prev &&
3138 prev != xpaned && xpaned != xpaned->priv->first_xpaned)
3142 else if (!reversed &&
3145 next != xpaned->priv->first_xpaned)
3151 gtk_xpaned_accept_position (xpaned);
3157 gtk_xpaned_set_saved_focus (focus, xpaned->priv->saved_focus);
3158 gtk_xpaned_set_first_xpaned (focus, xpaned->priv->first_xpaned);
3160 gtk_xpaned_set_saved_focus (xpaned, NULL);
3161 gtk_xpaned_set_first_xpaned (xpaned, NULL);
3163 gtk_widget_grab_focus (GTK_WIDGET (focus));
3165 if (!gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3167 xpaned->original_position.x = -1;
3168 xpaned->original_position.y = -1;
3169 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3170 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3175 GtkContainer* container = GTK_CONTAINER (xpaned);
3180 GtkWidget* toplevel;
3182 gtk_xpaned_find_neighbours (xpaned, &next, &prev);
3184 if (container->focus_child == xpaned->top_left_child)
3197 else if (container->focus_child == xpaned->top_right_child)
3212 /* Focus is not inside this xpaned, and we don't have focus.
3213 * Presumably this happened because the application wants us
3214 * to start keyboard navigating.
3224 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (xpaned));
3226 if (GTK_IS_WINDOW (toplevel))
3227 gtk_xpaned_set_saved_focus (focus, GTK_WINDOW (toplevel)->focus_widget);
3228 gtk_xpaned_set_first_xpaned (focus, first);
3229 focus->original_position.x = gtk_xpaned_get_position_x (focus);
3230 focus->original_position.y = gtk_xpaned_get_position_y (focus);
3232 gtk_widget_grab_focus (GTK_WIDGET (focus));
3238 static gboolean gtk_xpaned_toggle_handle_focus (GtkXPaned* xpaned)
3240 /* This function/signal has the wrong name. It is called when you
3241 * press Tab or Shift-Tab and what we do is act as if
3242 * the user pressed Return and then Tab or Shift-Tab
3244 if (gtk_widget_is_focus (GTK_WIDGET (xpaned)))
3245 gtk_xpaned_accept_position (xpaned);
3250 /*#define __GTK_XPANED_C__*/
3251 /*#include "gtkaliasdef.c"*/