Code

Connector tool: pointers should be nulled after snapping
[inkscape.git] / src / rect-context.cpp
index ef5881378fd0fd7b17fcafdfdc1ebacfc958426d..d60a6630bcd3991ca5dcc76fae583386cc258f74 100644 (file)
@@ -50,6 +50,7 @@ static void sp_rect_context_init(SPRectContext *rect_context);
 static void sp_rect_context_dispose(GObject *object);
 
 static void sp_rect_context_setup(SPEventContext *ec);
+static void sp_rect_context_finish(SPEventContext *ec);
 static void sp_rect_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
 
 static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent *event);
@@ -91,6 +92,7 @@ static void sp_rect_context_class_init(SPRectContextClass *klass)
     object_class->dispose = sp_rect_context_dispose;
 
     event_context_class->setup = sp_rect_context_setup;
+    event_context_class->finish = sp_rect_context_finish;
     event_context_class->set = sp_rect_context_set;
     event_context_class->root_handler  = sp_rect_context_root_handler;
     event_context_class->item_handler  = sp_rect_context_item_handler;
@@ -117,6 +119,21 @@ static void sp_rect_context_init(SPRectContext *rect_context)
     new (&rect_context->sel_changed_connection) sigc::connection();
 }
 
+static void sp_rect_context_finish(SPEventContext *ec)
+{
+    SPRectContext *rc = SP_RECT_CONTEXT(ec);
+    SPDesktop *desktop = ec->desktop;
+
+    sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
+    sp_rect_finish(rc);
+    rc->sel_changed_connection.disconnect();
+
+    if (((SPEventContextClass *) parent_class)->finish) {
+        ((SPEventContextClass *) parent_class)->finish(ec);
+    }
+}
+
+
 static void sp_rect_context_dispose(GObject *object)
 {
     SPRectContext *rc = SP_RECT_CONTEXT(object);
@@ -266,7 +283,8 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             /* Snap center */
             SnapManager &m = desktop->namedview->snap_manager;
             m.setup(desktop);
-            m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt, Inkscape::SNAPSOURCE_HANDLE);
+            m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
+            m.unSetup();
             rc->center = from_2geom(button_dt);
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
@@ -300,6 +318,15 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             sp_rect_drag(*rc, motion_dt, event->motion.state); // this will also handle the snapping
             gobble_motion_events(GDK_BUTTON1_MASK);
             ret = TRUE;
+        } else if (!sp_event_context_knot_mouseover(rc)) {
+            SnapManager &m = desktop->namedview->snap_manager;
+            m.setup(desktop);
+
+            Geom::Point const motion_w(event->motion.x, event->motion.y);
+            Geom::Point motion_dt(desktop->w2d(motion_w));
+
+            m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE));
+            m.unSetup();
         }
         break;
     case GDK_BUTTON_RELEASE:
@@ -372,14 +399,14 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             break;
 
         case GDK_Escape:
-               if (dragging) {
-                       dragging = false;
-                       sp_event_context_discard_delayed_snap_event(event_context);
-                       // if drawing, cancel, otherwise pass it up for deselecting
-                       sp_rect_cancel(rc);
-                       ret = TRUE;
-               }
-               break;
+            if (dragging) {
+                dragging = false;
+                sp_event_context_discard_delayed_snap_event(event_context);
+                // if drawing, cancel, otherwise pass it up for deselecting
+                sp_rect_cancel(rc);
+                ret = TRUE;
+            }
+            break;
 
         case GDK_space:
             if (dragging) {
@@ -510,8 +537,8 @@ static void sp_rect_finish(SPRectContext *rc)
     if ( rc->item != NULL ) {
         SPRect *rect = SP_RECT(rc->item);
         if (rect->width.computed == 0 || rect->height.computed == 0) {
-               sp_rect_cancel(rc); // Don't allow the creating of zero sized rectangle, for example when the start and and point snap to the snap grid point
-               return;
+            sp_rect_cancel(rc); // Don't allow the creating of zero sized rectangle, for example when the start and and point snap to the snap grid point
+            return;
         }
 
         SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
@@ -530,14 +557,14 @@ static void sp_rect_finish(SPRectContext *rc)
 
 static void sp_rect_cancel(SPRectContext *rc)
 {
-       SPDesktop *desktop = SP_EVENT_CONTEXT(rc)->desktop;
+    SPDesktop *desktop = SP_EVENT_CONTEXT(rc)->desktop;
 
-       sp_desktop_selection(desktop)->clear();
-       sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0);
+    sp_desktop_selection(desktop)->clear();
+    sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0);
 
     if (rc->item != NULL) {
-       SP_OBJECT(rc->item)->deleteObject();
-       rc->item = NULL;
+        SP_OBJECT(rc->item)->deleteObject();
+        rc->item = NULL;
     }
 
     rc->within_tolerance = false;