1 /* Fo
2 * fo-property-padding-end.c: 'padding-end' 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 "datatype/fo-length-conditional.h"
15 #include "property/fo-property-private.h"
16 #include "property/fo-property-font-size.h"
17 #include "property/fo-property-padding-end.h"
18 #include "property/fo-property-util.h"
19
20 /* Inherited: FALSE */
21 /* Shorthand: FALSE */
22 /* padding-end */
23 /* <padding-width> | <length-conditional> | inherit */
24 /* NO ENUMERATED VALUE */
25
26
27 struct _FoPropertyPaddingEnd
28 {
29 FoProperty parent_instance;
30 };
31
32 struct _FoPropertyPaddingEndClass
33 {
34 FoPropertyClass parent_class;
35 };
36
37 static void fo_property_padding_end_init (FoPropertyPaddingEnd *property_padding_end);
38 static void fo_property_padding_end_class_init (FoPropertyPaddingEndClass *klass);
39 static void fo_property_padding_end_finalize (GObject *object);
40
41 static FoDatatype* fo_property_padding_end_resolve_enum (const gchar *token,
42 FoContext *context,
43 GError **error);
44 static FoDatatype* fo_property_padding_end_validate (FoDatatype *datatype,
45 FoContext *context,
46 GError **error);
47
48 static const gchar class_name[] = "padding-end";
49 static gpointer parent_class;
50
51 /**
52 * fo_property_padding_end_get_type:
53 *
54 * Register the #FoPropertyPaddingEnd type if not already registered and
55 * return its #GType value.
56 *
57 * Return value: #GType of #FoPropertyPaddingEnd.
58 **/
59 GType
fo_property_padding_end_get_type(void)60 fo_property_padding_end_get_type (void)
61 {
62 static GType object_type = 0;
63
64 if (!object_type)
65 {
66 static const GTypeInfo object_info =
67 {
68 sizeof (FoPropertyPaddingEndClass),
69 NULL, /* base_init */
70 NULL, /* base_finalize */
71 (GClassInitFunc) fo_property_padding_end_class_init,
72 NULL, /* class_finalize */
73 NULL, /* class_data */
74 sizeof (FoPropertyPaddingEnd),
75 0, /* n_preallocs */
76 (GInstanceInitFunc) fo_property_padding_end_init,
77 NULL /* value_table */
78 };
79
80 object_type = g_type_register_static (FO_TYPE_PROPERTY,
81 class_name,
82 &object_info, 0);
83 }
84
85 return object_type;
86 }
87
88 /**
89 * fo_property_padding_end_init:
90 * @padding_end: #FoPropertyPaddingEnd object to initialise.
91 *
92 * Implements #GInstanceInitFunc for #FoPropertyPaddingEnd.
93 **/
94 void
fo_property_padding_end_init(FoPropertyPaddingEnd * padding_end)95 fo_property_padding_end_init (FoPropertyPaddingEnd *padding_end)
96 {
97 FO_PROPERTY (padding_end)->value =
98 g_object_ref (fo_length_cond_get_length_cond_zero ());
99 }
100
101 /**
102 * fo_property_padding_end_class_init:
103 * @klass: #FoPropertyPaddingEndClass object to initialise.
104 *
105 * Implements #GClassInitFunc for #FoPropertyPaddingEndClass.
106 **/
107 void
fo_property_padding_end_class_init(FoPropertyPaddingEndClass * klass)108 fo_property_padding_end_class_init (FoPropertyPaddingEndClass *klass)
109 {
110 GObjectClass *object_class = G_OBJECT_CLASS (klass);
111 FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
112
113 parent_class = g_type_class_peek_parent (klass);
114
115 object_class->finalize = fo_property_padding_end_finalize;
116
117 property_class->is_inherited = FALSE;
118 property_class->is_shorthand = FALSE;
119 property_class->resolve_enum =
120 fo_property_padding_end_resolve_enum;
121 property_class->resolve_percent =
122 fo_property_util_resolve_ipdim_percent;
123 property_class->validate =
124 fo_property_padding_end_validate;
125 property_class->get_initial =
126 fo_property_padding_end_get_initial;
127 }
128
129 /**
130 * fo_property_padding_end_finalize:
131 * @object: #FoPropertyPaddingEnd object to finalize.
132 *
133 * Implements #GObjectFinalizeFunc for #FoPropertyPaddingEnd.
134 **/
135 void
fo_property_padding_end_finalize(GObject * object)136 fo_property_padding_end_finalize (GObject *object)
137 {
138 FoPropertyPaddingEnd *padding_end;
139
140 padding_end = FO_PROPERTY_PADDING_END (object);
141
142 G_OBJECT_CLASS (parent_class)->finalize (object);
143 }
144
145
146 /**
147 * fo_property_padding_end_new:
148 *
149 * Creates a new #FoPropertyPaddingEnd initialized to default value.
150 *
151 * Return value: the new #FoPropertyPaddingEnd.
152 **/
153 FoProperty*
fo_property_padding_end_new(void)154 fo_property_padding_end_new (void)
155 {
156 FoProperty* padding_end;
157
158 padding_end =
159 FO_PROPERTY (g_object_new (fo_property_padding_end_get_type (),
160 NULL));
161
162 return padding_end;
163 }
164
165 /**
166 * fo_property_padding_end_resolve_enum:
167 * @token: Token from the XML attribute value to be evaluated as an
168 * enumeration token.
169 * @context: #FoContext object from which to possibly inherit values.
170 * @error: Information about any error that has occurred.
171 *
172 * Compare @token against the enumeration tokens that are valid for the
173 * current FO property. If @token is valid, returns either an #FoEnum datatype
174 * representing the enumeration token or a different datatype representing
175 * the enumeration token's resolved value. If @token is not valid,
176 * sets @error and returns NULL.
177 *
178 * Return value: Resolved enumeration value or NULL.
179 **/
180 FoDatatype*
fo_property_padding_end_resolve_enum(const gchar * token,FoContext * context,GError ** error)181 fo_property_padding_end_resolve_enum (const gchar *token,
182 FoContext *context,
183 GError **error)
184 {
185 g_return_val_if_fail (token != NULL, NULL);
186 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
187 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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 * fo_property_padding_end_validate:
200 * @datatype: #FoDatatype to be validated against allowed datatypes and
201 * values for current property.
202 * @context: #FoContext object from which to possibly inherit values.
203 * @error: Information about any error that has occurred.
204 *
205 * Validates @datatype against allowed values. Returns @datatype, a
206 * replacement datatype value, or NULL if validation failed.
207 *
208 * Return value: Valid datatype value or NULL.
209 **/
210 FoDatatype*
fo_property_padding_end_validate(FoDatatype * datatype,FoContext * context,GError ** error)211 fo_property_padding_end_validate (FoDatatype *datatype,
212 FoContext *context,
213 GError **error)
214 {
215 g_return_val_if_fail (datatype != NULL, NULL);
216 g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
217 g_return_val_if_fail (context != NULL, NULL);
218 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
219 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
220
221 if (FO_IS_LENGTH (datatype))
222 {
223 return datatype;
224 }
225 else if (FO_IS_PERCENTAGE (datatype))
226 {
227 return datatype;
228 }
229 else if (FO_IS_LENGTH_COND (datatype))
230 {
231 return datatype;
232 }
233 else
234 {
235 gchar *datatype_sprintf = fo_object_sprintf (datatype);
236
237 g_set_error (error,
238 FO_FO_ERROR,
239 FO_FO_ERROR_DATATYPE,
240 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
241 class_name,
242 datatype_sprintf,
243 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
244
245 g_object_unref (datatype);
246
247 g_free (datatype_sprintf);
248
249 return NULL;
250 }
251 }
252
253 /**
254 * fo_property_padding_end_get_initial:
255 *
256 * Get an instance of the property with the correct initial value.
257 *
258 * Return value: An instance of the property.
259 **/
260 FoProperty*
fo_property_padding_end_get_initial(void)261 fo_property_padding_end_get_initial (void)
262 {
263 static FoProperty *padding_end = NULL;
264
265 if (padding_end == NULL)
266 {
267 padding_end = fo_property_padding_end_new ();
268 }
269
270 return padding_end;
271 }
272