Code

remove desktop-affine.cpp
[inkscape.git] / src / arc-context.cpp
index d7982e979d2e4a494c1dddf7cf20f0fa45440957..da236ae8730672f7b1278afed563edd3a4538b39 100644 (file)
@@ -40,6 +40,7 @@
 #include "desktop-style.h"
 #include "context-fns.h"
 #include "verbs.h"
+#include "shape-editor.h"
 
 #include "arc-context.h"
 
@@ -103,9 +104,6 @@ static void sp_arc_context_init(SPArcContext *arc_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     arc_context->item = NULL;
 
     new (&arc_context->sel_changed_connection) sigc::connection();
@@ -121,16 +119,8 @@ static void sp_arc_context_dispose(GObject *object)
     ac->sel_changed_connection.disconnect();
     ac->sel_changed_connection.~connection();
 
-    if (ec->shape_knot_holder) {
-        delete ec->shape_knot_holder;
-        ec->shape_knot_holder = NULL;
-    }
-
-    if (ec->shape_repr) { // remove old listener
-        sp_repr_remove_listener_by_data(ec->shape_repr, ec);
-        Inkscape::GC::release(ec->shape_repr);
-        ec->shape_repr = 0;
-    }
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
 
     /* fixme: This is necessary because we do not grab */
     if (ac->item) {
@@ -142,14 +132,6 @@ static void sp_arc_context_dispose(GObject *object)
     G_OBJECT_CLASS(parent_class)->dispose(object);
 }
 
-static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
-    NULL, /* child_added */
-    NULL, /* child_removed */
-    ec_shape_event_attr_changed,
-    NULL, /* content_changed */
-    NULL  /* order_changed */
-};
-
 /**
 \brief  Callback that processes the "changed" signal on the selection;
 destroys old and creates new knotholder.
@@ -159,27 +141,9 @@ void sp_arc_context_selection_changed(Inkscape::Selection * selection, gpointer
     SPArcContext *ac = SP_ARC_CONTEXT(data);
     SPEventContext *ec = SP_EVENT_CONTEXT(ac);
 
-    if (ec->shape_knot_holder) { // desktroy knotholder
-        delete ec->shape_knot_holder;
-        ec->shape_knot_holder = NULL;
-    }
-
-    if (ec->shape_repr) { // remove old listener
-        sp_repr_remove_listener_by_data(ec->shape_repr, ec);
-        Inkscape::GC::release(ec->shape_repr);
-        ec->shape_repr = 0;
-    }
-
-    SPItem *item = selection ? selection->singleItem() : NULL;
-    if (item) {
-        ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
-        Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
-        if (shape_repr) {
-            ec->shape_repr = shape_repr;
-            Inkscape::GC::anchor(shape_repr);
-            sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-        }
-    }
+    ec->shape_editor->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem();
+    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 }
 
 static void sp_arc_context_setup(SPEventContext *ec)
@@ -191,16 +155,11 @@ static void sp_arc_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
-    SPItem *item = selection->singleItem();
+    ec->shape_editor = new ShapeEditor(ec->desktop);
 
+    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
     if (item) {
-        ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
-        Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
-        if (shape_repr) {
-            ec->shape_repr = shape_repr;
-            Inkscape::GC::anchor(shape_repr);
-            sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-        }
+        ec->shape_editor->set_item(item, SH_KNOTHOLDER);
     }
 
     ac->sel_changed_connection.disconnect();
@@ -262,8 +221,9 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
             if (event->button.button == 1 && !event_context->space_panning) {
 
                 dragging = true;
+                sp_canvas_set_snap_delay_active(desktop->canvas, true);
                 ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
-                
+
                 /* Snap center */
                 SnapManager &m = desktop->namedview->snap_manager;
                 m.setup(desktop);
@@ -293,7 +253,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
 
                 Geom::Point const motion_w(event->motion.x, event->motion.y);
                 Geom::Point motion_dt(desktop->w2d(motion_w));
-                
+
                 sp_arc_drag(ac, motion_dt, event->motion.state);
 
                 gobble_motion_events(GDK_BUTTON1_MASK);
@@ -305,6 +265,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
             event_context->xp = event_context->yp = 0;
             if (event->button.button == 1 && !event_context->space_panning) {
                 dragging = false;
+                sp_canvas_set_snap_delay_active(desktop->canvas, false);
                 if (!event_context->within_tolerance) {
                     // we've been dragging, finish the arc
                     sp_arc_finish(ac);
@@ -368,6 +329,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                         sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
                                               event->button.time);
                         dragging = false;
+                        sp_canvas_set_snap_delay_active(desktop->canvas, false);
                         if (!event_context->within_tolerance) {
                             // we've been dragging, finish the rect
                             sp_arc_finish(ac);
@@ -503,9 +465,9 @@ static void sp_arc_finish(SPArcContext *ac)
         SP_OBJECT(ac->item)->updateRepr();
 
         sp_canvas_end_forced_full_redraws(desktop->canvas);
-        
+
         sp_desktop_selection(desktop)->set(ac->item);
-        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC, 
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
                          _("Create ellipse"));
 
         ac->item = NULL;