API: Change cellrenderer->render vfunc to take a cairo_t

Also constify the rectangle arguments. They were const anyway.
This commit is contained in:
Benjamin Otte 2010-08-21 13:18:14 +02:00
parent 4138e86ad4
commit e31e77eeb8
7 changed files with 136 additions and 148 deletions

View File

@ -641,30 +641,32 @@ gtk_cell_renderer_render (GtkCellRenderer *cell,
{
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);
if (priv->cell_background_set && !selected)
{
cairo_t *cr = gdk_cairo_create (window);
gdk_cairo_rectangle (cr, background_area);
gdk_cairo_set_source_color (cr, &priv->cell_background);
cairo_fill (cr);
cairo_destroy (cr);
}
GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
window,
cr,
widget,
(GdkRectangle *) background_area,
(GdkRectangle *) cell_area,
(GdkRectangle *) expose_area,
background_area,
cell_area,
flags);
cairo_destroy (cr);
}
/**

View File

@ -77,11 +77,10 @@ struct _GtkCellRendererClass
gint *width,
gint *height);
void (* render) (GtkCellRenderer *cell,
GdkDrawable *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
gboolean (* activate) (GtkCellRenderer *cell,
GdkEvent *event,

View File

@ -45,11 +45,10 @@ static void gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cel
gint *width,
gint *height);
static void gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
GdkDrawable *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
@ -743,11 +742,10 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
static void
gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
GdkWindow *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
@ -759,11 +757,10 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
GdkPixbuf *symbolic = NULL;
GdkRectangle pix_rect;
GdkRectangle draw_rect;
cairo_t *cr;
gboolean is_expander;
gint xpad, ypad;
gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area,
gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area,
&pix_rect.x,
&pix_rect.y,
&pix_rect.width,
@ -775,8 +772,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
pix_rect.width -= xpad * 2;
pix_rect.height -= ypad * 2;
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect) ||
!gdk_rectangle_intersect (expose_area, &draw_rect, &draw_rect))
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
return;
pixbuf = priv->pixbuf;
@ -852,14 +848,10 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
}
}
cr = gdk_cairo_create (window);
gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
gdk_cairo_rectangle (cr, &draw_rect);
cairo_fill (cr);
cairo_destroy (cr);
if (invisible)
g_object_unref (invisible);

View File

@ -89,11 +89,10 @@ static void gtk_cell_renderer_progress_get_size (GtkCellRenderer *ce
gint *width,
gint *height);
static void gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
GdkWindow *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
guint flags);
@ -527,13 +526,12 @@ get_bar_position (gint start,
}
static void
gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags)
gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
GtkCellRendererProgressPrivate *priv= cellprogress->priv;
@ -559,11 +557,11 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
* but some engines don't paint anything with that detail for
* non-GtkProgressBar widgets.
*/
gtk_paint_box (style,
window,
GTK_STATE_NORMAL, GTK_SHADOW_IN,
NULL, widget, NULL,
x, y, w, h);
gtk_cairo_paint_box (style,
cr,
GTK_STATE_NORMAL, GTK_SHADOW_IN,
widget, NULL,
x, y, w, h);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
@ -606,12 +604,12 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
clip.y = bar_position;
}
gtk_paint_box (style,
window,
GTK_STATE_SELECTED, GTK_SHADOW_OUT,
&clip, widget, "bar",
clip.x, clip.y,
clip.width, clip.height);
gtk_cairo_paint_box (style,
cr,
GTK_STATE_SELECTED, GTK_SHADOW_OUT,
widget, "bar",
clip.x, clip.y,
clip.width, clip.height);
if (priv->label)
{
@ -631,11 +629,17 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
y_pos = y + style->ythickness + priv->text_yalign *
(h - 2 * style->ythickness - logical_rect.height);
gtk_paint_layout (style, window,
GTK_STATE_SELECTED,
FALSE, &clip, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_save (cr);
gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr);
gtk_cairo_paint_layout (style, cr,
GTK_STATE_SELECTED,
FALSE, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_restore (cr);
if (bar_position > start)
{
@ -650,11 +654,17 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
clip.height = bar_position - y;
}
gtk_paint_layout (style, window,
GTK_STATE_NORMAL,
FALSE, &clip, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_save (cr);
gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr);
gtk_cairo_paint_layout (style, cr,
GTK_STATE_NORMAL,
FALSE, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_restore (cr);
}
if (bar_position + bar_size < start + full_size)
@ -670,11 +680,17 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
clip.height = y + h - (bar_position + bar_size);
}
gtk_paint_layout (style, window,
GTK_STATE_NORMAL,
FALSE, &clip, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_save (cr);
gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr);
gtk_cairo_paint_layout (style, cr,
GTK_STATE_NORMAL,
FALSE, widget, "progressbar",
x_pos, y_pos,
layout);
cairo_restore (cr);
}
g_object_unref (layout);

View File

