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 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-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"
59 static void get_property (GObject
*object
,
63 static void set_property (GObject
*object
,
67 static void apply (AdgStyle
*style
,
72 G_DEFINE_TYPE(AdgTableStyle
, adg_table_style
, ADG_TYPE_STYLE
);
76 adg_table_style_class_init(AdgTableStyleClass
*klass
)
78 GObjectClass
*gobject_class
;
79 AdgStyleClass
*style_class
;
82 gobject_class
= (GObjectClass
*) klass
;
83 style_class
= (AdgStyleClass
*) klass
;
85 g_type_class_add_private(klass
, sizeof(AdgTableStylePrivate
));
87 gobject_class
->get_property
= get_property
;
88 gobject_class
->set_property
= set_property
;
90 style_class
->apply
= apply
;
92 param
= adg_param_spec_dress("color-dress",
94 P_("Color dress for the whole tableension"),
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_TEXT_LIMIT
,
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"),
123 ADG_DRESS_TEXT_VALUE
,
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
;
154 data
= G_TYPE_INSTANCE_GET_PRIVATE(table_style
, ADG_TYPE_TABLE_STYLE
,
155 AdgTableStylePrivate
);
157 data
->color_dress
= ADG_DRESS_COLOR
;
158 data
->grid_dress
= ADG_DRESS_LINE_GRID
;
159 data
->frame_dress
= ADG_DRESS_LINE_FRAME
;
160 data
->title_dress
= ADG_DRESS_TEXT_LIMIT
;
161 data
->value_dress
= ADG_DRESS_TEXT_VALUE
;
162 data
->row_height
= 30;
163 data
->cell_padding
.x
= 5;
164 data
->cell_padding
.y
= 5;
165 data
->cell_spacing
.x
= 0;
166 data
->cell_spacing
.y
= 0;
168 table_style
->data
= data
;
172 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
174 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
177 case PROP_COLOR_DRESS
:
178 g_value_set_int(value
, data
->color_dress
);
180 case PROP_GRID_DRESS
:
181 g_value_set_int(value
, data
->grid_dress
);
183 case PROP_FRAME_DRESS
:
184 g_value_set_int(value
, data
->frame_dress
);
186 case PROP_TITLE_DRESS
:
187 g_value_set_int(value
, data
->title_dress
);
189 case PROP_VALUE_DRESS
:
190 g_value_set_int(value
, data
->value_dress
);
192 case PROP_ROW_HEIGHT
:
193 g_value_set_double(value
, data
->row_height
);
195 case PROP_CELL_PADDING
:
196 g_value_set_boxed(value
, &data
->cell_padding
);
198 case PROP_CELL_SPACING
:
199 g_value_set_boxed(value
, &data
->cell_spacing
);
202 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
208 set_property(GObject
*object
,
209 guint prop_id
, const GValue
*value
, GParamSpec
*pspec
)
211 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) object
)->data
;
214 case PROP_COLOR_DRESS
:
215 adg_dress_set(&data
->color_dress
, g_value_get_int(value
));
217 case PROP_GRID_DRESS
:
218 adg_dress_set(&data
->grid_dress
, g_value_get_int(value
));
220 case PROP_FRAME_DRESS
:
221 adg_dress_set(&data
->frame_dress
, g_value_get_int(value
));
223 case PROP_TITLE_DRESS
:
224 adg_dress_set(&data
->title_dress
, g_value_get_int(value
));
226 case PROP_VALUE_DRESS
:
227 adg_dress_set(&data
->value_dress
, g_value_get_int(value
));
229 case PROP_ROW_HEIGHT
:
230 data
->row_height
= g_value_get_double(value
);
232 case PROP_CELL_PADDING
:
233 cpml_pair_copy(&data
->cell_padding
, g_value_get_boxed(value
));
235 case PROP_CELL_SPACING
:
236 cpml_pair_copy(&data
->cell_spacing
, g_value_get_boxed(value
));
239 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
246 * adg_table_style_new:
248 * Constructs a new tableension style initialized with default params.
250 * Returns: a new tableension 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.
266 adg_table_style_set_color_dress(AdgTableStyle
*table_style
, AdgDress dress
)
268 AdgTableStylePrivate
*data
;
270 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
272 data
= table_style
->data
;
274 if (adg_dress_set(&data
->color_dress
, dress
))
275 g_object_notify((GObject
*) table_style
, "color-dress");
279 * adg_table_style_get_color_dress:
280 * @table_style: an #AdgTableStyle object
282 * Gets the @table_style color dress to be used. This dress should be
283 * intended as a fallback color as it could be overriden by more
284 * specific dresses, such as a color explicitely specified on the
285 * #AdgTableStyle:value-dress.
287 * Returns: the color dress
290 adg_table_style_get_color_dress(AdgTableStyle
*table_style
)
292 AdgTableStylePrivate
*data
;
294 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
296 data
= table_style
->data
;
298 return data
->color_dress
;
302 * adg_table_style_set_frame_dress:
303 * @table_style: an #AdgTableStyle object
304 * @dress: the new line dress
306 * 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 AdgTableStylePrivate
*data
;
313 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
315 data
= table_style
->data
;
317 if (adg_dress_set(&data
->frame_dress
, dress
))
318 g_object_notify((GObject
*) table_style
, "frame-dress");
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: the line dress
331 adg_table_style_get_frame_dress(AdgTableStyle
*table_style
)
333 AdgTableStylePrivate
*data
;
335 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
337 data
= table_style
->data
;
339 return data
->frame_dress
;
343 * adg_table_style_set_grid_dress:
344 * @table_style: an #AdgTableStyle object
345 * @dress: the new line dress
347 * Sets a new line dress on @table_style for rendering the grids.
350 adg_table_style_set_grid_dress(AdgTableStyle
*table_style
, AdgDress dress
)
352 AdgTableStylePrivate
*data
;
354 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
356 data
= table_style
->data
;
358 if (adg_dress_set(&data
->grid_dress
, dress
))
359 g_object_notify((GObject
*) table_style
, "grid-dress");
363 * adg_table_style_get_grid_dress:
364 * @table_style: an #AdgTableStyle object
366 * Gets the line dress to be used for rendering the grids with
369 * Returns: 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.
391 adg_table_style_set_title_dress(AdgTableStyle
*table_style
, AdgDress dress
)
393 AdgTableStylePrivate
*data
;
395 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
397 data
= table_style
->data
;
399 if (adg_dress_set(&data
->title_dress
, dress
))
400 g_object_notify((GObject
*) table_style
, "title-dress");
404 * adg_table_style_get_title_dress:
405 * @table_style: an #AdgTableStyle object
407 * Gets the font dress to be used for rendering cell titles
410 * Returns: the font dress
413 adg_table_style_get_title_dress(AdgTableStyle
*table_style
)
415 AdgTableStylePrivate
*data
;
417 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
419 data
= table_style
->data
;
421 return data
->title_dress
;
425 * adg_table_style_set_value_dress:
426 * @table_style: an #AdgTableStyle object
427 * @dress: the new font dress
429 * 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 AdgTableStylePrivate
*data
;
436 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
438 data
= table_style
->data
;
440 if (adg_dress_set(&data
->value_dress
, dress
))
441 g_object_notify((GObject
*) table_style
, "value-dress");
445 * adg_table_style_get_value_dress:
446 * @table_style: an #AdgTableStyle object
448 * Gets the font dress to be used for rendering cell values
451 * Returns: the font dress
454 adg_table_style_get_value_dress(AdgTableStyle
*table_style
)
456 AdgTableStylePrivate
*data
;
458 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), ADG_DRESS_UNDEFINED
);
460 data
= table_style
->data
;
462 return data
->value_dress
;
466 * adg_table_style_set_row_height:
467 * @table_style: an #AdgTableStyle object
468 * @row_heigth: the new row heigth fallback
470 * Sets a new #AdgTableStyle:row-height fallback. @row_height must
471 * be a valid row height greather than %0 or a warning will be
472 * raised and this function will fail.
475 adg_table_style_set_row_height(AdgTableStyle
*table_style
, gdouble row_height
)
477 AdgTableStylePrivate
*data
;
479 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
480 g_return_if_fail(row_height
> 0);
482 data
= table_style
->data
;
484 if (row_height
== data
->row_height
)
487 data
->row_height
= row_height
;
489 g_object_notify((GObject
*) table_style
, "row-height");
493 * adg_table_style_get_row_height:
494 * @table_style: an #AdgTableStyle object
496 * Gets the row height fallback value.
498 * Returns: the fallback row height or %0 on errors
501 adg_table_style_get_row_height(AdgTableStyle
*table_style
)
503 AdgTableStylePrivate
*data
;
505 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), 0);
507 data
= table_style
->data
;
509 return data
->row_height
;
513 * adg_table_style_set_cell_padding:
514 * @table_style: an #AdgTableStyle object
515 * @cell_padding: the new padding values
517 * Sets new #AdgTableStyle:cell-padding values.
520 adg_table_style_set_cell_padding(AdgTableStyle
*table_style
,
521 const AdgPair
*cell_padding
)
523 AdgTableStylePrivate
*data
;
525 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
526 g_return_if_fail(cell_padding
!= NULL
);
528 data
= table_style
->data
;
529 cpml_pair_copy(&data
->cell_padding
, cell_padding
);
531 g_object_notify((GObject
*) table_style
, "cell-padding");
535 * adg_table_style_get_cell_padding:
536 * @table_style: an #AdgTableStyle object
538 * Gets the padding values in x and y to be left clear inside the cells.
539 * The returned pointer refers to an internal allocated struct and
540 * must not be modified or freed.
542 * The cell padding is a symmetric value, that is the padding on the
543 * left will always be equal to the padding on the right and the top
544 * will always be equal to the bottom.
546 * Returns: the cell padding values or %NULL on errors
549 adg_table_style_get_cell_padding(AdgTableStyle
*table_style
)
551 AdgTableStylePrivate
*data
;
553 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
555 data
= table_style
->data
;
557 return &data
->cell_padding
;
561 * adg_table_style_set_cell_spacing:
562 * @table_style: an #AdgTableStyle object
563 * @cell_spacing: the new spacing values
565 * Sets new #AdgTableStyle:cell-spacing values.
568 adg_table_style_set_cell_spacing(AdgTableStyle
*table_style
,
569 const AdgPair
*cell_spacing
)
571 AdgTableStylePrivate
*data
;
573 g_return_if_fail(ADG_IS_TABLE_STYLE(table_style
));
574 g_return_if_fail(cell_spacing
!= NULL
);
576 data
= table_style
->data
;
577 cpml_pair_copy(&data
->cell_spacing
, cell_spacing
);
579 g_object_notify((GObject
*) table_style
, "cell-spacing");
583 * adg_table_style_get_cell_spacing:
584 * @table_style: an #AdgTableStyle object
586 * Gets the spacing values in x and y to be left between the cell
587 * boundary boxes. The returned pointer refers to an internal
588 * allocated struct and must not be modified or freed.
590 * The cell spacing is a symmetric value, that is the spacing on the
591 * left will always be equal to the spacing on the right and the top
592 * will always be equal to the bottom.
594 * Returns: the cell spacing values or %NULL on errors
597 adg_table_style_get_cell_spacing(AdgTableStyle
*table_style
)
599 AdgTableStylePrivate
*data
;
601 g_return_val_if_fail(ADG_IS_TABLE_STYLE(table_style
), NULL
);
603 data
= table_style
->data
;
605 return &data
->cell_spacing
;
610 apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
612 AdgTableStylePrivate
*data
= ((AdgTableStyle
*) style
)->data
;
614 adg_entity_apply_dress(entity
, data
->color_dress
, cr
);