cellrenderer: Remove render() vfunc

Make the last 2 cell renderers create the cairo node themselves.
This commit is contained in:
Benjamin Otte 2016-12-23 11:11:52 +01:00
parent 513a8c46af
commit a36e5ceea7
4 changed files with 37 additions and 65 deletions

View File

@ -83,12 +83,6 @@ static void gtk_cell_renderer_set_property (GObject *object,
static void set_cell_bg_color (GtkCellRenderer *cell, static void set_cell_bg_color (GtkCellRenderer *cell,
GdkRGBA *rgba); GdkRGBA *rgba);
static void gtk_cell_renderer_real_snapshot (GtkCellRenderer *cell,
GtkSnapshot *snapshot,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
/* Fallback GtkCellRenderer implementation to use remaining ->get_size() implementations */ /* Fallback GtkCellRenderer implementation to use remaining ->get_size() implementations */
static GtkSizeRequestMode gtk_cell_renderer_real_get_request_mode(GtkCellRenderer *cell); static GtkSizeRequestMode gtk_cell_renderer_real_get_request_mode(GtkCellRenderer *cell);
static void gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell, static void gtk_cell_renderer_real_get_preferred_width (GtkCellRenderer *cell,
@ -208,8 +202,7 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
object_class->get_property = gtk_cell_renderer_get_property; object_class->get_property = gtk_cell_renderer_get_property;
object_class->set_property = gtk_cell_renderer_set_property; object_class->set_property = gtk_cell_renderer_set_property;
class->render = NULL; class->snapshot = NULL;
class->snapshot = gtk_cell_renderer_real_snapshot;
class->get_size = NULL; class->get_size = NULL;
class->get_request_mode = gtk_cell_renderer_real_get_request_mode; class->get_request_mode = gtk_cell_renderer_real_get_request_mode;
class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width; class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
@ -1255,30 +1248,6 @@ gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
} }
} }
static void
gtk_cell_renderer_real_snapshot (GtkCellRenderer *cell,
GtkSnapshot *snapshot,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
cairo_t *cr;
g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
cr = gtk_snapshot_append_cairo_node (snapshot,
&GRAPHENE_RECT_INIT (
background_area->x,
background_area->y,
background_area->width,
background_area->height
),
"CellFallback<%s>", G_OBJECT_TYPE_NAME (cell));
GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell, cr, widget, background_area, cell_area, flags);
cairo_destroy (cr);
}
static void static void
gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell, gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
GtkWidget *widget, GtkWidget *widget,

View File

