summaryrefslogtreecommitdiffstats
path: root/src/object/sp-tref-reference.cpp
blob: 798e74ad86252140874c251d654d56a12f0ab50b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * The reference corresponding to href of <tref> element.
 *
 * Copyright (C) 2007 Gail Banaszkiewicz
 *
 * This file was created based on sp-use-reference.cpp
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

//#include "enums.h"
#include "sp-tref-reference.h"

#include "sp-text.h"
#include "sp-tref.h"


bool SPTRefReference::_acceptObject(SPObject * const obj) const
{
    SPObject *owner = getOwner();
    if (SP_IS_TREF(owner))
        return URIReference::_acceptObject(obj);
    else
        return false;
}


void SPTRefReference::updateObserver()
{
    SPObject *referred = getObject();

    if (referred) {
        if (subtreeObserved) {
            subtreeObserved->removeObserver(*this);
            delete subtreeObserved;
        }

        subtreeObserved = new Inkscape::XML::Subtree(*referred->getRepr());
        subtreeObserved->addObserver(*this);
    }
}


void SPTRefReference::notifyChildAdded(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
                                       Inkscape::XML::Node */*prev*/)
{
    SPObject *owner = getOwner();

    if (owner && SP_IS_TREF(owner)) {
        sp_tref_update_text(SP_TREF(owner));
    }
}


void SPTRefReference::notifyChildRemoved(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
                                         Inkscape::XML::Node */*prev*/)
{
    SPObject *owner = getOwner();

    if (owner && SP_IS_TREF(owner)) {
        sp_tref_update_text(SP_TREF(owner));
    }
}


void SPTRefReference::notifyChildOrderChanged(Inkscape::XML::Node &/*node*/, Inkscape::XML::Node &/*child*/,
                                              Inkscape::XML::Node */*old_prev*/, Inkscape::XML::Node */*new_prev*/)
{
    SPObject *owner = getOwner();

    if (owner && SP_IS_TREF(owner)) {
        sp_tref_update_text(SP_TREF(owner));
    }
}


void SPTRefReference::notifyContentChanged(Inkscape::XML::Node &/*node*/,
                                           Inkscape::Util::ptr_shared /*old_content*/,
                                           Inkscape::Util::ptr_shared /*new_content*/)
{
    SPObject *owner = getOwner();

    if (owner && SP_IS_TREF(owner)) {
        sp_tref_update_text(SP_TREF(owner));
    }
}


void SPTRefReference::notifyAttributeChanged(Inkscape::XML::Node &/*node*/, GQuark /*name*/,
                                             Inkscape::Util::ptr_shared /*old_value*/,
                                             Inkscape::Util::ptr_shared /*new_value*/)
{
    // Do nothing - tref only cares about textual content
}


/*
  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 :