Code

switch to sigc++ signals for "modified" and "release"
authormental <mental@users.sourceforge.net>
Fri, 21 Jul 2006 19:05:07 +0000 (19:05 +0000)
committermental <mental@users.sourceforge.net>
Fri, 21 Jul 2006 19:05:07 +0000 (19:05 +0000)
ChangeLog
src/selection.cpp
src/selection.h

index 878b79a90c7569babd32333d3231bfc794bab9a9..7d4312a70b2f3781450f94f15c6cbeb39ac58e59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-07-21  MenTaLguY  <mental@rydia.net>
+
+       * src/selection.cpp, src/selection.h:
+
+         switch to sigc++ signals for "modified" and "release"
+
 2006-07-21  MenTaLguY  <mental@rydia.net>
 
        * src/ui/view/edit-widget.cpp, src/ui/view/edit-widget.cpp:
index ae11a1432717c7a69453ed42cf188a1fa755aeb5..a27e45cb290280da0e57ed6b6fa577c38f156601 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "sp-shape.h"
 
+#include <sigc++/functors/mem_fun.h>
 
 #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<SPObject *>(_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);
 }
 
index d633d5c3bb9e3e522125a8169b00f012f71a7752..1dcaa53ff3d836082dc63d253d128dcd6171b524 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <vector>
+#include <map>
 #include <sigc++/sigc++.h>
 
 #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<SPDesktop> _desktop;
     SPObject* _selection_context;
-    gulong _context_release_handler_id;
     guint _flags;
     guint _idle;
 
+    std::map<SPObject *, sigc::connection> _modified_connections;
+    std::map<SPObject *, sigc::connection> _release_connections;
+    sigc::connection _context_release_connection;
+
     sigc::signal<void, Selection *> _changed_signal;
     sigc::signal<void, Selection *, guint> _modified_signal;
 };