Code

Fix fallback icon loading order for icons with legacy names.
[inkscape.git] / src / arc-context.cpp
index e689c93db186669b3768243e8d755cb40536aa6a..1c480ecbc6efaeb971230fc2bce45977edf624a8 100644 (file)
@@ -6,6 +6,7 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <johan@shouraizou.nl>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2000-2006 Authors
  * Copyright (C) 2000-2001 Ximian, Inc.
@@ -45,6 +46,8 @@
 
 #include "arc-context.h"
 
+using Inkscape::DocumentUndo;
+
 static void sp_arc_context_class_init(SPArcContextClass *klass);
 static void sp_arc_context_init(SPArcContext *arc_context);
 static void sp_arc_context_dispose(GObject *object);
@@ -107,6 +110,7 @@ static void sp_arc_context_init(SPArcContext *arc_context)
     event_context->tolerance = 0;
     event_context->within_tolerance = false;
     event_context->item_to_select = NULL;
+    event_context->tool_url = "/tools/shapes/arc";
 
     arc_context->item = NULL;
 
@@ -116,15 +120,15 @@ static void sp_arc_context_init(SPArcContext *arc_context)
 static void sp_arc_context_finish(SPEventContext *ec)
 {
     SPArcContext *ac = SP_ARC_CONTEXT(ec);
-       SPDesktop *desktop = ec->desktop;
+    SPDesktop *desktop = ec->desktop;
 
-       sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
-       sp_arc_finish(ac);
+    sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
+    sp_arc_finish(ac);
     ac->sel_changed_connection.disconnect();
 
     if (((SPEventContextClass *) parent_class)->finish) {
-               ((SPEventContextClass *) parent_class)->finish(ec);
-       }
+        ((SPEventContextClass *) parent_class)->finish(ec);
+    }
 }
 
 static void sp_arc_context_dispose(GObject *object)
@@ -244,15 +248,14 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                 /* Snap center */
                 SnapManager &m = desktop->namedview->snap_manager;
                 m.setup(desktop);
-                Geom::Point pt2g = to_2geom(ac->center);
-                m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g, Inkscape::SNAPSOURCE_HANDLE);
-                ac->center = from_2geom(pt2g);
+                m.freeSnapReturnByRef(ac->center, Inkscape::SNAPSOURCE_NODE_HANDLE);
 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                                     GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK,
                                     NULL, event->button.time);
                 ret = TRUE;
+                m.unSetup();
             }
             break;
         case GDK_MOTION_NOTIFY:
@@ -276,6 +279,14 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                 gobble_motion_events(GDK_BUTTON1_MASK);
 
                 ret = TRUE;
+            } else if (!sp_event_context_knot_mouseover(ac)){
+                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:
@@ -285,7 +296,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                 sp_event_context_discard_delayed_snap_event(event_context);
                 if (!event_context->within_tolerance) {
                     // we've been dragging, finish the arc
-                               sp_arc_finish(ac);
+                       sp_arc_finish(ac);
                 } else if (event_context->item_to_select) {
                     // no dragging, select clicked item if any
                     if (event->button.state & GDK_SHIFT_MASK) {
@@ -337,14 +348,14 @@ static gint sp_arc_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_arc_cancel(ac);
-                                               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_arc_cancel(ac);
+                        ret = TRUE;
+                    }
+                    break;
                 case GDK_space:
                     if (dragging) {
                         sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
@@ -402,17 +413,17 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state)
             return;
         }
 
-        /* Create object */
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+        // Create object
+        Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
         Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
         repr->setAttribute("sodipodi:type", "arc");
 
-        /* Set style */
+        // Set style
         sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/arc", false);
 
         ac->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
         Inkscape::GC::release(repr);
-        ac->item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
+        ac->item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
         ac->item->updateRepr();
 
         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
@@ -436,7 +447,7 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state)
         Geom::Point c = r.midpoint();
         if (!ctrl_save) {
             if (fabs(dir[Geom::X]) > 1E-6 && fabs(dir[Geom::Y]) > 1E-6) {
-                Geom::Matrix const i2d (sp_item_i2d_affine (ac->item));
+                Geom::Matrix const i2d ((ac->item)->i2d_affine ());
                 Geom::Point new_dir = pt * i2d - c;
                 new_dir[Geom::X] *= dir[Geom::Y] / dir[Geom::X];
                 double lambda = new_dir.length() / dir[Geom::Y];
@@ -482,20 +493,20 @@ static void sp_arc_finish(SPArcContext *ac)
 
     if (ac->item != NULL) {
 
-       SPGenericEllipse *ge = SP_GENERICELLIPSE(SP_ARC(ac->item));
-               if (ge->rx.computed == 0 || ge->ry.computed == 0) {
-                       sp_arc_cancel(ac); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point
-                       return;
-               }
+        SPGenericEllipse *ge = SP_GENERICELLIPSE(SP_ARC(ac->item));
+        if (ge->rx.computed == 0 || ge->ry.computed == 0) {
+            sp_arc_cancel(ac); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point
+            return;
+        }
 
-       SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop;
+        SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop;
 
         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,
+               DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
                          _("Create ellipse"));
 
         ac->item = NULL;
@@ -504,14 +515,14 @@ static void sp_arc_finish(SPArcContext *ac)
 
 static void sp_arc_cancel(SPArcContext *ac)
 {
-       SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop;
+    SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->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 (ac->item != NULL) {
-       SP_OBJECT(ac->item)->deleteObject();
-       ac->item = NULL;
+        SP_OBJECT(ac->item)->deleteObject();
+        ac->item = NULL;
     }
 
     ac->within_tolerance = false;
@@ -521,7 +532,7 @@ static void sp_arc_cancel(SPArcContext *ac)
 
     sp_canvas_end_forced_full_redraws(desktop->canvas);
 
-    sp_document_cancel(sp_desktop_document(desktop));
+    DocumentUndo::cancel(sp_desktop_document(desktop));
 }
 
 
@@ -534,4 +545,4 @@ static void sp_arc_cancel(SPArcContext *ac)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :