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
|
|
|
|
2015-03-11 20:24:05 +00:00
|
|
|
#include "gtkcssenumvalueprivate.h"
|
2015-12-02 02:18:26 +00:00
|
|
|
#include "gtkcssiconthemevalueprivate.h"
|
2015-12-09 17:32:05 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
|
|
|
#include "gtkcssstyleprivate.h"
|
2015-12-11 14:12:19 +00:00
|
|
|
#include "gtkcssstylepropertyprivate.h"
|
2015-12-14 04:29:35 +00:00
|
|
|
#include "gtkcsstransientnodeprivate.h"
|
2015-12-07 03:44:39 +00:00
|
|
|
#include "gtkiconthemeprivate.h"
|
2015-12-09 17:32:05 +00:00
|
|
|
#include "gtkrendericonprivate.h"
|
2016-11-19 18:58:23 +00:00
|
|
|
#include "gtksnapshot.h"
|
2017-01-10 23:37:12 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
struct _GtkIconHelperPrivate {
|
2015-11-24 18:55:09 +00:00
|
|
|
GtkImageDefinition *def;
|
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;
|
2016-02-06 08:23:11 +00:00
|
|
|
guint rendered_surface_is_symbolic : 1;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
GtkWidget *owner;
|
|
|
|
GtkCssNode *node;
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *rendered_surface;
|
2016-11-07 17:25:12 +00:00
|
|
|
GskTexture *texture;
|
2011-11-30 03:26:19 +00:00
|
|
|
};
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkIconHelper, gtk_icon_helper, G_TYPE_OBJECT)
|
2013-06-27 19:02:52 +00:00
|
|
|
|
2016-11-15 05:36:34 +00:00
|
|
|
void
|
2015-12-11 14:12:19 +00:00
|
|
|
gtk_icon_helper_invalidate (GtkIconHelper *self)
|
|
|
|
{
|
2017-01-01 12:40:13 +00:00
|
|
|
g_clear_object (&self->priv->texture);
|
2016-11-07 17:25:12 +00:00
|
|
|
|
2015-12-11 14:12:19 +00:00
|
|
|
if (self->priv->rendered_surface != NULL)
|
|
|
|
{
|
|
|
|
cairo_surface_destroy (self->priv->rendered_surface);
|
|
|
|
self->priv->rendered_surface = NULL;
|
2016-02-06 08:23:11 +00:00
|
|
|
self->priv->rendered_surface_is_symbolic = FALSE;
|
2015-12-11 14:12:19 +00:00
|
|
|
}
|
2015-12-14 04:29:35 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
if (!GTK_IS_CSS_TRANSIENT_NODE (self->priv->node))
|
|
|
|
gtk_widget_queue_resize (self->priv->owner);
|
2015-12-11 14:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 08:24:36 +00:00
|
|
|
void
|
|
|
|
gtk_icon_helper_invalidate_for_change (GtkIconHelper *self,
|
|
|
|
GtkCssStyleChange *change)
|
|
|
|
{
|
|
|
|
GtkIconHelperPrivate *priv = self->priv;
|
|
|
|
|
2016-03-04 13:50:52 +00:00
|
|
|
if (change == NULL ||
|
2016-02-06 08:24:36 +00:00
|
|
|
((gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SYMBOLIC_ICON) &&
|
|
|
|
priv->rendered_surface_is_symbolic) ||
|
2016-03-04 13:50:52 +00:00
|
|
|
(gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON) &&
|
|
|
|
!priv->rendered_surface_is_symbolic)))
|
2016-02-06 08:24:36 +00:00
|
|
|
{
|
|
|
|
gtk_icon_helper_invalidate (self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
static void
|
|
|
|
gtk_icon_helper_take_definition (GtkIconHelper *self,
|
|
|
|
GtkImageDefinition *def)
|
|
|
|
{
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
|
|
|
|
if (def == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_image_definition_unref (self->priv->def);
|
|
|
|
self->priv->def = def;
|
|
|
|
|
2015-12-11 14:12:19 +00:00
|
|
|
gtk_icon_helper_invalidate (self);
|
2015-11-24 18:55:09 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_clear (GtkIconHelper *self)
|
|
|
|
{
|
2017-01-01 12:40:13 +00:00
|
|
|
g_clear_object (&self->priv->texture);
|
2013-10-02 13:06:36 +00:00
|
|
|
g_clear_pointer (&self->priv->rendered_surface, cairo_surface_destroy);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_image_definition_unref (self->priv->def);
|
|
|
|
self->priv->def = gtk_image_definition_new_empty ();
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
self->priv->icon_size = GTK_ICON_SIZE_INVALID;
|
2016-04-14 19:03:27 +00:00
|
|
|
|
|
|
|
gtk_icon_helper_invalidate (self);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_helper_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkIconHelper *self = GTK_ICON_HELPER (object);
|
2015-12-11 14:12:19 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
widget = self->priv->owner;
|
2015-12-11 14:12:19 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (gtk_icon_helper_invalidate), self);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
|
|
|
_gtk_icon_helper_clear (self);
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_image_definition_unref (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
2015-12-09 13:01:46 +00:00
|
|
|
G_OBJECT_CLASS (gtk_icon_helper_parent_class)->finalize (object);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-09 13:01:46 +00:00
|
|
|
gtk_icon_helper_class_init (GtkIconHelperClass *klass)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2015-12-11 14:12:19 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
2015-12-11 14:12:19 +00:00
|
|
|
object_class->finalize = gtk_icon_helper_finalize;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-09 13:01:46 +00:00
|
|
|
gtk_icon_helper_init (GtkIconHelper *self)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2015-12-09 13:01:46 +00:00
|
|
|
self->priv = gtk_icon_helper_get_instance_private (self);
|
2011-11-30 03:26:19 +00:00
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
self->priv->def = gtk_image_definition_new_empty ();
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
self->priv->icon_size = GTK_ICON_SIZE_INVALID;
|
|
|
|
self->priv->pixel_size = -1;
|
2016-02-06 08:23:11 +00:00
|
|
|
self->priv->rendered_surface_is_symbolic = FALSE;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_icon_size (GtkIconHelper *self,
|
|
|
|
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
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Invalid icon size %d", self->priv->icon_size);
|
2011-11-30 23:32:01 +00:00
|
|
|
width = height = 24;
|
|
|
|
}
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*width_out = width;
|
|
|
|
*height_out = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkIconLookupFlags
|
2015-12-07 03:44:39 +00:00
|
|
|
get_icon_lookup_flags (GtkIconHelper *self,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkTextDirection dir)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2015-03-11 20:24:05 +00:00
|
|
|
GtkIconLookupFlags flags;
|
|
|
|
GtkCssIconStyle icon_style;
|
|
|
|
|
|
|
|
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
|
2011-11-30 03:26:19 +00:00
|
|
|
|
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;
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
icon_style = _gtk_css_icon_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_STYLE));
|
2015-03-11 20:24:05 +00:00
|
|
|
|
|
|
|
switch (icon_style)
|
|
|
|
{
|
|
|
|
case GTK_CSS_ICON_STYLE_REGULAR:
|
|
|
|
flags |= GTK_ICON_LOOKUP_FORCE_REGULAR;
|
|
|
|
break;
|
|
|
|
case GTK_CSS_ICON_STYLE_SYMBOLIC:
|
|
|
|
flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC;
|
|
|
|
break;
|
|
|
|
case GTK_CSS_ICON_STYLE_REQUESTED:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
if (dir == GTK_TEXT_DIR_LTR)
|
2015-03-11 20:24:05 +00:00
|
|
|
flags |= GTK_ICON_LOOKUP_DIR_LTR;
|
2015-12-07 03:44:39 +00:00
|
|
|
else if (dir == GTK_TEXT_DIR_RTL)
|
2015-03-11 20:24:05 +00:00
|
|
|
flags |= GTK_ICON_LOOKUP_DIR_RTL;
|
2014-05-10 19:50:37 +00:00
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
static void
|
|
|
|
get_surface_size (GtkIconHelper *self,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
2015-11-28 06:06:37 +00:00
|
|
|
GdkRectangle clip;
|
|
|
|
cairo_t *cr;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-11-28 06:06:37 +00:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
if (gdk_cairo_get_clip_rectangle (cr, &clip))
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2015-11-28 06:06:37 +00:00
|
|
|
if (clip.x != 0 || clip.y != 0)
|
|
|
|
{
|
|
|
|
g_warning ("origin of surface is %d %d, not supported", clip.x, clip.y);
|
|
|
|
}
|
|
|
|
*width = clip.width;
|
|
|
|
*height = clip.height;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-28 06:06:37 +00:00
|
|
|
{
|
|
|
|
g_warning ("infinite surface size not supported");
|
|
|
|
ensure_icon_size (self, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 23:45:58 +00:00
|
|
|
static cairo_surface_t *
|
2013-06-24 12:13:43 +00:00
|
|
|
ensure_surface_from_surface (GtkIconHelper *self,
|
2015-11-24 18:55:09 +00:00
|
|
|
cairo_surface_t *orig_surface)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2015-11-29 23:45:58 +00:00
|
|
|
return cairo_surface_reference (orig_surface);
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
static gboolean
|
|
|
|
get_pixbuf_size (GtkIconHelper *self,
|
2015-11-30 00:33:14 +00:00
|
|
|
gint scale,
|
2015-11-24 18:55:09 +00:00
|
|
|
GdkPixbuf *orig_pixbuf,
|
|
|
|
gint orig_scale,
|
2014-08-12 10:34:12 +00:00
|
|
|
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;
|
|
|
|
|
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))
|
|
|
|
{
|
2015-11-22 18:42:33 +00:00
|
|
|
ensure_icon_size (self, &width, &height);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
if (scale != orig_scale ||
|
|
|
|
width < gdk_pixbuf_get_width (orig_pixbuf) / orig_scale ||
|
|
|
|
height < gdk_pixbuf_get_height (orig_pixbuf) / orig_scale)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
width = MIN (width * scale, gdk_pixbuf_get_width (orig_pixbuf) * scale / orig_scale);
|
|
|
|
height = MIN (height * scale, gdk_pixbuf_get_height (orig_pixbuf) * scale / orig_scale);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
scale_pixmap = TRUE;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
width = gdk_pixbuf_get_width (orig_pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (orig_pixbuf);
|
|
|
|
scale = orig_scale;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
width = gdk_pixbuf_get_width (orig_pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (orig_pixbuf);
|
|
|
|
scale = orig_scale;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
*width_out = width;
|
|
|
|
*height_out = height;
|
|
|
|
*scale_out = scale;
|
|
|
|
|
|
|
|
return scale_pixmap;
|
|
|
|
}
|
|
|
|
|
2015-11-29 23:45:58 +00:00
|
|
|
static cairo_surface_t *
|
2015-12-07 18:49:51 +00:00
|
|
|
ensure_surface_from_pixbuf (GtkIconHelper *self,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
gint scale,
|
|
|
|
GdkPixbuf *orig_pixbuf,
|
|
|
|
gint orig_scale)
|
2014-08-12 10:34:12 +00:00
|
|
|
{
|
|
|
|
gint width, height;
|
2015-11-29 23:45:58 +00:00
|
|
|
cairo_surface_t *surface;
|
2015-12-04 15:18:23 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
2014-08-12 10:34:12 +00:00
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
if (get_pixbuf_size (self,
|
2015-11-30 00:33:14 +00:00
|
|
|
scale,
|
2015-11-24 18:55:09 +00:00
|
|
|
orig_pixbuf,
|
|
|
|
orig_scale,
|
|
|
|
&width, &height, &scale))
|
|
|
|
pixbuf = gdk_pixbuf_scale_simple (orig_pixbuf,
|
2014-08-12 10:34:12 +00:00
|
|
|
width, height,
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
else
|
2015-11-24 18:55:09 +00:00
|
|
|
pixbuf = g_object_ref (orig_pixbuf);
|
2014-08-12 10:34:12 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, _gtk_widget_get_window (self->priv->owner));
|
2013-06-24 12:13:43 +00:00
|
|
|
g_object_unref (pixbuf);
|
2015-11-29 23:45:58 +00:00
|
|
|
|
|
|
|
return surface;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 23:45:58 +00:00
|
|
|
static cairo_surface_t *
|
2015-12-07 03:44:39 +00:00
|
|
|
ensure_surface_for_gicon (GtkIconHelper *self,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkTextDirection dir,
|
|
|
|
gint scale,
|
|
|
|
GIcon *gicon)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2016-02-06 08:23:11 +00:00
|
|
|
GtkIconHelperPrivate *priv = self->priv;
|
2015-12-04 15:06:08 +00:00
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
gint width, height;
|
|
|
|
GtkIconInfo *info;
|
|
|
|
GtkIconLookupFlags flags;
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *surface;
|
2015-12-04 15:06:08 +00:00
|
|
|
GdkPixbuf *destination;
|
2013-06-24 12:13:43 +00:00
|
|
|
gboolean symbolic;
|
|
|
|
|
2015-12-04 15:06:08 +00:00
|
|
|
icon_theme = gtk_css_icon_theme_value_get_icon_theme
|
2015-12-07 03:44:39 +00:00
|
|
|
(gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME));
|
|
|
|
flags = get_icon_lookup_flags (self, style, dir);
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-12-04 15:06:08 +00:00
|
|
|
ensure_icon_size (self, &width, &height);
|
|
|
|
|
|
|
|
info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
|
|
|
|
gicon,
|
|
|
|
MIN (width, height),
|
|
|
|
scale, flags);
|
2013-06-24 12:13:43 +00:00
|
|
|
if (info)
|
2015-12-04 15:13:22 +00:00
|
|
|
{
|
2015-12-07 03:44:39 +00:00
|
|
|
symbolic = gtk_icon_info_is_symbolic (info);
|
|
|
|
|
|
|
|
if (symbolic)
|
|
|
|
{
|
|
|
|
GdkRGBA fg, success_color, warning_color, error_color;
|
|
|
|
|
|
|
|
gtk_icon_theme_lookup_symbolic_colors (style, &fg, &success_color, &warning_color, &error_color);
|
|
|
|
|
|
|
|
destination = gtk_icon_info_load_symbolic (info,
|
|
|
|
&fg, &success_color,
|
|
|
|
&warning_color, &error_color,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
destination = gtk_icon_info_load_icon (info, NULL);
|
|
|
|
}
|
|
|
|
|
2015-12-04 15:13:22 +00:00
|
|
|
g_object_unref (info);
|
|
|
|
}
|
2015-12-04 15:06:08 +00:00
|
|
|
else
|
2015-12-04 15:13:22 +00:00
|
|
|
{
|
|
|
|
destination = NULL;
|
|
|
|
}
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
if (destination == NULL)
|
|
|
|
{
|
2017-06-07 23:29:09 +00:00
|
|
|
GError *error = NULL;
|
2015-12-04 15:13:22 +00:00
|
|
|
destination = gtk_icon_theme_load_icon (icon_theme,
|
|
|
|
"image-missing",
|
|
|
|
width,
|
|
|
|
flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK,
|
2017-06-07 23:29:09 +00:00
|
|
|
&error);
|
2015-12-04 15:13:22 +00:00
|
|
|
/* We include this image as resource, so we always have it available or
|
|
|
|
* the icontheme code is broken */
|
2017-06-07 23:29:09 +00:00
|
|
|
g_assert_no_error (error);
|
2015-12-04 15:13:22 +00:00
|
|
|
g_assert (destination);
|
|
|
|
symbolic = FALSE;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
2015-12-04 15:13:22 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, _gtk_widget_get_window (priv->owner));
|
2016-02-06 08:27:00 +00:00
|
|
|
|
2016-12-31 01:36:00 +00:00
|
|
|
if (symbolic)
|
2016-02-06 08:23:11 +00:00
|
|
|
{
|
|
|
|
priv->rendered_surface_is_symbolic = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-12-04 15:13:22 +00:00
|
|
|
g_object_unref (destination);
|
2015-11-29 23:45:58 +00:00
|
|
|
|
|
|
|
return surface;
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:16:10 +00:00
|
|
|
static cairo_surface_t *
|
2015-11-29 23:55:43 +00:00
|
|
|
gtk_icon_helper_load_surface (GtkIconHelper *self,
|
2015-11-30 00:33:14 +00:00
|
|
|
int scale)
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
2017-06-17 06:39:43 +00:00
|
|
|
GtkIconHelperPrivate *priv = gtk_icon_helper_get_instance_private (self);
|
2015-11-29 23:45:58 +00:00
|
|
|
cairo_surface_t *surface;
|
2015-11-24 18:55:09 +00:00
|
|
|
GIcon *gicon;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-11-24 18:55:09 +00:00
|
|
|
switch (gtk_image_definition_get_storage_type (self->priv->def))
|
2013-06-24 12:13:43 +00:00
|
|
|
{
|
|
|
|
case GTK_IMAGE_SURFACE:
|
2015-12-07 18:47:49 +00:00
|
|
|
surface = ensure_surface_from_surface (self, gtk_image_definition_get_surface (self->priv->def));
|
2013-06-24 12:13:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
2015-12-07 18:49:51 +00:00
|
|
|
surface = ensure_surface_from_pixbuf (self,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_css_node_get_style (priv->node),
|
2015-12-07 18:49:51 +00:00
|
|
|
scale,
|
2015-11-29 23:45:58 +00:00
|
|
|
gtk_image_definition_get_pixbuf (self->priv->def),
|
|
|
|
gtk_image_definition_get_scale (self->priv->def));
|
2013-06-24 12:13:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
2015-11-24 18:55:09 +00:00
|
|
|
if (self->priv->use_fallback)
|
|
|
|
gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->priv->def));
|
|
|
|
else
|
|
|
|
gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->priv->def));
|
2015-12-07 03:44:39 +00:00
|
|
|
surface = ensure_surface_for_gicon (self,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_css_node_get_style (priv->node),
|
|
|
|
gtk_widget_get_direction (priv->owner),
|
2015-12-07 03:44:39 +00:00
|
|
|
scale,
|
|
|
|
gicon);
|
2015-11-24 18:55:09 +00:00
|
|
|
g_object_unref (gicon);
|
|
|
|
break;
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
case GTK_IMAGE_GICON:
|
2015-12-07 03:44:39 +00:00
|
|
|
surface = ensure_surface_for_gicon (self,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_css_node_get_style (priv->node),
|
|
|
|
gtk_widget_get_direction (priv->owner),
|
2015-12-07 03:44:39 +00:00
|
|
|
scale,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_image_definition_get_gicon (priv->def));
|
2013-06-24 12:13:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
case GTK_IMAGE_EMPTY:
|
|
|
|
default:
|
|
|
|
surface = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-29 23:55:43 +00:00
|
|
|
return surface;
|
2013-06-24 12:13:43 +00:00
|
|
|
|
2015-11-29 23:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-09 17:32:05 +00:00
|
|
|
gtk_icon_helper_ensure_surface (GtkIconHelper *self)
|
2015-11-29 23:55:43 +00:00
|
|
|
{
|
2015-11-30 00:33:14 +00:00
|
|
|
int scale;
|
|
|
|
|
2015-12-27 02:02:19 +00:00
|
|
|
if (self->priv->rendered_surface)
|
|
|
|
return;
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
scale = gtk_widget_get_scale_factor (self->priv->owner);
|
2015-11-30 00:33:14 +00:00
|
|
|
|
2015-12-08 19:57:24 +00:00
|
|
|
self->priv->rendered_surface = gtk_icon_helper_load_surface (self, scale);
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 17:25:12 +00:00
|
|
|
static void
|
2016-12-13 04:08:40 +00:00
|
|
|
gtk_icon_helper_ensure_texture (GtkIconHelper *self)
|
2016-11-07 17:25:12 +00:00
|
|
|
{
|
|
|
|
cairo_surface_t *map;
|
|
|
|
int width, height, scale;
|
|
|
|
|
|
|
|
if (self->priv->texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_icon_helper_ensure_surface (self);
|
|
|
|
if (self->priv->rendered_surface == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
scale = gtk_widget_get_scale_factor (self->priv->owner);
|
2016-11-07 17:25:12 +00:00
|
|
|
_gtk_icon_helper_get_size (self, &width, &height);
|
2016-12-02 16:32:12 +00:00
|
|
|
|
|
|
|
if (cairo_image_surface_get_format (self->priv->rendered_surface) != CAIRO_FORMAT_ARGB32)
|
|
|
|
{
|
|
|
|
cairo_surface_t *argb_surface = cairo_surface_create_similar_image (self->priv->rendered_surface,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height);
|
|
|
|
cairo_t *ct;
|
|
|
|
cairo_surface_set_device_scale (argb_surface, scale, scale);
|
|
|
|
|
|
|
|
ct = cairo_create (argb_surface);
|
|
|
|
cairo_set_source_surface (ct, self->priv->rendered_surface, 0, 0);
|
|
|
|
cairo_paint (ct);
|
|
|
|
cairo_destroy (ct);
|
|
|
|
cairo_surface_destroy (self->priv->rendered_surface);
|
|
|
|
self->priv->rendered_surface = argb_surface;
|
|
|
|
}
|
|
|
|
|
2016-11-07 17:25:12 +00:00
|
|
|
map = cairo_surface_map_to_image (self->priv->rendered_surface,
|
|
|
|
&(GdkRectangle) { 0, 0, width * scale, height * scale});
|
|
|
|
|
2016-11-16 03:14:32 +00:00
|
|
|
self->priv->texture = gsk_texture_new_for_data (cairo_image_surface_get_data (map),
|
2016-11-07 17:25:12 +00:00
|
|
|
width * scale,
|
|
|
|
height * scale,
|
|
|
|
cairo_image_surface_get_stride (map));
|
|
|
|
|
|
|
|
cairo_surface_unmap_image (self->priv->rendered_surface, map);
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_get_size (GtkIconHelper *self,
|
|
|
|
gint *width_out,
|
|
|
|
gint *height_out)
|
|
|
|
{
|
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 */
|
2015-11-24 18:55:09 +00:00
|
|
|
switch (gtk_image_definition_get_storage_type (self->priv->def))
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2014-08-12 10:34:12 +00:00
|
|
|
case GTK_IMAGE_SURFACE:
|
2015-11-24 18:55:09 +00:00
|
|
|
get_surface_size (self,
|
|
|
|
gtk_image_definition_get_surface (self->priv->def),
|
2014-08-12 10:34:12 +00:00
|
|
|
&width,
|
|
|
|
&height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
2015-12-07 18:47:49 +00:00
|
|
|
get_pixbuf_size (self,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_widget_get_scale_factor (self->priv->owner),
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_image_definition_get_pixbuf (self->priv->def),
|
|
|
|
gtk_image_definition_get_scale (self->priv->def),
|
|
|
|
&width, &height, &scale);
|
2014-08-12 10:34:12 +00:00
|
|
|
width = (width + scale - 1) / scale;
|
|
|
|
height = (height + scale - 1) / scale;
|
|
|
|
break;
|
|
|
|
|
2015-11-27 17:05:36 +00:00
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
{
|
|
|
|
GdkPixbufAnimation *animation = gtk_image_definition_get_animation (self->priv->def);
|
|
|
|
width = gdk_pixbuf_animation_get_width (animation);
|
|
|
|
height = gdk_pixbuf_animation_get_height (animation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-12 10:34:12 +00:00
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
case GTK_IMAGE_GICON:
|
|
|
|
if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
|
2015-11-22 18:42:33 +00:00
|
|
|
ensure_icon_size (self, &width, &height);
|
2014-08-12 10:34:12 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-12-09 17:32:05 +00:00
|
|
|
gtk_icon_helper_ensure_surface (self);
|
2014-08-12 10:34:12 +00:00
|
|
|
|
2015-11-29 23:55:43 +00:00
|
|
|
if (self->priv->rendered_surface != NULL)
|
2014-08-12 10:34:12 +00:00
|
|
|
{
|
2015-11-29 23:55:43 +00:00
|
|
|
get_surface_size (self, self->priv->rendered_surface, &width, &height);
|
2014-08-12 10:34:12 +00:00
|
|
|
}
|
2015-03-22 19:14:42 +00:00
|
|
|
else if (self->priv->icon_size != GTK_ICON_SIZE_INVALID)
|
2014-08-12 10:34:12 +00:00
|
|
|
{
|
2015-11-22 18:42:33 +00:00
|
|
|
ensure_icon_size (self, &width, &height);
|
2014-08-12 10:34:12 +00:00
|
|
|
}
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width_out)
|
|
|
|
*width_out = width;
|
|
|
|
if (height_out)
|
|
|
|
*height_out = height;
|
|
|
|
}
|
|
|
|
|
2015-11-25 14:59:44 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_definition (GtkIconHelper *self,
|
|
|
|
GtkImageDefinition *def)
|
|
|
|
{
|
|
|
|
if (def)
|
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_ref (def));
|
|
|
|
else
|
|
|
|
_gtk_icon_helper_clear (self);
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_gicon (GtkIconHelper *self,
|
|
|
|
GIcon *gicon,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
2015-12-01 03:44:29 +00:00
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_new_gicon (gicon));
|
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_icon_name (GtkIconHelper *self,
|
|
|
|
const gchar *icon_name,
|
|
|
|
GtkIconSize icon_size)
|
|
|
|
{
|
2015-12-01 03:44:29 +00:00
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_new_icon_name (icon_name));
|
|
|
|
_gtk_icon_helper_set_icon_size (self, icon_size);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 08:33:17 +00:00
|
|
|
void
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_pixbuf (GtkIconHelper *self,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_new_pixbuf (pixbuf, 1));
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 08:33:17 +00:00
|
|
|
void
|
2011-11-30 03:26:19 +00:00
|
|
|
_gtk_icon_helper_set_animation (GtkIconHelper *self,
|
|
|
|
GdkPixbufAnimation *animation)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_new_animation (animation, 1));
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 08:33:17 +00:00
|
|
|
void
|
2013-06-24 12:13:43 +00:00
|
|
|
_gtk_icon_helper_set_surface (GtkIconHelper *self,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
gtk_icon_helper_take_definition (self, gtk_image_definition_new_surface (surface));
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2015-12-11 14:12:19 +00:00
|
|
|
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;
|
2015-12-11 14:12:19 +00:00
|
|
|
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;
|
2015-12-11 14:12:19 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_storage_type (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-01 01:25:17 +00:00
|
|
|
GtkImageDefinition *
|
|
|
|
gtk_icon_helper_get_definition (GtkIconHelper *self)
|
|
|
|
{
|
|
|
|
return self->priv->def;
|
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
GdkPixbuf *
|
|
|
|
_gtk_icon_helper_peek_pixbuf (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_pixbuf (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GIcon *
|
|
|
|
_gtk_icon_helper_peek_gicon (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_gicon (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixbufAnimation *
|
|
|
|
_gtk_icon_helper_peek_animation (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_animation (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 12:13:43 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
_gtk_icon_helper_peek_surface (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_surface (self->priv->def);
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
const gchar *
|
|
|
|
_gtk_icon_helper_get_icon_name (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_icon_name (self->priv->def);
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkIconHelper *
|
2015-12-09 17:25:36 +00:00
|
|
|
gtk_icon_helper_new (GtkCssNode *node,
|
|
|
|
GtkWidget *owner)
|
2011-11-30 03:26:19 +00:00
|
|
|
{
|
2017-06-17 06:39:43 +00:00
|
|
|
GtkIconHelper *helper;
|
2015-12-08 14:39:10 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CSS_NODE (node), NULL);
|
2015-12-14 03:00:31 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (owner), NULL);
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
helper = g_object_new (GTK_TYPE_ICON_HELPER, NULL);
|
2015-12-14 03:00:31 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
helper->priv->node = node;
|
|
|
|
helper->priv->owner = owner;
|
|
|
|
g_signal_connect_swapped (owner, "direction-changed", G_CALLBACK (gtk_icon_helper_invalidate), helper);
|
|
|
|
g_signal_connect_swapped (owner, "notify::scale-factor", G_CALLBACK (gtk_icon_helper_invalidate), helper);
|
2015-12-14 03:00:31 +00:00
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
return helper;
|
2015-12-14 03:00:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 05:19:16 +00:00
|
|
|
void
|
|
|
|
gtk_icon_helper_snapshot (GtkIconHelper *self,
|
|
|
|
GtkSnapshot *snapshot)
|
2016-11-07 17:25:12 +00:00
|
|
|
{
|
2016-11-15 06:25:13 +00:00
|
|
|
GtkCssStyle *style;
|
2016-11-07 17:25:12 +00:00
|
|
|
GskTexture *texture;
|
|
|
|
|
2017-06-17 06:39:43 +00:00
|
|
|
style = gtk_css_node_get_style (self->priv->node);
|
2016-12-23 22:16:30 +00:00
|
|
|
|
2016-12-13 04:08:40 +00:00
|
|
|
gtk_icon_helper_ensure_texture (self);
|
2016-11-07 17:25:12 +00:00
|
|
|
texture = self->priv->texture;
|
|
|
|
if (texture == NULL)
|
2016-11-15 05:19:16 +00:00
|
|
|
return;
|
2016-11-07 17:25:12 +00:00
|
|
|
|
2016-11-26 10:51:30 +00:00
|
|
|
gtk_css_style_snapshot_icon_texture (style,
|
|
|
|
snapshot,
|
|
|
|
texture,
|
2017-06-17 06:39:43 +00:00
|
|
|
gtk_widget_get_scale_factor (self->priv->owner));
|
2016-11-07 17:25:12 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 03:26:19 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_icon_helper_get_is_empty (GtkIconHelper *self)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
return gtk_image_definition_get_storage_type (self->priv->def) == GTK_IMAGE_EMPTY;
|
2011-11-30 03:26:19 +00:00
|
|
|
}
|
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;
|
2015-12-11 14:12:19 +00:00
|
|
|
gtk_icon_helper_invalidate (self);
|
2012-07-13 13:54:29 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-24 12:13:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
|
|
|
|
int scale)
|
|
|
|
{
|
2015-11-24 18:55:09 +00:00
|
|
|
switch (gtk_image_definition_get_storage_type (self->priv->def))
|
|
|
|
{
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
|
|
|
gtk_icon_helper_take_definition (self,
|
|
|
|
gtk_image_definition_new_pixbuf (gtk_image_definition_get_pixbuf (self->priv->def),
|
|
|
|
scale));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_IMAGE_ANIMATION:
|
|
|
|
gtk_icon_helper_take_definition (self,
|
|
|
|
gtk_image_definition_new_animation (gtk_image_definition_get_animation (self->priv->def),
|
|
|
|
scale));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-06-24 12:13:43 +00:00
|
|
|
}
|