X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fconnector-context.cpp;h=6da465f2a48691557a97d0ffb71f5bbd95bc4030;hb=57eb32794c2df43d60ee8f0a9aa8576567358ce6;hp=9d15ce10a3a4367821580c977640f674c27e8a19;hpb=3caca4f8381f7ae35678d16074c2414c02a0c0ff;p=inkscape.git diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 9d15ce10a..6da465f2a 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -42,6 +42,8 @@ */ #include +#include +#include #include "connector-context.h" #include "pixmaps/cursor-connector.xpm" @@ -104,6 +106,8 @@ static void cc_clear_active_conn(SPConnectorContext *cc); static gchar *conn_pt_handle_test(SPConnectorContext *cc, NR::Point& w); static bool cc_item_is_shape(SPItem *item); static void cc_selection_changed(Inkscape::Selection *selection, gpointer data); +static void cc_connector_rerouting_finish(SPConnectorContext *const cc, + NR::Point *const p); static void shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data); @@ -386,19 +390,19 @@ conn_pt_handle_test(SPConnectorContext *cc, NR::Point& p) static gint -sp_connector_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) +sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { gint ret = FALSE; - SPDesktop *desktop = ec->desktop; + SPDesktop *desktop = event_context->desktop; - SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); + SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context); NR::Point p(event->button.x, event->button.y); switch (event->type) { case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { + if (event->button.button == 1 && !event_context->space_panning) { if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) && (connector_within_tolerance)) { @@ -487,9 +491,10 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const NR::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ NR::Point p = cc->desktop->w2d(event_w); + SPEventContext *event_context = SP_EVENT_CONTEXT(cc); gint ret = FALSE; - if ( bevent.button == 1 ) { + if ( bevent.button == 1 && !event_context->space_panning ) { SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); @@ -526,7 +531,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const // This is the first point, so just snap it to the grid // as there's no other points to go off. SnapManager const &m = cc->desktop->namedview->snap_manager; - p = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT, + p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint(); } spcc_connector_set_initial_point(cc, p); @@ -561,7 +566,17 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const break; } } else if (bevent.button == 3) { - if (cc->npoints != 0) { + if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { + // A context menu is going to be triggered here, + // so end the rerouting operation. + cc_connector_rerouting_finish(cc, &p); + + cc->state = SP_CONNECTOR_CONTEXT_IDLE; + + // Don't set ret to TRUE, so we drop through to the + // parent handler which will open the context menu. + } + else if (cc->npoints != 0) { spcc_connector_finish(cc); ret = TRUE; } @@ -574,8 +589,9 @@ static gint connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent) { gint ret = FALSE; + SPEventContext *event_context = SP_EVENT_CONTEXT(cc); - if (mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow middle-button scrolling return FALSE; } @@ -653,7 +669,8 @@ static gint connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent) { gint ret = FALSE; - if ( revent.button == 1 ) { + SPEventContext *event_context = SP_EVENT_CONTEXT(cc); + if ( revent.button == 1 && !event_context->space_panning ) { SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); SPDocument *doc = sp_desktop_document(desktop); @@ -686,30 +703,8 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con } case SP_CONNECTOR_CONTEXT_REROUTING: { - // Clear the temporary path: - sp_curve_reset(cc->red_curve); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); - - // Test whether we clicked on a connection point - gchar *shape_label = conn_pt_handle_test(cc, p); - - if (shape_label) { - if (cc->clickedhandle == cc->endpt_handle[0]) { - sp_object_setAttribute(cc->clickeditem, - "inkscape:connection-start",shape_label, false); - } - else { - sp_object_setAttribute(cc->clickeditem, - "inkscape:connection-end",shape_label, false); - } - g_free(shape_label); - } - cc->clickeditem->setHidden(false); - sp_conn_adjust_path(SP_PATH(cc->clickeditem)); - cc->clickeditem->updateRepr(); - sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, - _("Reroute connector")); - cc_set_active_conn(cc, cc->clickeditem); + cc_connector_rerouting_finish(cc, &p); + sp_document_ensure_up_to_date(doc); cc->state = SP_CONNECTOR_CONTEXT_IDLE; return TRUE; @@ -742,7 +737,21 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) } break; case GDK_Escape: - if (cc->npoints != 0) { + if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { + + SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); + SPDocument *doc = sp_desktop_document(desktop); + + cc_connector_rerouting_finish(cc, NULL); + + sp_document_undo(doc); + + cc->state = SP_CONNECTOR_CONTEXT_IDLE; + desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, + _("Connector endpoint drag cancelled.")); + ret = TRUE; + } + else if (cc->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting cc->state = SP_CONNECTOR_CONTEXT_STOP; spcc_reset_colors(cc); @@ -756,6 +765,42 @@ connector_handle_key_press(SPConnectorContext *const cc, guint const keyval) } +static void +cc_connector_rerouting_finish(SPConnectorContext *const cc, NR::Point *const p) +{ + SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc); + SPDocument *doc = sp_desktop_document(desktop); + + // Clear the temporary path: + sp_curve_reset(cc->red_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); + + if (p != NULL) + { + // Test whether we clicked on a connection point + gchar *shape_label = conn_pt_handle_test(cc, *p); + + if (shape_label) { + if (cc->clickedhandle == cc->endpt_handle[0]) { + sp_object_setAttribute(cc->clickeditem, + "inkscape:connection-start",shape_label, false); + } + else { + sp_object_setAttribute(cc->clickeditem, + "inkscape:connection-end",shape_label, false); + } + g_free(shape_label); + } + } + cc->clickeditem->setHidden(false); + sp_conn_adjust_path(SP_PATH(cc->clickeditem)); + cc->clickeditem->updateRepr(); + sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, + _("Reroute connector")); + cc_set_active_conn(cc, cc->clickeditem); +} + + static void spcc_reset_colors(SPConnectorContext *cc) { @@ -922,7 +967,7 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc) static void -spcc_connector_finish_segment(SPConnectorContext *const cc, NR::Point const p) +spcc_connector_finish_segment(SPConnectorContext *const cc, NR::Point const /*p*/) { if (!sp_curve_empty(cc->red_curve)) { sp_curve_append_continuous(cc->green_curve, cc->red_curve, 0.0625); @@ -1004,7 +1049,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) static gboolean -endpt_handler(SPKnot *knot, GdkEvent *event, SPConnectorContext *cc) +endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc) { g_assert( SP_IS_CONNECTOR_CONTEXT(cc) ); @@ -1105,12 +1150,14 @@ static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item) } - NR::Rect bbox = sp_item_bbox_desktop(cc->active_shape); - NR::Point center = bbox.midpoint(); - sp_knot_set_position(cc->connpthandle, ¢er, 0); - - sp_knot_show(cc->connpthandle); - + NR::Maybe bbox = sp_item_bbox_desktop(cc->active_shape); + if (bbox) { + NR::Point center = bbox->midpoint(); + sp_knot_set_position(cc->connpthandle, ¢er, 0); + sp_knot_show(cc->connpthandle); + } else { + sp_knot_hide(cc->connpthandle); + } } @@ -1303,8 +1350,8 @@ cc_selection_changed(Inkscape::Selection *selection, gpointer data) static void -shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, - Inkscape::XML::Node *ref, gpointer data) +shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child, + Inkscape::XML::Node */*ref*/, gpointer data) { g_assert(data); SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data); @@ -1318,8 +1365,8 @@ shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, - gchar const *old_value, gchar const *new_value, - bool is_interactive, gpointer data) + gchar const */*old_value*/, gchar const */*new_value*/, + bool /*is_interactive*/, gpointer data) { g_assert(data); SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);