1 /* Fo
2 * fo-property-block-progression-dimension-optimum.c: 'block-progression-dimension-optimum' 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-block-progression-dimension-optimum.h"
17 #include "property/fo-property-util.h"
18
19 /* block-progression-dimension-optimum */
20 /* Inherited: FALSE */
21 /* Shorthand: FALSE */
22 /* auto | <length> */
23 /* Initial value: auto */
24
25 struct _FoPropertyBlockProgressionDimensionOptimum
26 {
27 FoProperty parent_instance;
28 };
29
30 struct _FoPropertyBlockProgressionDimensionOptimumClass
31 {
32 FoPropertyClass parent_class;
33 };
34
35 static void fo_property_block_progression_dimension_optimum_init (FoPropertyBlockProgressionDimensionOptimum *property_block_progression_dimension_optimum);
36 static void fo_property_block_progression_dimension_optimum_class_init (FoPropertyBlockProgressionDimensionOptimumClass *klass);
37 static void fo_property_block_progression_dimension_optimum_finalize (GObject *object);
38
39 static FoDatatype* fo_property_block_progression_dimension_optimum_validate (FoDatatype *datatype,
40 FoContext *context,
41 GError **error);
42
43 static const gchar class_name[] = "block-progression-dimension-optimum";
44 static gpointer parent_class;
45
46 /**
47 * fo_property_block_progression_dimension_optimum_get_type:
48 *
49 * Register the #FoPropertyBlockProgressionDimensionOptimum type if not already registered and
50 * return its #GType value.
51 *
52 * Return value: #GType of #FoPropertyBlockProgressionDimensionOptimum.
53 **/
54 GType
fo_property_block_progression_dimension_optimum_get_type(void)55 fo_property_block_progression_dimension_optimum_get_type (void)
56 {
57 static GType object_type = 0;
58
59 if (!object_type)
60 {
61 static const GTypeInfo object_info =
62 {
63 sizeof (FoPropertyBlockProgressionDimensionOptimumClass),
64 NULL, /* base_init */
65 NULL, /* base_finalize */
66 (GClassInitFunc) fo_property_block_progression_dimension_optimum_class_init,
67 NULL, /* class_finalize */
68 NULL, /* class_data */
69 sizeof (FoPropertyBlockProgressionDimensionOptimum),
70 0, /* n_preallocs */
71 (GInstanceInitFunc) fo_property_block_progression_dimension_optimum_init,
72 NULL /* value_table */
73 };
74
75 object_type = g_type_register_static (FO_TYPE_PROPERTY,
76 class_name,
77 &object_info, 0);
78 }
79
80 return object_type;
81 }
82
83 /**
84 * fo_property_block_progression_dimension_optimum_init:
85 * @block_progression_dimension_optimum: #FoPropertyBlockProgressionDimensionOptimum object to initialise.
86 *
87 * Implements #GInstanceInitFunc for #FoPropertyBlockProgressionDimensionOptimum.
88 **/
89 void
fo_property_block_progression_dimension_optimum_init(FoPropertyBlockProgressionDimensionOptimum * block_progression_dimension_optimum)90 fo_property_block_progression_dimension_optimum_init (FoPropertyBlockProgressionDimensionOptimum *block_progression_dimension_optimum)
91 {
92 FO_PROPERTY (block_progression_dimension_optimum)->value =
93 g_object_ref (fo_enum_factory_get_enum_by_value (FO_ENUM_ENUM_AUTO));
94 }
95
96 /**
97 * fo_property_block_progression_dimension_optimum_class_init:
98 * @klass: #FoPropertyBlockProgressionDimensionOptimumClass object to initialise.
99 *
100 * Implements #GClassInitFunc for #FoPropertyBlockProgressionDimensionOptimumClass.
101 **/
102 void
fo_property_block_progression_dimension_optimum_class_init(FoPropertyBlockProgressionDimensionOptimumClass * klass)103 fo_property_block_progression_dimension_optimum_class_init (FoPropertyBlockProgressionDimensionOptimumClass *klass)
104 {
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
106 FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
107
108 parent_class = g_type_class_peek_parent (klass);
109
110 object_class->finalize = fo_property_block_progression_dimension_optimum_finalize;
111
112 property_class->is_inherited = FALSE;
113 property_class->is_shorthand = FALSE;
114 property_class->resolve_enum =
115 fo_property_util_resolve_auto_enum;
116 property_class->validate =
117 fo_property_block_progression_dimension_optimum_validate;
118 property_class->get_initial =
119 fo_property_block_progression_dimension_optimum_get_initial;
120 }
121
122 /**
123 * fo_property_block_progression_dimension_optimum_finalize:
124 * @object: #FoPropertyBlockProgressionDimensionOptimum object to finalize.
125 *
126 * Implements #GObjectFinalizeFunc for #FoPropertyBlockProgressionDimensionOptimum.
127 **/
128 void
fo_property_block_progression_dimension_optimum_finalize(GObject * object)129 fo_property_block_progression_dimension_optimum_finalize (GObject *object)
130 {
131 FoPropertyBlockProgressionDimensionOptimum *block_progression_dimension_optimum;
132
133 block_progression_dimension_optimum = FO_PROPERTY_BLOCK_PROGRESSION_DIMENSION_OPTIMUM (object);
134
135 G_OBJECT_CLASS (parent_class)->finalize (object);
136 }
137
138
139 /**
140 * fo_property_block_progression_dimension_optimum_new:
141 *
142 * Creates a new #FoPropertyBlockProgressionDimensionOptimum initialized to default value.
143 *
144 * Return value: the new #FoPropertyBlockProgressionDimensionOptimum.
145 **/
146 FoProperty*
fo_property_block_progression_dimension_optimum_new(void)147 fo_property_block_progression_dimension_optimum_new (void)
148 {
149 FoProperty* block_progression_dimension_optimum;
150
151 block_progression_dimension_optimum =
152 FO_PROPERTY (g_object_new (fo_property_block_progression_dimension_optimum_get_type (),
153 NULL));
154
155 return block_progression_dimension_optimum;
156 }
157
158 /**
159 * fo_property_block_progression_dimension_optimum_validate:
160 * @datatype: #FoDatatype to be validated against allowed datatypes and
161 * values for current property.
162 * @context: #FoContext object from which to possibly inherit values.
163 * @error: Information about any error that has occurred.
164 *
165 * Validates @datatype against allowed values. Returns @datatype, a
166 * replacement datatype value, or NULL if validation failed.
167 *
168 * Return value: Valid datatype value or NULL.
169 **/
170 FoDatatype*
fo_property_block_progression_dimension_optimum_validate(FoDatatype * datatype,FoContext * context,GError ** error)171 fo_property_block_progression_dimension_optimum_validate (FoDatatype *datatype,
172 FoContext *context,
173 GError **error)
174 {
175 FoDatatype *new_datatype;
176 GError *tmp_error = NULL;
177 gchar *token;
178
179 g_return_val_if_fail (datatype != NULL, NULL);
180 g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
181 g_return_val_if_fail (context != NULL, NULL);
182 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
183 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
184
185 if (FO_IS_ENUM (datatype))
186 {
187 FoEnumEnum value = fo_enum_get_value (datatype);
188
189 if ((value == FO_ENUM_ENUM_AUTO))
190 {
191 return datatype;
192 }
193 else
194 {
195 gchar *datatype_sprintf = fo_object_sprintf (datatype);
196
197 g_set_error (error,
198 FO_FO_ERROR,
199 FO_FO_ERROR_ENUMERATION_TOKEN,
200 _(fo_fo_error_messages[FO_FO_ERROR_ENUMERATION_TOKEN]),
201 class_name,
202 datatype_sprintf,
203 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
204
205 g_object_unref (datatype);
206
207 g_free (datatype_sprintf);
208
209 return NULL;
210 }
211 }
212 else if (FO_IS_STRING (datatype))
213 {
214 token = fo_string_get_value (datatype);
215
216 new_datatype =
217 fo_property_util_resolve_auto_enum (token, context, &tmp_error);
218
219 g_object_unref (datatype);
220
221 fo_propagate_and_return_val_if_error (error, tmp_error, NULL);
222
223 return new_datatype;
224 }
225 else if (FO_IS_NAME (datatype))
226 {
227 token = fo_name_get_value (datatype);
228
229 new_datatype =
230 fo_property_util_resolve_auto_enum (token, context, &tmp_error);
231
232 g_object_unref (datatype);
233
234 fo_propagate_and_return_val_if_error (error, tmp_error, NULL);
235
236 return new_datatype;
237 }
238 else if (FO_IS_LENGTH (datatype))
239 {
240 return datatype;
241 }
242 else
243 {
244 gchar *datatype_sprintf = fo_object_sprintf (datatype);
245
246 g_set_error (error,
247 FO_FO_ERROR,
248 FO_FO_ERROR_DATATYPE,
249 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
250 class_name,
251 datatype_sprintf,
252 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
253
254 g_object_unref (datatype);
255
256 g_free (datatype_sprintf);
257
258 return NULL;
259 }
260 }
261
262 /**
263 * fo_property_block_progression_dimension_optimum_get_initial:
264 *
265 * Get an instance of the property with the correct initial value.
266 *
267 * Return value: An instance of the property.
268 **/
269 FoProperty*
fo_property_block_progression_dimension_optimum_get_initial(void)270 fo_property_block_progression_dimension_optimum_get_initial (void)
271 {
272 static FoProperty *block_progression_dimension_optimum = NULL;
273
274 if (block_progression_dimension_optimum == NULL)
275 {
276 block_progression_dimension_optimum =
277 fo_property_block_progression_dimension_optimum_new ();
278 }
279
280 return block_progression_dimension_optimum;
281 }
282