Code

4063abde4be867cb0cdc662a362ecddec4273601
[inkscape.git] / src / xml / simple-document.cpp
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 "xml/simple-document.h"
16 #include "xml/event-fns.h"
17 #include "xml/element-node.h"
18 #include "xml/text-node.h"
19 #include "xml/comment-node.h"
21 namespace Inkscape {
23 namespace XML {
25 void SimpleDocument::_initBindings() {
26     _bindDocument(*this);
27 }
29 void SimpleDocument::beginTransaction() {
30     g_assert(!_in_transaction);
31     _in_transaction = true;
32 }
34 void SimpleDocument::rollback() {
35     g_assert(_in_transaction);
36     _in_transaction = false;
37     Event *log = _log_builder.detach();
38     sp_repr_undo_log(log);
39     sp_repr_free_log(log);
40 }
42 void SimpleDocument::commit() {
43     g_assert(_in_transaction);
44     _in_transaction = false;
45     _log_builder.discard();
46 }
48 Inkscape::XML::Event *SimpleDocument::commitUndoable() {
49     g_assert(_in_transaction);
50     _in_transaction = false;
51     return _log_builder.detach();
52 }
54 Node *SimpleDocument::createElement(char const *name) {
55     return new ElementNode(g_quark_from_string(name));
56 }
58 Node *SimpleDocument::createTextNode(char const *content) {
59     return new TextNode(Util::share_string(content));
60 }
62 Node *SimpleDocument::createComment(char const *content) {
63     return new CommentNode(Util::share_string(content));
64 }
66 void SimpleDocument::notifyChildAdded(Node &parent,
67                                       Node &child,
68                                       Node *prev)
69 {
70     if (_in_transaction) {
71         _log_builder.addChild(parent, child, prev);
72     }
73 }
75 void SimpleDocument::notifyChildRemoved(Node &parent,
76                                         Node &child,
77                                         Node *prev)
78 {
79     if (_in_transaction) {
80         _log_builder.removeChild(parent, child, prev);
81     }
82 }
84 void SimpleDocument::notifyChildOrderChanged(Node &parent,
85                                              Node &child,
86                                              Node *old_prev,
87                                              Node *new_prev)
88 {
89     if (_in_transaction) {
90         _log_builder.setChildOrder(parent, child, old_prev, new_prev);
91     }
92 }
94 void SimpleDocument::notifyContentChanged(Node &node,
95                                           Util::ptr_shared<char> old_content,
96                                           Util::ptr_shared<char> new_content)
97 {
98     if (_in_transaction) {
99         _log_builder.setContent(node, old_content, new_content);
100     }
103 void SimpleDocument::notifyAttributeChanged(Node &node,
104                                             GQuark name,
105                                             Util::ptr_shared<char> old_value,
106                                             Util::ptr_shared<char> new_value)
108     if (_in_transaction) {
109         _log_builder.setAttribute(node, name, old_value, new_value);
110     }
117 /*
118   Local Variables:
119   mode:c++
120   c-file-style:"stroustrup"
121   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
122   indent-tabs-mode:nil
123   fill-column:99
124   End:
125 */
126 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :