summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2008-03-07 22:18:56 +0000
committermental <mental@users.sourceforge.net>2008-03-07 22:18:56 +0000
commit31acc450aa0320ab82f5075adf8afbcae0763e6d (patch)
treeef45a9eeb5a7baa754176307396a2837bca879e0 /src
parentFix #include (diff)
downloadinkscape-31acc450aa0320ab82f5075adf8afbcae0763e6d.tar.gz
inkscape-31acc450aa0320ab82f5075adf8afbcae0763e6d.zip
add basic support for preserving processing instructions in the AST
(bzr r4987)
Diffstat (limited to 'src')
-rw-r--r--src/dialogs/xml-tree.cpp4
-rw-r--r--src/jabber_whiteboard/inkboard-document.cpp8
-rw-r--r--src/jabber_whiteboard/inkboard-document.h1
-rw-r--r--src/widgets/sp-xmlview-tree.cpp25
-rw-r--r--src/xml/Makefile_insert1
-rw-r--r--src/xml/document.h1
-rw-r--r--src/xml/node.h3
-rw-r--r--src/xml/pi-node.h52
-rw-r--r--src/xml/repr-io.cpp13
-rw-r--r--src/xml/simple-document.cpp5
-rw-r--r--src/xml/simple-document.h1
11 files changed, 107 insertions, 7 deletions
diff --git a/src/dialogs/xml-tree.cpp b/src/dialogs/xml-tree.cpp
index 6da0096e2..a9db979d6 100644
--- a/src/dialogs/xml-tree.cpp
+++ b/src/dialogs/xml-tree.cpp
@@ -772,7 +772,7 @@ void propagate_tree_select(Inkscape::XML::Node *repr)
sp_xmlview_attr_list_set_repr(attributes, NULL);
}
- if (repr && ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE ) ) {
+ if (repr && ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE || repr->type() == Inkscape::XML::PI_NODE ) ) {
sp_xmlview_content_set_repr(content, repr);
} else {
sp_xmlview_content_set_repr(content, NULL);
@@ -986,7 +986,7 @@ void on_tree_select_row_show_if_text(GtkCTree *tree, GtkCTreeNode *node,
{
Inkscape::XML::Node *repr = sp_xmlview_tree_node_get_repr(SP_XMLVIEW_TREE(tree), node);
- if ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE ) {
+ if ( repr->type() == Inkscape::XML::TEXT_NODE || repr->type() == Inkscape::XML::COMMENT_NODE || repr->type() == Inkscape::XML::PI_NODE ) {
gtk_widget_show(GTK_WIDGET(data));
} else {
gtk_widget_hide(GTK_WIDGET(data));
diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp
index 9f3d8ce42..36295dd28 100644
--- a/src/jabber_whiteboard/inkboard-document.cpp
+++ b/src/jabber_whiteboard/inkboard-document.cpp
@@ -33,6 +33,7 @@
#include "xml/element-node.h"
#include "xml/text-node.h"
#include "xml/comment-node.h"
+#include "xml/pi-node.h"
#include "util/share.h"
#include "util/ucompose.hpp"
@@ -362,6 +363,13 @@ InkboardDocument::createComment(char const* content)
return new XML::CommentNode(Util::share_string(content));
}
+XML::Node*
+InkboardDocument::createPI(char const *target, char const* content)
+{
+ return new XML::PINode(g_quark_from_string(target), Util::share_string(content));
+}
+
+
void InkboardDocument::notifyChildAdded(XML::Node &parent,
XML::Node &child,
diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h
index 26d79396e..23ce9f3b9 100644
--- a/src/jabber_whiteboard/inkboard-document.h
+++ b/src/jabber_whiteboard/inkboard-document.h
@@ -84,6 +84,7 @@ public:
XML::Node* createElement(char const* name);
XML::Node* createTextNode(char const* content);
XML::Node* createComment(char const* content);
+ XML::Node* createPI(char const *target, char const* content);
//
// XML::NodeObserver methods
diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp
index ee5ca1823..b2d1a2531 100644
--- a/src/widgets/sp-xmlview-tree.cpp
+++ b/src/widgets/sp-xmlview-tree.cpp
@@ -41,6 +41,7 @@ static void element_order_changed (Inkscape::XML::Node * repr, Inkscape::XML::No
static void text_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
static void comment_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
+static void pi_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
static void tree_move (GtkCTree * tree, GtkCTreeNode * node, GtkCTreeNode * new_parent, GtkCTreeNode * new_sibling);
@@ -76,6 +77,14 @@ static const Inkscape::XML::NodeEventVector comment_repr_events = {
NULL /* order_changed */
};
+static const Inkscape::XML::NodeEventVector pi_repr_events = {
+ NULL, /* child_added */
+ NULL, /* child_removed */
+ NULL, /* attr_changed */
+ pi_content_changed,
+ NULL /* order_changed */
+};
+
static GtkCTreeClass * parent_class = NULL;
GtkWidget *
@@ -191,6 +200,8 @@ add_node (SPXMLViewTree * tree, GtkCTreeNode * parent, GtkCTreeNode * before, In
vec = &text_repr_events;
} else if ( repr->type() == Inkscape::XML::COMMENT_NODE ) {
vec = &comment_repr_events;
+ } else if ( repr->type() == Inkscape::XML::PI_NODE ) {
+ vec = &pi_repr_events;
} else if ( repr->type() == Inkscape::XML::ELEMENT_NODE ) {
vec = &element_repr_events;
} else {
@@ -330,6 +341,20 @@ comment_content_changed (Inkscape::XML::Node *repr, const gchar * old_content, c
}
void
+pi_content_changed(Inkscape::XML::Node *repr, const gchar * old_content, const gchar *new_content, gpointer ptr)
+{
+ NodeData *data;
+ gchar *label;
+
+ data = (NodeData *) ptr;
+
+ if (data->tree->blocked) return;
+
+ label = g_strdup_printf ("<?%s %s?>", repr->name(), new_content);
+ gtk_ctree_node_set_text (GTK_CTREE (data->tree), data->node, 0, label);
+ g_free (label);
+}
+void
tree_move (GtkCTree * tree, GtkCTreeNode * node, GtkCTreeNode * new_parent, GtkCTreeNode * new_sibling)
{
GtkCTreeNode * old_parent;
diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert
index 0a95a2062..ac7b03751 100644
--- a/src/xml/Makefile_insert
+++ b/src/xml/Makefile_insert
@@ -26,6 +26,7 @@ xml_libspxml_a_SOURCES = \
xml/log-builder.h \
xml/node-fns.cpp \
xml/node-fns.h \
+ xml/pi-node.h \
xml/repr-io.cpp \
xml/repr-sorting.cpp \
xml/repr-sorting.h \
diff --git a/src/xml/document.h b/src/xml/document.h
index de9164aa2..5065092d0 100644
--- a/src/xml/document.h
+++ b/src/xml/document.h
@@ -37,6 +37,7 @@ public:
virtual Node *createElement(char const *name)=0;
virtual Node *createTextNode(char const *content)=0;
virtual Node *createComment(char const *content)=0;
+ virtual Node *createPI(char const *target, char const *content)=0;
};
}
diff --git a/src/xml/node.h b/src/xml/node.h
index 997f3ccda..ab7e2ba2f 100644
--- a/src/xml/node.h
+++ b/src/xml/node.h
@@ -31,7 +31,8 @@ enum NodeType {
DOCUMENT_NODE,
ELEMENT_NODE,
TEXT_NODE,
- COMMENT_NODE
+ COMMENT_NODE,
+ PI_NODE
};
// careful; GC::Anchored should only appear once in the inheritance
diff --git a/src/xml/pi-node.h b/src/xml/pi-node.h
new file mode 100644
index 000000000..c3f84b636
--- /dev/null
+++ b/src/xml/pi-node.h
@@ -0,0 +1,52 @@
+/*
+ * Inkscape::XML::PINode - simple XML comment implementation
+ *
+ * Copyright 2004-2005 MenTaLguY <mental@rydia.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * See the file COPYING for details.
+ *
+ */
+
+#ifndef SEEN_INKSCAPE_XML_PI_NODE_H
+#define SEEN_INKSCAPE_XML_PI_NODE_H
+
+#include <glib/gquark.h>
+#include "xml/simple-node.h"
+
+namespace Inkscape {
+
+namespace XML {
+
+struct PINode : public SimpleNode {
+ explicit PINode(GQuark target, Util::ptr_shared<char> content)
+ : SimpleNode(target)
+ {
+ setContent(content);
+ }
+
+ Inkscape::XML::NodeType type() const { return Inkscape::XML::PI_NODE; }
+
+protected:
+ SimpleNode *_duplicate(Document* doc) const { return new PINode(*this); }
+};
+
+}
+
+}
+
+#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp
index 28e7c4f21..26537d750 100644
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
@@ -395,10 +395,10 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns)
root = NULL;
break;
}
- } else if ( node->type == XML_COMMENT_NODE ) {
- Node *comment=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
- rdoc->appendChild(comment);
- Inkscape::GC::release(comment);
+ } else if ( node->type == XML_COMMENT_NODE || node->type == XML_PI_NODE ) {
+ Node *repr=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+ rdoc->appendChild(repr);
+ Inkscape::GC::release(repr);
}
}
@@ -463,6 +463,9 @@ sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_
if (node->type == XML_COMMENT_NODE)
return xml_doc->createComment((const gchar *)node->content);
+ if (node->type == XML_PI_NODE)
+ return xml_doc->createPI((const gchar *)node->name, (const gchar *)node->content);
+
if (node->type == XML_ENTITY_DECL) return NULL;
sp_repr_qualified_name (c, 256, node->ns, node->name, default_ns, prefix_map);
@@ -717,6 +720,8 @@ sp_repr_write_stream (Node *repr, Writer &out, gint indent_level,
repr_quote_write (out, repr->content());
} else if (repr->type() == Inkscape::XML::COMMENT_NODE) {
out.printf( "<!--%s-->", repr->content() );
+ } else if (repr->type() == Inkscape::XML::PI_NODE) {
+ out.printf( "<?%s %s?>", repr->name(), repr->content() );
} else if (repr->type() == Inkscape::XML::ELEMENT_NODE) {
sp_repr_write_stream_element(repr, out, indent_level, add_whitespace, elide_prefix, repr->attributeList(), inlineattrs, indent);
} else {
diff --git a/src/xml/simple-document.cpp b/src/xml/simple-document.cpp
index 30e74a455..d0aa31939 100644
--- a/src/xml/simple-document.cpp
+++ b/src/xml/simple-document.cpp
@@ -19,6 +19,7 @@
#include "xml/element-node.h"
#include "xml/text-node.h"
#include "xml/comment-node.h"
+#include "xml/pi-node.h"
namespace Inkscape {
@@ -65,6 +66,10 @@ Node *SimpleDocument::createComment(char const *content) {
return new CommentNode(Util::share_string(content));
}
+Node *SimpleDocument::createPI(char const *target, char const *content) {
+ return new PINode(g_quark_from_string(target), Util::share_string(content));
+}
+
void SimpleDocument::notifyChildAdded(Node &parent,
Node &child,
Node *prev)
diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h
index 17e283f2a..cadda36cb 100644
--- a/src/xml/simple-document.h
+++ b/src/xml/simple-document.h
@@ -49,6 +49,7 @@ public:
Node *createElement(char const *name);
Node *createTextNode(char const *content);
Node *createComment(char const *content);
+ Node *createPI(char const *target, char const *content);
void notifyChildAdded(Node &parent, Node &child, Node *prev);