Code

A simple layout document as to what, why and how is cppification.
[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 and a set of nodes that can potentially
66  *   be selected. There can be more than one selection. Performs actions that require no
67  *   knowledge about the path, only about the nodes, like dragging and transforms. It is not
68  *   specific to nodes and can accomodate any control point derived from SelectableControlPoint.
69  *   Transforms nodes in response to transform handle events.
70  * - TransformHandleSet: displays nodeset transform handles and emits transform events. The aim
71  *   is to eventually use a common class for object and control point transforms.
72  * - SelectableControlPoint: base for any type of selectable point. It can belong to only one
73  *   selection.
74  * 
75  * @par Plans for the future
76  * @par
77  * - MultiPathManipulator should become a generic shape editor that manages all active manipulator,
78  *   more or less like the old ShapeEditor.
79  * - Knotholder should be rewritten into one manipulator class per shape, using the control point
80  *   classes. Interesting features like dragging rectangle sides could be added along the way.
81  * - Better handling of clip and mask editing, particularly in response to undo.
82  * - High level refactoring of the event context hierarchy. All aspects of tools, like toolbox
83  *   controls, icons, event handling should be collected in one class, though each aspect
84  *   of a tool might be in an separate class for better modularity. The long term goal is to allow
85  *   tools to be defined in extensions or shared library plugins.
86  */
88 namespace {
89 SPCanvasGroup *create_control_group(SPDesktop *d);
90 void ink_node_tool_class_init(InkNodeToolClass *klass);
91 void ink_node_tool_init(InkNodeTool *node_context);
92 void ink_node_tool_dispose(GObject *object);
94 void ink_node_tool_setup(SPEventContext *ec);
95 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event);
96 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
97 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value);
99 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event);
100 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel);
101 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *);
102 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *);
103 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p);
104 } // anonymous namespace
106 GType ink_node_tool_get_type()
108     static GType type = 0;
109     if (!type) {
110         GTypeInfo info = {
111             sizeof(InkNodeToolClass),
112             NULL, NULL,
113             (GClassInitFunc) ink_node_tool_class_init,
114             NULL, NULL,
115             sizeof(InkNodeTool),
116             4,
117             (GInstanceInitFunc) ink_node_tool_init,
118             NULL,    /* value_table */
119         };
120         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "InkNodeTool", &info, (GTypeFlags)0);
121     }
122     return type;
125 namespace {
127 SPCanvasGroup *create_control_group(SPDesktop *d)
129     return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new(
130         sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL));
133 void destroy_group(SPCanvasGroup *g)
135     gtk_object_destroy(GTK_OBJECT(g));
138 void ink_node_tool_class_init(InkNodeToolClass *klass)
140     GObjectClass *object_class = (GObjectClass *) klass;
141     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
143     object_class->dispose = ink_node_tool_dispose;
145     event_context_class->setup = ink_node_tool_setup;
146     event_context_class->set = ink_node_tool_set;
147     event_context_class->root_handler = ink_node_tool_root_handler;
148     event_context_class->item_handler = ink_node_tool_item_handler;
151 void ink_node_tool_init(InkNodeTool *nt)
153     SPEventContext *event_context = SP_EVENT_CONTEXT(nt);
155     event_context->cursor_shape = cursor_node_xpm;
156     event_context->hot_x = 1;
157     event_context->hot_y = 1;
159     new (&nt->_selection_changed_connection) sigc::connection();
160     new (&nt->_selection_modified_connection) sigc::connection();
161     new (&nt->_mouseover_changed_connection) sigc::connection();
162     //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop);
163     new (&nt->_selected_nodes) CSelPtr();
164     new (&nt->_multipath) MultiPathPtr();
165     new (&nt->_selector) SelectorPtr();
166     new (&nt->_path_data) PathSharedDataPtr();
169 void ink_node_tool_dispose(GObject *object)
171     InkNodeTool *nt = INK_NODE_TOOL(object);
173     nt->enableGrDrag(false);
175     nt->_selection_changed_connection.disconnect();
176     nt->_selection_modified_connection.disconnect();
177     nt->_mouseover_changed_connection.disconnect();
178     nt->_multipath.~MultiPathPtr();
179     nt->_selected_nodes.~CSelPtr();
180     nt->_selector.~SelectorPtr();
181     
182     Inkscape::UI::PathSharedData &data = *nt->_path_data;
183     destroy_group(data.node_data.node_group);
184     destroy_group(data.node_data.handle_group);
185     destroy_group(data.node_data.handle_line_group);
186     destroy_group(data.outline_group);
187     destroy_group(data.dragpoint_group);
188     destroy_group(nt->_transform_handle_group);
189     
190     nt->_path_data.~PathSharedDataPtr();
191     nt->_selection_changed_connection.~connection();
192     nt->_selection_modified_connection.~connection();
193     nt->_mouseover_changed_connection.~connection();
195     if (nt->_node_message_context) {
196         delete nt->_node_message_context;
197     }
198     if (nt->shape_editor) {
199         nt->shape_editor->unset_item(SH_KNOTHOLDER);
200         delete nt->shape_editor;
201     }
203     G_OBJECT_CLASS(g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)))->dispose(object);
206 void ink_node_tool_setup(SPEventContext *ec)
208     InkNodeTool *nt = INK_NODE_TOOL(ec);
210     SPEventContextClass *parent = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
211     if (parent->setup) parent->setup(ec);
213     nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
215     nt->_path_data.reset(new Inkscape::UI::PathSharedData());
216     Inkscape::UI::PathSharedData &data = *nt->_path_data;
217     data.node_data.desktop = nt->desktop;
219     // selector has to be created here, so that its hidden control point is on the bottom
220     nt->_selector.reset(new Inkscape::UI::Selector(nt->desktop));
222     // Prepare canvas groups for controls. This guarantees correct z-order, so that
223     // for example a dragpoint won't obscure a node
224     data.outline_group = create_control_group(nt->desktop);
225     data.node_data.handle_line_group = create_control_group(nt->desktop);
226     data.dragpoint_group = create_control_group(nt->desktop);
227     nt->_transform_handle_group = create_control_group(nt->desktop);
228     data.node_data.node_group = create_control_group(nt->desktop);
229     data.node_data.handle_group = create_control_group(nt->desktop);
231     Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
232     nt->_selection_changed_connection.disconnect();
233     nt->_selection_changed_connection =
234         selection->connectChanged(
235             sigc::bind<0>(
236                 sigc::ptr_fun(&ink_node_tool_selection_changed),
237                 nt));
238     /*nt->_selection_modified_connection.disconnect();
239     nt->_selection_modified_connection =
240         selection->connectModified(
241             sigc::hide(sigc::bind<0>(
242                 sigc::ptr_fun(&ink_node_tool_selection_modified),
243                 nt)));*/
244     nt->_mouseover_changed_connection.disconnect();
245     nt->_mouseover_changed_connection = 
246         Inkscape::UI::ControlPoint::signal_mouseover_change.connect(
247             sigc::bind<0>(
248                 sigc::ptr_fun(&ink_node_tool_mouseover_changed),
249                 nt));
250     
251     nt->_selected_nodes.reset(
252         new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group));
253     data.node_data.selection = nt->_selected_nodes.get();
254     nt->_multipath.reset(new Inkscape::UI::MultiPathManipulator(data,
255         nt->_selection_changed_connection));
257     nt->_selector->signal_point.connect(
258         sigc::bind<0>(
259             sigc::ptr_fun(&ink_node_tool_select_point),
260             nt));
261     nt->_selector->signal_area.connect(
262         sigc::bind<0>(
263             sigc::ptr_fun(&ink_node_tool_select_area),
264             nt));
266     nt->_multipath->signal_coords_changed.connect(
267         sigc::bind(
268             sigc::mem_fun(*nt->desktop, &SPDesktop::emitToolSubselectionChanged),
269             (void*) 0));
270     nt->_selected_nodes->signal_point_changed.connect(
271         sigc::hide( sigc::hide(
272             sigc::bind(
273                 sigc::bind(
274                     sigc::ptr_fun(ink_node_tool_update_tip),
275                     (GdkEvent*)0),
276                 nt))));
278     nt->cursor_drag = false;
279     nt->show_transform_handles = true;
280     nt->single_node_transform_handles = false;
281     nt->flash_tempitem = NULL;
282     nt->flashed_item = NULL;
283     nt->_last_over = NULL;
284     // TODO long term, fold ShapeEditor into MultiPathManipulator and rename MPM
285     // to something better
286     nt->shape_editor = new ShapeEditor(nt->desktop);
288     // read prefs before adding items to selection to prevent momentarily showing the outline
289     sp_event_context_read(nt, "show_handles");
290     sp_event_context_read(nt, "show_outline");
291     sp_event_context_read(nt, "live_outline");
292     sp_event_context_read(nt, "live_objects");
293     sp_event_context_read(nt, "show_path_direction");
294     sp_event_context_read(nt, "show_transform_handles");
295     sp_event_context_read(nt, "single_node_transform_handles");
296     sp_event_context_read(nt, "edit_clipping_paths");
297     sp_event_context_read(nt, "edit_masks");
299     ink_node_tool_selection_changed(nt, selection);
300     ink_node_tool_update_tip(nt, NULL);
302     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
303     if (prefs->getBool("/tools/nodes/selcue")) {
304         ec->enableSelectionCue();
305     }
306     if (prefs->getBool("/tools/nodes/gradientdrag")) {
307         ec->enableGrDrag();
308     }
310     nt->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
313 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value)
315     InkNodeTool *nt = INK_NODE_TOOL(ec);
316     Glib::ustring entry_name = value->getEntryName();
318     if (entry_name == "show_handles") {
319         nt->show_handles = value->getBool(true);
320         nt->_multipath->showHandles(nt->show_handles);
321     } else if (entry_name == "show_outline") {
322         nt->show_outline = value->getBool();
323         nt->_multipath->showOutline(nt->show_outline);
324     } else if (entry_name == "live_outline") {
325         nt->live_outline = value->getBool();
326         nt->_multipath->setLiveOutline(nt->live_outline);
327     } else if (entry_name == "live_objects") {
328         nt->live_objects = value->getBool();
329         nt->_multipath->setLiveObjects(nt->live_objects);
330     } else if (entry_name == "show_path_direction") {
331         nt->show_path_direction = value->getBool();
332         nt->_multipath->showPathDirection(nt->show_path_direction);
333     } else if (entry_name == "show_transform_handles") {
334         nt->show_transform_handles = value->getBool(true);
335         nt->_selected_nodes->showTransformHandles(
336             nt->show_transform_handles, nt->single_node_transform_handles);
337     } else if (entry_name == "single_node_transform_handles") {
338         nt->single_node_transform_handles = value->getBool();
339         nt->_selected_nodes->showTransformHandles(
340             nt->show_transform_handles, nt->single_node_transform_handles);
341     } else if (entry_name == "edit_clipping_paths") {
342         nt->edit_clipping_paths = value->getBool();
343         ink_node_tool_selection_changed(nt, nt->desktop->selection);
344     } else if (entry_name == "edit_masks") {
345         nt->edit_masks = value->getBool();
346         ink_node_tool_selection_changed(nt, nt->desktop->selection);
347     } else {
348         SPEventContextClass *parent_class =
349             (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
350         if (parent_class->set)
351             parent_class->set(ec, value);
352     }
355 /** Recursively collect ShapeRecords */
356 void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::ShapeRole role,
357     std::set<Inkscape::UI::ShapeRecord> &s)
359     using namespace Inkscape::UI;
360     if (!obj) return;
362         //XML Tree being used directly here while it shouldn't be.
363     if (SP_IS_PATH(obj) && obj->getRepr()->attribute("inkscape:original-d") != NULL) {
364         ShapeRecord r;
365         r.item = static_cast<SPItem*>(obj);
366         r.edit_transform = Geom::identity(); // TODO wrong?
367         r.role = role;
368         s.insert(r);
369     } else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) {
370         for (SPObject *c = obj->children; c; c = c->next) {
371             gather_items(nt, base, c, role, s);
372         }
373     } else if (SP_IS_ITEM(obj)) {
374         SPItem *item = static_cast<SPItem*>(obj);
375         ShapeRecord r;
376         r.item = item;
377         // TODO add support for objectBoundingBox
378         r.edit_transform = base ? base->i2doc_affine() : Geom::identity();
379         r.role = role;
380         if (s.insert(r).second) {
381             // this item was encountered the first time
382             if (nt->edit_clipping_paths && item->clip_ref) {
383                 gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s);
384             }
385             if (nt->edit_masks && item->mask_ref) {
386                 gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s);
387             }
388         }
389     }
392 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel)
394     using namespace Inkscape::UI;
396     std::set<ShapeRecord> shapes;
398     GSList const *ilist = sel->itemList();
400     for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) {
401         SPObject *obj = static_cast<SPObject*>(i->data);
402         if (SP_IS_ITEM(obj)) {
403             gather_items(nt, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes);
404         }
405     }
407     // ugly hack: set the first editable non-path item for knotholder
408     // maybe use multiple ShapeEditors for now, to allow editing many shapes at once?
409     bool something_set = false;
410     for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
411         ShapeRecord const &r = *i;
413                 //XML Tree being used directly here while it shouldn't be.
414         if (SP_IS_SHAPE(r.item) ||
415             (SP_IS_PATH(r.item) && r.item->getRepr()->attribute("inkscape:original-d") != NULL))
416         {
417             nt->shape_editor->set_item(r.item, SH_KNOTHOLDER);
418             something_set = true;
419             break;
420         }
421     }
422     if (!something_set) {
423         nt->shape_editor->unset_item(SH_KNOTHOLDER);
424     }
426     nt->_multipath->setItems(shapes);
427     ink_node_tool_update_tip(nt, NULL);
428     nt->desktop->updateNow();
431 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event)
433     /* things to handle here:
434      * 1. selection of items
435      * 2. passing events to manipulators
436      * 3. some keybindings
437      */
438     using namespace Inkscape::UI; // pull in event helpers
439     
440     SPDesktop *desktop = event_context->desktop;
441     Inkscape::Selection *selection = desktop->selection;
442     InkNodeTool *nt = static_cast<InkNodeTool*>(event_context);
443     static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
444     
445     if (nt->_multipath->event(event)) return true;
446     if (nt->_selector->event(event)) return true;
447     if (nt->_selected_nodes->event(event)) return true;
449     switch (event->type)
450     {
451     case GDK_MOTION_NOTIFY: {
452         combine_motion_events(desktop->canvas, event->motion, 0);
453         SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
454                 FALSE, TRUE);
455         if (over_item != nt->_last_over) {
456             nt->_last_over = over_item;
457             ink_node_tool_update_tip(nt, event);
458         }
460         // create pathflash outline
461         if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
462             if (over_item == nt->flashed_item) break;
463             if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) break;
464             if (nt->flash_tempitem) {
465                 desktop->remove_temporary_canvasitem(nt->flash_tempitem);
466                 nt->flash_tempitem = NULL;
467                 nt->flashed_item = NULL;
468             }
469             if (!SP_IS_PATH(over_item)) break; // for now, handle only paths
471             nt->flashed_item = over_item;
472             SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(over_item));
473             c->transform(over_item->i2d_affine());
474             SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
475             sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
476                 prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
477                 SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
478             sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO);
479             nt->flash_tempitem = desktop->add_temporary_canvasitem(flash,
480                 prefs->getInt("/tools/nodes/pathflash_timeout", 500));
481             c->unref();
482         }
483         } break; // do not return true, because we need to pass this event to the parent context
484         // otherwise some features cease to work
486     case GDK_KEY_PRESS:
487         switch (get_group0_keyval(&event->key))
488         {
489         case GDK_Escape: // deselect everything
490             if (nt->_selected_nodes->empty()) {
491                 selection->clear();
492             } else {
493                 nt->_selected_nodes->clear();
494             }
495             ink_node_tool_update_tip(nt, event);
496             return TRUE;
497         case GDK_a:
498         case GDK_A:
499             if (held_control(event->key) && held_alt(event->key)) {
500                 nt->_selected_nodes->selectAll();
501                 // Ctrl+A is handled in selection-chemistry.cpp via verb
502                 ink_node_tool_update_tip(nt, event);
503                 return TRUE;
504             }
505             break;
506         case GDK_h:
507         case GDK_H:
508             if (held_only_control(event->key)) {
509                 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
510                 prefs->setBool("/tools/nodes/show_handles", !nt->show_handles);
511                 return TRUE;
512             }
513             break;
514         default:
515             break;
516         }
517         ink_node_tool_update_tip(nt, event);
518         break;
519     case GDK_KEY_RELEASE:
520         ink_node_tool_update_tip(nt, event);
521         break;
522     default: break;
523     }
524     
525     SPEventContextClass *parent_class = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
526     if (parent_class->root_handler)
527         return parent_class->root_handler(event_context, event);
528     return FALSE;
531 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event)
533     using namespace Inkscape::UI;
534     if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
535         unsigned new_state = state_after_event(event);
536         if (new_state == event->key.state) return;
537         if (state_held_shift(new_state)) {
538             if (nt->_last_over) {
539                 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
540                     C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection, "
541                     "click to toggle object selection"));
542             } else {
543                 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
544                     C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection"));
545             }
546             return;
547         }
548     }
549     unsigned sz = nt->_selected_nodes->size();
550     unsigned total = nt->_selected_nodes->allPoints().size();
551     if (sz != 0) {
552         if (nt->_last_over) {
553             char *dyntip = g_strdup_printf(C_("Node tool tip",
554                 "<b>%u of %u nodes</b> selected. "
555                 "Drag to select nodes, click to edit only this object (more: Shift)"), sz, total);
556             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
557             g_free(dyntip);
558         } else {
559             char *dyntip = g_strdup_printf(C_("Node tool tip",
560                 "<b>%u of %u nodes</b> selected. "
561                 "Drag to select nodes, click clear the selection"), sz, total);
562             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
563             g_free(dyntip);
564         }
565     } else if (!nt->_multipath->empty()) {
566         if (nt->_last_over) {
567             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
568                 "Drag to select nodes, click to edit only this object"));
569         } else {
570             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
571                 "Drag to select nodes, click to clear the selection"));
572         }
573     } else {
574         if (nt->_last_over) {
575             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
576                 "Drag to select objects to edit, click to edit this object (more: Shift)"));
577         } else {
578             nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
579                 "Drag to select objects to edit"));
580         }
581     }
584 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
586     SPEventContextClass *parent_class =
587         (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
588     if (parent_class->item_handler)
589         return parent_class->item_handler(event_context, item, event);
590     return FALSE;
593 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventButton *event)
595     using namespace Inkscape::UI;
596     if (nt->_multipath->empty()) {
597         // if multipath is empty, select rubberbanded items rather than nodes
598         Inkscape::Selection *selection = nt->desktop->selection;
599         GSList *items = sp_desktop_document(nt->desktop)->items_in_box(nt->desktop->dkey, sel);
600         selection->setList(items);
601         g_slist_free(items);
602     } else {
603         if (!held_shift(*event)) nt->_selected_nodes->clear();
604         nt->_selected_nodes->selectArea(sel);
605     }
607 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, GdkEventButton *event)
609     using namespace Inkscape::UI; // pull in event helpers
610     if (!event) return;
611     if (event->button != 1) return;
613     Inkscape::Selection *selection = nt->desktop->selection;
615     SPItem *item_clicked = sp_event_context_find_item (nt->desktop, event_point(*event),
616                     (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE);
618     if (item_clicked == NULL) { // nothing under cursor
619         // if no Shift, deselect
620         if (!(event->state & GDK_SHIFT_MASK)) {
621             selection->clear();
622         }
623     } else {
624         if (held_shift(*event)) {
625             selection->toggle(item_clicked);
626         } else {
627             selection->set(item_clicked);
628         }
629         nt->desktop->updateNow();
630     }
633 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p)
635     using Inkscape::UI::CurveDragPoint;
636     CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p);
637     if (cdp && !nt->cursor_drag) {
638         nt->cursor_shape = cursor_node_d_xpm;
639         nt->hot_x = 1;
640         nt->hot_y = 1;
641         sp_event_context_update_cursor(nt);
642         nt->cursor_drag = true;
643     } else if (!cdp && nt->cursor_drag) {
644         nt->cursor_shape = cursor_node_xpm;
645         nt->hot_x = 1;
646         nt->hot_y = 1;
647         sp_event_context_update_cursor(nt);
648         nt->cursor_drag = false;
649     }
652 } // anonymous namespace
654 /*
655   Local Variables:
656   mode:c++
657   c-file-style:"stroustrup"
658   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
659   indent-tabs-mode:nil
660   fill-column:99
661   End:
662 */
663 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :