Code

switch to sigc++ SPObject signals for SPShape
authormental <mental@users.sourceforge.net>
Fri, 28 Jul 2006 03:08:10 +0000 (03:08 +0000)
committermental <mental@users.sourceforge.net>
Fri, 28 Jul 2006 03:08:10 +0000 (03:08 +0000)
ChangeLog
src/sp-shape.cpp
src/sp-shape.h

index 6b6adff27f8c7b45adf48ff78221861820af8f3a..8f8d200e9a96bcb4702de7ec9863ff89b65f6079 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-06-27  MenTaLguY  <mental@rydia.net>
+
+       * src/sp-shape.cpp, src/sp-shape.h:
+
+         switch to sigc++ SPObject signals for SPShape
+
 2006-07-26  MenTaLguY  <mental@rydia.net>
 
        * src/dialogs/object-attributes.cpp:
index 153d1fa517a4496b28961eb87f767f8cc26682d8..f72a0da340162c1efd4afa7666f2a3d9f35fe309 100644 (file)
@@ -24,6 +24,8 @@
 #include <libnr/nr-matrix-translate-ops.h>
 #include <libnr/nr-scale-matrix-ops.h>
 
+#include <sigc++/functors/ptr_fun.h>
+#include <sigc++/adaptors/bind.h>
 
 #include "macros.h"
 #include "display/nr-arena-shape.h"
@@ -39,6 +41,7 @@
 
 static void sp_shape_class_init (SPShapeClass *klass);
 static void sp_shape_init (SPShape *shape);
+static void sp_shape_finalize (GObject *object);
 
 static void sp_shape_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr);
 static void sp_shape_release (SPObject *object);
@@ -86,16 +89,20 @@ sp_shape_get_type (void)
 static void
 sp_shape_class_init (SPShapeClass *klass)
 {
+        GObjectClass *gobject_class;
        SPObjectClass *sp_object_class;
        SPItemClass * item_class;
        SPPathClass * path_class;
 
+        gobject_class = (GObjectClass *) klass;
        sp_object_class = (SPObjectClass *) klass;
        item_class = (SPItemClass *) klass;
        path_class = (SPPathClass *) klass;
 
        parent_class = (SPItemClass *)g_type_class_peek_parent (klass);
 
+        gobject_class->finalize = sp_shape_finalize;
+
        sp_object_class->build = sp_shape_build;
        sp_object_class->release = sp_shape_release;
        sp_object_class->update = sp_shape_update;
@@ -109,13 +116,32 @@ sp_shape_class_init (SPShapeClass *klass)
 }
 
 /**
- * Initializes an SPShape object.  Nothing particular is needed to initialize
- * an SPShape object; this is just here as a stub.
+ * Initializes an SPShape object.
  */
 static void
 sp_shape_init (SPShape *shape)
 {
-       /* Nothing here */
+    for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
+        new (&shape->release_connect[i]) sigc::connection();
+        new (&shape->modified_connect[i]) sigc::connection();
+    }
+}
+
+static void
+sp_shape_finalize (GObject *object)
+{
+    SPShape *shape=(SPShape *)object;
+
+    for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
+        shape->release_connect[i].disconnect();
+        shape->release_connect[i].~connection();
+        shape->modified_connect[i].disconnect();
+        shape->modified_connect[i].~connection();
+    }
+
+    if (((GObjectClass *) (parent_class))->finalize) {
+        (* ((GObjectClass *) (parent_class))->finalize)(object);
+    }
 }
 
 /**
@@ -885,8 +911,8 @@ sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value)
             SPItemView *v;
 
             /* Detach marker */
-            g_signal_handler_disconnect (shape->marker[key], shape->release_connect[key]);
-            g_signal_handler_disconnect (shape->marker[key], shape->modified_connect[key]);
+            shape->release_connect[key].disconnect();
+            shape->modified_connect[key].disconnect();
 
             /* Hide marker */
             for (v = item->display; v != NULL; v = v->next) {
@@ -901,10 +927,8 @@ sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value)
         }
         if (SP_IS_MARKER (mrk)) {
             shape->marker[key] = sp_object_href (mrk, object);
-            shape->release_connect[key] = g_signal_connect (G_OBJECT (shape->marker[key]), "release",
-                              G_CALLBACK (sp_shape_marker_release), shape);
-            shape->modified_connect[key] = g_signal_connect (G_OBJECT (shape->marker[key]), "modified",
-                              G_CALLBACK (sp_shape_marker_modified), shape);
+            shape->release_connect[key] = mrk->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_shape_marker_release), shape));
+            shape->modified_connect[key] = mrk->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_shape_marker_modified), shape));
         }
     }
 }
index 32774f60315abab3321bfbca0cfc41087037628e..2b265fdaaf6b397c8c4247098dbf3ee7354c9068 100644 (file)
@@ -17,7 +17,7 @@
 #include "sp-item.h"
 #include "sp-marker-loc.h"
 
-
+#include <sigc++/connection.h>
 
 #define SP_TYPE_SHAPE (sp_shape_get_type ())
 #define SP_SHAPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_SHAPE, SPShape))
@@ -31,8 +31,8 @@ struct SPShape : public SPItem {
        SPCurve *curve;
 
       SPObject *marker[SP_MARKER_LOC_QTY];
-      gulong release_connect [SP_MARKER_LOC_QTY];
-      gulong modified_connect [SP_MARKER_LOC_QTY];
+      sigc::connection release_connect [SP_MARKER_LOC_QTY];
+      sigc::connection modified_connect [SP_MARKER_LOC_QTY];
 };
 
 struct SPShapeClass {