struct _GtkImagePrivate
{
+ /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
+ gchar *filename;
+
gint pixel_size;
};
static void gtk_image_screen_changed (GtkWidget *widget,
GdkScreen *prev_screen);
static void gtk_image_destroy (GtkObject *object);
-static void gtk_image_clear (GtkImage *image);
static void gtk_image_reset (GtkImage *image);
static void gtk_image_calc_size (GtkImage *image);
(GInstanceInitFunc) gtk_image_init,
};
- image_type = g_type_register_static (GTK_TYPE_MISC, "GtkImage",
+ image_type = g_type_register_static (GTK_TYPE_MISC, I_("GtkImage"),
&image_info, 0);
}
P_("Filename"),
P_("Filename to load and display"),
NULL,
- GTK_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
image->mask = NULL;
priv->pixel_size = -1;
+
+ priv->filename = NULL;
}
static void
GParamSpec *pspec)
{
GtkImage *image;
- GtkImagePrivate *priv;
image = GTK_IMAGE (object);
- priv = GTK_IMAGE_GET_PRIVATE (image);
switch (prop_id)
{
}
break;
case PROP_FILE:
- gtk_image_set_from_file (image,
- g_value_get_string (value));
+ gtk_image_set_from_file (image, g_value_get_string (value));
break;
case PROP_STOCK:
gtk_image_set_from_stock (image, g_value_get_string (value),
g_value_set_object (value,
image->data.image.image);
break;
+ case PROP_FILE:
+ g_value_set_string (value, priv->filename);
+ break;
case PROP_STOCK:
if (image->storage_type != GTK_IMAGE_STOCK)
g_value_set_string (value, NULL);
* @size: a stock icon size
*
* Creates a #GtkImage displaying a stock icon. Sample stock icon
- * names are #GTK_STOCK_OPEN, #GTK_STOCK_EXIT. Sample stock sizes
+ * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. Sample stock sizes
* are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
- * icon name isn't known, a "broken image" icon will be displayed instead.
+ * icon name isn't known, the image will be empty.
* You can register your own stock icon names, see
* gtk_icon_factory_add_default() and gtk_icon_factory_add().
*
* The #GtkImage does not assume a reference to the
* animation; you still need to unref it if you own references.
* #GtkImage will add its own reference rather than adopting yours.
- *
+ *
+ * Note that the animation frames are shown using a timeout with
+ * #G_PRIORITY_DEFAULT. When using animations to indicate busyness,
+ * keep in mind that the animation will only be shown if the main loop
+ * is not busy with something that has a higher priority.
+ *
* Return value: a new #GtkImage widget
**/
GtkWidget*
gtk_image_set_from_file (GtkImage *image,
const gchar *filename)
{
+ GtkImagePrivate *priv = GTK_IMAGE_GET_PRIVATE (image);
GdkPixbufAnimation *anim;
g_return_if_fail (GTK_IS_IMAGE (image));
if (filename == NULL)
{
+ priv->filename = NULL;
g_object_thaw_notify (G_OBJECT (image));
return;
}
-
+
anim = gdk_pixbuf_animation_new_from_file (filename, NULL);
if (anim == NULL)
*/
if (gdk_pixbuf_animation_is_static_image (anim))
- {
- gtk_image_set_from_pixbuf (image,
- gdk_pixbuf_animation_get_static_image (anim));
- }
+ gtk_image_set_from_pixbuf (image,
+ gdk_pixbuf_animation_get_static_image (anim));
else
- {
- gtk_image_set_from_animation (image, anim);
- }
+ gtk_image_set_from_animation (image, anim);
g_object_unref (anim);
+ priv->filename = g_strdup (filename);
+
g_object_thaw_notify (G_OBJECT (image));
}
g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
animation_timeout,
image);
-
+
gtk_widget_queue_draw (GTK_WIDGET (image));
+ if (GTK_WIDGET_DRAWABLE (image))
+ gdk_window_process_updates (GTK_WIDGET (image)->window, TRUE);
+
GDK_THREADS_LEAVE ();
return FALSE;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
gboolean needs_state_transform;
- GtkStockItem item;
- gchar *stock_id;
-
-
+
image = GTK_IMAGE (widget);
misc = GTK_MISC (widget);
xalign = 1.0 - misc->xalign;
x = floor (widget->allocation.x + misc->xpad
- + ((widget->allocation.width - widget->requisition.width) * xalign)
- + 0.5);
+ + ((widget->allocation.width - widget->requisition.width) * xalign));
y = floor (widget->allocation.y + misc->ypad
- + ((widget->allocation.height - widget->requisition.height) * misc->yalign)
- + 0.5);
+ + ((widget->allocation.height - widget->requisition.height) * misc->yalign));
mask_x = x;
mask_y = y;
break;
case GTK_IMAGE_STOCK:
- if (gtk_stock_lookup (image->data.stock.stock_id, &item))
- stock_id = image->data.stock.stock_id;
- else
- stock_id = GTK_STOCK_MISSING_IMAGE;
pixbuf = gtk_widget_render_icon (widget,
- stock_id,
+ image->data.stock.stock_id,
image->icon_size,
NULL);
if (pixbuf)
image_bound.height,
GDK_RGB_DITHER_NORMAL,
0, 0);
-
- g_object_unref (pixbuf);
- pixbuf = NULL;
}
}
else
gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
}
+ if (pixbuf)
+ g_object_unref (pixbuf);
+
} /* if widget is drawable */
return FALSE;
}
-static void
+/**
+ * gtk_image_clear:
+ * @image: a #GtkImage
+ *
+ * Resets the image to be empty.
+ *
+ * Since: 2.8
+ */
+void
gtk_image_clear (GtkImage *image)
{
+ GtkImagePrivate *priv;
+
+ g_return_if_fail (GTK_IS_IMAGE (image));
+
+ priv = GTK_IMAGE_GET_PRIVATE (image);
+
g_object_freeze_notify (G_OBJECT (image));
if (image->storage_type != GTK_IMAGE_EMPTY)
}
+ if (priv->filename)
+ {
+ g_free (priv->filename);
+ priv->filename = NULL;
+ g_object_notify (G_OBJECT (image), "file");
+ }
+
image->storage_type = GTK_IMAGE_EMPTY;
memset (&image->data, '\0', sizeof (image->data));
{
GtkWidget *widget = GTK_WIDGET (image);
GdkPixbuf *pixbuf = NULL;
- GtkStockItem item;
- gchar *stock_id;
/* We update stock/icon set on every size request, because
* the theme could have affected the size; for other kinds of
switch (image->storage_type)
{
case GTK_IMAGE_STOCK:
- if (gtk_stock_lookup (image->data.stock.stock_id, &item))
- stock_id = image->data.stock.stock_id;
- else
- stock_id = GTK_STOCK_MISSING_IMAGE;
pixbuf = gtk_widget_render_icon (widget,
- stock_id,
+ image->data.stock.stock_id,
image->icon_size,
NULL);
break;