Code

Warning cleanup.
[inkscape.git] / src / star-context.cpp
index 33224d7fdc3b69ddbfaf3b0d49444a121c57ecb9..da79d4719a9852ce62e294b91516ac7e919f9750 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;
-    }
-
+    ec->shape_editor->unset_item(SH_KNOTHOLDER);
     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->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));
 
@@ -243,7 +202,7 @@ sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val)
 {
     SPStarContext *sc = SP_STAR_CONTEXT (ec);
     Glib::ustring path = val->getEntryName();
-    
+
     if (path == "magnitude") {
         sc->magnitude = CLAMP (val->getInt(5), 3, 1024);
     } else if (path == "proportion") {
@@ -276,9 +235,10 @@ static gint sp_star_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);
 
             sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
-            
+
             /* Snap center */
             SnapManager &m = desktop->namedview->snap_manager;
             m.setup(desktop, true);
@@ -310,7 +270,7 @@ static gint sp_star_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_star_drag (sc, motion_dt, event->motion.state);
 
             gobble_motion_events(GDK_BUTTON1_MASK);
@@ -322,6 +282,7 @@ static gint sp_star_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 star
                 sp_star_finish (sc);
@@ -381,6 +342,7 @@ static gint sp_star_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_star_finish(sc);
@@ -454,11 +416,11 @@ static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state)
     SnapManager &m = desktop->namedview->snap_manager;
     m.setup(desktop, true, sc->item);
     Geom::Point pt2g = to_2geom(p);
-    m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);    
-    
+    m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);
+
     Geom::Point const p0 = to_2geom(sp_desktop_dt2doc_xy_point(desktop, sc->center));
     Geom::Point const p1 = to_2geom(sp_desktop_dt2doc_xy_point(desktop, from_2geom(pt2g)));
-    
+
     SPStar *star = SP_STAR(sc->item);
 
     double const sides = (gdouble) sc->magnitude;
@@ -501,7 +463,7 @@ sp_star_finish (SPStarContext * sc)
         sp_canvas_end_forced_full_redraws(desktop->canvas);
 
         sp_desktop_selection(desktop)->set(sc->item);
-        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, 
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR,
                          _("Create star"));
 
         sc->item = NULL;