1 /*
2 * Abstract base class for non-item groups
3 *
4 * Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * Jon A. Cruz <jon@joncruz.org>
7 * Abhishek Sharma
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"
17 #include "document.h"
19 SPObjectClass * SPObjectGroupClass::static_parent_class = 0;
21 GType SPObjectGroup::sp_objectgroup_get_type(void)
22 {
23 static GType objectgroup_type = 0;
24 if (!objectgroup_type) {
25 GTypeInfo objectgroup_info = {
26 sizeof(SPObjectGroupClass),
27 NULL, /* base_init */
28 NULL, /* base_finalize */
29 (GClassInitFunc) SPObjectGroupClass::sp_objectgroup_class_init,
30 NULL, /* class_finalize */
31 NULL, /* class_data */
32 sizeof(SPObjectGroup),
33 16, /* n_preallocs */
34 (GInstanceInitFunc) init,
35 NULL, /* value_table */
36 };
37 objectgroup_type = g_type_register_static(SP_TYPE_OBJECT, "SPObjectGroup", &objectgroup_info, (GTypeFlags)0);
38 }
39 return objectgroup_type;
40 }
42 void SPObjectGroupClass::sp_objectgroup_class_init(SPObjectGroupClass *klass)
43 {
44 GObjectClass * object_class = (GObjectClass *) klass;
45 SPObjectClass * sp_object_class = (SPObjectClass *) klass;
47 static_parent_class = (SPObjectClass *)g_type_class_ref(SP_TYPE_OBJECT);
49 sp_object_class->child_added = SPObjectGroup::childAdded;
50 sp_object_class->remove_child = SPObjectGroup::removeChild;
51 sp_object_class->order_changed = SPObjectGroup::orderChanged;
52 sp_object_class->write = SPObjectGroup::write;
53 }
55 void SPObjectGroup::init(SPObjectGroup * /*objectgroup*/)
56 {
57 }
59 void SPObjectGroup::childAdded(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
60 {
61 if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->child_added) {
62 (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->child_added)(object, child, ref);
63 }
65 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
66 }
68 void SPObjectGroup::removeChild(SPObject *object, Inkscape::XML::Node *child)
69 {
70 if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->remove_child) {
71 (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->remove_child)(object, child);
72 }
74 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
75 }
77 void SPObjectGroup::orderChanged(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
78 {
79 if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->order_changed) {
80 (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->order_changed)(object, child, old_ref, new_ref);
81 }
83 object->requestModified(SP_OBJECT_MODIFIED_FLAG);
84 }
86 Inkscape::XML::Node *SPObjectGroup::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
87 {
88 SP_OBJECTGROUP(object); // Ensure we have the right type of SPObject
90 if (flags & SP_OBJECT_WRITE_BUILD) {
91 if (!repr) {
92 repr = xml_doc->createElement("svg:g");
93 }
94 GSList *l = 0;
95 for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
96 Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
97 if (crepr) {
98 l = g_slist_prepend(l, crepr);
99 }
100 }
101 while (l) {
102 repr->addChild((Inkscape::XML::Node *) l->data, NULL);
103 Inkscape::GC::release((Inkscape::XML::Node *) l->data);
104 l = g_slist_remove(l, l->data);
105 }
106 } else {
107 for ( SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
108 child->updateRepr(flags);
109 }
110 }
112 if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->write) {
113 ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->write(object, xml_doc, repr, flags);
114 }
116 return repr;
117 }
119 /*
120 Local Variables:
121 mode:c++
122 c-file-style:"stroustrup"
123 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
124 indent-tabs-mode:nil
125 fill-column:99
126 End:
127 */
128 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :