1 /* Fo
2  * fo-property-keep-with-previous-within-line.c: 'keep-with-previous-within-line' 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 /*
16 #include "property/fo-property-text-property.h"
17 */
18 #include "property/fo-property-font-size.h"
19 #include "property/fo-property-keep-with-previous-within-line.h"
20 #include "property/fo-property-util.h"
21 
22 /* keep-with-previous-within-line */
23 /* Inherited: FALSE */
24 /* Shorthand: FALSE */
25 /* <keep> | inherit */
26 /* Initial value: .within-line=auto, .within-column=auto, .within-page=auto */
27 
28 struct _FoPropertyKeepWithPreviousWithinLine
29 {
30   FoProperty parent_instance;
31 };
32 
33 struct _FoPropertyKeepWithPreviousWithinLineClass
34 {
35   FoPropertyClass parent_class;
36 };
37 
38 static void fo_property_keep_with_previous_within_line_init         (FoPropertyKeepWithPreviousWithinLine      *property_keep_with_previous_within_line);
39 static void fo_property_keep_with_previous_within_line_class_init   (FoPropertyKeepWithPreviousWithinLineClass *klass);
40 static void fo_property_keep_with_previous_within_line_finalize     (GObject       *object);
41 
42 static FoDatatype* fo_property_keep_with_previous_within_line_validate (FoDatatype *datatype,
43                                                                         FoContext  *context,
44                                                                         GError    **error);
45 /*
46 PangoAttribute * fo_property_keep_with_previous_within_line_new_attr (FoProperty *property);
47 static void fo_property_keep_with_previous_within_line_text_property_init (FoPropertyTextPropertyIface *iface);
48 */
49 static const gchar class_name[] = "keep-with-previous-within-line";
50 static gpointer parent_class;
51 
52 /**
53  * fo_property_keep_with_previous_within_line_get_type:
54  *
55  * Register the #FoPropertyKeepWithPreviousWithinLine type if not already registered and
56  * return its #GType value.
57  *
58  * Return value: #GType of #FoPropertyKeepWithPreviousWithinLine.
59  **/
60 GType
fo_property_keep_with_previous_within_line_get_type(void)61 fo_property_keep_with_previous_within_line_get_type (void)
62 {
63   static GType object_type = 0;
64 
65   if (!object_type)
66     {
67       static const GTypeInfo object_info =
68       {
69         sizeof (FoPropertyKeepWithPreviousWithinLineClass),
70         NULL,           /* base_init */
71         NULL,           /* base_finalize */
72         (GClassInitFunc) fo_property_keep_with_previous_within_line_class_init,
73         NULL,           /* class_finalize */
74         NULL,           /* class_data */
75         sizeof (FoPropertyKeepWithPreviousWithinLine),
76         0,              /* n_preallocs */
77         (GInstanceInitFunc) fo_property_keep_with_previous_within_line_init,
78 	NULL		/* value_table */
79       };
80 
81       /*
82       static const GInterfaceInfo fo_property_text_property_info =
83       {
84 	(GInterfaceInitFunc) fo_property_keep_with_previous_within_line_text_property_init, / * interface_init * /
85         NULL,
86         NULL
87       };
88       */
89 
90       object_type = g_type_register_static (FO_TYPE_PROPERTY,
91                                             class_name,
92                                             &object_info, 0);
93       /*
94       g_type_add_interface_static (object_type,
95                                    FO_TYPE_PROPERTY_TEXT_PROPERTY,
96                                    &fo_property_text_property_info);
97       */
98     }
99 
100   return object_type;
101 }
102 
103 /**
104  * fo_property_keep_with_previous_within_line_init:
105  * @keep_with_previous_within_line: #FoPropertyKeepWithPreviousWithinLine object to initialise.
106  *
107  * Implements #GInstanceInitFunc for #FoPropertyKeepWithPreviousWithinLine.
108  **/
109 void
fo_property_keep_with_previous_within_line_init(FoPropertyKeepWithPreviousWithinLine * keep_with_previous_within_line)110 fo_property_keep_with_previous_within_line_init (FoPropertyKeepWithPreviousWithinLine *keep_with_previous_within_line)
111 {
112   FO_PROPERTY (keep_with_previous_within_line)->value =
113     g_object_ref (fo_enum_factory_get_enum_by_value (FO_ENUM_ENUM_AUTO));
114 }
115 
116 /**
117  * fo_property_keep_with_previous_within_line_class_init:
118  * @klass: #FoPropertyKeepWithPreviousWithinLineClass object to initialise.
119  *
120  * Implements #GClassInitFunc for #FoPropertyKeepWithPreviousWithinLineClass.
121  **/
122 void
fo_property_keep_with_previous_within_line_class_init(FoPropertyKeepWithPreviousWithinLineClass * klass)123 fo_property_keep_with_previous_within_line_class_init (FoPropertyKeepWithPreviousWithinLineClass *klass)
124 {
125   GObjectClass *object_class = G_OBJECT_CLASS (klass);
126   FoPropertyClass *property_class = FO_PROPERTY_CLASS (klass);
127 
128   parent_class = g_type_class_peek_parent (klass);
129 
130   object_class->finalize = fo_property_keep_with_previous_within_line_finalize;
131 
132   property_class->is_inherited = FALSE;
133   property_class->is_shorthand = FALSE;
134   property_class->resolve_enum =
135     fo_property_util_resolve_auto_always_enum;
136   property_class->validate =
137     fo_property_keep_with_previous_within_line_validate;
138   property_class->get_initial =
139     fo_property_keep_with_previous_within_line_get_initial;
140 }
141 
142 /**
143  * fo_property_keep_with_previous_within_line_finalize:
144  * @object: #FoPropertyKeepWithPreviousWithinLine object to finalize.
145  *
146  * Implements #GObjectFinalizeFunc for #FoPropertyKeepWithPreviousWithinLine.
147  **/
148 void
fo_property_keep_with_previous_within_line_finalize(GObject * object)149 fo_property_keep_with_previous_within_line_finalize (GObject *object)
150 {
151   FoPropertyKeepWithPreviousWithinLine *keep_with_previous_within_line;
152 
153   keep_with_previous_within_line = FO_PROPERTY_KEEP_WITH_PREVIOUS_WITHIN_LINE (object);
154 
155   G_OBJECT_CLASS (parent_class)->finalize (object);
156 }
157 
158 /**
159  * fo_property_keep_with_previous_within_line_text_property_init:
160  * @iface: #FoPropertyTextPropertyIFace structure for this class
161  *
162  * Initialize #FoPropertyTextPropertyIface interface for this class
163  **/
164 /*
165 void
166 fo_property_keep_with_previous_within_line_text_property_init (FoPropertyTextPropertyIface *iface)
167 {
168   iface->new_attr = fo_property_keep_with_previous_within_line_new_attr;
169 }
170 */
171 
172 /**
173  * fo_property_keep_with_previous_within_line_new:
174  *
175  * Creates a new #FoPropertyKeepWithPreviousWithinLine initialized to default value.
176  *
177  * Return value: the new #FoPropertyKeepWithPreviousWithinLine.
178  **/
179 FoProperty*
fo_property_keep_with_previous_within_line_new(void)180 fo_property_keep_with_previous_within_line_new (void)
181 {
182   FoProperty* keep_with_previous_within_line;
183 
184   keep_with_previous_within_line =
185     FO_PROPERTY (g_object_new (fo_property_keep_with_previous_within_line_get_type (),
186                                NULL));
187 
188   return keep_with_previous_within_line;
189 }
190 
191 /**
192  * fo_property_keep_with_previous_within_line_validate:
193  * @datatype: #FoDatatype to be validated against allowed datatypes and
194  *            values for current property.
195  * @context:  #FoContext object from which to possibly inherit values.
196  * @error:    Information about any error that has occurred.
197  *
198  * Validates @datatype against allowed values.  Returns @datatype, a
199  * replacement datatype value, or NULL if validation failed.
200  *
201  * Return value: Valid datatype value or NULL.
202  **/
203 FoDatatype*
fo_property_keep_with_previous_within_line_validate(FoDatatype * datatype,FoContext * context,GError ** error)204 fo_property_keep_with_previous_within_line_validate (FoDatatype *datatype,
205                                                      FoContext  *context,
206                                                      GError    **error)
207 {
208   FoDatatype *new_datatype;
209   GError     *tmp_error = NULL;
210   gchar      *token;
211 
212   g_return_val_if_fail (datatype != NULL, NULL);
213   g_return_val_if_fail (FO_IS_DATATYPE (datatype), NULL);
214   g_return_val_if_fail (context != NULL, NULL);
215   g_return_val_if_fail (FO_IS_CONTEXT (context), NULL);
216   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
217 
218   if (FO_IS_ENUM (datatype))
219     {
220       return datatype;
221     }
222   else if (FO_IS_STRING (datatype))
223     {
224       token = fo_string_get_value (datatype);
225 
226       new_datatype =
227         fo_property_util_resolve_auto_always_enum (token, context, &tmp_error);
228 
229       g_object_unref (datatype);
230 
231       if (tmp_error != NULL)
232 	{
233 	  g_propagate_error (error, tmp_error);
234 	  return NULL;
235 	}
236 
237       return new_datatype;
238     }
239   else if (FO_IS_NAME (datatype))
240     {
241       token = fo_name_get_value (datatype);
242 
243       new_datatype =
244         fo_property_util_resolve_auto_always_enum (token, context, &tmp_error);
245 
246       g_object_unref (datatype);
247 
248       if (tmp_error != NULL)
249 	{
250 	  g_propagate_error (error, tmp_error);
251 	  return NULL;
252 	}
253 
254       return new_datatype;
255     }
256   else if (FO_IS_INTEGER (datatype))
257     {
258       return datatype;
259     }
260   else if (FO_IS_NUMBER (datatype))
261     {
262       new_datatype =
263         fo_integer_new_with_value ((gint) fo_number_get_value (datatype));
264 
265       g_object_unref (datatype);
266 
267       return new_datatype;
268     }
269   else
270     {
271       gchar *datatype_sprintf = fo_object_sprintf (datatype);
272 
273       g_set_error (error,
274 		   FO_FO_ERROR,
275 		   FO_FO_ERROR_DATATYPE,
276 		   _(fo_fo_error_messages[FO_FO_ERROR_DATATYPE]),
277 		   class_name,
278 		   datatype_sprintf,
279 		   g_type_name (G_TYPE_FROM_INSTANCE (datatype)));
280 
281       g_object_unref (datatype);
282 
283       g_free (datatype_sprintf);
284 
285       return NULL;
286     }
287 }
288 
289 /**
290  * fo_property_keep_with_previous_within_line_get_initial:
291  *
292  * Get an instance of the property with the correct initial value.
293  *
294  * Return value: An instance of the property.
295  **/
296 FoProperty*
fo_property_keep_with_previous_within_line_get_initial(void)297 fo_property_keep_with_previous_within_line_get_initial (void)
298 {
299   static FoProperty *keep_with_previous_within_line = NULL;
300 
301   if (keep_with_previous_within_line == NULL)
302     {
303       keep_with_previous_within_line =
304 	fo_property_keep_with_previous_within_line_new ();
305     }
306 
307   return keep_with_previous_within_line;
308 }
309 
310 /**
311  * fo_property_keep_with_previous_within_line_new_attr:
312  * @property: #FoProperty from which to create a #PangoAttribute.
313  *
314  * Makes a new #PangoAttribute representing the current property.
315  *
316  * Return value: New #PangoAttribute.
317  **/
318 /*
319 PangoAttribute*
320 fo_property_keep_with_previous_within_line_new_attr (FoProperty *property)
321 {
322   FoDatatype *datatype;
323   gint pango_keep_with_previous_within_line = G_MININT;
324 
325   g_return_val_if_fail (FO_IS_PROPERTY_KEEP_WITH_PREVIOUS_WITHIN_LINE (property), NULL);
326 
327   datatype = property->value;
328 
329   if (FO_IS_INTEGER (datatype))
330     {
331       pango_keep_with_previous_within_line =
332 	fo_integer_get_value (datatype);
333     }
334   else if (FO_IS_ENUM (datatype))
335     {
336       guint value = fo_enum_get_value (datatype);
337 
338       if (value == FO_ENUM_ENUM_AUTO)
339 	{
340 	  pango_keep_with_previous_within_line = G_MININT;
341 	}
342       else if (value == FO_ENUM_ENUM_ALWAYS)
343 	{
344 	  pango_keep_with_previous_within_line = G_MAXINT;
345 	}
346       else
347 	{
348 	  g_assert_not_reached ();
349 	}
350     }
351   else
352     {
353       g_assert_not_reached ();
354     }
355 
356   return pango_attr_keep_with_previous_within_line_new (pango_keep_with_previous_within_line);
357 }
358 */
359