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/.
33 static void gtk_hbox_size_request (GtkWidget *widget,
34 GtkRequisition *requisition);
35 static void gtk_hbox_size_allocate (GtkWidget *widget,
36 GtkAllocation *allocation);
39 G_DEFINE_TYPE (GtkHBox, gtk_hbox, GTK_TYPE_BOX)
42 gtk_hbox_class_init (GtkHBoxClass *class)
44 GtkWidgetClass *widget_class;
46 widget_class = (GtkWidgetClass*) class;
48 widget_class->size_request = gtk_hbox_size_request;
49 widget_class->size_allocate = gtk_hbox_size_allocate;
53 gtk_hbox_init (GtkHBox *hbox)
58 gtk_hbox_new (gboolean homogeneous,
63 hbox = g_object_new (GTK_TYPE_HBOX, NULL);
65 GTK_BOX (hbox)->spacing = spacing;
66 GTK_BOX (hbox)->homogeneous = homogeneous ? TRUE : FALSE;
68 return GTK_WIDGET (hbox);
73 gtk_hbox_size_request (GtkWidget *widget,
74 GtkRequisition *requisition)
82 box = GTK_BOX (widget);
83 requisition->width = 0;
84 requisition->height = 0;
87 children = box->children;
90 child = children->data;
91 children = children->next;
93 if (GTK_WIDGET_VISIBLE (child->widget))
95 GtkRequisition child_requisition;
97 gtk_widget_size_request (child->widget, &child_requisition);
101 width = child_requisition.width + child->padding * 2;
102 requisition->width = MAX (requisition->width, width);
106 requisition->width += child_requisition.width + child->padding * 2;
109 requisition->height = MAX (requisition->height, child_requisition.height);
115 if (nvis_children > 0)
117 if (box->homogeneous)
118 requisition->width *= nvis_children;
119 requisition->width += (nvis_children - 1) * box->spacing;
122 requisition->width += GTK_CONTAINER (box)->border_width * 2;
123 requisition->height += GTK_CONTAINER (box)->border_width * 2;
127 gtk_hbox_size_allocate (GtkWidget *widget,
128 GtkAllocation *allocation)
133 GtkAllocation child_allocation;
135 gint nexpand_children;
140 GtkTextDirection direction;
142 box = GTK_BOX (widget);
143 widget->allocation = *allocation;
145 direction = gtk_widget_get_direction (widget);
148 nexpand_children = 0;
149 children = box->children;
153 child = children->data;
154 children = children->next;
156 if (GTK_WIDGET_VISIBLE (child->widget))
160 nexpand_children += 1;
164 if (nvis_children > 0)
166 if (box->homogeneous)
168 width = (allocation->width -
169 GTK_CONTAINER (box)->border_width * 2 -
170 (nvis_children - 1) * box->spacing);
171 extra = width / nvis_children;
173 else if (nexpand_children > 0)
175 width = (gint) allocation->width - (gint) widget->requisition.width;
176 extra = width / nexpand_children;
184 x = allocation->x + GTK_CONTAINER (box)->border_width;
185 child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width;
186 child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2);
188 children = box->children;
191 child = children->data;
192 children = children->next;
194 if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
196 if (box->homogeneous)
198 if (nvis_children == 1)
208 GtkRequisition child_requisition;
210 gtk_widget_get_child_requisition (child->widget, &child_requisition);
212 child_width = child_requisition.width + child->padding * 2;
216 if (nexpand_children == 1)
217 child_width += width;
219 child_width += extra;
221 nexpand_children -= 1;
228 child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2);
229 child_allocation.x = x + child->padding;
233 GtkRequisition child_requisition;
235 gtk_widget_get_child_requisition (child->widget, &child_requisition);
236 child_allocation.width = child_requisition.width;
237 child_allocation.x = x + (child_width - child_allocation.width) / 2;
240 if (direction == GTK_TEXT_DIR_RTL)
241 child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
243 gtk_widget_size_allocate (child->widget, &child_allocation);
245 x += child_width + box->spacing;
249 x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width;
251 children = box->children;
254 child = children->data;
255 children = children->next;
257 if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
259 GtkRequisition child_requisition;
260 gtk_widget_get_child_requisition (child->widget, &child_requisition);
262 if (box->homogeneous)
264 if (nvis_children == 1)
274 child_width = child_requisition.width + child->padding * 2;
278 if (nexpand_children == 1)
279 child_width += width;
281 child_width += extra;
283 nexpand_children -= 1;
290 child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2);
291 child_allocation.x = x + child->padding - child_width;
295 child_allocation.width = child_requisition.width;
296 child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
299 if (direction == GTK_TEXT_DIR_RTL)
300 child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
302 gtk_widget_size_allocate (child->widget, &child_allocation);
304 x -= (child_width + box->spacing);
310 #define __GTK_HBOX_C__
311 #include "gtkaliasdef.c"