Re: GtkButton patch for bug #58603



Ok, new version.

I believe this one is correct, but it exposes some sort of size 
allocation/repaint bug when you make a label of a button larger than the 
buttons size request, and then shrink the label. This is easily tested in 
the property test in testgtk. Just enter text in the label of any button, 
and when the button grows, press backspace.

Anyway, here is the patch:

Index: gtk/gtkbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbutton.c,v
retrieving revision 1.66
diff -u -p -r1.66 gtkbutton.c
--- gtk/gtkbutton.c	2001/08/25 23:11:45	1.66
+++ gtk/gtkbutton.c	2001/08/26 23:34:32
@@ -58,7 +58,9 @@ enum {
 enum {
   PROP_0,
   PROP_LABEL,
-  PROP_RELIEF
+  PROP_RELIEF,
+  PROP_USE_UNDERLINE,
+  PROP_USE_STOCK
 };
 
 static void gtk_button_class_init     (GtkButtonClass   *klass);
@@ -91,19 +93,20 @@ static gint gtk_button_enter_notify   (G
 				       GdkEventCrossing *event);
 static gint gtk_button_leave_notify   (GtkWidget        *widget,
 				       GdkEventCrossing *event);
-static void gtk_button_add            (GtkContainer     *container,
-				       GtkWidget        *widget);
-static void gtk_button_remove         (GtkContainer     *container,
-				       GtkWidget        *widget);
 static void gtk_real_button_pressed   (GtkButton        *button);
 static void gtk_real_button_released  (GtkButton        *button);
 static void gtk_real_button_activate (GtkButton         *button);
 static void gtk_button_update_state   (GtkButton        *button);
 static GtkType gtk_button_child_type  (GtkContainer     *container);
-
 static void gtk_button_finish_activate (GtkButton *button,
 					gboolean   do_it);
 
+static GObject*	gtk_button_constructor     (GType                  type,
+					    guint                  n_construct_properties,
+					    GObjectConstructParam *construct_params);
+static void     gtk_button_construct_child (GtkButton             *button);
+
+
 static GtkBinClass *parent_class = NULL;
 static guint button_signals[LAST_SIGNAL] = { 0 };
 
@@ -137,18 +140,21 @@ gtk_button_get_type (void)
 static void
 gtk_button_class_init (GtkButtonClass *klass)
 {
+  GObjectClass *g_object_class;
   GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
 
+  g_object_class = G_OBJECT_CLASS (klass);
   object_class = (GtkObjectClass*) klass;
   widget_class = (GtkWidgetClass*) klass;
   container_class = (GtkContainerClass*) klass;
   
   parent_class = g_type_class_peek_parent (klass);
 
-  G_OBJECT_CLASS(object_class)->set_property = gtk_button_set_property;
-  G_OBJECT_CLASS(object_class)->get_property = gtk_button_get_property;
+  g_object_class->constructor = gtk_button_constructor;
+  g_object_class->set_property = gtk_button_set_property;
+  g_object_class->get_property = gtk_button_get_property;
 
   widget_class->realize = gtk_button_realize;
   widget_class->unrealize = gtk_button_unrealize;
@@ -161,8 +167,6 @@ gtk_button_class_init (GtkButtonClass *k
   widget_class->enter_notify_event = gtk_button_enter_notify;
   widget_class->leave_notify_event = gtk_button_leave_notify;
 
-  container_class->add = gtk_button_add;
-  container_class->remove = gtk_button_remove;
   container_class->child_type = gtk_button_child_type;
 
   klass->pressed = gtk_real_button_pressed;
@@ -178,9 +182,25 @@ gtk_button_class_init (GtkButtonClass *k
                                                         _("Label"),
                                                         _("Text of the label widget inside the button, if the button contains a label widget."),
                                                         NULL,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_object_class_install_property (G_OBJECT_CLASS(object_class),
+                                   PROP_USE_UNDERLINE,
+                                   g_param_spec_boolean ("use_underline",
+							 _("Use underline"),
+							 _("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
+                                                        FALSE,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
   
   g_object_class_install_property (G_OBJECT_CLASS(object_class),
+                                   PROP_USE_STOCK,
+                                   g_param_spec_boolean ("use_stock",
+							 _("Use stock"),
+							 _("If set, the label is used to pick a stock item instead of being displayed"),
+                                                        FALSE,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_object_class_install_property (G_OBJECT_CLASS(object_class),
                                    PROP_RELIEF,
                                    g_param_spec_enum ("relief",
                                                       _("Border relief"),
@@ -270,13 +290,39 @@ gtk_button_init (GtkButton *button)
   GTK_WIDGET_SET_FLAGS (button, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT);
   GTK_WIDGET_UNSET_FLAGS (button, GTK_NO_WINDOW);
 
-  button->child = NULL;
+  button->label_text = NULL;
+  
+  button->constructed = FALSE;
   button->in_button = FALSE;
   button->button_down = FALSE;
   button->relief = GTK_RELIEF_NORMAL;
+  button->use_stock = FALSE;
+  button->use_underline = FALSE;
   button->depressed = FALSE;
 }
 
+static GObject*
+gtk_button_constructor (GType                  type,
+			guint                  n_construct_properties,
+			GObjectConstructParam *construct_params)
+{
+  GObject *object;
+  GtkButton *button;
+
+  object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
+							   n_construct_properties,
+							   construct_params);
+
+  button = GTK_BUTTON (object);
+  button->constructed = TRUE;
+
+  if (button->label_text != NULL)
+    gtk_button_construct_child (button);
+  
+  return object;
+}
+
+
 static GtkType
 gtk_button_child_type  (GtkContainer     *container)
 {
@@ -298,24 +344,18 @@ gtk_button_set_property (GObject        
 
   switch (prop_id)
     {
-      GtkWidget *child;
-
     case PROP_LABEL:
-      child = GTK_BIN (button)->child;
-      if (!child)
-	child = gtk_widget_new (GTK_TYPE_LABEL,
-				"visible", TRUE,
-				"parent", button,
-				NULL);
-      if (GTK_IS_LABEL (child))
-        {
-          gtk_label_set_text (GTK_LABEL (child),
-                              g_value_get_string (value) ? g_value_get_string (value) : "");
-        }
+      gtk_button_set_label (button, g_value_get_string (value));
       break;
     case PROP_RELIEF:
       gtk_button_set_relief (button, g_value_get_enum (value));
       break;
+    case PROP_USE_UNDERLINE:
+      gtk_button_set_use_underline (button, g_value_get_boolean (value));
+      break;
+    case PROP_USE_STOCK:
+      gtk_button_set_use_stock (button, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -335,14 +375,17 @@ gtk_button_get_property (GObject        
   switch (prop_id)
     {
     case PROP_LABEL:
-      if (GTK_BIN (button)->child && GTK_IS_LABEL (GTK_BIN (button)->child))
-	 g_value_set_string (value, GTK_LABEL (GTK_BIN (button)->child)->label); 
-      else
-	 g_value_set_string (value, NULL);
+      g_value_set_string (value, button->label_text);
       break;
     case PROP_RELIEF:
       g_value_set_enum (value, gtk_button_get_relief (button));
       break;
+    case PROP_USE_UNDERLINE:
+      g_value_set_boolean (value, button->use_underline);
+      break;
+    case PROP_USE_STOCK:
+      g_value_set_boolean (value, button->use_stock);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -355,50 +398,33 @@ gtk_button_new (void)
   return GTK_WIDGET (gtk_type_new (gtk_button_get_type ()));
 }
 
-GtkWidget*
-gtk_button_new_with_label (const gchar *label)
+static void
+gtk_button_construct_child (GtkButton *button)
 {
-  GtkWidget *button;
-  GtkWidget *label_widget;
-
-  button = gtk_button_new ();
-  label_widget = gtk_label_new (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.5, 0.5);
-
-  gtk_container_add (GTK_CONTAINER (button), label_widget);
-  gtk_widget_show (label_widget);
+  GtkStockItem item;
+  GtkWidget *label;
+  GtkWidget *image;
+  GtkWidget *hbox;
 
-  return button;
-}
+  if (!button->constructed)
+    return;
+  
+  if (button->label_text == NULL)
+    return;
 
-/**
- * gtk_button_new_from_stock:
- * @stock_id: the name of the stock item 
- * @returns: a new #GtkButton
- *
- * Creates a new #GtkButton containing the image and text from a stock item.
- * Some stock ids have preprocessor macros like #GTK_STOCK_OK and
- * #GTK_STOCK_APPLY.
- **/
-GtkWidget*
-gtk_button_new_from_stock (const gchar   *stock_id)
-{
-  GtkWidget *button;
-  GtkStockItem item;
+  if (GTK_BIN (button)->child)
+    gtk_container_remove (GTK_CONTAINER (button),
+			  GTK_BIN (button)->child);
 
-  if (gtk_stock_lookup (stock_id, &item))
+  
+  if (button->use_stock &&
+      gtk_stock_lookup (button->label_text, &item))
     {
-      GtkWidget *label;
-      GtkWidget *image;
-      GtkWidget *hbox;
-      
-      button = gtk_button_new ();
-
       label = gtk_label_new_with_mnemonic (item.label);
-
-      gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
 
-      image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
+      gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
+      
+      image = gtk_image_new_from_stock (button->label_text, GTK_ICON_SIZE_BUTTON);
       hbox = gtk_hbox_new (FALSE, 1);
 
       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
@@ -406,13 +432,44 @@ gtk_button_new_from_stock (const gchar  
       
       gtk_container_add (GTK_CONTAINER (button), hbox);
       gtk_widget_show_all (hbox);
+
+      return;
     }
-  else
+
+  if (button->use_underline)
     {
-      button = gtk_button_new_with_mnemonic (stock_id);
+      label = gtk_label_new_with_mnemonic (button->label_text);
+      gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
     }
+  else
+    label = gtk_label_new (button->label_text);
   
-  return button;
+  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
+
+  gtk_widget_show (label);
+  gtk_container_add (GTK_CONTAINER (button), label);
+}
+
+
+GtkWidget*
+gtk_button_new_with_label (const gchar *label)
+{
+  return GTK_WIDGET (g_object_new (GTK_TYPE_BUTTON, "label", label, NULL));
+}
+
+/**
+ * gtk_button_new_from_stock:
+ * @stock_id: the name of the stock item 
+ * @returns: a new #GtkButton
+ *
+ * Creates a new #GtkButton containing the image and text from a stock item.
+ * Some stock ids have preprocessor macros like #GTK_STOCK_OK and
+ * #GTK_STOCK_APPLY.
+ **/
+GtkWidget*
+gtk_button_new_from_stock (const gchar   *stock_id)
+{
+  return GTK_WIDGET (g_object_new (GTK_TYPE_BUTTON, "label", stock_id, "use_stock", TRUE,  NULL));
 }
 
 /**
@@ -429,19 +486,7 @@ gtk_button_new_from_stock (const gchar  
 GtkWidget*
 gtk_button_new_with_mnemonic (const gchar *label)
 {
-  GtkWidget *button;
-  GtkWidget *label_widget;
-
-  button = gtk_button_new ();
-  
-  label_widget = gtk_label_new_with_mnemonic (label);
-
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label_widget), button);
-  
-  gtk_container_add (GTK_CONTAINER (button), label_widget);
-  gtk_widget_show (label_widget);
-
-  return button;
+  return GTK_WIDGET (g_object_new (GTK_TYPE_BUTTON, "label", label, "use_underline", TRUE,  NULL));
 }
 
 void
@@ -935,32 +980,6 @@ gtk_button_leave_notify (GtkWidget      
 }
 
 static void
-gtk_button_add (GtkContainer *container,
-		GtkWidget    *widget)
-{
-  g_return_if_fail (container != NULL);
-  g_return_if_fail (widget != NULL);
-
-  if (GTK_CONTAINER_CLASS (parent_class)->add)
-    GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
-
-  GTK_BUTTON (container)->child = GTK_BIN (container)->child;
-}
-
-static void
-gtk_button_remove (GtkContainer *container,
-		   GtkWidget    *widget)
-{
-  g_return_if_fail (container != NULL);
-  g_return_if_fail (widget != NULL);
-
-  if (GTK_CONTAINER_CLASS (parent_class)->remove)
-    GTK_CONTAINER_CLASS (parent_class)->remove (container, widget);
-
-  GTK_BUTTON (container)->child = GTK_BIN (container)->child;
-}
-
-static void
 gtk_real_button_pressed (GtkButton *button)
 {
   if (button->activate_timeout)
@@ -1039,6 +1058,140 @@ gtk_button_finish_activate (GtkButton *b
 
   if (do_it)
     gtk_button_clicked (button);
+}
+
+/**
+ * gtk_button_set_label:
+ * @button: a #GtkButton
+ * @label: a string
+ *
+ * Sets the text of the label of the button to @str. This text is
+ * also used to select the stock item if gtk_button_set_use_stock()
+ * is used.
+ *
+ * This will also clear any previously set labels.
+ **/
+void
+gtk_button_set_label (GtkButton   *button,
+		      const gchar *label)
+{
+  g_return_if_fail (GTK_IS_BUTTON (button));
+  
+  g_free (button->label_text);
+  button->label_text = g_strdup (label);
+  
+  gtk_button_construct_child (button);
+  
+  g_object_notify (G_OBJECT (button), "label");
+}
+
+/**
+ * gtk_button_get_label:
+ * @button: a #GtkButton
+ *
+ * Fetches the text from the label of the button, as set by
+ * gtk_button_set_label().
+ *
+ * Return value: the text of the label widget. This string is
+ *   owned by the widget and must not be modified or freed.
+ *   If the label text has not been set the return value
+ *   will be NULL. This will be the case if you create an
+ *   empty button with gtk_button_new() to use as a container.
+ **/
+G_CONST_RETURN gchar *
+gtk_button_get_label (GtkButton *button)
+{
+  g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
+  
+  return button->label_text;
+}
+
+/**
+ * gtk_button_set_use_underline:
+ * @button: a #GtkButton
+ * @use_underline: %TRUE if underlines in the text indicate mnemonics
+ *
+ * If true, an underline in the text of the button label indicates
+ * the next character should be used for the mnemonic accelerator key.
+ */
+void
+gtk_button_set_use_underline (GtkButton *button,
+			      gboolean   use_underline)
+{
+  g_return_if_fail (GTK_IS_BUTTON (button));
+
+  use_underline = use_underline != FALSE;
+
+  if (use_underline != button->use_underline)
+    {
+      button->use_underline = use_underline;
+  
+      gtk_button_construct_child (button);
+      
+      g_object_notify (G_OBJECT (button), "use_underline");
+    }
+}
+
+/**
+ * gtk_button_get_use_underline:
+ * @label: a #GtkButton
+ *
+ * Returns whether an embedded underline in the button label indicates a
+ * mnemonic. See gtk_button_set_use_underline ().
+ *
+ * Return value: %TRUE if an embedded underline in the button label
+ *               indicates the mnemonic accelerator keys.
+ **/
+gboolean
+gtk_button_get_use_underline (GtkButton *button)
+{
+  g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
+  
+  return button->use_underline;
+}
+
+/**
+ * gtk_button_set_use_stock:
+ * @button: a #GtkButton
+ * @use_stock: %TRUE if the button should use a stock item
+ *
+ * If true, the label set on the button is used as a
+ * stock id to select the stock item for the button.
+ */
+void
+gtk_button_set_use_stock (GtkButton *button,
+			  gboolean   use_stock)
+{
+  g_return_if_fail (GTK_IS_BUTTON (button));
+
+  use_stock = use_stock != FALSE;
+
+  if (use_stock != button->use_stock)
+    {
+      button->use_stock = use_stock;
+  
+      gtk_button_construct_child (button);
+      
+      g_object_notify (G_OBJECT (button), "use_stock");
+    }
+}
+
+/**
+ * gtk_button_get_use_stock:
+ * @button: a #GtkButton
+ *
+ * Returns whether the button label is a stock item.
+ *
+ * Return value: %TRUE if the button label is used to
+ *               select a stock item instead of being
+ *               used directly as the label text.
+ */
+gboolean
+gtk_button_get_use_stock (GtkButton *button)
+{
+  g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
+  
+  return button->use_stock;
 }
 
 /**
Index: gtk/gtkbutton.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbutton.h,v
retrieving revision 1.18
diff -u -p -r1.18 gtkbutton.h
--- gtk/gtkbutton.h	2001/08/25 23:11:45	1.18
+++ gtk/gtkbutton.h	2001/08/26 23:34:32
@@ -52,15 +52,16 @@ struct _GtkButton
 {
   GtkBin bin;
 
-  GtkWidget *child /* deprecapted field,
-		    * use GTK_BIN (button)->child instead
-		    */;
+  gchar *label_text;
 
   guint activate_timeout;
 
+  guint constructed : 1;
   guint in_button : 1;
   guint button_down : 1;
   guint relief : 2;
+  guint use_underline : 1;
+  guint use_stock : 1;
   guint depressed : 1;
 };
 
@@ -90,8 +91,18 @@ void           gtk_button_leave         
 void           gtk_button_set_relief        (GtkButton      *button,
 					     GtkReliefStyle  newstyle);
 GtkReliefStyle gtk_button_get_relief        (GtkButton      *button);
-void          _gtk_button_set_depressed     (GtkButton      *button,
-					     gboolean        depressed);
+
+void                  gtk_button_set_label         (GtkButton   *button,
+						    const gchar *label);
+G_CONST_RETURN gchar *gtk_button_get_label         (GtkButton   *button);
+void                  gtk_button_set_use_underline (GtkButton   *button,
+						    gboolean     value);
+gboolean              gtk_button_get_use_underline (GtkButton   *button);
+void                  gtk_button_set_use_stock     (GtkButton   *button,
+						    gboolean     value);
+gboolean              gtk_button_get_use_stock     (GtkButton   *button);
+void                  _gtk_button_set_depressed    (GtkButton   *button,
+						    gboolean     depressed);
 
 #ifdef __cplusplus
 }
Index: gtk/gtkcheckbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcheckbutton.c,v
retrieving revision 1.32
diff -u -p -r1.32 gtkcheckbutton.c
--- gtk/gtkcheckbutton.c	2001/07/18 23:39:21	1.32
+++ gtk/gtkcheckbutton.c	2001/08/26 23:34:32
@@ -126,17 +126,7 @@ gtk_check_button_new (void)
 GtkWidget*
 gtk_check_button_new_with_label (const gchar *label)
 {
-  GtkWidget *check_button;
-  GtkWidget *label_widget;
-  
-  check_button = gtk_check_button_new ();
-  label_widget = gtk_label_new (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
-  
-  gtk_container_add (GTK_CONTAINER (check_button), label_widget);
-  gtk_widget_show (label_widget);
-  
-  return check_button;
+  return GTK_WIDGET (g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, NULL));
 }
 
 /**
@@ -152,17 +142,7 @@ gtk_check_button_new_with_label (const g
 GtkWidget*
 gtk_check_button_new_with_mnemonic (const gchar *label)
 {
-  GtkWidget *check_button;
-  GtkWidget *label_widget;
-  
-  check_button = gtk_check_button_new ();
-  label_widget = gtk_label_new_with_mnemonic (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
-  
-  gtk_container_add (GTK_CONTAINER (check_button), label_widget);
-  gtk_widget_show (label_widget);
-  
-  return check_button;
+  return GTK_WIDGET (g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, "use_underline", TRUE, NULL));
 }
 
 
@@ -306,10 +286,11 @@ gtk_check_button_size_allocate (GtkWidge
 	  child_allocation.x = (border_width + indicator_size + indicator_spacing * 3 + 1 +
 				widget->allocation.x);
 	  child_allocation.y = border_width + 1 + widget->allocation.y;
-	  child_allocation.width = MAX (1, allocation->width - 
-					(border_width + indicator_size + indicator_spacing * 3 + 1) -
-					border_width - 1);
-	  child_allocation.height = MAX (1, allocation->height - (border_width + 1) * 2);
+	  child_allocation.width = MIN (GTK_BIN (button)->child->requisition.width,
+					allocation->width -
+					((border_width + 1) * 2 + indicator_size + indicator_spacing * 3));
+	  child_allocation.height = MIN (GTK_BIN (button)->child->requisition.height,
+					 allocation->height - (border_width + 1) * 2);
 	  
 	  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
 	    child_allocation.x = allocation->x + allocation->width
Index: gtk/gtkclist.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkclist.c,v
retrieving revision 1.201
diff -u -p -r1.201 gtkclist.c
--- gtk/gtkclist.c	2001/08/11 20:27:35	1.201
+++ gtk/gtkclist.c	2001/08/26 23:34:34
@@ -1572,7 +1572,7 @@ gtk_clist_get_column_widget (GtkCList *c
     return NULL;
 
   if (clist->column[column].button)
-    return GTK_BUTTON (clist->column[column].button)->child;
+    return GTK_BIN (clist->column[column].button)->child;
 
   return NULL;
 }
Index: gtk/gtklabel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtklabel.c,v
retrieving revision 1.97
diff -u -p -r1.97 gtklabel.c
--- gtk/gtklabel.c	2001/07/18 23:39:22	1.97
+++ gtk/gtklabel.c	2001/08/26 23:34:34
@@ -2309,7 +2309,7 @@ gtk_label_set_use_underline (GtkLabel *l
  * gtk_label_get_use_underline:
  * @label: a #GtkLabel
  *
- * Returns whether an embedded underline in thef label indicates a
+ * Returns whether an embedded underline in the label indicates a
  * mnemonic. See gtk_label_set_use_underline ().
  *
  * Return value: %TRUE whether an embedded underline in the label indicates
Index: gtk/gtkradiobutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkradiobutton.c,v
retrieving revision 1.28
diff -u -p -r1.28 gtkradiobutton.c
--- gtk/gtkradiobutton.c	2001/07/18 23:39:23	1.28
+++ gtk/gtkradiobutton.c	2001/08/26 23:34:35
@@ -216,14 +216,11 @@ gtk_radio_button_new_with_label (GSList 
 				 const gchar *label)
 {
   GtkWidget *radio_button;
-  GtkWidget *label_widget;
 
-  radio_button = gtk_radio_button_new (group);
-  label_widget = gtk_label_new (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
+  radio_button = GTK_WIDGET (g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, NULL));
 
-  gtk_container_add (GTK_CONTAINER (radio_button), label_widget);
-  gtk_widget_show (label_widget);
+  if (group)
+    gtk_radio_button_set_group (radio_button, group);
 
   return radio_button;
 }
@@ -245,14 +242,11 @@ gtk_radio_button_new_with_mnemonic (GSLi
 				    const gchar *label)
 {
   GtkWidget *radio_button;
-  GtkWidget *label_widget;
 
-  radio_button = gtk_radio_button_new (group);
-  label_widget = gtk_label_new_with_mnemonic (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
+  radio_button = GTK_WIDGET (g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, "use_underline", TRUE, NULL));
 
-  gtk_container_add (GTK_CONTAINER (radio_button), label_widget);
-  gtk_widget_show (label_widget);
+  if (group)
+    gtk_radio_button_set_group (radio_button, group);
 
   return radio_button;
 }
Index: gtk/gtktogglebutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktogglebutton.c,v
retrieving revision 1.40
diff -u -p -r1.40 gtktogglebutton.c
--- gtk/gtktogglebutton.c	2001/08/25 23:11:45	1.40
+++ gtk/gtktogglebutton.c	2001/08/26 23:34:35
@@ -187,17 +187,7 @@ gtk_toggle_button_new (void)
 GtkWidget*
 gtk_toggle_button_new_with_label (const gchar *label)
 {
-  GtkWidget *toggle_button;
-  GtkWidget *label_widget;
-
-  toggle_button = gtk_toggle_button_new ();
-  label_widget = gtk_label_new (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.5, 0.5);
-
-  gtk_container_add (GTK_CONTAINER (toggle_button), label_widget);
-  gtk_widget_show (label_widget);
-
-  return toggle_button;
+  return GTK_WIDGET (g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL));
 }
 
 /**
@@ -213,17 +203,7 @@ gtk_toggle_button_new_with_label (const 
 GtkWidget*
 gtk_toggle_button_new_with_mnemonic (const gchar *label)
 {
-  GtkWidget *toggle_button;
-  GtkWidget *label_widget;
-
-  toggle_button = gtk_toggle_button_new ();
-  label_widget = gtk_label_new_with_mnemonic (label);
-  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.5, 0.5);
-
-  gtk_container_add (GTK_CONTAINER (toggle_button), label_widget);
-  gtk_widget_show (label_widget);
-
-  return toggle_button;
+  return GTK_WIDGET (g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, "use_underline", TRUE, NULL));
 }
 
 static void





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]