X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fconnector-context.cpp;h=10312c41104479d99540d71ab9dfede92eb89a00;hb=4832d71a0d49fe090b917e233370be20d1d72884;hp=d8e7b879710430e9cf72a80dd36b7335ed9fbecb;hpb=6129af7cc5b723223e9617614c931936e5190421;p=inkscape.git diff --git a/src/connector-context.cpp b/src/connector-context.cpp index d8e7b8797..10312c411 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -17,13 +17,14 @@ * an object involves going inside C but without entering S.) * o Draw connectors to shape edges rather than bounding box. * o Show a visual indicator for objects with the 'avoid' property set. + * o Allow user to change a object between a path and connector through + * the interface. * o Create an interface for setting markers (arrow heads). * o Better distinguish between paths and connectors to prevent problems * in the node tool and paths accidently being turned into connectors * in the connector tool. Perhaps have a way to convert between. * o Only call libavoid's updateEndPoint as required. Currently we do it * for both endpoints, even if only one is moving. - * o Cleanup to remove unecessary borrowed DrawContext code. * o Allow user-placeable connection points. * o Deal sanely with connectors with both endpoints attached to the * same connection point, and drawing of connectors attaching @@ -67,7 +68,9 @@ #include "conn-avoid-ref.h" #include "libavoid/vertices.h" #include "context-fns.h" - +#include "sp-namedview.h" +#include "sp-text.h" +#include "sp-flowtext.h" static void sp_connector_context_class_init(SPConnectorContextClass *klass); @@ -522,7 +525,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const if (!cc->sid) { // 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); + SnapManager const &m = cc->desktop->namedview->snap_manager; p = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT, p, NULL).getPoint(); } @@ -955,6 +958,8 @@ static gboolean cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) { g_assert (knot != NULL); + + g_object_ref(knot); SPConnectorContext *cc = SP_CONNECTOR_CONTEXT( knot->desktop->event_context); @@ -963,11 +968,8 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) switch (event->type) { case GDK_ENTER_NOTIFY: - gtk_object_set (GTK_OBJECT (knot->item), "fill_color", - knot->fill [SP_KNOT_STATE_MOUSEOVER], NULL); - gtk_object_set (GTK_OBJECT (knot->item), "stroke_color", - knot->stroke [SP_KNOT_STATE_MOUSEOVER], NULL); - + sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE); + cc->active_handle = knot; if (knot->tip) @@ -975,26 +977,25 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) knot->desktop->event_context->defaultMessageContext()->set( Inkscape::NORMAL_MESSAGE, knot->tip); } - + consumed = TRUE; break; case GDK_LEAVE_NOTIFY: - gtk_object_set (GTK_OBJECT (knot->item), "fill_color", - knot->fill [SP_KNOT_STATE_NORMAL], NULL); - gtk_object_set (GTK_OBJECT (knot->item), "stroke_color", - knot->stroke [SP_KNOT_STATE_NORMAL], NULL); + sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE); cc->active_handle = NULL; - + if (knot->tip) { knot->desktop->event_context->defaultMessageContext()->clear(); } - + consumed = TRUE; break; default: break; } + + g_object_unref(knot); return consumed; } @@ -1080,32 +1081,23 @@ static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item) // Set center connection point. if ( cc->connpthandle == NULL ) { - SPKnot * knot = (SPKnot*)g_object_new (SP_TYPE_KNOT, 0); - - knot->desktop = cc->desktop; - knot->flags = SP_KNOT_VISIBLE; + SPKnot *knot = sp_knot_new(cc->desktop, + _("Connection point: click or drag to create a new connector")); - knot->item = sp_canvas_item_new (sp_desktop_controls(cc->desktop), - SP_TYPE_CTRL, - "anchor", GTK_ANCHOR_CENTER, - "filled", TRUE, - "stroked", TRUE, - "mode", SP_KNOT_MODE_XOR, - NULL); + knot->setShape(SP_KNOT_SHAPE_SQUARE); + knot->setSize(8); + knot->setAnchor(GTK_ANCHOR_CENTER); + knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); + sp_knot_update_ctrl(knot); - gtk_signal_connect (GTK_OBJECT (knot->item), "event", - GTK_SIGNAL_FUNC (cc_generic_knot_handler), knot); + // We don't want to use the standard knot handler, + //since we don't want this knot to be draggable. + g_signal_handler_disconnect(G_OBJECT(knot->item), + knot->_event_handler_id); + knot->_event_handler_id = 0; - knot->fill [SP_KNOT_STATE_NORMAL] = 0xffffff00; - knot->fill [SP_KNOT_STATE_MOUSEOVER] = 0xff0000ff; - knot->stroke [SP_KNOT_STATE_NORMAL] = 0x01000000; - - g_object_set(G_OBJECT(knot), - "shape", SP_KNOT_SHAPE_SQUARE, - "size", 8, - "anchor", GTK_ANCHOR_CENTER, - "tip", _("Connection point: click or drag to create a new connector"), - NULL); + gtk_signal_connect(GTK_OBJECT(knot->item), "event", + GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot); cc->connpthandle = knot; } @@ -1160,32 +1152,24 @@ cc_set_active_conn(SPConnectorContext *cc, SPItem *item) // Create the handle if it doesn't exist if ( cc->endpt_handle[i] == NULL ) { - SPKnot * knot = (SPKnot*) g_object_new (SP_TYPE_KNOT, 0); - - knot->desktop = cc->desktop; - knot->flags = SP_KNOT_VISIBLE; - - knot->item = sp_canvas_item_new (sp_desktop_controls (cc->desktop), - SP_TYPE_CTRL, - "anchor", GTK_ANCHOR_CENTER, - "filled", TRUE, - "stroked", TRUE, - "mode", SP_KNOT_MODE_XOR, - NULL); + SPKnot *knot = sp_knot_new(cc->desktop, + _("Connector endpoint: drag to reroute or connect to new shapes")); - knot->fill [SP_KNOT_STATE_NORMAL] = 0xffffff00; - knot->stroke [SP_KNOT_STATE_NORMAL] = 0x000000ff; - knot->stroke [SP_KNOT_STATE_DRAGGING] = 0x000000ff; - knot->stroke [SP_KNOT_STATE_MOUSEOVER] = 0x000000ff; + knot->setShape(SP_KNOT_SHAPE_SQUARE); + knot->setSize(7); + knot->setAnchor(GTK_ANCHOR_CENTER); + knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); + knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); + sp_knot_update_ctrl(knot); - g_object_set(G_OBJECT(knot), - "shape", SP_KNOT_SHAPE_DIAMOND, - "size", 10, - "tip", _("Connector endpoint: drag to reroute or connect to new shapes"), - NULL); + // We don't want to use the standard knot handler, + //since we don't want this knot to be draggable. + g_signal_handler_disconnect(G_OBJECT(knot->item), + knot->_event_handler_id); + knot->_event_handler_id = 0; - gtk_signal_connect (GTK_OBJECT (knot->item), "event", - GTK_SIGNAL_FUNC (cc_generic_knot_handler), knot); + gtk_signal_connect(GTK_OBJECT(knot->item), "event", + GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot); cc->endpt_handle[i] = knot; } @@ -1226,6 +1210,12 @@ static bool cc_item_is_shape(SPItem *item) return false; } } + else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { + if (prefs_get_int_attribute("tools.connector", "ignoretext", 1) == 1) { + // Don't count text as a shape we can connect connector to. + return false; + } + } return true; }