1 #define __SP_NODE_CONTEXT_C__
3 /*
4 * Node editing context
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * This code is in public domain
11 */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16 #include <cstring>
17 #include <string>
18 #include <gdk/gdkkeysyms.h>
19 #include "macros.h"
20 #include <glibmm/i18n.h>
21 #include "display/sp-canvas-util.h"
22 #include "object-edit.h"
23 #include "sp-path.h"
24 #include "path-chemistry.h"
25 #include "rubberband.h"
26 #include "desktop.h"
27 #include "desktop-handles.h"
28 #include "selection.h"
29 #include "pixmaps/cursor-node.xpm"
30 #include "message-context.h"
31 #include "node-context.h"
32 #include "pixmaps/cursor-node-d.xpm"
33 #include "preferences.h"
34 #include "xml/node-event-vector.h"
35 #include "style.h"
36 #include "splivarot.h"
37 #include "shape-editor.h"
38 #include "live_effects/effect.h"
40 #include "sp-lpe-item.h"
42 // needed for flash nodepath upon mouseover:
43 #include "display/canvas-bpath.h"
44 #include "display/curve.h"
46 static void sp_node_context_class_init(SPNodeContextClass *klass);
47 static void sp_node_context_init(SPNodeContext *node_context);
48 static void sp_node_context_dispose(GObject *object);
50 static void sp_node_context_setup(SPEventContext *ec);
51 static gint sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event);
52 static gint sp_node_context_item_handler(SPEventContext *event_context,
53 SPItem *item, GdkEvent *event);
55 static SPEventContextClass *parent_class;
57 GType
58 sp_node_context_get_type()
59 {
60 static GType type = 0;
61 if (!type) {
62 GTypeInfo info = {
63 sizeof(SPNodeContextClass),
64 NULL, NULL,
65 (GClassInitFunc) sp_node_context_class_init,
66 NULL, NULL,
67 sizeof(SPNodeContext),
68 4,
69 (GInstanceInitFunc) sp_node_context_init,
70 NULL, /* value_table */
71 };
72 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPNodeContext", &info, (GTypeFlags)0);
73 }
74 return type;
75 }
77 static void
78 sp_node_context_class_init(SPNodeContextClass *klass)
79 {
80 GObjectClass *object_class = (GObjectClass *) klass;
81 SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
83 parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
85 object_class->dispose = sp_node_context_dispose;
87 event_context_class->setup = sp_node_context_setup;
88 event_context_class->root_handler = sp_node_context_root_handler;
89 event_context_class->item_handler = sp_node_context_item_handler;
90 }
92 static void
93 sp_node_context_init(SPNodeContext *node_context)
94 {
95 SPEventContext *event_context = SP_EVENT_CONTEXT(node_context);
97 event_context->cursor_shape = cursor_node_xpm;
98 event_context->hot_x = 1;
99 event_context->hot_y = 1;
101 node_context->leftalt = FALSE;
102 node_context->rightalt = FALSE;
103 node_context->leftctrl = FALSE;
104 node_context->rightctrl = FALSE;
106 new (&node_context->sel_changed_connection) sigc::connection();
108 node_context->flash_tempitem = NULL;
109 node_context->flashed_item = NULL;
110 node_context->remove_flash_counter = 0;
111 }
113 static void
114 sp_node_context_dispose(GObject *object)
115 {
116 SPNodeContext *nc = SP_NODE_CONTEXT(object);
117 SPEventContext *ec = SP_EVENT_CONTEXT(object);
119 ec->enableGrDrag(false);
121 nc->sel_changed_connection.disconnect();
122 nc->sel_changed_connection.~connection();
124 delete ec->shape_editor;
126 if (nc->_node_message_context) {
127 delete nc->_node_message_context;
128 }
130 G_OBJECT_CLASS(parent_class)->dispose(object);
131 }
133 static void
134 sp_node_context_setup(SPEventContext *ec)
135 {
136 SPNodeContext *nc = SP_NODE_CONTEXT(ec);
138 if (((SPEventContextClass *) parent_class)->setup)
139 ((SPEventContextClass *) parent_class)->setup(ec);
141 Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
142 nc->sel_changed_connection.disconnect();
143 nc->sel_changed_connection =
144 selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
146 SPItem *item = selection->singleItem();
148 ec->shape_editor = new ShapeEditor(ec->desktop);
150 nc->rb_escaped = false;
152 nc->cursor_drag = false;
154 nc->added_node = false;
156 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
158 if (item) {
159 ec->shape_editor->set_item(item, SH_NODEPATH);
160 ec->shape_editor->set_item(item, SH_KNOTHOLDER);
161 }
163 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
164 if (prefs->getBool("/tools/nodes/selcue")) {
165 ec->enableSelectionCue();
166 }
167 if (prefs->getBool("/tools/nodes/gradientdrag")) {
168 ec->enableGrDrag();
169 }
171 ec->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
173 nc->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
175 ec->shape_editor->update_statusbar();
176 }
178 static void
179 sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) {
180 SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
182 nc->remove_flash_counter = 3; // for some reason root_handler is called twice after each item_handler...
183 if (nc->flashed_item != item) {
184 // we entered a new item
185 nc->flashed_item = item;
186 SPDesktop *desktop = event_context->desktop;
187 if (nc->flash_tempitem) {
188 desktop->remove_temporary_canvasitem(nc->flash_tempitem);
189 nc->flash_tempitem = NULL;
190 }
192 SPCanvasItem *canvasitem = NULL;
193 if (SP_IS_PATH(item)) {
194 canvasitem = sp_nodepath_helperpath_from_path(desktop, SP_PATH(item));
195 } else {
196 g_print ("-----> sp_node_context_flash_path(): TODO: generate the helper path!!\n");
197 }
199 if (canvasitem) {
200 nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
201 }
202 }
203 }
205 /**
206 \brief Callback that processes the "changed" signal on the selection;
207 destroys old and creates new nodepath and reassigns listeners to the new selected item's repr
208 */
209 void
210 sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data)
211 {
212 SPEventContext *ec = SP_EVENT_CONTEXT(data);
214 // TODO: update ShapeEditorsCollective instead
215 ec->shape_editor->unset_item(SH_NODEPATH);
216 ec->shape_editor->unset_item(SH_KNOTHOLDER);
217 SPItem *item = selection->singleItem();
218 ec->shape_editor->set_item(item, SH_NODEPATH);
219 ec->shape_editor->set_item(item, SH_KNOTHOLDER);
220 ec->shape_editor->update_statusbar();
221 }
223 void
224 sp_node_context_show_modifier_tip(SPEventContext *event_context, GdkEvent *event)
225 {
226 sp_event_show_modifier_tip
227 (event_context->defaultMessageContext(), event,
228 _("<b>Ctrl</b>: toggle node type, snap handle angle, move hor/vert; <b>Ctrl+Alt</b>: move along handles"),
229 _("<b>Shift</b>: toggle node selection, disable snapping, rotate both handles"),
230 _("<b>Alt</b>: lock handle length; <b>Ctrl+Alt</b>: move along handles"));
231 }
233 static gint
234 sp_node_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
235 {
236 gint ret = FALSE;
237 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
239 if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
240 guint timeout = prefs->getInt("/tools/nodes/pathflash_timeout", 500);
241 if (SP_IS_LPE_ITEM(item)) {
242 Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
243 if (lpe && (lpe->providesOwnFlashPaths() ||
244 lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH)) {
245 // path should be suppressed or permanent; this is handled in
246 // sp_node_context_selection_changed()
247 return ret;
248 }
249 }
250 sp_node_context_flash_path(event_context, item, timeout);
251 }
253 if (((SPEventContextClass *) parent_class)->item_handler)
254 ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
256 return ret;
257 }
259 static gint
260 sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event)
261 {
262 SPDesktop *desktop = event_context->desktop;
263 ShapeEditor* se = event_context->shape_editor;
264 Inkscape::Selection *selection = sp_desktop_selection (desktop);
265 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
267 SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
268 double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
269 event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); // read every time, to make prefs changes really live
270 int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
271 double const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000);
273 if ( (nc->flash_tempitem) && (nc->remove_flash_counter <= 0) ) {
274 desktop->remove_temporary_canvasitem(nc->flash_tempitem);
275 nc->flash_tempitem = NULL;
276 nc->flashed_item = NULL; // also reset this one, so the next time the same object is hovered over it shows again the highlight
277 } else {
278 nc->remove_flash_counter--;
279 }
281 gint ret = FALSE;
282 switch (event->type) {
283 case GDK_BUTTON_PRESS:
284 if (event->button.button == 1 && !event_context->space_panning) {
285 // save drag origin
286 event_context->xp = (gint) event->button.x;
287 event_context->yp = (gint) event->button.y;
288 event_context->within_tolerance = true;
289 se->cancel_hit();
291 if (!(event->button.state & GDK_SHIFT_MASK)) {
292 if (!nc->drag) {
293 if (se->has_nodepath() && selection->single() /* && item_over */) {
294 // save drag origin
295 bool over_stroke = se->is_over_stroke(Geom::Point(event->button.x, event->button.y), true);
296 //only dragging curves
297 if (over_stroke) {
298 ret = TRUE;
299 break;
300 }
301 }
302 }
303 }
304 Geom::Point const button_w(event->button.x,
305 event->button.y);
306 Geom::Point const button_dt(desktop->w2d(button_w));
307 Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
308 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
309 desktop->updateNow();
310 ret = TRUE;
311 }
312 break;
313 case GDK_MOTION_NOTIFY:
314 if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
316 if ( event_context->within_tolerance
317 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
318 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
319 break; // do not drag if we're within tolerance from origin
320 }
322 // The path went away while dragging; throw away any further motion
323 // events until the mouse pointer is released.
325 if (se->hits_curve() && !se->has_nodepath()) {
326 break;
327 }
329 // Once the user has moved farther than tolerance from the original location
330 // (indicating they intend to move the object, not click), then always process the
331 // motion notify coordinates as given (no snapping back to origin)
332 event_context->within_tolerance = false;
334 // Once we determine what the user is doing (dragging either a node or the
335 // selection rubberband), make sure we continue to perform that operation
336 // until the mouse pointer is lifted.
337 if (nc->current_state == SP_NODE_CONTEXT_INACTIVE) {
338 if (se->hits_curve() && se->has_nodepath()) {
339 nc->current_state = SP_NODE_CONTEXT_NODE_DRAGGING;
340 } else {
341 nc->current_state = SP_NODE_CONTEXT_RUBBERBAND_DRAGGING;
342 }
343 }
345 switch (nc->current_state) {
346 case SP_NODE_CONTEXT_NODE_DRAGGING:
347 {
348 se->curve_drag (event->motion.x, event->motion.y);
350 gobble_motion_events(GDK_BUTTON1_MASK);
351 break;
352 }
353 case SP_NODE_CONTEXT_RUBBERBAND_DRAGGING:
354 if (Inkscape::Rubberband::get(desktop)->is_started()) {
355 Geom::Point const motion_w(event->motion.x,
356 event->motion.y);
357 Geom::Point const motion_dt(desktop->w2d(motion_w));
358 Inkscape::Rubberband::get(desktop)->move(motion_dt);
359 }
360 break;
361 }
363 nc->drag = TRUE;
364 ret = TRUE;
365 } else {
366 if (!se->has_nodepath() || selection->singleItem() == NULL) {
367 break;
368 }
370 bool over_stroke = false;
371 over_stroke = se->is_over_stroke(Geom::Point(event->motion.x, event->motion.y), false);
373 if (nc->cursor_drag && !over_stroke) {
374 event_context->cursor_shape = cursor_node_xpm;
375 event_context->hot_x = 1;
376 event_context->hot_y = 1;
377 sp_event_context_update_cursor(event_context);
378 nc->cursor_drag = false;
379 } else if (!nc->cursor_drag && over_stroke) {
380 event_context->cursor_shape = cursor_node_d_xpm;
381 event_context->hot_x = 1;
382 event_context->hot_y = 1;
383 sp_event_context_update_cursor(event_context);
384 nc->cursor_drag = true;
385 }
386 }
387 break;
389 case GDK_2BUTTON_PRESS:
390 case GDK_BUTTON_RELEASE:
391 if ( (event->button.button == 1) && (!nc->drag) && !event_context->space_panning) {
392 // find out clicked item, disregarding groups, honoring Alt
393 SPItem *item_clicked = sp_event_context_find_item (desktop,
394 Geom::Point(event->button.x, event->button.y),
395 (event->button.state & GDK_MOD1_MASK) && !(event->button.state & GDK_CONTROL_MASK), TRUE);
397 event_context->xp = event_context->yp = 0;
399 bool over_stroke = false;
400 if (se->has_nodepath()) {
401 over_stroke = se->is_over_stroke(Geom::Point(event->button.x, event->button.y), false);
402 }
404 if (item_clicked || over_stroke) {
405 if (over_stroke || nc->added_node) {
406 switch (event->type) {
407 case GDK_BUTTON_RELEASE:
408 if (event->button.state & GDK_CONTROL_MASK && event->button.state & GDK_MOD1_MASK) {
409 //add a node
410 se->add_node_near_point();
411 } else {
412 if (nc->added_node) { // we just received double click, ignore release
413 nc->added_node = false;
414 break;
415 }
416 //select the segment
417 if (event->button.state & GDK_SHIFT_MASK) {
418 se->select_segment_near_point(true);
419 } else {
420 se->select_segment_near_point(false);
421 }
422 desktop->updateNow();
423 }
424 break;
425 case GDK_2BUTTON_PRESS:
426 //add a node
427 se->add_node_near_point();
428 nc->added_node = true;
429 break;
430 default:
431 break;
432 }
433 } else if (event->button.state & GDK_SHIFT_MASK) {
434 selection->toggle(item_clicked);
435 desktop->updateNow();
436 } else {
437 selection->set(item_clicked);
438 desktop->updateNow();
439 }
440 Inkscape::Rubberband::get(desktop)->stop();
441 ret = TRUE;
442 break;
443 }
444 }
445 if (event->type == GDK_BUTTON_RELEASE) {
446 event_context->xp = event_context->yp = 0;
447 if (event->button.button == 1) {
448 Geom::OptRect b = Inkscape::Rubberband::get(desktop)->getRectangle();
450 if (se->hits_curve() && !event_context->within_tolerance) { //drag curve
451 se->finish_drag();
452 } else if (b && !event_context->within_tolerance) { // drag to select
453 se->select_rect(*b, event->button.state & GDK_SHIFT_MASK);
454 } else {
455 if (!(nc->rb_escaped)) { // unless something was cancelled
456 if (se->has_selection())
457 se->deselect();
458 else
459 sp_desktop_selection(desktop)->clear();
460 }
461 }
462 ret = TRUE;
463 Inkscape::Rubberband::get(desktop)->stop();
464 desktop->updateNow();
465 nc->rb_escaped = false;
466 nc->drag = FALSE;
467 se->cancel_hit();
468 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
469 }
470 }
471 break;
472 case GDK_KEY_PRESS:
473 switch (get_group0_keyval(&event->key)) {
474 case GDK_Insert:
475 case GDK_KP_Insert:
476 // with any modifiers
477 se->add_node();
478 ret = TRUE;
479 break;
480 case GDK_Delete:
481 case GDK_KP_Delete:
482 case GDK_BackSpace:
483 if (MOD__CTRL_ONLY) {
484 se->delete_nodes();
485 } else {
486 se->delete_nodes_preserving_shape();
487 }
488 ret = TRUE;
489 break;
490 case GDK_C:
491 case GDK_c:
492 if (MOD__SHIFT_ONLY) {
493 se->set_node_type(Inkscape::NodePath::NODE_CUSP);
494 ret = TRUE;
495 }
496 break;
497 case GDK_S:
498 case GDK_s:
499 if (MOD__SHIFT_ONLY) {
500 se->set_node_type(Inkscape::NodePath::NODE_SMOOTH);
501 ret = TRUE;
502 }
503 break;
504 case GDK_A:
505 case GDK_a:
506 if (MOD__SHIFT_ONLY) {
507 se->set_node_type(Inkscape::NodePath::NODE_AUTO);
508 ret = TRUE;
509 }
510 break;
511 case GDK_Y:
512 case GDK_y:
513 if (MOD__SHIFT_ONLY) {
514 se->set_node_type(Inkscape::NodePath::NODE_SYMM);
515 ret = TRUE;
516 }
517 break;
518 case GDK_B:
519 case GDK_b:
520 if (MOD__SHIFT_ONLY) {
521 se->break_at_nodes();
522 ret = TRUE;
523 }
524 break;
525 case GDK_J:
526 case GDK_j:
527 if (MOD__SHIFT_ONLY) {
528 se->join_nodes();
529 ret = TRUE;
530 }
531 break;
532 case GDK_D:
533 case GDK_d:
534 if (MOD__SHIFT_ONLY) {
535 se->duplicate_nodes();
536 ret = TRUE;
537 }
538 break;
539 case GDK_L:
540 case GDK_l:
541 if (MOD__SHIFT_ONLY) {
542 se->set_type_of_segments(NR_LINETO);
543 ret = TRUE;
544 }
545 break;
546 case GDK_U:
547 case GDK_u:
548 if (MOD__SHIFT_ONLY) {
549 se->set_type_of_segments(NR_CURVETO);
550 ret = TRUE;
551 }
552 break;
553 case GDK_R:
554 case GDK_r:
555 if (MOD__SHIFT_ONLY) {
556 // FIXME: add top panel button
557 sp_selected_path_reverse(desktop);
558 ret = TRUE;
559 }
560 break;
561 case GDK_x:
562 case GDK_X:
563 if (MOD__ALT_ONLY) {
564 desktop->setToolboxFocusTo ("altx-nodes");
565 ret = TRUE;
566 }
567 break;
568 case GDK_Left: // move selection left
569 case GDK_KP_Left:
570 case GDK_KP_4:
571 if (!MOD__CTRL) { // not ctrl
572 gint mul = 1 + gobble_key_events(
573 get_group0_keyval(&event->key), 0); // with any mask
574 if (MOD__ALT) { // alt
575 if (MOD__SHIFT) se->move_nodes_screen(desktop, mul*-10, 0); // shift
576 else se->move_nodes_screen(desktop, mul*-1, 0); // no shift
577 }
578 else { // no alt
579 if (MOD__SHIFT) se->move_nodes(mul*-10*nudge, 0); // shift
580 else se->move_nodes(mul*-nudge, 0); // no shift
581 }
582 ret = TRUE;
583 }
584 break;
585 case GDK_Up: // move selection up
586 case GDK_KP_Up:
587 case GDK_KP_8:
588 if (!MOD__CTRL) { // not ctrl
589 gint mul = 1 + gobble_key_events(
590 get_group0_keyval(&event->key), 0); // with any mask
591 if (MOD__ALT) { // alt
592 if (MOD__SHIFT) se->move_nodes_screen(desktop, 0, mul*10); // shift
593 else se->move_nodes_screen(desktop, 0, mul*1); // no shift
594 }
595 else { // no alt
596 if (MOD__SHIFT) se->move_nodes(0, mul*10*nudge); // shift
597 else se->move_nodes(0, mul*nudge); // no shift
598 }
599 ret = TRUE;
600 }
601 break;
602 case GDK_Right: // move selection right
603 case GDK_KP_Right:
604 case GDK_KP_6:
605 if (!MOD__CTRL) { // not ctrl
606 gint mul = 1 + gobble_key_events(
607 get_group0_keyval(&event->key), 0); // with any mask
608 if (MOD__ALT) { // alt
609 if (MOD__SHIFT) se->move_nodes_screen(desktop, mul*10, 0); // shift
610 else se->move_nodes_screen(desktop, mul*1, 0); // no shift
611 }
612 else { // no alt
613 if (MOD__SHIFT) se->move_nodes(mul*10*nudge, 0); // shift
614 else se->move_nodes(mul*nudge, 0); // no shift
615 }
616 ret = TRUE;
617 }
618 break;
619 case GDK_Down: // move selection down
620 case GDK_KP_Down:
621 case GDK_KP_2:
622 if (!MOD__CTRL) { // not ctrl
623 gint mul = 1 + gobble_key_events(
624 get_group0_keyval(&event->key), 0); // with any mask
625 if (MOD__ALT) { // alt
626 if (MOD__SHIFT) se->move_nodes_screen(desktop, 0, mul*-10); // shift
627 else se->move_nodes_screen(desktop, 0, mul*-1); // no shift
628 }
629 else { // no alt
630 if (MOD__SHIFT) se->move_nodes(0, mul*-10*nudge); // shift
631 else se->move_nodes(0, mul*-nudge); // no shift
632 }
633 ret = TRUE;
634 }
635 break;
636 case GDK_Escape:
637 {
638 Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle();
639 if (b) {
640 Inkscape::Rubberband::get(desktop)->stop();
641 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
642 nc->rb_escaped = true;
643 } else {
644 if (se->has_selection()) {
645 se->deselect();
646 } else {
647 sp_desktop_selection(desktop)->clear();
648 }
649 }
650 ret = TRUE;
651 break;
652 }
654 case GDK_bracketleft:
655 if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
656 if (nc->leftctrl)
657 se->rotate_nodes (M_PI/snaps, -1, false);
658 if (nc->rightctrl)
659 se->rotate_nodes (M_PI/snaps, 1, false);
660 } else if ( MOD__ALT && !MOD__CTRL ) {
661 if (nc->leftalt && nc->rightalt)
662 se->rotate_nodes (1, 0, true);
663 else {
664 if (nc->leftalt)
665 se->rotate_nodes (1, -1, true);
666 if (nc->rightalt)
667 se->rotate_nodes (1, 1, true);
668 }
669 } else if ( snaps != 0 ) {
670 se->rotate_nodes (M_PI/snaps, 0, false);
671 }
672 ret = TRUE;
673 break;
674 case GDK_bracketright:
675 if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
676 if (nc->leftctrl)
677 se->rotate_nodes (-M_PI/snaps, -1, false);
678 if (nc->rightctrl)
679 se->rotate_nodes (-M_PI/snaps, 1, false);
680 } else if ( MOD__ALT && !MOD__CTRL ) {
681 if (nc->leftalt && nc->rightalt)
682 se->rotate_nodes (-1, 0, true);
683 else {
684 if (nc->leftalt)
685 se->rotate_nodes (-1, -1, true);
686 if (nc->rightalt)
687 se->rotate_nodes (-1, 1, true);
688 }
689 } else if ( snaps != 0 ) {
690 se->rotate_nodes (-M_PI/snaps, 0, false);
691 }
692 ret = TRUE;
693 break;
694 case GDK_less:
695 case GDK_comma:
696 if (MOD__CTRL) {
697 if (nc->leftctrl)
698 se->scale_nodes(-offset, -1);
699 if (nc->rightctrl)
700 se->scale_nodes(-offset, 1);
701 } else if (MOD__ALT) {
702 if (nc->leftalt && nc->rightalt)
703 se->scale_nodes_screen (-1, 0);
704 else {
705 if (nc->leftalt)
706 se->scale_nodes_screen (-1, -1);
707 if (nc->rightalt)
708 se->scale_nodes_screen (-1, 1);
709 }
710 } else {
711 se->scale_nodes (-offset, 0);
712 }
713 ret = TRUE;
714 break;
715 case GDK_greater:
716 case GDK_period:
717 if (MOD__CTRL) {
718 if (nc->leftctrl)
719 se->scale_nodes (offset, -1);
720 if (nc->rightctrl)
721 se->scale_nodes (offset, 1);
722 } else if (MOD__ALT) {
723 if (nc->leftalt && nc->rightalt)
724 se->scale_nodes_screen (1, 0);
725 else {
726 if (nc->leftalt)
727 se->scale_nodes_screen (1, -1);
728 if (nc->rightalt)
729 se->scale_nodes_screen (1, 1);
730 }
731 } else {
732 se->scale_nodes (offset, 0);
733 }
734 ret = TRUE;
735 break;
737 case GDK_Alt_L:
738 nc->leftalt = TRUE;
739 sp_node_context_show_modifier_tip(event_context, event);
740 break;
741 case GDK_Alt_R:
742 nc->rightalt = TRUE;
743 sp_node_context_show_modifier_tip(event_context, event);
744 break;
745 case GDK_Control_L:
746 nc->leftctrl = TRUE;
747 sp_node_context_show_modifier_tip(event_context, event);
748 break;
749 case GDK_Control_R:
750 nc->rightctrl = TRUE;
751 sp_node_context_show_modifier_tip(event_context, event);
752 break;
753 case GDK_Shift_L:
754 case GDK_Shift_R:
755 case GDK_Meta_L:
756 case GDK_Meta_R:
757 sp_node_context_show_modifier_tip(event_context, event);
758 break;
759 default:
760 ret = node_key(event);
761 break;
762 }
763 break;
764 case GDK_KEY_RELEASE:
765 switch (get_group0_keyval(&event->key)) {
766 case GDK_Alt_L:
767 nc->leftalt = FALSE;
768 event_context->defaultMessageContext()->clear();
769 break;
770 case GDK_Alt_R:
771 nc->rightalt = FALSE;
772 event_context->defaultMessageContext()->clear();
773 break;
774 case GDK_Control_L:
775 nc->leftctrl = FALSE;
776 event_context->defaultMessageContext()->clear();
777 break;
778 case GDK_Control_R:
779 nc->rightctrl = FALSE;
780 event_context->defaultMessageContext()->clear();
781 break;
782 case GDK_Shift_L:
783 case GDK_Shift_R:
784 case GDK_Meta_L:
785 case GDK_Meta_R:
786 event_context->defaultMessageContext()->clear();
787 break;
788 }
789 break;
790 default:
791 break;
792 }
794 if (!ret) {
795 if (((SPEventContextClass *) parent_class)->root_handler)
796 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
797 }
799 return ret;
800 }
803 /*
804 Local Variables:
805 mode:c++
806 c-file-style:"stroustrup"
807 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
808 indent-tabs-mode:nil
809 fill-column:99
810 End:
811 */
812 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :