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.
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.
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
37 #include "adg-table.h"
38 #include "adg-table-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-line-style.h"
43 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_table_parent_class)
44 #define PARENT_ENTITY_CLASS ((AdgEntityClass *) adg_table_parent_class)
52 static void get_property (GObject
*object
,
56 static void set_property (GObject
*object
,
60 static void arrange (AdgEntity
*entity
);
61 static void render (AdgEntity
*entity
,
65 G_DEFINE_TYPE(AdgTable
, adg_table
, ADG_TYPE_ENTITY
);
69 adg_table_class_init(AdgTableClass
*klass
)
71 GObjectClass
*gobject_class
;
72 AdgEntityClass
*entity_class
;
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",
88 P_("The dress to use for stroking this entity"),
91 g_object_class_install_property(gobject_class
, PROP_TABLE_DRESS
, param
);
95 adg_table_init(AdgTable
*table
)
97 AdgTablePrivate
*data
= G_TYPE_INSTANCE_GET_PRIVATE(table
,
101 data
->table_dress
= ADG_DRESS_TABLE
;
107 get_property(GObject
*object
, guint prop_id
, GValue
*value
, GParamSpec
*pspec
)
109 AdgTablePrivate
*data
= ((AdgTable
*) object
)->data
;
112 case PROP_TABLE_DRESS
:
113 g_value_set_int(value
, data
->table_dress
);
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
122 set_property(GObject
*object
, guint prop_id
,
123 const GValue
*value
, GParamSpec
*pspec
)
126 AdgTablePrivate
*data
;
128 table
= (AdgTable
*) object
;
132 case PROP_TABLE_DRESS
:
133 adg_dress_set(&data
->table_dress
, g_value_get_int(value
));
136 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
145 * Creates a new table entity.
147 * Returns: the newly created table entity
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
164 adg_table_get_table_dress(AdgTable
*table
)
166 AdgTablePrivate
*data
;
168 g_return_val_if_fail(ADG_IS_TABLE(table
), ADG_DRESS_UNDEFINED
);
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
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.
190 adg_table_set_table_dress(AdgTable
*table
, AdgDress dress
)
192 AdgTablePrivate
*data
;
194 g_return_if_fail(ADG_IS_TABLE(table
));
198 if (adg_dress_set(&data
->table_dress
, dress
))
199 g_object_notify((GObject
*) table
, "table-dress");
204 arrange(AdgEntity
*entity
)
210 render(AdgEntity
*entity
, cairo_t
*cr
)
213 AdgTablePrivate
*data
;
215 table
= (AdgTable
*) entity
;
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
);