@ -85,13 +85,12 @@ 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,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags);
static void gtk_cell_renderer_spinner_render (GtkCellRenderer *cell,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
G_DEFINE_TYPE (GtkCellRendererSpinner, gtk_cell_renderer_spinner, GTK_TYPE_CELL_RENDERER)
@ -320,13 +319,12 @@ gtk_cell_renderer_spinner_get_size (GtkCellRenderer *cellr,
}
static void
gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
GdkWindow *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
guint flags)
gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererSpinner *cell = GTK_CELL_RENDERER_SPINNER (cellr);
GtkCellRendererSpinnerPrivate *priv = cell->priv;
@ -338,7 +336,7 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
if (!priv->active)
return;
gtk_cell_renderer_spinner_get_size (cellr, widget, cell_area,
gtk_cell_renderer_spinner_get_size (cellr, widget, (GdkRectangle *) cell_area,
&pix_rect.x, &pix_rect.y,
&pix_rect.width, &pix_rect.height);
@ -351,11 +349,8 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
pix_rect.width -= xpad * 2;
pix_rect.height -= ypad * 2;
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect) ||
!gdk_rectangle_intersect (expose_area, &pix_rect, &draw_rect))
{
return;
}
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
return;
state = GTK_STATE_NORMAL;
if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE ||
@ -376,13 +371,12 @@ gtk_cell_renderer_spinner_render (GtkCellRenderer *cellr,
state = GTK_STATE_PRELIGHT;
}
gtk_paint_spinner (gtk_widget_get_style (widget),
window,
state,
expose_area,
widget,
"cell",
priv->pulse,
draw_rect.x, draw_rect.y,
draw_rect.width, draw_rect.height);
gtk_cairo_paint_spinner (gtk_widget_get_style (widget),
cr,
state,
widget,
"cell",
priv->pulse,
draw_rect.x, draw_rect.y,
draw_rect.width, draw_rect.height);
}

View File

@ -44,11 +44,10 @@ static void gtk_cell_renderer_text_set_property (GObject *obje
const GValue *value,
GParamSpec *pspec);
static void gtk_cell_renderer_text_render (GtkCellRenderer *cell,
GdkWindow *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
@ -1434,7 +1433,7 @@ add_attr (PangoAttrList *attr_list,
static PangoLayout*
get_layout (GtkCellRendererText *celltext,
GtkWidget *widget,
GdkRectangle *cell_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererTextPrivate *priv = celltext->priv;
@ -1694,11 +1693,10 @@ get_size (GtkCellRenderer *cell,
static void
gtk_cell_renderer_text_render (GtkCellRenderer *cell,
GdkDrawable *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
@ -1711,7 +1709,7 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
gint xpad, ypad;
layout = get_layout (celltext, widget, cell_area, flags);
get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
get_size (cell, widget, (GdkRectangle *) cell_area, layout, &x_offset, &y_offset, NULL, NULL);
if (!gtk_cell_renderer_get_sensitive (cell))
{
@ -1740,22 +1738,12 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
if (priv->background_set &&
(flags & GTK_CELL_RENDERER_SELECTED) == 0)
{
cairo_t *cr = gdk_cairo_create (window);
if (expose_area)
{
gdk_cairo_rectangle (cr, expose_area);
cairo_clip (cr);
}
gdk_cairo_rectangle (cr, background_area);
cairo_set_source_rgb (cr,
priv->background.red / 65535.,
priv->background.green / 65535.,
priv->background.blue / 65535.);
cairo_fill (cr);
cairo_destroy (cr);
}
gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
@ -1766,16 +1754,15 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
else if (priv->wrap_width == -1)
pango_layout_set_width (layout, -1);
gtk_paint_layout (gtk_widget_get_style (widget),
window,
state,
TRUE,
expose_area,
widget,
"cellrenderertext",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
layout);
gtk_cairo_paint_layout (gtk_widget_get_style (widget),
cr,
state,
TRUE,
widget,
"cellrenderertext",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
layout);
g_object_unref (layout);
}
@ -2145,7 +2132,7 @@ gtk_cell_renderer_text_get_height_for_width (GtkCellSizeRequest *cell,
gtk_cell_renderer_get_padding (GTK_CELL_RENDERER (cell), &xpad, &ypad);
layout = get_layout (celltext, widget, FALSE, 0);
layout = get_layout (celltext, widget, NULL, 0);
pango_layout_set_width (layout, (width - xpad * 2) * PANGO_SCALE);
pango_layout_get_pixel_size (layout, NULL, &text_height);

View File

@ -42,11 +42,10 @@ static void gtk_cell_renderer_toggle_get_size (GtkCellRenderer *cel
gint *width,
gint *height);
static void gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
GdkWindow *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
static gboolean gtk_cell_renderer_toggle_activate (GtkCellRenderer *cell,
GdkEvent *event,
@ -324,11 +323,10 @@ gtk_cell_renderer_toggle_get_size (GtkCellRenderer *cell,
static void
gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
GdkDrawable *window,
cairo_t *cr,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
@ -339,7 +337,7 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
GtkShadowType shadow;
GtkStateType state = 0;
gtk_cell_renderer_toggle_get_size (cell, widget, cell_area,
gtk_cell_renderer_toggle_get_size (cell, widget, (GdkRectangle *) cell_area,
&x_offset, &y_offset,
&width, &height);
gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
@ -376,23 +374,23 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
if (priv->radio)
{
gtk_paint_option (gtk_widget_get_style (widget),
window,
state, shadow,
expose_area, widget, "cellradio",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
width, height);
gtk_cairo_paint_option (gtk_widget_get_style (widget),
cr,
state, shadow,
widget, "cellradio",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
width, height);
}
else
{
gtk_paint_check (gtk_widget_get_style (widget),
window,
state, shadow,
expose_area, widget, "cellcheck",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
width, height);
gtk_cairo_paint_check (gtk_widget_get_style (widget),
cr,
state, shadow,
widget, "cellcheck",
cell_area->x + x_offset + xpad,
cell_area->y + y_offset + ypad,
width, height);
}
}