1 /** \file
2 * SVG <skeleton> implementation, used as an example for a base starting class
3 * when implementing new sp-objects.
4 *
5 * In vi, three global search-and-replaces will let you rename everything
6 * in this and the .h file:
7 *
8 * :%s/SKELETON/YOURNAME/g
9 * :%s/Skeleton/Yourname/g
10 * :%s/skeleton/yourname/g
11 */
12 /*
13 * Authors:
14 * Kees Cook <kees@outflux.net>
15 * Abhishek Sharma
16 *
17 * Copyright (C) 2004 Kees Cook
18 *
19 * Released under GNU GPL, read the file 'COPYING' for more information
20 */
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include "attributes.h"
27 #include "sp-skeleton.h"
28 #include "xml/repr.h"
30 #define DEBUG_SKELETON
31 #ifdef DEBUG_SKELETON
32 # define debug(f, a...) { g_print("%s(%d) %s:", \
33 __FILE__,__LINE__,__FUNCTION__); \
34 g_print(f, ## a); \
35 g_print("\n"); \
36 }
37 #else
38 # define debug(f, a...) /**/
39 #endif
41 /* Skeleton base class */
43 static void sp_skeleton_class_init(SPSkeletonClass *klass);
44 static void sp_skeleton_init(SPSkeleton *skeleton);
46 static void sp_skeleton_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
47 static void sp_skeleton_release(SPObject *object);
48 static void sp_skeleton_set(SPObject *object, unsigned int key, gchar const *value);
49 static void sp_skeleton_update(SPObject *object, SPCtx *ctx, guint flags);
50 static Inkscape::XML::Node *sp_skeleton_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
52 static SPObjectClass *skeleton_parent_class;
54 GType
55 sp_skeleton_get_type()
56 {
57 static GType skeleton_type = 0;
59 if (!skeleton_type) {
60 GTypeInfo skeleton_info = {
61 sizeof(SPSkeletonClass),
62 NULL, NULL,
63 (GClassInitFunc) sp_skeleton_class_init,
64 NULL, NULL,
65 sizeof(SPSkeleton),
66 16,
67 (GInstanceInitFunc) sp_skeleton_init,
68 NULL, /* value_table */
69 };
70 skeleton_type = g_type_register_static(SP_TYPE_OBJECT, "SPSkeleton", &skeleton_info, (GTypeFlags)0);
71 }
72 return skeleton_type;
73 }
75 static void
76 sp_skeleton_class_init(SPSkeletonClass *klass)
77 {
78 //GObjectClass *gobject_class = (GObjectClass *)klass;
79 SPObjectClass *sp_object_class = (SPObjectClass *)klass;
81 skeleton_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
83 sp_object_class->build = sp_skeleton_build;
84 sp_object_class->release = sp_skeleton_release;
85 sp_object_class->write = sp_skeleton_write;
86 sp_object_class->set = sp_skeleton_set;
87 sp_object_class->update = sp_skeleton_update;
88 }
90 static void
91 sp_skeleton_init(SPSkeleton *skeleton)
92 {
93 debug("0x%p",skeleton);
94 }
96 /**
97 * Reads the Inkscape::XML::Node, and initializes SPSkeleton variables. For this to get called,
98 * our name must be associated with a repr via "sp_object_type_register". Best done through
99 * sp-object-repr.cpp's repr_name_entries array.
100 */
101 static void
102 sp_skeleton_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
103 {
104 debug("0x%p",object);
105 if (((SPObjectClass *) skeleton_parent_class)->build) {
106 ((SPObjectClass *) skeleton_parent_class)->build(object, document, repr);
107 }
109 /*
110 Pay attention to certain settings here
112 object->readAttr( "xlink:href" );
113 object->readAttr( "attributeName" );
114 object->readAttr( "attributeType" );
115 object->readAttr( "begin" );
116 object->readAttr( "dur" );
117 object->readAttr( "end" );
118 object->readAttr( "min" );
119 object->readAttr( "max" );
120 object->readAttr( "restart" );
121 object->readAttr( "repeatCount" );
122 object->readAttr( "repeatDur" );
123 object->readAttr( "fill" );
124 */
125 }
127 /**
128 * Drops any allocated memory.
129 */
130 static void
131 sp_skeleton_release(SPObject *object)
132 {
133 debug("0x%p",object);
135 /* deal with our children and our selves here */
137 if (((SPObjectClass *) skeleton_parent_class)->release)
138 ((SPObjectClass *) skeleton_parent_class)->release(object);
139 }
141 /**
142 * Sets a specific value in the SPSkeleton.
143 */
144 static void
145 sp_skeleton_set(SPObject *object, unsigned int key, gchar const *value)
146 {
147 debug("0x%p %s(%u): '%s'",object,
148 sp_attribute_name(key),key,value ? value : "<no value>");
149 //SPSkeleton *skeleton = SP_SKELETON(object);
151 /* See if any parents need this value. */
152 if (((SPObjectClass *) skeleton_parent_class)->set) {
153 ((SPObjectClass *) skeleton_parent_class)->set(object, key, value);
154 }
155 }
157 /**
158 * Receives update notifications.
159 */
160 static void
161 sp_skeleton_update(SPObject *object, SPCtx *ctx, guint flags)
162 {
163 debug("0x%p",object);
164 //SPSkeleton *skeleton = SP_SKELETON(object);
166 if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
167 SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
169 /* do something to trigger redisplay, updates? */
171 }
173 if (((SPObjectClass *) skeleton_parent_class)->update) {
174 ((SPObjectClass *) skeleton_parent_class)->update(object, ctx, flags);
175 }
176 }
178 /**
179 * Writes its settings to an incoming repr object, if any.
180 */
181 static Inkscape::XML::Node *
182 sp_skeleton_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
183 {
184 debug("0x%p",object);
185 //SPSkeleton *skeleton = SP_SKELETON(object);
187 // Inkscape-only object, not copied during an "plain SVG" dump:
188 if (flags & SP_OBJECT_WRITE_EXT) {
189 if (repr) {
190 // is this sane?
191 repr->mergeFrom(SP_OBJECT_REPR(object), "id");
192 } else {
193 repr = SP_OBJECT_REPR(object)->duplicate(doc);
194 }
195 }
197 if (((SPObjectClass *) skeleton_parent_class)->write) {
198 ((SPObjectClass *) skeleton_parent_class)->write(object, doc, repr, flags);
199 }
201 return repr;
202 }
205 /*
206 Local Variables:
207 mode:c++
208 c-file-style:"stroustrup"
209 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
210 indent-tabs-mode:nil
211 fill-column:99
212 End:
213 */
214 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :