1 #ifndef SEEN_SP_CLIPPATH_H
2 #define SEEN_SP_CLIPPATH_H
4 /*
5 * SVG <clipPath> implementation
6 *
7 * Authors:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Abhishek Sharma
10 * Jon A. Cruz <jon@joncruz.org>
11 *
12 * Copyright (C) 2001-2002 authors
13 * Copyright (C) 2001 Ximian, Inc.
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #define SP_TYPE_CLIPPATH (SPClipPath::sp_clippath_get_type())
19 #define SP_CLIPPATH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_CLIPPATH, SPClipPath))
20 #define SP_CLIPPATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_CLIPPATH, SPClipPathClass))
21 #define SP_IS_CLIPPATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_CLIPPATH))
22 #define SP_IS_CLIPPATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_CLIPPATH))
24 class SPClipPathView;
26 #include "display/nr-arena-forward.h"
27 #include "libnr/nr-forward.h"
28 #include "sp-object-group.h"
29 #include "uri-references.h"
30 #include "xml/node.h"
32 class SPClipPath : public SPObjectGroup {
33 public:
34 class Reference;
36 unsigned int clipPathUnits_set : 1;
37 unsigned int clipPathUnits : 1;
39 SPClipPathView *display;
40 static const gchar *create(GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform);
41 static GType sp_clippath_get_type(void);
43 NRArenaItem *show(NRArena *arena, unsigned int key);
44 void hide(unsigned int key);
46 void setBBox(unsigned int key, NRRect *bbox);
47 void getBBox(NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
49 private:
50 static void init(SPClipPath *clippath);
52 static void build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
53 static void release(SPObject * object);
54 static void set(SPObject *object, unsigned int key, gchar const *value);
55 static void childAdded(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
56 static void update(SPObject *object, SPCtx *ctx, guint flags);
57 static void modified(SPObject *object, guint flags);
58 static Inkscape::XML::Node *write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
60 friend class SPClipPathClass;
61 };
63 class SPClipPathClass {
64 public:
65 SPObjectGroupClass parent_class;
67 private:
68 static void sp_clippath_class_init(SPClipPathClass *klass);
69 static SPObjectGroupClass *static_parent_class;
71 friend class SPClipPath;
72 };
74 class SPClipPathReference : public Inkscape::URIReference {
75 public:
76 SPClipPathReference(SPObject *obj) : URIReference(obj) {}
77 SPClipPath *getObject() const {
78 return (SPClipPath *)URIReference::getObject();
79 }
81 protected:
82 /**
83 * If the owner element of this reference (the element with <... clippath="...">)
84 * is a child of the clippath it refers to, return false.
85 * \return false if obj is not a clippath or if obj is a parent of this
86 * reference's owner element. True otherwise.
87 */
88 virtual bool _acceptObject(SPObject *obj) const {
89 if (!SP_IS_CLIPPATH(obj)) {
90 return false;
91 }
92 SPObject * const owner = this->getOwner();
93 if (obj->isAncestorOf(owner)) {
94 //XML Tree being used directly here while it shouldn't be...
95 Inkscape::XML::Node * const owner_repr = owner->getRepr();
96 //XML Tree being used directly here while it shouldn't be...
97 Inkscape::XML::Node * const obj_repr = obj->getRepr();
98 gchar const * owner_name = NULL;
99 gchar const * owner_clippath = NULL;
100 gchar const * obj_name = NULL;
101 gchar const * obj_id = NULL;
102 if (owner_repr != NULL) {
103 owner_name = owner_repr->name();
104 owner_clippath = owner_repr->attribute("clippath");
105 }
106 if (obj_repr != NULL) {
107 obj_name = obj_repr->name();
108 obj_id = obj_repr->attribute("id");
109 }
110 g_warning("Ignoring recursive clippath reference "
111 "<%s clippath=\"%s\"> in <%s id=\"%s\">",
112 owner_name, owner_clippath,
113 obj_name, obj_id);
114 return false;
115 }
116 return true;
117 }
118 };
120 #endif // SEEN_SP_CLIPPATH_H
122 /*
123 Local Variables:
124 mode:c++
125 c-file-style:"stroustrup"
126 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
127 indent-tabs-mode:nil
128 fill-column:99
129 End:
130 */
131 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :