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/.
29 #include "gtkcontainer.h"
31 #include "gtkiconfactory.h"
33 #include "gtkicontheme.h"
38 typedef struct _GtkImagePrivate GtkImagePrivate;
40 struct _GtkImagePrivate
45 #define GTK_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_IMAGE, GtkImagePrivate))
48 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
50 static void gtk_image_class_init (GtkImageClass *klass);
51 static void gtk_image_init (GtkImage *image);
52 static gint gtk_image_expose (GtkWidget *widget,
53 GdkEventExpose *event);
54 static void gtk_image_unmap (GtkWidget *widget);
55 static void gtk_image_unrealize (GtkWidget *widget);
56 static void gtk_image_size_request (GtkWidget *widget,
57 GtkRequisition *requisition);
58 static void gtk_image_style_set (GtkWidget *widget,
59 GtkStyle *prev_style);
60 static void gtk_image_screen_changed (GtkWidget *widget,
61 GdkScreen *prev_screen);
62 static void gtk_image_destroy (GtkObject *object);
63 static void gtk_image_clear (GtkImage *image);
64 static void gtk_image_reset (GtkImage *image);
65 static void gtk_image_calc_size (GtkImage *image);
67 static void gtk_image_update_size (GtkImage *image,
71 static void gtk_image_set_property (GObject *object,
75 static void gtk_image_get_property (GObject *object,
80 static void icon_theme_changed (GtkImage *image);
82 static gpointer parent_class;
96 PROP_PIXBUF_ANIMATION,
102 gtk_image_get_type (void)
104 static GType image_type = 0;
108 static const GTypeInfo image_info =
110 sizeof (GtkImageClass),
111 NULL, /* base_init */
112 NULL, /* base_finalize */
113 (GClassInitFunc) gtk_image_class_init,
114 NULL, /* class_finalize */
115 NULL, /* class_data */
118 (GInstanceInitFunc) gtk_image_init,
121 image_type = g_type_register_static (GTK_TYPE_MISC, "GtkImage",
129 gtk_image_class_init (GtkImageClass *class)
131 GObjectClass *gobject_class;
132 GtkObjectClass *object_class;
133 GtkWidgetClass *widget_class;
135 parent_class = g_type_class_peek_parent (class);
137 gobject_class = G_OBJECT_CLASS (class);
139 gobject_class->set_property = gtk_image_set_property;
140 gobject_class->get_property = gtk_image_get_property;
142 object_class = GTK_OBJECT_CLASS (class);
144 object_class->destroy = gtk_image_destroy;
146 widget_class = GTK_WIDGET_CLASS (class);
148 widget_class->expose_event = gtk_image_expose;
149 widget_class->size_request = gtk_image_size_request;
150 widget_class->unmap = gtk_image_unmap;
151 widget_class->unrealize = gtk_image_unrealize;
152 widget_class->style_set = gtk_image_style_set;
153 widget_class->screen_changed = gtk_image_screen_changed;
155 g_object_class_install_property (gobject_class,
157 g_param_spec_object ("pixbuf",
159 P_("A GdkPixbuf to display"),
163 g_object_class_install_property (gobject_class,
165 g_param_spec_object ("pixmap",
167 P_("A GdkPixmap to display"),
171 g_object_class_install_property (gobject_class,
173 g_param_spec_object ("image",
175 P_("A GdkImage to display"),
179 g_object_class_install_property (gobject_class,
181 g_param_spec_object ("mask",
183 P_("Mask bitmap to use with GdkImage or GdkPixmap"),
187 g_object_class_install_property (gobject_class,
189 g_param_spec_string ("file",
191 P_("Filename to load and display"),
196 g_object_class_install_property (gobject_class,
198 g_param_spec_string ("stock",
200 P_("Stock ID for a stock image to display"),
204 g_object_class_install_property (gobject_class,
206 g_param_spec_boxed ("icon-set",
208 P_("Icon set to display"),
212 g_object_class_install_property (gobject_class,
214 g_param_spec_int ("icon-size",
216 P_("Symbolic size to use for stock icon, icon set or named icon"),
221 * GtkImage:pixel-size:
223 * The :pixel-size property can be used to specify a fixed size
224 * overriding the :icon-size property for images of type
225 * %GTK_IMAGE_ICON_NAME.
229 g_object_class_install_property (gobject_class,
231 g_param_spec_int ("pixel-size",
233 P_("Pixel size to use for named icon"),
238 g_object_class_install_property (gobject_class,
239 PROP_PIXBUF_ANIMATION,
240 g_param_spec_object ("pixbuf-animation",
242 P_("GdkPixbufAnimation to display"),
243 GDK_TYPE_PIXBUF_ANIMATION,
247 * GtkImage:icon-name:
249 * The name of the icon in the icon theme. If the icon theme is
250 * changed, the image will be updated automatically.
254 g_object_class_install_property (gobject_class,
256 g_param_spec_string ("icon-name",
258 P_("The name of the icon from the icon theme"),
262 g_object_class_install_property (gobject_class,
264 g_param_spec_enum ("storage-type",
266 P_("The representation being used for image data"),
271 g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
275 gtk_image_init (GtkImage *image)
277 GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
279 GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
281 image->storage_type = GTK_IMAGE_EMPTY;
282 image->icon_size = DEFAULT_ICON_SIZE;
285 priv->pixel_size = -1;
289 gtk_image_destroy (GtkObject *object)
291 GtkImage *image = GTK_IMAGE (object);
293 gtk_image_clear (image);
295 GTK_OBJECT_CLASS (parent_class)->destroy (object);
299 gtk_image_set_property (GObject *object,
305 GtkImagePrivate *priv;
307 image = GTK_IMAGE (object);
308 priv = GTK_IMAGE_GET_PRIVATE (image);
313 gtk_image_set_from_pixbuf (image,
314 g_value_get_object (value));
317 gtk_image_set_from_pixmap (image,
318 g_value_get_object (value),
322 gtk_image_set_from_image (image,
323 g_value_get_object (value),
327 if (image->storage_type == GTK_IMAGE_PIXMAP)
328 gtk_image_set_from_pixmap (image,
329 image->data.pixmap.pixmap,
330 g_value_get_object (value));
331 else if (image->storage_type == GTK_IMAGE_IMAGE)
332 gtk_image_set_from_image (image,
333 image->data.image.image,
334 g_value_get_object (value));
339 mask = g_value_get_object (value);
344 gtk_image_reset (image);
350 gtk_image_set_from_file (image,
351 g_value_get_string (value));
354 gtk_image_set_from_stock (image, g_value_get_string (value),
358 gtk_image_set_from_icon_set (image, g_value_get_boxed (value),
362 if (image->storage_type == GTK_IMAGE_STOCK)
363 gtk_image_set_from_stock (image,
364 image->data.stock.stock_id,
365 g_value_get_int (value));
366 else if (image->storage_type == GTK_IMAGE_ICON_SET)
367 gtk_image_set_from_icon_set (image,
368 image->data.icon_set.icon_set,
369 g_value_get_int (value));
370 else if (image->storage_type == GTK_IMAGE_ICON_NAME)
371 gtk_image_set_from_icon_name (image,
372 image->data.name.icon_name,
373 g_value_get_int (value));
375 /* Save to be used when STOCK or ICON_SET property comes in */
376 image->icon_size = g_value_get_int (value);
378 case PROP_PIXEL_SIZE:
379 gtk_image_set_pixel_size (image, g_value_get_int (value));
381 case PROP_PIXBUF_ANIMATION:
382 gtk_image_set_from_animation (image,
383 g_value_get_object (value));
386 gtk_image_set_from_icon_name (image, g_value_get_string (value),
391 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
397 gtk_image_get_property (GObject *object,
403 GtkImagePrivate *priv;
405 image = GTK_IMAGE (object);
406 priv = GTK_IMAGE_GET_PRIVATE (image);
408 /* The "getter" functions whine if you try to get the wrong
409 * storage type. This function is instead robust against that,
410 * so that GUI builders don't have to jump through hoops
417 if (image->storage_type != GTK_IMAGE_PIXBUF)
418 g_value_set_object (value, NULL);
420 g_value_set_object (value,
421 gtk_image_get_pixbuf (image));
424 if (image->storage_type != GTK_IMAGE_PIXMAP)
425 g_value_set_object (value, NULL);
427 g_value_set_object (value,
428 image->data.pixmap.pixmap);
431 g_value_set_object (value, image->mask);
434 if (image->storage_type != GTK_IMAGE_IMAGE)
435 g_value_set_object (value, NULL);
437 g_value_set_object (value,
438 image->data.image.image);
441 if (image->storage_type != GTK_IMAGE_STOCK)
442 g_value_set_string (value, NULL);
444 g_value_set_string (value,
445 image->data.stock.stock_id);
448 if (image->storage_type != GTK_IMAGE_ICON_SET)
449 g_value_set_boxed (value, NULL);
451 g_value_set_boxed (value,
452 image->data.icon_set.icon_set);
455 g_value_set_int (value, image->icon_size);
457 case PROP_PIXEL_SIZE:
458 g_value_set_int (value, priv->pixel_size);
460 case PROP_PIXBUF_ANIMATION:
461 if (image->storage_type != GTK_IMAGE_ANIMATION)
462 g_value_set_object (value, NULL);
464 g_value_set_object (value,
465 image->data.anim.anim);
468 if (image->storage_type != GTK_IMAGE_ICON_NAME)
469 g_value_set_string (value, NULL);
471 g_value_set_string (value,
472 image->data.name.icon_name);
474 case PROP_STORAGE_TYPE:
475 g_value_set_enum (value, image->storage_type);
479 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
486 * gtk_image_new_from_pixmap:
487 * @pixmap: a #GdkPixmap, or %NULL
488 * @mask: a #GdkBitmap, or %NULL
490 * Creates a #GtkImage widget displaying @pixmap with a @mask.
491 * A #GdkPixmap is a server-side image buffer in the pixel format of the
492 * current display. The #GtkImage does not assume a reference to the
493 * pixmap or mask; you still need to unref them if you own references.
494 * #GtkImage will add its own reference rather than adopting yours.
496 * Return value: a new #GtkImage
499 gtk_image_new_from_pixmap (GdkPixmap *pixmap,
504 image = g_object_new (GTK_TYPE_IMAGE, NULL);
506 gtk_image_set_from_pixmap (image, pixmap, mask);
508 return GTK_WIDGET (image);
512 * gtk_image_new_from_image:
513 * @image: a #GdkImage, or %NULL
514 * @mask: a #GdkBitmap, or %NULL
516 * Creates a #GtkImage widget displaying a @image with a @mask.
517 * A #GdkImage is a client-side image buffer in the pixel format of the
519 * The #GtkImage does not assume a reference to the
520 * image or mask; you still need to unref them if you own references.
521 * #GtkImage will add its own reference rather than adopting yours.
523 * Return value: a new #GtkImage
526 gtk_image_new_from_image (GdkImage *gdk_image,
531 image = g_object_new (GTK_TYPE_IMAGE, NULL);
533 gtk_image_set_from_image (image, gdk_image, mask);
535 return GTK_WIDGET (image);
539 * gtk_image_new_from_file:
540 * @filename: a filename
542 * Creates a new #GtkImage displaying the file @filename. If the file
543 * isn't found or can't be loaded, the resulting #GtkImage will
544 * display a "broken image" icon. This function never returns %NULL,
545 * it always returns a valid #GtkImage widget.
547 * If the file contains an animation, the image will contain an
550 * If you need to detect failures to load the file, use
551 * gdk_pixbuf_new_from_file() to load the file yourself, then create
552 * the #GtkImage from the pixbuf. (Or for animations, use
553 * gdk_pixbuf_animation_new_from_file()).
555 * The storage type (gtk_image_get_storage_type()) of the returned
556 * image is not defined, it will be whatever is appropriate for
557 * displaying the file.
559 * Return value: a new #GtkImage
562 gtk_image_new_from_file (const gchar *filename)
566 image = g_object_new (GTK_TYPE_IMAGE, NULL);
568 gtk_image_set_from_file (image, filename);
570 return GTK_WIDGET (image);
574 * gtk_image_new_from_pixbuf:
575 * @pixbuf: a #GdkPixbuf, or %NULL
577 * Creates a new #GtkImage displaying @pixbuf.
578 * The #GtkImage does not assume a reference to the
579 * pixbuf; you still need to unref it if you own references.
580 * #GtkImage will add its own reference rather than adopting yours.
582 * Note that this function just creates an #GtkImage from the pixbuf. The
583 * #GtkImage created will not react to state changes. Should you want that, you
584 * should use gtk_image_new_from_icon_set().
586 * Return value: a new #GtkImage
589 gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
593 image = g_object_new (GTK_TYPE_IMAGE, NULL);
595 gtk_image_set_from_pixbuf (image, pixbuf);
597 return GTK_WIDGET (image);
601 * gtk_image_new_from_stock:
602 * @stock_id: a stock icon name
603 * @size: a stock icon size
605 * Creates a #GtkImage displaying a stock icon. Sample stock icon
606 * names are #GTK_STOCK_OPEN, #GTK_STOCK_EXIT. Sample stock sizes
607 * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
608 * icon name isn't known, a "broken image" icon will be displayed instead.
609 * You can register your own stock icon names, see
610 * gtk_icon_factory_add_default() and gtk_icon_factory_add().
612 * Return value: a new #GtkImage displaying the stock icon
615 gtk_image_new_from_stock (const gchar *stock_id,
620 image = g_object_new (GTK_TYPE_IMAGE, NULL);
622 gtk_image_set_from_stock (image, stock_id, size);
624 return GTK_WIDGET (image);
628 * gtk_image_new_from_icon_set:
629 * @icon_set: a #GtkIconSet
630 * @size: a stock icon size
632 * Creates a #GtkImage displaying an icon set. Sample stock sizes are
633 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using
634 * this function, usually it's better to create a #GtkIconFactory, put
635 * your icon sets in the icon factory, add the icon factory to the
636 * list of default factories with gtk_icon_factory_add_default(), and
637 * then use gtk_image_new_from_stock(). This will allow themes to
638 * override the icon you ship with your application.
640 * The #GtkImage does not assume a reference to the
641 * icon set; you still need to unref it if you own references.
642 * #GtkImage will add its own reference rather than adopting yours.
645 * Return value: a new #GtkImage
648 gtk_image_new_from_icon_set (GtkIconSet *icon_set,
653 image = g_object_new (GTK_TYPE_IMAGE, NULL);
655 gtk_image_set_from_icon_set (image, icon_set, size);
657 return GTK_WIDGET (image);
661 * gtk_image_new_from_animation:
662 * @animation: an animation
664 * Creates a #GtkImage displaying the given animation.
665 * The #GtkImage does not assume a reference to the
666 * animation; you still need to unref it if you own references.
667 * #GtkImage will add its own reference rather than adopting yours.
669 * Return value: a new #GtkImage widget
672 gtk_image_new_from_animation (GdkPixbufAnimation *animation)
676 g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
678 image = g_object_new (GTK_TYPE_IMAGE, NULL);
680 gtk_image_set_from_animation (image, animation);
682 return GTK_WIDGET (image);
686 * gtk_image_new_from_icon_name:
687 * @icon_name: an icon name
688 * @size: a stock icon size
690 * Creates a #GtkImage displaying an icon from the current icon theme.
691 * If the icon name isn't known, a "broken image" icon will be
692 * displayed instead. If the current icon theme is changed, the icon
693 * will be updated appropriately.
695 * Return value: a new #GtkImage displaying the themed icon
700 gtk_image_new_from_icon_name (const gchar *icon_name,
705 image = g_object_new (GTK_TYPE_IMAGE, NULL);
707 gtk_image_set_from_icon_name (image, icon_name, size);
709 return GTK_WIDGET (image);
713 * gtk_image_set_from_pixmap:
714 * @image: a #GtkImage
715 * @pixmap: a #GdkPixmap or %NULL
716 * @mask: a #GdkBitmap or %NULL
718 * See gtk_image_new_from_pixmap() for details.
722 gtk_image_set_from_pixmap (GtkImage *image,
726 g_return_if_fail (GTK_IS_IMAGE (image));
727 g_return_if_fail (pixmap == NULL ||
728 GDK_IS_PIXMAP (pixmap));
729 g_return_if_fail (mask == NULL ||
730 GDK_IS_PIXMAP (mask));
732 g_object_freeze_notify (G_OBJECT (image));
735 g_object_ref (pixmap);
740 gtk_image_reset (image);
749 image->storage_type = GTK_IMAGE_PIXMAP;
751 image->data.pixmap.pixmap = pixmap;
753 gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
755 gtk_image_update_size (image, width, height);
758 g_object_notify (G_OBJECT (image), "pixmap");
759 g_object_notify (G_OBJECT (image), "mask");
761 g_object_thaw_notify (G_OBJECT (image));
765 * gtk_image_set_from_image:
766 * @image: a #GtkImage
767 * @gdk_image: a #GdkImage or %NULL
768 * @mask: a #GdkBitmap or %NULL
770 * See gtk_image_new_from_image() for details.
774 gtk_image_set_from_image (GtkImage *image,
778 g_return_if_fail (GTK_IS_IMAGE (image));
779 g_return_if_fail (gdk_image == NULL ||
780 GDK_IS_IMAGE (gdk_image));
781 g_return_if_fail (mask == NULL ||
782 GDK_IS_PIXMAP (mask));
784 g_object_freeze_notify (G_OBJECT (image));
787 g_object_ref (gdk_image);
792 gtk_image_reset (image);
796 image->storage_type = GTK_IMAGE_IMAGE;
798 image->data.image.image = gdk_image;
801 gtk_image_update_size (image, gdk_image->width, gdk_image->height);
805 /* Clean up the mask if gdk_image was NULL */
807 g_object_unref (mask);
810 g_object_notify (G_OBJECT (image), "image");
811 g_object_notify (G_OBJECT (image), "mask");
813 g_object_thaw_notify (G_OBJECT (image));
817 * gtk_image_set_from_file:
818 * @image: a #GtkImage
819 * @filename: a filename or %NULL
821 * See gtk_image_new_from_file() for details.
825 gtk_image_set_from_file (GtkImage *image,
826 const gchar *filename)
828 GdkPixbufAnimation *anim;
830 g_return_if_fail (GTK_IS_IMAGE (image));
832 g_object_freeze_notify (G_OBJECT (image));
834 gtk_image_reset (image);
836 if (filename == NULL)
838 g_object_thaw_notify (G_OBJECT (image));
842 anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
846 gtk_image_set_from_stock (image,
847 GTK_STOCK_MISSING_IMAGE,
848 GTK_ICON_SIZE_BUTTON);
849 g_object_thaw_notify (G_OBJECT (image));
853 /* We could just unconditionally set_from_animation,
854 * but it's nicer for memory if we toss the animation
855 * if it's just a single pixbuf
858 if (gdk_pixbuf_animation_is_static_image (anim))
860 gtk_image_set_from_pixbuf (image,
861 gdk_pixbuf_animation_get_static_image (anim));
865 gtk_image_set_from_animation (image, anim);
868 g_object_unref (anim);
870 g_object_thaw_notify (G_OBJECT (image));
874 * gtk_image_set_from_pixbuf:
875 * @image: a #GtkImage
876 * @pixbuf: a #GdkPixbuf or %NULL
878 * See gtk_image_new_from_pixbuf() for details.
882 gtk_image_set_from_pixbuf (GtkImage *image,
885 g_return_if_fail (GTK_IS_IMAGE (image));
886 g_return_if_fail (pixbuf == NULL ||
887 GDK_IS_PIXBUF (pixbuf));
889 g_object_freeze_notify (G_OBJECT (image));
892 g_object_ref (pixbuf);
894 gtk_image_reset (image);
898 image->storage_type = GTK_IMAGE_PIXBUF;
900 image->data.pixbuf.pixbuf = pixbuf;
902 gtk_image_update_size (image,
903 gdk_pixbuf_get_width (pixbuf),
904 gdk_pixbuf_get_height (pixbuf));
907 g_object_notify (G_OBJECT (image), "pixbuf");
909 g_object_thaw_notify (G_OBJECT (image));
913 * gtk_image_set_from_stock:
914 * @image: a #GtkImage
915 * @stock_id: a stock icon name
916 * @size: a stock icon size
918 * See gtk_image_new_from_stock() for details.
922 gtk_image_set_from_stock (GtkImage *image,
923 const gchar *stock_id,
928 g_return_if_fail (GTK_IS_IMAGE (image));
930 g_object_freeze_notify (G_OBJECT (image));
932 /* in case stock_id == image->data.stock.stock_id */
933 new_id = g_strdup (stock_id);
935 gtk_image_reset (image);
939 image->storage_type = GTK_IMAGE_STOCK;
941 image->data.stock.stock_id = new_id;
942 image->icon_size = size;
944 /* Size is demand-computed in size request method
945 * if we're a stock image, since changing the
946 * style impacts the size request
950 g_object_notify (G_OBJECT (image), "stock");
951 g_object_notify (G_OBJECT (image), "icon_size");
953 g_object_thaw_notify (G_OBJECT (image));
957 * gtk_image_set_from_icon_set:
958 * @image: a #GtkImage
959 * @icon_set: a #GtkIconSet
960 * @size: a stock icon size
962 * See gtk_image_new_from_icon_set() for details.
966 gtk_image_set_from_icon_set (GtkImage *image,
967 GtkIconSet *icon_set,
970 g_return_if_fail (GTK_IS_IMAGE (image));
972 g_object_freeze_notify (G_OBJECT (image));
975 gtk_icon_set_ref (icon_set);
977 gtk_image_reset (image);
981 image->storage_type = GTK_IMAGE_ICON_SET;
983 image->data.icon_set.icon_set = icon_set;
984 image->icon_size = size;
986 /* Size is demand-computed in size request method
987 * if we're an icon set
991 g_object_notify (G_OBJECT (image), "icon_set");
992 g_object_notify (G_OBJECT (image), "icon_size");
994 g_object_thaw_notify (G_OBJECT (image));
998 * gtk_image_set_from_animation:
999 * @image: a #GtkImage
1000 * @animation: the #GdkPixbufAnimation
1002 * Causes the #GtkImage to display the given animation (or display
1003 * nothing, if you set the animation to %NULL).
1006 gtk_image_set_from_animation (GtkImage *image,
1007 GdkPixbufAnimation *animation)
1009 g_return_if_fail (GTK_IS_IMAGE (image));
1010 g_return_if_fail (animation == NULL ||
1011 GDK_IS_PIXBUF_ANIMATION (animation));
1013 g_object_freeze_notify (G_OBJECT (image));
1016 g_object_ref (animation);
1018 gtk_image_reset (image);
1020 if (animation != NULL)
1022 image->storage_type = GTK_IMAGE_ANIMATION;
1024 image->data.anim.anim = animation;
1025 image->data.anim.frame_timeout = 0;
1026 image->data.anim.iter = NULL;
1028 gtk_image_update_size (image,
1029 gdk_pixbuf_animation_get_width (animation),
1030 gdk_pixbuf_animation_get_height (animation));
1033 g_object_notify (G_OBJECT (image), "pixbuf_animation");
1035 g_object_thaw_notify (G_OBJECT (image));
1039 * gtk_image_set_from_icon_name:
1040 * @image: a #GtkImage
1041 * @icon_name: an icon name
1042 * @size: an icon size
1044 * See gtk_image_new_from_icon_name() for details.
1049 gtk_image_set_from_icon_name (GtkImage *image,
1050 const gchar *icon_name,
1055 g_return_if_fail (GTK_IS_IMAGE (image));
1057 g_object_freeze_notify (G_OBJECT (image));
1059 /* in case icon_name == image->data.name.icon_name */
1060 new_name = g_strdup (icon_name);
1062 gtk_image_reset (image);
1066 image->storage_type = GTK_IMAGE_ICON_NAME;
1068 image->data.name.icon_name = new_name;
1069 image->icon_size = size;
1071 /* Size is demand-computed in size request method
1072 * if we're a icon theme image, since changing the
1073 * style impacts the size request
1077 g_object_notify (G_OBJECT (image), "icon_name");
1078 g_object_notify (G_OBJECT (image), "icon_size");
1080 g_object_thaw_notify (G_OBJECT (image));
1084 * gtk_image_get_storage_type:
1085 * @image: a #GtkImage
1087 * Gets the type of representation being used by the #GtkImage
1088 * to store image data. If the #GtkImage has no image data,
1089 * the return value will be %GTK_IMAGE_EMPTY.
1091 * Return value: image representation being used
1094 gtk_image_get_storage_type (GtkImage *image)
1096 g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
1098 return image->storage_type;
1102 * gtk_image_get_pixmap:
1103 * @image: a #GtkImage
1104 * @pixmap: location to store the pixmap, or %NULL
1105 * @mask: location to store the mask, or %NULL
1107 * Gets the pixmap and mask being displayed by the #GtkImage.
1108 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1109 * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
1110 * The caller of this function does not own a reference to the
1111 * returned pixmap and mask.
1115 gtk_image_get_pixmap (GtkImage *image,
1119 g_return_if_fail (GTK_IS_IMAGE (image));
1120 g_return_if_fail (image->storage_type == GTK_IMAGE_PIXMAP ||
1121 image->storage_type == GTK_IMAGE_EMPTY);
1124 *pixmap = image->data.pixmap.pixmap;
1127 *mask = image->mask;
1131 * gtk_image_get_image:
1132 * @image: a #GtkImage
1133 * @gdk_image: return location for a #GtkImage
1134 * @mask: return location for a #GdkBitmap
1136 * Gets the #GdkImage and mask being displayed by the #GtkImage.
1137 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1138 * %GTK_IMAGE_IMAGE (see gtk_image_get_storage_type()).
1139 * The caller of this function does not own a reference to the
1140 * returned image and mask.
1143 gtk_image_get_image (GtkImage *image,
1144 GdkImage **gdk_image,
1147 g_return_if_fail (GTK_IS_IMAGE (image));
1148 g_return_if_fail (image->storage_type == GTK_IMAGE_IMAGE ||
1149 image->storage_type == GTK_IMAGE_EMPTY);
1152 *gdk_image = image->data.image.image;
1155 *mask = image->mask;
1159 * gtk_image_get_pixbuf:
1160 * @image: a #GtkImage
1163 * Gets the #GdkPixbuf being displayed by the #GtkImage.
1164 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1165 * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
1166 * The caller of this function does not own a reference to the
1169 * Return value: the displayed pixbuf, or %NULL if the image is empty
1172 gtk_image_get_pixbuf (GtkImage *image)
1174 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1175 g_return_val_if_fail (image->storage_type == GTK_IMAGE_PIXBUF ||
1176 image->storage_type == GTK_IMAGE_EMPTY, NULL);
1178 if (image->storage_type == GTK_IMAGE_EMPTY)
1179 image->data.pixbuf.pixbuf = NULL;
1181 return image->data.pixbuf.pixbuf;
1185 * gtk_image_get_stock:
1186 * @image: a #GtkImage
1187 * @stock_id: place to store a stock icon name
1188 * @size: place to store a stock icon size
1190 * Gets the stock icon name and size being displayed by the #GtkImage.
1191 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1192 * %GTK_IMAGE_STOCK (see gtk_image_get_storage_type()).
1193 * The returned string is owned by the #GtkImage and should not
1198 gtk_image_get_stock (GtkImage *image,
1202 g_return_if_fail (GTK_IS_IMAGE (image));
1203 g_return_if_fail (image->storage_type == GTK_IMAGE_STOCK ||
1204 image->storage_type == GTK_IMAGE_EMPTY);
1206 if (image->storage_type == GTK_IMAGE_EMPTY)
1207 image->data.stock.stock_id = NULL;
1210 *stock_id = image->data.stock.stock_id;
1213 *size = image->icon_size;
1217 * gtk_image_get_icon_set:
1218 * @image: a #GtkImage
1219 * @icon_set: location to store a #GtkIconSet
1220 * @size: location to store a stock icon size
1222 * Gets the icon set and size being displayed by the #GtkImage.
1223 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1224 * %GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()).
1228 gtk_image_get_icon_set (GtkImage *image,
1229 GtkIconSet **icon_set,
1232 g_return_if_fail (GTK_IS_IMAGE (image));
1233 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_SET ||
1234 image->storage_type == GTK_IMAGE_EMPTY);
1237 *icon_set = image->data.icon_set.icon_set;
1240 *size = image->icon_size;
1244 * gtk_image_get_animation:
1245 * @image: a #GtkImage
1248 * Gets the #GdkPixbufAnimation being displayed by the #GtkImage.
1249 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1250 * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
1251 * The caller of this function does not own a reference to the
1252 * returned animation.
1254 * Return value: the displayed animation, or %NULL if the image is empty
1257 gtk_image_get_animation (GtkImage *image)
1259 g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
1260 g_return_val_if_fail (image->storage_type == GTK_IMAGE_ANIMATION ||
1261 image->storage_type == GTK_IMAGE_EMPTY,
1264 if (image->storage_type == GTK_IMAGE_EMPTY)
1265 image->data.anim.anim = NULL;
1267 return image->data.anim.anim;
1271 * gtk_image_get_icon_name:
1272 * @image: a #GtkImage
1273 * @icon_name: place to store an icon name
1274 * @size: place to store an icon size
1276 * Gets the icon name and size being displayed by the #GtkImage.
1277 * The storage type of the image must be %GTK_IMAGE_EMPTY or
1278 * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
1279 * The returned string is owned by the #GtkImage and should not
1285 gtk_image_get_icon_name (GtkImage *image,
1286 G_CONST_RETURN gchar **icon_name,
1289 g_return_if_fail (GTK_IS_IMAGE (image));
1290 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME ||
1291 image->storage_type == GTK_IMAGE_EMPTY);
1293 if (image->storage_type == GTK_IMAGE_EMPTY)
1294 image->data.name.icon_name = NULL;
1297 *icon_name = image->data.name.icon_name;
1300 *size = image->icon_size;
1306 * Creates a new empty #GtkImage widget.
1308 * Return value: a newly created #GtkImage widget.
1311 gtk_image_new (void)
1313 return g_object_new (GTK_TYPE_IMAGE, NULL);
1317 gtk_image_set (GtkImage *image,
1321 g_return_if_fail (GTK_IS_IMAGE (image));
1323 gtk_image_set_from_image (image, val, mask);
1327 gtk_image_get (GtkImage *image,
1331 g_return_if_fail (GTK_IS_IMAGE (image));
1333 gtk_image_get_image (image, val, mask);
1337 gtk_image_reset_anim_iter (GtkImage *image)
1339 if (image->storage_type == GTK_IMAGE_ANIMATION)
1341 /* Reset the animation */
1343 if (image->data.anim.frame_timeout)
1345 g_source_remove (image->data.anim.frame_timeout);
1346 image->data.anim.frame_timeout = 0;
1349 if (image->data.anim.iter)
1351 g_object_unref (image->data.anim.iter);
1352 image->data.anim.iter = NULL;
1358 gtk_image_unmap (GtkWidget *widget)
1360 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1362 if (GTK_WIDGET_CLASS (parent_class)->unmap)
1363 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
1367 gtk_image_unrealize (GtkWidget *widget)
1369 gtk_image_reset_anim_iter (GTK_IMAGE (widget));
1371 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1372 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
1376 animation_timeout (gpointer data)
1380 GDK_THREADS_ENTER ();
1382 image = GTK_IMAGE (data);
1384 image->data.anim.frame_timeout = 0;
1386 gdk_pixbuf_animation_iter_advance (image->data.anim.iter, NULL);
1388 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1389 image->data.anim.frame_timeout =
1390 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1394 gtk_widget_queue_draw (GTK_WIDGET (image));
1396 GDK_THREADS_LEAVE ();
1402 icon_theme_changed (GtkImage *image)
1404 if (image->data.name.pixbuf)
1405 g_object_unref (image->data.name.pixbuf);
1406 image->data.name.pixbuf = NULL;
1408 gtk_widget_queue_draw (GTK_WIDGET (image));
1412 ensure_pixbuf_for_icon_name (GtkImage *image)
1414 GtkImagePrivate *priv;
1416 GtkIconTheme *icon_theme;
1417 GtkSettings *settings;
1419 gint *sizes, *s, dist;
1420 GError *error = NULL;
1422 g_return_if_fail (image->storage_type == GTK_IMAGE_ICON_NAME);
1424 priv = GTK_IMAGE_GET_PRIVATE (image);
1425 screen = gtk_widget_get_screen (GTK_WIDGET (image));
1426 icon_theme = gtk_icon_theme_get_for_screen (screen);
1427 settings = gtk_settings_get_for_screen (screen);
1428 if (image->data.name.pixbuf == NULL)
1430 if (priv->pixel_size != -1)
1432 width = height = priv->pixel_size;
1434 else if (!gtk_icon_size_lookup_for_settings (settings,
1438 if (image->icon_size == -1)
1440 /* Find an available size close to 48 */
1441 sizes = gtk_icon_theme_get_icon_sizes (icon_theme, image->data.name.icon_name);
1443 width = height = 48;
1444 for (s = sizes; *s; s++)
1448 width = height = 48;
1455 width = height = *s;
1463 width = height = *s;
1472 g_warning ("Invalid icon size %d\n", image->icon_size);
1473 width = height = 24;
1476 image->data.name.pixbuf =
1477 gtk_icon_theme_load_icon (icon_theme,
1478 image->data.name.icon_name,
1479 MIN (width, height), 0, &error);
1480 if (image->data.name.pixbuf == NULL)
1482 g_error_free (error);
1483 image->data.name.pixbuf =
1484 gtk_widget_render_icon (GTK_WIDGET (image),
1485 GTK_STOCK_MISSING_IMAGE,
1493 * Like gdk_rectangle_intersect (dest, src, dest), but make
1494 * sure that the origin of dest is moved by an "even" offset.
1495 * If necessary grow the intersection by one row or column
1498 * This is necessary since we can't pass alignment information
1499 * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
1500 * thus we have to makesure that the subimages are properly aligned.
1503 rectangle_intersect_even (GdkRectangle *src,
1511 isect = gdk_rectangle_intersect (dest, src, dest);
1513 if ((dest->x - x + dest->y - y) % 2 != 0)
1531 gtk_image_expose (GtkWidget *widget,
1532 GdkEventExpose *event)
1534 g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
1535 g_return_val_if_fail (event != NULL, FALSE);
1537 if (GTK_WIDGET_MAPPED (widget) &&
1538 GTK_IMAGE (widget)->storage_type != GTK_IMAGE_EMPTY)
1542 GdkRectangle area, image_bound;
1544 gint x, y, mask_x, mask_y;
1547 gboolean needs_state_transform;
1549 image = GTK_IMAGE (widget);
1550 misc = GTK_MISC (widget);
1554 /* For stock items and icon sets, we lazily calculate
1555 * the size; we might get here between a queue_resize()
1556 * and size_request() if something explicitely forces
1559 if (widget->requisition.width == 0 && widget->requisition.height == 0)
1560 gtk_image_calc_size (image);
1562 if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
1565 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1566 xalign = misc->xalign;
1568 xalign = 1.0 - misc->xalign;
1570 x = floor (widget->allocation.x + misc->xpad
1571 + ((widget->allocation.width - widget->requisition.width) * xalign)
1573 y = floor (widget->allocation.y + misc->ypad
1574 + ((widget->allocation.height - widget->requisition.height) * misc->yalign)
1581 image_bound.width = 0;
1582 image_bound.height = 0;
1586 needs_state_transform = GTK_WIDGET_STATE (widget) != GTK_STATE_NORMAL;
1588 switch (image->storage_type)
1590 case GTK_IMAGE_PIXMAP:
1592 gdk_drawable_get_size (image->data.pixmap.pixmap,
1594 &image_bound.height);
1595 if (rectangle_intersect_even (&area, &image_bound) &&
1596 needs_state_transform)
1598 pixbuf = gdk_pixbuf_get_from_drawable (NULL,
1599 image->data.pixmap.pixmap,
1600 gtk_widget_get_colormap (widget),
1601 image_bound.x - x, image_bound.y - y,
1604 image_bound.height);
1612 case GTK_IMAGE_IMAGE:
1614 image_bound.width = image->data.image.image->width;
1615 image_bound.height = image->data.image.image->height;
1617 if (rectangle_intersect_even (&area, &image_bound) &&
1618 needs_state_transform)
1620 pixbuf = gdk_pixbuf_get_from_image (NULL,
1621 image->data.image.image,
1622 gtk_widget_get_colormap (widget),
1623 image_bound.x - x, image_bound.y - y,
1626 image_bound.height);
1633 case GTK_IMAGE_PIXBUF:
1634 image_bound.width = gdk_pixbuf_get_width (image->data.pixbuf.pixbuf);
1635 image_bound.height = gdk_pixbuf_get_height (image->data.pixbuf.pixbuf);
1638 if (rectangle_intersect_even (&area, &image_bound) &&
1639 needs_state_transform)
1641 pixbuf = gdk_pixbuf_new_subpixbuf (image->data.pixbuf.pixbuf,
1642 image_bound.x - x, image_bound.y - y,
1643 image_bound.width, image_bound.height);
1650 pixbuf = image->data.pixbuf.pixbuf;
1651 g_object_ref (pixbuf);
1655 case GTK_IMAGE_STOCK:
1656 pixbuf = gtk_widget_render_icon (widget,
1657 image->data.stock.stock_id,
1662 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1663 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1667 needs_state_transform = FALSE;
1670 case GTK_IMAGE_ICON_SET:
1672 gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1674 gtk_widget_get_direction (widget),
1675 GTK_WIDGET_STATE (widget),
1682 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1683 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1687 needs_state_transform = FALSE;
1690 case GTK_IMAGE_ANIMATION:
1692 if (image->data.anim.iter == NULL)
1694 image->data.anim.iter = gdk_pixbuf_animation_get_iter (image->data.anim.anim, NULL);
1696 if (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter) >= 0)
1697 image->data.anim.frame_timeout =
1698 g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
1703 image_bound.width = gdk_pixbuf_animation_get_width (image->data.anim.anim);
1704 image_bound.height = gdk_pixbuf_animation_get_height (image->data.anim.anim);
1706 /* don't advance the anim iter here, or we could get frame changes between two
1707 * exposes of different areas.
1710 pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->data.anim.iter);
1711 g_object_ref (pixbuf);
1715 case GTK_IMAGE_ICON_NAME:
1716 ensure_pixbuf_for_icon_name (image);
1717 pixbuf = image->data.name.pixbuf;
1720 g_object_ref (pixbuf);
1721 image_bound.width = gdk_pixbuf_get_width (pixbuf);
1722 image_bound.height = gdk_pixbuf_get_height (pixbuf);
1726 case GTK_IMAGE_EMPTY:
1727 g_assert_not_reached ();
1733 gdk_gc_set_clip_mask (widget->style->black_gc, mask);
1734 gdk_gc_set_clip_origin (widget->style->black_gc, mask_x, mask_y);
1737 if (rectangle_intersect_even (&area, &image_bound))
1741 if (needs_state_transform)
1743 GtkIconSource *source;
1744 GdkPixbuf *rendered;
1746 source = gtk_icon_source_new ();
1747 gtk_icon_source_set_pixbuf (source, pixbuf);
1748 /* The size here is arbitrary; since size isn't
1749 * wildcarded in the souce, it isn't supposed to be
1750 * scaled by the engine function
1752 gtk_icon_source_set_size (source,
1753 GTK_ICON_SIZE_SMALL_TOOLBAR);
1754 gtk_icon_source_set_size_wildcarded (source, FALSE);
1756 rendered = gtk_style_render_icon (widget->style,
1758 gtk_widget_get_direction (widget),
1759 GTK_WIDGET_STATE (widget),
1765 gtk_icon_source_free (source);
1767 g_object_unref (pixbuf);
1773 gdk_draw_pixbuf (widget->window,
1774 widget->style->black_gc,
1782 GDK_RGB_DITHER_NORMAL,
1785 g_object_unref (pixbuf);
1791 switch (image->storage_type)
1793 case GTK_IMAGE_PIXMAP:
1794 gdk_draw_drawable (widget->window,
1795 widget->style->black_gc,
1796 image->data.pixmap.pixmap,
1797 image_bound.x - x, image_bound.y - y,
1798 image_bound.x, image_bound.y,
1799 image_bound.width, image_bound.height);
1802 case GTK_IMAGE_IMAGE:
1803 gdk_draw_image (widget->window,
1804 widget->style->black_gc,
1805 image->data.image.image,
1806 image_bound.x - x, image_bound.y - y,
1807 image_bound.x, image_bound.y,
1808 image_bound.width, image_bound.height);
1811 case GTK_IMAGE_PIXBUF:
1812 case GTK_IMAGE_STOCK:
1813 case GTK_IMAGE_ICON_SET:
1814 case GTK_IMAGE_ANIMATION:
1815 case GTK_IMAGE_ICON_NAME:
1816 case GTK_IMAGE_EMPTY:
1817 g_assert_not_reached ();
1821 } /* if rectangle intersects */
1825 gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
1826 gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
1829 } /* if widget is drawable */
1835 gtk_image_clear (GtkImage *image)
1837 g_object_freeze_notify (G_OBJECT (image));
1839 if (image->storage_type != GTK_IMAGE_EMPTY)
1840 g_object_notify (G_OBJECT (image), "storage_type");
1844 g_object_unref (image->mask);
1846 g_object_notify (G_OBJECT (image), "mask");
1849 if (image->icon_size != DEFAULT_ICON_SIZE)
1851 image->icon_size = DEFAULT_ICON_SIZE;
1852 g_object_notify (G_OBJECT (image), "icon_size");
1855 switch (image->storage_type)
1857 case GTK_IMAGE_PIXMAP:
1859 if (image->data.pixmap.pixmap)
1860 g_object_unref (image->data.pixmap.pixmap);
1861 image->data.pixmap.pixmap = NULL;
1863 g_object_notify (G_OBJECT (image), "pixmap");
1867 case GTK_IMAGE_IMAGE:
1869 if (image->data.image.image)
1870 g_object_unref (image->data.image.image);
1871 image->data.image.image = NULL;
1873 g_object_notify (G_OBJECT (image), "image");
1877 case GTK_IMAGE_PIXBUF:
1879 if (image->data.pixbuf.pixbuf)
1880 g_object_unref (image->data.pixbuf.pixbuf);
1882 g_object_notify (G_OBJECT (image), "pixbuf");
1886 case GTK_IMAGE_STOCK:
1888 g_free (image->data.stock.stock_id);
1890 image->data.stock.stock_id = NULL;
1892 g_object_notify (G_OBJECT (image), "stock");
1895 case GTK_IMAGE_ICON_SET:
1896 if (image->data.icon_set.icon_set)
1897 gtk_icon_set_unref (image->data.icon_set.icon_set);
1898 image->data.icon_set.icon_set = NULL;
1900 g_object_notify (G_OBJECT (image), "icon_set");
1903 case GTK_IMAGE_ANIMATION:
1904 gtk_image_reset_anim_iter (image);
1906 if (image->data.anim.anim)
1907 g_object_unref (image->data.anim.anim);
1908 image->data.anim.anim = NULL;
1910 g_object_notify (G_OBJECT (image), "pixbuf_animation");
1914 case GTK_IMAGE_ICON_NAME:
1915 if (image->data.name.icon_name)
1916 g_free (image->data.name.icon_name);
1917 image->data.name.icon_name = NULL;
1918 if (image->data.name.pixbuf)
1919 g_object_unref (image->data.name.pixbuf);
1920 image->data.name.pixbuf = NULL;
1922 g_object_notify (G_OBJECT (image), "icon_name");
1926 case GTK_IMAGE_EMPTY:
1932 image->storage_type = GTK_IMAGE_EMPTY;
1934 memset (&image->data, '\0', sizeof (image->data));
1936 g_object_thaw_notify (G_OBJECT (image));
1940 gtk_image_reset (GtkImage *image)
1942 gtk_image_clear (image);
1944 gtk_image_update_size (image, 0, 0);
1948 gtk_image_calc_size (GtkImage *image)
1950 GtkWidget *widget = GTK_WIDGET (image);
1951 GdkPixbuf *pixbuf = NULL;
1953 /* We update stock/icon set on every size request, because
1954 * the theme could have affected the size; for other kinds of
1955 * image, we just update the requisition when the image data
1958 switch (image->storage_type)
1960 case GTK_IMAGE_STOCK:
1961 pixbuf = gtk_widget_render_icon (widget,
1962 image->data.stock.stock_id,
1967 case GTK_IMAGE_ICON_SET:
1968 pixbuf = gtk_icon_set_render_icon (image->data.icon_set.icon_set,
1970 gtk_widget_get_direction (widget),
1971 GTK_WIDGET_STATE (widget),
1976 case GTK_IMAGE_ICON_NAME:
1977 ensure_pixbuf_for_icon_name (image);
1978 pixbuf = image->data.name.pixbuf;
1979 if (pixbuf) g_object_ref (pixbuf);
1987 widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
1988 widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
1990 g_object_unref (pixbuf);
1995 gtk_image_size_request (GtkWidget *widget,
1996 GtkRequisition *requisition)
2000 image = GTK_IMAGE (widget);
2002 gtk_image_calc_size (image);
2004 /* Chain up to default that simply reads current requisition */
2005 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
2009 gtk_image_style_set (GtkWidget *widget,
2010 GtkStyle *prev_style)
2014 image = GTK_IMAGE (widget);
2016 if (GTK_WIDGET_CLASS (parent_class)->style_set)
2017 GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
2019 icon_theme_changed (image);
2023 gtk_image_screen_changed (GtkWidget *widget,
2024 GdkScreen *prev_screen)
2028 image = GTK_IMAGE (widget);
2030 if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
2031 GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, prev_screen);
2033 icon_theme_changed (image);
2038 gtk_image_update_size (GtkImage *image,
2042 GTK_WIDGET (image)->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
2043 GTK_WIDGET (image)->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
2045 if (GTK_WIDGET_VISIBLE (image))
2046 gtk_widget_queue_resize (GTK_WIDGET (image));
2051 * gtk_image_set_pixel_size:
2052 * @image: a #GtkImage
2053 * @pixel_size: the new pixel size
2055 * Sets the pixel size to use for named icons. If the pixel size is set
2056 * to a value != -1, it is used instead of the icon size set by
2057 * gtk_image_set_from_icon_name().
2062 gtk_image_set_pixel_size (GtkImage *image,
2065 GtkImagePrivate *priv;
2067 g_return_if_fail (GTK_IS_IMAGE (image));
2069 priv = GTK_IMAGE_GET_PRIVATE (image);
2071 if (priv->pixel_size != pixel_size)
2073 priv->pixel_size = pixel_size;
2075 if (image->storage_type == GTK_IMAGE_ICON_NAME)
2077 if (image->data.name.pixbuf)
2079 g_object_unref (image->data.name.pixbuf);
2080 image->data.name.pixbuf = NULL;
2083 gtk_image_update_size (image, pixel_size, pixel_size);
2086 g_object_notify (G_OBJECT (image), "pixel-size");
2091 * gtk_image_get_pixel_size:
2092 * @image: a #GtkImage
2094 * Gets the pixel size used for named icons.
2096 * Returns: the pixel size used for named icons.
2101 gtk_image_get_pixel_size (GtkImage *image)
2103 GtkImagePrivate *priv;
2105 g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
2107 priv = GTK_IMAGE_GET_PRIVATE (image);
2109 return priv->pixel_size;
2114 #undef gtk_image_new_from_file
2117 gtk_image_new_from_file (const gchar *filename)
2119 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2122 retval = gtk_image_new_from_file_utf8 (utf8_filename);
2124 g_free (utf8_filename);
2129 #undef gtk_image_set_from_file
2132 gtk_image_set_from_file (GtkImage *image,
2133 const gchar *filename)
2135 gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
2137 gtk_image_set_from_file_utf8 (image, utf8_filename);
2139 g_free (utf8_filename);
2144 #define __GTK_IMAGE_C__
2145 #include "gtkaliasdef.c"