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