Code

Patch by Luca for 449709
[inkscape.git] / src / connector-context.cpp
index 8260456d4bad10d9e563249582a461a495b22c5a..2131bdced797be78964e0e798c769ba9535f06d7 100644 (file)
@@ -52,7 +52,6 @@
 #include "svg/svg.h"
 #include "desktop.h"
 #include "desktop-style.h"
-#include "desktop-affine.h"
 #include "desktop-handles.h"
 #include "document.h"
 #include "message-context.h"
@@ -300,6 +299,7 @@ sp_connector_context_finish(SPEventContext *ec)
     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
 
     spcc_connector_finish(cc);
+    cc->state = SP_CONNECTOR_CONTEXT_IDLE;
 
     if (((SPEventContextClass *) parent_class)->finish) {
         ((SPEventContextClass *) parent_class)->finish(ec);
@@ -409,6 +409,7 @@ sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, G
                 {
                     spcc_reset_colors(cc);
                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                    sp_event_context_discard_delayed_snap_event(event_context);
                 }
                 if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) {
                     // Doing simething else like rerouting.
@@ -424,6 +425,7 @@ sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, G
                     cc->selection->set(item_ungrouped);
                 }
                 ret = TRUE;
+
             }
             break;
         case GDK_ENTER_NOTIFY:
@@ -460,7 +462,7 @@ sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event)
             break;
 
         case GDK_MOTION_NOTIFY:
-            ret = connector_handle_motion_notify(cc, event->motion);
+               ret = connector_handle_motion_notify(cc, event->motion);
             break;
 
         case GDK_BUTTON_RELEASE:
@@ -509,6 +511,10 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
         connector_within_tolerance = true;
 
         Geom::Point const event_dt = cc->desktop->w2d(event_w);
+
+        SnapManager &m = cc->desktop->namedview->snap_manager;
+               m.setup(cc->desktop);
+
         switch (cc->state) {
             case SP_CONNECTOR_CONTEXT_STOP:
                 /* This is allowed, if we just cancelled curve */
@@ -525,17 +531,13 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
 
                     // 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 &m = cc->desktop->namedview->snap_manager;
-                        m.setup(cc->desktop);
-                        m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);
+                        m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
                     }
-                    spcc_connector_set_initial_point(cc, from_2geom(pt2g));
+                    spcc_connector_set_initial_point(cc, p);
 
                 }
                 cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
@@ -545,6 +547,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
             case SP_CONNECTOR_CONTEXT_DRAGGING:
             {
                 // This is the second click of a connector creation.
+               m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
 
                 spcc_connector_set_subsequent_point(cc, p);
                 spcc_connector_finish_segment(cc, p);
@@ -555,6 +558,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
                 }
                 cc_set_active_conn(cc, cc->newconn);
                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                sp_event_context_discard_delayed_snap_event(event_context);
                 ret = TRUE;
                 break;
             }
@@ -568,17 +572,20 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
         }
     } else if (bevent.button == 3) {
         if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
-            // A context menu is going to be triggered here, 
+            // 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;
-            
+            sp_event_context_discard_delayed_snap_event(event_context);
+
             // 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);
+            cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+            sp_event_context_discard_delayed_snap_event(event_context);
             ret = TRUE;
         }
     }
@@ -616,13 +623,16 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons
     /* Find desktop coordinates */
     Geom::Point p = dt->w2d(event_w);
 
+    SnapManager &m = dt->namedview->snap_manager;
+       m.setup(dt);
+
     switch (cc->state) {
         case SP_CONNECTOR_CONTEXT_DRAGGING:
         {
             // This is movement during a connector creation.
-
-            if ( cc->npoints > 0 ) {
-                cc->selection->clear();
+               if ( cc->npoints > 0 ) {
+                       m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
+                       cc->selection->clear();
                 spcc_connector_set_subsequent_point(cc, p);
                 ret = TRUE;
             }
@@ -632,6 +642,8 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons
         {
             g_assert( SP_IS_PATH(cc->clickeditem));
 
+            m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
+
             // Update the hidden path
             Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
             Geom::Matrix d2i = i2d.inverse();
@@ -673,9 +685,12 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
     SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
     if ( revent.button == 1 && !event_context->space_panning ) {
 
-        SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
+       SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
         SPDocument *doc = sp_desktop_document(desktop);
 
+        SnapManager &m = desktop->namedview->snap_manager;
+               m.setup(desktop);
+
         Geom::Point const event_w(revent.x, revent.y);
 
         /* Find desktop coordinates */
@@ -685,7 +700,9 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
             //case SP_CONNECTOR_CONTEXT_POINT:
             case SP_CONNECTOR_CONTEXT_DRAGGING:
             {
-                if (connector_within_tolerance)
+               m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
+
+               if (connector_within_tolerance)
                 {
                     spcc_connector_finish_segment(cc, p);
                     return TRUE;
@@ -700,14 +717,17 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
                 }
                 cc_set_active_conn(cc, cc->newconn);
                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                sp_event_context_discard_delayed_snap_event(event_context);
                 break;
             }
             case SP_CONNECTOR_CONTEXT_REROUTING:
             {
-                cc_connector_rerouting_finish(cc, &p);
-                
+               m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, Inkscape::SNAPSOURCE_HANDLE);
+               cc_connector_rerouting_finish(cc, &p);
+
                 sp_document_ensure_up_to_date(doc);
                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                sp_event_context_discard_delayed_snap_event(event_context);
                 return TRUE;
                 break;
             }
@@ -734,20 +754,23 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
         case GDK_KP_Enter:
             if (cc->npoints != 0) {
                 spcc_connector_finish(cc);
+                cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+                sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc));
                 ret = TRUE;
             }
             break;
         case GDK_Escape:
             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;
+                sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc));
                 desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
                         _("Connector endpoint drag cancelled."));
                 ret = TRUE;
@@ -755,6 +778,7 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
             else if (cc->npoints != 0) {
                 // if drawing, cancel, otherwise pass it up for deselecting
                 cc->state = SP_CONNECTOR_CONTEXT_STOP;
+                sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(cc));
                 spcc_reset_colors(cc);
                 ret = TRUE;
             }
@@ -771,7 +795,7 @@ 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);
@@ -796,7 +820,7 @@ cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p
     cc->clickeditem->setHidden(false);
     sp_conn_adjust_path(SP_PATH(cc->clickeditem));
     cc->clickeditem->updateRepr();
-    sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, 
+    sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
                      _("Reroute connector"));
     cc_set_active_conn(cc, cc->clickeditem);
 }
@@ -909,7 +933,7 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
     }
 
     /* Now we have to go back to item coordinates at last */
-    c->transform(sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(cc)));
+    c->transform(SP_EVENT_CONTEXT_DESKTOP(cc)->dt2doc());
 
     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
     SPDocument *doc = sp_desktop_document(desktop);
@@ -931,7 +955,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;
@@ -997,7 +1021,6 @@ spcc_connector_finish(SPConnectorContext *const cc)
         delete cc->newConnRef;
         cc->newConnRef = NULL;
     }
-    cc->state = SP_CONNECTOR_CONTEXT_IDLE;
 }
 
 
@@ -1005,7 +1028,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(
@@ -1016,7 +1039,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)
@@ -1024,24 +1047,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;
@@ -1127,7 +1150,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);
@@ -1200,7 +1223,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);