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 <lttv/gtkcustomhbox.h>
30 static void gtk_custom_hbox_class_init (GtkCustomHBoxClass
*klass
);
31 static void gtk_custom_hbox_init (GtkCustomHBox
*box
);
32 static void gtk_custom_hbox_size_request (GtkWidget
*widget
,
33 GtkRequisition
*requisition
);
34 static void gtk_custom_hbox_size_allocate (GtkWidget
*widget
,
35 GtkAllocation
*allocation
);
39 gtk_custom_hbox_get_type (void)
41 static GType hbox_type
= 0;
45 static const GTypeInfo hbox_info
=
47 sizeof (GtkCustomHBoxClass
),
49 NULL
, /* base_finalize */
50 (GClassInitFunc
) gtk_custom_hbox_class_init
,
51 NULL
, /* class_finalize */
52 NULL
, /* class_data */
53 sizeof (GtkCustomHBox
),
55 (GInstanceInitFunc
) gtk_custom_hbox_init
,
58 hbox_type
= g_type_register_static (GTK_TYPE_BOX
, "GtkCustomHBox",
66 gtk_custom_hbox_finalize (GObject
*object
)
68 GtkCustomHBox
* hbox
= GTK_CUSTOM_HBOX (object
);
70 hbox
->remove_item(hbox
);
72 G_OBJECT_CLASS(g_type_class_peek_parent(GTK_CUSTOM_HBOX_GET_CLASS(hbox
)))->finalize(G_OBJECT(object
));
76 gtk_custom_hbox_class_init (GtkCustomHBoxClass
*class)
78 GtkWidgetClass
*widget_class
;
79 GObjectClass
*gobject_class
= G_OBJECT_CLASS(class);
81 gobject_class
->finalize
= gtk_custom_hbox_finalize
;
83 widget_class
= (GtkWidgetClass
*) class;
85 widget_class
->size_request
= gtk_custom_hbox_size_request
;
86 widget_class
->size_allocate
= gtk_custom_hbox_size_allocate
;
90 gtk_custom_hbox_init (GtkCustomHBox
*hbox
)
95 gtk_custom_hbox_new (gboolean homogeneous
,
101 hbox
= g_object_new (GTK_TYPE_CUSTOM_HBOX
, NULL
);
102 hbox
->remove_item
= remove
;
104 GTK_BOX (hbox
)->spacing
= spacing
;
105 GTK_BOX (hbox
)->homogeneous
= homogeneous
? TRUE
: FALSE
;
107 return GTK_WIDGET (hbox
);
111 gtk_custom_hbox_size_request (GtkWidget
*widget
,
112 GtkRequisition
*requisition
)
120 box
= GTK_BOX (widget
);
121 requisition
->width
= 0;
122 requisition
->height
= 0;
125 children
= box
->children
;
128 child
= children
->data
;
129 children
= children
->next
;
131 if (GTK_WIDGET_VISIBLE (child
->widget
))
133 GtkRequisition child_requisition
;
135 gtk_widget_size_request (child
->widget
, &child_requisition
);
137 if (box
->homogeneous
)
139 width
= child_requisition
.width
+ child
->padding
* 2;
140 requisition
->width
= MAX (requisition
->width
, width
);
144 requisition
->width
+= child_requisition
.width
+ child
->padding
* 2;
147 requisition
->height
= MAX (requisition
->height
, child_requisition
.height
);
153 if (nvis_children
> 0)
155 if (box
->homogeneous
)
156 requisition
->width
*= nvis_children
;
157 requisition
->width
+= (nvis_children
- 1) * box
->spacing
;
160 requisition
->width
+= GTK_CONTAINER (box
)->border_width
* 2;
161 requisition
->height
+= GTK_CONTAINER (box
)->border_width
* 2;
165 gtk_custom_hbox_size_allocate (GtkWidget
*widget
,
166 GtkAllocation
*allocation
)
171 GtkAllocation child_allocation
;
173 gint nexpand_children
;
178 GtkTextDirection direction
;
180 box
= GTK_BOX (widget
);
181 widget
->allocation
= *allocation
;
183 direction
= gtk_widget_get_direction (widget
);
186 nexpand_children
= 0;
187 children
= box
->children
;
191 child
= children
->data
;
192 children
= children
->next
;
194 if (GTK_WIDGET_VISIBLE (child
->widget
))
198 nexpand_children
+= 1;
202 if (nvis_children
> 0)
204 if (box
->homogeneous
)
206 width
= (allocation
->width
-
207 GTK_CONTAINER (box
)->border_width
* 2 -
208 (nvis_children
- 1) * box
->spacing
);
209 extra
= width
/ nvis_children
;
211 else if (nexpand_children
> 0)
213 width
= (gint
) allocation
->width
- (gint
) widget
->requisition
.width
;
214 extra
= width
/ nexpand_children
;
222 x
= allocation
->x
+ GTK_CONTAINER (box
)->border_width
;
223 child_allocation
.y
= allocation
->y
+ GTK_CONTAINER (box
)->border_width
;
224 child_allocation
.height
= MAX (1, (gint
) allocation
->height
- (gint
) GTK_CONTAINER (box
)->border_width
* 2);
226 children
= box
->children
;
229 child
= children
->data
;
230 children
= children
->next
;
232 if ((child
->pack
== GTK_PACK_START
) && GTK_WIDGET_VISIBLE (child
->widget
))
234 if (box
->homogeneous
)
236 if (nvis_children
== 1)
246 GtkRequisition child_requisition
;
248 gtk_widget_get_child_requisition (child
->widget
, &child_requisition
);
250 child_width
= child_requisition
.width
+ child
->padding
* 2;
254 if (nexpand_children
== 1)
255 child_width
+= width
;
257 child_width
+= extra
;
259 nexpand_children
-= 1;
266 child_allocation
.width
= MAX (1, (gint
) child_width
- (gint
) child
->padding
* 2);
267 child_allocation
.x
= x
+ child
->padding
;
271 GtkRequisition child_requisition
;
273 gtk_widget_get_child_requisition (child
->widget
, &child_requisition
);
274 child_allocation
.width
= child_requisition
.width
;
275 child_allocation
.x
= x
+ (child_width
- child_allocation
.width
) / 2;
278 if (direction
== GTK_TEXT_DIR_RTL
)
279 child_allocation
.x
= allocation
->x
+ allocation
->width
- (child_allocation
.x
- allocation
->x
) - child_allocation
.width
;
281 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
283 x
+= child_width
+ box
->spacing
;
287 x
= allocation
->x
+ allocation
->width
- GTK_CONTAINER (box
)->border_width
;
289 children
= box
->children
;
292 child
= children
->data
;
293 children
= children
->next
;
295 if ((child
->pack
== GTK_PACK_END
) && GTK_WIDGET_VISIBLE (child
->widget
))
297 GtkRequisition child_requisition
;
298 gtk_widget_get_child_requisition (child
->widget
, &child_requisition
);
300 if (box
->homogeneous
)
302 if (nvis_children
== 1)
312 child_width
= child_requisition
.width
+ child
->padding
* 2;
316 if (nexpand_children
== 1)
317 child_width
+= width
;
319 child_width
+= extra
;
321 nexpand_children
-= 1;
328 child_allocation
.width
= MAX (1, (gint
)child_width
- (gint
)child
->padding
* 2);
329 child_allocation
.x
= x
+ child
->padding
- child_width
;
333 child_allocation
.width
= child_requisition
.width
;
334 child_allocation
.x
= x
+ (child_width
- child_allocation
.width
) / 2 - child_width
;
337 if (direction
== GTK_TEXT_DIR_RTL
)
338 child_allocation
.x
= allocation
->x
+ allocation
->width
- (child_allocation
.x
- allocation
->x
) - child_allocation
.width
;
340 gtk_widget_size_allocate (child
->widget
, &child_allocation
);
342 x
-= (child_width
+ box
->spacing
);