1 /* Fo
2  * fo-property-grouping-separator.c: 'grouping-separator' 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-grouping-separator.h"
17 
18 /* Inherited: FALSE */
19 /* Shorthand: FALSE */
20 /* grouping-separator */
21 /* <character> */
22 /* NO ENUMERATED VALUE */
23 
24 
25 struct _FoPropertyGroupingSeparator
26 {
27   FoProperty parent_instance;
28 };
29 
30 struct _FoPropertyGroupingSeparatorClass
31 {
32   FoPropertyClass parent_class;
33 };
34 
35 static void fo_property_grouping_separator_init         (FoPropertyGroupingSeparator      *property_grouping_separator);
36 static void fo_property_grouping_separator_class_init   (FoPropertyGroupingSeparatorClass *klass);
37 static void fo_property_grouping_separator_finalize     (GObject       *object);
38 
39 static FoDatatype* fo_property_grouping_separator_resolve_enum (const gchar *token,
40                                                                 FoContext   *context,
41                                                                 GError     **error);
42 static FoDatatype* fo_property_grouping_separator_validate (FoDatatype *datatype,
43                                                             FoContext  *context,
44                                                             GError    **error);
45 
46 static const gchar class_name[] = "grouping-separator";
47 static gpointer parent_class;
48 
49 /**
50  * fo_property_grouping_separator_get_type:
51  *
52  * Register the #FoPropertyGroupingSeparator type if not already registered and
53  * return its #GType value.
54  *
55  * Return value: #GType of #FoPropertyGroupingSeparator.
56  **/
57 GType
fo_property_grouping_separator_get_type(void)58 fo_property_grouping_separator_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 (FoPropertyGroupingSeparatorClass),
67         NULL,           /* base_init */
68         NULL,           /* base_finalize */
69         (GClassInitFunc) fo_property_grouping_separator_class_init,
70         NULL,           /* class_finalize */
71         NULL,           /* class_data */
72         sizeof (FoPropertyGroupingSeparator),
73         0,              /* n_preallocs */
74         (GInstanceInitFunc) fo_property_grouping_separator_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_grouping_separator_init:
88  * @grouping_separator: #FoPropertyGroupingSeparator object to initialise.
89  *
90  * Implements #GInstanceInitFunc for #FoPropertyGroupingSeparator.
91  **/
92 void
fo_property_grouping_separator_init(FoPropertyGroupingSeparator * grouping_separator)93 fo_property_grouping_separator_init (FoPropertyGroupingSeparator *grouping_separator)
94 {
95   FO_PROPERTY (grouping_separator)->value =
96     NULL;
97 }
98 
99 /**
100  * fo_property_grouping_separator_class_init:
101  * @klass: #FoPropertyGroupingSeparatorClass object to initialise.
102  *
103  * Implements #GClassInitFunc for #FoPropertyGroupingSeparatorClass.
104  **/
105 void
fo_property_grouping_separator_class_init(FoPropertyGroupingSeparatorClass * klass)106 fo_property_grouping_separator_class_init (FoPropertyGroupingSeparatorClass *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_grouping_separator_finalize;
114 
115   property_class->is_inherited = FALSE;
116   property_class->is_shorthand = FALSE;
117   property_class->resolve_enum =
118     fo_property_grouping_separator_resolve_enum;
119   property_class->validate =
120     fo_property_grouping_separator_validate;
121   property_class->get_initial =
122     fo_property_grouping_separator_get_initial;
123 }
124 
125 /**
126  * fo_property_grouping_separator_finalize:
127  * @object: #FoPropertyGroupingSeparator object to finalize.
128  *
129  * Implements #GObjectFinalizeFunc for #FoPropertyGroupingSeparator.
130  **/
131 void
fo_property_grouping_separator_finalize(GObject * object)132 fo_property_grouping_separator_finalize (GObject *object)
133 {
134   FoPropertyGroupingSeparator *grouping_separator;
135 
136   grouping_separator = FO_PROPERTY_GROUPING_SEPARATOR (object);
137 
138   G_OBJECT_CLASS (parent_class)->finalize (object);
139 }
140 
141 
142 /**
143  * fo_property_grouping_separator_new:
144  *
145  * Creates a new #FoPropertyGroupingSeparator initialized to default value.
146  *
147  * Return value: the new #FoPropertyGroupingSeparator.
148  **/
149 FoProperty*
fo_property_grouping_separator_new(void)150 fo_property_grouping_separator_new (void)
151 {
152   FoProperty* grouping_separator;
153 
154   grouping_separator =
155     FO_PROPERTY (g_object_new (fo_property_grouping_separator_get_type (),
156                                NULL));
157 
158   return grouping_separator;
159 }
160 
161 /**
162  * fo_property_grouping_separator_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_grouping_separator_resolve_enum(const gchar * token,FoContext * context,GError ** error)177 fo_property_grouping_separator_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_grouping_separator_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_grouping_separator_validate(FoDatatype * datatype,FoContext * context,GError ** error)207 fo_property_grouping_separator_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_CHAR (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_grouping_separator_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_grouping_separator_get_initial(void)249 fo_property_grouping_separator_get_initial (void)
250 {
251   static FoProperty *grouping_separator = NULL;
252 
253   if (grouping_separator == NULL)
254     {
255       grouping_separator = fo_property_grouping_separator_new ();
256     }
257 
258   return grouping_separator;
259 }
260