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