From 1d292290278c99756affd4d351fa7b9baea2c49c Mon Sep 17 00:00:00 2001 From: mental Date: Sun, 8 Jun 2008 19:44:26 +0000 Subject: [PATCH] plumb document references a little deeper in --- src/jabber_whiteboard/inkboard-document.cpp | 10 +++++----- src/jabber_whiteboard/inkboard-node.cpp | 4 ++-- src/xml/comment-node.h | 9 ++++++--- src/xml/element-node.h | 8 +++++--- src/xml/pi-node.h | 8 +++++--- src/xml/repr-css.cpp | 15 ++++++++++++--- src/xml/simple-document.cpp | 8 ++++---- src/xml/simple-document.h | 3 ++- src/xml/simple-node.cpp | 11 +++++------ src/xml/simple-node.h | 4 ++-- src/xml/text-node.h | 8 +++++--- 11 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index dd039ab6f..7e4afff8d 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -44,7 +44,7 @@ namespace Whiteboard { InkboardDocument::InkboardDocument(int code, State::SessionType sessionType, Glib::ustring const& to) -: XML::SimpleNode(code), sessionType(sessionType), recipient(to), +: XML::SimpleNode(code, NULL), sessionType(sessionType), recipient(to), _in_transaction(false) { _initBindings(); @@ -348,25 +348,25 @@ InkboardDocument::commitUndoable() XML::Node* InkboardDocument::createElement(char const* name) { - return new XML::ElementNode(g_quark_from_string(name)); + return new XML::ElementNode(g_quark_from_string(name), this); } XML::Node* InkboardDocument::createTextNode(char const* content) { - return new XML::TextNode(Util::share_string(content)); + return new XML::TextNode(Util::share_string(content), this); } XML::Node* InkboardDocument::createComment(char const* content) { - return new XML::CommentNode(Util::share_string(content)); + return new XML::CommentNode(Util::share_string(content), this); } XML::Node* InkboardDocument::createPI(char const *target, char const* content) { - return new XML::PINode(g_quark_from_string(target), Util::share_string(content)); + return new XML::PINode(g_quark_from_string(target), Util::share_string(content), this); } diff --git a/src/jabber_whiteboard/inkboard-node.cpp b/src/jabber_whiteboard/inkboard-node.cpp index d3d568551..e6eee7304 100644 --- a/src/jabber_whiteboard/inkboard-node.cpp +++ b/src/jabber_whiteboard/inkboard-node.cpp @@ -104,7 +104,7 @@ InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id, if(name == "text") { XML::Node *parent = this->tracker->get(parentid); - XML::Node *node = new XML::TextNode(Util::share_string(data->getValue().c_str())); + XML::Node *node = new XML::TextNode(Util::share_string(data->getValue().c_str()), this); if(parent && node) { @@ -113,7 +113,7 @@ InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id, } }else { - XML::Node *node = new XML::ElementNode(g_quark_from_string(name.c_str())); + XML::Node *node = new XML::ElementNode(g_quark_from_string(name.c_str()), this); this->tracker->put(id,node); XML::Node *parent = (parentid != "ROOT") diff --git a/src/xml/comment-node.h b/src/xml/comment-node.h index 4be09ec85..5cff9caf6 100644 --- a/src/xml/comment-node.h +++ b/src/xml/comment-node.h @@ -23,16 +23,19 @@ namespace Inkscape { namespace XML { struct CommentNode : public SimpleNode { - explicit CommentNode(Util::ptr_shared content) - : SimpleNode(g_quark_from_static_string("comment")) + CommentNode(Util::ptr_shared content, Document *doc) + : SimpleNode(g_quark_from_static_string("comment"), doc) { setContent(content); } + CommentNode(CommentNode const &other, Document *doc) + : SimpleNode(other, doc) {} + Inkscape::XML::NodeType type() const { return Inkscape::XML::COMMENT_NODE; } protected: - SimpleNode *_duplicate(Document* /*doc*/) const { return new CommentNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new CommentNode(*this, doc); } }; } diff --git a/src/xml/element-node.h b/src/xml/element-node.h index 1b79910a8..11bc8e03a 100644 --- a/src/xml/element-node.h +++ b/src/xml/element-node.h @@ -23,13 +23,15 @@ namespace XML { class ElementNode : public SimpleNode { public: - explicit ElementNode(int code) - : SimpleNode(code) {} + ElementNode(int code, Document *doc) + : SimpleNode(code, doc) {} + ElementNode(ElementNode const &other, Document *doc) + : SimpleNode(other, doc) {} Inkscape::XML::NodeType type() const { return Inkscape::XML::ELEMENT_NODE; } protected: - SimpleNode *_duplicate(Document* /*doc*/) const { return new ElementNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new ElementNode(*this, doc); } }; } diff --git a/src/xml/pi-node.h b/src/xml/pi-node.h index b89ef25a0..502c5cd71 100644 --- a/src/xml/pi-node.h +++ b/src/xml/pi-node.h @@ -23,16 +23,18 @@ namespace Inkscape { namespace XML { struct PINode : public SimpleNode { - explicit PINode(GQuark target, Util::ptr_shared content) - : SimpleNode(target) + PINode(GQuark target, Util::ptr_shared content, Document *doc) + : SimpleNode(target, doc) { setContent(content); } + PINode(PINode const &other, Document *doc) + : SimpleNode(other, doc) {} Inkscape::XML::NodeType type() const { return Inkscape::XML::PI_NODE; } protected: - SimpleNode *_duplicate(Document* /*doc*/) const { return new PINode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new PINode(*this, doc); } }; } diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 888250c40..be125f453 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -8,6 +8,7 @@ #include #include "xml/repr.h" +#include "xml/simple-document.h" #include "xml/simple-node.h" #include "style.h" #include "libcroco/cr-sel-eng.h" @@ -21,20 +22,28 @@ using Inkscape::XML::Document; struct SPCSSAttrImpl : public SimpleNode, public SPCSSAttr { public: - SPCSSAttrImpl() : SimpleNode(g_quark_from_static_string("css")) {} + SPCSSAttrImpl(Document *doc) + : SimpleNode(g_quark_from_static_string("css"), doc) {} + SPCSSAttrImpl(SPCSSAttrImpl const &other, Document *doc) + : SimpleNode(other, doc) {} NodeType type() const { return Inkscape::XML::ELEMENT_NODE; } protected: - SimpleNode *_duplicate(Document* /*doc*/) const { return new SPCSSAttrImpl(*this); } + SimpleNode *_duplicate(Document* doc) const { return new SPCSSAttrImpl(*this, doc); } }; static void sp_repr_css_add_components(SPCSSAttr *css, Node *repr, gchar const *attr); + SPCSSAttr * sp_repr_css_attr_new() { - return new SPCSSAttrImpl(); + static Inkscape::XML::Document *attr_doc=NULL; + if (!attr_doc) { + attr_doc = new Inkscape::XML::SimpleDocument(); + } + return new SPCSSAttrImpl(attr_doc); } void diff --git a/src/xml/simple-document.cpp b/src/xml/simple-document.cpp index d0aa31939..0a2cb15fb 100644 --- a/src/xml/simple-document.cpp +++ b/src/xml/simple-document.cpp @@ -55,19 +55,19 @@ Inkscape::XML::Event *SimpleDocument::commitUndoable() { } Node *SimpleDocument::createElement(char const *name) { - return new ElementNode(g_quark_from_string(name)); + return new ElementNode(g_quark_from_string(name), this); } Node *SimpleDocument::createTextNode(char const *content) { - return new TextNode(Util::share_string(content)); + return new TextNode(Util::share_string(content), this); } Node *SimpleDocument::createComment(char const *content) { - return new CommentNode(Util::share_string(content)); + return new CommentNode(Util::share_string(content), this); } Node *SimpleDocument::createPI(char const *target, char const *content) { - return new PINode(g_quark_from_string(target), Util::share_string(content)); + return new PINode(g_quark_from_string(target), Util::share_string(content), this); } void SimpleDocument::notifyChildAdded(Node &parent, diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h index cadda36cb..9b3157add 100644 --- a/src/xml/simple-document.h +++ b/src/xml/simple-document.h @@ -30,7 +30,8 @@ class SimpleDocument : public SimpleNode, { public: explicit SimpleDocument() - : SimpleNode(g_quark_from_static_string("xml")), _in_transaction(false) + : SimpleNode(g_quark_from_static_string("xml"), NULL), + _in_transaction(false) { _initBindings(); } diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index 084547a59..8ddc5b167 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -160,33 +160,32 @@ using Util::cons; using Util::rest; using Util::set_rest; -SimpleNode::SimpleNode(int code) +SimpleNode::SimpleNode(int code, Document *document) : Node(), _name(code), _attributes(), _child_count(0), _cached_positions_valid(false) { - this->_document = NULL; - this->_document = NULL; + this->_document = document; this->_parent = this->_next = NULL; this->_first_child = this->_last_child = NULL; _observers.add(_subtree_observers); } -SimpleNode::SimpleNode(SimpleNode const &node) +SimpleNode::SimpleNode(SimpleNode const &node, Document *document) : Node(), _cached_position(node._cached_position), _name(node._name), _attributes(), _content(node._content), _child_count(node._child_count), _cached_positions_valid(node._cached_positions_valid) { - _document = NULL; + _document = document; _parent = _next = NULL; _first_child = _last_child = NULL; for ( Node *child = node._first_child ; child != NULL ; child = child->next() ) { - Node *child_copy=child->duplicate(NULL); // FIXME + Node *child_copy=child->duplicate(document); child_copy->_setParent(this); if (_last_child) { diff --git a/src/xml/simple-node.h b/src/xml/simple-node.h index 60bb53454..7c5556f27 100644 --- a/src/xml/simple-node.h +++ b/src/xml/simple-node.h @@ -113,8 +113,8 @@ public: } protected: - SimpleNode(int code); - SimpleNode(SimpleNode const &repr); + SimpleNode(int code, Document *document); + SimpleNode(SimpleNode const &repr, Document *document); virtual SimpleNode *_duplicate(Document *doc) const=0; diff --git a/src/xml/text-node.h b/src/xml/text-node.h index adcacb604..8fb797276 100644 --- a/src/xml/text-node.h +++ b/src/xml/text-node.h @@ -23,16 +23,18 @@ namespace Inkscape { namespace XML { struct TextNode : public SimpleNode { - TextNode(Util::ptr_shared content) - : SimpleNode(g_quark_from_static_string("string")) + TextNode(Util::ptr_shared content, Document *doc) + : SimpleNode(g_quark_from_static_string("string"), doc) { setContent(content); } + TextNode(TextNode const &other, Document *doc) + : SimpleNode(other, doc) {} Inkscape::XML::NodeType type() const { return Inkscape::XML::TEXT_NODE; } protected: - SimpleNode *_duplicate(Document* /*doc*/) const { return new TextNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new TextNode(*this, doc); } }; } -- 2.30.2