diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2008-08-02 05:07:02 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2008-08-02 05:07:02 +0000 |
commit | d2fc1c7ee02220d9db120e0f73cdf99225ba27eb (patch) | |
tree | 0651c753245027d81d0d9232c0d7623780474cf6 /gtk/gtkstatusicon.c | |
parent | 5b980c221ada88bf26f7d1d2fa5af01e79c9976a (diff) | |
download | gtk+-d2fc1c7ee02220d9db120e0f73cdf99225ba27eb.tar.gz |
Add GIcon support to GtkStatusIcon
svn path=/trunk/; revision=20940
Diffstat (limited to 'gtk/gtkstatusicon.c')
-rw-r--r-- | gtk/gtkstatusicon.c | 170 |
1 files changed, 167 insertions, 3 deletions
diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c index 52b8d85662..61ebcb09e8 100644 --- a/gtk/gtkstatusicon.c +++ b/gtk/gtkstatusicon.c @@ -71,6 +71,7 @@ enum PROP_FILE, PROP_STOCK, PROP_ICON_NAME, + PROP_GICON, PROP_STORAGE_TYPE, PROP_SIZE, PROP_SCREEN, @@ -125,6 +126,7 @@ struct _GtkStatusIconPrivate GdkPixbuf *pixbuf; gchar *stock_id; gchar *icon_name; + GIcon *gicon; } image_data; GdkPixbuf *blank_icon; @@ -209,7 +211,23 @@ gtk_status_icon_class_init (GtkStatusIconClass *class) P_("The name of the icon from the icon theme"), NULL, GTK_PARAM_READWRITE)); - + + /** + * GtkStatusIcon:gicon: + * + * The #GIcon displayed in the #GtkStatusIcon. For themed icons, + * the image will be updated automatically if the theme changes. + * + * Since: 2.14 + */ + g_object_class_install_property (gobject_class, + PROP_GICON, + g_param_spec_object ("gicon", + P_("GIcon"), + P_("The GIcon being displayed"), + G_TYPE_ICON, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_STORAGE_TYPE, g_param_spec_enum ("storage-type", @@ -698,6 +716,9 @@ gtk_status_icon_set_property (GObject *object, case PROP_ICON_NAME: gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value)); break; + case PROP_GICON: + gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value)); + break; case PROP_SCREEN: gtk_status_icon_set_screen (status_icon, g_value_get_object (value)); break; @@ -748,6 +769,17 @@ gtk_status_icon_get_property (GObject *object, else g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon)); break; + case PROP_GICON: + if (priv->storage_type != GTK_IMAGE_GICON) + g_value_set_object (value, NULL); + else + { + GIcon *icon; + + gtk_status_icon_get_gicon (status_icon, &icon); + g_value_set_object (value, icon); + } + break; case PROP_STORAGE_TYPE: g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon)); break; @@ -878,6 +910,25 @@ gtk_status_icon_new_from_icon_name (const gchar *icon_name) NULL); } +/** + * gtk_status_icon_new_from_gicon: + * @icon: a #GIcon + * + * Creates a status icon displaying a #GIcon. If the icon is a + * themed icon, it will be updated when the theme changes. + * + * Return value: a new #GtkStatusIcon + * + * Since: 2.14 + **/ +GtkStatusIcon * +gtk_status_icon_new_from_gicon (GIcon *icon) +{ + return g_object_new (GTK_TYPE_STATUS_ICON, + "gicon", icon, + NULL); +} + static void emit_activate_signal (GtkStatusIcon *status_icon) { @@ -1173,7 +1224,54 @@ gtk_status_icon_update_image (GtkStatusIcon *status_icon) } break; - + + case GTK_IMAGE_GICON: + { +#ifdef GDK_WINDOWING_X11 + GtkIconSize size = find_icon_size (priv->image, priv->size); + gtk_image_set_from_gicon (GTK_IMAGE (priv->image), + priv->image_data.gicon, + size); +#endif +#ifdef GDK_WINDOWING_WIN32 + { + GtkIconInfo *info = + gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), + priv->image_data.gicon, + priv->size, + 0); + GdkPixbuf *pixbuf = gtk_icon_icon_info_load_icon (info, NULL); + + prev_hicon = priv->nid.hIcon; + priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf); + priv->nid.uFlags |= NIF_ICON; + if (priv->nid.hWnd != NULL && priv->visible) + if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid)) + g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1); + if (prev_hicon) + DestroyIcon (prev_hicon); + g_object_unref (pixbuf); + } +#endif +#ifdef GDK_WINDOWING_QUARTZ + { + GtkIconInfo *info = + gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), + priv->image_data.gicon, + priv->size, + 0); + GdkPixbuf *pixbuf = gtk_icon_icon_info_load_icon (info, NULL); + + QUARTZ_POOL_ALLOC; + [priv->status_item setImage:pixbuf]; + QUARTZ_POOL_RELEASE; + g_object_unref (pixbuf); + } +#endif + + } + break; + case GTK_IMAGE_EMPTY: #ifdef GDK_WINDOWING_X11 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL); @@ -1332,7 +1430,14 @@ gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon) g_object_notify (G_OBJECT (status_icon), "icon-name"); break; - + + case GTK_IMAGE_GICON: + g_free (priv->image_data.gicon); + priv->image_data.gicon = NULL; + + g_object_notify (G_OBJECT (status_icon), "gicon"); + break; + case GTK_IMAGE_EMPTY: break; default: @@ -1372,6 +1477,10 @@ gtk_status_icon_set_image (GtkStatusIcon *status_icon, priv->image_data.icon_name = g_strdup ((const gchar *)data); g_object_notify (G_OBJECT (status_icon), "icon-name"); break; + case GTK_IMAGE_GICON: + priv->image_data.gicon = (GIcon *)data; + g_object_notify (G_OBJECT (status_icon), "gicon"); + break; default: g_warning ("Image type %u not handled by GtkStatusIcon", storage_type); } @@ -1476,6 +1585,27 @@ gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon, } /** + * gtk_status_icon_set_from_gicon: + * @status_icon: a #GtkStatusIcon + * @icon: a GIcon + * + * Makes @status_icon display the #GIcon. + * See gtk_status_icon_new_from_gicon() for details. + * + * Since: 2.14 + **/ +void +gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon, + GIcon *icon) +{ + g_return_if_fail (GTK_IS_STATUS_ICON (status_icon)); + g_return_if_fail (icon != NULL); + + gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON, + (gpointer) icon); +} + +/** * gtk_status_icon_get_storage_type: * @status_icon: a #GtkStatusIcon * @@ -1592,6 +1722,40 @@ gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon) } /** + * gtk_status_icon_get_gicon: + * @status_icon: a #GtkStatusIcon + * @icon: a place to store a #GIcon + * + * Retrieves the #GIcon being displayed by the #GtkStatusIcon. + * The storage type of the status icon must be %GTK_IMAGE_EMPTY or + * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()). + * The caller of this function does not own a reference to the + * returned #GIcon. + * + * If this function fails, @icon is left unchanged; + * + * Since: 2.14 + **/ +void +gtk_status_icon_get_gicon (GtkStatusIcon *status_icon, + GIcon **icon) +{ + GtkStatusIconPrivate *priv; + + g_return_if_fail (GTK_IS_STATUS_ICON (status_icon)); + + priv = status_icon->priv; + + g_return_if_fail (priv->storage_type == GTK_IMAGE_GICON || + priv->storage_type == GTK_IMAGE_EMPTY); + + if (priv->storage_type == GTK_IMAGE_EMPTY) + priv->image_data.gicon = NULL; + + *icon = priv->image_data.gicon; +} + +/** * gtk_status_icon_get_size: * @status_icon: a #GtkStatusIcon * |