From 728152945a5fe656e4bcfbd189f14956b7399630 Mon Sep 17 00:00:00 2001 From: mental Date: Fri, 21 Jul 2006 19:05:07 +0000 Subject: [PATCH] switch to sigc++ signals for "modified" and "release" --- ChangeLog | 6 +++++ src/selection.cpp | 56 +++++++++++++++-------------------------------- src/selection.h | 12 +++++----- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 878b79a90..7d4312a70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-07-21 MenTaLguY + + * src/selection.cpp, src/selection.h: + + switch to sigc++ signals for "modified" and "release" + 2006-07-21 MenTaLguY * src/ui/view/edit-widget.cpp, src/ui/view/edit-widget.cpp: diff --git a/src/selection.cpp b/src/selection.cpp index ae11a1432..a27e45cb2 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -28,6 +28,7 @@ #include "sp-shape.h" +#include #define SP_SELECTION_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE + 1) @@ -39,7 +40,6 @@ Selection::Selection(SPDesktop *desktop) : _items(NULL), _desktop(desktop), _selection_context(NULL), - _context_release_handler_id(0), _flags(0), _idle(0) { @@ -54,24 +54,16 @@ Selection::~Selection() { } } -void -Selection::_release(SPObject *obj, Selection *selection) -{ - selection->remove(obj); -} - /* Handler for selected objects "modified" signal */ -void -Selection::_schedule_modified(SPObject *obj, guint flags, Selection *selection) -{ - if (!selection->_idle) { +void Selection::_schedule_modified(SPObject *obj, guint flags) { + if (!this->_idle) { /* Request handling to be run in _idle loop */ - selection->_idle = g_idle_add_full(SP_SELECTION_UPDATE_PRIORITY, GSourceFunc(&Selection::_emit_modified), selection, NULL); + this->_idle = g_idle_add_full(SP_SELECTION_UPDATE_PRIORITY, GSourceFunc(&Selection::_emit_modified), this, NULL); } /* Collect all flags */ - selection->_flags |= flags; + this->_flags |= flags; } gboolean @@ -98,10 +90,7 @@ void Selection::_emitChanged(bool persist_selection_context/* = false */) { if (NULL == _selection_context) { _selection_context = desktop()->currentLayer(); sp_object_ref(_selection_context, NULL); - _context_release_handler_id = g_signal_connect( - G_OBJECT(_selection_context), "release", - G_CALLBACK(&Selection::_releaseSelectionContext), - this); + _context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext)); } } else { _releaseContext(_selection_context); @@ -111,21 +100,15 @@ void Selection::_emitChanged(bool persist_selection_context/* = false */) { _changed_signal.emit(this); } -void -Selection::_releaseSelectionContext(SPObject *obj, Selection *selection) -{ - selection->_releaseContext(obj); -} - void Selection::_releaseContext(SPObject *obj) { if (NULL == _selection_context || _selection_context != obj) return; - g_signal_handler_disconnect(G_OBJECT(_selection_context), _context_release_handler_id); + _context_release_connection.disconnect(); + sp_object_unref(_selection_context, NULL); - _context_release_handler_id = 0; _selection_context = NULL; } @@ -141,8 +124,7 @@ void Selection::_clear() { _invalidateCachedLists(); while (_objs) { SPObject *obj=reinterpret_cast(_objs->data); - sp_signal_disconnect_by_data(obj, this); - _objs = g_slist_remove(_objs, obj); + _remove(obj); } } @@ -181,16 +163,9 @@ void Selection::_add(SPObject *obj) { _removeObjectAncestors(obj); _objs = g_slist_prepend(_objs, obj); - g_signal_connect(G_OBJECT(obj), "release", - G_CALLBACK(&Selection::_release), this); - g_signal_connect(G_OBJECT(obj), "modified", - G_CALLBACK(&Selection::_schedule_modified), this); - - /* - if (!SP_IS_SHAPE(obj)) { - printf("This is not a shape\n"); - } - */ + + _release_connections[obj] = obj->connectRelease(sigc::mem_fun(*this, (void (Selection::*)(SPObject *))&Selection::remove)); + _modified_connections[obj] = obj->connectModified(sigc::mem_fun(*this, &Selection::_schedule_modified)); } void Selection::set(SPObject *object, bool persist_selection_context) { @@ -217,7 +192,12 @@ void Selection::remove(SPObject *obj) { } void Selection::_remove(SPObject *obj) { - sp_signal_disconnect_by_data(obj, this); + _modified_connections[obj].disconnect(); + _modified_connections.erase(obj); + + _release_connections[obj].disconnect(); + _release_connections.erase(obj); + _objs = g_slist_remove(_objs, obj); } diff --git a/src/selection.h b/src/selection.h index d633d5c3b..1dcaa53ff 100644 --- a/src/selection.h +++ b/src/selection.h @@ -17,6 +17,7 @@ */ #include +#include #include #include "libnr/nr-rect.h" @@ -318,11 +319,7 @@ private: /** @brief Issues modification notification signals */ static gboolean _emit_modified(Selection *selection); /** @brief Schedules an item modification signal to be sent */ - static void _schedule_modified(SPObject *obj, guint flags, Selection *selection); - /** @brief Releases a selected object that is being removed */ - static void _release(SPObject *obj, Selection *selection); - /** @brief Releases an active layer object that is being removed */ - static void _releaseSelectionContext(SPObject *obj, Selection *selection); + void _schedule_modified(SPObject *obj, guint flags); /** @brief Issues modified selection signal */ void _emitModified(guint flags); @@ -352,10 +349,13 @@ private: GC::soft_ptr _desktop; SPObject* _selection_context; - gulong _context_release_handler_id; guint _flags; guint _idle; + std::map _modified_connections; + std::map _release_connections; + sigc::connection _context_release_connection; + sigc::signal _changed_signal; sigc::signal _modified_signal; }; -- 2.30.2