Code

Extensions. Add option to choose dxf output units
[inkscape.git] / src / event-context.h
index 7e3c125fb7cb37a9f608bade9218d7c5dc339e0e..71084cb5f50cfb3e779c9ea1d4ee32723fd921ab 100644 (file)
 #include <glib-object.h>
 #include <gdk/gdktypes.h>
 #include <gdk/gdkevents.h>
+#include "knot.h"
+
+#include "2geom/forward.h"
+#include "preferences.h"
 
 struct GrDrag;
 struct SPDesktop;
 struct SPItem;
-struct SPKnotHolder;
-
-namespace NR {
-    class Point;
-}
+class ShapeEditor;
+struct SPEventContext;
 
 namespace Inkscape {
     class MessageContext;
@@ -38,6 +39,55 @@ namespace Inkscape {
     }
 }
 
+gboolean sp_event_context_snap_watchdog_callback(gpointer data);
+void sp_event_context_discard_delayed_snap_event(SPEventContext *ec);
+
+class DelayedSnapEvent
+{
+public:
+    enum DelayedSnapEventOrigin {
+        UNDEFINED_HANDLER = 0,
+        EVENTCONTEXT_ROOT_HANDLER,
+        EVENTCONTEXT_ITEM_HANDLER,
+        KNOT_HANDLER,
+        CONTROL_POINT_HANDLER,
+        GUIDE_HANDLER,
+        GUIDE_HRULER,
+        GUIDE_VRULER
+    };
+
+    DelayedSnapEvent(SPEventContext *event_context, gpointer const dse_item, gpointer dse_item2, GdkEventMotion const *event, DelayedSnapEvent::DelayedSnapEventOrigin const origin)
+    : _timer_id(0), _event(NULL), _item(dse_item), _item2(dse_item2), _origin(origin), _event_context(event_context)
+    {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000);
+        _timer_id = g_timeout_add(value, &sp_event_context_snap_watchdog_callback, this);
+        _event = gdk_event_copy((GdkEvent*) event);
+        ((GdkEventMotion *)_event)->time = GDK_CURRENT_TIME;
+    }
+
+    ~DelayedSnapEvent()    {
+        if (_timer_id > 0) g_source_remove(_timer_id); // Kill the watchdog
+        if (_event != NULL) gdk_event_free(_event); // Remove the copy of the original event
+    }
+
+    SPEventContext* getEventContext() {return _event_context;}
+    DelayedSnapEventOrigin getOrigin() {return _origin;}
+    GdkEvent* getEvent() {return _event;}
+    gpointer getItem() {return _item;}
+    gpointer getItem2() {return _item2;}
+
+private:
+    guint _timer_id;
+    GdkEvent* _event;
+    gpointer _item;
+    gpointer _item2;
+    DelayedSnapEventOrigin _origin;
+    SPEventContext* _event_context;
+};
+
+void sp_event_context_snap_delay_handler(SPEventContext *ec, gpointer const dse_item, gpointer const dse_item2, GdkEventMotion *event, DelayedSnapEvent::DelayedSnapEventOrigin origin);
+
 /**
  * Base class for Event processors.
  */
@@ -49,16 +99,16 @@ struct SPEventContext : public GObject {
     SPEventContext *next;
     unsigned key;
     SPDesktop *desktop;
-    Inkscape::XML::Node *prefs_repr;
-    gchar **cursor_shape;
-    gint hot_x, hot_y;
+    Inkscape::Preferences::Observer *pref_observer;
+    gchar const *const *cursor_shape;
+    gint hot_x, hot_y; ///< indicates the cursor's hot spot
     GdkCursor *cursor;
 
     gint xp, yp;           ///< where drag started
     gint tolerance;
     bool within_tolerance;  ///< are we still within tolerance of origin
 
-    SPItem *item_to_select; ///< the item where mouse_press occurred, to 
+    SPItem *item_to_select; ///< the item where mouse_press occurred, to
                             ///< be selected if this is a click not drag
 
     Inkscape::MessageContext *defaultMessageContext() {
@@ -72,8 +122,14 @@ struct SPEventContext : public GObject {
     GrDrag *_grdrag;
     GrDrag *get_drag () {return _grdrag;}
 
-    SPKnotHolder *shape_knot_holder;
-    Inkscape::XML::Node *shape_repr;
+    ShapeEditor* shape_editor;
+
+    bool space_panning;
+
+    DelayedSnapEvent *_delayed_snap_event;
+    bool _dse_callback_in_process;
+
+    char const * tool_url; ///< the (preferences) url for the tool (if a subclass corresponding to a tool is used)
 };
 
 /**
@@ -82,7 +138,7 @@ struct SPEventContext : public GObject {
 struct SPEventContextClass : public GObjectClass {
     void (* setup)(SPEventContext *ec);
     void (* finish)(SPEventContext *ec);
-    void (* set)(SPEventContext *ec, gchar const *key, gchar const *val);
+    void (* set)(SPEventContext *ec, Inkscape::Preferences::Entry *val);
     void (* activate)(SPEventContext *ec);
     void (* deactivate)(SPEventContext *ec);
     gint (* root_handler)(SPEventContext *ec, GdkEvent *event);
@@ -94,14 +150,16 @@ struct SPEventContextClass : public GObjectClass {
 
 #define SP_EVENT_CONTEXT_STATIC 0
 
-SPEventContext *sp_event_context_new(GType type, SPDesktop *desktop, Inkscape::XML::Node *prefs_repr, unsigned key);
+SPEventContext *sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, unsigned key);
 void sp_event_context_finish(SPEventContext *ec);
 void sp_event_context_read(SPEventContext *ec, gchar const *key);
 void sp_event_context_activate(SPEventContext *ec);
 void sp_event_context_deactivate(SPEventContext *ec);
 
 gint sp_event_context_root_handler(SPEventContext *ec, GdkEvent *event);
+gint sp_event_context_virtual_root_handler(SPEventContext *ec, GdkEvent *event);
 gint sp_event_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
+gint sp_event_context_virtual_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
 
 void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event);
 
@@ -115,13 +173,18 @@ void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, GdkEv
 
 guint get_group0_keyval(GdkEventKey *event);
 
-SPItem *sp_event_context_find_item (SPDesktop *desktop, NR::Point const p, bool select_under, bool into_groups);
-SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, NR::Point const p);
+SPItem *sp_event_context_find_item (SPDesktop *desktop, Geom::Point const &p, bool select_under, bool into_groups);
+SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Point const &p);
+
+ShapeEditor *sp_event_context_get_shape_editor (SPEventContext *ec);
+bool sp_event_context_knot_mouseover(SPEventContext *ec);
 
 void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr,
                                      gchar const *name, gchar const *old_value, gchar const *new_value,
                                  bool const is_interactive, gpointer const data);
 
+void event_context_print_event_info(GdkEvent *event, bool print_return = true);
+
 #endif
 
 
@@ -134,4 +197,4 @@ void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr,
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :