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
47 #define GTK_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_IMAGE, GtkImagePrivate))
50 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
52 static void gtk_image_class_init (GtkImageClass *klass);
53 static void gtk_image_init (GtkImage *image);
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_clear (GtkImage *image);
66 static void gtk_image_reset (GtkImage *image);
67 static void gtk_image_calc_size (GtkImage *image);
69 static void gtk_image_update_size (GtkImage *image,
73 static void gtk_image_set_property (GObject *object,
77 static void gtk_image_get_property (GObject *object,
82 static void icon_theme_changed (GtkImage *image);
84 static gpointer parent_class;
98 PROP_PIXBUF_ANIMATION,
104 gtk_image_get_type (void)
106 static GType image_type = 0;
110 static const GTypeInfo image_info =
112 sizeof (GtkImageClass),
113 NULL, /* base_init */
114 NULL, /* base_finalize */
115 (GClassInitFunc) gtk_image_class_init,
116 NULL, /* class_finalize */
117 NULL, /* class_data */
120 (GInstanceInitFunc) gtk_image_init,
123 image_type = g_type_register_static (GTK_TYPE_MISC, "GtkImage",
131 gtk_image_class_init (GtkImageClass *class)
133 GObjectClass *gobject_class;
134 GtkObjectClass *object_class;
135 GtkWidgetClass *widget_class;
137 parent_class = g_type_class_peek_parent (class);
139 gobject_class = G_OBJECT_CLASS (class);
141 gobject_class->set_property = gtk_image_set_property;
142 gobject_class->get_property = gtk_image_get_property;
144 object_class = GTK_OBJECT_CLASS (class);
146 object_class->destroy = gtk_image_destroy;
148 widget_class = GTK_WIDGET_CLASS (class);
150 widget_class->expose_event = gtk_image_expose;
151 widget_class->size_request = gtk_image_size_request;
152 widget_class->unmap = gtk_image_unmap;
153 widget_class->unrealize = gtk_image_unrealize;
154 widget_class->style_set = gtk_image_style_set;
155 widget_class->screen_changed = gtk_image_screen_changed;
157 g_object_class_install_property (gobject_class,
159 g_param_spec_object ("pixbuf",
161 P_("A GdkPixbuf to display"),
163 GTK_PARAM_READWRITE));
165 g_object_class_install_property (gobject_class,
167 g_param_spec_object ("pixmap",
169 P_("A GdkPixmap to display"),
171 GTK_PARAM_READWRITE));
173 g_object_class_install_property (gobject_class,
175 g_param_spec_object ("image",
177 P_("A GdkImage to display"),
179 GTK_PARAM_READWRITE));
181 g_object_class_install_property (gobject_class,
183 g_param_spec_object ("mask",
185 P_("Mask bitmap to use with GdkImage or GdkPixmap"),
187 GTK_PARAM_READWRITE));
189 g_object_class_install_property (gobject_class,
191 g_param_spec_string ("file",
193 P_("Filename to load and display"),
195 GTK_PARAM_WRITABLE));
198 g_object_class_install_property (gobject_class,
200 g_param_spec_string ("stock",
202 P_("Stock ID for a stock image to display"),
204 GTK_PARAM_READWRITE));
206 g_object_class_install_property (gobject_class,
208 g_param_spec_boxed ("icon-set",
210 P_("Icon set to display"),
212 GTK_PARAM_READWRITE));
214 g_object_class_install_property (gobject_class,
216 g_param_spec_int ("icon-size",
218 P_("Symbolic size to use for stock icon, icon set or named icon"),
221 GTK_PARAM_READWRITE));
223 * GtkImage:pixel-size:
225 * The :pixel-size property can be used to specify a fixed size
226 * overriding the :icon-size property for images of type
227 * %GTK_IMAGE_ICON_NAME.
231 g_object_class_install_property (gobject_class,
233 g_param_spec_int ("pixel-size",
235 P_("Pixel size to use for named icon"),
238 GTK_PARAM_READWRITE));
240 g_object_class_install_property (gobject_class,
241 PROP_PIXBUF_ANIMATION,
242 g_param_spec_object ("pixbuf-animation",
244 P_("GdkPixbufAnimation to display"),
245 GDK_TYPE_PIXBUF_ANIMATION,
246 GTK_PARAM_READWRITE));
249 * GtkImage:icon-name:
251 * The name of the icon in the icon theme. If the icon theme is
252 * changed, the image will be updated automatically.
256 g_object_class_install_property (gobject_class,
258 g_param_spec_string ("icon-name",
260 P_("The name of the icon from the icon theme"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (gobject_class,
266 g_param_spec_enum ("storage-type",
268 P_("The representation being used for image data"),
271 GTK_PARAM_READABLE));
273 g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
277 gtk_image_init (GtkImage *image)
279 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
281 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
283 image->storage_type = GTK_IMAGE_EMPTY;
284 image->icon_size = DEFAULT_ICON_SIZE;
287 priv->pixel_size = -1;
291 gtk_image_destroy (GtkObject *object)
293 GtkImage *image = GTK_IMAGE (object);
295 gtk_image_clear (image);
297 GTK_OBJECT_CLASS (parent_class)->destroy (object);
301 gtk_image_set_property (GObject *object,
307 GtkImagePrivate *priv;
309 image = GTK_IMAGE (object);
310 priv = GTK_IMAGE_GET_PRIVATE (image);
315 gtk_image_set_from_pixbuf (image,
316 g_value_get_object (value));
319 gtk_image_set_from_pixmap (image,
320 g_value_get_object (value),
324 gtk_image_set_from_image (image,
325 g_value_get_object (value),
329 if (image->storage_type == GTK_IMAGE_PIXMAP)
330 gtk_image_set_from_pixmap (image,
331 image->data.pixmap.pixmap,
332 g_value_get_object (value));
333 else if (image->storage_type == GTK_IMAGE_IMAGE)
334 gtk_image_set_from_image (image,
335 image->data.image.image,
336 g_value_get_object (value));
341 mask = g_value_get_object (value);
346 gtk_image_reset (image);
352 gtk_image_set_from_file (image,
353 g_value_get_string (value));
356 gtk_image_set_from_stock (image, g_value_get_string (value),
360 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
364 if (image->storage_type == GTK_IMAGE_STOCK)
365 gtk_image_set_from_stock (image,
366 image->data.stock.stock_id,
367 g_value_get_int (value));
368 else if (image->storage_type == GTK_IMAGE_ICON_SET)
369 gtk_image_set_from_icon_set (image,
370 image->data.icon_set.icon_set,
371 g_value_get_int (value));
372 else if (image->storage_type == GTK_IMAGE_ICON_NAME)
373 gtk_image_set_from_icon_name (image,
374 image->data.name.icon_name,
375 g_value_get_int (value));
377 /* Save to be used when STOCK or ICON_SET property comes in */
378 image->icon_size = g_value_get_int (value);
380 case PROP_PIXEL_SIZE:
381 gtk_image_set_pixel_size (image, g_value_get_int (value));
383 case PROP_PIXBUF_ANIMATION:
384 gtk_image_set_from_animation (image,
385 g_value_get_object (value));
388 gtk_image_set_from_icon_name (image, g_value_get_string (value),
393 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
399 gtk_image_get_property (GObject *object,
405 GtkImagePrivate *priv;
407 image = GTK_IMAGE (object);
408 priv = GTK_IMAGE_GET_PRIVATE (image);
410 /* The "getter" functions whine if you try to get the wrong
411 * storage type. This function is instead robust against that,
412 * so that GUI builders don't have to jump through hoops
419 if (image->storage_type != GTK_IMAGE_PIXBUF)
420 g_value_set_object (value, NULL);
422 g_value_set_object (value,
423 gtk_image_get_pixbuf (image));
426 if (image->storage_type != GTK_IMAGE_PIXMAP)
427 g_value_set_object (value, NULL);
429 g_value_set_object (value,
430 image->data.pixmap.pixmap);
433 g_value_set_object (value, image->mask);
436 if (image->storage_type != GTK_IMAGE_IMAGE)
437 g_value_set_object (value, NULL);
439 g_value_set_object (value,
440 image->data.image.image);
443 if (image->storage_type != GTK_IMAGE_STOCK)
444 g_value_set_string (value, NULL);
446 g_value_set_string (value,
447 image->data.stock.stock_id);
450 if (image->storage_type != GTK_IMAGE_ICON_SET)
451 g_value_set_boxed (value, NULL);
453 g_value_set_boxed (value,
454 image->data.icon_set.icon_set);
457 g_value_set_int (value, image->icon_size);
459 case PROP_PIXEL_SIZE:
460 g_value_set_int (value, priv->pixel_size);
462 case PROP_PIXBUF_ANIMATION:
463 if (image->storage_type != GTK_IMAGE_ANIMATION)
464 g_value_set_object (value, NULL);
466 g_value_set_object (value,
467 image->data.anim.anim);
470 if (image->storage_type != GTK_IMAGE_ICON_NAME)
471 g_value_set_string (value, NULL);
473 g_value_set_string (value,
474 image->data.name.icon_name);
476 case PROP_STORAGE_TYPE:
477 g_value_set_enum (value, image->storage_type);
481 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
488 * gtk_image_new_from_pixmap:
489 * @pixmap: a #GdkPixmap, or %NULL
490 * @mask: a #GdkBitmap, or %NULL
492 * Creates a #GtkImage widget displaying @pixmap with a @mask.
493 * A #GdkPixmap is a server-side image buffer in the pixel format of the
494 * current display. The #GtkImage does not assume a reference to the
495 * pixmap or mask; you still need to unref them if you own references.
496 * #GtkImage will add its own reference rather than adopting yours.
498 * Return value: a new #GtkImage
501 gtk_image_new_from_pixmap (GdkPixmap *pixmap,
506 image = g_object_new (GTK_TYPE_IMAGE, NULL);
508 gtk_image_set_from_pixmap (image, pixmap, mask);
510 return GTK_WIDGET (image);
514 * gtk_image_new_from_image:
515 * @image: a #GdkImage, or %NULL
516 * @mask: a #GdkBitmap, or %NULL
518 * Creates a #GtkImage widget displaying a @image with a @mask.
519 * A #GdkImage is a client-side image buffer in the pixel format of the
521 * The #GtkImage does not assume a reference to the
522 * image or mask; you still need to unref them if you own references.
523 * #GtkImage will add its own reference rather than adopting yours.
525 * Return value: a new #GtkImage
528 gtk_image_new_from_image (GdkImage *gdk_image,
533 image = g_object_new (GTK_TYPE_IMAGE, NULL);
535 gtk_image_set_from_image (image, gdk_image, mask);
537 return GTK_WIDGET (image);
541 * gtk_image_new_from_file:
542 * @filename: a filename
544 * Creates a new #GtkImage displaying the file @filename. If the file
545 * isn't found or can't be loaded, the resulting #GtkImage will
546 * display a "broken image" icon. This function never returns %NULL,
547 * it always returns a valid #GtkImage widget.
549 * If the file contains an animation, the image will contain an
552 * If you need to detect failures to load the file, use
553 * gdk_pixbuf_new_from_file() to load the file yourself, then create
554 * the #GtkImage from the pixbuf. (Or for animations, use
555 * gdk_pixbuf_animation_new_from_file()).
557 * The storage type (gtk_image_get_storage_type()) of the returned
558 * image is not defined, it will be whatever is appropriate for
559 * displaying the file.
561 * Return value: a new #GtkImage
564 gtk_image_new_from_file (const gchar *filename)
568 image = g_object_new (GTK_TYPE_IMAGE, NULL);
570 gtk_image_set_from_file (image, filename);
572 return GTK_WIDGET (image);
576 * gtk_image_new_from_pixbuf:
577 * @pixbuf: a #GdkPixbuf, or %NULL
579 * Creates a new #GtkImage displaying @pixbuf.
580 * The #GtkImage does not assume a reference to the
581 * pixbuf; you still need to unref it if you own references.
582 * #GtkImage will add its own reference rather than adopting yours.
584 * Note that this function just creates an #GtkImage from the pixbuf. The
585 * #GtkImage created will not react to state changes. Should you want that, you
586 * should use gtk_image_new_from_icon_set().
588 * Return value: a new #GtkImage
591 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
595 image = g_object_new (GTK_TYPE_IMAGE, NULL);
597 gtk_image_set_from_pixbuf (image, pixbuf);
599 return GTK_WIDGET (image);
603 * gtk_image_new_from_stock:
604 * @stock_id: a stock icon name
605 * @size: a stock icon size
607 * Creates a #GtkImage displaying a stock icon. Sample stock icon
608 * names are #GTK_STOCK_OPEN, #GTK_STOCK_EXIT. Sample stock sizes
609 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
610 * icon name isn't known, the image will be empty.
611 * You can register your own stock icon names, see
612 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
614 * Return value: a new #GtkImage displaying the stock icon
617 gtk_image_new_from_stock (const gchar *stock_id,
622 image = g_object_new (GTK_TYPE_IMAGE, NULL);
624 gtk_image_set_from_stock (image, stock_id, size);
626 return GTK_WIDGET (image);
630 * gtk_image_new_from_icon_set:
631 * @icon_set: a #GtkIconSet
632 * @size: a stock icon size
634 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
635 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
636 * this function, usually it's better to create a #GtkIconFactory, put
637 * your icon sets in the icon factory, add the icon factory to the
638 * list of default factories with gtk_icon_factory_add_default(), and
639 * then use gtk_image_new_from_stock(). This will allow themes to
640 * override the icon you ship with your application.
642 * The #GtkImage does not assume a reference to the
643 * icon set; you still need to unref it if you own references.
644 * #GtkImage will add its own reference rather than adopting yours.
647 * Return value: a new #GtkImage
650 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
655 image = g_object_new (GTK_TYPE_IMAGE, NULL);
657 gtk_image_set_from_icon_set (image, icon_set, size);
659 return GTK_WIDGET (image);
663 * gtk_image_new_from_animation:
664 * @animation: an animation
666 * Creates a #GtkImage displaying the given animation.
667 * The #GtkImage does not assume a reference to the
668 * animation; you still need to unref it if you own references.
669 * #GtkImage will add its own reference rather than adopting yours.
671 * Return value: a new #GtkImage widget
674 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
678 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
680 image = g_object_new (GTK_TYPE_IMAGE, NULL);
682 gtk_image_set_from_animation (image, animation);
684 return GTK_WIDGET (image);
688 * gtk_image_new_from_icon_name:
689 * @icon_name: an icon name
690 * @size: a stock icon size
692 * Creates a #GtkImage displaying an icon from the current icon theme.
693 * If the icon name isn't known, a "broken image" icon will be
694 * displayed instead. If the current icon theme is changed, the icon
695 * will be updated appropriately.
697 * Return value: a new #GtkImage displaying the themed icon
702 gtk_image_new_from_icon_name (const gchar *icon_name,
707 image = g_object_new (GTK_TYPE_IMAGE, NULL);
709 gtk_image_set_from_icon_name (image, icon_name, size);
711 return GTK_WIDGET (image);
715 * gtk_image_set_from_pixmap:
716 * @image: a #GtkImage
717 * @pixmap: a #GdkPixmap or %NULL
718 * @mask: a #GdkBitmap or %NULL
720 * See gtk_image_new_from_pixmap() for details.
724 gtk_image_set_from_pixmap (GtkImage *image,
728 g_return_if_fail (GTK_IS_IMAGE (image));
729 g_return_if_fail (pixmap == NULL ||
730 GDK_IS_PIXMAP (pixmap));
731 g_return_if_fail (mask == NULL ||
732 GDK_IS_PIXMAP (mask));
734 g_object_freeze_notify (G_OBJECT (image));
737 g_object_ref (pixmap);
742 gtk_image_reset (image);
751 image->storage_type = GTK_IMAGE_PIXMAP;
753 image->data.pixmap.pixmap = pixmap;
755 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
757 gtk_image_update_size (image, width, height);
760 g_object_notify (G_OBJECT (image), "pixmap");
761 g_object_notify (G_OBJECT (image), "mask");
763 g_object_thaw_notify (G_OBJECT (image));
767 * gtk_image_set_from_image:
768 * @image: a #GtkImage
769 * @gdk_image: a #GdkImage or %NULL
770 * @mask: a #GdkBitmap or %NULL
772 * See gtk_image_new_from_image() for details.
776 gtk_image_set_from_image (GtkImage *image,
780 g_return_if_fail (GTK_IS_IMAGE (image));
781 g_return_if_fail (gdk_image == NULL ||
782 GDK_IS_IMAGE (gdk_image));
783 g_return_if_fail (mask == NULL ||
784 GDK_IS_PIXMAP (mask));
786 g_object_freeze_notify (G_OBJECT (image));
789 g_object_ref (gdk_image);
794 gtk_image_reset (image);
798 image->storage_type = GTK_IMAGE_IMAGE;
800 image->data.image.image = gdk_image;
803 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
807 /* Clean up the mask if gdk_image was NULL */
809 g_object_unref (mask);
812 g_object_notify (G_OBJECT (image), "image");
813 g_object_notify (G_OBJECT (image), "mask");
815 g_object_thaw_notify (G_OBJECT (image));
819 * gtk_image_set_from_file:
820 * @image: a #GtkImage
821 * @filename: a filename or %NULL
823 * See gtk_image_new_from_file() for details.
827 gtk_image_set_from_file (GtkImage *image,
828 const gchar *filename)
830 GdkPixbufAnimation *anim;
832 g_return_if_fail (GTK_IS_IMAGE (image));
834 g_object_freeze_notify (G_OBJECT (image));
836 gtk_image_reset (image);
838 if (filename == NULL)
840 g_object_thaw_notify (G_OBJECT (image));
844 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
848 gtk_image_set_from_stock (image,
849 GTK_STOCK_MISSING_IMAGE,
850 GTK_ICON_SIZE_BUTTON);
851 g_object_thaw_notify (G_OBJECT (image));
855 /* We could just unconditionally set_from_animation,
856 * but it's nicer for memory if we toss the animation
857 * if it's just a single pixbuf
860 if (gdk_pixbuf_animation_is_static_image (anim))
862 gtk_image_set_from_pixbuf (image,
863 gdk_pixbuf_animation_get_static_image (anim));
867 gtk_image_set_from_animation (image, anim);
870 g_object_unref (anim);
872 g_object_thaw_notify (G_OBJECT (image));
876 * gtk_image_set_from_pixbuf:
877 * @image: a #GtkImage
878 * @pixbuf: a #GdkPixbuf or %NULL
880 * See gtk_image_new_from_pixbuf() for details.
884 gtk_image_set_from_pixbuf (GtkImage *image,
887 g_return_if_fail (GTK_IS_IMAGE (image));
888 g_return_if_fail (pixbuf == NULL ||
889 GDK_IS_PIXBUF (pixbuf));
891 g_object_freeze_notify (G_OBJECT (image));
894 g_object_ref (pixbuf);
896 gtk_image_reset (image);
900 image->storage_type = GTK_IMAGE_PIXBUF;
902 image->data.pixbuf.pixbuf = pixbuf;
904 gtk_image_update_size (image,
905 gdk_pixbuf_get_width (pixbuf),
906 gdk_pixbuf_get_height (pixbuf));
909 g_object_notify (G_OBJECT (image), "pixbuf");
911 g_object_thaw_notify (G_OBJECT (image));
915 * gtk_image_set_from_stock:
916 * @image: a #GtkImage
917 * @stock_id: a stock icon name
918 * @size: a stock icon size
920 * See gtk_image_new_from_stock() for details.
924 gtk_image_set_from_stock (GtkImage *image,
925 const gchar *stock_id,
930 g_return_if_fail (GTK_IS_IMAGE (image));
932 g_object_freeze_notify (G_OBJECT (image));
934 /* in case stock_id == image->data.stock.stock_id */
935 new_id = g_strdup (stock_id);
937 gtk_image_reset (image);
941 image->storage_type = GTK_IMAGE_STOCK;
943 image->data.stock.stock_id = new_id;
944 image->icon_size = size;
946 /* Size is demand-computed in size request method
947 * if we're a stock image, since changing the
948 * style impacts the size request
952 g_object_notify (G_OBJECT (image), "stock");
953 g_object_notify (G_OBJECT (image), "icon-size");
955 g_object_thaw_notify (G_OBJECT (image));
959 * gtk_image_set_from_icon_set:
960 * @image: a #GtkImage
961 * @icon_set: a #GtkIconSet
962 * @size: a stock icon size
964 * See gtk_image_new_from_icon_set() for details.
968 gtk_image_set_from_icon_set (GtkImage *image,
969 GtkIconSet *icon_set,
972 g_return_if_fail (GTK_IS_IMAGE (image));
974 g_object_freeze_notify (G_OBJECT (image));
977 gtk_icon_set_ref (icon_set);
979 gtk_image_reset (image);
983 image->storage_type = GTK_IMAGE_ICON_SET;
985 image->data.icon_set.icon_set = icon_set;
986 image->icon_size = size;
988 /* Size is demand-computed in size request method
989 * if we're an icon set
993 g_object_notify (G_OBJECT (image), "icon-set");
994 g_object_notify (G_OBJECT (image), "icon-size");
996 g_object_thaw_notify (G_OBJECT (image));
1000 * gtk_image_set_from_animation:
1001 * @image: a #GtkImage
1002 * @animation: the #GdkPixbufAnimation
1004 * Causes the #GtkImage to display the given animation (or display
1005 * nothing, if you set the animation to %NULL).
1008 gtk_image_set_from_animation (GtkImage *image,
1009 GdkPixbufAnimation *animation)
1011 g_return_if_fail (GTK_IS_IMAGE (image));
1012 g_return_if_fail (animation == NULL ||
1013 GDK_IS_PIXBUF_ANIMATION (animation));
1015 g_object_freeze_notify (G_OBJECT (image));
1018 g_object_ref (animation);
1020 gtk_image_reset (image);
1022 if (animation != NULL)
1024 image->storage_type = GTK_IMAGE_ANIMATION;
1026 image->data.anim.anim = animation;
1027 image->data.anim.frame_timeout = 0;
1028 image->data.anim.iter = NULL;
1030 gtk_image_update_size (image,
1031 gdk_pixbuf_animation_get_width (animation),
1032 gdk_pixbuf_animation_get_height (animation));
1035 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1037 g_object_thaw_notify (G_OBJECT (image));
1041 * gtk_image_set_from_icon_name:
1042 * @image: a #GtkImage
1043 * @icon_name: an icon name
1044 * @size: an icon size
1046 * See gtk_image_new_from_icon_name() for details.
1051 gtk_image_set_from_icon_name (GtkImage *image,
1052 const gchar *icon_name,
1057 g_return_if_fail (GTK_IS_IMAGE (image));
1059 g_object_freeze_notify (G_OBJECT (image));
1061 /* in case icon_name == image->data.name.icon_name */
1062 new_name = g_strdup (icon_name);
1064 gtk_image_reset (image);
1068 image->storage_type = GTK_IMAGE_ICON_NAME;
1070 image->data.name.icon_name = new_name;
1071 image->icon_size = size;
1073 /* Size is demand-computed in size request method
1074 * if we're a icon theme image, since changing the
1075 * style impacts the size request
1079 g_object_notify (G_OBJECT (image), "icon-name");
1080 g_object_notify (G_OBJECT (image), "icon-size");
1082 g_object_thaw_notify (G_OBJECT (image));
1086 * gtk_image_get_storage_type:
1087 * @image: a #GtkImage
1089 * Gets the type of representation being used by the #GtkImage
1090 * to store image data. If the #GtkImage has no image data,
1091 * the return value will be %GTK_IMAGE_EMPTY.
1093 * Return value: image representation being used
1096 gtk_image_get_storage_type (GtkImage *image)
1098 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1100 return image->storage_type;
1104 * gtk_image_get_pixmap:
1105 * @image: a #GtkImage
1106 * @pixmap: location to store the pixmap, or %NULL
1107 * @mask: location to store the mask, or %NULL
1109 * Gets the pixmap and mask being displayed by the #GtkImage.
1110 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1111 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1112 * The caller of this function does not own a reference to the
1113 * returned pixmap and mask.
1117 gtk_image_get_pixmap (GtkImage *image,
1121 g_return_if_fail (GTK_IS_IMAGE (image));
1122 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1123 image->storage_type == GTK_IMAGE_EMPTY);
1126 *pixmap = image->data.pixmap.pixmap;
1129 *mask = image->mask;
1133 * gtk_image_get_image:
1134 * @image: a #GtkImage
1135 * @gdk_image: return location for a #GtkImage
1136 * @mask: return location for a #GdkBitmap
1138 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1139 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1140 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1141 * The caller of this function does not own a reference to the
1142 * returned image and mask.
1145 gtk_image_get_image (GtkImage *image,
1146 GdkImage **gdk_image,
1149 g_return_if_fail (GTK_IS_IMAGE (image));
1150 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1151 image->storage_type == GTK_IMAGE_EMPTY);
1154 *gdk_image = image->data.image.image;
1157 *mask = image->mask;
1161 * gtk_image_get_pixbuf:
1162 * @image: a #GtkImage
1165 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1166 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1167 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1168 * The caller of this function does not own a reference to the
1171 * Return value: the displayed pixbuf, or %NULL if the image is empty
1174 gtk_image_get_pixbuf (GtkImage *image)
1176 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1177 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1178 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1180 if (image->storage_type == GTK_IMAGE_EMPTY)
1181 image->data.pixbuf.pixbuf = NULL;
1183 return image->data.pixbuf.pixbuf;
1187 * gtk_image_get_stock:
1188 * @image: a #GtkImage
1189 * @stock_id: place to store a stock icon name
1190 * @size: place to store a stock icon size
1192 * Gets the stock icon name and size being displayed by the #GtkImage.
1193 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1194 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1195 * The returned string is owned by the #GtkImage and should not
1200 gtk_image_get_stock (GtkImage *image,
1204 g_return_if_fail (GTK_IS_IMAGE (image));
1205 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1206 image->storage_type == GTK_IMAGE_EMPTY);
1208 if (image->storage_type == GTK_IMAGE_EMPTY)
1209 image->data.stock.stock_id = NULL;
1212 *stock_id = image->data.stock.stock_id;
1215 *size = image->icon_size;
1219 * gtk_image_get_icon_set:
1220 * @image: a #GtkImage
1221 * @icon_set: location to store a #GtkIconSet
1222 * @size: location to store a stock icon size
1224 * Gets the icon set and size being displayed by the #GtkImage.
1225 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1226 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1230 gtk_image_get_icon_set (GtkImage *image,
1231 GtkIconSet **icon_set,
1234 g_return_if_fail (GTK_IS_IMAGE (image));
1235 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1236 image->storage_type == GTK_IMAGE_EMPTY);
1239 *icon_set = image->data.icon_set.icon_set;
1242 *size = image->icon_size;
1246 * gtk_image_get_animation:
1247 * @image: a #GtkImage
1250 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1251 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1252 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1253 * The caller of this function does not own a reference to the
1254 * returned animation.
1256 * Return value: the displayed animation, or %NULL if the image is empty
1259 gtk_image_get_animation (GtkImage *image)
1261 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1262 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1263 image->storage_type == GTK_IMAGE_EMPTY,
1266 if (image->storage_type == GTK_IMAGE_EMPTY)
1267 image->data.anim.anim = NULL;
1269 return image->data.anim.anim;
1273 * gtk_image_get_icon_name:
1274 * @image: a #GtkImage
1275 * @icon_name: place to store an icon name
1276 * @size: place to store an icon size
1278 * Gets the icon name and size being displayed by the #GtkImage.
1279 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1280 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1281 * The returned string is owned by the #GtkImage and should not
1287 gtk_image_get_icon_name (GtkImage *image,
1288 G_CONST_RETURN gchar **icon_name,
1291 g_return_if_fail (GTK_IS_IMAGE (image));
1292 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1293 image->storage_type == GTK_IMAGE_EMPTY);
1295 if (image->storage_type == GTK_IMAGE_EMPTY)
1296 image->data.name.icon_name = NULL;
1299 *icon_name = image->data.name.icon_name;
1302 *size = image->icon_size;
1308 * Creates a new empty #GtkImage widget.
1310 * Return value: a newly created #GtkImage widget.
1313 gtk_image_new (void)
1315 return g_object_new (GTK_TYPE_IMAGE, NULL);
1319 gtk_image_set (GtkImage *image,
1323 g_return_if_fail (GTK_IS_IMAGE (image));
1325 gtk_image_set_from_image (image, val, mask);
1329 gtk_image_get (GtkImage *image,
1333 g_return_if_fail (GTK_IS_IMAGE (image));
1335 gtk_image_get_image (image, val, mask);
1339 gtk_image_reset_anim_iter (GtkImage *image)
1341 if (image->storage_type == GTK_IMAGE_ANIMATION)
1343 /* Reset the animation */
1345 if (image->data.anim.frame_timeout)
1347 g_source_remove (image->data.anim.frame_timeout);
1348 image->data.anim.frame_timeout = 0;
1351 if (image->data.anim.iter)
1353 g_object_unref (image->data.anim.iter);
1354 image->data.anim.iter = NULL;
1360 gtk_image_unmap (GtkWidget *widget)
1362 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1364 if (GTK_WIDGET_CLASS (parent_class)->unmap)
1365 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1369 gtk_image_unrealize (GtkWidget *widget)
1371 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1373 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1374 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
1378 animation_timeout (gpointer data)
1382 GDK_THREADS_ENTER ();
1384 image = GTK_IMAGE (data);
1386 image->data.anim.frame_timeout = 0;
1388 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1390 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1391 image->data.anim.frame_timeout =
1392 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1396 gtk_widget_queue_draw (GTK_WIDGET (image));
1398 GDK_THREADS_LEAVE ();
1404 icon_theme_changed (GtkImage *image)
1406 if (image->data.name.pixbuf)
1407 g_object_unref (image->data.name.pixbuf);
1408 image->data.name.pixbuf = NULL;
1410 gtk_widget_queue_draw (GTK_WIDGET (image));
1414 ensure_pixbuf_for_icon_name (GtkImage *image)
1416 GtkImagePrivate *priv;
1418 GtkIconTheme *icon_theme;
1419 GtkSettings *settings;
1421 gint *sizes, *s, dist;
1422 GError *error = NULL;
1424 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1426 priv = GTK_IMAGE_GET_PRIVATE (image);
1427 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1428 icon_theme = gtk_icon_theme_get_for_screen (screen);
1429 settings = gtk_settings_get_for_screen (screen);
1430 if (image->data.name.pixbuf == NULL)
1432 if (priv->pixel_size != -1)
1434 width = height = priv->pixel_size;
1436 else if (!gtk_icon_size_lookup_for_settings (settings,
1440 if (image->icon_size == -1)
1442 /* Find an available size close to 48 */
1443 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1445 width = height = 48;
1446 for (s = sizes; *s; s++)
1450 width = height = 48;
1457 width = height = *s;
1465 width = height = *s;
1474 g_warning ("Invalid icon size %d\n", image->icon_size);
1475 width = height = 24;
1478 image->data.name.pixbuf =
1479 gtk_icon_theme_load_icon (icon_theme,
1480 image->data.name.icon_name,
1481 MIN (width, height), 0, &error);
1482 if (image->data.name.pixbuf == NULL)
1484 g_error_free (error);
1485 image->data.name.pixbuf =
1486 gtk_widget_render_icon (GTK_WIDGET (image),
1487 GTK_STOCK_MISSING_IMAGE,
1495 * Like gdk_rectangle_intersect (dest, src, dest), but make
1496 * sure that the origin of dest is moved by an "even" offset.
1497 * If necessary grow the intersection by one row or column
1500 * This is necessary since we can't pass alignment information
1501 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1502 * thus we have to makesure that the subimages are properly aligned.
1505 rectangle_intersect_even (GdkRectangle *src,
1513 isect = gdk_rectangle_intersect (dest, src, dest);
1515 if ((dest->x - x + dest->y - y) % 2 != 0)
1533 gtk_image_expose (GtkWidget *widget,
1534 GdkEventExpose *event)
1536 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1537 g_return_val_if_fail (event != NULL, FALSE);
1539 if (GTK_WIDGET_MAPPED (widget) &&
1540 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1544 GdkRectangle area, image_bound;
1546 gint x, y, mask_x, mask_y;
1549 gboolean needs_state_transform;
1551 image = GTK_IMAGE (widget);
1552 misc = GTK_MISC (widget);
1556 /* For stock items and icon sets, we lazily calculate
1557 * the size; we might get here between a queue_resize()
1558 * and size_request() if something explicitely forces
1561 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1562 gtk_image_calc_size (image);
1564 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1567 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1568 xalign = misc->xalign;
1570 xalign = 1.0 - misc->xalign;
1572 x = floor (widget->allocation.x + misc->xpad
1573 + ((widget->allocation.width - widget->requisition.width) * xalign)
1575 y = floor (widget->allocation.y + misc->ypad
1576 + ((widget->allocation.height - widget->requisition.height) * misc->yalign)
1583 image_bound.width = 0;
1584 image_bound.height = 0;
1588 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1590 switch (image->storage_type)
1592 case GTK_IMAGE_PIXMAP:
1594 gdk_drawable_get_size (image->data.pixmap.pixmap,
1596 &image_bound.height);
1597 if (rectangle_intersect_even (&area, &image_bound) &&
1598 needs_state_transform)
1600 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1601 image->data.pixmap.pixmap,
1602 gtk_widget_get_colormap (widget),
1603 image_bound.x - x, image_bound.y - y,
1606 image_bound.height);
1614 case GTK_IMAGE_IMAGE:
1616 image_bound.width = image->data.image.image->width;
1617 image_bound.height = image->data.image.image->height;
1619 if (rectangle_intersect_even (&area, &image_bound) &&
1620 needs_state_transform)
1622 pixbuf = gdk_pixbuf_get_from_image (NULL,
1623 image->data.image.image,
1624 gtk_widget_get_colormap (widget),
1625 image_bound.x - x, image_bound.y - y,
1628 image_bound.height);
1635 case GTK_IMAGE_PIXBUF:
1636 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1637 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1639 if (rectangle_intersect_even (&area, &image_bound) &&
1640 needs_state_transform)
1642 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1643 image_bound.x - x, image_bound.y - y,
1644 image_bound.width, image_bound.height);
1651 pixbuf = image->data.pixbuf.pixbuf;
1652 g_object_ref (pixbuf);
1656 case GTK_IMAGE_STOCK:
1657 pixbuf = gtk_widget_render_icon (widget,
1658 image->data.stock.stock_id,
1663 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1664 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1668 needs_state_transform = FALSE;
1671 case GTK_IMAGE_ICON_SET:
1673 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1675 gtk_widget_get_direction (widget),
1676 GTK_WIDGET_STATE (widget),
1683 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1684 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1688 needs_state_transform = FALSE;
1691 case GTK_IMAGE_ANIMATION:
1693 if (image->data.anim.iter == NULL)
1695 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1697 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1698 image->data.anim.frame_timeout =
1699 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1704 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1705 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1707 /* don't advance the anim iter here, or we could get frame changes between two
1708 * exposes of different areas.
1711 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1712 g_object_ref (pixbuf);
1716 case GTK_IMAGE_ICON_NAME:
1717 ensure_pixbuf_for_icon_name (image);
1718 pixbuf = image->data.name.pixbuf;
1721 g_object_ref (pixbuf);
1722 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1723 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1727 case GTK_IMAGE_EMPTY:
1728 g_assert_not_reached ();
1734 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1735 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1738 if (rectangle_intersect_even (&area, &image_bound))
1742 if (needs_state_transform)
1744 GtkIconSource *source;
1745 GdkPixbuf *rendered;
1747 source = gtk_icon_source_new ();
1748 gtk_icon_source_set_pixbuf (source, pixbuf);
1749 /* The size here is arbitrary; since size isn't
1750 * wildcarded in the souce, it isn't supposed to be
1751 * scaled by the engine function
1753 gtk_icon_source_set_size (source,
1754 GTK_ICON_SIZE_SMALL_TOOLBAR);
1755 gtk_icon_source_set_size_wildcarded (source, FALSE);
1757 rendered = gtk_style_render_icon (widget->style,
1759 gtk_widget_get_direction (widget),
1760 GTK_WIDGET_STATE (widget),
1766 gtk_icon_source_free (source);
1768 g_object_unref (pixbuf);
1774 gdk_draw_pixbuf (widget->window,
1775 widget->style->black_gc,
1783 GDK_RGB_DITHER_NORMAL,
1786 g_object_unref (pixbuf);
1792 switch (image->storage_type)
1794 case GTK_IMAGE_PIXMAP:
1795 gdk_draw_drawable (widget->window,
1796 widget->style->black_gc,
1797 image->data.pixmap.pixmap,
1798 image_bound.x - x, image_bound.y - y,
1799 image_bound.x, image_bound.y,
1800 image_bound.width, image_bound.height);
1803 case GTK_IMAGE_IMAGE:
1804 gdk_draw_image (widget->window,
1805 widget->style->black_gc,
1806 image->data.image.image,
1807 image_bound.x - x, image_bound.y - y,
1808 image_bound.x, image_bound.y,
1809 image_bound.width, image_bound.height);
1812 case GTK_IMAGE_PIXBUF:
1813 case GTK_IMAGE_STOCK:
1814 case GTK_IMAGE_ICON_SET:
1815 case GTK_IMAGE_ANIMATION:
1816 case GTK_IMAGE_ICON_NAME:
1817 case GTK_IMAGE_EMPTY:
1818 g_assert_not_reached ();
1822 } /* if rectangle intersects */
1826 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1827 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1830 } /* if widget is drawable */
1836 gtk_image_clear (GtkImage *image)
1838 g_object_freeze_notify (G_OBJECT (image));
1840 if (image->storage_type != GTK_IMAGE_EMPTY)
1841 g_object_notify (G_OBJECT (image), "storage-type");
1845 g_object_unref (image->mask);
1847 g_object_notify (G_OBJECT (image), "mask");
1850 if (image->icon_size != DEFAULT_ICON_SIZE)
1852 image->icon_size = DEFAULT_ICON_SIZE;
1853 g_object_notify (G_OBJECT (image), "icon-size");
1856 switch (image->storage_type)
1858 case GTK_IMAGE_PIXMAP:
1860 if (image->data.pixmap.pixmap)
1861 g_object_unref (image->data.pixmap.pixmap);
1862 image->data.pixmap.pixmap = NULL;
1864 g_object_notify (G_OBJECT (image), "pixmap");
1868 case GTK_IMAGE_IMAGE:
1870 if (image->data.image.image)
1871 g_object_unref (image->data.image.image);
1872 image->data.image.image = NULL;
1874 g_object_notify (G_OBJECT (image), "image");
1878 case GTK_IMAGE_PIXBUF:
1880 if (image->data.pixbuf.pixbuf)
1881 g_object_unref (image->data.pixbuf.pixbuf);
1883 g_object_notify (G_OBJECT (image), "pixbuf");
1887 case GTK_IMAGE_STOCK:
1889 g_free (image->data.stock.stock_id);
1891 image->data.stock.stock_id = NULL;
1893 g_object_notify (G_OBJECT (image), "stock");
1896 case GTK_IMAGE_ICON_SET:
1897 if (image->data.icon_set.icon_set)
1898 gtk_icon_set_unref (image->data.icon_set.icon_set);
1899 image->data.icon_set.icon_set = NULL;
1901 g_object_notify (G_OBJECT (image), "icon-set");
1904 case GTK_IMAGE_ANIMATION:
1905 gtk_image_reset_anim_iter (image);
1907 if (image->data.anim.anim)
1908 g_object_unref (image->data.anim.anim);
1909 image->data.anim.anim = NULL;
1911 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1915 case GTK_IMAGE_ICON_NAME:
1916 if (image->data.name.icon_name)
1917 g_free (image->data.name.icon_name);
1918 image->data.name.icon_name = NULL;
1919 if (image->data.name.pixbuf)
1920 g_object_unref (image->data.name.pixbuf);
1921 image->data.name.pixbuf = NULL;
1923 g_object_notify (G_OBJECT (image), "icon-name");
1927 case GTK_IMAGE_EMPTY:
1933 image->storage_type = GTK_IMAGE_EMPTY;
1935 memset (&image->data, '\0', sizeof (image->data));
1937 g_object_thaw_notify (G_OBJECT (image));
1941 gtk_image_reset (GtkImage *image)
1943 gtk_image_clear (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 (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 (parent_class)->style_set)
2018 GTK_WIDGET_CLASS (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 (parent_class)->screen_changed)
2032 GTK_WIDGET_CLASS (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"