From 42947e3cdc2109bd611b0fd978a64b32b438a835 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 22 Aug 2010 03:53:45 +0200 Subject: [PATCH] API: Add gtk_cell_renderer_render_cairo() It's like gtk_cell_renderer_render(), just cooler. --- gtk/gtkcellrenderer.c | 53 +++++++++++++++++++++++++++++++++++++++---- gtk/gtkcellrenderer.h | 6 +++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c index 804e50b6bf..1431e3848a 100644 --- a/gtk/gtkcellrenderer.c +++ b/gtk/gtkcellrenderer.c @@ -639,19 +639,62 @@ gtk_cell_renderer_render (GtkCellRenderer *cell, const GdkRectangle *expose_area, GtkCellRendererState flags) { - gboolean selected = FALSE; - GtkCellRendererPrivate *priv = cell->priv; cairo_t *cr; g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL); - selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED; - cr = gdk_cairo_create (window); gdk_cairo_rectangle (cr, expose_area); cairo_clip (cr); + gtk_cell_renderer_render_cairo (cell, + cr, + widget, + background_area, + cell_area, + flags); + + cairo_destroy (cr); +} + +/** + * gtk_cell_renderer_render_cairo: + * @cell: a #GtkCellRenderer + * @cr: a cairo context to draw to + * @widget: the widget owning @window + * @background_area: entire cell area (including tree expanders and maybe + * padding on the sides) + * @cell_area: area normally rendered by a cell renderer + * @flags: flags that affect rendering + * + * Invokes the virtual render function of the #GtkCellRenderer. The three + * passed-in rectangles are areas in @cr. Most renderers will draw within + * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer + * should be honored with respect to @cell_area. @background_area includes the + * blank space around the cell, and also the area containing the tree expander; + * so the @background_area rectangles for all cells tile to cover the entire + * @window. + **/ +void +gtk_cell_renderer_render_cairo (GtkCellRenderer *cell, + cairo_t *cr, + GtkWidget *widget, + const GdkRectangle *background_area, + const GdkRectangle *cell_area, + GtkCellRendererState flags) +{ + gboolean selected = FALSE; + GtkCellRendererPrivate *priv = cell->priv; + + g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); + g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL); + g_return_if_fail (cr != NULL); + + selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED; + + cairo_save (cr); + if (priv->cell_background_set && !selected) { gdk_cairo_rectangle (cr, background_area); @@ -666,7 +709,7 @@ gtk_cell_renderer_render (GtkCellRenderer *cell, cell_area, flags); - cairo_destroy (cr); + cairo_restore (cr); } /** diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h index 49a043f8a7..a226173c39 100644 --- a/gtk/gtkcellrenderer.h +++ b/gtk/gtkcellrenderer.h @@ -126,6 +126,12 @@ void gtk_cell_renderer_render (GtkCellRenderer *cell, const GdkRectangle *cell_area, const GdkRectangle *expose_area, GtkCellRendererState flags); +void gtk_cell_renderer_render_cairo (GtkCellRenderer *cell, + cairo_t *cr, + GtkWidget *widget, + const GdkRectangle *background_area, + const GdkRectangle *cell_area, + GtkCellRendererState flags); gboolean gtk_cell_renderer_activate (GtkCellRenderer *cell, GdkEvent *event, GtkWidget *widget,