summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-07-21 05:42:47 +0000
committermental <mental@users.sourceforge.net>2006-07-21 05:42:47 +0000
commit9dd3e11fa4339c5216ad816fd4cf83638acb4945 (patch)
tree5ed46c66c0dabc9e08ef47657b3c8a403c6ce24b /src
parentreplace two uses of hash_map with standard STL map (diff)
downloadinkscape-9dd3e11fa4339c5216ad816fd4cf83638acb4945.tar.gz
inkscape-9dd3e11fa4339c5216ad816fd4cf83638acb4945.zip
sp_object_invoke_release -> SPObject::releaseReferences, plus the introduction of sigc++ signals for "release" and "modified" which will eventually replace their GObject signal counterparts
(bzr r1447)
Diffstat (limited to 'src')
-rw-r--r--src/document.cpp2
-rw-r--r--src/sp-object.cpp53
-rw-r--r--src/sp-object.h30
3 files changed, 57 insertions, 28 deletions
diff --git a/src/document.cpp b/src/document.cpp
index 44e13b4f2..3077198cf 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -131,7 +131,7 @@ SPDocument::~SPDocument() {
sp_document_clear_undo(this);
if (root) {
- sp_object_invoke_release(root);
+ root->releaseReferences();
sp_object_unref(root);
root = NULL;
}
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index 8a96258e8..43611e9ed 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -195,6 +195,8 @@ sp_object_init(SPObject *object)
object->_collection_policy = SPObject::COLLECT_WITH_PARENT;
+ new (&object->_release_signal) sigc::signal<void, SPObject *>();
+ new (&object->_modified_signal) sigc::signal<void, SPObject *, unsigned int>();
new (&object->_delete_signal) sigc::signal<void, SPObject *>();
new (&object->_position_changed_signal) sigc::signal<void, SPObject *>();
object->_successor = NULL;
@@ -225,6 +227,8 @@ sp_object_finalize(GObject *object)
(* ((GObjectClass *) (parent_class))->finalize)(object);
}
+ spobject->_release_signal.~signal();
+ spobject->_modified_signal.~signal();
spobject->_delete_signal.~signal();
spobject->_position_changed_signal.~signal();
}
@@ -653,7 +657,7 @@ sp_object_detach(SPObject *parent, SPObject *object) {
g_return_if_fail(SP_IS_OBJECT(object));
g_return_if_fail(object->parent == parent);
- sp_object_invoke_release(object);
+ object->releaseReferences();
SPObject *prev=NULL;
for ( SPObject *child = parent->children ; child && child != object ;
@@ -859,45 +863,41 @@ sp_object_invoke_build(SPObject *object, SPDocument *document, Inkscape::XML::No
sp_repr_add_listener(repr, &object_event_vector, object);
}
-void
-sp_object_invoke_release(SPObject *object)
-{
- g_assert(object != NULL);
- g_assert(SP_IS_OBJECT(object));
-
- g_assert(object->document);
- g_assert(object->repr);
+void SPObject::releaseReferences() {
+ g_assert(this->document);
+ g_assert(this->repr);
- sp_repr_remove_listener_by_data(object->repr, object);
+ sp_repr_remove_listener_by_data(this->repr, this);
- g_signal_emit(G_OBJECT(object), object_signals[RELEASE], 0);
+ g_signal_emit(G_OBJECT(this), object_signals[RELEASE], 0);
+ this->_release_signal.emit(this);
/* all hrefs should be released by the "release" handlers */
- g_assert(object->hrefcount == 0);
+ g_assert(this->hrefcount == 0);
- if (!SP_OBJECT_IS_CLONED(object)) {
- if (object->id) {
- object->document->bindObjectToId(object->id, NULL);
+ if (!SP_OBJECT_IS_CLONED(this)) {
+ if (this->id) {
+ this->document->bindObjectToId(this->id, NULL);
}
- g_free(object->id);
- object->id = NULL;
+ g_free(this->id);
+ this->id = NULL;
- g_free(object->_default_label);
- object->_default_label = NULL;
+ g_free(this->_default_label);
+ this->_default_label = NULL;
- object->document->bindObjectToRepr(object->repr, NULL);
+ this->document->bindObjectToRepr(this->repr, NULL);
} else {
- g_assert(!object->id);
+ g_assert(!this->id);
}
- if (object->style) {
- object->style = sp_style_unref(object->style);
+ if (this->style) {
+ this->style = sp_style_unref(this->style);
}
- Inkscape::GC::release(object->repr);
+ Inkscape::GC::release(this->repr);
- object->document = NULL;
- object->repr = NULL;
+ this->document = NULL;
+ this->repr = NULL;
}
/**
@@ -1303,6 +1303,7 @@ SPObject::emitModified(unsigned int flags)
g_object_ref(G_OBJECT(this));
g_signal_emit(G_OBJECT(this), object_signals[MODIFIED], 0, flags);
+ _modified_signal.emit(this, flags);
g_object_unref(G_OBJECT(this));
}
diff --git a/src/sp-object.h b/src/sp-object.h
index 054fb6c7a..b563d8d3b 100644
--- a/src/sp-object.h
+++ b/src/sp-object.h
@@ -158,6 +158,21 @@ struct SPObject : public GObject {
Inkscape::XML::Node *repr; /* Our xml representation */
gchar *id; /* Our very own unique id */
+ /** @brief cleans up an SPObject, releasing its references and
+ * requesting that references to it be released
+ */
+ void releaseReferences();
+
+ /** @brief connects to the release request signal
+ *
+ * @param slot the slot to connect
+ *
+ * @returns the sigc::connection formed
+ */
+ sigc::connection connectRelease(sigc::slot<void, SPObject *> slot) {
+ return _release_signal.connect(slot);
+ }
+
/**
* Represents the style properties, whether from presentation attributes, the <tt>style</tt>
* attribute, or inherited.
@@ -445,6 +460,18 @@ struct SPObject : public GObject {
*/
void emitModified(unsigned int flags);
+ /** @brief Connects to the modification notification signal
+ *
+ * @param slot the slot to connect
+ *
+ * @returns the connection formed thereby
+ */
+ sigc::connection connectModified(
+ sigc::slot<void, SPObject *, unsigned int> slot
+ ) {
+ return _modified_signal.connect(slot);
+ }
+
void _sendDeleteSignalRecursive();
void _updateTotalHRefCount(int increment);
@@ -453,8 +480,10 @@ struct SPObject : public GObject {
}
void _requireSVGVersion(Inkscape::Version version);
+ sigc::signal<void, SPObject *> _release_signal;
sigc::signal<void, SPObject *> _delete_signal;
sigc::signal<void, SPObject *> _position_changed_signal;
+ sigc::signal<void, SPObject *, unsigned int> _modified_signal;
SPObject *_successor;
CollectionPolicy _collection_policy;
gchar *_label;
@@ -501,7 +530,6 @@ inline SPObject *sp_object_first_child(SPObject *parent) {
SPObject *sp_object_get_child_by_repr(SPObject *object, Inkscape::XML::Node *repr);
void sp_object_invoke_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr, unsigned int cloned);
-void sp_object_invoke_release(SPObject *object);
void sp_object_set(SPObject *object, unsigned int key, gchar const *value);