Commit b63431c8 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add a new type GTK_IMAGE_ICON_NAME for named icons, update the size and

2004-10-25  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkimage.h:
	* gtk/gtkimage.c (gtk_image_new_from_icon_name)
	(gtk_image_set_from_icon_name, gtk_image_get_icon_name)
	(gtk_image_set_pixel_size, gtk_image_get_pixel_size):  Add a
	new type GTK_IMAGE_ICON_NAME for named icons, update the size
	and content of stock, icon set and named icon images upon style
	changes, and allow to set a fixed pixel size for named icon
	images.  (#155688, James Henstridge)

	* tests/testimage.c: Test application for theming behaviour of
	different image types and for image dnd.
parent 2b4ef064
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:
* gtk/gtkimage.c (gtk_image_new_from_icon_name)
(gtk_image_set_from_icon_name, gtk_image_get_icon_name)
(gtk_image_set_pixel_size, gtk_image_get_pixel_size): Add a
new type GTK_IMAGE_ICON_NAME for named icons, update the size
and content of stock, icon set and named icon images upon style
changes, and allow to set a fixed pixel size for named icon
images. (#155688, James Henstridge)
* tests/testimage.c: Test application for theming behaviour of
different image types and for image dnd.
2004-10-24 Matthias Clasen <mclasen@redhat.com> 2004-10-24 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, intialize the * gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, initialize the
has_entry property, ref the model and add a finalizer. (#156325, has_entry property, ref the model and add a finalizer. (#156325,
Olivier Andrieu) Olivier Andrieu)
......
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:
* gtk/gtkimage.c (gtk_image_new_from_icon_name)
(gtk_image_set_from_icon_name, gtk_image_get_icon_name)
(gtk_image_set_pixel_size, gtk_image_get_pixel_size): Add a
new type GTK_IMAGE_ICON_NAME for named icons, update the size
and content of stock, icon set and named icon images upon style
changes, and allow to set a fixed pixel size for named icon
images. (#155688, James Henstridge)
* tests/testimage.c: Test application for theming behaviour of
different image types and for image dnd.
2004-10-24 Matthias Clasen <mclasen@redhat.com> 2004-10-24 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, intialize the * gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, initialize the
has_entry property, ref the model and add a finalizer. (#156325, has_entry property, ref the model and add a finalizer. (#156325,
Olivier Andrieu) Olivier Andrieu)
......
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:
* gtk/gtkimage.c (gtk_image_new_from_icon_name)
(gtk_image_set_from_icon_name, gtk_image_get_icon_name)
(gtk_image_set_pixel_size, gtk_image_get_pixel_size): Add a
new type GTK_IMAGE_ICON_NAME for named icons, update the size
and content of stock, icon set and named icon images upon style
changes, and allow to set a fixed pixel size for named icon
images. (#155688, James Henstridge)
* tests/testimage.c: Test application for theming behaviour of
different image types and for image dnd.
2004-10-24 Matthias Clasen <mclasen@redhat.com> 2004-10-24 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, intialize the * gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, initialize the
has_entry property, ref the model and add a finalizer. (#156325, has_entry property, ref the model and add a finalizer. (#156325,
Olivier Andrieu) Olivier Andrieu)
......
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkimage.h:
* gtk/gtkimage.c (gtk_image_new_from_icon_name)
(gtk_image_set_from_icon_name, gtk_image_get_icon_name)
(gtk_image_set_pixel_size, gtk_image_get_pixel_size): Add a
new type GTK_IMAGE_ICON_NAME for named icons, update the size
and content of stock, icon set and named icon images upon style
changes, and allow to set a fixed pixel size for named icon
images. (#155688, James Henstridge)
* tests/testimage.c: Test application for theming behaviour of
different image types and for image dnd.
2004-10-24 Matthias Clasen <mclasen@redhat.com> 2004-10-24 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, intialize the * gtk/gtkcellrenderercombo.c: Use G_DEFINE_TYPE, initialize the
has_entry property, ref the model and add a finalizer. (#156325, has_entry property, ref the model and add a finalizer. (#156325,
Olivier Andrieu) Olivier Andrieu)
......
2004-10-25 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Add new named icon api in GtkImage.
Sun Oct 24 02:54:36 2004 Jonathan Blandford <jrb@redhat.com> Sun Oct 24 02:54:36 2004 Jonathan Blandford <jrb@redhat.com>
* gtk/gtk.types: Add GtkAboutDialog and GtkFileChooserButton * gtk/gtk.types: Add GtkAboutDialog and GtkFileChooserButton
......
...@@ -1664,6 +1664,7 @@ gtk_image_get_pixbuf ...@@ -1664,6 +1664,7 @@ gtk_image_get_pixbuf
gtk_image_get_pixmap gtk_image_get_pixmap
gtk_image_get_stock gtk_image_get_stock
gtk_image_get_animation gtk_image_get_animation
gtk_image_get_icon_name
gtk_image_get_storage_type gtk_image_get_storage_type
gtk_image_new_from_file gtk_image_new_from_file
gtk_image_new_from_icon_set gtk_image_new_from_icon_set
...@@ -1672,6 +1673,7 @@ gtk_image_new_from_pixbuf ...@@ -1672,6 +1673,7 @@ gtk_image_new_from_pixbuf
gtk_image_new_from_pixmap gtk_image_new_from_pixmap
gtk_image_new_from_stock gtk_image_new_from_stock
gtk_image_new_from_animation gtk_image_new_from_animation
gtk_image_new_from_icon_name
gtk_image_set_from_file gtk_image_set_from_file
gtk_image_set_from_icon_set gtk_image_set_from_icon_set
gtk_image_set_from_image gtk_image_set_from_image
...@@ -1679,9 +1681,12 @@ gtk_image_set_from_pixbuf ...@@ -1679,9 +1681,12 @@ gtk_image_set_from_pixbuf
gtk_image_set_from_pixmap gtk_image_set_from_pixmap
gtk_image_set_from_stock gtk_image_set_from_stock
gtk_image_set_from_animation gtk_image_set_from_animation
gtk_image_set_from_icon_name
gtk_image_new gtk_image_new
gtk_image_set gtk_image_set
gtk_image_get gtk_image_get
gtk_image_set_pixel_size
gtk_image_get_pixel_size
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_IMAGE GTK_IMAGE
GTK_IS_IMAGE GTK_IS_IMAGE
...@@ -1697,6 +1702,7 @@ GtkImagePixbufData ...@@ -1697,6 +1702,7 @@ GtkImagePixbufData
GtkImagePixmapData GtkImagePixmapData
GtkImageStockData GtkImageStockData
GtkImageAnimationData GtkImageAnimationData
GtkImageIconNameData
</SECTION> </SECTION>
<SECTION> <SECTION>
......
...@@ -31,9 +31,18 @@ ...@@ -31,9 +31,18 @@
#include "gtkimage.h" #include "gtkimage.h"
#include "gtkiconfactory.h" #include "gtkiconfactory.h"
#include "gtkstock.h" #include "gtkstock.h"
#include "gtkicontheme.h"
#include "gtkintl.h" #include "gtkintl.h"
#include <string.h> #include <string.h>
typedef struct _GtkImagePrivate GtkImagePrivate;
struct _GtkImagePrivate
{
gint pixel_size;
};
#define GTK_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_IMAGE, GtkImagePrivate))
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
...@@ -46,6 +55,8 @@ static void gtk_image_unmap (GtkWidget *widget); ...@@ -46,6 +55,8 @@ static void gtk_image_unmap (GtkWidget *widget);
static void gtk_image_unrealize (GtkWidget *widget); static void gtk_image_unrealize (GtkWidget *widget);
static void gtk_image_size_request (GtkWidget *widget, static void gtk_image_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_image_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gtk_image_destroy (GtkObject *object); static void gtk_image_destroy (GtkObject *object);
static void gtk_image_clear (GtkImage *image); static void gtk_image_clear (GtkImage *image);
static void gtk_image_reset (GtkImage *image); static void gtk_image_reset (GtkImage *image);
...@@ -77,7 +88,9 @@ enum ...@@ -77,7 +88,9 @@ enum
PROP_STOCK, PROP_STOCK,
PROP_ICON_SET, PROP_ICON_SET,
PROP_ICON_SIZE, PROP_ICON_SIZE,
PROP_PIXEL_SIZE,
PROP_PIXBUF_ANIMATION, PROP_PIXBUF_ANIMATION,
PROP_ICON_NAME,
PROP_STORAGE_TYPE PROP_STORAGE_TYPE
}; };
...@@ -132,6 +145,7 @@ gtk_image_class_init (GtkImageClass *class) ...@@ -132,6 +145,7 @@ gtk_image_class_init (GtkImageClass *class)
widget_class->size_request = gtk_image_size_request; widget_class->size_request = gtk_image_size_request;
widget_class->unmap = gtk_image_unmap; widget_class->unmap = gtk_image_unmap;
widget_class->unrealize = gtk_image_unrealize; widget_class->unrealize = gtk_image_unrealize;
widget_class->style_set = gtk_image_style_set;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PIXBUF, PROP_PIXBUF,
...@@ -194,11 +208,28 @@ gtk_image_class_init (GtkImageClass *class) ...@@ -194,11 +208,28 @@ gtk_image_class_init (GtkImageClass *class)
PROP_ICON_SIZE, PROP_ICON_SIZE,
g_param_spec_int ("icon_size", g_param_spec_int ("icon_size",
P_("Icon size"), P_("Icon size"),
P_("Size to use for stock icon or icon set"), P_("Symbolic size to use for stock icon, icon set or named icon"),
0, G_MAXINT, 0, G_MAXINT,
DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/**
* GtkImage:pixel-size:
*
* The :pixel-size property can be used to specify a fixed size
* overriding the :icon-size property for images of type
* %GTK_IMAGE_ICON_NAME.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_PIXEL_SIZE,
g_param_spec_int ("pixel_size",
P_("Pixel size"),
P_("Pixel size to use for named icon"),
-1, G_MAXINT,
-1,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_PIXBUF_ANIMATION, PROP_PIXBUF_ANIMATION,
g_param_spec_object ("pixbuf_animation", g_param_spec_object ("pixbuf_animation",
...@@ -206,6 +237,22 @@ gtk_image_class_init (GtkImageClass *class) ...@@ -206,6 +237,22 @@ gtk_image_class_init (GtkImageClass *class)
P_("GdkPixbufAnimation to display"), P_("GdkPixbufAnimation to display"),
GDK_TYPE_PIXBUF_ANIMATION, GDK_TYPE_PIXBUF_ANIMATION,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/**
* GtkImage:icon-name:
*
* The name of the icon in the icon theme. If the icon theme is
* changed, the image will be updated automatically.
*
* Since: 2.6
*/
g_object_class_install_property (gobject_class,
PROP_ICON_NAME,
g_param_spec_string ("icon_name",
P_("Icon Name"),
P_("The name of the icon from the icon theme"),
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_STORAGE_TYPE, PROP_STORAGE_TYPE,
...@@ -215,16 +262,22 @@ gtk_image_class_init (GtkImageClass *class) ...@@ -215,16 +262,22 @@ gtk_image_class_init (GtkImageClass *class)
GTK_TYPE_IMAGE_TYPE, GTK_TYPE_IMAGE_TYPE,
GTK_IMAGE_EMPTY, GTK_IMAGE_EMPTY,
G_PARAM_READABLE)); G_PARAM_READABLE));
g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
} }
static void static void
gtk_image_init (GtkImage *image) gtk_image_init (GtkImage *image)
{ {
GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW); GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
image->storage_type = GTK_IMAGE_EMPTY; image->storage_type = GTK_IMAGE_EMPTY;
image->icon_size = DEFAULT_ICON_SIZE; image->icon_size = DEFAULT_ICON_SIZE;
image->mask = NULL; image->mask = NULL;
priv->pixel_size = -1;
} }
static void static void
...@@ -244,8 +297,10 @@ gtk_image_set_property (GObject *object, ...@@ -244,8 +297,10 @@ gtk_image_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkImage *image; GtkImage *image;
GtkImagePrivate *priv;
image = GTK_IMAGE (object); image = GTK_IMAGE (object);
priv = GTK_IMAGE_GET_PRIVATE (image);
switch (prop_id) switch (prop_id)
{ {
...@@ -307,15 +362,24 @@ gtk_image_set_property (GObject *object, ...@@ -307,15 +362,24 @@ gtk_image_set_property (GObject *object,
gtk_image_set_from_icon_set (image, gtk_image_set_from_icon_set (image,
image->data.icon_set.icon_set, image->data.icon_set.icon_set,
g_value_get_int (value)); g_value_get_int (value));
else if (image->storage_type == GTK_IMAGE_ICON_NAME)
gtk_image_set_from_icon_name (image,
image->data.name.icon_name,
g_value_get_int (value));
else else
/* Save to be used when STOCK or ICON_SET property comes in */ /* Save to be used when STOCK or ICON_SET property comes in */
image->icon_size = g_value_get_int (value); image->icon_size = g_value_get_int (value);
break; break;
case PROP_PIXEL_SIZE:
priv->pixel_size = g_value_get_int (value);
break;
case PROP_PIXBUF_ANIMATION: case PROP_PIXBUF_ANIMATION:
gtk_image_set_from_animation (image, gtk_image_set_from_animation (image,
g_value_get_object (value)); g_value_get_object (value));
break; break;
case PROP_ICON_NAME:
gtk_image_set_from_icon_name (image, g_value_get_string (value),
image->icon_size);
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -329,8 +393,10 @@ gtk_image_get_property (GObject *object, ...@@ -329,8 +393,10 @@ gtk_image_get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkImage *image; GtkImage *image;
GtkImagePrivate *priv;
image = GTK_IMAGE (object); image = GTK_IMAGE (object);
priv = GTK_IMAGE_GET_PRIVATE (image);
/* The "getter" functions whine if you try to get the wrong /* The "getter" functions whine if you try to get the wrong
* storage type. This function is instead robust against that, * storage type. This function is instead robust against that,
...@@ -381,6 +447,9 @@ gtk_image_get_property (GObject *object, ...@@ -381,6 +447,9 @@ gtk_image_get_property (GObject *object,
case PROP_ICON_SIZE: case PROP_ICON_SIZE:
g_value_set_int (value, image->icon_size); g_value_set_int (value, image->icon_size);
break; break;
case PROP_PIXEL_SIZE:
g_value_set_int (value, priv->pixel_size);
break;
case PROP_PIXBUF_ANIMATION: case PROP_PIXBUF_ANIMATION:
if (image->storage_type != GTK_IMAGE_ANIMATION) if (image->storage_type != GTK_IMAGE_ANIMATION)
g_value_set_object (value, NULL); g_value_set_object (value, NULL);
...@@ -388,6 +457,13 @@ gtk_image_get_property (GObject *object, ...@@ -388,6 +457,13 @@ gtk_image_get_property (GObject *object,
g_value_set_object (value, g_value_set_object (value,
image->data.anim.anim); image->data.anim.anim);
break; break;
case PROP_ICON_NAME:
if (image->storage_type != GTK_IMAGE_ICON_NAME)
g_value_set_object (value, NULL);
else
g_value_set_string (value,
image->data.name.icon_name);
break;
case PROP_STORAGE_TYPE: case PROP_STORAGE_TYPE:
g_value_set_enum (value, image->storage_type); g_value_set_enum (value, image->storage_type);
break; break;
...@@ -599,6 +675,33 @@ gtk_image_new_from_animation (GdkPixbufAnimation *animation) ...@@ -599,6 +675,33 @@ gtk_image_new_from_animation (GdkPixbufAnimation *animation)
return GTK_WIDGET (image); return GTK_WIDGET (image);
} }
/**
* gtk_image_new_from_icon_name:
* @icon_name: an icon name
* @size: a stock icon size
*
* Creates a #GtkImage displaying an icon from the current icon theme.
* If the icon name isn't known, a "broken image" icon will be
* displayed instead. If the current icon theme is changed, the icon
* will be updated appropriately.
*
* Return value: a new #GtkImage displaying the themed icon
*
* Since: 2.6
**/
GtkWidget*
gtk_image_new_from_icon_name (const gchar *icon_name,
GtkIconSize size)
{
GtkImage *image;
image = g_object_new (GTK_TYPE_IMAGE, NULL);
gtk_image_set_from_icon_name (image, icon_name, size);
return GTK_WIDGET (image);
}
/** /**
* gtk_image_set_from_pixmap: * gtk_image_set_from_pixmap:
* @image: a #GtkImage * @image: a #GtkImage
...@@ -925,6 +1028,51 @@ gtk_image_set_from_animation (GtkImage *image, ...@@ -925,6 +1028,51 @@ gtk_image_set_from_animation (GtkImage *image,
g_object_thaw_notify (G_OBJECT (image)); g_object_thaw_notify (G_OBJECT (image));
} }
/**
* gtk_image_set_from_icon_name:
* @image: a #GtkImage
* @icon_name: an icon name
* @size: an icon size
*
* See gtk_image_new_from_icon_name() for details.
*
* Since: 2.6
**/
void
gtk_image_set_from_icon_name (GtkImage *image,
const gchar *icon_name,
GtkIconSize size)
{
gchar *new_name;
g_return_if_fail (GTK_IS_IMAGE (image));
g_object_freeze_notify (G_OBJECT (image));
/* in case stock_id == image->data.stock.stock_id */
new_name = g_strdup (icon_name);
gtk_image_reset (image);
if (new_name)
{
image->storage_type = GTK_IMAGE_ICON_NAME;
image->data.name.icon_name = new_name;
image->icon_size = size;
/* Size is demand-computed in size request method
* if we're a icon theme image, since changing the
* style impacts the size request
*/
}
g_object_notify (G_OBJECT (image), "icon_name");
g_object_notify (G_OBJECT (image), "icon_size");
g_object_thaw_notify (G_OBJECT (image));
}
/** /**
* gtk_image_get_storage_type: * gtk_image_get_storage_type:
* @image: a #GtkImage * @image: a #GtkImage
...@@ -1112,6 +1260,39 @@ gtk_image_get_animation (GtkImage *image) ...@@ -1112,6 +1260,39 @@ gtk_image_get_animation (GtkImage *image)
return image->data.anim.anim; return image->data.anim.anim;
} }
/**
* gtk_image_get_icon_name:
* @image: a #GtkImage
* @icon_name: place to store an icon name
* @size: place to store an icon size
*
* Gets the icon name and size being displayed by the #GtkImage.
* The storage type of the image must be %GTK_IMAGE_EMPTY or
* %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
* The returned string is owned by the #GtkImage and should not
* be freed.
*
* Since: 2.6
**/
void
gtk_image_get_icon_name (GtkImage *image,
gchar **icon_name,
GtkIconSize *size)
{
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
image->storage_type == GTK_IMAGE_EMPTY);
if (image->storage_type == GTK_IMAGE_EMPTY)
image->data.name.icon_name = NULL;
if (icon_name)
*icon_name = image->data.name.icon_name;
if (size)
*size = image->icon_size;
}
/** /**
* gtk_image_new: * gtk_image_new:
* *
...@@ -1166,10 +1347,30 @@ gtk_image_reset_anim_iter (GtkImage *image) ...@@ -1166,10 +1347,30 @@ gtk_image_reset_anim_iter (GtkImage *image)
} }
} }
static void
gtk_image_reset_icon_theme_change_cb (GtkImage *image)
{
GdkScreen *screen;
GtkIconTheme *icon_theme;
if (image->storage_type == GTK_IMAGE_ICON_NAME)
{
if (image->data.name.theme_change_id)
{
screen = gtk_widget_get_screen (GTK_WIDGET (image));
icon_theme = gtk_icon_theme_get_for_screen (screen);
g_signal_handler_disconnect (icon_theme,
image->data.name.theme_change_id);
}
image->data.name.theme_change_id = 0;
}
}
static void static void
gtk_image_unmap (GtkWidget *widget) gtk_image_unmap (GtkWidget *widget)
{ {
gtk_image_reset_anim_iter (GTK_IMAGE (widget)); gtk_image_reset_anim_iter (GTK_IMAGE (widget));
gtk_image_reset_icon_theme_change_cb (GTK_IMAGE (widget));
if (GTK_WIDGET_CLASS (parent_class)->unmap) if (GTK_WIDGET_CLASS (parent_class)->unmap)
GTK_WIDGET_CLASS (parent_class)->unmap (widget); GTK_WIDGET_CLASS (parent_class)->unmap (widget);
...@@ -1179,6 +1380,7 @@ static void ...@@ -1179,6 +1380,7 @@ static void
gtk_image_unrealize (GtkWidget *widget) gtk_image_unrealize (GtkWidget *widget)
{ {
gtk_image_reset_anim_iter (GTK_IMAGE (widget)); gtk_image_reset_anim_iter (GTK_IMAGE (widget));
gtk_image_reset_icon_theme_change_cb (GTK_IMAGE (widget));
if (GTK_WIDGET_CLASS (parent_class)->unrealize) if (GTK_WIDGET_CLASS (parent_class)->unrealize)
GTK_WIDGET_CLASS (parent_class)->unrealize (widget); GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
...@@ -1210,6 +1412,98 @@ animation_timeout (gpointer data) ...@@ -1210,6 +1412,98 @@ animation_timeout (gpointer data)
return FALSE; return FALSE;
} }
static void
icon_theme_changed (GtkIconTheme *icon_theme,
GtkImage *image)
{
if (image->data.name.pixbuf)
g_object_unref (image->data.name.pixbuf);
image->data.name.pixbuf = NULL;
gtk_widget_queue_draw (GTK_WIDGET (image));
}
static void
ensure_pixbuf_for_icon_name (GtkImage *image)
{
GtkImagePrivate *priv;
GdkScreen *screen;
GtkIconTheme *icon_theme;
GtkSettings *settings;
gint width, height;
gint *sizes, *s, dist;
GError *error = NULL;
g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
priv = GTK_IMAGE_GET_PRIVATE (image);
screen = gtk_widget_get_screen (GTK_WIDGET (image));
icon_theme = gtk_icon_theme_get_for_screen (screen);
settings = gtk_settings_get_for_screen (screen);
if (image->data.name.pixbuf == NULL)
{
if (priv->pixel_size != -1)
{
width = height = priv->pixel_size;
}
else if (!gtk_icon_size_lookup_for_settings (settings,
image->icon_size,
&width, &height))
{
if (image->icon_size == -1)
{
/* Find an available size close to 48 */
sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
dist = 100;
width = height = 48;
for (s = sizes; *s; s++)
{
if (*s == -1)
{
width = height = 48;
break;
}
if (*s < 48)
{
if (48 - *s < dist)
{
width = height = *s;
dist = 48 - *s;
}
}
else
{
if (*s - 48 < dist)
{
width = height = *s;
dist = *s - 48;
}
}
}
g_free (sizes);
}
else
{
g_warning ("Invalid icon size %d\n", image->icon_size);
width = height = 24;
}
}
image->data.name.pixbuf =
gtk_icon_theme_load_icon (icon_theme,
image->data.name.icon_name,
MIN (width, height), 0, &error);
if (image->data.name.pixbuf == NULL)
{
g_error_free (error);
image->data.name.pixbuf =
gtk_widget_render_icon (GTK_WIDGET (image),
GTK_STOCK_MISSING_IMAGE,
image->icon_size,
NULL);
}
}
}
/* /*
* Like gdk_rectangle_intersect (dest, src, dest), but make * Like gdk_rectangle_intersect (dest, src, dest), but make
* sure that the origin of dest is moved by an "even" offset. * sure that the origin of dest is moved by an "even" offset.
...@@ -1266,6 +1560,8 @@ gtk_image_expose (GtkWidget *widget, ...@@ -1266,6 +1560,8 @@ gtk_image_expose (GtkWidget *widget,
GdkBitmap *mask; GdkBitmap *mask;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gboolean needs_state_transform; gboolean needs_state_transform;
GdkScreen *screen;
GtkIconTheme *icon_theme;
image = GTK_IMAGE (widget); image = GTK_IMAGE (widget);
misc = GTK_MISC (widget); misc = GTK_MISC (widget);
...@@ -1433,6 +1729,26 @@ gtk_image_expose (GtkWidget *widget, ...@@ -1433,6 +1729,26 @@ gtk_image_expose (GtkWidget *widget,
} }
break; break;
case GTK_IMAGE_ICON_NAME:
if (image->data.name.theme_change_id == 0)
{
screen = gtk_widget_get_screen (widget);
icon_theme = gtk_icon_theme_get_for_screen (screen);
image->data.name.theme_change_id =
g_signal_connect_object (icon_theme, "changed",