1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 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 borders 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-table-style.h"
38 #include "adg-table-style-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-font-style.h"
41 #include "adg-line-style.h"
57 static void get_property (GObject
*object
,
61 static void set_property (GObject
*object
,
65 static void apply (AdgStyle
*style
,
70 G_DEFINE_TYPE(AdgTableStyle
, adg_table_style
, ADG_TYPE_STYLE
);
74 adg_table_style_class_init(AdgTableStyleClass
*klass
)
76 GObjectClass
*gobject_class
;
77 AdgStyleClass
*style_class
;
80 gobject_class
= (GObjectClass
*) klass
;
81 style_class
= (AdgStyleClass
*) klass
;
83 g_type_class_add_private(klass
, sizeof(AdgTableStylePrivate
));
85 gobject_class
->get_property
= get_property
;
86 gobject_class
->set_property
= set_property
;
88 style_class
->apply
= apply
;
90 param
= adg_param_spec_dress("color-dress",
92 P_("Color dress for the whole tableension"),
95 g_object_class_install_property(gobject_class
, PROP_COLOR_DRESS
, param
);
97 param
= adg_param_spec_dress("border-dress",
99 P_("Line dress to use while drawing the table border"),
100 ADG_DRESS_LINE_STROKE
,
102 g_object_class_install_property(gobject_class
, PROP_BORDER_DRESS
, param
);
104 param
= adg_param_spec_dress("grid-dress",
106 P_("Line dress to use while rendering the grid of the table"),
107 ADG_DRESS_LINE_HATCH
,
109 g_object_class_install_property(gobject_class
, PROP_GRID_DRESS
, param
);
111 param
= adg_param_spec_dress("title-dress",
113 P_("Font dress to use for titles"),
114 ADG_DRESS_TEXT_VALUE
,
116 g_object_class_install_property(gobject_class
, PROP_TITLE_DRESS
, param
);
118 param
= adg_param_spec_dress("value-dress",
120 P_("Font dress to use for values inside the cells"),
121 ADG_DRESS_TEXT_LIMIT
,
123 g_object_class_install_property(gobject_class
, PROP_VALUE_DRESS
, param
);
125 param
= g_param_spec_boxed("padding",
127 P_("How much space from the extents must be reserved (that is, left clear) inside the cell"),
130 g_object_class_install_property(gobject_class
, PROP_PADDING
, param
);
134 adg_table_style_init(AdgTableStyle
*table_style
)
136 AdgTableStylePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(table_style
,
137 ADG_TYPE_TABLE_STYLE
,
138 AdgTableStylePrivate
);
140 data
->color_dress
= ADG_DRESS_COLOR
;
141 data
->border_dress
= ADG_DRESS_LINE_STROKE
;
142 data
->grid_dress
= ADG_DRESS_LINE_HATCH
;
143 data
->title_dress
= ADG_DRESS_TEXT_VALUE
;
144 data
->value_dress
= ADG_DRESS_TEXT_LIMIT
;
148 table_style
->data
= data
;
152 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
154 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
157 case PROP_COLOR_DRESS
:
158 g_value_set_int(value
, data
->color_dress
);
160 case PROP_BORDER_DRESS
:
161 g_value_set_int(value
, data
->border_dress
);
163 case PROP_GRID_DRESS
:
164 g_value_set_int(value
, data
->grid_dress
);
166 case PROP_TITLE_DRESS
:
167 g_value_set_int(value
, data
->title_dress
);
169 case PROP_VALUE_DRESS
:
170 g_value_set_int(value
, data
->value_dress
);
173 g_value_set_boxed(value
, &data
->padding
);
176 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
182 set_property(GObject
*object
,
183 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
185 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
188 case PROP_COLOR_DRESS
:
189 adg_dress_set(&data
->color_dress
, g_value_get_int(value
));
191 case PROP_BORDER_DRESS
:
192 adg_dress_set(&data
->border_dress
, g_value_get_int(value
));
194 case PROP_GRID_DRESS
:
195 adg_dress_set(&data
->grid_dress
, g_value_get_int(value
));
197 case PROP_TITLE_DRESS
:
198 adg_dress_set(&data
->title_dress
, g_value_get_int(value
));
200 case PROP_VALUE_DRESS
:
201 adg_dress_set(&data
->value_dress
, g_value_get_int(value
));
204 cpml_pair_copy(&data
->padding
, g_value_get_boxed(value
));
207 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
214 * adg_table_style_new:
216 * Constructs a new tableension style initialized with default params.
218 * Returns: a new tableension style
221 adg_table_style_new(void)
223 return g_object_new(ADG_TYPE_TABLE_STYLE
, NULL
);
227 * adg_table_style_get_color_dress:
228 * @table_style: an #AdgTableStyle object
230 * Gets the @table_style color dress to be used. This dress should be
231 * intended as a fallback color as it could be overriden by more
232 * specific dresses, such as a color explicitely specified on the
233 * #AdgTableStyle:value-dress.
235 * Returns: the color dress
238 adg_table_style_get_color_dress(AdgTableStyle
*table_style
)
240 AdgTableStylePrivate
*data
;
242 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
244 data
= table_style
->data
;
246 return data
->color_dress
;
250 * adg_table_style_set_color_dress:
251 * @table_style: an #AdgTableStyle object
252 * @dress: the new color dress
254 * Sets a new color dress on @table_style.
257 adg_table_style_set_color_dress(AdgTableStyle
*table_style
, AdgDress dress
)
259 AdgTableStylePrivate
*data
;
261 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
263 data
= table_style
->data
;
265 if (adg_dress_set(&data
->color_dress
, dress
))
266 g_object_notify((GObject
*) table_style
, "color-dress");
270 * adg_table_style_get_border_dress:
271 * @table_style: an #AdgTableStyle object
273 * Gets the line dress to be used for rendering the borders with
276 * Returns: the line dress
279 adg_table_style_get_border_dress(AdgTableStyle
*table_style
)
281 AdgTableStylePrivate
*data
;
283 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
285 data
= table_style
->data
;
287 return data
->border_dress
;
291 * adg_table_style_set_border_dress:
292 * @table_style: an #AdgTableStyle object
293 * @dress: the new line dress
295 * Sets a new line dress on @table_style for rendering the borders.
298 adg_table_style_set_border_dress(AdgTableStyle
*table_style
, AdgDress dress
)
300 AdgTableStylePrivate
*data
;
302 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
304 data
= table_style
->data
;
306 if (adg_dress_set(&data
->border_dress
, dress
))
307 g_object_notify((GObject
*) table_style
, "border-dress");
311 * adg_table_style_get_grid_dress:
312 * @table_style: an #AdgTableStyle object
314 * Gets the line dress to be used for rendering the grids with
317 * Returns: the line dress
320 adg_table_style_get_grid_dress(AdgTableStyle
*table_style
)
322 AdgTableStylePrivate
*data
;
324 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
326 data
= table_style
->data
;
328 return data
->grid_dress
;
332 * adg_table_style_set_grid_dress:
333 * @table_style: an #AdgTableStyle object
334 * @dress: the new line dress
336 * Sets a new line dress on @table_style for rendering the grids.
339 adg_table_style_set_grid_dress(AdgTableStyle
*table_style
, AdgDress dress
)
341 AdgTableStylePrivate
*data
;
343 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
345 data
= table_style
->data
;
347 if (adg_dress_set(&data
->grid_dress
, dress
))
348 g_object_notify((GObject
*) table_style
, "grid-dress");
352 * adg_table_style_get_title_dress:
353 * @table_style: an #AdgTableStyle object
355 * Gets the font dress to be used for rendering cell titles
358 * Returns: the font dress
361 adg_table_style_get_title_dress(AdgTableStyle
*table_style
)
363 AdgTableStylePrivate
*data
;
365 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
367 data
= table_style
->data
;
369 return data
->title_dress
;
373 * adg_table_style_set_title_dress:
374 * @table_style: an #AdgTableStyle object
375 * @dress: the new font dress
377 * Sets a new font dress on @table_style for rendering cell titles.
380 adg_table_style_set_title_dress(AdgTableStyle
*table_style
, AdgDress dress
)
382 AdgTableStylePrivate
*data
;
384 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
386 data
= table_style
->data
;
388 if (adg_dress_set(&data
->title_dress
, dress
))
389 g_object_notify((GObject
*) table_style
, "title-dress");
393 * adg_table_style_get_value_dress:
394 * @table_style: an #AdgTableStyle object
396 * Gets the font dress to be used for rendering cell values
399 * Returns: the font dress
402 adg_table_style_get_value_dress(AdgTableStyle
*table_style
)
404 AdgTableStylePrivate
*data
;
406 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
408 data
= table_style
->data
;
410 return data
->value_dress
;
414 * adg_table_style_set_value_dress:
415 * @table_style: an #AdgTableStyle object
416 * @dress: the new font dress
418 * Sets a new font dress on @table_style for rendering cell values.
421 adg_table_style_set_value_dress(AdgTableStyle
*table_style
, AdgDress dress
)
423 AdgTableStylePrivate
*data
;
425 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
427 data
= table_style
->data
;
429 if (adg_dress_set(&data
->value_dress
, dress
))
430 g_object_notify((GObject
*) table_style
, "value-dress");
434 * adg_table_style_get_padding:
435 * @table_style: an #AdgTableStyle object
437 * Gets the padding values in x and y to be left clear inside the cells.
438 * The returned pointer refers to an internal allocated struct and
439 * must not be modified or freed.
441 * Returns: the internal padding values
444 adg_table_style_get_padding(AdgTableStyle
*table_style
)
446 AdgTableStylePrivate
*data
;
448 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
450 data
= table_style
->data
;
452 return &data
->padding
;
456 * adg_table_style_set_padding:
457 * @table_style: an #AdgTableStyle object
458 * @padding: the new padding values
460 * Sets new #AdgTableStyle:padding values.
463 adg_table_style_set_padding(AdgTableStyle
*table_style
, const AdgPair
*padding
)
465 AdgTableStylePrivate
*data
;
467 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
468 g_return_if_fail(padding
!= NULL
);
470 data
= table_style
->data
;
471 cpml_pair_copy(&data
->padding
, padding
);
473 g_object_notify((GObject
*) table_style
, "padding");
478 apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
480 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) style
)->data
;
482 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);