Code

use an accessor method to get filter from style
[inkscape.git] / src / sp-feimage.cpp
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"
26 /* FeImage base class */
28 static void sp_feImage_class_init(SPFeImageClass *klass);
29 static void sp_feImage_init(SPFeImage *feImage);
31 static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
32 static void sp_feImage_release(SPObject *object);
33 static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value);
34 static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags);
35 static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
37 static SPFilterPrimitiveClass *feImage_parent_class;
39 GType
40 sp_feImage_get_type()
41 {
42     static GType feImage_type = 0;
44     if (!feImage_type) {
45         GTypeInfo feImage_info = {
46             sizeof(SPFeImageClass),
47             NULL, NULL,
48             (GClassInitFunc) sp_feImage_class_init,
49             NULL, NULL,
50             sizeof(SPFeImage),
51             16,
52             (GInstanceInitFunc) sp_feImage_init,
53             NULL,    /* value_table */
54         };
55         feImage_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeImage", &feImage_info, (GTypeFlags)0);
56     }
57     return feImage_type;
58 }
60 static void
61 sp_feImage_class_init(SPFeImageClass *klass)
62 {
63     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
65     feImage_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
67     sp_object_class->build = sp_feImage_build;
68     sp_object_class->release = sp_feImage_release;
69     sp_object_class->write = sp_feImage_write;
70     sp_object_class->set = sp_feImage_set;
71     sp_object_class->update = sp_feImage_update;
72 }
74 static void
75 sp_feImage_init(SPFeImage *feImage)
76 {
77 }
79 /**
80  * Reads the Inkscape::XML::Node, and initializes SPFeImage variables.  For this to get called,
81  * our name must be associated with a repr via "sp_object_type_register".  Best done through
82  * sp-object-repr.cpp's repr_name_entries array.
83  */
84 static void
85 sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
86 {
87     if (((SPObjectClass *) feImage_parent_class)->build) {
88         ((SPObjectClass *) feImage_parent_class)->build(object, document, repr);
89     }
91     /*LOAD ATTRIBUTES FROM REPR HERE*/
92 }
94 /**
95  * Drops any allocated memory.
96  */
97 static void
98 sp_feImage_release(SPObject *object)
99 {
101     if (((SPObjectClass *) feImage_parent_class)->release)
102         ((SPObjectClass *) feImage_parent_class)->release(object);
105 /**
106  * Sets a specific value in the SPFeImage.
107  */
108 static void
109 sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
111     SPFeImage *feImage = SP_FEIMAGE(object);
112     (void)feImage;
114     switch(key) {
115         /*DEAL WITH SETTING ATTRIBUTES HERE*/
116         default:
117             if (((SPObjectClass *) feImage_parent_class)->set)
118                 ((SPObjectClass *) feImage_parent_class)->set(object, key, value);
119             break;
120     }
124 /**
125  * Receives update notifications.
126  */
127 static void
128 sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags)
130     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
131                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
133         /* do something to trigger redisplay, updates? */
135     }
137     if (((SPObjectClass *) feImage_parent_class)->update) {
138         ((SPObjectClass *) feImage_parent_class)->update(object, ctx, flags);
139     }
142 /**
143  * Writes its settings to an incoming repr object, if any.
144  */
145 static Inkscape::XML::Node *
146 sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
148     // Inkscape-only object, not copied during an "plain SVG" dump:
149     if (flags & SP_OBJECT_WRITE_EXT) {
150         if (repr) {
151             // is this sane?
152             repr->mergeFrom(SP_OBJECT_REPR(object), "id");
153         } else {
154             repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
155         }
156     }
158     if (((SPObjectClass *) feImage_parent_class)->write) {
159         ((SPObjectClass *) feImage_parent_class)->write(object, repr, flags);
160     }
162     return repr;
166 /*
167   Local Variables:
168   mode:c++
169   c-file-style:"stroustrup"
170   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
171   indent-tabs-mode:nil
172   fill-column:99
173   End:
174 */
175 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :