Code

Switched pen and pencil toobars to stock GTK+ toolbars
[inkscape.git] / src / spiral-context.cpp
index 6ce05dbd979d9485f7382657e4b145c0f87d59ba..1fcbc29a9eb9927aa10b110c16613ce3dc5c1b41 100644 (file)
@@ -264,7 +264,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
 
                 SnapManager const &m = desktop->namedview->snap_manager;
-                sc->center = m.freeSnap(Inkscape::Snapper::SNAP_POINT, sc->center, sc->item).getPoint();
+                sc->center = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, sc->center, sc->item).getPoint();
 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     ( GDK_KEY_PRESS_MASK |
@@ -276,7 +276,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
             }
             break;
         case GDK_MOTION_NOTIFY:
-            if (dragging && event->motion.state && GDK_BUTTON1_MASK) {
+            if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
 
                 if ( event_context->within_tolerance
                      && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
@@ -289,7 +289,11 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 event_context->within_tolerance = false;
 
                 NR::Point const motion_w(event->motion.x, event->motion.y);
-                NR::Point const motion_dt(event_context->desktop->w2d(motion_w));
+                NR::Point motion_dt(event_context->desktop->w2d(motion_w));
+                
+                SnapManager const &m = desktop->namedview->snap_manager;
+                motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, sc->item).getPoint();
+            
                 sp_spiral_drag(sc, motion_dt, event->motion.state);
                 ret = TRUE;
             }
@@ -350,6 +354,21 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 case GDK_Escape:
                     sp_desktop_selection(desktop)->clear();
                     //TODO: make dragging escapable by Esc
+                    break;
+
+                case GDK_space:
+                    if (dragging) {
+                        sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
+                                              event->button.time);
+                        dragging = false;
+                        if (!event_context->within_tolerance) {
+                            // we've been dragging, finish the rect
+                            sp_spiral_finish(sc);
+                        }
+                        // do not return true, so that space would work switching to selector
+                    }
+                    break;
+
                 default:
                     break;
             }
@@ -396,7 +415,8 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state)
         }
 
         /* Create object */
-        Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(sc));
+        Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
         repr->setAttribute("sodipodi:type", "spiral");
 
         /* Set style */
@@ -451,7 +471,7 @@ sp_spiral_finish(SPSpiralContext *sc)
         SPSpiral  *spiral = SP_SPIRAL(sc->item);
 
         sp_shape_set_shape(SP_SHAPE(spiral));
-        SP_OBJECT(spiral)->updateRepr(NULL, SP_OBJECT_WRITE_EXT);
+        SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT);
 
         sp_canvas_end_forced_full_redraws(desktop->canvas);