]> Pileus Git - ~andy/gtk/commitdiff
Add properties for labels, mnemonics and stock items. Added C accessor
authorAlexander Larsson <alla@lysator.liu.se>
Mon, 27 Aug 2001 01:05:07 +0000 (01:05 +0000)
committerAlexander Larsson <alexl@src.gnome.org>
Mon, 27 Aug 2001 01:05:07 +0000 (01:05 +0000)
2001-08-26  Alexander Larsson  <alla@lysator.liu.se>

* gtk/gtkbutton.[ch]:
Add properties for labels, mnemonics and stock items.
Added C accessor functions for the properties.
Removed deprecated button->child.

* gtk/gtkradiobutton.c:
* gtk/gtktogglebutton.c:
Update to use the functions in GtkButton.

* gtk/gtkcheckbutton.c:
Update to use the functions in GtkButton.
Changed size allocation of child. Now only gets as much
space as it requests.

* gtk/gtkclist.c:
Don't use GtkButton->child

* gtk/gtklabel.c:
Fixed typo in docs

14 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkbutton.c
gtk/gtkbutton.h
gtk/gtkcheckbutton.c
gtk/gtkclist.c
gtk/gtklabel.c
gtk/gtkradiobutton.c
gtk/gtktogglebutton.c

index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 3ed3632b0c62f1a8a2273b943fb68c9be85d5823..b7d167201152110d209b18d0bee9fdb7def5cadf 100644 (file)
@@ -1,3 +1,25 @@
+2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
+
+       * gtk/gtkbutton.[ch]:
+       Add properties for labels, mnemonics and stock items.
+       Added C accessor functions for the properties.
+       Removed deprecated button->child.
+
+       * gtk/gtkradiobutton.c:
+       * gtk/gtktogglebutton.c:
+       Update to use the functions in GtkButton.
+
+       * gtk/gtkcheckbutton.c:
+       Update to use the functions in GtkButton.
+       Changed size allocation of child. Now only gets as much
+       space as it requests.
+
+       * gtk/gtkclist.c:
+       Don't use GtkButton->child
+
+       * gtk/gtklabel.c:
+       Fixed typo in docs
+       
 2001-08-26  Alexander Larsson  <alla@lysator.liu.se>
 
        * tests/testgtk.c:
index 4ac476bb602031d44cf83357f401dd54a13d2487..a671ee640616e8c4d3afee035c4ea95c0279eb33 100644 (file)
@@ -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   (GtkWidget        *widget,
                                       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 *klass)
   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,7 +182,23 @@ gtk_button_class_init (GtkButtonClass *klass)
                                                         _("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,
@@ -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         *object,
 
   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         *object,
   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   *stock_id)
       
       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 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 g_object_new (GTK_TYPE_BUTTON, "label", stock_id, "use_stock", TRUE,  NULL);
 }
 
 /**
@@ -429,19 +486,7 @@ gtk_button_new_from_stock (const gchar   *stock_id)
 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 g_object_new (GTK_TYPE_BUTTON, "label", label, "use_underline", TRUE,  NULL);
 }
 
 void
@@ -934,32 +979,6 @@ gtk_button_leave_notify (GtkWidget        *widget,
   return FALSE;
 }
 
-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)
 {
@@ -1041,6 +1060,140 @@ gtk_button_finish_activate (GtkButton *button,
     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;
+}
+
 /**
  * _gtk_button_set_depressed:
  * @button: a #GtkButton
index 1a5cbaf3d902c8fa7152fe240368f22594026e15..b27df541a82f643f331dcc9cf9313a98b377003f 100644 (file)
@@ -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             (GtkButton      *button);
 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 67f3e4a15f35f59b7f639fd8aa79994fde6dc54c..b9671e0d69d0c7e413468ad5e10ab121da38ebe4 100644 (file)
@@ -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 g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, NULL);
 }
 
 /**
@@ -152,17 +142,7 @@ gtk_check_button_new_with_label (const gchar *label)
 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 g_object_new (GTK_TYPE_CHECK_BUTTON, "label", label, "use_underline", TRUE, NULL);
 }
 
 
@@ -306,10 +286,11 @@ gtk_check_button_size_allocate (GtkWidget     *widget,
          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 822430d67de2ca07702c8cc625aa8a4d41720d5d..1e51268acd051d1310be5e16a338adcb73d0b0ac 100644 (file)
@@ -1572,7 +1572,7 @@ gtk_clist_get_column_widget (GtkCList *clist,
     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 a47a19978a0a656d96e0bae98dbf15628a2f140c..0f8eb5053c5a214203ca1a7b45376858a41c1e0a 100644 (file)
@@ -2309,7 +2309,7 @@ gtk_label_set_use_underline (GtkLabel *label,
  * 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 e41f04233f48ec0125fc064e0c5758d6c0a726b8..070c1adeb54fcc6f082310110e0610ad4df2ae35 100644 (file)
@@ -216,14 +216,11 @@ gtk_radio_button_new_with_label (GSList      *group,
                                 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 = 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 (GSList      *group,
                                    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 = 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 af600886758497b1c5a48d08b1e9198074b1b50c..5d32d97306112b4afdaeecfc1704e50c504f694c 100644 (file)
@@ -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 g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
 }
 
 /**
@@ -213,17 +203,7 @@ gtk_toggle_button_new_with_label (const gchar *label)
 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 g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, "use_underline", TRUE, NULL);
 }
 
 static void