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