Code

SPShape c++ified to the extent it was possible and more changes done for XML privatis...
[inkscape.git] / src / sp-clippath.h
index d6a4e6f0b8b39f1bc13b04047fe9358260b36078..308c3c8930e110671ca5d619c2ccc559169f67d9 100644 (file)
 class SPClipPathView;
 
 #include "display/nr-arena-forward.h"
+#include "libnr/nr-forward.h"
 #include "sp-object-group.h"
 #include "uri-references.h"
-#include <libnr/nr-forward.h>
+#include "xml/node.h"
 
 struct SPClipPath : public SPObjectGroup {
        class Reference;
@@ -48,8 +49,41 @@ public:
                return (SPClipPath *)URIReference::getObject();
        }
 protected:
+    /**
+     * If the owner element of this reference (the element with <... clippath="...">)
+     * is a child of the clippath it refers to, return false.
+     * \return false if obj is not a clippath or if obj is a parent of this
+     *         reference's owner element.  True otherwise.
+     */
        virtual bool _acceptObject(SPObject *obj) const {
-               return SP_IS_CLIPPATH(obj);
+               if (!SP_IS_CLIPPATH(obj)) {
+                   return false;
+           }
+           SPObject * const owner = this->getOwner();
+        if (obj->isAncestorOf(owner)) {
+                       //XML Tree being used directly here while it shouldn't be...
+            Inkscape::XML::Node * const owner_repr = owner->getRepr();
+                       //XML Tree being used directly here while it shouldn't be...
+            Inkscape::XML::Node * const obj_repr = obj->getRepr();
+            gchar const * owner_name = NULL;
+            gchar const * owner_clippath = NULL;
+            gchar const * obj_name = NULL;
+            gchar const * obj_id = NULL;
+            if (owner_repr != NULL) {
+                owner_name = owner_repr->name();
+                owner_clippath = owner_repr->attribute("clippath");
+            }
+            if (obj_repr != NULL) {
+                obj_name = obj_repr->name();
+                obj_id = obj_repr->attribute("id");
+            }
+            g_warning("Ignoring recursive clippath reference "
+                      "<%s clippath=\"%s\"> in <%s id=\"%s\">",
+                      owner_name, owner_clippath,
+                      obj_name, obj_id);
+            return false;
+        }
+        return true;
        }
 };
 
@@ -59,6 +93,6 @@ void sp_clippath_hide(SPClipPath *cp, unsigned int key);
 void sp_clippath_set_bbox(SPClipPath *cp, unsigned int key, NRRect *bbox);
 void sp_clippath_get_bbox(SPClipPath *cp, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
 
-const gchar *sp_clippath_create (GSList *reprs, Document *document, Geom::Matrix const* applyTransform);
+const gchar *sp_clippath_create (GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform);
 
 #endif