Code

remove color cursors
[inkscape.git] / src / select-context.cpp
1 #define __SP_SELECT_CONTEXT_C__
3 /*
4  * Selection and transformation context
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   bulia byak <buliabyak@users.sf.net>
9  *
10  * Copyright (C) 2006      Johan Engelen <johan@shouraizou.nl>
11  * Copyright (C) 1999-2005 Authors
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
19 #include <gdk/gdkkeysyms.h>
20 #include "macros.h"
21 #include "rubberband.h"
22 #include "document.h"
23 #include "selection.h"
24 #include "seltrans-handles.h"
25 #include "sp-cursor.h"
26 #include "pixmaps/cursor-select-m.xpm"
27 #include "pixmaps/cursor-select-d.xpm"
28 #include "pixmaps/handles.xpm"
29 #include <glibmm/i18n.h>
31 #include "select-context.h"
32 #include "selection-chemistry.h"
33 #include "desktop.h"
34 #include "desktop-handles.h"
35 #include "sp-root.h"
36 #include "prefs-utils.h"
37 #include "tools-switch.h"
38 #include "message-stack.h"
39 #include "selection-describer.h"
40 #include "seltrans.h"
42 static void sp_select_context_class_init(SPSelectContextClass *klass);
43 static void sp_select_context_init(SPSelectContext *select_context);
44 static void sp_select_context_dispose(GObject *object);
46 static void sp_select_context_setup(SPEventContext *ec);
47 static void sp_select_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
48 static gint sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event);
49 static gint sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
51 static SPEventContextClass *parent_class;
53 static GdkCursor *CursorSelectMouseover = NULL;
54 static GdkCursor *CursorSelectDragging = NULL;
55 GdkPixbuf *handles[13];
57 static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so the next button release should not deselect
58 static gint drag_escaped = 0; // if non-zero, drag was canceled by esc
60 static gint xp = 0, yp = 0; // where drag started
61 static gint tolerance = 0;
62 static bool within_tolerance = false;
64 GtkType
65 sp_select_context_get_type(void)
66 {
67     static GType type = 0;
68     if (!type) {
69         GTypeInfo info = {
70             sizeof(SPSelectContextClass),
71             NULL, NULL,
72             (GClassInitFunc) sp_select_context_class_init,
73             NULL, NULL,
74             sizeof(SPSelectContext),
75             4,
76             (GInstanceInitFunc) sp_select_context_init,
77             NULL,   /* value_table */
78         };
79         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPSelectContext", &info, (GTypeFlags)0);
80     }
81     return type;
82 }
84 static void
85 sp_select_context_class_init(SPSelectContextClass *klass)
86 {
87     GObjectClass *object_class = (GObjectClass *) klass;
88     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
90     parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
92     object_class->dispose = sp_select_context_dispose;
94     event_context_class->setup = sp_select_context_setup;
95     event_context_class->set = sp_select_context_set;
96     event_context_class->root_handler = sp_select_context_root_handler;
97     event_context_class->item_handler = sp_select_context_item_handler;
99     // cursors in select context
100     CursorSelectMouseover = sp_cursor_new_from_xpm(cursor_select_m_xpm , 1, 1);
101     CursorSelectDragging = sp_cursor_new_from_xpm(cursor_select_d_xpm , 1, 1);
102     // selection handles
103     handles[0]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_nw_xpm);
104     handles[1]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_ne_xpm);
105     handles[2]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_h_xpm);
106     handles[3]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_v_xpm);
107     handles[4]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_nw_xpm);
108     handles[5]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_n_xpm);
109     handles[6]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_ne_xpm);
110     handles[7]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_e_xpm);
111     handles[8]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_se_xpm);
112     handles[9]  = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_s_xpm);
113     handles[10] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_sw_xpm);
114     handles[11] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_w_xpm);
115     handles[12] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_center_xpm);
119 static void
120 sp_select_context_init(SPSelectContext *sc)
122     sc->dragging = FALSE;
123     sc->moved = FALSE;
124     sc->button_press_shift = false;
125     sc->button_press_ctrl = false;
126     sc->button_press_alt = false;
127     sc->_seltrans = NULL;
128     sc->_describer = NULL;
131 static void
132 sp_select_context_dispose(GObject *object)
134     SPSelectContext *sc = SP_SELECT_CONTEXT(object);
135     SPEventContext * ec = SP_EVENT_CONTEXT (object);
137     ec->enableGrDrag(false);
139     if (sc->grabbed) {
140         sp_canvas_item_ungrab(sc->grabbed, GDK_CURRENT_TIME);
141         sc->grabbed = NULL;
142     }
144     delete sc->_seltrans;
145     sc->_seltrans = NULL;
146     delete sc->_describer;
147     sc->_describer = NULL;
149     if (CursorSelectDragging) {
150         gdk_cursor_unref (CursorSelectDragging);
151         CursorSelectDragging = NULL;
152     }
153     if (CursorSelectMouseover) {
154         gdk_cursor_unref (CursorSelectMouseover);
155         CursorSelectMouseover = NULL;
156     }
158     G_OBJECT_CLASS(parent_class)->dispose(object);
161 static void
162 sp_select_context_setup(SPEventContext *ec)
164     SPSelectContext *select_context = SP_SELECT_CONTEXT(ec);
166     if (((SPEventContextClass *) parent_class)->setup) {
167         ((SPEventContextClass *) parent_class)->setup(ec);
168     }
170     SPDesktop *desktop = ec->desktop;
172     select_context->_describer = new Inkscape::SelectionDescriber(desktop->selection, desktop->messageStack());
174     select_context->_seltrans = new Inkscape::SelTrans(desktop);
176     sp_event_context_read(ec, "show");
177     sp_event_context_read(ec, "transform");
179     if (prefs_get_int_attribute("tools.select", "gradientdrag", 0) != 0) {
180         ec->enableGrDrag();
181     }
184 static void
185 sp_select_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
187     SPSelectContext *sc = SP_SELECT_CONTEXT(ec);
189     if (!strcmp(key, "show")) {
190         if (val && !strcmp(val, "outline")) {
191             sc->_seltrans->setShow(Inkscape::SelTrans::SHOW_OUTLINE);
192         } else {
193             sc->_seltrans->setShow(Inkscape::SelTrans::SHOW_CONTENT);
194         }
195     }
198 static bool
199 sp_select_context_abort(SPEventContext *event_context)
201     SPDesktop *desktop = event_context->desktop;
202     SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
203     Inkscape::SelTrans *seltrans = sc->_seltrans;
205     if (sc->dragging) {
206         if (sc->moved) { // cancel dragging an object
207             seltrans->ungrab();
208             sc->moved = FALSE;
209             sc->dragging = FALSE;
210             drag_escaped = 1;
212             if (sc->item) {
213                 // only undo if the item is still valid
214                 if (SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))) {
215                     sp_document_undo(sp_desktop_document(desktop));
216                 }
218                 sp_object_unref( SP_OBJECT(sc->item), NULL);
219             } else if (sc->button_press_ctrl) {
220                 // NOTE:  This is a workaround to a bug.
221                 // When the ctrl key is held, sc->item is not defined
222                 // so in this case (only), we skip the object doc check
223                 sp_document_undo(sp_desktop_document(desktop));
224             }
225             sc->item = NULL;
227             SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Move canceled."));
228             return true;
229         }
230     } else {
231         NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
232         if (b != NR::Nothing()) {
233             Inkscape::Rubberband::get()->stop();
234             rb_escaped = 1;
235             SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selection canceled."));
236             return true;
237         }
238     }
239     return false;
242 bool
243 key_is_a_modifier (guint key) {
244     return (key == GDK_Alt_L ||
245                 key == GDK_Alt_R ||
246                 key == GDK_Control_L ||
247                 key == GDK_Control_R ||
248                 key == GDK_Shift_L ||
249                 key == GDK_Shift_R ||
250                 key == GDK_Meta_L ||  // Meta is when you press Shift+Alt (at least on my machine)
251             key == GDK_Meta_R);
254 void
255 sp_select_context_up_one_layer(SPDesktop *desktop)
257     /* Click in empty place, go up one level -- but don't leave a layer to root.
258      *
259      * (Rationale: we don't usually allow users to go to the root, since that
260      * detracts from the layer metaphor: objects at the root level can in front
261      * of or behind layers.  Whereas it's fine to go to the root if editing
262      * a document that has no layers (e.g. a non-Inkscape document).)
263      *
264      * Once we support editing SVG "islands" (e.g. <svg> embedded in an xhtml
265      * document), we might consider further restricting the below to disallow
266      * leaving a layer to go to a non-layer.
267      */
268     SPObject *const current_layer = desktop->currentLayer();
269     if (current_layer) {
270         SPObject *const parent = SP_OBJECT_PARENT(current_layer);
271         if ( parent
272              && ( SP_OBJECT_PARENT(parent)
273                   || !( SP_IS_GROUP(current_layer)
274                         && ( SPGroup::LAYER
275                              == SP_GROUP(current_layer)->layerMode() ) ) ) )
276         {
277             desktop->setCurrentLayer(parent);
278             if (SP_IS_GROUP(current_layer) && SPGroup::LAYER != SP_GROUP(current_layer)->layerMode())
279                 sp_desktop_selection(desktop)->set(current_layer);
280         }
281     }
284 static gint
285 sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
287     gint ret = FALSE;
289     SPDesktop *desktop = event_context->desktop;
290     SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
291     Inkscape::SelTrans *seltrans = sc->_seltrans;
293     tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
295     // make sure we still have valid objects to move around
296     if (sc->item && SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))==NULL) {
297         sp_select_context_abort(event_context);
298     }
300     switch (event->type) {
301         case GDK_BUTTON_PRESS:
302             if (event->button.button == 1) {
303                 /* Left mousebutton */
305                 // save drag origin
306                 xp = (gint) event->button.x;
307                 yp = (gint) event->button.y;
308                 within_tolerance = true;
310                 // remember what modifiers were on before button press
311                 sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false;
312                 sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false;
313                 sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false;
315                 if (event->button.state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) {
316                     // if shift or ctrl was pressed, do not move objects;
317                     // pass the event to root handler which will perform rubberband, shift-click, ctrl-click, ctrl-drag
318                 } else {
319                     sc->dragging = TRUE;
320                     sc->moved = FALSE;
322                     sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
323                     
324                     // remember the clicked item in sc->item:
325                     sc->item = sp_event_context_find_item (desktop,
326                                               NR::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, FALSE);
327                     sp_object_ref(sc->item, NULL);
329                     rb_escaped = drag_escaped = 0;
331                     sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->drawing),
332                                         GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK |
333                                         GDK_POINTER_MOTION_MASK,
334                                         NULL, event->button.time);
335                     sc->grabbed = SP_CANVAS_ITEM(desktop->drawing);
337                     sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
339                     ret = TRUE;
340                 }
341             } else if (event->button.button == 3) {
342                 // right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband
343                 sp_select_context_abort(event_context);
344             }
345             break;
347         case GDK_ENTER_NOTIFY:
348         {
349             GdkCursor *cursor = gdk_cursor_new(GDK_FLEUR);
350             gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, cursor);
351             gdk_cursor_destroy(cursor);
352             break;
353         }
355         case GDK_LEAVE_NOTIFY:
356             gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, event_context->cursor);
357             break;
359         case GDK_KEY_PRESS:
360             if (get_group0_keyval (&event->key) == GDK_space) {
361                 if (sc->dragging && sc->grabbed) {
362                     /* stamping mode: show content mode moving */
363                     seltrans->stamp();
364                     ret = TRUE;
365                 }
366             }
367             break;
369         default:
370             break;
371     }
373     if (!ret) {
374         if (((SPEventContextClass *) parent_class)->item_handler)
375             ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
376     }
378     return ret;
381 static gint
382 sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
384     SPItem *item = NULL;
385     SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL;
386     gint ret = FALSE;
388     SPDesktop *desktop = event_context->desktop;
389     SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
390     Inkscape::SelTrans *seltrans = sc->_seltrans;
391     Inkscape::Selection *selection = sp_desktop_selection(desktop);
392     gdouble const nudge = prefs_get_double_attribute_limited("options.nudgedistance", "value", 2, 0, 1000); // in px
393     gdouble const offset = prefs_get_double_attribute_limited("options.defaultscale", "value", 2, 0, 1000);
394     tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
395     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
397     // make sure we still have valid objects to move around
398     if (sc->item && SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))==NULL) {
399         sp_select_context_abort(event_context);
400     }
402     switch (event->type) {
403         case GDK_2BUTTON_PRESS:
404             if (event->button.button == 1) {
405                 if (!selection->isEmpty()) {
406                     SPItem *clicked_item = (SPItem *) selection->itemList()->data;
407                     if (SP_IS_GROUP (clicked_item)) { // enter group
408                         desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
409                         sp_desktop_selection(desktop)->clear();
410                         sc->dragging = false;
412                         sp_canvas_end_forced_full_redraws(desktop->canvas);
413                     } else { // switch tool
414                         tools_switch_by_item (desktop, clicked_item);
415                     }
416                 } else {
417                     sp_select_context_up_one_layer(desktop);
418                 }
419                 ret = TRUE;
420             }
421             break;
422         case GDK_BUTTON_PRESS:
423             if (event->button.button == 1) {
425                 // save drag origin
426                 xp = (gint) event->button.x;
427                 yp = (gint) event->button.y;
428                 within_tolerance = true;
430                 NR::Point const button_pt(event->button.x, event->button.y);
431                 NR::Point const p(desktop->w2d(button_pt));
432                 Inkscape::Rubberband::get()->start(desktop, p);
433                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
434                                     GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK,
435                                     NULL, event->button.time);
436                 sc->grabbed = SP_CANVAS_ITEM(desktop->acetate);
438                 // remember what modifiers were on before button press
439                 sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false;
440                 sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false;
441                 sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false;
443                 sc->moved = FALSE;
445                 rb_escaped = drag_escaped = 0;
447                 ret = TRUE;
448             } else if (event->button.button == 3) {
449                 // right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband
450                 sp_select_context_abort(event_context);
451             }
452             break;
454         case GDK_MOTION_NOTIFY:
455             if (event->motion.state & GDK_BUTTON1_MASK) {
456                 NR::Point const motion_pt(event->motion.x, event->motion.y);
457                 NR::Point const p(desktop->w2d(motion_pt));
459                 if ( within_tolerance
460                      && ( abs( (gint) event->motion.x - xp ) < tolerance )
461                      && ( abs( (gint) event->motion.y - yp ) < tolerance ) ) {
462                     break; // do not drag if we're within tolerance from origin
463                 }
464                 // Once the user has moved farther than tolerance from the original location
465                 // (indicating they intend to move the object, not click), then always process the
466                 // motion notify coordinates as given (no snapping back to origin)
467                 within_tolerance = false;
469                 if (sc->button_press_ctrl || sc->button_press_alt) {
470                     // if ctrl or alt was pressed and it's not click, we want to drag rather than rubberband
471                     sc->dragging = TRUE;
473                     sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
474                 }
476                 if (sc->dragging) {
477                     /* User has dragged fast, so we get events on root (lauris)*/
478                     // not only that; we will end up here when ctrl-dragging as well
479                     // and also when we started within tolerance, but trespassed tolerance outside of item
480                     Inkscape::Rubberband::get()->stop();
481                     item_at_point = desktop->item_at_point(NR::Point(event->button.x, event->button.y), FALSE);
482                     if (!item_at_point) // if no item at this point, try at the click point (bug 1012200)
483                         item_at_point = desktop->item_at_point(NR::Point(xp, yp), FALSE);
484                     if (item_at_point || sc->moved || sc->button_press_alt) {
485                         // drag only if starting from an item, or if something is already grabbed, or if alt-dragging
486                         if (!sc->moved) {
487                             item_in_group = desktop->item_at_point(NR::Point(event->button.x, event->button.y), TRUE);
488                             group_at_point = desktop->group_at_point(NR::Point(event->button.x, event->button.y));
489                             // if neither a group nor an item (possibly in a group) at point are selected, set selection to the item at point
490                             if ((!item_in_group || !selection->includes(item_in_group)) &&
491                                 (!group_at_point || !selection->includes(group_at_point))
492                                 && !sc->button_press_alt) {
493                                 // select what is under cursor
494                                 if (!seltrans->isEmpty()) {
495                                     seltrans->resetState();
496                                 }
497                                 // when simply ctrl-dragging, we don't want to go into groups
498                                 if (item_at_point && !selection->includes(item_at_point))
499                                     selection->set(item_at_point);
500                             } // otherwise, do not change selection so that dragging selected-within-group items, as well as alt-dragging, is possible
501                             seltrans->grab(p, -1, -1, FALSE);
502                             sc->moved = TRUE;
503                         }
504                         if (!seltrans->isEmpty())
505                             seltrans->moveTo(p, event->button.state);
506                         if (desktop->scroll_to_point(&p))
507                             // unfortunately in complex drawings, gobbling results in losing grab of the object, for some mysterious reason
508                             ; //gobble_motion_events(GDK_BUTTON1_MASK);
509                         ret = TRUE;
510                     } else {
511                         sc->dragging = FALSE;
513                         sp_canvas_end_forced_full_redraws(desktop->canvas);
514                     }
515                 } else {
516                     Inkscape::Rubberband::get()->move(p);
517                     gobble_motion_events(GDK_BUTTON1_MASK);
518                 }
519             }
520             break;
521         case GDK_BUTTON_RELEASE:
522             xp = yp = 0;
523             if ((event->button.button == 1) && (sc->grabbed)) {
524                 if (sc->dragging) {
525                     if (sc->moved) {
526                         // item has been moved
527                         seltrans->ungrab();
528                         sc->moved = FALSE;
529                     } else if (sc->item && !drag_escaped) {
530                         // item has not been moved -> simply a click, do selecting
531                         if (!selection->isEmpty()) {
532                             if (event->button.state & GDK_SHIFT_MASK) {
533                                 // with shift, toggle selection
534                                 seltrans->resetState();
535                                 selection->toggle(sc->item);
536                             } else {
537                                 // without shift, increase state (i.e. toggle scale/rotation handles)
538                                 if (selection->includes(sc->item)) {
539                                     seltrans->increaseState();
540                                 } else {
541                                     seltrans->resetState();
542                                     selection->set(sc->item);
543                                 }
544                             }
545                         } else { // simple or shift click, no previous selection
546                             seltrans->resetState();
547                             selection->set(sc->item);
548                         }
549                     }
550                     sc->dragging = FALSE;
552                     sp_canvas_end_forced_full_redraws(desktop->canvas);
554                     if (sc->item) {
555                         sp_object_unref( SP_OBJECT(sc->item), NULL);
556                     }
557                     sc->item = NULL;
558                 } else {
559                     NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
560                     if (b != NR::Nothing() && !within_tolerance) {
561                         // this was a rubberband drag
562                         Inkscape::Rubberband::get()->stop();
563                         seltrans->resetState();
564                         // find out affected items:
565                         GSList *items = sp_document_items_in_box(sp_desktop_document(desktop), desktop->dkey, b.assume());
566                         if (event->button.state & GDK_SHIFT_MASK) {
567                             // with shift, add to selection
568                             selection->addList (items);
569                         } else {
570                             // without shift, simply select anew
571                             selection->setList (items);
572                         }
573                         g_slist_free (items);
574                     } else { // it was just a click, or a too small rubberband
575                         Inkscape::Rubberband::get()->stop();
576                         if (sc->button_press_shift && !rb_escaped && !drag_escaped) {
577                             // this was a shift-click, select what was clicked upon
579                             sc->button_press_shift = false;
581                             if (sc->button_press_ctrl) {
582                                 // go into groups, honoring Alt
583                                 item = sp_event_context_find_item (desktop,
584                                                    NR::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, TRUE);
585                                 sc->button_press_ctrl = FALSE;
586                             } else {
587                                 // don't go into groups, honoring Alt
588                                 item = sp_event_context_find_item (desktop,
589                                                    NR::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, FALSE);
590                             }
592                             if (item) {
593                                 selection->toggle(item);
594                                 item = NULL;
595                             }
597                         } else if (sc->button_press_ctrl && !rb_escaped && !drag_escaped) { // ctrl-click
599                             sc->button_press_ctrl = FALSE;
601                             item = sp_event_context_find_item (desktop,
602                                          NR::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, TRUE);
604                             if (item) {
605                                 if (selection->includes(item)) {
606                                     seltrans->increaseState();
607                                 } else {
608                                     seltrans->resetState();
609                                     selection->set(item);
610                                 }
611                                 item = NULL;
612                             }
614                         } else { // click without shift, simply deselect, unless with Alt or something was cancelled
615                             if (!selection->isEmpty()) {
616                                 if (!(rb_escaped) && !(drag_escaped) && !(event->button.state & GDK_MOD1_MASK))
617                                     selection->clear();
618                                 rb_escaped = 0;
619                                 ret = TRUE;
620                             }
621                         }
622                     }
623                     ret = TRUE;
624                 }
625                 if (sc->grabbed) {
626                     sp_canvas_item_ungrab(sc->grabbed, event->button.time);
627                     sc->grabbed = NULL;
628                 }
629                 
630                 desktop->updateNow();
631             }
632             sc->button_press_shift = false;
633             sc->button_press_ctrl = false;
634             sc->button_press_alt = false;
635             break;
637         case GDK_KEY_PRESS: // keybindings for select context
639             if (!key_is_a_modifier (get_group0_keyval (&event->key))) {
640                     event_context->defaultMessageContext()->clear();
641             } else if (sc->grabbed || seltrans->isGrabbed()) {
642                 // do not change the statusbar text when mousekey is down to move or transform the object,
643                 // because the statusbar text is already updated somewhere else.
644                    break;
645             } else {
646                     sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
647                                                 _("<b>Ctrl</b>: select in groups, move hor/vert"),
648                                                 _("<b>Shift</b>: toggle select, force rubberband, disable snapping"),
649                                                 _("<b>Alt</b>: select under, move selected"));
650                     // if Alt then change cursor to moving cursor:
651                     guint keyval = get_group0_keyval(&event->key);
652                     bool alt = ( MOD__ALT
653                                     || (keyval == GDK_Alt_L)
654                                     || (keyval == GDK_Alt_R)
655                                     || (keyval == GDK_Meta_L)
656                                     || (keyval == GDK_Meta_R));
657                     if (alt) {
658                         GdkCursor *cursor = gdk_cursor_new(GDK_FLEUR);
659                         gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, cursor);
660                         gdk_cursor_destroy(cursor);
661                     }
662                     //*/
663                     break;
664             }
666             switch (get_group0_keyval (&event->key)) {
667                 case GDK_Left: // move selection left
668                 case GDK_KP_Left:
669                 case GDK_KP_4:
670                     if (!MOD__CTRL) { // not ctrl
671                         if (MOD__ALT) { // alt
672                             if (MOD__SHIFT) sp_selection_move_screen(-10, 0); // shift
673                             else sp_selection_move_screen(-1, 0); // no shift
674                         }
675                         else { // no alt
676                             if (MOD__SHIFT) sp_selection_move(-10*nudge, 0); // shift
677                             else sp_selection_move(-nudge, 0); // no shift
678                         }
679                         ret = TRUE;
680                     }
681                     break;
682                 case GDK_Up: // move selection up
683                 case GDK_KP_Up:
684                 case GDK_KP_8:
685                     if (!MOD__CTRL) { // not ctrl
686                         if (MOD__ALT) { // alt
687                             if (MOD__SHIFT) sp_selection_move_screen(0, 10); // shift
688                             else sp_selection_move_screen(0, 1); // no shift
689                         }
690                         else { // no alt
691                             if (MOD__SHIFT) sp_selection_move(0, 10*nudge); // shift
692                             else sp_selection_move(0, nudge); // no shift
693                         }
694                         ret = TRUE;
695                     }
696                     break;
697                 case GDK_Right: // move selection right
698                 case GDK_KP_Right:
699                 case GDK_KP_6:
700                     if (!MOD__CTRL) { // not ctrl
701                         if (MOD__ALT) { // alt
702                             if (MOD__SHIFT) sp_selection_move_screen(10, 0); // shift
703                             else sp_selection_move_screen(1, 0); // no shift
704                         }
705                         else { // no alt
706                             if (MOD__SHIFT) sp_selection_move(10*nudge, 0); // shift
707                             else sp_selection_move(nudge, 0); // no shift
708                         }
709                         ret = TRUE;
710                     }
711                     break;
712                 case GDK_Down: // move selection down
713                 case GDK_KP_Down:
714                 case GDK_KP_2:
715                     if (!MOD__CTRL) { // not ctrl
716                         if (MOD__ALT) { // alt
717                             if (MOD__SHIFT) sp_selection_move_screen(0, -10); // shift
718                             else sp_selection_move_screen(0, -1); // no shift
719                         }
720                         else { // no alt
721                             if (MOD__SHIFT) sp_selection_move(0, -10*nudge); // shift
722                             else sp_selection_move(0, -nudge); // no shift
723                         }
724                         ret = TRUE;
725                     }
726                     break;
727                 case GDK_Escape:
728                     if (!sp_select_context_abort(event_context))
729                         selection->clear();
730                     ret = TRUE;
731                     break;
732                 case GDK_a:
733                 case GDK_A:
734                     if (MOD__CTRL_ONLY) {
735                         sp_edit_select_all();
736                         ret = TRUE;
737                     }
738                     break;
739                 case GDK_Tab: // Tab - cycle selection forward
740                     if (!(MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT))) {
741                         sp_selection_item_next();
742                         ret = TRUE;
743                     }
744                     break;
745                 case GDK_ISO_Left_Tab: // Shift Tab - cycle selection backward
746                     if (!(MOD__CTRL_ONLY || (MOD__CTRL && MOD__SHIFT))) {
747                         sp_selection_item_prev();
748                         ret = TRUE;
749                     }
750                     break;
751                 case GDK_space:
752                     /* stamping mode: show outline mode moving */
753                     /* FIXME: Is next condition ok? (lauris) */
754                     if (sc->dragging && sc->grabbed) {
755                         seltrans->stamp();
756                         ret = TRUE;
757                     }
758                     break;
759                 case GDK_x:
760                 case GDK_X:
761                     if (MOD__ALT_ONLY) {
762                         desktop->setToolboxFocusTo ("altx");
763                         ret = TRUE;
764                     }
765                     break;
766                 case GDK_bracketleft:
767                     if (MOD__ALT) {
768                         sp_selection_rotate_screen(selection, 1);
769                     } else if (MOD__CTRL) {
770                         sp_selection_rotate(selection, 90);
771                     } else if (snaps) {
772                         sp_selection_rotate(selection, 180/snaps);
773                     }
774                     ret = TRUE;
775                     break;
776                 case GDK_bracketright:
777                     if (MOD__ALT) {
778                         sp_selection_rotate_screen(selection, -1);
779                     } else if (MOD__CTRL) {
780                         sp_selection_rotate(selection, -90);
781                     } else if (snaps) {
782                         sp_selection_rotate(selection, -180/snaps);
783                     }
784                     ret = TRUE;
785                     break;
786                 case GDK_less:
787                 case GDK_comma:
788                     if (MOD__ALT) {
789                         sp_selection_scale_screen(selection, -2);
790                     } else if (MOD__CTRL) {
791                         sp_selection_scale_times(selection, 0.5);
792                     } else {
793                         sp_selection_scale(selection, -offset);
794                     }
795                     ret = TRUE;
796                     break;
797                 case GDK_greater:
798                 case GDK_period:
799                     if (MOD__ALT) {
800                         sp_selection_scale_screen(selection, 2);
801                     } else if (MOD__CTRL) {
802                         sp_selection_scale_times(selection, 2);
803                     } else {
804                         sp_selection_scale(selection, offset);
805                     }
806                     ret = TRUE;
807                     break;
808                 case GDK_Return:
809                     if (MOD__CTRL_ONLY) {
810                         if (selection->singleItem()) {
811                             SPItem *clicked_item = selection->singleItem();
812                             if (SP_IS_GROUP (clicked_item)) { // enter group
813                                 desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
814                                 sp_desktop_selection(desktop)->clear();
815                             } else {
816                                 SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter."));
817                             }
818                         }
819                         ret = TRUE;
820                     }
821                     break;
822                 case GDK_BackSpace:
823                     if (MOD__CTRL_ONLY) {
824                         sp_select_context_up_one_layer(desktop);
825                         ret = TRUE;
826                     }
827                     break;
828                 default:
829                     break;
830             }
831             break;
832         case GDK_KEY_RELEASE:
833             if (key_is_a_modifier (get_group0_keyval (&event->key)))
834                 event_context->defaultMessageContext()->clear();
835                 // set cursor to default.
836                 gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, event_context->cursor);
837             break;
838         default:
839             break;
840     }
842     if (!ret) {
843         if (((SPEventContextClass *) parent_class)->root_handler)
844             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
845     }
847     return ret;
851 /*
852   Local Variables:
853   mode:c++
854   c-file-style:"stroustrup"
855   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
856   indent-tabs-mode:nil
857   fill-column:99
858   End:
859 */
860 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :