From: mental Date: Fri, 21 Jul 2006 05:42:47 +0000 (+0000) Subject: sp_object_invoke_release -> SPObject::releaseReferences, plus the introduction of... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=35fd1876bd1a5dd349689f0aec5f1dc2b4d3ba99;p=inkscape.git sp_object_invoke_release -> SPObject::releaseReferences, plus the introduction of sigc++ signals for "release" and "modified" which will eventually replace their GObject signal counterparts --- diff --git a/ChangeLog b/ChangeLog index 7304f0b11..afffdfe09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-07-21 MenTaLguY + + * src/document.cpp, src/sp-object.cpp, src/sp-object.h: + + sp_object_invoke_release -> SPObject::releaseReferences, + plus the introduction of sigc++ signals for "release" and + "modified" which will eventually replace the GObject signals + 2006-07-20 MenTaLguY * src/libnrtype/RasterFont.h, src/libnrtype/font-instance.h: 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(); + new (&object->_modified_signal) sigc::signal(); new (&object->_delete_signal) sigc::signal(); new (&object->_position_changed_signal) sigc::signal(); 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 slot) { + return _release_signal.connect(slot); + } + /** * Represents the style properties, whether from presentation attributes, the style * 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 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 _release_signal; sigc::signal _delete_signal; sigc::signal _position_changed_signal; + sigc::signal _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);