Code

update 2geom
[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 "prefs-utils.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     // TODO: should this be here?
125     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
126     if (item && SP_IS_LPE_ITEM(item)) {
127         sp_lpe_item_remove_temporary_canvasitems(SP_LPE_ITEM(item), ec->desktop);
128     }
130     delete nc->shape_editor;
132     if (nc->_node_message_context) {
133         delete nc->_node_message_context;
134     }
136     G_OBJECT_CLASS(parent_class)->dispose(object);
139 static void
140 sp_node_context_setup(SPEventContext *ec)
142     SPNodeContext *nc = SP_NODE_CONTEXT(ec);
144     if (((SPEventContextClass *) parent_class)->setup)
145         ((SPEventContextClass *) parent_class)->setup(ec);
147     Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
148     nc->sel_changed_connection.disconnect();
149     nc->sel_changed_connection =
150         selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
152     SPItem *item = selection->singleItem();
154     nc->shape_editor = new ShapeEditor(ec->desktop);
156     nc->rb_escaped = false;
158     nc->cursor_drag = false;
160     nc->added_node = false;
162     nc->current_state = SP_NODE_CONTEXT_INACTIVE;
164     if (item) {
165         nc->shape_editor->set_item(item);
166     }
168     if (prefs_get_int_attribute("tools.nodes", "selcue", 0) != 0) {
169         ec->enableSelectionCue();
170     }
172     if (prefs_get_int_attribute("tools.nodes", "gradientdrag", 0) != 0) {
173         ec->enableGrDrag();
174     }
176     ec->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
178     nc->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
180     nc->shape_editor->update_statusbar();
183 static void
184 sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) {
185     SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
187     nc->remove_flash_counter = 3; // for some reason root_handler is called twice after each item_handler...
188     if (nc->flashed_item != item) {
189         // we entered a new item
190         nc->flashed_item = item;
191         SPDesktop *desktop = event_context->desktop;
192         if (nc->flash_tempitem) {
193             desktop->remove_temporary_canvasitem(nc->flash_tempitem);
194             nc->flash_tempitem = NULL;
195         }
197         if (SP_IS_PATH(item)) {
198             SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(item));
199             nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
200         }
201     }
204 /**
205 \brief  Callback that processes the "changed" signal on the selection;
206 destroys old and creates new nodepath and reassigns listeners to the new selected item's repr
207 */
208 void
209 sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data)
211     SPNodeContext *nc = SP_NODE_CONTEXT(data);
213     // TODO: update ShapeEditorsCollective instead
214     nc->shape_editor->unset_item();
215     SPItem *item = selection->singleItem(); 
216     nc->shape_editor->set_item(item);
217     nc->shape_editor->update_statusbar();
220 void
221 sp_node_context_show_modifier_tip(SPEventContext *event_context, GdkEvent *event)
223     sp_event_show_modifier_tip
224         (event_context->defaultMessageContext(), event,
225          _("<b>Ctrl</b>: toggle node type, snap handle angle, move hor/vert; <b>Ctrl+Alt</b>: move along handles"),
226          _("<b>Shift</b>: toggle node selection, disable snapping, rotate both handles"),
227          _("<b>Alt</b>: lock handle length; <b>Ctrl+Alt</b>: move along handles"));
230 static gint
231 sp_node_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
233     gint ret = FALSE;
235     if (prefs_get_int_attribute ("tools.nodes", "pathflash_enabled", 0) == 1) {
236         guint timeout = prefs_get_int_attribute("tools.nodes", "pathflash_timeout", 500);
237         if (SP_IS_LPE_ITEM(item)) {
238             Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
239             if (lpe && (lpe->providesOwnFlashPaths() ||
240                         lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH)) {
241                 // path should be suppressed or permanent; this is handled in
242                 // sp_node_context_selection_changed()
243                 return ret;
244             }
245         }
246         sp_node_context_flash_path(event_context, item, timeout);
247     }
249     if (((SPEventContextClass *) parent_class)->item_handler)
250         ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
252     return ret;
255 static gint
256 sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event)
258     SPDesktop *desktop = event_context->desktop;
259     Inkscape::Selection *selection = sp_desktop_selection (desktop);
261     SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
262     double const nudge = prefs_get_double_attribute_limited("options.nudgedistance", "value", 2, 0, 1000); // in px
263     event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); // read every time, to make prefs changes really live
264     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
265     double const offset = prefs_get_double_attribute_limited("options.defaultscale", "value", 2, 0, 1000);
267     if ( (nc->flash_tempitem) && (nc->remove_flash_counter <= 0) ) {
268         desktop->remove_temporary_canvasitem(nc->flash_tempitem);
269         nc->flash_tempitem = NULL;
270         nc->flashed_item = NULL; // also reset this one, so the next time the same object is hovered over it shows again the highlight
271     } else {
272         nc->remove_flash_counter--;
273     }
275     gint ret = FALSE;
276     switch (event->type) {
277         case GDK_BUTTON_PRESS:
278             if (event->button.button == 1 && !event_context->space_panning) {
279                 // save drag origin
280                 event_context->xp = (gint) event->button.x;
281                 event_context->yp = (gint) event->button.y;
282                 event_context->within_tolerance = true;
283                 nc->shape_editor->cancel_hit();
285                 if (!(event->button.state & GDK_SHIFT_MASK)) {
286                     if (!nc->drag) {
287                         if (nc->shape_editor->has_nodepath() && selection->single() /* && item_over */) {
288                             // save drag origin
289                             bool over_stroke = nc->shape_editor->is_over_stroke(NR::Point(event->button.x, event->button.y), true);
290                             //only dragging curves
291                             if (over_stroke) {
292                                 ret = TRUE;
293                                 break;
294                             }
295                         }
296                     }
297                 }
298                 NR::Point const button_w(event->button.x,
299                                          event->button.y);
300                 NR::Point const button_dt(desktop->w2d(button_w));
301                 Inkscape::Rubberband::get()->start(desktop, button_dt);
302                 nc->current_state = SP_NODE_CONTEXT_INACTIVE;
303                 desktop->updateNow();
304                 ret = TRUE;
305             }
306             break;
307         case GDK_MOTION_NOTIFY:
308             if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
310                 if ( event_context->within_tolerance
311                      && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
312                      && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
313                     break; // do not drag if we're within tolerance from origin
314                 }
316                 // The path went away while dragging; throw away any further motion
317                 // events until the mouse pointer is released.
318                 
319                 if (nc->shape_editor->hits_curve() && !nc->shape_editor->has_nodepath()) {
320                   break;
321                 }
323                 // Once the user has moved farther than tolerance from the original location
324                 // (indicating they intend to move the object, not click), then always process the
325                 // motion notify coordinates as given (no snapping back to origin)
326                 event_context->within_tolerance = false;
328                 // Once we determine what the user is doing (dragging either a node or the
329                 // selection rubberband), make sure we continue to perform that operation
330                 // until the mouse pointer is lifted.
331                 if (nc->current_state == SP_NODE_CONTEXT_INACTIVE) {
332                     if (nc->shape_editor->hits_curve() && nc->shape_editor->has_nodepath()) {
333                         nc->current_state = SP_NODE_CONTEXT_NODE_DRAGGING;
334                     } else {
335                         nc->current_state = SP_NODE_CONTEXT_RUBBERBAND_DRAGGING;
336                     }
337                 }
339                 switch (nc->current_state) {
340                     case SP_NODE_CONTEXT_NODE_DRAGGING:
341                         {
342                             nc->shape_editor->curve_drag (event->motion.x, event->motion.y);
344                             gobble_motion_events(GDK_BUTTON1_MASK);
345                             break;
346                         }
347                     case SP_NODE_CONTEXT_RUBBERBAND_DRAGGING:
348                         if (Inkscape::Rubberband::get()->is_started()) {
349                             NR::Point const motion_w(event->motion.x,
350                                                 event->motion.y);
351                             NR::Point const motion_dt(desktop->w2d(motion_w));
352                             Inkscape::Rubberband::get()->move(motion_dt);
353                         }
354                         break;
355                 }
357                 nc->drag = TRUE;
358                 ret = TRUE;
359             } else {
360                 if (!nc->shape_editor->has_nodepath() || selection->singleItem() == NULL) {
361                     break;
362                 }
364                 bool over_stroke = false;
365                 over_stroke = nc->shape_editor->is_over_stroke(NR::Point(event->motion.x, event->motion.y), false);
367                 if (nc->cursor_drag && !over_stroke) {
368                     event_context->cursor_shape = cursor_node_xpm;
369                     event_context->hot_x = 1;
370                     event_context->hot_y = 1;
371                     sp_event_context_update_cursor(event_context);
372                     nc->cursor_drag = false;
373                 } else if (!nc->cursor_drag && over_stroke) {
374                     event_context->cursor_shape = cursor_node_d_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 = true;
379                 }
380             }
381             break;
383         case GDK_2BUTTON_PRESS:
384         case GDK_BUTTON_RELEASE:
385             if ( (event->button.button == 1) && (!nc->drag) && !event_context->space_panning) {
386                 // find out clicked item, disregarding groups, honoring Alt
387                 SPItem *item_clicked = sp_event_context_find_item (desktop,
388                         NR::Point(event->button.x, event->button.y),
389                         (event->button.state & GDK_MOD1_MASK) && !(event->button.state & GDK_CONTROL_MASK), TRUE);
391                 event_context->xp = event_context->yp = 0;
393                 bool over_stroke = false;
394                 if (nc->shape_editor->has_nodepath()) {
395                     over_stroke = nc->shape_editor->is_over_stroke(NR::Point(event->button.x, event->button.y), false);
396                 }
398                 if (item_clicked || over_stroke) {
399                     if (over_stroke || nc->added_node) {
400                         switch (event->type) {
401                             case GDK_BUTTON_RELEASE:
402                                 if (event->button.state & GDK_CONTROL_MASK && event->button.state & GDK_MOD1_MASK) {
403                                     //add a node
404                                     nc->shape_editor->add_node_near_point();
405                                 } else {
406                                     if (nc->added_node) { // we just received double click, ignore release
407                                         nc->added_node = false;
408                                         break;
409                                     }
410                                     //select the segment
411                                     if (event->button.state & GDK_SHIFT_MASK) {
412                                         nc->shape_editor->select_segment_near_point(true);
413                                     } else {
414                                         nc->shape_editor->select_segment_near_point(false);
415                                     }
416                                     desktop->updateNow();
417                                 }
418                                 break;
419                             case GDK_2BUTTON_PRESS:
420                                 //add a node
421                                 nc->shape_editor->add_node_near_point();
422                                 nc->added_node = true;
423                                 break;
424                             default:
425                                 break;
426                         }
427                     } else if (event->button.state & GDK_SHIFT_MASK) {
428                         selection->toggle(item_clicked);
429                         desktop->updateNow();
430                     } else {
431                         selection->set(item_clicked);
432                         desktop->updateNow();
433                     }
434                     Inkscape::Rubberband::get()->stop();
435                     ret = TRUE;
436                     break;
437                 }
438             } 
439             if (event->type == GDK_BUTTON_RELEASE) {
440                 event_context->xp = event_context->yp = 0;
441                 if (event->button.button == 1) {
442                     NR::Maybe<NR::Rect> b = Inkscape::Rubberband::get()->getRectangle();
444                     if (nc->shape_editor->hits_curve() && !event_context->within_tolerance) { //drag curve
445                         nc->shape_editor->finish_drag();
446                     } else if (b && !event_context->within_tolerance) { // drag to select
447                         nc->shape_editor->select_rect(*b, event->button.state & GDK_SHIFT_MASK);
448                     } else {
449                         if (!(nc->rb_escaped)) { // unless something was cancelled
450                             if (nc->shape_editor->has_selection())
451                                 nc->shape_editor->deselect();
452                             else
453                                 sp_desktop_selection(desktop)->clear();
454                         }
455                     }
456                     ret = TRUE;
457                     Inkscape::Rubberband::get()->stop();
458                     desktop->updateNow();
459                     nc->rb_escaped = false;
460                     nc->drag = FALSE;
461                     nc->shape_editor->cancel_hit();
462                     nc->current_state = SP_NODE_CONTEXT_INACTIVE;
463                 }
464             }
465             break;
466         case GDK_KEY_PRESS:
467             switch (get_group0_keyval(&event->key)) {
468                 case GDK_Insert:
469                 case GDK_KP_Insert:
470                     // with any modifiers
471                     nc->shape_editor->add_node();
472                     ret = TRUE;
473                     break;
474                 case GDK_Delete:
475                 case GDK_KP_Delete:
476                 case GDK_BackSpace:
477                     if (MOD__CTRL_ONLY) {
478                         nc->shape_editor->delete_nodes();
479                     } else {
480                         nc->shape_editor->delete_nodes_preserving_shape();
481                     }
482                     ret = TRUE;
483                     break;
484                 case GDK_C:
485                 case GDK_c:
486                     if (MOD__SHIFT_ONLY) {
487                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_CUSP);
488                         ret = TRUE;
489                     }
490                     break;
491                 case GDK_S:
492                 case GDK_s:
493                     if (MOD__SHIFT_ONLY) {
494                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_SMOOTH);
495                         ret = TRUE;
496                     }
497                     break;
498                 case GDK_Y:
499                 case GDK_y:
500                     if (MOD__SHIFT_ONLY) {
501                         nc->shape_editor->set_node_type(Inkscape::NodePath::NODE_SYMM);
502                         ret = TRUE;
503                     }
504                     break;
505                 case GDK_B:
506                 case GDK_b:
507                     if (MOD__SHIFT_ONLY) {
508                         nc->shape_editor->break_at_nodes();
509                         ret = TRUE;
510                     }
511                     break;
512                 case GDK_J:
513                 case GDK_j:
514                     if (MOD__SHIFT_ONLY) {
515                         nc->shape_editor->join_nodes();
516                         ret = TRUE;
517                     }
518                     break;
519                 case GDK_D:
520                 case GDK_d:
521                     if (MOD__SHIFT_ONLY) {
522                         nc->shape_editor->duplicate_nodes();
523                         ret = TRUE;
524                     }
525                     break;
526                 case GDK_L:
527                 case GDK_l:
528                     if (MOD__SHIFT_ONLY) {
529                         nc->shape_editor->set_type_of_segments(NR_LINETO);
530                         ret = TRUE;
531                     }
532                     break;
533                 case GDK_U:
534                 case GDK_u:
535                     if (MOD__SHIFT_ONLY) {
536                         nc->shape_editor->set_type_of_segments(NR_CURVETO);
537                         ret = TRUE;
538                     }
539                     break;
540                 case GDK_R:
541                 case GDK_r:
542                     if (MOD__SHIFT_ONLY) {
543                         // FIXME: add top panel button
544                         sp_selected_path_reverse();
545                         ret = TRUE;
546                     }
547                     break;
548                 case GDK_x:
549                 case GDK_X:
550                     if (MOD__ALT_ONLY) {
551                         desktop->setToolboxFocusTo ("altx-nodes");
552                         ret = TRUE;
553                     }
554                     break;
555                 case GDK_Left: // move selection left
556                 case GDK_KP_Left:
557                 case GDK_KP_4:
558                     if (!MOD__CTRL) { // not ctrl
559                         gint mul = 1 + gobble_key_events(
560                             get_group0_keyval(&event->key), 0); // with any mask
561                         if (MOD__ALT) { // alt
562                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(mul*-10, 0); // shift
563                             else nc->shape_editor->move_nodes_screen(mul*-1, 0); // no shift
564                         }
565                         else { // no alt
566                             if (MOD__SHIFT) nc->shape_editor->move_nodes(mul*-10*nudge, 0); // shift
567                             else nc->shape_editor->move_nodes(mul*-nudge, 0); // no shift
568                         }
569                         ret = TRUE;
570                     }
571                     break;
572                 case GDK_Up: // move selection up
573                 case GDK_KP_Up:
574                 case GDK_KP_8:
575                     if (!MOD__CTRL) { // not ctrl
576                         gint mul = 1 + gobble_key_events(
577                             get_group0_keyval(&event->key), 0); // with any mask
578                         if (MOD__ALT) { // alt
579                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(0, mul*10); // shift
580                             else nc->shape_editor->move_nodes_screen(0, mul*1); // no shift
581                         }
582                         else { // no alt
583                             if (MOD__SHIFT) nc->shape_editor->move_nodes(0, mul*10*nudge); // shift
584                             else nc->shape_editor->move_nodes(0, mul*nudge); // no shift
585                         }
586                         ret = TRUE;
587                     }
588                     break;
589                 case GDK_Right: // move selection right
590                 case GDK_KP_Right:
591                 case GDK_KP_6:
592                     if (!MOD__CTRL) { // not ctrl
593                         gint mul = 1 + gobble_key_events(
594                             get_group0_keyval(&event->key), 0); // with any mask
595                         if (MOD__ALT) { // alt
596                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(mul*10, 0); // shift
597                             else nc->shape_editor->move_nodes_screen(mul*1, 0); // no shift
598                         }
599                         else { // no alt
600                             if (MOD__SHIFT) nc->shape_editor->move_nodes(mul*10*nudge, 0); // shift
601                             else nc->shape_editor->move_nodes(mul*nudge, 0); // no shift
602                         }
603                         ret = TRUE;
604                     }
605                     break;
606                 case GDK_Down: // move selection down
607                 case GDK_KP_Down:
608                 case GDK_KP_2:
609                     if (!MOD__CTRL) { // not ctrl
610                         gint mul = 1 + gobble_key_events(
611                             get_group0_keyval(&event->key), 0); // with any mask
612                         if (MOD__ALT) { // alt
613                             if (MOD__SHIFT) nc->shape_editor->move_nodes_screen(0, mul*-10); // shift
614                             else nc->shape_editor->move_nodes_screen(0, mul*-1); // no shift
615                         }
616                         else { // no alt
617                             if (MOD__SHIFT) nc->shape_editor->move_nodes(0, mul*-10*nudge); // shift
618                             else nc->shape_editor->move_nodes(0, mul*-nudge); // no shift
619                         }
620                         ret = TRUE;
621                     }
622                     break;
623                 case GDK_Escape:
624                 {
625                     NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
626                     if (b) {
627                         Inkscape::Rubberband::get()->stop();
628                         nc->current_state = SP_NODE_CONTEXT_INACTIVE;
629                         nc->rb_escaped = true;
630                     } else {
631                         if (nc->shape_editor->has_selection()) {
632                             nc->shape_editor->deselect();
633                         } else {
634                             sp_desktop_selection(desktop)->clear();
635                         }
636                     }
637                     ret = TRUE;
638                     break;
639                 }
641                 case GDK_bracketleft:
642                     if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
643                         if (nc->leftctrl)
644                             nc->shape_editor->rotate_nodes (M_PI/snaps, -1, false);
645                         if (nc->rightctrl)
646                             nc->shape_editor->rotate_nodes (M_PI/snaps, 1, false);
647                     } else if ( MOD__ALT && !MOD__CTRL ) {
648                         if (nc->leftalt && nc->rightalt)
649                             nc->shape_editor->rotate_nodes (1, 0, true);
650                         else {
651                             if (nc->leftalt)
652                                 nc->shape_editor->rotate_nodes (1, -1, true);
653                             if (nc->rightalt)
654                                 nc->shape_editor->rotate_nodes (1, 1, true);
655                         }
656                     } else if ( snaps != 0 ) {
657                         nc->shape_editor->rotate_nodes (M_PI/snaps, 0, false);
658                     }
659                     ret = TRUE;
660                     break;
661                 case GDK_bracketright:
662                     if ( MOD__CTRL && !MOD__ALT && ( snaps != 0 ) ) {
663                         if (nc->leftctrl)
664                             nc->shape_editor->rotate_nodes (-M_PI/snaps, -1, false);
665                         if (nc->rightctrl)
666                             nc->shape_editor->rotate_nodes (-M_PI/snaps, 1, false);
667                     } else if ( MOD__ALT && !MOD__CTRL ) {
668                         if (nc->leftalt && nc->rightalt)
669                             nc->shape_editor->rotate_nodes (-1, 0, true);
670                         else {
671                             if (nc->leftalt)
672                                 nc->shape_editor->rotate_nodes (-1, -1, true);
673                             if (nc->rightalt)
674                                 nc->shape_editor->rotate_nodes (-1, 1, true);
675                         }
676                     } else if ( snaps != 0 ) {
677                         nc->shape_editor->rotate_nodes (-M_PI/snaps, 0, false);
678                     }
679                     ret = TRUE;
680                     break;
681                 case GDK_less:
682                 case GDK_comma:
683                     if (MOD__CTRL) {
684                         if (nc->leftctrl)
685                             nc->shape_editor->scale_nodes(-offset, -1);
686                         if (nc->rightctrl)
687                             nc->shape_editor->scale_nodes(-offset, 1);
688                     } else if (MOD__ALT) {
689                         if (nc->leftalt && nc->rightalt)
690                             nc->shape_editor->scale_nodes_screen (-1, 0);
691                         else {
692                             if (nc->leftalt)
693                                 nc->shape_editor->scale_nodes_screen (-1, -1);
694                             if (nc->rightalt)
695                                 nc->shape_editor->scale_nodes_screen (-1, 1);
696                         }
697                     } else {
698                         nc->shape_editor->scale_nodes (-offset, 0);
699                     }
700                     ret = TRUE;
701                     break;
702                 case GDK_greater:
703                 case GDK_period:
704                     if (MOD__CTRL) {
705                         if (nc->leftctrl)
706                             nc->shape_editor->scale_nodes (offset, -1);
707                         if (nc->rightctrl)
708                             nc->shape_editor->scale_nodes (offset, 1);
709                     } else if (MOD__ALT) {
710                         if (nc->leftalt && nc->rightalt)
711                             nc->shape_editor->scale_nodes_screen (1, 0);
712                         else {
713                             if (nc->leftalt)
714                                 nc->shape_editor->scale_nodes_screen (1, -1);
715                             if (nc->rightalt)
716                                 nc->shape_editor->scale_nodes_screen (1, 1);
717                         }
718                     } else {
719                         nc->shape_editor->scale_nodes (offset, 0);
720                     }
721                     ret = TRUE;
722                     break;
724                 case GDK_Alt_L:
725                     nc->leftalt = TRUE;
726                     sp_node_context_show_modifier_tip(event_context, event);
727                     break;
728                 case GDK_Alt_R:
729                     nc->rightalt = TRUE;
730                     sp_node_context_show_modifier_tip(event_context, event);
731                     break;
732                 case GDK_Control_L:
733                     nc->leftctrl = TRUE;
734                     sp_node_context_show_modifier_tip(event_context, event);
735                     break;
736                 case GDK_Control_R:
737                     nc->rightctrl = TRUE;
738                     sp_node_context_show_modifier_tip(event_context, event);
739                     break;
740                 case GDK_Shift_L:
741                 case GDK_Shift_R:
742                 case GDK_Meta_L:
743                 case GDK_Meta_R:
744                     sp_node_context_show_modifier_tip(event_context, event);
745                     break;
746                 default:
747                     ret = node_key(event);
748                     break;
749             }
750             break;
751         case GDK_KEY_RELEASE:
752             switch (get_group0_keyval(&event->key)) {
753                 case GDK_Alt_L:
754                     nc->leftalt = FALSE;
755                     event_context->defaultMessageContext()->clear();
756                     break;
757                 case GDK_Alt_R:
758                     nc->rightalt = FALSE;
759                     event_context->defaultMessageContext()->clear();
760                     break;
761                 case GDK_Control_L:
762                     nc->leftctrl = FALSE;
763                     event_context->defaultMessageContext()->clear();
764                     break;
765                 case GDK_Control_R:
766                     nc->rightctrl = FALSE;
767                     event_context->defaultMessageContext()->clear();
768                     break;
769                 case GDK_Shift_L:
770                 case GDK_Shift_R:
771                 case GDK_Meta_L:
772                 case GDK_Meta_R:
773                     event_context->defaultMessageContext()->clear();
774                     break;
775             }
776             break;
777         default:
778             break;
779     }
781     if (!ret) {
782         if (((SPEventContextClass *) parent_class)->root_handler)
783             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
784     }
786     return ret;
790 /*
791   Local Variables:
792   mode:c++
793   c-file-style:"stroustrup"
794   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
795   indent-tabs-mode:nil
796   fill-column:99
797   End:
798 */
799 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :