Code

8661e79465dbf13ef75c43501da10230c1d3eb5c
[inkscape.git] / src / ui / tool / node-tool.cpp
1 /** @file
2  * @brief New node tool - implementation
3  */
4 /* Authors:
5  *   Krzysztof KosiƄski <tweenk@gmail.com>
6  *   Abhishek Sharma
7  *
8  * Copyright (C) 2009 Authors
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #include <glib.h>
13 #include <glib/gi18n.h>
14 #include "desktop.h"
15 #include "desktop-handles.h"
16 #include "display/canvas-bpath.h"
17 #include "display/curve.h"
18 #include "display/sp-canvas.h"
19 #include "document.h"
20 #include "live_effects/lpeobject.h"
21 #include "message-context.h"
22 #include "selection.h"
23 #include "shape-editor.h" // temporary!
24 #include "sp-clippath.h"
25 #include "sp-item-group.h"
26 #include "sp-mask.h"
27 #include "sp-object-group.h"
28 #include "sp-path.h"
29 #include "sp-text.h"
30 #include "ui/tool/node-tool.h"
31 #include "ui/tool/control-point-selection.h"
32 #include "ui/tool/curve-drag-point.h"
33 #include "ui/tool/event-utils.h"
34 #include "ui/tool/manipulator.h"
35 #include "ui/tool/multi-path-manipulator.h"
36 #include "ui/tool/path-manipulator.h"
37 #include "ui/tool/selector.h"
38 #include "ui/tool/shape-record.h"
40 #include "pixmaps/cursor-node.xpm"
41 #include "pixmaps/cursor-node-d.xpm"
43 /** @struct InkNodeTool
44  *
45  * Node tool event context.
46  *
47  * @par Architectural overview of the tool
48  * @par
49  * Here's a breakdown of what each object does.
50  * - Handle: shows a handle and keeps the node type constraint (smooth / symmetric) by updating
51  *   the other handle's position when dragged. Its move() method cannot violate the constraints.
52  * - Node: keeps node type constraints for auto nodes and smooth nodes at ends of linear segments.
53  *   Its move() method cannot violate constraints. Handles linear grow and dispatches spatial grow
54  *   to MultiPathManipulator. Keeps a reference to its NodeList.
55  * - NodeList: exposes an iterator-based interface to nodes. It is possible to obtain an iterator
56  *   to a node from the node. Keeps a reference to its SubpathList.
57  * - SubpathList: list of NodeLists that represents an editable pathvector. Keeps a reference
58  *   to its PathManipulator.
59  * - PathManipulator: performs most of the single-path actions like reverse subpaths,
60  *   delete segment, shift selection, etc. Keeps a reference to MultiPathManipulator.
61  * - MultiPathManipulator: performs additional operations for actions that are not per-path,
62  *   for example node joins and segment joins. Tracks the control transforms for PMs that edit
63  *   clipping paths and masks. It is more or less equivalent to ShapeEditor and in the future
64  *   it might handle all shapes. Handles XML commit of actions that affect all paths or
65  *   the node selection and removes PathManipulators that have no nodes left after e.g. node
66  *   deletes.
67  * - ControlPointSelection: keeps track of node selection and a set of nodes that can potentially
68  *   be selected. There can be more than one selection. Performs actions that require no
69  *   knowledge about the path, only about the nodes, like dragging and transforms. It is not
70  *   specific to nodes and can accomodate any control point derived from SelectableControlPoint.
71  *   Transforms nodes in response to transform handle events.
72  * - TransformHandleSet: displays nodeset transform handles and emits transform events. The aim
73  *   is to eventually use a common class for object and control point transforms.
74  * - SelectableControlPoint: base for any type of selectable point. It can belong to only one
75  *   selection.
76  *
77  * @par Functionality that resides in weird places
78  * @par
79  *
80  * This list is probably incomplete.
81  * - Curve dragging: CurveDragPoint, controlled by PathManipulator
82  * - Single handle shortcuts: MultiPathManipulator::event(), ModifierTracker
83  * - Linear and spatial grow: Node, spatial grow routed to ControlPointSelection
84  * - Committing handle actions performed with the mouse: PathManipulator
85  * - Sculpting: ControlPointSelection
86  *
87  * @par Plans for the future
88  * @par
89  * - MultiPathManipulator should become a generic shape editor that manages all active manipulator,
90  *   more or less like the old ShapeEditor.
91  * - Knotholder should be rewritten into one manipulator class per shape, using the control point
92  *   classes. Interesting features like dragging rectangle sides could be added along the way.
93  * - Better handling of clip and mask editing, particularly in response to undo.
94  * - High level refactoring of the event context hierarchy. All aspects of tools, like toolbox
95  *   controls, icons, event handling should be collected in one class, though each aspect
96  *   of a tool might be in an separate class for better modularity. The long term goal is to allow
97  *   tools to be defined in extensions or shared library plugins.
98  */
100 namespace {
101 SPCanvasGroup *create_control_group(SPDesktop *d);
102 void ink_node_tool_class_init(InkNodeToolClass *klass);
103 void ink_node_tool_init(InkNodeTool *node_context);
104 void ink_node_tool_dispose(GObject *object);
106 void ink_node_tool_setup(SPEventContext *ec);
107 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event);
108 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
109 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value);
111 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event);
112 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel);
113 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *);
114 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *);
115 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p);
116 } // anonymous namespace
118 GType ink_node_tool_get_type()
120     static GType type = 0;
121     if (!type) {
122         GTypeInfo info = {
123             sizeof(InkNodeToolClass),
124             NULL, NULL,
125             (GClassInitFunc) ink_node_tool_class_init,
126             NULL, NULL,
127             sizeof(InkNodeTool),
128             4,
129             (GInstanceInitFunc) ink_node_tool_init,
130             NULL,    /* value_table */
131         };
132         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "InkNodeTool", &info, (GTypeFlags)0);
133     }
134     return type;
137 namespace {
139 SPCanvasGroup *create_control_group(SPDesktop *d)
141     return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new(
142         sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL));
145 void destroy_group(SPCanvasGroup *g)
147     gtk_object_destroy(GTK_OBJECT(g));
150 void ink_node_tool_class_init(InkNodeToolClass *klass)
152     GObjectClass *object_class = (GObjectClass *) klass;
153     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
155     object_class->dispose = ink_node_tool_dispose;
157     event_context_class->setup = ink_node_tool_setup;
158     event_context_class->set = ink_node_tool_set;
159     event_context_class->root_handler = ink_node_tool_root_handler;
160     event_context_class->item_handler = ink_node_tool_item_handler;
163 void ink_node_tool_init(InkNodeTool *nt)
165     SPEventContext *event_context = SP_EVENT_CONTEXT(nt);
167     event_context->cursor_shape = cursor_node_xpm;
168     event_context->hot_x = 1;
169     event_context->hot_y = 1;
171     new (&nt->_selection_changed_connection) sigc::connection();
172     new (&nt->_selection_modified_connection) sigc::connection();
173     new (&nt->_mouseover_changed_connection) sigc::connection();
174     //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop);
175     new (&nt->_selected_nodes) CSelPtr();
176     new (&nt->_multipath) MultiPathPtr();
177     new (&nt->_selector) SelectorPtr();
178     new (&nt->_path_data) PathSharedDataPtr();
179     new (&nt->_shape_editors) ShapeEditors();
182 void ink_node_tool_dispose(GObject *object)
184     InkNodeTool *nt = INK_NODE_TOOL(object);
186     nt->enableGrDrag(false);
188     nt->_selection_changed_connection.disconnect();
189     nt->_selection_modified_connection.disconnect();
190     nt->_mouseover_changed_connection.disconnect();
191     nt->_multipath.~MultiPathPtr();
192     nt->_selected_nodes.~CSelPtr();
193     nt->_selector.~SelectorPtr();
194     nt->_shape_editors.~ShapeEditors();
195     
196     Inkscape::UI::PathSharedData &data = *nt->_path_data;
197     destroy_group(data.node_data.node_group);
198     destroy_group(data.node_data.handle_group);
199     destroy_group(data.node_data.handle_line_group);
200     destroy_group(data.outline_group);
201     destroy_group(data.dragpoint_group);
202     destroy_group(nt->_transform_handle_group);
203     
204     nt->_path_data.~PathSharedDataPtr();
205     nt->_selection_changed_connection.~connection();
206     nt->_selection_modified_connection.~connection();
207     nt->_mouseover_changed_connection.~connection();
209     if (nt->_node_message_context) {
210         delete nt->_node_message_context;
211     }
213     G_OBJECT_CLASS(g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)))->dispose(object);
216 void ink_node_tool_setup(SPEventContext *ec)
218     InkNodeTool *nt = INK_NODE_TOOL(ec);
220     SPEventContextClass *parent = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
221     if (parent->setup) parent->setup(ec);
223     nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
225     nt->_path_data.reset(new Inkscape::UI::PathSharedData());
226     Inkscape::UI::PathSharedData &data = *nt->_path_data;
227     data.node_data.desktop = nt->desktop;
229     // selector has to be created here, so that its hidden control point is on the bottom
230     nt->_selector.reset(new Inkscape::UI::Selector(nt->desktop));
232     // Prepare canvas groups for controls. This guarantees correct z-order, so that
233     // for example a dragpoint won't obscure a node
234     data.outline_group = create_control_group(nt->desktop);
235     data.node_data.handle_line_group = create_control_group(nt->desktop);
236     data.dragpoint_group = create_control_group(nt->desktop);
237     nt->_transform_handle_group = create_control_group(nt->desktop);
238     data.node_data.node_group = create_control_group(nt->desktop);
239     data.node_data.handle_group = create_control_group(nt->desktop);
241     Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
242     nt->_selection_changed_connection.disconnect();
243     nt->_selection_changed_connection =
244         selection->connectChanged(
245             sigc::bind<0>(
246                 sigc::ptr_fun(&ink_node_tool_selection_changed),
247                 nt));
248     /*nt->_selection_modified_connection.disconnect();
249     nt->_selection_modified_connection =
250         selection->connectModified(
251             sigc::hide(sigc::bind<0>(
252                 sigc::ptr_fun(&ink_node_tool_selection_modified),
253                 nt)));*/
254     nt->_mouseover_changed_connection.disconnect();
255     nt->_mouseover_changed_connection = 
256         Inkscape::UI::ControlPoint::signal_mouseover_change.connect(
257             sigc::bind<0>(
258                 sigc::ptr_fun(&ink_node_tool_mouseover_changed),
259                 nt));
260     
261     nt->_selected_nodes.reset(
262         new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group));
263     data.node_data.selection = nt->_selected_nodes.get();
264     nt->_multipath.reset(new Inkscape::UI::MultiPathManipulator(data,
265         nt->_selection_changed_connection));
267     nt->_selector->signal_point.connect(
268         sigc::bind<0>(
269             sigc::ptr_fun(&ink_node_tool_select_point),
270             nt));
271     nt->_selector->signal_area.connect(
272         sigc::bind<0>(
273             sigc::ptr_fun(&ink_node_tool_select_area),
274             nt));
276     nt->_multipath->signal_coords_changed.connect(
277         sigc::bind(
278             sigc::mem_fun(*nt->desktop, &SPDesktop::emitToolSubselectionChanged),
279             (void*) 0));
280     nt->_selected_nodes->signal_point_changed.connect(
281         sigc::hide( sigc::hide(
282             sigc::bind(
283                 sigc::bind(
284                     sigc::ptr_fun(ink_node_tool_update_tip),
285                     (GdkEvent*)0),
286                 nt))));
288     nt->cursor_drag = false;
289     nt->show_transform_handles = true;
290     nt->single_node_transform_handles = false;
291     nt->flash_tempitem = NULL;
292     nt->flashed_item = NULL;
293     nt->_last_over = NULL;
295     // read prefs before adding items to selection to prevent momentarily showing the outline
296     sp_event_context_read(nt, "show_handles");
297     sp_event_context_read(nt, "show_outline");
298     sp_event_context_read(nt, "live_outline");
299     sp_event_context_read(nt, "live_objects");
300     sp_event_context_read(nt, "show_path_direction");
301     sp_event_context_read(nt, "show_transform_handles");
302     sp_event_context_read(nt, "single_node_transform_handles");
303     sp_event_context_read(nt, "edit_clipping_paths");
304     sp_event_context_read(nt, "edit_masks");
306     ink_node_tool_selection_changed(nt, selection);
307     ink_node_tool_update_tip(nt, NULL);
309     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
310     if (prefs->getBool("/tools/nodes/selcue")) {
311         ec->enableSelectionCue();
312     }
313     if (prefs->getBool("/tools/nodes/gradientdrag")) {
314         ec->enableGrDrag();
315     }
317     nt->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
320 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value)
322     InkNodeTool *nt = INK_NODE_TOOL(ec);
323     Glib::ustring entry_name = value->getEntryName();
325     if (entry_name == "show_handles") {
326         nt->show_handles = value->getBool(true);
327         nt->_multipath->showHandles(nt->show_handles);
328     } else if (entry_name == "show_outline") {
329         nt->show_outline = value->getBool();
330         nt->_multipath->showOutline(nt->show_outline);
331     } else if (entry_name == "live_outline") {
332         nt->live_outline = value->getBool();
333         nt->_multipath->setLiveOutline(nt->live_outline);
334     } else if (entry_name == "live_objects") {
335         nt->live_objects = value->getBool();
336         nt->_multipath->setLiveObjects(nt->live_objects);
337     } else if (entry_name == "show_path_direction") {
338         nt->show_path_direction = value->getBool();
339         nt->_multipath->showPathDirection(nt->show_path_direction);
340     } else if (entry_name == "show_transform_handles") {
341         nt->show_transform_handles = value->getBool(true);
342         nt->_selected_nodes->showTransformHandles(
343             nt->show_transform_handles, nt->single_node_transform_handles);
344     } else if (entry_name == "single_node_transform_handles") {
345         nt->single_node_transform_handles = value->getBool();
346         nt->_selected_nodes->showTransformHandles(
347             nt->show_transform_handles, nt->single_node_transform_handles);
348     } else if (entry_name == "edit_clipping_paths") {
349         nt->edit_clipping_paths = value->getBool();
350         ink_node_tool_selection_changed(nt, nt->desktop->selection);
351     } else if (entry_name == "edit_masks") {
352         nt->edit_masks = value->getBool();
353         ink_node_tool_selection_changed(nt, nt->desktop->selection);
354     } else {
355         SPEventContextClass *parent_class =
356             (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
357         if (parent_class->set)
358             parent_class->set(ec, value);
359     }
362 /** Recursively collect ShapeRecords */
363 void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::ShapeRole role,
364     std::set<Inkscape::UI::ShapeRecord> &s)
366     using namespace Inkscape::UI;
367     if (!obj) return;
369     //XML Tree being used directly here while it shouldn't be.
370     if (SP_IS_PATH(obj) && obj->getRepr()->attribute("inkscape:original-d") != NULL) {
371         ShapeRecord r;
372         r.item = static_cast<SPItem*>(obj);
373         r.edit_transform = Geom::identity(); // TODO wrong?
374         r.role = role;
375         s.insert(r);
376     } else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) {
377         for (SPObject *c = obj->children; c; c = c->next) {
378             gather_items(nt, base, c, role, s);
379         }
380     } else if (SP_IS_ITEM(obj)) {
381         SPItem *item = static_cast<SPItem*>(obj);
382         ShapeRecord r;
383         r.item = item;
384         // TODO add support for objectBoundingBox
385         r.edit_transform = base ? base->i2doc_affine() : Geom::identity();
386         r.role = role;
387         if (s.insert(r).second) {
388             // this item was encountered the first time
389             if (nt->edit_clipping_paths && item->clip_ref) {
390                 gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s);
391             }
392             if (nt->edit_masks && item->mask_ref) {
393                 gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s);
394             }
395         }
396     }
399 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel)
401     using namespace Inkscape::UI;
403     std::set<ShapeRecord> shapes;
405     GSList const *ilist = sel->itemList();
407     for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) {
408         SPObject *obj = static_cast<SPObject*>(i->data);
409         if (SP_IS_ITEM(obj)) {
410             gather_items(nt, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes);
411         }
412     }
414     // use multiple ShapeEditors for now, to allow editing many shapes at once
415     // needs to be rethought
416     for (ShapeEditors::iterator i = nt->_shape_editors.begin();
417          i != nt->_shape_editors.end(); )
418     {
419         ShapeRecord s;
420         s.item = i->first;
421         if (shapes.find(s) == shapes.end()) {
422             nt->_shape_editors.erase(i++);
423         } else {
424             ++i;
425         }
426     }
428     for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
429         ShapeRecord const &r = *i;
430         if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item)) &&
431             nt->_shape_editors.find(r.item) == nt->_shape_editors.end())
432         {
433             ShapeEditor *si = new ShapeEditor(nt->desktop);
434             si->set_item(r.item, SH_KNOTHOLDER);
435             nt->_shape_editors.insert(const_cast<SPItem*&>(r.item), si);
436         }
437     }
439     nt->_multipath->setItems(shapes);
440     ink_node_tool_update_tip(nt, NULL);
441     nt->desktop->updateNow();
444 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event)
446     /* things to handle here:
447      * 1. selection of items
448      * 2. passing events to manipulators
449      * 3. some keybindings
450      */
451     using namespace Inkscape::UI; // pull in event helpers
452     
453     SPDesktop *desktop = event_context->desktop;
454     Inkscape::Selection *selection = desktop->selection;
455     InkNodeTool *nt = static_cast<InkNodeTool*>(event_context);
456     static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
457     
458     if (nt->_multipath->event(event)) return true;
459     if (nt->_selector->event(event)) return true;
460     if (nt->_selected_nodes->event(event)) return true;
462     switch (event->type)
463     {
464     case GDK_MOTION_NOTIFY: {
465         combine_motion_events(desktop->canvas, event->motion, 0);
466         SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
467                 FALSE, TRUE);
468         if (over_item != nt->_last_over) {
469             nt->_last_over = over_item;
470             ink_node_tool_update_tip(nt, event);
471         }
473         // create pathflash outline
474         if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
475             if (over_item == nt->flashed_item) break;
476             if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) break;
477             if (nt->flash_tempitem) {
478                 desktop->remove_temporary_canvasitem(nt->flash_tempitem);
479                 nt->flash_tempitem = NULL;
480                 nt->flashed_item = NULL;
481             }
482             if (!SP_IS_PATH(over_item)) break; // for now, handle only paths
484             nt->flashed_item = over_item;
485             SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(over_item));
486             c->transform(over_item->i2d_affine());
487             SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
488             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
489                 prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
490                 SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
491             sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO);
492             nt->flash_tempitem = desktop->add_temporary_canvasitem(flash,
493                 prefs->getInt("/tools/nodes/pathflash_timeout", 500));
494             c->unref();
495         }
496         } break; // do not return true, because we need to pass this event to the parent context
497         // otherwise some features cease to work
499     case GDK_KEY_PRESS:
500         switch (get_group0_keyval(&event->key))
501         {
502         case GDK_Escape: // deselect everything
503             if (nt->_selected_nodes->empty()) {
504                 selection->clear();
505             } else {
506                 nt->_selected_nodes->clear();
507             }
508             ink_node_tool_update_tip(nt, event);
509             return TRUE;
510         case GDK_a:
511         case GDK_A:
512             if (held_control(event->key) && held_alt(event->key)) {
513                 nt->_selected_nodes->selectAll();
514                 // Ctrl+A is handled in selection-chemistry.cpp via verb
515                 ink_node_tool_update_tip(nt, event);
516                 return TRUE;
517             }
518             break;
519         case GDK_h:
520         case GDK_H:
521             if (held_only_control(event->key)) {
522                 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
523                 prefs->setBool("/tools/nodes/show_handles", !nt->show_handles);
524                 return TRUE;
525             }
526             break;
527         default:
528             break;
529         }
530         ink_node_tool_update_tip(nt, event);
531         break;
532     case GDK_KEY_RELEASE:
533         ink_node_tool_update_tip(nt, event);
534         break;
535     default: break;
536     }
537     
538     SPEventContextClass *parent_class = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
539     if (parent_class->root_handler)
540         return parent_class->root_handler(event_context, event);
541     return FALSE;
544 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event)
546     using namespace Inkscape::UI;
547     if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
548         unsigned new_state = state_after_event(event);
549         if (new_state == event->key.state) return;
550         if (state_held_shift(new_state)) {
551             if (nt->_last_over) {
552                 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
553                     C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection, "
554                     "click to toggle object selection"));
555             } else {
556                 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
557                     C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection"));
558             }
559             return;
560         }
561     }
562     unsigned sz = nt->_selected_nodes->size();
563     unsigned total = nt->_selected_nodes->allPoints().size();
564     if (sz != 0) {
565         char *nodestring = g_strdup_printf(
566             ngettext("<b>%u of %u</b> node selected.", "<b>%u of %u</b> nodes selected.", total),
567             sz, total);
568         if (nt->_last_over) {
569             // TRANSLATORS: The %s below is where the "%u of %u nodes selected" sentence gets put
570             char *dyntip = g_strdup_printf(C_("Node tool tip",
571                 "%s Drag to select nodes, click to edit only this object (more: Shift)"),
572                 nodestring);
573             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
574             g_free(dyntip);
575         } else {
576             char *dyntip = g_strdup_printf(C_("Node tool tip",
577                 "%s Drag to select nodes, click clear the selection"),
578                 nodestring);
579             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
580             g_free(dyntip);
581         }
582         g_free(nodestring);
583     } else if (!nt->_multipath->empty()) {
584         if (nt->_last_over) {
585             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
586                 "Drag to select nodes, click to edit only this object"));
587         } else {
588             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
589                 "Drag to select nodes, click to clear the selection"));
590         }
591     } else {
592         if (nt->_last_over) {
593             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
594                 "Drag to select objects to edit, click to edit this object (more: Shift)"));
595         } else {
596             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
597                 "Drag to select objects to edit"));
598         }
599     }
602 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
604     SPEventContextClass *parent_class =
605         (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
606     if (parent_class->item_handler)
607         return parent_class->item_handler(event_context, item, event);
608     return FALSE;
611 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventButton *event)
613     using namespace Inkscape::UI;
614     if (nt->_multipath->empty()) {
615         // if multipath is empty, select rubberbanded items rather than nodes
616         Inkscape::Selection *selection = nt->desktop->selection;
617         GSList *items = sp_desktop_document(nt->desktop)->getItemsInBox(nt->desktop->dkey, sel);
618         selection->setList(items);
619         g_slist_free(items);
620     } else {
621         if (!held_shift(*event)) nt->_selected_nodes->clear();
622         nt->_selected_nodes->selectArea(sel);
623     }
625 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, GdkEventButton *event)
627     using namespace Inkscape::UI; // pull in event helpers
628     if (!event) return;
629     if (event->button != 1) return;
631     Inkscape::Selection *selection = nt->desktop->selection;
633     SPItem *item_clicked = sp_event_context_find_item (nt->desktop, event_point(*event),
634                     (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE);
636     if (item_clicked == NULL) { // nothing under cursor
637         // if no Shift, deselect
638         // if there are nodes selected, the first click should deselect the nodes
639         // and the second should deselect the items
640         if (!state_held_shift(event->state)) {
641             if (nt->_selected_nodes->empty()) {
642                 selection->clear();
643             } else {
644                 nt->_selected_nodes->clear();
645             }
646         }
647     } else {
648         if (held_shift(*event)) {
649             selection->toggle(item_clicked);
650         } else {
651             selection->set(item_clicked);
652         }
653         nt->desktop->updateNow();
654     }
657 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p)
659     using Inkscape::UI::CurveDragPoint;
660     CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p);
661     if (cdp && !nt->cursor_drag) {
662         nt->cursor_shape = cursor_node_d_xpm;
663         nt->hot_x = 1;
664         nt->hot_y = 1;
665         sp_event_context_update_cursor(nt);
666         nt->cursor_drag = true;
667     } else if (!cdp && nt->cursor_drag) {
668         nt->cursor_shape = cursor_node_xpm;
669         nt->hot_x = 1;
670         nt->hot_y = 1;
671         sp_event_context_update_cursor(nt);
672         nt->cursor_drag = false;
673     }
676 } // anonymous namespace
678 /*
679   Local Variables:
680   mode:c++
681   c-file-style:"stroustrup"
682   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
683   indent-tabs-mode:nil
684   fill-column:99
685   End:
686 */
687 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :