Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / ui / tool / node-tool.cpp
index 57e57b711d2e3388b2550cfa9de77f0a631fc548..e75f31370394913fa6b40834e56e31717340992d 100644 (file)
@@ -3,6 +3,7 @@
  */
 /* Authors:
  *   Krzysztof KosiƄski <tweenk@gmail.com>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2009 Authors
  * Released under GNU GPL, read the file 'COPYING' for more information
@@ -12,6 +13,7 @@
 #include <glib/gi18n.h>
 #include "desktop.h"
 #include "desktop-handles.h"
+#include "display/sp-canvas-group.h"
 #include "display/canvas-bpath.h"
 #include "display/curve.h"
 #include "display/sp-canvas.h"
  *   is to eventually use a common class for object and control point transforms.
  * - SelectableControlPoint: base for any type of selectable point. It can belong to only one
  *   selection.
- * 
+ *
+ * @par Functionality that resides in weird places
+ * @par
+ *
+ * This list is probably incomplete.
+ * - Curve dragging: CurveDragPoint, controlled by PathManipulator
+ * - Single handle shortcuts: MultiPathManipulator::event(), ModifierTracker
+ * - Linear and spatial grow: Node, spatial grow routed to ControlPointSelection
+ * - Committing handle actions performed with the mouse: PathManipulator
+ * - Sculpting: ControlPointSelection
+ *
  * @par Plans for the future
  * @par
  * - MultiPathManipulator should become a generic shape editor that manages all active manipulator,
@@ -355,7 +367,8 @@ void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Sh
     using namespace Inkscape::UI;
     if (!obj) return;
 
-    if (SP_IS_PATH(obj) && obj->repr->attribute("inkscape:original-d") != NULL) {
+    //XML Tree being used directly here while it shouldn't be.
+    if (SP_IS_PATH(obj) && obj->getRepr()->attribute("inkscape:original-d") != NULL) {
         ShapeRecord r;
         r.item = static_cast<SPItem*>(obj);
         r.edit_transform = Geom::identity(); // TODO wrong?
@@ -370,7 +383,7 @@ void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Sh
         ShapeRecord r;
         r.item = item;
         // TODO add support for objectBoundingBox
-        r.edit_transform = base ? sp_item_i2doc_affine(base) : Geom::identity();
+        r.edit_transform = base ? base->i2doc_affine() : Geom::identity();
         r.role = role;
         if (s.insert(r).second) {
             // this item was encountered the first time
@@ -471,7 +484,7 @@ gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event)
 
             nt->flashed_item = over_item;
             SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(over_item));
-            c->transform(sp_item_i2d_affine(over_item));
+            c->transform(over_item->i2d_affine());
             SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
                 prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
@@ -550,19 +563,24 @@ void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event)
     unsigned sz = nt->_selected_nodes->size();
     unsigned total = nt->_selected_nodes->allPoints().size();
     if (sz != 0) {
+        char *nodestring = g_strdup_printf(
+            ngettext("<b>%u of %u</b> node selected.", "<b>%u of %u</b> nodes selected.", total),
+            sz, total);
         if (nt->_last_over) {
+            // TRANSLATORS: The %s below is where the "%u of %u nodes selected" sentence gets put
             char *dyntip = g_strdup_printf(C_("Node tool tip",
-                "<b>%u of %u nodes</b> selected. "
-                "Drag to select nodes, click to edit only this object (more: Shift)"), sz, total);
+                "%s Drag to select nodes, click to edit only this object (more: Shift)"),
+                nodestring);
             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
             g_free(dyntip);
         } else {
             char *dyntip = g_strdup_printf(C_("Node tool tip",
-                "<b>%u of %u nodes</b> selected. "
-                "Drag to select nodes, click clear the selection"), sz, total);
+                "%s Drag to select nodes, click clear the selection"),
+                nodestring);
             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
             g_free(dyntip);
         }
+        g_free(nodestring);
     } else if (!nt->_multipath->empty()) {
         if (nt->_last_over) {
             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
@@ -597,8 +615,7 @@ void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventB
     if (nt->_multipath->empty()) {
         // if multipath is empty, select rubberbanded items rather than nodes
         Inkscape::Selection *selection = nt->desktop->selection;
-        GSList *items = sp_document_items_in_box(
-            sp_desktop_document(nt->desktop), nt->desktop->dkey, sel);
+        GSList *items = sp_desktop_document(nt->desktop)->getItemsInBox(nt->desktop->dkey, sel);
         selection->setList(items);
         g_slist_free(items);
     } else {
@@ -619,8 +636,14 @@ void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, Gdk
 
     if (item_clicked == NULL) { // nothing under cursor
         // if no Shift, deselect
-        if (!(event->state & GDK_SHIFT_MASK)) {
-            selection->clear();
+        // if there are nodes selected, the first click should deselect the nodes
+        // and the second should deselect the items
+        if (!state_held_shift(event->state)) {
+            if (nt->_selected_nodes->empty()) {
+                selection->clear();
+            } else {
+                nt->_selected_nodes->clear();
+            }
         }
     } else {
         if (held_shift(*event)) {