aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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)
{