2008-10-15 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Wed, 15 Oct 2008 17:00:53 +0000 (17:00 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Wed, 15 Oct 2008 17:00:53 +0000 (17:00 +0000)
* src/hildon-button.c
(hildon_button_construct_child):
Don't pack anything in the button until text or image are
set. This allows adding a custom child after creating the button
with hildon_button_new().
(hildon_button_finalize, hildon_button_class_init)
(hildon_button_init, hildon_button_set_arrangement): Destroy the
alignment and the label box even when they're not packed in the
button.

ChangeLog
src/hildon-button.c

index eccc9ea..f96c83f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-10-15  Alberto Garcia  <agarcia@igalia.com>
+
+       * src/hildon-button.c
+       (hildon_button_construct_child):
+       Don't pack anything in the button until text or image are
+       set. This allows adding a custom child after creating the button
+       with hildon_button_new().
+       (hildon_button_finalize, hildon_button_class_init)
+       (hildon_button_init, hildon_button_set_arrangement): Destroy the
+       alignment and the label box even when they're not packed in the
+       button.
+
 2008-10-14  Alejandro Pinheiro  <apinheiro@igalia.com>
 
        * src/hildon-touch-selector.h:
index 77e420b..1f2379b 100644 (file)
@@ -190,6 +190,17 @@ hildon_button_style_set                         (GtkWidget *widget,
 }
 
 static void
+hildon_button_finalize                          (GObject *object)
+{
+    HildonButtonPrivate *priv = HILDON_BUTTON (object)->priv;
+
+    g_object_unref (priv->alignment);
+    g_object_unref (priv->label_box);
+
+    G_OBJECT_CLASS (hildon_button_parent_class)->finalize (object);
+}
+
+static void
 hildon_button_class_init                        (HildonButtonClass *klass)
 {
     GObjectClass *gobject_class = (GObjectClass *)klass;
@@ -197,6 +208,7 @@ hildon_button_class_init                        (HildonButtonClass *klass)
 
     gobject_class->set_property = hildon_button_set_property;
     gobject_class->get_property = hildon_button_get_property;
+    gobject_class->finalize = hildon_button_finalize;
     widget_class->style_set = hildon_button_style_set;
 
     g_object_class_install_property (
@@ -285,6 +297,8 @@ hildon_button_init                              (HildonButton *self)
     gtk_misc_set_alignment (GTK_MISC (priv->title), 0, 0.5);
     gtk_misc_set_alignment (GTK_MISC (priv->value), 0, 0.5);
 
+    g_object_ref_sink (priv->alignment);
+
     /* The labels are not shown automatically, see hildon_button_set_(title|value) */
     gtk_widget_set_no_show_all (GTK_WIDGET (priv->title), TRUE);
     gtk_widget_set_no_show_all (GTK_WIDGET (priv->value), TRUE);
@@ -435,6 +449,8 @@ hildon_button_set_arrangement                   (HildonButton            *button
         priv->label_box = gtk_hbox_new (FALSE, 0);
     }
 
+    g_object_ref_sink (priv->label_box);
+
     /* If we pack both labels with (TRUE, TRUE) or (FALSE, FALSE) they
      * can be painted outside of the button in some situations, see
      * NB#88126 */
@@ -748,9 +764,16 @@ hildon_button_construct_child                   (HildonButton *button)
     HildonButtonPrivate *priv = button->priv;
     GtkWidget *child;
     gint image_spacing;
+    const gchar *title, *value;
 
     /* Don't do anything if the button is not constructed yet */
-    if (priv->label_box == NULL)
+    if (G_UNLIKELY (priv->label_box == NULL))
+        return;
+
+    /* Don't do anything if the button has no contents */
+    title = gtk_label_get_text (priv->title);
+    value = gtk_label_get_text (priv->value);
+    if (!priv->image && !title[0] && !value[0])
         return;
 
     /* Save a ref to the image if necessary */