Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / connector-context.cpp
index e38f8a627d34f1b7db0b21a8c4b324b6e9fa9cdc..6fa709b18915437322ef9827a8daacbb0e2786d9 100644 (file)
  */
 
 #include <gdk/gdkkeysyms.h>
+#include <string>
+#include <cstring>
 
 #include "connector-context.h"
 #include "pixmaps/cursor-connector.xpm"
-#include "pixmaps/cursor-connector.pixbuf"
 #include "xml/node-event-vector.h"
 #include "xml/repr.h"
 #include "svg/svg.h"
@@ -58,7 +59,7 @@
 #include "message-stack.h"
 #include "selection.h"
 #include "inkscape.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "sp-path.h"
 #include "display/canvas-bpath.h"
 #include "display/sodipodi-ctrl.h"
@@ -72,7 +73,7 @@
 #include "sp-namedview.h"
 #include "sp-text.h"
 #include "sp-flowtext.h"
-
+#include "display/curve.h"
 
 static void sp_connector_context_class_init(SPConnectorContextClass *klass);
 static void sp_connector_context_init(SPConnectorContext *conn_context);
@@ -84,9 +85,9 @@ static gint sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *even
 static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
 
 // Stuff borrowed from DrawContext
-static void spcc_connector_set_initial_point(SPConnectorContext *cc, NR::Point const p);
-static void spcc_connector_set_subsequent_point(SPConnectorContext *cc, NR::Point const p);
-static void spcc_connector_finish_segment(SPConnectorContext *cc, NR::Point p);
+static void spcc_connector_set_initial_point(SPConnectorContext *cc, Geom::Point const p);
+static void spcc_connector_set_subsequent_point(SPConnectorContext *cc, Geom::Point const p);
+static void spcc_connector_finish_segment(SPConnectorContext *cc, Geom::Point p);
 static void spcc_reset_colors(SPConnectorContext *cc);
 static void spcc_connector_finish(SPConnectorContext *cc);
 static void spcc_concat_colors_and_flush(SPConnectorContext *cc);
@@ -102,9 +103,11 @@ static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item);
 static void cc_clear_active_shape(SPConnectorContext *cc);
 static void cc_set_active_conn(SPConnectorContext *cc, SPItem *item);
 static void cc_clear_active_conn(SPConnectorContext *cc);
-static gchar *conn_pt_handle_test(SPConnectorContext *cc, NR::Point& w);
+static gchar *conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& w);
 static bool cc_item_is_shape(SPItem *item);
 static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
+static void cc_connector_rerouting_finish(SPConnectorContext *const cc,
+        Geom::Point *const p);
 
 static void shape_event_attr_deleted(Inkscape::XML::Node *repr,
         Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
@@ -113,7 +116,7 @@ static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *nam
         gpointer data);
 
 
-static NR::Point connector_drag_origin_w(0, 0);
+static Geom::Point connector_drag_origin_w(0, 0);
 static bool connector_within_tolerance = false;
 static SPEventContextClass *parent_class;
 
@@ -181,11 +184,6 @@ sp_connector_context_init(SPConnectorContext *cc)
     SPEventContext *ec = SP_EVENT_CONTEXT(cc);
 
     ec->cursor_shape = cursor_connector_xpm;
-    ec->cursor_pixbuf = gdk_pixbuf_new_from_inline(
-            -1,
-            cursor_connector_pixbuf,
-            FALSE,
-            NULL);  
     ec->hot_x = 1;
     ec->hot_y = 1;
     ec->xp = 0;
@@ -277,21 +275,24 @@ sp_connector_context_setup(SPEventContext *ec)
     sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cc->red_bpath), 0x00000000,
             SP_WIND_RULE_NONZERO);
     /* Create red curve */
-    cc->red_curve = sp_curve_new_sized(4);
+    cc->red_curve = new SPCurve();
 
     /* Create green curve */
-    cc->green_curve = sp_curve_new_sized(64);
+    cc->green_curve = new SPCurve();
 
     // Notice the initial selection.
     cc_selection_changed(cc->selection, (gpointer) cc);
 
