1 /* Fo
2 * fo-property-padding-top.c: 'padding-top' 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-top.h"
18 #include "property/fo-property-util.h"
19
20 /* Inherited: FALSE */
21 /* Shorthand: FALSE */
22 /* padding-top */
23 /* <padding-width> | inherit */
24 /* NO ENUMERATED VALUE */
25
26
27 struct _FoPropertyPaddingTop
28 {
29 FoProperty parent_instance;
30 };
31
32 struct _FoPropertyPaddingTopClass
33 {
34 FoPropertyClass parent_class;
35 };
36
37 static void fo_property_padding_top_init (FoPropertyPaddingTop *property_padding_top);
38 static void fo_property_padding_top_class_init (FoPropertyPaddingTopClass *klass);
39 static void fo_property_padding_top_finalize (GObject *object);
40
41 static FoDatatype* fo_property_padding_top_resolve_enum (const gchar *token,
42 FoContext *context,
43 GError **error);
44 static FoDatatype* fo_property_padding_top_validate (FoDatatype *datatype,
45 FoContext *context,
46 GError **error);
47
48 static const gchar class_name[] = "padding-top";
49 static gpointer parent_class;
50
51 /**
52 * fo_property_padding_top_get_type:
53 *
54 * Register the #FoPropertyPaddingTop type if not already registered and
55 * return its #GType value.
56 *
57 * Return value: #GType of #FoPropertyPaddingTop.
58 **/
59 GType
fo_property_padding_top_get_type(void)60 fo_property_padding_top_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 (FoPropertyPaddingTopClass),
69 NULL, /* base_init */
70 NULL, /* base_finalize */
71 (GClassInitFunc) fo_property_padding_top_class_init,
72 NULL, /* class_finalize */
73 NULL, /* class_data */
74 sizeof (FoPropertyPaddingTop),
75 0, /* n_preallocs */
76 (GInstanceInitFunc) fo_property_padding_top_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_top_init:
90 * @padding_top: #FoPropertyPaddingTop object to initialise.
91 *
92 * Implements #GInstanceInitFunc for #FoPropertyPaddingTop.
93 **/
94 void
fo_property_padding_top_init(FoPropertyPaddingTop * padding_top)95 fo_property_padding_top_init (FoPropertyPaddingTop *padding_top)
96 {
97 FO_PROPERTY (padding_top)->value =
98 g_object_ref (fo_length_cond_get_length_cond_zero ());
99 }
100
101 /**
102 * fo_property_padding_top_class_init:
103 * @klass: #FoPropertyPaddingTopClass object to initialise.
104 *
105 * Implements #GClassInitFunc for #FoPropertyPaddingTopClass.
106 **/
107 void
fo_property_padding_top_class_init(FoPropertyPaddingTopClass * klass)108 fo_property_padding_top_class_init (FoPropertyPaddingTopClass *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_top_finalize;
116
117 property_class->is_inherited = FALSE;
118 property_class->is_shorthand = FALSE;
119 property_class->resolve_enum =
120 fo_property_padding_top_resolve_enum;
121 property_class->resolve_percent =
122 fo_property_util_resolve_ipdim_percent;
123 property_class->validate =
124 fo_property_padding_top_validate;
125 property_class->get_initial =
126 fo_property_padding_top_get_initial;
127 }
128
129 /**
130 * fo_property_padding_top_finalize:
131 * @object: #FoPropertyPaddingTop object to finalize.
132 *
133 * Implements #GObjectFinalizeFunc for #FoPropertyPaddingTop.
134 **/
135 void
fo_property_padding_top_finalize(GObject * object)136 fo_property_padding_top_finalize (GObject *object)
137 {
138 FoPropertyPaddingTop *padding_top;
139
140 padding_top = FO_PROPERTY_PADDING_TOP (object);
141
142 G_OBJECT_CLASS (parent_class)->finalize (object);
143 }
144
145
146 /**
147 * fo_property_padding_top_new:
148 *
149 * Creates a new #FoPropertyPaddingTop initialized to default value.
150 *
151 * Return value: the new #FoPropertyPaddingTop.
152 **/
153 FoProperty*
fo_property_padding_top_new(void)154 fo_property_padding_top_new (void)
155 {
156 FoProperty* padding_top;
157
158 padding_top =
159 FO_PROPERTY (g_object_new (fo_property_padding_top_get_type (),
160 NULL));
161
162 return padding_top;
163 }
164
165 /**
166 * fo_property_padding_top_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_top_resolve_enum(const gchar * token,FoContext * context,GError ** error)181 fo_property_padding_top_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_top_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_top_validate(FoDatatype * datatype,FoContext * context,GError ** error)211 fo_property_padding_top_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
230 {
231 gchar *datatype_sprintf = fo_object_sprintf (datatype);
232
233 g_set_error (error,
234 FO_FO_ERROR,
235 FO_FO_ERROR_DATATYPE,
236 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
237 class_name,
238 datatype_sprintf,
239 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
240
241 g_object_unref (datatype);
242
243 g_free (datatype_sprintf);
244
245 return NULL;
246 }
247 }
248
249 /**
250 * fo_property_padding_top_get_initial:
251 *
252 * Get an instance of the property with the correct initial value.
253 *
254 * Return value: An instance of the property.
255 **/
256 FoProperty*
fo_property_padding_top_get_initial(void)257 fo_property_padding_top_get_initial (void)
258 {
259 static FoProperty *padding_top = NULL;
260
261 if (padding_top == NULL)
262 {
263 padding_top = fo_property_padding_top_new ();
264 }
265
266 return padding_top;
267 }
268