Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / sp-root.cpp
index 5a9cce8fbda6b157fc2f117d8ce35a4e3b8dbc27..5f868539b1eab0449e7366d1342fca5f615a751e 100644 (file)
@@ -1,11 +1,11 @@
-#define __SP_ROOT_C__
-
 /** \file
  * SVG \<svg\> implementation.
  */
 /*
  * Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 1999-2002 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
@@ -34,7 +34,7 @@
 #include <libnr/nr-translate-scale-ops.h>
 #include <xml/repr.h>
 #include "svg/stringstream.h"
-#include "inkscape_version.h"
+#include "inkscape-version.h"
 
 class SPDesktop;
 
@@ -51,7 +51,6 @@ static void sp_root_modified(SPObject *object, guint flags);
 static Inkscape::XML::Node *sp_root_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 static NRArenaItem *sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
-static void sp_root_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
 static void sp_root_print(SPItem *item, SPPrintContext *ctx);
 
 static SPGroupClass *parent_class;
@@ -106,7 +105,6 @@ sp_root_class_init(SPRootClass *klass)
     sp_object_class->write = sp_root_write;
 
     sp_item_class->show = sp_root_show;
-    sp_item_class->bbox = sp_root_bbox;
     sp_item_class->print = sp_root_print;
 }
 
@@ -119,9 +117,10 @@ sp_root_init(SPRoot *root)
     static Inkscape::Version const zero_version(0, 0);
 
     sp_version_from_string(SVG_VERSION, &root->original.svg);
-    root->version.svg = root->original.svg;
-    root->version.inkscape = root->original.inkscape =
-        root->version.sodipodi = root->original.sodipodi = zero_version;
+    root->version.svg = zero_version;
+    root->original.svg = zero_version;
+    root->version.inkscape = zero_version;
+    root->original.inkscape = zero_version;
 
     root->x.unset();
     root->y.unset();
@@ -147,28 +146,27 @@ sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
     SPGroup *group = (SPGroup *) object;
     SPRoot *root = (SPRoot *) object;
 
-    if (repr->attribute("sodipodi:docname") || repr->attribute("SP-DOCNAME")) {
-        /* so we have a nonzero initial version */
-        root->original.sodipodi.major = 0;
-        root->original.sodipodi.minor = 1;
+    //XML Tree being used directly here while it shouldn't be.
+    if ( !object->getRepr()->attribute("version") ) {
+        repr->setAttribute("version", SVG_VERSION);
     }
-    sp_object_read_attr(object, "version");
-    sp_object_read_attr(object, "sodipodi:version");
-    sp_object_read_attr(object, "inkscape:version");
+
+    object->readAttr( "version" );
+    object->readAttr( "inkscape:version" );
     /* It is important to parse these here, so objects will have viewport build-time */
-    sp_object_read_attr(object, "x");
-    sp_object_read_attr(object, "y");
-    sp_object_read_attr(object, "width");
-    sp_object_read_attr(object, "height");
-    sp_object_read_attr(object, "viewBox");
-    sp_object_read_attr(object, "preserveAspectRatio");
-    sp_object_read_attr(object, "onload");
+    object->readAttr( "x" );
+    object->readAttr( "y" );
+    object->readAttr( "width" );
+    object->readAttr( "height" );
+    object->readAttr( "viewBox" );
+    object->readAttr( "preserveAspectRatio" );
+    object->readAttr( "onload" );
 
     if (((SPObjectClass *) parent_class)->build)
         (* ((SPObjectClass *) parent_class)->build) (object, document, repr);
 
-    /* Search for first <defs> node */
-    for (SPObject *o = sp_object_first_child(SP_OBJECT(group)) ; o != NULL; o = SP_OBJECT_NEXT(o) ) {
+    // Search for first <defs> node
+    for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
         if (SP_IS_DEFS(o)) {
             root->defs = SP_DEFS(o);
             break;
@@ -176,7 +174,7 @@ sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
     }
 
     // clear transform, if any was read in - SVG does not allow transform= on <svg>
-    SP_ITEM(object)->transform = NR::identity();
+    SP_ITEM(object)->transform = Geom::identity();
 }
 
 /**
@@ -207,10 +205,6 @@ sp_root_set(SPObject *object, unsigned int key, gchar const *value)
                 root->version.svg = root->original.svg;
             }
             break;
-        case SP_ATTR_SODIPODI_VERSION:
-            if (!sp_version_from_string(value, &root->version.sodipodi)) {
-                root->version.sodipodi = root->original.sodipodi;
-            }
         case SP_ATTR_INKSCAPE_VERSION:
             if (!sp_version_from_string(value, &root->version.inkscape)) {
                 root->version.inkscape = root->original.inkscape;
@@ -352,22 +346,21 @@ sp_root_set(SPObject *object, unsigned int key, gchar const *value)
  * This routine is for adding a child SVG object to an SPRoot object.
  * The SPRoot object is taken to be an SPGroup.
  */
