1 #ifndef __SP_EVENT_CONTEXT_H__
2 #define __SP_EVENT_CONTEXT_H__
4 /** \file
5 * SPEventContext: base class for event processors
6 *
7 * This is per desktop object, which (its derivatives) implements
8 * different actions bound to mouse events.
9 *
10 * Authors:
11 * Lauris Kaplinski <lauris@kaplinski.com>
12 * Frank Felfe <innerspace@iname.com>
13 *
14 * Copyright (C) 1999-2002 authors
15 * Copyright (C) 2001-2002 Ximian, Inc.
16 *
17 * Released under GNU GPL, read the file 'COPYING' for more information
18 */
20 #include <glib-object.h>
21 #include <gdk/gdktypes.h>
22 #include <gdk/gdkevents.h>
23 #include "knot.h"
25 #include "2geom/forward.h"
26 #include "preferences.h"
28 struct GrDrag;
29 struct SPDesktop;
30 struct SPItem;
31 class ShapeEditor;
32 struct SPEventContext;
34 namespace Inkscape {
35 class MessageContext;
36 class SelCue;
37 namespace XML {
38 class Node;
39 }
40 }
42 gboolean sp_event_context_snap_watchdog_callback(gpointer data);
43 void sp_event_context_discard_delayed_snap_event(SPEventContext *ec);
45 class DelayedSnapEvent
46 {
47 public:
48 enum DelayedSnapEventOrigin {
49 UNDEFINED_HANDLER = 0,
50 EVENTCONTEXT_ROOT_HANDLER,
51 EVENTCONTEXT_ITEM_HANDLER,
52 KNOT_HANDLER,
53 CONTROL_POINT_HANDLER,
54 GUIDE_HANDLER,
55 GUIDE_HRULER,
56 GUIDE_VRULER
57 };
59 DelayedSnapEvent(SPEventContext *event_context, gpointer const dse_item, gpointer dse_item2, GdkEventMotion const *event, DelayedSnapEvent::DelayedSnapEventOrigin const origin)
60 : _timer_id(0), _event(NULL), _item(dse_item), _item2(dse_item2), _origin(origin), _event_context(event_context)
61 {
62 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
63 double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000);
64 _timer_id = g_timeout_add(value, &sp_event_context_snap_watchdog_callback, this);
65 _event = gdk_event_copy((GdkEvent*) event);
66 ((GdkEventMotion *)_event)->time = GDK_CURRENT_TIME;
67 }
69 ~DelayedSnapEvent() {
70 if (_timer_id > 0) g_source_remove(_timer_id); // Kill the watchdog
71 if (_event != NULL) gdk_event_free(_event); // Remove the copy of the original event
72 }
74 SPEventContext* getEventContext() {return _event_context;}
75 DelayedSnapEventOrigin getOrigin() {return _origin;}
76 GdkEvent* getEvent() {return _event;}
77 gpointer getItem() {return _item;}
78 gpointer getItem2() {return _item2;}
80 private:
81 guint _timer_id;
82 GdkEvent* _event;
83 gpointer _item;
84 gpointer _item2;
85 DelayedSnapEventOrigin _origin;
86 SPEventContext* _event_context;
87 };
89 void sp_event_context_snap_delay_handler(SPEventContext *ec, gpointer const dse_item, gpointer const dse_item2, GdkEventMotion *event, DelayedSnapEvent::DelayedSnapEventOrigin origin);
91 /**
92 * Base class for Event processors.
93 */
94 struct SPEventContext : public GObject {
95 void enableSelectionCue (bool enable=true);
96 void enableGrDrag (bool enable=true);
98 /// Desktop eventcontext stack
99 SPEventContext *next;
100 unsigned key;
101 SPDesktop *desktop;
102 Inkscape::Preferences::Observer *pref_observer;
103 gchar const *const *cursor_shape;
104 gint hot_x, hot_y; ///< indicates the cursor's hot spot
105 GdkCursor *cursor;
107 gint xp, yp; ///< where drag started
108 gint tolerance;
109 bool within_tolerance; ///< are we still within tolerance of origin
111 SPItem *item_to_select; ///< the item where mouse_press occurred, to
112 ///< be selected if this is a click not drag
114 Inkscape::MessageContext *defaultMessageContext() {
115 return _message_context;
116 }
118 Inkscape::MessageContext *_message_context;
120 Inkscape::SelCue *_selcue;
122 GrDrag *_grdrag;
123 GrDrag *get_drag () {return _grdrag;}
125 ShapeEditor* shape_editor;
127 bool space_panning;
129 DelayedSnapEvent *_delayed_snap_event;
130 bool _dse_callback_in_process;
131 };
133 /**
134 * The SPEvent vtable.
135 */
136 struct SPEventContextClass : public GObjectClass {
137 void (* setup)(SPEventContext *ec);
138 void (* finish)(SPEventContext *ec);
139 void (* set)(SPEventContext *ec, Inkscape::Preferences::Entry *val);
140 void (* activate)(SPEventContext *ec);
141 void (* deactivate)(SPEventContext *ec);
142 gint (* root_handler)(SPEventContext *ec, GdkEvent *event);
143 gint (* item_handler)(SPEventContext *ec, SPItem *item, GdkEvent *event);
144 };
146 #define SP_EVENT_CONTEXT_DESKTOP(e) (SP_EVENT_CONTEXT(e)->desktop)
147 #define SP_EVENT_CONTEXT_DOCUMENT(e) ((SP_EVENT_CONTEXT_DESKTOP(e))->doc())
149 #define SP_EVENT_CONTEXT_STATIC 0
151 SPEventContext *sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, unsigned key);
152 void sp_event_context_finish(SPEventContext *ec);
153 void sp_event_context_read(SPEventContext *ec, gchar const *key);
154 void sp_event_context_activate(SPEventContext *ec);
155 void sp_event_context_deactivate(SPEventContext *ec);
157 gint sp_event_context_root_handler(SPEventContext *ec, GdkEvent *event);
158 gint sp_event_context_virtual_root_handler(SPEventContext *ec, GdkEvent *event);
159 gint sp_event_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
160 gint sp_event_context_virtual_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
162 void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event);
164 gint gobble_key_events(guint keyval, gint mask);
165 gint gobble_motion_events(gint mask);
167 void sp_event_context_update_cursor(SPEventContext *ec);
169 void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, GdkEvent *event,
170 gchar const *ctrl_tip, gchar const *shift_tip, gchar const *alt_tip);
172 guint get_group0_keyval(GdkEventKey *event);
174 SPItem *sp_event_context_find_item (SPDesktop *desktop, Geom::Point const &p, bool select_under, bool into_groups);
175 SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Point const &p);
177 ShapeEditor *sp_event_context_get_shape_editor (SPEventContext *ec);
178 bool sp_event_context_knot_mouseover(SPEventContext *ec);
180 void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr,
181 gchar const *name, gchar const *old_value, gchar const *new_value,
182 bool const is_interactive, gpointer const data);
184 void event_context_print_event_info(GdkEvent *event, bool print_return = true);
186 #endif
189 /*
190 Local Variables:
191 mode:c++
192 c-file-style:"stroustrup"
193 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
194 indent-tabs-mode:nil
195 fill-column:99
196 End:
197 */
198 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :