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 "gtkhpaned.h"
29 static void gtk_hpaned_class_init (GtkHPanedClass *klass);
30 static void gtk_hpaned_init (GtkHPaned *hpaned);
31 static void gtk_hpaned_size_request (GtkWidget *widget,
32 GtkRequisition *requisition);
33 static void gtk_hpaned_size_allocate (GtkWidget *widget,
34 GtkAllocation *allocation);
36 static gpointer parent_class;
39 gtk_hpaned_get_type (void)
41 static GtkType hpaned_type = 0;
45 static const GtkTypeInfo hpaned_info =
49 sizeof (GtkHPanedClass),
50 (GtkClassInitFunc) gtk_hpaned_class_init,
51 (GtkObjectInitFunc) gtk_hpaned_init,
52 /* reserved_1 */ NULL,
53 /* reserved_2 */ NULL,
54 (GtkClassInitFunc) NULL,
57 hpaned_type = gtk_type_unique (GTK_TYPE_PANED, &hpaned_info);
64 gtk_hpaned_class_init (GtkHPanedClass *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_hpaned_size_request;
73 widget_class->size_allocate = gtk_hpaned_size_allocate;
77 gtk_hpaned_init (GtkHPaned *hpaned)
81 g_return_if_fail (GTK_IS_PANED (hpaned));
83 paned = GTK_PANED (hpaned);
85 paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
86 paned->orientation = GTK_ORIENTATION_VERTICAL;
94 hpaned = gtk_type_new (GTK_TYPE_HPANED);
96 return GTK_WIDGET (hpaned);
100 gtk_hpaned_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->height = MAX(requisition->height, child_requisition.height);
122 requisition->width += child_requisition.width;
125 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
126 requisition->height += 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->width += handle_size;
139 gtk_hpaned_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 GtkAllocation child1_allocation;
151 GtkAllocation child2_allocation;
152 GtkRequisition child1_requisition;
153 GtkRequisition child2_requisition;
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.width
165 child1_requisition.width,
166 child2_requisition.width);
168 paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
169 paned->handle_pos.y = widget->allocation.y + border_width;
170 paned->handle_pos.width = handle_size;
171 paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
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,
181 paned->handle_pos.height);
184 child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
185 child1_allocation.width = paned->child1_size;
186 child1_allocation.x = widget->allocation.x + border_width;
187 child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
189 child2_allocation.x = child1_allocation.x + child1_allocation.width + paned->handle_pos.width;
190 child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - 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.width < child1_allocation.width)
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);