1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-cell-renderer-color.c
4 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "evolution-data-server-config.h"
21 #include "e-cell-renderer-color.h"
24 #include <glib/gi18n-lib.h>
26 #define E_CELL_RENDERER_COLOR_GET_PRIVATE(obj) \
27 (G_TYPE_INSTANCE_GET_PRIVATE \
28 ((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorPrivate))
35 struct _ECellRendererColorPrivate
{
41 e_cell_renderer_color
,
42 GTK_TYPE_CELL_RENDERER
)
45 cell_renderer_color_get_size (GtkCellRenderer
*cell
,
47 const GdkRectangle
*cell_area
,
53 gint color_width
= 16;
54 gint color_height
= 16;
63 cell
, "xalign", &xalign
, "yalign", &yalign
,
64 "xpad", &xpad
, "ypad", &ypad
, NULL
);
66 calc_width
= (gint
) xpad
* 2 + color_width
;
67 calc_height
= (gint
) ypad
* 2 + color_height
;
69 if (cell_area
&& color_width
> 0 && color_height
> 0) {
71 *x_offset
= (((gtk_widget_get_direction (widget
) == GTK_TEXT_DIR_RTL
) ?
72 (1.0 - xalign
) : xalign
) *
73 (cell_area
->width
- calc_width
));
74 *x_offset
= MAX (*x_offset
, 0);
79 (cell_area
->height
- calc_height
));
80 *y_offset
= MAX (*y_offset
, 0);
83 if (x_offset
) *x_offset
= 0;
84 if (y_offset
) *y_offset
= 0;
91 *height
= calc_height
;
95 cell_renderer_color_render (GtkCellRenderer
*cell
,
98 const GdkRectangle
*background_area
,
99 const GdkRectangle
*cell_area
,
100 GtkCellRendererState flags
)
102 ECellRendererColorPrivate
*priv
;
103 GdkRectangle pix_rect
;
104 GdkRectangle draw_rect
;
108 priv
= E_CELL_RENDERER_COLOR_GET_PRIVATE (cell
);
110 cell_renderer_color_get_size (
111 cell
, widget
, cell_area
,
112 &pix_rect
.x
, &pix_rect
.y
,
113 &pix_rect
.width
, &pix_rect
.height
);
115 g_object_get (cell
, "xpad", &xpad
, "ypad", &ypad
, NULL
);
117 pix_rect
.x
+= cell_area
->x
+ xpad
;
118 pix_rect
.y
+= cell_area
->y
+ ypad
;
119 pix_rect
.width
-= xpad
* 2;
120 pix_rect
.height
-= ypad
* 2;
122 if (!gdk_rectangle_intersect (cell_area
, &pix_rect
, &draw_rect
))
125 gdk_cairo_set_source_rgba (cr
, &priv
->rgba
);
126 cairo_rectangle (cr
, pix_rect
.x
, pix_rect
.y
, draw_rect
.width
, draw_rect
.height
);
132 cell_renderer_color_set_property (GObject
*object
,
137 ECellRendererColorPrivate
*priv
;
140 priv
= E_CELL_RENDERER_COLOR_GET_PRIVATE (object
);
142 switch (property_id
) {
144 rgba
= g_value_dup_boxed (value
);
147 gdk_rgba_free (rgba
);
149 priv
->rgba
.red
= 0.0;
150 priv
->rgba
.green
= 0.0;
151 priv
->rgba
.blue
= 0.0;
152 priv
->rgba
.alpha
= 0.0;
157 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
161 cell_renderer_color_get_property (GObject
*object
,
166 ECellRendererColorPrivate
*priv
;
168 priv
= E_CELL_RENDERER_COLOR_GET_PRIVATE (object
);
170 switch (property_id
) {
172 g_value_set_boxed (value
, &priv
->rgba
);
176 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
180 e_cell_renderer_color_class_init (ECellRendererColorClass
*class)
182 GObjectClass
*object_class
;
183 GtkCellRendererClass
*cell_class
;
185 g_type_class_add_private (class, sizeof (ECellRendererColorPrivate
));
187 object_class
= G_OBJECT_CLASS (class);
188 object_class
->set_property
= cell_renderer_color_set_property
;
189 object_class
->get_property
= cell_renderer_color_get_property
;
191 cell_class
= GTK_CELL_RENDERER_CLASS (class);
192 cell_class
->get_size
= cell_renderer_color_get_size
;
193 cell_class
->render
= cell_renderer_color_render
;
195 g_object_class_install_property (
201 "The GdkRGBA color to render",
207 e_cell_renderer_color_init (ECellRendererColor
*cellcolor
)
209 cellcolor
->priv
= E_CELL_RENDERER_COLOR_GET_PRIVATE (cellcolor
);
211 g_object_set (cellcolor
, "xpad", 4, NULL
);
215 * e_cell_renderer_color_new:
220 e_cell_renderer_color_new (void)
222 return g_object_new (E_TYPE_CELL_RENDERER_COLOR
, NULL
);