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, I_("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,
312 image = GTK_IMAGE (object);
317 gtk_image_set_from_pixbuf (image,
318 g_value_get_object (value));
321 gtk_image_set_from_pixmap (image,
322 g_value_get_object (value),
326 gtk_image_set_from_image (image,
327 g_value_get_object (value),
331 if (image->storage_type == GTK_IMAGE_PIXMAP)
332 gtk_image_set_from_pixmap (image,
333 image->data.pixmap.pixmap,
334 g_value_get_object (value));
335 else if (image->storage_type == GTK_IMAGE_IMAGE)
336 gtk_image_set_from_image (image,
337 image->data.image.image,
338 g_value_get_object (value));
343 mask = g_value_get_object (value);
348 gtk_image_reset (image);
354 gtk_image_set_from_file (image, g_value_get_string (value));
357 gtk_image_set_from_stock (image, g_value_get_string (value),
361 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
365 if (image->storage_type == GTK_IMAGE_STOCK)
366 gtk_image_set_from_stock (image,
367 image->data.stock.stock_id,
368 g_value_get_int (value));
369 else if (image->storage_type == GTK_IMAGE_ICON_SET)
370 gtk_image_set_from_icon_set (image,
371 image->data.icon_set.icon_set,
372 g_value_get_int (value));
373 else if (image->storage_type == GTK_IMAGE_ICON_NAME)
374 gtk_image_set_from_icon_name (image,
375 image->data.name.icon_name,
376 g_value_get_int (value));
378 /* Save to be used when STOCK or ICON_SET property comes in */
379 image->icon_size = g_value_get_int (value);
381 case PROP_PIXEL_SIZE:
382 gtk_image_set_pixel_size (image, g_value_get_int (value));
384 case PROP_PIXBUF_ANIMATION:
385 gtk_image_set_from_animation (image,
386 g_value_get_object (value));
389 gtk_image_set_from_icon_name (image, g_value_get_string (value),
394 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
400 gtk_image_get_property (GObject *object,
406 GtkImagePrivate *priv;
408 image = GTK_IMAGE (object);
409 priv = GTK_IMAGE_GET_PRIVATE (image);
411 /* The "getter" functions whine if you try to get the wrong
412 * storage type. This function is instead robust against that,
413 * so that GUI builders don't have to jump through hoops
420 if (image->storage_type != GTK_IMAGE_PIXBUF)
421 g_value_set_object (value, NULL);
423 g_value_set_object (value,
424 gtk_image_get_pixbuf (image));
427 if (image->storage_type != GTK_IMAGE_PIXMAP)
428 g_value_set_object (value, NULL);
430 g_value_set_object (value,
431 image->data.pixmap.pixmap);
434 g_value_set_object (value, image->mask);
437 if (image->storage_type != GTK_IMAGE_IMAGE)
438 g_value_set_object (value, NULL);
440 g_value_set_object (value,
441 image->data.image.image);
444 g_value_set_string (value, priv->filename);
447 if (image->storage_type != GTK_IMAGE_STOCK)
448 g_value_set_string (value, NULL);
450 g_value_set_string (value,
451 image->data.stock.stock_id);
454 if (image->storage_type != GTK_IMAGE_ICON_SET)
455 g_value_set_boxed (value, NULL);
457 g_value_set_boxed (value,
458 image->data.icon_set.icon_set);
461 g_value_set_int (value, image->icon_size);
463 case PROP_PIXEL_SIZE:
464 g_value_set_int (value, priv->pixel_size);
466 case PROP_PIXBUF_ANIMATION:
467 if (image->storage_type != GTK_IMAGE_ANIMATION)
468 g_value_set_object (value, NULL);
470 g_value_set_object (value,
471 image->data.anim.anim);
474 if (image->storage_type != GTK_IMAGE_ICON_NAME)
475 g_value_set_string (value, NULL);
477 g_value_set_string (value,
478 image->data.name.icon_name);
480 case PROP_STORAGE_TYPE:
481 g_value_set_enum (value, image->storage_type);
485 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
492 * gtk_image_new_from_pixmap:
493 * @pixmap: a #GdkPixmap, or %NULL
494 * @mask: a #GdkBitmap, or %NULL
496 * Creates a #GtkImage widget displaying @pixmap with a @mask.
497 * A #GdkPixmap is a server-side image buffer in the pixel format of the
498 * current display. The #GtkImage does not assume a reference to the
499 * pixmap or mask; you still need to unref them if you own references.
500 * #GtkImage will add its own reference rather than adopting yours.
502 * Return value: a new #GtkImage
505 gtk_image_new_from_pixmap (GdkPixmap *pixmap,
510 image = g_object_new (GTK_TYPE_IMAGE, NULL);
512 gtk_image_set_from_pixmap (image, pixmap, mask);
514 return GTK_WIDGET (image);
518 * gtk_image_new_from_image:
519 * @image: a #GdkImage, or %NULL
520 * @mask: a #GdkBitmap, or %NULL
522 * Creates a #GtkImage widget displaying a @image with a @mask.
523 * A #GdkImage is a client-side image buffer in the pixel format of the
525 * The #GtkImage does not assume a reference to the
526 * image or mask; you still need to unref them if you own references.
527 * #GtkImage will add its own reference rather than adopting yours.
529 * Return value: a new #GtkImage
532 gtk_image_new_from_image (GdkImage *gdk_image,
537 image = g_object_new (GTK_TYPE_IMAGE, NULL);
539 gtk_image_set_from_image (image, gdk_image, mask);
541 return GTK_WIDGET (image);
545 * gtk_image_new_from_file:
546 * @filename: a filename
548 * Creates a new #GtkImage displaying the file @filename. If the file
549 * isn't found or can't be loaded, the resulting #GtkImage will
550 * display a "broken image" icon. This function never returns %NULL,
551 * it always returns a valid #GtkImage widget.
553 * If the file contains an animation, the image will contain an
556 * If you need to detect failures to load the file, use
557 * gdk_pixbuf_new_from_file() to load the file yourself, then create
558 * the #GtkImage from the pixbuf. (Or for animations, use
559 * gdk_pixbuf_animation_new_from_file()).
561 * The storage type (gtk_image_get_storage_type()) of the returned
562 * image is not defined, it will be whatever is appropriate for
563 * displaying the file.
565 * Return value: a new #GtkImage
568 gtk_image_new_from_file (const gchar *filename)
572 image = g_object_new (GTK_TYPE_IMAGE, NULL);
574 gtk_image_set_from_file (image, filename);
576 return GTK_WIDGET (image);
580 * gtk_image_new_from_pixbuf:
581 * @pixbuf: a #GdkPixbuf, or %NULL
583 * Creates a new #GtkImage displaying @pixbuf.
584 * The #GtkImage does not assume a reference to the
585 * pixbuf; you still need to unref it if you own references.
586 * #GtkImage will add its own reference rather than adopting yours.
588 * Note that this function just creates an #GtkImage from the pixbuf. The
589 * #GtkImage created will not react to state changes. Should you want that, you
590 * should use gtk_image_new_from_icon_set().
592 * Return value: a new #GtkImage
595 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
599 image = g_object_new (GTK_TYPE_IMAGE, NULL);
601 gtk_image_set_from_pixbuf (image, pixbuf);
603 return GTK_WIDGET (image);
607 * gtk_image_new_from_stock:
608 * @stock_id: a stock icon name
609 * @size: a stock icon size
611 * Creates a #GtkImage displaying a stock icon. Sample stock icon
612 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. Sample stock sizes
613 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
614 * icon name isn't known, the image will be empty.
615 * You can register your own stock icon names, see
616 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
618 * Return value: a new #GtkImage displaying the stock icon
621 gtk_image_new_from_stock (const gchar *stock_id,
626 image = g_object_new (GTK_TYPE_IMAGE, NULL);
628 gtk_image_set_from_stock (image, stock_id, size);
630 return GTK_WIDGET (image);
634 * gtk_image_new_from_icon_set:
635 * @icon_set: a #GtkIconSet
636 * @size: a stock icon size
638 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
639 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
640 * this function, usually it's better to create a #GtkIconFactory, put
641 * your icon sets in the icon factory, add the icon factory to the
642 * list of default factories with gtk_icon_factory_add_default(), and
643 * then use gtk_image_new_from_stock(). This will allow themes to
644 * override the icon you ship with your application.
646 * The #GtkImage does not assume a reference to the
647 * icon set; you still need to unref it if you own references.
648 * #GtkImage will add its own reference rather than adopting yours.
651 * Return value: a new #GtkImage
654 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
659 image = g_object_new (GTK_TYPE_IMAGE, NULL);
661 gtk_image_set_from_icon_set (image, icon_set, size);
663 return GTK_WIDGET (image);
667 * gtk_image_new_from_animation:
668 * @animation: an animation
670 * Creates a #GtkImage displaying the given animation.
671 * The #GtkImage does not assume a reference to the
672 * animation; you still need to unref it if you own references.
673 * #GtkImage will add its own reference rather than adopting yours.
675 * Return value: a new #GtkImage widget
678 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
682 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
684 image = g_object_new (GTK_TYPE_IMAGE, NULL);
686 gtk_image_set_from_animation (image, animation);
688 return GTK_WIDGET (image);
692 * gtk_image_new_from_icon_name:
693 * @icon_name: an icon name
694 * @size: a stock icon size
696 * Creates a #GtkImage displaying an icon from the current icon theme.
697 * If the icon name isn't known, a "broken image" icon will be
698 * displayed instead. If the current icon theme is changed, the icon
699 * will be updated appropriately.
701 * Return value: a new #GtkImage displaying the themed icon
706 gtk_image_new_from_icon_name (const gchar *icon_name,
711 image = g_object_new (GTK_TYPE_IMAGE, NULL);
713 gtk_image_set_from_icon_name (image, icon_name, size);
715 return GTK_WIDGET (image);
719 * gtk_image_set_from_pixmap:
720 * @image: a #GtkImage
721 * @pixmap: a #GdkPixmap or %NULL
722 * @mask: a #GdkBitmap or %NULL
724 * See gtk_image_new_from_pixmap() for details.
728 gtk_image_set_from_pixmap (GtkImage *image,
732 g_return_if_fail (GTK_IS_IMAGE (image));
733 g_return_if_fail (pixmap == NULL ||
734 GDK_IS_PIXMAP (pixmap));
735 g_return_if_fail (mask == NULL ||
736 GDK_IS_PIXMAP (mask));
738 g_object_freeze_notify (G_OBJECT (image));
741 g_object_ref (pixmap);
746 gtk_image_reset (image);
755 image->storage_type = GTK_IMAGE_PIXMAP;
757 image->data.pixmap.pixmap = pixmap;
759 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
761 gtk_image_update_size (image, width, height);
764 g_object_notify (G_OBJECT (image), "pixmap");
765 g_object_notify (G_OBJECT (image), "mask");
767 g_object_thaw_notify (G_OBJECT (image));
771 * gtk_image_set_from_image:
772 * @image: a #GtkImage
773 * @gdk_image: a #GdkImage or %NULL
774 * @mask: a #GdkBitmap or %NULL
776 * See gtk_image_new_from_image() for details.
780 gtk_image_set_from_image (GtkImage *image,
784 g_return_if_fail (GTK_IS_IMAGE (image));
785 g_return_if_fail (gdk_image == NULL ||
786 GDK_IS_IMAGE (gdk_image));
787 g_return_if_fail (mask == NULL ||
788 GDK_IS_PIXMAP (mask));
790 g_object_freeze_notify (G_OBJECT (image));
793 g_object_ref (gdk_image);
798 gtk_image_reset (image);
802 image->storage_type = GTK_IMAGE_IMAGE;
804 image->data.image.image = gdk_image;
807 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
811 /* Clean up the mask if gdk_image was NULL */
813 g_object_unref (mask);
816 g_object_notify (G_OBJECT (image), "image");
817 g_object_notify (G_OBJECT (image), "mask");
819 g_object_thaw_notify (G_OBJECT (image));
823 * gtk_image_set_from_file:
824 * @image: a #GtkImage
825 * @filename: a filename or %NULL
827 * See gtk_image_new_from_file() for details.
831 gtk_image_set_from_file (GtkImage *image,
832 const gchar *filename)
834 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
835 GdkPixbufAnimation *anim;
837 g_return_if_fail (GTK_IS_IMAGE (image));
839 g_object_freeze_notify (G_OBJECT (image));
841 gtk_image_reset (image);
843 if (filename == NULL)
845 priv->filename = NULL;
846 g_object_thaw_notify (G_OBJECT (image));
850 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
854 gtk_image_set_from_stock (image,
855 GTK_STOCK_MISSING_IMAGE,
856 GTK_ICON_SIZE_BUTTON);
857 g_object_thaw_notify (G_OBJECT (image));
861 /* We could just unconditionally set_from_animation,
862 * but it's nicer for memory if we toss the animation
863 * if it's just a single pixbuf
866 if (gdk_pixbuf_animation_is_static_image (anim))
867 gtk_image_set_from_pixbuf (image,
868 gdk_pixbuf_animation_get_static_image (anim));
870 gtk_image_set_from_animation (image, anim);
872 g_object_unref (anim);
874 priv->filename = g_strdup (filename);
876 g_object_thaw_notify (G_OBJECT (image));
880 * gtk_image_set_from_pixbuf:
881 * @image: a #GtkImage
882 * @pixbuf: a #GdkPixbuf or %NULL
884 * See gtk_image_new_from_pixbuf() for details.
888 gtk_image_set_from_pixbuf (GtkImage *image,
891 g_return_if_fail (GTK_IS_IMAGE (image));
892 g_return_if_fail (pixbuf == NULL ||
893 GDK_IS_PIXBUF (pixbuf));
895 g_object_freeze_notify (G_OBJECT (image));
898 g_object_ref (pixbuf);
900 gtk_image_reset (image);
904 image->storage_type = GTK_IMAGE_PIXBUF;
906 image->data.pixbuf.pixbuf = pixbuf;
908 gtk_image_update_size (image,
909 gdk_pixbuf_get_width (pixbuf),
910 gdk_pixbuf_get_height (pixbuf));
913 g_object_notify (G_OBJECT (image), "pixbuf");
915 g_object_thaw_notify (G_OBJECT (image));
919 * gtk_image_set_from_stock:
920 * @image: a #GtkImage
921 * @stock_id: a stock icon name
922 * @size: a stock icon size
924 * See gtk_image_new_from_stock() for details.
928 gtk_image_set_from_stock (GtkImage *image,
929 const gchar *stock_id,
934 g_return_if_fail (GTK_IS_IMAGE (image));
936 g_object_freeze_notify (G_OBJECT (image));
938 /* in case stock_id == image->data.stock.stock_id */
939 new_id = g_strdup (stock_id);
941 gtk_image_reset (image);
945 image->storage_type = GTK_IMAGE_STOCK;
947 image->data.stock.stock_id = new_id;
948 image->icon_size = size;
950 /* Size is demand-computed in size request method
951 * if we're a stock image, since changing the
952 * style impacts the size request
956 g_object_notify (G_OBJECT (image), "stock");
957 g_object_notify (G_OBJECT (image), "icon-size");
959 g_object_thaw_notify (G_OBJECT (image));
963 * gtk_image_set_from_icon_set:
964 * @image: a #GtkImage
965 * @icon_set: a #GtkIconSet
966 * @size: a stock icon size
968 * See gtk_image_new_from_icon_set() for details.
972 gtk_image_set_from_icon_set (GtkImage *image,
973 GtkIconSet *icon_set,
976 g_return_if_fail (GTK_IS_IMAGE (image));
978 g_object_freeze_notify (G_OBJECT (image));
981 gtk_icon_set_ref (icon_set);
983 gtk_image_reset (image);
987 image->storage_type = GTK_IMAGE_ICON_SET;
989 image->data.icon_set.icon_set = icon_set;
990 image->icon_size = size;
992 /* Size is demand-computed in size request method
993 * if we're an icon set
997 g_object_notify (G_OBJECT (image), "icon-set");
998 g_object_notify (G_OBJECT (image), "icon-size");
1000 g_object_thaw_notify (G_OBJECT (image));
1004 * gtk_image_set_from_animation:
1005 * @image: a #GtkImage
1006 * @animation: the #GdkPixbufAnimation
1008 * Causes the #GtkImage to display the given animation (or display
1009 * nothing, if you set the animation to %NULL).
1012 gtk_image_set_from_animation (GtkImage *image,
1013 GdkPixbufAnimation *animation)
1015 g_return_if_fail (GTK_IS_IMAGE (image));
1016 g_return_if_fail (animation == NULL ||
1017 GDK_IS_PIXBUF_ANIMATION (animation));
1019 g_object_freeze_notify (G_OBJECT (image));
1022 g_object_ref (animation);
1024 gtk_image_reset (image);
1026 if (animation != NULL)
1028 image->storage_type = GTK_IMAGE_ANIMATION;
1030 image->data.anim.anim = animation;
1031 image->data.anim.frame_timeout = 0;
1032 image->data.anim.iter = NULL;
1034 gtk_image_update_size (image,
1035 gdk_pixbuf_animation_get_width (animation),
1036 gdk_pixbuf_animation_get_height (animation));
1039 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1041 g_object_thaw_notify (G_OBJECT (image));
1045 * gtk_image_set_from_icon_name:
1046 * @image: a #GtkImage
1047 * @icon_name: an icon name
1048 * @size: an icon size
1050 * See gtk_image_new_from_icon_name() for details.
1055 gtk_image_set_from_icon_name (GtkImage *image,
1056 const gchar *icon_name,
1061 g_return_if_fail (GTK_IS_IMAGE (image));
1063 g_object_freeze_notify (G_OBJECT (image));
1065 /* in case icon_name == image->data.name.icon_name */
1066 new_name = g_strdup (icon_name);
1068 gtk_image_reset (image);
1072 image->storage_type = GTK_IMAGE_ICON_NAME;
1074 image->data.name.icon_name = new_name;
1075 image->icon_size = size;
1077 /* Size is demand-computed in size request method
1078 * if we're a icon theme image, since changing the
1079 * style impacts the size request
1083 g_object_notify (G_OBJECT (image), "icon-name");
1084 g_object_notify (G_OBJECT (image), "icon-size");
1086 g_object_thaw_notify (G_OBJECT (image));
1090 * gtk_image_get_storage_type:
1091 * @image: a #GtkImage
1093 * Gets the type of representation being used by the #GtkImage
1094 * to store image data. If the #GtkImage has no image data,
1095 * the return value will be %GTK_IMAGE_EMPTY.
1097 * Return value: image representation being used
1100 gtk_image_get_storage_type (GtkImage *image)
1102 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1104 return image->storage_type;
1108 * gtk_image_get_pixmap:
1109 * @image: a #GtkImage
1110 * @pixmap: location to store the pixmap, or %NULL
1111 * @mask: location to store the mask, or %NULL
1113 * Gets the pixmap and mask being displayed by the #GtkImage.
1114 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1115 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1116 * The caller of this function does not own a reference to the
1117 * returned pixmap and mask.
1121 gtk_image_get_pixmap (GtkImage *image,
1125 g_return_if_fail (GTK_IS_IMAGE (image));
1126 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1127 image->storage_type == GTK_IMAGE_EMPTY);
1130 *pixmap = image->data.pixmap.pixmap;
1133 *mask = image->mask;
1137 * gtk_image_get_image:
1138 * @image: a #GtkImage
1139 * @gdk_image: return location for a #GtkImage
1140 * @mask: return location for a #GdkBitmap
1142 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1143 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1144 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1145 * The caller of this function does not own a reference to the
1146 * returned image and mask.
1149 gtk_image_get_image (GtkImage *image,
1150 GdkImage **gdk_image,
1153 g_return_if_fail (GTK_IS_IMAGE (image));
1154 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1155 image->storage_type == GTK_IMAGE_EMPTY);
1158 *gdk_image = image->data.image.image;
1161 *mask = image->mask;
1165 * gtk_image_get_pixbuf:
1166 * @image: a #GtkImage
1169 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1170 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1171 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1172 * The caller of this function does not own a reference to the
1175 * Return value: the displayed pixbuf, or %NULL if the image is empty
1178 gtk_image_get_pixbuf (GtkImage *image)
1180 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1181 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1182 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1184 if (image->storage_type == GTK_IMAGE_EMPTY)
1185 image->data.pixbuf.pixbuf = NULL;
1187 return image->data.pixbuf.pixbuf;
1191 * gtk_image_get_stock:
1192 * @image: a #GtkImage
1193 * @stock_id: place to store a stock icon name
1194 * @size: place to store a stock icon size
1196 * Gets the stock icon name and size being displayed by the #GtkImage.
1197 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1198 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1199 * The returned string is owned by the #GtkImage and should not
1204 gtk_image_get_stock (GtkImage *image,
1208 g_return_if_fail (GTK_IS_IMAGE (image));
1209 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1210 image->storage_type == GTK_IMAGE_EMPTY);
1212 if (image->storage_type == GTK_IMAGE_EMPTY)
1213 image->data.stock.stock_id = NULL;
1216 *stock_id = image->data.stock.stock_id;
1219 *size = image->icon_size;
1223 * gtk_image_get_icon_set:
1224 * @image: a #GtkImage
1225 * @icon_set: location to store a #GtkIconSet
1226 * @size: location to store a stock icon size
1228 * Gets the icon set and size being displayed by the #GtkImage.
1229 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1230 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1234 gtk_image_get_icon_set (GtkImage *image,
1235 GtkIconSet **icon_set,
1238 g_return_if_fail (GTK_IS_IMAGE (image));
1239 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1240 image->storage_type == GTK_IMAGE_EMPTY);
1243 *icon_set = image->data.icon_set.icon_set;
1246 *size = image->icon_size;
1250 * gtk_image_get_animation:
1251 * @image: a #GtkImage
1254 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1255 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1256 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1257 * The caller of this function does not own a reference to the
1258 * returned animation.
1260 * Return value: the displayed animation, or %NULL if the image is empty
1263 gtk_image_get_animation (GtkImage *image)
1265 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1266 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1267 image->storage_type == GTK_IMAGE_EMPTY,
1270 if (image->storage_type == GTK_IMAGE_EMPTY)
1271 image->data.anim.anim = NULL;
1273 return image->data.anim.anim;
1277 * gtk_image_get_icon_name:
1278 * @image: a #GtkImage
1279 * @icon_name: place to store an icon name
1280 * @size: place to store an icon size
1282 * Gets the icon name and size being displayed by the #GtkImage.
1283 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1284 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1285 * The returned string is owned by the #GtkImage and should not
1291 gtk_image_get_icon_name (GtkImage *image,
1292 G_CONST_RETURN gchar **icon_name,
1295 g_return_if_fail (GTK_IS_IMAGE (image));
1296 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1297 image->storage_type == GTK_IMAGE_EMPTY);
1299 if (image->storage_type == GTK_IMAGE_EMPTY)
1300 image->data.name.icon_name = NULL;
1303 *icon_name = image->data.name.icon_name;
1306 *size = image->icon_size;
1312 * Creates a new empty #GtkImage widget.
1314 * Return value: a newly created #GtkImage widget.
1317 gtk_image_new (void)
1319 return g_object_new (GTK_TYPE_IMAGE, NULL);
1323 gtk_image_set (GtkImage *image,
1327 g_return_if_fail (GTK_IS_IMAGE (image));
1329 gtk_image_set_from_image (image, val, mask);
1333 gtk_image_get (GtkImage *image,
1337 g_return_if_fail (GTK_IS_IMAGE (image));
1339 gtk_image_get_image (image, val, mask);
1343 gtk_image_reset_anim_iter (GtkImage *image)
1345 if (image->storage_type == GTK_IMAGE_ANIMATION)
1347 /* Reset the animation */
1349 if (image->data.anim.frame_timeout)
1351 g_source_remove (image->data.anim.frame_timeout);
1352 image->data.anim.frame_timeout = 0;
1355 if (image->data.anim.iter)
1357 g_object_unref (image->data.anim.iter);
1358 image->data.anim.iter = NULL;
1364 gtk_image_unmap (GtkWidget *widget)
1366 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1368 if (GTK_WIDGET_CLASS (parent_class)->unmap)
1369 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1373 gtk_image_unrealize (GtkWidget *widget)
1375 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1377 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1378 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
1382 animation_timeout (gpointer data)
1386 GDK_THREADS_ENTER ();
1388 image = GTK_IMAGE (data);
1390 image->data.anim.frame_timeout = 0;
1392 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1394 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1395 image->data.anim.frame_timeout =
1396 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1400 gtk_widget_queue_draw (GTK_WIDGET (image));
1402 GDK_THREADS_LEAVE ();
1408 icon_theme_changed (GtkImage *image)
1410 if (image->data.name.pixbuf)
1411 g_object_unref (image->data.name.pixbuf);
1412 image->data.name.pixbuf = NULL;
1414 gtk_widget_queue_draw (GTK_WIDGET (image));
1418 ensure_pixbuf_for_icon_name (GtkImage *image)
1420 GtkImagePrivate *priv;
1422 GtkIconTheme *icon_theme;
1423 GtkSettings *settings;
1425 gint *sizes, *s, dist;
1426 GError *error = NULL;
1428 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1430 priv = GTK_IMAGE_GET_PRIVATE (image);
1431 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1432 icon_theme = gtk_icon_theme_get_for_screen (screen);
1433 settings = gtk_settings_get_for_screen (screen);
1434 if (image->data.name.pixbuf == NULL)
1436 if (priv->pixel_size != -1)
1438 width = height = priv->pixel_size;
1440 else if (!gtk_icon_size_lookup_for_settings (settings,
1444 if (image->icon_size == -1)
1446 /* Find an available size close to 48 */
1447 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1449 width = height = 48;
1450 for (s = sizes; *s; s++)
1454 width = height = 48;
1461 width = height = *s;
1469 width = height = *s;
1478 g_warning ("Invalid icon size %d\n", image->icon_size);
1479 width = height = 24;
1482 image->data.name.pixbuf =
1483 gtk_icon_theme_load_icon (icon_theme,
1484 image->data.name.icon_name,
1485 MIN (width, height), 0, &error);
1486 if (image->data.name.pixbuf == NULL)
1488 g_error_free (error);
1489 image->data.name.pixbuf =
1490 gtk_widget_render_icon (GTK_WIDGET (image),
1491 GTK_STOCK_MISSING_IMAGE,
1499 * Like gdk_rectangle_intersect (dest, src, dest), but make
1500 * sure that the origin of dest is moved by an "even" offset.
1501 * If necessary grow the intersection by one row or column
1504 * This is necessary since we can't pass alignment information
1505 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1506 * thus we have to makesure that the subimages are properly aligned.
1509 rectangle_intersect_even (GdkRectangle *src,
1517 isect = gdk_rectangle_intersect (dest, src, dest);
1519 if ((dest->x - x + dest->y - y) % 2 != 0)
1537 gtk_image_expose (GtkWidget *widget,
1538 GdkEventExpose *event)
1540 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1541 g_return_val_if_fail (event != NULL, FALSE);
1543 if (GTK_WIDGET_MAPPED (widget) &&
1544 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1548 GdkRectangle area, image_bound;
1550 gint x, y, mask_x, mask_y;
1553 gboolean needs_state_transform;
1555 image = GTK_IMAGE (widget);
1556 misc = GTK_MISC (widget);
1560 /* For stock items and icon sets, we lazily calculate
1561 * the size; we might get here between a queue_resize()
1562 * and size_request() if something explicitely forces
1565 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1566 gtk_image_calc_size (image);
1568 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1571 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1572 xalign = misc->xalign;
1574 xalign = 1.0 - misc->xalign;
1576 x = floor (widget->allocation.x + misc->xpad
1577 + ((widget->allocation.width - widget->requisition.width) * xalign));
1578 y = floor (widget->allocation.y + misc->ypad
1579 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
1585 image_bound.width = 0;
1586 image_bound.height = 0;
1590 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1592 switch (image->storage_type)
1594 case GTK_IMAGE_PIXMAP:
1596 gdk_drawable_get_size (image->data.pixmap.pixmap,
1598 &image_bound.height);
1599 if (rectangle_intersect_even (&area, &image_bound) &&
1600 needs_state_transform)
1602 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1603 image->data.pixmap.pixmap,
1604 gtk_widget_get_colormap (widget),
1605 image_bound.x - x, image_bound.y - y,
1608 image_bound.height);
1616 case GTK_IMAGE_IMAGE:
1618 image_bound.width = image->data.image.image->width;
1619 image_bound.height = image->data.image.image->height;
1621 if (rectangle_intersect_even (&area, &image_bound) &&
1622 needs_state_transform)
1624 pixbuf = gdk_pixbuf_get_from_image (NULL,
1625 image->data.image.image,
1626 gtk_widget_get_colormap (widget),
1627 image_bound.x - x, image_bound.y - y,
1630 image_bound.height);
1637 case GTK_IMAGE_PIXBUF:
1638 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1639 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1641 if (rectangle_intersect_even (&area, &image_bound) &&
1642 needs_state_transform)
1644 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1645 image_bound.x - x, image_bound.y - y,
1646 image_bound.width, image_bound.height);
1653 pixbuf = image->data.pixbuf.pixbuf;
1654 g_object_ref (pixbuf);
1658 case GTK_IMAGE_STOCK:
1659 pixbuf = gtk_widget_render_icon (widget,
1660 image->data.stock.stock_id,
1665 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1666 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1670 needs_state_transform = FALSE;
1673 case GTK_IMAGE_ICON_SET:
1675 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1677 gtk_widget_get_direction (widget),
1678 GTK_WIDGET_STATE (widget),
1685 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1686 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1690 needs_state_transform = FALSE;
1693 case GTK_IMAGE_ANIMATION:
1695 if (image->data.anim.iter == NULL)
1697 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1699 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1700 image->data.anim.frame_timeout =
1701 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1706 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1707 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1709 /* don't advance the anim iter here, or we could get frame changes between two
1710 * exposes of different areas.
1713 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1714 g_object_ref (pixbuf);
1718 case GTK_IMAGE_ICON_NAME:
1719 ensure_pixbuf_for_icon_name (image);
1720 pixbuf = image->data.name.pixbuf;
1723 g_object_ref (pixbuf);
1724 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1725 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1729 case GTK_IMAGE_EMPTY:
1730 g_assert_not_reached ();
1736 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1737 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1740 if (rectangle_intersect_even (&area, &image_bound))
1744 if (needs_state_transform)
1746 GtkIconSource *source;
1747 GdkPixbuf *rendered;
1749 source = gtk_icon_source_new ();
1750 gtk_icon_source_set_pixbuf (source, pixbuf);
1751 /* The size here is arbitrary; since size isn't
1752 * wildcarded in the souce, it isn't supposed to be
1753 * scaled by the engine function
1755 gtk_icon_source_set_size (source,
1756 GTK_ICON_SIZE_SMALL_TOOLBAR);
1757 gtk_icon_source_set_size_wildcarded (source, FALSE);
1759 rendered = gtk_style_render_icon (widget->style,
1761 gtk_widget_get_direction (widget),
1762 GTK_WIDGET_STATE (widget),
1768 gtk_icon_source_free (source);
1770 g_object_unref (pixbuf);
1776 gdk_draw_pixbuf (widget->window,
1777 widget->style->black_gc,
1785 GDK_RGB_DITHER_NORMAL,
1788 g_object_unref (pixbuf);
1794 switch (image->storage_type)
1796 case GTK_IMAGE_PIXMAP:
1797 gdk_draw_drawable (widget->window,
1798 widget->style->black_gc,
1799 image->data.pixmap.pixmap,
1800 image_bound.x - x, image_bound.y - y,
1801 image_bound.x, image_bound.y,
1802 image_bound.width, image_bound.height);
1805 case GTK_IMAGE_IMAGE:
1806 gdk_draw_image (widget->window,
1807 widget->style->black_gc,
1808 image->data.image.image,
1809 image_bound.x - x, image_bound.y - y,
1810 image_bound.x, image_bound.y,
1811 image_bound.width, image_bound.height);
1814 case GTK_IMAGE_PIXBUF:
1815 case GTK_IMAGE_STOCK:
1816 case GTK_IMAGE_ICON_SET:
1817 case GTK_IMAGE_ANIMATION:
1818 case GTK_IMAGE_ICON_NAME:
1819 case GTK_IMAGE_EMPTY:
1820 g_assert_not_reached ();
1824 } /* if rectangle intersects */
1828 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1829 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1832 } /* if widget is drawable */
1839 * @image: a #GtkImage
1841 * Resets the image to be empty.
1846 gtk_image_clear (GtkImage *image)
1848 GtkImagePrivate *priv;
1850 g_return_if_fail (GTK_IS_IMAGE (image));
1852 priv = GTK_IMAGE_GET_PRIVATE (image);
1854 g_object_freeze_notify (G_OBJECT (image));
1856 if (image->storage_type != GTK_IMAGE_EMPTY)
1857 g_object_notify (G_OBJECT (image), "storage-type");
1861 g_object_unref (image->mask);
1863 g_object_notify (G_OBJECT (image), "mask");
1866 if (image->icon_size != DEFAULT_ICON_SIZE)
1868 image->icon_size = DEFAULT_ICON_SIZE;
1869 g_object_notify (G_OBJECT (image), "icon-size");
1872 switch (image->storage_type)
1874 case GTK_IMAGE_PIXMAP:
1876 if (image->data.pixmap.pixmap)
1877 g_object_unref (image->data.pixmap.pixmap);
1878 image->data.pixmap.pixmap = NULL;
1880 g_object_notify (G_OBJECT (image), "pixmap");
1884 case GTK_IMAGE_IMAGE:
1886 if (image->data.image.image)
1887 g_object_unref (image->data.image.image);
1888 image->data.image.image = NULL;
1890 g_object_notify (G_OBJECT (image), "image");
1894 case GTK_IMAGE_PIXBUF:
1896 if (image->data.pixbuf.pixbuf)
1897 g_object_unref (image->data.pixbuf.pixbuf);
1899 g_object_notify (G_OBJECT (image), "pixbuf");
1903 case GTK_IMAGE_STOCK:
1905 g_free (image->data.stock.stock_id);
1907 image->data.stock.stock_id = NULL;
1909 g_object_notify (G_OBJECT (image), "stock");
1912 case GTK_IMAGE_ICON_SET:
1913 if (image->data.icon_set.icon_set)
1914 gtk_icon_set_unref (image->data.icon_set.icon_set);
1915 image->data.icon_set.icon_set = NULL;
1917 g_object_notify (G_OBJECT (image), "icon-set");
1920 case GTK_IMAGE_ANIMATION:
1921 gtk_image_reset_anim_iter (image);
1923 if (image->data.anim.anim)
1924 g_object_unref (image->data.anim.anim);
1925 image->data.anim.anim = NULL;
1927 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1931 case GTK_IMAGE_ICON_NAME:
1932 if (image->data.name.icon_name)
1933 g_free (image->data.name.icon_name);
1934 image->data.name.icon_name = NULL;
1935 if (image->data.name.pixbuf)
1936 g_object_unref (image->data.name.pixbuf);
1937 image->data.name.pixbuf = NULL;
1939 g_object_notify (G_OBJECT (image), "icon-name");
1943 case GTK_IMAGE_EMPTY:
1951 g_free (priv->filename);
1952 priv->filename = NULL;
1953 g_object_notify (G_OBJECT (image), "file");
1956 image->storage_type = GTK_IMAGE_EMPTY;
1958 memset (&image->data, '\0', sizeof (image->data));
1960 g_object_thaw_notify (G_OBJECT (image));
1964 gtk_image_reset (GtkImage *image)
1966 gtk_image_clear (image);
1968 gtk_image_update_size (image, 0, 0);
1972 gtk_image_calc_size (GtkImage *image)
1974 GtkWidget *widget = GTK_WIDGET (image);
1975 GdkPixbuf *pixbuf = NULL;
1977 /* We update stock/icon set on every size request, because
1978 * the theme could have affected the size; for other kinds of
1979 * image, we just update the requisition when the image data
1982 switch (image->storage_type)
1984 case GTK_IMAGE_STOCK:
1985 pixbuf = gtk_widget_render_icon (widget,
1986 image->data.stock.stock_id,
1991 case GTK_IMAGE_ICON_SET:
1992 pixbuf = gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1994 gtk_widget_get_direction (widget),
1995 GTK_WIDGET_STATE (widget),
2000 case GTK_IMAGE_ICON_NAME:
2001 ensure_pixbuf_for_icon_name (image);
2002 pixbuf = image->data.name.pixbuf;
2003 if (pixbuf) g_object_ref (pixbuf);
2011 widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
2012 widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
2014 g_object_unref (pixbuf);
2019 gtk_image_size_request (GtkWidget *widget,
2020 GtkRequisition *requisition)
2024 image = GTK_IMAGE (widget);
2026 gtk_image_calc_size (image);
2028 /* Chain up to default that simply reads current requisition */
2029 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
2033 gtk_image_style_set (GtkWidget *widget,
2034 GtkStyle *prev_style)
2038 image = GTK_IMAGE (widget);
2040 if (GTK_WIDGET_CLASS (parent_class)->style_set)
2041 GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
2043 icon_theme_changed (image);
2047 gtk_image_screen_changed (GtkWidget *widget,
2048 GdkScreen *prev_screen)
2052 image = GTK_IMAGE (widget);
2054 if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
2055 GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, prev_screen);
2057 icon_theme_changed (image);
2062 gtk_image_update_size (GtkImage *image,
2066 GTK_WIDGET (image)->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
2067 GTK_WIDGET (image)->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
2069 if (GTK_WIDGET_VISIBLE (image))
2070 gtk_widget_queue_resize (GTK_WIDGET (image));
2075 * gtk_image_set_pixel_size:
2076 * @image: a #GtkImage
2077 * @pixel_size: the new pixel size
2079 * Sets the pixel size to use for named icons. If the pixel size is set
2080 * to a value != -1, it is used instead of the icon size set by
2081 * gtk_image_set_from_icon_name().
2086 gtk_image_set_pixel_size (GtkImage *image,
2089 GtkImagePrivate *priv;
2091 g_return_if_fail (GTK_IS_IMAGE (image));
2093 priv = GTK_IMAGE_GET_PRIVATE (image);
2095 if (priv->pixel_size != pixel_size)
2097 priv->pixel_size = pixel_size;
2099 if (image->storage_type == GTK_IMAGE_ICON_NAME)
2101 if (image->data.name.pixbuf)
2103 g_object_unref (image->data.name.pixbuf);
2104 image->data.name.pixbuf = NULL;
2107 gtk_image_update_size (image, pixel_size, pixel_size);
2110 g_object_notify (G_OBJECT (image), "pixel-size");
2115 * gtk_image_get_pixel_size:
2116 * @image: a #GtkImage
2118 * Gets the pixel size used for named icons.
2120 * Returns: the pixel size used for named icons.
2125 gtk_image_get_pixel_size (GtkImage *image)
2127 GtkImagePrivate *priv;
2129 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2131 priv = GTK_IMAGE_GET_PRIVATE (image);
2133 return priv->pixel_size;
2138 #undef gtk_image_new_from_file
2141 gtk_image_new_from_file (const gchar *filename)
2143 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2146 retval = gtk_image_new_from_file_utf8 (utf8_filename);
2148 g_free (utf8_filename);
2153 #undef gtk_image_set_from_file
2156 gtk_image_set_from_file (GtkImage *image,
2157 const gchar *filename)
2159 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2161 gtk_image_set_from_file_utf8 (image, utf8_filename);
2163 g_free (utf8_filename);
2168 #define __GTK_IMAGE_C__
2169 #include "gtkaliasdef.c"