Code

Merge GSoC 2009 node tool rewrite
[inkscape.git] / src / event-context.h
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         };
56         DelayedSnapEvent(SPEventContext *event_context, SPItem* const item, SPKnot* knot, GdkEventMotion const *event, DelayedSnapEvent::DelayedSnapEventOrigin const origin)
57         : _timer_id(0), _event(NULL), _item(item), _knot(knot), _origin(origin), _event_context(event_context)
58         {
59                 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
60                 double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000);
61                 _timer_id = g_timeout_add(value, &sp_event_context_snap_watchdog_callback, this);
62                 _event = gdk_event_copy((GdkEvent*) event);
63                 ((GdkEventMotion *)_event)->time = GDK_CURRENT_TIME;
64         }
66         ~DelayedSnapEvent()     {
67                 if (_timer_id > 0) g_source_remove(_timer_id); // Kill the watchdog
68                 if (_event != NULL) gdk_event_free(_event); // Remove the copy of the original event
69         }
71         SPEventContext* getEventContext() {return _event_context;}
72         DelayedSnapEventOrigin getOrigin() {return _origin;}
73         GdkEvent* getEvent() {return _event;}
74         SPItem* getItem() {return _item;}
75         SPKnot* getKnot() {return _knot;}
77 private:
78         guint _timer_id;
79         GdkEvent* _event;
80         SPItem* _item;
81         SPKnot* _knot;
82         DelayedSnapEventOrigin _origin;
83         SPEventContext* _event_context;
84 };
86 void sp_event_context_snap_delay_handler(SPEventContext *ec, SPItem* const item, SPKnot* const knot, GdkEventMotion *event, DelayedSnapEvent::DelayedSnapEventOrigin origin);
88 /**
89  * Base class for Event processors.
90  */
91 struct SPEventContext : public GObject {
92     void enableSelectionCue (bool enable=true);
93     void enableGrDrag (bool enable=true);
95     /// Desktop eventcontext stack
96     SPEventContext *next;
97     unsigned key;
98     SPDesktop *desktop;
99     Inkscape::Preferences::Observer *pref_observer;
100     gchar const *const *cursor_shape;
101     gint hot_x, hot_y; ///< indicates the cursor's hot spot
102     GdkCursor *cursor;
104     gint xp, yp;           ///< where drag started
105     gint tolerance;
106     bool within_tolerance;  ///< are we still within tolerance of origin
108     SPItem *item_to_select; ///< the item where mouse_press occurred, to
109                             ///< be selected if this is a click not drag
111     Inkscape::MessageContext *defaultMessageContext() {
112         return _message_context;
113     }
115     Inkscape::MessageContext *_message_context;
117     Inkscape::SelCue *_selcue;
119     GrDrag *_grdrag;
120     GrDrag *get_drag () {return _grdrag;}
122     ShapeEditor* shape_editor;
124     bool space_panning;
126     DelayedSnapEvent *_delayed_snap_event;
127 };
129 /**
130  * The SPEvent vtable.
131  */
132 struct SPEventContextClass : public GObjectClass {
133     void (* setup)(SPEventContext *ec);
134     void (* finish)(SPEventContext *ec);
135     void (* set)(SPEventContext *ec, Inkscape::Preferences::Entry *val);
136     void (* activate)(SPEventContext *ec);
137     void (* deactivate)(SPEventContext *ec);
138     gint (* root_handler)(SPEventContext *ec, GdkEvent *event);
139     gint (* item_handler)(SPEventContext *ec, SPItem *item, GdkEvent *event);
140 };
142 #define SP_EVENT_CONTEXT_DESKTOP(e) (SP_EVENT_CONTEXT(e)->desktop)
143 #define SP_EVENT_CONTEXT_DOCUMENT(e) ((SP_EVENT_CONTEXT_DESKTOP(e))->doc())
145 #define SP_EVENT_CONTEXT_STATIC 0
147 SPEventContext *sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, unsigned key);
148 void sp_event_context_finish(SPEventContext *ec);
149 void sp_event_context_read(SPEventContext *ec, gchar const *key);
150 void sp_event_context_activate(SPEventContext *ec);
151 void sp_event_context_deactivate(SPEventContext *ec);
153 gint sp_event_context_root_handler(SPEventContext *ec, GdkEvent *event);
154 gint sp_event_context_virtual_root_handler(SPEventContext *ec, GdkEvent *event);
155 gint sp_event_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
156 gint sp_event_context_virtual_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
158 void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event);
160 gint gobble_key_events(guint keyval, gint mask);
161 gint gobble_motion_events(gint mask);
163 void sp_event_context_update_cursor(SPEventContext *ec);
165 void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, GdkEvent *event,
166                                 gchar const *ctrl_tip, gchar const *shift_tip, gchar const *alt_tip);
168 guint get_group0_keyval(GdkEventKey *event);
170 SPItem *sp_event_context_find_item (SPDesktop *desktop, Geom::Point const &p, bool select_under, bool into_groups);
171 SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Point const &p);
173 ShapeEditor *sp_event_context_get_shape_editor (SPEventContext *ec);
175 void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr,
176                                      gchar const *name, gchar const *old_value, gchar const *new_value,
177                                  bool const is_interactive, gpointer const data);
179 void event_context_print_event_info(GdkEvent *event, bool print_return = true);
181 #endif
184 /*
185   Local Variables:
186   mode:c++
187   c-file-style:"stroustrup"
188   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
189   indent-tabs-mode:nil
190   fill-column:99
191   End:
192 */
193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :