1 /* Fo
2 * fo-wsc.c: 'width-style-color' datatype
3 *
4 * Copyright (C) 2001-2005 Sun Microsystems
5 * Copyright (C) 2007 Menteith Consulting Ltd
6 *
7 * See COPYING for the status of this software.
8 */
9
10 #include "fo-utils.h"
11 #include "fo-datatype.h"
12 #include "fo-datatype-private.h"
13 #include "fo-wsc.h"
14 #include "fo-length.h"
15 #include "fo-color.h"
16
17 enum {
18 PROP_0,
19 PROP_WIDTH,
20 PROP_STYLE,
21 PROP_COLOR
22 };
23
24 struct _FoWsc
25 {
26 FoDatatype parent_instance;
27
28 FoDatatype *width;
29 FoDatatype *style;
30 FoDatatype *color;
31 };
32
33 struct _FoWscClass
34 {
35 FoDatatypeClass parent_class;
36 };
37
38 static void fo_wsc_class_init (FoWscClass *klass);
39 static void fo_wsc_set_property (GObject *object,
40 guint prop_id,
41 const GValue *value,
42 GParamSpec *pspec);
43 static void fo_wsc_get_property (GObject *object,
44 guint prop_id,
45 GValue *value,
46 GParamSpec *pspec);
47 static void fo_wsc_finalize (GObject *object);
48
49 gchar* fo_wsc_sprintf (FoObject *object);
50 FoDatatype* fo_wsc_copy (FoDatatype *datatype);
51
52 static void fo_wsc_set_width (FoDatatype *datatype,
53 FoDatatype *new_width);
54 static void fo_wsc_set_style (FoDatatype *datatype,
55 FoDatatype *new_style);
56 static void fo_wsc_set_color (FoDatatype *datatype,
57 FoDatatype *new_color);
58
59 static gpointer parent_class;
60
61 /**
62 * fo_wsc_get_type:
63 * @void:
64 *
65 * Register the #FoWsc object type.
66 *
67 * Return value: GType value of the #FoWsc object type.
68 **/
69 GType
fo_wsc_get_type(void)70 fo_wsc_get_type (void)
71 {
72 static GType object_type = 0;
73
74 if (!object_type)
75 {
76 static const GTypeInfo object_info =
77 {
78 sizeof (FoWscClass),
79 (GBaseInitFunc) NULL,
80 (GBaseFinalizeFunc) NULL,
81 (GClassInitFunc) fo_wsc_class_init,
82 NULL, /* class_finalize */
83 NULL, /* class_data */
84 sizeof (FoWsc),
85 0, /* n_preallocs */
86 NULL, /* instance_init */
87 NULL /* value_table */
88 };
89
90 object_type = g_type_register_static (FO_TYPE_DATATYPE,
91 "FoWsc",
92 &object_info, 0);
93 }
94
95 return object_type;
96 }
97
98 /**
99 * fo_wsc_class_init:
100 * @klass: FoWscClass object to initialise
101 *
102 * Implements GClassInitFunc for FoWscClass
103 **/
104 void
fo_wsc_class_init(FoWscClass * klass)105 fo_wsc_class_init (FoWscClass *klass)
106 {
107 GObjectClass *object_class = G_OBJECT_CLASS (klass);
108
109 parent_class = g_type_class_peek_parent (klass);
110
111 object_class->finalize = fo_wsc_finalize;
112
113 object_class->set_property = fo_wsc_set_property;
114 object_class->get_property = fo_wsc_get_property;
115
116 FO_OBJECT_CLASS (klass)->print_sprintf = fo_wsc_sprintf;
117
118 FO_DATATYPE_CLASS (klass)->copy = fo_wsc_copy;
119
120 g_object_class_install_property (object_class,
121 PROP_WIDTH,
122 g_param_spec_object ("width",
123 _("Width"),
124 _("Wsc width value"),
125 FO_TYPE_DATATYPE,
126 G_PARAM_READWRITE |
127 G_PARAM_CONSTRUCT_ONLY));
128
129 g_object_class_install_property (object_class,
130 PROP_STYLE,
131 g_param_spec_object ("style",
132 _("Style"),
133 _("Wsc style value"),
134 FO_TYPE_DATATYPE,
135 G_PARAM_READWRITE |
136 G_PARAM_CONSTRUCT_ONLY));
137
138 g_object_class_install_property (object_class,
139 PROP_COLOR,
140 g_param_spec_object ("color",
141 _("Color"),
142 _("Wsc color value"),
143 FO_TYPE_DATATYPE,
144 G_PARAM_READWRITE |
145 G_PARAM_CONSTRUCT_ONLY));
146
147 }
148
149 /**
150 * fo_wsc_finalize:
151 * @object: FoWsc object to finalize
152 *
153 * Implements GObjectFinalizeFunc for FoWsc
154 **/
155 void
fo_wsc_finalize(GObject * object)156 fo_wsc_finalize (GObject *object)
157 {
158 FoWsc *wsc;
159
160 wsc = FO_WSC (object);
161
162 G_OBJECT_CLASS (parent_class)->finalize (object);
163 }
164
165
166 /**
167 * fo_wsc_set_property:
168 * @object: GObject whose property will be set
169 * @prop_id: Property ID assigned when property registered
170 * @value: New value for property
171 * @pspec: Parameter specification for this property type
172 *
173 * Implements #GObjectSetPropertyFunc for FoWsc
174 **/
175 void
fo_wsc_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)176 fo_wsc_set_property (GObject *object,
177 guint prop_id,
178 const GValue *value,
179 GParamSpec *pspec)
180 {
181 FoDatatype *wsc;
182
183 wsc = FO_DATATYPE (object);
184
185 switch (prop_id)
186 {
187 case PROP_WIDTH:
188 fo_wsc_set_width (wsc, g_value_get_object (value));
189 break;
190 case PROP_STYLE:
191 fo_wsc_set_style (wsc, g_value_get_object (value));
192 break;
193 case PROP_COLOR:
194 fo_wsc_set_color (wsc, g_value_get_object (value));
195 break;
196 default:
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
198 break;
199 }
200 }
201
202 /**
203 * fo_wsc_get_property:
204 * @object: GObject whose property will be retreived
205 * @prop_id: Property ID assigned when property registered
206 * @value: GValue to set with property value
207 * @pspec: Parameter specification for this property type
208 *
209 * Implements #GObjectGetPropertyFunc for FoWsc
210 **/
211 void
fo_wsc_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)212 fo_wsc_get_property (GObject *object,
213 guint prop_id,
214 GValue *value,
215 GParamSpec *pspec)
216 {
217 FoDatatype *datatype;
218
219 datatype = FO_DATATYPE (object);
220
221 switch (prop_id)
222 {
223 case PROP_WIDTH:
224 g_value_set_object (value, fo_wsc_get_width (datatype));
225 break;
226 case PROP_STYLE:
227 g_value_set_object (value, fo_wsc_get_style (datatype));
228 break;
229 case PROP_COLOR:
230 g_value_set_object (value, fo_wsc_get_color (datatype));
231 break;
232 default:
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234 break;
235 }
236 }
237
238 /**
239 * fo_wsc_new:
240 *
241 * Creates a new #FoWsc initialized to default value.
242 *
243 * Return value: the new #FoWsc
244 **/
245 FoDatatype *
fo_wsc_new(void)246 fo_wsc_new (void)
247 {
248 FoDatatype *wsc;
249
250 wsc = FO_DATATYPE (g_object_new (fo_wsc_get_type (),
251 "width",
252 NULL,
253 "style",
254 NULL,
255 "color",
256 NULL,
257 NULL));
258
259 return wsc;
260 }
261
262 /**
263 * fo_wsc_new_from_values:
264 * @width: #FoDatatype to use as width value
265 * @style: #FoDatatype to use as style value
266 * @color: #FoDatatype to use as color value
267 *
268 * Creates a new #FoWsc with width, style, and color components set to
269 * provided values.
270 *
271 * Return value: New #FoWsc
272 **/
273 FoDatatype*
fo_wsc_new_from_values(FoDatatype * width,FoDatatype * style,FoDatatype * color)274 fo_wsc_new_from_values (FoDatatype *width,
275 FoDatatype *style,
276 FoDatatype *color)
277 {
278 FoDatatype *wsc;
279
280 g_return_val_if_fail ((width == NULL) || FO_IS_DATATYPE (width), NULL);
281 g_return_val_if_fail ((style == NULL) || FO_IS_DATATYPE (style), NULL);
282 g_return_val_if_fail ((color == NULL) || FO_IS_DATATYPE (color), NULL);
283
284
285 wsc = fo_wsc_new ();
286
287 fo_wsc_set_width (wsc, width);
288 fo_wsc_set_style (wsc, style);
289 fo_wsc_set_color (wsc, color);
290
291 return wsc;
292 }
293
294 /**
295 * fo_wsc_get_width:
296 * @datatype: #FoWsc
297 *
298 * Gets the width component value of @datatype.
299 *
300 * Return value: The width value of @datatype.
301 **/
302 FoDatatype *
fo_wsc_get_width(FoDatatype * datatype)303 fo_wsc_get_width (FoDatatype *datatype)
304 {
305 g_return_val_if_fail (datatype != NULL, NULL);
306 g_return_val_if_fail (FO_IS_WSC (datatype), NULL);
307
308 return FO_WSC (datatype)->width;
309 }
310
311 /**
312 * fo_wsc_set_width:
313 * @datatype: #FoWsc
314 * @new_width: New width value
315 *
316 * Sets the width component of @datatype
317 **/
318 void
fo_wsc_set_width(FoDatatype * datatype,FoDatatype * new_width)319 fo_wsc_set_width (FoDatatype *datatype,
320 FoDatatype *new_width)
321 {
322 FoWsc *wsc = (FoWsc *) datatype;
323
324 g_return_if_fail (datatype != NULL);
325 g_return_if_fail (FO_IS_WSC (datatype));
326 g_return_if_fail ((new_width == NULL) || FO_IS_DATATYPE (new_width));
327
328 if (new_width != NULL)
329 g_object_ref (G_OBJECT (new_width));
330 if (wsc->width != NULL)
331 g_object_unref (G_OBJECT (wsc->width));
332 wsc->width = new_width;
333 /*g_object_notify(G_OBJECT(datatype), "width");*/
334 }
335
336 /**
337 * fo_wsc_get_style:
338 * @datatype: #FoWsc
339 *
340 * Gets the style component value of @datatype
341 *
342 * Return value: The style value of @datatype
343 **/
344 FoDatatype *
fo_wsc_get_style(FoDatatype * datatype)345 fo_wsc_get_style (FoDatatype *datatype)
346 {
347 g_return_val_if_fail (datatype != NULL, NULL);
348 g_return_val_if_fail (FO_IS_WSC (datatype), NULL);
349
350 return FO_WSC (datatype)->style;
351 }
352
353 /**
354 * fo_wsc_set_style:
355 * @datatype: #FoWsc
356 * @new_style: New style value
357 *
358 * Sets the style component of @datatype
359 **/
360 void
fo_wsc_set_style(FoDatatype * datatype,FoDatatype * new_style)361 fo_wsc_set_style (FoDatatype *datatype,
362 FoDatatype *new_style)
363 {
364 FoWsc *wsc = (FoWsc *) datatype;
365
366 g_return_if_fail (datatype != NULL);
367 g_return_if_fail (FO_IS_WSC (datatype));
368 g_return_if_fail ((new_style == NULL) || FO_IS_DATATYPE (new_style));
369
370 if (new_style != NULL)
371 g_object_ref (G_OBJECT (new_style));
372 if (wsc->style != NULL)
373 g_object_unref (G_OBJECT (wsc->style));
374 wsc->style = new_style;
375 /*g_object_notify(G_OBJECT(datatype), "style");*/
376 }
377
378 /**
379 * fo_wsc_get_color:
380 * @datatype: #FoWsc
381 *
382 * Gets the color component value of @datatype
383 *
384 * Return value: The color value of @datatype
385 **/
386 FoDatatype *
fo_wsc_get_color(FoDatatype * datatype)387 fo_wsc_get_color (FoDatatype *datatype)
388 {
389 g_return_val_if_fail (datatype != NULL, NULL);
390 g_return_val_if_fail (FO_IS_WSC (datatype), NULL);
391
392 return FO_WSC (datatype)->color;
393 }
394
395 /**
396 * fo_wsc_set_color:
397 * @datatype: #FoWsc
398 * @new_color: New color value
399 *
400 * Sets the color component of @datatype
401 **/
402 void
fo_wsc_set_color(FoDatatype * datatype,FoDatatype * new_color)403 fo_wsc_set_color (FoDatatype *datatype,
404 FoDatatype *new_color)
405 {
406 FoWsc *wsc = (FoWsc *) datatype;
407
408 g_return_if_fail (datatype != NULL);
409 g_return_if_fail (FO_IS_WSC (datatype));
410 g_return_if_fail ((new_color == NULL) || FO_IS_DATATYPE (new_color));
411
412 if (new_color != NULL)
413 g_object_ref (G_OBJECT (new_color));
414 if (wsc->color != NULL)
415 g_object_unref (G_OBJECT (wsc->color));
416 wsc->color = new_color;
417 /*g_object_notify(G_OBJECT(datatype), "color");*/
418 }
419
420 /**
421 * fo_wsc_sprintf:
422 * @object: #FoWsc whose value is to be printed
423 *
424 * Create and return a string representation of the value of @object,
425 * which must be an #FoWsc.
426 *
427 * String must be freed by caller.
428 *
429 * Return value: String representation of value of @object
430 **/
431 gchar*
fo_wsc_sprintf(FoObject * object)432 fo_wsc_sprintf (FoObject *object)
433 {
434 g_return_val_if_fail (object != NULL, NULL);
435 g_return_val_if_fail (FO_IS_WSC (object), NULL);
436
437 return (g_strdup_printf("width: %s; style: %s; color: %s",
438 fo_object_sprintf (FO_WSC (object)->width),
439 fo_object_sprintf (FO_WSC (object)->style),
440 fo_object_sprintf (FO_WSC (object)->color)));
441 }
442
443 /**
444 * fo_wsc_copy:
445 * @datatype: Source #FoWsc.
446 *
447 * Creates a copy of @datatype.
448 *
449 * Return value: Copy of @datatype.
450 **/
451 FoDatatype*
fo_wsc_copy(FoDatatype * datatype)452 fo_wsc_copy (FoDatatype *datatype)
453 {
454 FoDatatype *wsc;
455
456 g_return_val_if_fail (datatype != NULL, NULL);
457 g_return_val_if_fail (FO_IS_WSC (datatype), NULL);
458
459 wsc = fo_wsc_new ();
460 fo_wsc_set_width (wsc,
461 FO_WSC(datatype)->width);
462 fo_wsc_set_style (wsc,
463 FO_WSC(datatype)->style);
464 fo_wsc_set_color (wsc,
465 FO_WSC(datatype)->color);
466
467 return (wsc);
468 }
469