1 /* Fo
2 * fo-property-padding-start-length.c: 'padding-start-length' 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-padding-start-length.h"
17
18 /* padding-start-length */
19 /* Inherited: FALSE */
20 /* Shorthand: FALSE */
21 /* <length> */
22 /* Initial value: 0pt */
23
24 struct _FoPropertyPaddingStartLength
25 {
26 FoProperty parent_instance;
27 };
28
29 struct _FoPropertyPaddingStartLengthClass
30 {
31 FoPropertyClass parent_class;
32 };
33
34 static void fo_property_padding_start_length_init (FoPropertyPaddingStartLength *property_padding_start_length);
35 static void fo_property_padding_start_length_class_init (FoPropertyPaddingStartLengthClass *klass);
36 static void fo_property_padding_start_length_finalize (GObject *object);
37
38 static FoDatatype* fo_property_padding_start_length_resolve_enum (const gchar *token,
39 FoContext *context,
40 GError **error);
41 static FoDatatype* fo_property_padding_start_length_validate (FoDatatype *datatype,
42 FoContext *context,
43 GError **error);
44
45 static const gchar class_name[] = "padding-start-length";
46 static gpointer parent_class;
47
48 /**
49 * fo_property_padding_start_length_get_type:
50 *
51 * Register the #FoPropertyPaddingStartLength type if not already registered and
52 * return its #GType value.
53 *
54 * Return value: #GType of #FoPropertyPaddingStartLength.
55 **/
56 GType
fo_property_padding_start_length_get_type(void)57 fo_property_padding_start_length_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 (FoPropertyPaddingStartLengthClass),
66 NULL, /* base_init */
67 NULL, /* base_finalize */
68 (GClassInitFunc) fo_property_padding_start_length_class_init,
69 NULL, /* class_finalize */
70 NULL, /* class_data */
71 sizeof (FoPropertyPaddingStartLength),
72 0, /* n_preallocs */
73 (GInstanceInitFunc) fo_property_padding_start_length_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_padding_start_length_init:
87 * @padding_start_length: #FoPropertyPaddingStartLength object to initialise.
88 *
89 * Implements #GInstanceInitFunc for #FoPropertyPaddingStartLength.
90 **/
91 void
fo_property_padding_start_length_init(FoPropertyPaddingStartLength * padding_start_length)92 fo_property_padding_start_length_init (FoPropertyPaddingStartLength *padding_start_length)
93 {
94 FO_PROPERTY (padding_start_length)->value =
95 NULL;
96 }
97
98 /**
99 * fo_property_padding_start_length_class_init:
100 * @klass: #FoPropertyPaddingStartLengthClass object to initialise.
101 *
102 * Implements #GClassInitFunc for #FoPropertyPaddingStartLengthClass.
103 **/
104 void
fo_property_padding_start_length_class_init(FoPropertyPaddingStartLengthClass * klass)105 fo_property_padding_start_length_class_init (FoPropertyPaddingStartLengthClass *klass)
106 {
107 GObjectClass *object_class = G_OBJECT_CLASS (klass);
108 FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
109
110 parent_class = g_type_class_peek_parent (klass);
111
112 object_class->finalize = fo_property_padding_start_length_finalize;
113
114 property_class->is_inherited = FALSE;
115 property_class->is_shorthand = FALSE;
116 property_class->resolve_enum =
117 fo_property_padding_start_length_resolve_enum;
118 property_class->validate =
119 fo_property_padding_start_length_validate;
120 property_class->get_initial =
121 fo_property_padding_start_length_get_initial;
122 }
123
124 /**
125 * fo_property_padding_start_length_finalize:
126 * @object: #FoPropertyPaddingStartLength object to finalize.
127 *
128 * Implements #GObjectFinalizeFunc for #FoPropertyPaddingStartLength.
129 **/
130 void
fo_property_padding_start_length_finalize(GObject * object)131 fo_property_padding_start_length_finalize (GObject *object)
132 {
133 FoPropertyPaddingStartLength *padding_start_length;
134
135 padding_start_length = FO_PROPERTY_PADDING_START_LENGTH (object);
136
137 G_OBJECT_CLASS (parent_class)->finalize (object);
138 }
139
140
141 /**
142 * fo_property_padding_start_length_new:
143 *
144 * Creates a new #FoPropertyPaddingStartLength initialized to default value.
145 *
146 * Return value: the new #FoPropertyPaddingStartLength.
147 **/
148 FoProperty*
fo_property_padding_start_length_new(void)149 fo_property_padding_start_length_new (void)
150 {
151 FoProperty* padding_start_length;
152
153 padding_start_length =
154 FO_PROPERTY (g_object_new (fo_property_padding_start_length_get_type (),
155 NULL));
156
157 return padding_start_length;
158 }
159
160 /**
161 * fo_property_padding_start_length_resolve_enum:
162 * @token: Token from the XML attribute value to be evaluated as an
163 * enumeration token.
164 * @context: #FoContext object from which to possibly inherit values.
165 * @error: Information about any error that has occurred.
166 *
167 * Compare @token against the enumeration tokens that are valid for the
168 * current FO property. If @token is valid, returns either an #FoEnum datatype
169 * representing the enumeration token or a different datatype representing
170 * the enumeration token's resolved value. If @token is not valid,
171 * sets @error and returns NULL.
172 *
173 * Return value: Resolved enumeration value or NULL.
174 **/
175 FoDatatype*
fo_property_padding_start_length_resolve_enum(const gchar * token,FoContext * context,GError ** error)176 fo_property_padding_start_length_resolve_enum (const gchar *token,
177 FoContext *context,
178 GError **error)
179 {
180 g_return_val_if_fail (token != NULL, NULL);
181 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
182 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
183
184 g_set_error (error,
185 FO_FO_ERROR,
186 FO_FO_ERROR_ENUMERATION_TOKEN,
187 _(fo_fo_error_messages[FO_FO_ERROR_ENUMERATION_TOKEN]),
188 class_name,
189 token);
190 return NULL;
191 }
192
193 /**
194 * fo_property_padding_start_length_validate:
195 * @datatype: #FoDatatype to be validated against allowed datatypes and
196 * values for current property.
197 * @context: #FoContext object from which to possibly inherit values.
198 * @error: Information about any error that has occurred.
199 *
200 * Validates @datatype against allowed values. Returns @datatype, a
201 * replacement datatype value, or NULL if validation failed.
202 *
203 * Return value: Valid datatype value or NULL.
204 **/
205 FoDatatype*
fo_property_padding_start_length_validate(FoDatatype * datatype,FoContext * context,GError ** error)206 fo_property_padding_start_length_validate (FoDatatype *datatype,
207 FoContext *context,
208 GError **error)
209 {
210 g_return_val_if_fail (datatype != NULL, NULL);
211 g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
212 g_return_val_if_fail (context != NULL, NULL);
213 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
214 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
215
216 if (FO_IS_LENGTH (datatype))
217 {
218 return datatype;
219 }
220 else
221 {
222 gchar *datatype_sprintf = fo_object_sprintf (datatype);
223
224 g_set_error (error,
225 FO_FO_ERROR,
226 FO_FO_ERROR_DATATYPE,
227 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
228 class_name,
229 datatype_sprintf,
230 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
231
232 g_object_unref (datatype);
233
234 g_free (datatype_sprintf);
235
236 return NULL;
237 }
238 }
239
240 /**
241 * fo_property_padding_start_length_get_initial:
242 *
243 * Get an instance of the property with the correct initial value.
244 *
245 * Return value: An instance of the property.
246 **/
247 FoProperty*
fo_property_padding_start_length_get_initial(void)248 fo_property_padding_start_length_get_initial (void)
249 {
250 static FoProperty *padding_start_length = NULL;
251
252 if (padding_start_length == NULL)
253 {
254 padding_start_length =
255 fo_property_padding_start_length_new ();
256 }
257
258 return padding_start_length;
259 }
260