2011-11-30 03:26:19 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors: Cosimo Cecchi <cosimoc@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-30 03:26:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-05-10 19:50:37 +00:00
|
|
|
#include "gtkiconhelperprivate.h"
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
#include <math.h>
|
2014-05-10 19:50:37 +00:00
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
#include "gtkiconhelperprivate.h"
|
2014-05-10 19:50:37 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
struct _GtkIconHelperPrivate {
|
|
|
|
GtkImageType storage_type;
|
|
|
|
|
2013-06-24 12:05:27 +00:00
|
|
|
GdkWindow *window;
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
GdkPixbuf *orig_pixbuf;
|
2013-06-24 12:13:43 +00:00
|
|
|
int orig_pixbuf_scale;
|
2011-11-30 03:26:19 +00:00
|
|
|
GdkPixbufAnimation *animation;
|
|
|
|
GIcon *gicon;
|
|
|
|
GtkIconSet *icon_set;
|
|
|
|
gchar *stock_id;
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *orig_surface;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
GtkIconSize icon_size;
|
|
|
|
gint pixel_size;
|
|
|
|
|
2012-07-13 13:54:29 +00:00
|
|
|
guint use_fallback : 1;
|
|
|
|
guint force_scale_pixbuf : 1;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
GdkPixbuf *rendered_pixbuf;
|
|
|
|
GtkStateFlags last_rendered_state;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
cairo_surface_t *rendered_surface;
|
|
|
|
gint rendered_surface_width;
|
|
|
|
gint rendered_surface_height;
|
|
|
|
GtkStateFlags last_surface_state;
|
|
|
|
gint last_surface_scale;
|
2011-11-30 03:26:19 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkIconHelper, _gtk_icon_helper, G_TYPE_OBJECT)
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_clear (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
g_clear_object (&self->priv->gicon);
|
|
|
|
g_clear_object (&self->priv->orig_pixbuf);
|
|
|
|
g_clear_object (&self->priv->animation);
|
|
|
|
g_clear_object (&self->priv->rendered_pixbuf);
|
2013-06-24 12:05:27 +00:00
|
|
|
g_clear_object (&self->priv->window);
|
2013-10-02 13:06:36 +00:00
|
|
|
g_clear_pointer (&self->priv->orig_surface, cairo_surface_destroy);
|
|
|
|
g_clear_pointer (&self->priv->rendered_surface, cairo_surface_destroy);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
if (self->priv->icon_set != NULL)
|
|
|
|
{
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
gtk_icon_set_unref (self->priv->icon_set);
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
self->priv->icon_set = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-02 13:06:36 +00:00
|
|
|
g_clear_pointer (&self->priv->stock_id, g_free);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
self->priv->storage_type = GTK_IMAGE_EMPTY;
|
|
|
|
self->priv->icon_size = GTK_ICON_SIZE_INVALID;
|
|
|
|
self->priv->last_rendered_state = GTK_STATE_FLAG_NORMAL;
|
2013-06-24 12:13:43 +00:00
|
|
|
self->priv->last_surface_state = GTK_STATE_FLAG_NORMAL;
|
|
|
|
self->priv->last_surface_scale = 0;
|
2014-07-23 04:27:59 +00:00
|
|
|
self->priv->orig_pixbuf_scale = 1;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_invalidate (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
g_clear_object (&self->priv->rendered_pixbuf);
|
2013-08-03 16:03:52 +00:00
|
|
|
if (self->priv->rendered_surface != NULL)
|
|
|
|
{
|
|
|
|
cairo_surface_destroy (self->priv->rendered_surface);
|
|
|
|
self->priv->rendered_surface = NULL;
|
|
|
|
}
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 12:05:27 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_window (GtkIconHelper *self,
|
|
|
|
GdkWindow *window)
|
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
g_object_ref (window);
|
|
|
|
g_clear_object (&self->priv->window);
|
|
|
|
self->priv->window = window;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
static void
|
|
|
|
gtk_icon_helper_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkIconHelper *self = GTK_ICON_HELPER (object);
|
|
|
|
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_icon_helper_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_icon_helper_class_init (GtkIconHelperClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *oclass;
|
|
|
|
|
|
|
|
oclass = G_OBJECT_CLASS (klass);
|
|
|
|
oclass->finalize = gtk_icon_helper_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_icon_helper_init (GtkIconHelper *self)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
self->priv = _gtk_icon_helper_get_instance_private (self);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
self->priv->storage_type = GTK_IMAGE_EMPTY;
|
|
|
|
self->priv->icon_size = GTK_ICON_SIZE_INVALID;
|
|
|
|
self->priv->pixel_size = -1;
|
|
|
|
self->priv->last_rendered_state = GTK_STATE_FLAG_NORMAL;
|
2013-06-24 12:13:43 +00:00
|
|
|
self->priv->orig_pixbuf_scale = 1;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_icon_size (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
gint *width_out,
|
|
|
|
gint *height_out)
|
|
|
|
{
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
if (self->priv->pixel_size != -1)
|
|
|
|
{
|
|
|
|
width = height = self->priv->pixel_size;
|
|
|
|
}
|
2013-06-26 22:41:15 +00:00
|
|
|
else if (!gtk_icon_size_lookup (self->priv->icon_size, &width, &height))
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2011-11-30 23:32:01 +00:00
|
|
|
if (self->priv->icon_size == GTK_ICON_SIZE_INVALID)
|
|
|
|
{
|
|
|
|
width = height = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Invalid icon size %d\n", self->priv->icon_size);
|
|
|
|
width = height = 24;
|
|
|
|
}
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*width_out = width;
|
|
|
|
*height_out = height;
|
|
|
|
}
|
|
|
|
|
2013-08-04 14:56:37 +00:00
|
|
|
static GdkPixbuf *
|
|
|
|
ensure_stated_pixbuf_from_pixbuf (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixbuf *rendered;
|
|
|
|
GtkIconSource *source;
|
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
|
|
/* FIXME: use gtk_icon_info_load_icon? */
|
|
|
|
|
|
|
|
source = gtk_icon_source_new ();
|
|
|
|
gtk_icon_source_set_pixbuf (source, pixbuf);
|
|
|
|
/* The size here is arbitrary; since size isn't
|
|
|
|
* wildcarded in the source, 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_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
|
|
return rendered;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
static GdkPixbuf *
|
|
|
|
ensure_stated_icon_from_info (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GtkIconInfo *info)
|
|
|
|
{
|
|
|
|
GdkPixbuf *destination = NULL;
|
|
|
|
gboolean symbolic;
|
|
|
|
|
|
|
|
symbolic = FALSE;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
destination =
|
|
|
|
gtk_icon_info_load_symbolic_for_context (info,
|
|
|
|
context,
|
|
|
|
&symbolic,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (destination == NULL)
|
|
|
|
{
|
2013-06-24 23:28:53 +00:00
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context));
|
|
|
|
gtk_icon_size_lookup (self->priv->icon_size, &width, NULL);
|
|
|
|
destination = gtk_icon_theme_load_icon (icon_theme,
|
|
|
|
"image-missing",
|
|
|
|
width,
|
|
|
|
GTK_ICON_LOOKUP_GENERIC_FALLBACK,
|
|
|
|
NULL);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
else if (!symbolic)
|
|
|
|
{
|
|
|
|
GdkPixbuf *rendered;
|
|
|
|
|
2013-08-04 14:56:37 +00:00
|
|
|
rendered = ensure_stated_pixbuf_from_pixbuf (self, context, destination);
|
2011-11-30 03:26:19 +00:00
|
|
|
g_object_unref (destination);
|
|
|
|
destination = rendered;
|
|
|
|
}
|
|
|
|
|
|
|
|
return destination;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_invalidate_pixbuf (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
|
|
|
state = gtk_style_context_get_state (context);
|
|
|
|
|
|
|
|
if ((self->priv->rendered_pixbuf != NULL) &&
|
|
|
|
(self->priv->last_rendered_state == state))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
self->priv->last_rendered_state = state;
|
|
|
|
g_clear_object (&self->priv->rendered_pixbuf);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkIconLookupFlags
|
2014-05-10 19:50:37 +00:00
|
|
|
get_icon_lookup_flags (GtkIconHelper *self, GtkStyleContext *context)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
GtkIconLookupFlags flags = GTK_ICON_LOOKUP_USE_BUILTIN;
|
|
|
|
|
|
|
|
if (self->priv->use_fallback)
|
|
|
|
flags |= GTK_ICON_LOOKUP_GENERIC_FALLBACK;
|
2014-06-22 15:14:41 +00:00
|
|
|
if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
|
2011-11-30 03:26:19 +00:00
|
|
|
flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
|
|
|
|
|
2014-05-10 19:50:37 +00:00
|
|
|
flags |= _gtk_style_context_get_icon_lookup_flags (context);
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-08 16:42:35 +00:00
|
|
|
ensure_pixbuf_for_gicon (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
gint width, height;
|
|
|
|
GtkIconInfo *info;
|
|
|
|
GtkIconLookupFlags flags;
|
|
|
|
|
|
|
|
if (!check_invalidate_pixbuf (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_get_default ();
|
2014-05-10 19:50:37 +00:00
|
|
|
flags = get_icon_lookup_flags (self, context);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
|
2014-05-08 16:42:35 +00:00
|
|
|
if (self->priv->gicon != NULL)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
info = gtk_icon_theme_lookup_by_gicon (icon_theme,
|
|
|
|
self->priv->gicon,
|
|
|
|
MIN (width, height), flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->priv->rendered_pixbuf = ensure_stated_icon_from_info (self, context, info);
|
|
|
|
|
|
|
|
if (info)
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (info);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_pixbuf_for_icon_set (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GtkIconSet *icon_set)
|
|
|
|
{
|
|
|
|
if (!check_invalidate_pixbuf (self, context))
|
|
|
|
return;
|
|
|
|
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
self->priv->rendered_pixbuf =
|
|
|
|
gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
static void
|
|
|
|
get_surface_size (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
|
|
|
double x_scale, y_scale;
|
|
|
|
|
|
|
|
if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE)
|
|
|
|
{
|
|
|
|
x_scale = y_scale = 1;
|
|
|
|
|
|
|
|
cairo_surface_get_device_scale (surface, &x_scale, &y_scale);
|
|
|
|
|
|
|
|
/* Assume any set scaling is icon scale */
|
|
|
|
*width =
|
|
|
|
ceil (cairo_image_surface_get_width (surface) / x_scale);
|
|
|
|
*height =
|
|
|
|
ceil (cairo_image_surface_get_height (surface) / y_scale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ensure_icon_size (self, context, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_pixbuf_from_surface (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
gint width, height;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
|
|
|
|
if (!check_invalidate_pixbuf (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->priv->rendered_pixbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
get_surface_size (self, context, self->priv->orig_surface, &width, &height);
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_source_surface (cr, self->priv->orig_surface, 0, 0);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
self->priv->rendered_pixbuf =
|
|
|
|
gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
2012-07-13 13:54:29 +00:00
|
|
|
static void
|
|
|
|
ensure_pixbuf_at_size (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
gint width, height;
|
2013-08-04 14:50:31 +00:00
|
|
|
GdkPixbuf *stated;
|
2012-07-13 13:54:29 +00:00
|
|
|
|
|
|
|
if (!check_invalidate_pixbuf (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->priv->rendered_pixbuf)
|
|
|
|
return;
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
if (self->priv->force_scale_pixbuf &&
|
|
|
|
(self->priv->pixel_size != -1 ||
|
|
|
|
self->priv->icon_size != GTK_ICON_SIZE_INVALID))
|
2012-07-13 13:54:29 +00:00
|
|
|
{
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
if (self->priv->orig_pixbuf_scale > 1 ||
|
|
|
|
/* These should divide the orig_pixbuf size by scale, but need not
|
|
|
|
due to the above scale > 1 check */
|
|
|
|
width < gdk_pixbuf_get_width (self->priv->orig_pixbuf) ||
|
2012-07-13 13:54:29 +00:00
|
|
|
height < gdk_pixbuf_get_height (self->priv->orig_pixbuf))
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
|
|
|
width = MIN (width, gdk_pixbuf_get_width (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale);
|
|
|
|
height = MIN (height, gdk_pixbuf_get_height (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale);
|
|
|
|
self->priv->rendered_pixbuf =
|
|
|
|
gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
|
|
|
|
width, height,
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (self->priv->orig_pixbuf_scale > 1)
|
|
|
|
{
|
|
|
|
width = gdk_pixbuf_get_width (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale;
|
|
|
|
height =gdk_pixbuf_get_height (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale;
|
|
|
|
self->priv->rendered_pixbuf =
|
|
|
|
gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
|
|
|
|
width, height,
|
|
|
|
GDK_INTERP_BILINEAR);
|
2012-07-13 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->priv->rendered_pixbuf)
|
|
|
|
self->priv->rendered_pixbuf = g_object_ref (self->priv->orig_pixbuf);
|
2013-08-04 14:50:31 +00:00
|
|
|
|
|
|
|
stated = ensure_stated_pixbuf_from_pixbuf (self, context, self->priv->rendered_pixbuf);
|
|
|
|
g_object_unref (self->priv->rendered_pixbuf);
|
|
|
|
self->priv->rendered_pixbuf = stated;
|
2012-07-13 13:54:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
GdkPixbuf *
|
|
|
|
_gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
GtkIconSet *icon_set;
|
|
|
|
|
|
|
|
switch (self->priv->storage_type)
|
|
|
|
{
|
2013-06-24 12:13:43 +00:00
|
|
|
case GTK_IMAGE_SURFACE:
|
|
|
|
ensure_pixbuf_from_surface (self, context);
|
|
|
|
break;
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
case GTK_IMAGE_PIXBUF:
|
2013-06-24 12:13:43 +00:00
|
|
|
ensure_pixbuf_at_size (self, context);
|
2011-11-30 03:26:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_STOCK:
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
icon_set = gtk_style_context_lookup_icon_set (context, self->priv->stock_id);
|
2012-12-13 09:08:37 +00:00
|
|
|
if (icon_set != NULL)
|
|
|
|
ensure_pixbuf_for_icon_set (self, context, icon_set);
|
|
|
|
else
|
|
|
|
pixbuf = NULL;
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_SET:
|
|
|
|
icon_set = self->priv->icon_set;
|
|
|
|
ensure_pixbuf_for_icon_set (self, context, icon_set);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
case GTK_IMAGE_GICON:
|
2014-05-08 16:42:35 +00:00
|
|
|
ensure_pixbuf_for_gicon (self, context);
|
2011-11-30 03:26:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
case GTK_IMAGE_EMPTY:
|
|
|
|
default:
|
|
|
|
pixbuf = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixbuf == NULL &&
|
|
|
|
self->priv->rendered_pixbuf != NULL)
|
|
|
|
pixbuf = g_object_ref (self->priv->rendered_pixbuf);
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
static gint
|
|
|
|
get_scale_factor (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
|
|
|
|
if (self->priv->window)
|
|
|
|
return gdk_window_get_scale_factor (self->priv->window);
|
|
|
|
|
|
|
|
screen = gtk_style_context_get_screen (context);
|
|
|
|
|
|
|
|
/* else fall back to something that is more likely to be right than
|
|
|
|
* just returning 1:
|
|
|
|
*/
|
|
|
|
return gdk_screen_get_monitor_scale_factor (screen, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_invalidate_surface (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
GtkStateFlags state;
|
|
|
|
int scale;
|
|
|
|
|
|
|
|
state = gtk_style_context_get_state (context);
|
|
|
|
scale = get_scale_factor (self, context);
|
|
|
|
|
|
|
|
if ((self->priv->rendered_surface != NULL) &&
|
|
|
|
(self->priv->last_surface_state == state) &&
|
|
|
|
(self->priv->last_surface_scale == scale))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
self->priv->last_surface_state = state;
|
|
|
|
self->priv->last_surface_scale = scale;
|
|
|
|
|
|
|
|
if (self->priv->rendered_surface)
|
|
|
|
cairo_surface_destroy (self->priv->rendered_surface);
|
|
|
|
self->priv->rendered_surface = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_surface_from_surface (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
if (!check_invalidate_surface (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->priv->rendered_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->priv->rendered_surface =
|
|
|
|
cairo_surface_reference (self->priv->orig_surface);
|
|
|
|
|
|
|
|
get_surface_size (self, context, self->priv->orig_surface,
|
|
|
|
&self->priv->rendered_surface_width,
|
|
|
|
&self->priv->rendered_surface_height);
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
static gboolean
|
|
|
|
get_pixbuf_size (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
gint *width_out,
|
|
|
|
gint *height_out,
|
|
|
|
gint *scale_out)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
gboolean scale_pixmap;
|
2013-06-24 12:13:43 +00:00
|
|
|
gint width, height;
|
|
|
|
int scale;
|
|
|
|
|
|
|
|
scale = get_scale_factor (self, context);
|
2014-08-12 10:34:12 +00:00
|
|
|
scale_pixmap = FALSE;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
if (self->priv->force_scale_pixbuf &&
|
|
|
|
(self->priv->pixel_size != -1 ||
|
|
|
|
self->priv->icon_size != GTK_ICON_SIZE_INVALID))
|
|
|
|
{
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
|
|
|
|
if (scale != self->priv->orig_pixbuf_scale ||
|
|
|
|
width < gdk_pixbuf_get_width (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale ||
|
|
|
|
height < gdk_pixbuf_get_height (self->priv->orig_pixbuf) / self->priv->orig_pixbuf_scale)
|
|
|
|
{
|
|
|
|
width = MIN (width * scale, gdk_pixbuf_get_width (self->priv->orig_pixbuf) * scale / self->priv->orig_pixbuf_scale);
|
|
|
|
height = MIN (height * scale, gdk_pixbuf_get_height (self->priv->orig_pixbuf) * scale / self->priv->orig_pixbuf_scale);
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
scale_pixmap = TRUE;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
width = gdk_pixbuf_get_width (self->priv->orig_pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (self->priv->orig_pixbuf);
|
2013-06-24 12:13:43 +00:00
|
|
|
scale = self->priv->orig_pixbuf_scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
width = gdk_pixbuf_get_width (self->priv->orig_pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (self->priv->orig_pixbuf);
|
2013-06-24 12:13:43 +00:00
|
|
|
scale = self->priv->orig_pixbuf_scale;
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
*width_out = width;
|
|
|
|
*height_out = height;
|
|
|
|
*scale_out = scale;
|
|
|
|
|
|
|
|
return scale_pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_surface_from_pixbuf (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
gint width, height;
|
|
|
|
GdkPixbuf *pixbuf, *stated;
|
|
|
|
int scale;
|
|
|
|
|
|
|
|
if (!check_invalidate_surface (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->priv->rendered_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (get_pixbuf_size (self, context, &width, &height, &scale))
|
|
|
|
pixbuf = gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
|
|
|
|
width, height,
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
else
|
|
|
|
pixbuf = g_object_ref (self->priv->orig_pixbuf);
|
|
|
|
|
2013-08-04 14:50:31 +00:00
|
|
|
stated = ensure_stated_pixbuf_from_pixbuf (self, context, pixbuf);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
pixbuf = stated;
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
self->priv->rendered_surface_width = (width + scale - 1) / scale;
|
|
|
|
self->priv->rendered_surface_height = (height + scale - 1) / scale;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
self->priv->rendered_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, self->priv->window);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_surface_for_icon_set (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GtkIconSet *icon_set)
|
|
|
|
{
|
|
|
|
gint scale;
|
|
|
|
|
|
|
|
if (!check_invalidate_surface (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
scale = get_scale_factor (self, context);
|
|
|
|
|
2013-07-05 13:42:31 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2013-06-24 12:13:43 +00:00
|
|
|
self->priv->rendered_surface =
|
|
|
|
gtk_icon_set_render_icon_surface (icon_set, context,
|
|
|
|
self->priv->icon_size,
|
|
|
|
scale, self->priv->window);
|
2013-07-05 13:42:31 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
if (self->priv->rendered_surface)
|
|
|
|
get_surface_size (self, context, self->priv->rendered_surface,
|
|
|
|
&self->priv->rendered_surface_width,
|
|
|
|
&self->priv->rendered_surface_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_stated_surface_from_info (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GtkIconInfo *info,
|
|
|
|
int scale)
|
|
|
|
{
|
|
|
|
GdkPixbuf *destination = NULL;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
gboolean symbolic;
|
|
|
|
|
|
|
|
symbolic = FALSE;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
destination =
|
|
|
|
gtk_icon_info_load_symbolic_for_context (info,
|
|
|
|
context,
|
|
|
|
&symbolic,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (destination == NULL)
|
|
|
|
{
|
|
|
|
GtkIconSet *icon_set;
|
2013-07-03 23:52:11 +00:00
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
icon_set = gtk_style_context_lookup_icon_set (context, GTK_STOCK_MISSING_IMAGE);
|
|
|
|
|
|
|
|
destination =
|
|
|
|
gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);
|
2013-07-03 23:52:11 +00:00
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
else if (!symbolic)
|
|
|
|
{
|
|
|
|
GdkPixbuf *rendered;
|
|
|
|
|
2013-08-04 14:56:37 +00:00
|
|
|
rendered = ensure_stated_pixbuf_from_pixbuf (self, context, destination);
|
2013-06-24 12:13:43 +00:00
|
|
|
g_object_unref (destination);
|
|
|
|
destination = rendered;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = NULL;
|
|
|
|
if (destination)
|
|
|
|
{
|
|
|
|
surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, self->priv->window);
|
|
|
|
|
|
|
|
self->priv->rendered_surface_width =
|
|
|
|
(gdk_pixbuf_get_width (destination) + scale - 1) / scale;
|
|
|
|
self->priv->rendered_surface_height =
|
|
|
|
(gdk_pixbuf_get_height (destination) + scale - 1) / scale;
|
2013-10-02 13:33:20 +00:00
|
|
|
g_object_unref (destination);
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self->priv->rendered_surface = surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-08 16:42:35 +00:00
|
|
|
ensure_surface_for_gicon (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
gint width, height, scale;
|
|
|
|
GtkIconInfo *info;
|
|
|
|
GtkIconLookupFlags flags;
|
|
|
|
|
|
|
|
if (!check_invalidate_surface (self, context))
|
|
|
|
return;
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_get_default ();
|
2014-05-10 19:50:37 +00:00
|
|
|
flags = get_icon_lookup_flags (self, context);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
scale = get_scale_factor (self, context);
|
|
|
|
|
2014-05-08 16:42:35 +00:00
|
|
|
if (self->priv->gicon != NULL)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
|
|
|
info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
|
|
|
|
self->priv->gicon,
|
|
|
|
MIN (width, height),
|
|
|
|
scale, flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_stated_surface_from_info (self, context, info, scale);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface = NULL;
|
|
|
|
GtkIconSet *icon_set;
|
|
|
|
|
|
|
|
switch (self->priv->storage_type)
|
|
|
|
{
|
|
|
|
case GTK_IMAGE_SURFACE:
|
|
|
|
ensure_surface_from_surface (self, context);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
|
|
|
ensure_surface_from_pixbuf (self, context);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_STOCK:
|
2013-07-05 13:17:24 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2013-06-24 12:13:43 +00:00
|
|
|
icon_set = gtk_style_context_lookup_icon_set (context, self->priv->stock_id);
|
|
|
|
if (icon_set != NULL)
|
|
|
|
ensure_surface_for_icon_set (self, context, icon_set);
|
|
|
|
else
|
|
|
|
surface = NULL;
|
2013-07-05 13:17:24 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2013-06-24 12:13:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_SET:
|
|
|
|
icon_set = self->priv->icon_set;
|
|
|
|
ensure_surface_for_icon_set (self, context, icon_set);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
case GTK_IMAGE_GICON:
|
2014-05-08 16:42:35 +00:00
|
|
|
ensure_surface_for_gicon (self, context);
|
2013-06-24 12:13:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
case GTK_IMAGE_EMPTY:
|
|
|
|
default:
|
|
|
|
surface = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface == NULL &&
|
|
|
|
self->priv->rendered_surface != NULL)
|
|
|
|
surface = cairo_surface_reference (self->priv->rendered_surface);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_get_size (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
gint *width_out,
|
|
|
|
gint *height_out)
|
|
|
|
{
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *surface;
|
2014-08-12 10:34:12 +00:00
|
|
|
gint width, height, scale;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
width = height = 0;
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
/* Certain kinds of images are easy to calculate the size for, these
|
|
|
|
we do immediately to avoid having to potentially load the image
|
|
|
|
data for something that may not yet be visible */
|
|
|
|
switch (self->priv->storage_type)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
case GTK_IMAGE_SURFACE:
|
|
|
|
get_surface_size (self, context, self->priv->orig_surface,
|
|
|
|
&width,
|
|
|
|
&height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
|
|
|
get_pixbuf_size (self, context, &width, &height, &scale);
|
|
|
|
width = (width + scale - 1) / scale;
|
|
|
|
height = (height + scale - 1) / scale;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
case GTK_IMAGE_GICON:
|
|
|
|
if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_STOCK:
|
|
|
|
case GTK_IMAGE_ICON_SET:
|
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
case GTK_IMAGE_EMPTY:
|
|
|
|
default:
|
|
|
|
break;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
2014-08-12 10:34:12 +00:00
|
|
|
|
|
|
|
/* Otherwise we load the surface to guarantee we get a size */
|
|
|
|
if (width == 0)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
surface = _gtk_icon_helper_ensure_surface (self, context);
|
|
|
|
|
|
|
|
if (surface != NULL)
|
|
|
|
{
|
|
|
|
width = self->priv->rendered_surface_width;
|
|
|
|
height = self->priv->rendered_surface_height;
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
else if (self->priv->storage_type == GTK_IMAGE_ANIMATION)
|
|
|
|
{
|
|
|
|
width = gdk_pixbuf_animation_get_width (self->priv->animation);
|
|
|
|
height = gdk_pixbuf_animation_get_height (self->priv->animation);
|
|
|
|
}
|
|
|
|
else if (self->priv->icon_size != -1)
|
|
|
|
{
|
|
|
|
ensure_icon_size (self, context, &width, &height);
|
|
|
|
}
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width_out)
|
|
|
|
*width_out = width;
|
|
|
|
if (height_out)
|
|
|
|
*height_out = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_gicon (GtkIconHelper *self,
|
|
|
|
GIcon *gicon,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (gicon != NULL)
|
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_GICON;
|
|
|
|
self->priv->gicon = g_object_ref (gicon);
|
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_icon_name (GtkIconHelper *self,
|
|
|
|
const gchar *icon_name,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
2011-12-15 19:01:35 +00:00
|
|
|
if (icon_name != NULL &&
|
2013-01-17 13:43:35 +00:00
|
|
|
icon_name[0] != '\0')
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_ICON_NAME;
|
2014-05-08 16:42:35 +00:00
|
|
|
self->priv->gicon = g_themed_icon_new (icon_name);
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_icon_set (GtkIconHelper *self,
|
|
|
|
GtkIconSet *icon_set,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (icon_set != NULL)
|
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_ICON_SET;
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
self->priv->icon_set = gtk_icon_set_ref (icon_set);
|
2013-06-26 22:41:15 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_pixbuf (GtkIconHelper *self,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (pixbuf != NULL)
|
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_PIXBUF;
|
|
|
|
self->priv->orig_pixbuf = g_object_ref (pixbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_animation (GtkIconHelper *self,
|
|
|
|
GdkPixbufAnimation *animation)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (animation != NULL)
|
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_ANIMATION;
|
|
|
|
self->priv->animation = g_object_ref (animation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_surface (GtkIconHelper *self,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (surface != NULL)
|
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_SURFACE;
|
|
|
|
self->priv->orig_surface = cairo_surface_reference (surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_stock_id (GtkIconHelper *self,
|
|
|
|
const gchar *stock_id,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
2012-10-26 14:32:14 +00:00
|
|
|
if (stock_id != NULL &&
|
2013-01-17 13:43:35 +00:00
|
|
|
stock_id[0] != '\0')
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
self->priv->storage_type = GTK_IMAGE_STOCK;
|
|
|
|
self->priv->stock_id = g_strdup (stock_id);
|
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-09 12:58:05 +00:00
|
|
|
gboolean
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_icon_size (GtkIconHelper *self,
|
2014-06-09 12:58:05 +00:00
|
|
|
GtkIconSize icon_size)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
if (self->priv->icon_size != icon_size)
|
|
|
|
{
|
|
|
|
self->priv->icon_size = icon_size;
|
|
|
|
_gtk_icon_helper_invalidate (self);
|
2014-06-09 12:58:05 +00:00
|
|
|
return TRUE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
2014-06-09 12:58:05 +00:00
|
|
|
return FALSE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 12:58:05 +00:00
|
|
|
gboolean
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
|
2014-06-09 12:58:05 +00:00
|
|
|
gint pixel_size)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
if (self->priv->pixel_size != pixel_size)
|
|
|
|
{
|
|
|
|
self->priv->pixel_size = pixel_size;
|
|
|
|
_gtk_icon_helper_invalidate (self);
|
2014-06-09 12:58:05 +00:00
|
|
|
return TRUE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
2014-06-09 12:58:05 +00:00
|
|
|
return FALSE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 12:58:05 +00:00
|
|
|
gboolean
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_use_fallback (GtkIconHelper *self,
|
2014-06-09 12:58:05 +00:00
|
|
|
gboolean use_fallback)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
|
|
|
if (self->priv->use_fallback != use_fallback)
|
|
|
|
{
|
|
|
|
self->priv->use_fallback = use_fallback;
|
|
|
|
_gtk_icon_helper_invalidate (self);
|
2014-06-09 12:58:05 +00:00
|
|
|
return TRUE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
2014-06-09 12:58:05 +00:00
|
|
|
return FALSE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkImageType
|
|
|
|
_gtk_icon_helper_get_storage_type (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->storage_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_icon_helper_get_use_fallback (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->use_fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkIconSize
|
|
|
|
_gtk_icon_helper_get_icon_size (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->icon_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
_gtk_icon_helper_get_pixel_size (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->pixel_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixbuf *
|
|
|
|
_gtk_icon_helper_peek_pixbuf (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->orig_pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIcon *
|
|
|
|
_gtk_icon_helper_peek_gicon (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->gicon;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixbufAnimation *
|
|
|
|
_gtk_icon_helper_peek_animation (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->animation;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkIconSet *
|
|
|
|
_gtk_icon_helper_peek_icon_set (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->icon_set;
|
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
_gtk_icon_helper_peek_surface (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->orig_surface;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
const gchar *
|
|
|
|
_gtk_icon_helper_get_stock_id (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->stock_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
_gtk_icon_helper_get_icon_name (GtkIconHelper *self)
|
|
|
|
{
|
2014-05-08 16:42:35 +00:00
|
|
|
if (self->priv->storage_type != GTK_IMAGE_ICON_NAME)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_themed_icon_get_names (G_THEMED_ICON (self->priv->gicon))[0];
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkIconHelper *
|
|
|
|
_gtk_icon_helper_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_ICON_HELPER, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_draw (GtkIconHelper *self,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
cairo_t *cr,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *surface;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
surface = _gtk_icon_helper_ensure_surface (self, context);
|
|
|
|
if (surface != NULL)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2013-06-24 12:13:43 +00:00
|
|
|
gtk_render_icon_surface (context, cr, surface, x, y);
|
|
|
|
cairo_surface_destroy (surface);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_icon_helper_get_is_empty (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return (self->priv->storage_type == GTK_IMAGE_EMPTY);
|
|
|
|
}
|
2012-07-13 13:54:29 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_icon_helper_get_force_scale_pixbuf (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->force_scale_pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_force_scale_pixbuf (GtkIconHelper *self,
|
|
|
|
gboolean force_scale)
|
|
|
|
{
|
|
|
|
if (self->priv->force_scale_pixbuf != force_scale)
|
|
|
|
{
|
|
|
|
self->priv->force_scale_pixbuf = force_scale;
|
|
|
|
_gtk_icon_helper_invalidate (self);
|
|
|
|
}
|
|
|
|
}
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
|
|
|
|
int scale)
|
|
|
|
{
|
|
|
|
if (self->priv->orig_pixbuf_scale != scale)
|
|
|
|
{
|
|
|
|
self->priv->orig_pixbuf_scale = scale;
|
|
|
|
_gtk_icon_helper_invalidate (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_gtk_icon_helper_get_pixbuf_scale (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->orig_pixbuf_scale;
|
|
|
|
}
|