1 /* Fo
2  * fo-property-provisional-label-separation.c: 'provisional-label-separation' 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-provisional-label-separation.h"
17 #include "property/fo-property-util.h"
18 
19 /* provisional-label-separation */
20 /* Inherited: TRUE */
21 /* Shorthand: FALSE */
22 /* <length> | <percentage> | inherit */
23 /* Initial value: 6.0pt */
24 
25 struct _FoPropertyProvisionalLabelSeparation
26 {
27   FoProperty parent_instance;
28 };
29 
30 struct _FoPropertyProvisionalLabelSeparationClass
31 {
32   FoPropertyClass parent_class;
33 };
34 
35 static void fo_property_provisional_label_separation_init         (FoPropertyProvisionalLabelSeparation      *property_provisional_label_separation);
36 static void fo_property_provisional_label_separation_class_init   (FoPropertyProvisionalLabelSeparationClass *klass);
37 static void fo_property_provisional_label_separation_finalize     (GObject       *object);
38 
39 static FoDatatype* fo_property_provisional_label_separation_validate (FoDatatype *datatype,
40                                                                       FoContext  *context,
41                                                                       GError    **error);
42 
43 static const gchar class_name[] = "provisional-label-separation";
44 static gpointer parent_class;
45 
46 /**
47  * fo_property_provisional_label_separation_get_type:
48  *
49  * Register the #FoPropertyProvisionalLabelSeparation type if not already registered and
50  * return its #GType value.
51  *
52  * Return value: #GType of #FoPropertyProvisionalLabelSeparation.
53  **/
54 GType
fo_property_provisional_label_separation_get_type(void)55 fo_property_provisional_label_separation_get_type (void)
56 {
57   static GType object_type = 0;
58 
59   if (!object_type)
60     {
61       static const GTypeInfo object_info =
62       {
63         sizeof (FoPropertyProvisionalLabelSeparationClass),
64         NULL,           /* base_init */
65         NULL,           /* base_finalize */
66         (GClassInitFunc) fo_property_provisional_label_separation_class_init,
67         NULL,           /* class_finalize */
68         NULL,           /* class_data */
69         sizeof (FoPropertyProvisionalLabelSeparation),
70         0,              /* n_preallocs */
71         (GInstanceInitFunc) fo_property_provisional_label_separation_init,
72 	NULL		/* value_table */
73       };
74 
75       object_type = g_type_register_static (FO_TYPE_PROPERTY,
76                                             class_name,
77                                             &object_info, 0);
78     }
79 
80   return object_type;
81 }
82 
83 /**
84  * fo_property_provisional_label_separation_init:
85  * @provisional_label_separation: #FoPropertyProvisionalLabelSeparation object to initialise.
86  *
87  * Implements #GInstanceInitFunc for #FoPropertyProvisionalLabelSeparation.
88  **/
89 void
fo_property_provisional_label_separation_init(FoPropertyProvisionalLabelSeparation * provisional_label_separation)90 fo_property_provisional_label_separation_init (FoPropertyProvisionalLabelSeparation *provisional_label_separation)
91 {
92   FO_PROPERTY (provisional_label_separation)->value =
93     g_object_ref (fo_length_get_length_6pt ());
94 }
95 
96 /**
97  * fo_property_provisional_label_separation_class_init:
98  * @klass: #FoPropertyProvisionalLabelSeparationClass object to initialise.
99  *
100  * Implements #GClassInitFunc for #FoPropertyProvisionalLabelSeparationClass.
101  **/
102 void
fo_property_provisional_label_separation_class_init(FoPropertyProvisionalLabelSeparationClass * klass)103 fo_property_provisional_label_separation_class_init (FoPropertyProvisionalLabelSeparationClass *klass)
104 {
105   GObjectClass *object_class = G_OBJECT_CLASS (klass);
106   FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
107 
108   parent_class = g_type_class_peek_parent (klass);
109 
110   object_class->finalize = fo_property_provisional_label_separation_finalize;
111 
112   property_class->is_inherited = TRUE;
113   property_class->is_shorthand = FALSE;
114   property_class->resolve_enum =
115     fo_property_util_resolve_no_enum;
116   property_class->validate =
117     fo_property_provisional_label_separation_validate;
118   property_class->get_initial =
119     fo_property_provisional_label_separation_get_initial;
120 }
121 
122 /**
123  * fo_property_provisional_label_separation_finalize:
124  * @object: #FoPropertyProvisionalLabelSeparation object to finalize.
125  *
126  * Implements #GObjectFinalizeFunc for #FoPropertyProvisionalLabelSeparation.
127  **/
128 void
fo_property_provisional_label_separation_finalize(GObject * object)129 fo_property_provisional_label_separation_finalize (GObject *object)
130 {
131   FoPropertyProvisionalLabelSeparation *provisional_label_separation;
132 
133   provisional_label_separation = FO_PROPERTY_PROVISIONAL_LABEL_SEPARATION (object);
134 
135   G_OBJECT_CLASS (parent_class)->finalize (object);
136 }
137 
138 
139 /**
140  * fo_property_provisional_label_separation_new:
141  *
142  * Creates a new #FoPropertyProvisionalLabelSeparation initialized to default value.
143  *
144  * Return value: the new #FoPropertyProvisionalLabelSeparation.
145  **/
146 FoProperty*
fo_property_provisional_label_separation_new(void)147 fo_property_provisional_label_separation_new (void)
148 {
149   FoProperty* provisional_label_separation;
150 
151   provisional_label_separation =
152     FO_PROPERTY (g_object_new (fo_property_provisional_label_separation_get_type (),
153                                NULL));
154 
155   return provisional_label_separation;
156 }
157 
158 /**
159  * fo_property_provisional_label_separation_validate:
160  * @datatype: #FoDatatype to be validated against allowed datatypes and
161  *            values for current property.
162  * @context:  #FoContext object from which to possibly inherit values.
163  * @error:    Information about any error that has occurred.
164  *
165  * Validates @datatype against allowed values.  Returns @datatype, a
166  * replacement datatype value, or NULL if validation failed.
167  *
168  * Return value: Valid datatype value or NULL.
169  **/
170 FoDatatype*
fo_property_provisional_label_separation_validate(FoDatatype * datatype,FoContext * context,GError ** error)171 fo_property_provisional_label_separation_validate (FoDatatype *datatype,
172                                                    FoContext  *context,
173                                                    GError    **error)
174 {
175   g_return_val_if_fail (datatype != NULL, NULL);
176   g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
177   g_return_val_if_fail (context != NULL, NULL);
178   g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
179   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
180 
181   if (FO_IS_LENGTH (datatype))
182     {
183       return datatype;
184     }
185   else if (FO_IS_PERCENTAGE (datatype))
186     {
187       return datatype;
188     }
189   else
190     {
191       gchar *datatype_sprintf = fo_object_sprintf (datatype);
192 
193       g_set_error (error,
194 		   FO_FO_ERROR,
195 		   FO_FO_ERROR_DATATYPE,
196 		   _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
197 		   class_name,
198 		   datatype_sprintf,
199 		   g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
200 
201       g_object_unref (datatype);
202 
203       g_free (datatype_sprintf);
204 
205       return NULL;
206     }
207 }
208 
209 /**
210  * fo_property_provisional_label_separation_get_initial:
211  *
212  * Get an instance of the property with the correct initial value.
213  *
214  * Return value: An instance of the property.
215  **/
216 FoProperty*
fo_property_provisional_label_separation_get_initial(void)217 fo_property_provisional_label_separation_get_initial (void)
218 {
219   static FoProperty *provisional_label_separation = NULL;
220 
221   if (provisional_label_separation == NULL)
222     {
223       provisional_label_separation =
224 	fo_property_provisional_label_separation_new ();
225     }
226 
227   return provisional_label_separation;
228 }
229