]> Pileus Git - ~andy/gtk/blob - gtk/gtkbbox.c
Make orientable base classes instantiable
[~andy/gtk] / gtk / gtkbbox.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 /**
28  * SECTION:gtkbbox
29  * @Short_description: Base class for GtkHButtonBox and GtkVButtonBox
30  * @Title: GtkButtonBox
31  * @See_also: #GtkVButtonBox, #GtkHButtonBox
32  *
33  * The primary purpose of this class is to keep track of the various properties
34  * of #GtkHButtonBox and #GtkVButtonBox widgets.
35  *
36  * gtk_button_box_get_child_size() retrieves the minimum width and height
37  * for widgets in a given button box.
38  *
39  * The internal padding of buttons can be retrieved and changed per button box
40  * using gtk_button_box_get_child_ipadding() and
41  * gtk_button_box_set_child_ipadding() respectively.
42  *
43  * gtk_button_box_get_spacing() and gtk_button_box_set_spacing() retrieve and
44  * change default number of pixels between buttons, respectively.
45  *
46  * gtk_button_box_get_layout() and gtk_button_box_set_layout() retrieve and
47  * alter the method used to spread the buttons in a button box across the
48  * container, respectively.
49  *
50  * The main purpose of GtkButtonBox is to make sure the children have all the
51  * same size. Therefore it ignores the homogeneous property which it inherited
52  * from GtkBox, and always behaves as if homogeneous was %TRUE.
53  */
54
55 #include "config.h"
56 #include "gtkbbox.h"
57 #include "gtkhbbox.h"
58 #include "gtkvbbox.h"
59 #include "gtkorientable.h"
60 #include "gtkprivate.h"
61 #include "gtkintl.h"
62 #include "gtkalias.h"
63
64 enum {
65   PROP_0,
66   PROP_LAYOUT_STYLE
67 };
68
69 enum {
70   CHILD_PROP_0,
71   CHILD_PROP_SECONDARY
72 };
73
74 static void gtk_button_box_set_property       (GObject           *object,
75                                                guint              prop_id,
76                                                const GValue      *value,
77                                                GParamSpec        *pspec);
78 static void gtk_button_box_get_property       (GObject           *object,
79                                                guint              prop_id,
80                                                GValue            *value,
81                                                GParamSpec        *pspec);
82 static void gtk_button_box_size_request       (GtkWidget         *widget,
83                                                GtkRequisition    *requisition);
84 static void gtk_button_box_size_allocate      (GtkWidget         *widget,
85                                                GtkAllocation     *allocation);
86 static void gtk_button_box_set_child_property (GtkContainer      *container,
87                                                GtkWidget         *child,
88                                                guint              property_id,
89                                                const GValue      *value,
90                                                GParamSpec        *pspec);
91 static void gtk_button_box_get_child_property (GtkContainer      *container,
92                                                GtkWidget         *child,
93                                                guint              property_id,
94                                                GValue            *value,
95                                                GParamSpec        *pspec);
96
97 #define DEFAULT_CHILD_MIN_WIDTH 85
98 #define DEFAULT_CHILD_MIN_HEIGHT 27
99 #define DEFAULT_CHILD_IPAD_X 4
100 #define DEFAULT_CHILD_IPAD_Y 0
101
102 G_DEFINE_TYPE (GtkButtonBox, gtk_button_box, GTK_TYPE_BOX)
103
104 static void
105 gtk_button_box_class_init (GtkButtonBoxClass *class)
106 {
107   GtkWidgetClass *widget_class;
108   GObjectClass *gobject_class;
109   GtkContainerClass *container_class;
110
111   gobject_class = G_OBJECT_CLASS (class);
112   widget_class = (GtkWidgetClass*) class;
113   container_class = (GtkContainerClass*) class;
114
115   gobject_class->set_property = gtk_button_box_set_property;
116   gobject_class->get_property = gtk_button_box_get_property;
117
118   widget_class->size_request = gtk_button_box_size_request;
119   widget_class->size_allocate = gtk_button_box_size_allocate;
120
121   container_class->set_child_property = gtk_button_box_set_child_property;
122   container_class->get_child_property = gtk_button_box_get_child_property;
123
124   /* FIXME we need to override the "spacing" property on GtkBox once
125    * libgobject allows that.
126    */
127   gtk_widget_class_install_style_property (widget_class,
128                                            g_param_spec_int ("child-min-width",
129                                                              P_("Minimum child width"),
130                                                              P_("Minimum width of buttons inside the box"),
131                                                              0,
132                                                              G_MAXINT,
133                                                              DEFAULT_CHILD_MIN_WIDTH,
134                                                              GTK_PARAM_READABLE));
135
136   gtk_widget_class_install_style_property (widget_class,
137                                            g_param_spec_int ("child-min-height",
138                                                              P_("Minimum child height"),
139                                                              P_("Minimum height of buttons inside the box"),
140                                                              0,
141                                                              G_MAXINT,
142                                                              DEFAULT_CHILD_MIN_HEIGHT,
143                                                              GTK_PARAM_READABLE));
144
145   gtk_widget_class_install_style_property (widget_class,
146                                            g_param_spec_int ("child-internal-pad-x",
147                                                              P_("Child internal width padding"),
148                                                              P_("Amount to increase child's size on either side"),
149                                                              0,
150                                                              G_MAXINT,
151                                                              DEFAULT_CHILD_IPAD_X,
152                                                              GTK_PARAM_READABLE));
153
154   gtk_widget_class_install_style_property (widget_class,
155                                            g_param_spec_int ("child-internal-pad-y",
156                                                              P_("Child internal height padding"),
157                                                              P_("Amount to increase child's size on the top and bottom"),
158                                                              0,
159                                                              G_MAXINT,
160                                                              DEFAULT_CHILD_IPAD_Y,
161                                                              GTK_PARAM_READABLE));
162   g_object_class_install_property (gobject_class,
163                                    PROP_LAYOUT_STYLE,
164                                    g_param_spec_enum ("layout-style",
165                                                       P_("Layout style"),
166                                                       P_("How to layout the buttons in the box. Possible values are default, spread, edge, start and end"),
167                                                       GTK_TYPE_BUTTON_BOX_STYLE,
168                                                       GTK_BUTTONBOX_DEFAULT_STYLE,
169                                                       GTK_PARAM_READWRITE));
170
171   gtk_container_class_install_child_property (container_class,
172                                               CHILD_PROP_SECONDARY,
173                                               g_param_spec_boolean ("secondary", 
174                                                                     P_("Secondary"),
175                                                                     P_("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons"),
176                                                                     FALSE,
177                                                                     GTK_PARAM_READWRITE));
178 }
179
180 static void
181 gtk_button_box_init (GtkButtonBox *button_box)
182 {
183   GTK_BOX (button_box)->spacing = 0;
184   button_box->child_min_width = GTK_BUTTONBOX_DEFAULT;
185   button_box->child_min_height = GTK_BUTTONBOX_DEFAULT;
186   button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT;
187   button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT;
188   button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE;
189 }
190
191 static void
192 gtk_button_box_set_property (GObject         *object,
193                              guint            prop_id,
194                              const GValue    *value,
195                              GParamSpec      *pspec)
196 {
197   switch (prop_id)
198     {
199     case PROP_LAYOUT_STYLE:
200       gtk_button_box_set_layout (GTK_BUTTON_BOX (object),
201                                  g_value_get_enum (value));
202       break;
203     default:
204       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205       break;
206     }
207 }
208
209 static void
210 gtk_button_box_get_property (GObject         *object,
211                              guint            prop_id,
212                              GValue          *value,
213                              GParamSpec      *pspec)
214 {
215   switch (prop_id)
216     {
217     case PROP_LAYOUT_STYLE:
218       g_value_set_enum (value, GTK_BUTTON_BOX (object)->layout_style);
219       break;
220     default:
221       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222       break;
223     }
224 }
225
226 static void
227 gtk_button_box_set_child_property (GtkContainer    *container,
228                                    GtkWidget       *child,
229                                    guint            property_id,
230                                    const GValue    *value,
231                                    GParamSpec      *pspec)
232 {
233   switch (property_id)
234     {
235     case CHILD_PROP_SECONDARY:
236       gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
237                                           g_value_get_boolean (value));
238       break;
239     default:
240       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
241       break;
242     }
243 }
244
245 static void
246 gtk_button_box_get_child_property (GtkContainer *container,
247                                    GtkWidget    *child,
248                                    guint         property_id,
249                                    GValue       *value,
250                                    GParamSpec   *pspec)
251 {
252   switch (property_id)
253     {
254     case CHILD_PROP_SECONDARY:
255       g_value_set_boolean (value, 
256                            gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (container), 
257                                                                child));
258       break;
259     default:
260       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
261       break;
262     }
263 }
264
265 /**
266  * gtk_button_box_set_layout:
267  * @widget: a #GtkButtonBox
268  * @layout_style: the new layout style
269  *
270  * Changes the way buttons are arranged in their container.
271  */
272 void
273 gtk_button_box_set_layout (GtkButtonBox      *widget, 
274                            GtkButtonBoxStyle  layout_style)
275 {
276   g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
277   g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE &&
278                     layout_style <= GTK_BUTTONBOX_CENTER);
279
280   if (widget->layout_style != layout_style)
281     {
282       widget->layout_style = layout_style;
283       g_object_notify (G_OBJECT (widget), "layout-style");
284       gtk_widget_queue_resize (GTK_WIDGET (widget));
285     }
286 }
287
288 /**
289  * gtk_button_box_get_layout:
290  * @widget: a #GtkButtonBox
291  *
292  * Retrieves the method being used to arrange the buttons in a button box.
293  *
294  * Returns: the method used to layout buttons in @widget.
295  */
296 GtkButtonBoxStyle 
297 gtk_button_box_get_layout (GtkButtonBox *widget)
298 {
299   g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
300   
301   return widget->layout_style;
302 }
303
304 /**
305  * gtk_button_box_get_child_secondary:
306  * @widget: a #GtkButtonBox
307  * @child: a child of @widget 
308  * 
309  * Returns whether @child should appear in a secondary group of children.
310  *
311  * Return value: whether @child should appear in a secondary group of children.
312  *
313  * Since: 2.4
314  **/
315 gboolean 
316 gtk_button_box_get_child_secondary (GtkButtonBox *widget,
317                                     GtkWidget    *child)
318 {
319   GList *list;
320   GtkBoxChild *child_info;
321
322   g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), FALSE);
323   g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
324
325   child_info = NULL;
326   list = GTK_BOX (widget)->children;
327   while (list)
328     {
329       child_info = list->data;
330       if (child_info->widget == child)
331         break;
332
333       list = list->next;
334     }
335
336   g_return_val_if_fail (list != NULL, FALSE);
337
338   return child_info->is_secondary;
339 }
340
341 /**
342  * gtk_button_box_set_child_secondary
343  * @widget: a #GtkButtonBox
344  * @child: a child of @widget
345  * @is_secondary: if %TRUE, the @child appears in a secondary group of the
346  *                button box.
347  *
348  * Sets whether @child should appear in a secondary group of children.
349  * A typical use of a secondary child is the help button in a dialog.
350  *
351  * This group appears after the other children if the style
352  * is %GTK_BUTTONBOX_START, %GTK_BUTTONBOX_SPREAD or
353  * %GTK_BUTTONBOX_EDGE, and before the other children if the style
354  * is %GTK_BUTTONBOX_END. For horizontal button boxes, the definition
355  * of before/after depends on direction of the widget (see
356  * gtk_widget_set_direction()). If the style is %GTK_BUTTONBOX_START
357  * or %GTK_BUTTONBOX_END, then the secondary children are aligned at
358  * the other end of the button box from the main children. For the
359  * other styles, they appear immediately next to the main children.
360  **/
361 void 
362 gtk_button_box_set_child_secondary (GtkButtonBox *widget, 
363                                     GtkWidget    *child,
364                                     gboolean      is_secondary)
365 {
366   GList *list;
367   
368   g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
369   g_return_if_fail (GTK_IS_WIDGET (child));
370   g_return_if_fail (child->parent == GTK_WIDGET (widget));
371
372   list = GTK_BOX (widget)->children;
373   while (list)
374     {
375       GtkBoxChild *child_info = list->data;
376       if (child_info->widget == child)
377         {
378           child_info->is_secondary = is_secondary;
379           break;
380         }
381
382       list = list->next;
383     }
384
385   gtk_widget_child_notify (child, "secondary");
386
387   if (gtk_widget_get_visible (GTK_WIDGET (widget))
388       && gtk_widget_get_visible (child))
389     gtk_widget_queue_resize (child);
390 }
391
392 /* Ask children how much space they require and round up 
393    to match minimum size and internal padding.
394    Returns the size each single child should have. */
395 void
396 _gtk_button_box_child_requisition (GtkWidget *widget,
397                                    int       *nvis_children,
398                                    int       *nvis_secondaries,
399                                    int       *width,
400                                    int       *height)
401 {
402   GtkButtonBox *bbox;
403   GtkBoxChild *child;
404   GList *children;
405   gint nchildren;
406   gint nsecondaries;
407   gint needed_width;
408   gint needed_height;
409   GtkRequisition child_requisition;
410   gint ipad_w;
411   gint ipad_h;
412   gint width_default;
413   gint height_default;
414   gint ipad_x_default;
415   gint ipad_y_default;
416   
417   gint child_min_width;
418   gint child_min_height;
419   gint ipad_x;
420   gint ipad_y;
421   
422   g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
423
424   bbox = GTK_BUTTON_BOX (widget);
425
426   gtk_widget_style_get (widget,
427                         "child-min-width", &width_default,
428                         "child-min-height", &height_default,
429                         "child-internal-pad-x", &ipad_x_default,
430                         "child-internal-pad-y", &ipad_y_default, 
431                         NULL);
432   
433   child_min_width = bbox->child_min_width   != GTK_BUTTONBOX_DEFAULT
434           ? bbox->child_min_width : width_default;
435   child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
436           ? bbox->child_min_height : height_default;
437   ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
438           ? bbox->child_ipad_x : ipad_x_default;
439   ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
440           ? bbox->child_ipad_y : ipad_y_default;
441
442   nchildren = 0;
443   nsecondaries = 0;
444   children = GTK_BOX(bbox)->children;
445   needed_width = child_min_width;
446   needed_height = child_min_height;  
447   ipad_w = ipad_x * 2;
448   ipad_h = ipad_y * 2;
449   
450   while (children)
451     {
452       child = children->data;
453       children = children->next;
454
455       if (gtk_widget_get_visible (child->widget))
456         {
457           nchildren += 1;
458           gtk_widget_size_request (child->widget, &child_requisition);
459
460           if (child_requisition.width + ipad_w > needed_width)
461             needed_width = child_requisition.width + ipad_w;
462           if (child_requisition.height + ipad_h > needed_height)
463             needed_height = child_requisition.height + ipad_h;
464           if (child->is_secondary)
465             nsecondaries++;
466         }
467     }
468
469   if (nvis_children)
470     *nvis_children = nchildren;
471   if (nvis_secondaries)
472     *nvis_secondaries = nsecondaries;
473   if (width)
474     *width = needed_width;
475   if (height)
476     *height = needed_height;
477 }
478
479 /* this is a kludge function to support the deprecated
480  * gtk_[vh]button_box_set_layout_default() just in case anyone is still
481  * using it (why?)
482  */
483 static GtkButtonBoxStyle
484 gtk_button_box_kludge_get_layout_default (GtkButtonBox *widget)
485 {
486   GtkOrientation orientation;
487
488   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
489
490   if (orientation == GTK_ORIENTATION_HORIZONTAL)
491     return _gtk_hbutton_box_get_layout_default ();
492   else
493     return _gtk_vbutton_box_get_layout_default ();
494 }
495
496 static void
497 gtk_button_box_size_request (GtkWidget      *widget,
498                              GtkRequisition *requisition)
499 {
500   GtkBox *box;
501   GtkButtonBox *bbox;
502   gint nvis_children;
503   gint child_width;
504   gint child_height;
505   gint spacing;
506   GtkButtonBoxStyle layout;
507   GtkOrientation orientation;
508
509   box = GTK_BOX (widget);
510   bbox = GTK_BUTTON_BOX (widget);
511
512   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
513   spacing = box->spacing;
514   layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
515           ? bbox->layout_style : gtk_button_box_kludge_get_layout_default (GTK_BUTTON_BOX (widget));
516
517   _gtk_button_box_child_requisition (widget,
518                                      &nvis_children,
519                                      NULL,
520                                      &child_width,
521                                      &child_height);
522
523   if (nvis_children == 0)
524     {
525       requisition->width = 0;
526       requisition->height = 0;
527     }
528   else
529     {
530       switch (layout)
531         {
532           case GTK_BUTTONBOX_SPREAD:
533             if (orientation == GTK_ORIENTATION_HORIZONTAL)
534               requisition->width =
535                       nvis_children*child_width + ((nvis_children+1)*spacing);
536             else
537               requisition->height =
538                       nvis_children*child_height + ((nvis_children+1)*spacing);
539
540             break;
541           case GTK_BUTTONBOX_EDGE:
542           case GTK_BUTTONBOX_START:
543           case GTK_BUTTONBOX_END:
544           case GTK_BUTTONBOX_CENTER:
545             if (orientation == GTK_ORIENTATION_HORIZONTAL)
546               requisition->width =
547                       nvis_children*child_width + ((nvis_children-1)*spacing);
548             else
549               requisition->height =
550                       nvis_children*child_height + ((nvis_children-1)*spacing);
551
552             break;
553           default:
554             g_assert_not_reached ();
555             break;
556         }
557
558       if (orientation == GTK_ORIENTATION_HORIZONTAL)
559         requisition->height = child_height;
560       else
561         requisition->width = child_width;
562     }
563
564   requisition->width += GTK_CONTAINER (box)->border_width * 2;
565   requisition->height += GTK_CONTAINER (box)->border_width * 2;
566 }
567
568 static void
569 gtk_button_box_size_allocate (GtkWidget     *widget,
570                               GtkAllocation *allocation)
571 {
572   GtkBox *base_box;
573   GtkButtonBox *box;
574   GtkBoxChild *child;
575   GList *children;
576   GtkAllocation child_allocation;
577   gint nvis_children;
578   gint n_secondaries;
579   gint child_width;
580   gint child_height;
581   gint x = 0;
582   gint y = 0;
583   gint secondary_x = 0;
584   gint secondary_y = 0;
585   gint width = 0;
586   gint height = 0;
587   gint childspace;
588   gint childspacing = 0;
589   GtkButtonBoxStyle layout;
590   gint spacing;
591   GtkOrientation orientation;
592
593   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
594   base_box = GTK_BOX (widget);
595   box = GTK_BUTTON_BOX (widget);
596   spacing = base_box->spacing;
597   layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
598           ? box->layout_style : gtk_button_box_kludge_get_layout_default (GTK_BUTTON_BOX (widget));
599   _gtk_button_box_child_requisition (widget,
600                                      &nvis_children,
601                                      &n_secondaries,
602                                      &child_width,
603                                      &child_height);
604   widget->allocation = *allocation;
605
606   if (orientation == GTK_ORIENTATION_HORIZONTAL)
607     width = allocation->width - GTK_CONTAINER (box)->border_width*2;
608   else
609     height = allocation->height - GTK_CONTAINER (box)->border_width*2;
610
611   switch (layout)
612     {
613       case GTK_BUTTONBOX_SPREAD:
614
615         if (orientation == GTK_ORIENTATION_HORIZONTAL)
616           {
617             childspacing = (width - (nvis_children * child_width))
618                     / (nvis_children + 1);
619             x = allocation->x + GTK_CONTAINER (box)->border_width
620                     + childspacing;
621             secondary_x = x + ((nvis_children - n_secondaries)
622                             * (child_width + childspacing));
623           }
624         else
625           {
626             childspacing = (height - (nvis_children * child_height))
627                     / (nvis_children + 1);
628             y = allocation->y + GTK_CONTAINER (box)->border_width
629                     + childspacing;
630             secondary_y = y + ((nvis_children - n_secondaries)
631                             * (child_height + childspacing));
632           }
633
634         break;
635
636       case GTK_BUTTONBOX_EDGE:
637
638         if (orientation == GTK_ORIENTATION_HORIZONTAL)
639           {
640             if (nvis_children >= 2)
641               {
642                 childspacing = (width - (nvis_children * child_width))
643                       / (nvis_children - 1);
644                 x = allocation->x + GTK_CONTAINER (box)->border_width;
645                 secondary_x = x + ((nvis_children - n_secondaries)
646                                    * (child_width + childspacing));
647               }
648             else
649               {
650                 /* one or zero children, just center */
651                 childspacing = width;
652                 x = secondary_x = allocation->x
653                       + (allocation->width - child_width) / 2;
654               }
655           }
656         else
657           {
658             if (nvis_children >= 2)
659               {
660                 childspacing = (height - (nvis_children*child_height))
661                         / (nvis_children-1);
662                 y = allocation->y + GTK_CONTAINER (box)->border_width;
663                 secondary_y = y + ((nvis_children - n_secondaries)
664                                 * (child_height + childspacing));
665               }
666             else
667               {
668                 /* one or zero children, just center */
669                 childspacing = height;
670                 y = secondary_y = allocation->y
671                         + (allocation->height - child_height) / 2;
672               }
673           }
674
675         break;
676
677       case GTK_BUTTONBOX_START:
678
679         if (orientation == GTK_ORIENTATION_HORIZONTAL)
680           {
681             childspacing = spacing;
682             x = allocation->x + GTK_CONTAINER (box)->border_width;
683             secondary_x = allocation->x + allocation->width
684               - child_width * n_secondaries
685               - spacing * (n_secondaries - 1)
686               - GTK_CONTAINER (box)->border_width;
687           }
688         else
689           {
690             childspacing = spacing;
691             y = allocation->y + GTK_CONTAINER (box)->border_width;
692             secondary_y = allocation->y + allocation->height
693               - child_height * n_secondaries
694               - spacing * (n_secondaries - 1)
695               - GTK_CONTAINER (box)->border_width;
696           }
697
698         break;
699
700       case GTK_BUTTONBOX_END:
701
702         if (orientation == GTK_ORIENTATION_HORIZONTAL)
703           {
704             childspacing = spacing;
705             x = allocation->x + allocation->width
706               - child_width * (nvis_children - n_secondaries)
707               - spacing * (nvis_children - n_secondaries - 1)
708               - GTK_CONTAINER (box)->border_width;
709             secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
710           }
711         else
712           {
713             childspacing = spacing;
714             y = allocation->y + allocation->height
715               - child_height * (nvis_children - n_secondaries)
716               - spacing * (nvis_children - n_secondaries - 1)
717               - GTK_CONTAINER (box)->border_width;
718             secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
719           }
720
721         break;
722
723       case GTK_BUTTONBOX_CENTER:
724
725         if (orientation == GTK_ORIENTATION_HORIZONTAL)
726           {
727             childspacing = spacing;
728             x = allocation->x +
729               (allocation->width
730                - (child_width * (nvis_children - n_secondaries)
731                + spacing * (nvis_children - n_secondaries - 1))) / 2
732               + (n_secondaries * child_width + n_secondaries * spacing) / 2;
733             secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
734           }
735         else
736           {
737             childspacing = spacing;
738             y = allocation->y +
739               (allocation->height
740                - (child_height * (nvis_children - n_secondaries)
741                   + spacing * (nvis_children - n_secondaries - 1))) / 2
742               + (n_secondaries * child_height + n_secondaries * spacing) / 2;
743             secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
744           }
745
746         break;
747
748       default:
749         g_assert_not_reached ();
750         break;
751     }
752
753     if (orientation == GTK_ORIENTATION_HORIZONTAL)
754       {
755         y = allocation->y + (allocation->height - child_height) / 2;
756         childspace = child_width + childspacing;
757       }
758     else
759       {
760         x = allocation->x + (allocation->width - child_width) / 2;
761         childspace = child_height + childspacing;
762       }
763
764   children = GTK_BOX (box)->children;
765
766   while (children)
767     {
768       child = children->data;
769       children = children->next;
770
771       if (gtk_widget_get_visible (child->widget))
772         {
773           child_allocation.width = child_width;
774           child_allocation.height = child_height;
775
776           if (orientation == GTK_ORIENTATION_HORIZONTAL)
777             {
778               child_allocation.y = y;
779
780               if (child->is_secondary)
781                 {
782                   child_allocation.x = secondary_x;
783                   secondary_x += childspace;
784                 }
785               else
786                 {
787                   child_allocation.x = x;
788                   x += childspace;
789                 }
790
791               if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
792                   child_allocation.x = (allocation->x + allocation->width)
793                           - (child_allocation.x + child_width - allocation->x);
794             }
795           else
796             {
797               child_allocation.x = x;
798
799               if (child->is_secondary)
800                 {
801                   child_allocation.y = secondary_y;
802                   secondary_y += childspace;
803                 }
804               else
805                 {
806                   child_allocation.y = y;
807                   y += childspace;
808                 }
809             }
810
811           gtk_widget_size_allocate (child->widget, &child_allocation);
812         }
813     }
814 }
815
816 /**
817  * gtk_button_box_new:
818  * @orientation: the box' orientation.
819  *
820  * Creates a new #GtkButtonBox.
821  *
822  * Return value: a new #GtkButtonBox.
823  *
824  * Since: 3.0
825  */
826 GtkWidget *
827 gtk_button_box_new (GtkOrientation orientation)
828 {
829   return g_object_new (GTK_TYPE_BUTTON_BOX,
830                        "orientation", orientation,
831                        NULL);
832 }
833
834 #define __GTK_BUTTON_BOX_C__
835 #include "gtkaliasdef.c"