2
* Inkscape::ObjectHierarchy - tracks a hierarchy of active SPObjects
5
* MenTaLguY <mental@rydia.net>
7
* Copyright (C) 2004 MenTaLguY
9
* Released under GNU GPL, read the file 'COPYING' for more information
12
#ifndef SEEN_INKSCAPE_OBJECT_HIERARCHY_H
13
#define SEEN_INKSCAPE_OBJECT_HIERARCHY_H
17
#include <sigc++/connection.h>
18
#include <sigc++/signal.h>
19
#include <glib/gmessages.h>
26
* An Inkscape::ObjectHierarchy is useful for situations where one wishes
27
* to keep a reference to an SPObject, but fall back on one of its ancestors
28
* when that object is removed.
30
* That cannot be accomplished simply by hooking the "release" signal of the
31
* SPObject, as by the time that signal is emitted, the object's parent
32
* field has already been cleared.
34
* There are also some subtle refcounting issues to take into account.
39
class ObjectHierarchy {
41
ObjectHierarchy(SPObject *top=NULL);
44
bool contains(SPObject *object);
46
sigc::connection connectAdded(const sigc::slot<void, SPObject *> &slot) {
47
return _added_signal.connect(slot);
49
sigc::connection connectRemoved(const sigc::slot<void, SPObject *> &slot) {
50
return _removed_signal.connect(slot);
52
sigc::connection connectChanged(const sigc::slot<void, SPObject *, SPObject *> &slot)
54
return _changed_signal.connect(slot);
60
return !_hierarchy.empty() ? _hierarchy.back().object : NULL;
62
void setTop(SPObject *object);
65
return !_hierarchy.empty() ? _hierarchy.front().object : NULL;
67
void setBottom(SPObject *object);
71
Record(SPObject *o, sigc::connection c)
72
: object(o), connection(c) {}
75
sigc::connection connection;
78
ObjectHierarchy(ObjectHierarchy const &); // no copy
79
void operator=(ObjectHierarchy const &); // no assign
81
/// @brief adds objects in range [senior, junior) to the top
82
void _addTop(SPObject *senior, SPObject *junior);
83
/// @brief adds one object to the top
84
void _addTop(SPObject *object);
85
/// @brief removes all objects above the limit object
86
void _trimAbove(SPObject *limit);
88
/// @brief adds objects in range (senior, junior] to the bottom
89
void _addBottom(SPObject *senior, SPObject *junior);
90
/// @brief adds one object to the bottom
91
void _addBottom(SPObject *object);
92
/// @brief removes all objects below the limit object
93
void _trimBelow(SPObject *limit);
95
Record _attach(SPObject *object);
96
void _detach(Record &record);
98
void _clear() { _trimBelow(NULL); }
100
void _trim_for_release(SPObject *released);
102
std::list<Record> _hierarchy;
103
sigc::signal<void, SPObject *> _added_signal;
104
sigc::signal<void, SPObject *> _removed_signal;
105
sigc::signal<void, SPObject *, SPObject *> _changed_signal;
114
c-file-style:"stroustrup"
115
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
120
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :