Code

735ddf87ef61c97a8f2f4a3ca7d227ea7e59a59c
[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  *
7  * Copyright (C) 2009 Authors
8  * Released under GNU GPL, read the file 'COPYING' for more information
9  */
11 #include <glib.h>
12 #include <glib/gi18n.h>
13 #include "desktop.h"
14 #include "desktop-handles.h"
15 #include "display/canvas-bpath.h"
16 #include "display/curve.h"
17 #include "display/sp-canvas.h"
18 #include "document.h"
19 #include "live_effects/lpeobject.h"
20 #include "message-context.h"
21 #include "selection.h"
22 #include "shape-editor.h" // temporary!
23 #include "sp-clippath.h"
24 #include "sp-item-group.h"
25 #include "sp-mask.h"
26 #include "sp-object-group.h"
27 #include "sp-path.h"
28 #include "ui/tool/node-tool.h"
29 #include "ui/tool/control-point-selection.h"
30 #include "ui/tool/curve-drag-point.h"
31 #include "ui/tool/event-utils.h"
32 #include "ui/tool/manipulator.h"
33 #include "ui/tool/multi-path-manipulator.h"
34 #include "ui/tool/path-manipulator.h"
35 #include "ui/tool/selector.h"
36 #include "ui/tool/shape-record.h"
38 #include "pixmaps/cursor-node.xpm"
39 #include "pixmaps/cursor-node-d.xpm"
41 /** @struct InkNodeTool
42  *
43  * Node tool event context.
44  *
45  * @par Architectural overview of the tool
46  * @par
47  * Here's a breakdown of what each object does.
48  * - Handle: shows a handle and keeps the node type constraint (smooth / symmetric) by updating
49  *   the other handle's position when dragged. Its move() method cannot violate the constraints.
50  * - Node: keeps node type constraints for auto nodes and smooth nodes at ends of linear segments.
51  *   Its move() method cannot violate constraints. Handles linear grow and dispatches spatial grow
52  *   to MultiPathManipulator. Keeps a reference to its NodeList.
53  * - NodeList: exposes an iterator-based interface to nodes. It is possible to obtain an iterator
54  *   to a node from the node. Keeps a reference to its SubpathList.
55  * - SubpathList: list of NodeLists that represents an editable pathvector. Keeps a reference
56  *   to its PathManipulator.
57  * - PathManipulator: performs most of the single-path actions like reverse subpaths,
58  *   delete segment, shift selection, etc. Keeps a reference to MultiPathManipulator.
59  * - MultiPathManipulator: performs additional operations for actions that are not per-path,
60  *   for example node joins and segment joins. Tracks the control transforms for PMs that edit
61  *   clipping paths and masks. It is more or less equivalent to ShapeEditor and in the future
62  *   it might handle all shapes. Handles XML commit of actions that affect all paths or
63  *   the node selection and removes PathManipulators that have no nodes left after e.g. node
64  *   deletes.
65  * - ControlPointSelection: keeps track of node selection. Performs actions that require no
66  *   knowledge about the path, only about the nodes, like dragging and transforms. It is not
67  *   specific to nodes and can accomodate any control point derived from SelectableControlPoint.
68  *   Transforms nodes in response to transform handle events.
69  * - TransformHandleSet: displays nodeset transform handles and emits transform events. The aim
70  *   is to eventually use a common class for object and control point transforms.
71  * 
72  * @par Plans for the future
73  * @par
74  * - MultiPathManipulator should become a generic shape editor that manages all active manipulator,
75  *   more or less like the old ShapeEditor.
76  * - Knotholder should be rewritten into one manipulator class per shape, using the control point
77  *   classes. Interesting features like dragging rectangle sides could be added along the way.
78  * - Better handling of clip and mask editing, particularly in response to undo.
79  * - High level refactoring of the event context hierarchy. All aspects of tools, like toolbox
80  *   controls, icons, event handling should be collected in one class, though each aspect
81  *   of a tool might be in an separate class for better modularity. The long term goal is to allow
82  *   tools to be defined in extensions or shared library plugins.
83  */
85 namespace {
86 SPCanvasGroup *create_control_group(SPDesktop *d);
87 void ink_node_tool_class_init(InkNodeToolClass *klass);
88 void ink_node_tool_init(InkNodeTool *node_context);
89 void ink_node_tool_dispose(GObject *object);
91 void ink_node_tool_setup(SPEventContext *ec);
92 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event);
93 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
94 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value);
96 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event);
97 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel);
98 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *);
99 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *);
100 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p);
101 } // anonymous namespace
103 GType ink_node_tool_get_type()
105     static GType type = 0;
106     if (!type) {
107         GTypeInfo info = {
108             sizeof(InkNodeToolClass),
109             NULL, NULL,
110             (GClassInitFunc) ink_node_tool_class_init,
111             NULL, NULL,
112             sizeof(InkNodeTool),
113             4,
114             (GInstanceInitFunc) ink_node_tool_init,
115             NULL,    /* value_table */
116         };
117         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "InkNodeTool", &info, (GTypeFlags)0);
118     }
119     return type;
122 namespace {
124 SPCanvasGroup *create_control_group(SPDesktop *d)
126     return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new(
127         sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL));
130 void destroy_group(SPCanvasGroup *g)
132     gtk_object_destroy(GTK_OBJECT(g));
135 void ink_node_tool_class_init(InkNodeToolClass *klass)
137     GObjectClass *object_class = (GObjectClass *) klass;
138     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
140     object_class->dispose = ink_node_tool_dispose;
142     event_context_class->setup = ink_node_tool_setup;
143     event_context_class->set = ink_node_tool_set;
144     event_context_class->root_handler = ink_node_tool_root_handler;
145     event_context_class->item_handler = ink_node_tool_item_handler;
148 void ink_node_tool_init(InkNodeTool *nt)
150     SPEventContext *event_context = SP_EVENT_CONTEXT(nt);
152     event_context->cursor_shape = cursor_node_xpm;
153     event_context->hot_x = 1;
154     event_context->hot_y = 1;
156     new (&nt->_selection_changed_connection) sigc::connection();
157     new (&nt->_selection_modified_connection) sigc::connection();
158     new (&nt->_mouseover_changed_connection) sigc::connection();
159     //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop);
160     new (&nt->_selected_nodes) CSelPtr();
161     new (&nt->_multipath) MultiPathPtr();
162     new (&nt->_selector) SelectorPtr();
163     new (&nt->_path_data) PathSharedDataPtr();
166 void ink_node_tool_dispose(GObject *object)
168     InkNodeTool *nt = INK_NODE_TOOL(object);
170     nt->enableGrDrag(false);
172     nt->_selection_changed_connection.disconnect();
173     nt->_selection_modified_connection.disconnect();
174     nt->_mouseover_changed_connection.disconnect();
175     nt->_multipath.~MultiPathPtr();
176     nt->_selected_nodes.~CSelPtr();
177     nt->_selector.~SelectorPtr();
178     
179     Inkscape::UI::PathSharedData &data = *nt->_path_data;
180     destroy_group(data.node_data.node_group);
181     destroy_group(data.node_data.handle_group);
182     destroy_group(data.node_data.handle_line_group);
183     destroy_group(data.outline_group);
184     destroy_group(data.dragpoint_group);
185     destroy_group(nt->_transform_handle_group);
186     
187     nt->_path_data.~PathSharedDataPtr();
188     nt->_selection_changed_connection.~connection();
189     nt->_selection_modified_connection.~connection();
190     nt->_mouseover_changed_connection.~connection();
192     if (nt->_node_message_context) {
193         delete nt->_node_message_context;
194     }
195     if (nt->shape_editor) {
196         nt->shape_editor->unset_item(SH_KNOTHOLDER);
197         delete nt->shape_editor;
198     }
200     G_OBJECT_CLASS(g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)))->dispose(object);
203 void ink_node_tool_setup(SPEventContext *ec)
205     InkNodeTool *nt = INK_NODE_TOOL(ec);
207     SPEventContextClass *parent = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
208     if (parent->setup) parent->setup(ec);
210     nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
212     nt->_path_data.reset(new Inkscape::UI::PathSharedData());
213     Inkscape::UI::PathSharedData &data = *nt->_path_data;
214     data.node_data.desktop = nt->desktop;
216     // selector has to be created here, so that its hidden control point is on the bottom
217     nt->_selector.reset(new Inkscape::UI::Selector(nt->desktop));
219     // Prepare canvas groups for controls. This guarantees correct z-order, so that
220     // for example a dragpoint won't obscure a node
221     data.outline_group = create_control_group(nt->desktop);
222     data.node_data.handle_line_group = create_control_group(nt->desktop);
223     data.dragpoint_group = create_control_group(nt->desktop);
224     nt->_transform_handle_group = create_control_group(nt->desktop);
225     data.node_data.node_group = create_control_group(nt->desktop);
226     data.node_data.handle_group = create_control_group(nt->desktop);
228     Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
229     nt->_selection_changed_connection.disconnect();
230     nt->_selection_changed_connection =
231         selection->connectChanged(
232             sigc::bind<0>(
233                 sigc::ptr_fun(&ink_node_tool_selection_changed),
234                 nt));
235     /*nt->_selection_modified_connection.disconnect();
236     nt->_selection_modified_connection =
237         selection->connectModified(
238             sigc::hide(sigc::bind<0>(
239                 sigc::ptr_fun(&ink_node_tool_selection_modified),
240                 nt)));*/
241     nt->_mouseover_changed_connection.disconnect();
242     nt->_mouseover_changed_connection = 
243         Inkscape::UI::ControlPoint::signal_mouseover_change.connect(
244             sigc::bind<0>(
245                 sigc::ptr_fun(&ink_node_tool_mouseover_changed),
246                 nt));
247     
248     nt->_selected_nodes.reset(
249         new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group));
250     data.node_data.selection = nt->_selected_nodes.get();
251     nt->_multipath.reset(new Inkscape::UI::MultiPathManipulator(data,
252         nt->_selection_changed_connection));
254     nt->_selector->signal_point.connect(
255         sigc::bind<0>(
256             sigc::ptr_fun(&ink_node_tool_select_point),
257             nt));
258     nt->_selector->signal_area.connect(
259         sigc::bind<0>(
260             sigc::ptr_fun(&ink_node_tool_select_area),
261             nt));
263     nt->_multipath->signal_coords_changed.connect(
264         sigc::bind(
265             sigc::mem_fun(*nt->desktop, &SPDesktop::emitToolSubselectionChanged),
266             (void*) 0));
267     nt->_selected_nodes->signal_point_changed.connect(
268         sigc::hide( sigc::hide(
269             sigc::bind(
270                 sigc::bind(
271                     sigc::ptr_fun(ink_node_tool_update_tip),
272                     (GdkEvent*)0),
273                 nt))));
275     nt->cursor_drag = false;
276     nt->show_transform_handles = true;
277     nt->single_node_transform_handles = false;
278     nt->flash_tempitem = NULL;
279     nt->flashed_item = NULL;
280     // TODO remove this!
281     nt->shape_editor = new ShapeEditor(nt->desktop);
283     // read prefs before adding items to selection to prevent momentarily showing the outline
284     sp_event_context_read(nt, "show_handles");
285     sp_event_context_read(nt, "show_outline");
286     sp_event_context_read(nt, "show_path_direction");
287     sp_event_context_read(nt, "show_transform_handles");
288     sp_event_context_read(nt, "single_node_transform_handles");
289     sp_event_context_read(nt, "edit_clipping_paths");
290     sp_event_context_read(nt, "edit_masks");
292     ink_node_tool_selection_changed(nt, selection);
293     ink_node_tool_update_tip(nt, NULL);
295     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
296     if (prefs->getBool("/tools/nodes/selcue")) {
297         ec->enableSelectionCue();
298     }
299     if (prefs->getBool("/tools/nodes/gradientdrag")) {
300         ec->enableGrDrag();
301     }
303     nt->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
306 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value)
308     InkNodeTool *nt = INK_NODE_TOOL(ec);
309     Glib::ustring entry_name = value->getEntryName();
311     if (entry_name == "show_handles") {
312         nt->_multipath->showHandles(value->getBool(true));
313     } else if (entry_name == "show_outline") {
314         nt->show_outline = value->getBool();
315         nt->_multipath->showOutline(nt->show_outline);
316     } else if (entry_name == "show_path_direction") {
317         nt->show_path_direction = value->getBool();
318         nt->_multipath->showPathDirection(nt->show_path_direction);
319     } else if (entry_name == "show_transform_handles") {
320         nt->show_transform_handles = value->getBool(true);
321         nt->_selected_nodes->showTransformHandles(
322             nt->show_transform_handles, nt->single_node_transform_handles);
323     } else if (entry_name == "single_node_transform_handles") {
324         nt->single_node_transform_handles = value->getBool();
325         nt->_selected_nodes->showTransformHandles(
326             nt->show_transform_handles, nt->single_node_transform_handles);
327     } else if (entry_name == "edit_clipping_paths") {
328         nt->edit_clipping_paths = value->getBool();
329         ink_node_tool_selection_changed(nt, nt->desktop->selection);
330     } else if (entry_name == "edit_masks") {
331         nt->edit_masks = value->getBool();
332         ink_node_tool_selection_changed(nt, nt->desktop->selection);
333     } else {
334         SPEventContextClass *parent_class =
335             (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
336         if (parent_class->set)
337             parent_class->set(ec, value);
338     }
341 /** Recursively collect ShapeRecords */
342 void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::ShapeRole role,
343     std::set<Inkscape::UI::ShapeRecord> &s)
345     using namespace Inkscape::UI;
346     if (!obj) return;
348     if (SP_IS_PATH(obj) && obj->repr->attribute("inkscape:original-d") != NULL) {
349         ShapeRecord r;
350         r.item = static_cast<SPItem*>(obj);
351         r.edit_transform = Geom::identity(); // TODO wrong?
352         r.role = SHAPE_ROLE_LPE_PARAM;
353         s.insert(r);
354     } else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) {
355         for (SPObject *c = obj->children; c; c = c->next) {
356             gather_items(nt, base, c, role, s);
357         }
358     } else if (SP_IS_ITEM(obj)) {
359         SPItem *item = static_cast<SPItem*>(obj);
360         ShapeRecord r;
361         r.item = item;
362         // TODO add support for objectBoundingBox
363         r.edit_transform = base ? sp_item_i2doc_affine(base) : Geom::identity();
364         r.role = role;
365         if (s.insert(r).second) {
366             // this item was encountered the first time
367             if (nt->edit_clipping_paths && item->clip_ref) {
368                 gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s);
369             }
370             if (nt->edit_masks && item->mask_ref) {
371                 gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s);
372             }
373         }
374     }
377 struct IsPath {
378     bool operator()(SPItem *i) const { return SP_IS_PATH(i); }
379 };
381 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel)
383     using namespace Inkscape::UI;
385     std::set<ShapeRecord> shapes;
387     // TODO this is ugly!!!
388     //typedef std::map<SPItem*, std::pair<Geom::Matrix, guint32> > TransMap;
389     //typedef std::map<SPPath*, std::pair<Geom::Matrix, guint32> > PathMap;
390     GSList const *ilist = sel->itemList();
392     for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) {
393         SPObject *obj = static_cast<SPObject*>(i->data);
394         if (SP_IS_ITEM(obj)) {
395             gather_items(nt, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes);
396         }
397     }
399     // ugly hack: set the first editable non-path item for knotholder
400     // maybe use multiple ShapeEditors for now, to allow editing many shapes at once?
401     bool something_set = false;
402     for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
403         ShapeRecord const &r = *i;
404         if (SP_IS_SHAPE(r.item) && !SP_IS_PATH(r.item)) {
405             nt->shape_editor->set_item(r.item, SH_KNOTHOLDER);
406             something_set = true;
407             break;
408         }
409     }
410     if (!something_set) {
411         nt->shape_editor->unset_item(SH_KNOTHOLDER);
412     }
414     nt->_multipath->setItems(shapes);
415     ink_node_tool_update_tip(nt, NULL);
416     nt->desktop->updateNow();
419 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event)
421     /* things to handle here:
422      * 1. selection of items
423      * 2. passing events to manipulators
424      * 3. some keybindings
425      */
426     using namespace Inkscape::UI; // pull in event helpers
427     
428     SPDesktop *desktop = event_context->desktop;
429     Inkscape::Selection *selection = desktop->selection;
430     InkNodeTool *nt = static_cast<InkNodeTool*>(event_context);
431     static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
432     
433     if (nt->_multipath->event(event)) return true;
434     if (nt->_selector->event(event)) return true;
435     if (nt->_selected_nodes->event(event)) return true;
437     switch (event->type)
438     {
439     case GDK_MOTION_NOTIFY:
440         // create outline
441         if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
442             SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
443                 FALSE, TRUE);
444             if (over_item == nt->flashed_item) break;
445             if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) break;
446             if (nt->flash_tempitem) {
447                 desktop->remove_temporary_canvasitem(nt->flash_tempitem);
448                 nt->flash_tempitem = NULL;
449                 nt->flashed_item = NULL;
450             }
451             if (!SP_IS_PATH(over_item)) break; // for now, handle only paths
453             nt->flashed_item = over_item;
454             SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(over_item));
455             c->transform(sp_item_i2d_affine(over_item));
456             SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
457             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
458                 prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
459                 SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
460             sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO);
461             nt->flash_tempitem = desktop->add_temporary_canvasitem(flash,
462                 prefs->getInt("/tools/nodes/pathflash_timeout", 500));
463             c->unref();
464         }
465         return true;
466     case GDK_KEY_PRESS:
467         switch (get_group0_keyval(&event->key))
468         {
469         case GDK_Escape: // deselect everything
470             if (nt->_selected_nodes->empty()) {
471                 selection->clear();
472             } else {
473                 nt->_selected_nodes->clear();
474             }
475             ink_node_tool_update_tip(nt, event);
476             return TRUE;
477         case GDK_a:
478             if (held_control(event->key)) {
479                 if (held_alt(event->key)) {
480                     nt->_multipath->selectAll();
481                 } else {
482                     // select all nodes in subpaths that have something selected
483                     // if nothing is selected, select everything
484                     nt->_multipath->selectSubpaths();
485                 }
486                 ink_node_tool_update_tip(nt, event);
487                 return TRUE;
488             }
489             break;
490         default:
491             break;
492         }
493         ink_node_tool_update_tip(nt, event);
494         break;
495     case GDK_KEY_RELEASE:
496         ink_node_tool_update_tip(nt, event);
497         break;
498     default: break;
499     }
500     
501     SPEventContextClass *parent_class = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
502     if (parent_class->root_handler)
503         return parent_class->root_handler(event_context, event);
504     return FALSE;
507 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event)
509     using namespace Inkscape::UI;
510     if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
511         unsigned new_state = state_after_event(event);
512         if (new_state == event->key.state) return;
513         if (state_held_shift(new_state)) {
514             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
515                 C_("Node tool tip", "<b>Shift:</b> drag to add nodes to the selection, "
516                 "click to toggle object selection"));
517             return;
518         }
519     }
520     unsigned sz = nt->_selected_nodes->size();
521     if (sz != 0) {
522         char *dyntip = g_strdup_printf(C_("Node tool tip",
523             "Selected <b>%d nodes</b>. Drag to select nodes, click to select a single object "
524             "or unselect all objects"), sz);
525         nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
526         g_free(dyntip);
527     } else if (nt->_multipath->empty()) {
528         nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
529             C_("Node tool tip", "Drag or click to select objects to edit"));
530     } else {
531         nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
532             C_("Node tool tip", "Drag to select nodes, click to select an object "
533             "or clear the selection"));
534     }
537 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
539     SPEventContextClass *parent_class =
540         (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
541     if (parent_class->item_handler)
542         return parent_class->item_handler(event_context, item, event);
543     return FALSE;
546 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventButton *event)
548     using namespace Inkscape::UI;
549     if (nt->_multipath->empty()) {
550         // if multipath is empty, select rubberbanded items rather than nodes
551         Inkscape::Selection *selection = nt->desktop->selection;
552         GSList *items = sp_document_items_in_box(
553             sp_desktop_document(nt->desktop), nt->desktop->dkey, sel);
554         selection->setList(items);
555         g_slist_free(items);
556     } else {
557         nt->_multipath->selectArea(sel, !held_shift(*event));
558     }
560 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &sel, GdkEventButton *event)
562     using namespace Inkscape::UI; // pull in event helpers
563     if (!event) return;
564     if (event->button != 1) return;
566     Inkscape::Selection *selection = nt->desktop->selection;
568     SPItem *item_clicked = sp_event_context_find_item (nt->desktop, event_point(*event),
569                     (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE);
571     if (item_clicked == NULL) { // nothing under cursor
572         // if no Shift, deselect
573         if (!(event->state & GDK_SHIFT_MASK)) {
574             selection->clear();
575         }
576         return;
577     }
578     if (held_shift(*event)) {
579         selection->toggle(item_clicked);
580     } else {
581         selection->set(item_clicked);
582     }
583     nt->desktop->updateNow();
586 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p)
588     using Inkscape::UI::CurveDragPoint;
589     CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p);
590     if (cdp && !nt->cursor_drag) {
591         nt->cursor_shape = cursor_node_d_xpm;
592         nt->hot_x = 1;
593         nt->hot_y = 1;
594         sp_event_context_update_cursor(nt);
595         nt->cursor_drag = true;
596     } else if (!cdp && nt->cursor_drag) {
597         nt->cursor_shape = cursor_node_xpm;
598         nt->hot_x = 1;
599         nt->hot_y = 1;
600         sp_event_context_update_cursor(nt);
601         nt->cursor_drag = false;
602     }
605 } // anonymous namespace
607 /*
608   Local Variables:
609   mode:c++
610   c-file-style:"stroustrup"
611   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
612   indent-tabs-mode:nil
613   fill-column:99
614   End:
615 */
616 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :