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.
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.
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
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
);
63 static void _adg_get_property (GObject
*object
,
67 static void _adg_set_property (GObject
*object
,
71 static void _adg_apply (AdgStyle
*style
,
77 adg_table_style_class_init(AdgTableStyleClass
*klass
)
79 GObjectClass
*gobject_class
;
80 AdgStyleClass
*style_class
;
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",
95 P_("Fallback color dress, used when no specific dresses are selected"),
96 ADG_DRESS_COLOR_ANNOTATION
,
98 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
100 param
= adg_param_spec_dress("grid-dress",
102 P_("Line dress to use while rendering the grid of the table"),
105 g_object_class_install_property(gobject_class
, PROP_GRID_DRESS
, param
);
107 param
= adg_param_spec_dress("frame-dress",
109 P_("Line dress to use while drawing the table frame"),
110 ADG_DRESS_LINE_FRAME
,
112 g_object_class_install_property(gobject_class
, PROP_FRAME_DRESS
, param
);
114 param
= adg_param_spec_dress("title-dress",
116 P_("Font dress to use for titles"),
117 ADG_DRESS_FONT_ANNOTATION
,
119 g_object_class_install_property(gobject_class
, PROP_TITLE_DRESS
, param
);
121 param
= adg_param_spec_dress("value-dress",
123 P_("Font dress to use for values inside the cells"),
126 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
128 param
= g_param_spec_double("row-height",
130 P_("The fallback row height when not explicitely specified while creating a new row"),
133 g_object_class_install_property(gobject_class
, PROP_ROW_HEIGHT
, param
);
135 param
= g_param_spec_boxed("cell-padding",
137 P_("How much space from the bounding box must left inside every cell"),
140 g_object_class_install_property(gobject_class
, PROP_CELL_PADDING
, param
);
142 param
= g_param_spec_boxed("cell-spacing",
144 P_("How much space to left between the cells"),
147 g_object_class_install_property(gobject_class
, PROP_CELL_SPACING
, param
);
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
;
173 _adg_get_property(GObject
*object
, guint prop_id
,
174 GValue
*value
, GParamSpec
*pspec
)
176 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
179 case PROP_COLOR_DRESS
:
180 g_value_set_int(value
, data
->color_dress
);
182 case PROP_GRID_DRESS
:
183 g_value_set_int(value
, data
->grid_dress
);
185 case PROP_FRAME_DRESS
:
186 g_value_set_int(value
, data
->frame_dress
);
188 case PROP_TITLE_DRESS
:
189 g_value_set_int(value
, data
->title_dress
);
191 case PROP_VALUE_DRESS
:
192 g_value_set_int(value
, data
->value_dress
);
194 case PROP_ROW_HEIGHT
:
195 g_value_set_double(value
, data
->row_height
);
197 case PROP_CELL_PADDING
:
198 g_value_set_boxed(value
, &data
->cell_padding
);
200 case PROP_CELL_SPACING
:
201 g_value_set_boxed(value
, &data
->cell_spacing
);
204 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
210 _adg_set_property(GObject
*object
, guint prop_id
,
211 const GValue
*value
, GParamSpec
*pspec
)
213 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
216 case PROP_COLOR_DRESS
:
217 data
->color_dress
= g_value_get_int(value
);
219 case PROP_GRID_DRESS
:
220 data
->grid_dress
= g_value_get_int(value
);
222 case PROP_FRAME_DRESS
:
223 data
->frame_dress
= g_value_get_int(value
);
225 case PROP_TITLE_DRESS
:
226 data
->title_dress
= g_value_get_int(value
);
228 case PROP_VALUE_DRESS
:
229 data
->value_dress
= g_value_get_int(value
);
231 case PROP_ROW_HEIGHT
:
232 data
->row_height
= g_value_get_double(value
);
234 case PROP_CELL_PADDING
:
235 adg_pair_copy(&data
->cell_padding
, g_value_get_boxed(value
));
237 case PROP_CELL_SPACING
:
238 adg_pair_copy(&data
->cell_spacing
, g_value_get_boxed(value
));
241 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
248 * adg_table_style_new:
250 * Constructs a new empty table style initialized with default params.
252 * Returns: a new table style
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.
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
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.
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
318 * Returns: the line dress
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.
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
353 * Returns: the line dress
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.
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
388 * Returns: the font dress
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.
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
423 * Returns: the font dress
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.
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
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.
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
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.
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
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
;
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
);