diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2014-04-07 12:30:06 +0000 |
---|---|---|
committer | CI bot <ps-jenkins@lists.canonical.com> | 2014-04-07 12:30:06 +0000 |
commit | c3fc9b1c57f26596b9928fa1053c09760dfd9d67 (patch) | |
tree | 1b0fe6620480de4244b490a0d95629683ea71da5 | |
parent | 1c842fe4ec9788ddf04e41fb634792bec7aebe92 (diff) | |
parent | 220d43caa077b337476a1557c774cc35a75fff6e (diff) | |
download | ayatana-ido-c3fc9b1c57f26596b9928fa1053c09760dfd9d67.tar.gz ayatana-ido-c3fc9b1c57f26596b9928fa1053c09760dfd9d67.tar.bz2 ayatana-ido-c3fc9b1c57f26596b9928fa1053c09760dfd9d67.zip |
idobasicmenuitem: update icon when the theme changes
-rw-r--r-- | src/idobasicmenuitem.c | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index 6185d23..382a150 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -136,6 +136,50 @@ my_finalize (GObject * object) G_OBJECT_CLASS (ido_basic_menu_item_parent_class)->finalize (object); } +static void +ido_basic_menu_item_update_image (IdoBasicMenuItem *self) +{ + IdoBasicMenuItemPrivate * p = self->priv; + + gtk_image_clear (GTK_IMAGE (p->image)); + + if (p->icon == NULL) + { + gtk_widget_set_visible (p->image, FALSE); + } + else + { + GtkIconInfo *info; + const gchar *filename; + + info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); + filename = gtk_icon_info_get_filename (info); + + if (filename) + { + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (p->image), pixbuf); + + g_object_unref (pixbuf); + } + + gtk_widget_set_visible (p->image, filename != NULL); + + g_object_unref (info); + } +} + +static void +ido_basic_menu_item_style_updated (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (ido_basic_menu_item_parent_class)->style_updated (widget); + + ido_basic_menu_item_update_image (IDO_BASIC_MENU_ITEM (widget)); + gtk_widget_queue_draw (widget); +} + /*** **** Instantiation ***/ @@ -145,6 +189,7 @@ ido_basic_menu_item_class_init (IdoBasicMenuItemClass *klass) { GParamFlags prop_flags; GObjectClass * gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); g_type_class_add_private (klass, sizeof (IdoBasicMenuItemPrivate)); @@ -153,6 +198,8 @@ ido_basic_menu_item_class_init (IdoBasicMenuItemClass *klass) gobject_class->dispose = my_dispose; gobject_class->finalize = my_finalize; + widget_class->style_updated = ido_basic_menu_item_style_updated; + prop_flags = G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS; @@ -244,37 +291,11 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) if (p->icon != icon) { - g_clear_object (&p->icon); - gtk_image_clear (GTK_IMAGE(p->image)); - - if (icon == NULL) - { - gtk_widget_set_visible (p->image, FALSE); - } - else - { - GtkIconInfo *info; - const gchar *filename; - - p->icon = g_object_ref (icon); - - info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); - filename = gtk_icon_info_get_filename (info); - - if (filename) - { - GdkPixbuf *pixbuf; + if (p->icon) + g_object_unref (p->icon); - pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); - gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf); - - g_object_unref (pixbuf); - } - - gtk_widget_set_visible (p->image, filename != NULL); - - g_object_unref (info); - } + p->icon = icon ? g_object_ref (icon) : NULL; + ido_basic_menu_item_update_image (self); } } |