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::beginTransaction() {
29 g_assert(!_in_transaction);
30 _in_transaction = true;
31 }
33 void SimpleDocument::rollback() {
34 g_assert(_in_transaction);
35 _in_transaction = false;
36 Event *log = _log_builder.detach();
37 sp_repr_undo_log(log);
38 sp_repr_free_log(log);
39 }
41 void SimpleDocument::commit() {
42 g_assert(_in_transaction);
43 _in_transaction = false;
44 _log_builder.discard();
45 }
47 Inkscape::XML::Event *SimpleDocument::commitUndoable() {
48 g_assert(_in_transaction);
49 _in_transaction = false;
50 return _log_builder.detach();
51 }
53 Node *SimpleDocument::createElement(char const *name) {
54 return new ElementNode(g_quark_from_string(name), this);
55 }
57 Node *SimpleDocument::createTextNode(char const *content) {
58 return new TextNode(Util::share_string(content), this);
59 }
61 Node *SimpleDocument::createComment(char const *content) {
62 return new CommentNode(Util::share_string(content), this);
63 }
65 Node *SimpleDocument::createPI(char const *target, char const *content) {
66 return new PINode(g_quark_from_string(target), Util::share_string(content), this);
67 }
69 void SimpleDocument::notifyChildAdded(Node &parent,
70 Node &child,
71 Node *prev)
72 {
73 if (_in_transaction) {
74 _log_builder.addChild(parent, child, prev);
75 }
76 }
78 void SimpleDocument::notifyChildRemoved(Node &parent,
79 Node &child,
80 Node *prev)
81 {
82 if (_in_transaction) {
83 _log_builder.removeChild(parent, child, prev);
84 }
85 }
87 void SimpleDocument::notifyChildOrderChanged(Node &parent,
88 Node &child,
89 Node *old_prev,
90 Node *new_prev)
91 {
92 if (_in_transaction) {
93 _log_builder.setChildOrder(parent, child, old_prev, new_prev);
94 }
95 }
97 void SimpleDocument::notifyContentChanged(Node &node,
98 Util::ptr_shared<char> old_content,
99 Util::ptr_shared<char> new_content)
100 {
101 if (_in_transaction) {
102 _log_builder.setContent(node, old_content, new_content);
103 }
104 }
106 void SimpleDocument::notifyAttributeChanged(Node &node,
107 GQuark name,
108 Util::ptr_shared<char> old_value,
109 Util::ptr_shared<char> new_value)
110 {
111 if (_in_transaction) {
112 _log_builder.setAttribute(node, name, old_value, new_value);
113 }
114 }
116 }
118 }
120 /*
121 Local Variables:
122 mode:c++
123 c-file-style:"stroustrup"
124 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
125 indent-tabs-mode:nil
126 fill-column:99
127 End:
128 */
129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :