diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 0f8a4204a928b19217d7138eb31138e82466feb2..f201513c8973bb72eee63cf2374dff3a74fae67f 100644 (file)
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
static void sp_pen_context_finish(SPEventContext *ec);
static void sp_pen_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event);
+static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static void spdc_pen_set_initial_point(SPPenContext *pc, NR::Point const p);
static void spdc_pen_set_subsequent_point(SPPenContext *pc, NR::Point const p, bool statusbar);
static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent);
static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent);
static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent);
-static gint pen_handle_2button_press(SPPenContext *const pc);
+static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent);
static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event);
static void spdc_reset_colors(SPPenContext *pc);
event_context_class->finish = sp_pen_context_finish;
event_context_class->set = sp_pen_context_set;
event_context_class->root_handler = sp_pen_context_root_handler;
+ event_context_class->item_handler = sp_pen_context_item_handler;
}
/**
@@ -284,6 +286,29 @@ spdc_endpoint_snap_handle(SPPenContext const *const pc, NR::Point &p, guint cons
spdc_endpoint_snap_free(pc, p, state);
}
+static gint
+sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
+{
+ SPPenContext *const pc = SP_PEN_CONTEXT(ec);
+
+ gint ret = FALSE;
+
+ switch (event->type) {
+ case GDK_BUTTON_PRESS:
+ ret = pen_handle_button_press(pc, event->button);
+ break;
+ default:
+ break;
+ }
+
+ if (!ret) {
+ if (((SPEventContextClass *) pen_parent_class)->item_handler)
+ ret = ((SPEventContextClass *) pen_parent_class)->item_handler(ec, item, event);
+ }
+
+ return ret;
+}
+
/**
* Callback to handle all pen events.
*/
break;
case GDK_2BUTTON_PRESS:
- ret = pen_handle_2button_press(pc);
+ ret = pen_handle_2button_press(pc, event->button);
break;
case GDK_KEY_PRESS:
@@ -340,24 +365,24 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
return FALSE;
}
+ SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
+ SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
+ NR::Point const event_w(bevent.x, bevent.y);
+ NR::Point const event_dt(desktop->w2d(event_w));
+
gint ret = FALSE;
if (bevent.button == 1) {
- SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
- SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
-
if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
return TRUE;
}
- NR::Point const event_w(bevent.x, bevent.y);
pen_drag_origin_w = event_w;
pen_within_tolerance = true;
/* Test whether we hit any anchor. */
SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w);
- NR::Point const event_dt(desktop->w2d(event_w));
switch (pc->mode) {
case SP_PEN_CONTEXT_MODE_CLICK:
/* In click mode we add point on release */
@@ -458,7 +483,16 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
}
} else if (bevent.button == 3) {
if (pc->npoints != 0) {
- spdc_pen_finish(pc, FALSE);
+
+ spdc_pen_finish_segment(pc, event_dt, bevent.state);
+ if (pc->green_closed) {
+ // finishing at the start anchor, close curve
+ spdc_pen_finish(pc, TRUE);
+ } else {
+ // finishing at some other anchor, finish curve but not close
+ spdc_pen_finish(pc, FALSE);
+ }
+
ret = TRUE;
}
}
@@ -710,10 +744,10 @@ pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
}
static gint
-pen_handle_2button_press(SPPenContext *const pc)
+pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent)
{
gint ret = FALSE;
- if (pc->npoints != 0) {
+ if (pc->npoints != 0 && bevent.button != 2) {
spdc_pen_finish(pc, FALSE);
ret = TRUE;
}