return GTK_WIDGET (image);
}
+/**
+ * gtk_image_new_from_resource:
+ * @resource_path: a resource path
+ *
+ * Creates a new #GtkImage displaying the resource file @resource_path. If the file
+ * isn't found or can't be loaded, the resulting #GtkImage will
+ * display a "broken image" icon. This function never returns %NULL,
+ * it always returns a valid #GtkImage widget.
+ *
+ * If the file contains an animation, the image will contain an
+ * animation.
+ *
+ * If you need to detect failures to load the file, use
+ * gdk_pixbuf_new_from_file() to load the file yourself, then create
+ * the #GtkImage from the pixbuf. (Or for animations, use
+ * gdk_pixbuf_animation_new_from_file()).
+ *
+ * The storage type (gtk_image_get_storage_type()) of the returned
+ * image is not defined, it will be whatever is appropriate for
+ * displaying the file.
+ *
+ * Return value: a new #GtkImage
+ *
+ * Since: 3.4
+ **/
+GtkWidget*
+gtk_image_new_from_resource (const gchar *resource_path)
+{
+ GtkImage *image;
+
+ image = g_object_new (GTK_TYPE_IMAGE, NULL);
+
+ gtk_image_set_from_resource (image, resource_path);
+
+ return GTK_WIDGET (image);
+}
+
/**
* gtk_image_new_from_pixbuf:
* @pixbuf: (allow-none): a #GdkPixbuf, or %NULL
g_object_thaw_notify (G_OBJECT (image));
}
+/**
+ * gtk_image_set_from_resource:
+ * @image: a #GtkImage
+ * @resource_path: (allow-none): a resource path or %NULL
+ *
+ * See gtk_image_new_from_resource() for details.
+ **/
+void
+gtk_image_set_from_resource (GtkImage *image,
+ const gchar *resource_path)
+{
+ GdkPixbuf *pixbuf = NULL;
+ GInputStream *stream;
+
+ g_return_if_fail (GTK_IS_IMAGE (image));
+
+ g_object_freeze_notify (G_OBJECT (image));
+
+ gtk_image_clear (image);
+
+ if (resource_path == NULL)
+ {
+ g_object_thaw_notify (G_OBJECT (image));
+ return;
+ }
+
+ stream = g_resources_open_stream (resource_path, 0, NULL);
+ if (stream != NULL)
+ {
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+ g_object_unref (stream);
+ }
+
+ if (pixbuf == NULL)
+ {
+ gtk_image_set_from_stock (image,
+ GTK_STOCK_MISSING_IMAGE,
+ DEFAULT_ICON_SIZE);
+ g_object_thaw_notify (G_OBJECT (image));
+ return;
+ }
+
+ gtk_image_set_from_pixbuf (image, pixbuf);
+
+ g_object_unref (pixbuf);
+
+ g_object_thaw_notify (G_OBJECT (image));
+}
+
+
/**
* gtk_image_set_from_pixbuf:
* @image: a #GtkImage
gint *height_out)
{
GtkImagePrivate *priv = image->priv;
- gint xpad, ypad, width, height;
+ gint width, height;
+ GtkBorder border;
GtkStyleContext *context;
context = gtk_widget_get_style_context (GTK_WIDGET (image));
- gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
_gtk_icon_helper_get_size (priv->icon_helper, context, &width, &height);
+ _gtk_misc_get_padding_and_border (GTK_MISC (image), &border);
- width += 2 * xpad;
- height += 2 * ypad;
+ width += border.left + border.right;
+ height += border.top + border.bottom;
if (width_out)
*width_out = width;
GtkMisc *misc;
GtkStyleContext *context;
gint x, y, width, height;
- gint xpad, ypad;
gfloat xalign, yalign;
+ GtkBorder border;
g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE);
context = gtk_widget_get_style_context (widget);
gtk_misc_get_alignment (misc, &xalign, &yalign);
- gtk_misc_get_padding (misc, &xpad, &ypad);
gtk_image_get_preferred_size (image, &width, &height);
+ _gtk_misc_get_padding_and_border (misc, &border);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
xalign = 1.0 - xalign;
- x = floor (xpad + ((gtk_widget_get_allocated_width (widget) - width) * xalign));
- y = floor (ypad + ((gtk_widget_get_allocated_height (widget) - height) * yalign));
+ x = floor ((gtk_widget_get_allocated_width (widget) - width) * xalign);
+ y = floor ((gtk_widget_get_allocated_height (widget) - height) * yalign);
+
+ gtk_render_background (context, cr, x, y, width, height);
+ gtk_render_frame (context, cr, x, y, width, height);
+
+ x += border.left;
+ y += border.top;
if (gtk_image_get_storage_type (image) == GTK_IMAGE_ANIMATION)
{