-static void
-sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
+static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
 {
     SPRoot *root = (SPRoot *) object;
     SPGroup *group = (SPGroup *) object;
 
-    if (((SPObjectClass *) (parent_class))->child_added)
+    if (((SPObjectClass *) (parent_class))->child_added) {
         (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref);
+    }
 
     SPObject *co = object->document->getObjectByRepr(child);
     g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object
 
     if (co && SP_IS_DEFS(co)) {
-        SPObject *c;
-        /* We search for first <defs> node - it is not beautiful, but works */
-        for (c = sp_object_first_child(SP_OBJECT(group)) ; c != NULL; c = SP_OBJECT_NEXT(c) ) {
+        // We search for first <defs> node - it is not beautiful, but works
+        for (SPObject *c = group->firstChild() ; c ; c = c->getNext() ) {
             if (SP_IS_DEFS(c)) {
                 root->defs = SP_DEFS(c);
                 break;
@@ -384,9 +377,9 @@ static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
     SPRoot *root = (SPRoot *) object;
 
     if ( root->defs && SP_OBJECT_REPR(root->defs) == child ) {
-        SPObject *iter;
-        /* We search for first remaining <defs> node - it is not beautiful, but works */
-        for ( iter = sp_object_first_child(object) ; iter ; iter = SP_OBJECT_NEXT(iter) ) {
+        SPObject *iter = 0;
+        // We search for first remaining <defs> node - it is not beautiful, but works
+        for ( iter = object->firstChild() ; iter ; iter = iter->getNext() ) {
             if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
                 root->defs = (SPDefs *)iter;
                 break;
@@ -398,8 +391,9 @@ static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child)
         }
     }
 
-    if (((SPObjectClass *) (parent_class))->remove_child)
+    if (((SPObjectClass *) (parent_class))->remove_child) {
         (* ((SPObjectClass *) (parent_class))->remove_child)(object, child);
+    }
 }
 
 /**
@@ -546,7 +540,7 @@ sp_root_update(SPObject *object, SPCtx *ctx, guint flags)
         rctx.vp.y1 = root->height.computed;
     }
 
-    rctx.i2vp = NR::identity();
+    rctx.i2vp = Geom::identity();
 
     /* And invoke parent method */
     if (((SPObjectClass *) (parent_class))->update)
@@ -573,7 +567,7 @@ sp_root_modified(SPObject *object, guint flags)
 
     /* fixme: (Lauris) */
     if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
-        sp_document_resized_signal_emit (SP_OBJECT_DOCUMENT(root), root->width.computed, root->height.computed);
+        SP_OBJECT_DOCUMENT(root)->emitResizedSignal(root->width.computed, root->height.computed);
     }
 }
 
@@ -590,11 +584,12 @@ sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:
     }
 
     if (flags & SP_OBJECT_WRITE_EXT) {
-        repr->setAttribute("sodipodi:version", SODIPODI_VERSION);
-        repr->setAttribute("inkscape:version", INKSCAPE_VERSION);
+        repr->setAttribute("inkscape:version", Inkscape::version_string);
     }
 
-    repr->setAttribute("version", SVG_VERSION);
+    if ( !repr->attribute("version") ) {
+        repr->setAttribute("version", sp_version_to_string(root->version.svg));
+    }
 
     if (fabs(root->x.computed) > 1e-9)
         sp_repr_set_svg_double(repr, "x", root->x.computed);
@@ -640,22 +635,6 @@ sp_root_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags)
     return ai;
 }
 
-/**
- * Virtual bbox callback.
- */
-static void
-sp_root_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags)
-{
-    SPRoot const *root = SP_ROOT(item);
-
-    if (((SPItemClass *) (parent_class))->bbox) {
-        Geom::Matrix const product( to_2geom(root->c2p) * transform );
-        ((SPItemClass *) (parent_class))->bbox(item, bbox,
-                                               product,
-                                               flags);
-    }
-}
-
 /**
  * Virtual print callback.
  */
@@ -683,4 +662,4 @@ sp_root_print(SPItem *item, SPPrintContext *ctx)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :