1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gtkvpaned.h"
29 static void gtk_vpaned_class_init (GtkVPanedClass *klass);
30 static void gtk_vpaned_init (GtkVPaned *vpaned);
31 static void gtk_vpaned_size_request (GtkWidget *widget,
32 GtkRequisition *requisition);
33 static void gtk_vpaned_size_allocate (GtkWidget *widget,
34 GtkAllocation *allocation);
36 static gpointer parent_class;
39 gtk_vpaned_get_type (void)
41 static GtkType vpaned_type = 0;
45 static const GtkTypeInfo vpaned_info =
49 sizeof (GtkVPanedClass),
50 (GtkClassInitFunc) gtk_vpaned_class_init,
51 (GtkObjectInitFunc) gtk_vpaned_init,
52 /* reserved_1 */ NULL,
53 /* reserved_2 */ NULL,
54 (GtkClassInitFunc) NULL,
57 vpaned_type = gtk_type_unique (GTK_TYPE_PANED, &vpaned_info);
64 gtk_vpaned_class_init (GtkVPanedClass *class)
66 GtkWidgetClass *widget_class;
68 parent_class = gtk_type_class (GTK_TYPE_PANED);
70 widget_class = (GtkWidgetClass *) class;
72 widget_class->size_request = gtk_vpaned_size_request;
73 widget_class->size_allocate = gtk_vpaned_size_allocate;
77 gtk_vpaned_init (GtkVPaned *vpaned)
81 g_return_if_fail (GTK_IS_PANED (vpaned));
83 paned = GTK_PANED (vpaned);
85 paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
86 paned->orientation = GTK_ORIENTATION_HORIZONTAL;
94 vpaned = gtk_type_new (GTK_TYPE_VPANED);
96 return GTK_WIDGET (vpaned);
100 gtk_vpaned_size_request (GtkWidget *widget,
101 GtkRequisition *requisition)
103 GtkPaned *paned = GTK_PANED (widget);
104 GtkRequisition child_requisition;
106 requisition->width = 0;
107 requisition->height = 0;
109 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
111 gtk_widget_size_request (paned->child1, &child_requisition);
113 requisition->height = child_requisition.height;
114 requisition->width = child_requisition.width;
117 if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
119 gtk_widget_size_request (paned->child2, &child_requisition);
121 requisition->width = MAX (requisition->width, child_requisition.width);
122 requisition->height += child_requisition.height;
125 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
126 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
128 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
129 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
133 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
134 requisition->height += handle_size;
139 gtk_vpaned_size_allocate (GtkWidget *widget,
140 GtkAllocation *allocation)
142 GtkPaned *paned = GTK_PANED (widget);
143 gint border_width = GTK_CONTAINER (paned)->border_width;
145 widget->allocation = *allocation;
147 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
148 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
150 GtkRequisition child1_requisition;
151 GtkRequisition child2_requisition;
152 GtkAllocation child1_allocation;
153 GtkAllocation child2_allocation;
156 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
158 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
159 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
161 gtk_paned_compute_position (paned,
162 MAX (1, widget->allocation.height
165 child1_requisition.height,
166 child2_requisition.height);
168 paned->handle_pos.x = widget->allocation.x + border_width;
169 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
170 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
171 paned->handle_pos.height = handle_size;
173 if (GTK_WIDGET_REALIZED (widget))
175 if (GTK_WIDGET_MAPPED (widget))
176 gdk_window_show (paned->handle);
177 gdk_window_move_resize (paned->handle,
180 paned->handle_pos.width,
184 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
185 child1_allocation.height = paned->child1_size;
186 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
187 child1_allocation.y = widget->allocation.y + border_width;
189 child2_allocation.y = child1_allocation.y + child1_allocation.height + paned->handle_pos.height;
190 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
192 /* Now allocate the childen, making sure, when resizing not to
193 * overlap the windows
195 if (GTK_WIDGET_MAPPED (widget) &&
196 paned->child1->allocation.height < child1_allocation.height)
198 gtk_widget_size_allocate (paned->child2, &child2_allocation);
199 gtk_widget_size_allocate (paned->child1, &child1_allocation);
203 gtk_widget_size_allocate (paned->child1, &child1_allocation);
204 gtk_widget_size_allocate (paned->child2, &child2_allocation);
209 GtkAllocation child_allocation;
211 if (GTK_WIDGET_REALIZED (widget))
212 gdk_window_hide (paned->handle);
214 child_allocation.x = widget->allocation.x + border_width;
215 child_allocation.y = widget->allocation.y + border_width;
216 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
217 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
219 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
220 gtk_widget_size_allocate (paned->child1, &child_allocation);
221 else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
222 gtk_widget_size_allocate (paned->child2, &child_allocation);