*/
#include "config.h"
+
#include <math.h>
#include <string.h>
#include "gtkiconfactory.h"
#include "gtkstock.h"
#include "gtkicontheme.h"
+#include "gtksizerequest.h"
#include "gtkintl.h"
#include "gtkprivate.h"
+#include "gtktypebuiltins.h"
/**
* SECTION:gtkimage
{
GtkIconSize icon_size; /* Only used with GTK_IMAGE_STOCK, GTK_IMAGE_ICON_SET, GTK_IMAGE_ICON_NAME */
GtkImageType storage_type;
- GdkBitmap *mask; /* Only used with GTK_IMAGE_PIXMAP, GTK_IMAGE_IMAGE */
union
{
- GtkImagePixmapData pixmap;
GtkImagePixbufData pixbuf;
GtkImageStockData stock;
GtkImageIconSetData icon_set;
gboolean was_symbolic;
gchar *filename; /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
- gint last_rendered_state; /* a GtkStateType, with -1 meaning an invalid state,
+ gint last_rendered_state; /* a GtkStateFlags, with -1 meaning an invalid state,
* only used with GTK_IMAGE_GICON, GTK_IMAGE_ICON_NAME */
gint pixel_size;
+ gint required_width;
+ gint required_height;
guint need_calc_size : 1;
+ guint use_fallback : 1;
};
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
-static gint gtk_image_expose (GtkWidget *widget,
- GdkEventExpose *event);
-static void gtk_image_unmap (GtkWidget *widget);
-static void gtk_image_unrealize (GtkWidget *widget);
-static void gtk_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_image_style_set (GtkWidget *widget,
- GtkStyle *prev_style);
-static void gtk_image_screen_changed (GtkWidget *widget,
- GdkScreen *prev_screen);
-static void gtk_image_destroy (GtkObject *object);
-static void gtk_image_reset (GtkImage *image);
-static void gtk_image_calc_size (GtkImage *image);
-
-static void gtk_image_update_size (GtkImage *image,
- gint image_width,
- gint image_height);
-
-static void gtk_image_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_image_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void icon_theme_changed (GtkImage *image);
+static gint gtk_image_draw (GtkWidget *widget,
+ cairo_t *cr);
+static void gtk_image_unmap (GtkWidget *widget);
+static void gtk_image_unrealize (GtkWidget *widget);
+static void gtk_image_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_image_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+
+static void gtk_image_style_updated (GtkWidget *widget);
+static void gtk_image_screen_changed (GtkWidget *widget,
+ GdkScreen *prev_screen);
+static void gtk_image_destroy (GtkWidget *widget);
+static void gtk_image_reset (GtkImage *image);
+static void gtk_image_calc_size (GtkImage *image);
+
+static void gtk_image_update_size (GtkImage *image,
+ gint image_width,
+ gint image_height);
+
+static void gtk_image_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_image_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void icon_theme_changed (GtkImage *image);
enum
{
PROP_0,
PROP_PIXBUF,
- PROP_PIXMAP,
- PROP_MASK,
PROP_FILE,
PROP_STOCK,
PROP_ICON_SET,
PROP_PIXBUF_ANIMATION,
PROP_ICON_NAME,
PROP_STORAGE_TYPE,
- PROP_GICON
+ PROP_GICON,
+ PROP_USE_FALLBACK
};
G_DEFINE_TYPE (GtkImage, gtk_image, GTK_TYPE_MISC)
gtk_image_class_init (GtkImageClass *class)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = gtk_image_set_property;
gobject_class->get_property = gtk_image_get_property;
-
- object_class = GTK_OBJECT_CLASS (class);
-
- object_class->destroy = gtk_image_destroy;
widget_class = GTK_WIDGET_CLASS (class);
-
- widget_class->expose_event = gtk_image_expose;
- widget_class->size_request = gtk_image_size_request;
+ widget_class->draw = gtk_image_draw;
+ widget_class->destroy = gtk_image_destroy;
+ widget_class->get_preferred_width = gtk_image_get_preferred_width;
+ widget_class->get_preferred_height = gtk_image_get_preferred_height;
widget_class->unmap = gtk_image_unmap;
widget_class->unrealize = gtk_image_unrealize;
- widget_class->style_set = gtk_image_style_set;
+ widget_class->style_updated = gtk_image_style_updated;
widget_class->screen_changed = gtk_image_screen_changed;
g_object_class_install_property (gobject_class,
GDK_TYPE_PIXBUF,
GTK_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
- PROP_PIXMAP,
- g_param_spec_object ("pixmap",
- P_("Pixmap"),
- P_("A GdkPixmap to display"),
- GDK_TYPE_PIXMAP,
- GTK_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_MASK,
- g_param_spec_object ("mask",
- P_("Mask"),
- P_("Mask bitmap to use with GdkPixmap"),
- GDK_TYPE_PIXMAP,
- GTK_PARAM_READWRITE));
-
g_object_class_install_property (gobject_class,
PROP_FILE,
g_param_spec_string ("file",
GTK_IMAGE_EMPTY,
GTK_PARAM_READABLE));
- g_type_class_add_private (object_class, sizeof (GtkImagePrivate));
+ /**
+ * GtkImage:use-fallback:
+ *
+ * Whether the icon displayed in the GtkImage will use
+ * standard icon names fallback. The value of this property
+ * is only relevant for images of type %GTK_IMAGE_ICON_NAME
+ * and %GTK_IMAGE_GICON.
+ *
+ * Since: 3.0
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_USE_FALLBACK,
+ g_param_spec_boolean ("use-fallback",
+ P_("Use Fallback"),
+ P_("Whether to use icon names fallback"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ g_type_class_add_private (class, sizeof (GtkImagePrivate));
}
static void
priv->storage_type = GTK_IMAGE_EMPTY;
priv->icon_size = DEFAULT_ICON_SIZE;
- priv->mask = NULL;
priv->pixel_size = -1;
}
static void
-gtk_image_destroy (GtkObject *object)
+gtk_image_destroy (GtkWidget *widget)
{
- GtkImage *image = GTK_IMAGE (object);
+ GtkImage *image = GTK_IMAGE (widget);
gtk_image_reset (image);
-
- GTK_OBJECT_CLASS (gtk_image_parent_class)->destroy (object);
+
+ GTK_WIDGET_CLASS (gtk_image_parent_class)->destroy (widget);
}
static void
gtk_image_set_from_pixbuf (image,
g_value_get_object (value));
break;
- case PROP_PIXMAP:
- gtk_image_set_from_pixmap (image,
- g_value_get_object (value),
- priv->mask);
- break;
- case PROP_MASK:
- if (priv->storage_type == GTK_IMAGE_PIXMAP)
- gtk_image_set_from_pixmap (image,
- priv->data.pixmap.pixmap,
- g_value_get_object (value));
- else
- {
- GdkBitmap *mask;
-
- mask = g_value_get_object (value);
-
- if (mask)
- g_object_ref (mask);
-
- gtk_image_clear (image);
-
- priv->mask = mask;
- }
- break;
case PROP_FILE:
gtk_image_set_from_file (image, g_value_get_string (value));
break;
priv->icon_size);
break;
+ case PROP_USE_FALLBACK:
+ priv->use_fallback = g_value_get_boolean (value);
+ if (priv->storage_type == GTK_IMAGE_ICON_NAME)
+ gtk_image_set_from_icon_name (image,
+ priv->data.name.icon_name,
+ priv->icon_size);
+ else if (priv->storage_type == GTK_IMAGE_GICON)
+ gtk_image_set_from_gicon (image,
+ priv->data.gicon.icon,
+ priv->icon_size);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_value_set_object (value,
gtk_image_get_pixbuf (image));
break;
- case PROP_PIXMAP:
- if (priv->storage_type != GTK_IMAGE_PIXMAP)
- g_value_set_object (value, NULL);
- else
- g_value_set_object (value,
- priv->data.pixmap.pixmap);
- break;
- case PROP_MASK:
- g_value_set_object (value, priv->mask);
- break;
case PROP_FILE:
g_value_set_string (value, priv->filename);
break;
case PROP_STORAGE_TYPE:
g_value_set_enum (value, priv->storage_type);
break;
+
+ case PROP_USE_FALLBACK:
+ g_value_set_boolean (value, priv->use_fallback);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
-/**
- * gtk_image_new_from_pixmap:
- * @pixmap: (allow-none): a #GdkPixmap, or %NULL
- * @mask: (allow-none): a #GdkBitmap, or %NULL
- *
- * Creates a #GtkImage widget displaying @pixmap with a @mask.
- * A #GdkPixmap is a server-side image buffer in the pixel format of the
- * current display. The #GtkImage does not assume a reference to the
- * pixmap or mask; you still need to unref them if you own references.
- * #GtkImage will add its own reference rather than adopting yours.
- *
- * Return value: a new #GtkImage
- **/
-GtkWidget*
-gtk_image_new_from_pixmap (GdkPixmap *pixmap,
- GdkBitmap *mask)
-{
- GtkImage *image;
-
- image = g_object_new (GTK_TYPE_IMAGE, NULL);
-
- gtk_image_set_from_pixmap (image, pixmap, mask);
-
- return GTK_WIDGET (image);
-}
-
/**
* gtk_image_new_from_file:
- * @filename: a filename
+ * @filename: (type filename): a filename
*
* Creates a new #GtkImage displaying the file @filename. If the file
* isn't found or can't be loaded, the resulting #GtkImage will
return GTK_WIDGET (image);
}
-/**
- * gtk_image_set_from_pixmap:
- * @image: a #GtkImage
- * @pixmap: (allow-none): a #GdkPixmap or %NULL
- * @mask: (allow-none): a #GdkBitmap or %NULL
- *
- * See gtk_image_new_from_pixmap() for details.
- **/
-void
-gtk_image_set_from_pixmap (GtkImage *image,
- GdkPixmap *pixmap,
- GdkBitmap *mask)
-{
- GtkImagePrivate *priv;
-
- g_return_if_fail (GTK_IS_IMAGE (image));
- g_return_if_fail (pixmap == NULL ||
- GDK_IS_PIXMAP (pixmap));
- g_return_if_fail (mask == NULL ||
- GDK_IS_PIXMAP (mask));
-
- priv = image->priv;
-
- g_object_freeze_notify (G_OBJECT (image));
-
- if (pixmap)
- g_object_ref (pixmap);
-
- if (mask)
- g_object_ref (mask);
-
- gtk_image_clear (image);
-
- priv->mask = mask;
-
- if (pixmap)
- {
- int width;
- int height;
-
- priv->storage_type = GTK_IMAGE_PIXMAP;
-
- priv->data.pixmap.pixmap = pixmap;
-
- gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &width, &height);
-
- gtk_image_update_size (image, width, height);
- }
-
- g_object_notify (G_OBJECT (image), "pixmap");
- g_object_notify (G_OBJECT (image), "mask");
-
- g_object_thaw_notify (G_OBJECT (image));
-}
-
/**
* gtk_image_set_from_file:
* @image: a #GtkImage
- * @filename: (allow-none): a filename or %NULL
+ * @filename: (type filename) (allow-none): a filename or %NULL
*
* See gtk_image_new_from_file() for details.
**/
return image->priv->storage_type;
}
-/**
- * gtk_image_get_pixmap:
- * @image: a #GtkImage
- * @pixmap: (out) (transfer none) (allow-none): location to store the
- * pixmap, or %NULL
- * @mask: (out) (transfer none) (allow-none): location to store the
- * mask, or %NULL
- *
- * Gets the pixmap and mask being displayed by the #GtkImage.
- * The storage type of the image must be %GTK_IMAGE_EMPTY or
- * %GTK_IMAGE_PIXMAP (see gtk_image_get_storage_type()).
- * The caller of this function does not own a reference to the
- * returned pixmap and mask.
- **/
-void
-gtk_image_get_pixmap (GtkImage *image,
- GdkPixmap **pixmap,
- GdkBitmap **mask)
-{
- GtkImagePrivate *priv;
-
- g_return_if_fail (GTK_IS_IMAGE (image));
-
- priv = image->priv;
-
- g_return_if_fail (priv->storage_type == GTK_IMAGE_PIXMAP ||
- priv->storage_type == GTK_IMAGE_EMPTY);
-
- if (pixmap)
- *pixmap = priv->data.pixmap.pixmap;
-
- if (mask)
- *mask = priv->mask;
-}
-
/**
* gtk_image_get_pixbuf:
* @image: a #GtkImage
delay = gdk_pixbuf_animation_iter_get_delay_time (priv->data.anim.iter);
if (delay >= 0)
{
+ GtkWidget *widget = GTK_WIDGET (image);
+
priv->data.anim.frame_timeout =
gdk_threads_add_timeout (delay, animation_timeout, image);
- gtk_widget_queue_draw (GTK_WIDGET (image));
+ gtk_widget_queue_draw (widget);
- if (gtk_widget_is_drawable (GTK_WIDGET (image)))
- gdk_window_process_updates (GTK_WIDGET (image)->window, TRUE);
+ if (gtk_widget_is_drawable (widget))
+ gdk_window_process_updates (gtk_widget_get_window (widget), TRUE);
}
return FALSE;
}
static void
-ensure_pixbuf_for_icon_name (GtkImage *image,
- GtkStateType state)
+ensure_pixbuf_for_icon_name (GtkImage *image,
+ GtkStateFlags state)
{
GtkImagePrivate *priv = image->priv;
GdkScreen *screen;
icon_theme = gtk_icon_theme_get_for_screen (screen);
settings = gtk_settings_get_for_screen (screen);
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
+ if (priv->use_fallback)
+ flags |= GTK_ICON_LOOKUP_GENERIC_FALLBACK;
if (priv->data.name.pixbuf == NULL ||
(priv->was_symbolic && priv->last_rendered_state != state))
{
MIN (width, height), flags);
if (info)
{
- GtkStyle *style;
+ GtkStyleContext *context;
gboolean was_symbolic;
- style = gtk_widget_get_style (GTK_WIDGET (image));
+ context = gtk_widget_get_style_context (GTK_WIDGET (image));
priv->data.name.pixbuf =
- gtk_icon_info_load_symbolic_for_style (info,
- style, state,
- &was_symbolic,
- NULL);
+ gtk_icon_info_load_symbolic_for_context (info,
+ context,
+ &was_symbolic,
+ NULL);
priv->was_symbolic = was_symbolic;
gtk_icon_info_free (info);
}
if (priv->data.name.pixbuf == NULL)
{
priv->data.name.pixbuf =
- gtk_widget_render_icon (GTK_WIDGET (image),
- GTK_STOCK_MISSING_IMAGE,
- priv->icon_size,
- NULL);
+ gtk_widget_render_icon_pixbuf (GTK_WIDGET (image),
+ GTK_STOCK_MISSING_IMAGE,
+ priv->icon_size);
priv->was_symbolic = FALSE;
}
}
}
static void
-ensure_pixbuf_for_gicon (GtkImage *image,
- GtkStateType state)
+ensure_pixbuf_for_gicon (GtkImage *image,
+ GtkStateFlags state)
{
GtkImagePrivate *priv = image->priv;
GdkScreen *screen;
icon_theme = gtk_icon_theme_get_for_screen (screen);
settings = gtk_settings_get_for_screen (screen);
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
+ if (priv->use_fallback)
+ flags |= GTK_ICON_LOOKUP_GENERIC_FALLBACK;
if (priv->data.gicon.pixbuf == NULL ||
(priv->was_symbolic && priv->last_rendered_state != state))
{
MIN (width, height), flags);
if (info)
{
- GtkStyle *style;
+ GtkStyleContext *context;
gboolean was_symbolic;
- style = gtk_widget_get_style (GTK_WIDGET (image));
+ context = gtk_widget_get_style_context (GTK_WIDGET (image));
priv->data.gicon.pixbuf =
- gtk_icon_info_load_symbolic_for_style (info,
- style, state,
- &was_symbolic,
- NULL);
+ gtk_icon_info_load_symbolic_for_context (info,
+ context,
+ &was_symbolic,
+ NULL);
priv->was_symbolic = was_symbolic;
gtk_icon_info_free (info);
}
if (priv->data.gicon.pixbuf == NULL)
{
priv->data.gicon.pixbuf =
- gtk_widget_render_icon (GTK_WIDGET (image),
- GTK_STOCK_MISSING_IMAGE,
- priv->icon_size,
- NULL);
+ gtk_widget_render_icon_pixbuf (GTK_WIDGET (image),
+ GTK_STOCK_MISSING_IMAGE,
+ priv->icon_size);
priv->was_symbolic = FALSE;
}
}
}
-
-/*
- * Like gdk_rectangle_intersect (dest, src, dest), but make
- * sure that the origin of dest is moved by an "even" offset.
- * If necessary grow the intersection by one row or column
- * to achieve this.
- *
- * This is necessary since we can't pass alignment information
- * for the pixelation pattern down to gdk_pixbuf_saturate_and_pixelate(),
- * thus we have to makesure that the subimages are properly aligned.
- */
-static gboolean
-rectangle_intersect_even (GdkRectangle *src,
- GdkRectangle *dest)
-{
- gboolean isect;
- gint x, y;
-
- x = dest->x;
- y = dest->y;
- isect = gdk_rectangle_intersect (dest, src, dest);
-
- if ((dest->x - x + dest->y - y) % 2 != 0)
- {
- if (dest->x > x)
- {
- dest->x--;
- dest->width++;
- }
- else
- {
- dest->y--;
- dest->height++;
- }
- }
-
- return isect;
-}
-
static gint
-gtk_image_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_image_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GtkImage *image;
GtkImagePrivate *priv;
g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
image = GTK_IMAGE (widget);
priv = image->priv;
- if (gtk_widget_get_mapped (widget) &&
- priv->storage_type != GTK_IMAGE_EMPTY)
+ if (priv->storage_type != GTK_IMAGE_EMPTY)
{
GtkMisc *misc;
- GdkRectangle area, image_bound;
- gint x, y, mask_x, mask_y;
+ gint x, y;
gint xpad, ypad;
gfloat xalign, yalign;
- GdkBitmap *mask;
GdkPixbuf *pixbuf;
- GtkStateType state;
+ GtkStateFlags state;
gboolean needs_state_transform;
+ GtkStyleContext *context;
misc = GTK_MISC (widget);
- area = event->area;
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
/* For stock items and icon sets, we lazily calculate
* the size; we might get here between a queue_resize()
*/
if (priv->need_calc_size)
gtk_image_calc_size (image);
-
- if (!gdk_rectangle_intersect (&area, &widget->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 (widget->allocation.x + xpad
- + ((widget->allocation.width - widget->requisition.width) * xalign));
- y = floor (widget->allocation.y + ypad
- + ((widget->allocation.height - widget->requisition.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;
-
+ x = floor (xpad + ((gtk_widget_get_allocated_width (widget) - priv->required_width) * xalign));
+ y = floor (ypad + ((gtk_widget_get_allocated_height (widget) - priv->required_height) * yalign));
+
+ needs_state_transform = state != 0;
+
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);
- }
+ 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);
- }
+ pixbuf = gtk_widget_render_icon_pixbuf (widget,
+ priv->data.stock.stock_id,
+ priv->icon_size);
/* already done */
needs_state_transform = FALSE;
case GTK_IMAGE_ICON_SET:
pixbuf =
- gtk_icon_set_render_icon (priv->data.icon_set.icon_set,
- widget->style,
- 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);
- }
+ gtk_icon_set_render_icon_pixbuf (priv->data.icon_set.icon_set,
+ context, priv->icon_size);
/* already done */
needs_state_transform = FALSE;
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.
*/
break;
case GTK_IMAGE_ICON_NAME:
- state = gtk_widget_get_state (widget);
- if (state == GTK_STATE_INSENSITIVE)
+ if (state & GTK_STATE_FLAG_INSENSITIVE)
{
- ensure_pixbuf_for_icon_name (image, GTK_STATE_NORMAL);
+ ensure_pixbuf_for_icon_name (image, 0);
}
else
{
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)
+ if (state & GTK_STATE_FLAG_INSENSITIVE)
{
- ensure_pixbuf_for_gicon (image, GTK_STATE_NORMAL);
+ ensure_pixbuf_for_gicon (image, 0);
}
else
{
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:
+ default:
g_assert_not_reached ();
+ pixbuf = NULL;
break;
}
- if (rectangle_intersect_even (&area, &image_bound))
+ if (pixbuf)
{
- if (pixbuf)
- {
- if (needs_state_transform)
- {
- GtkIconSource *source;
- GdkPixbuf *rendered;
-
- source = gtk_icon_source_new ();
- gtk_icon_source_set_pixbuf (source, pixbuf);
- /* The size here is arbitrary; since size isn't
- * wildcarded in the souce, it isn't supposed to be
- * scaled by the engine function
- */
- gtk_icon_source_set_size (source,
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- gtk_icon_source_set_size_wildcarded (source, FALSE);
-
- rendered = gtk_style_render_icon (widget->style,
- source,
- gtk_widget_get_direction (widget),
- gtk_widget_get_state (widget),
- /* arbitrary */
- (GtkIconSize)-1,
- widget,
- "gtk-image");
-
- gtk_icon_source_free (source);
-
- g_object_unref (pixbuf);
- pixbuf = rendered;
- }
-
- if (pixbuf)
- {
- cairo_t *cr = gdk_cairo_create (widget->window);
- gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
- gdk_cairo_rectangle (cr, &image_bound);
- cairo_fill (cr);
- cairo_destroy (cr);
- }
- }
- else
+ if (needs_state_transform)
{
- cairo_t *cr;
- cairo_pattern_t *mask_pattern;
-
- switch (priv->storage_type)
- {
- case GTK_IMAGE_PIXMAP:
- cr = gdk_cairo_create (widget->window);
-
- if (mask)
- {
- /* hack to get the mask pattern */
- gdk_cairo_set_source_pixmap (cr, mask, mask_x, mask_y);
- mask_pattern = cairo_get_source (cr);
- cairo_pattern_reference (mask_pattern);
-
- gdk_cairo_set_source_pixmap (cr, priv->data.pixmap.pixmap, x, y);
- gdk_cairo_rectangle (cr, &image_bound);
- cairo_clip (cr);
- cairo_mask (cr, mask_pattern);
- }
- else
- {
- gdk_cairo_set_source_pixmap (cr, priv->data.pixmap.pixmap, x, y);
- gdk_cairo_rectangle (cr, &image_bound);
- cairo_fill (cr);
- }
-
- cairo_destroy (cr);
- break;
-
- case GTK_IMAGE_PIXBUF:
- case GTK_IMAGE_STOCK:
- case GTK_IMAGE_ICON_SET:
- case GTK_IMAGE_ANIMATION:
- case GTK_IMAGE_ICON_NAME:
- case GTK_IMAGE_EMPTY:
- case GTK_IMAGE_GICON:
- g_assert_not_reached ();
- break;
- }
+ GtkIconSource *source;
+ GdkPixbuf *rendered;
+
+ source = gtk_icon_source_new ();
+ gtk_icon_source_set_pixbuf (source, pixbuf);
+ /* The size here is arbitrary; since size isn't
+ * wildcarded in the souce, it isn't supposed to be
+ * scaled by the engine function
+ */
+ gtk_icon_source_set_size (source,
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_icon_source_set_size_wildcarded (source, FALSE);
+
+ rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1);
+ gtk_icon_source_free (source);
+
+ g_object_unref (pixbuf);
+ pixbuf = rendered;
}
- } /* if rectangle intersects */
- if (pixbuf)
- g_object_unref (pixbuf);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+ cairo_paint (cr);
- } /* if widget is drawable */
+ g_object_unref (pixbuf);
+ }
+
+ gtk_style_context_restore (context);
+ }
return FALSE;
}
if (priv->storage_type != GTK_IMAGE_EMPTY)
g_object_notify (G_OBJECT (image), "storage-type");
- if (priv->mask)
- {
- g_object_unref (priv->mask);
- priv->mask = NULL;
- g_object_notify (G_OBJECT (image), "mask");
- }
-
if (priv->icon_size != DEFAULT_ICON_SIZE)
{
priv->icon_size = DEFAULT_ICON_SIZE;
switch (priv->storage_type)
{
- case GTK_IMAGE_PIXMAP:
-
- if (priv->data.pixmap.pixmap)
- g_object_unref (priv->data.pixmap.pixmap);
- priv->data.pixmap.pixmap = NULL;
-
- g_object_notify (G_OBJECT (image), "pixmap");
-
- break;
case GTK_IMAGE_PIXBUF:
GtkWidget *widget = GTK_WIDGET (image);
GtkImagePrivate *priv = image->priv;
GdkPixbuf *pixbuf = NULL;
+ GtkStyleContext *context;
+ GtkStateFlags state;
priv->need_calc_size = 0;
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
/* We update stock/icon set on every size request, because
* the theme could have affected the size; for other kinds of
- * image, we just update the requisition when the image data
+ * image, we just update the required width/height when the image data
* is set.
*/
switch (priv->storage_type)
{
case GTK_IMAGE_STOCK:
- pixbuf = gtk_widget_render_icon (widget,
- priv->data.stock.stock_id,
- priv->icon_size,
- NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (widget,
+ priv->data.stock.stock_id,
+ priv->icon_size);
break;
case GTK_IMAGE_ICON_SET:
- pixbuf = gtk_icon_set_render_icon (priv->data.icon_set.icon_set,
- widget->style,
- gtk_widget_get_direction (widget),
- gtk_widget_get_state (widget),
- priv->icon_size,
- widget,
- NULL);
+ pixbuf = gtk_icon_set_render_icon_pixbuf (priv->data.icon_set.icon_set,
+ context, priv->icon_size);
break;
case GTK_IMAGE_ICON_NAME:
- ensure_pixbuf_for_icon_name (image, GTK_STATE_NORMAL);
+ ensure_pixbuf_for_icon_name (image, 0);
pixbuf = priv->data.name.pixbuf;
if (pixbuf) g_object_ref (pixbuf);
break;
case GTK_IMAGE_GICON:
- ensure_pixbuf_for_gicon (image, GTK_STATE_NORMAL);
+ ensure_pixbuf_for_gicon (image, 0);
pixbuf = priv->data.gicon.pixbuf;
if (pixbuf)
g_object_ref (pixbuf);
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
- widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
- widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
+ priv->required_width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
+ priv->required_height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
g_object_unref (pixbuf);
}
+
+ gtk_style_context_restore (context);
}
static void
-gtk_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_image_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
GtkImage *image;
-
+ GtkImagePrivate *priv;
+
+ image = GTK_IMAGE (widget);
+ priv = image->priv;
+
+ gtk_image_calc_size (image);
+
+ *minimum = *natural = priv->required_width;
+}
+
+static void
+gtk_image_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkImage *image;
+ GtkImagePrivate *priv;
+
image = GTK_IMAGE (widget);
+ priv = image->priv;
gtk_image_calc_size (image);
- /* Chain up to default that simply reads current requisition */
- GTK_WIDGET_CLASS (gtk_image_parent_class)->size_request (widget, requisition);
+ *minimum = *natural = priv->required_height;
}
static void
-gtk_image_style_set (GtkWidget *widget,
- GtkStyle *prev_style)
+gtk_image_style_updated (GtkWidget *widget)
{
GtkImage *image;
image = GTK_IMAGE (widget);
- GTK_WIDGET_CLASS (gtk_image_parent_class)->style_set (widget, prev_style);
+ GTK_WIDGET_CLASS (gtk_image_parent_class)->style_updated (widget);
icon_theme_changed (image);
}
gint image_width,
gint image_height)
{
- GtkWidget *widget = GTK_WIDGET (image);
- gint xpad, ypad;
+ GtkWidget *widget = GTK_WIDGET (image);
+ GtkImagePrivate *priv = image->priv;
+ gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
- widget->requisition.width = image_width + xpad * 2;
- widget->requisition.height = image_height + ypad * 2;
+ priv->required_width = image_width + xpad * 2;
+ priv->required_height = image_height + ypad * 2;
if (gtk_widget_get_visible (widget))
gtk_widget_queue_resize (widget);
return image->priv->pixel_size;
}
-
-#if defined (G_OS_WIN32) && !defined (_WIN64)
-
-#undef gtk_image_new_from_file
-
-GtkWidget*
-gtk_image_new_from_file (const gchar *filename)
-{
- gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
- GtkWidget *retval;
-
- retval = gtk_image_new_from_file_utf8 (utf8_filename);
-
- g_free (utf8_filename);
-
- return retval;
-}
-
-#undef gtk_image_set_from_file
-
-void
-gtk_image_set_from_file (GtkImage *image,
- const gchar *filename)
-{
- gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
-
- gtk_image_set_from_file_utf8 (image, utf8_filename);
-
- g_free (utf8_filename);
-}
-
-#endif