-    if (prefs_get_int_attribute("tools.connector", "selcue", 0) != 0) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (prefs->getBool("/tools/connector/selcue", 0)) {
         ec->enableSelectionCue();
     }
 
     // Make sure we see all enter events for canvas items,
     // even if a mouse button is depressed.
     dt->canvas->gen_all_enter_events = true;
+
+    sp_canvas_set_snap_delay_active(dt->canvas, true);
 }
 
 
@@ -315,6 +316,8 @@ sp_connector_context_finish(SPEventContext *ec)
     // Restore the default event generating behaviour.
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
     desktop->canvas->gen_all_enter_events = false;
+
+    sp_canvas_set_snap_delay_active(desktop->canvas, false);
 }
 
 
@@ -375,7 +378,7 @@ cc_clear_active_conn(SPConnectorContext *cc)
 
 
 static gchar *
-conn_pt_handle_test(SPConnectorContext *cc, NR::Point& p)
+conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p)
 {
     // TODO: this will need to change when there are more connection
     //       points available for each shape.
@@ -392,19 +395,19 @@ conn_pt_handle_test(SPConnectorContext *cc, NR::Point& p)
 
 
 static gint
-sp_connector_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
+sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
 {
     gint ret = FALSE;
 
-    SPDesktop *desktop = ec->desktop;
+    SPDesktop *desktop = event_context->desktop;
 
-    SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
+    SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context);
 
-    NR::Point p(event->button.x, event->button.y);
+    Geom::Point p(event->button.x, event->button.y);
 
     switch (event->type) {
         case GDK_BUTTON_RELEASE:
-            if (event->button.button == 1) {
+            if (event->button.button == 1 && !event_context->space_panning) {
                 if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
                         (connector_within_tolerance))
                 {
@@ -490,12 +493,13 @@ sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event)
 static gint
 connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent)
 {
-    NR::Point const event_w(bevent.x, bevent.y);
+    Geom::Point const event_w(bevent.x, bevent.y);
     /* Find desktop coordinates */
-    NR::Point p = cc->desktop->w2d(event_w);
+    Geom::Point p = cc->desktop->w2d(event_w);
+    SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
 
     gint ret = FALSE;
-    if ( bevent.button == 1 ) {
+    if ( bevent.button == 1 && !event_context->space_panning ) {
 
         SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
 
@@ -503,39 +507,39 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
             return TRUE;
         }
 
-        NR::Point const event_w(bevent.x,
+        Geom::Point const event_w(bevent.x,
                                 bevent.y);
         connector_drag_origin_w = event_w;
         connector_within_tolerance = true;
 
-        NR::Point const event_dt = cc->desktop->w2d(event_w);
+        Geom::Point const event_dt = cc->desktop->w2d(event_w);
         switch (cc->state) {
             case SP_CONNECTOR_CONTEXT_STOP:
                 /* This is allowed, if we just cancelled curve */
             case SP_CONNECTOR_CONTEXT_IDLE:
             {
                 if ( cc->npoints == 0 ) {
-                    /* Set start anchor */
-                    NR::Point p;
-
                     cc_clear_active_conn(cc);
 
                     SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector"));
 
+                    /* Set start anchor */
                     /* Create green anchor */
-                    p = event_dt;
+                    Geom::Point p = event_dt;
 
                     // Test whether we clicked on a connection point
                     cc->sid = conn_pt_handle_test(cc, p);
 
+                    Geom::Point pt2g = to_2geom(p);
+
                     if (!cc->sid) {
                         // This is the first point, so just snap it to the grid
                         // as there's no other points to go off.
-                        SnapManager const &m = cc->desktop->namedview->snap_manager;
-                        p = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
-                                       p, NULL).getPoint();
+                        SnapManager &m = cc->desktop->namedview->snap_manager;
+                        m.setup(cc->desktop);
+                        m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);
                     }
-                    spcc_connector_set_initial_point(cc, p);
+                    spcc_connector_set_initial_point(cc, from_2geom(pt2g));
 
                 }
                 cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
@@ -567,7 +571,17 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
                 break;
         }
     } else if (bevent.button == 3) {
-        if (cc->npoints != 0) {
+        if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
+            // A context menu is going to be triggered here,
+            // so end the rerouting operation.
+            cc_connector_rerouting_finish(cc, &p);
+
+            cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+
+            // Don't set ret to TRUE, so we drop through to the
+            // parent handler which will open the context menu.
+        }
+        else if (cc->npoints != 0) {
             spcc_connector_finish(cc);
             ret = TRUE;
         }
@@ -580,18 +594,19 @@ static gint
 connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent)
 {
     gint ret = FALSE;
+    SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
-    if (mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
+    if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
         // allow middle-button scrolling
         return FALSE;
     }
 
-    NR::Point const event_w(mevent.x, mevent.y);
+    Geom::Point const event_w(mevent.x, mevent.y);
 
     if (connector_within_tolerance) {
-        gint const tolerance = prefs_get_int_attribute_limited("options.dragtolerance",
-                                                               "value", 0, 0, 100);
-        if ( NR::LInfty( event_w - connector_drag_origin_w ) < tolerance ) {
+        gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+        if ( Geom::LInfty( event_w - connector_drag_origin_w ) < tolerance ) {
             return FALSE;   // Do not drag if we're within tolerance from origin.
         }
     }
@@ -603,7 +618,7 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons
     SPDesktop *const dt = cc->desktop;
 
     /* Find desktop coordinates */
-    NR::Point p = dt->w2d(event_w);
+    Geom::Point p = dt->w2d(event_w);
 
     switch (cc->state) {
         case SP_CONNECTOR_CONTEXT_DRAGGING:
@@ -622,23 +637,23 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons
             g_assert( SP_IS_PATH(cc->clickeditem));
 
             // Update the hidden path
-            NR::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
-            NR::Matrix d2i = i2d.inverse();
+            Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
+            Geom::Matrix d2i = i2d.inverse();
             SPPath *path = SP_PATH(cc->clickeditem);
             SPCurve *curve = (SP_SHAPE(path))->curve;
             if (cc->clickedhandle == cc->endpt_handle[0]) {
-                NR::Point o = cc->endpt_handle[1]->pos;
-                sp_curve_stretch_endpoints(curve, p * d2i, o * d2i);
+                Geom::Point o = cc->endpt_handle[1]->pos;
+                curve->stretch_endpoints(p * d2i, o * d2i);
             }
             else {
-                NR::Point o = cc->endpt_handle[0]->pos;
-                sp_curve_stretch_endpoints(curve, o * d2i, p * d2i);
+                Geom::Point o = cc->endpt_handle[0]->pos;
+                curve->stretch_endpoints(o * d2i, p * d2i);
             }
             sp_conn_adjust_path(path);
 
             // Copy this to the temporary visible path
-            cc->red_curve = sp_curve_copy(SP_SHAPE(path)->curve);
-            sp_curve_transform(cc->red_curve, i2d);
+            cc->red_curve = SP_SHAPE(path)->curve->copy();
+            cc->red_curve->transform(i2d);
 
             sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
             ret = TRUE;
@@ -659,15 +674,16 @@ static gint
 connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
 {
     gint ret = FALSE;
-    if ( revent.button == 1 ) {
+    SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
+    if ( revent.button == 1 && !event_context->space_panning ) {
 
         SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
         SPDocument *doc = sp_desktop_document(desktop);
 
-        NR::Point const event_w(revent.x, revent.y);
+        Geom::Point const event_w(revent.x, revent.y);
 
         /* Find desktop coordinates */
-        NR::Point p = cc->desktop->w2d(event_w);
+        Geom::Point p = cc->desktop->w2d(event_w);
 
         switch (cc->state) {
             //case SP_CONNECTOR_CONTEXT_POINT:
@@ -692,30 +708,8 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
             }
             case SP_CONNECTOR_CONTEXT_REROUTING:
             {
-                // Clear the temporary path:
-                sp_curve_reset(cc->red_curve);
-                sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
+                cc_connector_rerouting_finish(cc, &p);
 
-                // Test whether we clicked on a connection point
-                gchar *shape_label = conn_pt_handle_test(cc, p);
-
-                if (shape_label) {
-                    if (cc->clickedhandle == cc->endpt_handle[0]) {
-                        sp_object_setAttribute(cc->clickeditem,
-                                "inkscape:connection-start",shape_label, false);
-                    }
-                    else {
-                        sp_object_setAttribute(cc->clickeditem,
-                                "inkscape:connection-end",shape_label, false);
-                    }
-                    g_free(shape_label);
-                }
-                cc->clickeditem->setHidden(false);
-                sp_conn_adjust_path(SP_PATH(cc->clickeditem));
-                cc->clickeditem->updateRepr();
-                sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, 
-                                 _("Reroute connector"));
-                cc_set_active_conn(cc, cc->clickeditem);
                 sp_document_ensure_up_to_date(doc);
                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
                 return TRUE;
@@ -748,7 +742,21 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
             }
             break;
         case GDK_Escape:
-            if (cc->npoints != 0) {
+            if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
+
+                SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
+                SPDocument *doc = sp_desktop_document(desktop);
+
+                cc_connector_rerouting_finish(cc, NULL);
+
+                sp_document_undo(doc);
+
+                cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
+                        _("Connector endpoint drag cancelled."));
+                ret = TRUE;
+            }
+            else if (cc->npoints != 0) {
                 // if drawing, cancel, otherwise pass it up for deselecting
                 cc->state = SP_CONNECTOR_CONTEXT_STOP;
                 spcc_reset_colors(cc);
@@ -762,20 +770,56 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
 }
 
 
+static void
+cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p)
+{
+    SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
+    SPDocument *doc = sp_desktop_document(desktop);
+
+    // Clear the temporary path:
+    cc->red_curve->reset();
+    sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
+
+    if (p != NULL)
+    {
+        // Test whether we clicked on a connection point
+        gchar *shape_label = conn_pt_handle_test(cc, *p);
+
+        if (shape_label) {
+            if (cc->clickedhandle == cc->endpt_handle[0]) {
+                sp_object_setAttribute(cc->clickeditem,
+                        "inkscape:connection-start",shape_label, false);
+            }
+            else {
+                sp_object_setAttribute(cc->clickeditem,
+                        "inkscape:connection-end",shape_label, false);
+            }
+            g_free(shape_label);
+        }
+    }
+    cc->clickeditem->setHidden(false);
+    sp_conn_adjust_path(SP_PATH(cc->clickeditem));
+    cc->clickeditem->updateRepr();
+    sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
+                     _("Reroute connector"));
+    cc_set_active_conn(cc, cc->clickeditem);
+}
+
+
 static void
 spcc_reset_colors(SPConnectorContext *cc)
 {
     /* Red */
-    sp_curve_reset(cc->red_curve);
+    cc->red_curve->reset();
     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
 
-    sp_curve_reset(cc->green_curve);
+    cc->green_curve->reset();
     cc->npoints = 0;
 }
 
 
 static void
-spcc_connector_set_initial_point(SPConnectorContext *const cc, NR::Point const p)
+spcc_connector_set_initial_point(SPConnectorContext *const cc, Geom::Point const p)
 {
     g_assert( cc->npoints == 0 );
 
@@ -787,15 +831,15 @@ spcc_connector_set_initial_point(SPConnectorContext *const cc, NR::Point const p
 
 
 static void
-spcc_connector_set_subsequent_point(SPConnectorContext *const cc, NR::Point const p)
+spcc_connector_set_subsequent_point(SPConnectorContext *const cc, Geom::Point const p)
 {
     g_assert( cc->npoints != 0 );
 
     SPDesktop *dt = cc->desktop;
-    NR::Point o = dt->dt2doc(cc->p[0]);
-    NR::Point d = dt->dt2doc(p);
-    Avoid::Point src(o[NR::X], o[NR::Y]);
-    Avoid::Point dst(d[NR::X], d[NR::Y]);
+    Geom::Point o = dt->dt2doc(cc->p[0]);
+    Geom::Point d = dt->dt2doc(p);
+    Avoid::Point src(o[Geom::X], o[Geom::Y]);
+    Avoid::Point dst(d[Geom::X], d[Geom::Y]);
 
     if (!cc->newConnRef) {
         Avoid::Router *router = sp_desktop_document(dt)->router;
@@ -810,15 +854,15 @@ spcc_connector_set_subsequent_point(SPConnectorContext *const cc, NR::Point cons
     Avoid::PolyLine route = cc->newConnRef->route();
     cc->newConnRef->calcRouteDist();
 
-    sp_curve_reset(cc->red_curve);
-    NR::Point pt(route.ps[0].x, route.ps[0].y);
-    sp_curve_moveto(cc->red_curve, pt);
+    cc->red_curve->reset();
+    Geom::Point pt(route.ps[0].x, route.ps[0].y);
+    cc->red_curve->moveto(pt);
 
     for (int i = 1; i < route.pn; ++i) {
-        NR::Point p(route.ps[i].x, route.ps[i].y);
-        sp_curve_lineto(cc->red_curve, p);
+        Geom::Point p(route.ps[i].x, route.ps[i].y);
+        cc->red_curve->lineto(p);
     }
-    sp_curve_transform(cc->red_curve, dt->doc2dt());
+    cc->red_curve->transform(dt->doc2dt());
     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
 }
 
@@ -832,19 +876,19 @@ static void
 spcc_concat_colors_and_flush(SPConnectorContext *cc)
 {
     SPCurve *c = cc->green_curve;
-    cc->green_curve = sp_curve_new_sized(64);
+    cc->green_curve = new SPCurve();
 
-    sp_curve_reset(cc->red_curve);
+    cc->red_curve->reset();
     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
 
-    if (sp_curve_empty(c)) {
-        sp_curve_unref(c);
+    if (c->is_empty()) {
+        c->unref();
         return;
     }
 
     spcc_flush_white(cc, c);
 
-    sp_curve_unref(c);
+    c->unref();
 }
 
 
@@ -863,26 +907,26 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
 
     if (gc) {
         c = gc;
-        sp_curve_ref(c);
+        c->ref();
     } else {
         return;
     }
 
     /* Now we have to go back to item coordinates at last */
-    sp_curve_transform(c,
-            sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(cc)));
+    c->transform(sp_desktop_dt2doc_affine(SP_EVENT_CONTEXT_DESKTOP(cc)));
 
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
     SPDocument *doc = sp_desktop_document(desktop);
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
 
-    if ( c && !sp_curve_empty(c) ) {
+    if ( c && !c->is_empty() ) {
         /* We actually have something to write */
 
-        Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+        Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
         /* Set style */
-        sp_desktop_apply_style_tool(desktop, repr, "tools.connector", false);
+        sp_desktop_apply_style_tool(desktop, repr, "/tools/connector", false);
 
-        gchar *str = sp_svg_write_path(SP_CURVE_BPATH(c));
+        gchar *str = sp_svg_write_path( c->get_pathvector() );
         g_assert( str != NULL );
         repr->setAttribute("d", str);
         g_free(str);
@@ -891,7 +935,7 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
         cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
         cc->selection->set(repr);
         Inkscape::GC::release(repr);
-        cc->newconn->transform = i2i_affine(desktop->currentRoot(), desktop->currentLayer());
+        cc->newconn->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
         cc->newconn->updateRepr();
 
         bool connection = false;
@@ -918,7 +962,7 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
         cc->newconn->updateRepr();
     }
 
-    sp_curve_unref(c);
+    c->unref();
 
     /* Flush pending updates */
     sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector"));
@@ -927,16 +971,16 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
 
 
 static void
-spcc_connector_finish_segment(SPConnectorContext *const cc, NR::Point const p)
+spcc_connector_finish_segment(SPConnectorContext *const cc, Geom::Point const /*p*/)
 {
-    if (!sp_curve_empty(cc->red_curve)) {
-        sp_curve_append_continuous(cc->green_curve, cc->red_curve, 0.0625);
+    if (!cc->red_curve->is_empty()) {
+        cc->green_curve->append_continuous(cc->red_curve, 0.0625);
 
         cc->p[0] = cc->p[3];
         cc->p[1] = cc->p[4];
         cc->npoints = 2;
 
-        sp_curve_reset(cc->red_curve);
+        cc->red_curve->reset();
     }
 }
 
@@ -947,7 +991,7 @@ spcc_connector_finish(SPConnectorContext *const cc)
     SPDesktop *const desktop = cc->desktop;
     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector"));
 
-    sp_curve_reset(cc->red_curve);
+    cc->red_curve->reset();
     spcc_concat_colors_and_flush(cc);
 
     cc->npoints = 0;
@@ -965,7 +1009,7 @@ static gboolean
 cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
 {
     g_assert (knot != NULL);
-    
+
     g_object_ref(knot);
 
     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(
@@ -976,7 +1020,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
     switch (event->type) {
         case GDK_ENTER_NOTIFY:
             sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE);
-            
+
             cc->active_handle = knot;
 
             if (knot->tip)
@@ -984,24 +1028,24 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
                 knot->desktop->event_context->defaultMessageContext()->set(
                         Inkscape::NORMAL_MESSAGE, knot->tip);
             }
-            
+
             consumed = TRUE;
             break;
         case GDK_LEAVE_NOTIFY:
             sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE);
 
             cc->active_handle = NULL;
-            
+
             if (knot->tip) {
                 knot->desktop->event_context->defaultMessageContext()->clear();
             }
-            
+
             consumed = TRUE;
             break;
         default:
             break;
     }
-    
+
     g_object_unref(knot);
 
     return consumed;
@@ -1009,7 +1053,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
 
 
 static gboolean
-endpt_handler(SPKnot *knot, GdkEvent *event, SPConnectorContext *cc)
+endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc)
 {
     g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
 
@@ -1029,7 +1073,7 @@ endpt_handler(SPKnot *knot, GdkEvent *event, SPConnectorContext *cc)
                 unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1;
                 sp_conn_end_detach(cc->clickeditem, ind);
 
-                NR::Point origin;
+                Geom::Point origin;
                 if (cc->clickedhandle == cc->endpt_handle[0]) {
                     origin = cc->endpt_handle[1]->pos;
                 }
@@ -1038,11 +1082,10 @@ endpt_handler(SPKnot *knot, GdkEvent *event, SPConnectorContext *cc)
                 }
 
                 // Show the red path for dragging.
-                cc->red_curve = sp_curve_copy(SP_PATH(cc->clickeditem)->curve);
-                NR::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
-                sp_curve_transform(cc->red_curve, i2d);
-                sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath),
-                        cc->red_curve);
+                cc->red_curve = SP_PATH(cc->clickeditem)->curve->copy();
+                Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
+                cc->red_curve->transform(i2d);
+                sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
 
                 cc->clickeditem->setHidden(true);
 
@@ -1088,7 +1131,7 @@ static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item)
 
     // Set center connection point.
     if ( cc->connpthandle == NULL ) {
-        SPKnot *knot = sp_knot_new(cc->desktop, 
+        SPKnot *knot = sp_knot_new(cc->desktop,
                 _("<b>Connection point</b>: click or drag to create a new connector"));
 
         knot->setShape(SP_KNOT_SHAPE_SQUARE);
@@ -1110,12 +1153,14 @@ static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item)
     }
 
 
-    NR::Rect bbox = sp_item_bbox_desktop(cc->active_shape);
-    NR::Point center = bbox.midpoint();
-    sp_knot_set_position(cc->connpthandle, &center, 0);
-
-    sp_knot_show(cc->connpthandle);
-
+    Geom::OptRect bbox = sp_item_bbox_desktop(cc->active_shape);
+    if (bbox) {
+        Geom::Point center = bbox->midpoint();
+        sp_knot_set_position(cc->connpthandle, center, 0);
+        sp_knot_show(cc->connpthandle);
+    } else {
+        sp_knot_hide(cc->connpthandle);
+    }
 }
 
 
@@ -1125,16 +1170,16 @@ cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
     g_assert( SP_IS_PATH(item) );
 
     SPCurve *curve = SP_SHAPE(SP_PATH(item))->curve;
-    NR::Matrix i2d = sp_item_i2d_affine(item);
+    Geom::Matrix i2d = sp_item_i2d_affine(item);
 
     if (cc->active_conn == item)
     {
         // Just adjust handle positions.
-        NR::Point startpt = sp_curve_first_point(curve) * i2d;
-        sp_knot_set_position(cc->endpt_handle[0], &startpt, 0);
+        Geom::Point startpt = *(curve->first_point()) * i2d;
+        sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
 
-        NR::Point endpt = sp_curve_last_point(curve) * i2d;
-        sp_knot_set_position(cc->endpt_handle[1], &endpt, 0);
+        Geom::Point endpt = *(curve->last_point()) * i2d;
+        sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
 
         return;
     }
@@ -1159,7 +1204,7 @@ cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
 
         // Create the handle if it doesn't exist
         if ( cc->endpt_handle[i] == NULL ) {
-            SPKnot *knot = sp_knot_new(cc->desktop, 
+            SPKnot *knot = sp_knot_new(cc->desktop,
                     _("<b>Connector endpoint</b>: drag to reroute or connect to new shapes"));
 
             knot->setShape(SP_KNOT_SHAPE_SQUARE);
@@ -1197,11 +1242,11 @@ cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
                 G_CALLBACK(endpt_handler), cc);
     }
 
-    NR::Point startpt = sp_curve_first_point(curve) * i2d;
-    sp_knot_set_position(cc->endpt_handle[0], &startpt, 0);
+    Geom::Point startpt = *(curve->first_point()) * i2d;
+    sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
 
-    NR::Point endpt = sp_curve_last_point(curve) * i2d;
-    sp_knot_set_position(cc->endpt_handle[1], &endpt, 0);
+    Geom::Point endpt = *(curve->last_point()) * i2d;
+    sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
 
     sp_knot_show(cc->endpt_handle[0]);
     sp_knot_show(cc->endpt_handle[1]);
@@ -1212,13 +1257,14 @@ static bool cc_item_is_shape(SPItem *item)
 {
     if (SP_IS_PATH(item)) {
         SPCurve *curve = (SP_SHAPE(item))->curve;
-        if ( curve && !(curve->closed) ) {
+        if ( curve && !(curve->is_closed()) ) {
             // Open paths are connectors.
             return false;
         }
     }
     else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
-        if (prefs_get_int_attribute("tools.connector", "ignoretext", 1) == 1) {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        if (prefs->getBool("/tools/connector/ignoretext", true)) {
             // Don't count text as a shape we can connect connector to.
             return false;
         }
@@ -1231,7 +1277,7 @@ bool cc_item_is_connector(SPItem *item)
 {
     if (SP_IS_PATH(item)) {
         if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) {
-            g_assert( !(SP_SHAPE(item)->curve->closed) );
+            g_assert( !(SP_SHAPE(item)->curve->is_closed()) );
             return true;
         }
     }
@@ -1308,8 +1354,8 @@ cc_selection_changed(Inkscape::Selection *selection, gpointer data)
 
 
 static void
-shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child,
-        Inkscape::XML::Node *ref, gpointer data)
+shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
+                         Inkscape::XML::Node */*ref*/, gpointer data)
 {
     g_assert(data);
     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
@@ -1323,8 +1369,8 @@ shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child,
 
 static void
 shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
-                            gchar const *old_value, gchar const *new_value,
-                            bool is_interactive, gpointer data)
+                         gchar const */*old_value*/, gchar const */*new_value*/,
+                         bool /*is_interactive*/, gpointer data)
 {
     g_assert(data);
     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);