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