Code

A simple layout document as to what, why and how is cppification.
[inkscape.git] / src / event-context.cpp
1 #define __SP_EVENT_CONTEXT_C__
3 /** \file
4  * Main event handling, and related helper functions.
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Frank Felfe <innerspace@iname.com>
9  *   bulia byak <buliabyak@users.sf.net>
10  *
11  * Copyright (C) 1999-2010 authors
12  * Copyright (C) 2001-2002 Ximian, Inc.
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 /** \class SPEventContext
18  * SPEventContext is an abstract base class of all tools. As the name
19  * indicates, event context implementations process UI events (mouse
20  * movements and keypresses) and take actions (like creating or modifying
21  * objects).  There is one event context implementation for each tool,
22  * plus few abstract base classes. Writing a new tool involves
23  * subclassing SPEventContext.
24  */
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include "event-context.h"
32 #include <string.h>
33 #include <gdk/gdkkeysyms.h>
34 #include <gtk/gtkmain.h>
35 #include <gtk/gtkmenu.h>
36 #include <glibmm/i18n.h>
37 #include <cstring>
38 #include <string>
40 #include "display/sp-canvas.h"
41 #include "xml/node-event-vector.h"
42 #include "sp-cursor.h"
43 #include "shortcuts.h"
44 #include "desktop.h"
45 #include "desktop-handles.h"
46 #include "desktop-events.h"
47 #include "widgets/desktop-widget.h"
48 #include "sp-namedview.h"
49 #include "selection.h"
50 #include "file.h"
51 #include "interface.h"
52 #include "macros.h"
53 #include "tools-switch.h"
54 #include "preferences.h"
55 #include "message-context.h"
56 #include "gradient-drag.h"
57 #include "object-edit.h"
58 #include "attributes.h"
59 #include "rubberband.h"
60 #include "selcue.h"
61 #include "lpe-tool-context.h"
62 #include "ui/tool/control-point.h"
63 #include "shape-editor.h"
64 #include "sp-guide.h"
66 static void sp_event_context_class_init(SPEventContextClass *klass);
67 static void sp_event_context_init(SPEventContext *event_context);
68 static void sp_event_context_dispose(GObject *object);
70 static void sp_event_context_private_setup(SPEventContext *ec);
71 static gint sp_event_context_private_root_handler(
72         SPEventContext *event_context, GdkEvent *event);
73 static gint sp_event_context_private_item_handler(
74         SPEventContext *event_context, SPItem *item, GdkEvent *event);
76 static void set_event_location(SPDesktop * desktop, GdkEvent * event);
78 static GObjectClass *parent_class;
80 // globals for temporary switching to selector by space
81 static bool selector_toggled = FALSE;
82 static int switch_selector_to = 0;
84 // globals for temporary switching to dropper by 'D'
85 static bool dropper_toggled = FALSE;
86 static int switch_dropper_to = 0;
88 static gint xp = 0, yp = 0; // where drag started
89 static gint tolerance = 0;
90 static bool within_tolerance = false;
92 // globals for keeping track of keyboard scroll events in order to accelerate
93 static guint32 scroll_event_time = 0;
94 static gdouble scroll_multiply = 1;
95 static guint scroll_keyval = 0;
97 /**
98  * Registers the SPEventContext class with Glib and returns its type number.
99  */
100 GType sp_event_context_get_type(void) {
101     static GType type = 0;
102     if (!type) {
103         GTypeInfo info = { sizeof(SPEventContextClass), NULL, NULL,
104                 (GClassInitFunc) sp_event_context_class_init, NULL, NULL,
105                 sizeof(SPEventContext), 4,
106                 (GInstanceInitFunc) sp_event_context_init, NULL, /* value_table */
107         };
108         type = g_type_register_static(G_TYPE_OBJECT, "SPEventContext", &info,
109                 (GTypeFlags) 0);
110     }
111     return type;
114 /**
115  * Callback to set up the SPEventContext vtable.
116  */
117 static void sp_event_context_class_init(SPEventContextClass *klass) {
118     GObjectClass *object_class;
120     object_class = (GObjectClass *) klass;
122     parent_class = (GObjectClass*) g_type_class_peek_parent(klass);
124     object_class->dispose = sp_event_context_dispose;
126     klass->setup = sp_event_context_private_setup;
127     klass->root_handler = sp_event_context_private_root_handler;
128     klass->item_handler = sp_event_context_private_item_handler;
131 /**
132  * Clears all SPEventContext object members.
133  */
134 static void sp_event_context_init(SPEventContext *event_context) {
135     event_context->desktop = NULL;
136     event_context->cursor = NULL;
137     event_context->_message_context = NULL;
138     event_context->_selcue = NULL;
139     event_context->_grdrag = NULL;
140     event_context->space_panning = false;
141     event_context->shape_editor = NULL;
142     event_context->_delayed_snap_event = NULL;
143     event_context->_dse_callback_in_process = false;
146 /**
147  * Callback to free and null member variables of SPEventContext object.
148  */
149 static void sp_event_context_dispose(GObject *object) {
150     SPEventContext *ec;
152     ec = SP_EVENT_CONTEXT(object);
154     if (ec->_message_context) {
155         delete ec->_message_context;
156     }
158     if (ec->cursor != NULL) {
159         gdk_cursor_unref(ec->cursor);
160         ec->cursor = NULL;
161     }
163     if (ec->desktop) {
164         ec->desktop = NULL;
165     }
167     if (ec->pref_observer) {
168         delete ec->pref_observer;
169     }
171     if (ec->_delayed_snap_event) {
172         delete ec->_delayed_snap_event;
173     }
175     G_OBJECT_CLASS(parent_class)->dispose(object);
178 /**
179  * Recreates and draws cursor on desktop related to SPEventContext.
180  */
181 void sp_event_context_update_cursor(SPEventContext *ec) {
182     GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(ec->desktop));
183     if (w->window) {
184         /* fixme: */
185         if (ec->cursor_shape) {
186             GdkBitmap *bitmap = NULL;
187             GdkBitmap *mask = NULL;
188             sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, ec->cursor_shape);
189             if ((bitmap != NULL) && (mask != NULL)) {
190                 if (ec->cursor)
191                     gdk_cursor_unref(ec->cursor);
192                 ec->cursor = gdk_cursor_new_from_pixmap(bitmap, mask,
193                         &w->style->black, &w->style->white, ec->hot_x,
194                         ec->hot_y);
195                 g_object_unref(bitmap);
196                 g_object_unref(mask);
197             }
198         }
199         gdk_window_set_cursor(w->window, ec->cursor);
200         gdk_flush();
201     }
202     ec->desktop->waiting_cursor = false;
205 /**
206  * Callback that gets called on initialization of SPEventContext object.
207  * Redraws mouse cursor, at the moment.
208  */
209 static void sp_event_context_private_setup(SPEventContext *ec) {
210     sp_event_context_update_cursor(ec);
213 /**
214  * \brief   Gobbles next key events on the queue with the same keyval and mask. Returns the number of events consumed.
215  */
216 gint gobble_key_events(guint keyval, gint mask) {
217     GdkEvent *event_next;
218     gint i = 0;
220     event_next = gdk_event_get();
221     // while the next event is also a key notify with the same keyval and mask,
222     while (event_next && (event_next->type == GDK_KEY_PRESS || event_next->type
223             == GDK_KEY_RELEASE) && event_next->key.keyval == keyval && (!mask
224             || (event_next->key.state & mask))) {
225         if (event_next->type == GDK_KEY_PRESS)
226             i++;
227         // kill it
228         gdk_event_free(event_next);
229         // get next
230         event_next = gdk_event_get();
231     }
232     // otherwise, put it back onto the queue
233     if (event_next)
234         gdk_event_put(event_next);
236     return i;
239 /**
240  * \brief   Gobbles next motion notify events on the queue with the same mask. Returns the number of events consumed.
241  */
242 gint gobble_motion_events(gint mask) {
243     GdkEvent *event_next;
244     gint i = 0;
246     event_next = gdk_event_get();
247     // while the next event is also a key notify with the same keyval and mask,
248     while (event_next && event_next->type == GDK_MOTION_NOTIFY
249             && (event_next->motion.state & mask)) {
250         // kill it
251         gdk_event_free(event_next);
252         // get next
253         event_next = gdk_event_get();
254         i++;
255     }
256     // otherwise, put it back onto the queue
257     if (event_next)
258         gdk_event_put(event_next);
260     return i;
263 /**
264  * Toggles current tool between active tool and selector tool.
265  * Subroutine of sp_event_context_private_root_handler().
266  */
267 static void sp_toggle_selector(SPDesktop *dt) {
268     if (!dt->event_context)
269         return;
271     if (tools_isactive(dt, TOOLS_SELECT)) {
272         if (selector_toggled) {
273             if (switch_selector_to)
274                 tools_switch(dt, switch_selector_to);
275             selector_toggled = FALSE;
276         } else
277             return;
278     } else {
279         selector_toggled = TRUE;
280         switch_selector_to = tools_active(dt);
281         tools_switch(dt, TOOLS_SELECT);
282     }
285 /**
286  * Toggles current tool between active tool and dropper tool.
287  * Subroutine of sp_event_context_private_root_handler().
288  */
289 static void sp_toggle_dropper(SPDesktop *dt) {
290     if (!dt->event_context)
291         return;
293     if (tools_isactive(dt, TOOLS_DROPPER)) {
294         if (dropper_toggled) {
295             if (switch_dropper_to)
296                 tools_switch(dt, switch_dropper_to);
297             dropper_toggled = FALSE;
298         } else
299             return;
300     } else {
301         dropper_toggled = TRUE;
302         switch_dropper_to = tools_active(dt);
303         tools_switch(dt, TOOLS_DROPPER);
304     }
307 /**
308  * Calculates and keeps track of scroll acceleration.
309  * Subroutine of sp_event_context_private_root_handler().
310  */
311 static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration,
312         SPCanvas */*canvas*/) {
313     guint32 time_diff = ((GdkEventKey *) event)->time - scroll_event_time;
315     /* key pressed within 500ms ? (1/2 second) */
316     if (time_diff > 500 || event->key.keyval != scroll_keyval) {
317         scroll_multiply = 1; // abort acceleration
318     } else {
319         scroll_multiply += acceleration; // continue acceleration
320     }
322     scroll_event_time = ((GdkEventKey *) event)->time;
323     scroll_keyval = event->key.keyval;
325     return scroll_multiply;
328 /**
329  * Main event dispatch, gets called from Gdk.
330  */
331 static gint sp_event_context_private_root_handler(
332         SPEventContext *event_context, GdkEvent *event) {
333     static Geom::Point button_w;
334     static unsigned int panning = 0;
335     static unsigned int zoom_rb = 0;
337     SPDesktop *desktop = event_context->desktop;
338     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
340     /// @todo REmove redundant /value in preference keys
341     tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
343     gint ret = FALSE;
345     switch (event->type) {
346     case GDK_2BUTTON_PRESS:
347         if (panning) {
348             panning = 0;
349             sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
350                     event->button.time);
351             ret = TRUE;
352         } else {
353             /* sp_desktop_dialog(); */
354         }
355         break;
356     case GDK_BUTTON_PRESS:
358         // save drag origin
359         xp = (gint) event->button.x;
360         yp = (gint) event->button.y;
361         within_tolerance = true;
363         button_w = Geom::Point(event->button.x, event->button.y);
365         switch (event->button.button) {
366         case 1:
367             if (event_context->space_panning) {
368                 // When starting panning, make sure there are no snap events pending because these might disable the panning again
369                 sp_event_context_discard_delayed_snap_event(event_context);
370                 panning = 1;
371                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
372                         GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK
373                                 | GDK_POINTER_MOTION_MASK
374                                 | GDK_POINTER_MOTION_HINT_MASK, NULL,
375                         event->button.time - 1);
376                 ret = TRUE;
377             }
378             break;
379         case 2:
380             if (event->button.state & GDK_SHIFT_MASK) {
381                 zoom_rb = 2;
382             } else {
383                 // When starting panning, make sure there are no snap events pending because these might disable the panning again
384                 sp_event_context_discard_delayed_snap_event(event_context);
385                 panning = 2;
386                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
387                         GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK
388                                 | GDK_POINTER_MOTION_HINT_MASK, NULL,
389                         event->button.time - 1);
390             }
391             ret = TRUE;
392             break;
393         case 3:
394             if (event->button.state & GDK_SHIFT_MASK || event->button.state
395                     & GDK_CONTROL_MASK) {
396                 // When starting panning, make sure there are no snap events pending because these might disable the panning again
397                 sp_event_context_discard_delayed_snap_event(event_context);
398                 panning = 3;
399                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
400                         GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK
401                                 | GDK_POINTER_MOTION_HINT_MASK, NULL,
402                         event->button.time);
403                 ret = TRUE;
404             } else {
405                 sp_event_root_menu_popup(desktop, NULL, event);
406             }
407             break;
408         default:
409             break;
410         }
411         break;
412     case GDK_MOTION_NOTIFY:
413         if (panning) {
414             if ((panning == 2 && !(event->motion.state & GDK_BUTTON2_MASK))
415                     || (panning == 1 && !(event->motion.state
416                             & GDK_BUTTON1_MASK)) || (panning == 3
417                     && !(event->motion.state & GDK_BUTTON3_MASK))) {
418                 /* Gdk seems to lose button release for us sometimes :-( */
419                 panning = 0;
420                 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
421                         event->button.time);
422                 ret = TRUE;
423             } else {
424                 if (within_tolerance && (abs((gint) event->motion.x - xp)
425                         < tolerance) && (abs((gint) event->motion.y - yp)
426                         < tolerance)) {
427                     // do not drag if we're within tolerance from origin
428                     break;
429                 }
430                 // Once the user has moved farther than tolerance from
431                 // the original location (indicating they intend to move
432                 // the object, not click), then always process the motion
433                 // notify coordinates as given (no snapping back to origin)
434                 within_tolerance = false;
436                 // gobble subsequent motion events to prevent "sticking"
437                 // when scrolling is slow
438                 gobble_motion_events(panning == 2 ? GDK_BUTTON2_MASK : (panning
439                         == 1 ? GDK_BUTTON1_MASK : GDK_BUTTON3_MASK));
441                 Geom::Point const motion_w(event->motion.x, event->motion.y);
442                 Geom::Point const moved_w(motion_w - button_w);
443                 event_context->desktop->scroll_world(moved_w, true); // we're still scrolling, do not redraw
444                 ret = TRUE;
445             }
446         } else if (zoom_rb) {
447             Geom::Point const motion_w(event->motion.x, event->motion.y);
448             Geom::Point const motion_dt(desktop->w2d(motion_w));
450             if (within_tolerance && (abs((gint) event->motion.x - xp)
451                     < tolerance) && (abs((gint) event->motion.y - yp)
452                     < tolerance)) {
453                 break; // do not drag if we're within tolerance from origin
454             }
455             // Once the user has moved farther than tolerance from the original location
456             // (indicating they intend to move the object, not click), then always process the
457             // motion notify coordinates as given (no snapping back to origin)
458             within_tolerance = false;
460             if (Inkscape::Rubberband::get(desktop)->is_started()) {
461                 Inkscape::Rubberband::get(desktop)->move(motion_dt);
462             } else {
463                 Inkscape::Rubberband::get(desktop)->start(desktop, motion_dt);
464             }
465             if (zoom_rb == 2)
466                 gobble_motion_events(GDK_BUTTON2_MASK);
467         }
468         break;
469     case GDK_BUTTON_RELEASE:
470         xp = yp = 0;
471         if (within_tolerance && (panning || zoom_rb)) {
472             zoom_rb = 0;
473             if (panning) {
474                 panning = 0;
475                 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
476                         event->button.time);
477             }
478             Geom::Point const event_w(event->button.x, event->button.y);
479             Geom::Point const event_dt(desktop->w2d(event_w));
480             double const zoom_inc = prefs->getDoubleLimited(
481                     "/options/zoomincrement/value", M_SQRT2, 1.01, 10);
482             desktop->zoom_relative_keep_point(event_dt, (event->button.state
483                     & GDK_SHIFT_MASK) ? 1 / zoom_inc : zoom_inc);
484             desktop->updateNow();
485             ret = TRUE;
486         } else if (panning == event->button.button) {
487             panning = 0;
488             sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
489                     event->button.time);
491             // in slow complex drawings, some of the motion events are lost;
492             // to make up for this, we scroll it once again to the button-up event coordinates
493             // (i.e. canvas will always get scrolled all the way to the mouse release point,
494             // even if few intermediate steps were visible)
495             Geom::Point const motion_w(event->button.x, event->button.y);
496             Geom::Point const moved_w(motion_w - button_w);
497             event_context->desktop->scroll_world(moved_w);
498             desktop->updateNow();
499             ret = TRUE;
500         } else if (zoom_rb == event->button.button) {
501             zoom_rb = 0;
502             Geom::OptRect const b =
503                     Inkscape::Rubberband::get(desktop)->getRectangle();
504             Inkscape::Rubberband::get(desktop)->stop();
505             if (b && !within_tolerance) {
506                 desktop->set_display_area(*b, 10);
507             }
508             ret = TRUE;
509         }
510         break;
511     case GDK_KEY_PRESS: {
512         double const acceleration = prefs->getDoubleLimited(
513                 "/options/scrollingacceleration/value", 0, 0, 6);
514         int const key_scroll = prefs->getIntLimited("/options/keyscroll/value",
515                 10, 0, 1000);
517         switch (get_group0_keyval(&event->key)) {
518         // GDK insists on stealing these keys (F1 for no idea what, tab for cycling widgets
519         // in the editing window). So we resteal them back and run our regular shortcut
520         // invoker on them.
521         unsigned int shortcut;
522     case GDK_Tab:
523     case GDK_ISO_Left_Tab:
524     case GDK_F1:
525         shortcut = get_group0_keyval(&event->key);
526         if (event->key.state & GDK_SHIFT_MASK)
527             shortcut |= SP_SHORTCUT_SHIFT_MASK;
528         if (event->key.state & GDK_CONTROL_MASK)
529             shortcut |= SP_SHORTCUT_CONTROL_MASK;
530         if (event->key.state & GDK_MOD1_MASK)
531             shortcut |= SP_SHORTCUT_ALT_MASK;
532         ret = sp_shortcut_invoke(shortcut, desktop);
533         break;
535     case GDK_D:
536     case GDK_d:
537         if (!MOD__SHIFT && !MOD__CTRL && !MOD__ALT) {
538             sp_toggle_dropper(desktop);
539             ret = TRUE;
540         }
541         break;
542     case GDK_Q:
543     case GDK_q:
544         if (desktop->quick_zoomed()) {
545             ret = TRUE;
546         }
547         if (!MOD__SHIFT && !MOD__CTRL && !MOD__ALT) {
548             desktop->zoom_quick(true);
549             ret = TRUE;
550         }
551         break;
552     case GDK_W:
553     case GDK_w:
554     case GDK_F4:
555         /* Close view */
556         if (MOD__CTRL_ONLY) {
557             sp_ui_close_view(NULL);
558             ret = TRUE;
559         }
560         break;
561     case GDK_Left: // Ctrl Left
562     case GDK_KP_Left:
563     case GDK_KP_4:
564         if (MOD__CTRL_ONLY) {
565             int i = (int) floor(key_scroll * accelerate_scroll(event,
566                     acceleration, sp_desktop_canvas(desktop)));
567             gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
568             event_context->desktop->scroll_world(i, 0);
569             ret = TRUE;
570         }
571         break;
572     case GDK_Up: // Ctrl Up
573     case GDK_KP_Up:
574     case GDK_KP_8:
575         if (MOD__CTRL_ONLY) {
576             int i = (int) floor(key_scroll * accelerate_scroll(event,
577                     acceleration, sp_desktop_canvas(desktop)));
578             gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
579             event_context->desktop->scroll_world(0, i);
580             ret = TRUE;
581         }
582         break;
583     case GDK_Right: // Ctrl Right
584     case GDK_KP_Right:
585     case GDK_KP_6:
586         if (MOD__CTRL_ONLY) {
587             int i = (int) floor(key_scroll * accelerate_scroll(event,
588                     acceleration, sp_desktop_canvas(desktop)));
589             gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
590             event_context->desktop->scroll_world(-i, 0);
591             ret = TRUE;
592         }
593         break;
594     case GDK_Down: // Ctrl Down
595     case GDK_KP_Down:
596     case GDK_KP_2:
597         if (MOD__CTRL_ONLY) {
598             int i = (int) floor(key_scroll * accelerate_scroll(event,
599                     acceleration, sp_desktop_canvas(desktop)));
600             gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
601             event_context->desktop->scroll_world(0, -i);
602             ret = TRUE;
603         }
604         break;
605     case GDK_F10:
606         if (MOD__SHIFT_ONLY) {
607             sp_event_root_menu_popup(desktop, NULL, event);
608             ret = TRUE;
609         }
610         break;
611     case GDK_space:
612         if (prefs->getBool("/options/spacepans/value")) {
613             event_context->space_panning = true;
614             event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE,
615                     _("<b>Space+mouse drag</b> to pan canvas"));
616             ret = TRUE;
617         } else {
618             sp_toggle_selector(desktop);
619             ret = TRUE;
620         }
621         break;
622     case GDK_z:
623     case GDK_Z:
624         if (MOD__ALT_ONLY) {
625             desktop->zoom_grab_focus();
626             ret = TRUE;
627         }
628         break;
629     default:
630         break;
631         }
632     }
633         break;
634     case GDK_KEY_RELEASE:
635         switch (get_group0_keyval(&event->key)) {
636         case GDK_space:
637             if (event_context->space_panning) {
638                 event_context->space_panning = false;
639                 event_context->_message_context->clear();
640                 if (panning == 1) {
641                     panning = 0;
642                     sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
643                             event->key.time);
644                     desktop->updateNow();
645                 }
646                 ret = TRUE;
647             }
648             break;
649         case GDK_Q:
650         case GDK_q:
651             if (desktop->quick_zoomed()) {
652                 desktop->zoom_quick(false);
653                 ret = TRUE;
654             }
655             break;
656         default:
657             break;
658         }
659         break;
660     case GDK_SCROLL: {
661         bool ctrl = (event->scroll.state & GDK_CONTROL_MASK);
662         bool wheelzooms = prefs->getBool("/options/wheelzooms/value");
663         int const wheel_scroll = prefs->getIntLimited(
664                 "/options/wheelscroll/value", 40, 0, 1000);
666         /* shift + wheel, pan left--right */
667         if (event->scroll.state & GDK_SHIFT_MASK) {
668             switch (event->scroll.direction) {
669             case GDK_SCROLL_UP:
670                 desktop->scroll_world(wheel_scroll, 0);
671                 break;
672             case GDK_SCROLL_DOWN:
673                 desktop->scroll_world(-wheel_scroll, 0);
674                 break;
675             default:
676                 break;
677             }
679             /* ctrl + wheel, zoom in--out */
680         } else if ((ctrl && !wheelzooms) || (!ctrl && wheelzooms)) {
681             double rel_zoom;
682             double const zoom_inc = prefs->getDoubleLimited(
683                     "/options/zoomincrement/value", M_SQRT2, 1.01, 10);
684             switch (event->scroll.direction) {
685             case GDK_SCROLL_UP:
686                 rel_zoom = zoom_inc;
687                 break;
688             case GDK_SCROLL_DOWN:
689                 rel_zoom = 1 / zoom_inc;
690                 break;
691             default:
692                 rel_zoom = 0.0;
693                 break;
694             }
695             if (rel_zoom != 0.0) {
696                 Geom::Point const scroll_dt = desktop->point();
697                 desktop->zoom_relative_keep_point(scroll_dt, rel_zoom);
698             }
700             /* no modifier, pan up--down (left--right on multiwheel mice?) */
701         } else {
702             switch (event->scroll.direction) {
703             case GDK_SCROLL_UP:
704                 desktop->scroll_world(0, wheel_scroll);
705                 break;
706             case GDK_SCROLL_DOWN:
707                 desktop->scroll_world(0, -wheel_scroll);
708                 break;
709             case GDK_SCROLL_LEFT:
710                 desktop->scroll_world(wheel_scroll, 0);
711                 break;
712             case GDK_SCROLL_RIGHT:
713                 desktop->scroll_world(-wheel_scroll, 0);
714                 break;
715             }
716         }
717         break;
718     }
719     default:
720         break;
721     }
723     return ret;
726 /**
727  * Handles item specific events. Gets called from Gdk.
728  *
729  * Only reacts to right mouse button at the moment.
730  * \todo Fixme: do context sensitive popup menu on items.
731  */
732 gint sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item,
733         GdkEvent *event) {
734     int ret = FALSE;
736     switch (event->type) {
737     case GDK_BUTTON_PRESS:
738         if ((event->button.button == 3) && !(event->button.state
739                 & GDK_SHIFT_MASK || event->button.state & GDK_CONTROL_MASK)) {
740             sp_event_root_menu_popup(ec->desktop, item, event);
741             ret = TRUE;
742         }
743         break;
744     default:
745         break;
746     }
748     return ret;
751 /**
752  * @brief: Returns true if we're hovering above a knot (needed because we don't want to pre-snap in that case)
753  */
755 bool sp_event_context_knot_mouseover(SPEventContext *ec)
757     if (ec->shape_editor) {
758         return ec->shape_editor->knot_mouseover();
759     }
761     return false;
764 /**
765  * @brief An observer that relays pref changes to the derived classes
766  */
767 class ToolPrefObserver: public Inkscape::Preferences::Observer {
768 public:
769     ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) :
770         Inkscape::Preferences::Observer(path), _ec(ec) {
771     }
772     virtual void notify(Inkscape::Preferences::Entry const &val) {
773         if (((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set) {
774             ((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set(_ec,
775                     const_cast<Inkscape::Preferences::Entry*> (&val));
776         }
777     }
778 private:
779     SPEventContext * const _ec;
780 };
782 /**
783  * Creates new SPEventContext object and calls its virtual setup() function.
784  * @todo This is bogus. pref_path should be a private property of the inheriting objects.
785  */
786 SPEventContext *
787 sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path,
788         unsigned int key) {
789     g_return_val_if_fail(g_type_is_a(type, SP_TYPE_EVENT_CONTEXT), NULL);
790     g_return_val_if_fail(desktop != NULL, NULL);
792     SPEventContext * const ec = (SPEventContext*) g_object_new(type, NULL);
794     ec->desktop = desktop;
795     ec->_message_context
796             = new Inkscape::MessageContext(desktop->messageStack());
797     ec->key = key;
798     ec->pref_observer = NULL;
800     if (pref_path) {
801         ec->pref_observer = new ToolPrefObserver(pref_path, ec);
803         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
804         prefs->addObserver(*(ec->pref_observer));
805     }
807     if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->setup)
808         ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->setup(ec);
810     return ec;
813 /**
814  * Finishes SPEventContext.
815  */
816 void sp_event_context_finish(SPEventContext *ec) {
817     g_return_if_fail(ec != NULL);
818     g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
820     ec->enableSelectionCue(false);
822     if (ec->next) {
823         g_warning("Finishing event context with active link\n");
824     }
826     if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->finish)
827         ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->finish(ec);
830 //-------------------------------member functions
832 /**
833  * Enables/disables the SPEventContext's SelCue.
834  */
835 void SPEventContext::enableSelectionCue(bool enable) {
836     if (enable) {
837         if (!_selcue) {
838             _selcue = new Inkscape::SelCue(desktop);
839         }
840     } else {
841         delete _selcue;
842         _selcue = NULL;
843     }
846 /**
847  * Enables/disables the SPEventContext's GrDrag.
848  */
849 void SPEventContext::enableGrDrag(bool enable) {
850     if (enable) {
851         if (!_grdrag) {
852             _grdrag = new GrDrag(desktop);
853         }
854     } else {
855         if (_grdrag) {
856             delete _grdrag;
857             _grdrag = NULL;
858         }
859     }
862 /**
863  * Calls virtual set() function of SPEventContext.
864  */
865 void sp_event_context_read(SPEventContext *ec, gchar const *key) {
866     g_return_if_fail(ec != NULL);
867     g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
868     g_return_if_fail(key != NULL);
870     if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set) {
871         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
872         Inkscape::Preferences::Entry val = prefs->getEntry(
873                 ec->pref_observer->observed_path + '/' + key);
874         ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set(ec, &val);
875     }
878 /**
879  * Calls virtual activate() function of SPEventContext.
880  */
881 void sp_event_context_activate(SPEventContext *ec) {
882     g_return_if_fail(ec != NULL);
883     g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
885     // Make sure no delayed snapping events are carried over after switching contexts
886     // (this is only an additional safety measure against sloppy coding, because each
887     // context should take care of this by itself.
888     sp_event_context_discard_delayed_snap_event(ec);
890     if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate)
891         ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate(ec);
894 /**
895  * Calls virtual deactivate() function of SPEventContext.
896  */
897 void sp_event_context_deactivate(SPEventContext *ec) {
898     g_return_if_fail(ec != NULL);
899     g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
901     if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->deactivate)
902         ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->deactivate(ec);
905 /**
906  * Calls virtual root_handler(), the main event handling function.
907  */
908 gint sp_event_context_root_handler(SPEventContext * event_context,
909         GdkEvent * event)
911     switch (event->type) {
912     case GDK_MOTION_NOTIFY:
913         sp_event_context_snap_delay_handler(event_context, NULL, NULL,
914                 (GdkEventMotion *) event,
915                 DelayedSnapEvent::EVENTCONTEXT_ROOT_HANDLER);
916         break;
917     case GDK_BUTTON_RELEASE:
918         if (event_context->_delayed_snap_event) {
919             // If we have any pending snapping action, then invoke it now
920             sp_event_context_snap_watchdog_callback(
921                     event_context->_delayed_snap_event);
922         }
923         break;
924     case GDK_BUTTON_PRESS:
925     case GDK_2BUTTON_PRESS:
926     case GDK_3BUTTON_PRESS:
927         // Snapping will be on hold if we're moving the mouse at high speeds. When starting
928         // drawing a new shape we really should snap though.
929         event_context->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(
930                 false);
931         break;
932     default:
933         break;
934     }
936     return sp_event_context_virtual_root_handler(event_context, event);
939 gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEvent * event) {
940     gint ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->root_handler(event_context, event);
941     set_event_location(event_context->desktop, event);
942     return ret;
945 /**
946  * Calls virtual item_handler(), the item event handling function.
947  */
948 gint sp_event_context_item_handler(SPEventContext * event_context,
949         SPItem * item, GdkEvent * event) {
950     switch (event->type) {
951     case GDK_MOTION_NOTIFY:
952         sp_event_context_snap_delay_handler(event_context, (gpointer) item, NULL, (GdkEventMotion *) event, DelayedSnapEvent::EVENTCONTEXT_ITEM_HANDLER);
953         break;
954     case GDK_BUTTON_RELEASE:
955         if (event_context->_delayed_snap_event) {
956             // If we have any pending snapping action, then invoke it now
957             sp_event_context_snap_watchdog_callback(event_context->_delayed_snap_event);
958         }
959         break;
960     case GDK_BUTTON_PRESS:
961     case GDK_2BUTTON_PRESS:
962     case GDK_3BUTTON_PRESS:
963         // Snapping will be on hold if we're moving the mouse at high speeds. When starting
964         // drawing a new shape we really should snap though.
965         event_context->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
966         break;
967     default:
968         break;
969     }
971     return sp_event_context_virtual_item_handler(event_context, item, event);
974 gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPItem * item, GdkEvent * event) {
975     gint ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->item_handler(event_context, item, event);
977     if (!ret) {
978         ret = sp_event_context_virtual_root_handler(event_context, event);
979     } else {
980         set_event_location(event_context->desktop, event);
981     }
983     return ret;
986 /**
987  * Emits 'position_set' signal on desktop and shows coordinates on status bar.
988  */
989 static void set_event_location(SPDesktop *desktop, GdkEvent *event) {
990     if (event->type != GDK_MOTION_NOTIFY) {
991         return;
992     }
994     Geom::Point const button_w(event->button.x, event->button.y);
995     Geom::Point const button_dt(desktop->w2d(button_w));
996     desktop->setPosition(button_dt);
997     desktop->set_coordinate_status(button_dt);
1000 //-------------------------------------------------------------------
1001 /**
1002  * Create popup menu and tell Gtk to show it.
1003  */
1004 void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event) {
1005     GtkWidget *menu;
1007     /* fixme: This is not what I want but works for now (Lauris) */
1008     if (event->type == GDK_KEY_PRESS) {
1009         item = sp_desktop_selection(desktop)->singleItem();
1010     }
1011     menu = sp_ui_context_menu(desktop, item);
1012     gtk_widget_show(menu);
1014     switch (event->type) {
1015     case GDK_BUTTON_PRESS:
1016         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, 0, NULL,
1017                 event->button.button, event->button.time);
1018         break;
1019     case GDK_KEY_PRESS:
1020         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, 0, NULL, 0, event->key.time);
1021         break;
1022     default:
1023         break;
1024     }
1027 /**
1028  * Show tool context specific modifier tip.
1029  */
1030 void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context,
1031         GdkEvent *event, gchar const *ctrl_tip, gchar const *shift_tip,
1032         gchar const *alt_tip) {
1033     guint keyval = get_group0_keyval(&event->key);
1035     bool ctrl = ctrl_tip && (MOD__CTRL || (keyval == GDK_Control_L) || (keyval
1036             == GDK_Control_R));
1037     bool shift = shift_tip && (MOD__SHIFT || (keyval == GDK_Shift_L) || (keyval
1038             == GDK_Shift_R));
1039     bool alt = alt_tip && (MOD__ALT || (keyval == GDK_Alt_L) || (keyval
1040             == GDK_Alt_R) || (keyval == GDK_Meta_L) || (keyval == GDK_Meta_R));
1042     gchar *tip = g_strdup_printf("%s%s%s%s%s", (ctrl ? ctrl_tip : ""), (ctrl
1043             && (shift || alt) ? "; " : ""), (shift ? shift_tip : ""), ((ctrl
1044             || shift) && alt ? "; " : ""), (alt ? alt_tip : ""));
1046     if (strlen(tip) > 0) {
1047         message_context->flash(Inkscape::INFORMATION_MESSAGE, tip);
1048     }
1050     g_free(tip);
1053 /**
1054  * Return the keyval corresponding to the key event in group 0, i.e.,
1055  * in the main (English) layout.
1056  *
1057  * Use this instead of simply event->keyval, so that your keyboard shortcuts
1058  * work regardless of layouts (e.g., in Cyrillic).
1059  */
1060 guint get_group0_keyval(GdkEventKey *event) {
1061     guint keyval = 0;
1062     gdk_keymap_translate_keyboard_state(gdk_keymap_get_for_display(
1063             gdk_display_get_default()), event->hardware_keycode,
1064             (GdkModifierType) event->state, 0 /*event->key.group*/, &keyval,
1065             NULL, NULL, NULL);
1066     return keyval;
1069 /**
1070  * Returns item at point p in desktop.
1071  *
1072  * If state includes alt key mask, cyclically selects under; honors
1073  * into_groups.
1074  */
1075 SPItem *
1076 sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p,
1077         bool select_under, bool into_groups) {
1078     SPItem *item;
1080     if (select_under) {
1081         SPItem *selected_at_point = desktop->item_from_list_at_point_bottom(
1082                 desktop->selection->itemList(), p);
1083         item = desktop->item_at_point(p, into_groups, selected_at_point);
1084         if (item == NULL) { // we may have reached bottom, flip over to the top
1085             item = desktop->item_at_point(p, into_groups, NULL);
1086         }
1087     } else
1088         item = desktop->item_at_point(p, into_groups, NULL);
1090     return item;
1093 /**
1094  * Returns item if it is under point p in desktop, at any depth; otherwise returns NULL.
1095  *
1096  * Honors into_groups.
1097  */
1098 SPItem *
1099 sp_event_context_over_item(SPDesktop *desktop, SPItem *item,
1100         Geom::Point const &p) {
1101     GSList *temp = NULL;
1102     temp = g_slist_prepend(temp, item);
1103     SPItem *item_at_point = desktop->item_from_list_at_point_bottom(temp, p);
1104     g_slist_free(temp);
1106     return item_at_point;
1109 ShapeEditor *
1110 sp_event_context_get_shape_editor(SPEventContext *ec) {
1111     return ec->shape_editor;
1114 void event_context_print_event_info(GdkEvent *event, bool print_return) {
1115     switch (event->type) {
1116     case GDK_BUTTON_PRESS:
1117         g_print("GDK_BUTTON_PRESS");
1118         break;
1119     case GDK_2BUTTON_PRESS:
1120         g_print("GDK_2BUTTON_PRESS");
1121         break;
1122     case GDK_3BUTTON_PRESS:
1123         g_print("GDK_3BUTTON_PRESS");
1124         break;
1126     case GDK_MOTION_NOTIFY:
1127         g_print("GDK_MOTION_NOTIFY");
1128         break;
1129     case GDK_ENTER_NOTIFY:
1130         g_print("GDK_ENTER_NOTIFY");
1131         break;
1133     case GDK_LEAVE_NOTIFY:
1134         g_print("GDK_LEAVE_NOTIFY");
1135         break;
1136     case GDK_BUTTON_RELEASE:
1137         g_print("GDK_BUTTON_RELEASE");
1138         break;
1140     case GDK_KEY_PRESS:
1141         g_print("GDK_KEY_PRESS: %d", get_group0_keyval(&event->key));
1142         break;
1143     case GDK_KEY_RELEASE:
1144         g_print("GDK_KEY_RELEASE: %d", get_group0_keyval(&event->key));
1145         break;
1146     default:
1147         //g_print ("even type not recognized");
1148         break;
1149     }
1151     if (print_return) {
1152         g_print("\n");
1153     }
1156 /**
1157  * \brief Analyses the current event, calculates the mouse speed, turns snapping off (temporarily) if the
1158  * mouse speed is above a threshold, and stores the current event such that it can be re-triggered when needed
1159  * (re-triggering is controlled by a watchdog timer)
1160  *
1161  * \param ec Pointer to the event context
1162  * \param dse_item Pointer that store a reference to a canvas or to an item
1163  * \param dse_item2 Another pointer, storing a reference to a knot or controlpoint
1164  * \param event Pointer to the motion event
1165  * \param origin Identifier (enum) specifying where the delay (and the call to this method) were initiated
1166  */
1167 void sp_event_context_snap_delay_handler(SPEventContext *ec,
1168         gpointer const dse_item, gpointer const dse_item2, GdkEventMotion *event,
1169         DelayedSnapEvent::DelayedSnapEventOrigin origin)
1171     static guint32 prev_time;
1172     static boost::optional<Geom::Point> prev_pos;
1174     if (ec->_dse_callback_in_process) {
1175         return;
1176     }
1178     // Snapping occurs when dragging with the left mouse button down, or when hovering e.g. in the pen tool with left mouse button up
1179     bool const c1 = event->state & GDK_BUTTON2_MASK; // We shouldn't hold back any events when other mouse buttons have been
1180     bool const c2 = event->state & GDK_BUTTON3_MASK; // pressed, e.g. when scrolling with the middle mouse button; if we do then
1181     // Inkscape will get stuck in an unresponsive state
1182     bool const c3 = tools_isactive(ec->desktop, TOOLS_CALLIGRAPHIC);
1183     // The snap delay will repeat the last motion event, which will lead to
1184     // erroneous points in the calligraphy context. And because we don't snap
1185     // in this context, we might just as well disable the snap delay all together
1187     if (c1 || c2 || c3) {
1188         // Make sure that we don't send any pending snap events to a context if we know in advance
1189         // that we're not going to snap any way (e.g. while scrolling with middle mouse button)
1190         // Any motion event might affect the state of the context, leading to unexpected behavior
1191         sp_event_context_discard_delayed_snap_event(ec);
1192     } else if (ec->desktop
1193             && ec->desktop->namedview->snap_manager.snapprefs.getSnapEnabledGlobally()) {
1194         // Snap when speed drops below e.g. 0.02 px/msec, or when no motion events have occurred for some period.
1195         // i.e. snap when we're at stand still. A speed threshold enforces snapping for tablets, which might never
1196         // be fully at stand still and might keep spitting out motion events.
1197         ec->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(true); // put snapping on hold
1199         Geom::Point event_pos(event->x, event->y);
1200         guint32 event_t = gdk_event_get_time((GdkEvent *) event);
1202         if (prev_pos) {
1203             Geom::Coord dist = Geom::L2(event_pos - *prev_pos);
1204             guint32 delta_t = event_t - prev_time;
1205             gdouble speed = delta_t > 0 ? dist / delta_t : 1000;
1206             //std::cout << "Mouse speed = " << speed << " px/msec " << std::endl;
1207             if (speed > 0.02) { // Jitter threshold, might be needed for tablets
1208                 // We're moving fast, so postpone any snapping until the next GDK_MOTION_NOTIFY event. We
1209                 // will keep on postponing the snapping as long as the speed is high.
1210                 // We must snap at some point in time though, so set a watchdog timer at some time from
1211                 // now, just in case there's no future motion event that drops under the speed limit (when
1212                 // stopping abruptly)
1213                 delete ec->_delayed_snap_event;
1214                 ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2,
1215                         event, origin); // watchdog is reset, i.e. pushed forward in time
1216                 // If the watchdog expires before a new motion event is received, we will snap (as explained
1217                 // above). This means however that when the timer is too short, we will always snap and that the
1218                 // speed threshold is ineffective. In the extreme case the delay is set to zero, and snapping will
1219                 // be immediate, as it used to be in the old days ;-).
1220             } else { // Speed is very low, so we're virtually at stand still
1221                 // But if we're really standing still, then we should snap now. We could use some low-pass filtering,
1222                 // otherwise snapping occurs for each jitter movement. For this filtering we'll leave the watchdog to expire,
1223                 // snap, and set a new watchdog again.
1224                 if (ec->_delayed_snap_event == NULL) { // no watchdog has been set
1225                     // it might have already expired, so we'll set a new one; the snapping frequency will be limited this way
1226                     ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item,
1227                             dse_item2, event, origin);
1228                 } // else: watchdog has been set before and we'll wait for it to expire
1229             }
1230         } else {
1231             // This is the first GDK_MOTION_NOTIFY event, so postpone snapping and set the watchdog
1232             g_assert(ec->_delayed_snap_event == NULL);
1233             ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2,
1234                     event, origin);
1235         }
1237         prev_pos = event_pos;
1238         prev_time = event_t;
1239     }
1242 /**
1243  * \brief When the snap delay watchdog timer barks, this method will be called and will re-inject the last motion
1244  * event in an appropriate place, with snapping being turned on again
1245  */
1246 gboolean sp_event_context_snap_watchdog_callback(gpointer data) {
1247     // Snap NOW! For this the "postponed" flag will be reset and the last motion event will be repeated
1248     DelayedSnapEvent *dse = reinterpret_cast<DelayedSnapEvent*> (data);
1250     if (dse == NULL) {
1251         // This might occur when this method is called directly, i.e. not through the timer
1252         // E.g. on GDK_BUTTON_RELEASE in sp_event_context_root_handler()
1253         return FALSE;
1254     }
1256     SPEventContext *ec = dse->getEventContext();
1257     if (ec == NULL || ec->desktop == NULL) {
1258         return false;
1259     }
1260     ec->_dse_callback_in_process = true;
1262     SPDesktop *dt = ec->desktop;
1263     dt->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
1265     // Depending on where the delayed snap event originated from, we will inject it back at it's origin
1266     // The switch below takes care of that and prepares the relevant parameters
1267     switch (dse->getOrigin()) {
1268     case DelayedSnapEvent::EVENTCONTEXT_ROOT_HANDLER:
1269         sp_event_context_virtual_root_handler(ec, dse->getEvent());
1270         break;
1271     case DelayedSnapEvent::EVENTCONTEXT_ITEM_HANDLER: {
1272         SPItem* item = NULL;
1273         item = SP_ITEM(dse->getItem());
1274         if (item && SP_IS_ITEM(item)) {
1275             sp_event_context_virtual_item_handler(ec, item, dse->getEvent());
1276         }
1277     }
1278         break;
1279     case DelayedSnapEvent::KNOT_HANDLER: {
1280         SPKnot* knot = SP_KNOT(dse->getItem2());
1281         if (knot && SP_IS_KNOT(knot)) {
1282             sp_knot_handler_request_position(dse->getEvent(), knot);
1283         }
1284     }
1285         break;
1286     case DelayedSnapEvent::CONTROL_POINT_HANDLER: {
1287         using Inkscape::UI::ControlPoint;
1288         ControlPoint *point = reinterpret_cast<ControlPoint*> (dse->getItem2());
1289         point->_eventHandler(dse->getEvent());
1290     }
1291         break;
1292     case DelayedSnapEvent::GUIDE_HANDLER: {
1293         gpointer item = dse->getItem();
1294         gpointer item2 = dse->getItem2();
1295         if (item && item2) {
1296             g_assert(SP_IS_CANVAS_ITEM(item));
1297             g_assert(SP_IS_GUIDE(item2));
1298             sp_dt_guide_event(SP_CANVAS_ITEM(item), dse->getEvent(), item2);
1299         }
1300     }
1301         break;
1302     case DelayedSnapEvent::GUIDE_HRULER:
1303     case DelayedSnapEvent::GUIDE_VRULER: {
1304         gpointer item = dse->getItem();
1305         gpointer item2 = dse->getItem2();
1306         if (item && item2) {
1307             g_assert(GTK_IS_WIDGET(item));
1308             g_assert(SP_IS_DESKTOP_WIDGET(item2));
1309             if (dse->getOrigin() == DelayedSnapEvent::GUIDE_HRULER) {
1310                 sp_dt_hruler_event(GTK_WIDGET(item), dse->getEvent(), SP_DESKTOP_WIDGET(item2));
1311             } else {
1312                 sp_dt_vruler_event(GTK_WIDGET(item), dse->getEvent(), SP_DESKTOP_WIDGET(item2));
1313             }
1314         }
1315     }
1316         break;
1317     default:
1318         g_warning("Origin of snap-delay event has not been defined!;");
1319         break;
1320     }
1322     ec->_delayed_snap_event = NULL;
1323     delete dse;
1325     ec->_dse_callback_in_process = false;
1327     return FALSE; //Kills the timer and stops it from executing this callback over and over again.
1330 void sp_event_context_discard_delayed_snap_event(SPEventContext *ec) {
1331     delete ec->_delayed_snap_event;
1332     ec->_delayed_snap_event = NULL;
1333     ec->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
1336 /*
1337  Local Variables:
1338  mode:c++
1339  c-file-style:"stroustrup"
1340  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1341  indent-tabs-mode:nil
1342  fill-column:99
1343  End:
1344  */
1345 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :