1 /*
2 * Inkscape::XML::SimpleDocument - generic XML document implementation
3 *
4 * Copyright 2004-2005 MenTaLguY <mental@rydia.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #include <glib.h> // g_assert()
17 #include "xml/simple-document.h"
18 #include "xml/event-fns.h"
19 #include "xml/element-node.h"
20 #include "xml/text-node.h"
21 #include "xml/comment-node.h"
22 #include "xml/pi-node.h"
24 namespace Inkscape {
26 namespace XML {
28 void SimpleDocument::_initBindings() {
29 _bindDocument(*this);
30 }
32 void SimpleDocument::beginTransaction() {
33 g_assert(!_in_transaction);
34 _in_transaction = true;
35 }
37 void SimpleDocument::rollback() {
38 g_assert(_in_transaction);
39 _in_transaction = false;
40 Event *log = _log_builder.detach();
41 sp_repr_undo_log(log);
42 sp_repr_free_log(log);
43 }
45 void SimpleDocument::commit() {
46 g_assert(_in_transaction);
47 _in_transaction = false;
48 _log_builder.discard();
49 }
51 Inkscape::XML::Event *SimpleDocument::commitUndoable() {
52 g_assert(_in_transaction);
53 _in_transaction = false;
54 return _log_builder.detach();
55 }
57 Node *SimpleDocument::createElement(char const *name) {
58 return new ElementNode(g_quark_from_string(name), this);
59 }
61 Node *SimpleDocument::createTextNode(char const *content) {
62 return new TextNode(Util::share_string(content), this);
63 }
65 Node *SimpleDocument::createComment(char const *content) {
66 return new CommentNode(Util::share_string(content), this);
67 }
69 Node *SimpleDocument::createPI(char const *target, char const *content) {
70 return new PINode(g_quark_from_string(target), Util::share_string(content), this);
71 }
73 void SimpleDocument::notifyChildAdded(Node &parent,
74 Node &child,
75 Node *prev)
76 {
77 if (_in_transaction) {
78 _log_builder.addChild(parent, child, prev);
79 }
80 }
82 void SimpleDocument::notifyChildRemoved(Node &parent,
83 Node &child,
84 Node *prev)
85 {
86 if (_in_transaction) {
87 _log_builder.removeChild(parent, child, prev);
88 }
89 }
91 void SimpleDocument::notifyChildOrderChanged(Node &parent,
92 Node &child,
93 Node *old_prev,
94 Node *new_prev)
95 {
96 if (_in_transaction) {
97 _log_builder.setChildOrder(parent, child, old_prev, new_prev);
98 }
99 }
101 void SimpleDocument::notifyContentChanged(Node &node,
102 Util::ptr_shared<char> old_content,
103 Util::ptr_shared<char> new_content)
104 {
105 if (_in_transaction) {
106 _log_builder.setContent(node, old_content, new_content);
107 }
108 }
110 void SimpleDocument::notifyAttributeChanged(Node &node,
111 GQuark name,
112 Util::ptr_shared<char> old_value,
113 Util::ptr_shared<char> new_value)
114 {
115 if (_in_transaction) {
116 _log_builder.setAttribute(node, name, old_value, new_value);
117 }
118 }
120 }
122 }
124 /*
125 Local Variables:
126 mode:c++
127 c-file-style:"stroustrup"
128 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
129 indent-tabs-mode:nil
130 fill-column:99
131 End:
132 */
133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :