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 * Note that the animation frames are shown using a timeout with
676 * #G_PRIORITY_DEFAULT. When using animations to indicate busyness,
677 * keep in mind that the animation will only be shown if the main loop
678 * is not busy with something that has a higher priority.
680 * Return value: a new #GtkImage widget
683 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
687 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
689 image = g_object_new (GTK_TYPE_IMAGE, NULL);
691 gtk_image_set_from_animation (image, animation);
693 return GTK_WIDGET (image);
697 * gtk_image_new_from_icon_name:
698 * @icon_name: an icon name
699 * @size: a stock icon size
701 * Creates a #GtkImage displaying an icon from the current icon theme.
702 * If the icon name isn't known, a "broken image" icon will be
703 * displayed instead. If the current icon theme is changed, the icon
704 * will be updated appropriately.
706 * Return value: a new #GtkImage displaying the themed icon
711 gtk_image_new_from_icon_name (const gchar *icon_name,
716 image = g_object_new (GTK_TYPE_IMAGE, NULL);
718 gtk_image_set_from_icon_name (image, icon_name, size);
720 return GTK_WIDGET (image);
724 * gtk_image_set_from_pixmap:
725 * @image: a #GtkImage
726 * @pixmap: a #GdkPixmap or %NULL
727 * @mask: a #GdkBitmap or %NULL
729 * See gtk_image_new_from_pixmap() for details.
733 gtk_image_set_from_pixmap (GtkImage *image,
737 g_return_if_fail (GTK_IS_IMAGE (image));
738 g_return_if_fail (pixmap == NULL ||
739 GDK_IS_PIXMAP (pixmap));
740 g_return_if_fail (mask == NULL ||
741 GDK_IS_PIXMAP (mask));
743 g_object_freeze_notify (G_OBJECT (image));
746 g_object_ref (pixmap);
751 gtk_image_reset (image);
760 image->storage_type = GTK_IMAGE_PIXMAP;
762 image->data.pixmap.pixmap = pixmap;
764 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
766 gtk_image_update_size (image, width, height);
769 g_object_notify (G_OBJECT (image), "pixmap");
770 g_object_notify (G_OBJECT (image), "mask");
772 g_object_thaw_notify (G_OBJECT (image));
776 * gtk_image_set_from_image:
777 * @image: a #GtkImage
778 * @gdk_image: a #GdkImage or %NULL
779 * @mask: a #GdkBitmap or %NULL
781 * See gtk_image_new_from_image() for details.
785 gtk_image_set_from_image (GtkImage *image,
789 g_return_if_fail (GTK_IS_IMAGE (image));
790 g_return_if_fail (gdk_image == NULL ||
791 GDK_IS_IMAGE (gdk_image));
792 g_return_if_fail (mask == NULL ||
793 GDK_IS_PIXMAP (mask));
795 g_object_freeze_notify (G_OBJECT (image));
798 g_object_ref (gdk_image);
803 gtk_image_reset (image);
807 image->storage_type = GTK_IMAGE_IMAGE;
809 image->data.image.image = gdk_image;
812 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
816 /* Clean up the mask if gdk_image was NULL */
818 g_object_unref (mask);
821 g_object_notify (G_OBJECT (image), "image");
822 g_object_notify (G_OBJECT (image), "mask");
824 g_object_thaw_notify (G_OBJECT (image));
828 * gtk_image_set_from_file:
829 * @image: a #GtkImage
830 * @filename: a filename or %NULL
832 * See gtk_image_new_from_file() for details.
836 gtk_image_set_from_file (GtkImage *image,
837 const gchar *filename)
839 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
840 GdkPixbufAnimation *anim;
842 g_return_if_fail (GTK_IS_IMAGE (image));
844 g_object_freeze_notify (G_OBJECT (image));
846 gtk_image_reset (image);
848 if (filename == NULL)
850 priv->filename = NULL;
851 g_object_thaw_notify (G_OBJECT (image));
855 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
859 gtk_image_set_from_stock (image,
860 GTK_STOCK_MISSING_IMAGE,
861 GTK_ICON_SIZE_BUTTON);
862 g_object_thaw_notify (G_OBJECT (image));
866 /* We could just unconditionally set_from_animation,
867 * but it's nicer for memory if we toss the animation
868 * if it's just a single pixbuf
871 if (gdk_pixbuf_animation_is_static_image (anim))
872 gtk_image_set_from_pixbuf (image,
873 gdk_pixbuf_animation_get_static_image (anim));
875 gtk_image_set_from_animation (image, anim);
877 g_object_unref (anim);
879 priv->filename = g_strdup (filename);
881 g_object_thaw_notify (G_OBJECT (image));
885 * gtk_image_set_from_pixbuf:
886 * @image: a #GtkImage
887 * @pixbuf: a #GdkPixbuf or %NULL
889 * See gtk_image_new_from_pixbuf() for details.
893 gtk_image_set_from_pixbuf (GtkImage *image,
896 g_return_if_fail (GTK_IS_IMAGE (image));
897 g_return_if_fail (pixbuf == NULL ||
898 GDK_IS_PIXBUF (pixbuf));
900 g_object_freeze_notify (G_OBJECT (image));
903 g_object_ref (pixbuf);
905 gtk_image_reset (image);
909 image->storage_type = GTK_IMAGE_PIXBUF;
911 image->data.pixbuf.pixbuf = pixbuf;
913 gtk_image_update_size (image,
914 gdk_pixbuf_get_width (pixbuf),
915 gdk_pixbuf_get_height (pixbuf));
918 g_object_notify (G_OBJECT (image), "pixbuf");
920 g_object_thaw_notify (G_OBJECT (image));
924 * gtk_image_set_from_stock:
925 * @image: a #GtkImage
926 * @stock_id: a stock icon name
927 * @size: a stock icon size
929 * See gtk_image_new_from_stock() for details.
933 gtk_image_set_from_stock (GtkImage *image,
934 const gchar *stock_id,
939 g_return_if_fail (GTK_IS_IMAGE (image));
941 g_object_freeze_notify (G_OBJECT (image));
943 /* in case stock_id == image->data.stock.stock_id */
944 new_id = g_strdup (stock_id);
946 gtk_image_reset (image);
950 image->storage_type = GTK_IMAGE_STOCK;
952 image->data.stock.stock_id = new_id;
953 image->icon_size = size;
955 /* Size is demand-computed in size request method
956 * if we're a stock image, since changing the
957 * style impacts the size request
961 g_object_notify (G_OBJECT (image), "stock");
962 g_object_notify (G_OBJECT (image), "icon-size");
964 g_object_thaw_notify (G_OBJECT (image));
968 * gtk_image_set_from_icon_set:
969 * @image: a #GtkImage
970 * @icon_set: a #GtkIconSet
971 * @size: a stock icon size
973 * See gtk_image_new_from_icon_set() for details.
977 gtk_image_set_from_icon_set (GtkImage *image,
978 GtkIconSet *icon_set,
981 g_return_if_fail (GTK_IS_IMAGE (image));
983 g_object_freeze_notify (G_OBJECT (image));
986 gtk_icon_set_ref (icon_set);
988 gtk_image_reset (image);
992 image->storage_type = GTK_IMAGE_ICON_SET;
994 image->data.icon_set.icon_set = icon_set;
995 image->icon_size = size;
997 /* Size is demand-computed in size request method
998 * if we're an icon set
1002 g_object_notify (G_OBJECT (image), "icon-set");
1003 g_object_notify (G_OBJECT (image), "icon-size");
1005 g_object_thaw_notify (G_OBJECT (image));
1009 * gtk_image_set_from_animation:
1010 * @image: a #GtkImage
1011 * @animation: the #GdkPixbufAnimation
1013 * Causes the #GtkImage to display the given animation (or display
1014 * nothing, if you set the animation to %NULL).
1017 gtk_image_set_from_animation (GtkImage *image,
1018 GdkPixbufAnimation *animation)
1020 g_return_if_fail (GTK_IS_IMAGE (image));
1021 g_return_if_fail (animation == NULL ||
1022 GDK_IS_PIXBUF_ANIMATION (animation));
1024 g_object_freeze_notify (G_OBJECT (image));
1027 g_object_ref (animation);
1029 gtk_image_reset (image);
1031 if (animation != NULL)
1033 image->storage_type = GTK_IMAGE_ANIMATION;
1035 image->data.anim.anim = animation;
1036 image->data.anim.frame_timeout = 0;
1037 image->data.anim.iter = NULL;
1039 gtk_image_update_size (image,
1040 gdk_pixbuf_animation_get_width (animation),
1041 gdk_pixbuf_animation_get_height (animation));
1044 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1046 g_object_thaw_notify (G_OBJECT (image));
1050 * gtk_image_set_from_icon_name:
1051 * @image: a #GtkImage
1052 * @icon_name: an icon name
1053 * @size: an icon size
1055 * See gtk_image_new_from_icon_name() for details.
1060 gtk_image_set_from_icon_name (GtkImage *image,
1061 const gchar *icon_name,
1066 g_return_if_fail (GTK_IS_IMAGE (image));
1068 g_object_freeze_notify (G_OBJECT (image));
1070 /* in case icon_name == image->data.name.icon_name */
1071 new_name = g_strdup (icon_name);
1073 gtk_image_reset (image);
1077 image->storage_type = GTK_IMAGE_ICON_NAME;
1079 image->data.name.icon_name = new_name;
1080 image->icon_size = size;
1082 /* Size is demand-computed in size request method
1083 * if we're a icon theme image, since changing the
1084 * style impacts the size request
1088 g_object_notify (G_OBJECT (image), "icon-name");
1089 g_object_notify (G_OBJECT (image), "icon-size");
1091 g_object_thaw_notify (G_OBJECT (image));
1095 * gtk_image_get_storage_type:
1096 * @image: a #GtkImage
1098 * Gets the type of representation being used by the #GtkImage
1099 * to store image data. If the #GtkImage has no image data,
1100 * the return value will be %GTK_IMAGE_EMPTY.
1102 * Return value: image representation being used
1105 gtk_image_get_storage_type (GtkImage *image)
1107 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1109 return image->storage_type;
1113 * gtk_image_get_pixmap:
1114 * @image: a #GtkImage
1115 * @pixmap: location to store the pixmap, or %NULL
1116 * @mask: location to store the mask, or %NULL
1118 * Gets the pixmap and mask being displayed by the #GtkImage.
1119 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1120 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1121 * The caller of this function does not own a reference to the
1122 * returned pixmap and mask.
1126 gtk_image_get_pixmap (GtkImage *image,
1130 g_return_if_fail (GTK_IS_IMAGE (image));
1131 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1132 image->storage_type == GTK_IMAGE_EMPTY);
1135 *pixmap = image->data.pixmap.pixmap;
1138 *mask = image->mask;
1142 * gtk_image_get_image:
1143 * @image: a #GtkImage
1144 * @gdk_image: return location for a #GtkImage
1145 * @mask: return location for a #GdkBitmap
1147 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1148 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1149 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1150 * The caller of this function does not own a reference to the
1151 * returned image and mask.
1154 gtk_image_get_image (GtkImage *image,
1155 GdkImage **gdk_image,
1158 g_return_if_fail (GTK_IS_IMAGE (image));
1159 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1160 image->storage_type == GTK_IMAGE_EMPTY);
1163 *gdk_image = image->data.image.image;
1166 *mask = image->mask;
1170 * gtk_image_get_pixbuf:
1171 * @image: a #GtkImage
1174 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1175 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1176 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1177 * The caller of this function does not own a reference to the
1180 * Return value: the displayed pixbuf, or %NULL if the image is empty
1183 gtk_image_get_pixbuf (GtkImage *image)
1185 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1186 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1187 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1189 if (image->storage_type == GTK_IMAGE_EMPTY)
1190 image->data.pixbuf.pixbuf = NULL;
1192 return image->data.pixbuf.pixbuf;
1196 * gtk_image_get_stock:
1197 * @image: a #GtkImage
1198 * @stock_id: place to store a stock icon name
1199 * @size: place to store a stock icon size
1201 * Gets the stock icon name and size being displayed by the #GtkImage.
1202 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1203 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1204 * The returned string is owned by the #GtkImage and should not
1209 gtk_image_get_stock (GtkImage *image,
1213 g_return_if_fail (GTK_IS_IMAGE (image));
1214 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1215 image->storage_type == GTK_IMAGE_EMPTY);
1217 if (image->storage_type == GTK_IMAGE_EMPTY)
1218 image->data.stock.stock_id = NULL;
1221 *stock_id = image->data.stock.stock_id;
1224 *size = image->icon_size;
1228 * gtk_image_get_icon_set:
1229 * @image: a #GtkImage
1230 * @icon_set: location to store a #GtkIconSet
1231 * @size: location to store a stock icon size
1233 * Gets the icon set and size being displayed by the #GtkImage.
1234 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1235 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1239 gtk_image_get_icon_set (GtkImage *image,
1240 GtkIconSet **icon_set,
1243 g_return_if_fail (GTK_IS_IMAGE (image));
1244 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1245 image->storage_type == GTK_IMAGE_EMPTY);
1248 *icon_set = image->data.icon_set.icon_set;
1251 *size = image->icon_size;
1255 * gtk_image_get_animation:
1256 * @image: a #GtkImage
1259 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1260 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1261 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1262 * The caller of this function does not own a reference to the
1263 * returned animation.
1265 * Return value: the displayed animation, or %NULL if the image is empty
1268 gtk_image_get_animation (GtkImage *image)
1270 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1271 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1272 image->storage_type == GTK_IMAGE_EMPTY,
1275 if (image->storage_type == GTK_IMAGE_EMPTY)
1276 image->data.anim.anim = NULL;
1278 return image->data.anim.anim;
1282 * gtk_image_get_icon_name:
1283 * @image: a #GtkImage
1284 * @icon_name: place to store an icon name
1285 * @size: place to store an icon size
1287 * Gets the icon name and size being displayed by the #GtkImage.
1288 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1289 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1290 * The returned string is owned by the #GtkImage and should not
1296 gtk_image_get_icon_name (GtkImage *image,
1297 G_CONST_RETURN gchar **icon_name,
1300 g_return_if_fail (GTK_IS_IMAGE (image));
1301 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1302 image->storage_type == GTK_IMAGE_EMPTY);
1304 if (image->storage_type == GTK_IMAGE_EMPTY)
1305 image->data.name.icon_name = NULL;
1308 *icon_name = image->data.name.icon_name;
1311 *size = image->icon_size;
1317 * Creates a new empty #GtkImage widget.
1319 * Return value: a newly created #GtkImage widget.
1322 gtk_image_new (void)
1324 return g_object_new (GTK_TYPE_IMAGE, NULL);
1328 gtk_image_set (GtkImage *image,
1332 g_return_if_fail (GTK_IS_IMAGE (image));
1334 gtk_image_set_from_image (image, val, mask);
1338 gtk_image_get (GtkImage *image,
1342 g_return_if_fail (GTK_IS_IMAGE (image));
1344 gtk_image_get_image (image, val, mask);
1348 gtk_image_reset_anim_iter (GtkImage *image)
1350 if (image->storage_type == GTK_IMAGE_ANIMATION)
1352 /* Reset the animation */
1354 if (image->data.anim.frame_timeout)
1356 g_source_remove (image->data.anim.frame_timeout);
1357 image->data.anim.frame_timeout = 0;
1360 if (image->data.anim.iter)
1362 g_object_unref (image->data.anim.iter);
1363 image->data.anim.iter = NULL;
1369 gtk_image_unmap (GtkWidget *widget)
1371 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1373 if (GTK_WIDGET_CLASS (parent_class)->unmap)
1374 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1378 gtk_image_unrealize (GtkWidget *widget)
1380 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1382 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1383 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
1387 animation_timeout (gpointer data)
1391 GDK_THREADS_ENTER ();
1393 image = GTK_IMAGE (data);
1395 image->data.anim.frame_timeout = 0;
1397 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1399 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1400 image->data.anim.frame_timeout =
1401 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1405 gtk_widget_queue_draw (GTK_WIDGET (image));
1407 if (GTK_WIDGET_DRAWABLE (image))
1408 gdk_window_process_updates (GTK_WIDGET (image)->window, TRUE);
1410 GDK_THREADS_LEAVE ();
1416 icon_theme_changed (GtkImage *image)
1418 if (image->data.name.pixbuf)
1419 g_object_unref (image->data.name.pixbuf);
1420 image->data.name.pixbuf = NULL;
1422 gtk_widget_queue_draw (GTK_WIDGET (image));
1426 ensure_pixbuf_for_icon_name (GtkImage *image)
1428 GtkImagePrivate *priv;
1430 GtkIconTheme *icon_theme;
1431 GtkSettings *settings;
1433 gint *sizes, *s, dist;
1434 GError *error = NULL;
1436 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1438 priv = GTK_IMAGE_GET_PRIVATE (image);
1439 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1440 icon_theme = gtk_icon_theme_get_for_screen (screen);
1441 settings = gtk_settings_get_for_screen (screen);
1442 if (image->data.name.pixbuf == NULL)
1444 if (priv->pixel_size != -1)
1446 width = height = priv->pixel_size;
1448 else if (!gtk_icon_size_lookup_for_settings (settings,
1452 if (image->icon_size == -1)
1454 /* Find an available size close to 48 */
1455 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1457 width = height = 48;
1458 for (s = sizes; *s; s++)
1462 width = height = 48;
1469 width = height = *s;
1477 width = height = *s;
1486 g_warning ("Invalid icon size %d\n", image->icon_size);
1487 width = height = 24;
1490 image->data.name.pixbuf =
1491 gtk_icon_theme_load_icon (icon_theme,
1492 image->data.name.icon_name,
1493 MIN (width, height), 0, &error);
1494 if (image->data.name.pixbuf == NULL)
1496 g_error_free (error);
1497 image->data.name.pixbuf =
1498 gtk_widget_render_icon (GTK_WIDGET (image),
1499 GTK_STOCK_MISSING_IMAGE,
1507 * Like gdk_rectangle_intersect (dest, src, dest), but make
1508 * sure that the origin of dest is moved by an "even" offset.
1509 * If necessary grow the intersection by one row or column
1512 * This is necessary since we can't pass alignment information
1513 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1514 * thus we have to makesure that the subimages are properly aligned.
1517 rectangle_intersect_even (GdkRectangle *src,
1525 isect = gdk_rectangle_intersect (dest, src, dest);
1527 if ((dest->x - x + dest->y - y) % 2 != 0)
1545 gtk_image_expose (GtkWidget *widget,
1546 GdkEventExpose *event)
1548 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1549 g_return_val_if_fail (event != NULL, FALSE);
1551 if (GTK_WIDGET_MAPPED (widget) &&
1552 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1556 GdkRectangle area, image_bound;
1558 gint x, y, mask_x, mask_y;
1561 gboolean needs_state_transform;
1563 image = GTK_IMAGE (widget);
1564 misc = GTK_MISC (widget);
1568 /* For stock items and icon sets, we lazily calculate
1569 * the size; we might get here between a queue_resize()
1570 * and size_request() if something explicitely forces
1573 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1574 gtk_image_calc_size (image);
1576 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1579 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1580 xalign = misc->xalign;
1582 xalign = 1.0 - misc->xalign;
1584 x = floor (widget->allocation.x + misc->xpad
1585 + ((widget->allocation.width - widget->requisition.width) * xalign));
1586 y = floor (widget->allocation.y + misc->ypad
1587 + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
1593 image_bound.width = 0;
1594 image_bound.height = 0;
1598 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1600 switch (image->storage_type)
1602 case GTK_IMAGE_PIXMAP:
1604 gdk_drawable_get_size (image->data.pixmap.pixmap,
1606 &image_bound.height);
1607 if (rectangle_intersect_even (&area, &image_bound) &&
1608 needs_state_transform)
1610 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1611 image->data.pixmap.pixmap,
1612 gtk_widget_get_colormap (widget),
1613 image_bound.x - x, image_bound.y - y,
1616 image_bound.height);
1624 case GTK_IMAGE_IMAGE:
1626 image_bound.width = image->data.image.image->width;
1627 image_bound.height = image->data.image.image->height;
1629 if (rectangle_intersect_even (&area, &image_bound) &&
1630 needs_state_transform)
1632 pixbuf = gdk_pixbuf_get_from_image (NULL,
1633 image->data.image.image,
1634 gtk_widget_get_colormap (widget),
1635 image_bound.x - x, image_bound.y - y,
1638 image_bound.height);
1645 case GTK_IMAGE_PIXBUF:
1646 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1647 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1649 if (rectangle_intersect_even (&area, &image_bound) &&
1650 needs_state_transform)
1652 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1653 image_bound.x - x, image_bound.y - y,
1654 image_bound.width, image_bound.height);
1661 pixbuf = image->data.pixbuf.pixbuf;
1662 g_object_ref (pixbuf);
1666 case GTK_IMAGE_STOCK:
1667 pixbuf = gtk_widget_render_icon (widget,
1668 image->data.stock.stock_id,
1673 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1674 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1678 needs_state_transform = FALSE;
1681 case GTK_IMAGE_ICON_SET:
1683 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1685 gtk_widget_get_direction (widget),
1686 GTK_WIDGET_STATE (widget),
1693 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1694 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1698 needs_state_transform = FALSE;
1701 case GTK_IMAGE_ANIMATION:
1703 if (image->data.anim.iter == NULL)
1705 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1707 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1708 image->data.anim.frame_timeout =
1709 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1714 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1715 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1717 /* don't advance the anim iter here, or we could get frame changes between two
1718 * exposes of different areas.
1721 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1722 g_object_ref (pixbuf);
1726 case GTK_IMAGE_ICON_NAME:
1727 ensure_pixbuf_for_icon_name (image);
1728 pixbuf = image->data.name.pixbuf;
1731 g_object_ref (pixbuf);
1732 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1733 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1737 case GTK_IMAGE_EMPTY:
1738 g_assert_not_reached ();
1744 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1745 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1748 if (rectangle_intersect_even (&area, &image_bound))
1752 if (needs_state_transform)
1754 GtkIconSource *source;
1755 GdkPixbuf *rendered;
1757 source = gtk_icon_source_new ();
1758 gtk_icon_source_set_pixbuf (source, pixbuf);
1759 /* The size here is arbitrary; since size isn't
1760 * wildcarded in the souce, it isn't supposed to be
1761 * scaled by the engine function
1763 gtk_icon_source_set_size (source,
1764 GTK_ICON_SIZE_SMALL_TOOLBAR);
1765 gtk_icon_source_set_size_wildcarded (source, FALSE);
1767 rendered = gtk_style_render_icon (widget->style,
1769 gtk_widget_get_direction (widget),
1770 GTK_WIDGET_STATE (widget),
1776 gtk_icon_source_free (source);
1778 g_object_unref (pixbuf);
1784 gdk_draw_pixbuf (widget->window,
1785 widget->style->black_gc,
1793 GDK_RGB_DITHER_NORMAL,
1799 switch (image->storage_type)
1801 case GTK_IMAGE_PIXMAP:
1802 gdk_draw_drawable (widget->window,
1803 widget->style->black_gc,
1804 image->data.pixmap.pixmap,
1805 image_bound.x - x, image_bound.y - y,
1806 image_bound.x, image_bound.y,
1807 image_bound.width, image_bound.height);
1810 case GTK_IMAGE_IMAGE:
1811 gdk_draw_image (widget->window,
1812 widget->style->black_gc,
1813 image->data.image.image,
1814 image_bound.x - x, image_bound.y - y,
1815 image_bound.x, image_bound.y,
1816 image_bound.width, image_bound.height);
1819 case GTK_IMAGE_PIXBUF:
1820 case GTK_IMAGE_STOCK:
1821 case GTK_IMAGE_ICON_SET:
1822 case GTK_IMAGE_ANIMATION:
1823 case GTK_IMAGE_ICON_NAME:
1824 case GTK_IMAGE_EMPTY:
1825 g_assert_not_reached ();
1829 } /* if rectangle intersects */
1833 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1834 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1838 g_object_unref (pixbuf);
1840 } /* if widget is drawable */
1847 * @image: a #GtkImage
1849 * Resets the image to be empty.
1854 gtk_image_clear (GtkImage *image)
1856 GtkImagePrivate *priv;
1858 g_return_if_fail (GTK_IS_IMAGE (image));
1860 priv = GTK_IMAGE_GET_PRIVATE (image);
1862 g_object_freeze_notify (G_OBJECT (image));
1864 if (image->storage_type != GTK_IMAGE_EMPTY)
1865 g_object_notify (G_OBJECT (image), "storage-type");
1869 g_object_unref (image->mask);
1871 g_object_notify (G_OBJECT (image), "mask");
1874 if (image->icon_size != DEFAULT_ICON_SIZE)
1876 image->icon_size = DEFAULT_ICON_SIZE;
1877 g_object_notify (G_OBJECT (image), "icon-size");
1880 switch (image->storage_type)
1882 case GTK_IMAGE_PIXMAP:
1884 if (image->data.pixmap.pixmap)
1885 g_object_unref (image->data.pixmap.pixmap);
1886 image->data.pixmap.pixmap = NULL;
1888 g_object_notify (G_OBJECT (image), "pixmap");
1892 case GTK_IMAGE_IMAGE:
1894 if (image->data.image.image)
1895 g_object_unref (image->data.image.image);
1896 image->data.image.image = NULL;
1898 g_object_notify (G_OBJECT (image), "image");
1902 case GTK_IMAGE_PIXBUF:
1904 if (image->data.pixbuf.pixbuf)
1905 g_object_unref (image->data.pixbuf.pixbuf);
1907 g_object_notify (G_OBJECT (image), "pixbuf");
1911 case GTK_IMAGE_STOCK:
1913 g_free (image->data.stock.stock_id);
1915 image->data.stock.stock_id = NULL;
1917 g_object_notify (G_OBJECT (image), "stock");
1920 case GTK_IMAGE_ICON_SET:
1921 if (image->data.icon_set.icon_set)
1922 gtk_icon_set_unref (image->data.icon_set.icon_set);
1923 image->data.icon_set.icon_set = NULL;
1925 g_object_notify (G_OBJECT (image), "icon-set");
1928 case GTK_IMAGE_ANIMATION:
1929 gtk_image_reset_anim_iter (image);
1931 if (image->data.anim.anim)
1932 g_object_unref (image->data.anim.anim);
1933 image->data.anim.anim = NULL;
1935 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1939 case GTK_IMAGE_ICON_NAME:
1940 if (image->data.name.icon_name)
1941 g_free (image->data.name.icon_name);
1942 image->data.name.icon_name = NULL;
1943 if (image->data.name.pixbuf)
1944 g_object_unref (image->data.name.pixbuf);
1945 image->data.name.pixbuf = NULL;
1947 g_object_notify (G_OBJECT (image), "icon-name");
1951 case GTK_IMAGE_EMPTY:
1959 g_free (priv->filename);
1960 priv->filename = NULL;
1961 g_object_notify (G_OBJECT (image), "file");
1964 image->storage_type = GTK_IMAGE_EMPTY;
1966 memset (&image->data, '\0', sizeof (image->data));
1968 g_object_thaw_notify (G_OBJECT (image));
1972 gtk_image_reset (GtkImage *image)
1974 gtk_image_clear (image);
1976 gtk_image_update_size (image, 0, 0);
1980 gtk_image_calc_size (GtkImage *image)
1982 GtkWidget *widget = GTK_WIDGET (image);
1983 GdkPixbuf *pixbuf = NULL;
1985 /* We update stock/icon set on every size request, because
1986 * the theme could have affected the size; for other kinds of
1987 * image, we just update the requisition when the image data
1990 switch (image->storage_type)
1992 case GTK_IMAGE_STOCK:
1993 pixbuf = gtk_widget_render_icon (widget,
1994 image->data.stock.stock_id,
1999 case GTK_IMAGE_ICON_SET:
2000 pixbuf = gtk_icon_set_render_icon (image->data.icon_set.icon_set,
2002 gtk_widget_get_direction (widget),
2003 GTK_WIDGET_STATE (widget),
2008 case GTK_IMAGE_ICON_NAME:
2009 ensure_pixbuf_for_icon_name (image);
2010 pixbuf = image->data.name.pixbuf;
2011 if (pixbuf) g_object_ref (pixbuf);
2019 widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
2020 widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
2022 g_object_unref (pixbuf);
2027 gtk_image_size_request (GtkWidget *widget,
2028 GtkRequisition *requisition)
2032 image = GTK_IMAGE (widget);
2034 gtk_image_calc_size (image);
2036 /* Chain up to default that simply reads current requisition */
2037 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
2041 gtk_image_style_set (GtkWidget *widget,
2042 GtkStyle *prev_style)
2046 image = GTK_IMAGE (widget);
2048 if (GTK_WIDGET_CLASS (parent_class)->style_set)
2049 GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
2051 icon_theme_changed (image);
2055 gtk_image_screen_changed (GtkWidget *widget,
2056 GdkScreen *prev_screen)
2060 image = GTK_IMAGE (widget);
2062 if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
2063 GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, prev_screen);
2065 icon_theme_changed (image);
2070 gtk_image_update_size (GtkImage *image,
2074 GTK_WIDGET (image)->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
2075 GTK_WIDGET (image)->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
2077 if (GTK_WIDGET_VISIBLE (image))
2078 gtk_widget_queue_resize (GTK_WIDGET (image));
2083 * gtk_image_set_pixel_size:
2084 * @image: a #GtkImage
2085 * @pixel_size: the new pixel size
2087 * Sets the pixel size to use for named icons. If the pixel size is set
2088 * to a value != -1, it is used instead of the icon size set by
2089 * gtk_image_set_from_icon_name().
2094 gtk_image_set_pixel_size (GtkImage *image,
2097 GtkImagePrivate *priv;
2099 g_return_if_fail (GTK_IS_IMAGE (image));
2101 priv = GTK_IMAGE_GET_PRIVATE (image);
2103 if (priv->pixel_size != pixel_size)
2105 priv->pixel_size = pixel_size;
2107 if (image->storage_type == GTK_IMAGE_ICON_NAME)
2109 if (image->data.name.pixbuf)
2111 g_object_unref (image->data.name.pixbuf);
2112 image->data.name.pixbuf = NULL;
2115 gtk_image_update_size (image, pixel_size, pixel_size);
2118 g_object_notify (G_OBJECT (image), "pixel-size");
2123 * gtk_image_get_pixel_size:
2124 * @image: a #GtkImage
2126 * Gets the pixel size used for named icons.
2128 * Returns: the pixel size used for named icons.
2133 gtk_image_get_pixel_size (GtkImage *image)
2135 GtkImagePrivate *priv;
2137 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2139 priv = GTK_IMAGE_GET_PRIVATE (image);
2141 return priv->pixel_size;
2146 #undef gtk_image_new_from_file
2149 gtk_image_new_from_file (const gchar *filename)
2151 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2154 retval = gtk_image_new_from_file_utf8 (utf8_filename);
2156 g_free (utf8_filename);
2161 #undef gtk_image_set_from_file
2164 gtk_image_set_from_file (GtkImage *image,
2165 const gchar *filename)
2167 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2169 gtk_image_set_from_file_utf8 (image, utf8_filename);
2171 g_free (utf8_filename);
2176 #define __GTK_IMAGE_C__
2177 #include "gtkaliasdef.c"