Code

Refactoring SPColor to C++ and removing legacy CMYK implementation
[inkscape.git] / src / sp-object.cpp
index b97aa4513abecefe7f7171c4a9c98cc62313434f..f76e70a51cbc9460fc7645c917d809d9001b4369 100644 (file)
@@ -174,8 +174,6 @@ sp_object_init(SPObject *object)
     object->repr = NULL;
     object->id = NULL;
 
-    object->style = sp_style_new_from_object(object);
-
     object->_collection_policy = SPObject::COLLECT_WITH_PARENT;
 
     new (&object->_release_signal) sigc::signal<void, SPObject *>();
@@ -184,6 +182,12 @@ sp_object_init(SPObject *object)
     new (&object->_position_changed_signal) sigc::signal<void, SPObject *>();
     object->_successor = NULL;
 
+    // FIXME: now we create style for all objects, but per SVG, only the following can have style attribute:
+    // vg, g, defs, desc, title, symbol, use, image, switch, path, rect, circle, ellipse, line, polyline, 
+    // polygon, text, tspan, tref, textPath, altGlyph, glyphRef, marker, linearGradient, radialGradient, 
+    // stop, pattern, clipPath, mask, filter, feImage, a, font, glyph, missing-glyph, foreignObject
+    object->style = sp_style_new_from_object(object);
+
     object->_label = NULL;
     object->_default_label = NULL;
 }
@@ -817,20 +821,26 @@ sp_object_invoke_build(SPObject *object, SPDocument *document, Inkscape::XML::No
         object->document->bindObjectToRepr(object->repr, object);
 
         if (Inkscape::XML::id_permitted(object->repr)) {
-            /* If we are not cloned, force unique id */
+            /* If we are not cloned, and not seeking, force unique id */
             gchar const *id = object->repr->attribute("id");
-            gchar *realid = sp_object_get_unique_id(object, id);
-            g_assert(realid != NULL);
-
-            object->document->bindObjectToId(realid, object);
-            object->id = realid;
-
-            /* Redefine ID, if required */
-            if ((id == NULL) || (strcmp(id, realid) != 0)) {
-                bool saved = sp_document_get_undo_sensitive(document);
-                sp_document_set_undo_sensitive(document, false);
-                object->repr->setAttribute("id", realid);
-                sp_document_set_undo_sensitive(document, saved);
+            if (!document->isSeeking()) {
+                gchar *realid = sp_object_get_unique_id(object, id);
+                g_assert(realid != NULL);
+
+                object->document->bindObjectToId(realid, object);
+                object->id = realid;
+
+                /* Redefine ID, if required */
+                if ((id == NULL) || (strcmp(id, realid) != 0)) {
+                    object->repr->setAttribute("id", realid);
+                }
+            } else if (id) {
+                // bind if id, but no conflict -- otherwise, we can expect
+                // a subsequent setting of the id attribute
+                if (!object->document->getObjectById(id)) {
+                    object->document->bindObjectToId(id, object);
+                    object->id = g_strdup(id);
+                }
             }
         }
     } else {
@@ -838,7 +848,6 @@ sp_object_invoke_build(SPObject *object, SPDocument *document, Inkscape::XML::No
     }
 
     /* Invoke derived methods, if any */
-
     if (((SPObjectClass *) G_OBJECT_GET_CLASS(object))->build) {
         (*((SPObjectClass *) G_OBJECT_GET_CLASS(object))->build)(object, document, repr);
     }
@@ -941,16 +950,23 @@ sp_object_private_set(SPObject *object, unsigned int key, gchar const *value)
                 SPDocument *document=object->document;
                 SPObject *conflict=NULL;
 
-                if (value) {
-                    conflict = document->getObjectById((char const *)value);
+                gchar const *new_id = value;
+
+                if (new_id) {
+                    conflict = document->getObjectById((char const *)new_id);
                 }
+
                 if ( conflict && conflict != object ) {
-                    sp_object_ref(conflict, NULL);
-                    // give the conflicting object a new ID
-                    gchar *new_conflict_id = sp_object_get_unique_id(conflict, NULL);
-                    SP_OBJECT_REPR(conflict)->setAttribute("id", new_conflict_id);
-                    g_free(new_conflict_id);
-                    sp_object_unref(conflict, NULL);
+                    if (!document->isSeeking()) {
+                        sp_object_ref(conflict, NULL);
+                        // give the conflicting object a new ID
+                        gchar *new_conflict_id = sp_object_get_unique_id(conflict, NULL);
+                        SP_OBJECT_REPR(conflict)->setAttribute("id", new_conflict_id);
+                        g_free(new_conflict_id);
+                        sp_object_unref(conflict, NULL);
+                    } else {
+                        new_id = NULL;
+                    }
                 }
 
                 if (object->id) {
@@ -958,8 +974,8 @@ sp_object_private_set(SPObject *object, unsigned int key, gchar const *value)
                     g_free(object->id);
                 }
 
-                if (value) {
-                    object->id = g_strdup((char const*)value);
+                if (new_id) {
+                    object->id = g_strdup((char const*)new_id);
                     document->bindObjectToId(object->id, object);
                 } else {
                     object->id = NULL;
@@ -1096,7 +1112,7 @@ static Inkscape::XML::Node *
 sp_object_private_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
 {
     if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) {
-        repr = SP_OBJECT_REPR(object)->duplicate();
+        repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
         if (!( flags & SP_OBJECT_WRITE_EXT )) {
             repr->setAttribute("inkscape:collect", NULL);
         }
@@ -1172,6 +1188,10 @@ SPObject::updateRepr(unsigned int flags) {
     }
 }
 
+/** Used both to create reprs in the original document, and to create 
+ *  reprs in another document (e.g. a temporary document used when
+ *  saving as "Plain SVG"
+ */
 Inkscape::XML::Node *
 SPObject::updateRepr(Inkscape::XML::Node *repr, unsigned int flags) {
     if (SP_OBJECT_IS_CLONED(this)) {
@@ -1187,9 +1207,10 @@ SPObject::updateRepr(Inkscape::XML::Node *repr, unsigned int flags) {
         g_warning("Class %s does not implement ::write", G_OBJECT_TYPE_NAME(this));
         if (!repr) {
             if (flags & SP_OBJECT_WRITE_BUILD) {
-                repr = SP_OBJECT_REPR(this)->duplicate();
+                /// \todo FIXME:  Plumb an appropriate XML::Document into this
+                repr = SP_OBJECT_REPR(this)->duplicate(NULL);
             }
-            /// \todo fixme: else probably error (Lauris) */
+            /// \todo FIXME: else probably error (Lauris) */
         } else {
             repr->mergeFrom(SP_OBJECT_REPR(this), "id");
         }