Code

PNG output for Cairo renderer
[inkscape.git] / src / desktop.cpp
index 5db7e5d2413a54c9d8a463fb05af4ab431388ec8..57d89c5bcb4a47550b502d78daa5d4e92a201369 100644 (file)
@@ -8,7 +8,9 @@
  *   MenTaLguY <mental@rydia.net>
  *   bulia byak <buliabyak@users.sf.net>
  *   Ralf Stephan <ralf@ark.in-berlin.de>
+ *   John Bintz <jcoswell@coswellproductions.org>
  *
+ * Copyright (C) 2006 John Bintz
  * Copyright (C) 2004 MenTaLguY
  * Copyright (C) 1999-2002 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
@@ -49,6 +51,7 @@
 #endif
 
 #include <glibmm/i18n.h>
+#include <sigc++/functors/mem_fun.h>
 
 #include "macros.h"
 #include "inkscape-private.h"
 #include "ui/dialog/dialog-manager.h"
 #include "xml/repr.h"
 #include "message-context.h"
-
-#ifdef WITH_INKBOARD
-#include "jabber_whiteboard/session-manager.h"
-#endif
+#include "layer-manager.h"
 
 namespace Inkscape { namespace XML { class Node; }}
 
@@ -90,7 +90,7 @@ static void _layer_deactivated(SPObject *layer, SPDesktop *desktop);
 static void _layer_hierarchy_changed(SPObject *top, SPObject *bottom, SPDesktop *desktop);
 static void _reconstruction_start(SPDesktop * desktop);
 static void _reconstruction_finish(SPDesktop * desktop);
-static void _namedview_modified (SPNamedView *nv, guint flags, SPDesktop *desktop);
+static void _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop);
 static void _update_snap_distances (SPDesktop *desktop);
 
 /**
@@ -112,6 +112,7 @@ SPDesktop::SPDesktop()
     sketch = NULL;
     controls = NULL;
     event_context = 0;
+    layer_manager = 0;
 
     _d2w.set_identity();
     _w2d.set_identity();
@@ -225,8 +226,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     _doc2dt[5] = sp_document_height (document);
     sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);
 
-    g_signal_connect (G_OBJECT (namedview), "modified", G_CALLBACK (_namedview_modified), this);
-
+    _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));
 
     NRArenaItem *ai = sp_item_invoke_show (SP_ITEM (sp_document_root (document)),
             SP_CANVAS_ARENA (drawing)->arena,
@@ -243,14 +243,6 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     /* Ugly hack */
     _namedview_modified (namedview, SP_OBJECT_MODIFIED_FLAG, this);
 
-       /* Construct SessionManager
-        *
-        * SessionManager construction needs to be done after document connection
-        */
-#ifdef WITH_INKBOARD
-       _whiteboard_session_manager = new Inkscape::Whiteboard::SessionManager(this);
-#endif
-
 /* Set up notification of rebuilding the document, this allows
        for saving object related settings in the document. */
     _reconstruction_start_connection =
@@ -258,7 +250,9 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     _reconstruction_finish_connection =
         document->connectReconstructionFinish(sigc::bind(sigc::ptr_fun(_reconstruction_finish), this));
     _reconstruction_old_layer_id = NULL;
-
+    
+    _commit_connection = document->connectCommit(sigc::mem_fun(*this, &SPDesktop::updateNow));
+    
     // ?
     // sp_active_desktop_set (desktop);
     _inkscape = INKSCAPE;
@@ -289,6 +283,10 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
         )
     );
 
+
+    /* setup LayerManager */
+    //   (Setting up after the connections are all in place, as it may use some of them)
+    layer_manager = new Inkscape::LayerManager( this );
 }
 
 
@@ -298,6 +296,14 @@ void SPDesktop::destroy()
     _deactivate_connection.disconnect();
     _sel_modified_connection.disconnect();
     _sel_changed_connection.disconnect();
+    _modified_connection.disconnect();
+    _commit_connection.disconnect();
+    _reconstruction_start_connection.disconnect();
+    _reconstruction_finish_connection.disconnect();
+
+    g_signal_handlers_disconnect_by_func(G_OBJECT (acetate), (gpointer) G_CALLBACK(sp_desktop_root_handler), this);
+    g_signal_handlers_disconnect_by_func(G_OBJECT (main), (gpointer) G_CALLBACK(sp_desktop_root_handler), this);
+    g_signal_handlers_disconnect_by_func(G_OBJECT (drawing), (gpointer) G_CALLBACK(_arena_handler), this);
 
     while (event_context) {
         SPEventContext *ec = event_context;
@@ -319,17 +325,9 @@ void SPDesktop::destroy()
         drawing = NULL;
     }
 
-#ifdef WITH_INKBOARD
-       if (_whiteboard_session_manager) {
-               delete _whiteboard_session_manager;
-       }
-#endif
-
     delete _guides_message_context;
     _guides_message_context = NULL;
 
-    sp_signal_disconnect_by_data (G_OBJECT (namedview), this);
-
     g_list_free (zooms_past);
     g_list_free (zooms_future);
 }
@@ -370,11 +368,13 @@ SPObject *SPDesktop::currentLayer() const
 }
 
 /**
+ * Sets the current layer of the desktop.
+ * 
  * Make \a object the top layer.
  */
 void SPDesktop::setCurrentLayer(SPObject *object) {
     g_return_if_fail(SP_IS_GROUP(object));
-    g_return_if_fail( currentRoot() == object || currentRoot()->isAncestorOf(object));
+    g_return_if_fail( currentRoot() == object || (currentRoot() && currentRoot()->isAncestorOf(object)) );
     // printf("Set Layer to ID: %s\n", SP_OBJECT_ID(object));
     _layer_hierarchy->setBottom(object);
 }
