1 /* Fo
2 * fo-property-inline-progression-dimension.c: 'inline-progression-dimension' property
3 *
4 * Copyright (C) 2001 Sun Microsystems
5 * Copyright (C) 2007 Menteith Consulting Ltd
6 *
7 * See COPYING for the status of this software.
8 */
9
10 #include <string.h>
11 #include "fo-utils.h"
12 #include "fo-context.h"
13 #include "datatype/fo-datatype.h"
14 #include "property/fo-property-private.h"
15 #include "property/fo-property-font-size.h"
16 #include "property/fo-property-inline-progression-dimension.h"
17
18 /* inline-progression-dimension */
19 /* Inherited: FALSE */
20 /* Shorthand: FALSE */
21 /* auto | <length> | <percentage> | <length-range> | inherit */
22 /* Initial value: auto */
23
24 struct _FoPropertyInlineProgressionDimension
25 {
26 FoProperty parent_instance;
27 };
28
29 struct _FoPropertyInlineProgressionDimensionClass
30 {
31 FoPropertyClass parent_class;
32 };
33
34 static void fo_property_inline_progression_dimension_init (FoPropertyInlineProgressionDimension *property_inline_progression_dimension);
35 static void fo_property_inline_progression_dimension_class_init (FoPropertyInlineProgressionDimensionClass *klass);
36 static void fo_property_inline_progression_dimension_finalize (GObject *object);
37
38 static FoDatatype* fo_property_inline_progression_dimension_resolve_enum (const gchar *token,
39 FoContext *context,
40 GError **error);
41 static FoDatatype* fo_property_inline_progression_dimension_validate (FoDatatype *datatype,
42 FoContext *context,
43 GError **error);
44
45 static const gchar class_name[] = "inline-progression-dimension";
46 static gpointer parent_class;
47
48 /**
49 * fo_property_inline_progression_dimension_get_type:
50 *
51 * Register the #FoPropertyInlineProgressionDimension type if not already registered and
52 * return its #GType value.
53 *
54 * Return value: #GType of #FoPropertyInlineProgressionDimension.
55 **/
56 GType
fo_property_inline_progression_dimension_get_type(void)57 fo_property_inline_progression_dimension_get_type (void)
58 {
59 static GType object_type = 0;
60
61 if (!object_type)
62 {
63 static const GTypeInfo object_info =
64 {
65 sizeof (FoPropertyInlineProgressionDimensionClass),
66 NULL, /* base_init */
67 NULL, /* base_finalize */
68 (GClassInitFunc) fo_property_inline_progression_dimension_class_init,
69 NULL, /* class_finalize */
70 NULL, /* class_data */
71 sizeof (FoPropertyInlineProgressionDimension),
72 0, /* n_preallocs */
73 (GInstanceInitFunc) fo_property_inline_progression_dimension_init,
74 NULL /* value_table */
75 };
76
77 object_type = g_type_register_static (FO_TYPE_PROPERTY,
78 class_name,
79 &object_info, 0);
80 }
81
82 return object_type;
83 }
84
85 /**
86 * fo_property_inline_progression_dimension_init:
87 * @inline_progression_dimension: #FoPropertyInlineProgressionDimension object to initialise.
88 *
89 * Implements #GInstanceInitFunc for #FoPropertyInlineProgressionDimension.
90 **/
91 void
fo_property_inline_progression_dimension_init(FoPropertyInlineProgressionDimension * inline_progression_dimension)92 fo_property_inline_progression_dimension_init (FoPropertyInlineProgressionDimension *inline_progression_dimension)
93 {
94 FO_PROPERTY (inline_progression_dimension)->value = fo_length_range_new_auto ();
95 }
96
97 /**
98 * fo_property_inline_progression_dimension_class_init:
99 * @klass: #FoPropertyInlineProgressionDimensionClass object to initialise.
100 *
101 * Implements #GClassInitFunc for #FoPropertyInlineProgressionDimensionClass.
102 **/
103 void
fo_property_inline_progression_dimension_class_init(FoPropertyInlineProgressionDimensionClass * klass)104 fo_property_inline_progression_dimension_class_init (FoPropertyInlineProgressionDimensionClass *klass)
105 {
106 GObjectClass *object_class = G_OBJECT_CLASS (klass);
107 FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
108
109 parent_class = g_type_class_peek_parent (klass);
110
111 object_class->finalize = fo_property_inline_progression_dimension_finalize;
112
113 property_class->is_inherited = FALSE;
114 property_class->is_shorthand = FALSE;
115 property_class->resolve_enum =
116 fo_property_inline_progression_dimension_resolve_enum;
117 property_class->validate =
118 fo_property_inline_progression_dimension_validate;
119 property_class->get_initial =
120 fo_property_inline_progression_dimension_get_initial;
121 }
122
123 /**
124 * fo_property_inline_progression_dimension_finalize:
125 * @object: #FoPropertyInlineProgressionDimension object to finalize.
126 *
127 * Implements #GObjectFinalizeFunc for #FoPropertyInlineProgressionDimension.
128 **/
129 void
fo_property_inline_progression_dimension_finalize(GObject * object)130 fo_property_inline_progression_dimension_finalize (GObject *object)
131 {
132 FoPropertyInlineProgressionDimension *inline_progression_dimension;
133
134 inline_progression_dimension = FO_PROPERTY_INLINE_PROGRESSION_DIMENSION (object);
135
136 G_OBJECT_CLASS (parent_class)->finalize (object);
137 }
138
139
140 /**
141 * fo_property_inline_progression_dimension_new:
142 *
143 * Creates a new #FoPropertyInlineProgressionDimension initialized to default value.
144 *
145 * Return value: the new #FoPropertyInlineProgressionDimension.
146 **/
147 FoProperty*
fo_property_inline_progression_dimension_new(void)148 fo_property_inline_progression_dimension_new (void)
149 {
150 FoProperty* inline_progression_dimension;
151
152 inline_progression_dimension =
153 FO_PROPERTY (g_object_new (fo_property_inline_progression_dimension_get_type (),
154 NULL));
155
156 return inline_progression_dimension;
157 }
158
159 /**
160 * fo_property_inline_progression_dimension_resolve_enum:
161 * @token: Token from the XML attribute value to be evaluated as an
162 * enumeration token.
163 * @context: #FoContext object from which to possibly inherit values.
164 * @error: Information about any error that has occurred.
165 *
166 * Compare @token against the enumeration tokens that are valid for the
167 * current FO property. If @token is valid, returns either an #FoEnum datatype
168 * representing the enumeration token or a different datatype representing
169 * the enumeration token's resolved value. If @token is not valid,
170 * sets @error and returns NULL.
171 *
172 * Return value: Resolved enumeration value or NULL.
173 **/
174 FoDatatype*
fo_property_inline_progression_dimension_resolve_enum(const gchar * token,FoContext * context,GError ** error)175 fo_property_inline_progression_dimension_resolve_enum (const gchar *token,
176 FoContext *context,
177 GError **error)
178 {
179 g_return_val_if_fail (token != NULL, NULL);
180 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
181 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
182
183 if (strcmp (token, "auto") == 0)
184 {
185 return g_object_ref (fo_length_range_new_auto ());
186 }
187 else
188 {
189 g_set_error (error,
190 FO_FO_ERROR,
191 FO_FO_ERROR_ENUMERATION_TOKEN,
192 _(fo_fo_error_messages[FO_FO_ERROR_ENUMERATION_TOKEN]),
193 class_name,
194 token);
195 return NULL;
196 }
197 }
198
199 /**
200 * fo_property_inline_progression_dimension_validate:
201 * @datatype: #FoDatatype to be validated against allowed datatypes and
202 * values for current property.
203 * @context: #FoContext object from which to possibly inherit values.
204 * @error: Information about any error that has occurred.
205 *
206 * Validates @datatype against allowed values. Returns @datatype, a
207 * replacement datatype value, or NULL if validation failed.
208 *
209 * Return value: Valid datatype value or NULL.
210 **/
211 FoDatatype*
fo_property_inline_progression_dimension_validate(FoDatatype * datatype,FoContext * context,GError ** error)212 fo_property_inline_progression_dimension_validate (FoDatatype *datatype,
213 FoContext *context,
214 GError **error)
215 {
216 FoDatatype *new_datatype;
217 GError *tmp_error = NULL;
218 gchar *token;
219
220 g_return_val_if_fail (datatype != NULL, NULL);
221 g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
222 g_return_val_if_fail (context != NULL, NULL);
223 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
224 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
225
226 if (FO_IS_ENUM (datatype))
227 {
228 FoEnumEnum value = fo_enum_get_value (datatype);
229
230 if ((value == FO_ENUM_ENUM_AUTO))
231 {
232 return datatype;
233 }
234 else
235 {
236 gchar *datatype_sprintf = fo_object_sprintf (datatype);
237
238 g_set_error (error,
239 FO_FO_ERROR,
240 FO_FO_ERROR_ENUMERATION_TOKEN,
241 _(fo_fo_error_messages[FO_FO_ERROR_ENUMERATION_TOKEN]),
242 class_name,
243 datatype_sprintf,
244 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
245
246 g_object_unref (datatype);
247
248 g_free (datatype_sprintf);
249
250 return NULL;
251 }
252 }
253 else if (FO_IS_STRING (datatype))
254 {
255 token = fo_string_get_value (datatype);
256
257 new_datatype =
258 fo_property_inline_progression_dimension_resolve_enum (token, context, &tmp_error);
259
260 g_object_unref (datatype);
261
262 fo_propagate_and_return_val_if_error (error, tmp_error, NULL);
263
264 return new_datatype;
265 }
266 else if (FO_IS_NAME (datatype))
267 {
268 token = fo_name_get_value (datatype);
269
270 new_datatype =
271 fo_property_inline_progression_dimension_resolve_enum (token, context, &tmp_error);
272
273 g_object_unref (datatype);
274
275 fo_propagate_and_return_val_if_error (error, tmp_error, NULL);
276
277 return new_datatype;
278 }
279 else if (FO_IS_LENGTH (datatype))
280 {
281 return datatype;
282 }
283 else if (FO_IS_PERCENTAGE (datatype))
284 {
285 return datatype;
286 }
287 else if (FO_IS_LENGTH_RANGE (datatype))
288 {
289 return datatype;
290 }
291 else
292 {
293 gchar *datatype_sprintf = fo_object_sprintf (datatype);
294
295 g_set_error (error,
296 FO_FO_ERROR,
297 FO_FO_ERROR_DATATYPE,
298 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
299 class_name,
300 datatype_sprintf,
301 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
302
303 g_object_unref (datatype);
304
305 g_free (datatype_sprintf);
306
307 return NULL;
308 }
309 }
310
311 /**
312 * fo_property_inline_progression_dimension_get_initial:
313 *
314 * Get an instance of the property with the correct initial value.
315 *
316 * Return value: An instance of the property.
317 **/
318 FoProperty*
fo_property_inline_progression_dimension_get_initial(void)319 fo_property_inline_progression_dimension_get_initial (void)
320 {
321 static FoProperty *inline_progression_dimension = NULL;
322
323 if (inline_progression_dimension == NULL)
324 {
325 inline_progression_dimension =
326 fo_property_inline_progression_dimension_new ();
327 }
328
329 return inline_progression_dimension;
330 }
331