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
54 static gint gtk_image_expose (GtkWidget *widget,
55 GdkEventExpose *event);
56 static void gtk_image_unmap (GtkWidget *widget);
57 static void gtk_image_unrealize (GtkWidget *widget);
58 static void gtk_image_size_request (GtkWidget *widget,
59 GtkRequisition *requisition);
60 static void gtk_image_style_set (GtkWidget *widget,
61 GtkStyle *prev_style);
62 static void gtk_image_screen_changed (GtkWidget *widget,
63 GdkScreen *prev_screen);
64 static void gtk_image_destroy (GtkObject *object);
65 static void gtk_image_reset (GtkImage *image);
66 static void gtk_image_calc_size (GtkImage *image);
68 static void gtk_image_update_size (GtkImage *image,
72 static void gtk_image_set_property (GObject *object,
76 static void gtk_image_get_property (GObject *object,
81 static void icon_theme_changed (GtkImage *image);
95 PROP_PIXBUF_ANIMATION,
100 G_DEFINE_TYPE (GtkImage, gtk_image, GTK_TYPE_MISC)
103 gtk_image_class_init (GtkImageClass *class)
105 GObjectClass *gobject_class;
106 GtkObjectClass *object_class;
107 GtkWidgetClass *widget_class;
109 gobject_class = G_OBJECT_CLASS (class);
111 gobject_class->set_property = gtk_image_set_property;
112 gobject_class->get_property = gtk_image_get_property;
114 object_class = GTK_OBJECT_CLASS (class);
116 object_class->destroy = gtk_image_destroy;
118 widget_class = GTK_WIDGET_CLASS (class);
120 widget_class->expose_event = gtk_image_expose;
121 widget_class->size_request = gtk_image_size_request;
122 widget_class->unmap = gtk_image_unmap;
123 widget_class->unrealize = gtk_image_unrealize;
124 widget_class->style_set = gtk_image_style_set;
125 widget_class->screen_changed = gtk_image_screen_changed;
127 g_object_class_install_property (gobject_class,
129 g_param_spec_object ("pixbuf",
131 P_("A GdkPixbuf to display"),
133 GTK_PARAM_READWRITE));
135 g_object_class_install_property (gobject_class,
137 g_param_spec_object ("pixmap",
139 P_("A GdkPixmap to display"),
141 GTK_PARAM_READWRITE));
143 g_object_class_install_property (gobject_class,
145 g_param_spec_object ("image",
147 P_("A GdkImage to display"),
149 GTK_PARAM_READWRITE));
151 g_object_class_install_property (gobject_class,
153 g_param_spec_object ("mask",
155 P_("Mask bitmap to use with GdkImage or GdkPixmap"),
157 GTK_PARAM_READWRITE));
159 g_object_class_install_property (gobject_class,
161 g_param_spec_string ("file",
163 P_("Filename to load and display"),
165 GTK_PARAM_READWRITE));
168 g_object_class_install_property (gobject_class,
170 g_param_spec_string ("stock",
172 P_("Stock ID for a stock image to display"),
174 GTK_PARAM_READWRITE));
176 g_object_class_install_property (gobject_class,
178 g_param_spec_boxed ("icon-set",
180 P_("Icon set to display"),
182 GTK_PARAM_READWRITE));
184 g_object_class_install_property (gobject_class,
186 g_param_spec_int ("icon-size",
188 P_("Symbolic size to use for stock icon, icon set or named icon"),
191 GTK_PARAM_READWRITE));
193 * GtkImage:pixel-size:
195 * The :pixel-size property can be used to specify a fixed size
196 * overriding the :icon-size property for images of type
197 * %GTK_IMAGE_ICON_NAME.
201 g_object_class_install_property (gobject_class,
203 g_param_spec_int ("pixel-size",
205 P_("Pixel size to use for named icon"),
208 GTK_PARAM_READWRITE));
210 g_object_class_install_property (gobject_class,
211 PROP_PIXBUF_ANIMATION,
212 g_param_spec_object ("pixbuf-animation",
214 P_("GdkPixbufAnimation to display"),
215 GDK_TYPE_PIXBUF_ANIMATION,
216 GTK_PARAM_READWRITE));
219 * GtkImage:icon-name:
221 * The name of the icon in the icon theme. If the icon theme is
222 * changed, the image will be updated automatically.
226 g_object_class_install_property (gobject_class,
228 g_param_spec_string ("icon-name",
230 P_("The name of the icon from the icon theme"),
232 GTK_PARAM_READWRITE));
234 g_object_class_install_property (gobject_class,
236 g_param_spec_enum ("storage-type",
238 P_("The representation being used for image data"),
241 GTK_PARAM_READABLE));
243 g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
247 gtk_image_init (GtkImage *image)
249 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
251 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
253 image->storage_type = GTK_IMAGE_EMPTY;
254 image->icon_size = DEFAULT_ICON_SIZE;
257 priv->pixel_size = -1;
259 priv->filename = NULL;
263 gtk_image_destroy (GtkObject *object)
265 GtkImage *image = GTK_IMAGE (object);
267 gtk_image_reset (image);
269 GTK_OBJECT_CLASS (gtk_image_parent_class)->destroy (object);
273 gtk_image_set_property (GObject *object,
280 image = GTK_IMAGE (object);
285 gtk_image_set_from_pixbuf (image,
286 g_value_get_object (value));
289 gtk_image_set_from_pixmap (image,
290 g_value_get_object (value),
294 gtk_image_set_from_image (image,
295 g_value_get_object (value),
299 if (image->storage_type == GTK_IMAGE_PIXMAP)
300 gtk_image_set_from_pixmap (image,
301 image->data.pixmap.pixmap,
302 g_value_get_object (value));
303 else if (image->storage_type == GTK_IMAGE_IMAGE)
304 gtk_image_set_from_image (image,
305 image->data.image.image,
306 g_value_get_object (value));
311 mask = g_value_get_object (value);
316 gtk_image_clear (image);
322 gtk_image_set_from_file (image, g_value_get_string (value));
325 gtk_image_set_from_stock (image, g_value_get_string (value),
329 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
333 if (image->storage_type == GTK_IMAGE_STOCK)
334 gtk_image_set_from_stock (image,
335 image->data.stock.stock_id,
336 g_value_get_int (value));
337 else if (image->storage_type == GTK_IMAGE_ICON_SET)
338 gtk_image_set_from_icon_set (image,
339 image->data.icon_set.icon_set,
340 g_value_get_int (value));
341 else if (image->storage_type == GTK_IMAGE_ICON_NAME)
342 gtk_image_set_from_icon_name (image,
343 image->data.name.icon_name,
344 g_value_get_int (value));
346 /* Save to be used when STOCK or ICON_SET property comes in */
347 image->icon_size = g_value_get_int (value);
349 case PROP_PIXEL_SIZE:
350 gtk_image_set_pixel_size (image, g_value_get_int (value));
352 case PROP_PIXBUF_ANIMATION:
353 gtk_image_set_from_animation (image,
354 g_value_get_object (value));
357 gtk_image_set_from_icon_name (image, g_value_get_string (value),
362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
368 gtk_image_get_property (GObject *object,
374 GtkImagePrivate *priv;
376 image = GTK_IMAGE (object);
377 priv = GTK_IMAGE_GET_PRIVATE (image);
379 /* The "getter" functions whine if you try to get the wrong
380 * storage type. This function is instead robust against that,
381 * so that GUI builders don't have to jump through hoops
388 if (image->storage_type != GTK_IMAGE_PIXBUF)
389 g_value_set_object (value, NULL);
391 g_value_set_object (value,
392 gtk_image_get_pixbuf (image));
395 if (image->storage_type != GTK_IMAGE_PIXMAP)
396 g_value_set_object (value, NULL);
398 g_value_set_object (value,
399 image->data.pixmap.pixmap);
402 g_value_set_object (value, image->mask);
405 if (image->storage_type != GTK_IMAGE_IMAGE)
406 g_value_set_object (value, NULL);
408 g_value_set_object (value,
409 image->data.image.image);
412 g_value_set_string (value, priv->filename);
415 if (image->storage_type != GTK_IMAGE_STOCK)
416 g_value_set_string (value, NULL);
418 g_value_set_string (value,
419 image->data.stock.stock_id);
422 if (image->storage_type != GTK_IMAGE_ICON_SET)
423 g_value_set_boxed (value, NULL);
425 g_value_set_boxed (value,
426 image->data.icon_set.icon_set);
429 g_value_set_int (value, image->icon_size);
431 case PROP_PIXEL_SIZE:
432 g_value_set_int (value, priv->pixel_size);
434 case PROP_PIXBUF_ANIMATION:
435 if (image->storage_type != GTK_IMAGE_ANIMATION)
436 g_value_set_object (value, NULL);
438 g_value_set_object (value,
439 image->data.anim.anim);
442 if (image->storage_type != GTK_IMAGE_ICON_NAME)
443 g_value_set_string (value, NULL);
445 g_value_set_string (value,
446 image->data.name.icon_name);
448 case PROP_STORAGE_TYPE:
449 g_value_set_enum (value, image->storage_type);
453 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
460 * gtk_image_new_from_pixmap:
461 * @pixmap: a #GdkPixmap, or %NULL
462 * @mask: a #GdkBitmap, or %NULL
464 * Creates a #GtkImage widget displaying @pixmap with a @mask.
465 * A #GdkPixmap is a server-side image buffer in the pixel format of the
466 * current display. The #GtkImage does not assume a reference to the
467 * pixmap or mask; you still need to unref them if you own references.
468 * #GtkImage will add its own reference rather than adopting yours.
470 * Return value: a new #GtkImage
473 gtk_image_new_from_pixmap (GdkPixmap *pixmap,
478 image = g_object_new (GTK_TYPE_IMAGE, NULL);
480 gtk_image_set_from_pixmap (image, pixmap, mask);
482 return GTK_WIDGET (image);
486 * gtk_image_new_from_image:
487 * @image: a #GdkImage, or %NULL
488 * @mask: a #GdkBitmap, or %NULL
490 * Creates a #GtkImage widget displaying a @image with a @mask.
491 * A #GdkImage is a client-side image buffer in the pixel format of the
493 * The #GtkImage does not assume a reference to the
494 * image or mask; you still need to unref them if you own references.
495 * #GtkImage will add its own reference rather than adopting yours.
497 * Return value: a new #GtkImage
500 gtk_image_new_from_image (GdkImage *gdk_image,
505 image = g_object_new (GTK_TYPE_IMAGE, NULL);
507 gtk_image_set_from_image (image, gdk_image, mask);
509 return GTK_WIDGET (image);
513 * gtk_image_new_from_file:
514 * @filename: a filename
516 * Creates a new #GtkImage displaying the file @filename. If the file
517 * isn't found or can't be loaded, the resulting #GtkImage will
518 * display a "broken image" icon. This function never returns %NULL,
519 * it always returns a valid #GtkImage widget.
521 * If the file contains an animation, the image will contain an
524 * If you need to detect failures to load the file, use
525 * gdk_pixbuf_new_from_file() to load the file yourself, then create
526 * the #GtkImage from the pixbuf. (Or for animations, use
527 * gdk_pixbuf_animation_new_from_file()).
529 * The storage type (gtk_image_get_storage_type()) of the returned
530 * image is not defined, it will be whatever is appropriate for
531 * displaying the file.
533 * Return value: a new #GtkImage
536 gtk_image_new_from_file (const gchar *filename)
540 image = g_object_new (GTK_TYPE_IMAGE, NULL);
542 gtk_image_set_from_file (image, filename);
544 return GTK_WIDGET (image);
548 * gtk_image_new_from_pixbuf:
549 * @pixbuf: a #GdkPixbuf, or %NULL
551 * Creates a new #GtkImage displaying @pixbuf.
552 * The #GtkImage does not assume a reference to the
553 * pixbuf; you still need to unref it if you own references.
554 * #GtkImage will add its own reference rather than adopting yours.
556 * Note that this function just creates an #GtkImage from the pixbuf. The
557 * #GtkImage created will not react to state changes. Should you want that, you
558 * should use gtk_image_new_from_icon_set().
560 * Return value: a new #GtkImage
563 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
567 image = g_object_new (GTK_TYPE_IMAGE, NULL);
569 gtk_image_set_from_pixbuf (image, pixbuf);
571 return GTK_WIDGET (image);
575 * gtk_image_new_from_stock:
576 * @stock_id: a stock icon name
577 * @size: a stock icon size
579 * Creates a #GtkImage displaying a stock icon. Sample stock icon
580 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. Sample stock sizes
581 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
582 * icon name isn't known, the image will be empty.
583 * You can register your own stock icon names, see
584 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
586 * Return value: a new #GtkImage displaying the stock icon
589 gtk_image_new_from_stock (const gchar *stock_id,
594 image = g_object_new (GTK_TYPE_IMAGE, NULL);
596 gtk_image_set_from_stock (image, stock_id, size);
598 return GTK_WIDGET (image);
602 * gtk_image_new_from_icon_set:
603 * @icon_set: a #GtkIconSet
604 * @size: a stock icon size
606 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
607 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
608 * this function, usually it's better to create a #GtkIconFactory, put
609 * your icon sets in the icon factory, add the icon factory to the
610 * list of default factories with gtk_icon_factory_add_default(), and
611 * then use gtk_image_new_from_stock(). This will allow themes to
612 * override the icon you ship with your application.
614 * The #GtkImage does not assume a reference to the
615 * icon set; you still need to unref it if you own references.
616 * #GtkImage will add its own reference rather than adopting yours.
619 * Return value: a new #GtkImage
622 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
627 image = g_object_new (GTK_TYPE_IMAGE, NULL);
629 gtk_image_set_from_icon_set (image, icon_set, size);
631 return GTK_WIDGET (image);
635 * gtk_image_new_from_animation:
636 * @animation: an animation
638 * Creates a #GtkImage displaying the given animation.
639 * The #GtkImage does not assume a reference to the
640 * animation; you still need to unref it if you own references.
641 * #GtkImage will add its own reference rather than adopting yours.
643 * Note that the animation frames are shown using a timeout with
644 * #G_PRIORITY_DEFAULT. When using animations to indicate busyness,
645 * keep in mind that the animation will only be shown if the main loop
646 * is not busy with something that has a higher priority.
648 * Return value: a new #GtkImage widget
651 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
655 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
657 image = g_object_new (GTK_TYPE_IMAGE, NULL);
659 gtk_image_set_from_animation (image, animation);
661 return GTK_WIDGET (image);
665 * gtk_image_new_from_icon_name:
666 * @icon_name: an icon name
667 * @size: a stock icon size
669 * Creates a #GtkImage displaying an icon from the current icon theme.
670 * If the icon name isn't known, a "broken image" icon will be
671 * displayed instead. If the current icon theme is changed, the icon
672 * will be updated appropriately.
674 * Return value: a new #GtkImage displaying the themed icon
679 gtk_image_new_from_icon_name (const gchar *icon_name,
684 image = g_object_new (GTK_TYPE_IMAGE, NULL);
686 gtk_image_set_from_icon_name (image, icon_name, size);
688 return GTK_WIDGET (image);
692 * gtk_image_set_from_pixmap:
693 * @image: a #GtkImage
694 * @pixmap: a #GdkPixmap or %NULL
695 * @mask: a #GdkBitmap or %NULL
697 * See gtk_image_new_from_pixmap() for details.
701 gtk_image_set_from_pixmap (GtkImage *image,
705 g_return_if_fail (GTK_IS_IMAGE (image));
706 g_return_if_fail (pixmap == NULL ||
707 GDK_IS_PIXMAP (pixmap));
708 g_return_if_fail (mask == NULL ||
709 GDK_IS_PIXMAP (mask));
711 g_object_freeze_notify (G_OBJECT (image));
714 g_object_ref (pixmap);
719 gtk_image_clear (image);
728 image->storage_type = GTK_IMAGE_PIXMAP;
730 image->data.pixmap.pixmap = pixmap;
732 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
734 gtk_image_update_size (image, width, height);
737 g_object_notify (G_OBJECT (image), "pixmap");
738 g_object_notify (G_OBJECT (image), "mask");
740 g_object_thaw_notify (G_OBJECT (image));
744 * gtk_image_set_from_image:
745 * @image: a #GtkImage
746 * @gdk_image: a #GdkImage or %NULL
747 * @mask: a #GdkBitmap or %NULL
749 * See gtk_image_new_from_image() for details.
753 gtk_image_set_from_image (GtkImage *image,
757 g_return_if_fail (GTK_IS_IMAGE (image));
758 g_return_if_fail (gdk_image == NULL ||
759 GDK_IS_IMAGE (gdk_image));
760 g_return_if_fail (mask == NULL ||
761 GDK_IS_PIXMAP (mask));
763 g_object_freeze_notify (G_OBJECT (image));
766 g_object_ref (gdk_image);
771 gtk_image_clear (image);
775 image->storage_type = GTK_IMAGE_IMAGE;
777 image->data.image.image = gdk_image;
780 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
784 /* Clean up the mask if gdk_image was NULL */
786 g_object_unref (mask);
789 g_object_notify (G_OBJECT (image), "image");
790 g_object_notify (G_OBJECT (image), "mask");
792 g_object_thaw_notify (G_OBJECT (image));
796 * gtk_image_set_from_file:
797 * @image: a #GtkImage
798 * @filename: a filename or %NULL
800 * See gtk_image_new_from_file() for details.
804 gtk_image_set_from_file (GtkImage *image,
805 const gchar *filename)
807 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
808 GdkPixbufAnimation *anim;
810 g_return_if_fail (GTK_IS_IMAGE (image));
812 g_object_freeze_notify (G_OBJECT (image));
814 gtk_image_clear (image);
816 if (filename == NULL)
818 priv->filename = NULL;
819 g_object_thaw_notify (G_OBJECT (image));
823 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
827 gtk_image_set_from_stock (image,
828 GTK_STOCK_MISSING_IMAGE,
829 GTK_ICON_SIZE_BUTTON);
830 g_object_thaw_notify (G_OBJECT (image));
834 /* We could just unconditionally set_from_animation,
835 * but it's nicer for memory if we toss the animation
836 * if it's just a single pixbuf
839 if (gdk_pixbuf_animation_is_static_image (anim))
840 gtk_image_set_from_pixbuf (image,
841 gdk_pixbuf_animation_get_static_image (anim));
843 gtk_image_set_from_animation (image, anim);
845 g_object_unref (anim);
847 priv->filename = g_strdup (filename);
849 g_object_thaw_notify (G_OBJECT (image));
853 * gtk_image_set_from_pixbuf:
854 * @image: a #GtkImage
855 * @pixbuf: a #GdkPixbuf or %NULL
857 * See gtk_image_new_from_pixbuf() for details.
861 gtk_image_set_from_pixbuf (GtkImage *image,
864 g_return_if_fail (GTK_IS_IMAGE (image));
865 g_return_if_fail (pixbuf == NULL ||
866 GDK_IS_PIXBUF (pixbuf));
868 g_object_freeze_notify (G_OBJECT (image));
871 g_object_ref (pixbuf);
873 gtk_image_clear (image);
877 image->storage_type = GTK_IMAGE_PIXBUF;
879 image->data.pixbuf.pixbuf = pixbuf;
881 gtk_image_update_size (image,
882 gdk_pixbuf_get_width (pixbuf),
883 gdk_pixbuf_get_height (pixbuf));
886 g_object_notify (G_OBJECT (image), "pixbuf");
888 g_object_thaw_notify (G_OBJECT (image));
892 * gtk_image_set_from_stock:
893 * @image: a #GtkImage
894 * @stock_id: a stock icon name
895 * @size: a stock icon size
897 * See gtk_image_new_from_stock() for details.
901 gtk_image_set_from_stock (GtkImage *image,
902 const gchar *stock_id,
907 g_return_if_fail (GTK_IS_IMAGE (image));
909 g_object_freeze_notify (G_OBJECT (image));
911 /* in case stock_id == image->data.stock.stock_id */
912 new_id = g_strdup (stock_id);
914 gtk_image_clear (image);
918 image->storage_type = GTK_IMAGE_STOCK;
920 image->data.stock.stock_id = new_id;
921 image->icon_size = size;
923 /* Size is demand-computed in size request method
924 * if we're a stock image, since changing the
925 * style impacts the size request
929 g_object_notify (G_OBJECT (image), "stock");
930 g_object_notify (G_OBJECT (image), "icon-size");
932 g_object_thaw_notify (G_OBJECT (image));
936 * gtk_image_set_from_icon_set:
937 * @image: a #GtkImage
938 * @icon_set: a #GtkIconSet
939 * @size: a stock icon size
941 * See gtk_image_new_from_icon_set() for details.
945 gtk_image_set_from_icon_set (GtkImage *image,
946 GtkIconSet *icon_set,
949 g_return_if_fail (GTK_IS_IMAGE (image));
951 g_object_freeze_notify (G_OBJECT (image));
954 gtk_icon_set_ref (icon_set);
956 gtk_image_clear (image);
960 image->storage_type = GTK_IMAGE_ICON_SET;
962 image->data.icon_set.icon_set = icon_set;
963 image->icon_size = size;
965 /* Size is demand-computed in size request method
966 * if we're an icon set
970 g_object_notify (G_OBJECT (image), "icon-set");
971 g_object_notify (G_OBJECT (image), "icon-size");
973 g_object_thaw_notify (G_OBJECT (image));
977 * gtk_image_set_from_animation:
978 * @image: a #GtkImage
979 * @animation: the #GdkPixbufAnimation
981 * Causes the #GtkImage to display the given animation (or display
982 * nothing, if you set the animation to %NULL).
985 gtk_image_set_from_animation (GtkImage *image,
986 GdkPixbufAnimation *animation)
988 g_return_if_fail (GTK_IS_IMAGE (image));
989 g_return_if_fail (animation == NULL ||
990 GDK_IS_PIXBUF_ANIMATION (animation));
992 g_object_freeze_notify (G_OBJECT (image));
995 g_object_ref (animation);
997 gtk_image_clear (image);
999 if (animation != NULL)
1001 image->storage_type = GTK_IMAGE_ANIMATION;
1003 image->data.anim.anim = animation;
1004 image->data.anim.frame_timeout = 0;
1005 image->data.anim.iter = NULL;
1007 gtk_image_update_size (image,
1008 gdk_pixbuf_animation_get_width (animation),
1009 gdk_pixbuf_animation_get_height (animation));
1012 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1014 g_object_thaw_notify (G_OBJECT (image));
1018 * gtk_image_set_from_icon_name:
1019 * @image: a #GtkImage
1020 * @icon_name: an icon name
1021 * @size: an icon size
1023 * See gtk_image_new_from_icon_name() for details.
1028 gtk_image_set_from_icon_name (GtkImage *image,
1029 const gchar *icon_name,
1034 g_return_if_fail (GTK_IS_IMAGE (image));
1036 g_object_freeze_notify (G_OBJECT (image));
1038 /* in case icon_name == image->data.name.icon_name */
1039 new_name = g_strdup (icon_name);
1041 gtk_image_clear (image);
1045 image->storage_type = GTK_IMAGE_ICON_NAME;
1047 image->data.name.icon_name = new_name;
1048 image->icon_size = size;
1050 /* Size is demand-computed in size request method
1051 * if we're a icon theme image, since changing the
1052 * style impacts the size request
1056 g_object_notify (G_OBJECT (image), "icon-name");
1057 g_object_notify (G_OBJECT (image), "icon-size");
1059 g_object_thaw_notify (G_OBJECT (image));
1063 * gtk_image_get_storage_type:
1064 * @image: a #GtkImage
1066 * Gets the type of representation being used by the #GtkImage
1067 * to store image data. If the #GtkImage has no image data,
1068 * the return value will be %GTK_IMAGE_EMPTY.
1070 * Return value: image representation being used
1073 gtk_image_get_storage_type (GtkImage *image)
1075 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1077 return image->storage_type;
1081 * gtk_image_get_pixmap:
1082 * @image: a #GtkImage
1083 * @pixmap: location to store the pixmap, or %NULL
1084 * @mask: location to store the mask, or %NULL
1086 * Gets the pixmap and mask being displayed by the #GtkImage.
1087 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1088 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1089 * The caller of this function does not own a reference to the
1090 * returned pixmap and mask.
1094 gtk_image_get_pixmap (GtkImage *image,
1098 g_return_if_fail (GTK_IS_IMAGE (image));
1099 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1100 image->storage_type == GTK_IMAGE_EMPTY);
1103 *pixmap = image->data.pixmap.pixmap;
1106 *mask = image->mask;
1110 * gtk_image_get_image:
1111 * @image: a #GtkImage
1112 * @gdk_image: return location for a #GtkImage
1113 * @mask: return location for a #GdkBitmap
1115 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1116 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1117 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1118 * The caller of this function does not own a reference to the
1119 * returned image and mask.
1122 gtk_image_get_image (GtkImage *image,
1123 GdkImage **gdk_image,
1126 g_return_if_fail (GTK_IS_IMAGE (image));
1127 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1128 image->storage_type == GTK_IMAGE_EMPTY);
1131 *gdk_image = image->data.image.image;
1134 *mask = image->mask;
1138 * gtk_image_get_pixbuf:
1139 * @image: a #GtkImage
1142 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1143 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1144 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1145 * The caller of this function does not own a reference to the
1148 * Return value: the displayed pixbuf, or %NULL if the image is empty
1151 gtk_image_get_pixbuf (GtkImage *image)
1153 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1154 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1155 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1157 if (image->storage_type == GTK_IMAGE_EMPTY)
1158 image->data.pixbuf.pixbuf = NULL;
1160 return image->data.pixbuf.pixbuf;
1164 * gtk_image_get_stock:
1165 * @image: a #GtkImage
1166 * @stock_id: place to store a stock icon name
1167 * @size: place to store a stock icon size
1169 * Gets the stock icon name and size being displayed by the #GtkImage.
1170 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1171 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1172 * The returned string is owned by the #GtkImage and should not
1177 gtk_image_get_stock (GtkImage *image,
1181 g_return_if_fail (GTK_IS_IMAGE (image));
1182 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1183 image->storage_type == GTK_IMAGE_EMPTY);
1185 if (image->storage_type == GTK_IMAGE_EMPTY)
1186 image->data.stock.stock_id = NULL;
1189 *stock_id = image->data.stock.stock_id;
1192 *size = image->icon_size;
1196 * gtk_image_get_icon_set:
1197 * @image: a #GtkImage
1198 * @icon_set: location to store a #GtkIconSet
1199 * @size: location to store a stock icon size
1201 * Gets the icon set and size being displayed by the #GtkImage.
1202 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1203 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1207 gtk_image_get_icon_set (GtkImage *image,
1208 GtkIconSet **icon_set,
1211 g_return_if_fail (GTK_IS_IMAGE (image));
1212 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1213 image->storage_type == GTK_IMAGE_EMPTY);
1216 *icon_set = image->data.icon_set.icon_set;
1219 *size = image->icon_size;
1223 * gtk_image_get_animation:
1224 * @image: a #GtkImage
1227 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1228 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1229 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1230 * The caller of this function does not own a reference to the
1231 * returned animation.
1233 * Return value: the displayed animation, or %NULL if the image is empty
1236 gtk_image_get_animation (GtkImage *image)
1238 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1239 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1240 image->storage_type == GTK_IMAGE_EMPTY,
1243 if (image->storage_type == GTK_IMAGE_EMPTY)
1244 image->data.anim.anim = NULL;
1246 return image->data.anim.anim;
1250 * gtk_image_get_icon_name:
1251 * @image: a #GtkImage
1252 * @icon_name: place to store an icon name
1253 * @size: place to store an icon size
1255 * Gets the icon name and size being displayed by the #GtkImage.
1256 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1257 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1258 * The returned string is owned by the #GtkImage and should not
1264 gtk_image_get_icon_name (GtkImage *image,
1265 G_CONST_RETURN gchar **icon_name,
1268 g_return_if_fail (GTK_IS_IMAGE (image));
1269 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1270 image->storage_type == GTK_IMAGE_EMPTY);
1272 if (image->storage_type == GTK_IMAGE_EMPTY)
1273 image->data.name.icon_name = NULL;
1276 *icon_name = image->data.name.icon_name;
1279 *size = image->icon_size;
1285 * Creates a new empty #GtkImage widget.
1287 * Return value: a newly created #GtkImage widget.
1290 gtk_image_new (void)
1292 return g_object_new (GTK_TYPE_IMAGE, NULL);
1296 gtk_image_set (GtkImage *image,
1300 g_return_if_fail (GTK_IS_IMAGE (image));
1302 gtk_image_set_from_image (image, val, mask);
1306 gtk_image_get (GtkImage *image,
1310 g_return_if_fail (GTK_IS_IMAGE (image));
1312 gtk_image_get_image (image, val, mask);
1316 gtk_image_reset_anim_iter (GtkImage *image)
1318 if (image->storage_type == GTK_IMAGE_ANIMATION)
1320 /* Reset the animation */
1322 if (image->data.anim.frame_timeout)
1324 g_source_remove (image->data.anim.frame_timeout);
1325 image->data.anim.frame_timeout = 0;
1328 if (image->data.anim.iter)
1330 g_object_unref (image->data.anim.iter);
1331 image->data.anim.iter = NULL;
1337 gtk_image_unmap (GtkWidget *widget)
1339 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1341 if (GTK_WIDGET_CLASS (gtk_image_parent_class)->unmap)
1342 GTK_WIDGET_CLASS (gtk_image_parent_class)->unmap (widget);
1346 gtk_image_unrealize (GtkWidget *widget)
1348 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1350 if (GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize)
1351 GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize (widget);
1355 animation_timeout (gpointer data)
1359 GDK_THREADS_ENTER ();
1361 image = GTK_IMAGE (data);
1363 image->data.anim.frame_timeout = 0;
1365 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1367 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1368 image->data.anim.frame_timeout =
1369 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1373 gtk_widget_queue_draw (GTK_WIDGET (image));
1375 if (GTK_WIDGET_DRAWABLE (image))
1376 gdk_window_process_updates (GTK_WIDGET (image)->window, TRUE);
1378 GDK_THREADS_LEAVE ();
1384 icon_theme_changed (GtkImage *image)
1386 if (image->storage_type == GTK_IMAGE_ICON_NAME)
1388 if (image->data.name.pixbuf)
1389 g_object_unref (image->data.name.pixbuf);
1390 image->data.name.pixbuf = NULL;
1392 gtk_widget_queue_draw (GTK_WIDGET (image));
1397 ensure_pixbuf_for_icon_name (GtkImage *image)
1399 GtkImagePrivate *priv;
1401 GtkIconTheme *icon_theme;
1402 GtkSettings *settings;
1404 gint *sizes, *s, dist;
1405 GError *error = NULL;
1407 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1409 priv = GTK_IMAGE_GET_PRIVATE (image);
1410 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1411 icon_theme = gtk_icon_theme_get_for_screen (screen);
1412 settings = gtk_settings_get_for_screen (screen);
1413 if (image->data.name.pixbuf == NULL)
1415 if (priv->pixel_size != -1)
1417 width = height = priv->pixel_size;
1419 else if (!gtk_icon_size_lookup_for_settings (settings,
1423 if (image->icon_size == -1)
1425 /* Find an available size close to 48 */
1426 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1428 width = height = 48;
1429 for (s = sizes; *s; s++)
1433 width = height = 48;
1440 width = height = *s;
1448 width = height = *s;
1457 g_warning ("Invalid icon size %d\n", image->icon_size);
1458 width = height = 24;
1461 image->data.name.pixbuf =
1462 gtk_icon_theme_load_icon (icon_theme,
1463 image->data.name.icon_name,
1464 MIN (width, height), 0, &error);
1465 if (image->data.name.pixbuf == NULL)
1467 g_error_free (error);
1468 image->data.name.pixbuf =
1469 gtk_widget_render_icon (GTK_WIDGET (image),
1470 GTK_STOCK_MISSING_IMAGE,
1478 * Like gdk_rectangle_intersect (dest, src, dest), but make
1479 * sure that the origin of dest is moved by an "even" offset.
1480 * If necessary grow the intersection by one row or column
1483 * This is necessary since we can't pass alignment information
1484 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1485 * thus we have to makesure that the subimages are properly aligned.
1488 rectangle_intersect_even (GdkRectangle *src,
1496 isect = gdk_rectangle_intersect (dest, src, dest);
1498 if ((dest->x - x + dest->y - y) % 2 != 0)
1516 gtk_image_expose (GtkWidget *widget,
1517 GdkEventExpose *event)
1519 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1520 g_return_val_if_fail (event != NULL, FALSE);
1522 if (GTK_WIDGET_MAPPED (widget) &&
1523 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1527 GdkRectangle area, image_bound;
1529 gint x, y, mask_x, mask_y;
1532 gboolean needs_state_transform;
1534 image = GTK_IMAGE (widget);
1535 misc = GTK_MISC (widget);
1539 /* For stock items and icon sets, we lazily calculate
1540 * the size; we might get here between a queue_resize()
1541 * and size_request() if something explicitely forces
1544 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1545 gtk_image_calc_size (image);
1547 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1550 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1551 xalign = misc->xalign;
1553 xalign = 1.0 - misc->xalign;
1555 x = floor (widget->allocation.x + misc->xpad
1556 + ((widget->allocation.width - widget->requisition.width) * xalign));
1557 y = floor (widget->allocation.y + misc->ypad
1558 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
1564 image_bound.width = 0;
1565 image_bound.height = 0;
1569 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1571 switch (image->storage_type)
1573 case GTK_IMAGE_PIXMAP:
1575 gdk_drawable_get_size (image->data.pixmap.pixmap,
1577 &image_bound.height);
1578 if (rectangle_intersect_even (&area, &image_bound) &&
1579 needs_state_transform)
1581 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1582 image->data.pixmap.pixmap,
1583 gtk_widget_get_colormap (widget),
1584 image_bound.x - x, image_bound.y - y,
1587 image_bound.height);
1595 case GTK_IMAGE_IMAGE:
1597 image_bound.width = image->data.image.image->width;
1598 image_bound.height = image->data.image.image->height;
1600 if (rectangle_intersect_even (&area, &image_bound) &&
1601 needs_state_transform)
1603 pixbuf = gdk_pixbuf_get_from_image (NULL,
1604 image->data.image.image,
1605 gtk_widget_get_colormap (widget),
1606 image_bound.x - x, image_bound.y - y,
1609 image_bound.height);
1616 case GTK_IMAGE_PIXBUF:
1617 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1618 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1620 if (rectangle_intersect_even (&area, &image_bound) &&
1621 needs_state_transform)
1623 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1624 image_bound.x - x, image_bound.y - y,
1625 image_bound.width, image_bound.height);
1632 pixbuf = image->data.pixbuf.pixbuf;
1633 g_object_ref (pixbuf);
1637 case GTK_IMAGE_STOCK:
1638 pixbuf = gtk_widget_render_icon (widget,
1639 image->data.stock.stock_id,
1644 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1645 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1649 needs_state_transform = FALSE;
1652 case GTK_IMAGE_ICON_SET:
1654 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1656 gtk_widget_get_direction (widget),
1657 GTK_WIDGET_STATE (widget),
1664 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1665 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1669 needs_state_transform = FALSE;
1672 case GTK_IMAGE_ANIMATION:
1674 if (image->data.anim.iter == NULL)
1676 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1678 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1679 image->data.anim.frame_timeout =
1680 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1685 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1686 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1688 /* don't advance the anim iter here, or we could get frame changes between two
1689 * exposes of different areas.
1692 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1693 g_object_ref (pixbuf);
1697 case GTK_IMAGE_ICON_NAME:
1698 ensure_pixbuf_for_icon_name (image);
1699 pixbuf = image->data.name.pixbuf;
1702 g_object_ref (pixbuf);
1703 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1704 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1708 case GTK_IMAGE_EMPTY:
1709 g_assert_not_reached ();
1715 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1716 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1719 if (rectangle_intersect_even (&area, &image_bound))
1723 if (needs_state_transform)
1725 GtkIconSource *source;
1726 GdkPixbuf *rendered;
1728 source = gtk_icon_source_new ();
1729 gtk_icon_source_set_pixbuf (source, pixbuf);
1730 /* The size here is arbitrary; since size isn't
1731 * wildcarded in the souce, it isn't supposed to be
1732 * scaled by the engine function
1734 gtk_icon_source_set_size (source,
1735 GTK_ICON_SIZE_SMALL_TOOLBAR);
1736 gtk_icon_source_set_size_wildcarded (source, FALSE);
1738 rendered = gtk_style_render_icon (widget->style,
1740 gtk_widget_get_direction (widget),
1741 GTK_WIDGET_STATE (widget),
1747 gtk_icon_source_free (source);
1749 g_object_unref (pixbuf);
1755 gdk_draw_pixbuf (widget->window,
1756 widget->style->black_gc,
1764 GDK_RGB_DITHER_NORMAL,
1770 switch (image->storage_type)
1772 case GTK_IMAGE_PIXMAP:
1773 gdk_draw_drawable (widget->window,
1774 widget->style->black_gc,
1775 image->data.pixmap.pixmap,
1776 image_bound.x - x, image_bound.y - y,
1777 image_bound.x, image_bound.y,
1778 image_bound.width, image_bound.height);
1781 case GTK_IMAGE_IMAGE:
1782 gdk_draw_image (widget->window,
1783 widget->style->black_gc,
1784 image->data.image.image,
1785 image_bound.x - x, image_bound.y - y,
1786 image_bound.x, image_bound.y,
1787 image_bound.width, image_bound.height);
1790 case GTK_IMAGE_PIXBUF:
1791 case GTK_IMAGE_STOCK:
1792 case GTK_IMAGE_ICON_SET:
1793 case GTK_IMAGE_ANIMATION:
1794 case GTK_IMAGE_ICON_NAME:
1795 case GTK_IMAGE_EMPTY:
1796 g_assert_not_reached ();
1800 } /* if rectangle intersects */
1804 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1805 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1809 g_object_unref (pixbuf);
1811 } /* if widget is drawable */
1817 gtk_image_reset (GtkImage *image)
1819 GtkImagePrivate *priv;
1821 priv = GTK_IMAGE_GET_PRIVATE (image);
1823 g_object_freeze_notify (G_OBJECT (image));
1825 if (image->storage_type != GTK_IMAGE_EMPTY)
1826 g_object_notify (G_OBJECT (image), "storage-type");
1830 g_object_unref (image->mask);
1832 g_object_notify (G_OBJECT (image), "mask");
1835 if (image->icon_size != DEFAULT_ICON_SIZE)
1837 image->icon_size = DEFAULT_ICON_SIZE;
1838 g_object_notify (G_OBJECT (image), "icon-size");
1841 switch (image->storage_type)
1843 case GTK_IMAGE_PIXMAP:
1845 if (image->data.pixmap.pixmap)
1846 g_object_unref (image->data.pixmap.pixmap);
1847 image->data.pixmap.pixmap = NULL;
1849 g_object_notify (G_OBJECT (image), "pixmap");
1853 case GTK_IMAGE_IMAGE:
1855 if (image->data.image.image)
1856 g_object_unref (image->data.image.image);
1857 image->data.image.image = NULL;
1859 g_object_notify (G_OBJECT (image), "image");
1863 case GTK_IMAGE_PIXBUF:
1865 if (image->data.pixbuf.pixbuf)
1866 g_object_unref (image->data.pixbuf.pixbuf);
1868 g_object_notify (G_OBJECT (image), "pixbuf");
1872 case GTK_IMAGE_STOCK:
1874 g_free (image->data.stock.stock_id);
1876 image->data.stock.stock_id = NULL;
1878 g_object_notify (G_OBJECT (image), "stock");
1881 case GTK_IMAGE_ICON_SET:
1882 if (image->data.icon_set.icon_set)
1883 gtk_icon_set_unref (image->data.icon_set.icon_set);
1884 image->data.icon_set.icon_set = NULL;
1886 g_object_notify (G_OBJECT (image), "icon-set");
1889 case GTK_IMAGE_ANIMATION:
1890 gtk_image_reset_anim_iter (image);
1892 if (image->data.anim.anim)
1893 g_object_unref (image->data.anim.anim);
1894 image->data.anim.anim = NULL;
1896 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1900 case GTK_IMAGE_ICON_NAME:
1901 if (image->data.name.icon_name)
1902 g_free (image->data.name.icon_name);
1903 image->data.name.icon_name = NULL;
1904 if (image->data.name.pixbuf)
1905 g_object_unref (image->data.name.pixbuf);
1906 image->data.name.pixbuf = NULL;
1908 g_object_notify (G_OBJECT (image), "icon-name");
1912 case GTK_IMAGE_EMPTY:
1920 g_free (priv->filename);
1921 priv->filename = NULL;
1922 g_object_notify (G_OBJECT (image), "file");
1925 image->storage_type = GTK_IMAGE_EMPTY;
1927 memset (&image->data, '\0', sizeof (image->data));
1929 g_object_thaw_notify (G_OBJECT (image));
1934 * @image: a #GtkImage
1936 * Resets the image to be empty.
1941 gtk_image_clear (GtkImage *image)
1943 gtk_image_reset (image);
1945 gtk_image_update_size (image, 0, 0);
1949 gtk_image_calc_size (GtkImage *image)
1951 GtkWidget *widget = GTK_WIDGET (image);
1952 GdkPixbuf *pixbuf = NULL;
1954 /* We update stock/icon set on every size request, because
1955 * the theme could have affected the size; for other kinds of
1956 * image, we just update the requisition when the image data
1959 switch (image->storage_type)
1961 case GTK_IMAGE_STOCK:
1962 pixbuf = gtk_widget_render_icon (widget,
1963 image->data.stock.stock_id,
1968 case GTK_IMAGE_ICON_SET:
1969 pixbuf = gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1971 gtk_widget_get_direction (widget),
1972 GTK_WIDGET_STATE (widget),
1977 case GTK_IMAGE_ICON_NAME:
1978 ensure_pixbuf_for_icon_name (image);
1979 pixbuf = image->data.name.pixbuf;
1980 if (pixbuf) g_object_ref (pixbuf);
1988 widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
1989 widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
1991 g_object_unref (pixbuf);
1996 gtk_image_size_request (GtkWidget *widget,
1997 GtkRequisition *requisition)
2001 image = GTK_IMAGE (widget);
2003 gtk_image_calc_size (image);
2005 /* Chain up to default that simply reads current requisition */
2006 GTK_WIDGET_CLASS (gtk_image_parent_class)->size_request (widget, requisition);
2010 gtk_image_style_set (GtkWidget *widget,
2011 GtkStyle *prev_style)
2015 image = GTK_IMAGE (widget);
2017 if (GTK_WIDGET_CLASS (gtk_image_parent_class)->style_set)
2018 GTK_WIDGET_CLASS (gtk_image_parent_class)->style_set (widget, prev_style);
2020 icon_theme_changed (image);
2024 gtk_image_screen_changed (GtkWidget *widget,
2025 GdkScreen *prev_screen)
2029 image = GTK_IMAGE (widget);
2031 if (GTK_WIDGET_CLASS (gtk_image_parent_class)->screen_changed)
2032 GTK_WIDGET_CLASS (gtk_image_parent_class)->screen_changed (widget, prev_screen);
2034 icon_theme_changed (image);
2039 gtk_image_update_size (GtkImage *image,
2043 GTK_WIDGET (image)->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
2044 GTK_WIDGET (image)->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
2046 if (GTK_WIDGET_VISIBLE (image))
2047 gtk_widget_queue_resize (GTK_WIDGET (image));
2052 * gtk_image_set_pixel_size:
2053 * @image: a #GtkImage
2054 * @pixel_size: the new pixel size
2056 * Sets the pixel size to use for named icons. If the pixel size is set
2057 * to a value != -1, it is used instead of the icon size set by
2058 * gtk_image_set_from_icon_name().
2063 gtk_image_set_pixel_size (GtkImage *image,
2066 GtkImagePrivate *priv;
2068 g_return_if_fail (GTK_IS_IMAGE (image));
2070 priv = GTK_IMAGE_GET_PRIVATE (image);
2072 if (priv->pixel_size != pixel_size)
2074 priv->pixel_size = pixel_size;
2076 if (image->storage_type == GTK_IMAGE_ICON_NAME)
2078 if (image->data.name.pixbuf)
2080 g_object_unref (image->data.name.pixbuf);
2081 image->data.name.pixbuf = NULL;
2084 gtk_image_update_size (image, pixel_size, pixel_size);
2087 g_object_notify (G_OBJECT (image), "pixel-size");
2092 * gtk_image_get_pixel_size:
2093 * @image: a #GtkImage
2095 * Gets the pixel size used for named icons.
2097 * Returns: the pixel size used for named icons.
2102 gtk_image_get_pixel_size (GtkImage *image)
2104 GtkImagePrivate *priv;
2106 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2108 priv = GTK_IMAGE_GET_PRIVATE (image);
2110 return priv->pixel_size;
2115 #undef gtk_image_new_from_file
2118 gtk_image_new_from_file (const gchar *filename)
2120 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2123 retval = gtk_image_new_from_file_utf8 (utf8_filename);
2125 g_free (utf8_filename);
2130 #undef gtk_image_set_from_file
2133 gtk_image_set_from_file (GtkImage *image,
2134 const gchar *filename)
2136 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2138 gtk_image_set_from_file_utf8 (image, utf8_filename);
2140 g_free (utf8_filename);
2145 #define __GTK_IMAGE_C__
2146 #include "gtkaliasdef.c"