aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-03-24 11:47:12 +0100
committerRobert Tari <robert@tari.in>2021-04-21 22:31:36 +0200
commit386eaabc3b2132bfba68551d61e2d9a0316526b1 (patch)
tree1e4164ce664e8acbf62dbff2df8f25cc434e959a
parentaa242a51551120c5f6a5f4483e4f96728afcb8ea (diff)
downloadayatana-ido-386eaabc3b2132bfba68551d61e2d9a0316526b1.tar.gz
ayatana-ido-386eaabc3b2132bfba68551d61e2d9a0316526b1.tar.bz2
ayatana-ido-386eaabc3b2132bfba68551d61e2d9a0316526b1.zip
src/basicmenuitem.c: Add GdkPixbuf source support for the icon
-rw-r--r--src/idobasicmenuitem.c69
1 files changed, 55 insertions, 14 deletions
diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c
index 080151c..109ea2e 100644
--- a/src/idobasicmenuitem.c
+++ b/src/idobasicmenuitem.c
@@ -26,6 +26,7 @@ enum
{
PROP_0,
PROP_ICON,
+ PROP_PIXBUF,
PROP_TEXT,
PROP_SECONDARY_TEXT,
PROP_LAST
@@ -35,6 +36,7 @@ static GParamSpec *properties[PROP_LAST];
typedef struct {
GIcon * icon;
+ GdkPixbuf *pPixbuf;
char * text;
char * secondary_text;
@@ -64,6 +66,10 @@ my_get_property (GObject * o,
g_value_set_object (value, p->icon);
break;
+ case PROP_PIXBUF:
+ g_value_set_object(value, p->pPixbuf);
+ break;
+
case PROP_TEXT:
g_value_set_string (value, p->text);
break;
@@ -92,6 +98,10 @@ my_set_property (GObject * o,
ido_basic_menu_item_set_icon (self, g_value_get_object (value));
break;
+ case PROP_PIXBUF:
+ ido_basic_menu_item_set_pixbuf(self, g_value_get_object(value));
+ break;
+
case PROP_TEXT:
ido_basic_menu_item_set_text (self, g_value_get_string (value));
break;
@@ -113,6 +123,7 @@ my_dispose (GObject * object)
IdoBasicMenuItemPrivate *p = ido_basic_menu_item_get_instance_private(self);
g_clear_object (&p->icon);
+ g_clear_object (&p->pPixbuf);
G_OBJECT_CLASS (ido_basic_menu_item_parent_class)->dispose (object);
}
@@ -136,31 +147,39 @@ ido_basic_menu_item_update_image (IdoBasicMenuItem *self)
gtk_image_clear (GTK_IMAGE (p->image));
- if (p->icon == NULL)
+ if (p->icon == NULL && p->pPixbuf == NULL)
{
gtk_widget_set_visible (p->image, FALSE);
}
else
{
- GtkIconInfo *info;
- const gchar *filename;
+ if (p->pPixbuf)
+ {
+ gtk_image_set_from_pixbuf(GTK_IMAGE(p->image), p->pPixbuf);
+ gtk_widget_set_visible(p->image, TRUE);
+ }
+ else if (p->icon)
+ {
+ 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);
+ 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 (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);
+ 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);
- }
+ g_object_unref (pixbuf);
+ }
- gtk_widget_set_visible (p->image, filename != NULL);
+ gtk_widget_set_visible (p->image, filename != NULL);
- g_object_unref (info);
+ g_object_unref (info);
+ }
}
}
@@ -201,6 +220,12 @@ ido_basic_menu_item_class_init (IdoBasicMenuItemClass *klass)
G_TYPE_OBJECT,
prop_flags);
+ properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf",
+ "Pixbuf",
+ "The menuitem's GdkPixbuf",
+ G_TYPE_OBJECT,
+ prop_flags);
+
properties[PROP_TEXT] = g_param_spec_string ("text",
"Text",
"The menuitem's text",
@@ -289,6 +314,22 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon)
}
}
+void ido_basic_menu_item_set_pixbuf(IdoBasicMenuItem *self, GdkPixbuf *pPixbuf)
+{
+ IdoBasicMenuItemPrivate *pPrivate = ido_basic_menu_item_get_instance_private(self);
+
+ if (pPrivate->pPixbuf != pPixbuf)
+ {
+ if (pPrivate->pPixbuf)
+ {
+ g_object_unref(pPrivate->pPixbuf);
+ }
+
+ pPrivate->pPixbuf = pPixbuf ? g_object_ref(pPixbuf) : NULL;
+ ido_basic_menu_item_update_image(self);
+ }
+}
+
void
ido_basic_menu_item_set_icon_from_file (IdoBasicMenuItem * self, const char * filename)
{