1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
40 #include "adg-internal.h"
41 #include "adg-style.h"
42 #include "adg-dress.h"
43 #include "adg-param-dress.h"
45 #include "adg-table-style.h"
46 #include "adg-table-style-private.h"
49 G_DEFINE_TYPE(AdgTableStyle
, adg_table_style
, ADG_TYPE_STYLE
)
64 static void _adg_get_property (GObject
*object
,
68 static void _adg_set_property (GObject
*object
,
72 static void _adg_apply (AdgStyle
*style
,
78 adg_table_style_class_init(AdgTableStyleClass
*klass
)
80 GObjectClass
*gobject_class
;
81 AdgStyleClass
*style_class
;
84 gobject_class
= (GObjectClass
*) klass
;
85 style_class
= (AdgStyleClass
*) klass
;
87 g_type_class_add_private(klass
, sizeof(AdgTableStylePrivate
));
89 gobject_class
->get_property
= _adg_get_property
;
90 gobject_class
->set_property
= _adg_set_property
;
92 style_class
->apply
= _adg_apply
;
94 param
= adg_param_spec_dress("color-dress",
96 P_("Fallback color dress, used when no specific dresses are selected"),
97 ADG_DRESS_COLOR_ANNOTATION
,
99 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
101 param
= adg_param_spec_dress("grid-dress",
103 P_("Line dress to use while rendering the grid of the table"),
106 g_object_class_install_property(gobject_class
, PROP_GRID_DRESS
, param
);
108 param
= adg_param_spec_dress("frame-dress",
110 P_("Line dress to use while drawing the table frame"),
111 ADG_DRESS_LINE_FRAME
,
113 g_object_class_install_property(gobject_class
, PROP_FRAME_DRESS
, param
);
115 param
= adg_param_spec_dress("title-dress",
117 P_("Font dress to use for titles"),
118 ADG_DRESS_FONT_ANNOTATION
,
120 g_object_class_install_property(gobject_class
, PROP_TITLE_DRESS
, param
);
122 param
= adg_param_spec_dress("value-dress",
124 P_("Font dress to use for values inside the cells"),
127 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
129 param
= g_param_spec_double("row-height",
131 P_("The fallback row height when not explicitely specified while creating a new row"),
134 g_object_class_install_property(gobject_class
, PROP_ROW_HEIGHT
, param
);
136 param
= g_param_spec_boxed("cell-padding",
138 P_("How much space from the bounding box must left inside every cell"),
141 g_object_class_install_property(gobject_class
, PROP_CELL_PADDING
, param
);
143 param
= g_param_spec_boxed("cell-spacing",
145 P_("How much space to left between the cells"),
148 g_object_class_install_property(gobject_class
, PROP_CELL_SPACING
, param
);
152 adg_table_style_init(AdgTableStyle
*table_style
)
154 AdgTableStylePrivate
*data
;
156 data
= G_TYPE_INSTANCE_GET_PRIVATE(table_style
, ADG_TYPE_TABLE_STYLE
,
157 AdgTableStylePrivate
);
159 data
->color_dress
= ADG_DRESS_COLOR_ANNOTATION
,
160 data
->grid_dress
= ADG_DRESS_LINE_GRID
;
161 data
->frame_dress
= ADG_DRESS_LINE_FRAME
;
162 data
->title_dress
= ADG_DRESS_FONT_ANNOTATION
;
163 data
->value_dress
= ADG_DRESS_FONT_TEXT
;
164 data
->row_height
= 30;
165 data
->cell_padding
.x
= 3;
166 data
->cell_padding
.y
= 3;
167 data
->cell_spacing
.x
= 0;
168 data
->cell_spacing
.y
= 0;
170 table_style
->data
= data
;
174 _adg_get_property(GObject
*object
, guint prop_id
,
175 GValue
*value
, GParamSpec
*pspec
)
177 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
180 case PROP_COLOR_DRESS
:
181 g_value_set_enum(value
, data
->color_dress
);
183 case PROP_GRID_DRESS
:
184 g_value_set_enum(value
, data
->grid_dress
);
186 case PROP_FRAME_DRESS
:
187 g_value_set_enum(value
, data
->frame_dress
);
189 case PROP_TITLE_DRESS
:
190 g_value_set_enum(value
, data
->title_dress
);
192 case PROP_VALUE_DRESS
:
193 g_value_set_enum(value
, data
->value_dress
);
195 case PROP_ROW_HEIGHT
:
196 g_value_set_double(value
, data
->row_height
);
198 case PROP_CELL_PADDING
:
199 g_value_set_boxed(value
, &data
->cell_padding
);
201 case PROP_CELL_SPACING
:
202 g_value_set_boxed(value
, &data
->cell_spacing
);
205 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
211 _adg_set_property(GObject
*object
, guint prop_id
,
212 const GValue
*value
, GParamSpec
*pspec
)
214 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
217 case PROP_COLOR_DRESS
:
218 data
->color_dress
= g_value_get_enum(value
);
220 case PROP_GRID_DRESS
:
221 data
->grid_dress
= g_value_get_enum(value
);
223 case PROP_FRAME_DRESS
:
224 data
->frame_dress
= g_value_get_enum(value
);
226 case PROP_TITLE_DRESS
:
227 data
->title_dress
= g_value_get_enum(value
);
229 case PROP_VALUE_DRESS
:
230 data
->value_dress
= g_value_get_enum(value
);
232 case PROP_ROW_HEIGHT
:
233 data
->row_height
= g_value_get_double(value
);
235 case PROP_CELL_PADDING
:
236 cpml_pair_copy(&data
->cell_padding
, g_value_get_boxed(value
));
238 case PROP_CELL_SPACING
:
239 cpml_pair_copy(&data
->cell_spacing
, g_value_get_boxed(value
));
242 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
249 * adg_table_style_new:
251 * Constructs a new empty table style initialized with default params.
253 * Returns: (transfer full): a new table style.
258 adg_table_style_new(void)
260 return g_object_new(ADG_TYPE_TABLE_STYLE
, NULL
);
264 * adg_table_style_set_color_dress:
265 * @table_style: an #AdgTableStyle object
266 * @dress: the new color dress
268 * Sets a new color dress on @table_style.
273 adg_table_style_set_color_dress(AdgTableStyle
*table_style
, AdgDress dress
)
275 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
276 g_object_set(table_style
, "color-dress", dress
, NULL
);
280 * adg_table_style_get_color_dress:
281 * @table_style: an #AdgTableStyle object
283 * Gets the @table_style color dress to be used. This dress should be
284 * intended as a fallback color as it could be overriden by more
285 * specific dresses, such as a color explicitely specified on the
286 * #AdgTableStyle:value-dress.
288 * Returns: (transfer none): the color dress.
293 adg_table_style_get_color_dress(AdgTableStyle
*table_style
)
295 AdgTableStylePrivate
*data
;
297 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
299 data
= table_style
->data
;
301 return data
->color_dress
;
305 * adg_table_style_set_frame_dress:
306 * @table_style: an #AdgTableStyle object
307 * @dress: the new line dress
309 * Sets a new line dress on @table_style for rendering the frames.
314 adg_table_style_set_frame_dress(AdgTableStyle
*table_style
, AdgDress dress
)
316 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
317 g_object_set(table_style
, "frame-dress", dress
, NULL
);
321 * adg_table_style_get_frame_dress:
322 * @table_style: an #AdgTableStyle object
324 * Gets the line dress to be used for rendering the frames with
327 * Returns: (transfer none): the line dress.
332 adg_table_style_get_frame_dress(AdgTableStyle
*table_style
)
334 AdgTableStylePrivate
*data
;
336 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
338 data
= table_style
->data
;
340 return data
->frame_dress
;
344 * adg_table_style_set_grid_dress:
345 * @table_style: an #AdgTableStyle object
346 * @dress: the new line dress
348 * Sets a new line dress on @table_style for rendering the grids.
353 adg_table_style_set_grid_dress(AdgTableStyle
*table_style
, AdgDress dress
)
355 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
356 g_object_set(table_style
, "grid-dress", dress
, NULL
);
360 * adg_table_style_get_grid_dress:
361 * @table_style: an #AdgTableStyle object
363 * Gets the line dress to be used for rendering the grids with
366 * Returns: (transfer none): the line dress.
371 adg_table_style_get_grid_dress(AdgTableStyle
*table_style
)
373 AdgTableStylePrivate
*data
;
375 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
377 data
= table_style
->data
;
379 return data
->grid_dress
;
383 * adg_table_style_set_title_dress:
384 * @table_style: an #AdgTableStyle object
385 * @dress: the new font dress
387 * Sets a new font dress on @table_style for rendering cell titles.
392 adg_table_style_set_title_dress(AdgTableStyle
*table_style
, AdgDress dress
)
394 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
395 g_object_set(table_style
, "title-dress", dress
, NULL
);
399 * adg_table_style_get_title_dress:
400 * @table_style: an #AdgTableStyle object
402 * Gets the font dress to be used for rendering cell titles
405 * Returns: (transfer none): the font dress.
410 adg_table_style_get_title_dress(AdgTableStyle
*table_style
)
412 AdgTableStylePrivate
*data
;
414 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
416 data
= table_style
->data
;
418 return data
->title_dress
;
422 * adg_table_style_set_value_dress:
423 * @table_style: an #AdgTableStyle object
424 * @dress: the new font dress
426 * Sets a new font dress on @table_style for rendering cell values.
431 adg_table_style_set_value_dress(AdgTableStyle
*table_style
, AdgDress dress
)
433 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
434 g_object_set(table_style
, "value-dress", dress
, NULL
);
438 * adg_table_style_get_value_dress:
439 * @table_style: an #AdgTableStyle object
441 * Gets the font dress to be used for rendering cell values
444 * Returns: (transfer none): the font dress.
449 adg_table_style_get_value_dress(AdgTableStyle
*table_style
)
451 AdgTableStylePrivate
*data
;
453 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
455 data
= table_style
->data
;
457 return data
->value_dress
;
461 * adg_table_style_set_row_height:
462 * @table_style: an #AdgTableStyle object
463 * @height: the new row heigth fallback
465 * Sets a new #AdgTableStyle:row-height fallback. @height must
466 * be a valid row height greather than 0 or a warning will be
467 * raised and this function will fail.
472 adg_table_style_set_row_height(AdgTableStyle
*table_style
, gdouble height
)
474 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
475 g_object_set(table_style
, "row-height", height
, NULL
);
479 * adg_table_style_get_row_height:
480 * @table_style: an #AdgTableStyle object
482 * Gets the row height fallback value.
484 * Returns: the fallback row height or 0 on errors.
489 adg_table_style_get_row_height(AdgTableStyle
*table_style
)
491 AdgTableStylePrivate
*data
;
493 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), 0);
495 data
= table_style
->data
;
497 return data
->row_height
;
501 * adg_table_style_set_cell_padding:
502 * @table_style: an #AdgTableStyle object
503 * @padding: the new padding values
505 * Sets new #AdgTableStyle:cell-padding values.
510 adg_table_style_set_cell_padding(AdgTableStyle
*table_style
,
511 const CpmlPair
*padding
)
513 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
514 g_object_set(table_style
, "cell-padding", padding
, NULL
);
518 * adg_table_style_get_cell_padding:
519 * @table_style: an #AdgTableStyle object
521 * Gets the padding values in x and y to be left clear inside the cells.
522 * The returned pointer refers to an internal allocated struct and
523 * must not be modified or freed.
525 * The cell padding is a symmetric value, that is the padding on the
526 * left will always be equal to the padding on the right and the top
527 * will always be equal to the bottom.
529 * Returns: (transfer none): the cell padding values or <constant>NULL</constant> on errors.
534 adg_table_style_get_cell_padding(AdgTableStyle
*table_style
)
536 AdgTableStylePrivate
*data
;
538 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
540 data
= table_style
->data
;
542 return &data
->cell_padding
;
546 * adg_table_style_set_cell_spacing:
547 * @table_style: an #AdgTableStyle object
548 * @spacing: the new spacing values
550 * Sets new #AdgTableStyle:cell-spacing values.
555 adg_table_style_set_cell_spacing(AdgTableStyle
*table_style
,
556 const CpmlPair
*spacing
)
558 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
559 g_object_set(table_style
, "cell-spacing", spacing
, NULL
);
563 * adg_table_style_get_cell_spacing:
564 * @table_style: an #AdgTableStyle object
566 * Gets the spacing values in x and y to be left between the cell
567 * boundary boxes. The returned pointer refers to an internal
568 * allocated struct and must not be modified or freed.
570 * The cell spacing is a symmetric value, that is the spacing on the
571 * left will always be equal to the spacing on the right and the top
572 * will always be equal to the bottom.
574 * Returns: (transfer none): the cell spacing values or <constant>NULL</constant> on errors.
579 adg_table_style_get_cell_spacing(AdgTableStyle
*table_style
)
581 AdgTableStylePrivate
*data
;
583 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
585 data
= table_style
->data
;
587 return &data
->cell_spacing
;
592 _adg_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
594 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) style
)->data
;
596 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);