1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012 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.
34 * All fields are private and should not be used directly.
35 * Use its public methods instead.
41 #include "adg-internal.h"
42 #include "adg-dress.h"
43 #include "adg-dress-builtins.h"
44 #include "adg-style.h"
46 #include "adg-table-style.h"
47 #include "adg-table-style-private.h"
50 G_DEFINE_TYPE(AdgTableStyle
, adg_table_style
, ADG_TYPE_STYLE
)
65 static void _adg_get_property (GObject
*object
,
69 static void _adg_set_property (GObject
*object
,
73 static void _adg_apply (AdgStyle
*style
,
79 adg_table_style_class_init(AdgTableStyleClass
*klass
)
81 GObjectClass
*gobject_class
;
82 AdgStyleClass
*style_class
;
85 gobject_class
= (GObjectClass
*) klass
;
86 style_class
= (AdgStyleClass
*) klass
;
88 g_type_class_add_private(klass
, sizeof(AdgTableStylePrivate
));
90 gobject_class
->get_property
= _adg_get_property
;
91 gobject_class
->set_property
= _adg_set_property
;
93 style_class
->apply
= _adg_apply
;
95 param
= adg_param_spec_dress("color-dress",
97 P_("Fallback color dress, used when no specific dresses are selected"),
98 ADG_DRESS_COLOR_ANNOTATION
,
100 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
102 param
= adg_param_spec_dress("grid-dress",
104 P_("Line dress to use while rendering the grid of the table"),
107 g_object_class_install_property(gobject_class
, PROP_GRID_DRESS
, param
);
109 param
= adg_param_spec_dress("frame-dress",
111 P_("Line dress to use while drawing the table frame"),
112 ADG_DRESS_LINE_FRAME
,
114 g_object_class_install_property(gobject_class
, PROP_FRAME_DRESS
, param
);
116 param
= adg_param_spec_dress("title-dress",
118 P_("Font dress to use for titles"),
119 ADG_DRESS_FONT_ANNOTATION
,
121 g_object_class_install_property(gobject_class
, PROP_TITLE_DRESS
, param
);
123 param
= adg_param_spec_dress("value-dress",
125 P_("Font dress to use for values inside the cells"),
128 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
130 param
= g_param_spec_double("row-height",
132 P_("The fallback row height when not explicitely specified while creating a new row"),
135 g_object_class_install_property(gobject_class
, PROP_ROW_HEIGHT
, param
);
137 param
= g_param_spec_boxed("cell-padding",
139 P_("How much space from the bounding box must left inside every cell"),
142 g_object_class_install_property(gobject_class
, PROP_CELL_PADDING
, param
);
144 param
= g_param_spec_boxed("cell-spacing",
146 P_("How much space to left between the cells"),
149 g_object_class_install_property(gobject_class
, PROP_CELL_SPACING
, param
);
153 adg_table_style_init(AdgTableStyle
*table_style
)
155 AdgTableStylePrivate
*data
;
157 data
= G_TYPE_INSTANCE_GET_PRIVATE(table_style
, ADG_TYPE_TABLE_STYLE
,
158 AdgTableStylePrivate
);
160 data
->color_dress
= ADG_DRESS_COLOR_ANNOTATION
,
161 data
->grid_dress
= ADG_DRESS_LINE_GRID
;
162 data
->frame_dress
= ADG_DRESS_LINE_FRAME
;
163 data
->title_dress
= ADG_DRESS_FONT_ANNOTATION
;
164 data
->value_dress
= ADG_DRESS_FONT_TEXT
;
165 data
->row_height
= 30;
166 data
->cell_padding
.x
= 3;
167 data
->cell_padding
.y
= 3;
168 data
->cell_spacing
.x
= 0;
169 data
->cell_spacing
.y
= 0;
171 table_style
->data
= data
;
175 _adg_get_property(GObject
*object
, guint prop_id
,
176 GValue
*value
, GParamSpec
*pspec
)
178 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
181 case PROP_COLOR_DRESS
:
182 g_value_set_int(value
, data
->color_dress
);
184 case PROP_GRID_DRESS
:
185 g_value_set_int(value
, data
->grid_dress
);
187 case PROP_FRAME_DRESS
:
188 g_value_set_int(value
, data
->frame_dress
);
190 case PROP_TITLE_DRESS
:
191 g_value_set_int(value
, data
->title_dress
);
193 case PROP_VALUE_DRESS
:
194 g_value_set_int(value
, data
->value_dress
);
196 case PROP_ROW_HEIGHT
:
197 g_value_set_double(value
, data
->row_height
);
199 case PROP_CELL_PADDING
:
200 g_value_set_boxed(value
, &data
->cell_padding
);
202 case PROP_CELL_SPACING
:
203 g_value_set_boxed(value
, &data
->cell_spacing
);
206 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
212 _adg_set_property(GObject
*object
, guint prop_id
,
213 const GValue
*value
, GParamSpec
*pspec
)
215 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
218 case PROP_COLOR_DRESS
:
219 data
->color_dress
= g_value_get_int(value
);
221 case PROP_GRID_DRESS
:
222 data
->grid_dress
= g_value_get_int(value
);
224 case PROP_FRAME_DRESS
:
225 data
->frame_dress
= g_value_get_int(value
);
227 case PROP_TITLE_DRESS
:
228 data
->title_dress
= g_value_get_int(value
);
230 case PROP_VALUE_DRESS
:
231 data
->value_dress
= g_value_get_int(value
);
233 case PROP_ROW_HEIGHT
:
234 data
->row_height
= g_value_get_double(value
);
236 case PROP_CELL_PADDING
:
237 adg_pair_copy(&data
->cell_padding
, g_value_get_boxed(value
));
239 case PROP_CELL_SPACING
:
240 adg_pair_copy(&data
->cell_spacing
, g_value_get_boxed(value
));
243 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
250 * adg_table_style_new:
252 * Constructs a new empty table style initialized with default params.
254 * Returns: (transfer full): a new table style.
259 adg_table_style_new(void)
261 return g_object_new(ADG_TYPE_TABLE_STYLE
, NULL
);
265 * adg_table_style_set_color_dress:
266 * @table_style: an #AdgTableStyle object
267 * @dress: the new color dress
269 * Sets a new color dress on @table_style.
274 adg_table_style_set_color_dress(AdgTableStyle
*table_style
, AdgDress dress
)
276 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
277 g_object_set(table_style
, "color-dress", dress
, NULL
);
281 * adg_table_style_get_color_dress:
282 * @table_style: an #AdgTableStyle object
284 * Gets the @table_style color dress to be used. This dress should be
285 * intended as a fallback color as it could be overriden by more
286 * specific dresses, such as a color explicitely specified on the
287 * #AdgTableStyle:value-dress.
289 * Returns: (transfer none): the color dress.
294 adg_table_style_get_color_dress(AdgTableStyle
*table_style
)
296 AdgTableStylePrivate
*data
;
298 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
300 data
= table_style
->data
;
302 return data
->color_dress
;
306 * adg_table_style_set_frame_dress:
307 * @table_style: an #AdgTableStyle object
308 * @dress: the new line dress
310 * Sets a new line dress on @table_style for rendering the frames.
315 adg_table_style_set_frame_dress(AdgTableStyle
*table_style
, AdgDress dress
)
317 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
318 g_object_set(table_style
, "frame-dress", dress
, NULL
);
322 * adg_table_style_get_frame_dress:
323 * @table_style: an #AdgTableStyle object
325 * Gets the line dress to be used for rendering the frames with
328 * Returns: (transfer none): the line dress.
333 adg_table_style_get_frame_dress(AdgTableStyle
*table_style
)
335 AdgTableStylePrivate
*data
;
337 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
339 data
= table_style
->data
;
341 return data
->frame_dress
;
345 * adg_table_style_set_grid_dress:
346 * @table_style: an #AdgTableStyle object
347 * @dress: the new line dress
349 * Sets a new line dress on @table_style for rendering the grids.
354 adg_table_style_set_grid_dress(AdgTableStyle
*table_style
, AdgDress dress
)
356 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
357 g_object_set(table_style
, "grid-dress", dress
, NULL
);
361 * adg_table_style_get_grid_dress:
362 * @table_style: an #AdgTableStyle object
364 * Gets the line dress to be used for rendering the grids with
367 * Returns: (transfer none): the line dress.
372 adg_table_style_get_grid_dress(AdgTableStyle
*table_style
)
374 AdgTableStylePrivate
*data
;
376 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
378 data
= table_style
->data
;
380 return data
->grid_dress
;
384 * adg_table_style_set_title_dress:
385 * @table_style: an #AdgTableStyle object
386 * @dress: the new font dress
388 * Sets a new font dress on @table_style for rendering cell titles.
393 adg_table_style_set_title_dress(AdgTableStyle
*table_style
, AdgDress dress
)
395 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
396 g_object_set(table_style
, "title-dress", dress
, NULL
);
400 * adg_table_style_get_title_dress:
401 * @table_style: an #AdgTableStyle object
403 * Gets the font dress to be used for rendering cell titles
406 * Returns: (transfer none): the font dress.
411 adg_table_style_get_title_dress(AdgTableStyle
*table_style
)
413 AdgTableStylePrivate
*data
;
415 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
417 data
= table_style
->data
;
419 return data
->title_dress
;
423 * adg_table_style_set_value_dress:
424 * @table_style: an #AdgTableStyle object
425 * @dress: the new font dress
427 * Sets a new font dress on @table_style for rendering cell values.
432 adg_table_style_set_value_dress(AdgTableStyle
*table_style
, AdgDress dress
)
434 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
435 g_object_set(table_style
, "value-dress", dress
, NULL
);
439 * adg_table_style_get_value_dress:
440 * @table_style: an #AdgTableStyle object
442 * Gets the font dress to be used for rendering cell values
445 * Returns: (transfer none): the font dress.
450 adg_table_style_get_value_dress(AdgTableStyle
*table_style
)
452 AdgTableStylePrivate
*data
;
454 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
456 data
= table_style
->data
;
458 return data
->value_dress
;
462 * adg_table_style_set_row_height:
463 * @table_style: an #AdgTableStyle object
464 * @height: the new row heigth fallback
466 * Sets a new #AdgTableStyle:row-height fallback. @height must
467 * be a valid row height greather than %0 or a warning will be
468 * raised and this function will fail.
473 adg_table_style_set_row_height(AdgTableStyle
*table_style
, gdouble height
)
475 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
476 g_object_set(table_style
, "row-height", height
, NULL
);
480 * adg_table_style_get_row_height:
481 * @table_style: an #AdgTableStyle object
483 * Gets the row height fallback value.
485 * Returns: the fallback row height or %0 on errors.
490 adg_table_style_get_row_height(AdgTableStyle
*table_style
)
492 AdgTableStylePrivate
*data
;
494 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), 0);
496 data
= table_style
->data
;
498 return data
->row_height
;
502 * adg_table_style_set_cell_padding:
503 * @table_style: an #AdgTableStyle object
504 * @padding: the new padding values
506 * Sets new #AdgTableStyle:cell-padding values.
511 adg_table_style_set_cell_padding(AdgTableStyle
*table_style
,
512 const AdgPair
*padding
)
514 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
515 g_object_set(table_style
, "cell-padding", padding
, NULL
);
519 * adg_table_style_get_cell_padding:
520 * @table_style: an #AdgTableStyle object
522 * Gets the padding values in x and y to be left clear inside the cells.
523 * The returned pointer refers to an internal allocated struct and
524 * must not be modified or freed.
526 * The cell padding is a symmetric value, that is the padding on the
527 * left will always be equal to the padding on the right and the top
528 * will always be equal to the bottom.
530 * Returns: (transfer none): the cell padding values or %NULL on errors.
535 adg_table_style_get_cell_padding(AdgTableStyle
*table_style
)
537 AdgTableStylePrivate
*data
;
539 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
541 data
= table_style
->data
;
543 return &data
->cell_padding
;
547 * adg_table_style_set_cell_spacing:
548 * @table_style: an #AdgTableStyle object
549 * @spacing: the new spacing values
551 * Sets new #AdgTableStyle:cell-spacing values.
556 adg_table_style_set_cell_spacing(AdgTableStyle
*table_style
,
557 const AdgPair
*spacing
)
559 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
560 g_object_set(table_style
, "cell-spacing", spacing
, NULL
);
564 * adg_table_style_get_cell_spacing:
565 * @table_style: an #AdgTableStyle object
567 * Gets the spacing values in x and y to be left between the cell
568 * boundary boxes. The returned pointer refers to an internal
569 * allocated struct and must not be modified or freed.
571 * The cell spacing is a symmetric value, that is the spacing on the
572 * left will always be equal to the spacing on the right and the top
573 * will always be equal to the bottom.
575 * Returns: (transfer none): the cell spacing values or %NULL on errors.
580 adg_table_style_get_cell_spacing(AdgTableStyle
*table_style
)
582 AdgTableStylePrivate
*data
;
584 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
586 data
= table_style
->data
;
588 return &data
->cell_spacing
;
593 _adg_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
595 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) style
)->data
;
597 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);