@@ -510,12 +510,17 @@ SPDesktop::push_event_context (GtkType type, const gchar *config, unsigned int k
     _event_context_changed_signal.emit (this, ec);
 }
 
+/**
+ * Sets the coordinate status to a given point
+ */
 void
 SPDesktop::set_coordinate_status (NR::Point p) {
     _widget->setCoordinateStatus(p);
 }
 
-
+/**
+ * \see sp_document_item_from_list_at_point_bottom()
+ */
 SPItem *
 SPDesktop::item_from_list_at_point_bottom (const GSList *list, NR::Point const p) const
 {
@@ -523,6 +528,9 @@ SPDesktop::item_from_list_at_point_bottom (const GSList *list, NR::Point const p
     return sp_document_item_from_list_at_point_bottom (dkey, SP_GROUP (doc()->root), list, p);
 }
 
+/**
+ * \see sp_document_item_at_point()
+ */
 SPItem *
 SPDesktop::item_at_point (NR::Point const p, bool into_groups, SPItem *upto) const
 {
@@ -530,6 +538,9 @@ SPDesktop::item_at_point (NR::Point const p, bool into_groups, SPItem *upto) con
     return sp_document_item_at_point (doc(), dkey, p, into_groups, upto);
 }
 
+/**
+ * \see sp_document_group_at_point()
+ */
 SPItem *
 SPDesktop::group_at_point (NR::Point const p) const
 {
@@ -1018,6 +1029,23 @@ SPDesktop::emitToolSubselectionChanged(gpointer data)
        inkscape_subselection_changed (this);
 }
 
+void
+SPDesktop::updateNow()
+{
+  sp_canvas_update_now(canvas);
+}
+
+void
+SPDesktop::enableInteraction()
+{
+  _widget->enableInteraction();
+}
+
+void SPDesktop::disableInteraction()
+{
+  _widget->disableInteraction();
+}
+
 //----------------------------------------------------------------------
 // Callback implementations. The virtual ones are connected by the view.
 
@@ -1044,9 +1072,16 @@ SPDesktop::onRedrawRequested ()
     }
 }
 
+void
+SPDesktop::updateCanvasNow()
+{
+  _widget->requestCanvasUpdateAndWait();
+}
+
 /**
  * Associate document with desktop.
  */
+/// \todo fixme: refactor SPDesktop::init to use setDocument
 void
 SPDesktop::setDocument (SPDocument *doc)
 {
@@ -1065,6 +1100,9 @@ SPDesktop::setDocument (SPDocument *doc)
     _layer_hierarchy->connectChanged(sigc::bind(sigc::ptr_fun(_layer_hierarchy_changed), this));
     _layer_hierarchy->setTop(SP_DOCUMENT_ROOT(doc));
 
+    _commit_connection.disconnect();
+    _commit_connection = doc->connectCommit(sigc::mem_fun(*this, &SPDesktop::updateNow));
+
     /// \todo fixme: This condition exists to make sure the code
     /// inside is called only once on initialization. But there
     /// are surely more safe methods to accomplish this.
@@ -1072,7 +1110,7 @@ SPDesktop::setDocument (SPDocument *doc)
         NRArenaItem *ai;
 
         namedview = sp_document_namedview (doc, NULL);
-        g_signal_connect (G_OBJECT (namedview), "modified", G_CALLBACK (_namedview_modified), this);
+        _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));
         number = namedview->getViewCount();
 
         ai = sp_item_invoke_show (SP_ITEM (sp_document_root (doc)),
@@ -1242,11 +1280,16 @@ _reconstruction_finish (SPDesktop * desktop)
  * Namedview_modified callback.
  */
 static void
-_namedview_modified (SPNamedView *nv, guint flags, SPDesktop *desktop)
+_namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop)
 {
+    SPNamedView *nv=SP_NAMEDVIEW(obj);
+
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
 
         /* Recalculate snap distances */
+        /* FIXME: why is the desktop getting involved in setting up something
+        ** that is entirely to do with the namedview?
+        */
         _update_snap_distances (desktop);
 
         /* Show/hide page background */
@@ -1312,15 +1355,15 @@ _update_snap_distances (SPDesktop *desktop)
 
     SPNamedView &nv = *desktop->namedview;
 
-    nv.grid_snapper.setDistance(sp_convert_distance_full(nv.gridtolerance,
-                                                         *nv.gridtoleranceunit,
-                                                         px));
-    nv.guide_snapper.setDistance(sp_convert_distance_full(nv.guidetolerance,
-                                                          *nv.guidetoleranceunit,
-                                                          px));
-    nv.object_snapper.setDistance(sp_convert_distance_full(nv.objecttolerance,
-                                                           *nv.objecttoleranceunit,
-                                                           px));
+    nv.snap_manager.grid.setDistance(sp_convert_distance_full(nv.gridtolerance,
+                                                                      *nv.gridtoleranceunit,
+                                                                      px));
+    nv.snap_manager.guide.setDistance(sp_convert_distance_full(nv.guidetolerance,
+                                                                       *nv.guidetoleranceunit,
+                                                                       px));
+    nv.snap_manager.object.setDistance(sp_convert_distance_full(nv.objecttolerance,
+                                                                        *nv.objecttoleranceunit,
+                                                                        px));
 }