]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhbbox.c
Silently return NULL if the widget is not realized. (#316023, Guillaume
[~andy/gtk] / gtk / gtkhbbox.c
index 28a7afb14139f7a64c2b251e2d962802ee459ad9..3dda89c16fd430ca632b903e61ca354ee4ce3911 100644 (file)
@@ -2,22 +2,32 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include <config.h>
 #include "gtkhbbox.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 
 static void gtk_hbutton_box_class_init    (GtkHButtonBoxClass   *klass);
@@ -30,25 +40,29 @@ static void gtk_hbutton_box_size_allocate (GtkWidget      *widget,
 static gint default_spacing = 30;
 static gint default_layout_style = GTK_BUTTONBOX_EDGE;
 
-guint
+GType
 gtk_hbutton_box_get_type (void)
 {
-  static guint hbutton_box_type = 0;
+  static GType hbutton_box_type = 0;
 
   if (!hbutton_box_type)
     {
-      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,
-       (GtkArgSetFunc) NULL,
-        (GtkArgGetFunc) 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_button_box_get_type (), &hbutton_box_info);
+      hbutton_box_type =
+       g_type_register_static (GTK_TYPE_BUTTON_BOX, I_("GtkHButtonBox"),
+                               &hbutton_box_info, 0);
     }
 
   return hbutton_box_type;
@@ -76,7 +90,7 @@ gtk_hbutton_box_new (void)
 {
   GtkHButtonBox *hbutton_box;
 
-  hbutton_box = gtk_type_new (gtk_hbutton_box_get_type ());
+  hbutton_box = g_object_new (GTK_TYPE_HBUTTON_BOX, NULL);
 
   return GTK_WIDGET (hbutton_box);
 }
@@ -84,7 +98,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;
 }
@@ -92,7 +107,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);
@@ -102,7 +118,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;
 }
@@ -110,7 +127,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;
 }
@@ -129,22 +147,18 @@ 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);
 
-  spacing = bbox->spacing != GTK_BUTTONBOX_DEFAULT
-         ? bbox->spacing : default_spacing;
+  spacing = box->spacing;
   layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
          ? bbox->layout_style : default_layout_style;
   
-  gtk_button_box_child_requisition (widget,
-                                   &nvis_children,
-                                   &child_width,
-                                   &child_height);
+  _gtk_button_box_child_requisition (widget,
+                                     &nvis_children,
+                                    NULL,
+                                     &child_width,
+                                     &child_height);
 
   if (nvis_children == 0)
   {
@@ -182,15 +196,18 @@ static void
 gtk_hbutton_box_size_allocate (GtkWidget     *widget,
                               GtkAllocation *allocation)
 {
+  GtkBox *base_box;
   GtkButtonBox *box;
   GtkHButtonBox *hbox;
   GtkBoxChild *child;
   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;
@@ -198,58 +215,62 @@ 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);
-  spacing = box->spacing != GTK_BUTTONBOX_DEFAULT
-         ? box->spacing : default_spacing;
+  spacing = base_box->spacing;
   layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
          ? box->layout_style : default_layout_style;
-  gtk_button_box_child_requisition (widget,
-                                   &nvis_children,
-                                   &child_width,
-                                   &child_height);
+  _gtk_button_box_child_requisition (widget,
+                                     &nvis_children,
+                                    &n_secondaries,
+                                     &child_width,
+                                     &child_height);
   widget->allocation = *allocation;
   width = allocation->width - GTK_CONTAINER (box)->border_width*2;
   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;
 
@@ -264,11 +285,26 @@ gtk_hbutton_box_size_allocate (GtkWidget     *widget,
        {
          child_allocation.width = child_width;
          child_allocation.height = child_height;
-         child_allocation.x = x;
          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;
        }
     }
 }
   
+#define __GTK_HBUTTON_BOX_C__
+#include "gtkaliasdef.c"