index 7343d6250c51a14e2a6049ef33c50df04307972a..6da465f2a48691557a97d0ffb71f5bbd95bc4030 100644 (file)
* Released under GNU GPL, read the file 'COPYING' for more information
*
* TODO:
* 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
* 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
*/
#include <gdk/gdkkeysyms.h>
*/
#include <gdk/gdkkeysyms.h>
+#include <string>
+#include <cstring>
#include "connector-context.h"
#include "pixmaps/cursor-connector.xpm"
#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"
#include "xml/node-event-vector.h"
#include "xml/repr.h"
#include "svg/svg.h"
static gchar *conn_pt_handle_test(SPConnectorContext *cc, NR::Point& w);
static bool cc_item_is_shape(SPItem *item);
static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
static gchar *conn_pt_handle_test(SPConnectorContext *cc, NR::Point& w);
static bool cc_item_is_shape(SPItem *item);
static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
+static void cc_connector_rerouting_finish(SPConnectorContext *const cc,
+ NR::Point *const p);
static void shape_event_attr_deleted(Inkscape::XML::Node *repr,
Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
static void shape_event_attr_deleted(Inkscape::XML::Node *repr,
Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data);
SPEventContext *ec = SP_EVENT_CONTEXT(cc);
ec->cursor_shape = cursor_connector_xpm;
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;
ec->hot_x = 1;
ec->hot_y = 1;
ec->xp = 0;
static gint
static gint
-sp_connector_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
+sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
{
gint ret = FALSE;
{
gint ret = FALSE;
- SPDesktop *desktop = ec->desktop;
+ SPDesktop *desktop = event_context->desktop;
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
+ SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context);
NR::Point p(event->button.x, event->button.y);
switch (event->type) {
case GDK_BUTTON_RELEASE:
NR::Point p(event->button.x, event->button.y);
switch (event->type) {
case GDK_BUTTON_RELEASE:
- if (event->button.button == 1) {
+ if (event->button.button == 1 && !event_context->space_panning) {
if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
(connector_within_tolerance))
{
if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
(connector_within_tolerance))
{
@@ -493,9 +491,10 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
NR::Point const event_w(bevent.x, bevent.y);
/* Find desktop coordinates */
NR::Point p = cc->desktop->w2d(event_w);
NR::Point const event_w(bevent.x, bevent.y);
/* Find desktop coordinates */
NR::Point p = cc->desktop->w2d(event_w);
+ SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
gint ret = FALSE;
gint ret = FALSE;
- if ( bevent.button == 1 ) {
+ if ( bevent.button == 1 && !event_context->space_panning ) {
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
@@ -532,7 +531,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
// This is the first point, so just snap it to the grid
// as there's no other points to go off.
SnapManager const &m = cc->desktop->namedview->snap_manager;
// This is the first point, so just snap it to the grid
// as there's no other points to go off.
SnapManager const &m = cc->desktop->namedview->snap_manager;
- p = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
+ p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE,
p, NULL).getPoint();
}
spcc_connector_set_initial_point(cc, p);
p, NULL).getPoint();
}
spcc_connector_set_initial_point(cc, p);
@@ -567,7 +566,17 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
break;
}
} else if (bevent.button == 3) {
break;
}
} else if (bevent.button == 3) {
- if (cc->npoints != 0) {
+ if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
+ // A context menu is going to be triggered here,
+ // so end the rerouting operation.
+ cc_connector_rerouting_finish(cc, &p);
+
+ cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+
+ // Don't set ret to TRUE, so we drop through to the
+ // parent handler which will open the context menu.
+ }
+ else if (cc->npoints != 0) {
spcc_connector_finish(cc);
ret = TRUE;
}
spcc_connector_finish(cc);
ret = TRUE;
}
connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent)
{
gint ret = FALSE;
connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion const &mevent)
{
gint ret = FALSE;
+ SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
- if (mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
+ if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
// allow middle-button scrolling
return FALSE;
}
// allow middle-button scrolling
return FALSE;
}
connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
{
gint ret = FALSE;
connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton const &revent)
{
gint ret = FALSE;
- if ( revent.button == 1 ) {
+ SPEventContext *event_context = SP_EVENT_CONTEXT(cc);
+ if ( revent.button == 1 && !event_context->space_panning ) {
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
SPDocument *doc = sp_desktop_document(desktop);
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
SPDocument *doc = sp_desktop_document(desktop);
@@ -692,29 +703,8 @@ connector_handle_button_release(SPConnectorContext *const cc, GdkEventButton con
}
case SP_CONNECTOR_CONTEXT_REROUTING:
{
}
case SP_CONNECTOR_CONTEXT_REROUTING:
{
- // Clear the temporary path:
- sp_curve_reset(cc->red_curve);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
-
- // Test whether we clicked on a connection point
- gchar *shape_label = conn_pt_handle_test(cc, p);
-
- if (shape_label) {
- if (cc->clickedhandle == cc->endpt_handle[0]) {
- sp_object_setAttribute(cc->clickeditem,
- "inkscape:connection-start",shape_label, false);
- }
- else {
- sp_object_setAttribute(cc->clickeditem,
- "inkscape:connection-end",shape_label, false);
- }
- g_free(shape_label);
- }
- cc->clickeditem->setHidden(false);
- sp_conn_adjust_path(SP_PATH(cc->clickeditem));
- cc->clickeditem->updateRepr();
- sp_document_done(doc);
- cc_set_active_conn(cc, cc->clickeditem);
+ cc_connector_rerouting_finish(cc, &p);
+
sp_document_ensure_up_to_date(doc);
cc->state = SP_CONNECTOR_CONTEXT_IDLE;
return TRUE;
sp_document_ensure_up_to_date(doc);
cc->state = SP_CONNECTOR_CONTEXT_IDLE;
return TRUE;
}
break;
case GDK_Escape:
}
break;
case GDK_Escape:
- if (cc->npoints != 0) {
+ if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) {
+
+ SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
+ SPDocument *doc = sp_desktop_document(desktop);
+
+ cc_connector_rerouting_finish(cc, NULL);
+
+ sp_document_undo(doc);
+
+ cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+ desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE,
+ _("Connector endpoint drag cancelled."));
+ ret = TRUE;
+ }
+ else if (cc->npoints != 0) {
// if drawing, cancel, otherwise pass it up for deselecting
cc->state = SP_CONNECTOR_CONTEXT_STOP;
spcc_reset_colors(cc);
// if drawing, cancel, otherwise pass it up for deselecting
cc->state = SP_CONNECTOR_CONTEXT_STOP;
spcc_reset_colors(cc);
}
}
+static void
+cc_connector_rerouting_finish(SPConnectorContext *const cc, NR::Point *const p)
+{
+ SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
+ SPDocument *doc = sp_desktop_document(desktop);
+
+ // Clear the temporary path:
+ sp_curve_reset(cc->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL);
+
+ if (p != NULL)
+ {
+ // Test whether we clicked on a connection point
+ gchar *shape_label = conn_pt_handle_test(cc, *p);
+
+ if (shape_label) {
+ if (cc->clickedhandle == cc->endpt_handle[0]) {
+ sp_object_setAttribute(cc->clickeditem,
+ "inkscape:connection-start",shape_label, false);
+ }
+ else {
+ sp_object_setAttribute(cc->clickeditem,
+ "inkscape:connection-end",shape_label, false);
+ }
+ g_free(shape_label);
+ }
+ }
+ cc->clickeditem->setHidden(false);
+ sp_conn_adjust_path(SP_PATH(cc->clickeditem));
+ cc->clickeditem->updateRepr();
+ sp_document_done(doc, SP_VERB_CONTEXT_CONNECTOR,
+ _("Reroute connector"));
+ cc_set_active_conn(cc, cc->clickeditem);
+}
+
+
static void
spcc_reset_colors(SPConnectorContext *cc)
{
static void
spcc_reset_colors(SPConnectorContext *cc)
{
@@ -793,8 +833,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);
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;
if (!cc->newConnRef) {
Avoid::Router *router = sp_desktop_document(dt)->router;
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
SPDocument *doc = sp_desktop_document(desktop);
SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(cc);
SPDocument *doc = sp_desktop_document(desktop);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
if ( c && !sp_curve_empty(c) ) {
/* We actually have something to write */
if ( c && !sp_curve_empty(c) ) {
/* We actually have something to write */
- Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
/* Set style */
sp_desktop_apply_style_tool(desktop, repr, "tools.connector", false);
/* Set style */
sp_desktop_apply_style_tool(desktop, repr, "tools.connector", false);
sp_curve_unref(c);
/* Flush pending updates */
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);
}
static void
sp_document_ensure_up_to_date(doc);
}
static void
-spcc_connector_finish_segment(SPConnectorContext *const cc, NR::Point const p)
+spcc_connector_finish_segment(SPConnectorContext *const cc, NR::Point const /*p*/)
{
if (!sp_curve_empty(cc->red_curve)) {
sp_curve_append_continuous(cc->green_curve, cc->red_curve, 0.0625);
{
if (!sp_curve_empty(cc->red_curve)) {
sp_curve_append_continuous(cc->green_curve, cc->red_curve, 0.0625);
static gboolean
static gboolean
-endpt_handler(SPKnot *knot, GdkEvent *event, SPConnectorContext *cc)
+endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc)
{
g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
{
g_assert( SP_IS_CONNECTOR_CONTEXT(cc) );
}
}
- NR::Rect bbox = sp_item_bbox_desktop(cc->active_shape);
- NR::Point center = bbox.midpoint();
- sp_knot_set_position(cc->connpthandle, ¢er, 0);
-
- sp_knot_show(cc->connpthandle);
-
+ NR::Maybe<NR::Rect> bbox = sp_item_bbox_desktop(cc->active_shape);
+ if (bbox) {
+ NR::Point center = bbox->midpoint();
+ sp_knot_set_position(cc->connpthandle, ¢er, 0);
+ sp_knot_show(cc->connpthandle);
+ } else {
+ sp_knot_hide(cc->connpthandle);
+ }
}
}
return;
}
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);
}
}
static void
static void
-shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child,
- Inkscape::XML::Node *ref, gpointer data)
+shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
+ Inkscape::XML::Node */*ref*/, gpointer data)
{
g_assert(data);
SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
{
g_assert(data);
SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
@@ -1319,8 +1365,8 @@ shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child,
static void
shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
static void
shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
- gchar const *old_value, gchar const *new_value,
- bool is_interactive, gpointer data)
+ gchar const */*old_value*/, gchar const */*new_value*/,
+ bool /*is_interactive*/, gpointer data)
{
g_assert(data);
SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
{
g_assert(data);
SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);