Code

User message context in extensions
[inkscape.git] / src / sp-mask.h
index d5bddd332861f2f18efdbe0e3b4d8013ce1013ea..d8b6b33ea9b7607e21d6f4879bd6bde90c95ab91 100644 (file)
@@ -1,11 +1,12 @@
-#ifndef __SP_MASK_H__
-#define __SP_MASK_H__
+#ifndef SEEN_SP_MASK_H
+#define SEEN_SP_MASK_H
 
 /*
  * SVG <mask> implementation
  *
  * Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2003 authors
  *
@@ -26,6 +27,7 @@ class SPMaskView;
 #include "libnr/nr-forward.h"
 #include "sp-object-group.h"
 #include "uri-references.h"
+#include "xml/node.h"
 
 struct SPMask : public SPObjectGroup {
        unsigned int maskUnits_set : 1;
@@ -50,8 +52,41 @@ public:
                return (SPMask *)URIReference::getObject();
        }
 protected:
+    /**
+     * If the owner element of this reference (the element with <... mask="...">)
+     * is a child of the mask it refers to, return false.
+     * \return false if obj is not a mask or if obj is a parent of this
+     *         reference's owner element.  True otherwise.
+     */
        virtual bool _acceptObject(SPObject *obj) const {
-               return SP_IS_MASK(obj);
+               if (!SP_IS_MASK(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_mask = NULL;
+            gchar const * obj_name = NULL;
+            gchar const * obj_id = NULL;
+            if (owner_repr != NULL) {
+                owner_name = owner_repr->name();
+                owner_mask = owner_repr->attribute("mask");
+            }
+            if (obj_repr != NULL) {
+                obj_name = obj_repr->name();
+                obj_id = obj_repr->attribute("id");
+            }
+            g_warning("Ignoring recursive mask reference "
+                      "<%s mask=\"%s\"> in <%s id=\"%s\">",
+                      owner_name, owner_mask,
+                      obj_name, obj_id);
+            return false;
+        }
+        return true;
        }
 };
 
@@ -62,4 +97,4 @@ void sp_mask_set_bbox (SPMask *mask, unsigned int key, NRRect *bbox);
 
 const gchar *sp_mask_create (GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform);
 
-#endif
+#endif // SEEN_SP_MASK_H