Code

A simple layout document as to what, why and how is cppification.
[inkscape.git] / src / sp-defs.cpp
1 #define __SP_DEFS_C__
3 /*
4  * SVG <defs> implementation
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 2000-2002 authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 /*
15  * fixme: We should really check childrens validity - currently everything
16  * flips in
17  */
19 #include "sp-defs.h"
20 #include "xml/repr.h"
21 #include "document.h"
23 /*static void sp_defs_class_init(SPDefsClass *dc);
24 static void sp_defs_init(SPDefs *defs);
26 static void sp_defs_release(SPObject *object);
27 static void sp_defs_update(SPObject *object, SPCtx *ctx, guint flags);
28 static void sp_defs_modified(SPObject *object, guint flags);
29 static Inkscape::XML::Node *sp_defs_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
31 static SPObjectClass *parent_class;*/
32 SPObjectClass * SPDefsClass::static_parent_class = 0;
34 GType SPDefs::sp_defs_get_type(void)
35 {
36     static GType defs_type = 0;
38     if (!defs_type) {
39         GTypeInfo defs_info = {
40             sizeof(SPDefsClass),
41             NULL,       /* base_init */
42             NULL,       /* base_finalize */
43             (GClassInitFunc) SPDefsClass::sp_defs_class_init,
44             NULL,       /* class_finalize */
45             NULL,       /* class_data */
46             sizeof(SPDefs),
47             16, /* n_preallocs */
48             (GInstanceInitFunc) sp_defs_init,
49             NULL,       /* value_table */
50         };
51         defs_type = g_type_register_static(SP_TYPE_OBJECT, "SPDefs", &defs_info, (GTypeFlags) 0);
52     }
54     return defs_type;
55 }
57 void SPDefsClass::sp_defs_class_init(SPDefsClass *dc)
58 {
59     static_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
60     SPObjectClass *sp_object_class = (SPObjectClass *) dc;
62     sp_object_class->release = SPDefs::sp_defs_release;
63     sp_object_class->update = SPDefs::sp_defs_update;
64     sp_object_class->modified = SPDefs::sp_defs_modified;
65     sp_object_class->write = SPDefs::sp_defs_write;
66 }
68 void SPDefs::sp_defs_init(SPDefs */*defs*/)
69 {
71 }
73 void SPDefs::sp_defs_release(SPObject *object)
74 {
75     if (((SPObjectClass *) (SPDefsClass::static_parent_class))->release) {
76         ((SPObjectClass *) (SPDefsClass::static_parent_class))->release(object);
77     }
78 }
80 void SPDefs::sp_defs_update(SPObject *object, SPCtx *ctx, guint flags)
81 {
82     if (flags & SP_OBJECT_MODIFIED_FLAG) {
83         flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
84     }
86     flags &= SP_OBJECT_MODIFIED_CASCADE;
88     GSList *l = g_slist_reverse(object->childList(true));
89     while (l) {
90         SPObject *child = SP_OBJECT(l->data);
91         l = g_slist_remove(l, child);
92         if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
93             child->updateDisplay(ctx, flags);
94         }
95         g_object_unref (G_OBJECT (child));
96     }
97 }
99 void SPDefs::sp_defs_modified(SPObject *object, guint flags)
101     if (flags & SP_OBJECT_MODIFIED_FLAG) {
102         flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
103     }
105     flags &= SP_OBJECT_MODIFIED_CASCADE;
107     GSList *l = NULL;
108     for ( SPObject *child = object->first_child() ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
109         g_object_ref(G_OBJECT(child));
110         l = g_slist_prepend(l, child);
111     }
113     l = g_slist_reverse(l);
115     while (l) {
116         SPObject *child = SP_OBJECT(l->data);
117         l = g_slist_remove(l, child);
118         if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
119             child->emitModified(flags);
120         }
121         g_object_unref(G_OBJECT (child));
122     }
125 Inkscape::XML::Node * SPDefs::sp_defs_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
127     if (flags & SP_OBJECT_WRITE_BUILD) {
129         if (!repr) {
130             repr = xml_doc->createElement("svg:defs");
131         }
133         GSList *l = NULL;
134         for ( SPObject *child = object->first_child() ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
135             Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
136             if (crepr) l = g_slist_prepend(l, crepr);
137         }
139         while (l) {
140             repr->addChild((Inkscape::XML::Node *) l->data, NULL);
141             Inkscape::GC::release((Inkscape::XML::Node *) l->data);
142             l = g_slist_remove(l, l->data);
143         }
145     } else {
146         for ( SPObject *child = object->first_child() ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
147             child->updateRepr(flags);
148         }
149     }
151     if (((SPObjectClass *) (SPDefsClass::static_parent_class))->write) {
152         (* ((SPObjectClass *) (SPDefsClass::static_parent_class))->write)(object, xml_doc, repr, flags);
153     }
155     return repr;
158 /*
159   Local Variables:
160   mode:c++
161   c-file-style:"stroustrup"
162   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163   indent-tabs-mode:nil
164   fill-column:99
165   End:
166 */
167 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :