Code

3f241850e76f9bc3407f77b9ea490e30e470aa12
[inkscape.git] / src / node-context.cpp
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;
105     
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;
113 static void
114 sp_node_context_dispose(GObject *object)
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 nc->shape_editor;
126     if (nc->_node_message_context) {
127         delete nc->_node_message_context;
128     }
130     G_OBJECT_CLASS(parent_class)->dispose(object);
133 static void
134 sp_node_context_setup(SPEventContext *ec)
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     nc->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         nc->shape_editor->set_item(item, SH_NODEPATH);
160         nc->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     nc->shape_editor->update_statusbar();
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         }
198         
199         if (canvasitem) {
200             nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
201         }
202     }
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)
212     SPNodeContext *nc = SP_NODE_CONTEXT(data);
214     // TODO: update ShapeEditorsCollective instead
215     nc->shape_editor->unset_item(SH_NODEPATH);
216     nc->shape_editor->unset_item(SH_KNOTHOLDER);
217     SPItem *item = selection->singleItem(); 
218     nc->shape_editor->set_item(item, SH_NODEPATH);
219     nc->shape_editor->set_item(item, SH_KNOTHOLDER);
220     nc->shape_editor->update_statusbar();
223 void
224 sp_node_context_show_modifier_tip(SPEventContext *event_context, GdkEvent *event)
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"));
233 static gint
234 sp_node_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
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;
259 static gint
260 sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event)
262     SPDesktop *desktop = event_context->desktop;
263     Inkscape::Selection *selection = sp_desktop_selection (desktop);
264     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
266     SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
267     double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
268     event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); // read every time, to make prefs changes really live
269     int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
270     double const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000);
272     if ( (nc->flash_tempitem) && (nc->remove_flash_counter <= 0) ) {
273         desktop->remove_temporary_canvasitem(nc->flash_tempitem);
274         nc->flash_tempitem = NULL;
275         nc->flashed_item = NULL; // also reset this one, so the next time the same object is hovered over it shows again the highlight
276     } else {
277         nc->remove_flash_counter--;
278     }
280     gint ret = FALSE;
281     switch (event->type) {
282         case GDK_BUTTON_PRESS:
283             if (event->button.button == 1 && !event_context->space_panning) {
284                 // save drag origin
285                 event_context->xp = (gint) event->button.x;
286                 event_context->yp = (gint) event->button.y;
287                 event_context->within_tolerance = true;
288                 nc->shape_editor->cancel_hit();
290                 if (!(event->button.state & GDK_SHIFT_MASK)) {
291                     if (!nc->drag) {
292                         if (nc->shape_editor->has_nodepath() && selection->single() /* && item_over */) {
293                             // save drag origin
294                             bool over_stroke = nc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), true);
295                             //only dragging curves
296                             if (over_stroke) {
297                                 ret = TRUE;
298                                 break;
299                             }
300                         }
301                     }
302                 }
303                 Geom::Point const button_w(event->button.x,
304                                          event->button.y);
305                 Geom::Point const button_dt(desktop->w2d(button_w));
306                 Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
307                 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
308                 desktop->updateNow();
309                 ret = TRUE;
310             }
311             break;
312         case GDK_MOTION_NOTIFY:
313             if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
315                 if ( event_context->within_tolerance
316                      && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
317                      && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
318                     break; // do not drag if we're within tolerance from origin
319                 }
321                 // The path went away while dragging; throw away any further motion
322                 // events until the mouse pointer is released.
323                 
324                 if (nc->shape_editor->hits_curve() && !nc->shape_editor->has_nodepath()) {
325                   break;
326                 }
328                 // Once the user has moved farther than tolerance from the original location
329                 // (indicating they intend to move the object, not click), then always process the
330                 // motion notify coordinates as given (no snapping back to origin)
331                 event_context->within_tolerance = false;
333                 // Once we determine what the user is doing (dragging either a node or the
334                 // selection rubberband), make sure we continue to perform that operation
335                 // until the mouse pointer is lifted.
336                 if (nc->current_state == SP_NODE_CONTEXT_INACTIVE) {
337                     if (nc->shape_editor->hits_curve() && nc->shape_editor->has_nodepath()) {
338                         nc->current_state = SP_NODE_CONTEXT_NODE_DRAGGING;
339                     } else {
340                         nc->current_state = SP_NODE_CONTEXT_RUBBERBAND_DRAGGING;
341                     }
342                 }
344                 switch (nc->current_state) {
345                     case SP_NODE_CONTEXT_NODE_DRAGGING:
346                         {
347                             nc->shape_editor->curve_drag (event->motion.x, event->motion.y);
349                             gobble_motion_events(GDK_BUTTON1_MASK);
350                             break;
351                         }
352                     case SP_NODE_CONTEXT_RUBBERBAND_DRAGGING:
353                         if (Inkscape::Rubberband::get(desktop)->is_started()) {
354                             Geom::Point const motion_w(event->motion.x,
355                                                 event->motion.y);
356                             Geom::Point const motion_dt(desktop->w2d(motion_w));
357                             Inkscape::Rubberband::get(desktop)->move(motion_dt);
358                         }
359                         break;
360                 }
362                 nc->drag = TRUE;
363                 ret = TRUE;
364             } else {
365                 if (!nc->shape_editor->has_nodepath() || selection->singleItem() == NULL) {
366                     break;
367                 }
369                 bool over_stroke = false;
370                 over_stroke = nc->shape_editor->is_over_stroke(Geom::Point(event->motion.x, event->motion.y), false);
372                 if (nc->cursor_drag && !over_stroke) {
373                     event_context->cursor_shape = cursor_node_xpm;
374                     event_context->hot_x = 1;
375                     event_context->hot_y = 1;
376                     sp_event_context_update_cursor(event_context);
377                     nc->cursor_drag = false;
378                 } else if (!nc->cursor_drag && over_stroke) {
379                     event_context->cursor_shape = cursor_node_d_xpm;
380                     event_context->hot_x = 1;
381                     event_context->hot_y = 1;
382                     sp_event_context_update_cursor(event_context);
383                     nc->cursor_drag = true;
384                 }
385             }
386             break;
388         case GDK_2BUTTON_PRESS:
389         case GDK_BUTTON_RELEASE:
390             if ( (event->button.button == 1) && (!nc->drag) && !event_context->space_panning) {
391                 // find out clicked item, disregarding groups, honoring Alt
392                 SPItem *item_clicked = sp_event_context_find_item (desktop,
393                         Geom::Point(event->button.x, event->button.y),
394                         (event->button.state & GDK_MOD1_MASK) && !(event->button.state & GDK_CONTROL_MASK), TRUE);
396                 event_context->xp = event_context->yp = 0;
398                 bool over_stroke = false;
399                 if (nc->shape_editor->has_nodepath()) {
400                     over_stroke = nc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), false);
401                 }
403                 if (item_clicked || over_stroke) {
404                     if (over_stroke || nc->added_node) {
405                         switch (event->type) {
406                             case GDK_BUTTON_RELEASE:
407                                 if (event->button.state & GDK_CONTROL_MASK && event->button.state & GDK_MOD1_MASK) {
408                                     //add a node
409                                     nc->shape_editor->add_node_near_point();
410                                 } else {
411                                     if (nc->added_node) { // we just received double click, ignore release
412                                         nc->added_node = false;
413                                         break;
414                                     }
415                                     //select the segment
416                                     if (event->button.state & GDK_SHIFT_MASK) {
417                                         nc->shape_editor->select_segment_near_point(true);
418                                     } else {
419                                         nc->shape_editor->select_segment_near_point(false);
420                                     }
421                                     desktop->updateNow();
422                                 }
423                                 break;
424                             case GDK_2BUTTON_PRESS:
425                                 //add a node
426                                 nc->shape_editor->add_node_near_point();
427                                 nc->added_node = true;
428                                 break;
429                             default:
430                                 break;
431                         }
432                     } else if (event->button.state & GDK_SHIFT_MASK) {
433                         selection->toggle(item_clicked);
434                         desktop->updateNow();
435                     } else {
436                         selection->set(item_clicked);
437                         desktop->updateNow();
438                     }
439                     Inkscape::Rubberband::get(desktop)->stop();
440                     ret = TRUE;
441                     break;
442                 }
443             } 
444             if (event->type == GDK_BUTTON_RELEASE) {
445                 event_context->xp = event_context->yp = 0;
446                 if (event->button.button == 1) {
447                     Geom::OptRect b = Inkscape::Rubberband::get(desktop)->getRectangle();
449                     if (nc->shape_editor->hits_curve() && !event_context->within_tolerance) { //drag curve
450                         nc->shape_editor->finish_drag();
451                     } else if (b && !event_context->within_tolerance) { // drag to select
452                         nc->shape_editor->select_rect(*b, event->button.state & GDK_SHIFT_MASK);
453                     } else {
454                         if (!(nc->rb_escaped)) { // unless something was cancelled
455                             if (nc->shape_editor->has_selection())
456                                 nc->shape_editor->deselect();
457                             else
458                                 sp_desktop_selection(desktop)->clear();
459                         }
460                     }
461                     ret = TRUE;
462                     Inkscape::Rubberband::get(desktop)->stop();
463                     desktop->updateNow();
464                     nc->rb_escaped = false;
465                     nc->drag = FALSE;
466                     nc->shape_editor->cancel_hit();
467                     nc->current_state = SP_NODE_CONTEXT_INACTIVE;
468                 }
469             }
470             break;
471         case GDK_KEY_PRESS:
472             switch (get_group0_keyval(&event->key)) {
473                 case GDK_Insert:
474                 case GDK_KP_Insert:
475                     // with any modifiers
476                     nc->shape_editor->add_node();
477                     ret = TRUE;
478                     break;
479                 case GDK_Delete:
480                 case GDK_KP_Delete:
481                 case GDK_BackSpace:
482                     if (MOD__CTRL_ONLY) {
483                         nc->shape_editor->delete_nodes();
484                     } else {
485                         nc->shape_editor->delete_nodes_preserving_shape();
486                     }
487                     ret = TRUE;
488                     break;
489                 case GDK_C:
490                 case GDK_c:
491                     if (MOD__SHIFT_ONLY) {
492                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_CUSP);
493                         ret = TRUE;
494                     }
495                     break;
496                 case GDK_S:
497                 case GDK_s:
498                     if (MOD__SHIFT_ONLY) {
499                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_SMOOTH);
500                         ret = TRUE;
501                     }
502                     break;
503                 case GDK_A:
504                 case GDK_a:
505                     if (MOD__SHIFT_ONLY) {
506                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_AUTO);
507                         ret = TRUE;
508                     }
509                     break;
510                 case GDK_Y:
511                 case GDK_y:
512                     if (MOD__SHIFT_ONLY) {
513                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_SYMM);
514                         ret = TRUE;
515                     }
516                     break;
517                 case GDK_B:
518                 case GDK_b:
519                     if (MOD__SHIFT_ONLY) {
520                         nc->shape_editor->break_at_nodes();
521                         ret = TRUE;
522                     }
523                     break;
524                 case GDK_J:
525                 case GDK_j:
526                     if (MOD__SHIFT_ONLY) {
527                         nc->shape_editor->join_nodes();
528                         ret = TRUE;
529                     }
530                     break;
531                 case GDK_D:
532                 case GDK_d:
533                     if (MOD__SHIFT_ONLY) {
534                         nc->shape_editor->duplicate_nodes();
535                         ret = TRUE;
536                     }
537                     break;
538                 case GDK_L:
539                 case GDK_l:
540                     if (MOD__SHIFT_ONLY) {
541                         nc->shape_editor->set_type_of_segments(NR_LINETO);
542                         ret = TRUE;
543                     }
544                     break;
545                 case GDK_U:
546                 case GDK_u:
547                     if (MOD__SHIFT_ONLY) {
548                         nc->shape_editor->set_type_of_segments(NR_CURVETO);
549                         ret = TRUE;
550                     }
551                     break;
552                 case GDK_R:
553                 case GDK_r:
554                     if (MOD__SHIFT_ONLY) {
555                         // FIXME: add top panel button
556                         sp_selected_path_reverse(desktop);
557                         ret = TRUE;
558                     }
559                     break;
560                 case GDK_x:
561                 case GDK_X:
562                     if (MOD__ALT_ONLY) {
563                         desktop->setToolboxFocusTo ("altx-nodes");
564                         ret = TRUE;
565                     }
566                     break;
567                 case GDK_Left: // move selection left
568                 case GDK_KP_Left:
569                 case GDK_KP_4:
570                     if (!MOD__CTRL) { // not ctrl
571                         gint mul = 1 + gobble_key_events(
572                             get_group0_keyval(&event->key), 0); // with any mask
573                         if (MOD__ALT) { // alt
574                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(desktop, mul*-10, 0); // shift
575                             else nc->shape_editor->move_nodes_screen(desktop, mul*-1, 0); // no shift
576                         }
577                         else { // no alt
578                             if (MOD__SHIFT) nc->shape_editor->move_nodes(mul*-10*nudge, 0); // shift
579                             else nc->shape_editor->move_nodes(mul*-nudge, 0); // no shift
580                         }
581                         ret = TRUE;
582                     }
583                     break;
584                 case GDK_Up: // move selection up
585                 case GDK_KP_Up:
586                 case GDK_KP_8:
587                     if (!MOD__CTRL) { // not ctrl
588                         gint mul = 1 + gobble_key_events(
589                             get_group0_keyval(&event->key), 0); // with any mask
590                         if (MOD__ALT) { // alt
591                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(desktop, 0, mul*10); // shift
592                             else nc->shape_editor->move_nodes_screen(desktop, 0, mul*1); // no shift
593                         }
594                         else { // no alt
595                             if (MOD__SHIFT) nc->shape_editor->move_nodes(0, mul*10*nudge); // shift
596                             else nc->shape_editor->move_nodes(0, mul*nudge); // no shift
597                         }
598                         ret = TRUE;
599                     }
600                     break;
601                 case GDK_Right: // move selection right
602                 case GDK_KP_Right:
603                 case GDK_KP_6:
604                     if (!MOD__CTRL) { // not ctrl
605                         gint mul = 1 + gobble_key_events(
606                             get_group0_keyval(&event->key), 0); // with any mask
607                         if (MOD__ALT) { // alt
608                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(desktop, mul*10, 0); // shift
609                             else nc->shape_editor->move_nodes_screen(desktop, mul*1, 0); // no shift
610                         }
611                         else { // no alt
612                             if (MOD__SHIFT) nc->shape_editor->move_nodes(mul*10*nudge, 0); // shift
613                             else nc->shape_editor->move_nodes(mul*nudge, 0); // no shift
614                         }
615                         ret = TRUE;
616                     }
617                     break;
618                 case GDK_Down: // move selection down
619                 case GDK_KP_Down:
620                 case GDK_KP_2:
621                     if (!MOD__CTRL) { // not ctrl
622                         gint mul = 1 + gobble_key_events(
623                             get_group0_keyval(&event->key), 0); // with any mask
624                         if (MOD__ALT) { // alt
625                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(desktop, 0, mul*-10); // shift
626                             else nc->shape_editor->move_nodes_screen(desktop, 0, mul*-1); // no shift
627                         }
628                         else { // no alt
629                             if (MOD__SHIFT) nc->shape_editor->move_nodes(0, mul*-10*nudge); // shift
630                             else nc->shape_editor->move_nodes(0, mul*-nudge); // no shift
631                         }
632                         ret = TRUE;
633                     }
634                     break;
635                 case GDK_Escape:
636                 {
637                     Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle();
638                     if (b) {
639                         Inkscape::Rubberband::get(desktop)->stop();
640                         nc->current_state = SP_NODE_CONTEXT_INACTIVE;
641                         nc->rb_escaped = true;
642                     } else {
643                         if (nc->shape_editor->has_selection()) {
644                             nc->shape_editor->deselect();
645                         } else {
646                             sp_desktop_selection(desktop)->clear();
647                         }
648                     }
649                     ret = TRUE;
650                     break;
651                 }
653                 case GDK_bracketleft:
654                     if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
655                         if (nc->leftctrl)
656                             nc->shape_editor->rotate_nodes (M_PI/snaps, -1, false);
657                         if (nc->rightctrl)
658                             nc->shape_editor->rotate_nodes (M_PI/snaps, 1, false);
659                     } else if ( MOD__ALT && !MOD__CTRL ) {
660                         if (nc->leftalt && nc->rightalt)
661                             nc->shape_editor->rotate_nodes (1, 0, true);
662                         else {
663                             if (nc->leftalt)
664                                 nc->shape_editor->rotate_nodes (1, -1, true);
665                             if (nc->rightalt)
666                                 nc->shape_editor->rotate_nodes (1, 1, true);
667                         }
668                     } else if ( snaps != 0 ) {
669                         nc->shape_editor->rotate_nodes (M_PI/snaps, 0, false);
670                     }
671                     ret = TRUE;
672                     break;
673                 case GDK_bracketright:
674                     if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
675                         if (nc->leftctrl)
676                             nc->shape_editor->rotate_nodes (-M_PI/snaps, -1, false);
677                         if (nc->rightctrl)
678                             nc->shape_editor->rotate_nodes (-M_PI/snaps, 1, false);
679                     } else if ( MOD__ALT && !MOD__CTRL ) {
680                         if (nc->leftalt && nc->rightalt)
681                             nc->shape_editor->rotate_nodes (-1, 0, true);
682                         else {
683                             if (nc->leftalt)
684                                 nc->shape_editor->rotate_nodes (-1, -1, true);
685                             if (nc->rightalt)
686                                 nc->shape_editor->rotate_nodes (-1, 1, true);
687                         }
688                     } else if ( snaps != 0 ) {
689                         nc->shape_editor->rotate_nodes (-M_PI/snaps, 0, false);
690                     }
691                     ret = TRUE;
692                     break;
693                 case GDK_less:
694                 case GDK_comma:
695                     if (MOD__CTRL) {
696                         if (nc->leftctrl)
697                             nc->shape_editor->scale_nodes(-offset, -1);
698                         if (nc->rightctrl)
699                             nc->shape_editor->scale_nodes(-offset, 1);
700                     } else if (MOD__ALT) {
701                         if (nc->leftalt && nc->rightalt)
702                             nc->shape_editor->scale_nodes_screen (-1, 0);
703                         else {
704                             if (nc->leftalt)
705                                 nc->shape_editor->scale_nodes_screen (-1, -1);
706                             if (nc->rightalt)
707                                 nc->shape_editor->scale_nodes_screen (-1, 1);
708                         }
709                     } else {
710                         nc->shape_editor->scale_nodes (-offset, 0);
711                     }
712                     ret = TRUE;
713                     break;
714                 case GDK_greater:
715                 case GDK_period:
716                     if (MOD__CTRL) {
717                         if (nc->leftctrl)
718                             nc->shape_editor->scale_nodes (offset, -1);
719                         if (nc->rightctrl)
720                             nc->shape_editor->scale_nodes (offset, 1);
721                     } else if (MOD__ALT) {
722                         if (nc->leftalt && nc->rightalt)
723                             nc->shape_editor->scale_nodes_screen (1, 0);
724                         else {
725                             if (nc->leftalt)
726                                 nc->shape_editor->scale_nodes_screen (1, -1);
727                             if (nc->rightalt)
728                                 nc->shape_editor->scale_nodes_screen (1, 1);
729                         }
730                     } else {
731                         nc->shape_editor->scale_nodes (offset, 0);
732                     }
733                     ret = TRUE;
734                     break;
736                 case GDK_Alt_L:
737                     nc->leftalt = TRUE;
738                     sp_node_context_show_modifier_tip(event_context, event);
739                     break;
740                 case GDK_Alt_R:
741                     nc->rightalt = TRUE;
742                     sp_node_context_show_modifier_tip(event_context, event);
743                     break;
744                 case GDK_Control_L:
745                     nc->leftctrl = TRUE;
746                     sp_node_context_show_modifier_tip(event_context, event);
747                     break;
748                 case GDK_Control_R:
749                     nc->rightctrl = TRUE;
750                     sp_node_context_show_modifier_tip(event_context, event);
751                     break;
752                 case GDK_Shift_L:
753                 case GDK_Shift_R:
754                 case GDK_Meta_L:
755                 case GDK_Meta_R:
756                     sp_node_context_show_modifier_tip(event_context, event);
757                     break;
758                 default:
759                     ret = node_key(event);
760                     break;
761             }
762             break;
763         case GDK_KEY_RELEASE:
764             switch (get_group0_keyval(&event->key)) {
765                 case GDK_Alt_L:
766                     nc->leftalt = FALSE;
767                     event_context->defaultMessageContext()->clear();
768                     break;
769                 case GDK_Alt_R:
770                     nc->rightalt = FALSE;
771                     event_context->defaultMessageContext()->clear();
772                     break;
773                 case GDK_Control_L:
774                     nc->leftctrl = FALSE;
775                     event_context->defaultMessageContext()->clear();
776                     break;
777                 case GDK_Control_R:
778                     nc->rightctrl = FALSE;
779                     event_context->defaultMessageContext()->clear();
780                     break;
781                 case GDK_Shift_L:
782                 case GDK_Shift_R:
783                 case GDK_Meta_L:
784                 case GDK_Meta_R:
785                     event_context->defaultMessageContext()->clear();
786                     break;
787             }
788             break;
789         default:
790             break;
791     }
793     if (!ret) {
794         if (((SPEventContextClass *) parent_class)->root_handler)
795             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
796     }
798     return ret;
802 /*
803   Local Variables:
804   mode:c++
805   c-file-style:"stroustrup"
806   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
807   indent-tabs-mode:nil
808   fill-column:99
809   End:
810 */
811 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :