[ADG] Moved include dependencies from .h to .c
[adg.git] / src / adg / adg-table-style.c
blobd67cfd8903a44f94082fdbb8490332ee2d29502f
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011 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 frames 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-internal.h"
38 #include "adg-dress.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-style.h"
41 #include "adg-font-style.h"
42 #include "adg-line-style.h"
44 #include "adg-table-style.h"
45 #include "adg-table-style-private.h"
48 G_DEFINE_TYPE(AdgTableStyle, adg_table_style, ADG_TYPE_STYLE);
50 enum {
51 PROP_0,
52 PROP_COLOR_DRESS,
53 PROP_GRID_DRESS,
54 PROP_FRAME_DRESS,
55 PROP_TITLE_DRESS,
56 PROP_VALUE_DRESS,
57 PROP_ROW_HEIGHT,
58 PROP_CELL_PADDING,
59 PROP_CELL_SPACING
63 static void _adg_get_property (GObject *object,
64 guint prop_id,
65 GValue *value,
66 GParamSpec *pspec);
67 static void _adg_set_property (GObject *object,
68 guint prop_id,
69 const GValue *value,
70 GParamSpec *pspec);
71 static void _adg_apply (AdgStyle *style,
72 AdgEntity *entity,
73 cairo_t *cr);
76 static void
77 adg_table_style_class_init(AdgTableStyleClass *klass)
79 GObjectClass *gobject_class;
80 AdgStyleClass *style_class;
81 GParamSpec *param;
83 gobject_class = (GObjectClass *) klass;
84 style_class = (AdgStyleClass *) klass;
86 g_type_class_add_private(klass, sizeof(AdgTableStylePrivate));
88 gobject_class->get_property = _adg_get_property;
89 gobject_class->set_property = _adg_set_property;
91 style_class->apply = _adg_apply;
93 param = adg_param_spec_dress("color-dress",
94 P_("Color Dress"),
95 P_("Fallback color dress, used when no specific dresses are selected"),
96 ADG_DRESS_COLOR_ANNOTATION,
97 G_PARAM_READWRITE);
98 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
100 param = adg_param_spec_dress("grid-dress",
101 P_("Grid Dress"),
102 P_("Line dress to use while rendering the grid of the table"),
103 ADG_DRESS_LINE_GRID,
104 G_PARAM_READWRITE);
105 g_object_class_install_property(gobject_class, PROP_GRID_DRESS, param);
107 param = adg_param_spec_dress("frame-dress",
108 P_("Frame Dress"),
109 P_("Line dress to use while drawing the table frame"),
110 ADG_DRESS_LINE_FRAME,
111 G_PARAM_READWRITE);
112 g_object_class_install_property(gobject_class, PROP_FRAME_DRESS, param);
114 param = adg_param_spec_dress("title-dress",
115 P_("Title Dress"),
116 P_("Font dress to use for titles"),
117 ADG_DRESS_FONT_ANNOTATION,
118 G_PARAM_READWRITE);
119 g_object_class_install_property(gobject_class, PROP_TITLE_DRESS, param);
121 param = adg_param_spec_dress("value-dress",
122 P_("Value Dress"),
123 P_("Font dress to use for values inside the cells"),
124 ADG_DRESS_FONT_TEXT,
125 G_PARAM_READWRITE);
126 g_object_class_install_property(gobject_class, PROP_VALUE_DRESS, param);
128 param = g_param_spec_double("row-height",
129 P_("Row Height"),
130 P_("The fallback row height when not explicitely specified while creating a new row"),
131 0, G_MAXDOUBLE, 30,
132 G_PARAM_READWRITE);
133 g_object_class_install_property(gobject_class, PROP_ROW_HEIGHT, param);
135 param = g_param_spec_boxed("cell-padding",
136 P_("Cell Padding"),
137 P_("How much space from the bounding box must left inside every cell"),
138 ADG_TYPE_PAIR,
139 G_PARAM_READWRITE);
140 g_object_class_install_property(gobject_class, PROP_CELL_PADDING, param);
142 param = g_param_spec_boxed("cell-spacing",
143 P_("Cell Spacing"),
144 P_("How much space to left between the cells"),
145 ADG_TYPE_PAIR,
146 G_PARAM_READWRITE);
147 g_object_class_install_property(gobject_class, PROP_CELL_SPACING, param);
150 static void
151 adg_table_style_init(AdgTableStyle *table_style)
153 AdgTableStylePrivate *data;
155 data = G_TYPE_INSTANCE_GET_PRIVATE(table_style, ADG_TYPE_TABLE_STYLE,
156 AdgTableStylePrivate);
158 data->color_dress = ADG_DRESS_COLOR_ANNOTATION,
159 data->grid_dress = ADG_DRESS_LINE_GRID;
160 data->frame_dress = ADG_DRESS_LINE_FRAME;
161 data->title_dress = ADG_DRESS_FONT_ANNOTATION;
162 data->value_dress = ADG_DRESS_FONT_TEXT;
163 data->row_height = 30;
164 data->cell_padding.x = 5;
165 data->cell_padding.y = 5;
166 data->cell_spacing.x = 0;
167 data->cell_spacing.y = 0;
169 table_style->data = data;
172 static void
173 _adg_get_property(GObject *object, guint prop_id,
174 GValue *value, GParamSpec *pspec)
176 AdgTableStylePrivate *data = ((AdgTableStyle *) object)->data;
178 switch (prop_id) {
179 case PROP_COLOR_DRESS:
180 g_value_set_int(value, data->color_dress);
181 break;
182 case PROP_GRID_DRESS:
183 g_value_set_int(value, data->grid_dress);
184 break;
185 case PROP_FRAME_DRESS:
186 g_value_set_int(value, data->frame_dress);
187 break;
188 case PROP_TITLE_DRESS:
189 g_value_set_int(value, data->title_dress);
190 break;
191 case PROP_VALUE_DRESS:
192 g_value_set_int(value, data->value_dress);
193 break;
194 case PROP_ROW_HEIGHT:
195 g_value_set_double(value, data->row_height);
196 break;
197 case PROP_CELL_PADDING:
198 g_value_set_boxed(value, &data->cell_padding);
199 break;
200 case PROP_CELL_SPACING:
201 g_value_set_boxed(value, &data->cell_spacing);
202 break;
203 default:
204 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
205 break;
209 static void
210 _adg_set_property(GObject *object, guint prop_id,
211 const GValue *value, GParamSpec *pspec)
213 AdgTableStylePrivate *data = ((AdgTableStyle *) object)->data;
215 switch (prop_id) {
216 case PROP_COLOR_DRESS:
217 data->color_dress = g_value_get_int(value);
218 break;
219 case PROP_GRID_DRESS:
220 data->grid_dress = g_value_get_int(value);
221 break;
222 case PROP_FRAME_DRESS:
223 data->frame_dress = g_value_get_int(value);
224 break;
225 case PROP_TITLE_DRESS:
226 data->title_dress = g_value_get_int(value);
227 break;
228 case PROP_VALUE_DRESS:
229 data->value_dress = g_value_get_int(value);
230 break;
231 case PROP_ROW_HEIGHT:
232 data->row_height = g_value_get_double(value);
233 break;
234 case PROP_CELL_PADDING:
235 adg_pair_copy(&data->cell_padding, g_value_get_boxed(value));
236 break;
237 case PROP_CELL_SPACING:
238 adg_pair_copy(&data->cell_spacing, g_value_get_boxed(value));
239 break;
240 default:
241 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
242 break;
248 * adg_table_style_new:
250 * Constructs a new empty table style initialized with default params.
252 * Returns: a new table style
254 AdgTableStyle *
255 adg_table_style_new(void)
257 return g_object_new(ADG_TYPE_TABLE_STYLE, NULL);
261 * adg_table_style_set_color_dress:
262 * @table_style: an #AdgTableStyle object
263 * @dress: the new color dress
265 * Sets a new color dress on @table_style.
267 void
268 adg_table_style_set_color_dress(AdgTableStyle *table_style, AdgDress dress)
270 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
271 g_object_set(table_style, "color-dress", dress, NULL);
275 * adg_table_style_get_color_dress:
276 * @table_style: an #AdgTableStyle object
278 * Gets the @table_style color dress to be used. This dress should be
279 * intended as a fallback color as it could be overriden by more
280 * specific dresses, such as a color explicitely specified on the
281 * #AdgTableStyle:value-dress.
283 * Returns: the color dress
285 AdgDress
286 adg_table_style_get_color_dress(AdgTableStyle *table_style)
288 AdgTableStylePrivate *data;
290 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
292 data = table_style->data;
294 return data->color_dress;
298 * adg_table_style_set_frame_dress:
299 * @table_style: an #AdgTableStyle object
300 * @dress: the new line dress
302 * Sets a new line dress on @table_style for rendering the frames.
304 void
305 adg_table_style_set_frame_dress(AdgTableStyle *table_style, AdgDress dress)
307 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
308 g_object_set(table_style, "frame-dress", dress, NULL);
312 * adg_table_style_get_frame_dress:
313 * @table_style: an #AdgTableStyle object
315 * Gets the line dress to be used for rendering the frames with
316 * @table_style.
318 * Returns: the line dress
320 AdgDress
321 adg_table_style_get_frame_dress(AdgTableStyle *table_style)
323 AdgTableStylePrivate *data;
325 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
327 data = table_style->data;
329 return data->frame_dress;
333 * adg_table_style_set_grid_dress:
334 * @table_style: an #AdgTableStyle object
335 * @dress: the new line dress
337 * Sets a new line dress on @table_style for rendering the grids.
339 void
340 adg_table_style_set_grid_dress(AdgTableStyle *table_style, AdgDress dress)
342 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
343 g_object_set(table_style, "grid-dress", dress, NULL);
347 * adg_table_style_get_grid_dress:
348 * @table_style: an #AdgTableStyle object
350 * Gets the line dress to be used for rendering the grids with
351 * @table_style.
353 * Returns: the line dress
355 AdgDress
356 adg_table_style_get_grid_dress(AdgTableStyle *table_style)
358 AdgTableStylePrivate *data;
360 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
362 data = table_style->data;
364 return data->grid_dress;
368 * adg_table_style_set_title_dress:
369 * @table_style: an #AdgTableStyle object
370 * @dress: the new font dress
372 * Sets a new font dress on @table_style for rendering cell titles.
374 void
375 adg_table_style_set_title_dress(AdgTableStyle *table_style, AdgDress dress)
377 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
378 g_object_set(table_style, "title-dress", dress, NULL);
382 * adg_table_style_get_title_dress:
383 * @table_style: an #AdgTableStyle object
385 * Gets the font dress to be used for rendering cell titles
386 * with @table_style.
388 * Returns: the font dress
390 AdgDress
391 adg_table_style_get_title_dress(AdgTableStyle *table_style)
393 AdgTableStylePrivate *data;
395 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
397 data = table_style->data;
399 return data->title_dress;
403 * adg_table_style_set_value_dress:
404 * @table_style: an #AdgTableStyle object
405 * @dress: the new font dress
407 * Sets a new font dress on @table_style for rendering cell values.
409 void
410 adg_table_style_set_value_dress(AdgTableStyle *table_style, AdgDress dress)
412 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
413 g_object_set(table_style, "value-dress", dress, NULL);
417 * adg_table_style_get_value_dress:
418 * @table_style: an #AdgTableStyle object
420 * Gets the font dress to be used for rendering cell values
421 * with @table_style.
423 * Returns: the font dress
425 AdgDress
426 adg_table_style_get_value_dress(AdgTableStyle *table_style)
428 AdgTableStylePrivate *data;
430 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), ADG_DRESS_UNDEFINED);
432 data = table_style->data;
434 return data->value_dress;
438 * adg_table_style_set_row_height:
439 * @table_style: an #AdgTableStyle object
440 * @heigth: the new row heigth fallback
442 * Sets a new #AdgTableStyle:row-height fallback. @height must
443 * be a valid row height greather than %0 or a warning will be
444 * raised and this function will fail.
446 void
447 adg_table_style_set_row_height(AdgTableStyle *table_style, gdouble height)
449 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
450 g_object_set(table_style, "row-height", height, NULL);
454 * adg_table_style_get_row_height:
455 * @table_style: an #AdgTableStyle object
457 * Gets the row height fallback value.
459 * Returns: the fallback row height or %0 on errors
461 gdouble
462 adg_table_style_get_row_height(AdgTableStyle *table_style)
464 AdgTableStylePrivate *data;
466 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), 0);
468 data = table_style->data;
470 return data->row_height;
474 * adg_table_style_set_cell_padding:
475 * @table_style: an #AdgTableStyle object
476 * @padding: the new padding values
478 * Sets new #AdgTableStyle:cell-padding values.
480 void
481 adg_table_style_set_cell_padding(AdgTableStyle *table_style,
482 const AdgPair *padding)
484 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
485 g_object_set(table_style, "cell-padding", padding, NULL);
489 * adg_table_style_get_cell_padding:
490 * @table_style: an #AdgTableStyle object
492 * Gets the padding values in x and y to be left clear inside the cells.
493 * The returned pointer refers to an internal allocated struct and
494 * must not be modified or freed.
496 * The cell padding is a symmetric value, that is the padding on the
497 * left will always be equal to the padding on the right and the top
498 * will always be equal to the bottom.
500 * Returns: the cell padding values or %NULL on errors
502 const AdgPair *
503 adg_table_style_get_cell_padding(AdgTableStyle *table_style)
505 AdgTableStylePrivate *data;
507 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), NULL);
509 data = table_style->data;
511 return &data->cell_padding;
515 * adg_table_style_set_cell_spacing:
516 * @table_style: an #AdgTableStyle object
517 * @spacing: the new spacing values
519 * Sets new #AdgTableStyle:cell-spacing values.
521 void
522 adg_table_style_set_cell_spacing(AdgTableStyle *table_style,
523 const AdgPair *spacing)
525 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style));
526 g_object_set(table_style, "cell-spacing", spacing, NULL);
530 * adg_table_style_get_cell_spacing:
531 * @table_style: an #AdgTableStyle object
533 * Gets the spacing values in x and y to be left between the cell
534 * boundary boxes. The returned pointer refers to an internal
535 * allocated struct and must not be modified or freed.
537 * The cell spacing is a symmetric value, that is the spacing on the
538 * left will always be equal to the spacing on the right and the top
539 * will always be equal to the bottom.
541 * Returns: the cell spacing values or %NULL on errors
543 const AdgPair *
544 adg_table_style_get_cell_spacing(AdgTableStyle *table_style)
546 AdgTableStylePrivate *data;
548 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style), NULL);
550 data = table_style->data;
552 return &data->cell_spacing;
556 static void
557 _adg_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
559 AdgTableStylePrivate *data = ((AdgTableStyle *) style)->data;
561 adg_entity_apply_dress(entity, data->color_dress, cr);