1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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_WITH_PRIVATE(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 gobject_class
->get_property
= _adg_get_property
;
88 gobject_class
->set_property
= _adg_set_property
;
90 style_class
->apply
= _adg_apply
;
92 param
= adg_param_spec_dress("color-dress",
94 P_("Fallback color dress, used when no specific dresses are selected"),
95 ADG_DRESS_COLOR_ANNOTATION
,
97 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
99 param
= adg_param_spec_dress("grid-dress",
101 P_("Line dress to use while rendering the grid of the table"),
104 g_object_class_install_property(gobject_class
, PROP_GRID_DRESS
, param
);
106 param
= adg_param_spec_dress("frame-dress",
108 P_("Line dress to use while drawing the table frame"),
109 ADG_DRESS_LINE_FRAME
,
111 g_object_class_install_property(gobject_class
, PROP_FRAME_DRESS
, param
);
113 param
= adg_param_spec_dress("title-dress",
115 P_("Font dress to use for titles"),
116 ADG_DRESS_FONT_ANNOTATION
,
118 g_object_class_install_property(gobject_class
, PROP_TITLE_DRESS
, param
);
120 param
= adg_param_spec_dress("value-dress",
122 P_("Font dress to use for values inside the cells"),
125 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
127 param
= g_param_spec_double("row-height",
129 P_("The fallback row height when not explicitely specified while creating a new row"),
132 g_object_class_install_property(gobject_class
, PROP_ROW_HEIGHT
, param
);
134 param
= g_param_spec_boxed("cell-padding",
136 P_("How much space from the bounding box must left inside every cell"),
139 g_object_class_install_property(gobject_class
, PROP_CELL_PADDING
, param
);
141 param
= g_param_spec_boxed("cell-spacing",
143 P_("How much space to left between the cells"),
146 g_object_class_install_property(gobject_class
, PROP_CELL_SPACING
, param
);
150 adg_table_style_init(AdgTableStyle
*table_style
)
152 AdgTableStylePrivate
*data
= adg_table_style_get_instance_private(table_style
);
154 data
->color_dress
= ADG_DRESS_COLOR_ANNOTATION
,
155 data
->grid_dress
= ADG_DRESS_LINE_GRID
;
156 data
->frame_dress
= ADG_DRESS_LINE_FRAME
;
157 data
->title_dress
= ADG_DRESS_FONT_ANNOTATION
;
158 data
->value_dress
= ADG_DRESS_FONT_TEXT
;
159 data
->row_height
= 30;
160 data
->cell_padding
.x
= 3;
161 data
->cell_padding
.y
= 3;
162 data
->cell_spacing
.x
= 0;
163 data
->cell_spacing
.y
= 0;
165 table_style
->data
= data
;
169 _adg_get_property(GObject
*object
, guint prop_id
,
170 GValue
*value
, GParamSpec
*pspec
)
172 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
175 case PROP_COLOR_DRESS
:
176 g_value_set_enum(value
, data
->color_dress
);
178 case PROP_GRID_DRESS
:
179 g_value_set_enum(value
, data
->grid_dress
);
181 case PROP_FRAME_DRESS
:
182 g_value_set_enum(value
, data
->frame_dress
);
184 case PROP_TITLE_DRESS
:
185 g_value_set_enum(value
, data
->title_dress
);
187 case PROP_VALUE_DRESS
:
188 g_value_set_enum(value
, data
->value_dress
);
190 case PROP_ROW_HEIGHT
:
191 g_value_set_double(value
, data
->row_height
);
193 case PROP_CELL_PADDING
:
194 g_value_set_boxed(value
, &data
->cell_padding
);
196 case PROP_CELL_SPACING
:
197 g_value_set_boxed(value
, &data
->cell_spacing
);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
206 _adg_set_property(GObject
*object
, guint prop_id
,
207 const GValue
*value
, GParamSpec
*pspec
)
209 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
212 case PROP_COLOR_DRESS
:
213 data
->color_dress
= g_value_get_enum(value
);
215 case PROP_GRID_DRESS
:
216 data
->grid_dress
= g_value_get_enum(value
);
218 case PROP_FRAME_DRESS
:
219 data
->frame_dress
= g_value_get_enum(value
);
221 case PROP_TITLE_DRESS
:
222 data
->title_dress
= g_value_get_enum(value
);
224 case PROP_VALUE_DRESS
:
225 data
->value_dress
= g_value_get_enum(value
);
227 case PROP_ROW_HEIGHT
:
228 data
->row_height
= g_value_get_double(value
);
230 case PROP_CELL_PADDING
:
231 cpml_pair_copy(&data
->cell_padding
, g_value_get_boxed(value
));
233 case PROP_CELL_SPACING
:
234 cpml_pair_copy(&data
->cell_spacing
, g_value_get_boxed(value
));
237 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
244 * adg_table_style_new:
246 * Constructs a new empty table style initialized with default params.
248 * Returns: (transfer full): a new table style.
253 adg_table_style_new(void)
255 return g_object_new(ADG_TYPE_TABLE_STYLE
, NULL
);
259 * adg_table_style_set_color_dress:
260 * @table_style: an #AdgTableStyle object
261 * @dress: the new color dress
263 * 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: (transfer none): the color dress.
288 adg_table_style_get_color_dress(AdgTableStyle
*table_style
)
290 AdgTableStylePrivate
*data
;
292 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
294 data
= table_style
->data
;
296 return data
->color_dress
;
300 * adg_table_style_set_frame_dress:
301 * @table_style: an #AdgTableStyle object
302 * @dress: the new line dress
304 * Sets a new line dress on @table_style for rendering the frames.
309 adg_table_style_set_frame_dress(AdgTableStyle
*table_style
, AdgDress dress
)
311 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
312 g_object_set(table_style
, "frame-dress", dress
, NULL
);
316 * adg_table_style_get_frame_dress:
317 * @table_style: an #AdgTableStyle object
319 * Gets the line dress to be used for rendering the frames with
322 * Returns: (transfer none): the line dress.
327 adg_table_style_get_frame_dress(AdgTableStyle
*table_style
)
329 AdgTableStylePrivate
*data
;
331 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
333 data
= table_style
->data
;
335 return data
->frame_dress
;
339 * adg_table_style_set_grid_dress:
340 * @table_style: an #AdgTableStyle object
341 * @dress: the new line dress
343 * Sets a new line dress on @table_style for rendering the grids.
348 adg_table_style_set_grid_dress(AdgTableStyle
*table_style
, AdgDress dress
)
350 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
351 g_object_set(table_style
, "grid-dress", dress
, NULL
);
355 * adg_table_style_get_grid_dress:
356 * @table_style: an #AdgTableStyle object
358 * Gets the line dress to be used for rendering the grids with
361 * Returns: (transfer none): the line dress.
366 adg_table_style_get_grid_dress(AdgTableStyle
*table_style
)
368 AdgTableStylePrivate
*data
;
370 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
372 data
= table_style
->data
;
374 return data
->grid_dress
;
378 * adg_table_style_set_title_dress:
379 * @table_style: an #AdgTableStyle object
380 * @dress: the new font dress
382 * Sets a new font dress on @table_style for rendering cell titles.
387 adg_table_style_set_title_dress(AdgTableStyle
*table_style
, AdgDress dress
)
389 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
390 g_object_set(table_style
, "title-dress", dress
, NULL
);
394 * adg_table_style_get_title_dress:
395 * @table_style: an #AdgTableStyle object
397 * Gets the font dress to be used for rendering cell titles
400 * Returns: (transfer none): the font dress.
405 adg_table_style_get_title_dress(AdgTableStyle
*table_style
)
407 AdgTableStylePrivate
*data
;
409 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
411 data
= table_style
->data
;
413 return data
->title_dress
;
417 * adg_table_style_set_value_dress:
418 * @table_style: an #AdgTableStyle object
419 * @dress: the new font dress
421 * Sets a new font dress on @table_style for rendering cell values.
426 adg_table_style_set_value_dress(AdgTableStyle
*table_style
, AdgDress dress
)
428 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
429 g_object_set(table_style
, "value-dress", dress
, NULL
);
433 * adg_table_style_get_value_dress:
434 * @table_style: an #AdgTableStyle object
436 * Gets the font dress to be used for rendering cell values
439 * Returns: (transfer none): the font dress.
444 adg_table_style_get_value_dress(AdgTableStyle
*table_style
)
446 AdgTableStylePrivate
*data
;
448 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
450 data
= table_style
->data
;
452 return data
->value_dress
;
456 * adg_table_style_set_row_height:
457 * @table_style: an #AdgTableStyle object
458 * @height: the new row heigth fallback
460 * Sets a new #AdgTableStyle:row-height fallback. @height must
461 * be a valid row height greather than 0 or a warning will be
462 * raised and this function will fail.
467 adg_table_style_set_row_height(AdgTableStyle
*table_style
, gdouble height
)
469 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
470 g_object_set(table_style
, "row-height", height
, NULL
);
474 * adg_table_style_get_row_height:
475 * @table_style: an #AdgTableStyle object
477 * Gets the row height fallback value.
479 * Returns: the fallback row height or 0 on errors.
484 adg_table_style_get_row_height(AdgTableStyle
*table_style
)
486 AdgTableStylePrivate
*data
;
488 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), 0);
490 data
= table_style
->data
;
492 return data
->row_height
;
496 * adg_table_style_set_cell_padding:
497 * @table_style: an #AdgTableStyle object
498 * @padding: the new padding values
500 * Sets new #AdgTableStyle:cell-padding values.
505 adg_table_style_set_cell_padding(AdgTableStyle
*table_style
,
506 const CpmlPair
*padding
)
508 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
509 g_object_set(table_style
, "cell-padding", padding
, NULL
);
513 * adg_table_style_get_cell_padding:
514 * @table_style: an #AdgTableStyle object
516 * Gets the padding values in x and y to be left clear inside the cells.
517 * The returned pointer refers to an internal allocated struct and
518 * must not be modified or freed.
520 * The cell padding is a symmetric value, that is the padding on the
521 * left will always be equal to the padding on the right and the top
522 * will always be equal to the bottom.
524 * Returns: (transfer none): the cell padding values or <constant>NULL</constant> on errors.
529 adg_table_style_get_cell_padding(AdgTableStyle
*table_style
)
531 AdgTableStylePrivate
*data
;
533 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
535 data
= table_style
->data
;
537 return &data
->cell_padding
;
541 * adg_table_style_set_cell_spacing:
542 * @table_style: an #AdgTableStyle object
543 * @spacing: the new spacing values
545 * Sets new #AdgTableStyle:cell-spacing values.
550 adg_table_style_set_cell_spacing(AdgTableStyle
*table_style
,
551 const CpmlPair
*spacing
)
553 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
554 g_object_set(table_style
, "cell-spacing", spacing
, NULL
);
558 * adg_table_style_get_cell_spacing:
559 * @table_style: an #AdgTableStyle object
561 * Gets the spacing values in x and y to be left between the cell
562 * boundary boxes. The returned pointer refers to an internal
563 * allocated struct and must not be modified or freed.
565 * The cell spacing is a symmetric value, that is the spacing on the
566 * left will always be equal to the spacing on the right and the top
567 * will always be equal to the bottom.
569 * Returns: (transfer none): the cell spacing values or <constant>NULL</constant> on errors.
574 adg_table_style_get_cell_spacing(AdgTableStyle
*table_style
)
576 AdgTableStylePrivate
*data
;
578 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
580 data
= table_style
->data
;
582 return &data
->cell_spacing
;
587 _adg_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
589 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) style
)->data
;
591 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);