Commit 2d47563e authored by Colomban Wendling's avatar Colomban Wendling

OVCCGtk: port OVCCGtkCellRendererColor to GTK3

parent 6bdf3a6a
......@@ -43,28 +43,28 @@ enum
};
static void ovccgtk_cell_renderer_color_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void ovccgtk_cell_renderer_color_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void ovccgtk_cell_renderer_color_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
GdkRectangle *cell_area,
gint *x_offset,
gint *y_offset,
gint *width,
gint *height);
static void ovccgtk_cell_renderer_color_render (GtkCellRenderer *cell,
GdkDrawable *window,
GtkWidget *widget,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GdkRectangle *expose_area,
GtkCellRendererState flags);
static void ovccgtk_cell_renderer_color_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void ovccgtk_cell_renderer_color_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void ovccgtk_cell_renderer_color_get_preferred_width (GtkCellRenderer *cell,
GtkWidget *widget,
gint *minimum_width,
gint *natural_width);
static void ovccgtk_cell_renderer_color_get_preferred_height (GtkCellRenderer *cell,
GtkWidget *widget,
gint *minimum_height,
gint *natural_height);
static void ovccgtk_cell_renderer_color_render (GtkCellRenderer *cell,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags);
G_DEFINE_TYPE (OVCCGtkCellRendererColor,
......@@ -81,8 +81,9 @@ ovccgtk_cell_renderer_color_class_init (OVCCGtkCellRendererColorClass *klass)
object_class->set_property = ovccgtk_cell_renderer_color_set_property;
object_class->get_property = ovccgtk_cell_renderer_color_get_property;
renderer_class->get_size = ovccgtk_cell_renderer_color_get_size;
renderer_class->render = ovccgtk_cell_renderer_color_render;
renderer_class->get_preferred_width = ovccgtk_cell_renderer_color_get_preferred_width;
renderer_class->get_preferred_height = ovccgtk_cell_renderer_color_get_preferred_height;
renderer_class->render = ovccgtk_cell_renderer_color_render;
g_object_class_install_property (object_class, PROP_COLOR,
g_param_spec_boxed ("color",
......@@ -190,57 +191,49 @@ ovccgtk_cell_renderer_color_get_property (GObject *object,
}
static void
ovccgtk_cell_renderer_color_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
GdkRectangle *cell_area,
gint *x_offset,
gint *y_offset,
gint *width,
gint *height)
ovccgtk_cell_renderer_color_get_preferred_width (GtkCellRenderer *cell,
GtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
OVCCGtkCellRendererColor *self = OVCCGTK_CELL_RENDERER_COLOR (cell);
gint w = cell->xpad * 2 + self->priv->size;
gint h = cell->ypad * 2 + self->priv->size;
gint xpad;
if (cell_area && w > 0 && h > 0 &&
self->priv->shape != OVCCGTK_CELL_RENDERER_COLOR_SHAPE_FILL) {
if (x_offset) {
*x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
(1.0 - cell->xalign) : cell->xalign) *
(cell_area->width - w);
*x_offset = MAX (*x_offset, 0);
}
if (y_offset) {
*y_offset = cell->yalign * (cell_area->height - h);
*y_offset = MAX (*y_offset, 0);
}
} else {
if (x_offset) *x_offset = 0;
if (y_offset) *y_offset = 0;
}
if (width) *width = w;
if (height) *height = h;
gtk_cell_renderer_get_padding (cell, &xpad, NULL);
*minimum_width = *natural_width = xpad * 2 + self->priv->size;
}
static void
ovccgtk_cell_renderer_color_get_preferred_height (GtkCellRenderer *cell,
GtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
OVCCGtkCellRendererColor *self = OVCCGTK_CELL_RENDERER_COLOR (cell);
gint ypad;
gtk_cell_renderer_get_padding (cell, NULL, &ypad);
*minimum_height = *natural_height = ypad * 2 + self->priv->size;
}
static void
ovccgtk_cell_renderer_color_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)
{
OVCCGtkCellRendererColor *self = OVCCGTK_CELL_RENDERER_COLOR (cell);
cairo_t *cr;
gint x = cell_area->x + cell->xpad;
gint y = cell_area->y + cell->ypad;
gint width = cell_area->width - cell->xpad * 2;
gint height = cell_area->height - cell->ypad * 2;
gint xpad, ypad;
gint x, y;
gint width, height;
cr = gdk_cairo_create (window);
gdk_cairo_rectangle (cr, expose_area);
cairo_clip (cr);
gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
x = cell_area->x + xpad;
y = cell_area->y + ypad;
width = cell_area->width - xpad * 2;
height = cell_area->height - ypad * 2;
switch (self->priv->shape) {
case OVCCGTK_CELL_RENDERER_COLOR_SHAPE_SQUARE:
......@@ -268,7 +261,6 @@ ovccgtk_cell_renderer_color_render (GtkCellRenderer *cell,
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_set_line_width (cr, 1.0);
cairo_stroke (cr);
cairo_destroy (cr);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment