diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-21 18:45:27 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-21 18:45:27 +0000 |
| commit | 389b871cdea29ace85567863c439eb0537a36f54 (patch) | |
| tree | 742ee2d623e5ecd4664e56818f4942833e1b6051 | |
| parent | Some refactoring in RectContext and StarContext. (diff) | |
| download | inkscape-389b871cdea29ace85567863c439eb0537a36f54.tar.gz inkscape-389b871cdea29ace85567863c439eb0537a36f54.zip | |
Cleaned up a bit.
(bzr r11608.1.102)
| -rw-r--r-- | src/arc-context.cpp | 280 | ||||
| -rw-r--r-- | src/arc-context.h | 24 | ||||
| -rw-r--r-- | src/desktop.cpp | 9 | ||||
| -rw-r--r-- | src/dropper-context.cpp | 184 | ||||
| -rw-r--r-- | src/dropper-context.h | 16 | ||||
| -rw-r--r-- | src/event-context.cpp | 280 | ||||
| -rw-r--r-- | src/event-context.h | 18 | ||||
| -rw-r--r-- | src/flood-context.cpp | 173 | ||||
| -rw-r--r-- | src/flood-context.h | 7 | ||||
| -rw-r--r-- | src/gradient-context.cpp | 294 | ||||
| -rw-r--r-- | src/gradient-context.h | 3 | ||||
| -rw-r--r-- | src/measure-context.cpp | 114 | ||||
| -rw-r--r-- | src/measure-context.h | 8 | ||||
| -rw-r--r-- | src/select-context.cpp | 619 | ||||
| -rw-r--r-- | src/spiral-context.cpp | 300 | ||||
| -rw-r--r-- | src/spiral-context.h | 26 | ||||
| -rw-r--r-- | src/tweak-context.cpp | 322 | ||||
| -rw-r--r-- | src/tweak-context.h | 5 | ||||
| -rw-r--r-- | src/ui/clipboard.cpp | 3 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.cpp | 582 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.h | 77 | ||||
| -rw-r--r-- | src/widgets/paintbucket-toolbar.cpp | 3 | ||||
| -rw-r--r-- | src/zoom-context.cpp | 115 | ||||
| -rw-r--r-- | src/zoom-context.h | 2 |
24 files changed, 1690 insertions, 1774 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp index bb24cba28..5851df26f 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -49,11 +49,6 @@ using Inkscape::DocumentUndo; -static void sp_arc_drag(SPArcContext *ec, Geom::Point pt, guint state); -static void sp_arc_finish(SPArcContext *ec); -static void sp_arc_cancel(SPArcContext *ec); - - #include "tool-factory.h" namespace { @@ -72,124 +67,89 @@ const std::string SPArcContext::prefsPath = "/tools/shapes/arc"; SPArcContext::SPArcContext() : SPEventContext() { - SPArcContext* arc_context = this; - - arc_context->_message_context = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(arc_context); - - event_context->cursor_shape = cursor_ellipse_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 0; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; - event_context->tool_url = "/tools/shapes/arc"; - - arc_context->item = NULL; - - //new (&arc_context->sel_changed_connection) sigc::connection(); + this->_message_context = 0; + this->cursor_shape = cursor_ellipse_xpm; + this->hot_x = 4; + this->hot_y = 4; + this->xp = 0; + this->yp = 0; + this->tolerance = 0; + this->within_tolerance = false; + this->item_to_select = NULL; + this->tool_url = "/tools/shapes/arc"; + + this->arc = NULL; } void SPArcContext::finish() { - SPEventContext* ec = this; - - SPArcContext *ac = SP_ARC_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); - sp_arc_finish(ac); - ac->sel_changed_connection.disconnect(); + this->finishItem(); + this->sel_changed_connection.disconnect(); -// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish) { -// (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish(ec); -// } SPEventContext::finish(); } SPArcContext::~SPArcContext() { - SPEventContext *ec = SP_EVENT_CONTEXT(this); - SPArcContext *ac = SP_ARC_CONTEXT(this); - - ec->enableGrDrag(false); + this->enableGrDrag(false); - ac->sel_changed_connection.disconnect(); - //ac->sel_changed_connection.~connection(); + this->sel_changed_connection.disconnect(); - delete ec->shape_editor; - ec->shape_editor = NULL; + delete this->shape_editor; + this->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ - if (ac->item) { - sp_arc_finish(ac); + if (this->arc) { + this->finishItem(); } - delete ac->_message_context; - - //G_OBJECT_CLASS(sp_arc_context_parent_class)->dispose(object); + delete this->_message_context; } /** * Callback that processes the "changed" signal on the selection; * destroys old and creates new knotholder. */ -static void sp_arc_context_selection_changed(Inkscape::Selection * selection, gpointer data) -{ - SPArcContext *ac = SP_ARC_CONTEXT(data); - SPEventContext *ec = SP_EVENT_CONTEXT(ac); - - ec->shape_editor->unset_item(SH_KNOTHOLDER); - SPItem *item = selection->singleItem(); - ec->shape_editor->set_item(item, SH_KNOTHOLDER); +void SPArcContext::selection_changed(Inkscape::Selection* selection) { + this->shape_editor->unset_item(SH_KNOTHOLDER); + this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); } void SPArcContext::setup() { - SPEventContext* ec = this; - - SPArcContext *ac = SP_ARC_CONTEXT(ec); - Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup(ec); -// } SPEventContext::setup(); - ec->shape_editor = new ShapeEditor(ec->desktop); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); - SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + this->shape_editor = new ShapeEditor(this->desktop); + + SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item, SH_KNOTHOLDER); } - ac->sel_changed_connection.disconnect(); - ac->sel_changed_connection = selection->connectChanged( - sigc::bind(sigc::ptr_fun(&sp_arc_context_selection_changed), (gpointer) ac) - ); + this->sel_changed_connection.disconnect(); + this->sel_changed_connection = selection->connectChanged( + sigc::mem_fun(this, &SPArcContext::selection_changed) + ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/shapes/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } if (prefs->getBool("/tools/shapes/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } - ac->_message_context = new Inkscape::MessageContext(ec->desktop->messageStack()); + this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } gint SPArcContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - - SPDesktop *desktop = event_context->desktop; gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - Inkscape::setup_for_drag_start(desktop, event_context, event); + if (event->button.button == 1 && !this->space_panning) { + Inkscape::setup_for_drag_start(desktop, this, event); ret = TRUE; } break; @@ -208,30 +168,26 @@ gint SPArcContext::item_handler(SPItem* item, GdkEvent* event) { } gint SPArcContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static bool dragging; - SPDesktop *desktop = event_context->desktop; Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPArcContext *ac = SP_ARC_CONTEXT(event_context); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - + if (event->button.button == 1 && !this->space_panning) { dragging = true; - ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event); + + this->center = Inkscape::setup_for_drag_start(desktop, this, event); /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - m.freeSnapReturnByRef(ac->center, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.freeSnapReturnByRef(this->center, Inkscape::SNAPSOURCE_NODE_HANDLE); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -242,27 +198,26 @@ gint SPArcContext::root_handler(GdkEvent* event) { } break; case GDK_MOTION_NOTIFY: - if (dragging && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { - - if ( event_context->within_tolerance - && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) - && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) { + if (dragging && (event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { + if ( this->within_tolerance + && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance ) + && ( abs( (gint) event->motion.y - this->yp ) < this->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 draw, not click), then always process the // motion notify coordinates as given (no snapping back to origin) - event_context->within_tolerance = false; + this->within_tolerance = false; Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w)); - sp_arc_drag(ac, motion_dt, event->motion.state); + this->drag(motion_dt, event->motion.state); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(ac)){ + } else if (!sp_event_context_knot_mouseover(this)){ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -273,31 +228,34 @@ gint SPArcContext::root_handler(GdkEvent* event) { } break; case GDK_BUTTON_RELEASE: - event_context->xp = event_context->yp = 0; - if (event->button.button == 1 && !event_context->space_panning) { + this->xp = this->yp = 0; + if (event->button.button == 1 && !this->space_panning) { dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); - if (!event_context->within_tolerance) { + sp_event_context_discard_delayed_snap_event(this); + + if (!this->within_tolerance) { // we've been dragging, finish the arc - sp_arc_finish(ac); - } else if (event_context->item_to_select) { + this->finishItem(); + } else if (this->item_to_select) { // no dragging, select clicked item if any if (event->button.state & GDK_SHIFT_MASK) { - selection->toggle(event_context->item_to_select); + selection->toggle(this->item_to_select); } else { - selection->set(event_context->item_to_select); + selection->set(this->item_to_select); } } else { // click in an empty space selection->clear(); } - event_context->xp = 0; - event_context->yp = 0; - event_context->item_to_select = NULL; + + this->xp = 0; + this->yp = 0; + this->item_to_select = NULL; ret = TRUE; } sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); break; + case GDK_KEY_PRESS: switch (get_group0_keyval (&event->key)) { case GDK_KEY_Alt_L: @@ -309,12 +267,13 @@ gint SPArcContext::root_handler(GdkEvent* event) { case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt (at least on my machine) case GDK_KEY_Meta_R: if (!dragging) { - sp_event_show_modifier_tip(event_context->defaultMessageContext(), event, + sp_event_show_modifier_tip(this->defaultMessageContext(), event, _("<b>Ctrl</b>: make circle or integer-ratio ellipse, snap arc/segment angle"), _("<b>Shift</b>: draw around the starting point"), NULL); } break; + case GDK_KEY_Up: case GDK_KEY_Down: case GDK_KEY_KP_Up: @@ -323,6 +282,7 @@ gint SPArcContext::root_handler(GdkEvent* event) { if (!MOD__CTRL_ONLY) ret = TRUE; break; + case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY) { @@ -330,38 +290,42 @@ gint SPArcContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Escape: if (dragging) { dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); // if drawing, cancel, otherwise pass it up for deselecting - sp_arc_cancel(ac); + this->cancel(); ret = TRUE; } break; + case GDK_KEY_space: if (dragging) { - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), - event->button.time); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); - if (!event_context->within_tolerance) { + sp_event_context_discard_delayed_snap_event(this); + + if (!this->within_tolerance) { // we've been dragging, finish the arc - sp_arc_finish(ac); + this->finishItem(); } // do not return true, so that space would work switching to selector } break; + case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; default: break; } break; + case GDK_KEY_RELEASE: switch (event->key.keyval) { case GDK_KEY_Alt_L: @@ -372,33 +336,28 @@ gint SPArcContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_R: case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt case GDK_KEY_Meta_R: - event_context->defaultMessageContext()->clear(); + this->defaultMessageContext()->clear(); break; + default: break; } break; + default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } return ret; } -static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop; - - if (!ac->item) { - - if (Inkscape::have_viable_layer(desktop, ac->_message_context) == false) { +void SPArcContext::drag(Geom::Point pt, guint state) { + if (!this->arc) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return; } @@ -410,33 +369,38 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) // Set style sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/arc", false); - ac->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + this->arc = SP_ARC(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); - ac->item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - ac->item->updateRepr(); + this->arc->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + this->arc->updateRepr(); desktop->canvas->forceFullRedrawAfterInterruptions(5); } bool ctrl_save = false; + if ((state & GDK_MOD1_MASK) && (state & GDK_CONTROL_MASK) && !(state & GDK_SHIFT_MASK)) { // if Alt is pressed without Shift in addition to Control, temporarily drop the CONTROL mask // so that the ellipse is not constrained to integer ratios ctrl_save = true; state = state ^ GDK_CONTROL_MASK; } - Geom::Rect r = Inkscape::snap_rectangular_box(desktop, ac->item, pt, ac->center, state); + + Geom::Rect r = Inkscape::snap_rectangular_box(desktop, this->arc, pt, this->center, state); + if (ctrl_save) { state = state ^ GDK_CONTROL_MASK; } Geom::Point dir = r.dimensions() / 2; + if (state & GDK_MOD1_MASK) { /* With Alt let the ellipse pass through the mouse pointer */ Geom::Point c = r.midpoint(); + if (!ctrl_save) { if (fabs(dir[Geom::X]) > 1E-6 && fabs(dir[Geom::Y]) > 1E-6) { - Geom::Affine const i2d ( (ac->item)->i2dt_affine() ); + Geom::Affine const i2d ( (this->arc)->i2dt_affine() ); Geom::Point new_dir = pt * i2d - c; new_dir[Geom::X] *= dir[Geom::Y] / dir[Geom::X]; double lambda = new_dir.length() / dir[Geom::Y]; @@ -451,7 +415,7 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) } } - sp_arc_position_set(SP_ARC(ac->item), + sp_arc_position_set(SP_ARC(this->arc), r.midpoint()[Geom::X], r.midpoint()[Geom::Y], r.dimensions()[Geom::X] / 2, r.dimensions()[Geom::Y] / 2); @@ -459,8 +423,10 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) double rdimy = r.dimensions()[Geom::Y]; GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric()); GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric()); + if (state & GDK_CONTROL_MASK) { int ratio_x, ratio_y; + if (fabs (rdimx) > fabs (rdimy)) { ratio_x = (int) rint (rdimx / rdimy); ratio_y = 1; @@ -468,56 +434,52 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) ratio_x = 1; ratio_y = (int) rint (rdimy / rdimx); } - ac->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Ellipse</b>: %s × %s (constrained to ratio %d:%d); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str, ratio_x, ratio_y); + + this->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Ellipse</b>: %s × %s (constrained to ratio %d:%d); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str, ratio_x, ratio_y); } else { - ac->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Ellipse</b>: %s × %s; with <b>Ctrl</b> to make square or integer-ratio ellipse; with <b>Shift</b> to draw around the starting point"), xs->str, ys->str); + this->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Ellipse</b>: %s × %s; with <b>Ctrl</b> to make square or integer-ratio ellipse; with <b>Shift</b> to draw around the starting point"), xs->str, ys->str); } + g_string_free(xs, FALSE); g_string_free(ys, FALSE); } -static void sp_arc_finish(SPArcContext *ac) -{ - ac->_message_context->clear(); - - if (ac->item != NULL) { +void SPArcContext::finishItem() { + this->_message_context->clear(); - SPGenericEllipse *ge = SP_GENERICELLIPSE(SP_ARC(ac->item)); - if (ge->rx.computed == 0 || ge->ry.computed == 0) { - sp_arc_cancel(ac); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point + if (this->arc != NULL) { + if (this->arc->rx.computed == 0 || this->arc->ry.computed == 0) { + this->cancel(); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point return; } - SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop; + SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; - SP_OBJECT(ac->item)->updateRepr(); + this->arc->updateRepr(); desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(ac->item); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC, - _("Create ellipse")); + sp_desktop_selection(desktop)->set(this->arc); - ac->item = NULL; + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC, _("Create ellipse")); + + this->arc = NULL; } } -static void sp_arc_cancel(SPArcContext *ac) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop; - +void SPArcContext::cancel() { sp_desktop_selection(desktop)->clear(); sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); - if (ac->item != NULL) { - SP_OBJECT(ac->item)->deleteObject(); - ac->item = NULL; + if (this->arc != NULL) { + this->arc->deleteObject(); + this->arc = NULL; } - ac->within_tolerance = false; - ac->xp = 0; - ac->yp = 0; - ac->item_to_select = NULL; + this->within_tolerance = false; + this->xp = 0; + this->yp = 0; + this->item_to_select = NULL; desktop->canvas->endForcedFullRedraws(); diff --git a/src/arc-context.h b/src/arc-context.h index 40bc83136..f544dd322 100644 --- a/src/arc-context.h +++ b/src/arc-context.h @@ -21,6 +21,8 @@ #include <2geom/point.h> #include "event-context.h" +#include "sp-ellipse.h" + #define SP_ARC_CONTEXT(obj) ((SPArcContext*)obj) #define SP_IS_ARC_CONTEXT(obj) (dynamic_cast<const SPArcContext*>(const SPEventContext*(obj))) @@ -29,13 +31,6 @@ public: SPArcContext(); virtual ~SPArcContext(); - SPItem *item; - Geom::Point center; - - sigc::connection sel_changed_connection; - - Inkscape::MessageContext *_message_context; - static const std::string prefsPath; virtual void setup(); @@ -44,6 +39,21 @@ public: virtual gint item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + SPArc *arc; + + Geom::Point center; + + sigc::connection sel_changed_connection; + + Inkscape::MessageContext *_message_context; + + void selection_changed(Inkscape::Selection* selection); + + void drag(Geom::Point pt, guint state); + void finishItem(); + void cancel(); }; #endif /* !SEEN_ARC_CONTEXT_H */ diff --git a/src/desktop.cpp b/src/desktop.cpp index d952fde35..2b768ede3 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -359,7 +359,8 @@ void SPDesktop::destroy() // sp_event_context_finish (ec); // g_object_unref (G_OBJECT (ec)); // } - sp_event_context_finish(event_context); + //sp_event_context_finish(event_context); + event_context->finish(); //g_object_unref(G_OBJECT(event_context)); if (event_context) { delete event_context; @@ -694,8 +695,10 @@ SPDesktop::change_document (SPDocument *theDocument) void SPDesktop::set_event_context2(const std::string& toolName) { if (event_context) { - sp_event_context_deactivate(event_context); - sp_event_context_finish(event_context); + //sp_event_context_deactivate(event_context); + event_context->deactivate(); + //sp_event_context_finish(event_context); + event_context->finish(); //g_object_unref(G_OBJECT(event_context)); delete event_context; } diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp index 4af1bba2d..d88281982 100644 --- a/src/dropper-context.cpp +++ b/src/dropper-context.cpp @@ -48,23 +48,6 @@ using Inkscape::DocumentUndo; -//typedef struct -//{ -// double R; -// double G; -// double B; -// double alpha; -// -// unsigned int dragging : 1; -// -// SPCanvasItem *grabbed; -// SPCanvasItem *area; -// Geom::Point centre; -//} SPDropperContextPrivate; -// -//#define SP_DROPPER_CONTEXT_GET_PRIVATE(dc) \ -// G_TYPE_INSTANCE_GET_PRIVATE(dc, SP_TYPE_DROPPER_CONTEXT, SPDropperContextPrivate) - static GdkCursor *cursor_dropper_fill = NULL; static GdkCursor *cursor_dropper_stroke = NULL; @@ -85,22 +68,19 @@ const std::string& SPDropperContext::getPrefsPath() { const std::string SPDropperContext::prefsPath = "/tools/dropper"; SPDropperContext::SPDropperContext() : SPEventContext() { - SPDropperContext* dc = this; - - dc->R = 0; - dc->G = 0; - dc->B = 0; - dc->alpha = 0; - dc->dragging = 0; + this->R = 0; + this->G = 0; + this->B = 0; + this->alpha = 0; + this->dragging = false; - dc->grabbed = 0; - dc->area = 0; - dc->centre = Geom::Point(0, 0); + this->grabbed = 0; + this->area = 0; + this->centre = Geom::Point(0, 0); - SPEventContext *event_context = SP_EVENT_CONTEXT(dc); - event_context->cursor_shape = cursor_dropper_f_xpm; - event_context->hot_x = 7; - event_context->hot_y = 7; + this->cursor_shape = cursor_dropper_f_xpm; + this->hot_x = 7; + this->hot_y = 7; cursor_dropper_fill = sp_cursor_new_from_xpm(cursor_dropper_f_xpm , 7, 7); cursor_dropper_stroke = sp_cursor_new_from_xpm(cursor_dropper_s_xpm , 7, 7); @@ -110,14 +90,6 @@ SPDropperContext::~SPDropperContext() { } void SPDropperContext::setup() { - SPEventContext* ec = this; - - SPDropperContext *dc = SP_DROPPER_CONTEXT(ec); - SPDropperContext *priv = (dc); - -// if ((SP_EVENT_CONTEXT_CLASS(parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(parent_class))->setup(ec); -// } SPEventContext::setup(); /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */ @@ -129,38 +101,35 @@ void SPDropperContext::setup() { c->curveto(1, -C1, C1, -1, 0, -1 ); c->curveto(-C1, -1, -1, -C1, -1, 0 ); c->closepath(); - priv->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c); + this->area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); c->unref(); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(priv->area), 0x00000000,(SPWindRule)0); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(priv->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_hide(priv->area); + + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->area), 0x00000000,(SPWindRule)0); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_hide(this->area); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/dropper/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } if (prefs->getBool("/tools/dropper/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } } void SPDropperContext::finish() { - SPEventContext* ec = this; - - SPDropperContext *dc = SP_DROPPER_CONTEXT(ec); - SPDropperContext *priv = (dc); - - ec->enableGrDrag(false); + this->enableGrDrag(false); - if (priv->grabbed) { - sp_canvas_item_ungrab(priv->grabbed, GDK_CURRENT_TIME); - priv->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); + this->grabbed = NULL; } - if (priv->area) { - sp_canvas_item_destroy(priv->area); - priv->area = NULL; + if (this->area) { + sp_canvas_item_destroy(this->area); + this->area = NULL; } if (cursor_dropper_fill) { @@ -171,6 +140,7 @@ void SPDropperContext::finish() { #endif cursor_dropper_fill = NULL; } + if (cursor_dropper_stroke) { #if GTK_CHECK_VERSION(3,0,0) g_object_unref(cursor_dropper_stroke); @@ -179,41 +149,25 @@ void SPDropperContext::finish() { #endif cursor_dropper_fill = NULL; } - - //Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - //prefs->setBool("/tools/dropper/onetimepick", false); - } /** * Returns the current dropper context color. */ -guint32 -sp_dropper_context_get_color(SPEventContext *ec) -{ - SPDropperContext *dc = SP_DROPPER_CONTEXT(ec); - SPDropperContext *priv = (dc); +guint32 SPDropperContext::get_color() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int pick = prefs->getInt("/tools/dropper/pick", - SP_DROPPER_PICK_VISIBLE); - + int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); - return SP_RGBA32_F_COMPOSE(priv->R, - priv->G, - priv->B, - (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? priv->alpha - : 1.0); + return SP_RGBA32_F_COMPOSE(this->R, + this->G, + this->B, + (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? this->alpha : 1.0); } gint SPDropperContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPDropperContext *dc = SP_DROPPER_CONTEXT(event_context); - SPDropperContext *priv = (dc); - SPDesktop *desktop = event_context->desktop; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int ret = FALSE; @@ -222,16 +176,16 @@ gint SPDropperContext::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - priv->centre = Geom::Point(event->button.x, event->button.y); - priv->dragging = TRUE; + if (event->button.button == 1 && !this->space_panning) { + this->centre = Geom::Point(event->button.x, event->button.y); + this->dragging = true; ret = TRUE; } sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - priv->grabbed = SP_CANVAS_ITEM(desktop->acetate); + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); break; case GDK_MOTION_NOTIFY: @@ -239,7 +193,7 @@ gint SPDropperContext::root_handler(GdkEvent* event) { // pass on middle and right drag ret = FALSE; break; - } else if (!event_context->space_panning) { + } else if (!this->space_panning) { // otherwise, constantly calculate color no matter is any button pressed or not // If one time pick with stroke set the pixmap @@ -252,25 +206,25 @@ gint SPDropperContext::root_handler(GdkEvent* event) { double rw = 0.0; double R(0), G(0), B(0), A(0); - if (priv->dragging) { + if (this->dragging) { // calculate average // radius - rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - priv->centre), 400.0); + rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - this->centre), 400.0); if (rw == 0) { // happens sometimes, little idea why... break; } - Geom::Point const cd = desktop->w2d(priv->centre); + Geom::Point const cd = desktop->w2d(this->centre); Geom::Affine const w2dt = desktop->w2d(); const double scale = rw * w2dt.descrim(); Geom::Affine const sm( Geom::Scale(scale, scale) * Geom::Translate(cd) ); - sp_canvas_item_affine_absolute(priv->area, sm); - sp_canvas_item_show(priv->area); + sp_canvas_item_affine_absolute(this->area, sm); + sp_canvas_item_show(this->area); /* Get buffer */ - Geom::Rect r(priv->centre, priv->centre); + Geom::Rect r(this->centre, this->centre); r.expandBy(rw); if (!r.hasZeroArea()) { Geom::IntRect area = r.roundOutwards(); @@ -309,13 +263,13 @@ gint SPDropperContext::root_handler(GdkEvent* event) { } // remember color - priv->R = R; - priv->G = G; - priv->B = B; - priv->alpha = A; + this->R = R; + this->G = G; + this->B = B; + this->alpha = A; // status message - double alpha_to_set = setalpha? priv->alpha : 1.0; + double alpha_to_set = setalpha? this->alpha : 1.0; guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, alpha_to_set); gchar c[64]; @@ -325,15 +279,14 @@ gint SPDropperContext::root_handler(GdkEvent* event) { // locale-sensitive printf is OK, since this goes to the UI, not into SVG gchar *alpha = g_strdup_printf(_(" alpha %.3g"), alpha_to_set); // where the color is picked, to show in the statusbar - gchar *where = priv->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf(_(" under cursor")); + gchar *where = this->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf(_(" under cursor")); // message, to show in the statusbar - const gchar *message = priv->dragging ? _("<b>Release mouse</b> to set color.") : _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard"); - event_context->defaultMessageContext()->setF( + const gchar *message = this->dragging ? _("<b>Release mouse</b> to set color.") : _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard"); + + this->defaultMessageContext()->setF( Inkscape::NORMAL_MESSAGE, "<b>%s%s</b>%s. %s", c, - (pick == SP_DROPPER_PICK_VISIBLE)? "" : alpha, - where, message - ); + (pick == SP_DROPPER_PICK_VISIBLE) ? "" : alpha, where, message); g_free(where); g_free(alpha); @@ -341,20 +294,21 @@ gint SPDropperContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_BUTTON_RELEASE: - if (event->button.button == 1 && !event_context->space_panning) - { - sp_canvas_item_hide(priv->area); - priv->dragging = FALSE; + if (event->button.button == 1 && !this->space_panning) { + sp_canvas_item_hide(this->area); + this->dragging = false; - if (priv->grabbed) { - sp_canvas_item_ungrab(priv->grabbed, event->button.time); - priv->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } - double alpha_to_set = setalpha? priv->alpha : 1.0; + double alpha_to_set = setalpha? this->alpha : 1.0; bool fill = !(event->button.state & GDK_SHIFT_MASK); // Stroke if Shift key held + if (prefs->getBool("/tools/dropper/onetimepick", false)) { // "One time" pick from Fill/Stroke dialog stroke page, always apply fill or stroke (ignore <Shift> key) fill = (prefs->getInt("/dialogs/fillstroke/page", 0) == 0) ? true : false; @@ -363,7 +317,7 @@ gint SPDropperContext::root_handler(GdkEvent* event) { // do the actual color setting sp_desktop_set_color(desktop, (event->button.state & GDK_MOD1_MASK)? - ColorRGBA(1 - priv->R, 1 - priv->G, 1 - priv->B, alpha_to_set) : ColorRGBA(priv->R, priv->G, priv->B, alpha_to_set), + ColorRGBA(1 - this->R, 1 - this->G, 1 - this->B, alpha_to_set) : ColorRGBA(this->R, this->G, this->B, alpha_to_set), false, fill); // REJON: set aux. toolbar input to hex color! @@ -386,6 +340,7 @@ gint SPDropperContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_PRESS: switch (get_group0_keyval(&event->key)) { case GDK_KEY_Up: @@ -397,6 +352,7 @@ gint SPDropperContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Escape: sp_desktop_selection(desktop)->clear(); case GDK_KEY_Shift_L: @@ -411,6 +367,7 @@ gint SPDropperContext::root_handler(GdkEvent* event) { break; } break; + case GDK_KEY_RELEASE: switch (get_group0_keyval(&event->key)) { case GDK_KEY_Shift_L: @@ -420,18 +377,17 @@ gint SPDropperContext::root_handler(GdkEvent* event) { gdk_window_set_cursor(window, cursor_dropper_fill); } break; + default: break; } break; + default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(parent_class))->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } diff --git a/src/dropper-context.h b/src/dropper-context.h index c2b6a0713..a95b4662e 100644 --- a/src/dropper-context.h +++ b/src/dropper-context.h @@ -27,8 +27,6 @@ public: SPDropperContext(); virtual ~SPDropperContext(); - //SPEventContext event_context; - static const std::string prefsPath; virtual void setup(); @@ -37,21 +35,21 @@ public: virtual const std::string& getPrefsPath(); -//private: + guint32 get_color(); + +private: double R; double G; double B; double alpha; - unsigned int dragging : 1; + bool dragging; - SPCanvasItem *grabbed; - SPCanvasItem *area; - Geom::Point centre; + SPCanvasItem* grabbed; + SPCanvasItem* area; + Geom::Point centre; }; -guint32 sp_dropper_context_get_color(SPEventContext *ec); - #endif /* 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, _("<b>Space+mouse move</b> 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; } diff --git a/src/event-context.h b/src/event-context.h index 155620c16..f2b8377fd 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -161,10 +161,10 @@ public: #define SP_EVENT_CONTEXT_STATIC 0 //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_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); +//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); @@ -204,21 +204,17 @@ void event_context_print_event_info(GdkEvent *event, bool print_return = true); class ToolPrefObserver: public Inkscape::Preferences::Observer { public: ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) : - Inkscape::Preferences::Observer(path), _ec(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<Inkscape::Preferences::Entry*> (&val)); -// } - _ec->set(const_cast<Inkscape::Preferences::Entry*>(&val)); + ec->set(const_cast<Inkscape::Preferences::Entry*>(&val)); } + private: - SPEventContext * const _ec; + SPEventContext * const ec; }; - - #endif // SEEN_SP_EVENT_CONTEXT_H diff --git a/src/flood-context.cpp b/src/flood-context.cpp index fccf9c24c..367597532 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -75,8 +75,6 @@ using Inkscape::Display::ExtractARGB32; using Inkscape::Display::ExtractRGB32; using Inkscape::Display::AssembleARGB32; -static void sp_flood_finish(SPFloodContext *rc); - #include "tool-factory.h" namespace { @@ -94,89 +92,65 @@ const std::string& SPFloodContext::getPrefsPath() { const std::string SPFloodContext::prefsPath = "/tools/paintbucket"; SPFloodContext::SPFloodContext() : SPEventContext() { - SPFloodContext* flood_context = this; - - flood_context->_message_context = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(flood_context); - - event_context->cursor_shape = cursor_paintbucket_xpm; - event_context->hot_x = 11; - event_context->hot_y = 30; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 4; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; - - flood_context->item = NULL; - - //new (&flood_context->sel_changed_connection) sigc::connection(); + this->_message_context = 0; + this->cursor_shape = cursor_paintbucket_xpm; + this->hot_x = 11; + this->hot_y = 30; + this->xp = 0; + this->yp = 0; + this->tolerance = 4; + this->within_tolerance = false; + this->item_to_select = NULL; + + this->item = NULL; } SPFloodContext::~SPFloodContext() { - SPFloodContext *rc = SP_FLOOD_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); + this->sel_changed_connection.disconnect(); - rc->sel_changed_connection.disconnect(); - //rc->sel_changed_connection.~connection(); - - delete ec->shape_editor; - ec->shape_editor = NULL; + delete this->shape_editor; + this->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ - if (rc->item) { - sp_flood_finish(rc); + if (this->item) { + this->finishItem(); } - if (rc->_message_context) { - delete rc->_message_context; + if (this->_message_context) { + delete this->_message_context; } - - //G_OBJECT_CLASS(sp_flood_context_parent_class)->dispose(object); } /** * Callback that processes the "changed" signal on the selection; * destroys old and creates new knotholder. */ -static void sp_flood_context_selection_changed(Inkscape::Selection *selection, gpointer data) -{ - SPFloodContext *rc = SP_FLOOD_CONTEXT(data); - SPEventContext *ec = SP_EVENT_CONTEXT(rc); - - ec->shape_editor->unset_item(SH_KNOTHOLDER); - SPItem *item = selection->singleItem(); - ec->shape_editor->set_item(item, SH_KNOTHOLDER); +void SPFloodContext::selection_changed(Inkscape::Selection* selection) { + this->shape_editor->unset_item(SH_KNOTHOLDER); + this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); } void SPFloodContext::setup() { - SPEventContext* ec = this; - - SPFloodContext *rc = SP_FLOOD_CONTEXT(ec); - -// if (((SPEventContextClass *) sp_flood_context_parent_class)->setup) { -// ((SPEventContextClass *) sp_flood_context_parent_class)->setup(ec); -// } SPEventContext::setup(); - ec->shape_editor = new ShapeEditor(ec->desktop); + this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item, SH_KNOTHOLDER); } - rc->sel_changed_connection.disconnect(); - rc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged( - sigc::bind(sigc::ptr_fun(&sp_flood_context_selection_changed), (gpointer)rc) + this->sel_changed_connection.disconnect(); + this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged( + sigc::mem_fun(this, &SPFloodContext::selection_changed) ); - rc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->_message_context = new Inkscape::MessageContext((this->desktop)->messageStack()); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/paintbucket/selcue")) { - rc->enableSelectionCue(); + this->enableSelectionCue(); } } @@ -1119,26 +1093,24 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even } gint SPFloodContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - gint ret = FALSE; - SPDesktop *desktop = event_context->desktop; - switch (event->type) { case GDK_BUTTON_PRESS: - if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !event_context->space_panning) { - Geom::Point const button_w(event->button.x, - event->button.y); + if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !this->space_panning) { + Geom::Point const button_w(event->button.x, event->button.y); SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE); // Set style desktop->applyCurrentOrToolStyle(item, "/tools/paintbucket", false); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object")); + ret = TRUE; } break; + default: break; } @@ -1153,25 +1125,21 @@ gint SPFloodContext::item_handler(SPItem* item, GdkEvent* event) { } gint SPFloodContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static bool dragging; gint ret = FALSE; - SPDesktop *desktop = event_context->desktop; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { + if (event->button.button == 1 && !this->space_panning) { if (!(event->button.state & GDK_CONTROL_MASK)) { - Geom::Point const button_w(event->button.x, - event->button.y); + Geom::Point const button_w(event->button.x, event->button.y); - if (Inkscape::have_viable_layer(desktop, event_context->defaultMessageContext())) { + if (Inkscape::have_viable_layer(desktop, this->defaultMessageContext())) { // save drag origin - event_context->xp = (gint) button_w[Geom::X]; - event_context->yp = (gint) button_w[Geom::Y]; - event_context->within_tolerance = true; + this->xp = (gint) button_w[Geom::X]; + this->yp = (gint) button_w[Geom::Y]; + this->within_tolerance = true; dragging = true; @@ -1181,44 +1149,45 @@ gint SPFloodContext::root_handler(GdkEvent* event) { } } } + case GDK_MOTION_NOTIFY: - if ( dragging - && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning) - { - if ( event_context->within_tolerance - && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) - && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) { + if ( dragging && ( event->motion.state & GDK_BUTTON1_MASK ) && !this->space_panning) { + if ( this->within_tolerance + && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance ) + && ( abs( (gint) event->motion.y - this->yp ) < this->tolerance ) ) { break; // do not drag if we're within tolerance from origin } - event_context->within_tolerance = false; + this->within_tolerance = false; Geom::Point const motion_pt(event->motion.x, event->motion.y); Geom::Point const p(desktop->w2d(motion_pt)); + if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->move(p); - event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill")); + this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill")); gobble_motion_events(GDK_BUTTON1_MASK); } } break; case GDK_BUTTON_RELEASE: - if (event->button.button == 1 && !event_context->space_panning) { + if (event->button.button == 1 && !this->space_panning) { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); + if (r->is_started()) { // set "busy" cursor desktop->setWaitingCursor(); - if (SP_IS_EVENT_CONTEXT(event_context)) { + if (SP_IS_EVENT_CONTEXT(this)) { // Since setWaitingCursor runs main loop iterations, we may have already left this tool! // So check if the tool is valid before doing anything dragging = false; - bool is_point_fill = event_context->within_tolerance; + bool is_point_fill = this->within_tolerance; bool is_touch_fill = event->button.state & GDK_MOD1_MASK; - sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill); + sp_flood_do_flood_fill(this, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill); desktop->clearWaitingCursor(); // restore cursor when done; note that it may already be different if e.g. user @@ -1229,9 +1198,9 @@ gint SPFloodContext::root_handler(GdkEvent* event) { r->stop(); - if (SP_IS_EVENT_CONTEXT(event_context)) { - event_context->defaultMessageContext()->clear(); - } + //if (SP_IS_EVENT_CONTEXT(this)) { + this->defaultMessageContext()->clear(); + //} } } break; @@ -1249,43 +1218,35 @@ gint SPFloodContext::root_handler(GdkEvent* event) { break; } break; + default: break; } if (!ret) { -// if (((SPEventContextClass *) sp_flood_context_parent_class)->root_handler) { -// ret = ((SPEventContextClass *) sp_flood_context_parent_class)->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } return ret; } -static void sp_flood_finish(SPFloodContext *rc) -{ - rc->_message_context->clear(); - - if ( rc->item != NULL ) { - SPDesktop * desktop; - - desktop = SP_EVENT_CONTEXT_DESKTOP(rc); +void SPFloodContext::finishItem() { + this->_message_context->clear(); - SP_OBJECT(rc->item)->updateRepr(); + if (this->item != NULL) { + this->item->updateRepr(); desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(rc->item); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, - _("Fill bounded area")); + sp_desktop_selection(desktop)->set(this->item); - rc->item = NULL; + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area")); + + this->item = NULL; } } -void flood_channels_set_channels( gint channels ) -{ +void SPFloodContext::set_channels(gint channels) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/paintbucket/channels", channels); } diff --git a/src/flood-context.h b/src/flood-context.h index f218bdfa6..5a60aa0f3 100644 --- a/src/flood-context.h +++ b/src/flood-context.h @@ -45,11 +45,16 @@ public: virtual gint item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); + + static void set_channels(gint channels); + +private: + void selection_changed(Inkscape::Selection* selection); + void finishItem(); }; GList* flood_channels_dropdown_items_list (void); GList* flood_autogap_dropdown_items_list (void); -void flood_channels_set_channels( gint channels ); enum PaintBucketChannels { FLOOD_CHANNELS_RGB, diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 690d6b5b4..8cb7e174b 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -72,42 +72,34 @@ const std::string SPGradientContext::prefsPath = "/tools/gradient"; SPGradientContext::SPGradientContext() : SPEventContext() { - SPGradientContext* gr_context = this; - - gr_context->node_added = false; - gr_context->subselcon = 0; - gr_context->_message_context = 0; - gr_context->selcon = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(gr_context); - - gr_context->cursor_addnode = false; - event_context->cursor_shape = cursor_gradient_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 6; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; + this->node_added = false; + this->subselcon = 0; + this->_message_context = 0; + this->selcon = 0; + + this->cursor_addnode = false; + this->cursor_shape = cursor_gradient_xpm; + this->hot_x = 4; + this->hot_y = 4; + this->xp = 0; + this->yp = 0; + this->tolerance = 6; + this->within_tolerance = false; + this->item_to_select = NULL; } SPGradientContext::~SPGradientContext() { - SPGradientContext *rc = SP_GRADIENT_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); + this->enableGrDrag(false); - ec->enableGrDrag(false); - - if (rc->_message_context) { - delete rc->_message_context; + if (this->_message_context) { + delete this->_message_context; } - rc->selcon->disconnect(); - delete rc->selcon; - rc->subselcon->disconnect(); - delete rc->subselcon; + this->selcon->disconnect(); + delete this->selcon; - //G_OBJECT_CLASS(sp_gradient_context_parent_class)->dispose(object); + this->subselcon->disconnect(); + delete this->subselcon; } const gchar *gr_handle_descr [] = { @@ -122,10 +114,8 @@ const gchar *gr_handle_descr [] = { N_("Radial gradient <b>mid stop</b>") }; -static void -gradient_selection_changed (Inkscape::Selection *, gpointer data) -{ - SPGradientContext *rc = (SPGradientContext *) data; +void SPGradientContext::selection_changed(Inkscape::Selection*) { + SPGradientContext *rc = (SPGradientContext *) this; GrDrag *drag = rc->_grdrag; Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop); @@ -173,35 +163,32 @@ gradient_selection_changed (Inkscape::Selection *, gpointer data) } } -static void -gradient_subselection_changed (gpointer, gpointer data) -{ - gradient_selection_changed (NULL, data); -} - void SPGradientContext::setup() { - SPEventContext* ec = this; - - SPGradientContext *rc = SP_GRADIENT_CONTEXT(ec); - -// if (((SPEventContextClass *) sp_gradient_context_parent_class)->setup) { -// ((SPEventContextClass *) sp_gradient_context_parent_class)->setup(ec); -// } SPEventContext::setup(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/gradient/selcue", true)) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } - ec->enableGrDrag(); - Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); + this->enableGrDrag(); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); - rc->_message_context = new Inkscape::MessageContext(sp_desktop_message_stack(ec->desktop)); + this->_message_context = new Inkscape::MessageContext(sp_desktop_message_stack(this->desktop)); - rc->selcon = new sigc::connection (selection->connectChanged( sigc::bind (sigc::ptr_fun(&gradient_selection_changed), rc))); - rc->subselcon = new sigc::connection (ec->desktop->connectToolSubselectionChanged(sigc::bind (sigc::ptr_fun(&gradient_subselection_changed), rc))); - gradient_selection_changed(selection, rc); + this->selcon = new sigc::connection(selection->connectChanged( + sigc::mem_fun(this, &SPGradientContext::selection_changed) + )); + + this->subselcon = new sigc::connection(this->desktop->connectToolSubselectionChanged( + sigc::hide(sigc::bind( + sigc::mem_fun(this, &SPGradientContext::selection_changed), + (Inkscape::Selection*)NULL + )) + )); + + this->selection_changed(selection); } void @@ -489,38 +476,36 @@ sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, G } gint SPGradientContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static bool dragging; - SPDesktop *desktop = event_context->desktop; Inkscape::Selection *selection = sp_desktop_selection (desktop); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - SPGradientContext *rc = SP_GRADIENT_CONTEXT(event_context); - - event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px - GrDrag *drag = event_context->_grdrag; + GrDrag *drag = this->_grdrag; g_assert (drag); gint ret = FALSE; + switch (event->type) { case GDK_2BUTTON_PRESS: if ( event->button.button == 1 ) { bool over_line = false; SPCtrlLine *line = NULL; + if (drag->lines) { for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { line = (SPCtrlLine*) l->data; - over_line |= sp_gradient_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); + over_line |= sp_gradient_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); } } + if (over_line) { // we take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_gradient_context_add_stop_near_point(rc, SP_ITEM(selection->itemList()->data), rc->mousepoint_doc, event->button.time); + sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time); } else { for (GSList const* i = selection->itemList(); i != NULL; i = i->next) { SPItem *item = SP_ITEM(i->data); @@ -539,14 +524,15 @@ gint SPGradientContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_BUTTON_PRESS: - if ( event->button.button == 1 && !event_context->space_panning ) { + if ( event->button.button == 1 && !this->space_panning ) { Geom::Point button_w(event->button.x, event->button.y); // save drag origin - event_context->xp = (gint) button_w[Geom::X]; - event_context->yp = (gint) button_w[Geom::Y]; - event_context->within_tolerance = true; + this->xp = (gint) button_w[Geom::X]; + this->yp = (gint) button_w[Geom::Y]; + this->within_tolerance = true; dragging = true; @@ -556,8 +542,9 @@ gint SPGradientContext::root_handler(GdkEvent* event) { } else { // remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to // enable Ctrl+doubleclick of exactly the selected item(s) - if (!(event->button.state & GDK_CONTROL_MASK)) - event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); + if (!(event->button.state & GDK_CONTROL_MASK)) { + this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE); + } if (!selection->isEmpty()) { SnapManager &m = desktop->namedview->snap_manager; @@ -565,36 +552,37 @@ gint SPGradientContext::root_handler(GdkEvent* event) { m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); } - rc->origin = button_dt; + + this->origin = button_dt; } ret = TRUE; } break; + case GDK_MOTION_NOTIFY: - if ( dragging - && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning ) - { - if ( event_context->within_tolerance - && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) - && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) { + if (dragging && ( event->motion.state & GDK_BUTTON1_MASK ) && !this->space_panning) { + if ( this->within_tolerance + && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance ) + && ( abs( (gint) event->motion.y - this->yp ) < this->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 draw, not click), then always process the // motion notify coordinates as given (no snapping back to origin) - event_context->within_tolerance = false; + this->within_tolerance = false; Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt = event_context->desktop->w2d(motion_w); + Geom::Point const motion_dt = this->desktop->w2d(motion_w); if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->move(motion_dt); - event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw around</b> handles to select them")); + this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw around</b> handles to select them")); } else { - sp_gradient_drag(*rc, motion_dt, event->motion.state, event->motion.time); + sp_gradient_drag(*this, motion_dt, event->motion.state, event->motion.time); } + gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; @@ -604,46 +592,51 @@ gint SPGradientContext::root_handler(GdkEvent* event) { m.setup(desktop); Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt = event_context->desktop->w2d(motion_w); + Geom::Point const motion_dt = this->desktop->w2d(motion_w); m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE)); m.unSetup(); } bool over_line = false; + if (drag->lines) { for (GSList *l = drag->lines; l != NULL; l = l->next) { - over_line |= sp_gradient_context_is_over_line (rc, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y)); + over_line |= sp_gradient_context_is_over_line (this, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y)); } } - if (rc->cursor_addnode && !over_line) { - event_context->cursor_shape = cursor_gradient_xpm; - sp_event_context_update_cursor(event_context); - rc->cursor_addnode = false; - } else if (!rc->cursor_addnode && over_line) { - event_context->cursor_shape = cursor_gradient_add_xpm; - sp_event_context_update_cursor(event_context); - rc->cursor_addnode = true; + if (this->cursor_addnode && !over_line) { + this->cursor_shape = cursor_gradient_xpm; + sp_event_context_update_cursor(this); + this->cursor_addnode = false; + } else if (!this->cursor_addnode && over_line) { + this->cursor_shape = cursor_gradient_add_xpm; + sp_event_context_update_cursor(this); + this->cursor_addnode = true; } } break; + case GDK_BUTTON_RELEASE: - event_context->xp = event_context->yp = 0; - if ( event->button.button == 1 && !event_context->space_panning ) { + this->xp = this->yp = 0; + + if ( event->button.button == 1 && !this->space_panning ) { bool over_line = false; SPCtrlLine *line = NULL; + if (drag->lines) { for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) { line = (SPCtrlLine*) l->data; - over_line = sp_gradient_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); + over_line = sp_gradient_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y)); if (over_line) break; } } + if ( (event->button.state & GDK_CONTROL_MASK) && (event->button.state & GDK_MOD1_MASK ) ) { if (over_line && line) { - sp_gradient_context_add_stop_near_point(rc, line->item, rc->mousepoint_doc, 0); + sp_gradient_context_add_stop_near_point(this, line->item, this->mousepoint_doc, 0); ret = TRUE; } } else { @@ -655,30 +648,29 @@ gint SPGradientContext::root_handler(GdkEvent* event) { break; } - if (!event_context->within_tolerance) { + if (!this->within_tolerance) { // we've been dragging, either do nothing (grdrag handles that), // or rubberband-select if we have rubberband Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); - if (r->is_started() && !event_context->within_tolerance) { + + if (r->is_started() && !this->within_tolerance) { // this was a rubberband drag if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); drag->selectRect(*b); } } - - } else if (event_context->item_to_select) { + } else if (this->item_to_select) { if (over_line && line) { // Clicked on an existing gradient line, dont change selection. This stops // possible change in selection during a double click with overlapping objects - } - else { + } else { // no dragging, select clicked item if any if (event->button.state & GDK_SHIFT_MASK) { - selection->toggle(event_context->item_to_select); + selection->toggle(this->item_to_select); } else { drag->deselectAll(); - selection->set(event_context->item_to_select); + selection->set(this->item_to_select); } } } else { @@ -690,12 +682,14 @@ gint SPGradientContext::root_handler(GdkEvent* event) { } } - event_context->item_to_select = NULL; + this->item_to_select = NULL; ret = TRUE; } + Inkscape::Rubberband::get(desktop)->stop(); } break; + case GDK_KEY_PRESS: switch (get_group0_keyval (&event->key)) { case GDK_KEY_Alt_L: @@ -706,7 +700,7 @@ gint SPGradientContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_R: case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt (at least on my machine) case GDK_KEY_Meta_R: - sp_event_show_modifier_tip (event_context->defaultMessageContext(), event, + sp_event_show_modifier_tip (this->defaultMessageContext(), event, _("<b>Ctrl</b>: snap gradient angle"), _("<b>Shift</b>: draw gradient around the starting point"), NULL); @@ -731,7 +725,7 @@ gint SPGradientContext::root_handler(GdkEvent* event) { case GDK_KEY_L: case GDK_KEY_l: if (MOD__CTRL_ONLY && drag->isNonEmpty() && drag->hasSelection()) { - sp_gradient_simplify(rc, 1e-4); + sp_gradient_simplify(this, 1e-4); ret = TRUE; } break; @@ -753,67 +747,98 @@ gint SPGradientContext::root_handler(GdkEvent* event) { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask if (MOD__ALT) { // alt - if (MOD__SHIFT) drag->selected_move_screen(mul*-10, 0); // shift - else drag->selected_move_screen(mul*-1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT) drag->selected_move(mul*-10*nudge, 0); // shift - else drag->selected_move(mul*-nudge, 0); // no shift + if (MOD__SHIFT) { + drag->selected_move_screen(mul*-10, 0); // shift + } else { + drag->selected_move_screen(mul*-1, 0); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + drag->selected_move(mul*-10*nudge, 0); // shift + } else { + drag->selected_move(mul*-nudge, 0); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Up: // move handle up case GDK_KEY_KP_Up: case GDK_KEY_KP_8: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) drag->selected_move_screen(0, mul*10); // shift - else drag->selected_move_screen(0, mul*1); // no shift - } - else { // no alt - if (MOD__SHIFT) drag->selected_move(0, mul*10*nudge); // shift - else drag->selected_move(0, mul*nudge); // no shift + if (MOD__SHIFT) { + drag->selected_move_screen(0, mul*10); // shift + } else { + drag->selected_move_screen(0, mul*1); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + drag->selected_move(0, mul*10*nudge); // shift + } else { + drag->selected_move(0, mul*nudge); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Right: // move handle right case GDK_KEY_KP_Right: case GDK_KEY_KP_6: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) drag->selected_move_screen(mul*10, 0); // shift - else drag->selected_move_screen(mul*1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT) drag->selected_move(mul*10*nudge, 0); // shift - else drag->selected_move(mul*nudge, 0); // no shift + if (MOD__SHIFT) { + drag->selected_move_screen(mul*10, 0); // shift + } else { + drag->selected_move_screen(mul*1, 0); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + drag->selected_move(mul*10*nudge, 0); // shift + } else { + drag->selected_move(mul*nudge, 0); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Down: // move handle down case GDK_KEY_KP_Down: case GDK_KEY_KP_2: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) drag->selected_move_screen(0, mul*-10); // shift - else drag->selected_move_screen(0, mul*-1); // no shift - } - else { // no alt - if (MOD__SHIFT) drag->selected_move(0, mul*-10*nudge); // shift - else drag->selected_move(0, mul*-nudge); // no shift + if (MOD__SHIFT) { + drag->selected_move_screen(0, mul*-10); // shift + } else { + drag->selected_move_screen(0, mul*-1); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + drag->selected_move(0, mul*-10*nudge); // shift + } else { + drag->selected_move(0, mul*-nudge); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_r: case GDK_KEY_R: if (MOD__SHIFT_ONLY) { @@ -825,19 +850,21 @@ gint SPGradientContext::root_handler(GdkEvent* event) { case GDK_KEY_Insert: case GDK_KEY_KP_Insert: // with any modifiers: - sp_gradient_context_add_stops_between_selected_stops (rc); + sp_gradient_context_add_stops_between_selected_stops (this); ret = TRUE; break; case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; + default: break; } break; + case GDK_KEY_RELEASE: switch (get_group0_keyval (&event->key)) { case GDK_KEY_Alt_L: @@ -848,20 +875,19 @@ gint SPGradientContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_R: case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt case GDK_KEY_Meta_R: - event_context->defaultMessageContext()->clear(); + this->defaultMessageContext()->clear(); break; + default: break; } break; + default: break; } if (!ret) { -// if (((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler) { -// ret = ((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } diff --git a/src/gradient-context.h b/src/gradient-context.h index 798647bf3..21418f89e 100644 --- a/src/gradient-context.h +++ b/src/gradient-context.h @@ -46,6 +46,9 @@ public: virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + void selection_changed(Inkscape::Selection*); }; void sp_gradient_context_select_next (SPEventContext *event_context); diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 2e8a1cd99..99f1d8d06 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -47,11 +47,6 @@ using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; -static gint xp = 0; // where drag started -static gint yp = 0; -static gint tolerance = 0; -static bool within_tolerance = false; - Geom::Point start_point; boost::optional<Geom::Point> explicitBase; boost::optional<Geom::Point> lastEnd; @@ -242,54 +237,44 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom SPMeasureContext::SPMeasureContext() : SPEventContext() { - SPMeasureContext* measure_context = this; - - measure_context->grabbed = 0; + this->grabbed = 0; - SPEventContext *event_context = SP_EVENT_CONTEXT(measure_context); - - event_context->cursor_shape = cursor_measure_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; + this->cursor_shape = cursor_measure_xpm; + this->hot_x = 4; + this->hot_y = 4; } SPMeasureContext::~SPMeasureContext() { } void SPMeasureContext::finish() { - SPEventContext* ec = this; - - SPMeasureContext *mc = SP_MEASURE_CONTEXT(ec); + this->enableGrDrag(false); - ec->enableGrDrag(false); - - if (mc->grabbed) { - sp_canvas_item_ungrab(mc->grabbed, GDK_CURRENT_TIME); - mc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); + this->grabbed = NULL; } } -void SPMeasureContext::setup() { - SPEventContext* ec = this; - -// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) { -// SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec); -// } - SPEventContext::setup(); -} - -gint SPMeasureContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - - gint ret = FALSE; - -// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler) { -// ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler(event_context, item, event); -// } - ret = SPEventContext::item_handler(item, event); - - return ret; -} +//void SPMeasureContext::setup() { +// SPEventContext* ec = this; +// +//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) { +//// SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec); +//// } +// SPEventContext::setup(); +//} + +//gint SPMeasureContext::item_handler(SPItem* item, GdkEvent* event) { +// gint ret = FALSE; +// +//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler) { +//// ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler(event_context, item, event); +//// } +// ret = SPEventContext::item_handler(item, event); +// +// return ret; +//} static bool GeomPointSortPredicate(const Geom::Point& p1, const Geom::Point& p2) { @@ -327,23 +312,19 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom: } gint SPMeasureContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPDesktop *desktop = event_context->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - SPMeasureContext *mc = SP_MEASURE_CONTEXT(event_context); gint ret = FALSE; switch (event->type) { - case GDK_BUTTON_PRESS: - { + case GDK_BUTTON_PRESS: { Geom::Point const button_w(event->button.x, event->button.y); explicitBase = boost::none; lastEnd = boost::none; start_point = desktop->w2d(button_w); - if (event->button.button == 1 && !event_context->space_panning) { + + if (event->button.button == 1 && !this->space_panning) { // save drag origin xp = static_cast<gint>(event->button.x); yp = static_cast<gint>(event->button.y); @@ -360,12 +341,10 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - mc->grabbed = SP_CANVAS_ITEM(desktop->acetate); + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); break; } - - case GDK_KEY_PRESS: - { + case GDK_KEY_PRESS: { if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { if (lastEnd) { explicitBase = lastEnd; @@ -373,10 +352,8 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { } break; } - - case GDK_MOTION_NOTIFY: - { - if (!((event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning)) { + case GDK_MOTION_NOTIFY: { + if (!((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning)) { if (!(event->motion.state & GDK_SHIFT_MASK)) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); @@ -407,6 +384,7 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); } + measure_tmp_items.clear(); Geom::Point const motion_w(event->motion.x, event->motion.y); @@ -414,7 +392,7 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { Geom::Point end_point = motion_dt; if (event->motion.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(event_context, end_point, start_point, event->motion.state); + spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); } else { if (!(event->motion.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; @@ -427,7 +405,6 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { } } - Geom::PathVector lineseg; Geom::Path p; p.start(desktop->dt2doc(start_point)); @@ -445,6 +422,7 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { baseAngle = atan2(deltay2, deltax2); angle -= baseAngle; + if (angle < -M_PI) { angle += 2 * M_PI; } else if (angle > M_PI) { @@ -457,6 +435,7 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { #define NPOINTS 800 std::vector<Geom::Point> points; + for (double i = 0; i < NPOINTS; i++) { points.push_back(desktop->d2w(start_point + (i / NPOINTS) * (end_point - start_point))); } @@ -749,10 +728,8 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { } break; } - - case GDK_BUTTON_RELEASE: - { - sp_event_context_discard_delayed_snap_event(event_context); + case GDK_BUTTON_RELEASE: { + sp_event_context_discard_delayed_snap_event(this); explicitBase = boost::none; lastEnd = boost::none; @@ -760,12 +737,14 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); } + measure_tmp_items.clear(); - if (mc->grabbed) { - sp_canvas_item_ungrab(mc->grabbed, event->button.time); - mc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } + xp = 0; yp = 0; break; @@ -775,9 +754,6 @@ gint SPMeasureContext::root_handler(GdkEvent* event) { } if (!ret) { -// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->root_handler) { -// ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } diff --git a/src/measure-context.h b/src/measure-context.h index 67f35025c..76509e91c 100644 --- a/src/measure-context.h +++ b/src/measure-context.h @@ -22,17 +22,15 @@ public: SPMeasureContext(); virtual ~SPMeasureContext(); - //SPEventContext event_context; - SPCanvasItem *grabbed; - static const std::string prefsPath; - virtual void setup(); virtual void finish(); virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + SPCanvasItem* grabbed; }; #endif // SEEN_SP_MEASURING_CONTEXT_H diff --git a/src/select-context.cpp b/src/select-context.cpp index 090f641f3..a347bcd9e 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -58,9 +58,9 @@ GdkPixbuf *handles[13]; static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so the next button release should not deselect static gint drag_escaped = 0; // if non-zero, drag was canceled by esc -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; #include "tool-factory.h" @@ -80,27 +80,26 @@ const std::string& SPSelectContext::getPrefsPath() { const std::string SPSelectContext::prefsPath = "/tools/select"; SPSelectContext::SPSelectContext() : SPEventContext() { - SPSelectContext* sc = this; - - sc->grabbed = 0; - sc->item = 0; - - sc->dragging = FALSE; - sc->moved = FALSE; - sc->button_press_shift = false; - sc->button_press_ctrl = false; - sc->button_press_alt = false; - sc->cycling_items = NULL; - sc->cycling_items_cmp = NULL; - sc->cycling_items_selected_before = NULL; - sc->cycling_cur_item = NULL; - sc->cycling_wrap = true; - sc->_seltrans = NULL; - sc->_describer = NULL; + this->grabbed = 0; + this->item = 0; + + this->dragging = FALSE; + this->moved = FALSE; + this->button_press_shift = false; + this->button_press_ctrl = false; + this->button_press_alt = false; + this->cycling_items = NULL; + this->cycling_items_cmp = NULL; + this->cycling_items_selected_before = NULL; + this->cycling_cur_item = NULL; + this->cycling_wrap = true; + this->_seltrans = NULL; + this->_describer = NULL; // cursors in select context CursorSelectMouseover = sp_cursor_new_from_xpm(cursor_select_m_xpm , 1, 1); CursorSelectDragging = sp_cursor_new_from_xpm(cursor_select_d_xpm , 1, 1); + // selection handles handles[0] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_nw_xpm); handles[1] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_scale_ne_xpm); @@ -118,20 +117,18 @@ SPSelectContext::SPSelectContext() : SPEventContext() { } SPSelectContext::~SPSelectContext() { - SPSelectContext *sc = SP_SELECT_CONTEXT(this); - SPEventContext * ec = SP_EVENT_CONTEXT (this); + this->enableGrDrag(false); - ec->enableGrDrag(false); - - if (sc->grabbed) { - sp_canvas_item_ungrab(sc->grabbed, GDK_CURRENT_TIME); - sc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); + this->grabbed = NULL; } - delete sc->_seltrans; - sc->_seltrans = NULL; - delete sc->_describer; - sc->_describer = NULL; + delete this->_seltrans; + this->_seltrans = NULL; + + delete this->_describer; + this->_describer = NULL; if (CursorSelectDragging) { #if GTK_CHECK_VERSION(3,0,0) @@ -141,6 +138,7 @@ SPSelectContext::~SPSelectContext() { #endif CursorSelectDragging = NULL; } + if (CursorSelectMouseover) { #if GTK_CHECK_VERSION(3,0,0) g_object_unref(CursorSelectMouseover); @@ -149,51 +147,38 @@ SPSelectContext::~SPSelectContext() { #endif CursorSelectMouseover = NULL; } - - //G_OBJECT_CLASS(sp_select_context_parent_class)->dispose(object); } void SPSelectContext::setup() { - SPEventContext* ec = this; - - SPSelectContext *select_context = SP_SELECT_CONTEXT(ec); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup(ec); -// } SPEventContext::setup(); - SPDesktop *desktop = ec->desktop; - - select_context->_describer = new Inkscape::SelectionDescriber( + this->_describer = new Inkscape::SelectionDescriber( desktop->selection, desktop->messageStack(), _("Click selection to toggle scale/rotation handles"), _("No objects selected. Click, Shift+click, Alt+scroll mouse on top of objects, or drag around objects to select.") - ); + ); - select_context->_seltrans = new Inkscape::SelTrans(desktop); + this->_seltrans = new Inkscape::SelTrans(desktop); - sp_event_context_read(ec, "show"); - sp_event_context_read(ec, "transform"); + sp_event_context_read(this, "show"); + sp_event_context_read(this, "transform"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/select/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } } void SPSelectContext::set(Inkscape::Preferences::Entry* val) { - SPEventContext* ec = this; - - SPSelectContext *sc = SP_SELECT_CONTEXT(ec); Glib::ustring path = val->getEntryName(); if (path == "show") { if (val->getString() == "outline") { - sc->_seltrans->setShow(Inkscape::SelTrans::SHOW_OUTLINE); + this->_seltrans->setShow(Inkscape::SelTrans::SHOW_OUTLINE); } else { - sc->_seltrans->setShow(Inkscape::SelTrans::SHOW_CONTENT); + this->_seltrans->setShow(Inkscape::SelTrans::SHOW_CONTENT); } } } @@ -286,25 +271,19 @@ sp_select_context_up_one_layer(SPDesktop *desktop) } gint SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - gint ret = FALSE; - SPDesktop *desktop = event_context->desktop; - SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); - Inkscape::SelTrans *seltrans = sc->_seltrans; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); // make sure we still have valid objects to move around - if (sc->item && sc->item->document == NULL) { - sp_select_context_abort(event_context); + if (this->item && this->item->document == NULL) { + sp_select_context_abort(this); } switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { + if (event->button.button == 1 && !this->space_panning) { /* Left mousebutton */ // save drag origin @@ -313,42 +292,45 @@ gint SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { within_tolerance = true; // remember what modifiers were on before button press - sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false; - sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false; - sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false; + this->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false; + this->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false; + this->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false; if (event->button.state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) { // if shift or ctrl was pressed, do not move objects; // pass the event to root handler which will perform rubberband, shift-click, ctrl-click, ctrl-drag } else { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); - sc->dragging = TRUE; - sc->moved = FALSE; + this->dragging = TRUE; + this->moved = FALSE; gdk_window_set_cursor(window, CursorSelectDragging); desktop->canvas->forceFullRedrawAfterInterruptions(5); - // remember the clicked item in sc->item: - if (sc->item) { - sp_object_unref(sc->item, NULL); - sc->item = NULL; + // remember the clicked item in this->item: + if (this->item) { + sp_object_unref(this->item, NULL); + this->item = NULL; } - sc->item = sp_event_context_find_item (desktop, + + this->item = sp_event_context_find_item (desktop, Geom::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, FALSE); - sp_object_ref(sc->item, NULL); + sp_object_ref(this->item, NULL); rb_escaped = drag_escaped = 0; - if (sc->grabbed) { - sp_canvas_item_ungrab(sc->grabbed, event->button.time); - sc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->drawing), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time); - sc->grabbed = SP_CANVAS_ITEM(desktop->drawing); + + this->grabbed = SP_CANVAS_ITEM(desktop->drawing); desktop->canvas->forceFullRedrawAfterInterruptions(5); @@ -356,43 +338,41 @@ gint SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { } } else if (event->button.button == 3) { // right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband - sp_select_context_abort(event_context); + sp_select_context_abort(this); } break; - case GDK_ENTER_NOTIFY: - { - if (!desktop->isWaitingCursor() && !sc->dragging) { + case GDK_ENTER_NOTIFY: { + if (!desktop->isWaitingCursor() && !this->dragging) { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectMouseover); } break; } - case GDK_LEAVE_NOTIFY: - if (!desktop->isWaitingCursor() && !sc->dragging) { + if (!desktop->isWaitingCursor() && !this->dragging) { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); - gdk_window_set_cursor(window, event_context->cursor); - } + gdk_window_set_cursor(window, this->cursor); + } break; case GDK_KEY_PRESS: if (get_group0_keyval (&event->key) == GDK_KEY_space) { - if (sc->dragging && sc->grabbed) { + if (this->dragging && this->grabbed) { /* stamping mode: show content mode moving */ - seltrans->stamp(); + _seltrans->stamp(); ret = TRUE; } } else if (get_group0_keyval (&event->key) == GDK_KEY_Tab) { - if (sc->dragging && sc->grabbed) { - seltrans->getNextClosestPoint(false); + if (this->dragging && this->grabbed) { + _seltrans->getNextClosestPoint(false); ret = TRUE; } } else if (get_group0_keyval (&event->key) == GDK_KEY_ISO_Left_Tab) { - if (sc->dragging && sc->grabbed) { - seltrans->getNextClosestPoint(true); + if (this->dragging && this->grabbed) { + _seltrans->getNextClosestPoint(true); ret = TRUE; } } @@ -403,8 +383,6 @@ gint SPSelectContext::item_handler(SPItem* item, GdkEvent* event) { } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler) -// ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler(event_context, item, event); ret = SPEventContext::item_handler(item, event); } @@ -451,21 +429,16 @@ sp_select_context_cycle_through_items(SPSelectContext *sc, Inkscape::Selection * } gint SPSelectContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - SPItem *item = NULL; SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL; gint ret = FALSE; - SPDesktop *desktop = event_context->desktop; - SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); - Inkscape::SelTrans *seltrans = sc->_seltrans; Inkscape::Selection *selection = sp_desktop_selection(desktop); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // make sure we still have valid objects to move around - if (sc->item && sc->item->document == NULL) { - sp_select_context_abort(event_context); + if (this->item && this->item->document == NULL) { + sp_select_context_abort(this); } switch (event->type) { @@ -473,11 +446,12 @@ gint SPSelectContext::root_handler(GdkEvent* event) { if (event->button.button == 1) { if (!selection->isEmpty()) { SPItem *clicked_item = static_cast<SPItem *>(selection->itemList()->data); + if (SP_IS_GROUP(clicked_item) && !SP_IS_BOX3D(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item)); sp_desktop_selection(desktop)->clear(); - sc->dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); + this->dragging = false; + sp_event_context_discard_delayed_snap_event(this); desktop->canvas->endForcedFullRedraws(); } else { // switch tool @@ -488,12 +462,13 @@ gint SPSelectContext::root_handler(GdkEvent* event) { } else { sp_select_context_up_one_layer(desktop); } + ret = TRUE; } break; - case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { + case GDK_BUTTON_PRESS: + if (event->button.button == 1 && !this->space_panning) { // save drag origin xp = (gint) event->button.x; yp = (gint) event->button.y; @@ -501,38 +476,44 @@ gint SPSelectContext::root_handler(GdkEvent* event) { Geom::Point const button_pt(event->button.x, event->button.y); Geom::Point const p(desktop->w2d(button_pt)); - if (event->button.state & GDK_MOD1_MASK) + + if (event->button.state & GDK_MOD1_MASK) { Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH); + } + Inkscape::Rubberband::get(desktop)->start(desktop, p); - if (sc->grabbed) { - sp_canvas_item_ungrab(sc->grabbed, event->button.time); - sc->grabbed = NULL; + + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - sc->grabbed = SP_CANVAS_ITEM(desktop->acetate); + + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); // remember what modifiers were on before button press - sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false; - sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false; - sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false; + this->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false; + this->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false; + this->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false; - sc->moved = FALSE; + this->moved = FALSE; rb_escaped = drag_escaped = 0; ret = TRUE; } else if (event->button.button == 3) { // right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband - sp_select_context_abort(event_context); + sp_select_context_abort(this); } break; - case GDK_MOTION_NOTIFY: - { + case GDK_MOTION_NOTIFY: { tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - if ((event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { + + if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { Geom::Point const motion_pt(event->motion.x, event->motion.y); Geom::Point const p(desktop->w2d(motion_pt)); @@ -546,73 +527,89 @@ gint SPSelectContext::root_handler(GdkEvent* event) { // motion notify coordinates as given (no snapping back to origin) within_tolerance = false; - if (sc->button_press_ctrl || (sc->button_press_alt && !sc->button_press_shift && !selection->isEmpty())) { + if (this->button_press_ctrl || (this->button_press_alt && !this->button_press_shift && !selection->isEmpty())) { // if it's not click and ctrl or alt was pressed (the latter with some selection // but not with shift) we want to drag rather than rubberband - sc->dragging = TRUE; - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + this->dragging = TRUE; + + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectDragging); desktop->canvas->forceFullRedrawAfterInterruptions(5); } - if (sc->dragging) { + if (this->dragging) { /* User has dragged fast, so we get events on root (lauris)*/ // not only that; we will end up here when ctrl-dragging as well // and also when we started within tolerance, but trespassed tolerance outside of item Inkscape::Rubberband::get(desktop)->stop(); - SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear(); + this->defaultMessageContext()->clear(); + item_at_point = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), FALSE); - if (!item_at_point) // if no item at this point, try at the click point (bug 1012200) + + if (!item_at_point) { // if no item at this point, try at the click point (bug 1012200) item_at_point = desktop->getItemAtPoint(Geom::Point(xp, yp), FALSE); - if (item_at_point || sc->moved || sc->button_press_alt) { + } + + if (item_at_point || this->moved || this->button_press_alt) { // drag only if starting from an item, or if something is already grabbed, or if alt-dragging - if (!sc->moved) { + if (!this->moved) { item_in_group = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE); group_at_point = desktop->getGroupAtPoint(Geom::Point(event->button.x, event->button.y)); - if (SP_IS_LAYER(selection->single())) + + if (SP_IS_LAYER(selection->single())) { group_at_point = SP_GROUP(selection->single()); + } // group-at-point is meant to be topmost item if it's a group, // not topmost group of all items at point if (group_at_point != item_in_group && !(group_at_point && item_at_point && - group_at_point->isAncestorOf(item_at_point))) + group_at_point->isAncestorOf(item_at_point))) { group_at_point = NULL; + } // if neither a group nor an item (possibly in a group) at point are selected, set selection to the item at point if ((!item_in_group || !selection->includes(item_in_group)) && (!group_at_point || !selection->includes(group_at_point)) - && !sc->button_press_alt) { + && !this->button_press_alt) { // select what is under cursor - if (!seltrans->isEmpty()) { - seltrans->resetState(); + if (!_seltrans->isEmpty()) { + _seltrans->resetState(); } + // when simply ctrl-dragging, we don't want to go into groups - if (item_at_point && !selection->includes(item_at_point)) + if (item_at_point && !selection->includes(item_at_point)) { selection->set(item_at_point); + } } // otherwise, do not change selection so that dragging selected-within-group items, as well as alt-dragging, is possible - seltrans->grab(p, -1, -1, FALSE, TRUE); - sc->moved = TRUE; + + _seltrans->grab(p, -1, -1, FALSE, TRUE); + this->moved = TRUE; } - if (!seltrans->isEmpty()) - seltrans->moveTo(p, event->button.state); + + if (!_seltrans->isEmpty()) { + _seltrans->moveTo(p, event->button.state); + } + desktop->scroll_to_point(p); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; } else { - sc->dragging = FALSE; - sp_event_context_discard_delayed_snap_event(event_context); + this->dragging = FALSE; + sp_event_context_discard_delayed_snap_event(this); desktop->canvas->endForcedFullRedraws(); } } else { if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->move(p); + if (Inkscape::Rubberband::get(desktop)->getMode() == RUBBERBAND_MODE_TOUCHPATH) { - event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> objects to select them; release <b>Alt</b> to switch to rubberband selection")); + this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> objects to select them; release <b>Alt</b> to switch to rubberband selection")); } else { - event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag around</b> objects to select them; press <b>Alt</b> to switch to touch selection")); + this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag around</b> objects to select them; press <b>Alt</b> to switch to touch selection")); } + gobble_motion_events(GDK_BUTTON1_MASK); } } @@ -621,55 +618,61 @@ gint SPSelectContext::root_handler(GdkEvent* event) { } case GDK_BUTTON_RELEASE: xp = yp = 0; - if ((event->button.button == 1) && (sc->grabbed) && !event_context->space_panning) { - if (sc->dragging) { + + if ((event->button.button == 1) && (this->grabbed) && !this->space_panning) { + if (this->dragging) { GdkWindow* window; - if (sc->moved) { + + if (this->moved) { // item has been moved - seltrans->ungrab(); - sc->moved = FALSE; + _seltrans->ungrab(); + this->moved = FALSE; #ifdef WITH_DBUS - dbus_send_ping(desktop, sc->item); + dbus_send_ping(desktop, this->item); #endif - } else if (sc->item && !drag_escaped) { + } else if (this->item && !drag_escaped) { // item has not been moved -> simply a click, do selecting if (!selection->isEmpty()) { if (event->button.state & GDK_SHIFT_MASK) { // with shift, toggle selection - seltrans->resetState(); - selection->toggle(sc->item); + _seltrans->resetState(); + selection->toggle(this->item); } else { SPObject* single = selection->single(); // without shift, increase state (i.e. toggle scale/rotation handles) - if (selection->includes(sc->item)) { - seltrans->increaseState(); - } else if (SP_IS_LAYER(single) && single->isAncestorOf(sc->item)) { - seltrans->increaseState(); + if (selection->includes(this->item)) { + _seltrans->increaseState(); + } else if (SP_IS_LAYER(single) && single->isAncestorOf(this->item)) { + _seltrans->increaseState(); } else { - seltrans->resetState(); - selection->set(sc->item); + _seltrans->resetState(); + selection->set(this->item); } } } else { // simple or shift click, no previous selection - seltrans->resetState(); - selection->set(sc->item); + _seltrans->resetState(); + selection->set(this->item); } } - sc->dragging = FALSE; - window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + + this->dragging = FALSE; + window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectMouseover); - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); desktop->canvas->endForcedFullRedraws(); - if (sc->item) { - sp_object_unref( sc->item, NULL); + if (this->item) { + sp_object_unref( this->item, NULL); } - sc->item = NULL; + + this->item = NULL; } else { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); + if (r->is_started() && !within_tolerance) { // this was a rubberband drag GSList *items = NULL; + if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); items = sp_desktop_document(desktop)->getItemsInBox(desktop->dkey, *b); @@ -677,9 +680,9 @@ gint SPSelectContext::root_handler(GdkEvent* event) { items = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, r->getPoints()); } - seltrans->resetState(); + _seltrans->resetState(); r->stop(); - SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear(); + this->defaultMessageContext()->clear(); if (event->button.state & GDK_SHIFT_MASK) { // with shift, add to selection @@ -688,19 +691,20 @@ gint SPSelectContext::root_handler(GdkEvent* event) { // without shift, simply select anew selection->setList (items); } + g_slist_free (items); } else { // it was just a click, or a too small rubberband r->stop(); - if (sc->button_press_shift && !rb_escaped && !drag_escaped) { - // this was a shift+click or alt+shift+click, select what was clicked upon - sc->button_press_shift = false; + if (this->button_press_shift && !rb_escaped && !drag_escaped) { + // this was a shift+click or alt+shift+click, select what was clicked upon + this->button_press_shift = false; - if (sc->button_press_ctrl) { + if (this->button_press_ctrl) { // go into groups, honoring Alt item = sp_event_context_find_item (desktop, Geom::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, TRUE); - sc->button_press_ctrl = FALSE; + this->button_press_ctrl = FALSE; } else { // don't go into groups, honoring Alt item = sp_event_context_find_item (desktop, @@ -712,53 +716,56 @@ gint SPSelectContext::root_handler(GdkEvent* event) { item = NULL; } - } else if ((sc->button_press_ctrl || sc->button_press_alt) && !rb_escaped && !drag_escaped) { // ctrl+click, alt+click - + } else if ((this->button_press_ctrl || this->button_press_alt) && !rb_escaped && !drag_escaped) { // ctrl+click, alt+click item = sp_event_context_find_item (desktop, - Geom::Point(event->button.x, event->button.y), sc->button_press_alt, sc->button_press_ctrl); + Geom::Point(event->button.x, event->button.y), this->button_press_alt, this->button_press_ctrl); - sc->button_press_ctrl = FALSE; - sc->button_press_alt = FALSE; + this->button_press_ctrl = FALSE; + this->button_press_alt = FALSE; if (item) { if (selection->includes(item)) { - seltrans->increaseState(); + _seltrans->increaseState(); } else { - seltrans->resetState(); + _seltrans->resetState(); selection->set(item); } + item = NULL; } - } else { // click without shift, simply deselect, unless with Alt or something was cancelled if (!selection->isEmpty()) { - if (!(rb_escaped) && !(drag_escaped) && !(event->button.state & GDK_MOD1_MASK)) + if (!(rb_escaped) && !(drag_escaped) && !(event->button.state & GDK_MOD1_MASK)) { selection->clear(); + } + rb_escaped = 0; ret = TRUE; } } } + ret = TRUE; } - if (sc->grabbed) { - sp_canvas_item_ungrab(sc->grabbed, event->button.time); - sc->grabbed = NULL; + + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } desktop->updateNow(); } + if (event->button.button == 1) { Inkscape::Rubberband::get(desktop)->stop(); // might have been started in another tool! } - sc->button_press_shift = false; - sc->button_press_ctrl = false; - sc->button_press_alt = false; + + this->button_press_shift = false; + this->button_press_ctrl = false; + this->button_press_alt = false; break; - case GDK_SCROLL: - { - SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); + case GDK_SCROLL: { GdkEventScroll *scroll_event = (GdkEventScroll*) event; if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed @@ -769,21 +776,22 @@ gint SPSelectContext::root_handler(GdkEvent* event) { SPItem *item = desktop->getItemAtPoint(p, true, NULL); // Save pointer to current cycle-item so that we can find it again later, in the freshly built list - SPItem *tmp_cur_item = sc->cycling_cur_item ? SP_ITEM(sc->cycling_cur_item->data) : NULL; - g_list_free(sc->cycling_items); - sc->cycling_items = NULL; - sc->cycling_cur_item = NULL; + SPItem *tmp_cur_item = this->cycling_cur_item ? SP_ITEM(this->cycling_cur_item->data) : NULL; + g_list_free(this->cycling_items); + this->cycling_items = NULL; + this->cycling_cur_item = NULL; while(item != NULL) { - sc->cycling_items = g_list_append(sc->cycling_items, item); + this->cycling_items = g_list_append(this->cycling_items, item); item = desktop->getItemAtPoint(p, true, item); } /* Compare current item list with item list during previous scroll ... */ GList *l1, *l2; bool item_lists_differ = false; + // Note that we can do an 'or' comparison in the loop because it is safe to call g_list_next with a NULL pointer. - for (l1 = sc->cycling_items, l2 = sc->cycling_items_cmp; l1 != NULL || l2 != NULL; l1 = g_list_next(l1), l2 = g_list_next(l2)) { + for (l1 = this->cycling_items, l2 = this->cycling_items_cmp; l1 != NULL || l2 != NULL; l1 = g_list_next(l1), l2 = g_list_next(l2)) { if ((l1 !=NULL && l2 == NULL) || (l1 == NULL && l2 != NULL) || (l1->data != l2->data)) { item_lists_differ = true; break; @@ -794,47 +802,52 @@ gint SPSelectContext::root_handler(GdkEvent* event) { if (!item_lists_differ) { // ... find current item in the freshly built list and continue cycling ... // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead - sc->cycling_cur_item = g_list_find(sc->cycling_items, tmp_cur_item); - g_assert(sc->cycling_cur_item != NULL || sc->cycling_items == NULL); + this->cycling_cur_item = g_list_find(this->cycling_items, tmp_cur_item); + g_assert(this->cycling_cur_item != NULL || this->cycling_items == NULL); } else { // ... otherwise reset opacities for outdated items ... Inkscape::DrawingItem *arenaitem; - for(GList *l = sc->cycling_items_cmp; l != NULL; l = l->next) { + + for(GList *l = this->cycling_items_cmp; l != NULL; l = l->next) { arenaitem = SP_ITEM(l->data)->get_arenaitem(desktop->dkey); arenaitem->setOpacity(1.0); - //if (!shift_pressed && !g_list_find(sc->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data))) - if (!g_list_find(sc->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data))) + //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data))) + if (!g_list_find(this->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data))) { selection->remove(SP_ITEM(l->data)); + } } // ... clear the lists ... - g_list_free(sc->cycling_items_cmp); - g_list_free(sc->cycling_items_selected_before); - sc->cycling_items_cmp = NULL; - sc->cycling_items_selected_before = NULL; - sc->cycling_cur_item = NULL; + g_list_free(this->cycling_items_cmp); + g_list_free(this->cycling_items_selected_before); + + this->cycling_items_cmp = NULL; + this->cycling_items_selected_before = NULL; + this->cycling_cur_item = NULL; // ... and rebuild them with the new items. - sc->cycling_items_cmp = g_list_copy(sc->cycling_items); + this->cycling_items_cmp = g_list_copy(this->cycling_items); SPItem *item; - for(GList *l = sc->cycling_items; l != NULL; l = l->next) { + + for(GList *l = this->cycling_items; l != NULL; l = l->next) { item = SP_ITEM(l->data); arenaitem = item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(0.3); + if (selection->includes(item)) { // already selected items are stored separately, too - sc->cycling_items_selected_before = g_list_append(sc->cycling_items_selected_before, item); + this->cycling_items_selected_before = g_list_append(this->cycling_items_selected_before, item); } } // set the current item to the bottommost one so that the cycling step below re-starts at the top - sc->cycling_cur_item = g_list_last(sc->cycling_items); + this->cycling_cur_item = g_list_last(this->cycling_items); } - sc->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); + this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); // Cycle through the items underneath the mouse pointer, one-by-one - sp_select_context_cycle_through_items(sc, selection, scroll_event, shift_pressed); + sp_select_context_cycle_through_items(this, selection, scroll_event, shift_pressed); ret = TRUE; } @@ -846,6 +859,7 @@ gint SPSelectContext::root_handler(GdkEvent* event) { { { guint keyval = get_group0_keyval(&event->key); + bool alt = ( MOD__ALT || (keyval == GDK_KEY_Alt_L) || (keyval == GDK_KEY_Alt_R) @@ -853,8 +867,8 @@ gint SPSelectContext::root_handler(GdkEvent* event) { || (keyval == GDK_KEY_Meta_R)); if (!key_is_a_modifier (keyval)) { - event_context->defaultMessageContext()->clear(); - } else if (sc->grabbed || seltrans->isGrabbed()) { + this->defaultMessageContext()->clear(); + } else if (this->grabbed || _seltrans->isGrabbed()) { if (Inkscape::Rubberband::get(desktop)->is_started()) { // if Alt then change cursor to moving cursor: if (alt) { @@ -866,13 +880,14 @@ gint SPSelectContext::root_handler(GdkEvent* event) { break; } } else { - sp_event_show_modifier_tip (event_context->defaultMessageContext(), event, + sp_event_show_modifier_tip (this->defaultMessageContext(), event, _("<b>Ctrl</b>: click to select in groups; drag to move hor/vert"), _("<b>Shift</b>: click to toggle select; drag for rubberband selection"), _("<b>Alt</b>: click to select under; scroll mouse-wheel to cycle-select; drag to move selected or select by touch")); + // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (sp_desktop_canvas(desktop))); gdk_window_set_cursor(window, CursorSelectDragging); } //*/ @@ -888,70 +903,100 @@ gint SPSelectContext::root_handler(GdkEvent* event) { case GDK_KEY_Left: // move selection left case GDK_KEY_KP_Left: if (!MOD__CTRL) { // not ctrl - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) sp_selection_move_screen(desktop, mul*-10, 0); // shift - else sp_selection_move_screen(desktop, mul*-1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT) sp_selection_move(desktop, mul*-10*nudge, 0); // shift - else sp_selection_move(desktop, mul*-nudge, 0); // no shift + if (MOD__SHIFT) { + sp_selection_move_screen(desktop, mul*-10, 0); // shift + } else { + sp_selection_move_screen(desktop, mul*-1, 0); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + sp_selection_move(desktop, mul*-10*nudge, 0); // shift + } else { + sp_selection_move(desktop, mul*-nudge, 0); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Up: // move selection up case GDK_KEY_KP_Up: if (!MOD__CTRL) { // not ctrl - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) sp_selection_move_screen(desktop, 0, mul*10); // shift - else sp_selection_move_screen(desktop, 0, mul*1); // no shift - } - else { // no alt - if (MOD__SHIFT) sp_selection_move(desktop, 0, mul*10*nudge); // shift - else sp_selection_move(desktop, 0, mul*nudge); // no shift + if (MOD__SHIFT) { + sp_selection_move_screen(desktop, 0, mul*10); // shift + } else { + sp_selection_move_screen(desktop, 0, mul*1); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + sp_selection_move(desktop, 0, mul*10*nudge); // shift + } else { + sp_selection_move(desktop, 0, mul*nudge); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Right: // move selection right case GDK_KEY_KP_Right: if (!MOD__CTRL) { // not ctrl - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) sp_selection_move_screen(desktop, mul*10, 0); // shift - else sp_selection_move_screen(desktop, mul*1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT) sp_selection_move(desktop, mul*10*nudge, 0); // shift - else sp_selection_move(desktop, mul*nudge, 0); // no shift + if (MOD__SHIFT) { + sp_selection_move_screen(desktop, mul*10, 0); // shift + } else { + sp_selection_move_screen(desktop, mul*1, 0); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + sp_selection_move(desktop, mul*10*nudge, 0); // shift + } else { + sp_selection_move(desktop, mul*nudge, 0); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Down: // move selection down case GDK_KEY_KP_Down: if (!MOD__CTRL) { // not ctrl - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask + if (MOD__ALT) { // alt - if (MOD__SHIFT) sp_selection_move_screen(desktop, 0, mul*-10); // shift - else sp_selection_move_screen(desktop, 0, mul*-1); // no shift - } - else { // no alt - if (MOD__SHIFT) sp_selection_move(desktop, 0, mul*-10*nudge); // shift - else sp_selection_move(desktop, 0, mul*-nudge); // no shift + if (MOD__SHIFT) { + sp_selection_move_screen(desktop, 0, mul*-10); // shift + } else { + sp_selection_move_screen(desktop, 0, mul*-1); // no shift + } + } else { // no alt + if (MOD__SHIFT) { + sp_selection_move(desktop, 0, mul*-10*nudge); // shift + } else { + sp_selection_move(desktop, 0, mul*-nudge); // no shift + } } + ret = TRUE; } break; + case GDK_KEY_Escape: - if (!sp_select_context_abort(event_context)) + if (!sp_select_context_abort(this)) { selection->clear(); + } + ret = TRUE; break; @@ -962,14 +1007,16 @@ gint SPSelectContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_space: /* stamping mode: show outline mode moving */ /* FIXME: Is next condition ok? (lauris) */ - if (sc->dragging && sc->grabbed) { - seltrans->stamp(); + if (this->dragging && this->grabbed) { + _seltrans->stamp(); ret = TRUE; } break; + case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY) { @@ -977,90 +1024,98 @@ gint SPSelectContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_bracketleft: if (MOD__ALT) { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_rotate_screen(selection, mul*1); } else if (MOD__CTRL) { sp_selection_rotate(selection, 90); } else if (snaps) { sp_selection_rotate(selection, 180.0/snaps); } + ret = TRUE; break; + case GDK_KEY_bracketright: if (MOD__ALT) { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_rotate_screen(selection, -1*mul); } else if (MOD__CTRL) { sp_selection_rotate(selection, -90); } else if (snaps) { sp_selection_rotate(selection, -180.0/snaps); } + ret = TRUE; break; + case GDK_KEY_less: case GDK_KEY_comma: if (MOD__ALT) { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale_screen(selection, -2*mul); } else if (MOD__CTRL) { sp_selection_scale_times(selection, 0.5); } else { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale(selection, -offset*mul); } + ret = TRUE; break; + case GDK_KEY_greater: case GDK_KEY_period: if (MOD__ALT) { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale_screen(selection, 2*mul); } else if (MOD__CTRL) { sp_selection_scale_times(selection, 2); } else { - gint mul = 1 + gobble_key_events( - get_group0_keyval(&event->key), 0); // with any mask + gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale(selection, offset*mul); } + ret = TRUE; break; + case GDK_KEY_Return: if (MOD__CTRL_ONLY) { if (selection->singleItem()) { SPItem *clicked_item = selection->singleItem(); - if ( SP_IS_GROUP(clicked_item) || - SP_IS_BOX3D(clicked_item)) { // enter group or a 3D box + + if ( SP_IS_GROUP(clicked_item) || SP_IS_BOX3D(clicked_item)) { // enter group or a 3D box desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item)); sp_desktop_selection(desktop)->clear(); } else { - SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter.")); + this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter.")); } } + ret = TRUE; } break; + case GDK_KEY_BackSpace: if (MOD__CTRL_ONLY) { sp_select_context_up_one_layer(desktop); ret = TRUE; } break; + case GDK_KEY_s: case GDK_KEY_S: if (MOD__SHIFT_ONLY) { if (!selection->isEmpty()) { - seltrans->increaseState(); + _seltrans->increaseState(); } + ret = TRUE; } break; + case GDK_KEY_g: case GDK_KEY_G: if (MOD__SHIFT_ONLY) { @@ -1068,17 +1123,18 @@ gint SPSelectContext::root_handler(GdkEvent* event) { ret = true; } break; + default: break; } break; } - case GDK_KEY_RELEASE: - { + case GDK_KEY_RELEASE: { guint keyval = get_group0_keyval(&event->key); - if (key_is_a_modifier (keyval)) - event_context->defaultMessageContext()->clear(); - + if (key_is_a_modifier (keyval)) { + this->defaultMessageContext()->clear(); + } + bool alt = ( MOD__ALT || (keyval == GDK_KEY_Alt_L) || (keyval == GDK_KEY_Alt_R) @@ -1093,19 +1149,21 @@ gint SPSelectContext::root_handler(GdkEvent* event) { } else { if (alt) { // TODO: Should we have a variable like is_cycling or is it harmless to run this piece of code each time? // quit cycle-selection and reset opacities - SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); Inkscape::DrawingItem *arenaitem; - for (GList *l = sc->cycling_items; l != NULL; l = g_list_next(l)) { + + for (GList *l = this->cycling_items; l != NULL; l = g_list_next(l)) { arenaitem = SP_ITEM(l->data)->get_arenaitem(desktop->dkey); arenaitem->setOpacity(1.0); } - g_list_free(sc->cycling_items); - g_list_free(sc->cycling_items_selected_before); - g_list_free(sc->cycling_items_cmp); - sc->cycling_items = NULL; - sc->cycling_items_selected_before = NULL; - sc->cycling_cur_item = NULL; - sc->cycling_items_cmp = NULL; + + g_list_free(this->cycling_items); + g_list_free(this->cycling_items_selected_before); + g_list_free(this->cycling_items_cmp); + + this->cycling_items = NULL; + this->cycling_items_selected_before = NULL; + this->cycling_cur_item = NULL; + this->cycling_items_cmp = NULL; } } @@ -1117,13 +1175,12 @@ gint SPSelectContext::root_handler(GdkEvent* event) { //gdk_window_set_cursor(window, event_context->cursor); } break; + default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler) -// ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler(event_context, event); ret = SPEventContext::root_handler(event); } diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 6df7a4036..f9c5c3a17 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -46,10 +46,6 @@ using Inkscape::DocumentUndo; -static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint state); -static void sp_spiral_finish(SPSpiralContext *sc); -static void sp_spiral_cancel(SPSpiralContext *sc); - #include "tool-factory.h" namespace { @@ -67,157 +63,129 @@ const std::string& SPSpiralContext::getPrefsPath() { const std::string SPSpiralContext::prefsPath = "/tools/shapes/spiral"; SPSpiralContext::SPSpiralContext() : SPEventContext() { - SPSpiralContext* spiral_context = this; - - spiral_context->_message_context = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(spiral_context); - - event_context->cursor_shape = cursor_spiral_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 0; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; - - spiral_context->item = NULL; - - spiral_context->revo = 3.0; - spiral_context->exp = 1.0; - spiral_context->t0 = 0.0; - - //new (&spiral_context->sel_changed_connection) sigc::connection(); + this->_message_context = 0; + + this->cursor_shape = cursor_spiral_xpm; + this->hot_x = 4; + this->hot_y = 4; + this->xp = 0; + this->yp = 0; + this->tolerance = 0; + this->within_tolerance = false; + this->item_to_select = NULL; + + this->spiral = NULL; + + this->revo = 3.0; + this->exp = 1.0; + this->t0 = 0.0; } void SPSpiralContext::finish() { - SPEventContext* ec = this; - - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; + SPDesktop *desktop = this->desktop; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); - sp_spiral_finish(sc); - sc->sel_changed_connection.disconnect(); -// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish) { -// (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish(ec); -// } + this->finishItem(); + this->sel_changed_connection.disconnect(); + SPEventContext::finish(); } SPSpiralContext::~SPSpiralContext() { - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); - - ec->enableGrDrag(false); + this->enableGrDrag(false); - sc->sel_changed_connection.disconnect(); - //sc->sel_changed_connection.~connection(); + this->sel_changed_connection.disconnect(); - delete ec->shape_editor; - ec->shape_editor = NULL; + delete this->shape_editor; + this->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ - if (sc->item) sp_spiral_finish(sc); - - if (sc->_message_context) { - delete sc->_message_context; + if (this->spiral) { + this->finishItem(); } - //G_OBJECT_CLASS(sp_spiral_context_parent_class)->dispose(object); + if (this->_message_context) { + delete this->_message_context; + } } /** * Callback that processes the "changed" signal on the selection; * destroys old and creates new knotholder. */ -static void sp_spiral_context_selection_changed(Inkscape::Selection *selection, gpointer data) -{ - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(data); - SPEventContext *ec = SP_EVENT_CONTEXT(sc); - - ec->shape_editor->unset_item(SH_KNOTHOLDER); - SPItem *item = selection->singleItem(); - ec->shape_editor->set_item(item, SH_KNOTHOLDER); +void SPSpiralContext::selection_changed(Inkscape::Selection *selection) { + this->shape_editor->unset_item(SH_KNOTHOLDER); + this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); } void SPSpiralContext::setup() { - SPEventContext* ec = this; - - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup) -// (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup(ec); SPEventContext::setup(); - sp_event_context_read(ec, "expansion"); - sp_event_context_read(ec, "revolution"); - sp_event_context_read(ec, "t0"); + sp_event_context_read(this, "expansion"); + sp_event_context_read(this, "revolution"); + sp_event_context_read(this, "t0"); - ec->shape_editor = new ShapeEditor(ec->desktop); + this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item, SH_KNOTHOLDER); } - Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); - sc->sel_changed_connection.disconnect(); - sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_spiral_context_selection_changed), (gpointer)sc)); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); + this->sel_changed_connection.disconnect(); + + this->sel_changed_connection = selection->connectChanged(sigc::mem_fun(this, &SPSpiralContext::selection_changed)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/shapes/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } + if (prefs->getBool("/tools/shapes/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } - sc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } void SPSpiralContext::set(Inkscape::Preferences::Entry* val) { - SPEventContext* ec = this; - - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); Glib::ustring name = val->getEntryName(); if (name == "expansion") { - sc->exp = CLAMP(val->getDouble(), 0.0, 1000.0); + this->exp = CLAMP(val->getDouble(), 0.0, 1000.0); } else if (name == "revolution") { - sc->revo = CLAMP(val->getDouble(3.0), 0.05, 40.0); + this->revo = CLAMP(val->getDouble(3.0), 0.05, 40.0); } else if (name == "t0") { - sc->t0 = CLAMP(val->getDouble(), 0.0, 0.999); + this->t0 = CLAMP(val->getDouble(), 0.0, 0.999); } } gint SPSpiralContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static gboolean dragging; - SPDesktop *desktop = event_context->desktop; + SPDesktop *desktop = this->desktop; Inkscape::Selection *selection = sp_desktop_selection (desktop); - SPSpiralContext *sc = SP_SPIRAL_CONTEXT(event_context); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - + if (event->button.button == 1 && !this->space_panning) { dragging = TRUE; - sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event); + + this->center = Inkscape::setup_for_drag_start(desktop, this, event); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); - m.freeSnapReturnByRef(sc->center, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.freeSnapReturnByRef(this->center, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -228,32 +196,33 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { ret = TRUE; } break; - case GDK_MOTION_NOTIFY: - if (dragging && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { - if ( event_context->within_tolerance - && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) - && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) { + case GDK_MOTION_NOTIFY: + if (dragging && (event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { + if ( this->within_tolerance + && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance ) + && ( abs( (gint) event->motion.y - this->yp ) < this->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 draw, not click), then always process the // motion notify coordinates as given (no snapping back to origin) - event_context->within_tolerance = false; + this->within_tolerance = false; Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point motion_dt(event_context->desktop->w2d(motion_w)); + Geom::Point motion_dt(this->desktop->w2d(motion_w)); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, true, sc->item); + m.setup(desktop, true, this->spiral); m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - sp_spiral_drag(sc, motion_dt, event->motion.state); + + this->drag(motion_dt, event->motion.state); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(sc)) { + } else if (!sp_event_context_knot_mouseover(this)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Geom::Point const motion_w(event->motion.x, event->motion.y); @@ -262,31 +231,34 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { m.unSetup(); } break; + case GDK_BUTTON_RELEASE: - event_context->xp = event_context->yp = 0; - if (event->button.button == 1 && !event_context->space_panning) { + this->xp = this->yp = 0; + if (event->button.button == 1 && !this->space_panning) { dragging = FALSE; - sp_event_context_discard_delayed_snap_event(event_context); - if (!event_context->within_tolerance) { + sp_event_context_discard_delayed_snap_event(this); + + if (!this->within_tolerance) { // we've been dragging, finish the spiral - sp_spiral_finish(sc); - } else if (event_context->item_to_select) { + this->finishItem(); + } else if (this->item_to_select) { // no dragging, select clicked item if any if (event->button.state & GDK_SHIFT_MASK) { - selection->toggle(event_context->item_to_select); + selection->toggle(this->item_to_select); } else { - selection->set(event_context->item_to_select); + selection->set(this->item_to_select); } } else { // click in an empty space selection->clear(); } - event_context->item_to_select = NULL; + this->item_to_select = NULL; ret = TRUE; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); } break; + case GDK_KEY_PRESS: switch (get_group0_keyval(&event->key)) { case GDK_KEY_Alt_R: @@ -296,7 +268,7 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_R: case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt (at least on my machine) case GDK_KEY_Meta_R: - sp_event_show_modifier_tip(event_context->defaultMessageContext(), event, + sp_event_show_modifier_tip(this->defaultMessageContext(), event, _("<b>Ctrl</b>: snap angle"), NULL, _("<b>Alt</b>: lock spiral radius")); @@ -309,6 +281,7 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { if (!MOD__CTRL_ONLY) ret = TRUE; break; + case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY) { @@ -316,12 +289,13 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Escape: if (dragging) { dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); // if drawing, cancel, otherwise pass it up for deselecting - sp_spiral_cancel(sc); + this->cancel(); ret = TRUE; } break; @@ -331,24 +305,27 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); - if (!event_context->within_tolerance) { + sp_event_context_discard_delayed_snap_event(this); + + if (!this->within_tolerance) { // we've been dragging, finish the spiral - sp_spiral_finish(sc); + this->finish(); } // do not return true, so that space would work switching to selector } break; + case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; default: break; } break; + case GDK_KEY_RELEASE: switch (get_group0_keyval(&event->key)) { case GDK_KEY_Alt_L: @@ -359,63 +336,61 @@ gint SPSpiralContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_R: case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt case GDK_KEY_Meta_R: - event_context->defaultMessageContext()->clear(); + this->defaultMessageContext()->clear(); break; + default: break; } break; + default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler) -// ret = (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler(event_context, event); ret = SPEventContext::root_handler(event); } return ret; } -static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint state) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; +void SPSpiralContext::drag(Geom::Point const &p, guint state) { + SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); - if (!sc->item) { - - if (Inkscape::have_viable_layer(desktop, sc->_message_context) == false) { + if (!this->spiral) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return; } // Create object - Inkscape::XML::Document *xml_doc = SP_EVENT_CONTEXT_DOCUMENT(sc)->getReprDoc(); + Inkscape::XML::Document *xml_doc = SP_EVENT_CONTEXT_DOCUMENT(this)->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); repr->setAttribute("sodipodi:type", "spiral"); // Set style sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/spiral", false); - sc->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + this->spiral = SP_SPIRAL(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); - sc->item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); - sc->item->updateRepr(); + this->spiral->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + this->spiral->updateRepr(); desktop->canvas->forceFullRedrawAfterInterruptions(5); } SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, true, sc->item); + m.setup(desktop, true, this->spiral); Geom::Point pt2g = p; m.freeSnapReturnByRef(pt2g, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - Geom::Point const p0 = desktop->dt2doc(sc->center); + Geom::Point const p0 = desktop->dt2doc(this->center); Geom::Point const p1 = desktop->dt2doc(pt2g); - SPSpiral *spiral = SP_SPIRAL(sc->item); + SPSpiral *spiral = SP_SPIRAL(this->spiral); Geom::Point const delta = p1 - p0; gdouble const rad = Geom::L2(delta); @@ -428,66 +403,57 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat /* Fixme: these parameters should be got from dialog box */ spiral->setPosition(p0[Geom::X], p0[Geom::Y], - /*expansion*/ sc->exp, - /*revolution*/ sc->revo, + /*expansion*/ this->exp, + /*revolution*/ this->revo, rad, arg, - /*t0*/ sc->t0); + /*t0*/ this->t0); /* status text */ GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric()); - sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, + this->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Spiral</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle"), rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001)); g_string_free(rads, FALSE); } -static void -sp_spiral_finish(SPSpiralContext *sc) -{ - sc->_message_context->clear(); +void SPSpiralContext::finishItem() { + this->_message_context->clear(); - if (sc->item != NULL) { - SPSpiral *spiral = SP_SPIRAL(sc->item); - if (spiral->rad == 0) { - sp_spiral_cancel(sc); // Don't allow the creating of zero sized spiral, for example when the start and and point snap to the snap grid point + if (this->spiral != NULL) { + if (this->spiral->rad == 0) { + this->cancel(); // Don't allow the creating of zero sized spiral, for example when the start and and point snap to the snap grid point return; } - SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; + spiral->set_shape(); + spiral->updateRepr(SP_OBJECT_WRITE_EXT); - SP_SHAPE(spiral)->set_shape(); - SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT); + this->desktop->canvas->endForcedFullRedraws(); - desktop->canvas->endForcedFullRedraws(); + sp_desktop_selection(this->desktop)->set(this->spiral); + DocumentUndo::done(sp_desktop_document(this->desktop), SP_VERB_CONTEXT_SPIRAL, _("Create spiral")); - sp_desktop_selection(desktop)->set(sc->item); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SPIRAL, - _("Create spiral")); - - sc->item = NULL; + this->spiral = NULL; } } -static void sp_spiral_cancel(SPSpiralContext *sc) -{ - SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; - - sp_desktop_selection(desktop)->clear(); - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); +void SPSpiralContext::cancel() { + sp_desktop_selection(this->desktop)->clear(); + sp_canvas_item_ungrab(SP_CANVAS_ITEM(this->desktop->acetate), 0); - if (sc->item != NULL) { - SP_OBJECT(sc->item)->deleteObject(); - sc->item = NULL; + if (this->spiral != NULL) { + this->spiral->deleteObject(); + this->spiral = NULL; } - sc->within_tolerance = false; - sc->xp = 0; - sc->yp = 0; - sc->item_to_select = NULL; + this->within_tolerance = false; + this->xp = 0; + this->yp = 0; + this->item_to_select = NULL; - desktop->canvas->endForcedFullRedraws(); + this->desktop->canvas->endForcedFullRedraws(); - DocumentUndo::cancel(sp_desktop_document(desktop)); + DocumentUndo::cancel(sp_desktop_document(this->desktop)); } /* diff --git a/src/spiral-context.h b/src/spiral-context.h index c7cc0b1b1..65a10dd04 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -21,6 +21,8 @@ #include <2geom/point.h> #include "event-context.h" +#include "sp-spiral.h" + #define SP_SPIRAL_CONTEXT(obj) ((SPSpiralContext*)obj) #define SP_IS_SPIRAL_CONTEXT(obj) (dynamic_cast<const SPSpiralContext*>((const SPEventContext*)obj)) @@ -29,7 +31,17 @@ public: SPSpiralContext(); virtual ~SPSpiralContext(); - SPItem * item; + static const std::string prefsPath; + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + + virtual const std::string& getPrefsPath(); + +private: + SPSpiral * spiral; Geom::Point center; gdouble revo; gdouble exp; @@ -39,14 +51,10 @@ public: Inkscape::MessageContext *_message_context; - static const std::string prefsPath; - - virtual void setup(); - virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); - virtual gint root_handler(GdkEvent* event); - - virtual const std::string& getPrefsPath(); + void drag(Geom::Point const &p, guint state); + void finishItem(); + void cancel(); + void selection_changed(Inkscape::Selection *selection); }; #endif diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index d6d5ccd47..990a62000 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -98,59 +98,47 @@ const std::string& SPTweakContext::getPrefsPath() { const std::string SPTweakContext::prefsPath = "/tools/tweak"; SPTweakContext::SPTweakContext() : SPEventContext() { - SPTweakContext* tc = this; - - tc->_message_context = 0; - tc->mode = 0; - tc->dilate_area = 0; - tc->usetilt = 0; - tc->usepressure = 0; - tc->is_drawing = false; - tc->fidelity = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(tc); - - event_context->cursor_shape = cursor_push_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; + this->_message_context = 0; + this->mode = 0; + this->dilate_area = 0; + this->usetilt = 0; + this->usepressure = 0; + this->is_drawing = false; + this->fidelity = 0; + + this->cursor_shape = cursor_push_xpm; + this->hot_x = 4; + this->hot_y = 4; /* attributes */ - tc->dragging = FALSE; + this->dragging = FALSE; - tc->width = 0.2; - tc->force = 0.2; - tc->pressure = TC_DEFAULT_PRESSURE; + this->width = 0.2; + this->force = 0.2; + this->pressure = TC_DEFAULT_PRESSURE; - tc->is_dilating = false; - tc->has_dilated = false; + this->is_dilating = false; + this->has_dilated = false; - tc->do_h = true; - tc->do_s = true; - tc->do_l = true; - tc->do_o = false; - - //new (&tc->style_set_connection) sigc::connection(); + this->do_h = true; + this->do_s = true; + this->do_l = true; + this->do_o = false; } SPTweakContext::~SPTweakContext() { - SPTweakContext *tc = SP_TWEAK_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); - - ec->enableGrDrag(false); + this->enableGrDrag(false); - tc->style_set_connection.disconnect(); - //tc->style_set_connection.~connection(); + this->style_set_connection.disconnect(); - if (tc->dilate_area) { - sp_canvas_item_destroy(tc->dilate_area); - tc->dilate_area = NULL; + if (this->dilate_area) { + sp_canvas_item_destroy(this->dilate_area); + this->dilate_area = NULL; } - if (tc->_message_context) { - delete tc->_message_context; + if (this->_message_context) { + delete this->_message_context; } - - //G_OBJECT_CLASS(sp_tweak_context_parent_class)->dispose(object); } static bool is_transform_mode (gint mode) @@ -249,27 +237,19 @@ sp_tweak_update_cursor (SPTweakContext *tc, bool with_shift) g_free(sel_message); } -static bool -sp_tweak_context_style_set(SPCSSAttr const *css, SPTweakContext *tc) -{ - if (tc->mode == TWEAK_MODE_COLORPAINT) { // intercept color setting only in this mode +bool SPTweakContext::set_style(const SPCSSAttr* css) { + if (this->mode == TWEAK_MODE_COLORPAINT) { // intercept color setting only in this mode // we cannot store properties with uris - css = sp_css_attr_unset_uris (const_cast<SPCSSAttr *>(css)); + css = sp_css_attr_unset_uris(const_cast<SPCSSAttr *>(css)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setStyle("/tools/tweak/style", const_cast<SPCSSAttr*>(css)); + prefs->setStyle("/tools/tweak/style", const_cast<SPCSSAttr *>(css)); return true; } + return false; } void SPTweakContext::setup() { - SPEventContext* ec = this; - - SPTweakContext *tc = SP_TWEAK_CONTEXT(ec); - -// if ((SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->setup(ec); -// } SPEventContext::setup(); { @@ -282,65 +262,63 @@ void SPTweakContext::setup() { c->curveto(1, -C1, C1, -1, 0, -1 ); c->curveto(-C1, -1, -1, -C1, -1, 0 ); c->closepath(); - tc->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c); + this->dilate_area = sp_canvas_bpath_new(sp_desktop_controls(this->desktop), c); c->unref(); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(tc->dilate_area), 0x00000000,(SPWindRule)0); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_hide(tc->dilate_area); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->dilate_area), 0x00000000,(SPWindRule)0); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_hide(this->dilate_area); } - tc->is_drawing = false; + this->is_drawing = false; - tc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); - sp_event_context_read(ec, "width"); - sp_event_context_read(ec, "mode"); - sp_event_context_read(ec, "fidelity"); - sp_event_context_read(ec, "force"); - sp_event_context_read(ec, "usepressure"); - sp_event_context_read(ec, "doh"); - sp_event_context_read(ec, "dol"); - sp_event_context_read(ec, "dos"); - sp_event_context_read(ec, "doo"); + sp_event_context_read(this, "width"); + sp_event_context_read(this, "mode"); + sp_event_context_read(this, "fidelity"); + sp_event_context_read(this, "force"); + sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "doh"); + sp_event_context_read(this, "dol"); + sp_event_context_read(this, "dos"); + sp_event_context_read(this, "doo"); - tc->style_set_connection = ec->desktop->connectSetStyle( // catch style-setting signal in this tool - sigc::bind(sigc::ptr_fun(&sp_tweak_context_style_set), tc) + this->style_set_connection = this->desktop->connectSetStyle( // catch style-setting signal in this tool + //sigc::bind(sigc::ptr_fun(&sp_tweak_context_style_set), this) + sigc::mem_fun(this, &SPTweakContext::set_style) ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/tweak/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } if (prefs->getBool("/tools/tweak/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } } void SPTweakContext::set(Inkscape::Preferences::Entry* val) { - SPEventContext* ec = this; - - SPTweakContext *tc = SP_TWEAK_CONTEXT(ec); Glib::ustring path = val->getEntryName(); if (path == "width") { - tc->width = CLAMP(val->getDouble(0.1), -1000.0, 1000.0); + this->width = CLAMP(val->getDouble(0.1), -1000.0, 1000.0); } else if (path == "mode") { - tc->mode = val->getInt(); - sp_tweak_update_cursor(tc, false); + this->mode = val->getInt(); + sp_tweak_update_cursor(this, false); } else if (path == "fidelity") { - tc->fidelity = CLAMP(val->getDouble(), 0.0, 1.0); + this->fidelity = CLAMP(val->getDouble(), 0.0, 1.0); } else if (path == "force") { - tc->force = CLAMP(val->getDouble(1.0), 0, 1.0); + this->force = CLAMP(val->getDouble(1.0), 0, 1.0); } else if (path == "usepressure") { - tc->usepressure = val->getBool(); + this->usepressure = val->getBool(); } else if (path == "doh") { - tc->do_h = val->getBool(); + this->do_h = val->getBool(); } else if (path == "dos") { - tc->do_s = val->getBool(); + this->do_s = val->getBool(); } else if (path == "dol") { - tc->do_l = val->getBool(); + this->do_l = val->getBool(); } else if (path == "doo") { - tc->do_o = val->getBool(); + this->do_o = val->getBool(); } } @@ -1152,38 +1130,33 @@ sp_tweak_switch_mode_temporarily (SPTweakContext *tc, gint mode, bool with_shift } gint SPTweakContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPTweakContext *tc = SP_TWEAK_CONTEXT(event_context); - SPDesktop *desktop = event_context->desktop; - gint ret = FALSE; switch (event->type) { case GDK_ENTER_NOTIFY: - sp_canvas_item_show(tc->dilate_area); + sp_canvas_item_show(this->dilate_area); break; case GDK_LEAVE_NOTIFY: - sp_canvas_item_hide(tc->dilate_area); + sp_canvas_item_hide(this->dilate_area); break; case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { + if (event->button.button == 1 && !this->space_panning) { - if (Inkscape::have_viable_layer(desktop, tc->_message_context) == false) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return TRUE; } Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - tc->last_push = desktop->dt2doc(button_dt); + this->last_push = desktop->dt2doc(button_dt); - sp_tweak_extinput(tc, event); + sp_tweak_extinput(this, event); desktop->canvas->forceFullRedrawAfterInterruptions(3); - tc->is_drawing = true; - tc->is_dilating = true; - tc->has_dilated = false; + this->is_drawing = true; + this->is_dilating = true; + this->has_dilated = false; ret = TRUE; } @@ -1194,27 +1167,27 @@ gint SPTweakContext::root_handler(GdkEvent* event) { event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w)); Geom::Point motion_doc(desktop->dt2doc(motion_dt)); - sp_tweak_extinput(tc, event); + sp_tweak_extinput(this, event); // draw the dilating cursor - double radius = get_dilate_radius(tc); + double radius = get_dilate_radius(this); Geom::Affine const sm (Geom::Scale(radius, radius) * Geom::Translate(desktop->w2d(motion_w))); - sp_canvas_item_affine_absolute(tc->dilate_area, sm); - sp_canvas_item_show(tc->dilate_area); + sp_canvas_item_affine_absolute(this->dilate_area, sm); + sp_canvas_item_show(this->dilate_area); guint num = 0; if (!desktop->selection->isEmpty()) { num = g_slist_length(const_cast<GSList *>(desktop->selection->itemList())); } if (num == 0) { - tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak.")); + this->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak.")); } // dilating: - if (tc->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { - sp_tweak_dilate (tc, motion_w, motion_doc, motion_doc - tc->last_push, event->button.state & GDK_SHIFT_MASK? true : false); - //tc->last_push = motion_doc; - tc->has_dilated = true; + if (this->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { + sp_tweak_dilate (this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false); + //this->last_push = motion_doc; + this->has_dilated = true; // it's slow, so prevent clogging up with events gobble_motion_events(GDK_BUTTON1_MASK); return TRUE; @@ -1228,67 +1201,67 @@ gint SPTweakContext::root_handler(GdkEvent* event) { Geom::Point const motion_dt(desktop->w2d(motion_w)); desktop->canvas->endForcedFullRedraws(); - tc->is_drawing = false; + this->is_drawing = false; - if (tc->is_dilating && event->button.button == 1 && !event_context->space_panning) { - if (!tc->has_dilated) { + if (this->is_dilating && event->button.button == 1 && !this->space_panning) { + if (!this->has_dilated) { // if we did not rub, do a light tap - tc->pressure = 0.03; - sp_tweak_dilate (tc, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT); + this->pressure = 0.03; + sp_tweak_dilate (this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT); } - tc->is_dilating = false; - tc->has_dilated = false; - switch (tc->mode) { + this->is_dilating = false; + this->has_dilated = false; + switch (this->mode) { case TWEAK_MODE_MOVE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Move tweak")); break; case TWEAK_MODE_MOVE_IN_OUT: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Move in/out tweak")); break; case TWEAK_MODE_MOVE_JITTER: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Move jitter tweak")); break; case TWEAK_MODE_SCALE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Scale tweak")); break; case TWEAK_MODE_ROTATE: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Rotate tweak")); break; case TWEAK_MODE_MORELESS: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Duplicate/delete tweak")); break; case TWEAK_MODE_PUSH: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Push path tweak")); break; case TWEAK_MODE_SHRINK_GROW: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Shrink/grow path tweak")); break; case TWEAK_MODE_ATTRACT_REPEL: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Attract/repel path tweak")); break; case TWEAK_MODE_ROUGHEN: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Roughen path tweak")); break; case TWEAK_MODE_COLORPAINT: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Color paint tweak")); break; case TWEAK_MODE_COLORJITTER: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Color jitter tweak")); break; case TWEAK_MODE_BLUR: - DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(tc)->desktop), + DocumentUndo::done(sp_desktop_document(SP_EVENT_CONTEXT(this)->desktop), SP_VERB_CONTEXT_TWEAK, _("Blur tweak")); break; } @@ -1302,7 +1275,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_M: case GDK_KEY_0: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_MOVE, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_MOVE, MOD__SHIFT); ret = TRUE; } break; @@ -1310,7 +1283,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_I: case GDK_KEY_1: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_MOVE_IN_OUT, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_MOVE_IN_OUT, MOD__SHIFT); ret = TRUE; } break; @@ -1318,7 +1291,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_Z: case GDK_KEY_2: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_MOVE_JITTER, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_MOVE_JITTER, MOD__SHIFT); ret = TRUE; } break; @@ -1328,7 +1301,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_period: case GDK_KEY_3: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_SCALE, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_SCALE, MOD__SHIFT); ret = TRUE; } break; @@ -1336,7 +1309,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_bracketleft: case GDK_KEY_4: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_ROTATE, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_ROTATE, MOD__SHIFT); ret = TRUE; } break; @@ -1344,7 +1317,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_D: case GDK_KEY_5: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_MORELESS, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_MORELESS, MOD__SHIFT); ret = TRUE; } break; @@ -1352,7 +1325,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_P: case GDK_KEY_6: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_PUSH, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_PUSH, MOD__SHIFT); ret = TRUE; } break; @@ -1360,7 +1333,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_S: case GDK_KEY_7: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_SHRINK_GROW, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_SHRINK_GROW, MOD__SHIFT); ret = TRUE; } break; @@ -1368,7 +1341,7 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_A: case GDK_KEY_8: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_ATTRACT_REPEL, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_ATTRACT_REPEL, MOD__SHIFT); ret = TRUE; } break; @@ -1376,28 +1349,28 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_R: case GDK_KEY_9: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_ROUGHEN, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_ROUGHEN, MOD__SHIFT); ret = TRUE; } break; case GDK_KEY_c: case GDK_KEY_C: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_COLORPAINT, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_COLORPAINT, MOD__SHIFT); ret = TRUE; } break; case GDK_KEY_j: case GDK_KEY_J: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_COLORJITTER, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_COLORJITTER, MOD__SHIFT); ret = TRUE; } break; case GDK_KEY_b: case GDK_KEY_B: if (MOD__SHIFT_ONLY) { - sp_tweak_switch_mode(tc, TWEAK_MODE_BLUR, MOD__SHIFT); + sp_tweak_switch_mode(this, TWEAK_MODE_BLUR, MOD__SHIFT); ret = TRUE; } break; @@ -1405,61 +1378,61 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_Up: case GDK_KEY_KP_Up: if (!MOD__CTRL_ONLY) { - tc->force += 0.05; - if (tc->force > 1.0) { - tc->force = 1.0; + this->force += 0.05; + if (this->force > 1.0) { + this->force = 1.0; } - desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100); + desktop->setToolboxAdjustmentValue ("tweak-force", this->force * 100); ret = TRUE; } break; case GDK_KEY_Down: case GDK_KEY_KP_Down: if (!MOD__CTRL_ONLY) { - tc->force -= 0.05; - if (tc->force < 0.0) { - tc->force = 0.0; + this->force -= 0.05; + if (this->force < 0.0) { + this->force = 0.0; } - desktop->setToolboxAdjustmentValue ("tweak-force", tc->force * 100); + desktop->setToolboxAdjustmentValue ("tweak-force", this->force * 100); ret = TRUE; } break; case GDK_KEY_Right: case GDK_KEY_KP_Right: if (!MOD__CTRL_ONLY) { - tc->width += 0.01; - if (tc->width > 1.0) { - tc->width = 1.0; + this->width += 0.01; + if (this->width > 1.0) { + this->width = 1.0; } - desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); // the same spinbutton is for alt+x - sp_tweak_update_area(tc); + desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); // the same spinbutton is for alt+x + sp_tweak_update_area(this); ret = TRUE; } break; case GDK_KEY_Left: case GDK_KEY_KP_Left: if (!MOD__CTRL_ONLY) { - tc->width -= 0.01; - if (tc->width < 0.01) { - tc->width = 0.01; + this->width -= 0.01; + if (this->width < 0.01) { + this->width = 0.01; } - desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); - sp_tweak_update_area(tc); + desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + sp_tweak_update_area(this); ret = TRUE; } break; case GDK_KEY_Home: case GDK_KEY_KP_Home: - tc->width = 0.01; - desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); - sp_tweak_update_area(tc); + this->width = 0.01; + desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + sp_tweak_update_area(this); ret = TRUE; break; case GDK_KEY_End: case GDK_KEY_KP_End: - tc->width = 1.0; - desktop->setToolboxAdjustmentValue ("altx-tweak", tc->width * 100); - sp_tweak_update_area(tc); + this->width = 1.0; + desktop->setToolboxAdjustmentValue ("altx-tweak", this->width * 100); + sp_tweak_update_area(this); ret = TRUE; break; case GDK_KEY_x: @@ -1472,17 +1445,17 @@ gint SPTweakContext::root_handler(GdkEvent* event) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - sp_tweak_update_cursor(tc, true); + sp_tweak_update_cursor(this, true); break; case GDK_KEY_Control_L: case GDK_KEY_Control_R: - sp_tweak_switch_mode_temporarily(tc, TWEAK_MODE_SHRINK_GROW, MOD__SHIFT); + sp_tweak_switch_mode_temporarily(this, TWEAK_MODE_SHRINK_GROW, MOD__SHIFT); break; case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; default: @@ -1495,15 +1468,15 @@ gint SPTweakContext::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - sp_tweak_update_cursor(tc, false); + sp_tweak_update_cursor(this, false); break; case GDK_KEY_Control_L: case GDK_KEY_Control_R: - sp_tweak_switch_mode (tc, prefs->getInt("/tools/tweak/mode"), MOD__SHIFT); - tc->_message_context->clear(); + sp_tweak_switch_mode (this, prefs->getInt("/tools/tweak/mode"), MOD__SHIFT); + this->_message_context->clear(); break; default: - sp_tweak_switch_mode (tc, prefs->getInt("/tools/tweak/mode"), MOD__SHIFT); + sp_tweak_switch_mode (this, prefs->getInt("/tools/tweak/mode"), MOD__SHIFT); break; } } @@ -1512,9 +1485,6 @@ gint SPTweakContext::root_handler(GdkEvent* event) { } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->root_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_tweak_context_parent_class))->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } diff --git a/src/tweak-context.h b/src/tweak-context.h index f4461dd93..f513b573e 100644 --- a/src/tweak-context.h +++ b/src/tweak-context.h @@ -45,8 +45,6 @@ public: SPTweakContext(); virtual ~SPTweakContext(); - //SPEventContext event_context; - /* extended input data */ gdouble pressure; @@ -84,6 +82,9 @@ public: virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + bool set_style(const SPCSSAttr* css); }; #endif diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0fbc09df8..822f55a93 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -238,7 +238,8 @@ void ClipboardManagerImpl::copy(SPDesktop *desktop) // Special case for when the color picker ("dropper") is active - copies color under cursor if (tools_isactive(desktop, TOOLS_DROPPER)) { - _setClipboardColor(sp_dropper_context_get_color(desktop->event_context)); + //_setClipboardColor(sp_dropper_context_get_color(desktop->event_context)); + _setClipboardColor(SP_DROPPER_CONTEXT(desktop->event_context)->get_color()); _discardInternalClipboard(); return; } diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index f994080b0..f64aa4d2a 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -104,21 +104,8 @@ using Inkscape::ControlManager; -//namespace { - SPCanvasGroup *create_control_group(SPDesktop *d); -void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event); -void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel); -void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *); -void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *); -void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p); - -void handleControlUiStyleChange(InkNodeTool *nt); - -//} // anonymous namespace - - #include "tool-factory.h" namespace { @@ -136,50 +123,32 @@ const std::string& InkNodeTool::getPrefsPath() { const std::string InkNodeTool::prefsPath = "/tools/nodes"; InkNodeTool::InkNodeTool() : SPEventContext() { - InkNodeTool* nt = this; - - nt->show_handles = 0; - nt->single_node_transform_handles = 0; - nt->show_transform_handles = 0; - nt->cursor_drag = 0; - nt->_node_message_context = 0; - nt->live_objects = 0; - nt->edit_clipping_paths = 0; - nt->live_outline = 0; - nt->flashed_item = 0; - nt->_transform_handle_group = 0; - nt->show_path_direction = 0; - nt->_last_over = 0; - nt->edit_masks = 0; - nt->show_outline = 0; - nt->flash_tempitem = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(nt); - - event_context->cursor_shape = cursor_node_xpm; - event_context->hot_x = 1; - event_context->hot_y = 1; - -// new (&nt->_selection_changed_connection) sigc::connection(); -// new (&nt->_selection_modified_connection) sigc::connection(); -// new (&nt->_mouseover_changed_connection) sigc::connection(); -// new (&nt->_sizeUpdatedConn) sigc::connection(); -// //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop); -// new (&nt->_selected_nodes) CSelPtr(); -// new (&nt->_multipath) MultiPathPtr(); -// new (&nt->_selector) SelectorPtr(); -// new (&nt->_path_data) PathSharedDataPtr(); -// new (&nt->_shape_editors) ShapeEditors(); - - nt->_selected_nodes = 0; - nt->_multipath = 0; - nt->_selector = 0; - nt->_path_data = 0; - //nt->_shape_editors = 0; + this->show_handles = false; + this->single_node_transform_handles = false; + this->show_transform_handles = false; + this->cursor_drag = false; + this->_node_message_context = 0; + this->live_objects = false; + this->edit_clipping_paths = false; + this->live_outline = false; + this->flashed_item = 0; + this->_transform_handle_group = 0; + this->show_path_direction = false; + this->_last_over = 0; + this->edit_masks = false; + this->show_outline = false; + this->flash_tempitem = 0; + + this->cursor_shape = cursor_node_xpm; + this->hot_x = 1; + this->hot_y = 1; + + this->_selected_nodes = 0; + this->_multipath = 0; + this->_selector = 0; + this->_path_data = 0; } -//namespace { - SPCanvasGroup *create_control_group(SPDesktop *d) { return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new( @@ -192,202 +161,163 @@ void destroy_group(SPCanvasGroup *g) } InkNodeTool::~InkNodeTool() { - InkNodeTool *nt = INK_NODE_TOOL(this); - - nt->enableGrDrag(false); + this->enableGrDrag(false); - if (nt->flash_tempitem) { - nt->desktop->remove_temporary_canvasitem(nt->flash_tempitem); + if (this->flash_tempitem) { + this->desktop->remove_temporary_canvasitem(this->flash_tempitem); } - nt->_selection_changed_connection.disconnect(); - nt->_selection_modified_connection.disconnect(); - nt->_mouseover_changed_connection.disconnect(); - nt->_sizeUpdatedConn.disconnect(); + this->_selection_changed_connection.disconnect(); + //this->_selection_modified_connection.disconnect(); + this->_mouseover_changed_connection.disconnect(); + this->_sizeUpdatedConn.disconnect(); -// nt->_multipath.~MultiPathPtr(); -// nt->_selected_nodes.~CSelPtr(); -// nt->_selector.~SelectorPtr(); -// nt->_shape_editors.~ShapeEditors(); + delete this->_multipath; + delete this->_selected_nodes; + delete this->_selector; - delete nt->_multipath; - delete nt->_selected_nodes; - delete nt->_selector; - - Inkscape::UI::PathSharedData &data = *nt->_path_data; + Inkscape::UI::PathSharedData &data = *this->_path_data; destroy_group(data.node_data.node_group); destroy_group(data.node_data.handle_group); destroy_group(data.node_data.handle_line_group); destroy_group(data.outline_group); destroy_group(data.dragpoint_group); - destroy_group(nt->_transform_handle_group); - -// nt->_path_data.~PathSharedDataPtr(); -// nt->_selection_changed_connection.~connection(); -// nt->_selection_modified_connection.~connection(); -// nt->_mouseover_changed_connection.~connection(); -// nt->_sizeUpdatedConn.~connection(); + destroy_group(this->_transform_handle_group); - if (nt->_node_message_context) { - delete nt->_node_message_context; + if (this->_node_message_context) { + delete this->_node_message_context; } - - //G_OBJECT_CLASS(ink_node_tool_parent_class)->dispose(object); } void InkNodeTool::setup() { - SPEventContext* ec = this; - - InkNodeTool *nt = INK_NODE_TOOL(ec); - -// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup) -// SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup(ec); SPEventContext::setup(); - nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->_node_message_context = new Inkscape::MessageContext((this->desktop)->messageStack()); + this->_path_data = new Inkscape::UI::PathSharedData(); - //nt->_path_data.reset(new Inkscape::UI::PathSharedData()); - nt->_path_data = new Inkscape::UI::PathSharedData(); - Inkscape::UI::PathSharedData &data = *nt->_path_data; - data.node_data.desktop = nt->desktop; + Inkscape::UI::PathSharedData &data = *this->_path_data; + data.node_data.desktop = this->desktop; // selector has to be created here, so that its hidden control point is on the bottom - //nt->_selector.reset(new Inkscape::UI::Selector(nt->desktop)); - nt->_selector = new Inkscape::UI::Selector(nt->desktop); + this->_selector = new Inkscape::UI::Selector(this->desktop); // Prepare canvas groups for controls. This guarantees correct z-order, so that // for example a dragpoint won't obscure a node - data.outline_group = create_control_group(nt->desktop); - data.node_data.handle_line_group = create_control_group(nt->desktop); - data.dragpoint_group = create_control_group(nt->desktop); - nt->_transform_handle_group = create_control_group(nt->desktop); - data.node_data.node_group = create_control_group(nt->desktop); - data.node_data.handle_group = create_control_group(nt->desktop); - - Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); - nt->_selection_changed_connection.disconnect(); - nt->_selection_changed_connection = - selection->connectChanged( - sigc::bind<0>( - sigc::ptr_fun(&ink_node_tool_selection_changed), - nt)); - /*nt->_selection_modified_connection.disconnect(); - nt->_selection_modified_connection = - selection->connectModified( - sigc::hide(sigc::bind<0>( - sigc::ptr_fun(&ink_node_tool_selection_modified), - nt)));*/ - nt->_mouseover_changed_connection.disconnect(); - nt->_mouseover_changed_connection = - Inkscape::UI::ControlPoint::signal_mouseover_change.connect( - sigc::bind<0>( - sigc::ptr_fun(&ink_node_tool_mouseover_changed), - nt)); - - nt->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged(sigc::bind(sigc::ptr_fun(&handleControlUiStyleChange), nt)); + data.outline_group = create_control_group(this->desktop); + data.node_data.handle_line_group = create_control_group(this->desktop); + data.dragpoint_group = create_control_group(this->desktop); + this->_transform_handle_group = create_control_group(this->desktop); + data.node_data.node_group = create_control_group(this->desktop); + data.node_data.handle_group = create_control_group(this->desktop); + + Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + + this->_selection_changed_connection.disconnect(); + this->_selection_changed_connection = + selection->connectChanged(sigc::mem_fun(this, &InkNodeTool::selection_changed)); + + this->_mouseover_changed_connection.disconnect(); + this->_mouseover_changed_connection = + Inkscape::UI::ControlPoint::signal_mouseover_change.connect(sigc::mem_fun(this, &InkNodeTool::mouseover_changed)); + + this->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged( + sigc::mem_fun(this, &InkNodeTool::handleControlUiStyleChange) + ); -// nt->_selected_nodes.reset( -// new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group)); - nt->_selected_nodes = new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group); - - //data.node_data.selection = nt->_selected_nodes.get(); - data.node_data.selection = nt->_selected_nodes; - - //nt->_multipath.reset(new Inkscape::UI::MultiPathManipulator(data, - // nt->_selection_changed_connection)); - nt->_multipath = new Inkscape::UI::MultiPathManipulator(data, nt->_selection_changed_connection); - - nt->_selector->signal_point.connect( - sigc::bind<0>( - sigc::ptr_fun(&ink_node_tool_select_point), - nt)); - nt->_selector->signal_area.connect( - sigc::bind<0>( - sigc::ptr_fun(&ink_node_tool_select_area), - nt)); - - nt->_multipath->signal_coords_changed.connect( + this->_selected_nodes = new Inkscape::UI::ControlPointSelection(this->desktop, this->_transform_handle_group); + + data.node_data.selection = this->_selected_nodes; + + this->_multipath = new Inkscape::UI::MultiPathManipulator(data, this->_selection_changed_connection); + + this->_selector->signal_point.connect(sigc::mem_fun(this, &InkNodeTool::select_point)); + this->_selector->signal_area.connect(sigc::mem_fun(this, &InkNodeTool::select_area)); + + this->_multipath->signal_coords_changed.connect( sigc::bind( - sigc::mem_fun(*nt->desktop, &SPDesktop::emitToolSubselectionChanged), - (void*) 0)); - nt->_selected_nodes->signal_point_changed.connect( - sigc::hide( sigc::hide( - sigc::bind( - sigc::bind( - sigc::ptr_fun(ink_node_tool_update_tip), - (GdkEvent*)0), - nt)))); - - nt->cursor_drag = false; - nt->show_transform_handles = true; - nt->single_node_transform_handles = false; - nt->flash_tempitem = NULL; - nt->flashed_item = NULL; - nt->_last_over = NULL; + sigc::mem_fun(*this->desktop, &SPDesktop::emitToolSubselectionChanged), + (void*)NULL + ) + ); + + this->_selected_nodes->signal_point_changed.connect( + // Hide both signal parameters and bind the function parameter to 0 + // sigc::signal<void, SelectableControlPoint *, bool> + // <=> + // void update_tip(GdkEvent *event) + sigc::hide(sigc::hide(sigc::bind( + sigc::mem_fun(this, &InkNodeTool::update_tip), + (GdkEvent*)NULL + ))) + ); + + this->cursor_drag = false; + this->show_transform_handles = true; + this->single_node_transform_handles = false; + this->flash_tempitem = NULL; + this->flashed_item = NULL; + this->_last_over = NULL; // read prefs before adding items to selection to prevent momentarily showing the outline - sp_event_context_read(nt, "show_handles"); - sp_event_context_read(nt, "show_outline"); - sp_event_context_read(nt, "live_outline"); - sp_event_context_read(nt, "live_objects"); - sp_event_context_read(nt, "show_path_direction"); - sp_event_context_read(nt, "show_transform_handles"); - sp_event_context_read(nt, "single_node_transform_handles"); - sp_event_context_read(nt, "edit_clipping_paths"); - sp_event_context_read(nt, "edit_masks"); - - ink_node_tool_selection_changed(nt, selection); - ink_node_tool_update_tip(nt, NULL); + sp_event_context_read(this, "show_handles"); + sp_event_context_read(this, "show_outline"); + sp_event_context_read(this, "live_outline"); + sp_event_context_read(this, "live_objects"); + sp_event_context_read(this, "show_path_direction"); + sp_event_context_read(this, "show_transform_handles"); + sp_event_context_read(this, "single_node_transform_handles"); + sp_event_context_read(this, "edit_clipping_paths"); + sp_event_context_read(this, "edit_masks"); + + this->selection_changed(selection); + this->update_tip(NULL); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/nodes/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } + if (prefs->getBool("/tools/nodes/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } - nt->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive + this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive } void InkNodeTool::set(Inkscape::Preferences::Entry* value) { - SPEventContext* ec = this; - - InkNodeTool *nt = INK_NODE_TOOL(ec); Glib::ustring entry_name = value->getEntryName(); if (entry_name == "show_handles") { - nt->show_handles = value->getBool(true); - nt->_multipath->showHandles(nt->show_handles); + this->show_handles = value->getBool(true); + this->_multipath->showHandles(this->show_handles); } else if (entry_name == "show_outline") { - nt->show_outline = value->getBool(); - nt->_multipath->showOutline(nt->show_outline); + this->show_outline = value->getBool(); + this->_multipath->showOutline(this->show_outline); } else if (entry_name == "live_outline") { - nt->live_outline = value->getBool(); - nt->_multipath->setLiveOutline(nt->live_outline); + this->live_outline = value->getBool(); + this->_multipath->setLiveOutline(this->live_outline); } else if (entry_name == "live_objects") { - nt->live_objects = value->getBool(); - nt->_multipath->setLiveObjects(nt->live_objects); + this->live_objects = value->getBool(); + this->_multipath->setLiveObjects(this->live_objects); } else if (entry_name == "show_path_direction") { - nt->show_path_direction = value->getBool(); - nt->_multipath->showPathDirection(nt->show_path_direction); + this->show_path_direction = value->getBool(); + this->_multipath->showPathDirection(this->show_path_direction); } else if (entry_name == "show_transform_handles") { - nt->show_transform_handles = value->getBool(true); - nt->_selected_nodes->showTransformHandles( - nt->show_transform_handles, nt->single_node_transform_handles); + this->show_transform_handles = value->getBool(true); + this->_selected_nodes->showTransformHandles( + this->show_transform_handles, this->single_node_transform_handles); } else if (entry_name == "single_node_transform_handles") { - nt->single_node_transform_handles = value->getBool(); - nt->_selected_nodes->showTransformHandles( - nt->show_transform_handles, nt->single_node_transform_handles); + this->single_node_transform_handles = value->getBool(); + this->_selected_nodes->showTransformHandles( + this->show_transform_handles, this->single_node_transform_handles); } else if (entry_name == "edit_clipping_paths") { - nt->edit_clipping_paths = value->getBool(); - ink_node_tool_selection_changed(nt, nt->desktop->selection); + this->edit_clipping_paths = value->getBool(); + this->selection_changed(this->desktop->selection); } else if (entry_name == "edit_masks") { - nt->edit_masks = value->getBool(); - ink_node_tool_selection_changed(nt, nt->desktop->selection); + this->edit_masks = value->getBool(); + this->selection_changed(this->desktop->selection); } else { -// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set) -// SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set(ec, value); SPEventContext::set(value); } } @@ -397,7 +327,10 @@ void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Sh std::set<Inkscape::UI::ShapeRecord> &s) { using namespace Inkscape::UI; - if (!obj) return; + + if (!obj) { + return; + } //XML Tree being used directly here while it shouldn't be. if (SP_IS_PATH(obj) && obj->getRepr()->attribute("inkscape:original-d") != NULL) { @@ -417,11 +350,13 @@ void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Sh // TODO add support for objectBoundingBox r.edit_transform = base ? base->i2doc_affine() : Geom::identity(); r.role = role; + if (s.insert(r).second) { // this item was encountered the first time if (nt->edit_clipping_paths && item->clip_ref) { gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s); } + if (nt->edit_masks && item->mask_ref) { gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s); } @@ -429,8 +364,7 @@ void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Sh } } -void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel) -{ +void InkNodeTool::selection_changed(Inkscape::Selection *sel) { using namespace Inkscape::UI; std::set<ShapeRecord> shapes; @@ -439,20 +373,22 @@ void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel) for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) { SPObject *obj = static_cast<SPObject*>(i->data); + if (SP_IS_ITEM(obj)) { - gather_items(nt, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes); + gather_items(this, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes); } } // use multiple ShapeEditors for now, to allow editing many shapes at once // needs to be rethought - for (ShapeEditors::iterator i = nt->_shape_editors.begin(); - i != nt->_shape_editors.end(); ) + for (boost::ptr_map<SPItem*, ShapeEditor>::iterator i = this->_shape_editors.begin(); + i != this->_shape_editors.end(); ) { ShapeRecord s; s.item = i->first; + if (shapes.find(s) == shapes.end()) { - nt->_shape_editors.erase(i++); + this->_shape_editors.erase(i++); } else { ++i; } @@ -460,23 +396,22 @@ void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel) for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) { ShapeRecord const &r = *i; + if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item)) && - nt->_shape_editors.find(r.item) == nt->_shape_editors.end()) + this->_shape_editors.find(r.item) == this->_shape_editors.end()) { - ShapeEditor *si = new ShapeEditor(nt->desktop); + ShapeEditor *si = new ShapeEditor(this->desktop); si->set_item(r.item, SH_KNOTHOLDER); - nt->_shape_editors.insert(const_cast<SPItem*&>(r.item), si); + this->_shape_editors.insert(const_cast<SPItem*&>(r.item), si); } } - nt->_multipath->setItems(shapes); - ink_node_tool_update_tip(nt, NULL); - nt->desktop->updateNow(); + this->_multipath->setItems(shapes); + this->update_tip(NULL); + this->desktop->updateNow(); } gint InkNodeTool::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - /* things to handle here: * 1. selection of items * 2. passing events to manipulators @@ -484,14 +419,20 @@ gint InkNodeTool::root_handler(GdkEvent* event) { */ using namespace Inkscape::UI; // pull in event helpers - SPDesktop *desktop = event_context->desktop; Inkscape::Selection *selection = desktop->selection; - InkNodeTool *nt = static_cast<InkNodeTool*>(event_context); static Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (nt->_multipath->event(event_context, event)) return true; - if (nt->_selector->event(event_context, event)) return true; - if (nt->_selected_nodes->event(event_context, event)) return true; + if (this->_multipath->event(this, event)) { + return true; + } + + if (this->_selector->event(this, event)) { + return true; + } + + if (this->_selected_nodes->event(this, event)) { + return true; + } switch (event->type) { @@ -499,33 +440,52 @@ gint InkNodeTool::root_handler(GdkEvent* event) { combine_motion_events(desktop->canvas, event->motion, 0); SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button), FALSE, TRUE); - if (over_item != nt->_last_over) { - nt->_last_over = over_item; - ink_node_tool_update_tip(nt, event); + + if (over_item != this->_last_over) { + this->_last_over = over_item; + //ink_node_tool_update_tip(nt, event); + this->update_tip(event); } // create pathflash outline if (prefs->getBool("/tools/nodes/pathflash_enabled")) { - if (over_item == nt->flashed_item) break; - if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) break; - if (nt->flash_tempitem) { - desktop->remove_temporary_canvasitem(nt->flash_tempitem); - nt->flash_tempitem = NULL; - nt->flashed_item = NULL; + if (over_item == this->flashed_item) { + break; } - if (!SP_IS_SHAPE(over_item)) break; // for now, handle only shapes - nt->flashed_item = over_item; + if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) { + break; + } + + if (this->flash_tempitem) { + desktop->remove_temporary_canvasitem(this->flash_tempitem); + this->flash_tempitem = NULL; + this->flashed_item = NULL; + } + + if (!SP_IS_SHAPE(over_item)) { + break; // for now, handle only shapes + } + + this->flashed_item = over_item; SPCurve *c = SP_SHAPE(over_item)->getCurveBeforeLPE(); - if (!c) break; // break out when curve doesn't exist + + if (!c) { + break; // break out when curve doesn't exist + } + c->transform(over_item->i2dt_affine()); SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash), prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO); - nt->flash_tempitem = desktop->add_temporary_canvasitem(flash, + + this->flash_tempitem = desktop->add_temporary_canvasitem(flash, prefs->getInt("/tools/nodes/pathflash_timeout", 500)); + c->unref(); } } break; // do not return true, because we need to pass this event to the parent context @@ -535,39 +495,49 @@ gint InkNodeTool::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Escape: // deselect everything - if (nt->_selected_nodes->empty()) { + if (this->_selected_nodes->empty()) { Inkscape::SelectionHelper::selectNone(desktop); } else { - nt->_selected_nodes->clear(); + this->_selected_nodes->clear(); } - ink_node_tool_update_tip(nt, event); + //ink_node_tool_update_tip(nt, event); + this->update_tip(event); return TRUE; + case GDK_KEY_a: case GDK_KEY_A: if (held_control(event->key) && held_alt(event->key)) { - nt->_selected_nodes->selectAll(); + this->_selected_nodes->selectAll(); // Ctrl+A is handled in selection-chemistry.cpp via verb - ink_node_tool_update_tip(nt, event); + //ink_node_tool_update_tip(nt, event); + this->update_tip(event); return TRUE; } break; + case GDK_KEY_h: case GDK_KEY_H: if (held_only_control(event->key)) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/nodes/show_handles", !nt->show_handles); + prefs->setBool("/tools/nodes/show_handles", !this->show_handles); return TRUE; } break; + default: break; } - ink_node_tool_update_tip(nt, event); + //ink_node_tool_update_tip(nt, event); + this->update_tip(event); break; + case GDK_KEY_RELEASE: - ink_node_tool_update_tip(nt, event); + //ink_node_tool_update_tip(nt, event); + this->update_tip(event); break; - default: break; + + default: + break; } // if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler) @@ -577,97 +547,110 @@ gint InkNodeTool::root_handler(GdkEvent* event) { return FALSE; } -void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event) -{ +void InkNodeTool::update_tip(GdkEvent *event) { using namespace Inkscape::UI; + if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) { unsigned new_state = state_after_event(event); - if (new_state == event->key.state) return; + + if (new_state == event->key.state) { + return; + } + if (state_held_shift(new_state)) { - if (nt->_last_over) { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, + if (this->_last_over) { + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection, " "click to toggle object selection")); } else { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection")); } + return; } } - unsigned sz = nt->_selected_nodes->size(); - unsigned total = nt->_selected_nodes->allPoints().size(); + + unsigned sz = this->_selected_nodes->size(); + unsigned total = this->_selected_nodes->allPoints().size(); + if (sz != 0) { char *nodestring = g_strdup_printf( ngettext("<b>%u of %u</b> node selected.", "<b>%u of %u</b> nodes selected.", total), sz, total); - if (nt->_last_over) { + + if (this->_last_over) { // TRANSLATORS: The %s below is where the "%u of %u nodes selected" sentence gets put char *dyntip = g_strdup_printf(C_("Node tool tip", "%s Drag to select nodes, click to edit only this object (more: Shift)"), nodestring); - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); g_free(dyntip); } else { char *dyntip = g_strdup_printf(C_("Node tool tip", "%s Drag to select nodes, click clear the selection"), nodestring); - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); g_free(dyntip); } g_free(nodestring); - } else if (!nt->_multipath->empty()) { - if (nt->_last_over) { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", + } else if (!this->_multipath->empty()) { + if (this->_last_over) { + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "Drag to select nodes, click to edit only this object")); } else { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "Drag to select nodes, click to clear the selection")); } } else { - if (nt->_last_over) { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", + if (this->_last_over) { + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "Drag to select objects to edit, click to edit this object (more: Shift)")); } else { - nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", + this->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", "Drag to select objects to edit")); } } } gint InkNodeTool::item_handler(SPItem* item, GdkEvent* event) { - - -// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler) -// return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler(event_context, item, event); SPEventContext::item_handler(item, event); return FALSE; } -void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventButton *event) -{ +void InkNodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { using namespace Inkscape::UI; - if (nt->_multipath->empty()) { + + if (this->_multipath->empty()) { // if multipath is empty, select rubberbanded items rather than nodes - Inkscape::Selection *selection = nt->desktop->selection; - GSList *items = sp_desktop_document(nt->desktop)->getItemsInBox(nt->desktop->dkey, sel); + Inkscape::Selection *selection = this->desktop->selection; + GSList *items = sp_desktop_document(this->desktop)->getItemsInBox(this->desktop->dkey, sel); selection->setList(items); g_slist_free(items); } else { - if (!held_shift(*event)) nt->_selected_nodes->clear(); - nt->_selected_nodes->selectArea(sel); + if (!held_shift(*event)) { + this->_selected_nodes->clear(); + } + + this->_selected_nodes->selectArea(sel); } } -void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, GdkEventButton *event) -{ + +void InkNodeTool::select_point(Geom::Point const &sel, GdkEventButton *event) { using namespace Inkscape::UI; // pull in event helpers - if (!event) return; - if (event->button != 1) return; - Inkscape::Selection *selection = nt->desktop->selection; + if (!event) { + return; + } + + if (event->button != 1) { + return; + } - SPItem *item_clicked = sp_event_context_find_item (nt->desktop, event_point(*event), + Inkscape::Selection *selection = this->desktop->selection; + + SPItem *item_clicked = sp_event_context_find_item (this->desktop, event_point(*event), (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE); if (item_clicked == NULL) { // nothing under cursor @@ -675,10 +658,10 @@ void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, Gdk // if there are nodes selected, the first click should deselect the nodes // and the second should deselect the items if (!state_held_shift(event->state)) { - if (nt->_selected_nodes->empty()) { + if (this->_selected_nodes->empty()) { selection->clear(); } else { - nt->_selected_nodes->clear(); + this->_selected_nodes->clear(); } } } else { @@ -687,32 +670,33 @@ void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, Gdk } else { selection->set(item_clicked); } - nt->desktop->updateNow(); + + this->desktop->updateNow(); } } -void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p) -{ +void InkNodeTool::mouseover_changed(Inkscape::UI::ControlPoint *p) { using Inkscape::UI::CurveDragPoint; + CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p); - if (cdp && !nt->cursor_drag) { - nt->cursor_shape = cursor_node_d_xpm; - nt->hot_x = 1; - nt->hot_y = 1; - sp_event_context_update_cursor(nt); - nt->cursor_drag = true; - } else if (!cdp && nt->cursor_drag) { - nt->cursor_shape = cursor_node_xpm; - nt->hot_x = 1; - nt->hot_y = 1; - sp_event_context_update_cursor(nt); - nt->cursor_drag = false; + + if (cdp && !this->cursor_drag) { + this->cursor_shape = cursor_node_d_xpm; + this->hot_x = 1; + this->hot_y = 1; + sp_event_context_update_cursor(this); + this->cursor_drag = true; + } else if (!cdp && this->cursor_drag) { + this->cursor_shape = cursor_node_xpm; + this->hot_x = 1; + this->hot_y = 1; + sp_event_context_update_cursor(this); + this->cursor_drag = false; } } -void handleControlUiStyleChange(InkNodeTool *nt) -{ - nt->_multipath->updateHandles(); +void InkNodeTool::handleControlUiStyleChange() { + this->_multipath->updateHandles(); } //} // anonymous namespace diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index fb2b41663..597f2a347 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -11,7 +11,6 @@ #ifndef SEEN_UI_TOOL_NODE_TOOL_H #define SEEN_UI_TOOL_NODE_TOOL_H -#include <memory> #include <boost/ptr_container/ptr_map.hpp> #include <glib.h> #include "event-context.h" @@ -29,53 +28,20 @@ class MultiPathManipulator; class ControlPointSelection; class Selector; struct PathSharedData; +class ControlPoint; } // namespace UI } // namespace Inkscape -//typedef std::auto_ptr<Inkscape::UI::MultiPathManipulator> MultiPathPtr; -//typedef std::auto_ptr<Inkscape::UI::ControlPointSelection> CSelPtr; -//typedef std::auto_ptr<Inkscape::UI::Selector> SelectorPtr; -//typedef std::auto_ptr<Inkscape::UI::PathSharedData> PathSharedDataPtr; - - -typedef Inkscape::UI::MultiPathManipulator* MultiPathPtr; -typedef Inkscape::UI::ControlPointSelection* CSelPtr; -typedef Inkscape::UI::Selector* SelectorPtr; -typedef Inkscape::UI::PathSharedData* PathSharedDataPtr; - -typedef boost::ptr_map<SPItem*, ShapeEditor> ShapeEditors; - - class InkNodeTool : public SPEventContext { public: InkNodeTool(); virtual ~InkNodeTool(); - sigc::connection _selection_changed_connection; - sigc::connection _mouseover_changed_connection; - sigc::connection _selection_modified_connection; - sigc::connection _sizeUpdatedConn; - Inkscape::MessageContext *_node_message_context; - SPItem *flashed_item; - Inkscape::Display::TemporaryItem *flash_tempitem; - CSelPtr _selected_nodes; - MultiPathPtr _multipath; - SelectorPtr _selector; - PathSharedDataPtr _path_data; - SPCanvasGroup *_transform_handle_group; - SPItem *_last_over; - ShapeEditors _shape_editors; - - unsigned cursor_drag : 1; - unsigned show_handles : 1; - unsigned show_outline : 1; - unsigned live_outline : 1; - unsigned live_objects : 1; - unsigned show_path_direction : 1; - unsigned show_transform_handles : 1; - unsigned single_node_transform_handles : 1; - unsigned edit_clipping_paths : 1; - unsigned edit_masks : 1; + Inkscape::UI::ControlPointSelection* _selected_nodes; + Inkscape::UI::MultiPathManipulator* _multipath; + + bool edit_clipping_paths; + bool edit_masks; static const std::string prefsPath; @@ -85,6 +51,37 @@ public: virtual gint item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + sigc::connection _selection_changed_connection; + sigc::connection _mouseover_changed_connection; + sigc::connection _sizeUpdatedConn; + + Inkscape::MessageContext *_node_message_context; + SPItem *flashed_item; + Inkscape::Display::TemporaryItem *flash_tempitem; + Inkscape::UI::Selector* _selector; + Inkscape::UI::PathSharedData* _path_data; + SPCanvasGroup *_transform_handle_group; + SPItem *_last_over; + boost::ptr_map<SPItem*, ShapeEditor> _shape_editors; + + bool cursor_drag; + bool show_handles; + bool show_outline; + bool live_outline; + bool live_objects; + bool show_path_direction; + bool show_transform_handles; + bool single_node_transform_handles; + + void selection_changed(Inkscape::Selection *sel); + + void select_area(Geom::Rect const &sel, GdkEventButton *event); + void select_point(Geom::Point const &sel, GdkEventButton *event); + void mouseover_changed(Inkscape::UI::ControlPoint *p); + void update_tip(GdkEvent *event); + void handleControlUiStyleChange(); }; #endif diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 73815b86d..50031a427 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -79,7 +79,8 @@ using Inkscape::UI::PrefPusher; static void paintbucket_channels_changed(EgeSelectOneAction* act, GObject* /*tbl*/) { gint channels = ege_select_one_action_get_active( act ); - flood_channels_set_channels( channels ); + //flood_channels_set_channels( channels ); + SPFloodContext::set_channels(channels); } static void paintbucket_threshold_changed(GtkAdjustment *adj, GObject * /*tbl*/) diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp index ee72b85ab..b86fee0ee 100644 --- a/src/zoom-context.cpp +++ b/src/zoom-context.cpp @@ -26,9 +26,9 @@ #include "zoom-context.h" -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; static bool escaped; #include "tool-factory.h" @@ -48,70 +48,49 @@ const std::string& SPZoomContext::getPrefsPath() { const std::string SPZoomContext::prefsPath = "/tools/zoom"; SPZoomContext::SPZoomContext() : SPEventContext() { - SPZoomContext* zoom_context = this; - - zoom_context->grabbed = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(zoom_context); - - event_context->cursor_shape = cursor_zoom_xpm; - event_context->hot_x = 6; - event_context->hot_y = 6; + this->grabbed = 0; + this->cursor_shape = cursor_zoom_xpm; + this->hot_x = 6; + this->hot_y = 6; } SPZoomContext::~SPZoomContext() { } void SPZoomContext::finish() { - SPEventContext* ec = this; - - SPZoomContext *zc = SP_ZOOM_CONTEXT(ec); + this->enableGrDrag(false); - ec->enableGrDrag(false); - - if (zc->grabbed) { - sp_canvas_item_ungrab(zc->grabbed, GDK_CURRENT_TIME); - zc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); + this->grabbed = NULL; } } void SPZoomContext::setup() { - SPEventContext* ec = this; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/zoom/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } + if (prefs->getBool("/tools/zoom/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } -// if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup) { -// (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup(ec); -// } SPEventContext::setup(); } -gint SPZoomContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - - gint ret = FALSE; - -// if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler (event_context, item, event); -// } - ret = SPEventContext::item_handler(item, event); - - return ret; -} +//gint SPZoomContext::item_handler(SPItem* item, GdkEvent* event) { +// gint ret = FALSE; +// +// ret = SPEventContext::item_handler(item, event); +// +// return ret; +//} gint SPZoomContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPDesktop *desktop = event_context->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - SPZoomContext *zc = SP_ZOOM_CONTEXT(event_context); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10); @@ -122,7 +101,8 @@ gint SPZoomContext::root_handler(GdkEvent* event) { { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - if (event->button.button == 1 && !event_context->space_panning) { + + if (event->button.button == 1 && !this->space_panning) { // save drag origin xp = (gint) event->button.x; yp = (gint) event->button.y; @@ -137,6 +117,7 @@ gint SPZoomContext::root_handler(GdkEvent* event) { double const zoom_rel( (event->button.state & GDK_SHIFT_MASK) ? zoom_inc : 1 / zoom_inc ); + desktop->zoom_relative_keep_point(button_dt, zoom_rel); ret = TRUE; } @@ -144,13 +125,13 @@ gint SPZoomContext::root_handler(GdkEvent* event) { sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - zc->grabbed = SP_CANVAS_ITEM(desktop->acetate); - + + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); break; } case GDK_MOTION_NOTIFY: - if ((event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { + if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { ret = TRUE; if ( within_tolerance @@ -174,23 +155,28 @@ gint SPZoomContext::root_handler(GdkEvent* event) { { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - if ( event->button.button == 1 && !event_context->space_panning) { + + if ( event->button.button == 1 && !this->space_panning) { Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle(); + if (b && !within_tolerance) { desktop->set_display_area(*b, 10); } else if (!escaped) { double const zoom_rel( (event->button.state & GDK_SHIFT_MASK) ? 1 / zoom_inc : zoom_inc ); + desktop->zoom_relative_keep_point(button_dt, zoom_rel); } + ret = TRUE; - } + } + Inkscape::Rubberband::get(desktop)->stop(); - if (zc->grabbed) { - sp_canvas_item_ungrab(zc->grabbed, event->button.time); - zc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } xp = yp = 0; @@ -203,11 +189,13 @@ gint SPZoomContext::root_handler(GdkEvent* event) { if (!Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::SelectionHelper::selectNone(desktop); } + Inkscape::Rubberband::get(desktop)->stop(); xp = yp = 0; escaped = true; ret = TRUE; break; + case GDK_KEY_Up: case GDK_KEY_Down: case GDK_KEY_KP_Up: @@ -216,15 +204,17 @@ gint SPZoomContext::root_handler(GdkEvent* event) { if (!MOD__CTRL_ONLY) ret = TRUE; break; + case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - event_context->cursor_shape = cursor_zoom_out_xpm; - sp_event_context_update_cursor(event_context); + this->cursor_shape = cursor_zoom_out_xpm; + sp_event_context_update_cursor(this); break; + case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; default: @@ -233,23 +223,20 @@ gint SPZoomContext::root_handler(GdkEvent* event) { break; case GDK_KEY_RELEASE: switch (get_group0_keyval (&event->key)) { - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - event_context->cursor_shape = cursor_zoom_xpm; - sp_event_context_update_cursor(event_context); + case GDK_KEY_Shift_L: + case GDK_KEY_Shift_R: + this->cursor_shape = cursor_zoom_xpm; + sp_event_context_update_cursor(this); break; - default: + default: break; - } + } break; default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } diff --git a/src/zoom-context.h b/src/zoom-context.h index 402ce0995..f5f2145b1 100644 --- a/src/zoom-context.h +++ b/src/zoom-context.h @@ -31,7 +31,7 @@ public: virtual void setup(); virtual void finish(); virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + //virtual gint item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); }; |
