[gtk+] iconhelper: Don't inherit from GObject
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] iconhelper: Don't inherit from GObject
- Date: Sun, 1 Oct 2017 07:18:22 +0000 (UTC)
commit a32725bc9ab54320cda3bdf02449937c97121038
Author: Timm Bäder <mail baedert org>
Date: Sat Sep 30 17:26:42 2017 +0200
iconhelper: Don't inherit from GObject
It's not a GtkCssGadget anymore, it doesn't have any properties or
signals either and it's not public. Further, its lifetime is very clear
the way it's being used inside GTK+.
gtk/gtkcellrendererpixbuf.c | 54 +++++----
gtk/gtkiconhelper.c | 268 +++++++++++++++++-------------------------
gtk/gtkiconhelperprivate.h | 48 +++-----
gtk/gtkimage.c | 84 +++++++-------
4 files changed, 196 insertions(+), 258 deletions(-)
---
diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
index 675f8b3..eb00e3e 100644
--- a/gtk/gtkcellrendererpixbuf.c
+++ b/gtk/gtkcellrendererpixbuf.c
@@ -387,20 +387,20 @@ gtk_cell_renderer_pixbuf_new (void)
return g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, NULL);
}
-static GtkIconHelper *
-create_icon_helper (GtkCellRendererPixbuf *cellpixbuf,
+static void
+create_icon_helper (GtkIconHelper *icon_helper,
+ GtkCellRendererPixbuf *cellpixbuf,
GtkWidget *widget)
{
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
- GtkIconHelper *helper;
- helper = gtk_icon_helper_new (gtk_style_context_get_node (gtk_widget_get_style_context (widget)), widget);
- _gtk_icon_helper_set_force_scale_pixbuf (helper, TRUE);
- _gtk_icon_helper_set_definition (helper, priv->image_def);
+ gtk_icon_helper_init (icon_helper,
+ gtk_style_context_get_node (gtk_widget_get_style_context (widget)),
+ widget);
+ _gtk_icon_helper_set_force_scale_pixbuf (icon_helper, TRUE);
+ _gtk_icon_helper_set_definition (icon_helper, priv->image_def);
if (gtk_image_definition_get_storage_type (priv->image_def) != GTK_IMAGE_PIXBUF)
- _gtk_icon_helper_set_icon_size (helper, priv->icon_size);
-
- return helper;
+ _gtk_icon_helper_set_icon_size (icon_helper, priv->icon_size);
}
static void
@@ -420,18 +420,18 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
gint calc_height;
gint xpad, ypad;
GtkStyleContext *context;
- GtkIconHelper *icon_helper;
+ GtkIconHelper icon_helper;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
- icon_helper = create_icon_helper (cellpixbuf, widget);
+ create_icon_helper (&icon_helper, cellpixbuf, widget);
- if (!_gtk_icon_helper_get_is_empty (icon_helper))
- _gtk_icon_helper_get_size (icon_helper,
+ if (!_gtk_icon_helper_get_is_empty (&icon_helper))
+ _gtk_icon_helper_get_size (&icon_helper,
&pixbuf_width, &pixbuf_height);
- g_object_unref (icon_helper);
+ gtk_icon_helper_destroy (&icon_helper);
gtk_style_context_restore (context);
if (priv->pixbuf_expander_open)
@@ -497,7 +497,7 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell,
GdkRectangle draw_rect;
gboolean is_expander;
gint xpad, ypad;
- GtkIconHelper *icon_helper = NULL;
+ GtkIconHelper icon_helper;
gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area,
&pix_rect.x,
@@ -528,24 +528,28 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell,
if (is_expanded && priv->pixbuf_expander_open != NULL)
{
- icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
- _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_open);
+ gtk_icon_helper_init (&icon_helper, gtk_style_context_get_node (context), widget);
+ _gtk_icon_helper_set_pixbuf (&icon_helper, priv->pixbuf_expander_open);
}
else if (!is_expanded && priv->pixbuf_expander_closed != NULL)
{
- icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
- _gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_closed);
+ gtk_icon_helper_init (&icon_helper, gtk_style_context_get_node (context), widget);
+ _gtk_icon_helper_set_pixbuf (&icon_helper, priv->pixbuf_expander_closed);
+ }
+ else
+ {
+ create_icon_helper (&icon_helper, cellpixbuf, widget);
}
}
-
- if (icon_helper == NULL)
- icon_helper = create_icon_helper (cellpixbuf, widget);
+ else
+ {
+ create_icon_helper (&icon_helper, cellpixbuf, widget);
+ }
gtk_snapshot_offset (snapshot, pix_rect.x, pix_rect.y);
- gtk_icon_helper_snapshot (icon_helper, snapshot);
+ gtk_icon_helper_snapshot (&icon_helper, snapshot);
gtk_snapshot_offset (snapshot, - pix_rect.x, - pix_rect.y);
- g_object_unref (icon_helper);
-
+ gtk_icon_helper_destroy (&icon_helper);
gtk_style_context_restore (context);
}
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index e7ef55f..6f9c329 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -34,51 +34,31 @@
#include "gtksnapshot.h"
#include "gtkwidgetprivate.h"
-struct _GtkIconHelperPrivate {
- GtkImageDefinition *def;
-
- GtkIconSize icon_size;
- gint pixel_size;
-
- guint use_fallback : 1;
- guint force_scale_pixbuf : 1;
- guint rendered_surface_is_symbolic : 1;
-
- GtkWidget *owner;
- GtkCssNode *node;
- cairo_surface_t *rendered_surface;
- GskTexture *texture;
-};
-
-G_DEFINE_TYPE_WITH_PRIVATE (GtkIconHelper, gtk_icon_helper, G_TYPE_OBJECT)
-
void
gtk_icon_helper_invalidate (GtkIconHelper *self)
{
- g_clear_object (&self->priv->texture);
+ g_clear_object (&self->texture);
- if (self->priv->rendered_surface != NULL)
+ if (self->rendered_surface != NULL)
{
- cairo_surface_destroy (self->priv->rendered_surface);
- self->priv->rendered_surface = NULL;
- self->priv->rendered_surface_is_symbolic = FALSE;
+ cairo_surface_destroy (self->rendered_surface);
+ self->rendered_surface = NULL;
+ self->rendered_surface_is_symbolic = FALSE;
}
- if (!GTK_IS_CSS_TRANSIENT_NODE (self->priv->node))
- gtk_widget_queue_resize (self->priv->owner);
+ if (!GTK_IS_CSS_TRANSIENT_NODE (self->node))
+ gtk_widget_queue_resize (self->owner);
}
void
gtk_icon_helper_invalidate_for_change (GtkIconHelper *self,
GtkCssStyleChange *change)
{
- GtkIconHelperPrivate *priv = self->priv;
-
if (change == NULL ||
((gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SYMBOLIC_ICON) &&
- priv->rendered_surface_is_symbolic) ||
+ self->rendered_surface_is_symbolic) ||
(gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON) &&
- !priv->rendered_surface_is_symbolic)))
+ !self->rendered_surface_is_symbolic)))
{
gtk_icon_helper_invalidate (self);
}
@@ -93,8 +73,8 @@ gtk_icon_helper_take_definition (GtkIconHelper *self,
if (def == NULL)
return;
- gtk_image_definition_unref (self->priv->def);
- self->priv->def = def;
+ gtk_image_definition_unref (self->def);
+ self->def = def;
gtk_icon_helper_invalidate (self);
}
@@ -102,50 +82,41 @@ gtk_icon_helper_take_definition (GtkIconHelper *self,
void
_gtk_icon_helper_clear (GtkIconHelper *self)
{
- g_clear_object (&self->priv->texture);
- g_clear_pointer (&self->priv->rendered_surface, cairo_surface_destroy);
+ g_clear_object (&self->texture);
+ g_clear_pointer (&self->rendered_surface, cairo_surface_destroy);
- gtk_image_definition_unref (self->priv->def);
- self->priv->def = gtk_image_definition_new_empty ();
+ gtk_image_definition_unref (self->def);
+ self->def = gtk_image_definition_new_empty ();
- self->priv->icon_size = GTK_ICON_SIZE_INVALID;
+ self->icon_size = GTK_ICON_SIZE_INVALID;
gtk_icon_helper_invalidate (self);
}
-static void
-gtk_icon_helper_finalize (GObject *object)
+void
+gtk_icon_helper_destroy (GtkIconHelper *self)
{
- GtkIconHelper *self = GTK_ICON_HELPER (object);
- GtkWidget *widget;
-
- widget = self->priv->owner;
- g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (gtk_icon_helper_invalidate), self);
-
_gtk_icon_helper_clear (self);
- gtk_image_definition_unref (self->priv->def);
-
- G_OBJECT_CLASS (gtk_icon_helper_parent_class)->finalize (object);
+ g_signal_handlers_disconnect_by_func (self->owner, G_CALLBACK (gtk_icon_helper_invalidate), self);
+ gtk_image_definition_unref (self->def);
}
-static void
-gtk_icon_helper_class_init (GtkIconHelperClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = gtk_icon_helper_finalize;
-}
-
-static void
-gtk_icon_helper_init (GtkIconHelper *self)
+void
+gtk_icon_helper_init (GtkIconHelper *self,
+ GtkCssNode *css_node,
+ GtkWidget *owner)
{
- self->priv = gtk_icon_helper_get_instance_private (self);
+ memset (self, 0, sizeof (GtkIconHelper));
+ self->def = gtk_image_definition_new_empty ();
- self->priv->def = gtk_image_definition_new_empty ();
+ self->icon_size = GTK_ICON_SIZE_INVALID;
+ self->pixel_size = -1;
+ self->rendered_surface_is_symbolic = FALSE;
- self->priv->icon_size = GTK_ICON_SIZE_INVALID;
- self->priv->pixel_size = -1;
- self->priv->rendered_surface_is_symbolic = FALSE;
+ self->node = css_node;
+ self->owner = owner;
+ g_signal_connect_swapped (owner, "direction-changed", G_CALLBACK (gtk_icon_helper_invalidate), self);
+ g_signal_connect_swapped (owner, "notify::scale-factor", G_CALLBACK (gtk_icon_helper_invalidate), self);
}
static void
@@ -155,19 +126,19 @@ ensure_icon_size (GtkIconHelper *self,
{
gint width, height;
- if (self->priv->pixel_size != -1)
+ if (self->pixel_size != -1)
{
- width = height = self->priv->pixel_size;
+ width = height = self->pixel_size;
}
- else if (!gtk_icon_size_lookup (self->priv->icon_size, &width, &height))
+ else if (!gtk_icon_size_lookup (self->icon_size, &width, &height))
{
- if (self->priv->icon_size == GTK_ICON_SIZE_INVALID)
+ if (self->icon_size == GTK_ICON_SIZE_INVALID)
{
width = height = 0;
}
else
{
- g_warning ("Invalid icon size %d", self->priv->icon_size);
+ g_warning ("Invalid icon size %d", self->icon_size);
width = height = 24;
}
}
@@ -186,7 +157,7 @@ get_icon_lookup_flags (GtkIconHelper *self,
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
- if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
+ if (self->pixel_size != -1 || self->force_scale_pixbuf)
flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
icon_style = _gtk_css_icon_style_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_STYLE));
@@ -263,9 +234,9 @@ get_pixbuf_size (GtkIconHelper *self,
scale_pixmap = FALSE;
- if (self->priv->force_scale_pixbuf &&
- (self->priv->pixel_size != -1 ||
- self->priv->icon_size != GTK_ICON_SIZE_INVALID))
+ if (self->force_scale_pixbuf &&
+ (self->pixel_size != -1 ||
+ self->icon_size != GTK_ICON_SIZE_INVALID))
{
ensure_icon_size (self, &width, &height);
@@ -321,7 +292,7 @@ ensure_surface_from_pixbuf (GtkIconHelper *self,
else
pixbuf = g_object_ref (orig_pixbuf);
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, _gtk_widget_get_window (self->priv->owner));
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, _gtk_widget_get_window (self->owner));
g_object_unref (pixbuf);
return surface;
@@ -334,7 +305,6 @@ ensure_surface_for_gicon (GtkIconHelper *self,
gint scale,
GIcon *gicon)
{
- GtkIconHelperPrivate *priv = self->priv;
GtkIconTheme *icon_theme;
gint width, height;
GtkIconInfo *info;
@@ -396,11 +366,11 @@ ensure_surface_for_gicon (GtkIconHelper *self,
symbolic = FALSE;
}
- surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, _gtk_widget_get_window (priv->owner));
+ surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, _gtk_widget_get_window (self->owner));
if (symbolic)
{
- priv->rendered_surface_is_symbolic = TRUE;
+ self->rendered_surface_is_symbolic = TRUE;
}
g_object_unref (destination);
@@ -412,32 +382,31 @@ static cairo_surface_t *
gtk_icon_helper_load_surface (GtkIconHelper *self,
int scale)
{
- GtkIconHelperPrivate *priv = gtk_icon_helper_get_instance_private (self);
cairo_surface_t *surface;
GIcon *gicon;
- switch (gtk_image_definition_get_storage_type (self->priv->def))
+ switch (gtk_image_definition_get_storage_type (self->def))
{
case GTK_IMAGE_SURFACE:
- surface = ensure_surface_from_surface (self, gtk_image_definition_get_surface (self->priv->def));
+ surface = ensure_surface_from_surface (self, gtk_image_definition_get_surface (self->def));
break;
case GTK_IMAGE_PIXBUF:
surface = ensure_surface_from_pixbuf (self,
- gtk_css_node_get_style (priv->node),
+ gtk_css_node_get_style (self->node),
scale,
- gtk_image_definition_get_pixbuf (self->priv->def),
- gtk_image_definition_get_scale (self->priv->def));
+ gtk_image_definition_get_pixbuf (self->def),
+ gtk_image_definition_get_scale (self->def));
break;
case GTK_IMAGE_ICON_NAME:
- if (self->priv->use_fallback)
- gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name
(self->priv->def));
+ if (self->use_fallback)
+ gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->def));
else
- gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->priv->def));
+ gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->def));
surface = ensure_surface_for_gicon (self,
- gtk_css_node_get_style (priv->node),
- gtk_widget_get_direction (priv->owner),
+ gtk_css_node_get_style (self->node),
+ gtk_widget_get_direction (self->owner),
scale,
gicon);
g_object_unref (gicon);
@@ -445,10 +414,10 @@ gtk_icon_helper_load_surface (GtkIconHelper *self,
case GTK_IMAGE_GICON:
surface = ensure_surface_for_gicon (self,
- gtk_css_node_get_style (priv->node),
- gtk_widget_get_direction (priv->owner),
+ gtk_css_node_get_style (self->node),
+ gtk_widget_get_direction (self->owner),
scale,
- gtk_image_definition_get_gicon (priv->def));
+ gtk_image_definition_get_gicon (self->def));
break;
case GTK_IMAGE_ANIMATION:
@@ -467,12 +436,12 @@ gtk_icon_helper_ensure_surface (GtkIconHelper *self)
{
int scale;
- if (self->priv->rendered_surface)
+ if (self->rendered_surface)
return;
- scale = gtk_widget_get_scale_factor (self->priv->owner);
+ scale = gtk_widget_get_scale_factor (self->owner);
- self->priv->rendered_surface = gtk_icon_helper_load_surface (self, scale);
+ self->rendered_surface = gtk_icon_helper_load_surface (self, scale);
}
static void
@@ -481,41 +450,41 @@ gtk_icon_helper_ensure_texture (GtkIconHelper *self)
cairo_surface_t *map;
int width, height, scale;
- if (self->priv->texture)
+ if (self->texture)
return;
gtk_icon_helper_ensure_surface (self);
- if (self->priv->rendered_surface == NULL)
+ if (self->rendered_surface == NULL)
return;
- scale = gtk_widget_get_scale_factor (self->priv->owner);
+ scale = gtk_widget_get_scale_factor (self->owner);
_gtk_icon_helper_get_size (self, &width, &height);
- if (cairo_image_surface_get_format (self->priv->rendered_surface) != CAIRO_FORMAT_ARGB32)
+ if (cairo_image_surface_get_format (self->rendered_surface) != CAIRO_FORMAT_ARGB32)
{
- cairo_surface_t *argb_surface = cairo_surface_create_similar_image (self->priv->rendered_surface,
+ cairo_surface_t *argb_surface = cairo_surface_create_similar_image (self->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_set_source_surface (ct, self->rendered_surface, 0, 0);
cairo_paint (ct);
cairo_destroy (ct);
- cairo_surface_destroy (self->priv->rendered_surface);
- self->priv->rendered_surface = argb_surface;
+ cairo_surface_destroy (self->rendered_surface);
+ self->rendered_surface = argb_surface;
}
- map = cairo_surface_map_to_image (self->priv->rendered_surface,
+ map = cairo_surface_map_to_image (self->rendered_surface,
&(GdkRectangle) { 0, 0, width * scale, height * scale});
- self->priv->texture = gsk_texture_new_for_data (cairo_image_surface_get_data (map),
+ self->texture = gsk_texture_new_for_data (cairo_image_surface_get_data (map),
width * scale,
height * scale,
cairo_image_surface_get_stride (map));
- cairo_surface_unmap_image (self->priv->rendered_surface, map);
+ cairo_surface_unmap_image (self->rendered_surface, map);
}
void
@@ -527,23 +496,23 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
width = height = 0;
- /* Certain kinds of images are easy to calculate the size for, these
+ /* Certain kinds of images are easy to calculate the size for,</cosimoc>3 these
we do immediately to avoid having to potentially load the image
data for something that may not yet be visible */
- switch (gtk_image_definition_get_storage_type (self->priv->def))
+ switch (gtk_image_definition_get_storage_type (self->def))
{
case GTK_IMAGE_SURFACE:
get_surface_size (self,
- gtk_image_definition_get_surface (self->priv->def),
+ gtk_image_definition_get_surface (self->def),
&width,
&height);
break;
case GTK_IMAGE_PIXBUF:
get_pixbuf_size (self,
- gtk_widget_get_scale_factor (self->priv->owner),
- gtk_image_definition_get_pixbuf (self->priv->def),
- gtk_image_definition_get_scale (self->priv->def),
+ gtk_widget_get_scale_factor (self->owner),
+ gtk_image_definition_get_pixbuf (self->def),
+ gtk_image_definition_get_scale (self->def),
&width, &height, &scale);
width = (width + scale - 1) / scale;
height = (height + scale - 1) / scale;
@@ -551,7 +520,7 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
case GTK_IMAGE_ANIMATION:
{
- GdkPixbufAnimation *animation = gtk_image_definition_get_animation (self->priv->def);
+ GdkPixbufAnimation *animation = gtk_image_definition_get_animation (self->def);
width = gdk_pixbuf_animation_get_width (animation);
height = gdk_pixbuf_animation_get_height (animation);
break;
@@ -559,7 +528,7 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
case GTK_IMAGE_ICON_NAME:
case GTK_IMAGE_GICON:
- if (self->priv->pixel_size != -1 || self->priv->force_scale_pixbuf)
+ if (self->pixel_size != -1 || self->force_scale_pixbuf)
ensure_icon_size (self, &width, &height);
break;
@@ -574,11 +543,11 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
{
gtk_icon_helper_ensure_surface (self);
- if (self->priv->rendered_surface != NULL)
+ if (self->rendered_surface != NULL)
{
- get_surface_size (self, self->priv->rendered_surface, &width, &height);
+ get_surface_size (self, self->rendered_surface, &width, &height);
}
- else if (self->priv->icon_size != GTK_ICON_SIZE_INVALID)
+ else if (self->icon_size != GTK_ICON_SIZE_INVALID)
{
ensure_icon_size (self, &width, &height);
}
@@ -643,9 +612,9 @@ gboolean
_gtk_icon_helper_set_icon_size (GtkIconHelper *self,
GtkIconSize icon_size)
{
- if (self->priv->icon_size != icon_size)
+ if (self->icon_size != icon_size)
{
- self->priv->icon_size = icon_size;
+ self->icon_size = icon_size;
gtk_icon_helper_invalidate (self);
return TRUE;
}
@@ -656,9 +625,9 @@ gboolean
_gtk_icon_helper_set_pixel_size (GtkIconHelper *self,
gint pixel_size)
{
- if (self->priv->pixel_size != pixel_size)
+ if (self->pixel_size != pixel_size)
{
- self->priv->pixel_size = pixel_size;
+ self->pixel_size = pixel_size;
gtk_icon_helper_invalidate (self);
return TRUE;
}
@@ -669,9 +638,9 @@ gboolean
_gtk_icon_helper_set_use_fallback (GtkIconHelper *self,
gboolean use_fallback)
{
- if (self->priv->use_fallback != use_fallback)
+ if (self->use_fallback != use_fallback)
{
- self->priv->use_fallback = use_fallback;
+ self->use_fallback = use_fallback;
gtk_icon_helper_invalidate (self);
return TRUE;
}
@@ -681,80 +650,61 @@ _gtk_icon_helper_set_use_fallback (GtkIconHelper *self,
GtkImageType
_gtk_icon_helper_get_storage_type (GtkIconHelper *self)
{
- return gtk_image_definition_get_storage_type (self->priv->def);
+ return gtk_image_definition_get_storage_type (self->def);
}
gboolean
_gtk_icon_helper_get_use_fallback (GtkIconHelper *self)
{
- return self->priv->use_fallback;
+ return self->use_fallback;
}
GtkIconSize
_gtk_icon_helper_get_icon_size (GtkIconHelper *self)
{
- return self->priv->icon_size;
+ return self->icon_size;
}
gint
_gtk_icon_helper_get_pixel_size (GtkIconHelper *self)
{
- return self->priv->pixel_size;
+ return self->pixel_size;
}
GtkImageDefinition *
gtk_icon_helper_get_definition (GtkIconHelper *self)
{
- return self->priv->def;
+ return self->def;
}
GdkPixbuf *
_gtk_icon_helper_peek_pixbuf (GtkIconHelper *self)
{
- return gtk_image_definition_get_pixbuf (self->priv->def);
+ return gtk_image_definition_get_pixbuf (self->def);
}
GIcon *
_gtk_icon_helper_peek_gicon (GtkIconHelper *self)
{
- return gtk_image_definition_get_gicon (self->priv->def);
+ return gtk_image_definition_get_gicon (self->def);
}
GdkPixbufAnimation *
_gtk_icon_helper_peek_animation (GtkIconHelper *self)
{
- return gtk_image_definition_get_animation (self->priv->def);
+ return gtk_image_definition_get_animation (self->def);
}
cairo_surface_t *
_gtk_icon_helper_peek_surface (GtkIconHelper *self)
{
- return gtk_image_definition_get_surface (self->priv->def);
+ return gtk_image_definition_get_surface (self->def);
}
const gchar *
_gtk_icon_helper_get_icon_name (GtkIconHelper *self)
{
- return gtk_image_definition_get_icon_name (self->priv->def);
-}
-
-GtkIconHelper *
-gtk_icon_helper_new (GtkCssNode *node,
- GtkWidget *owner)
-{
- GtkIconHelper *helper;
-
- g_return_val_if_fail (GTK_IS_CSS_NODE (node), NULL);
- g_return_val_if_fail (GTK_IS_WIDGET (owner), NULL);
-
- helper = g_object_new (GTK_TYPE_ICON_HELPER, NULL);
-
- 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);
-
- return helper;
+ return gtk_image_definition_get_icon_name (self->def);
}
void
@@ -764,38 +714,38 @@ gtk_icon_helper_snapshot (GtkIconHelper *self,
GtkCssStyle *style;
GskTexture *texture;
- style = gtk_css_node_get_style (self->priv->node);
+ style = gtk_css_node_get_style (self->node);
gtk_icon_helper_ensure_texture (self);
- texture = self->priv->texture;
+ texture = self->texture;
if (texture == NULL)
return;
gtk_css_style_snapshot_icon_texture (style,
snapshot,
texture,
- gtk_widget_get_scale_factor (self->priv->owner));
+ gtk_widget_get_scale_factor (self->owner));
}
gboolean
_gtk_icon_helper_get_is_empty (GtkIconHelper *self)
{
- return gtk_image_definition_get_storage_type (self->priv->def) == GTK_IMAGE_EMPTY;
+ return gtk_image_definition_get_storage_type (self->def) == GTK_IMAGE_EMPTY;
}
gboolean
_gtk_icon_helper_get_force_scale_pixbuf (GtkIconHelper *self)
{
- return self->priv->force_scale_pixbuf;
+ return self->force_scale_pixbuf;
}
void
_gtk_icon_helper_set_force_scale_pixbuf (GtkIconHelper *self,
gboolean force_scale)
{
- if (self->priv->force_scale_pixbuf != force_scale)
+ if (self->force_scale_pixbuf != force_scale)
{
- self->priv->force_scale_pixbuf = force_scale;
+ self->force_scale_pixbuf = force_scale;
gtk_icon_helper_invalidate (self);
}
}
@@ -804,17 +754,17 @@ void
_gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
int scale)
{
- switch (gtk_image_definition_get_storage_type (self->priv->def))
+ switch (gtk_image_definition_get_storage_type (self->def))
{
case GTK_IMAGE_PIXBUF:
gtk_icon_helper_take_definition (self,
- gtk_image_definition_new_pixbuf (gtk_image_definition_get_pixbuf
(self->priv->def),
+ gtk_image_definition_new_pixbuf (gtk_image_definition_get_pixbuf
(self->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),
+ gtk_image_definition_new_animation (gtk_image_definition_get_animation
(self->def),
scale));
break;
diff --git a/gtk/gtkiconhelperprivate.h b/gtk/gtkiconhelperprivate.h
index cbaa4b4..2de38a7 100644
--- a/gtk/gtkiconhelperprivate.h
+++ b/gtk/gtkiconhelperprivate.h
@@ -28,48 +28,32 @@
G_BEGIN_DECLS
-#define GTK_TYPE_ICON_HELPER gtk_icon_helper_get_type()
-
-#define GTK_ICON_HELPER(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- GTK_TYPE_ICON_HELPER, GtkIconHelper))
-
-#define GTK_ICON_HELPER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- GTK_TYPE_ICON_HELPER, GtkIconHelperClass))
-
-#define GTK_IS_ICON_HELPER(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- GTK_TYPE_ICON_HELPER))
-
-#define GTK_IS_ICON_HELPER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- GTK_TYPE_ICON_HELPER))
-
-#define GTK_ICON_HELPER_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- GTK_TYPE_ICON_HELPER, GtkIconHelperClass))
-
typedef struct _GtkIconHelper GtkIconHelper;
-typedef struct _GtkIconHelperClass GtkIconHelperClass;
-typedef struct _GtkIconHelperPrivate GtkIconHelperPrivate;
struct _GtkIconHelper
{
GObject parent_instance;
- GtkIconHelperPrivate *priv;
-};
+ GtkImageDefinition *def;
-struct _GtkIconHelperClass
-{
- GObjectClass parent_class;
+ GtkIconSize icon_size;
+ gint pixel_size;
+
+ guint use_fallback : 1;
+ guint force_scale_pixbuf : 1;
+ guint rendered_surface_is_symbolic : 1;
+
+ GtkWidget *owner;
+ GtkCssNode *node;
+ cairo_surface_t *rendered_surface;
+ GskTexture *texture;
};
-GType gtk_icon_helper_get_type (void) G_GNUC_CONST;
+void gtk_icon_helper_init (GtkIconHelper *self,
+ GtkCssNode *css_node,
+ GtkWidget *owner);
-GtkIconHelper *gtk_icon_helper_new (GtkCssNode *node,
- GtkWidget *owner);
+void gtk_icon_helper_destroy (GtkIconHelper *self);
void _gtk_icon_helper_clear (GtkIconHelper *self);
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 3dc3a22..08435d4 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -83,7 +83,7 @@
struct _GtkImagePrivate
{
- GtkIconHelper *icon_helper;
+ GtkIconHelper icon_helper;
GdkPixbufAnimationIter *animation_iter;
gint animation_timeout;
@@ -306,8 +306,8 @@ gtk_image_init (GtkImage *image)
widget_node = gtk_widget_get_css_node (GTK_WIDGET (image));
gtk_widget_set_has_window (GTK_WIDGET (image), FALSE);
- priv->icon_helper = gtk_icon_helper_new (widget_node, GTK_WIDGET (image));
- _gtk_icon_helper_set_icon_size (priv->icon_helper, DEFAULT_ICON_SIZE);
+ gtk_icon_helper_init (&priv->icon_helper, widget_node, GTK_WIDGET (image));
+ _gtk_icon_helper_set_icon_size (&priv->icon_helper, DEFAULT_ICON_SIZE);
}
static void
@@ -315,7 +315,7 @@ gtk_image_finalize (GObject *object)
{
GtkImage *image = GTK_IMAGE (object);
- g_clear_object (&image->priv->icon_helper);
+ gtk_icon_helper_destroy (&image->priv->icon_helper);
g_free (image->priv->filename);
g_free (image->priv->resource_path);
@@ -331,7 +331,7 @@ gtk_image_set_property (GObject *object,
{
GtkImage *image = GTK_IMAGE (object);
GtkImagePrivate *priv = image->priv;
- GtkIconSize icon_size = _gtk_icon_helper_get_icon_size (priv->icon_helper);
+ GtkIconSize icon_size = _gtk_icon_helper_get_icon_size (&priv->icon_helper);
if (icon_size == GTK_ICON_SIZE_INVALID)
icon_size = DEFAULT_ICON_SIZE;
@@ -348,7 +348,7 @@ gtk_image_set_property (GObject *object,
gtk_image_set_from_file (image, g_value_get_string (value));
break;
case PROP_ICON_SIZE:
- if (_gtk_icon_helper_set_icon_size (priv->icon_helper, g_value_get_int (value)))
+ if (_gtk_icon_helper_set_icon_size (&priv->icon_helper, g_value_get_int (value)))
{
g_object_notify_by_pspec (object, pspec);
gtk_widget_queue_resize (GTK_WIDGET (image));
@@ -371,7 +371,7 @@ gtk_image_set_property (GObject *object,
break;
case PROP_USE_FALLBACK:
- if (_gtk_icon_helper_set_use_fallback (priv->icon_helper, g_value_get_boolean (value)))
+ if (_gtk_icon_helper_set_use_fallback (&priv->icon_helper, g_value_get_boolean (value)))
g_object_notify_by_pspec (object, pspec);
break;
@@ -393,37 +393,37 @@ gtk_image_get_property (GObject *object,
switch (prop_id)
{
case PROP_PIXBUF:
- g_value_set_object (value, _gtk_icon_helper_peek_pixbuf (priv->icon_helper));
+ g_value_set_object (value, _gtk_icon_helper_peek_pixbuf (&priv->icon_helper));
break;
case PROP_SURFACE:
- g_value_set_boxed (value, _gtk_icon_helper_peek_surface (priv->icon_helper));
+ g_value_set_boxed (value, _gtk_icon_helper_peek_surface (&priv->icon_helper));
break;
case PROP_FILE:
g_value_set_string (value, priv->filename);
break;
case PROP_ICON_SIZE:
- g_value_set_int (value, _gtk_icon_helper_get_icon_size (priv->icon_helper));
+ g_value_set_int (value, _gtk_icon_helper_get_icon_size (&priv->icon_helper));
break;
case PROP_PIXEL_SIZE:
- g_value_set_int (value, _gtk_icon_helper_get_pixel_size (priv->icon_helper));
+ g_value_set_int (value, _gtk_icon_helper_get_pixel_size (&priv->icon_helper));
break;
case PROP_PIXBUF_ANIMATION:
- g_value_set_object (value, _gtk_icon_helper_peek_animation (priv->icon_helper));
+ g_value_set_object (value, _gtk_icon_helper_peek_animation (&priv->icon_helper));
break;
case PROP_ICON_NAME:
- g_value_set_string (value, _gtk_icon_helper_get_icon_name (priv->icon_helper));
+ g_value_set_string (value, _gtk_icon_helper_get_icon_name (&priv->icon_helper));
break;
case PROP_GICON:
- g_value_set_object (value, _gtk_icon_helper_peek_gicon (priv->icon_helper));
+ g_value_set_object (value, _gtk_icon_helper_peek_gicon (&priv->icon_helper));
break;
case PROP_RESOURCE:
g_value_set_string (value, priv->resource_path);
break;
case PROP_USE_FALLBACK:
- g_value_set_boolean (value, _gtk_icon_helper_get_use_fallback (priv->icon_helper));
+ g_value_set_boolean (value, _gtk_icon_helper_get_use_fallback (&priv->icon_helper));
break;
case PROP_STORAGE_TYPE:
- g_value_set_enum (value, _gtk_icon_helper_get_storage_type (priv->icon_helper));
+ g_value_set_enum (value, _gtk_icon_helper_get_storage_type (&priv->icon_helper));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -782,7 +782,7 @@ gtk_image_set_from_file (GtkImage *image,
else
gtk_image_set_from_animation (image, anim);
- _gtk_icon_helper_set_pixbuf_scale (priv->icon_helper, scale_factor);
+ _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
g_object_unref (anim);
@@ -874,7 +874,7 @@ gtk_image_set_from_resource (GtkImage *image,
else
gtk_image_set_from_animation (image, animation);
- _gtk_icon_helper_set_pixbuf_scale (priv->icon_helper, scale_factor);
+ _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
priv->resource_path = g_strdup (resource_path);
@@ -910,7 +910,7 @@ gtk_image_set_from_pixbuf (GtkImage *image,
gtk_image_clear (image);
if (pixbuf != NULL)
- _gtk_icon_helper_set_pixbuf (priv->icon_helper, pixbuf);
+ _gtk_icon_helper_set_pixbuf (&priv->icon_helper, pixbuf);
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PIXBUF]);
@@ -946,7 +946,7 @@ gtk_image_set_from_animation (GtkImage *image,
if (animation != NULL)
{
- _gtk_icon_helper_set_animation (priv->icon_helper, animation);
+ _gtk_icon_helper_set_animation (&priv->icon_helper, animation);
g_object_unref (animation);
}
@@ -981,7 +981,7 @@ gtk_image_set_from_icon_name (GtkImage *image,
gtk_image_clear (image);
if (icon_name)
- _gtk_icon_helper_set_icon_name (priv->icon_helper, icon_name, size);
+ _gtk_icon_helper_set_icon_name (&priv->icon_helper, icon_name, size);
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_ICON_NAME]);
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_ICON_SIZE]);
@@ -1019,7 +1019,7 @@ gtk_image_set_from_gicon (GtkImage *image,
if (icon)
{
- _gtk_icon_helper_set_gicon (priv->icon_helper, icon, size);
+ _gtk_icon_helper_set_gicon (&priv->icon_helper, icon, size);
g_object_unref (icon);
}
@@ -1057,7 +1057,7 @@ gtk_image_set_from_surface (GtkImage *image,
if (surface)
{
- _gtk_icon_helper_set_surface (priv->icon_helper, surface);
+ _gtk_icon_helper_set_surface (&priv->icon_helper, surface);
cairo_surface_destroy (surface);
}
@@ -1081,7 +1081,7 @@ gtk_image_get_storage_type (GtkImage *image)
{
g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_IMAGE_EMPTY);
- return _gtk_icon_helper_get_storage_type (image->priv->icon_helper);
+ return _gtk_icon_helper_get_storage_type (&image->priv->icon_helper);
}
/**
@@ -1102,7 +1102,7 @@ gtk_image_get_pixbuf (GtkImage *image)
{
g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
- return _gtk_icon_helper_peek_pixbuf (image->priv->icon_helper);
+ return _gtk_icon_helper_peek_pixbuf (&image->priv->icon_helper);
}
/**
@@ -1127,7 +1127,7 @@ gtk_image_get_animation (GtkImage *image)
priv = image->priv;
- return _gtk_icon_helper_peek_animation (priv->icon_helper);
+ return _gtk_icon_helper_peek_animation (&priv->icon_helper);
}
/**
@@ -1158,10 +1158,10 @@ gtk_image_get_icon_name (GtkImage *image,
priv = image->priv;
if (icon_name)
- *icon_name = _gtk_icon_helper_get_icon_name (priv->icon_helper);
+ *icon_name = _gtk_icon_helper_get_icon_name (&priv->icon_helper);
if (size)
- *size = _gtk_icon_helper_get_icon_size (priv->icon_helper);
+ *size = _gtk_icon_helper_get_icon_size (&priv->icon_helper);
}
/**
@@ -1192,10 +1192,10 @@ gtk_image_get_gicon (GtkImage *image,
priv = image->priv;
if (gicon)
- *gicon = _gtk_icon_helper_peek_gicon (priv->icon_helper);
+ *gicon = _gtk_icon_helper_peek_gicon (&priv->icon_helper);
if (size)
- *size = _gtk_icon_helper_get_icon_size (priv->icon_helper);
+ *size = _gtk_icon_helper_get_icon_size (&priv->icon_helper);
}
/**
@@ -1259,7 +1259,7 @@ gtk_image_unrealize (GtkWidget *widget)
gtk_image_reset_anim_iter (image);
- gtk_icon_helper_invalidate (priv->icon_helper);
+ gtk_icon_helper_invalidate (&priv->icon_helper);
GTK_WIDGET_CLASS (gtk_image_parent_class)->unrealize (widget);
}
@@ -1300,7 +1300,7 @@ get_animation_frame (GtkImage *image)
int delay;
priv->animation_iter =
- gdk_pixbuf_animation_get_iter (_gtk_icon_helper_peek_animation (priv->icon_helper), NULL);
+ gdk_pixbuf_animation_get_iter (_gtk_icon_helper_peek_animation (&priv->icon_helper), NULL);
delay = gdk_pixbuf_animation_iter_get_delay_time (priv->animation_iter);
if (delay >= 0) {
@@ -1351,7 +1351,7 @@ gtk_image_snapshot (GtkWidget *widget,
x = 0;
y = 0;
- _gtk_icon_helper_get_size (priv->icon_helper, &w, &h);
+ _gtk_icon_helper_get_size (&priv->icon_helper, &w, &h);
baseline = gtk_widget_get_allocated_baseline (widget);
@@ -1374,7 +1374,7 @@ gtk_image_snapshot (GtkWidget *widget,
else
{
gtk_snapshot_offset (snapshot, x, y);
- gtk_icon_helper_snapshot (priv->icon_helper, snapshot);
+ gtk_icon_helper_snapshot (&priv->icon_helper, snapshot);
gtk_snapshot_offset (snapshot, -x, -y);
}
}
@@ -1420,12 +1420,12 @@ gtk_image_set_from_definition (GtkImage *image,
if (def != NULL)
{
- _gtk_icon_helper_set_definition (priv->icon_helper, def);
+ _gtk_icon_helper_set_definition (&priv->icon_helper, def);
gtk_image_notify_for_storage_type (image, gtk_image_definition_get_storage_type (def));
}
- _gtk_icon_helper_set_icon_size (priv->icon_helper, icon_size);
+ _gtk_icon_helper_set_icon_size (&priv->icon_helper, icon_size);
g_object_thaw_notify (G_OBJECT (image));
}
@@ -1433,7 +1433,7 @@ gtk_image_set_from_definition (GtkImage *image,
GtkImageDefinition *
gtk_image_get_definition (GtkImage *image)
{
- return gtk_icon_helper_get_definition (image->priv->icon_helper);
+ return gtk_icon_helper_get_definition (&image->priv->icon_helper);
}
/**
@@ -1476,7 +1476,7 @@ gtk_image_clear (GtkImage *image)
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_RESOURCE]);
}
- _gtk_icon_helper_clear (priv->icon_helper);
+ _gtk_icon_helper_clear (&priv->icon_helper);
g_object_thaw_notify (G_OBJECT (image));
}
@@ -1493,7 +1493,7 @@ gtk_image_measure (GtkWidget *widget,
gint width, height;
float baseline_align;
- _gtk_icon_helper_get_size (GTK_IMAGE (widget)->priv->icon_helper,
+ _gtk_icon_helper_get_size (>K_IMAGE (widget)->priv->icon_helper,
&width, &height);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -1519,7 +1519,7 @@ gtk_image_style_updated (GtkWidget *widget)
GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkCssStyleChange *change = gtk_style_context_get_change (context);
- gtk_icon_helper_invalidate_for_change (priv->icon_helper, change);
+ gtk_icon_helper_invalidate_for_change (&priv->icon_helper, change);
GTK_WIDGET_CLASS (gtk_image_parent_class)->style_updated (widget);
@@ -1543,7 +1543,7 @@ gtk_image_set_pixel_size (GtkImage *image,
{
g_return_if_fail (GTK_IS_IMAGE (image));
- if (_gtk_icon_helper_set_pixel_size (image->priv->icon_helper, pixel_size))
+ if (_gtk_icon_helper_set_pixel_size (&image->priv->icon_helper, pixel_size))
{
if (gtk_widget_get_visible (GTK_WIDGET (image)))
gtk_widget_queue_resize (GTK_WIDGET (image));
@@ -1566,5 +1566,5 @@ gtk_image_get_pixel_size (GtkImage *image)
{
g_return_val_if_fail (GTK_IS_IMAGE (image), -1);
- return _gtk_icon_helper_get_pixel_size (image->priv->icon_helper);
+ return _gtk_icon_helper_get_pixel_size (&image->priv->icon_helper);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]