08bb1f3e2e67c1994888361615eb108c6f594736
1 #define __SP_FEIMAGE_CPP__
3 /** \file
4 * SVG <feImage> implementation.
5 *
6 */
7 /*
8 * Authors:
9 * hugo Rodrigues <haa.rodrigues@gmail.com>
10 *
11 * Copyright (C) 2006 Hugo Rodrigues
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #include "attributes.h"
21 #include "svg/svg.h"
22 #include "sp-feimage.h"
23 #include "xml/repr.h"
25 //#define SP_MACROS_SILENT
26 //#include "macros.h"
28 #define DEBUG_FEIMAGE
29 #ifdef DEBUG_FEIMAGE
30 # define debug(f, a...) { g_print("%s(%d) %s:", \
31 __FILE__,__LINE__,__FUNCTION__); \
32 g_print(f, ## a); \
33 g_print("\n"); \
34 }
35 #else
36 # define debug(f, a...) /**/
37 #endif
39 /* FeImage base class */
41 static void sp_feImage_class_init(SPFeImageClass *klass);
42 static void sp_feImage_init(SPFeImage *feImage);
44 static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
45 static void sp_feImage_release(SPObject *object);
46 static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value);
47 static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags);
48 static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
50 static SPObjectClass *feImage_parent_class;
52 GType
53 sp_feImage_get_type()
54 {
55 static GType feImage_type = 0;
57 if (!feImage_type) {
58 GTypeInfo feImage_info = {
59 sizeof(SPFeImageClass),
60 NULL, NULL,
61 (GClassInitFunc) sp_feImage_class_init,
62 NULL, NULL,
63 sizeof(SPFeImage),
64 16,
65 (GInstanceInitFunc) sp_feImage_init,
66 NULL, /* value_table */
67 };
68 feImage_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeImage", &feImage_info, (GTypeFlags)0);
69 }
70 return feImage_type;
71 }
73 static void
74 sp_feImage_class_init(SPFeImageClass *klass)
75 {
76 SPObjectClass *sp_object_class = (SPObjectClass *)klass;
78 feImage_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
80 sp_object_class->build = sp_feImage_build;
81 sp_object_class->release = sp_feImage_release;
82 sp_object_class->write = sp_feImage_write;
83 sp_object_class->set = sp_feImage_set;
84 sp_object_class->update = sp_feImage_update;
85 }
87 static void
88 sp_feImage_init(SPFeImage *feImage)
89 {
90 debug("0x%p",feImage);
91 }
93 /**
94 * Reads the Inkscape::XML::Node, and initializes SPFeImage variables. For this to get called,
95 * our name must be associated with a repr via "sp_object_type_register". Best done through
96 * sp-object-repr.cpp's repr_name_entries array.
97 */
98 static void
99 sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
100 {
101 debug("0x%p",object);
102 if (((SPObjectClass *) feImage_parent_class)->build) {
103 ((SPObjectClass *) feImage_parent_class)->build(object, document, repr);
104 }
106 /*LOAD ATTRIBUTES FROM REPR HERE*/
107 }
109 /**
110 * Drops any allocated memory.
111 */
112 static void
113 sp_feImage_release(SPObject *object)
114 {
115 debug("0x%p",object);
117 if (((SPObjectClass *) feImage_parent_class)->release)
118 ((SPObjectClass *) feImage_parent_class)->release(object);
119 }
121 /**
122 * Sets a specific value in the SPFeImage.
123 */
124 static void
125 sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
126 {
127 debug("0x%p %s(%u): '%s'",object,
128 sp_attribute_name(key),key,value);
129 SPFeImage *feImage = SP_FEIMAGE(object);
131 switch(key) {\r
132 /*DEAL WITH SETTING ATTRIBUTES HERE*/
133 default:
134 if (((SPObjectClass *) feImage_parent_class)->set)
135 ((SPObjectClass *) feImage_parent_class)->set(object, key, value);
136 break;
137 }
139 }
141 /**
142 * Receives update notifications.
143 */
144 static void
145 sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags)
146 {
147 debug("0x%p",object);
149 if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
150 SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
152 /* do something to trigger redisplay, updates? */
154 }
156 if (((SPObjectClass *) feImage_parent_class)->update) {
157 ((SPObjectClass *) feImage_parent_class)->update(object, ctx, flags);
158 }
159 }
161 /**
162 * Writes its settings to an incoming repr object, if any.
163 */
164 static Inkscape::XML::Node *
165 sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
166 {
167 debug("0x%p",object);
169 // Inkscape-only object, not copied during an "plain SVG" dump:
170 if (flags & SP_OBJECT_WRITE_EXT) {
171 if (repr) {
172 // is this sane?
173 repr->mergeFrom(SP_OBJECT_REPR(object), "id");
174 } else {
175 repr = SP_OBJECT_REPR(object)->duplicate();
176 }
177 }
179 if (((SPObjectClass *) feImage_parent_class)->write) {
180 ((SPObjectClass *) feImage_parent_class)->write(object, repr, flags);
181 }
183 return repr;
184 }
187 /*
188 Local Variables:
189 mode:c++
190 c-file-style:"stroustrup"
191 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
192 indent-tabs-mode:nil
193 fill-column:99
194 End:
195 */
196 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :