-
- if (gtk_widget_get_mapped (widget) &&
- priv->storage_type != GTK_IMAGE_EMPTY)
- {
- GtkAllocation allocation;
- GtkMisc *misc;
- GdkRectangle area, image_bound;
- gint x, y, mask_x, mask_y;
- gint xpad, ypad;
- gfloat xalign, yalign;
- GdkBitmap *mask;
- GdkPixbuf *pixbuf;
- GtkStateType state;
- gboolean needs_state_transform;
-
- misc = GTK_MISC (widget);
- area = event->area;
-
- /* For stock items and icon sets, we lazily calculate
- * the size; we might get here between a queue_resize()
- * and size_request() if something explicitely forces
- * a redraw.
- */
- if (priv->need_calc_size)
- gtk_image_calc_size (image);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- if (!gdk_rectangle_intersect (&area, &allocation, &area))
- return FALSE;
-
- gtk_misc_get_alignment (misc, &xalign, &yalign);
- gtk_misc_get_padding (misc, &xpad, &ypad);
-
- if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
- xalign = 1.0 - xalign;
-
- x = floor (allocation.x + xpad + ((allocation.width - priv->required_width) * xalign));
- y = floor (allocation.y + ypad + ((allocation.height - priv->required_height) * yalign));
- mask_x = x;
- mask_y = y;
-
- image_bound.x = x;
- image_bound.y = y;
- image_bound.width = 0;
- image_bound.height = 0;
-
- mask = NULL;
- pixbuf = NULL;
- needs_state_transform = gtk_widget_get_state (widget) != GTK_STATE_NORMAL;
-
- switch (priv->storage_type)
- {
- case GTK_IMAGE_PIXMAP:
- mask = priv->mask;
- gdk_drawable_get_size (priv->data.pixmap.pixmap,
- &image_bound.width,
- &image_bound.height);
- if (rectangle_intersect_even (&area, &image_bound) &&
- needs_state_transform)
- {
- pixbuf = gdk_pixbuf_get_from_drawable (NULL,
- priv->data.pixmap.pixmap,
- gtk_widget_get_colormap (widget),
- image_bound.x - x, image_bound.y - y,
- 0, 0,
- image_bound.width,
- image_bound.height);
-
- x = image_bound.x;
- y = image_bound.y;
- }
-
- break;
-
- case GTK_IMAGE_PIXBUF:
- image_bound.width = gdk_pixbuf_get_width (priv->data.pixbuf.pixbuf);
- image_bound.height = gdk_pixbuf_get_height (priv->data.pixbuf.pixbuf);
-
- if (rectangle_intersect_even (&area, &image_bound) &&
- needs_state_transform)
- {
- pixbuf = gdk_pixbuf_new_subpixbuf (priv->data.pixbuf.pixbuf,
- image_bound.x - x, image_bound.y - y,
- image_bound.width, image_bound.height);
-
- x = image_bound.x;
- y = image_bound.y;
- }
- else
- {
- pixbuf = priv->data.pixbuf.pixbuf;
- g_object_ref (pixbuf);
- }
- break;
-
- case GTK_IMAGE_STOCK:
- pixbuf = gtk_widget_render_icon (widget,
- priv->data.stock.stock_id,
- priv->icon_size,
- NULL);
- if (pixbuf)
- {
- image_bound.width = gdk_pixbuf_get_width (pixbuf);
- image_bound.height = gdk_pixbuf_get_height (pixbuf);
- }
-
- /* already done */
- needs_state_transform = FALSE;
- break;
-
- case GTK_IMAGE_ICON_SET:
- pixbuf =
- gtk_icon_set_render_icon (priv->data.icon_set.icon_set,
- gtk_widget_get_style (widget),
- gtk_widget_get_direction (widget),
- gtk_widget_get_state (widget),
- priv->icon_size,
- widget,
- NULL);
-
- if (pixbuf)
- {
- image_bound.width = gdk_pixbuf_get_width (pixbuf);
- image_bound.height = gdk_pixbuf_get_height (pixbuf);
- }
-
- /* already done */
- needs_state_transform = FALSE;
- break;
-
- case GTK_IMAGE_ANIMATION:
- {
- if (priv->data.anim.iter == NULL)
- {
- priv->data.anim.iter = gdk_pixbuf_animation_get_iter (priv->data.anim.anim, NULL);
-
- if (gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter) >= 0)
- priv->data.anim.frame_timeout =
- gdk_threads_add_timeout (gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter),
- animation_timeout,
- image);
- }
-
- image_bound.width = gdk_pixbuf_animation_get_width (priv->data.anim.anim);
- image_bound.height = gdk_pixbuf_animation_get_height (priv->data.anim.anim);
-
- /* don't advance the anim iter here, or we could get frame changes between two
- * exposes of different areas.
- */
-
- pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (priv->data.anim.iter);
- g_object_ref (pixbuf);
- }
- break;
-
- case GTK_IMAGE_ICON_NAME:
- state = gtk_widget_get_state (widget);
- if (state == GTK_STATE_INSENSITIVE)
- {
- ensure_pixbuf_for_icon_name (image, GTK_STATE_NORMAL);
- }
- else
- {
- ensure_pixbuf_for_icon_name (image, state);
- /* Already done by the loading function? */
- if (priv->was_symbolic)
- needs_state_transform = FALSE;
- }
- pixbuf = priv->data.name.pixbuf;
- if (pixbuf)
- {
- g_object_ref (pixbuf);
- image_bound.width = gdk_pixbuf_get_width (pixbuf);
- image_bound.height = gdk_pixbuf_get_height (pixbuf);
- }
- break;
-
- case GTK_IMAGE_GICON:
- state = gtk_widget_get_state (widget);
- if (state == GTK_STATE_INSENSITIVE)
- {
- ensure_pixbuf_for_gicon (image, GTK_STATE_NORMAL);
- }
- else
- {
- ensure_pixbuf_for_gicon (image, state);
- /* Already done by the loading function? */
- if (priv->was_symbolic)
- needs_state_transform = FALSE;
- }
- pixbuf = priv->data.gicon.pixbuf;
- if (pixbuf)
- {
- g_object_ref (pixbuf);
- image_bound.width = gdk_pixbuf_get_width (pixbuf);
- image_bound.height = gdk_pixbuf_get_height (pixbuf);
- }
- break;
-
- case GTK_IMAGE_EMPTY:
- g_assert_not_reached ();
- break;
- }