1 /* Fo
2 * fo-property-type-condity.c: Abstract parent type of '.conditionality' components.
3 *
4 * Copyright (C) 2001-2004 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-type-condity-private.h"
15 #include "property/fo-property-font-size.h"
16 #include "property/fo-property-type-condity.h"
17 #include "property/fo-property-util.h"
18
19 /* type-condity */
20 /* Inherited: FALSE */
21 /* Shorthand: FALSE */
22 /* discard | retain */
23 /* Initial value: discard */
24
25 static void fo_property_type_condity_base_init (FoPropertyTypeCondityClass *klass);
26 static void fo_property_type_condity_class_init (FoPropertyTypeCondityClass *klass);
27 static void fo_property_type_condity_finalize (GObject *object);
28
29 static FoDatatype* fo_property_type_condity_validate (FoDatatype *datatype,
30 FoContext *context,
31 GError **error);
32
33 static const gchar class_name[] = "FoProperytTypeCondity";
34 static gpointer parent_class;
35
36 /**
37 * fo_property_type_condity_get_type:
38 *
39 * Register the #FoPropertyTypeCondity type if not already registered and
40 * return its #GType value.
41 *
42 * Return value: #GType of #FoPropertyTypeCondity.
43 **/
44 GType
fo_property_type_condity_get_type(void)45 fo_property_type_condity_get_type (void)
46 {
47 static GType object_type = 0;
48
49 if (!object_type)
50 {
51 static const GTypeInfo object_info =
52 {
53 sizeof (FoPropertyTypeCondityClass),
54 (GBaseInitFunc) fo_property_type_condity_base_init,
55 NULL, /* base_finalize */
56 (GClassInitFunc) fo_property_type_condity_class_init,
57 NULL, /* class_finalize */
58 NULL, /* class_data */
59 sizeof (FoPropertyTypeCondity),
60 0, /* n_preallocs */
61 (GInstanceInitFunc) fo_property_type_condity_init,
62 NULL /* value_table */
63 };
64
65 object_type = g_type_register_static (FO_TYPE_PROPERTY,
66 class_name,
67 &object_info,
68 G_TYPE_FLAG_ABSTRACT);
69 }
70
71 return object_type;
72 }
73
74 /**
75 * fo_property_type_condity_init:
76 * @type_condity: #FoPropertyTypeCondity object to initialise.
77 *
78 * Implements #GInstanceInitFunc for #FoPropertyTypeCondity.
79 **/
80 void
fo_property_type_condity_init(FoPropertyTypeCondity * type_condity)81 fo_property_type_condity_init (FoPropertyTypeCondity *type_condity)
82 {
83 FO_PROPERTY (type_condity)->value =
84 g_object_ref (fo_boolean_get_true ());
85 }
86
87 /**
88 * fo_property_type_condity_base_init:
89 * @klass: #FoPropertyTypeCondityClass object to initialise.
90 *
91 * Implements #GBaseInitFunc for #FoPropertyTypeCondityClass.
92 **/
93 void
fo_property_type_condity_base_init(FoPropertyTypeCondityClass * klass)94 fo_property_type_condity_base_init (FoPropertyTypeCondityClass *klass)
95 {
96 FoPropertyClass *fo_property_class = FO_PROPERTY_CLASS (klass);
97
98 fo_property_class->is_inherited = FALSE;
99 fo_property_class->is_shorthand = FALSE;
100 fo_property_class->resolve_enum = fo_property_util_resolve_condity_enum;
101 fo_property_class->validate = fo_property_type_condity_validate;
102 }
103
104 /**
105 * fo_property_type_condity_class_init:
106 * @klass: #FoPropertyTypeCondityClass object to initialise.
107 *
108 * Implements #GClassInitFunc for #FoPropertyTypeCondityClass.
109 **/
110 void
fo_property_type_condity_class_init(FoPropertyTypeCondityClass * klass)111 fo_property_type_condity_class_init (FoPropertyTypeCondityClass *klass)
112 {
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114 FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
115
116 parent_class = g_type_class_peek_parent (klass);
117
118 object_class->finalize = fo_property_type_condity_finalize;
119
120 property_class->is_inherited = FALSE;
121 property_class->is_shorthand = FALSE;
122 property_class->resolve_enum =
123 fo_property_util_resolve_condity_enum;
124 property_class->validate =
125 fo_property_type_condity_validate;
126 }
127
128 /**
129 * fo_property_type_condity_finalize:
130 * @object: #FoPropertyTypeCondity object to finalize.
131 *
132 * Implements #GObjectFinalizeFunc for #FoPropertyTypeCondity.
133 **/
134 void
fo_property_type_condity_finalize(GObject * object)135 fo_property_type_condity_finalize (GObject *object)
136 {
137 FoPropertyTypeCondity *type_condity;
138
139 type_condity = FO_PROPERTY_TYPE_CONDITY (object);
140
141 G_OBJECT_CLASS (parent_class)->finalize (object);
142 }
143
144
145 /**
146 * fo_property_type_condity_new:
147 *
148 * Creates a new #FoPropertyTypeCondity initialized to default value.
149 *
150 * Return value: the new #FoPropertyTypeCondity.
151 **/
152 FoProperty*
fo_property_type_condity_new(void)153 fo_property_type_condity_new (void)
154 {
155 FoProperty* type_condity;
156
157 type_condity =
158 FO_PROPERTY (g_object_new (fo_property_type_condity_get_type (),
159 NULL));
160
161 return type_condity;
162 }
163
164 /**
165 * fo_property_type_condity_validate:
166 * @datatype: #FoDatatype to be validated against allowed datatypes and
167 * values for current property.
168 * @context: #FoContext object from which to possibly inherit values.
169 * @error: Information about any error that has occurred.
170 *
171 * Validates @datatype against allowed values. Returns @datatype, a
172 * replacement datatype value, or NULL if validation failed.
173 *
174 * Return value: Valid datatype value or NULL.
175 **/
176 FoDatatype*
fo_property_type_condity_validate(FoDatatype * datatype,FoContext * context,GError ** error)177 fo_property_type_condity_validate (FoDatatype *datatype,
178 FoContext *context,
179 GError **error)
180 {
181 g_return_val_if_fail (datatype != NULL, NULL);
182 g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
183 g_return_val_if_fail (context != NULL, NULL);
184 g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
185 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
186
187 if (FO_IS_BOOLEAN (datatype))
188 {
189 return datatype;
190 }
191 else
192 {
193 gchar *datatype_sprintf = fo_object_sprintf (datatype);
194
195 g_set_error (error,
196 FO_FO_ERROR,
197 FO_FO_ERROR_DATATYPE,
198 _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
199 class_name,
200 datatype_sprintf,
201 g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
202
203 g_object_unref (datatype);
204
205 g_free (datatype_sprintf);
206
207 return NULL;
208 }
209 }
210