forked from AuroraMiddleware/gtk
Make GtkCellRendererPixbuf use GtkStyleContext
This commit is contained in:
parent
3285eff289
commit
c59a05b0d4
@ -548,7 +548,7 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
|
|||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
||||||
GtkWidget *widget,
|
GtkWidget *widget,
|
||||||
GtkStateType state)
|
GtkStateFlags state)
|
||||||
{
|
{
|
||||||
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
|
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
@ -604,11 +604,17 @@ create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
|||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (GTK_WIDGET (widget));
|
context = gtk_widget_get_style_context (GTK_WIDGET (widget));
|
||||||
|
|
||||||
|
gtk_style_context_save (context);
|
||||||
|
gtk_style_context_set_state (context, state);
|
||||||
pixbuf = gtk_icon_info_load_symbolic_for_context (info,
|
pixbuf = gtk_icon_info_load_symbolic_for_context (info,
|
||||||
context,
|
context,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
gtk_style_context_restore (context);
|
||||||
gtk_icon_info_free (info);
|
gtk_icon_info_free (info);
|
||||||
|
|
||||||
return pixbuf;
|
return pixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,8 +622,8 @@ create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
create_colorized_pixbuf (GdkPixbuf *src,
|
create_colorized_pixbuf (GdkPixbuf *src,
|
||||||
GdkColor *new_color)
|
GdkRGBA *new_color)
|
||||||
{
|
{
|
||||||
gint i, j;
|
gint i, j;
|
||||||
gint width, height, has_alpha, src_row_stride, dst_row_stride;
|
gint width, height, has_alpha, src_row_stride, dst_row_stride;
|
||||||
@ -627,11 +633,11 @@ create_colorized_pixbuf (GdkPixbuf *src,
|
|||||||
guchar *pixsrc;
|
guchar *pixsrc;
|
||||||
guchar *pixdest;
|
guchar *pixdest;
|
||||||
GdkPixbuf *dest;
|
GdkPixbuf *dest;
|
||||||
|
|
||||||
red_value = new_color->red / 255.0;
|
red_value = (new_color->red * 65535.0) / 255.0;
|
||||||
green_value = new_color->green / 255.0;
|
green_value = (new_color->green * 65535.0) / 255.0;
|
||||||
blue_value = new_color->blue / 255.0;
|
blue_value = (new_color->blue * 65535.0) / 255.0;
|
||||||
|
|
||||||
dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
|
dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
|
||||||
gdk_pixbuf_get_has_alpha (src),
|
gdk_pixbuf_get_has_alpha (src),
|
||||||
gdk_pixbuf_get_bits_per_sample (src),
|
gdk_pixbuf_get_bits_per_sample (src),
|
||||||
@ -750,6 +756,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
|
|||||||
{
|
{
|
||||||
GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
|
GtkCellRendererPixbuf *cellpixbuf = (GtkCellRendererPixbuf *) cell;
|
||||||
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
|
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
|
||||||
|
GtkStyleContext *context;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
GdkPixbuf *invisible = NULL;
|
GdkPixbuf *invisible = NULL;
|
||||||
GdkPixbuf *colorized = NULL;
|
GdkPixbuf *colorized = NULL;
|
||||||
@ -794,7 +801,9 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
|
|||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE ||
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
|
if (!gtk_widget_get_sensitive (widget) ||
|
||||||
!gtk_cell_renderer_get_sensitive (cell))
|
!gtk_cell_renderer_get_sensitive (cell))
|
||||||
{
|
{
|
||||||
GtkIconSource *source;
|
GtkIconSource *source;
|
||||||
@ -808,43 +817,32 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
|
|||||||
gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
||||||
gtk_icon_source_set_size_wildcarded (source, FALSE);
|
gtk_icon_source_set_size_wildcarded (source, FALSE);
|
||||||
|
|
||||||
invisible = gtk_style_render_icon (gtk_widget_get_style (widget),
|
gtk_style_context_save (context);
|
||||||
source,
|
gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
|
||||||
gtk_widget_get_direction (widget),
|
|
||||||
GTK_STATE_INSENSITIVE,
|
pixbuf = invisible = gtk_render_icon_pixbuf (context, source,
|
||||||
/* arbitrary */
|
(GtkIconSize) -1);
|
||||||
(GtkIconSize)-1,
|
|
||||||
widget,
|
gtk_style_context_restore (context);
|
||||||
"gtkcellrendererpixbuf");
|
gtk_icon_source_free (source);
|
||||||
|
|
||||||
gtk_icon_source_free (source);
|
|
||||||
|
|
||||||
pixbuf = invisible;
|
|
||||||
}
|
}
|
||||||
else if (priv->follow_state &&
|
else if (priv->follow_state &&
|
||||||
(flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0)
|
(flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0)
|
||||||
{
|
{
|
||||||
GtkStateType state;
|
GtkStateFlags state;
|
||||||
|
|
||||||
if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
|
|
||||||
{
|
|
||||||
if (gtk_widget_has_focus (widget))
|
|
||||||
state = GTK_STATE_SELECTED;
|
|
||||||
else
|
|
||||||
state = GTK_STATE_ACTIVE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
state = GTK_STATE_PRELIGHT;
|
|
||||||
|
|
||||||
|
state = gtk_cell_renderer_get_state (cell, widget, flags);
|
||||||
symbolic = create_symbolic_pixbuf (cellpixbuf, widget, state);
|
symbolic = create_symbolic_pixbuf (cellpixbuf, widget, state);
|
||||||
if (!symbolic) {
|
|
||||||
colorized = create_colorized_pixbuf (pixbuf,
|
|
||||||
>k_widget_get_style (widget)->base[state]);
|
|
||||||
|
|
||||||
pixbuf = colorized;
|
if (!symbolic)
|
||||||
} else {
|
{
|
||||||
|
GdkRGBA color;
|
||||||
|
|
||||||
|
gtk_style_context_get_background_color (context, state, &color);
|
||||||
|
pixbuf = colorized = create_colorized_pixbuf (pixbuf, &color);
|
||||||
|
}
|
||||||
|
else
|
||||||
pixbuf = symbolic;
|
pixbuf = symbolic;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
|
gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
|
||||||
|
Loading…
Reference in New Issue
Block a user