summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2014-01-22 22:58:40 +0000
committerMartin Owens <doctormo@gmail.com>2014-01-22 22:58:40 +0000
commit423ea7c0373e77a83c8a9ef62df9a786b4feb7ac (patch)
tree148e75843778f8b96619d73b7242d880682bd134
parentProtect against infinate looping of new included hrefs (diff)
downloadinkscape-423ea7c0373e77a83c8a9ef62df9a786b4feb7ac.tar.gz
inkscape-423ea7c0373e77a83c8a9ef62df9a786b4feb7ac.zip
Move sub-document reference creation code from uri-reference to document.cpp as createChildDoc(path)
(bzr r12971)
-rw-r--r--src/document.cpp47
-rw-r--r--src/document.h10
-rw-r--r--src/uri-references.cpp37
3 files changed, 51 insertions, 43 deletions
diff --git a/src/document.cpp b/src/document.cpp
index 90f35307d..f5c799575 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -106,10 +106,10 @@ SPDocument::SPDocument() :
profileManager(0), // deferred until after other initialization
router(new Avoid::Router(Avoid::PolyLineRouting|Avoid::OrthogonalRouting)),
_collection_queue(0),
- parent_document(NULL),
oldSignalsConnected(false),
current_persp3d(NULL),
- current_persp3d_impl(NULL)
+ current_persp3d_impl(NULL),
+ _parent_document(NULL)
{
// Penalise libavoid for choosing paths with needless extra segments.
// This results in much better looking orthogonal connector paths.
@@ -327,7 +327,10 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc,
document->rdoc = rdoc;
document->rroot = rroot;
- document->parent_document = parent;
+ if (parent) {
+ document->_parent_document = parent;
+ parent->_child_documents.push_back(document);
+ }
if (document->uri){
g_free(document->uri);
@@ -473,6 +476,43 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc,
}
/**
+ * Fetches a document and attaches it to the current document as a child href
+ */
+SPDocument *SPDocument::createChildDoc(gchar const *uri) {
+
+ // Calculate the absolute path from an available document
+ std::string basePath = std::string( this->getBase() );
+ std::string absPath = Glib::build_filename(basePath, std::string( uri ) );
+ const char *path = absPath.c_str();
+
+ SPDocument *parent = this;
+ SPDocument *document = NULL;
+
+ while(parent != NULL && document == NULL) {
+ // Check myself and any parents int he chain
+ if(strcmp(parent->getURI(), path)==0) {
+ document = parent;
+ break;
+ }
+ // Then check children of those.
+ boost::ptr_list<SPDocument>::iterator iter;
+ for (iter = parent->_child_documents.begin();
+ iter != parent->_child_documents.end(); ++iter) {
+ if(strcmp(iter->getURI(), path)==0) {
+ document = &*iter;
+ break;
+ }
+ }
+ parent = parent->_parent_document;
+ }
+
+ // Load a fresh document from the svg source.
+ if(!document) {
+ document = createNewDoc(path, false, false, this);
+ }
+ return document;
+}
+/**
* Fetches document from URI, or creates new, if NULL; public document
* appears in document list.
*/
@@ -605,6 +645,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
root->updateRepr();
}
+
Inkscape::Util::Quantity SPDocument::getHeight() const
{
g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
diff --git a/src/document.h b/src/document.h
index 06b2b5f6e..79381e0c2 100644
--- a/src/document.h
+++ b/src/document.h
@@ -121,10 +121,6 @@ public:
GSList *_collection_queue;
- // A list of svg documents being used or shown within this document
- boost::ptr_list<SPDocument> child_documents;
- SPDocument *parent_document;
-
bool oldSignalsConnected;
/** Returns our SPRoot */
@@ -207,6 +203,11 @@ private:
Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */
Persp3DImpl *current_persp3d_impl;
+ // A list of svg documents being used or shown within this document
+ boost::ptr_list<SPDocument> _child_documents;
+ // Conversely this is a parent document because this is a child.
+ SPDocument *_parent_document;
+
public:
sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
@@ -224,6 +225,7 @@ public:
static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive,
bool make_new = false, SPDocument *parent=NULL );
static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive);
+ SPDocument *createChildDoc(gchar const *uri);
/**
* Returns the bottommost item from the list which is at the point, or NULL if none.
diff --git a/src/uri-references.cpp b/src/uri-references.cpp
index 30e832c04..1684c6ade 100644
--- a/src/uri-references.cpp
+++ b/src/uri-references.cpp
@@ -59,42 +59,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException)
// The path contains references to seperate document files to load.
const char *path = uri.getPath();
if(path && document != NULL) {
- // Calculate the absolute path from an available document
- std::string basePath = std::string( document->getBase() );
- std::string absPath = Glib::build_filename(basePath, std::string( path ) );
- path = absPath.c_str();
-
- SPDocument *parent = document;
- SPDocument *original = document;
- document = NULL;
-
- while(parent != NULL && document == NULL) {
- // Check myself and any parents int he chain
- if(strcmp(parent->getURI(), path)==0) {
- document = parent;
- break;
- }
- // Then check children of those.
- boost::ptr_list<SPDocument>::iterator iter;
- for (iter = parent->child_documents.begin();
- iter != parent->child_documents.end(); ++iter) {
- if(strcmp(iter->getURI(), path)==0) {
- document = &*iter;
- break;
- }
- }
- parent = parent->parent_document;
- }
-
- // Load a fresh document from the svg source.
- if(!document) {
- document = SPDocument::createNewDoc(path, false, false, original);
- if(document) {
- original->child_documents.push_back(document);
- } else {
- g_warning("Could not load svg file: %s", path);
- }
- }
+ document = document->createChildDoc(path);
}
g_return_if_fail(document != NULL);