summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/tool-base.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-11-13 00:00:04 +0000
committerJabiertxof <jtx@jtx.marker.es>2013-11-13 00:00:04 +0000
commit152a0caf7e216e7ceafeed20822500c385e3e2df (patch)
treea3b5d60e08f3bd8221ba2e50eea80b087e5d541a /src/ui/tools/tool-base.cpp
parentUpdate to trunk (diff)
parentfix C++11 compilation. There A LOT of const_casts in this file... :-( (diff)
downloadinkscape-152a0caf7e216e7ceafeed20822500c385e3e2df.tar.gz
inkscape-152a0caf7e216e7ceafeed20822500c385e3e2df.zip
Update to trunk
(bzr r12588.1.26)
Diffstat (limited to '')
-rw-r--r--src/ui/tools/tool-base.cpp (renamed from src/event-context.cpp)189
1 files changed, 44 insertions, 145 deletions
diff --git a/src/event-context.cpp b/src/ui/tools/tool-base.cpp
index 398d3b0e3..6c7867633 100644
--- a/src/event-context.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -24,7 +24,7 @@
#include "shortcuts.h"
#include "file.h"
-#include "event-context.h"
+#include "ui/tools/tool-base.h"
#include <string.h>
#include <gdk/gdkkeysyms.h>
@@ -52,14 +52,12 @@
#include "attributes.h"
#include "rubberband.h"
#include "selcue.h"
-#include "lpe-tool-context.h"
+#include "ui/tools/lpe-tool.h"
#include "ui/tool/control-point.h"
#include "shape-editor.h"
#include "sp-guide.h"
#include "color.h"
-static void set_event_location(SPDesktop * desktop, GdkEvent * event);
-
// globals for temporary switching to selector by space
static bool selector_toggled = FALSE;
static int switch_selector_to = 0;
@@ -68,29 +66,31 @@ 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;
-
// globals for keeping track of keyboard scroll events in order to accelerate
static guint32 scroll_event_time = 0;
static gdouble scroll_multiply = 1;
static guint scroll_keyval = 0;
-void SPEventContext::set(const Inkscape::Preferences::Entry& /*val*/) {
-}
-void SPEventContext::activate() {
-}
+namespace Inkscape {
+namespace UI {
+namespace Tools {
-void SPEventContext::deactivate() {
+static void set_event_location(SPDesktop * desktop, GdkEvent * event);
+
+
+void ToolBase::set(const Inkscape::Preferences::Entry& /*val*/) {
}
-void SPEventContext::finish() {
+void ToolBase::finish() {
this->enableSelectionCue(false);
}
-SPEventContext::SPEventContext() {
+SPDesktop const& ToolBase::getDesktop() const {
+ return *desktop;
+}
+
+ToolBase::ToolBase() {
this->hot_y = 0;
this->xp = 0;
this->cursor_shape = 0;
@@ -114,7 +114,7 @@ SPEventContext::SPEventContext() {
//this->tool_url = NULL;
}
-SPEventContext::~SPEventContext() {
+ToolBase::~ToolBase() {
if (this->message_context) {
delete this->message_context;
}
@@ -145,7 +145,7 @@ SPEventContext::~SPEventContext() {
/**
* Set the cursor to a standard GDK cursor
*/
-static void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursorType cursor_type) {
+static void sp_event_context_set_cursor(ToolBase *event_context, GdkCursorType cursor_type) {
GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop));
GdkDisplay *display = gdk_display_get_default();
@@ -164,9 +164,9 @@ static void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursor
}
/**
- * Recreates and draws cursor on desktop related to SPEventContext.
+ * Recreates and draws cursor on desktop related to ToolBase.
*/
-void SPEventContext::sp_event_context_update_cursor() {
+void ToolBase::sp_event_context_update_cursor() {
GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop));
if (gtk_widget_get_window (w)) {
@@ -223,14 +223,12 @@ void SPEventContext::sp_event_context_update_cursor() {
}
/**
- * Callback that gets called on initialization of SPEventContext object.
+ * Callback that gets called on initialization of ToolBase object.
* Redraws mouse cursor, at the moment.
- */
-
-/**
+ *
* When you override it, call this method first.
*/
-void SPEventContext::setup() {
+void ToolBase::setup() {
this->pref_observer = new ToolPrefObserver(this->getPrefsPath(), this);
Inkscape::Preferences::get()->addObserver(*(this->pref_observer));
@@ -352,16 +350,7 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration,
return scroll_multiply;
}
-/**
- * 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);
-//}
-
-bool SPEventContext::root_handler(GdkEvent* event) {
+bool ToolBase::root_handler(GdkEvent* event) {
static Geom::Point button_w;
static unsigned int panning = 0;
static unsigned int panning_cursor = 0;
@@ -866,13 +855,7 @@ bool SPEventContext::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);
-//}
-
-bool SPEventContext::item_handler(SPItem* item, GdkEvent* event) {
+bool ToolBase::item_handler(SPItem* item, GdkEvent* event) {
int ret = FALSE;
switch (event->type) {
@@ -893,7 +876,7 @@ bool SPEventContext::item_handler(SPItem* item, GdkEvent* event) {
/**
* Returns true if we're hovering above a knot (needed because we don't want to pre-snap in that case).
*/
-bool sp_event_context_knot_mouseover(SPEventContext *ec)
+bool sp_event_context_knot_mouseover(ToolBase *ec)
{
if (ec->shape_editor) {
return ec->shape_editor->knot_mouseover();
@@ -903,61 +886,9 @@ bool sp_event_context_knot_mouseover(SPEventContext *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<SPEventContext*>(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.
+ * Enables/disables the ToolBase's SelCue.
*/
-//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
-
-/**
- * Enables/disables the SPEventContext's SelCue.
- */
-void SPEventContext::enableSelectionCue(bool enable) {
+void ToolBase::enableSelectionCue(bool enable) {
if (enable) {
if (!_selcue) {
_selcue = new Inkscape::SelCue(desktop);
@@ -969,9 +900,9 @@ void SPEventContext::enableSelectionCue(bool enable) {
}
/**
- * Enables/disables the SPEventContext's GrDrag.
+ * Enables/disables the ToolBase's GrDrag.
*/
-void SPEventContext::enableGrDrag(bool enable) {
+void ToolBase::enableGrDrag(bool enable) {
if (enable) {
if (!_grdrag) {
_grdrag = new GrDrag(desktop);
@@ -987,7 +918,7 @@ void SPEventContext::enableGrDrag(bool enable) {
/**
* Delete a selected GrDrag point
*/
-bool SPEventContext::deleteSelectedDrag(bool just_one) {
+bool ToolBase::deleteSelectedDrag(bool just_one) {
if (_grdrag && _grdrag->selected) {
_grdrag->deleteSelected(just_one);
@@ -998,58 +929,22 @@ bool SPEventContext::deleteSelectedDrag(bool just_one) {
}
/**
- * Calls virtual set() function of SPEventContext.
+ * Calls virtual set() function of ToolBase.
*/
-void sp_event_context_read(SPEventContext *ec, gchar const *key) {
+void sp_event_context_read(ToolBase *ec, gchar const *key) {
g_return_if_fail(ec != NULL);
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);
-// }
-
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Inkscape::Preferences::Entry val = prefs->getEntry(ec->pref_observer->observed_path + '/' + key);
ec->set(val);
}
/**
- * Calls virtual activate() function of SPEventContext.
- */
-void sp_event_context_activate(SPEventContext *ec) {
- g_return_if_fail(ec != NULL);
- g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
-
- // Make sure no delayed snapping events are carried over after switching contexts
- // (this is only an additional safety measure against sloppy coding, because each
- // 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);
- ec->activate();
-}
-
-/**
- * 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();
-//}
-
-/**
* Calls virtual root_handler(), the main event handling function.
*/
-gint sp_event_context_root_handler(SPEventContext * event_context,
+gint sp_event_context_root_handler(ToolBase * event_context,
GdkEvent * event)
{
switch (event->type) {
@@ -1080,7 +975,7 @@ gint sp_event_context_root_handler(SPEventContext * event_context,
return sp_event_context_virtual_root_handler(event_context, event);
}
-gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEvent * event) {
+gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * event) {
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)
@@ -1095,7 +990,7 @@ gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEv
/**
* Calls virtual item_handler(), the item event handling function.
*/
-gint sp_event_context_item_handler(SPEventContext * event_context,
+gint sp_event_context_item_handler(ToolBase * event_context,
SPItem * item, GdkEvent * event) {
switch (event->type) {
case GDK_MOTION_NOTIFY:
@@ -1121,7 +1016,7 @@ gint sp_event_context_item_handler(SPEventContext * event_context,
return sp_event_context_virtual_item_handler(event_context, item, event);
}
-gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPItem * item, GdkEvent * event) {
+gint sp_event_context_virtual_item_handler(ToolBase * event_context, SPItem * item, GdkEvent * event) {
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)
@@ -1269,7 +1164,7 @@ sp_event_context_over_item(SPDesktop *desktop, SPItem *item,
}
ShapeEditor *
-sp_event_context_get_shape_editor(SPEventContext *ec) {
+sp_event_context_get_shape_editor(ToolBase *ec) {
return ec->shape_editor;
}
@@ -1326,7 +1221,7 @@ void event_context_print_event_info(GdkEvent *event, bool print_return) {
* @param event Pointer to the motion event.
* @param origin Identifier (enum) specifying where the delay (and the call to this method) were initiated.
*/
-void sp_event_context_snap_delay_handler(SPEventContext *ec,
+void sp_event_context_snap_delay_handler(ToolBase *ec,
gpointer const dse_item, gpointer const dse_item2, GdkEventMotion *event,
DelayedSnapEvent::DelayedSnapEventOrigin origin)
{
@@ -1415,7 +1310,7 @@ gboolean sp_event_context_snap_watchdog_callback(gpointer data) {
return FALSE;
}
- SPEventContext *ec = dse->getEventContext();
+ ToolBase *ec = dse->getEventContext();
if (ec == NULL) {
delete dse;
return false;
@@ -1513,12 +1408,16 @@ gboolean sp_event_context_snap_watchdog_callback(gpointer data) {
return FALSE; //Kills the timer and stops it from executing this callback over and over again.
}
-void sp_event_context_discard_delayed_snap_event(SPEventContext *ec) {
+void sp_event_context_discard_delayed_snap_event(ToolBase *ec) {
delete ec->_delayed_snap_event;
ec->_delayed_snap_event = NULL;
ec->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
}
+}
+}
+}
+
/*
Local Variables:
mode:c++