Code

* src/Makefile_insert, src/Makefile.am, src/svg/Makefile_insert,
[inkscape.git] / src / connector-context.cpp
index edb9a8b459473939deaf365dc6eafc81e9733cf9..e38f8a627d34f1b7db0b21a8c4b324b6e9fa9cdc 100644 (file)
@@ -9,7 +9,7 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  *
  * TODO:
- *  o  Have shapes avoid coonvex hulls of objects, rather than their
+ *  o  Have shapes avoid convex hulls of objects, rather than their
  *     bounding box.  Possibly implement the unfinished ConvexHull
  *     class in libnr.
  *     (HOWEVER, using the convex hull C of a shape S does the wrong thing if a
  *     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
@@ -44,6 +45,7 @@
 
 #include "connector-context.h"
 #include "pixmaps/cursor-connector.xpm"
+#include "pixmaps/cursor-connector.pixbuf"
 #include "xml/node-event-vector.h"
 #include "xml/repr.h"
 #include "svg/svg.h"
@@ -68,6 +70,9 @@
 #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);
 static void sp_connector_context_init(SPConnectorContext *conn_context);
@@ -176,6 +181,11 @@ sp_connector_context_init(SPConnectorContext *cc)
     SPEventContext *ec = SP_EVENT_CONTEXT(cc);
 
     ec->cursor_shape = cursor_connector_xpm;
+    ec->cursor_pixbuf = gdk_pixbuf_new_from_inline(
+            -1,
+            cursor_connector_pixbuf,
+            FALSE,
+            NULL);  
     ec->hot_x = 1;
     ec->hot_y = 1;
     ec->xp = 0;
@@ -703,7 +713,8 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
                 cc->clickeditem->setHidden(false);
                 sp_conn_adjust_path(SP_PATH(cc->clickeditem));
                 cc->clickeditem->updateRepr();
-                sp_document_done(doc);
+                sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, 
+                                 _("Reroute connector"));
                 cc_set_active_conn(cc, cc->clickeditem);
                 sp_document_ensure_up_to_date(doc);
                 cc->state = SP_CONNECTOR_CONTEXT_IDLE;
@@ -783,8 +794,8 @@ spcc_connector_set_subsequent_point(SPConnectorContext *const cc, NR::Point cons
     SPDesktop *dt = cc->desktop;
     NR::Point o = dt->dt2doc(cc->p[0]);
     NR::Point d = dt->dt2doc(p);
-    Avoid::Point src = { o[NR::X], o[NR::Y] };
-    Avoid::Point dst = { d[NR::X], d[NR::Y] };
+    Avoid::Point src(o[NR::X], o[NR::Y]);
+    Avoid::Point dst(d[NR::X], d[NR::Y]);
 
     if (!cc->newConnRef) {
         Avoid::Router *router = sp_desktop_document(dt)->router;
@@ -910,7 +921,7 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc)
     sp_curve_unref(c);
 
     /* Flush pending updates */
-    sp_document_done(doc);
+    sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Create connector"));
     sp_document_ensure_up_to_date(doc);
 }
 
@@ -954,6 +965,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);
@@ -962,11 +975,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)
@@ -974,26 +984,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;
 }
@@ -1079,32 +1088,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, 
+                _("<b>Connection point</b>: 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", _("<b>Connection point</b>: 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;
     }
@@ -1159,32 +1159,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, 
+                    _("<b>Connector endpoint</b>: 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", _("<b>Connector endpoint</b>: 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;
         }
@@ -1225,6 +1217,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;
 }
 
@@ -1277,7 +1275,10 @@ void cc_selection_set_avoid(bool const set_avoid)
         return;
     }
 
-    sp_document_done(document);
+    char *event_desc = (set_avoid) ?
+            _("Make connectors avoid selected objects") :
+            _("Make connectors ignore selected objects");
+    sp_document_done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc);
 }