diff --git a/src/uri-references.cpp b/src/uri-references.cpp
index fff985139b1f6c9071ec54d07d5fc843b65c6a8d..c9482839d56a5452579583549712eb6ba1b9395d 100644 (file)
--- a/src/uri-references.cpp
+++ b/src/uri-references.cpp
#include "uri.h"
#include "uri-references.h"
+#include <sigc++/functors/mem_fun.h>
+
static gchar *uri_to_id(SPDocument *document, const gchar *uri);
namespace Inkscape {
URIReference::URIReference(SPObject *owner)
-: _owner(owner), _obj(NULL), _uri(NULL)
+ : _owner(owner), _owner_document(NULL), _obj(NULL), _uri(NULL)
{
g_assert(_owner != NULL);
/* FIXME !!! attach to owner's destroy signal to clean up in case */
}
+URIReference::URIReference(SPDocument *owner_document)
+ : _owner(NULL), _owner_document(owner_document), _obj(NULL), _uri(NULL)
+{
+ g_assert(_owner_document != NULL);
+}
+
URIReference::~URIReference() {
detach();
}
void URIReference::attach(const URI &uri) throw(BadURIException)
{
- SPDocument *document = SP_OBJECT_DOCUMENT(_owner);
+ SPDocument *document;
+ if (_owner) {
+ document = SP_OBJECT_DOCUMENT(_owner);
+ } else if (_owner_document) {
+ document = _owner_document;
+ } else {
+ g_assert_not_reached();
+ }
gchar const *fragment = uri.getFragment();
if ( !uri.isRelative() || uri.getQuery() || !fragment ) {
throw UnsupportedURIException();
SPObject *old_obj=_obj;
_obj = obj;
+ _release_connection.disconnect();
if (_obj) {
sp_object_href(_obj, _owner);
- g_signal_connect(G_OBJECT(_obj), "release", G_CALLBACK(&URIReference::_release), reinterpret_cast<gpointer>(this));
+ _release_connection = _obj->connectRelease(sigc::mem_fun(*this, &URIReference::_release));
}
_changed_signal.emit(old_obj, _obj);
if (old_obj) {
/* release the old object _after_ the signal emission */
- g_signal_handlers_disconnect_by_func(G_OBJECT(old_obj), (void *)&URIReference::_release, reinterpret_cast<gpointer>(this));
sp_object_hunref(old_obj, _owner);
}
}
* it on its "release" signal, rather than later, when its ID is actually
* unregistered from the document.
*/
-void URIReference::_release(SPObject *obj, URIReference *reference) {
- g_assert( reference->_obj == obj );
- reference->_setObject(NULL);
+void URIReference::_release(SPObject *obj) {
+ g_assert( _obj == obj );
+ _setObject(NULL);
}
} /* namespace Inkscape */