summaryrefslogtreecommitdiff
path: root/gtk/gtkbutton.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-03-06 03:47:06 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-03-06 03:47:06 +0000
commit459eeebde91a906c8a6ca63af416c41c69b2695c (patch)
tree22e83258c8d94a672817c73d46b41621c5c59475 /gtk/gtkbutton.c
parent33f840d24430afed668b864cf7ed91ba2b5b6c67 (diff)
downloadgtk+-459eeebde91a906c8a6ca63af416c41c69b2695c.tar.gz
Fix handling of image-only buttons. (#332985, Kalle Vahlmann, #333555)
2006-03-05 Matthias Clasen <mclasen@redhat.com> Fix handling of image-only buttons. (#332985, Kalle Vahlmann, #333555) * gtk/gtkbutton.c (gtk_button_construct_child): Don't return early if there an image to show. (show_image): Always return TRUE if there is no text.
Diffstat (limited to 'gtk/gtkbutton.c')
-rw-r--r--gtk/gtkbutton.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 93f433dfa7..0d70bfa893 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -677,10 +677,17 @@ gtk_button_new (void)
static gboolean
show_image (GtkButton *button)
{
- GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (button));
gboolean show;
+
+ if (button->label_text)
+ {
+ GtkSettings *settings;
- g_object_get (settings, "gtk-button-images", &show, NULL);
+ settings = gtk_widget_get_settings (GTK_WIDGET (button));
+ g_object_get (settings, "gtk-button-images", &show, NULL);
+ }
+ else
+ show = TRUE;
return show;
}
@@ -698,26 +705,25 @@ gtk_button_construct_child (GtkButton *button)
if (!button->constructed)
return;
-
- if (button->label_text == NULL)
+
+ if (!button->label_text && !priv->image)
return;
-
- if (GTK_BIN (button)->child)
- {
- if (priv->image && !priv->image_is_stock)
- {
- image = g_object_ref (priv->image);
- if (image->parent)
- gtk_container_remove (GTK_CONTAINER (image->parent), image);
- }
-
- gtk_container_remove (GTK_CONTAINER (button),
- GTK_BIN (button)->child);
+ if (priv->image && !priv->image_is_stock)
+ {
+ image = g_object_ref (priv->image);
+ if (image->parent)
+ gtk_container_remove (GTK_CONTAINER (image->parent), image);
+
priv->image = NULL;
}
+ if (GTK_BIN (button)->child)
+ gtk_container_remove (GTK_CONTAINER (button),
+ GTK_BIN (button)->child);
+
if (button->use_stock &&
+ button->label_text &&
gtk_stock_lookup (button->label_text, &item))
{
if (!image)
@@ -730,9 +736,6 @@ gtk_button_construct_child (GtkButton *button)
if (image)
{
- label = gtk_label_new_with_mnemonic (label_text);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
-
priv->image = image;
g_object_set (priv->image,
@@ -747,7 +750,15 @@ gtk_button_construct_child (GtkButton *button)
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), priv->image, FALSE, FALSE, 0);
- gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ if (label_text)
+ {
+ label = gtk_label_new_with_mnemonic (label_text);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label),
+ GTK_WIDGET (button));
+
+ gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ }
gtk_container_add (GTK_CONTAINER (button), align);
gtk_container_add (GTK_CONTAINER (align), hbox);
@@ -758,7 +769,7 @@ gtk_button_construct_child (GtkButton *button)
return;
}
- if (button->use_underline)
+ if (button->use_underline)
{
label = gtk_label_new_with_mnemonic (button->label_text);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
@@ -768,7 +779,7 @@ gtk_button_construct_child (GtkButton *button)
if (priv->align_set)
gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
-
+
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (button), label);
}