@ -100,7 +100,7 @@ struct _GtkCellRenderer
* @get_preferred_width_for_height: Called to get a renderers natural width for height. * @get_preferred_width_for_height: Called to get a renderers natural width for height.
* @get_aligned_area: Called to get the aligned area used by @cell inside @cell_area. * @get_aligned_area: Called to get the aligned area used by @cell inside @cell_area.
* @get_size: Called to get the width and height needed to render the cell. Deprecated: 3.0. * @get_size: Called to get the width and height needed to render the cell. Deprecated: 3.0.
* @render: Called to render the content of the #GtkCellRenderer. * @snapshot: Called to snapshot the content of the #GtkCellRenderer.
* @activate: Called to activate the content of the #GtkCellRenderer. * @activate: Called to activate the content of the #GtkCellRenderer.
* @start_editing: Called to initiate editing the content of the #GtkCellRenderer. * @start_editing: Called to initiate editing the content of the #GtkCellRenderer.
* @editing_canceled: Signal gets emitted when the user cancels the process of editing a cell. * @editing_canceled: Signal gets emitted when the user cancels the process of editing a cell.
@ -145,12 +145,6 @@ struct _GtkCellRendererClass
gint *y_offset, gint *y_offset,
gint *width, gint *width,
gint *height); gint *height);
void (* render) (GtkCellRenderer *cell,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
void (* snapshot) (GtkCellRenderer *cell, void (* snapshot) (GtkCellRenderer *cell,
GtkSnapshot *snapshot, GtkSnapshot *snapshot,
GtkWidget *widget, GtkWidget *widget,

View File

@ -31,15 +31,11 @@
#include "gtkicontheme.h" #include "gtkicontheme.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtksettings.h" #include "gtksettings.h"
#include "gtksnapshot.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include <math.h> #include <math.h>
#undef GDK_DEPRECATED
#undef GDK_DEPRECATED_FOR
#define GDK_DEPRECATED
#define GDK_DEPRECATED_FOR(f)
/** /**
* SECTION:gtkcellrendererspinner * SECTION:gtkcellrendererspinner
* @Short_description: Renders a spinning animation in a cell * @Short_description: Renders a spinning animation in a cell
@ -90,8 +86,8 @@ static void gtk_cell_renderer_spinner_get_size (GtkCellRenderer *cell,
gint *y_offset, gint *y_offset,
gint *width, gint *width,
gint *height); gint *height);
static void gtk_cell_renderer_spinner_render (GtkCellRenderer *cell, static void gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cell,
cairo_t *cr, GtkSnapshot *snapshot,
GtkWidget *widget, GtkWidget *widget,
const GdkRectangle *background_area, const GdkRectangle *background_area,
const GdkRectangle *cell_area, const GdkRectangle *cell_area,
@ -109,7 +105,7 @@ gtk_cell_renderer_spinner_class_init (GtkCellRendererSpinnerClass *klass)
object_class->set_property = gtk_cell_renderer_spinner_set_property; object_class->set_property = gtk_cell_renderer_spinner_set_property;
cell_class->get_size = gtk_cell_renderer_spinner_get_size; cell_class->get_size = gtk_cell_renderer_spinner_get_size;
cell_class->render = gtk_cell_renderer_spinner_render; cell_class->snapshot = gtk_cell_renderer_spinner_snapshot;
/* GtkCellRendererSpinner:active: /* GtkCellRendererSpinner:active:
* *
@ -388,18 +384,19 @@ gtk_paint_spinner (GtkStyleContext *context,
} }
static void static void
gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr, gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cellr,
cairo_t *cr, GtkSnapshot *snapshot,
GtkWidget *widget, GtkWidget *widget,
const GdkRectangle *background_area, const GdkRectangle *background_area,
const GdkRectangle *cell_area, const GdkRectangle *cell_area,
GtkCellRendererState flags) GtkCellRendererState flags)
{ {
GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (cellr); GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (cellr);
GtkCellRendererSpinnerPrivate *priv = cell->priv; GtkCellRendererSpinnerPrivate *priv = cell->priv;
GdkRectangle pix_rect; GdkRectangle pix_rect;
GdkRectangle draw_rect; GdkRectangle draw_rect;
gint xpad, ypad; gint xpad, ypad;
cairo_t *cr;
if (!priv->active) if (!priv->active)
return; return;
@ -420,10 +417,12 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect)) if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
return; return;
cairo_save (cr); cr = gtk_snapshot_append_cairo_node (snapshot,
&GRAPHENE_RECT_INIT (
gdk_cairo_rectangle (cr, cell_area); cell_area->x, cell_area->y,
cairo_clip (cr); cell_area->width, cell_area->height
),
"CellSpinner");
gtk_paint_spinner (gtk_widget_get_style_context (widget), gtk_paint_spinner (gtk_widget_get_style_context (widget),
cr, cr,
@ -431,5 +430,5 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
draw_rect.x, draw_rect.y, draw_rect.x, draw_rect.y,
draw_rect.width, draw_rect.height); draw_rect.width, draw_rect.height);
cairo_restore (cr); cairo_destroy (cr);
} }

View File

@ -153,12 +153,12 @@ gtk_cell_renderer_graph_get_size (GtkCellRenderer *cell,
} }
static void static void
gtk_cell_renderer_graph_render (GtkCellRenderer *cell, gtk_cell_renderer_graph_snapshot (GtkCellRenderer *cell,
cairo_t *cr, GtkSnapshot *snapshot,
GtkWidget *widget, GtkWidget *widget,
const GdkRectangle *background_area, const GdkRectangle *background_area,
const GdkRectangle *cell_area, const GdkRectangle *cell_area,
GtkCellRendererState flags) GtkCellRendererState flags)
{ {
GtkCellRendererGraph *graph = GTK_CELL_RENDERER_GRAPH (cell); GtkCellRendererGraph *graph = GTK_CELL_RENDERER_GRAPH (cell);
GtkCellRendererGraphPrivate *priv = graph->priv; GtkCellRendererGraphPrivate *priv = graph->priv;
@ -166,6 +166,7 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
double minimum, maximum, diff; double minimum, maximum, diff;
double x, y, width, height; double x, y, width, height;
int xpad, ypad; int xpad, ypad;
cairo_t *cr;
GdkRGBA color; GdkRGBA color;
guint i, n; guint i, n;
@ -194,6 +195,13 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_style_context_get_color (context, &color); gtk_style_context_get_color (context, &color);
cr = gtk_snapshot_append_cairo_node (snapshot,
&GRAPHENE_RECT_INIT (
background_area->x, background_area->y,
background_area->width, background_area->height
),
"CellGraph");
cairo_set_line_width (cr, 1.0); cairo_set_line_width (cr, 1.0);
x = background_area->x + xpad + LINE_WIDTH / 2.0; x = background_area->x + xpad + LINE_WIDTH / 2.0;
@ -226,6 +234,8 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
color.alpha *= 0.2; color.alpha *= 0.2;
gdk_cairo_set_source_rgba (cr, &color); gdk_cairo_set_source_rgba (cr, &color);
cairo_fill (cr); cairo_fill (cr);
cairo_destroy (cr);
} }
static void static void
@ -239,7 +249,7 @@ gtk_cell_renderer_graph_class_init (GtkCellRendererGraphClass *klass)
object_class->set_property = gtk_cell_renderer_graph_set_property; object_class->set_property = gtk_cell_renderer_graph_set_property;
cell_class->get_size = gtk_cell_renderer_graph_get_size; cell_class->get_size = gtk_cell_renderer_graph_get_size;
cell_class->render = gtk_cell_renderer_graph_render; cell_class->snapshot = gtk_cell_renderer_graph_snapshot;
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_DATA, PROP_DATA,