]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhbbox.c
Use the correct screen for getting the height. (Fix from Stephen Browne,
[~andy/gtk] / gtk / gtkhbbox.c
index af95fe73ef718ae2125d60001d006713ddaa7102..cf7932723564e48eb173058fe2f1a55a10e8e9f4 100644 (file)
@@ -37,26 +37,29 @@ static void gtk_hbutton_box_size_allocate (GtkWidget      *widget,
 static gint default_spacing = 30;
 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
 
-GtkType
+GType
 gtk_hbutton_box_get_type (void)
 {
-  static GtkType hbutton_box_type = 0;
+  static GType hbutton_box_type = 0;
 
   if (!hbutton_box_type)
     {
-      static const GtkTypeInfo hbutton_box_info =
+      static const GTypeInfo hbutton_box_info =
       {
-       "GtkHButtonBox",
-       sizeof (GtkHButtonBox),
        sizeof (GtkHButtonBoxClass),
-       (GtkClassInitFunc) gtk_hbutton_box_class_init,
-       (GtkObjectInitFunc) gtk_hbutton_box_init,
-       /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_hbutton_box_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkHButtonBox),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_hbutton_box_init,
       };
 
-      hbutton_box_type = gtk_type_unique (GTK_TYPE_BUTTON_BOX, &hbutton_box_info);
+      hbutton_box_type =
+       g_type_register_static (GTK_TYPE_BUTTON_BOX, "GtkHButtonBox",
+                               &hbutton_box_info, 0);
     }
 
   return hbutton_box_type;
@@ -84,7 +87,7 @@ gtk_hbutton_box_new (void)
 {
   GtkHButtonBox *hbutton_box;
 
-  hbutton_box = gtk_type_new (GTK_TYPE_HBUTTON_BOX);
+  hbutton_box = g_object_new (GTK_TYPE_HBUTTON_BOX, NULL);
 
   return GTK_WIDGET (hbutton_box);
 }
@@ -92,7 +95,8 @@ gtk_hbutton_box_new (void)
 
 /* set default value for spacing */
 
-void gtk_hbutton_box_set_spacing_default (gint spacing)
+void 
+gtk_hbutton_box_set_spacing_default (gint spacing)
 {
   default_spacing = spacing;
 }
@@ -100,7 +104,8 @@ void gtk_hbutton_box_set_spacing_default (gint spacing)
 
 /* set default value for layout style */
 
-void gtk_hbutton_box_set_layout_default (GtkButtonBoxStyle layout)
+void 
+gtk_hbutton_box_set_layout_default (GtkButtonBoxStyle layout)
 {
   g_return_if_fail (layout >= GTK_BUTTONBOX_DEFAULT_STYLE &&
                    layout <= GTK_BUTTONBOX_END);
@@ -110,7 +115,8 @@ void gtk_hbutton_box_set_layout_default (GtkButtonBoxStyle layout)
 
 /* get default value for spacing */
 
-gint gtk_hbutton_box_get_spacing_default (void)
+gint 
+gtk_hbutton_box_get_spacing_default (void)
 {
   return default_spacing;
 }
@@ -118,7 +124,8 @@ gint gtk_hbutton_box_get_spacing_default (void)
 
 /* get default value for layout style */
 
-GtkButtonBoxStyle gtk_hbutton_box_get_layout_default (void)
+GtkButtonBoxStyle
+gtk_hbutton_box_get_layout_default (void)
 {
   return default_layout_style;
 }
@@ -137,10 +144,6 @@ gtk_hbutton_box_size_request (GtkWidget      *widget,
   gint spacing;
   GtkButtonBoxStyle layout;
   
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
-  g_return_if_fail (requisition != NULL);
-
   box = GTK_BOX (widget);
   bbox = GTK_BUTTON_BOX (widget);
 
@@ -150,6 +153,7 @@ gtk_hbutton_box_size_request (GtkWidget      *widget,
   
   _gtk_button_box_child_requisition (widget,
                                      &nvis_children,
+                                    NULL,
                                      &child_width,
                                      &child_height);
 
@@ -196,9 +200,11 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
   GList *children;
   GtkAllocation child_allocation;
   gint nvis_children;
+  gint n_secondaries;
   gint child_width;
   gint child_height;
   gint x = 0;
+  gint secondary_x = 0;
   gint y = 0;
   gint width;
   gint childspace;
@@ -206,10 +212,6 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
   GtkButtonBoxStyle layout;
   gint spacing;
   
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_HBUTTON_BOX (widget));
-  g_return_if_fail (allocation != NULL);
-
   base_box = GTK_BOX (widget);
   box = GTK_BUTTON_BOX (widget);
   hbox = GTK_HBUTTON_BOX (widget);
@@ -218,6 +220,7 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
          ? box->layout_style : default_layout_style;
   _gtk_button_box_child_requisition (widget,
                                      &nvis_children,
+                                    &n_secondaries,
                                      &child_width,
                                      &child_height);
   widget->allocation = *allocation;
@@ -225,39 +228,46 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
   switch (layout)
   {
   case GTK_BUTTONBOX_SPREAD:
-    childspacing = (width - (nvis_children*child_width)) / (nvis_children+1);
+    childspacing = (width - (nvis_children * child_width)) / (nvis_children + 1);
     x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
+    secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
     break;
   case GTK_BUTTONBOX_EDGE:
     if (nvis_children >= 2)
-    {
-      childspacing =
-             (width - (nvis_children*child_width)) / (nvis_children-1);
-      x = allocation->x + GTK_CONTAINER (box)->border_width;
-    }
+      {
+       childspacing = (width - (nvis_children * child_width)) / (nvis_children - 1);
+       x = allocation->x + GTK_CONTAINER (box)->border_width;
+       secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
+      }
     else
       {
-                     /* one or zero children, just center */
+       /* one or zero children, just center */
         childspacing = width;
-       x = allocation->x + (allocation->width - child_width) / 2;
+       x = secondary_x = allocation->x + (allocation->width - child_width) / 2;
       }
     break;
   case GTK_BUTTONBOX_START:
     childspacing = spacing;
     x = allocation->x + GTK_CONTAINER (box)->border_width;
+    secondary_x = allocation->x + allocation->width 
+      - child_width * n_secondaries
+      - spacing * (n_secondaries - 1)
+      - GTK_CONTAINER (box)->border_width;
     break;
   case GTK_BUTTONBOX_END:
     childspacing = spacing;
-    x = allocation->x + allocation->width - child_width * nvis_children
-           - spacing *(nvis_children-1)
-           - GTK_CONTAINER (box)->border_width;
+    x = allocation->x + allocation->width 
+      - child_width * (nvis_children - n_secondaries)
+      - spacing * (nvis_children - n_secondaries - 1)
+      - GTK_CONTAINER (box)->border_width;
+    secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
     break;
   default:
     g_assert_not_reached();
     break;
   }
+
                  
-  
   y = allocation->y + (allocation->height - child_height) / 2;
   childspace = child_width + childspacing;
 
@@ -272,16 +282,23 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
        {
          child_allocation.width = child_width;
          child_allocation.height = child_height;
-
-         if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
-           child_allocation.x = x;
-         else
-           child_allocation.x = allocation->x + allocation->width - (x - allocation->x + child_width);
-         
          child_allocation.y = y;
+         
+         if (child->is_secondary)
+           {
+             child_allocation.x = secondary_x;
+             secondary_x += childspace;
+           }
+         else
+           {
+             child_allocation.x = x;
+             x += childspace;
+           }
 
+         if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+           child_allocation.x = (allocation->x + allocation->width) - (child_allocation.x + child_width - allocation->x);
+         
          gtk_widget_size_allocate (child->widget, &child_allocation);
-         x += childspace;
        }
     }
 }