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