Code

switch to using shape_editor, instead of separate knotholders and listeners; fixes...
authorbuliabyak <buliabyak@users.sourceforge.net>
Thu, 8 Jan 2009 05:37:37 +0000 (05:37 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Thu, 8 Jan 2009 05:37:37 +0000 (05:37 +0000)
src/arc-context.cpp
src/box3d-context.cpp
src/flood-context.cpp
src/rect-context.cpp
src/spiral-context.cpp
src/star-context.cpp
src/text-context.cpp
src/vanishing-point.cpp

index d7982e979d2e4a494c1dddf7cf20f0fa45440957..3c8a50192fc2c3124ee5fa0c51a9aca5ce4602e2 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();
index 404723231d80bf4bc4309f9e11b81528fd776695..2d20318e36cd5bae58bfb56612adbd5c21b953d7 100644 (file)
@@ -47,6 +47,7 @@
 #include "box3d-side.h"
 #include "document-private.h"
 #include "line-geometry.h"
+#include "shape-editor.h"
 
 static void sp_box3d_context_class_init(Box3DContextClass *klass);
 static void sp_box3d_context_init(Box3DContext *box3d_context);
@@ -108,9 +109,6 @@ static void sp_box3d_context_init(Box3DContext *box3d_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     box3d_context->item = NULL;
 
     box3d_context->ctrl_dragged = false;
@@ -134,22 +132,14 @@ static void sp_box3d_context_dispose(GObject *object)
     bc->sel_changed_connection.disconnect();
     bc->sel_changed_connection.~connection();
 
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
+
     /* fixme: This is necessary because we do not grab */
     if (bc->item) {
         sp_box3d_finish(bc);
     }
 
-    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;
-    }
-
     if (bc->_message_context) {
         delete bc->_message_context;
     }
@@ -157,14 +147,6 @@ static void sp_box3d_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
@@ -174,27 +156,9 @@ static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, g
     Box3DContext *bc = SP_BOX3D_CONTEXT(data);
     SPEventContext *ec = SP_EVENT_CONTEXT(bc);
 
-    if (ec->shape_knot_holder) { // destroy 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->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->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem(); 
+    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 
     if (selection->perspList().size() == 1) {
         // selecting a single box changes the current perspective
@@ -230,15 +194,11 @@ static void sp_box3d_context_setup(SPEventContext *ec)
 
     sp_box3d_context_check_for_persp_in_defs(sp_desktop_document (ec->desktop));
 
+    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);
     }
 
     bc->sel_changed_connection.disconnect();
index a45ec5dfe79569b53d5e19359789447216322e76..7b622338480a85124c78052ed2f9f4c0c68029b3 100644 (file)
@@ -46,6 +46,7 @@
 #include "preferences.h"
 #include "context-fns.h"
 #include "rubberband.h"
+#include "shape-editor.h"
 
 #include "display/nr-arena-item.h"
 #include "display/nr-arena.h"
@@ -133,9 +134,6 @@ static void sp_flood_context_init(SPFloodContext *flood_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     flood_context->item = NULL;
 
     new (&flood_context->sel_changed_connection) sigc::connection();
@@ -149,17 +147,14 @@ static void sp_flood_context_dispose(GObject *object)
     rc->sel_changed_connection.disconnect();
     rc->sel_changed_connection.~connection();
 
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
+
     /* fixme: This is necessary because we do not grab */
     if (rc->item) {
         sp_flood_finish(rc);
     }
 
-    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;
-    }
-
     if (rc->_message_context) {
         delete rc->_message_context;
     }
@@ -167,14 +162,6 @@ static void sp_flood_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
@@ -184,21 +171,9 @@ void sp_flood_context_selection_changed(Inkscape::Selection *selection, gpointer
     SPFloodContext *rc = SP_FLOOD_CONTEXT(data);
     SPEventContext *ec = SP_EVENT_CONTEXT(rc);
 
-    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->singleItem();
-    if (item) {
-        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_flood_context_setup(SPEventContext *ec)
@@ -209,14 +184,11 @@ static void sp_flood_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
+    ec->shape_editor = new ShapeEditor(ec->desktop);
+
     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
     if (item) {
-        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);
     }
 
     rc->sel_changed_connection.disconnect();
index 1d8e8c12b02cc6c3207dedff98e8238bfad7fe93..65292851be4c59c79e1a67957a456af8248ea2a5 100644 (file)
@@ -41,6 +41,7 @@
 #include "xml/node-event-vector.h"
 #include "preferences.h"
 #include "context-fns.h"
+#include "shape-editor.h"
 
 //static const double goldenratio = 1.61803398874989484820; // golden ratio
 
@@ -107,9 +108,6 @@ static void sp_rect_context_init(SPRectContext *rect_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     rect_context->item = NULL;
 
     rect_context->rx = 0.0;
@@ -128,22 +126,14 @@ static void sp_rect_context_dispose(GObject *object)
     rc->sel_changed_connection.disconnect();
     rc->sel_changed_connection.~connection();
 
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
+
     /* fixme: This is necessary because we do not grab */
     if (rc->item) {
         sp_rect_finish(rc);
     }
 
-    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;
-    }
-
     if (rc->_message_context) {
         delete rc->_message_context;
     }
@@ -151,14 +141,6 @@ static void sp_rect_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
@@ -168,27 +150,9 @@ void sp_rect_context_selection_changed(Inkscape::Selection *selection, gpointer
     SPRectContext *rc = SP_RECT_CONTEXT(data);
     SPEventContext *ec = SP_EVENT_CONTEXT(rc);
 
-    if (ec->shape_knot_holder) { // destroy 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->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->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem(); 
+    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 }
 
 static void sp_rect_context_setup(SPEventContext *ec)
@@ -199,15 +163,11 @@ static void sp_rect_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
+    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);
     }
 
     rc->sel_changed_connection.disconnect();
index 9944e86b4a99d76a77754acc257d34465e6fe2e7..ce9ea1e03fabbbafb96c4c71eac50a72d188fc89 100644 (file)
@@ -41,6 +41,7 @@
 #include "xml/node-event-vector.h"
 #include "preferences.h"
 #include "context-fns.h"
+#include "shape-editor.h"
 
 static void sp_spiral_context_class_init(SPSpiralContextClass * klass);
 static void sp_spiral_context_init(SPSpiralContext *spiral_context);
@@ -104,9 +105,6 @@ sp_spiral_context_init(SPSpiralContext *spiral_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     spiral_context->item = NULL;
 
     spiral_context->revo = 3.0;
@@ -127,20 +125,12 @@ sp_spiral_context_dispose(GObject *object)
     sc->sel_changed_connection.disconnect();
     sc->sel_changed_connection.~connection();
 
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
+
     /* fixme: This is necessary because we do not grab */
     if (sc->item) sp_spiral_finish(sc);
 
-    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;
-    }
-
     if (sc->_message_context) {
         delete sc->_message_context;
     }
@@ -148,14 +138,6 @@ sp_spiral_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
@@ -166,27 +148,9 @@ sp_spiral_context_selection_changed(Inkscape::Selection *selection, gpointer dat
     SPSpiralContext *sc = SP_SPIRAL_CONTEXT(data);
     SPEventContext *ec = SP_EVENT_CONTEXT(sc);
 
-    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->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->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem(); 
+    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 }
 
 static void
@@ -201,19 +165,14 @@ sp_spiral_context_setup(SPEventContext *ec)
     sp_event_context_read(ec, "revolution");
     sp_event_context_read(ec, "t0");
 
-    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
+    ec->shape_editor = new ShapeEditor(ec->desktop);
 
-    SPItem *item = selection->singleItem();
+    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);
     }
 
+    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
     sc->sel_changed_connection.disconnect();
     sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_spiral_context_selection_changed), (gpointer)sc));
 
index 33224d7fdc3b69ddbfaf3b0d49444a121c57ecb9..9dc2db296dcb978d09c40f14b2d9edf518051107 100644 (file)
@@ -43,6 +43,7 @@
 #include "xml/node-event-vector.h"
 #include "object-edit.h"
 #include "context-fns.h"
+#include "shape-editor.h"
 
 #include "star-context.h"
 
@@ -108,9 +109,6 @@ sp_star_context_init (SPStarContext * star_context)
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     star_context->item = NULL;
 
     star_context->magnitude = 5;
@@ -131,16 +129,8 @@ sp_star_context_dispose (GObject *object)
     sc->sel_changed_connection.disconnect();
     sc->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 (sc->item) sp_star_finish (sc);
@@ -152,14 +142,6 @@ sp_star_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
@@ -173,27 +155,9 @@ sp_star_context_selection_changed (Inkscape::Selection * selection, gpointer dat
     SPStarContext *sc = SP_STAR_CONTEXT (data);
     SPEventContext *ec = SP_EVENT_CONTEXT (sc);
 
-    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->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->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem(); 
+    ec->shape_editor->set_item(item, SH_KNOTHOLDER);
 }
 
 static void
