From e58cac52b258e64c2cc88b0044bf9cfbaecedce2 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 9 Apr 2013 00:23:07 +0200 Subject: Started conversion of SPEventContext tree; added virtual pads to all classes. (bzr r11608.1.89) --- src/event-context.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 6e5f0caad..47c8eff95 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -96,10 +96,31 @@ static void sp_event_context_class_init(SPEventContextClass *klass) { klass->item_handler = sp_event_context_private_item_handler; } +CEventContext::CEventContext(SPEventContext* eventcontext) { + this->speventcontext = eventcontext; +} + +CEventContext::~CEventContext() { +} + +void CEventContext::set(Inkscape::Preferences::Entry* val) { +} + +void CEventContext::activate() { +} + +void CEventContext::deactivate() { +} + +void CEventContext::finish() { +} + /** * Clears all SPEventContext object members. */ static void sp_event_context_init(SPEventContext *event_context) { + event_context->ceventcontext = new CEventContext(event_context); + event_context->desktop = NULL; event_context->cursor = NULL; event_context->_message_context = NULL; @@ -233,7 +254,12 @@ void sp_event_context_update_cursor(SPEventContext *ec) { * Redraws mouse cursor, at the moment. */ static void sp_event_context_private_setup(SPEventContext *ec) { - sp_event_context_update_cursor(ec); + //sp_event_context_update_cursor(ec); + ec->ceventcontext->setup(); +} + +void CEventContext::setup() { + sp_event_context_update_cursor(this->speventcontext); } /** @@ -356,6 +382,13 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, */ static gint sp_event_context_private_root_handler( SPEventContext *event_context, GdkEvent *event) { + + return event_context->ceventcontext->root_handler(event); +} + +gint CEventContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static Geom::Point button_w; static unsigned int panning = 0; static unsigned int panning_cursor = 0; @@ -811,6 +844,13 @@ static gint sp_event_context_private_root_handler( */ gint sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) { + + return ec->ceventcontext->item_handler(item, event); +} + +gint CEventContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + int ret = FALSE; switch (event->type) { -- cgit v1.2.3 From 1d8f1753cd8cab38d19fcc26a4ad70ba2e794ac8 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 9 Apr 2013 22:12:07 +0200 Subject: Added constructors to EventContext tree / some missing virtual pads. (bzr r11608.1.90) --- src/event-context.cpp | 113 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 41 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 47c8eff95..c4152a71a 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -91,9 +91,9 @@ static void sp_event_context_class_init(SPEventContextClass *klass) { object_class->dispose = sp_event_context_dispose; - klass->setup = sp_event_context_private_setup; - klass->root_handler = sp_event_context_private_root_handler; - klass->item_handler = sp_event_context_private_item_handler; +// klass->setup = sp_event_context_private_setup; +// klass->root_handler = sp_event_context_private_root_handler; +// klass->item_handler = sp_event_context_private_item_handler; } CEventContext::CEventContext(SPEventContext* eventcontext) { @@ -115,12 +115,23 @@ void CEventContext::deactivate() { void CEventContext::finish() { } -/** - * Clears all SPEventContext object members. - */ -static void sp_event_context_init(SPEventContext *event_context) { +SPEventContext::SPEventContext() { + SPEventContext* event_context = this; + event_context->ceventcontext = new CEventContext(event_context); + event_context->hot_y = 0; + event_context->xp = 0; + event_context->cursor_shape = 0; + event_context->pref_observer = 0; + event_context->hot_x = 0; + event_context->yp = 0; + event_context->within_tolerance = false; + event_context->next = 0; + event_context->tolerance = 0; + event_context->key = 0; + event_context->item_to_select = 0; + event_context->desktop = NULL; event_context->cursor = NULL; event_context->_message_context = NULL; @@ -133,6 +144,13 @@ static void sp_event_context_init(SPEventContext *event_context) { event_context->tool_url = NULL; } +/** + * Clears all SPEventContext object members. + */ +static void sp_event_context_init(SPEventContext *event_context) { + new (event_context) SPEventContext(); +} + /** * Callback to free and null member variables of SPEventContext object. */ @@ -253,10 +271,10 @@ void sp_event_context_update_cursor(SPEventContext *ec) { * Callback that gets called on initialization of SPEventContext object. * Redraws mouse cursor, at the moment. */ -static void sp_event_context_private_setup(SPEventContext *ec) { - //sp_event_context_update_cursor(ec); - ec->ceventcontext->setup(); -} +//static void sp_event_context_private_setup(SPEventContext *ec) { +// //sp_event_context_update_cursor(ec); +// ec->ceventcontext->setup(); +//} void CEventContext::setup() { sp_event_context_update_cursor(this->speventcontext); @@ -380,11 +398,11 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, /** * Main event dispatch, gets called from Gdk. */ -static gint sp_event_context_private_root_handler( - SPEventContext *event_context, GdkEvent *event) { - - return event_context->ceventcontext->root_handler(event); -} +//static gint sp_event_context_private_root_handler( +// SPEventContext *event_context, GdkEvent *event) { +// +// return event_context->ceventcontext->root_handler(event); +//} gint CEventContext::root_handler(GdkEvent* event) { SPEventContext* event_context = this->speventcontext; @@ -842,11 +860,11 @@ gint CEventContext::root_handler(GdkEvent* event) { * Only reacts to right mouse button at the moment. * \todo Fixme: do context sensitive popup menu on items. */ -gint sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, - GdkEvent *event) { - - return ec->ceventcontext->item_handler(item, event); -} +//gint sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, +// GdkEvent *event) { +// +// return ec->ceventcontext->item_handler(item, event); +//} gint CEventContext::item_handler(SPItem* item, GdkEvent* event) { SPEventContext* ec = this->speventcontext; @@ -889,10 +907,11 @@ public: Inkscape::Preferences::Observer(path), _ec(ec) { } virtual void notify(Inkscape::Preferences::Entry const &val) { - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set) { - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set(_ec, - const_cast (&val)); - } +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set) { +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set(_ec, +// const_cast (&val)); +// } + _ec->ceventcontext->set(const_cast(&val)); } private: SPEventContext * const _ec; @@ -923,8 +942,9 @@ sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, prefs->addObserver(*(ec->pref_observer)); } - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup) - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup(ec); +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup) +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup(ec); + ec->ceventcontext->setup(); return ec; } @@ -942,8 +962,9 @@ void sp_event_context_finish(SPEventContext *ec) { g_warning("Finishing event context with active link\n"); } - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); + ec->ceventcontext->finish(); } //-------------------------------member functions @@ -999,12 +1020,16 @@ void sp_event_context_read(SPEventContext *ec, gchar const *key) { g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); g_return_if_fail(key != NULL); - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Preferences::Entry val = prefs->getEntry( - ec->pref_observer->observed_path + '/' + key); - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set(ec, &val); - } +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set) { +// Inkscape::Preferences *prefs = Inkscape::Preferences::get(); +// Inkscape::Preferences::Entry val = prefs->getEntry( +// ec->pref_observer->observed_path + '/' + key); +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set(ec, &val); +// } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::Preferences::Entry val = prefs->getEntry(ec->pref_observer->observed_path + '/' + key); + ec->ceventcontext->set(&val); } /** @@ -1019,8 +1044,9 @@ void sp_event_context_activate(SPEventContext *ec) { // context should take care of this by itself. sp_event_context_discard_delayed_snap_event(ec); - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate) - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate(ec); +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate) +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate(ec); + ec->ceventcontext->activate(); } /** @@ -1030,8 +1056,9 @@ void sp_event_context_deactivate(SPEventContext *ec) { g_return_if_fail(ec != NULL); g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); - if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) - (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); +// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) +// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); + ec->ceventcontext->deactivate(); } /** @@ -1072,7 +1099,9 @@ gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEv gint ret = false; if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) - ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->root_handler(event_context, event); + //ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->root_handler(event_context, event); + ret = event_context->ceventcontext->root_handler(event); + set_event_location(event_context->desktop, event); } return ret; @@ -1111,7 +1140,9 @@ gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPIte gint ret = false; if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) - ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->item_handler(event_context, item, event); + //ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->item_handler(event_context, item, event); + ret = event_context->ceventcontext->item_handler(item, event); + if (!ret) { ret = sp_event_context_virtual_root_handler(event_context, event); } else { -- cgit v1.2.3 From fbb85064cfaaf03cc09bacedb16a8561f61f2b3d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 00:37:18 +0200 Subject: Added prefPaths to contexts; modified SPFactory (bzr r11608.1.94) --- src/event-context.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index c4152a71a..b5677a5fc 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -127,7 +127,7 @@ SPEventContext::SPEventContext() { event_context->hot_x = 0; event_context->yp = 0; event_context->within_tolerance = false; - event_context->next = 0; + //event_context->next = 0; event_context->tolerance = 0; event_context->key = 0; event_context->item_to_select = 0; @@ -958,9 +958,9 @@ void sp_event_context_finish(SPEventContext *ec) { ec->enableSelectionCue(false); - if (ec->next) { - g_warning("Finishing event context with active link\n"); - } +// if (ec->next) { +// g_warning("Finishing event context with active link\n"); +// } // if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) // (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); -- cgit v1.2.3 From fbdc8b84ff670c684dafc7d7d403ed01e7077e70 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 18:13:17 +0200 Subject: Replaced casting macros for EventContext tree; added contructors. (bzr r11608.1.96) --- src/event-context.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index b5677a5fc..3257a2a82 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -56,12 +56,6 @@ static void sp_event_context_dispose(GObject *object); -static void sp_event_context_private_setup(SPEventContext *ec); -static gint sp_event_context_private_root_handler( - SPEventContext *event_context, GdkEvent *event); -static gint sp_event_context_private_item_handler( - SPEventContext *event_context, SPItem *item, GdkEvent *event); - static void set_event_location(SPDesktop * desktop, GdkEvent * event); // globals for temporary switching to selector by space @@ -118,7 +112,10 @@ void CEventContext::finish() { SPEventContext::SPEventContext() { SPEventContext* event_context = this; - event_context->ceventcontext = new CEventContext(event_context); + event_context->ceventcontext = 0; + //event_context->ceventcontext = new CEventContext(event_context); + new (&types) std::set(); + types.insert(typeid(SPEventContext)); event_context->hot_y = 0; event_context->xp = 0; -- cgit v1.2.3 From 1227ca0189590b281116fcc808bdd8c674b2196c Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 20 Apr 2013 21:16:13 +0200 Subject: Further changes to EventContexts; they work without GObject (bzr r11608.1.97) --- src/event-context.cpp | 106 ++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 3257a2a82..c10711497 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -148,6 +148,39 @@ static void sp_event_context_init(SPEventContext *event_context) { new (event_context) SPEventContext(); } +SPEventContext::~SPEventContext() { + SPEventContext *ec; + + ec = SP_EVENT_CONTEXT(this); + + if (ec->_message_context) { + delete ec->_message_context; + } + + if (ec->cursor != NULL) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_unref(ec->cursor); +#else + gdk_cursor_unref(ec->cursor); +#endif + ec->cursor = NULL; + } + + if (ec->desktop) { + ec->desktop = NULL; + } + + if (ec->pref_observer) { + delete ec->pref_observer; + } + + if (ec->_delayed_snap_event) { + delete ec->_delayed_snap_event; + } + + //G_OBJECT_CLASS(sp_event_context_parent_class)->dispose(object); +} + /** * Callback to free and null member variables of SPEventContext object. */ @@ -895,56 +928,37 @@ bool sp_event_context_knot_mouseover(SPEventContext *ec) return false; } -/** - * An observer that relays pref changes to the derived classes. - */ -class ToolPrefObserver: public Inkscape::Preferences::Observer { -public: - ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) : - Inkscape::Preferences::Observer(path), _ec(ec) { - } - virtual void notify(Inkscape::Preferences::Entry const &val) { -// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set) { -// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set(_ec, -// const_cast (&val)); -// } - _ec->ceventcontext->set(const_cast(&val)); - } -private: - SPEventContext * const _ec; -}; - /** * Creates new SPEventContext object and calls its virtual setup() function. * @todo This is bogus. pref_path should be a private property of the inheriting objects. */ -SPEventContext * -sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, - unsigned int key) { - g_return_val_if_fail(g_type_is_a(type, SP_TYPE_EVENT_CONTEXT), NULL); - g_return_val_if_fail(desktop != NULL, NULL); - - SPEventContext * const ec = static_cast(g_object_new(type, NULL)); - - ec->desktop = desktop; - ec->_message_context - = new Inkscape::MessageContext(desktop->messageStack()); - ec->key = key; - ec->pref_observer = NULL; - - if (pref_path) { - ec->pref_observer = new ToolPrefObserver(pref_path, ec); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->addObserver(*(ec->pref_observer)); - } - -// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup) -// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup(ec); - ec->ceventcontext->setup(); - - return ec; -} +//SPEventContext * +//sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, +// unsigned int key) { +// g_return_val_if_fail(g_type_is_a(type, SP_TYPE_EVENT_CONTEXT), NULL); +// g_return_val_if_fail(desktop != NULL, NULL); +// +// SPEventContext * const ec = static_cast(g_object_new(type, NULL)); +// +// ec->desktop = desktop; +// ec->_message_context +// = new Inkscape::MessageContext(desktop->messageStack()); +// ec->key = key; +// ec->pref_observer = NULL; +// +// if (pref_path) { +// ec->pref_observer = new ToolPrefObserver(pref_path, ec); +// +// Inkscape::Preferences *prefs = Inkscape::Preferences::get(); +// prefs->addObserver(*(ec->pref_observer)); +// } +// +//// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup) +//// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup(ec); +// ec->ceventcontext->setup(); +// +// return ec; +//} /** * Finishes SPEventContext. -- cgit v1.2.3 From 65ba6ad9a82f8f47974eb10665478fd783692bb5 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 20 Apr 2013 23:19:46 +0200 Subject: Merging of EventContext classes complete. (bzr r11608.1.98) --- src/event-context.cpp | 103 ++++++++------------------------------------------ 1 file changed, 16 insertions(+), 87 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index c10711497..2b84487b6 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -54,8 +54,6 @@ #include "sp-guide.h" #include "color.h" -static void sp_event_context_dispose(GObject *object); - static void set_event_location(SPDesktop * desktop, GdkEvent * event); // globals for temporary switching to selector by space @@ -75,48 +73,21 @@ static guint32 scroll_event_time = 0; static gdouble scroll_multiply = 1; static guint scroll_keyval = 0; -G_DEFINE_TYPE(SPEventContext, sp_event_context, G_TYPE_OBJECT); - -/** - * Callback to set up the SPEventContext vtable. - */ -static void sp_event_context_class_init(SPEventContextClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - object_class->dispose = sp_event_context_dispose; - -// klass->setup = sp_event_context_private_setup; -// klass->root_handler = sp_event_context_private_root_handler; -// klass->item_handler = sp_event_context_private_item_handler; +void SPEventContext::set(Inkscape::Preferences::Entry* val) { } -CEventContext::CEventContext(SPEventContext* eventcontext) { - this->speventcontext = eventcontext; +void SPEventContext::activate() { } -CEventContext::~CEventContext() { +void SPEventContext::deactivate() { } -void CEventContext::set(Inkscape::Preferences::Entry* val) { -} - -void CEventContext::activate() { -} - -void CEventContext::deactivate() { -} - -void CEventContext::finish() { +void SPEventContext::finish() { } SPEventContext::SPEventContext() { SPEventContext* event_context = this; - event_context->ceventcontext = 0; - //event_context->ceventcontext = new CEventContext(event_context); - new (&types) std::set(); - types.insert(typeid(SPEventContext)); - event_context->hot_y = 0; event_context->xp = 0; event_context->cursor_shape = 0; @@ -141,13 +112,6 @@ SPEventContext::SPEventContext() { event_context->tool_url = NULL; } -/** - * Clears all SPEventContext object members. - */ -static void sp_event_context_init(SPEventContext *event_context) { - new (event_context) SPEventContext(); -} - SPEventContext::~SPEventContext() { SPEventContext *ec; @@ -181,41 +145,6 @@ SPEventContext::~SPEventContext() { //G_OBJECT_CLASS(sp_event_context_parent_class)->dispose(object); } -/** - * Callback to free and null member variables of SPEventContext object. - */ -static void sp_event_context_dispose(GObject *object) { - SPEventContext *ec; - - ec = SP_EVENT_CONTEXT(object); - - if (ec->_message_context) { - delete ec->_message_context; - } - - if (ec->cursor != NULL) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); -#else - gdk_cursor_unref(ec->cursor); -#endif - ec->cursor = NULL; - } - - if (ec->desktop) { - ec->desktop = NULL; - } - - if (ec->pref_observer) { - delete ec->pref_observer; - } - - if (ec->_delayed_snap_event) { - delete ec->_delayed_snap_event; - } - - G_OBJECT_CLASS(sp_event_context_parent_class)->dispose(object); -} /** * Set the cursor to a standard GDK cursor @@ -306,8 +235,8 @@ void sp_event_context_update_cursor(SPEventContext *ec) { // ec->ceventcontext->setup(); //} -void CEventContext::setup() { - sp_event_context_update_cursor(this->speventcontext); +void SPEventContext::setup() { + sp_event_context_update_cursor(this); } /** @@ -434,8 +363,8 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, // return event_context->ceventcontext->root_handler(event); //} -gint CEventContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this->speventcontext; +gint SPEventContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this; static Geom::Point button_w; static unsigned int panning = 0; @@ -896,8 +825,8 @@ gint CEventContext::root_handler(GdkEvent* event) { // return ec->ceventcontext->item_handler(item, event); //} -gint CEventContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* ec = this->speventcontext; +gint SPEventContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this; int ret = FALSE; @@ -975,7 +904,7 @@ void sp_event_context_finish(SPEventContext *ec) { // if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) // (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); - ec->ceventcontext->finish(); + ec->finish(); } //-------------------------------member functions @@ -1040,7 +969,7 @@ void sp_event_context_read(SPEventContext *ec, gchar const *key) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Preferences::Entry val = prefs->getEntry(ec->pref_observer->observed_path + '/' + key); - ec->ceventcontext->set(&val); + ec->set(&val); } /** @@ -1057,7 +986,7 @@ void sp_event_context_activate(SPEventContext *ec) { // if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate) // (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate(ec); - ec->ceventcontext->activate(); + ec->activate(); } /** @@ -1069,7 +998,7 @@ void sp_event_context_deactivate(SPEventContext *ec) { // if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) // (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); - ec->ceventcontext->deactivate(); + ec->deactivate(); } /** @@ -1111,7 +1040,7 @@ gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEv if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) //ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->root_handler(event_context, event); - ret = event_context->ceventcontext->root_handler(event); + ret = event_context->root_handler(event); set_event_location(event_context->desktop, event); } @@ -1152,7 +1081,7 @@ gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPIte if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) //ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->item_handler(event_context, item, event); - ret = event_context->ceventcontext->item_handler(item, event); + ret = event_context->item_handler(item, event); if (!ret) { ret = sp_event_context_virtual_root_handler(event_context, event); -- cgit v1.2.3 From 389b871cdea29ace85567863c439eb0537a36f54 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 21 Apr 2013 20:45:27 +0200 Subject: Cleaned up a bit. (bzr r11608.1.102) --- src/event-context.cpp | 280 +++++++++++++++++++++++++++++--------------------- 1 file changed, 165 insertions(+), 115 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 2b84487b6..63bb87570 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -64,9 +64,9 @@ static int switch_selector_to = 0; static bool dropper_toggled = FALSE; static int switch_dropper_to = 0; -static gint xp = 0, yp = 0; // where drag started -static gint tolerance = 0; -static bool within_tolerance = false; +//static gint xp = 0, yp = 0; // where drag started +//static gint tolerance = 0; +//static bool within_tolerance = false; // globals for keeping track of keyboard scroll events in order to accelerate static guint32 scroll_event_time = 0; @@ -83,66 +83,58 @@ void SPEventContext::deactivate() { } void SPEventContext::finish() { + this->enableSelectionCue(false); } SPEventContext::SPEventContext() { - SPEventContext* event_context = this; - - event_context->hot_y = 0; - event_context->xp = 0; - event_context->cursor_shape = 0; - event_context->pref_observer = 0; - event_context->hot_x = 0; - event_context->yp = 0; - event_context->within_tolerance = false; - //event_context->next = 0; - event_context->tolerance = 0; - event_context->key = 0; - event_context->item_to_select = 0; - - event_context->desktop = NULL; - event_context->cursor = NULL; - event_context->_message_context = NULL; - event_context->_selcue = NULL; - event_context->_grdrag = NULL; - event_context->space_panning = false; - event_context->shape_editor = NULL; - event_context->_delayed_snap_event = NULL; - event_context->_dse_callback_in_process = false; - event_context->tool_url = NULL; + this->hot_y = 0; + this->xp = 0; + this->cursor_shape = 0; + this->pref_observer = 0; + this->hot_x = 0; + this->yp = 0; + this->within_tolerance = false; + this->tolerance = 0; + this->key = 0; + this->item_to_select = 0; + + this->desktop = NULL; + this->cursor = NULL; + this->_message_context = NULL; + this->_selcue = NULL; + this->_grdrag = NULL; + this->space_panning = false; + this->shape_editor = NULL; + this->_delayed_snap_event = NULL; + this->_dse_callback_in_process = false; + this->tool_url = NULL; } SPEventContext::~SPEventContext() { - SPEventContext *ec; - - ec = SP_EVENT_CONTEXT(this); - - if (ec->_message_context) { - delete ec->_message_context; + if (this->_message_context) { + delete this->_message_context; } - if (ec->cursor != NULL) { + if (this->cursor != NULL) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); + g_object_unref(this->cursor); #else - gdk_cursor_unref(ec->cursor); + gdk_cursor_unref(this->cursor); #endif - ec->cursor = NULL; + this->cursor = NULL; } - if (ec->desktop) { - ec->desktop = NULL; + if (this->desktop) { + this->desktop = NULL; } - if (ec->pref_observer) { - delete ec->pref_observer; + if (this->pref_observer) { + delete this->pref_observer; } - if (ec->_delayed_snap_event) { - delete ec->_delayed_snap_event; + if (this->_delayed_snap_event) { + delete this->_delayed_snap_event; } - - //G_OBJECT_CLASS(sp_event_context_parent_class)->dispose(object); } @@ -204,7 +196,7 @@ void sp_event_context_update_cursor(SPEventContext *ec) { g_object_unref(pixbuf); } } else { - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)ec->cursor_shape); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)ec->cursor_shape); if (pixbuf) { if (ec->cursor) { @@ -364,14 +356,11 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, //} gint SPEventContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static Geom::Point button_w; static unsigned int panning = 0; static unsigned int panning_cursor = 0; static unsigned int zoom_rb = 0; - SPDesktop *desktop = event_context->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); /// @todo REmove redundant /value in preference keys @@ -383,15 +372,14 @@ gint SPEventContext::root_handler(GdkEvent* event) { case GDK_2BUTTON_PRESS: if (panning) { panning = 0; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), - event->button.time); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); ret = TRUE; } else { /* sp_desktop_dialog(); */ } break; - case GDK_BUTTON_PRESS: + case GDK_BUTTON_PRESS: // save drag origin xp = (gint) event->button.x; yp = (gint) event->button.y; @@ -401,54 +389,61 @@ gint SPEventContext::root_handler(GdkEvent* event) { switch (event->button.button) { case 1: - if (event_context->space_panning) { - + if (this->space_panning) { // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); panning = 1; + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time - 1); + ret = TRUE; } break; + case 2: if (event->button.state & GDK_SHIFT_MASK) { zoom_rb = 2; } else { - // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); panning = 2; + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time - 1); } + ret = TRUE; break; + case 3: - if (event->button.state & GDK_SHIFT_MASK || event->button.state - & GDK_CONTROL_MASK) { + if ((event->button.state & GDK_SHIFT_MASK) || (event->button.state & GDK_CONTROL_MASK)) { // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); panning = 3; + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time); + ret = TRUE; } else { sp_event_root_menu_popup(desktop, NULL, event); } break; + default: break; } break; + case GDK_MOTION_NOTIFY: if (panning) { if (panning == 4 && !xp && !yp ) { @@ -462,16 +457,14 @@ gint SPEventContext::root_handler(GdkEvent* event) { | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->motion.time - 1); - - } + if ((panning == 2 && !(event->motion.state & GDK_BUTTON2_MASK)) || (panning == 1 && !(event->motion.state & GDK_BUTTON1_MASK)) || (panning == 3 && !(event->motion.state & GDK_BUTTON3_MASK))) { /* Gdk seems to lose button release for us sometimes :-( */ panning = 0; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), - event->button.time); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); ret = TRUE; } else { if (within_tolerance && (abs((gint) event->motion.x - xp) @@ -480,6 +473,7 @@ gint SPEventContext::root_handler(GdkEvent* event) { // do not drag if we're within tolerance from origin break; } + // Once the user has moved farther than tolerance from // the original location (indicating they intend to move // the object, not click), then always process the motion @@ -493,12 +487,12 @@ gint SPEventContext::root_handler(GdkEvent* event) { if (panning_cursor == 0) { panning_cursor = 1; - sp_event_context_set_cursor(event_context, GDK_FLEUR); + sp_event_context_set_cursor(this, GDK_FLEUR); } Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const moved_w(motion_w - button_w); - event_context->desktop->scroll_world(moved_w, true); // we're still scrolling, do not redraw + this->desktop->scroll_world(moved_w, true); // we're still scrolling, do not redraw ret = TRUE; } } else if (zoom_rb) { @@ -510,6 +504,7 @@ gint SPEventContext::root_handler(GdkEvent* event) { < tolerance)) { break; // do not drag if we're within tolerance from origin } + // Once the user has moved farther than tolerance from the original location // (indicating they intend to move the object, not click), then always process the // motion notify coordinates as given (no snapping back to origin) @@ -520,30 +515,40 @@ gint SPEventContext::root_handler(GdkEvent* event) { } else { Inkscape::Rubberband::get(desktop)->start(desktop, motion_dt); } - if (zoom_rb == 2) + + if (zoom_rb == 2) { gobble_motion_events(GDK_BUTTON2_MASK); + } } break; + case GDK_BUTTON_RELEASE: xp = yp = 0; + if (panning_cursor == 1) { panning_cursor = 0; - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); - gdk_window_set_cursor(gtk_widget_get_window (w), event_context->cursor); + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); } + if (within_tolerance && (panning || zoom_rb)) { zoom_rb = 0; + if (panning) { panning = 0; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); } + Geom::Point const event_w(event->button.x, event->button.y); Geom::Point const event_dt(desktop->w2d(event_w)); + double const zoom_inc = prefs->getDoubleLimited( "/options/zoomincrement/value", M_SQRT2, 1.01, 10); + desktop->zoom_relative_keep_point(event_dt, (event->button.state & GDK_SHIFT_MASK) ? 1 / zoom_inc : zoom_inc); + desktop->updateNow(); ret = TRUE; } else if (panning == event->button.button) { @@ -557,24 +562,28 @@ gint SPEventContext::root_handler(GdkEvent* event) { // even if few intermediate steps were visible) Geom::Point const motion_w(event->button.x, event->button.y); Geom::Point const moved_w(motion_w - button_w); - event_context->desktop->scroll_world(moved_w); + + this->desktop->scroll_world(moved_w); desktop->updateNow(); ret = TRUE; } else if (zoom_rb == event->button.button) { zoom_rb = 0; - Geom::OptRect const b = - Inkscape::Rubberband::get(desktop)->getRectangle(); + + Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle(); Inkscape::Rubberband::get(desktop)->stop(); + if (b && !within_tolerance) { desktop->set_display_area(*b, 10); } + ret = TRUE; } - break; + case GDK_KEY_PRESS: { double const acceleration = prefs->getDoubleLimited( "/options/scrollingacceleration/value", 0, 0, 6); + int const key_scroll = prefs->getIntLimited("/options/keyscroll/value", 10, 0, 1000); @@ -587,12 +596,19 @@ gint SPEventContext::root_handler(GdkEvent* event) { case GDK_KEY_ISO_Left_Tab: case GDK_KEY_F1: shortcut = get_group0_keyval(&event->key); - if (event->key.state & GDK_SHIFT_MASK) + + if (event->key.state & GDK_SHIFT_MASK) { shortcut |= SP_SHORTCUT_SHIFT_MASK; - if (event->key.state & GDK_CONTROL_MASK) + } + + if (event->key.state & GDK_CONTROL_MASK) { shortcut |= SP_SHORTCUT_CONTROL_MASK; - if (event->key.state & GDK_MOD1_MASK) + } + + if (event->key.state & GDK_MOD1_MASK) { shortcut |= SP_SHORTCUT_ALT_MASK; + } + ret = sp_shortcut_invoke(shortcut, desktop); break; @@ -603,16 +619,19 @@ gint SPEventContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Q: case GDK_KEY_q: if (desktop->quick_zoomed()) { ret = TRUE; } + if (!MOD__SHIFT && !MOD__CTRL && !MOD__ALT) { desktop->zoom_quick(true); ret = TRUE; } break; + case GDK_KEY_W: case GDK_KEY_w: case GDK_KEY_F4: @@ -622,65 +641,78 @@ gint SPEventContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Left: // Ctrl Left case GDK_KEY_KP_Left: case GDK_KEY_KP_4: if (MOD__CTRL_ONLY) { int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop))); + gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); - event_context->desktop->scroll_world(i, 0); + this->desktop->scroll_world(i, 0); ret = TRUE; } break; + case GDK_KEY_Up: // Ctrl Up case GDK_KEY_KP_Up: case GDK_KEY_KP_8: if (MOD__CTRL_ONLY) { int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop))); + gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); - event_context->desktop->scroll_world(0, i); + this->desktop->scroll_world(0, i); ret = TRUE; } break; + case GDK_KEY_Right: // Ctrl Right case GDK_KEY_KP_Right: case GDK_KEY_KP_6: if (MOD__CTRL_ONLY) { int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop))); + gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); - event_context->desktop->scroll_world(-i, 0); + this->desktop->scroll_world(-i, 0); ret = TRUE; } break; + case GDK_KEY_Down: // Ctrl Down case GDK_KEY_KP_Down: case GDK_KEY_KP_2: if (MOD__CTRL_ONLY) { int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop))); + gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK); - event_context->desktop->scroll_world(0, -i); + this->desktop->scroll_world(0, -i); ret = TRUE; } break; + case GDK_KEY_F10: if (MOD__SHIFT_ONLY) { sp_event_root_menu_popup(desktop, NULL, event); ret = TRUE; } break; + case GDK_KEY_space: xp = yp = 0; within_tolerance = true; panning = 4; - event_context->space_panning = true; - event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, + + this->space_panning = true; + this->_message_context->set(Inkscape::INFORMATION_MESSAGE, _("Space+mouse move to pan canvas")); + ret = TRUE; break; + case GDK_KEY_z: case GDK_KEY_Z: if (MOD__ALT_ONLY) { @@ -688,31 +720,34 @@ gint SPEventContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + default: break; } } break; - case GDK_KEY_RELEASE: + case GDK_KEY_RELEASE: // Stop panning on any key release - if (event_context->space_panning) { - event_context->space_panning = false; - event_context->_message_context->clear(); + if (this->space_panning) { + this->space_panning = false; + this->_message_context->clear(); } if (panning) { panning = 0; xp = yp = 0; + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->key.time); + desktop->updateNow(); } if (panning_cursor == 1) { panning_cursor = 0; - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); - gdk_window_set_cursor(gtk_widget_get_window (w), event_context->cursor); + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); + gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); } switch (get_group0_keyval(&event->key)) { @@ -722,8 +757,10 @@ gint SPEventContext::root_handler(GdkEvent* event) { sp_toggle_selector(desktop); ret = TRUE; } + within_tolerance = false; break; + case GDK_KEY_Q: case GDK_KEY_q: if (desktop->quick_zoomed()) { @@ -731,13 +768,16 @@ gint SPEventContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + default: break; } break; + case GDK_SCROLL: { bool ctrl = (event->scroll.state & GDK_CONTROL_MASK); bool wheelzooms = prefs->getBool("/options/wheelzooms/value"); + int const wheel_scroll = prefs->getIntLimited( "/options/wheelscroll/value", 40, 0, 1000); @@ -753,9 +793,11 @@ gint SPEventContext::root_handler(GdkEvent* event) { case GDK_SCROLL_UP: desktop->scroll_world(wheel_scroll, 0); break; + case GDK_SCROLL_DOWN: desktop->scroll_world(-wheel_scroll, 0); break; + default: break; } @@ -765,17 +807,21 @@ gint SPEventContext::root_handler(GdkEvent* event) { double rel_zoom; double const zoom_inc = prefs->getDoubleLimited( "/options/zoomincrement/value", M_SQRT2, 1.01, 10); + switch (event->scroll.direction) { case GDK_SCROLL_UP: rel_zoom = zoom_inc; break; + case GDK_SCROLL_DOWN: rel_zoom = 1 / zoom_inc; break; + default: rel_zoom = 0.0; break; } + if (rel_zoom != 0.0) { Geom::Point const scroll_dt = desktop->point(); desktop->zoom_relative_keep_point(scroll_dt, rel_zoom); @@ -787,15 +833,19 @@ gint SPEventContext::root_handler(GdkEvent* event) { case GDK_SCROLL_UP: desktop->scroll_world(0, wheel_scroll); break; + case GDK_SCROLL_DOWN: desktop->scroll_world(0, -wheel_scroll); break; + case GDK_SCROLL_LEFT: desktop->scroll_world(wheel_scroll, 0); break; + case GDK_SCROLL_RIGHT: desktop->scroll_world(-wheel_scroll, 0); break; + #if GTK_CHECK_VERSION(3,0,0) case GDK_SCROLL_SMOOTH: gdk_event_get_scroll_deltas(event, &delta_x, &delta_y); @@ -826,18 +876,16 @@ gint SPEventContext::root_handler(GdkEvent* event) { //} gint SPEventContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* ec = this; - int ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if ((event->button.button == 3) && !(event->button.state - & GDK_SHIFT_MASK || event->button.state & GDK_CONTROL_MASK)) { - sp_event_root_menu_popup(ec->desktop, item, event); + if ((event->button.button == 3) && !((event->button.state & GDK_SHIFT_MASK) || (event->button.state & GDK_CONTROL_MASK))) { + sp_event_root_menu_popup(this->desktop, item, event); ret = TRUE; } break; + default: break; } @@ -892,20 +940,20 @@ bool sp_event_context_knot_mouseover(SPEventContext *ec) /** * Finishes SPEventContext. */ -void sp_event_context_finish(SPEventContext *ec) { - g_return_if_fail(ec != NULL); - g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); - - ec->enableSelectionCue(false); - -// if (ec->next) { -// g_warning("Finishing event context with active link\n"); -// } - -// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) -// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); - ec->finish(); -} +//void sp_event_context_finish(SPEventContext *ec) { +// g_return_if_fail(ec != NULL); +// g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); +// +// ec->enableSelectionCue(false); +// +//// if (ec->next) { +//// g_warning("Finishing event context with active link\n"); +//// } +// +//// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) +//// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); +// ec->finish(); +//} //-------------------------------member functions @@ -992,14 +1040,14 @@ void sp_event_context_activate(SPEventContext *ec) { /** * Calls virtual deactivate() function of SPEventContext. */ -void sp_event_context_deactivate(SPEventContext *ec) { - g_return_if_fail(ec != NULL); - g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); - -// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) -// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); - ec->deactivate(); -} +//void sp_event_context_deactivate(SPEventContext *ec) { +// g_return_if_fail(ec != NULL); +// g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); +// +//// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) +//// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); +// ec->deactivate(); +//} /** * Calls virtual root_handler(), the main event handling function. @@ -1173,10 +1221,12 @@ void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, */ guint get_group0_keyval(GdkEventKey *event) { guint keyval = 0; + gdk_keymap_translate_keyboard_state(gdk_keymap_get_for_display( gdk_display_get_default()), event->hardware_keycode, (GdkModifierType) event->state, 0 /*event->key.group*/, &keyval, NULL, NULL, NULL); + return keyval; } -- cgit v1.2.3 From d483730f7dbad0c29366354b32b4b2a1020eba0d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 21 Apr 2013 21:32:53 +0200 Subject: More cleaning. (bzr r11608.1.103) --- src/event-context.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 63bb87570..75d156a38 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -95,7 +95,7 @@ SPEventContext::SPEventContext() { this->yp = 0; this->within_tolerance = false; this->tolerance = 0; - this->key = 0; + //this->key = 0; this->item_to_select = 0; this->desktop = NULL; @@ -107,7 +107,7 @@ SPEventContext::SPEventContext() { this->shape_editor = NULL; this->_delayed_snap_event = NULL; this->_dse_callback_in_process = false; - this->tool_url = NULL; + //this->tool_url = NULL; } SPEventContext::~SPEventContext() { @@ -171,12 +171,12 @@ void sp_event_context_update_cursor(SPEventContext *ec) { /* fixme: */ if (ec->cursor_shape) { GdkDisplay *display = gdk_display_get_default(); - if (ec->tool_url && gdk_display_supports_cursor_alpha(display) && gdk_display_supports_cursor_color(display)) { + if (gdk_display_supports_cursor_alpha(display) && gdk_display_supports_cursor_color(display)) { bool fillHasColor=false, strokeHasColor=false; - guint32 fillColor = sp_desktop_get_color_tool(ec->desktop, ec->tool_url, true, &fillHasColor); - guint32 strokeColor = sp_desktop_get_color_tool(ec->desktop, ec->tool_url, false, &strokeHasColor); - double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->tool_url, true) : 0; - double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->tool_url, false) : 0; + guint32 fillColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), true, &fillHasColor); + guint32 strokeColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), false, &strokeHasColor); + double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), true) : 0; + double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), false) : 0; GdkPixbuf *pixbuf = sp_cursor_pixbuf_from_xpm( ec->cursor_shape, @@ -222,12 +222,14 @@ void sp_event_context_update_cursor(SPEventContext *ec) { * Callback that gets called on initialization of SPEventContext object. * Redraws mouse cursor, at the moment. */ -//static void sp_event_context_private_setup(SPEventContext *ec) { -// //sp_event_context_update_cursor(ec); -// ec->ceventcontext->setup(); -//} +/** + * When you override it, call this method first. + */ void SPEventContext::setup() { + this->pref_observer = new ToolPrefObserver(this->getPrefsPath(), this); + Inkscape::Preferences::get()->addObserver(*(this->pref_observer)); + sp_event_context_update_cursor(this); } -- cgit v1.2.3 From bdde74bbab299f2ee448f1c55469c56a66fb01f7 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 21 Apr 2013 23:58:15 +0200 Subject: Removed some unused files; more refactoring in EventContext tree. (bzr r11608.1.104) --- src/event-context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 75d156a38..622936fdb 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -73,7 +73,7 @@ static guint32 scroll_event_time = 0; static gdouble scroll_multiply = 1; static guint scroll_keyval = 0; -void SPEventContext::set(Inkscape::Preferences::Entry* val) { +void SPEventContext::set(const Inkscape::Preferences::Entry& val) { } void SPEventContext::activate() { @@ -1019,7 +1019,7 @@ void sp_event_context_read(SPEventContext *ec, gchar const *key) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Preferences::Entry val = prefs->getEntry(ec->pref_observer->observed_path + '/' + key); - ec->set(&val); + ec->set(val); } /** -- cgit v1.2.3 From b2dd3583e7372d23d18bbc6e861f4f645ec3dc37 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 30 Jul 2013 23:17:21 +0200 Subject: Further refactoring of EventContexts. (bzr r11608.1.109) --- src/event-context.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index edf34b923..bea5f63f6 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -166,60 +166,60 @@ static void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursor /** * Recreates and draws cursor on desktop related to SPEventContext. */ -void sp_event_context_update_cursor(SPEventContext *ec) { - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(ec->desktop)); +void SPEventContext::sp_event_context_update_cursor() { + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); if (gtk_widget_get_window (w)) { GtkStyle *style = gtk_widget_get_style(w); /* fixme: */ - if (ec->cursor_shape) { + if (this->cursor_shape) { GdkDisplay *display = gdk_display_get_default(); if (gdk_display_supports_cursor_alpha(display) && gdk_display_supports_cursor_color(display)) { bool fillHasColor=false, strokeHasColor=false; - guint32 fillColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), true, &fillHasColor); - guint32 strokeColor = sp_desktop_get_color_tool(ec->desktop, ec->getPrefsPath(), false, &strokeHasColor); - double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), true) : 0; - double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(ec->desktop, ec->getPrefsPath(), false) : 0; + guint32 fillColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), true, &fillHasColor); + guint32 strokeColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), false, &strokeHasColor); + double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), true) : 0; + double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), false) : 0; GdkPixbuf *pixbuf = sp_cursor_pixbuf_from_xpm( - ec->cursor_shape, + this->cursor_shape, style->black, style->white, SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(fillColor),SP_RGBA32_G_U(fillColor),SP_RGBA32_B_U(fillColor),SP_COLOR_F_TO_U(fillOpacity)), SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(strokeColor),SP_RGBA32_G_U(strokeColor),SP_RGBA32_B_U(strokeColor),SP_COLOR_F_TO_U(strokeOpacity)) ); if (pixbuf != NULL) { - if (ec->cursor) { + if (this->cursor) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); + g_object_unref(this->cursor); #else - gdk_cursor_unref(ec->cursor); + gdk_cursor_unref(this->cursor); #endif } - ec->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, ec->hot_x, ec->hot_y); + this->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, this->hot_x, this->hot_y); g_object_unref(pixbuf); } } else { - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)ec->cursor_shape); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)this->cursor_shape); if (pixbuf) { - if (ec->cursor) { + if (this->cursor) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(ec->cursor); + g_object_unref(this->cursor); #else - gdk_cursor_unref(ec->cursor); + gdk_cursor_unref(this->cursor); #endif } - ec->cursor = gdk_cursor_new_from_pixbuf(display, - pixbuf, ec->hot_x, ec->hot_y); + this->cursor = gdk_cursor_new_from_pixbuf(display, + pixbuf, this->hot_x, this->hot_y); g_object_unref(pixbuf); } } } - gdk_window_set_cursor(gtk_widget_get_window (w), ec->cursor); + gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor); gdk_flush(); } - ec->desktop->waiting_cursor = false; + this->desktop->waiting_cursor = false; } /** @@ -234,7 +234,7 @@ void SPEventContext::setup() { this->pref_observer = new ToolPrefObserver(this->getPrefsPath(), this); Inkscape::Preferences::get()->addObserver(*(this->pref_observer)); - sp_event_context_update_cursor(this); + this->sp_event_context_update_cursor(); } /** @@ -361,7 +361,7 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, // return event_context->ceventcontext->root_handler(event); //} -gint SPEventContext::root_handler(GdkEvent* event) { +bool SPEventContext::root_handler(GdkEvent* event) { static Geom::Point button_w; static unsigned int panning = 0; static unsigned int panning_cursor = 0; @@ -872,7 +872,7 @@ gint SPEventContext::root_handler(GdkEvent* event) { // return ec->ceventcontext->item_handler(item, event); //} -gint SPEventContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPEventContext::item_handler(SPItem* item, GdkEvent* event) { int ret = FALSE; switch (event->type) { -- cgit v1.2.3 From 989abbac025a8b3349748d19a613a08586c5fdcd Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 31 Jul 2013 21:11:20 +0200 Subject: Fixed SPObject ctor and dtor; removed singleton.h; some smaller changes. (bzr r11608.1.110) --- src/event-context.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index bea5f63f6..e5ea85818 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -104,7 +104,7 @@ SPEventContext::SPEventContext() { this->desktop = NULL; this->cursor = NULL; - this->_message_context = NULL; + this->message_context = NULL; this->_selcue = NULL; this->_grdrag = NULL; this->space_panning = false; @@ -115,8 +115,8 @@ SPEventContext::SPEventContext() { } SPEventContext::~SPEventContext() { - if (this->_message_context) { - delete this->_message_context; + if (this->message_context) { + delete this->message_context; } if (this->cursor != NULL) { @@ -704,7 +704,7 @@ bool SPEventContext::root_handler(GdkEvent* event) { panning = 4; this->space_panning = true; - this->_message_context->set(Inkscape::INFORMATION_MESSAGE, + this->message_context->set(Inkscape::INFORMATION_MESSAGE, _("Space+mouse move to pan canvas")); ret = TRUE; @@ -728,7 +728,7 @@ bool SPEventContext::root_handler(GdkEvent* event) { // Stop panning on any key release if (this->space_panning) { this->space_panning = false; - this->_message_context->clear(); + this->message_context->clear(); } if (panning) { -- cgit v1.2.3