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"
36 #include "gtksizerequest.h"
38 #include "gtkprivate.h"
42 * @Short_description: A widget displaying an image
44 * @See_also:#GdkPixbuf
46 * The #GtkImage widget displays an image. Various kinds of object
47 * can be displayed as an image; most typically, you would load a
48 * #GdkPixbuf ("pixel buffer") from a file, and then display that.
49 * There's a convenience function to do this, gtk_image_new_from_file(),
51 * <informalexample><programlisting>
53 * image = gtk_image_new_from_file ("myfile.png");
54 * </programlisting></informalexample>
55 * If the file isn't loaded successfully, the image will contain a
56 * "broken image" icon similar to that used in many web browsers.
57 * If you want to handle errors in loading the file yourself,
58 * for example by displaying an error message, then load the image with
59 * gdk_pixbuf_new_from_file(), then create the #GtkImage with
60 * gtk_image_new_from_pixbuf().
62 * The image file may contain an animation, if so the #GtkImage will
63 * display an animation (#GdkPixbufAnimation) instead of a static image.
65 * #GtkImage is a subclass of #GtkMisc, which implies that you can
66 * align it (center, left, right) and add padding to it, using
69 * #GtkImage is a "no window" widget (has no #GdkWindow of its own),
70 * so by default does not receive events. If you want to receive events
71 * on the image, such as button clicks, place the image inside a
72 * #GtkEventBox, then connect to the event signals on the event box.
74 * <title>Handling button press events on a
75 * <structname>GtkImage</structname>.</title>
78 * button_press_callback (GtkWidget *event_box,
79 * GdkEventButton *event,
82 * g_print ("Event box clicked at coordinates %f,%f\n",
83 * event->x, event->y);
85 * /<!---->* Returning TRUE means we handled the event, so the signal
86 * * emission should be stopped (don't call any further
87 * * callbacks that may be connected). Return FALSE
88 * * to continue invoking callbacks.
97 * GtkWidget *event_box;
99 * image = gtk_image_new_from_file ("myfile.png");
101 * event_box = gtk_event_box_new (<!-- -->);
103 * gtk_container_add (GTK_CONTAINER (event_box), image);
105 * g_signal_connect (G_OBJECT (event_box),
106 * "button_press_event",
107 * G_CALLBACK (button_press_callback),
115 * When handling events on the event box, keep in mind that coordinates
116 * in the image may be different from event box coordinates due to
117 * the alignment and padding settings on the image (see #GtkMisc).
118 * The simplest way to solve this is to set the alignment to 0.0
119 * (left/top), and set the padding to zero. Then the origin of
120 * the image will be the same as the origin of the event box.
122 * Sometimes an application will want to avoid depending on external data
123 * files, such as image files. GTK+ comes with a program to avoid this,
124 * called <application>gdk-pixbuf-csource</application>. This program
125 * allows you to convert an image into a C variable declaration, which
126 * can then be loaded into a #GdkPixbuf using
127 * gdk_pixbuf_new_from_inline().
131 struct _GtkImagePrivate
133 GtkIconSize icon_size; /* Only used with GTK_IMAGE_STOCK, GTK_IMAGE_ICON_SET, GTK_IMAGE_ICON_NAME */
134 GtkImageType storage_type;
138 GtkImagePixbufData pixbuf;
139 GtkImageStockData stock;
140 GtkImageIconSetData icon_set;
141 GtkImageAnimationData anim;
142 GtkImageIconNameData name;
143 GtkImageGIconData gicon;
146 gboolean was_symbolic;
147 gchar *filename; /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
148 gint last_rendered_state; /* a GtkStateType, with -1 meaning an invalid state,
149 * only used with GTK_IMAGE_GICON, GTK_IMAGE_ICON_NAME */
151 guint need_calc_size : 1;
153 gint required_height;
157 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
158 static gint gtk_image_draw (GtkWidget *widget,
160 static void gtk_image_unmap (GtkWidget *widget);
161 static void gtk_image_unrealize (GtkWidget *widget);
162 static void gtk_image_size_request (GtkWidget *widget,
163 GtkRequisition *requisition);
164 static void gtk_image_style_set (GtkWidget *widget,
165 GtkStyle *prev_style);
166 static void gtk_image_screen_changed (GtkWidget *widget,
167 GdkScreen *prev_screen);
168 static void gtk_image_destroy (GtkWidget *widget);
169 static void gtk_image_reset (GtkImage *image);
170 static void gtk_image_calc_size (GtkImage *image);
172 static void gtk_image_update_size (GtkImage *image,
176 static void gtk_image_set_property (GObject *object,
180 static void gtk_image_get_property (GObject *object,
185 static void icon_theme_changed (GtkImage *image);
196 PROP_PIXBUF_ANIMATION,
202 G_DEFINE_TYPE (GtkImage, gtk_image, GTK_TYPE_MISC)
205 gtk_image_class_init (GtkImageClass *class)
207 GObjectClass *gobject_class;
208 GtkWidgetClass *widget_class;
210 gobject_class = G_OBJECT_CLASS (class);
212 gobject_class->set_property = gtk_image_set_property;
213 gobject_class->get_property = gtk_image_get_property;
215 widget_class = GTK_WIDGET_CLASS (class);
216 widget_class->draw = gtk_image_draw;
217 widget_class->destroy = gtk_image_destroy;
218 widget_class->size_request = gtk_image_size_request;
219 widget_class->unmap = gtk_image_unmap;
220 widget_class->unrealize = gtk_image_unrealize;
221 widget_class->style_set = gtk_image_style_set;
222 widget_class->screen_changed = gtk_image_screen_changed;
224 g_object_class_install_property (gobject_class,
226 g_param_spec_object ("pixbuf",
228 P_("A GdkPixbuf to display"),
230 GTK_PARAM_READWRITE));
232 g_object_class_install_property (gobject_class,
234 g_param_spec_string ("file",
236 P_("Filename to load and display"),
238 GTK_PARAM_READWRITE));
241 g_object_class_install_property (gobject_class,
243 g_param_spec_string ("stock",
245 P_("Stock ID for a stock image to display"),
247 GTK_PARAM_READWRITE));
249 g_object_class_install_property (gobject_class,
251 g_param_spec_boxed ("icon-set",
253 P_("Icon set to display"),
255 GTK_PARAM_READWRITE));
257 g_object_class_install_property (gobject_class,
259 g_param_spec_int ("icon-size",
261 P_("Symbolic size to use for stock icon, icon set or named icon"),
264 GTK_PARAM_READWRITE));
266 * GtkImage:pixel-size:
268 * The "pixel-size" property can be used to specify a fixed size
269 * overriding the #GtkImage:icon-size property for images of type
270 * %GTK_IMAGE_ICON_NAME.
274 g_object_class_install_property (gobject_class,
276 g_param_spec_int ("pixel-size",
278 P_("Pixel size to use for named icon"),
281 GTK_PARAM_READWRITE));
283 g_object_class_install_property (gobject_class,
284 PROP_PIXBUF_ANIMATION,
285 g_param_spec_object ("pixbuf-animation",
287 P_("GdkPixbufAnimation to display"),
288 GDK_TYPE_PIXBUF_ANIMATION,
289 GTK_PARAM_READWRITE));
292 * GtkImage:icon-name:
294 * The name of the icon in the icon theme. If the icon theme is
295 * changed, the image will be updated automatically.
299 g_object_class_install_property (gobject_class,
301 g_param_spec_string ("icon-name",
303 P_("The name of the icon from the icon theme"),
305 GTK_PARAM_READWRITE));
310 * The GIcon displayed in the GtkImage. For themed icons,
311 * If the icon theme is changed, the image will be updated
316 g_object_class_install_property (gobject_class,
318 g_param_spec_object ("gicon",
320 P_("The GIcon being displayed"),
322 GTK_PARAM_READWRITE));
324 g_object_class_install_property (gobject_class,
326 g_param_spec_enum ("storage-type",
328 P_("The representation being used for image data"),
331 GTK_PARAM_READABLE));
333 g_type_class_add_private (class, sizeof (GtkImagePrivate));
337 gtk_image_init (GtkImage *image)
339 GtkImagePrivate *priv;
341 image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image,
346 gtk_widget_set_has_window (GTK_WIDGET (image), FALSE);
348 priv->storage_type = GTK_IMAGE_EMPTY;
349 priv->icon_size = DEFAULT_ICON_SIZE;
351 priv->pixel_size = -1;
353 priv->filename = NULL;
357 gtk_image_destroy (GtkWidget *widget)
359 GtkImage *image = GTK_IMAGE (widget);
361 gtk_image_reset (image);
363 GTK_WIDGET_CLASS (gtk_image_parent_class)->destroy (widget);
367 gtk_image_set_property (GObject *object,
372 GtkImage *image = GTK_IMAGE (object);
373 GtkImagePrivate *priv = image->priv;
378 gtk_image_set_from_pixbuf (image,
379 g_value_get_object (value));
382 gtk_image_set_from_file (image, g_value_get_string (value));
385 gtk_image_set_from_stock (image, g_value_get_string (value),
389 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
393 if (priv->storage_type == GTK_IMAGE_STOCK)
394 gtk_image_set_from_stock (image,
395 priv->data.stock.stock_id,
396 g_value_get_int (value));
397 else if (priv->storage_type == GTK_IMAGE_ICON_SET)
398 gtk_image_set_from_icon_set (image,
399 priv->data.icon_set.icon_set,
400 g_value_get_int (value));
401 else if (priv->storage_type == GTK_IMAGE_ICON_NAME)
402 gtk_image_set_from_icon_name (image,
403 priv->data.name.icon_name,
404 g_value_get_int (value));
405 else if (priv->storage_type == GTK_IMAGE_GICON)
406 gtk_image_set_from_gicon (image,
407 priv->data.gicon.icon,
408 g_value_get_int (value));
410 /* Save to be used when STOCK, ICON_SET, ICON_NAME or GICON property comes in */
411 priv->icon_size = g_value_get_int (value);
413 case PROP_PIXEL_SIZE:
414 gtk_image_set_pixel_size (image, g_value_get_int (value));
416 case PROP_PIXBUF_ANIMATION:
417 gtk_image_set_from_animation (image,
418 g_value_get_object (value));
421 gtk_image_set_from_icon_name (image, g_value_get_string (value),
425 gtk_image_set_from_gicon (image, g_value_get_object (value),
430 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
436 gtk_image_get_property (GObject *object,
441 GtkImage *image = GTK_IMAGE (object);
442 GtkImagePrivate *priv = image->priv;
444 /* The "getter" functions whine if you try to get the wrong
445 * storage type. This function is instead robust against that,
446 * so that GUI builders don't have to jump through hoops
453 if (priv->storage_type != GTK_IMAGE_PIXBUF)
454 g_value_set_object (value, NULL);
456 g_value_set_object (value,
457 gtk_image_get_pixbuf (image));
460 g_value_set_string (value, priv->filename);
463 if (priv->storage_type != GTK_IMAGE_STOCK)
464 g_value_set_string (value, NULL);
466 g_value_set_string (value,
467 priv->data.stock.stock_id);
470 if (priv->storage_type != GTK_IMAGE_ICON_SET)
471 g_value_set_boxed (value, NULL);
473 g_value_set_boxed (value,
474 priv->data.icon_set.icon_set);
477 g_value_set_int (value, priv->icon_size);
479 case PROP_PIXEL_SIZE:
480 g_value_set_int (value, priv->pixel_size);
482 case PROP_PIXBUF_ANIMATION:
483 if (priv->storage_type != GTK_IMAGE_ANIMATION)
484 g_value_set_object (value, NULL);
486 g_value_set_object (value,
487 priv->data.anim.anim);
490 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
491 g_value_set_string (value, NULL);
493 g_value_set_string (value,
494 priv->data.name.icon_name);
497 if (priv->storage_type != GTK_IMAGE_GICON)
498 g_value_set_object (value, NULL);
500 g_value_set_object (value,
501 priv->data.gicon.icon);
503 case PROP_STORAGE_TYPE:
504 g_value_set_enum (value, priv->storage_type);
508 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
515 * gtk_image_new_from_file:
516 * @filename: a filename
518 * Creates a new #GtkImage displaying the file @filename. If the file
519 * isn't found or can't be loaded, the resulting #GtkImage will
520 * display a "broken image" icon. This function never returns %NULL,
521 * it always returns a valid #GtkImage widget.
523 * If the file contains an animation, the image will contain an
526 * If you need to detect failures to load the file, use
527 * gdk_pixbuf_new_from_file() to load the file yourself, then create
528 * the #GtkImage from the pixbuf. (Or for animations, use
529 * gdk_pixbuf_animation_new_from_file()).
531 * The storage type (gtk_image_get_storage_type()) of the returned
532 * image is not defined, it will be whatever is appropriate for
533 * displaying the file.
535 * Return value: a new #GtkImage
538 gtk_image_new_from_file (const gchar *filename)
542 image = g_object_new (GTK_TYPE_IMAGE, NULL);
544 gtk_image_set_from_file (image, filename);
546 return GTK_WIDGET (image);
550 * gtk_image_new_from_pixbuf:
551 * @pixbuf: (allow-none): a #GdkPixbuf, or %NULL
553 * Creates a new #GtkImage displaying @pixbuf.
554 * The #GtkImage does not assume a reference to the
555 * pixbuf; you still need to unref it if you own references.
556 * #GtkImage will add its own reference rather than adopting yours.
558 * Note that this function just creates an #GtkImage from the pixbuf. The
559 * #GtkImage created will not react to state changes. Should you want that,
560 * you should use gtk_image_new_from_icon_set().
562 * Return value: a new #GtkImage
565 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
569 image = g_object_new (GTK_TYPE_IMAGE, NULL);
571 gtk_image_set_from_pixbuf (image, pixbuf);
573 return GTK_WIDGET (image);
577 * gtk_image_new_from_stock:
578 * @stock_id: a stock icon name
579 * @size: (type int): a stock icon size
581 * Creates a #GtkImage displaying a stock icon. Sample stock icon
582 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. Sample stock sizes
583 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
584 * icon name isn't known, the image will be empty.
585 * You can register your own stock icon names, see
586 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
588 * Return value: a new #GtkImage displaying the stock icon
591 gtk_image_new_from_stock (const gchar *stock_id,
596 image = g_object_new (GTK_TYPE_IMAGE, NULL);
598 gtk_image_set_from_stock (image, stock_id, size);
600 return GTK_WIDGET (image);
604 * gtk_image_new_from_icon_set:
605 * @icon_set: a #GtkIconSet
606 * @size: (type int): a stock icon size
608 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
609 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
610 * this function, usually it's better to create a #GtkIconFactory, put
611 * your icon sets in the icon factory, add the icon factory to the
612 * list of default factories with gtk_icon_factory_add_default(), and
613 * then use gtk_image_new_from_stock(). This will allow themes to
614 * override the icon you ship with your application.
616 * The #GtkImage does not assume a reference to the
617 * icon set; you still need to unref it if you own references.
618 * #GtkImage will add its own reference rather than adopting yours.
620 * Return value: a new #GtkImage
623 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
628 image = g_object_new (GTK_TYPE_IMAGE, NULL);
630 gtk_image_set_from_icon_set (image, icon_set, size);
632 return GTK_WIDGET (image);
636 * gtk_image_new_from_animation:
637 * @animation: an animation
639 * Creates a #GtkImage displaying the given animation.
640 * The #GtkImage does not assume a reference to the
641 * animation; you still need to unref it if you own references.
642 * #GtkImage will add its own reference rather than adopting yours.
644 * Note that the animation frames are shown using a timeout with
645 * #G_PRIORITY_DEFAULT. When using animations to indicate busyness,
646 * keep in mind that the animation will only be shown if the main loop
647 * is not busy with something that has a higher priority.
649 * Return value: a new #GtkImage widget
652 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
656 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
658 image = g_object_new (GTK_TYPE_IMAGE, NULL);
660 gtk_image_set_from_animation (image, animation);
662 return GTK_WIDGET (image);
666 * gtk_image_new_from_icon_name:
667 * @icon_name: an icon name
668 * @size: (type int): a stock icon size
670 * Creates a #GtkImage displaying an icon from the current icon theme.
671 * If the icon name isn't known, a "broken image" icon will be
672 * displayed instead. If the current icon theme is changed, the icon
673 * will be updated appropriately.
675 * Return value: a new #GtkImage displaying the themed icon
680 gtk_image_new_from_icon_name (const gchar *icon_name,
685 image = g_object_new (GTK_TYPE_IMAGE, NULL);
687 gtk_image_set_from_icon_name (image, icon_name, size);
689 return GTK_WIDGET (image);
693 * gtk_image_new_from_gicon:
695 * @size: (type int): a stock icon size
697 * Creates a #GtkImage displaying an icon from the current icon theme.
698 * If the icon name isn't known, a "broken image" icon will be
699 * displayed instead. If the current icon theme is changed, the icon
700 * will be updated appropriately.
702 * Return value: a new #GtkImage displaying the themed icon
707 gtk_image_new_from_gicon (GIcon *icon,
712 image = g_object_new (GTK_TYPE_IMAGE, NULL);
714 gtk_image_set_from_gicon (image, icon, size);
716 return GTK_WIDGET (image);
720 * gtk_image_set_from_file:
721 * @image: a #GtkImage
722 * @filename: (allow-none): a filename or %NULL
724 * See gtk_image_new_from_file() for details.
727 gtk_image_set_from_file (GtkImage *image,
728 const gchar *filename)
730 GtkImagePrivate *priv;
731 GdkPixbufAnimation *anim;
733 g_return_if_fail (GTK_IS_IMAGE (image));
737 g_object_freeze_notify (G_OBJECT (image));
739 gtk_image_clear (image);
741 if (filename == NULL)
743 priv->filename = NULL;
744 g_object_thaw_notify (G_OBJECT (image));
748 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
752 gtk_image_set_from_stock (image,
753 GTK_STOCK_MISSING_IMAGE,
754 GTK_ICON_SIZE_BUTTON);
755 g_object_thaw_notify (G_OBJECT (image));
759 /* We could just unconditionally set_from_animation,
760 * but it's nicer for memory if we toss the animation
761 * if it's just a single pixbuf
764 if (gdk_pixbuf_animation_is_static_image (anim))
765 gtk_image_set_from_pixbuf (image,
766 gdk_pixbuf_animation_get_static_image (anim));
768 gtk_image_set_from_animation (image, anim);
770 g_object_unref (anim);
772 priv->filename = g_strdup (filename);
774 g_object_thaw_notify (G_OBJECT (image));
778 * gtk_image_set_from_pixbuf:
779 * @image: a #GtkImage
780 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
782 * See gtk_image_new_from_pixbuf() for details.
785 gtk_image_set_from_pixbuf (GtkImage *image,
788 GtkImagePrivate *priv;
790 g_return_if_fail (GTK_IS_IMAGE (image));
791 g_return_if_fail (pixbuf == NULL ||
792 GDK_IS_PIXBUF (pixbuf));
796 g_object_freeze_notify (G_OBJECT (image));
799 g_object_ref (pixbuf);
801 gtk_image_clear (image);
805 priv->storage_type = GTK_IMAGE_PIXBUF;
807 priv->data.pixbuf.pixbuf = pixbuf;
809 gtk_image_update_size (image,
810 gdk_pixbuf_get_width (pixbuf),
811 gdk_pixbuf_get_height (pixbuf));
814 g_object_notify (G_OBJECT (image), "pixbuf");
816 g_object_thaw_notify (G_OBJECT (image));
820 * gtk_image_set_from_stock:
821 * @image: a #GtkImage
822 * @stock_id: a stock icon name
823 * @size: (type int): a stock icon size
825 * See gtk_image_new_from_stock() for details.
828 gtk_image_set_from_stock (GtkImage *image,
829 const gchar *stock_id,
832 GtkImagePrivate *priv;
835 g_return_if_fail (GTK_IS_IMAGE (image));
839 g_object_freeze_notify (G_OBJECT (image));
841 /* in case stock_id == priv->data.stock.stock_id */
842 new_id = g_strdup (stock_id);
844 gtk_image_clear (image);
848 priv->storage_type = GTK_IMAGE_STOCK;
850 priv->data.stock.stock_id = new_id;
851 priv->icon_size = size;
853 /* Size is demand-computed in size request method
854 * if we're a stock image, since changing the
855 * style impacts the size request
859 g_object_notify (G_OBJECT (image), "stock");
860 g_object_notify (G_OBJECT (image), "icon-size");
862 g_object_thaw_notify (G_OBJECT (image));
866 * gtk_image_set_from_icon_set:
867 * @image: a #GtkImage
868 * @icon_set: a #GtkIconSet
869 * @size: (type int): a stock icon size
871 * See gtk_image_new_from_icon_set() for details.
874 gtk_image_set_from_icon_set (GtkImage *image,
875 GtkIconSet *icon_set,
878 GtkImagePrivate *priv;
880 g_return_if_fail (GTK_IS_IMAGE (image));
884 g_object_freeze_notify (G_OBJECT (image));
887 gtk_icon_set_ref (icon_set);
889 gtk_image_clear (image);
893 priv->storage_type = GTK_IMAGE_ICON_SET;
895 priv->data.icon_set.icon_set = icon_set;
896 priv->icon_size = size;
898 /* Size is demand-computed in size request method
899 * if we're an icon set
903 g_object_notify (G_OBJECT (image), "icon-set");
904 g_object_notify (G_OBJECT (image), "icon-size");
906 g_object_thaw_notify (G_OBJECT (image));
910 * gtk_image_set_from_animation:
911 * @image: a #GtkImage
912 * @animation: the #GdkPixbufAnimation
914 * Causes the #GtkImage to display the given animation (or display
915 * nothing, if you set the animation to %NULL).
918 gtk_image_set_from_animation (GtkImage *image,
919 GdkPixbufAnimation *animation)
921 GtkImagePrivate *priv;
923 g_return_if_fail (GTK_IS_IMAGE (image));
924 g_return_if_fail (animation == NULL ||
925 GDK_IS_PIXBUF_ANIMATION (animation));
929 g_object_freeze_notify (G_OBJECT (image));
932 g_object_ref (animation);
934 gtk_image_clear (image);
936 if (animation != NULL)
938 priv->storage_type = GTK_IMAGE_ANIMATION;
940 priv->data.anim.anim = animation;
941 priv->data.anim.frame_timeout = 0;
942 priv->data.anim.iter = NULL;
944 gtk_image_update_size (image,
945 gdk_pixbuf_animation_get_width (animation),
946 gdk_pixbuf_animation_get_height (animation));
949 g_object_notify (G_OBJECT (image), "pixbuf-animation");
951 g_object_thaw_notify (G_OBJECT (image));
955 * gtk_image_set_from_icon_name:
956 * @image: a #GtkImage
957 * @icon_name: an icon name
958 * @size: (type int): an icon size
960 * See gtk_image_new_from_icon_name() for details.
965 gtk_image_set_from_icon_name (GtkImage *image,
966 const gchar *icon_name,
970 GtkImagePrivate *priv;
972 g_return_if_fail (GTK_IS_IMAGE (image));
976 g_object_freeze_notify (G_OBJECT (image));
978 /* in case icon_name == priv->data.name.icon_name */
979 new_name = g_strdup (icon_name);
981 gtk_image_clear (image);
985 priv->storage_type = GTK_IMAGE_ICON_NAME;
987 priv->data.name.icon_name = new_name;
988 priv->icon_size = size;
990 /* Size is demand-computed in size request method
991 * if we're a icon theme image, since changing the
992 * style impacts the size request
996 g_object_notify (G_OBJECT (image), "icon-name");
997 g_object_notify (G_OBJECT (image), "icon-size");
999 g_object_thaw_notify (G_OBJECT (image));
1003 * gtk_image_set_from_gicon:
1004 * @image: a #GtkImage
1006 * @size: (type int): an icon size
1008 * See gtk_image_new_from_gicon() for details.
1013 gtk_image_set_from_gicon (GtkImage *image,
1017 GtkImagePrivate *priv;
1019 g_return_if_fail (GTK_IS_IMAGE (image));
1023 g_object_freeze_notify (G_OBJECT (image));
1025 /* in case icon == priv->data.gicon.icon */
1027 g_object_ref (icon);
1029 gtk_image_clear (image);
1033 priv->storage_type = GTK_IMAGE_GICON;
1035 priv->data.gicon.icon = icon;
1036 priv->icon_size = size;
1038 /* Size is demand-computed in size request method
1039 * if we're a icon theme image, since changing the
1040 * style impacts the size request
1044 g_object_notify (G_OBJECT (image), "gicon");
1045 g_object_notify (G_OBJECT (image), "icon-size");
1047 g_object_thaw_notify (G_OBJECT (image));
1051 * gtk_image_get_storage_type:
1052 * @image: a #GtkImage
1054 * Gets the type of representation being used by the #GtkImage
1055 * to store image data. If the #GtkImage has no image data,
1056 * the return value will be %GTK_IMAGE_EMPTY.
1058 * Return value: image representation being used
1061 gtk_image_get_storage_type (GtkImage *image)
1063 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1065 return image->priv->storage_type;
1069 * gtk_image_get_pixbuf:
1070 * @image: a #GtkImage
1072 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1073 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1074 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1075 * The caller of this function does not own a reference to the
1078 * Return value: (transfer none): the displayed pixbuf, or %NULL if
1079 * the image is empty
1082 gtk_image_get_pixbuf (GtkImage *image)
1084 GtkImagePrivate *priv;
1086 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1090 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
1091 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1093 if (priv->storage_type == GTK_IMAGE_EMPTY)
1094 priv->data.pixbuf.pixbuf = NULL;
1096 return priv->data.pixbuf.pixbuf;
1100 * gtk_image_get_stock:
1101 * @image: a #GtkImage
1102 * @stock_id: (out) (transfer none) (allow-none): place to store a
1103 * stock icon name, or %NULL
1104 * @size: (out) (allow-none) (type int): place to store a stock icon
1107 * Gets the stock icon name and size being displayed by the #GtkImage.
1108 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1109 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1110 * The returned string is owned by the #GtkImage and should not
1114 gtk_image_get_stock (GtkImage *image,
1118 GtkImagePrivate *priv;
1120 g_return_if_fail (GTK_IS_IMAGE (image));
1124 g_return_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
1125 priv->storage_type == GTK_IMAGE_EMPTY);
1127 if (priv->storage_type == GTK_IMAGE_EMPTY)
1128 priv->data.stock.stock_id = NULL;
1131 *stock_id = priv->data.stock.stock_id;
1134 *size = priv->icon_size;
1138 * gtk_image_get_icon_set:
1139 * @image: a #GtkImage
1140 * @icon_set: (out) (transfer none) (allow-none): location to store a
1141 * #GtkIconSet, or %NULL
1142 * @size: (out) (allow-none) (type int): location to store a stock
1143 * icon size, or %NULL
1145 * Gets the icon set and size being displayed by the #GtkImage.
1146 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1147 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1150 gtk_image_get_icon_set (GtkImage *image,
1151 GtkIconSet **icon_set,
1154 GtkImagePrivate *priv;
1156 g_return_if_fail (GTK_IS_IMAGE (image));
1160 g_return_if_fail (priv->storage_type == GTK_IMAGE_ICON_SET ||
1161 priv->storage_type == GTK_IMAGE_EMPTY);
1164 *icon_set = priv->data.icon_set.icon_set;
1167 *size = priv->icon_size;
1171 * gtk_image_get_animation:
1172 * @image: a #GtkImage
1174 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1175 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1176 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1177 * The caller of this function does not own a reference to the
1178 * returned animation.
1180 * Return value: (transfer none): the displayed animation, or %NULL if
1181 * the image is empty
1184 gtk_image_get_animation (GtkImage *image)
1186 GtkImagePrivate *priv;
1188 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1192 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ANIMATION ||
1193 priv->storage_type == GTK_IMAGE_EMPTY,
1196 if (priv->storage_type == GTK_IMAGE_EMPTY)
1197 priv->data.anim.anim = NULL;
1199 return priv->data.anim.anim;
1203 * gtk_image_get_icon_name:
1204 * @image: a #GtkImage
1205 * @icon_name: (out) (transfer none) (allow-none): place to store an
1206 * icon name, or %NULL
1207 * @size: (out) (allow-none) (type int): place to store an icon size,
1210 * Gets the icon name and size being displayed by the #GtkImage.
1211 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1212 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1213 * The returned string is owned by the #GtkImage and should not
1219 gtk_image_get_icon_name (GtkImage *image,
1220 G_CONST_RETURN gchar **icon_name,
1223 GtkImagePrivate *priv;
1225 g_return_if_fail (GTK_IS_IMAGE (image));
1229 g_return_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
1230 priv->storage_type == GTK_IMAGE_EMPTY);
1232 if (priv->storage_type == GTK_IMAGE_EMPTY)
1233 priv->data.name.icon_name = NULL;
1236 *icon_name = priv->data.name.icon_name;
1239 *size = priv->icon_size;
1243 * gtk_image_get_gicon:
1244 * @image: a #GtkImage
1245 * @gicon: (out) (transfer none) (allow-none): place to store a
1247 * @size: (out) (allow-none) (type int): place to store an icon size,
1250 * Gets the #GIcon and size being displayed by the #GtkImage.
1251 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1252 * %GTK_IMAGE_GICON (see gtk_image_get_storage_type()).
1253 * The caller of this function does not own a reference to the
1259 gtk_image_get_gicon (GtkImage *image,
1263 GtkImagePrivate *priv;
1265 g_return_if_fail (GTK_IS_IMAGE (image));
1269 g_return_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
1270 priv->storage_type == GTK_IMAGE_EMPTY);
1272 if (priv->storage_type == GTK_IMAGE_EMPTY)
1273 priv->data.gicon.icon = NULL;
1276 *gicon = priv->data.gicon.icon;
1279 *size = priv->icon_size;
1285 * Creates a new empty #GtkImage widget.
1287 * Return value: a newly created #GtkImage widget.
1290 gtk_image_new (void)
1292 return g_object_new (GTK_TYPE_IMAGE, NULL);
1296 gtk_image_reset_anim_iter (GtkImage *image)
1298 GtkImagePrivate *priv = image->priv;
1300 if (priv->storage_type == GTK_IMAGE_ANIMATION)
1302 /* Reset the animation */
1304 if (priv->data.anim.frame_timeout)
1306 g_source_remove (priv->data.anim.frame_timeout);
1307 priv->data.anim.frame_timeout = 0;
1310 if (priv->data.anim.iter)
1312 g_object_unref (priv->data.anim.iter);
1313 priv->data.anim.iter = NULL;
1319 gtk_image_unmap (GtkWidget *widget)
1321 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1323 GTK_WIDGET_CLASS (gtk_image_parent_class)->unmap (widget);
1327 gtk_image_unrealize (GtkWidget *widget)
1329 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1331 GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize (widget);
1335 animation_timeout (gpointer data)
1337 GtkImage *image = GTK_IMAGE (data);
1338 GtkImagePrivate *priv = image->priv;
1341 priv->data.anim.frame_timeout = 0;
1343 gdk_pixbuf_animation_iter_advance (priv->data.anim.iter, NULL);
1345 delay = gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter);
1348 GtkWidget *widget = GTK_WIDGET (image);
1350 priv->data.anim.frame_timeout =
1351 gdk_threads_add_timeout (delay, animation_timeout, image);
1353 gtk_widget_queue_draw (widget);
1355 if (gtk_widget_is_drawable (widget))
1356 gdk_window_process_updates (gtk_widget_get_window (widget), TRUE);
1363 icon_theme_changed (GtkImage *image)
1365 GtkImagePrivate *priv = image->priv;
1367 if (priv->storage_type == GTK_IMAGE_ICON_NAME)
1369 if (priv->data.name.pixbuf)
1370 g_object_unref (priv->data.name.pixbuf);
1371 priv->data.name.pixbuf = NULL;
1373 gtk_widget_queue_draw (GTK_WIDGET (image));
1375 if (priv->storage_type == GTK_IMAGE_GICON)
1377 if (priv->data.gicon.pixbuf)
1378 g_object_unref (priv->data.gicon.pixbuf);
1379 priv->data.gicon.pixbuf = NULL;
1381 gtk_widget_queue_draw (GTK_WIDGET (image));
1386 ensure_pixbuf_for_icon_name (GtkImage *image,
1389 GtkImagePrivate *priv = image->priv;
1391 GtkIconTheme *icon_theme;
1392 GtkSettings *settings;
1394 gint *sizes, *s, dist;
1396 GtkIconLookupFlags flags;
1398 g_return_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME);
1400 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1401 icon_theme = gtk_icon_theme_get_for_screen (screen);
1402 settings = gtk_settings_get_for_screen (screen);
1403 flags = GTK_ICON_LOOKUP_USE_BUILTIN;
1404 if (priv->data.name.pixbuf == NULL ||
1405 (priv->was_symbolic && priv->last_rendered_state != state))
1407 priv->last_rendered_state = state;
1408 if (priv->data.name.pixbuf)
1410 g_object_unref (priv->data.name.pixbuf);
1411 priv->data.name.pixbuf = NULL;
1413 if (priv->pixel_size != -1)
1415 width = height = priv->pixel_size;
1416 flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
1418 else if (!gtk_icon_size_lookup_for_settings (settings,
1422 if (priv->icon_size == -1)
1424 /* Find an available size close to 48 */
1425 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->data.name.icon_name);
1427 width = height = 48;
1428 for (s = sizes; *s; s++)
1432 width = height = 48;
1439 width = height = *s;
1447 width = height = *s;
1456 g_warning ("Invalid icon size %d\n", priv->icon_size);
1457 width = height = 24;
1461 info = gtk_icon_theme_lookup_icon (icon_theme,
1462 priv->data.name.icon_name,
1463 MIN (width, height), flags);
1467 gboolean was_symbolic;
1469 style = gtk_widget_get_style (GTK_WIDGET (image));
1470 priv->data.name.pixbuf =
1471 gtk_icon_info_load_symbolic_for_style (info,
1475 priv->was_symbolic = was_symbolic;
1476 gtk_icon_info_free (info);
1479 if (priv->data.name.pixbuf == NULL)
1481 priv->data.name.pixbuf =
1482 gtk_widget_render_icon (GTK_WIDGET (image),
1483 GTK_STOCK_MISSING_IMAGE,
1486 priv->was_symbolic = FALSE;
1492 ensure_pixbuf_for_gicon (GtkImage *image,
1495 GtkImagePrivate *priv = image->priv;
1497 GtkIconTheme *icon_theme;
1498 GtkSettings *settings;
1501 GtkIconLookupFlags flags;
1503 g_return_if_fail (priv->storage_type == GTK_IMAGE_GICON);
1505 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1506 icon_theme = gtk_icon_theme_get_for_screen (screen);
1507 settings = gtk_settings_get_for_screen (screen);
1508 flags = GTK_ICON_LOOKUP_USE_BUILTIN;
1509 if (priv->data.gicon.pixbuf == NULL ||
1510 (priv->was_symbolic && priv->last_rendered_state != state))
1512 priv->last_rendered_state = state;
1513 if (priv->data.gicon.pixbuf)
1515 g_object_unref (priv->data.gicon.pixbuf);
1516 priv->data.gicon.pixbuf = NULL;
1518 if (priv->pixel_size != -1)
1520 width = height = priv->pixel_size;
1521 flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
1523 else if (!gtk_icon_size_lookup_for_settings (settings,
1527 if (priv->icon_size == -1)
1528 width = height = 48;
1531 g_warning ("Invalid icon size %d\n", priv->icon_size);
1532 width = height = 24;
1536 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
1537 priv->data.gicon.icon,
1538 MIN (width, height), flags);
1542 gboolean was_symbolic;
1544 style = gtk_widget_get_style (GTK_WIDGET (image));
1545 priv->data.gicon.pixbuf =
1546 gtk_icon_info_load_symbolic_for_style (info,
1550 priv->was_symbolic = was_symbolic;
1551 gtk_icon_info_free (info);
1554 if (priv->data.gicon.pixbuf == NULL)
1556 priv->data.gicon.pixbuf =
1557 gtk_widget_render_icon (GTK_WIDGET (image),
1558 GTK_STOCK_MISSING_IMAGE,
1561 priv->was_symbolic = FALSE;
1567 gtk_image_draw (GtkWidget *widget,
1571 GtkImagePrivate *priv;
1573 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1575 image = GTK_IMAGE (widget);
1578 if (priv->storage_type != GTK_IMAGE_EMPTY)
1583 gfloat xalign, yalign;
1586 gboolean needs_state_transform;
1588 misc = GTK_MISC (widget);
1590 /* For stock items and icon sets, we lazily calculate
1591 * the size; we might get here between a queue_resize()
1592 * and size_request() if something explicitely forces
1595 if (priv->need_calc_size)
1596 gtk_image_calc_size (image);
1598 gtk_misc_get_alignment (misc, &xalign, &yalign);
1599 gtk_misc_get_padding (misc, &xpad, &ypad);
1601 if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
1602 xalign = 1.0 - xalign;
1604 x = floor (xpad + ((gtk_widget_get_allocated_width (widget) - priv->required_width) * xalign));
1605 y = floor (ypad + ((gtk_widget_get_allocated_height (widget) - priv->required_height) * yalign));
1607 needs_state_transform = gtk_widget_get_state (widget) != GTK_STATE_NORMAL;
1609 switch (priv->storage_type)
1612 case GTK_IMAGE_PIXBUF:
1613 pixbuf = priv->data.pixbuf.pixbuf;
1614 g_object_ref (pixbuf);
1617 case GTK_IMAGE_STOCK:
1618 pixbuf = gtk_widget_render_icon (widget,
1619 priv->data.stock.stock_id,
1624 needs_state_transform = FALSE;
1627 case GTK_IMAGE_ICON_SET:
1629 gtk_icon_set_render_icon (priv->data.icon_set.icon_set,
1630 gtk_widget_get_style (widget),
1631 gtk_widget_get_direction (widget),
1632 gtk_widget_get_state (widget),
1638 needs_state_transform = FALSE;
1641 case GTK_IMAGE_ANIMATION:
1643 if (priv->data.anim.iter == NULL)
1645 priv->data.anim.iter = gdk_pixbuf_animation_get_iter (priv->data.anim.anim, NULL);
1647 if (gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter) >= 0)
1648 priv->data.anim.frame_timeout =
1649 gdk_threads_add_timeout (gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter),
1654 /* don't advance the anim iter here, or we could get frame changes between two
1655 * exposes of different areas.
1658 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (priv->data.anim.iter);
1659 g_object_ref (pixbuf);
1663 case GTK_IMAGE_ICON_NAME:
1664 state = gtk_widget_get_state (widget);
1665 if (state == GTK_STATE_INSENSITIVE)
1667 ensure_pixbuf_for_icon_name (image, GTK_STATE_NORMAL);
1671 ensure_pixbuf_for_icon_name (image, state);
1672 /* Already done by the loading function? */
1673 if (priv->was_symbolic)
1674 needs_state_transform = FALSE;
1676 pixbuf = priv->data.name.pixbuf;
1679 g_object_ref (pixbuf);
1683 case GTK_IMAGE_GICON:
1684 state = gtk_widget_get_state (widget);
1685 if (state == GTK_STATE_INSENSITIVE)
1687 ensure_pixbuf_for_gicon (image, GTK_STATE_NORMAL);
1691 ensure_pixbuf_for_gicon (image, state);
1692 /* Already done by the loading function? */
1693 if (priv->was_symbolic)
1694 needs_state_transform = FALSE;
1696 pixbuf = priv->data.gicon.pixbuf;
1699 g_object_ref (pixbuf);
1703 case GTK_IMAGE_EMPTY:
1705 g_assert_not_reached ();
1712 if (needs_state_transform)
1714 GtkIconSource *source;
1715 GdkPixbuf *rendered;
1717 source = gtk_icon_source_new ();
1718 gtk_icon_source_set_pixbuf (source, pixbuf);
1719 /* The size here is arbitrary; since size isn't
1720 * wildcarded in the souce, it isn't supposed to be
1721 * scaled by the engine function
1723 gtk_icon_source_set_size (source,
1724 GTK_ICON_SIZE_SMALL_TOOLBAR);
1725 gtk_icon_source_set_size_wildcarded (source, FALSE);
1727 rendered = gtk_style_render_icon (gtk_widget_get_style (widget),
1729 gtk_widget_get_direction (widget),
1730 gtk_widget_get_state (widget),
1736 gtk_icon_source_free (source);
1738 g_object_unref (pixbuf);
1742 gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
1745 g_object_unref (pixbuf);
1753 gtk_image_reset (GtkImage *image)
1755 GtkImagePrivate *priv = image->priv;
1757 g_object_freeze_notify (G_OBJECT (image));
1759 if (priv->storage_type != GTK_IMAGE_EMPTY)
1760 g_object_notify (G_OBJECT (image), "storage-type");
1762 if (priv->icon_size != DEFAULT_ICON_SIZE)
1764 priv->icon_size = DEFAULT_ICON_SIZE;
1765 g_object_notify (G_OBJECT (image), "icon-size");
1768 switch (priv->storage_type)
1771 case GTK_IMAGE_PIXBUF:
1773 if (priv->data.pixbuf.pixbuf)
1774 g_object_unref (priv->data.pixbuf.pixbuf);
1776 g_object_notify (G_OBJECT (image), "pixbuf");
1780 case GTK_IMAGE_STOCK:
1782 g_free (priv->data.stock.stock_id);
1784 priv->data.stock.stock_id = NULL;
1786 g_object_notify (G_OBJECT (image), "stock");
1789 case GTK_IMAGE_ICON_SET:
1790 if (priv->data.icon_set.icon_set)
1791 gtk_icon_set_unref (priv->data.icon_set.icon_set);
1792 priv->data.icon_set.icon_set = NULL;
1794 g_object_notify (G_OBJECT (image), "icon-set");
1797 case GTK_IMAGE_ANIMATION:
1798 gtk_image_reset_anim_iter (image);
1800 if (priv->data.anim.anim)
1801 g_object_unref (priv->data.anim.anim);
1802 priv->data.anim.anim = NULL;
1804 g_object_notify (G_OBJECT (image), "pixbuf-animation");
1808 case GTK_IMAGE_ICON_NAME:
1809 g_free (priv->data.name.icon_name);
1810 priv->data.name.icon_name = NULL;
1811 if (priv->data.name.pixbuf)
1812 g_object_unref (priv->data.name.pixbuf);
1813 priv->data.name.pixbuf = NULL;
1815 g_object_notify (G_OBJECT (image), "icon-name");
1819 case GTK_IMAGE_GICON:
1820 if (priv->data.gicon.icon)
1821 g_object_unref (priv->data.gicon.icon);
1822 priv->data.gicon.icon = NULL;
1823 if (priv->data.gicon.pixbuf)
1824 g_object_unref (priv->data.gicon.pixbuf);
1825 priv->data.gicon.pixbuf = NULL;
1827 g_object_notify (G_OBJECT (image), "gicon");
1831 case GTK_IMAGE_EMPTY:
1839 g_free (priv->filename);
1840 priv->filename = NULL;
1841 g_object_notify (G_OBJECT (image), "file");
1844 priv->storage_type = GTK_IMAGE_EMPTY;
1846 memset (&priv->data, '\0', sizeof (priv->data));
1848 g_object_thaw_notify (G_OBJECT (image));
1853 * @image: a #GtkImage
1855 * Resets the image to be empty.
1860 gtk_image_clear (GtkImage *image)
1862 GtkImagePrivate *priv = image->priv;
1864 priv->need_calc_size = 1;
1866 gtk_image_reset (image);
1867 gtk_image_update_size (image, 0, 0);
1871 gtk_image_calc_size (GtkImage *image)
1873 GtkWidget *widget = GTK_WIDGET (image);
1874 GtkImagePrivate *priv = image->priv;
1875 GdkPixbuf *pixbuf = NULL;
1877 priv->need_calc_size = 0;
1879 /* We update stock/icon set on every size request, because
1880 * the theme could have affected the size; for other kinds of
1881 * image, we just update the required width/height when the image data
1884 switch (priv->storage_type)
1886 case GTK_IMAGE_STOCK:
1887 pixbuf = gtk_widget_render_icon (widget,
1888 priv->data.stock.stock_id,
1893 case GTK_IMAGE_ICON_SET:
1894 pixbuf = gtk_icon_set_render_icon (priv->data.icon_set.icon_set,
1895 gtk_widget_get_style (widget),
1896 gtk_widget_get_direction (widget),
1897 gtk_widget_get_state (widget),
1902 case GTK_IMAGE_ICON_NAME:
1903 ensure_pixbuf_for_icon_name (image, GTK_STATE_NORMAL);
1904 pixbuf = priv->data.name.pixbuf;
1905 if (pixbuf) g_object_ref (pixbuf);
1907 case GTK_IMAGE_GICON:
1908 ensure_pixbuf_for_gicon (image, GTK_STATE_NORMAL);
1909 pixbuf = priv->data.gicon.pixbuf;
1911 g_object_ref (pixbuf);
1921 gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
1923 priv->required_width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
1924 priv->required_height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
1926 g_object_unref (pixbuf);
1931 gtk_image_size_request (GtkWidget *widget,
1932 GtkRequisition *requisition)
1935 GtkImagePrivate *priv;
1937 image = GTK_IMAGE (widget);
1940 gtk_image_calc_size (image);
1942 requisition->width = priv->required_width;
1943 requisition->height = priv->required_height;
1947 gtk_image_style_set (GtkWidget *widget,
1948 GtkStyle *prev_style)
1952 image = GTK_IMAGE (widget);
1954 GTK_WIDGET_CLASS (gtk_image_parent_class)->style_set (widget, prev_style);
1956 icon_theme_changed (image);
1960 gtk_image_screen_changed (GtkWidget *widget,
1961 GdkScreen *prev_screen)
1965 image = GTK_IMAGE (widget);
1967 if (GTK_WIDGET_CLASS (gtk_image_parent_class)->screen_changed)
1968 GTK_WIDGET_CLASS (gtk_image_parent_class)->screen_changed (widget, prev_screen);
1970 icon_theme_changed (image);
1975 gtk_image_update_size (GtkImage *image,
1979 GtkWidget *widget = GTK_WIDGET (image);
1980 GtkImagePrivate *priv = image->priv;
1983 gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
1985 priv->required_width = image_width + xpad * 2;
1986 priv->required_height = image_height + ypad * 2;
1988 if (gtk_widget_get_visible (widget))
1989 gtk_widget_queue_resize (widget);
1994 * gtk_image_set_pixel_size:
1995 * @image: a #GtkImage
1996 * @pixel_size: the new pixel size
1998 * Sets the pixel size to use for named icons. If the pixel size is set
1999 * to a value != -1, it is used instead of the icon size set by
2000 * gtk_image_set_from_icon_name().
2005 gtk_image_set_pixel_size (GtkImage *image,
2008 GtkImagePrivate *priv;
2010 g_return_if_fail (GTK_IS_IMAGE (image));
2014 if (priv->pixel_size != pixel_size)
2016 priv->pixel_size = pixel_size;
2018 if (priv->storage_type == GTK_IMAGE_ICON_NAME)
2020 if (priv->data.name.pixbuf)
2022 g_object_unref (priv->data.name.pixbuf);
2023 priv->data.name.pixbuf = NULL;
2026 gtk_image_update_size (image, pixel_size, pixel_size);
2029 if (priv->storage_type == GTK_IMAGE_GICON)
2031 if (priv->data.gicon.pixbuf)
2033 g_object_unref (priv->data.gicon.pixbuf);
2034 priv->data.gicon.pixbuf = NULL;
2037 gtk_image_update_size (image, pixel_size, pixel_size);
2040 g_object_notify (G_OBJECT (image), "pixel-size");
2045 * gtk_image_get_pixel_size:
2046 * @image: a #GtkImage
2048 * Gets the pixel size used for named icons.
2050 * Returns: the pixel size used for named icons.
2055 gtk_image_get_pixel_size (GtkImage *image)
2057 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2059 return image->priv->pixel_size;