1 /*
2 * The reference corresponding to href of <tref> element.
3 *
4 * Copyright (C) 2007 Gail Banaszkiewicz
5 *
6 * This file was created based on sp-use-reference.cpp
7 *
8 * Released under GNU GPL, read the file 'COPYING' for more information.
9 */
11 //#include "enums.h"
12 #include "sp-tref-reference.h"
14 #include "sp-text.h"
15 #include "sp-tref.h"
16 #include "sp-tspan.h"
20 bool SPTRefReference::_acceptObject(SPObject * const obj) const
21 {
22 SPObject *owner = getOwner();
23 if (SP_IS_TREF(owner))
24 return sp_tref_reference_allowed(SP_TREF(getOwner()), obj);
25 else
26 return false;
27 }
30 void SPTRefReference::updateObserver()
31 {
32 SPObject *referred = getObject();
34 if (referred) {
35 if (subtreeObserved) {
36 subtreeObserved->removeObserver(*this);
37 delete subtreeObserved;
38 }
40 subtreeObserved = new Inkscape::XML::Subtree(*SP_OBJECT_REPR(referred));
41 subtreeObserved->addObserver(*this);
42 }
43 }
46 void SPTRefReference::notifyChildAdded(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
47 Inkscape::XML::Node */*prev*/)
48 {
49 SPObject *owner = getOwner();
51 if (owner && SP_IS_TREF(owner)) {
52 sp_tref_update_text(SP_TREF(owner));
53 }
54 }
57 void SPTRefReference::notifyChildRemoved(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
58 Inkscape::XML::Node */*prev*/)
59 {
60 SPObject *owner = getOwner();
62 if (owner && SP_IS_TREF(owner)) {
63 sp_tref_update_text(SP_TREF(owner));
64 }
65 }
68 void SPTRefReference::notifyChildOrderChanged(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
69 Inkscape::XML::Node */*old_prev*/, Inkscape::XML::Node */*new_prev*/)
70 {
71 SPObject *owner = getOwner();
73 if (owner && SP_IS_TREF(owner)) {
74 sp_tref_update_text(SP_TREF(owner));
75 }
76 }
79 void SPTRefReference::notifyContentChanged(Inkscape::XML::Node &/*node*/,
80 Inkscape::Util::ptr_shared<char> /*old_content*/,
81 Inkscape::Util::ptr_shared<char> /*new_content*/)
82 {
83 SPObject *owner = getOwner();
85 if (owner && SP_IS_TREF(owner)) {
86 sp_tref_update_text(SP_TREF(owner));
87 }
88 }
91 void SPTRefReference::notifyAttributeChanged(Inkscape::XML::Node &/*node*/, GQuark /*name*/,
92 Inkscape::Util::ptr_shared<char> /*old_value*/,
93 Inkscape::Util::ptr_shared<char> /*new_value*/)
94 {
95 // Do nothing - tref only cares about textual content
96 }
99 /*
100 Local Variables:
101 mode:c++
102 c-file-style:"stroustrup"
103 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
104 indent-tabs-mode:nil
105 fill-column:99
106 End:
107 */
108 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :