I#27 - [IMAPx] Ignore DavMail's CR/LF in BODYSTRUCTURE response
[evolution-data-server.git] / src / libedataserverui / e-cell-renderer-color.c
blob2f35064c29019b77b894ebcaf01bbc252cb5d987
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
13 * for more details.
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"
23 #include <string.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))
30 enum {
31 PROP_0,
32 PROP_RGBA
35 struct _ECellRendererColorPrivate {
36 GdkRGBA rgba;
39 G_DEFINE_TYPE (
40 ECellRendererColor,
41 e_cell_renderer_color,
42 GTK_TYPE_CELL_RENDERER)
44 static void
45 cell_renderer_color_get_size (GtkCellRenderer *cell,
46 GtkWidget *widget,
47 const GdkRectangle *cell_area,
48 gint *x_offset,
49 gint *y_offset,
50 gint *width,
51 gint *height)
53 gint color_width = 16;
54 gint color_height = 16;
55 gint calc_width;
56 gint calc_height;
57 gfloat xalign;
58 gfloat yalign;
59 guint xpad;
60 guint ypad;
62 g_object_get (
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) {
70 if (x_offset) {
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);
77 if (y_offset) {
78 *y_offset =(yalign *
79 (cell_area->height - calc_height));
80 *y_offset = MAX (*y_offset, 0);
82 } else {
83 if (x_offset) *x_offset = 0;
84 if (y_offset) *y_offset = 0;
87 if (width)
88 *width = calc_width;
90 if (height)
91 *height = calc_height;
94 static void
95 cell_renderer_color_render (GtkCellRenderer *cell,
96 cairo_t *cr,
97 GtkWidget *widget,
98 const GdkRectangle *background_area,
99 const GdkRectangle *cell_area,
100 GtkCellRendererState flags)
102 ECellRendererColorPrivate *priv;
103 GdkRectangle pix_rect;
104 GdkRectangle draw_rect;
105 guint xpad;
106 guint ypad;
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))
123 return;
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);
128 cairo_fill (cr);
131 static void
132 cell_renderer_color_set_property (GObject *object,
133 guint property_id,
134 const GValue *value,
135 GParamSpec *pspec)
137 ECellRendererColorPrivate *priv;
138 GdkRGBA *rgba;
140 priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
142 switch (property_id) {
143 case PROP_RGBA:
144 rgba = g_value_dup_boxed (value);
145 if (rgba) {
146 priv->rgba = *rgba;
147 gdk_rgba_free (rgba);
148 } else {
149 priv->rgba.red = 0.0;
150 priv->rgba.green = 0.0;
151 priv->rgba.blue = 0.0;
152 priv->rgba.alpha = 0.0;
154 return;
157 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
160 static void
161 cell_renderer_color_get_property (GObject *object,
162 guint property_id,
163 GValue *value,
164 GParamSpec *pspec)
166 ECellRendererColorPrivate *priv;
168 priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
170 switch (property_id) {
171 case PROP_RGBA:
172 g_value_set_boxed (value, &priv->rgba);
173 return;
176 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
179 static void
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 (
196 object_class,
197 PROP_RGBA,
198 g_param_spec_boxed (
199 "rgba",
200 "Color Info",
201 "The GdkRGBA color to render",
202 GDK_TYPE_RGBA,
203 G_PARAM_READWRITE));
206 static void
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:
217 * Since: 2.22
219 GtkCellRenderer *
220 e_cell_renderer_color_new (void)
222 return g_object_new (E_TYPE_CELL_RENDERER_COLOR, NULL);