1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
33 #include "gtkiconfactory.h"
35 #include "gtkicontheme.h"
37 #include "gtkprivate.h"
40 typedef struct _GtkImagePrivate GtkImagePrivate;
42 struct _GtkImagePrivate
44 /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
50 #define GTK_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_IMAGE, GtkImagePrivate))
53 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
55 static void gtk_image_class_init (GtkImageClass *klass);
56 static void gtk_image_init (GtkImage *image);
57 static gint gtk_image_expose (GtkWidget *widget,
58 GdkEventExpose *event);
59 static void gtk_image_unmap (GtkWidget *widget);
60 static void gtk_image_unrealize (GtkWidget *widget);
61 static void gtk_image_size_request (GtkWidget *widget,
62 GtkRequisition *requisition);
63 static void gtk_image_style_set (GtkWidget *widget,
64 GtkStyle *prev_style);
65 static void gtk_image_screen_changed (GtkWidget *widget,
66 GdkScreen *prev_screen);
67 static void gtk_image_destroy (GtkObject *object);
68 static void gtk_image_reset (GtkImage *image);
69 static void gtk_image_calc_size (GtkImage *image);
71 static void gtk_image_update_size (GtkImage *image,
75 static void gtk_image_set_property (GObject *object,
79 static void gtk_image_get_property (GObject *object,
84 static void icon_theme_changed (GtkImage *image);
86 static gpointer parent_class;
100 PROP_PIXBUF_ANIMATION,
106 gtk_image_get_type (void)
108 static GType image_type = 0;
112 static const GTypeInfo image_info =
114 sizeof (GtkImageClass),
115 NULL, /* base_init */
116 NULL, /* base_finalize */
117 (GClassInitFunc) gtk_image_class_init,
118 NULL, /* class_finalize */
119 NULL, /* class_data */
122 (GInstanceInitFunc) gtk_image_init,
125 image_type = g_type_register_static (GTK_TYPE_MISC, "GtkImage",
133 gtk_image_class_init (GtkImageClass *class)
135 GObjectClass *gobject_class;
136 GtkObjectClass *object_class;
137 GtkWidgetClass *widget_class;
139 parent_class = g_type_class_peek_parent (class);
141 gobject_class = G_OBJECT_CLASS (class);
143 gobject_class->set_property = gtk_image_set_property;
144 gobject_class->get_property = gtk_image_get_property;
146 object_class = GTK_OBJECT_CLASS (class);
148 object_class->destroy = gtk_image_destroy;
150 widget_class = GTK_WIDGET_CLASS (class);
152 widget_class->expose_event = gtk_image_expose;
153 widget_class->size_request = gtk_image_size_request;
154 widget_class->unmap = gtk_image_unmap;
155 widget_class->unrealize = gtk_image_unrealize;
156 widget_class->style_set = gtk_image_style_set;
157 widget_class->screen_changed = gtk_image_screen_changed;
159 g_object_class_install_property (gobject_class,
161 g_param_spec_object ("pixbuf",
163 P_("A GdkPixbuf to display"),
165 GTK_PARAM_READWRITE));
167 g_object_class_install_property (gobject_class,
169 g_param_spec_object ("pixmap",
171 P_("A GdkPixmap to display"),
173 GTK_PARAM_READWRITE));
175 g_object_class_install_property (gobject_class,
177 g_param_spec_object ("image",
179 P_("A GdkImage to display"),
181 GTK_PARAM_READWRITE));
183 g_object_class_install_property (gobject_class,
185 g_param_spec_object ("mask",
187 P_("Mask bitmap to use with GdkImage or GdkPixmap"),
189 GTK_PARAM_READWRITE));
191 g_object_class_install_property (gobject_class,
193 g_param_spec_string ("file",
195 P_("Filename to load and display"),
197 GTK_PARAM_READWRITE));
200 g_object_class_install_property (gobject_class,
202 g_param_spec_string ("stock",
204 P_("Stock ID for a stock image to display"),
206 GTK_PARAM_READWRITE));
208 g_object_class_install_property (gobject_class,
210 g_param_spec_boxed ("icon-set",
212 P_("Icon set to display"),
214 GTK_PARAM_READWRITE));
216 g_object_class_install_property (gobject_class,
218 g_param_spec_int ("icon-size",
220 P_("Symbolic size to use for stock icon, icon set or named icon"),
223 GTK_PARAM_READWRITE));
225 * GtkImage:pixel-size:
227 * The :pixel-size property can be used to specify a fixed size
228 * overriding the :icon-size property for images of type
229 * %GTK_IMAGE_ICON_NAME.
233 g_object_class_install_property (gobject_class,
235 g_param_spec_int ("pixel-size",
237 P_("Pixel size to use for named icon"),
240 GTK_PARAM_READWRITE));
242 g_object_class_install_property (gobject_class,
243 PROP_PIXBUF_ANIMATION,
244 g_param_spec_object ("pixbuf-animation",
246 P_("GdkPixbufAnimation to display"),
247 GDK_TYPE_PIXBUF_ANIMATION,
248 GTK_PARAM_READWRITE));
251 * GtkImage:icon-name:
253 * The name of the icon in the icon theme. If the icon theme is
254 * changed, the image will be updated automatically.
258 g_object_class_install_property (gobject_class,
260 g_param_spec_string ("icon-name",
262 P_("The name of the icon from the icon theme"),
264 GTK_PARAM_READWRITE));
266 g_object_class_install_property (gobject_class,
268 g_param_spec_enum ("storage-type",
270 P_("The representation being used for image data"),
273 GTK_PARAM_READABLE));
275 g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
279 gtk_image_init (GtkImage *image)
281 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
283 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
285 image->storage_type = GTK_IMAGE_EMPTY;
286 image->icon_size = DEFAULT_ICON_SIZE;
289 priv->pixel_size = -1;
291 priv->filename = NULL;
295 gtk_image_destroy (GtkObject *object)
297 GtkImage *image = GTK_IMAGE (object);
299 gtk_image_clear (image);
301 GTK_OBJECT_CLASS (parent_class)->destroy (object);
305 gtk_image_set_property (GObject *object,
311 GtkImagePrivate *priv;
313 image = GTK_IMAGE (object);
314 priv = GTK_IMAGE_GET_PRIVATE (image);
319 gtk_image_set_from_pixbuf (image,
320 g_value_get_object (value));
323 gtk_image_set_from_pixmap (image,
324 g_value_get_object (value),
328 gtk_image_set_from_image (image,
329 g_value_get_object (value),
333 if (image->storage_type == GTK_IMAGE_PIXMAP)
334 gtk_image_set_from_pixmap (image,
335 image->data.pixmap.pixmap,
336 g_value_get_object (value));
337 else if (image->storage_type == GTK_IMAGE_IMAGE)
338 gtk_image_set_from_image (image,
339 image->data.image.image,
340 g_value_get_object (value));
345 mask = g_value_get_object (value);
350 gtk_image_reset (image);
356 gtk_image_set_from_file (image, g_value_get_string (value));
359 gtk_image_set_from_stock (image, g_value_get_string (value),
363 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
367 if (image->storage_type == GTK_IMAGE_STOCK)
368 gtk_image_set_from_stock (image,
369 image->data.stock.stock_id,
370 g_value_get_int (value));
371 else if (image->storage_type == GTK_IMAGE_ICON_SET)
372 gtk_image_set_from_icon_set (image,
373 image->data.icon_set.icon_set,
374 g_value_get_int (value));
375 else if (image->storage_type == GTK_IMAGE_ICON_NAME)
376 gtk_image_set_from_icon_name (image,
377 image->data.name.icon_name,
378 g_value_get_int (value));
380 /* Save to be used when STOCK or ICON_SET property comes in */
381 image->icon_size = g_value_get_int (value);
383 case PROP_PIXEL_SIZE:
384 gtk_image_set_pixel_size (image, g_value_get_int (value));
386 case PROP_PIXBUF_ANIMATION:
387 gtk_image_set_from_animation (image,
388 g_value_get_object (value));
391 gtk_image_set_from_icon_name (image, g_value_get_string (value),
396 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
402 gtk_image_get_property (GObject *object,
408 GtkImagePrivate *priv;
410 image = GTK_IMAGE (object);
411 priv = GTK_IMAGE_GET_PRIVATE (image);
413 /* The "getter" functions whine if you try to get the wrong
414 * storage type. This function is instead robust against that,
415 * so that GUI builders don't have to jump through hoops
422 if (image->storage_type != GTK_IMAGE_PIXBUF)
423 g_value_set_object (value, NULL);
425 g_value_set_object (value,
426 gtk_image_get_pixbuf (image));
429 if (image->storage_type != GTK_IMAGE_PIXMAP)
430 g_value_set_object (value, NULL);
432 g_value_set_object (value,
433 image->data.pixmap.pixmap);
436 g_value_set_object (value, image->mask);
439 if (image->storage_type != GTK_IMAGE_IMAGE)
440 g_value_set_object (value, NULL);
442 g_value_set_object (value,
443 image->data.image.image);
446 g_value_set_string (value, priv->filename);
449 if (image->storage_type != GTK_IMAGE_STOCK)
450 g_value_set_string (value, NULL);
452 g_value_set_string (value,
453 image->data.stock.stock_id);
456 if (image->storage_type != GTK_IMAGE_ICON_SET)
457 g_value_set_boxed (value, NULL);
459 g_value_set_boxed (value,
460 image->data.icon_set.icon_set);
463 g_value_set_int (value, image->icon_size);
465 case PROP_PIXEL_SIZE:
466 g_value_set_int (value, priv->pixel_size);
468 case PROP_PIXBUF_ANIMATION:
469 if (image->storage_type != GTK_IMAGE_ANIMATION)
470 g_value_set_object (value, NULL);
472 g_value_set_object (value,
473 image->data.anim.anim);
476 if (image->storage_type != GTK_IMAGE_ICON_NAME)
477 g_value_set_string (value, NULL);
479 g_value_set_string (value,
480 image->data.name.icon_name);
482 case PROP_STORAGE_TYPE:
483 g_value_set_enum (value, image->storage_type);
487 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
494 * gtk_image_new_from_pixmap:
495 * @pixmap: a #GdkPixmap, or %NULL
496 * @mask: a #GdkBitmap, or %NULL
498 * Creates a #GtkImage widget displaying @pixmap with a @mask.
499 * A #GdkPixmap is a server-side image buffer in the pixel format of the
500 * current display. The #GtkImage does not assume a reference to the
501 * pixmap or mask; you still need to unref them if you own references.
502 * #GtkImage will add its own reference rather than adopting yours.
504 * Return value: a new #GtkImage
507 gtk_image_new_from_pixmap (GdkPixmap *pixmap,
512 image = g_object_new (GTK_TYPE_IMAGE, NULL);
514 gtk_image_set_from_pixmap (image, pixmap, mask);
516 return GTK_WIDGET (image);
520 * gtk_image_new_from_image:
521 * @image: a #GdkImage, or %NULL
522 * @mask: a #GdkBitmap, or %NULL
524 * Creates a #GtkImage widget displaying a @image with a @mask.
525 * A #GdkImage is a client-side image buffer in the pixel format of the
527 * The #GtkImage does not assume a reference to the
528 * image or mask; you still need to unref them if you own references.
529 * #GtkImage will add its own reference rather than adopting yours.
531 * Return value: a new #GtkImage
534 gtk_image_new_from_image (GdkImage *gdk_image,
539 image = g_object_new (GTK_TYPE_IMAGE, NULL);
541 gtk_image_set_from_image (image, gdk_image, mask);
543 return GTK_WIDGET (image);
547 * gtk_image_new_from_file:
548 * @filename: a filename
550 * Creates a new #GtkImage displaying the file @filename. If the file
551 * isn't found or can't be loaded, the resulting #GtkImage will
552 * display a "broken image" icon. This function never returns %NULL,
553 * it always returns a valid #GtkImage widget.
555 * If the file contains an animation, the image will contain an
558 * If you need to detect failures to load the file, use
559 * gdk_pixbuf_new_from_file() to load the file yourself, then create
560 * the #GtkImage from the pixbuf. (Or for animations, use
561 * gdk_pixbuf_animation_new_from_file()).
563 * The storage type (gtk_image_get_storage_type()) of the returned
564 * image is not defined, it will be whatever is appropriate for
565 * displaying the file.
567 * Return value: a new #GtkImage
570 gtk_image_new_from_file (const gchar *filename)
574 image = g_object_new (GTK_TYPE_IMAGE, NULL);
576 gtk_image_set_from_file (image, filename);
578 return GTK_WIDGET (image);
582 * gtk_image_new_from_pixbuf:
583 * @pixbuf: a #GdkPixbuf, or %NULL
585 * Creates a new #GtkImage displaying @pixbuf.
586 * The #GtkImage does not assume a reference to the
587 * pixbuf; you still need to unref it if you own references.
588 * #GtkImage will add its own reference rather than adopting yours.
590 * Note that this function just creates an #GtkImage from the pixbuf. The
591 * #GtkImage created will not react to state changes. Should you want that, you
592 * should use gtk_image_new_from_icon_set().
594 * Return value: a new #GtkImage
597 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
601 image = g_object_new (GTK_TYPE_IMAGE, NULL);
603 gtk_image_set_from_pixbuf (image, pixbuf);
605 return GTK_WIDGET (image);
609 * gtk_image_new_from_stock:
610 * @stock_id: a stock icon name
611 * @size: a stock icon size
613 * Creates a #GtkImage displaying a stock icon. Sample stock icon
614 * names are #GTK_STOCK_OPEN, #GTK_STOCK_EXIT. Sample stock sizes
615 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
616 * icon name isn't known, the image will be empty.
617 * You can register your own stock icon names, see
618 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
620 * Return value: a new #GtkImage displaying the stock icon
623 gtk_image_new_from_stock (const gchar *stock_id,
628 image = g_object_new (GTK_TYPE_IMAGE, NULL);
630 gtk_image_set_from_stock (image, stock_id, size);
632 return GTK_WIDGET (image);
636 * gtk_image_new_from_icon_set:
637 * @icon_set: a #GtkIconSet
638 * @size: a stock icon size
640 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
641 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
642 * this function, usually it's better to create a #GtkIconFactory, put
643 * your icon sets in the icon factory, add the icon factory to the
644 * list of default factories with gtk_icon_factory_add_default(), and
645 * then use gtk_image_new_from_stock(). This will allow themes to
646 * override the icon you ship with your application.
648 * The #GtkImage does not assume a reference to the
649 * icon set; you still need to unref it if you own references.
650 * #GtkImage will add its own reference rather than adopting yours.
653 * Return value: a new #GtkImage
656 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
661 image = g_object_new (GTK_TYPE_IMAGE, NULL);
663 gtk_image_set_from_icon_set (image, icon_set, size);
665 return GTK_WIDGET (image);
669 * gtk_image_new_from_animation:
670 * @animation: an animation
672 * Creates a #GtkImage displaying the given animation.
673 * The #GtkImage does not assume a reference to the
674 * animation; you still need to unref it if you own references.
675 * #GtkImage will add its own reference rather than adopting yours.
677 * Return value: a new #GtkImage widget
680 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
684 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
686 image = g_object_new (GTK_TYPE_IMAGE, NULL);
688 gtk_image_set_from_animation (image, animation);
690 return GTK_WIDGET (image);
694 * gtk_image_new_from_icon_name:
695 * @icon_name: an icon name
696 * @size: a stock icon size
698 * Creates a #GtkImage displaying an icon from the current icon theme.
699 * If the icon name isn't known, a "broken image" icon will be
700 * displayed instead. If the current icon theme is changed, the icon
701 * will be updated appropriately.
703 * Return value: a new #GtkImage displaying the themed icon
708 gtk_image_new_from_icon_name (const gchar *icon_name,
713 image = g_object_new (GTK_TYPE_IMAGE, NULL);
715 gtk_image_set_from_icon_name (image, icon_name, size);
717 return GTK_WIDGET (image);
721 * gtk_image_set_from_pixmap:
722 * @image: a #GtkImage
723 * @pixmap: a #GdkPixmap or %NULL
724 * @mask: a #GdkBitmap or %NULL
726 * See gtk_image_new_from_pixmap() for details.
730 gtk_image_set_from_pixmap (GtkImage *image,
734 g_return_if_fail (GTK_IS_IMAGE (image));
735 g_return_if_fail (pixmap == NULL ||
736 GDK_IS_PIXMAP (pixmap));
737 g_return_if_fail (mask == NULL ||
738 GDK_IS_PIXMAP (mask));
740 g_object_freeze_notify (G_OBJECT (image));
743 g_object_ref (pixmap);
748 gtk_image_reset (image);
757 image->storage_type = GTK_IMAGE_PIXMAP;
759 image->data.pixmap.pixmap = pixmap;
761 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
763 gtk_image_update_size (image, width, height);
766 g_object_notify (G_OBJECT (image), "pixmap");
767 g_object_notify (G_OBJECT (image), "mask");
769 g_object_thaw_notify (G_OBJECT (image));
773 * gtk_image_set_from_image:
774 * @image: a #GtkImage
775 * @gdk_image: a #GdkImage or %NULL
776 * @mask: a #GdkBitmap or %NULL
778 * See gtk_image_new_from_image() for details.
782 gtk_image_set_from_image (GtkImage *image,
786 g_return_if_fail (GTK_IS_IMAGE (image));
787 g_return_if_fail (gdk_image == NULL ||
788 GDK_IS_IMAGE (gdk_image));
789 g_return_if_fail (mask == NULL ||
790 GDK_IS_PIXMAP (mask));
792 g_object_freeze_notify (G_OBJECT (image));
795 g_object_ref (gdk_image);
800 gtk_image_reset (image);
804 image->storage_type = GTK_IMAGE_IMAGE;
806 image->data.image.image = gdk_image;
809 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
813 /* Clean up the mask if gdk_image was NULL */
815 g_object_unref (mask);
818 g_object_notify (G_OBJECT (image), "image");
819 g_object_notify (G_OBJECT (image), "mask");
821 g_object_thaw_notify (G_OBJECT (image));
825 * gtk_image_set_from_file:
826 * @image: a #GtkImage
827 * @filename: a filename or %NULL
829 * See gtk_image_new_from_file() for details.
833 gtk_image_set_from_file (GtkImage *image,
834 const gchar *filename)
836 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
837 GdkPixbufAnimation *anim;
839 g_return_if_fail (GTK_IS_IMAGE (image));
841 g_object_freeze_notify (G_OBJECT (image));
843 gtk_image_reset (image);
845 if (filename == NULL)
847 priv->filename = NULL;
848 g_object_thaw_notify (G_OBJECT (image));
852 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
856 gtk_image_set_from_stock (image,
857 GTK_STOCK_MISSING_IMAGE,
858 GTK_ICON_SIZE_BUTTON);
859 g_object_thaw_notify (G_OBJECT (image));
863 /* We could just unconditionally set_from_animation,
864 * but it's nicer for memory if we toss the animation
865 * if it's just a single pixbuf
868 if (gdk_pixbuf_animation_is_static_image (anim))
869 gtk_image_set_from_pixbuf (image,
870 gdk_pixbuf_animation_get_static_image (anim));
872 gtk_image_set_from_animation (image, anim);
874 g_object_unref (anim);
876 priv->filename = g_strdup (filename);
878 g_object_thaw_notify (G_OBJECT (image));
882 * gtk_image_set_from_pixbuf:
883 * @image: a #GtkImage
884 * @pixbuf: a #GdkPixbuf or %NULL
886 * See gtk_image_new_from_pixbuf() for details.
890 gtk_image_set_from_pixbuf (GtkImage *image,
893 g_return_if_fail (GTK_IS_IMAGE (image));
894 g_return_if_fail (pixbuf == NULL ||
895 GDK_IS_PIXBUF (pixbuf));
897 g_object_freeze_notify (G_OBJECT (image));
900 g_object_ref (pixbuf);
902 gtk_image_reset (image);
906 image->storage_type = GTK_IMAGE_PIXBUF;
908 image->data.pixbuf.pixbuf = pixbuf;
910 gtk_image_update_size (image,
911 gdk_pixbuf_get_width (pixbuf),
912 gdk_pixbuf_get_height (pixbuf));
915 g_object_notify (G_OBJECT (image), "pixbuf");
917 g_object_thaw_notify (G_OBJECT (image));
921 * gtk_image_set_from_stock:
922 * @image: a #GtkImage
923 * @stock_id: a stock icon name
924 * @size: a stock icon size
926 * See gtk_image_new_from_stock() for details.
930 gtk_image_set_from_stock (GtkImage *image,
931 const gchar *stock_id,
936 g_return_if_fail (GTK_IS_IMAGE (image));
938 g_object_freeze_notify (G_OBJECT (image));
940 /* in case stock_id == image->data.stock.stock_id */
941 new_id = g_strdup (stock_id);
943 gtk_image_reset (image);
947 image->storage_type = GTK_IMAGE_STOCK;
949 image->data.stock.stock_id = new_id;
950 image->icon_size = size;
952 /* Size is demand-computed in size request method
953 * if we're a stock image, since changing the
954 * style impacts the size request
958 g_object_notify (G_OBJECT (image), "stock");
959 g_object_notify (G_OBJECT (image), "icon-size");
961 g_object_thaw_notify (G_OBJECT (image));
965 * gtk_image_set_from_icon_set:
966 * @image: a #GtkImage
967 * @icon_set: a #GtkIconSet
968 * @size: a stock icon size
970 * See gtk_image_new_from_icon_set() for details.
974 gtk_image_set_from_icon_set (GtkImage *image,
975 GtkIconSet *icon_set,
978 g_return_if_fail (GTK_IS_IMAGE (image));
980 g_object_freeze_notify (G_OBJECT (image));
983 gtk_icon_set_ref (icon_set);
985 gtk_image_reset (image);
989 image->storage_type = GTK_IMAGE_ICON_SET;
991 image->data.icon_set.icon_set = icon_set;
992 image->icon_size = size;
994 /* Size is demand-computed in size request method
995 * if we're an icon set
999 g_object_notify (G_OBJECT (image), "icon-set");
1000 g_object_notify (G_OBJECT (image), "icon-size");
1002 g_object_thaw_notify (G_OBJECT (image));
1006 * gtk_image_set_from_animation:
1007 * @image: a #GtkImage
1008 * @animation: the #GdkPixbufAnimation
1010 * Causes the #GtkImage to display the given animation (or display
1011 * nothing, if you set the animation to %NULL).
1014 gtk_image_set_from_animation (GtkImage *image,
1015 GdkPixbufAnimation *animation)
1017 g_return_if_fail (GTK_IS_IMAGE (image));
1018 g_return_if_fail (animation == NULL ||
1019 GDK_IS_PIXBUF_ANIMATION (animation));
1021 g_object_freeze_notify (G_OBJECT (image));
1024 g_object_ref (animation);
1026 gtk_image_reset (image);
1028 if (animation != NULL)
1030 image->storage_type = GTK_IMAGE_ANIMATION;
1032 image->data.anim.anim = animation;
1033 image->data.anim.frame_timeout = 0;
1034 image->data.anim.iter = NULL;
1036 gtk_image_update_size (image,
1037 gdk_pixbuf_animation_get_width (animation),
1038 gdk_pixbuf_animation_get_height (animation));
1041 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1043 g_object_thaw_notify (G_OBJECT (image));
1047 * gtk_image_set_from_icon_name:
1048 * @image: a #GtkImage
1049 * @icon_name: an icon name
1050 * @size: an icon size
1052 * See gtk_image_new_from_icon_name() for details.
1057 gtk_image_set_from_icon_name (GtkImage *image,
1058 const gchar *icon_name,
1063 g_return_if_fail (GTK_IS_IMAGE (image));
1065 g_object_freeze_notify (G_OBJECT (image));
1067 /* in case icon_name == image->data.name.icon_name */
1068 new_name = g_strdup (icon_name);
1070 gtk_image_reset (image);
1074 image->storage_type = GTK_IMAGE_ICON_NAME;
1076 image->data.name.icon_name = new_name;
1077 image->icon_size = size;
1079 /* Size is demand-computed in size request method
1080 * if we're a icon theme image, since changing the
1081 * style impacts the size request
1085 g_object_notify (G_OBJECT (image), "icon-name");
1086 g_object_notify (G_OBJECT (image), "icon-size");
1088 g_object_thaw_notify (G_OBJECT (image));
1092 * gtk_image_get_storage_type:
1093 * @image: a #GtkImage
1095 * Gets the type of representation being used by the #GtkImage
1096 * to store image data. If the #GtkImage has no image data,
1097 * the return value will be %GTK_IMAGE_EMPTY.
1099 * Return value: image representation being used
1102 gtk_image_get_storage_type (GtkImage *image)
1104 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1106 return image->storage_type;
1110 * gtk_image_get_pixmap:
1111 * @image: a #GtkImage
1112 * @pixmap: location to store the pixmap, or %NULL
1113 * @mask: location to store the mask, or %NULL
1115 * Gets the pixmap and mask being displayed by the #GtkImage.
1116 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1117 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1118 * The caller of this function does not own a reference to the
1119 * returned pixmap and mask.
1123 gtk_image_get_pixmap (GtkImage *image,
1127 g_return_if_fail (GTK_IS_IMAGE (image));
1128 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1129 image->storage_type == GTK_IMAGE_EMPTY);
1132 *pixmap = image->data.pixmap.pixmap;
1135 *mask = image->mask;
1139 * gtk_image_get_image:
1140 * @image: a #GtkImage
1141 * @gdk_image: return location for a #GtkImage
1142 * @mask: return location for a #GdkBitmap
1144 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1145 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1146 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1147 * The caller of this function does not own a reference to the
1148 * returned image and mask.
1151 gtk_image_get_image (GtkImage *image,
1152 GdkImage **gdk_image,
1155 g_return_if_fail (GTK_IS_IMAGE (image));
1156 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1157 image->storage_type == GTK_IMAGE_EMPTY);
1160 *gdk_image = image->data.image.image;
1163 *mask = image->mask;
1167 * gtk_image_get_pixbuf:
1168 * @image: a #GtkImage
1171 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1172 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1173 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1174 * The caller of this function does not own a reference to the
1177 * Return value: the displayed pixbuf, or %NULL if the image is empty
1180 gtk_image_get_pixbuf (GtkImage *image)
1182 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1183 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1184 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1186 if (image->storage_type == GTK_IMAGE_EMPTY)
1187 image->data.pixbuf.pixbuf = NULL;
1189 return image->data.pixbuf.pixbuf;
1193 * gtk_image_get_stock:
1194 * @image: a #GtkImage
1195 * @stock_id: place to store a stock icon name
1196 * @size: place to store a stock icon size
1198 * Gets the stock icon name and size being displayed by the #GtkImage.
1199 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1200 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1201 * The returned string is owned by the #GtkImage and should not
1206 gtk_image_get_stock (GtkImage *image,
1210 g_return_if_fail (GTK_IS_IMAGE (image));
1211 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1212 image->storage_type == GTK_IMAGE_EMPTY);
1214 if (image->storage_type == GTK_IMAGE_EMPTY)
1215 image->data.stock.stock_id = NULL;
1218 *stock_id = image->data.stock.stock_id;
1221 *size = image->icon_size;
1225 * gtk_image_get_icon_set:
1226 * @image: a #GtkImage
1227 * @icon_set: location to store a #GtkIconSet
1228 * @size: location to store a stock icon size
1230 * Gets the icon set and size being displayed by the #GtkImage.
1231 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1232 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1236 gtk_image_get_icon_set (GtkImage *image,
1237 GtkIconSet **icon_set,
1240 g_return_if_fail (GTK_IS_IMAGE (image));
1241 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1242 image->storage_type == GTK_IMAGE_EMPTY);
1245 *icon_set = image->data.icon_set.icon_set;
1248 *size = image->icon_size;
1252 * gtk_image_get_animation:
1253 * @image: a #GtkImage
1256 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1257 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1258 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1259 * The caller of this function does not own a reference to the
1260 * returned animation.
1262 * Return value: the displayed animation, or %NULL if the image is empty
1265 gtk_image_get_animation (GtkImage *image)
1267 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1268 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1269 image->storage_type == GTK_IMAGE_EMPTY,
1272 if (image->storage_type == GTK_IMAGE_EMPTY)
1273 image->data.anim.anim = NULL;
1275 return image->data.anim.anim;
1279 * gtk_image_get_icon_name:
1280 * @image: a #GtkImage
1281 * @icon_name: place to store an icon name
1282 * @size: place to store an icon size
1284 * Gets the icon name and size being displayed by the #GtkImage.
1285 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1286 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1287 * The returned string is owned by the #GtkImage and should not
1293 gtk_image_get_icon_name (GtkImage *image,
1294 G_CONST_RETURN gchar **icon_name,
1297 g_return_if_fail (GTK_IS_IMAGE (image));
1298 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1299 image->storage_type == GTK_IMAGE_EMPTY);
1301 if (image->storage_type == GTK_IMAGE_EMPTY)
1302 image->data.name.icon_name = NULL;
1305 *icon_name = image->data.name.icon_name;
1308 *size = image->icon_size;
1314 * Creates a new empty #GtkImage widget.
1316 * Return value: a newly created #GtkImage widget.
1319 gtk_image_new (void)
1321 return g_object_new (GTK_TYPE_IMAGE, NULL);
1325 gtk_image_set (GtkImage *image,
1329 g_return_if_fail (GTK_IS_IMAGE (image));
1331 gtk_image_set_from_image (image, val, mask);
1335 gtk_image_get (GtkImage *image,
1339 g_return_if_fail (GTK_IS_IMAGE (image));
1341 gtk_image_get_image (image, val, mask);
1345 gtk_image_reset_anim_iter (GtkImage *image)
1347 if (image->storage_type == GTK_IMAGE_ANIMATION)
1349 /* Reset the animation */
1351 if (image->data.anim.frame_timeout)
1353 g_source_remove (image->data.anim.frame_timeout);
1354 image->data.anim.frame_timeout = 0;
1357 if (image->data.anim.iter)
1359 g_object_unref (image->data.anim.iter);
1360 image->data.anim.iter = NULL;
1366 gtk_image_unmap (GtkWidget *widget)
1368 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1370 if (GTK_WIDGET_CLASS (parent_class)->unmap)
1371 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1375 gtk_image_unrealize (GtkWidget *widget)
1377 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1379 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1380 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
1384 animation_timeout (gpointer data)
1388 GDK_THREADS_ENTER ();
1390 image = GTK_IMAGE (data);
1392 image->data.anim.frame_timeout = 0;
1394 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1396 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1397 image->data.anim.frame_timeout =
1398 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1402 gtk_widget_queue_draw (GTK_WIDGET (image));
1404 GDK_THREADS_LEAVE ();
1410 icon_theme_changed (GtkImage *image)
1412 if (image->data.name.pixbuf)
1413 g_object_unref (image->data.name.pixbuf);
1414 image->data.name.pixbuf = NULL;
1416 gtk_widget_queue_draw (GTK_WIDGET (image));
1420 ensure_pixbuf_for_icon_name (GtkImage *image)
1422 GtkImagePrivate *priv;
1424 GtkIconTheme *icon_theme;
1425 GtkSettings *settings;
1427 gint *sizes, *s, dist;
1428 GError *error = NULL;
1430 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1432 priv = GTK_IMAGE_GET_PRIVATE (image);
1433 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1434 icon_theme = gtk_icon_theme_get_for_screen (screen);
1435 settings = gtk_settings_get_for_screen (screen);
1436 if (image->data.name.pixbuf == NULL)
1438 if (priv->pixel_size != -1)
1440 width = height = priv->pixel_size;
1442 else if (!gtk_icon_size_lookup_for_settings (settings,
1446 if (image->icon_size == -1)
1448 /* Find an available size close to 48 */
1449 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1451 width = height = 48;
1452 for (s = sizes; *s; s++)
1456 width = height = 48;
1463 width = height = *s;
1471 width = height = *s;
1480 g_warning ("Invalid icon size %d\n", image->icon_size);
1481 width = height = 24;
1484 image->data.name.pixbuf =
1485 gtk_icon_theme_load_icon (icon_theme,
1486 image->data.name.icon_name,
1487 MIN (width, height), 0, &error);
1488 if (image->data.name.pixbuf == NULL)
1490 g_error_free (error);
1491 image->data.name.pixbuf =
1492 gtk_widget_render_icon (GTK_WIDGET (image),
1493 GTK_STOCK_MISSING_IMAGE,
1501 * Like gdk_rectangle_intersect (dest, src, dest), but make
1502 * sure that the origin of dest is moved by an "even" offset.
1503 * If necessary grow the intersection by one row or column
1506 * This is necessary since we can't pass alignment information
1507 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1508 * thus we have to makesure that the subimages are properly aligned.
1511 rectangle_intersect_even (GdkRectangle *src,
1519 isect = gdk_rectangle_intersect (dest, src, dest);
1521 if ((dest->x - x + dest->y - y) % 2 != 0)
1539 gtk_image_expose (GtkWidget *widget,
1540 GdkEventExpose *event)
1542 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1543 g_return_val_if_fail (event != NULL, FALSE);
1545 if (GTK_WIDGET_MAPPED (widget) &&
1546 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1550 GdkRectangle area, image_bound;
1552 gint x, y, mask_x, mask_y;
1555 gboolean needs_state_transform;
1557 image = GTK_IMAGE (widget);
1558 misc = GTK_MISC (widget);
1562 /* For stock items and icon sets, we lazily calculate
1563 * the size; we might get here between a queue_resize()
1564 * and size_request() if something explicitely forces
1567 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1568 gtk_image_calc_size (image);
1570 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1573 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1574 xalign = misc->xalign;
1576 xalign = 1.0 - misc->xalign;
1578 x = floor (widget->allocation.x + misc->xpad
1579 + ((widget->allocation.width - widget->requisition.width) * xalign));
1580 y = floor (widget->allocation.y + misc->ypad
1581 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
1587 image_bound.width = 0;
1588 image_bound.height = 0;
1592 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1594 switch (image->storage_type)
1596 case GTK_IMAGE_PIXMAP:
1598 gdk_drawable_get_size (image->data.pixmap.pixmap,
1600 &image_bound.height);
1601 if (rectangle_intersect_even (&area, &image_bound) &&
1602 needs_state_transform)
1604 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1605 image->data.pixmap.pixmap,
1606 gtk_widget_get_colormap (widget),
1607 image_bound.x - x, image_bound.y - y,
1610 image_bound.height);
1618 case GTK_IMAGE_IMAGE:
1620 image_bound.width = image->data.image.image->width;
1621 image_bound.height = image->data.image.image->height;
1623 if (rectangle_intersect_even (&area, &image_bound) &&
1624 needs_state_transform)
1626 pixbuf = gdk_pixbuf_get_from_image (NULL,
1627 image->data.image.image,
1628 gtk_widget_get_colormap (widget),
1629 image_bound.x - x, image_bound.y - y,
1632 image_bound.height);
1639 case GTK_IMAGE_PIXBUF:
1640 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1641 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1643 if (rectangle_intersect_even (&area, &image_bound) &&
1644 needs_state_transform)
1646 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1647 image_bound.x - x, image_bound.y - y,
1648 image_bound.width, image_bound.height);
1655 pixbuf = image->data.pixbuf.pixbuf;
1656 g_object_ref (pixbuf);
1660 case GTK_IMAGE_STOCK:
1661 pixbuf = gtk_widget_render_icon (widget,
1662 image->data.stock.stock_id,
1667 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1668 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1672 needs_state_transform = FALSE;
1675 case GTK_IMAGE_ICON_SET:
1677 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1679 gtk_widget_get_direction (widget),
1680 GTK_WIDGET_STATE (widget),
1687 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1688 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1692 needs_state_transform = FALSE;
1695 case GTK_IMAGE_ANIMATION:
1697 if (image->data.anim.iter == NULL)
1699 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1701 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1702 image->data.anim.frame_timeout =
1703 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1708 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1709 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1711 /* don't advance the anim iter here, or we could get frame changes between two
1712 * exposes of different areas.
1715 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1716 g_object_ref (pixbuf);
1720 case GTK_IMAGE_ICON_NAME:
1721 ensure_pixbuf_for_icon_name (image);
1722 pixbuf = image->data.name.pixbuf;
1725 g_object_ref (pixbuf);
1726 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1727 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1731 case GTK_IMAGE_EMPTY:
1732 g_assert_not_reached ();
1738 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1739 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1742 if (rectangle_intersect_even (&area, &image_bound))
1746 if (needs_state_transform)
1748 GtkIconSource *source;
1749 GdkPixbuf *rendered;
1751 source = gtk_icon_source_new ();
1752 gtk_icon_source_set_pixbuf (source, pixbuf);
1753 /* The size here is arbitrary; since size isn't
1754 * wildcarded in the souce, it isn't supposed to be
1755 * scaled by the engine function
1757 gtk_icon_source_set_size (source,
1758 GTK_ICON_SIZE_SMALL_TOOLBAR);
1759 gtk_icon_source_set_size_wildcarded (source, FALSE);
1761 rendered = gtk_style_render_icon (widget->style,
1763 gtk_widget_get_direction (widget),
1764 GTK_WIDGET_STATE (widget),
1770 gtk_icon_source_free (source);
1772 g_object_unref (pixbuf);
1778 gdk_draw_pixbuf (widget->window,
1779 widget->style->black_gc,
1787 GDK_RGB_DITHER_NORMAL,
1790 g_object_unref (pixbuf);
1796 switch (image->storage_type)
1798 case GTK_IMAGE_PIXMAP:
1799 gdk_draw_drawable (widget->window,
1800 widget->style->black_gc,
1801 image->data.pixmap.pixmap,
1802 image_bound.x - x, image_bound.y - y,
1803 image_bound.x, image_bound.y,
1804 image_bound.width, image_bound.height);
1807 case GTK_IMAGE_IMAGE:
1808 gdk_draw_image (widget->window,
1809 widget->style->black_gc,
1810 image->data.image.image,
1811 image_bound.x - x, image_bound.y - y,
1812 image_bound.x, image_bound.y,
1813 image_bound.width, image_bound.height);
1816 case GTK_IMAGE_PIXBUF:
1817 case GTK_IMAGE_STOCK:
1818 case GTK_IMAGE_ICON_SET:
1819 case GTK_IMAGE_ANIMATION:
1820 case GTK_IMAGE_ICON_NAME:
1821 case GTK_IMAGE_EMPTY:
1822 g_assert_not_reached ();
1826 } /* if rectangle intersects */
1830 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1831 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1834 } /* if widget is drawable */
1841 * @image: a #GtkImage
1843 * Resets the image to be empty.
1848 gtk_image_clear (GtkImage *image)
1850 GtkImagePrivate *priv;
1852 g_return_if_fail (GTK_IS_IMAGE (image));
1854 priv = GTK_IMAGE_GET_PRIVATE (image);
1856 g_object_freeze_notify (G_OBJECT (image));
1858 if (image->storage_type != GTK_IMAGE_EMPTY)
1859 g_object_notify (G_OBJECT (image), "storage-type");
1863 g_object_unref (image->mask);
1865 g_object_notify (G_OBJECT (image), "mask");
1868 if (image->icon_size != DEFAULT_ICON_SIZE)
1870 image->icon_size = DEFAULT_ICON_SIZE;
1871 g_object_notify (G_OBJECT (image), "icon-size");
1874 switch (image->storage_type)
1876 case GTK_IMAGE_PIXMAP:
1878 if (image->data.pixmap.pixmap)
1879 g_object_unref (image->data.pixmap.pixmap);
1880 image->data.pixmap.pixmap = NULL;
1882 g_object_notify (G_OBJECT (image), "pixmap");
1886 case GTK_IMAGE_IMAGE:
1888 if (image->data.image.image)
1889 g_object_unref (image->data.image.image);
1890 image->data.image.image = NULL;
1892 g_object_notify (G_OBJECT (image), "image");
1896 case GTK_IMAGE_PIXBUF:
1898 if (image->data.pixbuf.pixbuf)
1899 g_object_unref (image->data.pixbuf.pixbuf);
1901 g_object_notify (G_OBJECT (image), "pixbuf");
1905 case GTK_IMAGE_STOCK:
1907 g_free (image->data.stock.stock_id);
1909 image->data.stock.stock_id = NULL;
1911 g_object_notify (G_OBJECT (image), "stock");
1914 case GTK_IMAGE_ICON_SET:
1915 if (image->data.icon_set.icon_set)
1916 gtk_icon_set_unref (image->data.icon_set.icon_set);
1917 image->data.icon_set.icon_set = NULL;
1919 g_object_notify (G_OBJECT (image), "icon-set");
1922 case GTK_IMAGE_ANIMATION:
1923 gtk_image_reset_anim_iter (image);
1925 if (image->data.anim.anim)
1926 g_object_unref (image->data.anim.anim);
1927 image->data.anim.anim = NULL;
1929 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1933 case GTK_IMAGE_ICON_NAME:
1934 if (image->data.name.icon_name)
1935 g_free (image->data.name.icon_name);
1936 image->data.name.icon_name = NULL;
1937 if (image->data.name.pixbuf)
1938 g_object_unref (image->data.name.pixbuf);
1939 image->data.name.pixbuf = NULL;
1941 g_object_notify (G_OBJECT (image), "icon-name");
1945 case GTK_IMAGE_EMPTY:
1953 g_free (priv->filename);
1954 priv->filename = NULL;
1955 g_object_notify (G_OBJECT (image), "file");
1958 image->storage_type = GTK_IMAGE_EMPTY;
1960 memset (&image->data, '\0', sizeof (image->data));
1962 g_object_thaw_notify (G_OBJECT (image));
1966 gtk_image_reset (GtkImage *image)
1968 gtk_image_clear (image);
1970 gtk_image_update_size (image, 0, 0);
1974 gtk_image_calc_size (GtkImage *image)
1976 GtkWidget *widget = GTK_WIDGET (image);
1977 GdkPixbuf *pixbuf = NULL;
1979 /* We update stock/icon set on every size request, because
1980 * the theme could have affected the size; for other kinds of
1981 * image, we just update the requisition when the image data
1984 switch (image->storage_type)
1986 case GTK_IMAGE_STOCK:
1987 pixbuf = gtk_widget_render_icon (widget,
1988 image->data.stock.stock_id,
1993 case GTK_IMAGE_ICON_SET:
1994 pixbuf = gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1996 gtk_widget_get_direction (widget),
1997 GTK_WIDGET_STATE (widget),
2002 case GTK_IMAGE_ICON_NAME:
2003 ensure_pixbuf_for_icon_name (image);
2004 pixbuf = image->data.name.pixbuf;
2005 if (pixbuf) g_object_ref (pixbuf);
2013 widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
2014 widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
2016 g_object_unref (pixbuf);
2021 gtk_image_size_request (GtkWidget *widget,
2022 GtkRequisition *requisition)
2026 image = GTK_IMAGE (widget);
2028 gtk_image_calc_size (image);
2030 /* Chain up to default that simply reads current requisition */
2031 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
2035 gtk_image_style_set (GtkWidget *widget,
2036 GtkStyle *prev_style)
2040 image = GTK_IMAGE (widget);
2042 if (GTK_WIDGET_CLASS (parent_class)->style_set)
2043 GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
2045 icon_theme_changed (image);
2049 gtk_image_screen_changed (GtkWidget *widget,
2050 GdkScreen *prev_screen)
2054 image = GTK_IMAGE (widget);
2056 if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
2057 GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, prev_screen);
2059 icon_theme_changed (image);
2064 gtk_image_update_size (GtkImage *image,
2068 GTK_WIDGET (image)->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
2069 GTK_WIDGET (image)->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
2071 if (GTK_WIDGET_VISIBLE (image))
2072 gtk_widget_queue_resize (GTK_WIDGET (image));
2077 * gtk_image_set_pixel_size:
2078 * @image: a #GtkImage
2079 * @pixel_size: the new pixel size
2081 * Sets the pixel size to use for named icons. If the pixel size is set
2082 * to a value != -1, it is used instead of the icon size set by
2083 * gtk_image_set_from_icon_name().
2088 gtk_image_set_pixel_size (GtkImage *image,
2091 GtkImagePrivate *priv;
2093 g_return_if_fail (GTK_IS_IMAGE (image));
2095 priv = GTK_IMAGE_GET_PRIVATE (image);
2097 if (priv->pixel_size != pixel_size)
2099 priv->pixel_size = pixel_size;
2101 if (image->storage_type == GTK_IMAGE_ICON_NAME)
2103 if (image->data.name.pixbuf)
2105 g_object_unref (image->data.name.pixbuf);
2106 image->data.name.pixbuf = NULL;
2109 gtk_image_update_size (image, pixel_size, pixel_size);
2112 g_object_notify (G_OBJECT (image), "pixel-size");
2117 * gtk_image_get_pixel_size:
2118 * @image: a #GtkImage
2120 * Gets the pixel size used for named icons.
2122 * Returns: the pixel size used for named icons.
2127 gtk_image_get_pixel_size (GtkImage *image)
2129 GtkImagePrivate *priv;
2131 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2133 priv = GTK_IMAGE_GET_PRIVATE (image);
2135 return priv->pixel_size;
2140 #undef gtk_image_new_from_file
2143 gtk_image_new_from_file (const gchar *filename)
2145 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2148 retval = gtk_image_new_from_file_utf8 (utf8_filename);
2150 g_free (utf8_filename);
2155 #undef gtk_image_set_from_file
2158 gtk_image_set_from_file (GtkImage *image,
2159 const gchar *filename)
2161 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2163 gtk_image_set_from_file_utf8 (image, utf8_filename);
2165 g_free (utf8_filename);
2170 #define __GTK_IMAGE_C__
2171 #include "gtkaliasdef.c"