[gtk+] cellrenderer: Remove render() vfunc
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cellrenderer: Remove render() vfunc
- Date: Fri, 23 Dec 2016 10:14:23 +0000 (UTC)
commit a36e5ceea74fecb7b8f5f196e592a4b633ed6eb3
Author: Benjamin Otte <otte redhat com>
Date: Fri Dec 23 11:11:52 2016 +0100
cellrenderer: Remove render() vfunc
Make the last 2 cell renderers create the cairo node themselves.
gtk/gtkcellrenderer.c | 33 +--------------------------------
gtk/gtkcellrenderer.h | 8 +-------
gtk/gtkcellrendererspinner.c | 37 ++++++++++++++++++-------------------
gtk/inspector/cellrenderergraph.c | 24 +++++++++++++++++-------
4 files changed, 37 insertions(+), 65 deletions(-)
---
diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c
index 048f82a..7c0f776 100644
--- a/gtk/gtkcellrenderer.c
+++ b/gtk/gtkcellrenderer.c
@@ -83,12 +83,6 @@ static void gtk_cell_renderer_set_property (GObject *object,
static void set_cell_bg_color (GtkCellRenderer *cell,
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 */
static GtkSizeRequestMode gtk_cell_renderer_real_get_request_mode(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->set_property = gtk_cell_renderer_set_property;
- class->render = NULL;
- class->snapshot = gtk_cell_renderer_real_snapshot;
+ class->snapshot = NULL;
class->get_size = NULL;
class->get_request_mode = gtk_cell_renderer_real_get_request_mode;
class->get_preferred_width = gtk_cell_renderer_real_get_preferred_width;
@@ -1256,30 +1249,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
gtk_cell_renderer_real_get_preferred_size (GtkCellRenderer *cell,
GtkWidget *widget,
GtkOrientation orientation,
diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h
index 6ac40b3..cc71027 100644
--- a/gtk/gtkcellrenderer.h
+++ b/gtk/gtkcellrenderer.h
@@ -100,7 +100,7 @@ struct _GtkCellRenderer
* @get_preferred_width_for_height: Called to get a renderer’s natural width for height.
* @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.
- * @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.
* @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.
@@ -145,12 +145,6 @@ struct _GtkCellRendererClass
gint *y_offset,
gint *width,
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,
GtkSnapshot *snapshot,
GtkWidget *widget,
diff --git a/gtk/gtkcellrendererspinner.c b/gtk/gtkcellrendererspinner.c
index 3e86a4f..8803d36 100644
--- a/gtk/gtkcellrendererspinner.c
+++ b/gtk/gtkcellrendererspinner.c
@@ -31,15 +31,11 @@
#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtksettings.h"
+#include "gtksnapshot.h"
#include "gtktypebuiltins.h"
#include <math.h>
-#undef GDK_DEPRECATED
-#undef GDK_DEPRECATED_FOR
-#define GDK_DEPRECATED
-#define GDK_DEPRECATED_FOR(f)
-
/**
* SECTION:gtkcellrendererspinner
* @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 *width,
gint *height);
-static void gtk_cell_renderer_spinner_render (GtkCellRenderer *cell,
- cairo_t *cr,
+static void gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cell,
+ GtkSnapshot *snapshot,
GtkWidget *widget,
const GdkRectangle *background_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;
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:
*
@@ -388,18 +384,19 @@ gtk_paint_spinner (GtkStyleContext *context,
}
static void
-gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
- cairo_t *cr,
- GtkWidget *widget,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags)
+gtk_cell_renderer_spinner_snapshot (GtkCellRenderer *cellr,
+ GtkSnapshot *snapshot,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
{
GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (cellr);
GtkCellRendererSpinnerPrivate *priv = cell->priv;
GdkRectangle pix_rect;
GdkRectangle draw_rect;
gint xpad, ypad;
+ cairo_t *cr;
if (!priv->active)
return;
@@ -420,10 +417,12 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
return;
- cairo_save (cr);
-
- gdk_cairo_rectangle (cr, cell_area);
- cairo_clip (cr);
+ cr = gtk_snapshot_append_cairo_node (snapshot,
+ &GRAPHENE_RECT_INIT (
+ cell_area->x, cell_area->y,
+ cell_area->width, cell_area->height
+ ),
+ "CellSpinner");
gtk_paint_spinner (gtk_widget_get_style_context (widget),
cr,
@@ -431,5 +430,5 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
draw_rect.x, draw_rect.y,
draw_rect.width, draw_rect.height);
- cairo_restore (cr);
+ cairo_destroy (cr);
}
diff --git a/gtk/inspector/cellrenderergraph.c b/gtk/inspector/cellrenderergraph.c
index 766bd05..08e4e8d 100644
--- a/gtk/inspector/cellrenderergraph.c
+++ b/gtk/inspector/cellrenderergraph.c
@@ -153,12 +153,12 @@ gtk_cell_renderer_graph_get_size (GtkCellRenderer *cell,
}
static void
-gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
- cairo_t *cr,
- GtkWidget *widget,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags)
+gtk_cell_renderer_graph_snapshot (GtkCellRenderer *cell,
+ GtkSnapshot *snapshot,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
{
GtkCellRendererGraph *graph = GTK_CELL_RENDERER_GRAPH (cell);
GtkCellRendererGraphPrivate *priv = graph->priv;
@@ -166,6 +166,7 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
double minimum, maximum, diff;
double x, y, width, height;
int xpad, ypad;
+ cairo_t *cr;
GdkRGBA color;
guint i, n;
@@ -194,6 +195,13 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
context = gtk_widget_get_style_context (widget);
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);
x = background_area->x + xpad + LINE_WIDTH / 2.0;
@@ -226,6 +234,8 @@ gtk_cell_renderer_graph_render (GtkCellRenderer *cell,
color.alpha *= 0.2;
gdk_cairo_set_source_rgba (cr, &color);
cairo_fill (cr);
+
+ cairo_destroy (cr);
}
static void
@@ -239,7 +249,7 @@ gtk_cell_renderer_graph_class_init (GtkCellRendererGraphClass *klass)
object_class->set_property = gtk_cell_renderer_graph_set_property;
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,
PROP_DATA,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]