[AdgTableStyle] Typo in docblock
[adg.git] / adg / adg-table-style.c
blob102714ee1b9848a0d4282070e697025f89d9bf52
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-table-style
23 * @short_description: Customization of table rendering
25 * Contains parameters on how to build tables such as the lines to
26 * use for borders and grids and the font dresses for titles or values.
29 /**
30 * AdgTableStyle:
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
34 **/
37 #include "adg-table-style.h"
38 #include "adg-table-style-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-font-style.h"
41 #include "adg-line-style.h"
42 #include "adg-intl.h"
43 #include "adg-util.h"
46 enum {
47 PROP_0,
48 PROP_COLOR_DRESS,
49 PROP_BORDER_DRESS,
50 PROP_GRID_DRESS,
51 PROP_TITLE_DRESS,
52 PROP_VALUE_DRESS,
53 PROP_PADDING
57 static void get_property (GObject *object,
58 guint prop_id,
59 GValue *value,
60 GParamSpec *pspec);
61 static void set_property (GObject *object,
62 guint prop_id,
63 const GValue *value,
64 GParamSpec *pspec);
65 static void apply (AdgStyle *style,
66 AdgEntity *entity,
67 cairo_t *cr);
70 G_DEFINE_TYPE(AdgTableStyle, adg_table_style, ADG_TYPE_STYLE);
73 static void
74 adg_table_style_class_init(AdgTableStyleClass *klass)
76 GObjectClass *gobject_class;
77 AdgStyleClass *style_class;
78 GParamSpec *param;
80 gobject_class = (GObjectClass *) klass;
81 style_class = (AdgStyleClass *) klass;
83 g_type_class_add_private(klass, sizeof(AdgTableStylePrivate));
85 gobject_class->get_property = get_property;
86 gobject_class->set_property = set_property;
88 style_class->apply = apply;
90 param = adg_param_spec_dress("color-dress",
91 P_("Color Dress"),
92 P_("Color dress for the whole tableension"),
93 ADG_DRESS_COLOR,
94 G_PARAM_READWRITE);
95 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
97 param = adg_param_spec_dress("border-dress",
98 P_("Border Dress"),
99 P_("Line dress to use while drawing the table border"),
100 ADG_DRESS_LINE_STROKE,
101 G_PARAM_READWRITE);
102 g_object_class_install_property(gobject_class, PROP_BORDER_DRESS, param);
104 param = adg_param_spec_dress("grid-dress",
105 P_("Grid Dress"),
106 P_("Line dress to use while rendering the grid of the table"),
107 ADG_DRESS_LINE_HATCH,
108 G_PARAM_READWRITE);
109 g_object_class_install_property(gobject_class, PROP_GRID_DRESS, param);
111 param = adg_param_spec_dress("title-dress",
112 P_("Title Dress"),
113 P_("Font dress to use for titles"),
114 ADG_DRESS_TEXT_VALUE,
115 G_PARAM_READWRITE);
116 g_object_class_install_property(gobject_class, PROP_TITLE_DRESS, param);
118 param = adg_param_spec_dress("value-dress",
119 P_("Value Dress"),
120 P_("Font dress to use for values inside the cells"),
121 ADG_DRESS_TEXT_LIMIT,
122 G_PARAM_READWRITE);
123 g_object_class_install_property(gobject_class, PROP_VALUE_DRESS, param);
125 param = g_param_spec_boxed("padding",
126 P_("Padding"),
127 P_("How much space from the extents must be reserved (that is, left clear) inside the cell"),
128 ADG_TYPE_PAIR,
129 G_PARAM_READWRITE);
130 g_object_class_install_property(gobject_class, PROP_PADDING, param);
133 static void
134 adg_table_style_init(AdgTableStyle *table_style)
136 AdgTableStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(table_style,
137 ADG_TYPE_TABLE_STYLE,
138 AdgTableStylePrivate);
140 data->color_dress = ADG_DRESS_COLOR;
141 data->border_dress = ADG_DRESS_LINE_STROKE;
142 data->grid_dress = ADG_DRESS_LINE_HATCH;
143 data->title_dress = ADG_DRESS_TEXT_VALUE;
144 data->value_dress = ADG_DRESS_TEXT_LIMIT;
145 data->padding.x = 2;
146 data->padding.y = 2;
148 table_style->data = data;
151 static void
152 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
154 AdgTableStylePrivate *data = ((AdgTableStyle *) object)->data;
156 switch (prop_id) {
157 case PROP_COLOR_DRESS:
158 g_value_set_int(value, data->color_dress);
159 break;
160 case PROP_BORDER_DRESS:
161 g_value_set_int(value, data->border_dress);
162 break;
163 case PROP_GRID_DRESS:
164 g_value_set_int(value, data->grid_dress);
165 break;
166 case PROP_TITLE_DRESS:
167 g_value_set_int(value, data->title_dress);
168 break;
169 case PROP_VALUE_DRESS:
170 g_value_set_int(value, data->value_dress);
171 break;
172 case PROP_PADDING:
173 g_value_set_boxed(value, &data->padding);
174 break;
175 default:
176 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
177 break;
181 static void
182 set_property(GObject *object,
183 guint prop_id, const GValue *value, GParamSpec *pspec)
185 AdgTableStylePrivate *data = ((AdgTableStyle *) object)->data;
187 switch (prop_id) {
188 case PROP_COLOR_DRESS:
189 adg_dress_set(&data->color_dress, g_value_get_int(value));
190 break;
191 case PROP_BORDER_DRESS:
192 adg_dress_set(&data->border_dress, g_value_get_int(value));
193 break;
194 case PROP_GRID_DRESS:
195 adg_dress_set(&data->grid_dress, g_value_get_int(value));
196 break;
197 case PROP_TITLE_DRESS:
198 adg_dress_set(&data->title_dress, g_value_get_int(value));
199 break;
200 case PROP_VALUE_DRESS:
201 adg_dress_set(&data->value_dress, g_value_get_int(value));
202 break;
203 case PROP_PADDING:
204 cpml_pair_copy(&data->padding, g_value_get_boxed(value));
205 break;
206 default:
207 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
208 break;
214 * adg_table_style_new:
216 * Constructs a new tableension style initialized with default params.
218 * Returns: a new tableension style
220 AdgStyle *
221 adg_table_style_new(void)
223 return g_object_new(ADG_TYPE_TABLE_STYLE, NULL);
227 * adg_table_style_get_color_dress:
228 * @table_style: an #AdgTableStyle object
230 * Gets the @table_style color dress to be used. This dress should be
231 * intended as a fallback color as it could be overriden by more
232 * specific dresses, such as a color explicitely specified on the
233 * #AdgTableStyle:value-dress.
235 * Returns: the color dress
237 AdgDress
238 adg_table_style_get_color_dress(AdgTableStyle *table_style)
240 AdgTableStylePrivate *data;
242 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
244 data = table_style->data;
246 return data->color_dress;
250 * adg_table_style_set_color_dress:
251 * @table_style: an #AdgTableStyle object
252 * @dress: the new color dress
254 * Sets a new color dress on @table_style.
256 void
257 adg_table_style_set_color_dress(AdgTableStyle *table_style, AdgDress dress)
259 AdgTableStylePrivate *data;
261 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
263 data = table_style->data;
265 if (adg_dress_set(&data->color_dress, dress))
266 g_object_notify((GObject *) table_style, "color-dress");
270 * adg_table_style_get_border_dress:
271 * @table_style: an #AdgTableStyle object
273 * Gets the line dress to be used for rendering the borders with
274 * @table_style.
276 * Returns: the line dress
278 AdgDress
279 adg_table_style_get_border_dress(AdgTableStyle *table_style)
281 AdgTableStylePrivate *data;
283 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
285 data = table_style->data;
287 return data->border_dress;
291 * adg_table_style_set_border_dress:
292 * @table_style: an #AdgTableStyle object
293 * @dress: the new line dress
295 * Sets a new line dress on @table_style for rendering the borders.
297 void
298 adg_table_style_set_border_dress(AdgTableStyle *table_style, AdgDress dress)
300 AdgTableStylePrivate *data;
302 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
304 data = table_style->data;
306 if (adg_dress_set(&data->border_dress, dress))
307 g_object_notify((GObject *) table_style, "border-dress");
311 * adg_table_style_get_grid_dress:
312 * @table_style: an #AdgTableStyle object
314 * Gets the line dress to be used for rendering the grids with
315 * @table_style.
317 * Returns: the line dress
319 AdgDress
320 adg_table_style_get_grid_dress(AdgTableStyle *table_style)
322 AdgTableStylePrivate *data;
324 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
326 data = table_style->data;
328 return data->grid_dress;
332 * adg_table_style_set_grid_dress:
333 * @table_style: an #AdgTableStyle object
334 * @dress: the new line dress
336 * Sets a new line dress on @table_style for rendering the grids.
338 void
339 adg_table_style_set_grid_dress(AdgTableStyle *table_style, AdgDress dress)
341 AdgTableStylePrivate *data;
343 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
345 data = table_style->data;
347 if (adg_dress_set(&data->grid_dress, dress))
348 g_object_notify((GObject *) table_style, "grid-dress");
352 * adg_table_style_get_title_dress:
353 * @table_style: an #AdgTableStyle object
355 * Gets the font dress to be used for rendering cell titles
356 * with @table_style.
358 * Returns: the font dress
360 AdgDress
361 adg_table_style_get_title_dress(AdgTableStyle *table_style)
363 AdgTableStylePrivate *data;
365 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
367 data = table_style->data;
369 return data->title_dress;
373 * adg_table_style_set_title_dress:
374 * @table_style: an #AdgTableStyle object
375 * @dress: the new font dress
377 * Sets a new font dress on @table_style for rendering cell titles.
379 void
380 adg_table_style_set_title_dress(AdgTableStyle *table_style, AdgDress dress)
382 AdgTableStylePrivate *data;
384 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
386 data = table_style->data;
388 if (adg_dress_set(&data->title_dress, dress))
389 g_object_notify((GObject *) table_style, "title-dress");
393 * adg_table_style_get_value_dress:
394 * @table_style: an #AdgTableStyle object
396 * Gets the font dress to be used for rendering cell values
397 * with @table_style.
399 * Returns: the font dress
401 AdgDress
402 adg_table_style_get_value_dress(AdgTableStyle *table_style)
404 AdgTableStylePrivate *data;
406 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
408 data = table_style->data;
410 return data->value_dress;
414 * adg_table_style_set_value_dress:
415 * @table_style: an #AdgTableStyle object
416 * @dress: the new font dress
418 * Sets a new font dress on @table_style for rendering cell values.
420 void
421 adg_table_style_set_value_dress(AdgTableStyle *table_style, AdgDress dress)
423 AdgTableStylePrivate *data;
425 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
427 data = table_style->data;
429 if (adg_dress_set(&data->value_dress, dress))
430 g_object_notify((GObject *) table_style, "value-dress");
434 * adg_table_style_get_padding:
435 * @table_style: an #AdgTableStyle object
437 * Gets the padding values in x and y to be left clear inside the cells.
438 * The returned pointer refers to an internal allocated struct and
439 * must not be modified or freed.
441 * Returns: the internal padding values
443 const AdgPair *
444 adg_table_style_get_padding(AdgTableStyle *table_style)
446 AdgTableStylePrivate *data;
448 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), NULL);
450 data = table_style->data;
452 return &data->padding;
456 * adg_table_style_set_padding:
457 * @table_style: an #AdgTableStyle object
458 * @padding: the new padding values
460 * Sets new #AdgTableStyle:padding values.
462 void
463 adg_table_style_set_padding(AdgTableStyle *table_style, const AdgPair *padding)
465 AdgTableStylePrivate *data;
467 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
468 g_return_if_fail(padding != NULL);
470 data = table_style->data;
471 cpml_pair_copy(&data->padding, padding);
473 g_object_notify((GObject *) table_style, "padding");
477 static void
478 apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
480 AdgTableStylePrivate *data = ((AdgTableStyle *) style)->data;
482 adg_entity_apply_dress(entity, data->color_dress, cr);