Code

switch to sigc++ SPObject signals for desktop widget
authormental <mental@users.sourceforge.net>
Sat, 29 Jul 2006 20:21:27 +0000 (20:21 +0000)
committermental <mental@users.sourceforge.net>
Sat, 29 Jul 2006 20:21:27 +0000 (20:21 +0000)
ChangeLog
src/widgets/desktop-widget.cpp
src/widgets/desktop-widget.h

index 0053906a4c60810c8d42286310bbc2fab293b947..ec994c951dc3daf1815c58a73f893e17473685bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2006-06-29  MenTaLguY  <mental@rydia.net>
 
-       * src/widgets/gradient-image.cpp, src/widgets/gradient-image.h,
+       * src/widgets/desktop-widget.cpp, src/widgets/desktop-widget.h,
+         src/widgets/gradient-image.cpp, src/widgets/gradient-image.h,
          src/widgets/gradient-toolbar.cpp, src/widgets/gradient-toolbar.cpp:
 
          switch to sigc++ SPObject signals
index 0a4536bb1ba5deb64b160ca9e1496aadac8308d7..9590af94c898c241ceddf0a2bdcd6d37acae2a5b 100644 (file)
@@ -77,7 +77,7 @@ static gint sp_desktop_widget_event (GtkWidget *widget, GdkEvent *event, SPDeskt
 
 
 static void sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget *dtw);
-static void sp_desktop_widget_namedview_modified (SPNamedView *nv, guint flags, SPDesktopWidget *dtw);
+static void sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw);
 
 static gdouble sp_dtw_zoom_value_to_display (gdouble value);
 static gdouble sp_dtw_zoom_display_to_value (gdouble value);
@@ -163,6 +163,8 @@ sp_desktop_widget_init (SPDesktopWidget *dtw)
     GtkWidget *eventbox;
     GtkStyle *style;
 
+    new (&dtw->modified_connection) sigc::connection();
+
     widget = GTK_WIDGET (dtw);
 
     dtw->window = 0;
@@ -344,12 +346,14 @@ sp_desktop_widget_destroy (GtkObject *object)
     if (dtw->desktop) {
         dtw->layer_selector->unreference();
         inkscape_remove_desktop (dtw->desktop); // clears selection too
-        sp_signal_disconnect_by_data (G_OBJECT (dtw->desktop->namedview), dtw);
+        dtw->modified_connection.disconnect();
         dtw->desktop->destroy();
         Inkscape::GC::release (dtw->desktop);
         dtw->desktop = NULL;
     }
 
+    dtw->modified_connection.~connection();
+
     if (GTK_OBJECT_CLASS (dtw_parent_class)->destroy) {
         (* GTK_OBJECT_CLASS (dtw_parent_class)->destroy) (object);
     }
@@ -449,7 +453,10 @@ sp_desktop_widget_realize (GtkWidget *widget)
     dtw->desktop->set_display_area (d.x0, d.y0, d.x1, d.y1, 10);
 
     /* Listen on namedview modification */
-    g_signal_connect (G_OBJECT (dtw->desktop->namedview), "modified", G_CALLBACK (sp_desktop_widget_namedview_modified), dtw);
+    // originally (prior to the sigc++ conversion) the signal was simply
+    // connected twice rather than disconnecting the first connection
+    dtw->modified_connection.disconnect();
+    dtw->modified_connection = dtw->desktop->namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
     sp_desktop_widget_namedview_modified (dtw->desktop->namedview, SP_OBJECT_MODIFIED_FLAG, dtw);
 
     dtw->updateTitle(SP_DOCUMENT_NAME (dtw->desktop->doc()));
@@ -897,7 +904,7 @@ sp_desktop_widget_new (SPNamedView *namedview)
     sp_view_widget_set_view (SP_VIEW_WIDGET (dtw), dtw->desktop);
 
     /* Listen on namedview modification */
-    g_signal_connect (G_OBJECT (namedview), "modified", G_CALLBACK (sp_desktop_widget_namedview_modified), dtw);
+    dtw->modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
 
     dtw->layer_selector->setDesktop(dtw->desktop);
 
@@ -941,8 +948,9 @@ sp_desktop_widget_update_rulers (SPDesktopWidget *dtw)
 
 
 static void
-sp_desktop_widget_namedview_modified (SPNamedView *nv, guint flags, SPDesktopWidget *dtw)
+sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw)
 {
+    SPNamedView *nv=SP_NAMEDVIEW(obj);
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
         dtw->dt2r = 1.0 / nv->doc_units->unittobase;
         dtw->ruler_origin = nv->gridorigin;
index 5129fbf490a5d6346c3e3f2bb4040c798e142eaa..cc66bf1800cd6772be2f52d0918ef712aea40afe 100644 (file)
@@ -19,6 +19,8 @@
 #include "ui/view/view-widget.h"
 #include "ui/view/edit-widget-interface.h"
 
+#include <sigc++/connection.h>
+
 #define SP_TYPE_DESKTOP_WIDGET (sp_desktop_widget_get_type ())
 #define SP_DESKTOP_WIDGET(o) (GTK_CHECK_CAST ((o), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidget))
 #define SP_DESKTOP_WIDGET_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SP_TYPE_DESKTOP_WIDGET, SPDesktopWidgetClass))
@@ -55,6 +57,8 @@ struct SPDesktopWidget {
 
     unsigned int update : 1;
 
+    sigc::connection modified_connection;
+
     GtkTooltips *tt;
 
     SPDesktop *desktop;