[AdgTable] First stub implementation
[adg.git] / adg / adg-table.c
blob3f4a3052e7721c5ab81e1a15e5709ee049b99049
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.
21 /**
22 * SECTION:adg-table
23 * @short_description: A tabled entity
25 * The #AdgTable is a simple table of evenly spaced rows. Every cell
26 * can optionally contains a title and a value text.
27 **/
29 /**
30 * AdgTable:
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
34 **/
37 #include "adg-table.h"
38 #include "adg-table-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-line-style.h"
41 #include "adg-intl.h"
43 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_table_parent_class)
44 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_table_parent_class)
47 enum {
48 PROP_0,
49 PROP_TABLE_DRESS
52 static void get_property (GObject *object,
53 guint param_id,
54 GValue *value,
55 GParamSpec *pspec);
56 static void set_property (GObject *object,
57 guint param_id,
58 const GValue *value,
59 GParamSpec *pspec);
60 static void arrange (AdgEntity *entity);
61 static void render (AdgEntity *entity,
62 cairo_t *cr);
65 G_DEFINE_TYPE(AdgTable, adg_table, ADG_TYPE_ENTITY);
68 static void
69 adg_table_class_init(AdgTableClass *klass)
71 GObjectClass *gobject_class;
72 AdgEntityClass *entity_class;
73 GParamSpec *param;
75 gobject_class = (GObjectClass *) klass;
76 entity_class = (AdgEntityClass *) klass;
78 g_type_class_add_private(klass, sizeof(AdgTablePrivate));
80 gobject_class->get_property = get_property;
81 gobject_class->set_property = set_property;
83 entity_class->arrange = arrange;
84 entity_class->render = render;
86 param = adg_param_spec_dress("table-dress",
87 P_("Table Dress"),
88 P_("The dress to use for stroking this entity"),
89 ADG_DRESS_TABLE,
90 G_PARAM_READWRITE);
91 g_object_class_install_property(gobject_class, PROP_TABLE_DRESS, param);
94 static void
95 adg_table_init(AdgTable *table)
97 AdgTablePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(table,
98 ADG_TYPE_TABLE,
99 AdgTablePrivate);
101 data->table_dress = ADG_DRESS_TABLE;
103 table->data = data;
106 static void
107 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
109 AdgTablePrivate *data = ((AdgTable *) object)->data;
111 switch (prop_id) {
112 case PROP_TABLE_DRESS:
113 g_value_set_int(value, data->table_dress);
114 break;
115 default:
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
117 break;
121 static void
122 set_property(GObject *object, guint prop_id,
123 const GValue *value, GParamSpec *pspec)
125 AdgTable *table;
126 AdgTablePrivate *data;
128 table = (AdgTable *) object;
129 data = table->data;
131 switch (prop_id) {
132 case PROP_TABLE_DRESS:
133 adg_dress_set(&data->table_dress, g_value_get_int(value));
134 break;
135 default:
136 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
137 break;
143 * adg_table_new:
145 * Creates a new table entity.
147 * Returns: the newly created table entity
149 AdgTable *
150 adg_table_new(void)
152 return g_object_new(ADG_TYPE_TABLE, NULL);
156 * adg_table_get_table_dress:
157 * @table: an #AdgTable
159 * Gets the table dress to be used in rendering @table.
161 * Returns: the current table dress
163 AdgDress
164 adg_table_get_table_dress(AdgTable *table)
166 AdgTablePrivate *data;
168 g_return_val_if_fail(ADG_IS_TABLE(table), ADG_DRESS_UNDEFINED);
170 data = table->data;
172 return data->table_dress;
176 * adg_table_set_table_dress:
177 * @table: an #AdgTable
178 * @dress: the new #AdgDress to use
180 * Sets a new table dress for rendering @table. The new dress
181 * must be related to the original dress for this property:
182 * you cannot set a dress used for line styles to a dress
183 * managing fonts.
185 * The check is done by calling adg_dress_are_related() with
186 * @dress and the previous dress as arguments. Check out its
187 * documentation for details on what is a related dress.
189 void
190 adg_table_set_table_dress(AdgTable *table, AdgDress dress)
192 AdgTablePrivate *data;
194 g_return_if_fail(ADG_IS_TABLE(table));
196 data = table->data;
198 if (adg_dress_set(&data->table_dress, dress))
199 g_object_notify((GObject *) table, "table-dress");
203 static void
204 arrange(AdgEntity *entity)
206 /* TODO */
209 static void
210 render(AdgEntity *entity, cairo_t *cr)
212 AdgTable *table;
213 AdgTablePrivate *data;
215 table = (AdgTable *) entity;
216 data = table->data;
218 if (data->border != NULL)
219 adg_entity_render((AdgEntity *) data->border, cr);
221 if (data->grid != NULL)
222 adg_entity_render((AdgEntity *) data->grid, cr);