Code

Remove redundancy from snapping API (type of snapsource no longer has to be specified...
[inkscape.git] / src / connector-context.cpp
1 /*
2  * Connector creation tool
3  *
4  * Authors:
5  *   Michael Wybrow <mjwybrow@users.sourceforge.net>
6  *
7  * Copyright (C) 2005-2008  Michael Wybrow
8  * Copyright (C) 2009  Monash University
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  *
12  * TODO:
13  *  o  Show a visual indicator for objects with the 'avoid' property set.
14  *  o  Allow user to change a object between a path and connector through
15  *     the interface.
16  *  o  Create an interface for setting markers (arrow heads).
17  *  o  Better distinguish between paths and connectors to prevent problems
18  *     in the node tool and paths accidentally being turned into connectors
19  *     in the connector tool.  Perhaps have a way to convert between.
20  *  o  Only call libavoid's updateEndPoint as required.  Currently we do it
21  *     for both endpoints, even if only one is moving.
22  *  o  Allow user-placeable connection points.
23  *  o  Deal sanely with connectors with both endpoints attached to the
24  *     same connection point, and drawing of connectors attaching
25  *     overlapping shapes (currently tries to adjust connector to be
26  *     outside both bounding boxes).
27  *  o  Fix many special cases related to connectors updating,
28  *     e.g., copying a couple of shapes and a connector that are
29  *           attached to each other.
30  *     e.g., detach connector when it is moved or transformed in
31  *           one of the other contexts.
32  *  o  Cope with shapes whose ids change when they have attached
33  *     connectors.
34  *  o  During dragging motion, gobble up to and use the final motion event.
35  *     Gobbling away all duplicates after the current can occasionally result
36  *     in the path lagging behind the mouse cursor if it is no longer being
37  *     dragged.
38  *  o  Fix up libavoid's representation after undo actions.  It doesn't see
39  *     any transform signals and hence doesn't know shapes have moved back to
40  *     there earlier positions.
41  *  o  Decide whether drawing/editing mode should be an Inkscape preference
42  *     or the connector tool should always start in drawing mode.
43  *  o  Correct the problem with switching to the select tool when pressing
44  *     space bar (there are moments when it refuses to do so).
45  *
46  * ----------------------------------------------------------------------------
47  *
48  * mjwybrow's observations on acracan's Summer of Code connector work:
49  *
50  *  -  GUI comments:
51  *
52  *      -  Buttons for adding and removing user-specified connection
53  *      points should probably have "+" and "-" symbols on them so they
54  *      are consistent with the similar buttons for the node tool.
55  *      -  Controls on the connector tool be should be reordered logically,
56  *      possibly as follows:
57  *
58  *      *Connector*: [Polyline-radio-button] [Orthgonal-radio-button]
59  *        [Curvature-control] | *Shape*: [Avoid-button] [Dont-avoid-button]
60  *        [Spacing-control] | *Connection pts*: [Edit-mode] [Add-pt] [Rm-pt]
61  *
62  *      I think that the network layout controls be moved to the
63  *      Align and Distribute dialog (there is already the layout button
64  *      there, but no options are exposed).
65  *
66  *      I think that the style change between polyline and orthogonal
67  *      would be much clearer with two buttons (radio behaviour -- just
68  *      one is true).
69  *
70  *      The other tools show a label change from "New:" to "Change:"
71  *      depending on whether an object is selected.  We could consider
72  *      this but there may not be space.
73  *
74  *      The Add-pt and Rm-pt buttons should be greyed out (inactive) if
75  *      we are not in connection point editing mode.  And probably also
76  *      if there is no shape selected, i.e. at the times they have no
77  *      effect when clicked.
78  *
79  *      Likewise for the avoid/ignore shapes buttons.  These should be
80  *      inactive when a shape is not selected in the connector context.
81  *
82  *  -  When creating/editing connection points:
83  *
84  *      -  Strange things can happen if you have connectors selected, or
85  *      try rerouting connectors by dragging their endpoints when in
86  *      connection point editing mode.
87  *
88  *      -  Possibly the selected shape's connection points should always
89  *      be shown (i.e., have knots) when in editing mode.
90  *
91  *      -  It is a little strange to be able to place connection points
92  *      competely outside shapes.  Especially when you later can't draw
93  *      connectors to them since the knots are only visible when you
94  *      are over the shape.  I think that you should only be able to
95  *      place connection points inside or on the boundary of the shape
96  *      itself.
97  *
98  *      -  The intended ability to place a new point at the current cursor
99  *      position by pressing RETURN does not seem to work.
100  *
101  *      -  The Status bar tooltip should change to reflect editing mode
102  *      and tell the user about RETURN and how to use the tool.
103  *
104  *  -  Connection points general:
105  *
106  *      -  Connection points that were inside the shape can end up outside
107  *      after a rotation is applied to the shape in the select tool.
108  *      It doesn't seem like the correct transform is being applied to
109  *      these, or it is being applied at the wrong time.  I'd expect
110  *      connection points to rotate with the shape, and stay at the
111  *      same position "on the shape"
112  *
113  *      -  I was able to make the connectors attached to a shape fall off
114  *      the shape after scaling it.  Not sure the exact cause, but may
115  *      require more investigation/debugging.
116  *
117  *      -  The user-defined connection points should be either absolute
118  *      (as the current ones are) or defined as a percentage of the
119  *      shape.  These would be based on a toggle setting on the
120  *      toolbar, and they would be placed in exactly the same way by
121  *      the user.  The only difference would be that they would be
122  *      store as percentage positions in the SVG connection-points
123  *      property and that they would update/move automatically if the
124  *      object was resized or scaled.
125  *
126  *      -  Thinking more, I think you always want to store and think about
127  *      the positions of connection points to be pre-transform, but
128  *      obviously the shape transform is applied to them.  That way,
129  *      they will rotate and scale automatically with the shape, when
130  *      the shape transform is altered.  The Percentage version would
131  *      compute their position from the pre-transform dimensions and
132  *      then have the transform applied to them, for example.
133  *
134  *      -  The connection points in the test_connection_points.svg file
135  *      seem to follow the shape when it is moved, but connection
136  *      points I add to new shapes, do not follow the shape, either
137  *      when the shape is just moved or transformed.  There is
138  *      something wrong here.  What exactly should the behaviour be
139  *      currently?
140  *
141  *      -  I see that connection points are specified at absolute canvas
142  *      positions.  I really think that they should be specified in
143  *      shape coordinated relative to the shapes.  There may be
144  *      transforms applied to layers and the canvas which would make
145  *      specifying them quite difficult.  I'd expect a position of 0, 0
146  *      to be on the shape in question or very close to it, for example.
147  *
148  */
152 #include <gdk/gdkkeysyms.h>
153 #include <string>
154 #include <cstring>
156 #include "connector-context.h"
157 #include "pixmaps/cursor-connector.xpm"
158 #include "pixmaps/cursor-node.xpm"
159 //#include "pixmaps/cursor-node-m.xpm"
160 //#include "pixmaps/cursor-node-d.xpm"
161 #include "xml/node-event-vector.h"
162 #include "xml/repr.h"
163 #include "svg/svg.h"
164 #include "desktop.h"
165 #include "desktop-style.h"
166 #include "desktop-handles.h"
167 #include "document.h"
168 #include "message-context.h"
169 #include "message-stack.h"
170 #include "selection.h"
171 #include "inkscape.h"
172 #include "preferences.h"
173 #include "sp-path.h"
174 #include "display/canvas-bpath.h"
175 #include "display/sodipodi-ctrl.h"
176 #include <glibmm/i18n.h>
177 #include <glibmm/stringutils.h>
178 #include "snap.h"
179 #include "knot.h"
180 #include "sp-conn-end.h"
181 #include "sp-conn-end-pair.h"
182 #include "conn-avoid-ref.h"
183 #include "libavoid/vertices.h"
184 #include "libavoid/router.h"
185 #include "context-fns.h"
186 #include "sp-namedview.h"
187 #include "sp-text.h"
188 #include "sp-flowtext.h"
189 #include "display/curve.h"
191 static void sp_connector_context_class_init(SPConnectorContextClass *klass);
192 static void sp_connector_context_init(SPConnectorContext *conn_context);
193 static void sp_connector_context_dispose(GObject *object);
195 static void sp_connector_context_setup(SPEventContext *ec);
196 static void sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
197 static void sp_connector_context_finish(SPEventContext *ec);
198 static gint sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event);
199 static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
201 // Stuff borrowed from DrawContext
202 static void spcc_connector_set_initial_point(SPConnectorContext *cc, Geom::Point const p);
203 static void spcc_connector_set_subsequent_point(SPConnectorContext *cc, Geom::Point const p);
204 static void spcc_connector_finish_segment(SPConnectorContext *cc, Geom::Point p);
205 static void spcc_reset_colors(SPConnectorContext *cc);
206 static void spcc_connector_finish(SPConnectorContext *cc);
207 static void spcc_concat_colors_and_flush(SPConnectorContext *cc);
208 static void spcc_flush_white(SPConnectorContext *cc, SPCurve *gc);
210 // Context event handlers
211 static gint connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent);
212 static gint connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent);
213 static gint connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent);
214 static gint connector_handle_key_press(SPConnectorContext *const cc, guint const keyval);
216 static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp);
217 static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item);
218 static void cc_clear_active_shape(SPConnectorContext *cc);
219 static void cc_set_active_conn(SPConnectorContext *cc, SPItem *item);
220 static void cc_clear_active_conn(SPConnectorContext *cc);
221 static gchar *conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& w);
222 static void cc_select_handle(SPKnot* knot);
223 static void cc_deselect_handle(SPKnot* knot);
224 static bool cc_item_is_shape(SPItem *item);
225 static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
226 static void cc_connector_rerouting_finish(SPConnectorContext *const cc,
227         Geom::Point *const p);
229 static void shape_event_attr_deleted(Inkscape::XML::Node *repr,
230         Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
231 static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
232         gchar const *old_value, gchar const *new_value, bool is_interactive,
233         gpointer data);
236 /*static Geom::Point connector_drag_origin_w(0, 0);
237 static bool connector_within_tolerance = false;*/
238 static SPEventContextClass *parent_class;
241 static Inkscape::XML::NodeEventVector shape_repr_events = {
242     NULL, /* child_added */
243     NULL, /* child_added */
244     shape_event_attr_changed,
245     NULL, /* content_changed */
246     NULL  /* order_changed */
247 };
249 static Inkscape::XML::NodeEventVector layer_repr_events = {
250     NULL, /* child_added */
251     shape_event_attr_deleted,
252     NULL, /* child_added */
253     NULL, /* content_changed */
254     NULL  /* order_changed */
255 };
258 GType
259 sp_connector_context_get_type(void)
261     static GType type = 0;
262     if (!type) {
263         GTypeInfo info = {
264             sizeof(SPConnectorContextClass),
265             NULL, NULL,
266             (GClassInitFunc) sp_connector_context_class_init,
267             NULL, NULL,
268             sizeof(SPConnectorContext),
269             4,
270             (GInstanceInitFunc) sp_connector_context_init,
271             NULL,   /* value_table */
272         };
273         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPConnectorContext", &info, (GTypeFlags)0);
274     }
275     return type;
278 static void
279 sp_connector_context_class_init(SPConnectorContextClass *klass)
281     GObjectClass *object_class;
282     SPEventContextClass *event_context_class;
284     object_class = (GObjectClass *) klass;
285     event_context_class = (SPEventContextClass *) klass;
287     parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
289     object_class->dispose = sp_connector_context_dispose;
291     event_context_class->setup = sp_connector_context_setup;
292     event_context_class->set = sp_connector_context_set;
293     event_context_class->finish = sp_connector_context_finish;
294     event_context_class->root_handler = sp_connector_context_root_handler;
295     event_context_class->item_handler = sp_connector_context_item_handler;
299 static void
300 sp_connector_context_init(SPConnectorContext *cc)
302     SPEventContext *ec = SP_EVENT_CONTEXT(cc);
304     ec->cursor_shape = cursor_connector_xpm;
305     ec->hot_x = 1;
306     ec->hot_y = 1;
307     ec->xp = 0;
308     ec->yp = 0;
310     cc->mode = SP_CONNECTOR_CONTEXT_DRAWING_MODE;
311     cc->knot_tip = 0;
313     cc->red_color = 0xff00007f;
315     cc->newconn = NULL;
316     cc->newConnRef = NULL;
317     cc->curvature = 0.0;
319     cc->sel_changed_connection = sigc::connection();
321     cc->active_shape = NULL;
322     cc->active_shape_repr = NULL;
323     cc->active_shape_layer_repr = NULL;
325     cc->active_conn = NULL;
326     cc->active_conn_repr = NULL;
328     cc->active_handle = NULL;
330     cc->selected_handle = NULL;
332     cc->clickeditem = NULL;
333     cc->clickedhandle = NULL;
335     new (&cc->connpthandles) ConnectionPointMap();
337     for (int i = 0; i < 2; ++i) {
338         cc->endpt_handle[i] = NULL;
339         cc->endpt_handler_id[i] = 0;
340     }
341     cc->sid = NULL;
342     cc->eid = NULL;
343     cc->npoints = 0;
344     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
348 static void
349 sp_connector_context_dispose(GObject *object)
351     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(object);
353     cc->sel_changed_connection.disconnect();
355     if (!cc->connpthandles.empty()) {
356         for (ConnectionPointMap::iterator it = cc->connpthandles.begin();
357                 it != cc->connpthandles.end(); ++it) {
358             g_object_unref(it->first);
359         }
360         cc->connpthandles.clear();
361     }
362     cc->connpthandles.~ConnectionPointMap();
363     for (int i = 0; i < 2; ++i) {
364         if (cc->endpt_handle[1]) {
365             g_object_unref(cc->endpt_handle[i]);
366             cc->endpt_handle[i] = NULL;
367         }
368     }
369     if (cc->sid) {
370         g_free(cc->sid);
371         cc->sid = NULL;
372     }
373     if (cc->eid) {
374         g_free(cc->eid);
375         cc->eid = NULL;
376     }
377     g_assert( cc->newConnRef == NULL );
379     G_OBJECT_CLASS(parent_class)->dispose(object);
383 static void
384 sp_connector_context_setup(SPEventContext *ec)
386     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
387     SPDesktop *dt = ec->desktop;
389     if (((SPEventContextClass *) parent_class)->setup) {
390         ((SPEventContextClass *) parent_class)->setup(ec);
391     }
393     cc->selection = sp_desktop_selection(dt);
395     cc->sel_changed_connection.disconnect();
396     cc->sel_changed_connection = cc->selection->connectChanged(
397             sigc::bind(sigc::ptr_fun(&cc_selection_changed),
398             (gpointer) cc));
400     /* Create red bpath */
401     cc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
402     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cc->red_bpath), cc->red_color,
403             1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
404     sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cc->red_bpath), 0x00000000,
405             SP_WIND_RULE_NONZERO);
406     /* Create red curve */
407     cc->red_curve = new SPCurve();
409     /* Create green curve */
410     cc->green_curve = new SPCurve();
412     // Notice the initial selection.
413     cc_selection_changed(cc->selection, (gpointer) cc);
415     cc->within_tolerance = false;
417     sp_event_context_read(ec, "curvature");
418     sp_event_context_read(ec, "orthogonal");
419     sp_event_context_read(ec, "mode");
420     cc->knot_tip = cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE ? cc_knot_tips[0] : cc_knot_tips[1];
421     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
422     if (prefs->getBool("/tools/connector/selcue", 0)) {
423         ec->enableSelectionCue();
424     }
426     // Make sure we see all enter events for canvas items,
427     // even if a mouse button is depressed.
428     dt->canvas->gen_all_enter_events = true;
432 static void
433 sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
435     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
437     /* fixme: Proper error handling for non-numeric data.  Use a locale-independent function like
438      * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */
439     Glib::ustring name = val->getEntryName();
440     if ( name == "curvature" ) {
441         cc->curvature = val->getDoubleLimited(); // prevents NaN and +/-Inf from messing up
442     }
443     else if ( name == "orthogonal" ) {
444         cc->isOrthogonal = val->getBool();
445     }
446     else if ( name == "mode")
447     {
448         sp_connector_context_switch_mode(ec, val->getBool() ? SP_CONNECTOR_CONTEXT_EDITING_MODE : SP_CONNECTOR_CONTEXT_DRAWING_MODE);
449     }
452 void sp_connector_context_switch_mode(SPEventContext* ec, unsigned int newMode)
454     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
456     cc->mode = newMode;
457     if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
458     {
459         ec->cursor_shape = cursor_connector_xpm;
460         cc->knot_tip = cc_knot_tips[0];
461         if (cc->selected_handle)
462             cc_deselect_handle( cc->selected_handle );
463         cc->selected_handle = NULL;
464         // Show all default connection points
466     }
467     else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
468     {
469         ec->cursor_shape = cursor_node_xpm;
470         cc->knot_tip = cc_knot_tips[1];
471 /*            if (cc->active_shape)
472         {
473             cc->selection->set( SP_OBJECT( cc->active_shape ) );
474         }
475         else
476         {
477             SPItem* item = cc->selection->singleItem();
478             if ( item )
479             {
480                 cc_set_active_shape(cc, item);
481                 cc->selection->set( SP_OBJECT( item ) );
482             }
483         }*/
484     }
485     sp_event_context_update_cursor(ec);
490 static void
491 sp_connector_context_finish(SPEventContext *ec)
493     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
495     spcc_connector_finish(cc);
496     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
498     if (((SPEventContextClass *) parent_class)->finish) {
499         ((SPEventContextClass *) parent_class)->finish(ec);
500     }
502     if (cc->selection) {
503         cc->selection = NULL;
504     }
505     cc_clear_active_shape(cc);
506     cc_clear_active_conn(cc);
508     // Restore the default event generating behaviour.
509     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
510     desktop->canvas->gen_all_enter_events = false;
514 //-----------------------------------------------------------------------------
517 static void
518 cc_clear_active_shape(SPConnectorContext *cc)
520     if (cc->active_shape == NULL) {
521         return;
522     }
523     g_assert( cc->active_shape_repr );
524     g_assert( cc->active_shape_layer_repr );
526     cc->active_shape = NULL;
528     if (cc->active_shape_repr) {
529         sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
530         Inkscape::GC::release(cc->active_shape_repr);
531         cc->active_shape_repr = NULL;
533         sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc);
534         Inkscape::GC::release(cc->active_shape_layer_repr);
535         cc->active_shape_layer_repr = NULL;
536     }
538     // Hide the connection points if they exist.
539     if (cc->connpthandles.size()) {
540         for (ConnectionPointMap::iterator it = cc->connpthandles.begin();
541                 it != cc->connpthandles.end(); ++it) {
542             sp_knot_hide(it->first);
543         }
544     }
548 static void
549 cc_clear_active_conn(SPConnectorContext *cc)
551     if (cc->active_conn == NULL) {
552         return;
553     }
554     g_assert( cc->active_conn_repr );
556     cc->active_conn = NULL;
558     if (cc->active_conn_repr) {
559         sp_repr_remove_listener_by_data(cc->active_conn_repr, cc);
560         Inkscape::GC::release(cc->active_conn_repr);
561         cc->active_conn_repr = NULL;
562     }
564     // Hide the endpoint handles.
565     for (int i = 0; i < 2; ++i) {
566         if (cc->endpt_handle[i]) {
567             sp_knot_hide(cc->endpt_handle[i]);
568         }
569     }
573 static gchar *
574 conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p)
576     // TODO: this will need to change when there are more connection
577     //       points available for each shape.
579     if (cc->active_handle && (cc->connpthandles.find(cc->active_handle) != cc->connpthandles.end()))
580     {
581         p = cc->active_handle->pos;
582         const ConnectionPoint& cp = cc->connpthandles[cc->active_handle];
583         return g_strdup_printf("#%s_%c_%d", SP_OBJECT_ID(cc->active_shape),
584                                cp.type == ConnPointDefault ? 'd' : 'u' , cp.id);
585     }
586     return NULL;
589 static void
590 cc_select_handle(SPKnot* knot)
592     knot->setShape(SP_KNOT_SHAPE_SQUARE);
593     knot->setSize(10);
594     knot->setAnchor(GTK_ANCHOR_CENTER);
595     knot->setFill(0x0000ffff, 0x0000ffff, 0x0000ffff);
596     sp_knot_update_ctrl(knot);
599 static void
600 cc_deselect_handle(SPKnot* knot)
602     knot->setShape(SP_KNOT_SHAPE_SQUARE);
603     knot->setSize(8);
604     knot->setAnchor(GTK_ANCHOR_CENTER);
605     knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
606     sp_knot_update_ctrl(knot);
609 static gint
610 sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
612     gint ret = FALSE;
614     SPDesktop *desktop = event_context->desktop;
616     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context);
618     Geom::Point p(event->button.x, event->button.y);
620     switch (event->type) {
621         case GDK_BUTTON_RELEASE:
622             if (event->button.button == 1 && !event_context->space_panning) {
623                 if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
624                         (event_context->within_tolerance))
625                 {
626                     spcc_reset_colors(cc);
627                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
628                 }
629                 if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) {
630                     // Doing something else like rerouting.
631                     break;
632                 }
633                 // find out clicked item, honoring Alt
634                 SPItem *item = sp_event_context_find_item(desktop,
635                         p, event->button.state & GDK_MOD1_MASK, FALSE);
637                 if (event->button.state & GDK_SHIFT_MASK) {
638                     cc->selection->toggle(item);
639                 } else {
640                     cc->selection->set(item);
641                     if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && cc->selected_handle )
642                     {
643                         cc_deselect_handle( cc->selected_handle );
644                         cc->selected_handle = NULL;
645                     }
646                     /* When selecting a new item,
647                        do not allow showing connection points
648                        on connectors. (yet?)
649                     */
650                     if ( item != cc->active_shape && !cc_item_is_connector( item ) )
651                         cc_set_active_shape( cc, item );
652                 }
653                 ret = TRUE;
655             }
656             break;
657         case GDK_ENTER_NOTIFY:
658         {
659             if (cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE || (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE && !cc->selected_handle))
660             {
661                 if (cc_item_is_shape(item)) {
663                     // I don't really understand what the above does,
664                     // so I commented it.
665                     // This is a shape, so show connection point(s).
666     /*                if (!(cc->active_shape)
667                             // Don't show handle for another handle.
668     //                         || (cc->connpthandles.find((SPKnot*) item) != cc->connpthandles.end())
669                         )
670                     {
671                         cc_set_active_shape(cc, item);
672                     }*/
673                     cc_set_active_shape(cc, item);
674                 }
675                 ret = TRUE;
676             }
677             break;
678         }
679         default:
680             break;
681     }
683     return ret;
687 gint
688 sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event)
690     SPConnectorContext *const cc = SP_CONNECTOR_CONTEXT(ec);
692     gint ret = FALSE;
694     switch (event->type) {
695         case GDK_BUTTON_PRESS:
696             ret = connector_handle_button_press(cc, event->button);
697             break;
699         case GDK_MOTION_NOTIFY:
700             ret = connector_handle_motion_notify(cc, event->motion);
701             break;
703         case GDK_BUTTON_RELEASE:
704             ret = connector_handle_button_release(cc, event->button);
705             break;
706         case GDK_KEY_PRESS:
707             ret = connector_handle_key_press(cc, get_group0_keyval (&event->key));
708             break;
710         default:
711             break;
712     }
714     if (!ret) {
715         gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
716             = ((SPEventContextClass *) parent_class)->root_handler;
717         if (parent_root_handler) {
718             ret = parent_root_handler(ec, event);
719         }
720     }
722     return ret;
726 static gint
727 connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const &bevent)
729     Geom::Point const event_w(bevent.x, bevent.y);
730     /* Find desktop coordinates */
731     Geom::Point p = cc->desktop->w2d(event_w);
732     SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
734     gint ret = FALSE;
735     if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
736     {
737         if ( bevent.button == 1 && !event_context->space_panning ) {
739             SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
741             if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) {
742                 return TRUE;
743             }
745             Geom::Point const event_w(bevent.x,
746                                     bevent.y);
747 //             connector_drag_origin_w = event_w;
748             cc->xp = bevent.x;
749             cc->yp = bevent.y;
750             cc->within_tolerance = true;
752             Geom::Point const event_dt = cc->desktop->w2d(event_w);
754             SnapManager &m = cc->desktop->namedview->snap_manager;
755             m.setup(cc->desktop);
757             switch (cc->state) {
758                 case SP_CONNECTOR_CONTEXT_STOP:
759                     /* This is allowed, if we just canceled curve */
760                 case SP_CONNECTOR_CONTEXT_IDLE:
761                 {
762                     if ( cc->npoints == 0 ) {
763                         cc_clear_active_conn(cc);
765                         SP_EVENT_CONTEXT_DESKTOP(cc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector"));
767                         /* Set start anchor */
768                         /* Create green anchor */
769                         Geom::Point p = event_dt;
771                         // Test whether we clicked on a connection point
772                         cc->sid = conn_pt_handle_test(cc, p);
774                         if (!cc->sid) {
775                             // This is the first point, so just snap it to the grid
776                             // as there's no other points to go off.
777                             m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
778                         }
779                         spcc_connector_set_initial_point(cc, p);
781                     }
782                     cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
783                     ret = TRUE;
784                     break;
785                 }
786                 case SP_CONNECTOR_CONTEXT_DRAGGING:
787                 {
788                     // This is the second click of a connector creation.
789                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
791                     spcc_connector_set_subsequent_point(cc, p);
792                     spcc_connector_finish_segment(cc, p);
793                     // Test whether we clicked on a connection point
794                     cc->eid = conn_pt_handle_test(cc, p);
795                     if (cc->npoints != 0) {
796                         spcc_connector_finish(cc);
797                     }
798                     cc_set_active_conn(cc, cc->newconn);
799                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
800                     ret = TRUE;
801                     break;
802                 }
803                 case SP_CONNECTOR_CONTEXT_CLOSE:
804                 {
805                     g_warning("Button down in CLOSE state");
806                     break;
807                 }
808                 default:
809                     break;
810             }
811         } else if (bevent.button == 3) {
812             if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
813                 // A context menu is going to be triggered here,
814                 // so end the rerouting operation.
815                 cc_connector_rerouting_finish(cc, &p);
817                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
819                 // Don't set ret to TRUE, so we drop through to the
820                 // parent handler which will open the context menu.
821             }
822             else if (cc->npoints != 0) {
823                 spcc_connector_finish(cc);
824                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
825                 ret = TRUE;
826             }
827         }
828     }
829     else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
830     {
831         if ( bevent.button == 1 && !event_context->space_panning )
832         {
833             // Initialize variables in case of dragging
835             SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
837             if (Inkscape::have_viable_layer(desktop, cc->_message_context) == false) {
838                 return TRUE;
839             }
841             cc->xp = bevent.x;
842             cc->yp = bevent.y;
843             cc->within_tolerance = true;
845             ConnectionPointMap::iterator const& active_knot_it = cc->connpthandles.find( cc->active_handle );
847             switch (cc->state)
848             {
849                 case SP_CONNECTOR_CONTEXT_IDLE:
850                     if ( active_knot_it != cc->connpthandles.end() )
851                     {
852                         // We do not allow selecting and, thereby, moving default knots
853                         if ( active_knot_it->second.type != ConnPointDefault)
854                         {
855                             if (cc->selected_handle != cc->active_handle)
856                             {
857                                 if ( cc->selected_handle )
858                                     cc_deselect_handle( cc->selected_handle );
859                                 cc->selected_handle = cc->active_handle;
860                                 cc_select_handle( cc->selected_handle );
861                             }
862                         }
863                         else
864                             // Just ignore the default connection point
865                             return FALSE;
866                     }
867                     else
868                         if ( cc->selected_handle )
869                         {
870                             cc_deselect_handle( cc->selected_handle );
871                             cc->selected_handle = NULL;
872                         }
874                     if ( cc->selected_handle )
875                     {
876                         cc->state = SP_CONNECTOR_CONTEXT_DRAGGING;
877                         cc->selection->set( SP_OBJECT( cc->active_shape ) );
878                     }
880                     ret = TRUE;
881                     break;
882                 // Dragging valid because of the way we create
883                 // new connection points.
884                 case SP_CONNECTOR_CONTEXT_DRAGGING:
885                     // Do nothing.
886                     ret = TRUE;
887                     break;
888             }
889         }
890     }
891     return ret;
895 static gint
896 connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent)
898     gint ret = FALSE;
899     SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
900     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
902     if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
903         // allow middle-button scrolling
904         return FALSE;
905     }
907     Geom::Point const event_w(mevent.x, mevent.y);
909     if (cc->within_tolerance) {
910         cc->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
911         if ( ( abs( (gint) mevent.x - cc->xp ) < cc->tolerance ) &&
912              ( abs( (gint) mevent.y - cc->yp ) < cc->tolerance ) ) {
913             return FALSE;   // Do not drag if we're within tolerance from origin.
914         }
915     }
916     // Once the user has moved farther than tolerance from the original location
917     // (indicating they intend to move the object, not click), then always process
918     // the motion notify coordinates as given (no snapping back to origin)
919     cc->within_tolerance = false;
921     SPDesktop *const dt = cc->desktop;
923     /* Find desktop coordinates */
924     Geom::Point p = dt->w2d(event_w);
926     if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
927     {
928         SnapManager &m = dt->namedview->snap_manager;
929         m.setup(dt);
931         switch (cc->state) {
932             case SP_CONNECTOR_CONTEXT_DRAGGING:
933             {
934                 gobble_motion_events(mevent.state);
935                 // This is movement during a connector creation.
936                 if ( cc->npoints > 0 ) {
937                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
938                     cc->selection->clear();
939                     spcc_connector_set_subsequent_point(cc, p);
940                     ret = TRUE;
941                 }
942                 break;
943             }
944             case SP_CONNECTOR_CONTEXT_REROUTING:
945             {
946                 gobble_motion_events(GDK_BUTTON1_MASK);
947                 g_assert( SP_IS_PATH(cc->clickeditem));
949                 m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
951                 // Update the hidden path
952                 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
953                 Geom::Matrix d2i = i2d.inverse();
954                 SPPath *path = SP_PATH(cc->clickeditem);
955                 SPCurve *curve = path->original_curve ? path->original_curve : path->curve;
956                 if (cc->clickedhandle == cc->endpt_handle[0]) {
957                     Geom::Point o = cc->endpt_handle[1]->pos;
958                     curve->stretch_endpoints(p * d2i, o * d2i);
959                 }
960                 else {
961                     Geom::Point o = cc->endpt_handle[0]->pos;
962                     curve->stretch_endpoints(o * d2i, p * d2i);
963                 }
964                 sp_conn_reroute_path_immediate(path);
966                 // Copy this to the temporary visible path
967                 cc->red_curve = path->original_curve ?
968                         path->original_curve->copy() : path->curve->copy();
969                 cc->red_curve->transform(i2d);
971                 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
972                 ret = TRUE;
973                 break;
974             }
975             case SP_CONNECTOR_CONTEXT_STOP:
976                 /* This is perfectly valid */
977                 break;
978             default:
979                 break;
980         }
981     }
982     else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
983     {
984         switch ( cc->state )
985         {
986             case SP_CONNECTOR_CONTEXT_DRAGGING:
987                 sp_knot_set_position(cc->selected_handle, p, 0);
988                 ret = TRUE;
989                 break;
990             case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
991                 sp_knot_set_position(cc->selected_handle, p, 0);
992                 ret = TRUE;
993                 break;
994         }
995     }
997     return ret;
1001 static gint
1002 connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
1004     gint ret = FALSE;
1005     SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
1006     if ( revent.button == 1 && !event_context->space_panning ) {
1008         SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1009         SPDocument *doc = sp_desktop_document(desktop);
1011         SnapManager &m = desktop->namedview->snap_manager;
1012         m.setup(desktop);
1014         Geom::Point const event_w(revent.x, revent.y);
1016         /* Find desktop coordinates */
1017         Geom::Point p = cc->desktop->w2d(event_w);
1018         if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1019         {
1020             switch (cc->state) {
1021                 //case SP_CONNECTOR_CONTEXT_POINT:
1022                 case SP_CONNECTOR_CONTEXT_DRAGGING:
1023                 {
1024                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1026                     if (cc->within_tolerance)
1027                     {
1028                         spcc_connector_finish_segment(cc, p);
1029                         return TRUE;
1030                     }
1031                     // Connector has been created via a drag, end it now.
1032                     spcc_connector_set_subsequent_point(cc, p);
1033                     spcc_connector_finish_segment(cc, p);
1034                     // Test whether we clicked on a connection point
1035                     cc->eid = conn_pt_handle_test(cc, p);
1036                     if (cc->npoints != 0) {
1037                         spcc_connector_finish(cc);
1038                     }
1039                     cc_set_active_conn(cc, cc->newconn);
1040                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1041                     break;
1042                 }
1043                 case SP_CONNECTOR_CONTEXT_REROUTING:
1044                 {
1045                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1046                     cc_connector_rerouting_finish(cc, &p);
1048                     sp_document_ensure_up_to_date(doc);
1049                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1050                     return TRUE;
1051                     break;
1052                 }
1053                 case SP_CONNECTOR_CONTEXT_STOP:
1054                     /* This is allowed, if we just cancelled curve */
1055                     break;
1056                 default:
1057                     break;
1058             }
1059             ret = TRUE;
1060         }
1061         else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1062         {
1063             switch ( cc->state )
1064             {
1065                 case SP_CONNECTOR_CONTEXT_DRAGGING:
1067                     if (!cc->within_tolerance)
1068                     {
1069                         m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1070                         sp_knot_set_position(cc->selected_handle, p, 0);
1071                         ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1072                         cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1073                         cc->active_shape->avoidRef->updateConnectionPoint(cp);
1074                     }
1076                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1077                     ret = TRUE;
1078                     break;
1081                 case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1082                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1084                     sp_knot_set_position(cc->selected_handle, p, 0);
1086                     ConnectionPoint cp;
1087                     cp.type = ConnPointUserDefined;
1088                     cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1089                     cp.dir = Avoid::ConnDirAll;
1090                     g_object_unref(cc->selected_handle);
1091                     cc->active_shape->avoidRef->addConnectionPoint(cp);
1092                     sp_document_ensure_up_to_date(doc);
1093                     for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1094                         if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1095                         {
1096                             cc->selected_handle = it->first;
1097                             break;
1098                         }
1099                     cc_select_handle( cc->selected_handle );
1100                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1101                     ret = TRUE;
1102                     break;
1103             }
1104         }
1105     }
1108     return ret;
1112 static gint
1113 connector_handle_key_press(SPConnectorContext *const cc, guint const keyval)
1115     gint ret = FALSE;
1116     /* fixme: */
1117     if ( cc->mode == SP_CONNECTOR_CONTEXT_DRAWING_MODE )
1118     {
1119         switch (keyval) {
1120             case GDK_Return:
1121             case GDK_KP_Enter:
1122                 if (cc->npoints != 0) {
1123                     spcc_connector_finish(cc);
1124                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1125                     ret = TRUE;
1126                 }
1127                 break;
1128             case GDK_Escape:
1129                 if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
1131                     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1132                     SPDocument *doc = sp_desktop_document(desktop);
1134                     cc_connector_rerouting_finish(cc, NULL);
1136                     sp_document_undo(doc);
1138                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1139                     desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1140                             _("Connector endpoint drag cancelled."));
1141                     ret = TRUE;
1142                 }
1143                 else if (cc->npoints != 0) {
1144                     // if drawing, cancel, otherwise pass it up for deselecting
1145                     cc->state = SP_CONNECTOR_CONTEXT_STOP;
1146                     spcc_reset_colors(cc);
1147                     ret = TRUE;
1148                 }
1149                 break;
1150             default:
1151                 break;
1152         }
1153     }
1154     else if ( cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE )
1155     {
1156         switch ( cc->state )
1157         {
1158             case SP_CONNECTOR_CONTEXT_DRAGGING:
1159                 if ( keyval == GDK_Escape )
1160                 {
1161                     // Cancel connection point dragging
1163                     // Obtain original position
1164                     ConnectionPoint const& cp = cc->connpthandles[cc->selected_handle];
1165                     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1166                     const Geom::Matrix& i2doc = sp_item_i2doc_affine(cc->active_shape);
1167                     sp_knot_set_position(cc->selected_handle, cp.pos * i2doc * desktop->doc2dt(), 0);
1168                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1169                     desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
1170                         _("Connection point drag cancelled."));
1171                     ret = TRUE;
1172                 }
1173                 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1174                 {
1175                     // Put connection point at current position
1177                     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1178                     SnapManager &m = desktop->namedview->snap_manager;
1179                     m.setup(desktop);
1180                     Geom::Point p = cc->selected_handle->pos;
1181 //                     SPEventContext* event_context = SP_EVENT_CONTEXT( cc );
1183                     if (!cc->within_tolerance)
1184                     {
1185                         m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1186                         sp_knot_set_position(cc->selected_handle, p, 0);
1187                         ConnectionPoint& cp = cc->connpthandles[cc->selected_handle];
1188                         cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1189                         cc->active_shape->avoidRef->updateConnectionPoint(cp);
1190                     }
1192                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1193                     ret = TRUE;
1194                 }
1195                 break;
1196             case SP_CONNECTOR_CONTEXT_NEWCONNPOINT:
1197                 if ( keyval == GDK_Escape )
1198                 {
1199                     // Just destroy the knot
1200                     g_object_unref( cc->selected_handle );
1201                     cc->selected_handle = NULL;
1202                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1203                     ret = TRUE;
1204                 }
1205                 else if ( keyval == GDK_Return || keyval == GDK_KP_Enter )
1206                 {
1207                     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1208                     SPDocument *doc = sp_desktop_document(desktop);
1209                     SnapManager &m = desktop->namedview->snap_manager;
1210                     m.setup(desktop);
1211                     Geom::Point p = cc->selected_handle->pos;
1213                     m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
1215                     sp_knot_set_position(cc->selected_handle, p, 0);
1217                     ConnectionPoint cp;
1218                     cp.type = ConnPointUserDefined;
1219                     cp.pos = p * sp_item_dt2i_affine(cc->active_shape);
1220                     cp.dir = Avoid::ConnDirAll;
1221                     g_object_unref(cc->selected_handle);
1222                     cc->active_shape->avoidRef->addConnectionPoint(cp);
1223                     sp_document_ensure_up_to_date(doc);
1224                     for (ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end(); ++it)
1225                         if (it->second.type == ConnPointUserDefined && it->second.id == cp.id)
1226                         {
1227                             cc->selected_handle = it->first;
1228                             break;
1229                         }
1230                     cc_select_handle( cc->selected_handle );
1231                     cc->state = SP_CONNECTOR_CONTEXT_IDLE;
1232                     ret = TRUE;
1233                 }
1235                 break;
1236             case SP_CONNECTOR_CONTEXT_IDLE:
1237                 if ( keyval == GDK_Delete && cc->selected_handle )
1238                 {
1239                     cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1240                     cc->selected_handle = NULL;
1241                     ret = TRUE;
1242                 }
1244                 break;
1245         }
1246     }
1248     return ret;
1252 static void
1253 cc_connector_rerouting_finish(SPConnectorContext *const cc, Geom::Point *const p)
1255     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1256     SPDocument *doc = sp_desktop_document(desktop);
1258     // Clear the temporary path:
1259     cc->red_curve->reset();
1260     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1262     if (p != NULL)
1263     {
1264         // Test whether we clicked on a connection point
1265         gchar *shape_label = conn_pt_handle_test(cc, *p);
1267         if (shape_label) {
1268             if (cc->clickedhandle == cc->endpt_handle[0]) {
1269                 sp_object_setAttribute(cc->clickeditem,
1270                         "inkscape:connection-start",shape_label, false);
1271             }
1272             else {
1273                 sp_object_setAttribute(cc->clickeditem,
1274                         "inkscape:connection-end",shape_label, false);
1275             }
1276             g_free(shape_label);
1277         }
1278     }
1279     cc->clickeditem->setHidden(false);
1280     sp_conn_reroute_path_immediate(SP_PATH(cc->clickeditem));
1281     cc->clickeditem->updateRepr();
1282     sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
1283                      _("Reroute connector"));
1284     cc_set_active_conn(cc, cc->clickeditem);
1288 static void
1289 spcc_reset_colors(SPConnectorContext *cc)
1291     /* Red */
1292     cc->red_curve->reset();
1293     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1295     cc->green_curve->reset();
1296     cc->npoints = 0;
1300 static void
1301 spcc_connector_set_initial_point(SPConnectorContext *const cc, Geom::Point const p)
1303     g_assert( cc->npoints == 0 );
1305     cc->p[0] = p;
1306     cc->p[1] = p;
1307     cc->npoints = 2;
1308     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1312 static void
1313 spcc_connector_set_subsequent_point(SPConnectorContext *const cc, Geom::Point const p)
1315     g_assert( cc->npoints != 0 );
1317     SPDesktop *dt = cc->desktop;
1318     Geom::Point o = dt->dt2doc(cc->p[0]);
1319     Geom::Point d = dt->dt2doc(p);
1320     Avoid::Point src(o[Geom::X], o[Geom::Y]);
1321     Avoid::Point dst(d[Geom::X], d[Geom::Y]);
1323     if (!cc->newConnRef) {
1324         Avoid::Router *router = sp_desktop_document(dt)->router;
1325         cc->newConnRef = new Avoid::ConnRef(router);
1326         cc->newConnRef->setEndpoint(Avoid::VertID::src, src);
1327         if (cc->isOrthogonal)
1328             cc->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal);
1329         else
1330             cc->newConnRef->setRoutingType(Avoid::ConnType_PolyLine);
1331     }
1332     // Set new endpoint.
1333     cc->newConnRef->setEndpoint(Avoid::VertID::tar, dst);
1334     // Immediately generate new routes for connector.
1335     cc->newConnRef->makePathInvalid();
1336     cc->newConnRef->router()->processTransaction();
1337     // Recreate curve from libavoid route.
1338     recreateCurve( cc->red_curve, cc->newConnRef, cc->curvature );
1339     cc->red_curve->transform(dt->doc2dt());
1340     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1344 /**
1345  * Concats red, blue and green.
1346  * If any anchors are defined, process these, optionally removing curves from white list
1347  * Invoke _flush_white to write result back to object.
1348  */
1349 static void
1350 spcc_concat_colors_and_flush(SPConnectorContext *cc)
1352     SPCurve *c = cc->green_curve;
1353     cc->green_curve = new SPCurve();
1355     cc->red_curve->reset();
1356     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
1358     if (c->is_empty()) {
1359         c->unref();
1360         return;
1361     }
1363     spcc_flush_white(cc, c);
1365     c->unref();
1369 /*
1370  * Flushes white curve(s) and additional curve into object
1371  *
1372  * No cleaning of colored curves - this has to be done by caller
1373  * No rereading of white data, so if you cannot rely on ::modified, do it in caller
1374  *
1375  */
1377 static void
1378 spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
1380     SPCurve *c;
1382     if (gc) {
1383         c = gc;
1384         c->ref();
1385     } else {
1386         return;
1387     }
1389     /* Now we have to go back to item coordinates at last */
1390     c->transform(SP_EVENT_CONTEXT_DESKTOP(cc)->dt2doc());
1392     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
1393     SPDocument *doc = sp_desktop_document(desktop);
1394     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
1396     if ( c && !c->is_empty() ) {
1397         /* We actually have something to write */
1399         Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
1400         /* Set style */
1401         sp_desktop_apply_style_tool(desktop, repr, "/tools/connector", false);
1403         gchar *str = sp_svg_write_path( c->get_pathvector() );
1404         g_assert( str != NULL );
1405         repr->setAttribute("d", str);
1406         g_free(str);
1408         /* Attach repr */
1409         cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
1410         cc->newconn->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
1412         bool connection = false;
1413         sp_object_setAttribute(cc->newconn, "inkscape:connector-type",
1414                 cc->isOrthogonal ? "orthogonal" : "polyline", false);
1415         sp_object_setAttribute(cc->newconn, "inkscape:connector-curvature",
1416                 Glib::Ascii::dtostr(cc->curvature).c_str(), false);
1417         if (cc->sid)
1418         {
1419             sp_object_setAttribute(cc->newconn, "inkscape:connection-start",
1420                     cc->sid, false);
1421             connection = true;
1422         }
1424         if (cc->eid)
1425         {
1426             sp_object_setAttribute(cc->newconn, "inkscape:connection-end",
1427                     cc->eid, false);
1428             connection = true;
1429         }
1430         // Process pending updates.
1431         cc->newconn->updateRepr();
1432         sp_document_ensure_up_to_date(doc);
1434         if (connection) {
1435             // Adjust endpoints to shape edge.
1436             sp_conn_reroute_path_immediate(SP_PATH(cc->newconn));
1437             cc->newconn->updateRepr();
1438         }
1440         // Only set the selection after we are finished with creating the attributes of
1441         // the connector.  Otherwise, the selection change may alter the defaults for
1442         // values like curvature in the connector context, preventing subsequent lookup
1443         // of their original values.
1444         cc->selection->set(repr);
1445         Inkscape::GC::release(repr);
1446     }
1448     c->unref();
1450     sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector"));
1454 static void
1455 spcc_connector_finish_segment(SPConnectorContext *const cc, Geom::Point const /*p*/)
1457     if (!cc->red_curve->is_empty()) {
1458         cc->green_curve->append_continuous(cc->red_curve, 0.0625);
1460         cc->p[0] = cc->p[3];
1461         cc->p[1] = cc->p[4];
1462         cc->npoints = 2;
1464         cc->red_curve->reset();
1465     }
1469 static void
1470 spcc_connector_finish(SPConnectorContext *const cc)
1472     SPDesktop *const desktop = cc->desktop;
1473     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector"));
1475     cc->red_curve->reset();
1476     spcc_concat_colors_and_flush(cc);
1478     cc->npoints = 0;
1480     if (cc->newConnRef) {
1481         cc->newConnRef->removeFromGraph();
1482         delete cc->newConnRef;
1483         cc->newConnRef = NULL;
1484     }
1488 static gboolean
1489 cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot)
1491     g_assert (knot != NULL);
1493     g_object_ref(knot);
1495     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(
1496             knot->desktop->event_context);
1498     gboolean consumed = FALSE;
1500     gchar* knot_tip = knot->tip ? knot->tip : cc->knot_tip;
1501     switch (event->type) {
1502         case GDK_ENTER_NOTIFY:
1503             sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE);
1505             cc->active_handle = knot;
1506             if (knot_tip)
1507             {
1508                 knot->desktop->event_context->defaultMessageContext()->set(
1509                         Inkscape::NORMAL_MESSAGE, knot_tip);
1510             }
1512             consumed = TRUE;
1513             break;
1514         case GDK_LEAVE_NOTIFY:
1515             sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE);
1517             cc->active_handle = NULL;
1519             if (knot_tip) {
1520                 knot->desktop->event_context->defaultMessageContext()->clear();
1521             }
1523             consumed = TRUE;
1524             break;
1525         default:
1526             break;
1527     }
1529     g_object_unref(knot);
1531     return consumed;
1535 static gboolean
1536 endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc)
1538     g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
1540     gboolean consumed = FALSE;
1542     switch (event->type) {
1543         case GDK_BUTTON_PRESS:
1544             g_assert( (cc->active_handle == cc->endpt_handle[0]) ||
1545                       (cc->active_handle == cc->endpt_handle[1]) );
1546             if (cc->state == SP_CONNECTOR_CONTEXT_IDLE) {
1547                 cc->clickeditem = cc->active_conn;
1548                 cc->clickedhandle = cc->active_handle;
1549                 cc_clear_active_conn(cc);
1550                 cc->state = SP_CONNECTOR_CONTEXT_REROUTING;
1552                 // Disconnect from attached shape
1553                 unsigned ind = (cc->active_handle == cc->endpt_handle[0]) ? 0 : 1;
1554                 sp_conn_end_detach(cc->clickeditem, ind);
1556                 Geom::Point origin;
1557                 if (cc->clickedhandle == cc->endpt_handle[0]) {
1558                     origin = cc->endpt_handle[1]->pos;
1559                 }
1560                 else {
1561                     origin = cc->endpt_handle[0]->pos;
1562                 }
1564                 // Show the red path for dragging.
1565                 cc->red_curve = SP_PATH(cc->clickeditem)->original_curve ? SP_PATH(cc->clickeditem)->original_curve->copy() : SP_PATH(cc->clickeditem)->curve->copy();
1566                 Geom::Matrix i2d = sp_item_i2d_affine(cc->clickeditem);
1567                 cc->red_curve->transform(i2d);
1568                 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
1570                 cc->clickeditem->setHidden(true);
1572                 // The rest of the interaction rerouting the connector is
1573                 // handled by the context root handler.
1574                 consumed = TRUE;
1575             }
1576             break;
1577         default:
1578             break;
1579     }
1581     return consumed;
1584 static void cc_active_shape_add_knot(SPDesktop* desktop, SPItem* item, ConnectionPointMap &cphandles, ConnectionPoint& cp)
1586         SPKnot *knot = sp_knot_new(desktop, 0);
1588         knot->setShape(SP_KNOT_SHAPE_SQUARE);
1589         knot->setSize(8);
1590         knot->setAnchor(GTK_ANCHOR_CENTER);
1591         knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1592         sp_knot_update_ctrl(knot);
1594         // We don't want to use the standard knot handler.
1595         g_signal_handler_disconnect(G_OBJECT(knot->item),
1596                 knot->_event_handler_id);
1597         knot->_event_handler_id = 0;
1599         gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1600                 GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1601         sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos(cp.type, cp.id) * desktop->doc2dt(), 0);
1602         sp_knot_show(knot);
1603         cphandles[knot] = cp;
1606 static void cc_set_active_shape(SPConnectorContext *cc, SPItem *item)
1608     g_assert(item != NULL );
1610     std::map<int, ConnectionPoint>* connpts = &item->avoidRef->connection_points;
1612     if (cc->active_shape != item)
1613     {
1614         // The active shape has changed
1615         // Rebuild everything
1616         cc->active_shape = item;
1617         // Remove existing active shape listeners
1618         if (cc->active_shape_repr) {
1619             sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
1620             Inkscape::GC::release(cc->active_shape_repr);
1622             sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc);
1623             Inkscape::GC::release(cc->active_shape_layer_repr);
1624         }
1626         // Listen in case the active shape changes
1627         cc->active_shape_repr = SP_OBJECT_REPR(item);
1628         if (cc->active_shape_repr) {
1629             Inkscape::GC::anchor(cc->active_shape_repr);
1630             sp_repr_add_listener(cc->active_shape_repr, &shape_repr_events, cc);
1632             cc->active_shape_layer_repr = cc->active_shape_repr->parent();
1633             Inkscape::GC::anchor(cc->active_shape_layer_repr);
1634             sp_repr_add_listener(cc->active_shape_layer_repr, &layer_repr_events, cc);
1635         }
1638         // Set the connection points.
1639         if ( cc->connpthandles.size() )
1640             // destroy the old list
1641             while (! cc->connpthandles.empty() )
1642             {
1643                 g_object_unref(cc->connpthandles.begin()->first);
1644                 cc->connpthandles.erase(cc->connpthandles.begin());
1645             }
1646         // build the new one
1647         if ( connpts->size() )
1648         for (std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it)
1649             cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1651         // Also add default connection points
1652         // For now, only centre default connection point will
1653         // be available
1654         ConnectionPoint centre;
1655         centre.type = ConnPointDefault;
1656         centre.id = ConnPointPosCC;
1657         cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, centre);
1658     }
1659     else
1660     {
1661         // The active shape didn't change
1662         // Update only the connection point knots
1664         // Ensure the item's connection_points map
1665         // has been updated
1666         sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
1668         std::set<int> seen;
1669         for  ( ConnectionPointMap::iterator it = cc->connpthandles.begin(); it != cc->connpthandles.end() ;)
1670         {
1671             bool removed = false;
1672             if ( it->second.type == ConnPointUserDefined )
1673             {
1674                 std::map<int, ConnectionPoint>::iterator p = connpts->find(it->second.id);
1675                 if (p != connpts->end())
1676                 {
1677                     if ( it->second != p->second )
1678                         // Connection point position has changed
1679                         // Update knot position
1680                         sp_knot_set_position(it->first,
1681                                              item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1682                     seen.insert(it->second.id);
1683                     sp_knot_show(it->first);
1684                 }
1685                 else
1686                 {
1687                     // This connection point does no longer exist,
1688                     // remove the knot
1689                     ConnectionPointMap::iterator curr = it;
1690                     ++it;
1691                     g_object_unref( curr->first );
1692                     cc->connpthandles.erase(curr);
1693                     removed = true;
1694                 }
1695             }
1696             else
1697             {
1698                 // It's a default connection point
1699                 // Just make sure it's position is correct
1700                 sp_knot_set_position(it->first,
1701                                      item->avoidRef->getConnectionPointPos(it->second.type, it->second.id) * cc->desktop->doc2dt(), 0);
1702                 sp_knot_show(it->first);
1704             }
1705             if ( !removed )
1706                 ++it;
1707         }
1708         // Add knots for new connection points.
1709         if (connpts->size())
1710             for ( std::map<int, ConnectionPoint>::iterator it = connpts->begin(); it != connpts->end(); ++it )
1711                 if ( seen.find(it->first) == seen.end() )
1712                     // A new connection point has been added
1713                     // to the shape. Add a knot for it.
1714                     cc_active_shape_add_knot(cc->desktop, item, cc->connpthandles, it->second);
1715     }
1719 static void
1720 cc_set_active_conn(SPConnectorContext *cc, SPItem *item)
1722     g_assert( SP_IS_PATH(item) );
1724     SPCurve *curve = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve : SP_PATH(item)->curve;
1725     Geom::Matrix i2d = sp_item_i2d_affine(item);
1727     if (cc->active_conn == item)
1728     {
1729         // Just adjust handle positions.
1730         Geom::Point startpt = *(curve->first_point()) * i2d;
1731         sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1733         Geom::Point endpt = *(curve->last_point()) * i2d;
1734         sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1736         return;
1737     }
1739     cc->active_conn = item;
1741     // Remove existing active conn listeners
1742     if (cc->active_conn_repr) {
1743         sp_repr_remove_listener_by_data(cc->active_conn_repr, cc);
1744         Inkscape::GC::release(cc->active_conn_repr);
1745         cc->active_conn_repr = NULL;
1746     }
1748     // Listen in case the active conn changes
1749     cc->active_conn_repr = SP_OBJECT_REPR(item);
1750     if (cc->active_conn_repr) {
1751         Inkscape::GC::anchor(cc->active_conn_repr);
1752         sp_repr_add_listener(cc->active_conn_repr, &shape_repr_events, cc);
1753     }
1755     for (int i = 0; i < 2; ++i) {
1757         // Create the handle if it doesn't exist
1758         if ( cc->endpt_handle[i] == NULL ) {
1759             SPKnot *knot = sp_knot_new(cc->desktop,
1760                     _("<b>Connector endpoint</b>: drag to reroute or connect to new shapes"));
1762             knot->setShape(SP_KNOT_SHAPE_SQUARE);
1763             knot->setSize(7);
1764             knot->setAnchor(GTK_ANCHOR_CENTER);
1765             knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff);
1766             knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
1767             sp_knot_update_ctrl(knot);
1769             // We don't want to use the standard knot handler,
1770             // since we don't want this knot to be draggable.
1771             g_signal_handler_disconnect(G_OBJECT(knot->item),
1772                     knot->_event_handler_id);
1773             knot->_event_handler_id = 0;
1775             gtk_signal_connect(GTK_OBJECT(knot->item), "event",
1776                     GTK_SIGNAL_FUNC(cc_generic_knot_handler), knot);
1778             cc->endpt_handle[i] = knot;
1779         }
1781         // Remove any existing handlers
1782         if (cc->endpt_handler_id[i]) {
1783             g_signal_handlers_disconnect_by_func(
1784                     G_OBJECT(cc->endpt_handle[i]->item),
1785                     (void*)G_CALLBACK(endpt_handler), (gpointer) cc );
1786             cc->endpt_handler_id[i] = 0;
1787         }
1789         // Setup handlers for connector endpoints, this is
1790         // is as 'after' so that cc_generic_knot_handler is
1791         // triggered first for any endpoint.
1792         cc->endpt_handler_id[i] = g_signal_connect_after(
1793                 G_OBJECT(cc->endpt_handle[i]->item), "event",
1794                 G_CALLBACK(endpt_handler), cc);
1795     }
1797     Geom::Point startpt = *(curve->first_point()) * i2d;
1798     sp_knot_set_position(cc->endpt_handle[0], startpt, 0);
1800     Geom::Point endpt = *(curve->last_point()) * i2d;
1801     sp_knot_set_position(cc->endpt_handle[1], endpt, 0);
1803     sp_knot_show(cc->endpt_handle[0]);
1804     sp_knot_show(cc->endpt_handle[1]);
1807 void cc_create_connection_point(SPConnectorContext* cc)
1809     if (cc->active_shape && cc->state == SP_CONNECTOR_CONTEXT_IDLE)
1810     {
1811         if (cc->selected_handle)
1812         {
1813             cc_deselect_handle( cc->selected_handle );
1814         }
1815         SPKnot *knot = sp_knot_new(cc->desktop, 0);
1816         // We do not process events on this knot.
1817         g_signal_handler_disconnect(G_OBJECT(knot->item),
1818                                     knot->_event_handler_id);
1819         knot->_event_handler_id = 0;
1821         cc_select_handle( knot );
1822         cc->selected_handle = knot;
1823         sp_knot_show(cc->selected_handle);
1824         cc->state = SP_CONNECTOR_CONTEXT_NEWCONNPOINT;
1825     }
1828 void cc_remove_connection_point(SPConnectorContext* cc)
1830     if (cc->selected_handle && cc->state == SP_CONNECTOR_CONTEXT_IDLE )
1831     {
1832         cc->active_shape->avoidRef->deleteConnectionPoint(cc->connpthandles[cc->selected_handle]);
1833         cc->selected_handle = NULL;
1834     }
1837 static bool cc_item_is_shape(SPItem *item)
1839     if (SP_IS_PATH(item)) {
1840         SPCurve *curve = (SP_SHAPE(item))->curve;
1841         if ( curve && !(curve->is_closed()) ) {
1842             // Open paths are connectors.
1843             return false;
1844         }
1845     }
1846     else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
1847         Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1848         if (prefs->getBool("/tools/connector/ignoretext", true)) {
1849             // Don't count text as a shape we can connect connector to.
1850             return false;
1851         }
1852     }
1853     return true;
1857 bool cc_item_is_connector(SPItem *item)
1859     if (SP_IS_PATH(item)) {
1860         if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) {
1861             g_assert( SP_PATH(item)->original_curve ? !(SP_PATH(item)->original_curve->is_closed()) : !(SP_PATH(item)->curve->is_closed()) );
1862             return true;
1863         }
1864     }
1865     return false;
1869 void cc_selection_set_avoid(bool const set_avoid)
1871     SPDesktop *desktop = inkscape_active_desktop();
1872     if (desktop == NULL) {
1873         return;
1874     }
1876     SPDocument *document = sp_desktop_document(desktop);
1878     Inkscape::Selection *selection = sp_desktop_selection(desktop);
1880     GSList *l = (GSList *) selection->itemList();
1882     int changes = 0;
1884     while (l) {
1885         SPItem *item = (SPItem *) l->data;
1887         char const *value = (set_avoid) ? "true" : NULL;
1889         if (cc_item_is_shape(item)) {
1890             sp_object_setAttribute(item, "inkscape:connector-avoid",
1891                     value, false);
1892             item->avoidRef->handleSettingChange();
1893             changes++;
1894         }
1896         l = l->next;
1897     }
1899     if (changes == 0) {
1900         desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE,
1901                 _("Select <b>at least one non-connector object</b>."));
1902         return;
1903     }
1905     char *event_desc = (set_avoid) ?
1906             _("Make connectors avoid selected objects") :
1907             _("Make connectors ignore selected objects");
1908     sp_document_done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc);
1912 static void
1913 cc_selection_changed(Inkscape::Selection *selection, gpointer data)
1915     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1916     //SPEventContext *ec = SP_EVENT_CONTEXT(cc);
1918     SPItem *item = selection->singleItem();
1920     if (cc->active_conn == item)
1921     {
1922         // Nothing to change.
1923         return;
1924     }
1925     if (item == NULL)
1926     {
1927         cc_clear_active_conn(cc);
1928         return;
1929     }
1931     if (cc_item_is_connector(item)) {
1932         cc_set_active_conn(cc, item);
1933     }
1937 static void
1938 shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
1939                          Inkscape::XML::Node */*ref*/, gpointer data)
1941     g_assert(data);
1942     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1944     if (child == cc->active_shape_repr) {
1945         // The active shape has been deleted.  Clear active shape.
1946         cc_clear_active_shape(cc);
1947     }
1951 static void
1952 shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
1953                          gchar const */*old_value*/, gchar const */*new_value*/,
1954                          bool /*is_interactive*/, gpointer data)
1956     g_assert(data);
1957     SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
1959     // Look for changes that result in onscreen movement.
1960     if (!strcmp(name, "d") || !strcmp(name, "x") || !strcmp(name, "y") ||
1961             !strcmp(name, "width") || !strcmp(name, "height") ||
1962             !strcmp(name, "transform"))
1963     {
1964         if (repr == cc->active_shape_repr) {
1965             // Active shape has moved. Clear active shape.
1966             cc_clear_active_shape(cc);
1967         }
1968         else if (repr == cc->active_conn_repr) {
1969             // The active conn has been moved.
1970             // Set it again, which just sets new handle positions.
1971             cc_set_active_conn(cc, cc->active_conn);
1972         }
1973     }
1974     else
1975         if ( !strcmp(name, "inkscape:connection-points") )
1976             if (repr == cc->active_shape_repr)
1977                 // The connection points of the active shape
1978                 // have changed. Update them.
1979                 cc_set_active_shape(cc, cc->active_shape);
1983 /*
1984   Local Variables:
1985   mode:c++
1986   c-file-style:"stroustrup"
1987   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1988   indent-tabs-mode:nil
1989   fill-column:99
1990   End:
1991 */
1992 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :