cellrendererpixbuf: Store the texture in the iconhelper paintable

That's kinda weird but allows us to delete the texture case from
GtkIconHelper and GTK_IMAGE_TEXTURE from the GtkImageType enum.

And it doesn't cause any other problems because the cell renderer
can't deal with paintables - otherwise it would mirror GtkImage and have
a "paintable" property instead.
This commit is contained in:
Benjamin Otte 2018-03-16 04:50:26 +01:00
parent cbe40f5f46
commit 12409ee075
8 changed files with 6 additions and 103 deletions

View File

@ -240,7 +240,7 @@ gtk_cell_renderer_pixbuf_get_property (GObject *object,
g_value_set_object (value, priv->pixbuf_expander_closed); g_value_set_object (value, priv->pixbuf_expander_closed);
break; break;
case PROP_TEXTURE: case PROP_TEXTURE:
g_value_set_object (value, gtk_image_definition_get_texture (priv->image_def)); g_value_set_object (value, gtk_image_definition_get_paintable (priv->image_def));
break; break;
case PROP_ICON_SIZE: case PROP_ICON_SIZE:
g_value_set_enum (value, priv->icon_size); g_value_set_enum (value, priv->icon_size);
@ -263,11 +263,8 @@ notify_storage_type (GtkCellRendererPixbuf *cellpixbuf,
{ {
switch (storage_type) switch (storage_type)
{ {
case GTK_IMAGE_TEXTURE:
g_object_notify (G_OBJECT (cellpixbuf), "texture");
break;
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
g_object_notify (G_OBJECT (cellpixbuf), "paintable"); g_object_notify (G_OBJECT (cellpixbuf), "texture");
break; break;
case GTK_IMAGE_ICON_NAME: case GTK_IMAGE_ICON_NAME:
g_object_notify (G_OBJECT (cellpixbuf), "icon-name"); g_object_notify (G_OBJECT (cellpixbuf), "icon-name");
@ -335,7 +332,7 @@ gtk_cell_renderer_pixbuf_set_property (GObject *object,
texture = gdk_texture_new_for_pixbuf (pixbuf); texture = gdk_texture_new_for_pixbuf (pixbuf);
else else
texture = NULL; texture = NULL;
take_image_definition (cellpixbuf, gtk_image_definition_new_texture (texture)); take_image_definition (cellpixbuf, gtk_image_definition_new_paintable (GDK_PAINTABLE (texture)));
break; break;
case PROP_PIXBUF_EXPANDER_OPEN: case PROP_PIXBUF_EXPANDER_OPEN:
if (priv->pixbuf_expander_open) if (priv->pixbuf_expander_open)
@ -348,7 +345,7 @@ gtk_cell_renderer_pixbuf_set_property (GObject *object,
priv->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value); priv->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
break; break;
case PROP_TEXTURE: case PROP_TEXTURE:
take_image_definition (cellpixbuf, gtk_image_definition_new_texture (g_value_get_object (value))); take_image_definition (cellpixbuf, gtk_image_definition_new_paintable (g_value_get_object (value)));
break; break;
case PROP_ICON_SIZE: case PROP_ICON_SIZE:
gtk_cell_renderer_pixbuf_set_icon_size (cellpixbuf, g_value_get_enum (value)); gtk_cell_renderer_pixbuf_set_icon_size (cellpixbuf, g_value_get_enum (value));
@ -530,14 +527,14 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell,
{ {
icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget); icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_open); texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_open);
_gtk_icon_helper_set_texture (icon_helper, texture); _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (texture));
g_object_unref (texture); g_object_unref (texture);
} }
else if (!is_expanded && priv->pixbuf_expander_closed != NULL) else if (!is_expanded && priv->pixbuf_expander_closed != NULL)
{ {
icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget); icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget);
texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_closed); texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_closed);
_gtk_icon_helper_set_texture (icon_helper, texture); _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (texture));
g_object_unref (texture); g_object_unref (texture);
} }
else else

View File

@ -6555,7 +6555,6 @@ gtk_entry_clear_icon (GtkEntry *entry,
: PROP_GICON_SECONDARY]); : PROP_GICON_SECONDARY]);
break; break;
case GTK_IMAGE_TEXTURE:
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
default: default:
g_assert_not_reached (); g_assert_not_reached ();

View File

@ -103,16 +103,6 @@ get_icon_lookup_flags (GtkIconHelper *self,
return flags; return flags;
} }
static GdkPaintable *
ensure_paintable_from_texture (GtkIconHelper *self,
GdkTexture *texture,
int *scale)
{
*scale = gtk_image_definition_get_storage_type (self->def);
return g_object_ref (GDK_PAINTABLE (texture));
}
static GdkPaintable * static GdkPaintable *
ensure_paintable_from_paintable (GtkIconHelper *self, ensure_paintable_from_paintable (GtkIconHelper *self,
GdkPaintable *paintable, GdkPaintable *paintable,
@ -171,11 +161,6 @@ gtk_icon_helper_load_paintable (GtkIconHelper *self,
switch (gtk_image_definition_get_storage_type (self->def)) switch (gtk_image_definition_get_storage_type (self->def))
{ {
case GTK_IMAGE_TEXTURE:
paintable = ensure_paintable_from_texture (self, gtk_image_definition_get_texture (self->def), &scale);
symbolic = FALSE;
break;
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
paintable = ensure_paintable_from_paintable (self, gtk_image_definition_get_paintable (self->def), &scale); paintable = ensure_paintable_from_paintable (self, gtk_image_definition_get_paintable (self->def), &scale);
symbolic = FALSE; symbolic = FALSE;
@ -273,7 +258,6 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
} }
break; break;
case GTK_IMAGE_TEXTURE:
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
default: default:
@ -305,9 +289,6 @@ gtk_icon_helper_paintable_get_intrinsic_width (GdkPaintable *paintable)
switch (gtk_image_definition_get_storage_type (self->def)) switch (gtk_image_definition_get_storage_type (self->def))
{ {
case GTK_IMAGE_TEXTURE:
return gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (gtk_image_definition_get_texture (self->def)));
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
return gdk_paintable_get_intrinsic_width (gtk_image_definition_get_paintable (self->def)); return gdk_paintable_get_intrinsic_width (gtk_image_definition_get_paintable (self->def));
@ -337,9 +318,6 @@ gtk_icon_helper_paintable_get_intrinsic_height (GdkPaintable *paintable)
switch (gtk_image_definition_get_storage_type (self->def)) switch (gtk_image_definition_get_storage_type (self->def))
{ {
case GTK_IMAGE_TEXTURE:
return gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (gtk_image_definition_get_texture (self->def)));
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
return gdk_paintable_get_intrinsic_height (gtk_image_definition_get_paintable (self->def)); return gdk_paintable_get_intrinsic_height (gtk_image_definition_get_paintable (self->def));
@ -368,9 +346,6 @@ static double gtk_icon_helper_paintable_get_intrinsic_aspect_ratio (GdkPaintable
switch (gtk_image_definition_get_storage_type (self->def)) switch (gtk_image_definition_get_storage_type (self->def))
{ {
case GTK_IMAGE_TEXTURE:
return gdk_paintable_get_intrinsic_aspect_ratio (GDK_PAINTABLE (gtk_image_definition_get_texture (self->def)));
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
return gdk_paintable_get_intrinsic_aspect_ratio (gtk_image_definition_get_paintable (self->def)); return gdk_paintable_get_intrinsic_aspect_ratio (gtk_image_definition_get_paintable (self->def));
@ -551,7 +526,6 @@ gtk_icon_helper_measure (GtkIconHelper *self,
} }
break; break;
case GTK_IMAGE_TEXTURE:
case GTK_IMAGE_ICON_NAME: case GTK_IMAGE_ICON_NAME:
case GTK_IMAGE_GICON: case GTK_IMAGE_GICON:
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
@ -626,14 +600,6 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
width = height = get_default_size (self); width = height = get_default_size (self);
break; break;
case GTK_IMAGE_TEXTURE:
{
GdkTexture *texture = gtk_image_definition_get_texture (self->def);
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
}
break;
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
{ {
GdkPaintable *paintable = gtk_image_definition_get_paintable (self->def); GdkPaintable *paintable = gtk_image_definition_get_paintable (self->def);
@ -692,13 +658,6 @@ _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
gtk_icon_helper_take_definition (self, gtk_image_definition_new_icon_name (icon_name)); gtk_icon_helper_take_definition (self, gtk_image_definition_new_icon_name (icon_name));
} }
void
_gtk_icon_helper_set_texture (GtkIconHelper *self,
GdkTexture *texture)
{
gtk_icon_helper_take_definition (self, gtk_image_definition_new_texture (texture));
}
void void
_gtk_icon_helper_set_paintable (GtkIconHelper *self, _gtk_icon_helper_set_paintable (GtkIconHelper *self,
GdkPaintable *paintable) GdkPaintable *paintable)
@ -762,12 +721,6 @@ _gtk_icon_helper_peek_gicon (GtkIconHelper *self)
return gtk_image_definition_get_gicon (self->def); return gtk_image_definition_get_gicon (self->def);
} }
GdkTexture *
_gtk_icon_helper_peek_texture (GtkIconHelper *self)
{
return gtk_image_definition_get_texture (self->def);
}
GdkPaintable * GdkPaintable *
_gtk_icon_helper_peek_paintable (GtkIconHelper *self) _gtk_icon_helper_peek_paintable (GtkIconHelper *self)
{ {

View File

@ -46,8 +46,6 @@ void _gtk_icon_helper_set_gicon (GtkIconHelper *self,
void _gtk_icon_helper_set_icon_name (GtkIconHelper *self, void _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
const gchar *icon_name); const gchar *icon_name);
void _gtk_icon_helper_set_texture (GtkIconHelper *self,
GdkTexture *texture);
void _gtk_icon_helper_set_paintable (GtkIconHelper *self, void _gtk_icon_helper_set_paintable (GtkIconHelper *self,
GdkPaintable *paintable); GdkPaintable *paintable);
@ -61,7 +59,6 @@ gint _gtk_icon_helper_get_pixel_size (GtkIconHelper *self);
gboolean _gtk_icon_helper_get_use_fallback (GtkIconHelper *self); gboolean _gtk_icon_helper_get_use_fallback (GtkIconHelper *self);
GIcon *_gtk_icon_helper_peek_gicon (GtkIconHelper *self); GIcon *_gtk_icon_helper_peek_gicon (GtkIconHelper *self);
GdkTexture *_gtk_icon_helper_peek_texture (GtkIconHelper *self);
GdkPaintable *_gtk_icon_helper_peek_paintable (GtkIconHelper *self); GdkPaintable *_gtk_icon_helper_peek_paintable (GtkIconHelper *self);
GtkImageDefinition *gtk_icon_helper_get_definition (GtkIconHelper *self); GtkImageDefinition *gtk_icon_helper_get_definition (GtkIconHelper *self);

View File

@ -1205,7 +1205,6 @@ gtk_image_notify_for_storage_type (GtkImage *image,
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PAINTABLE]); g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PAINTABLE]);
break; break;
case GTK_IMAGE_TEXTURE:
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
default: default:
break; break;

View File

@ -55,8 +55,6 @@ typedef struct _GtkImageClass GtkImageClass;
* This image type was added in GTK+ 2.6 * This image type was added in GTK+ 2.6
* @GTK_IMAGE_GICON: the widget contains a #GIcon. * @GTK_IMAGE_GICON: the widget contains a #GIcon.
* This image type was added in GTK+ 2.14 * This image type was added in GTK+ 2.14
* @GTK_IMAGE_TEXTURE: the widget contains a #GdkTexture.
* This image type was added in GTK+ 3.94
* @GTK_IMAGE_PAINTABLE: the widget contains a #GdkPaintable. * @GTK_IMAGE_PAINTABLE: the widget contains a #GdkPaintable.
* This image type was added in GTK+ 3.96 * This image type was added in GTK+ 3.96
* *
@ -73,7 +71,6 @@ typedef enum
GTK_IMAGE_EMPTY, GTK_IMAGE_EMPTY,
GTK_IMAGE_ICON_NAME, GTK_IMAGE_ICON_NAME,
GTK_IMAGE_GICON, GTK_IMAGE_GICON,
GTK_IMAGE_TEXTURE,
GTK_IMAGE_PAINTABLE GTK_IMAGE_PAINTABLE
} GtkImageType; } GtkImageType;

View File

@ -22,7 +22,6 @@
typedef struct _GtkImageDefinitionEmpty GtkImageDefinitionEmpty; typedef struct _GtkImageDefinitionEmpty GtkImageDefinitionEmpty;
typedef struct _GtkImageDefinitionIconName GtkImageDefinitionIconName; typedef struct _GtkImageDefinitionIconName GtkImageDefinitionIconName;
typedef struct _GtkImageDefinitionGIcon GtkImageDefinitionGIcon; typedef struct _GtkImageDefinitionGIcon GtkImageDefinitionGIcon;
typedef struct _GtkImageDefinitionTexture GtkImageDefinitionTexture;
typedef struct _GtkImageDefinitionPaintable GtkImageDefinitionPaintable; typedef struct _GtkImageDefinitionPaintable GtkImageDefinitionPaintable;
struct _GtkImageDefinitionEmpty { struct _GtkImageDefinitionEmpty {
@ -44,13 +43,6 @@ struct _GtkImageDefinitionGIcon {
GIcon *gicon; GIcon *gicon;
}; };
struct _GtkImageDefinitionTexture {
GtkImageType type;
gint ref_count;
GdkTexture *texture;
};
struct _GtkImageDefinitionPaintable { struct _GtkImageDefinitionPaintable {
GtkImageType type; GtkImageType type;
gint ref_count; gint ref_count;
@ -64,7 +56,6 @@ union _GtkImageDefinition
GtkImageDefinitionEmpty empty; GtkImageDefinitionEmpty empty;
GtkImageDefinitionIconName icon_name; GtkImageDefinitionIconName icon_name;
GtkImageDefinitionGIcon gicon; GtkImageDefinitionGIcon gicon;
GtkImageDefinitionTexture texture;
GtkImageDefinitionPaintable paintable; GtkImageDefinitionPaintable paintable;
}; };
@ -83,7 +74,6 @@ gtk_image_definition_alloc (GtkImageType type)
sizeof (GtkImageDefinitionEmpty), sizeof (GtkImageDefinitionEmpty),
sizeof (GtkImageDefinitionIconName), sizeof (GtkImageDefinitionIconName),
sizeof (GtkImageDefinitionGIcon), sizeof (GtkImageDefinitionGIcon),
sizeof (GtkImageDefinitionTexture),
sizeof (GtkImageDefinitionPaintable) sizeof (GtkImageDefinitionPaintable)
}; };
GtkImageDefinition *def; GtkImageDefinition *def;
@ -125,20 +115,6 @@ gtk_image_definition_new_gicon (GIcon *gicon)
return def; return def;
} }
GtkImageDefinition *
gtk_image_definition_new_texture (GdkTexture *texture)
{
GtkImageDefinition *def;
if (texture == NULL)
return NULL;
def = gtk_image_definition_alloc (GTK_IMAGE_TEXTURE);
def->texture.texture = g_object_ref (texture);
return def;
}
GtkImageDefinition * GtkImageDefinition *
gtk_image_definition_new_paintable (GdkPaintable *paintable) gtk_image_definition_new_paintable (GdkPaintable *paintable)
{ {
@ -175,9 +151,6 @@ gtk_image_definition_unref (GtkImageDefinition *def)
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
g_assert_not_reached (); g_assert_not_reached ();
break; break;
case GTK_IMAGE_TEXTURE:
g_object_unref (def->texture.texture);
break;
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
g_object_unref (def->paintable.paintable); g_object_unref (def->paintable.paintable);
break; break;
@ -207,7 +180,6 @@ gtk_image_definition_get_scale (const GtkImageDefinition *def)
g_assert_not_reached (); g_assert_not_reached ();
case GTK_IMAGE_EMPTY: case GTK_IMAGE_EMPTY:
case GTK_IMAGE_PAINTABLE: case GTK_IMAGE_PAINTABLE:
case GTK_IMAGE_TEXTURE:
case GTK_IMAGE_ICON_NAME: case GTK_IMAGE_ICON_NAME:
case GTK_IMAGE_GICON: case GTK_IMAGE_GICON:
return 1; return 1;
@ -232,15 +204,6 @@ gtk_image_definition_get_gicon (const GtkImageDefinition *def)
return def->gicon.gicon; return def->gicon.gicon;
} }
GdkTexture *
gtk_image_definition_get_texture (const GtkImageDefinition *def)
{
if (def->type != GTK_IMAGE_TEXTURE)
return NULL;
return def->texture.texture;
}
GdkPaintable * GdkPaintable *
gtk_image_definition_get_paintable (const GtkImageDefinition *def) gtk_image_definition_get_paintable (const GtkImageDefinition *def)
{ {

View File

@ -28,7 +28,6 @@ typedef union _GtkImageDefinition GtkImageDefinition;
GtkImageDefinition * gtk_image_definition_new_empty (void); GtkImageDefinition * gtk_image_definition_new_empty (void);
GtkImageDefinition * gtk_image_definition_new_icon_name (const char *icon_name); GtkImageDefinition * gtk_image_definition_new_icon_name (const char *icon_name);
GtkImageDefinition * gtk_image_definition_new_gicon (GIcon *gicon); GtkImageDefinition * gtk_image_definition_new_gicon (GIcon *gicon);
GtkImageDefinition * gtk_image_definition_new_texture (GdkTexture *texture);
GtkImageDefinition * gtk_image_definition_new_paintable (GdkPaintable *paintable); GtkImageDefinition * gtk_image_definition_new_paintable (GdkPaintable *paintable);
GtkImageDefinition * gtk_image_definition_ref (GtkImageDefinition *def); GtkImageDefinition * gtk_image_definition_ref (GtkImageDefinition *def);
@ -38,7 +37,6 @@ GtkImageType gtk_image_definition_get_storage_type (const GtkImageD
gint gtk_image_definition_get_scale (const GtkImageDefinition *def); gint gtk_image_definition_get_scale (const GtkImageDefinition *def);
const gchar * gtk_image_definition_get_icon_name (const GtkImageDefinition *def); const gchar * gtk_image_definition_get_icon_name (const GtkImageDefinition *def);
GIcon * gtk_image_definition_get_gicon (const GtkImageDefinition *def); GIcon * gtk_image_definition_get_gicon (const GtkImageDefinition *def);
GdkTexture * gtk_image_definition_get_texture (const GtkImageDefinition *def);
GdkPaintable * gtk_image_definition_get_paintable (const GtkImageDefinition *def); GdkPaintable * gtk_image_definition_get_paintable (const GtkImageDefinition *def);