@@ -210,19 +174,14 @@ sp_star_context_setup (SPEventContext *ec)
     sp_event_context_read (ec, "rounded");
     sp_event_context_read (ec, "randomized");
 
-    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
+    ec->shape_editor = new ShapeEditor(ec->desktop);
 
-    SPItem *item = selection->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);
-            }
-        }
+    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
+    if (item) {
+        ec->shape_editor->set_item(item, SH_KNOTHOLDER);
+    }
 
+    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
     sc->sel_changed_connection.disconnect();
     sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_star_context_selection_changed), (gpointer)sc));
 
index 96fa716cf997eef6d98e53ed5bf19a3e723d9d28..ad9211cbac0e363ef79d759c38fd2416288f3317 100644 (file)
@@ -49,6 +49,7 @@
 #include "sp-metrics.h"
 #include "context-fns.h"
 #include "verbs.h"
+#include "shape-editor.h"
 
 #include "text-editing.h"
 
@@ -131,9 +132,6 @@ sp_text_context_init(SPTextContext *tc)
     event_context->tolerance = 0;
     event_context->within_tolerance = false;
 
-    event_context->shape_repr = NULL;
-    event_context->shape_knot_holder = NULL;
-
     tc->imc = NULL;
 
     tc->text = NULL;
@@ -171,6 +169,10 @@ sp_text_context_dispose(GObject *obj)
     tc->style_set_connection.~connection();
     tc->sel_changed_connection.~connection();
     tc->sel_modified_connection.~connection();
+
+    delete ec->shape_editor;
+    ec->shape_editor = NULL;
+
     tc->text_sel_end.~iterator();
     tc->text_sel_start.~iterator();
     tc->text_selection_quads.~vector();
@@ -183,26 +185,8 @@ sp_text_context_dispose(GObject *obj)
     }
 
     Inkscape::Rubberband::get(ec->desktop)->stop();
-
-    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;
-    }
 }
 
-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 */
-};
-
 static void
 sp_text_context_setup(SPEventContext *ec)
 {
@@ -259,15 +243,11 @@ sp_text_context_setup(SPEventContext *ec)
     if (((SPEventContextClass *) parent_class)->setup)
         ((SPEventContextClass *) parent_class)->setup(ec);
 
+    ec->shape_editor = new ShapeEditor(ec->desktop);
+
     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
     if (item && SP_IS_FLOWTEXT (item) && SP_FLOWTEXT(item)->has_internal_frame()) {
-        ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
-        Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(SP_FLOWTEXT(item)->get_frame(NULL));
-        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);
     }
 
     tc->sel_changed_connection = sp_desktop_selection(desktop)->connectChanged(
@@ -1449,26 +1429,10 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, SPTextContext
 
     SPEventContext *ec = SP_EVENT_CONTEXT(tc);
 
-    if (ec->shape_knot_holder) { // destroy 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->singleItem();
+    ec->shape_editor->unset_item(SH_KNOTHOLDER);
+    SPItem *item = selection->singleItem(); 
     if (item && SP_IS_FLOWTEXT (item) && SP_FLOWTEXT(item)->has_internal_frame()) {
-        ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
-        Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(SP_FLOWTEXT(item)->get_frame(NULL));
-        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);
     }
 
     if (tc->text && (item != tc->text)) {
index c57232c74859f06aea965e7dc3e0d34c03f3e590..10f80fef1a206d3d790f59d44719b67c2d534551 100644 (file)
@@ -21,6 +21,7 @@
 #include "event-context.h"
 #include "xml/repr.h"
 #include "perspective-line.h"
+#include "shape-editor.h"
 
 #include "knotholder.h" // FIXME: can we avoid direct access to KnotHolder::update_knots?
 
@@ -614,8 +615,8 @@ VPDrag::updateBoxHandles ()
 
     SPEventContext *ec = inkscape_active_event_context();
     g_assert (ec != NULL);
-    if (ec->shape_knot_holder != NULL) {
-        ec->shape_knot_holder->update_knots();
+    if (ec->shape_editor != NULL) {
+        ec->shape_editor->update_knotholder();
     }
 }