1 #define __SP_OBJECTGROUP_C__
3 /*
4 * Abstract base class for non-item groups
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 *
9 * Copyright (C) 1999-2003 Authors
10 * Copyright (C) 2001-2002 Ximian, Inc.
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include "sp-object-group.h"
16 #include "xml/repr.h"
18 static void sp_objectgroup_class_init (SPObjectGroupClass *klass);
19 static void sp_objectgroup_init (SPObjectGroup *objectgroup);
21 static void sp_objectgroup_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
22 static void sp_objectgroup_remove_child (SPObject * object, Inkscape::XML::Node * child);
23 static void sp_objectgroup_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
24 static Inkscape::XML::Node *sp_objectgroup_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
26 static SPObjectClass *parent_class;
28 GType
29 sp_objectgroup_get_type (void)
30 {
31 static GType objectgroup_type = 0;
32 if (!objectgroup_type) {
33 GTypeInfo objectgroup_info = {
34 sizeof (SPObjectGroupClass),
35 NULL, /* base_init */
36 NULL, /* base_finalize */
37 (GClassInitFunc) sp_objectgroup_class_init,
38 NULL, /* class_finalize */
39 NULL, /* class_data */
40 sizeof (SPObjectGroup),
41 16, /* n_preallocs */
42 (GInstanceInitFunc) sp_objectgroup_init,
43 NULL, /* value_table */
44 };
45 objectgroup_type = g_type_register_static (SP_TYPE_OBJECT, "SPObjectGroup", &objectgroup_info, (GTypeFlags)0);
46 }
47 return objectgroup_type;
48 }
50 static void
51 sp_objectgroup_class_init (SPObjectGroupClass *klass)
52 {
53 GObjectClass * object_class;
54 SPObjectClass * sp_object_class;
56 object_class = (GObjectClass *) klass;
57 sp_object_class = (SPObjectClass *) klass;
59 parent_class = (SPObjectClass *)g_type_class_ref (SP_TYPE_OBJECT);
61 sp_object_class->child_added = sp_objectgroup_child_added;
62 sp_object_class->remove_child = sp_objectgroup_remove_child;
63 sp_object_class->order_changed = sp_objectgroup_order_changed;
64 sp_object_class->write = sp_objectgroup_write;
65 }
67 static void
68 sp_objectgroup_init (SPObjectGroup *objectgroup)
69 {
70 }
72 static void
73 sp_objectgroup_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
74 {
75 if (((SPObjectClass *) (parent_class))->child_added)
76 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
78 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
79 }
81 static void
82 sp_objectgroup_remove_child (SPObject *object, Inkscape::XML::Node *child)
83 {
84 if (((SPObjectClass *) (parent_class))->remove_child)
85 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
87 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
88 }
90 static void
91 sp_objectgroup_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
92 {
93 if (((SPObjectClass *) (parent_class))->order_changed)
94 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
96 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
97 }
99 static Inkscape::XML::Node *
100 sp_objectgroup_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
101 {
102 SPObjectGroup *group;
103 SPObject *child;
104 Inkscape::XML::Node *crepr;
106 group = SP_OBJECTGROUP (object);
108 if (flags & SP_OBJECT_WRITE_BUILD) {
109 GSList *l;
110 if (!repr) repr = sp_repr_new ("svg:g");
111 l = NULL;
112 for ( child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
113 crepr = child->updateRepr(NULL, flags);
114 if (crepr) l = g_slist_prepend (l, crepr);
115 }
116 while (l) {
117 repr->addChild((Inkscape::XML::Node *) l->data, NULL);
118 Inkscape::GC::release((Inkscape::XML::Node *) l->data);
119 l = g_slist_remove (l, l->data);
120 }
121 } else {
122 for ( child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
123 child->updateRepr(flags);
124 }
125 }
127 if (((SPObjectClass *) (parent_class))->write)
128 ((SPObjectClass *) (parent_class))->write (object, repr, flags);
130 return repr;
131 }