]> Pileus Git - ~andy/gtk/blob - gtk/gtkbox.c
use gtk_box_pack_start() instead of the deprecated
[~andy/gtk] / gtk / gtkbox.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28 #include "gtkbox.h"
29 #include "gtkprivate.h"
30 #include "gtkintl.h"
31 #include "gtkalias.h"
32
33 enum {
34   PROP_0,
35   PROP_SPACING,
36   PROP_HOMOGENEOUS
37 };
38
39 enum {
40   CHILD_PROP_0,
41   CHILD_PROP_EXPAND,
42   CHILD_PROP_FILL,
43   CHILD_PROP_PADDING,
44   CHILD_PROP_PACK_TYPE,
45   CHILD_PROP_POSITION
46 };
47
48 static void gtk_box_set_property (GObject         *object,
49                                   guint            prop_id,
50                                   const GValue    *value,
51                                   GParamSpec      *pspec);
52 static void gtk_box_get_property (GObject         *object,
53                                   guint            prop_id,
54                                   GValue          *value,
55                                   GParamSpec      *pspec);
56 static void gtk_box_add        (GtkContainer   *container,
57                                 GtkWidget      *widget);
58 static void gtk_box_remove     (GtkContainer   *container,
59                                 GtkWidget      *widget);
60 static void gtk_box_forall     (GtkContainer   *container,
61                                 gboolean        include_internals,
62                                 GtkCallback     callback,
63                                 gpointer        callback_data);
64 static void gtk_box_set_child_property (GtkContainer    *container,
65                                         GtkWidget       *child,
66                                         guint            property_id,
67                                         const GValue    *value,
68                                         GParamSpec      *pspec);
69 static void gtk_box_get_child_property (GtkContainer    *container,
70                                         GtkWidget       *child,
71                                         guint            property_id,
72                                         GValue          *value,
73                                         GParamSpec      *pspec);
74 static GType gtk_box_child_type (GtkContainer   *container);
75      
76
77 G_DEFINE_ABSTRACT_TYPE (GtkBox, gtk_box, GTK_TYPE_CONTAINER)
78
79 static void
80 gtk_box_class_init (GtkBoxClass *class)
81 {
82   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
83   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
84
85   gobject_class->set_property = gtk_box_set_property;
86   gobject_class->get_property = gtk_box_get_property;
87    
88   container_class->add = gtk_box_add;
89   container_class->remove = gtk_box_remove;
90   container_class->forall = gtk_box_forall;
91   container_class->child_type = gtk_box_child_type;
92   container_class->set_child_property = gtk_box_set_child_property;
93   container_class->get_child_property = gtk_box_get_child_property;
94
95   g_object_class_install_property (gobject_class,
96                                    PROP_SPACING,
97                                    g_param_spec_int ("spacing",
98                                                      P_("Spacing"),
99                                                      P_("The amount of space between children"),
100                                                      0,
101                                                      G_MAXINT,
102                                                      0,
103                                                      GTK_PARAM_READWRITE));
104   
105   g_object_class_install_property (gobject_class,
106                                    PROP_HOMOGENEOUS,
107                                    g_param_spec_boolean ("homogeneous",
108                                                          P_("Homogeneous"),
109                                                          P_("Whether the children should all be the same size"),
110                                                          FALSE,
111                                                          GTK_PARAM_READWRITE));
112
113   gtk_container_class_install_child_property (container_class,
114                                               CHILD_PROP_EXPAND,
115                                               g_param_spec_boolean ("expand", 
116                                                                     P_("Expand"), 
117                                                                     P_("Whether the child should receive extra space when the parent grows"),
118                                                                     TRUE,
119                                                                     GTK_PARAM_READWRITE));
120   gtk_container_class_install_child_property (container_class,
121                                               CHILD_PROP_FILL,
122                                               g_param_spec_boolean ("fill", 
123                                                                     P_("Fill"), 
124                                                                     P_("Whether extra space given to the child should be allocated to the child or used as padding"),
125                                                                     TRUE,
126                                                                     GTK_PARAM_READWRITE));
127   gtk_container_class_install_child_property (container_class,
128                                               CHILD_PROP_PADDING,
129                                               g_param_spec_uint ("padding", 
130                                                                  P_("Padding"), 
131                                                                  P_("Extra space to put between the child and its neighbors, in pixels"),
132                                                                  0, G_MAXINT, 0,
133                                                                  GTK_PARAM_READWRITE));
134   gtk_container_class_install_child_property (container_class,
135                                               CHILD_PROP_PACK_TYPE,
136                                               g_param_spec_enum ("pack-type", 
137                                                                  P_("Pack type"), 
138                                                                  P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
139                                                                  GTK_TYPE_PACK_TYPE, GTK_PACK_START,
140                                                                  GTK_PARAM_READWRITE));
141   gtk_container_class_install_child_property (container_class,
142                                               CHILD_PROP_POSITION,
143                                               g_param_spec_int ("position", 
144                                                                 P_("Position"), 
145                                                                 P_("The index of the child in the parent"),
146                                                                 -1, G_MAXINT, 0,
147                                                                 GTK_PARAM_READWRITE));
148 }
149
150 static void
151 gtk_box_init (GtkBox *box)
152 {
153   GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);
154   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
155   
156   box->children = NULL;
157   box->spacing = 0;
158   box->homogeneous = FALSE;
159 }
160
161 static void 
162 gtk_box_set_property (GObject         *object,
163                       guint            prop_id,
164                       const GValue    *value,
165                       GParamSpec      *pspec)
166 {
167   GtkBox *box;
168
169   box = GTK_BOX (object);
170
171   switch (prop_id)
172     {
173     case PROP_SPACING:
174       gtk_box_set_spacing (box, g_value_get_int (value));
175       break;
176     case PROP_HOMOGENEOUS:
177       gtk_box_set_homogeneous (box, g_value_get_boolean (value));
178       break;
179     default:
180       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
181       break;
182     }
183 }
184
185 static void gtk_box_get_property (GObject         *object,
186                                   guint            prop_id,
187                                   GValue          *value,
188                                   GParamSpec      *pspec)
189 {
190   GtkBox *box;
191
192   box = GTK_BOX (object);
193
194   switch (prop_id)
195     {
196     case PROP_SPACING:
197       g_value_set_int (value, box->spacing);
198       break;
199     case PROP_HOMOGENEOUS:
200       g_value_set_boolean (value, box->homogeneous);
201       break;
202     default:
203       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204       break;
205     }
206 }
207
208 static GType
209 gtk_box_child_type (GtkContainer   *container)
210 {
211   return GTK_TYPE_WIDGET;
212 }
213
214 static void
215 gtk_box_set_child_property (GtkContainer    *container,
216                             GtkWidget       *child,
217                             guint            property_id,
218                             const GValue    *value,
219                             GParamSpec      *pspec)
220 {
221   gboolean expand = 0;
222   gboolean fill = 0;
223   guint padding = 0;
224   GtkPackType pack_type = 0;
225
226   if (property_id != CHILD_PROP_POSITION)
227     gtk_box_query_child_packing (GTK_BOX (container),
228                                  child,
229                                  &expand,
230                                  &fill,
231                                  &padding,
232                                  &pack_type);
233   switch (property_id)
234     {
235     case CHILD_PROP_EXPAND:
236       gtk_box_set_child_packing (GTK_BOX (container),
237                                  child,
238                                  g_value_get_boolean (value),
239                                  fill,
240                                  padding,
241                                  pack_type);
242       break;
243     case CHILD_PROP_FILL:
244       gtk_box_set_child_packing (GTK_BOX (container),
245                                  child,
246                                  expand,
247                                  g_value_get_boolean (value),
248                                  padding,
249                                  pack_type);
250       break;
251     case CHILD_PROP_PADDING:
252       gtk_box_set_child_packing (GTK_BOX (container),
253                                  child,
254                                  expand,
255                                  fill,
256                                  g_value_get_uint (value),
257                                  pack_type);
258       break;
259     case CHILD_PROP_PACK_TYPE:
260       gtk_box_set_child_packing (GTK_BOX (container),
261                                  child,
262                                  expand,
263                                  fill,
264                                  padding,
265                                  g_value_get_enum (value));
266       break;
267     case CHILD_PROP_POSITION:
268       gtk_box_reorder_child (GTK_BOX (container),
269                              child,
270                              g_value_get_int (value));
271       break;
272     default:
273       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
274       break;
275     }
276 }
277
278 static void
279 gtk_box_get_child_property (GtkContainer *container,
280                             GtkWidget    *child,
281                             guint         property_id,
282                             GValue       *value,
283                             GParamSpec   *pspec)
284 {
285   gboolean expand = 0;
286   gboolean fill = 0;
287   guint padding = 0;
288   GtkPackType pack_type = 0;
289   GList *list;
290
291   if (property_id != CHILD_PROP_POSITION)
292     gtk_box_query_child_packing (GTK_BOX (container),
293                                  child,
294                                  &expand,
295                                  &fill,
296                                  &padding,
297                                  &pack_type);
298   switch (property_id)
299     {
300       guint i;
301     case CHILD_PROP_EXPAND:
302       g_value_set_boolean (value, expand);
303       break;
304     case CHILD_PROP_FILL:
305       g_value_set_boolean (value, fill);
306       break;
307     case CHILD_PROP_PADDING:
308       g_value_set_uint (value, padding);
309       break;
310     case CHILD_PROP_PACK_TYPE:
311       g_value_set_enum (value, pack_type);
312       break;
313     case CHILD_PROP_POSITION:
314       i = 0;
315       for (list = GTK_BOX (container)->children; list; list = list->next)
316         {
317           GtkBoxChild *child_entry;
318
319           child_entry = list->data;
320           if (child_entry->widget == child)
321             break;
322           i++;
323         }
324       g_value_set_int (value, list ? i : -1);
325       break;
326     default:
327       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
328       break;
329     }
330 }
331
332 static void
333 gtk_box_pack (GtkBox      *box,
334               GtkWidget   *child,
335               gboolean     expand,
336               gboolean     fill,
337               guint        padding,
338               GtkPackType  pack_type)
339 {
340   GtkBoxChild *child_info;
341
342   g_return_if_fail (GTK_IS_BOX (box));
343   g_return_if_fail (GTK_IS_WIDGET (child));
344   g_return_if_fail (child->parent == NULL);
345
346   child_info = g_new (GtkBoxChild, 1);
347   child_info->widget = child;
348   child_info->padding = padding;
349   child_info->expand = expand ? TRUE : FALSE;
350   child_info->fill = fill ? TRUE : FALSE;
351   child_info->pack = pack_type;
352   child_info->is_secondary = FALSE;
353
354   box->children = g_list_append (box->children, child_info);
355
356   gtk_widget_freeze_child_notify (child);
357
358   gtk_widget_set_parent (child, GTK_WIDGET (box));
359   
360   gtk_widget_child_notify (child, "expand");
361   gtk_widget_child_notify (child, "fill");
362   gtk_widget_child_notify (child, "padding");
363   gtk_widget_child_notify (child, "pack-type");
364   gtk_widget_child_notify (child, "position");
365   gtk_widget_thaw_child_notify (child);
366 }
367
368 /**
369  * gtk_box_pack_start:
370  * @box: a #GtkBox
371  * @child: the #GtkWidget to be added to @box
372  * @expand: %TRUE if the new child is to be given extra space allocated to
373  * @box.  The extra space will be divided evenly between all children of
374  * @box that use this option
375  * @fill: %TRUE if space given to @child by the @expand option is
376  *   actually allocated to @child, rather than just padding it.  This
377  *   parameter has no effect if @expand is set to %FALSE.  A child is
378  *   always allocated the full height of a #GtkHBox and the full width 
379  *   of a #GtkVBox. This option affects the other dimension
380  * @padding: extra space in pixels to put between this child and its
381  *   neighbors, over and above the global amount specified by
382  *   #GtkBox:spacing property.  If @child is a widget at one of the 
383  *   reference ends of @box, then @padding pixels are also put between 
384  *   @child and the reference edge of @box
385  *
386  * Adds @child to @box, packed with reference to the start of @box.
387  * The @child is packed after any other child packed with reference 
388  * to the start of @box.
389  */
390 void
391 gtk_box_pack_start (GtkBox    *box,
392                     GtkWidget *child,
393                     gboolean   expand,
394                     gboolean   fill,
395                     guint      padding)
396 {
397   gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_START);
398 }
399
400 /**
401  * gtk_box_pack_end:
402  * @box: a #GtkBox
403  * @child: the #GtkWidget to be added to @box
404  * @expand: %TRUE if the new child is to be given extra space allocated 
405  *   to @box. The extra space will be divided evenly between all children 
406  *   of @box that use this option
407  * @fill: %TRUE if space given to @child by the @expand option is
408  *   actually allocated to @child, rather than just padding it.  This
409  *   parameter has no effect if @expand is set to %FALSE.  A child is
410  *   always allocated the full height of a #GtkHBox and the full width 
411  *   of a #GtkVBox.  This option affects the other dimension
412  * @padding: extra space in pixels to put between this child and its
413  *   neighbors, over and above the global amount specified by
414  *   #GtkBox:spacing property.  If @child is a widget at one of the 
415  *   reference ends of @box, then @padding pixels are also put between 
416  *   @child and the reference edge of @box
417  *
418  * Adds @child to @box, packed with reference to the end of @box.  
419  * The @child is packed after (away from end of) any other child 
420  * packed with reference to the end of @box.
421  */
422 void
423 gtk_box_pack_end (GtkBox    *box,
424                   GtkWidget *child,
425                   gboolean   expand,
426                   gboolean   fill,
427                   guint      padding)
428 {
429   gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_END);
430 }
431
432 /**
433  * gtk_box_pack_start_defaults:
434  * @box: a #GtkBox
435  * @widget: the #GtkWidget to be added to @box
436  *
437  * Adds @widget to @box, packed with reference to the start of @box.
438  * The child is packed after any other child packed with reference 
439  * to the start of @box. 
440  * 
441  * Parameters for how to pack the child @widget, #GtkBox:expand, 
442  * #GtkBox:fill and #GtkBox:padding, are given their default
443  * values, %TRUE, %TRUE, and 0, respectively.
444  *
445  * Deprecated: 2.14: Use gtk_box_pack_start()
446  */
447 void
448 gtk_box_pack_start_defaults (GtkBox    *box,
449                              GtkWidget *child)
450 {
451   gtk_box_pack_start (box, child, TRUE, TRUE, 0);
452 }
453
454 /**
455  * gtk_box_pack_end_defaults:
456  * @box: a #GtkBox
457  * @widget: the #GtkWidget to be added to @box
458  *
459  * Adds @widget to @box, packed with reference to the end of @box.
460  * The child is packed after any other child packed with reference 
461  * to the start of @box. 
462  * 
463  * Parameters for how to pack the child @widget, #GtkBox:expand, 
464  * #GtkBox:fill and #GtkBox:padding, are given their default
465  * values, %TRUE, %TRUE, and 0, respectively.
466  *
467  * Deprecated: 2.14: Use gtk_box_pack_end()
468  */
469 void
470 gtk_box_pack_end_defaults (GtkBox    *box,
471                            GtkWidget *child)
472 {
473   gtk_box_pack_end (box, child, TRUE, TRUE, 0);
474 }
475
476 /**
477  * gtk_box_set_homogeneous:
478  * @box: a #GtkBox
479  * @homogeneous: a boolean value, %TRUE to create equal allotments,
480  *   %FALSE for variable allotments
481  * 
482  * Sets the #GtkBox:homogeneous property of @box, controlling 
483  * whether or not all children of @box are given equal space 
484  * in the box.
485  */
486 void
487 gtk_box_set_homogeneous (GtkBox  *box,
488                          gboolean homogeneous)
489 {
490   g_return_if_fail (GTK_IS_BOX (box));
491
492   if ((homogeneous ? TRUE : FALSE) != box->homogeneous)
493     {
494       box->homogeneous = homogeneous ? TRUE : FALSE;
495       g_object_notify (G_OBJECT (box), "homogeneous");
496       gtk_widget_queue_resize (GTK_WIDGET (box));
497     }
498 }
499
500 /**
501  * gtk_box_get_homogeneous:
502  * @box: a #GtkBox
503  *
504  * Returns whether the box is homogeneous (all children are the
505  * same size). See gtk_box_set_homogeneous().
506  *
507  * Return value: %TRUE if the box is homogeneous.
508  **/
509 gboolean
510 gtk_box_get_homogeneous (GtkBox *box)
511 {
512   g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
513
514   return box->homogeneous;
515 }
516
517 /**
518  * gtk_box_set_spacing:
519  * @box: a #GtkBox
520  * @spacing: the number of pixels to put between children
521  *
522  * Sets the #GtkBox:spacing property of @box, which is the 
523  * number of pixels to place between children of @box.
524  */
525 void
526 gtk_box_set_spacing (GtkBox *box,
527                      gint    spacing)
528 {
529   g_return_if_fail (GTK_IS_BOX (box));
530
531   if (spacing != box->spacing)
532     {
533       box->spacing = spacing;
534       g_object_notify (G_OBJECT (box), "spacing");
535       gtk_widget_queue_resize (GTK_WIDGET (box));
536     }
537 }
538
539 /**
540  * gtk_box_get_spacing:
541  * @box: a #GtkBox
542  * 
543  * Gets the value set by gtk_box_set_spacing().
544  * 
545  * Return value: spacing between children
546  **/
547 gint
548 gtk_box_get_spacing (GtkBox *box)
549 {
550   g_return_val_if_fail (GTK_IS_BOX (box), 0);
551
552   return box->spacing;
553 }
554
555 /**
556  * gtk_box_reorder_child:
557  * @box: a #GtkBox
558  * @child: the #GtkWidget to move
559  * @position: the new position for @child in the list of children 
560  *   of @box, starting from 0. If negative, indicates the end of 
561  *   the list
562  *
563  * Moves @child to a new @position in the list of @box children.  
564  * The list is the <structfield>children</structfield> field of
565  * #GtkBox-struct, and contains both widgets packed #GTK_PACK_START 
566  * as well as widgets packed #GTK_PACK_END, in the order that these 
567  * widgets were added to @box.
568  * 
569  * A widget's position in the @box children list determines where 
570  * the widget is packed into @box.  A child widget at some position 
571  * in the list will be packed just after all other widgets of the 
572  * same packing type that appear earlier in the list.
573  */ 
574 void
575 gtk_box_reorder_child (GtkBox    *box,
576                        GtkWidget *child,
577                        gint       position)
578 {
579   GList *old_link;
580   GList *new_link;
581   GtkBoxChild *child_info = NULL;
582   gint old_position;
583
584   g_return_if_fail (GTK_IS_BOX (box));
585   g_return_if_fail (GTK_IS_WIDGET (child));
586
587   old_link = box->children;
588   old_position = 0;
589   while (old_link)
590     {
591       child_info = old_link->data;
592       if (child_info->widget == child)
593         break;
594
595       old_link = old_link->next;
596       old_position++;
597     }
598
599   g_return_if_fail (old_link != NULL);
600
601   if (position == old_position)
602     return;
603
604   box->children = g_list_delete_link (box->children, old_link);
605
606   if (position < 0)
607     new_link = NULL;
608   else
609     new_link = g_list_nth (box->children, position);
610
611   box->children = g_list_insert_before (box->children, new_link, child_info);
612
613   gtk_widget_child_notify (child, "position");
614   if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
615     gtk_widget_queue_resize (child);
616 }
617
618 /**
619  * gtk_box_query_child_packing:
620  * @box: a #GtkBox
621  * @child: the #GtkWidget of the child to query
622  * @expand: pointer to return location for #GtkBox:expand child property 
623  * @fill: pointer to return location for #GtkBox:fill child property 
624  * @padding: pointer to return location for #GtkBox:padding child property 
625  * @pack_type: pointer to return location for #GtkBox:pack-type child property 
626  * 
627  * Obtains information about how @child is packed into @box.
628  */
629 void
630 gtk_box_query_child_packing (GtkBox      *box,
631                              GtkWidget   *child,
632                              gboolean    *expand,
633                              gboolean    *fill,
634                              guint       *padding,
635                              GtkPackType *pack_type)
636 {
637   GList *list;
638   GtkBoxChild *child_info = NULL;
639
640   g_return_if_fail (GTK_IS_BOX (box));
641   g_return_if_fail (GTK_IS_WIDGET (child));
642
643   list = box->children;
644   while (list)
645     {
646       child_info = list->data;
647       if (child_info->widget == child)
648         break;
649
650       list = list->next;
651     }
652
653   if (list)
654     {
655       if (expand)
656         *expand = child_info->expand;
657       if (fill)
658         *fill = child_info->fill;
659       if (padding)
660         *padding = child_info->padding;
661       if (pack_type)
662         *pack_type = child_info->pack;
663     }
664 }
665
666 /**
667  * gtk_box_set_child_packing:
668  * @box: a #GtkBox
669  * @child: the #GtkWidget of the child to set
670  * @expand: the new value of the #GtkBox:expand child property 
671  * @fill: the new value of the #GtkBox:fill child property
672  * @padding: the new value of the #GtkBox:padding child property
673  * @pack_type: the new value of the #GtkBox:pack-type child property
674  *
675  * Sets the way @child is packed into @box.
676  */
677 void
678 gtk_box_set_child_packing (GtkBox      *box,
679                            GtkWidget   *child,
680                            gboolean     expand,
681                            gboolean     fill,
682                            guint        padding,
683                            GtkPackType  pack_type)
684 {
685   GList *list;
686   GtkBoxChild *child_info = NULL;
687
688   g_return_if_fail (GTK_IS_BOX (box));
689   g_return_if_fail (GTK_IS_WIDGET (child));
690
691   list = box->children;
692   while (list)
693     {
694       child_info = list->data;
695       if (child_info->widget == child)
696         break;
697
698       list = list->next;
699     }
700
701   gtk_widget_freeze_child_notify (child);
702   if (list)
703     {
704       child_info->expand = expand != FALSE;
705       gtk_widget_child_notify (child, "expand");
706       child_info->fill = fill != FALSE;
707       gtk_widget_child_notify (child, "fill");
708       child_info->padding = padding;
709       gtk_widget_child_notify (child, "padding");
710       if (pack_type == GTK_PACK_END)
711         child_info->pack = GTK_PACK_END;
712       else
713         child_info->pack = GTK_PACK_START;
714       gtk_widget_child_notify (child, "pack-type");
715
716       if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
717         gtk_widget_queue_resize (child);
718     }
719   gtk_widget_thaw_child_notify (child);
720 }
721
722 static void
723 gtk_box_add (GtkContainer *container,
724              GtkWidget    *widget)
725 {
726   gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
727 }
728
729 static void
730 gtk_box_remove (GtkContainer *container,
731                 GtkWidget    *widget)
732 {
733   GtkBox *box = GTK_BOX (container);
734   GtkBoxChild *child;
735   GList *children;
736
737   children = box->children;
738   while (children)
739     {
740       child = children->data;
741
742       if (child->widget == widget)
743         {
744           gboolean was_visible;
745
746           was_visible = GTK_WIDGET_VISIBLE (widget);
747           gtk_widget_unparent (widget);
748
749           box->children = g_list_remove_link (box->children, children);
750           g_list_free (children);
751           g_free (child);
752
753           /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
754            * since that's what is needed by toplevels.
755            */
756           if (was_visible)
757             gtk_widget_queue_resize (GTK_WIDGET (container));
758
759           break;
760         }
761
762       children = children->next;
763     }
764 }
765
766 static void
767 gtk_box_forall (GtkContainer *container,
768                 gboolean      include_internals,
769                 GtkCallback   callback,
770                 gpointer      callback_data)
771 {
772   GtkBox *box = GTK_BOX (container);
773   GtkBoxChild *child;
774   GList *children;
775
776   children = box->children;
777   while (children)
778     {
779       child = children->data;
780       children = children->next;
781
782       if (child->pack == GTK_PACK_START)
783         (* callback) (child->widget, callback_data);
784     }
785
786   children = g_list_last (box->children);
787   while (children)
788     {
789       child = children->data;
790       children = children->prev;
791
792       if (child->pack == GTK_PACK_END)
793         (* callback) (child->widget, callback_data);
794     }
795 }
796
797 #define __GTK_BOX_C__
798 #include "gtkaliasdef.c"