diff --git a/src/select-context.cpp b/src/select-context.cpp
index b2a05dca2217567ab785f6bea5e767da91e1c2e9..4d1d06fe3ad44e823371fc9e62043fe6e3f612e4 100644 (file)
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
-#define __SP_SELECT_CONTEXT_C__
-
/*
* Selection and transformation context
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
+ * Abhishek Sharma
+ * Jon A. Cruz <jon@joncruz.org>
*
+ * Copyright (C) 2010 authors
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
* Copyright (C) 1999-2005 Authors
*
#include "selection-describer.h"
#include "seltrans.h"
#include "box3d.h"
+#include "display/sp-canvas.h"
+#include "display/nr-arena-item.h"
+
+using Inkscape::DocumentUndo;
static void sp_select_context_class_init(SPSelectContextClass *klass);
static void sp_select_context_init(SPSelectContext *select_context);
event_context_class->set = sp_select_context_set;
event_context_class->root_handler = sp_select_context_root_handler;
event_context_class->item_handler = sp_select_context_item_handler;
+}
+
+static void
+sp_select_context_init(SPSelectContext *sc)
+{
+ sc->dragging = FALSE;
+ sc->moved = FALSE;
+ sc->button_press_shift = false;
+ sc->button_press_ctrl = false;
+ sc->button_press_alt = false;
+ sc->cycling_items = NULL;
+ sc->cycling_items_cmp = NULL;
+ sc->cycling_items_selected_before = NULL;
+ sc->cycling_cur_item = NULL;
+ sc->_seltrans = NULL;
+ sc->_describer = NULL;
// cursors in select context
CursorSelectMouseover = sp_cursor_new_from_xpm(cursor_select_m_xpm , 1, 1);
handles[10] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_sw_xpm);
handles[11] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_rotate_w_xpm);
handles[12] = gdk_pixbuf_new_from_xpm_data((gchar const **)handle_center_xpm);
-
-}
-
-static void
-sp_select_context_init(SPSelectContext *sc)
-{
- sc->dragging = FALSE;
- sc->moved = FALSE;
- sc->button_press_shift = false;
- sc->button_press_ctrl = false;
- sc->button_press_alt = false;
- sc->_seltrans = NULL;
- sc->_describer = NULL;
}
static void
SPDesktop *desktop = ec->desktop;
- select_context->_describer = new Inkscape::SelectionDescriber(desktop->selection, desktop->messageStack());
+ select_context->_describer = new Inkscape::SelectionDescriber(
+ desktop->selection,
+ desktop->messageStack(),
+ _("Click selection to toggle scale/rotation handles"),
+ _("No objects selected. Click, Shift+click, Alt+scroll mouse on top of objects, or drag around objects to select.")
+ );
select_context->_seltrans = new Inkscape::SelTrans(desktop);
seltrans->ungrab();
sc->moved = FALSE;
sc->dragging = FALSE;
+ sp_event_context_discard_delayed_snap_event(event_context);
drag_escaped = 1;
if (sc->item) {
// only undo if the item is still valid
if (SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))) {
- sp_document_undo(sp_desktop_document(desktop));
+ DocumentUndo::undo(sp_desktop_document(desktop));
}
sp_object_unref( SP_OBJECT(sc->item), NULL);
// NOTE: This is a workaround to a bug.
// When the ctrl key is held, sc->item is not defined
// so in this case (only), we skip the object doc check
- sp_document_undo(sp_desktop_document(desktop));
+ DocumentUndo::undo(sp_desktop_document(desktop));
}
sc->item = NULL;
@@ -325,6 +339,8 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE
sc->dragging = TRUE;
sc->moved = FALSE;
+ gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, CursorSelectDragging);
+
sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
// remember the clicked item in sc->item:
@@ -360,16 +376,14 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE
case GDK_ENTER_NOTIFY:
{
- if (!desktop->isWaitingCursor()) {
- GdkCursor *cursor = gdk_cursor_new(GDK_FLEUR);
- gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, cursor);
- gdk_cursor_destroy(cursor);
+ if (!desktop->isWaitingCursor() && !sc->dragging) {
+ gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, CursorSelectMouseover);
}
break;
}
case GDK_LEAVE_NOTIFY:
- if (!desktop->isWaitingCursor())
+ if (!desktop->isWaitingCursor() && !sc->dragging)
gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, event_context->cursor);
break;
@@ -395,6 +409,43 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE
return ret;
}
+static void
+sp_select_context_cycle_through_items(SPSelectContext *sc, Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) {
+ if (!sc->cycling_cur_item)
+ return;
+
+ NRArenaItem *arenaitem;
+ SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop;
+ SPItem *item = SP_ITEM(sc->cycling_cur_item->data);
+
+ // Deactivate current item
+ if (!g_list_find(sc->cycling_items_selected_before, item) && selection->includes(item))
+ selection->remove(item);
+ arenaitem = item->get_arenaitem(desktop->dkey);
+ nr_arena_item_set_opacity (arenaitem, 0.3);
+
+ // Find next item and activate it
+ GList *next;
+ if (scroll_event->direction == GDK_SCROLL_UP) {
+ next = sc->cycling_cur_item->next;
+ if (next == NULL)
+ next = sc->cycling_items;
+ } else {
+ next = sc->cycling_cur_item->prev;
+ if (next == NULL)
+ next = g_list_last(sc->cycling_items);
+ }
+ sc->cycling_cur_item = next;
+ item = SP_ITEM(sc->cycling_cur_item->data);
+ arenaitem = item->get_arenaitem(desktop->dkey);
+ nr_arena_item_set_opacity (arenaitem, 1.0);
+
+ if (shift_pressed)
+ selection->add(item);
+ else
+ selection->set(item);
+}
+
static gint
sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
- gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000);
- tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
- int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
-
// make sure we still have valid objects to move around
if (sc->item && SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))==NULL) {
sp_select_context_abort(event_context);
desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
sp_desktop_selection(desktop)->clear();
sc->dragging = false;
+ sp_event_context_discard_delayed_snap_event(event_context);
sp_canvas_end_forced_full_redraws(desktop->canvas);
} else { // switch tool
break;
case GDK_MOTION_NOTIFY:
- if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
+ {
+ tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+ if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
Geom::Point const motion_pt(event->motion.x, event->motion.y);
Geom::Point const p(desktop->w2d(motion_pt));
if (sc->button_press_ctrl || (sc->button_press_alt && !sc->button_press_shift && !selection->isEmpty())) {
// if it's not click and ctrl or alt was pressed (the latter with some selection
// but not with shift) we want to drag rather than rubberband
- sc->dragging = TRUE;
+ sc->dragging = TRUE;
+ gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, CursorSelectDragging);
sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
}
@@ -507,14 +557,14 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
// and also when we started within tolerance, but trespassed tolerance outside of item
Inkscape::Rubberband::get(desktop)->stop();
SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear();
- item_at_point = desktop->item_at_point(Geom::Point(event->button.x, event->button.y), FALSE);
+ item_at_point = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), FALSE);
if (!item_at_point) // if no item at this point, try at the click point (bug 1012200)
- item_at_point = desktop->item_at_point(Geom::Point(xp, yp), FALSE);
+ item_at_point = desktop->getItemAtPoint(Geom::Point(xp, yp), FALSE);
if (item_at_point || sc->moved || sc->button_press_alt) {
// drag only if starting from an item, or if something is already grabbed, or if alt-dragging
if (!sc->moved) {
- item_in_group = desktop->item_at_point(Geom::Point(event->button.x, event->button.y), TRUE);
- group_at_point = desktop->group_at_point(Geom::Point(event->button.x, event->button.y));
+ item_in_group = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE);
+ group_at_point = desktop->getGroupAtPoint(Geom::Point(event->button.x, event->button.y));
if (SP_IS_LAYER(selection->single()))
group_at_point = SP_GROUP(selection->single());
if (item_at_point && !selection->includes(item_at_point))
selection->set(item_at_point);
} // otherwise, do not change selection so that dragging selected-within-group items, as well as alt-dragging, is possible
- seltrans->grab(p, -1, -1, FALSE);
+ seltrans->grab(p, -1, -1, FALSE, TRUE);
sc->moved = TRUE;
}
if (!seltrans->isEmpty())
ret = TRUE;
} else {
sc->dragging = FALSE;
-
+ sp_event_context_discard_delayed_snap_event(event_context);
sp_canvas_end_forced_full_redraws(desktop->canvas);
}
} else {
}
}
break;
+ }
case GDK_BUTTON_RELEASE:
xp = yp = 0;
if ((event->button.button == 1) && (sc->grabbed) && !event_context->space_panning) {
}
}
sc->dragging = FALSE;
-
+ gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, CursorSelectMouseover);
+ sp_event_context_discard_delayed_snap_event(event_context);
sp_canvas_end_forced_full_redraws(desktop->canvas);
if (sc->item) {
@@ -604,15 +656,15 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
}
sc->item = NULL;
} else {
- Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get(desktop);
+ Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
if (r->is_started() && !within_tolerance) {
// this was a rubberband drag
GSList *items = NULL;
if (r->getMode() == RUBBERBAND_MODE_RECT) {
Geom::OptRect const b = r->getRectangle();
- items = sp_document_items_in_box(sp_desktop_document(desktop), desktop->dkey, *b);
+ items = sp_desktop_document(desktop)->getItemsInBox(desktop->dkey, *b);
} else if (r->getMode() == RUBBERBAND_MODE_TOUCHPATH) {
- items = sp_document_items_at_points(sp_desktop_document(desktop), desktop->dkey, r->getPoints());
+ items = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, r->getPoints());
}
seltrans->resetState();
@@ -694,10 +746,94 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
sc->button_press_alt = false;
break;
+ case GDK_SCROLL:
+ {
+ SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
+ GdkEventScroll *scroll_event = (GdkEventScroll*) event;
+
+ if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed
+ bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK;
+
+ /* Rebuild list of items underneath the mouse pointer */
+ Geom::Point p = desktop->d2w(desktop->point());
+ SPItem *item = desktop->getItemAtPoint(p, true, NULL);
+
+ // Save pointer to current cycle-item so that we can find it again later, in the freshly built list
+ SPItem *tmp_cur_item = sc->cycling_cur_item ? SP_ITEM(sc->cycling_cur_item->data) : NULL;
+ g_list_free(sc->cycling_items);
+ sc->cycling_items = NULL;
+ sc->cycling_cur_item = NULL;
+
+ while(item != NULL) {
+ sc->cycling_items = g_list_append(sc->cycling_items, item);
+ item = desktop->getItemAtPoint(p, true, item);
+ }
+
+ /* Compare current item list with item list during previous scroll ... */
+ GList *l1, *l2;
+ bool item_lists_differ = false;
+ // Note that we can do an 'or' comparison in the loop because it is safe to call g_list_next with a NULL pointer.
+ for (l1 = sc->cycling_items, l2 = sc->cycling_items_cmp; l1 != NULL || l2 != NULL; l1 = g_list_next(l1), l2 = g_list_next(l2)) {
+ if ((l1 !=NULL && l2 == NULL) || (l1 == NULL && l2 != NULL) || (l1->data != l2->data)) {
+ item_lists_differ = true;
+ break;
+ }
+ }
+
+ /* If list of items under mouse pointer hasn't changed ... */
+ if (!item_lists_differ) {
+ // ... find current item in the freshly built list and continue cycling ...
+ // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead
+ sc->cycling_cur_item = g_list_find(sc->cycling_items, tmp_cur_item);
+ g_assert(sc->cycling_cur_item != NULL || sc->cycling_items == NULL);
+ } else {
+ // ... otherwise reset opacities for outdated items ...
+ NRArenaItem *arenaitem;
+ for(GList *l = sc->cycling_items_cmp; l != NULL; l = l->next) {
+ arenaitem = SP_ITEM(l->data)->get_arenaitem(desktop->dkey);
+ nr_arena_item_set_opacity (arenaitem, 1.0);
+ //if (!shift_pressed && !g_list_find(sc->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data)))
+ if (!g_list_find(sc->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data)))
+ selection->remove(SP_ITEM(l->data));
+ }
+
+ // ... clear the lists ...
+ g_list_free(sc->cycling_items_cmp);
+ g_list_free(sc->cycling_items_selected_before);
+ sc->cycling_items_cmp = NULL;
+ sc->cycling_items_selected_before = NULL;
+ sc->cycling_cur_item = NULL;
+
+ // ... and rebuild them with the new items.
+ sc->cycling_items_cmp = g_list_copy(sc->cycling_items);
+ SPItem *item;
+ for(GList *l = sc->cycling_items; l != NULL; l = l->next) {
+ item = SP_ITEM(l->data);
+ arenaitem = item->get_arenaitem(desktop->dkey);
+ nr_arena_item_set_opacity (arenaitem, 0.3);
+ if (selection->includes(item)) {
+ // already selected items are stored separately, too
+ sc->cycling_items_selected_before = g_list_append(sc->cycling_items_selected_before, item);
+ }
+ }
+
+ // set the current item to the bottommost one so that the cycling step below re-starts at the top
+ sc->cycling_cur_item = g_list_last(sc->cycling_items);
+ }
+
+ // Cycle through the items underneath the mouse pointer, one-by-one
+ sp_select_context_cycle_through_items(sc, selection, scroll_event, shift_pressed);
+
+ ret = TRUE;
+ }
+ break;
+ }
+
case GDK_KEY_PRESS: // keybindings for select context
- {
- guint keyval = get_group0_keyval(&event->key);
+ {
+ {
+ guint keyval = get_group0_keyval(&event->key);
bool alt = ( MOD__ALT
|| (keyval == GDK_Alt_L)
|| (keyval == GDK_Alt_R)
@@ -721,19 +857,21 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
_("<b>Ctrl</b>: click to select in groups; drag to move hor/vert"),
_("<b>Shift</b>: click to toggle select; drag for rubberband selection"),
- _("<b>Alt</b>: click to select under; drag to move selected or select by touch"));
+ _("<b>Alt</b>: click to select under; scroll mouse-wheel to cycle-select; drag to move selected or select by touch"));
// if Alt and nonempty selection, show moving cursor ("move selected"):
if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) {
- GdkCursor *cursor = gdk_cursor_new(GDK_FLEUR);
- gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, cursor);
- gdk_cursor_destroy(cursor);
+ gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, CursorSelectDragging);
}
//*/
break;
}
- }
+ }
- switch (get_group0_keyval (&event->key)) {
+ gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px
+ gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000);
+ int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
+
+ switch (get_group0_keyval (&event->key)) {
case GDK_Left: // move selection left
case GDK_KP_Left:
case GDK_KP_4:
selection->clear();
ret = TRUE;
break;
+
case GDK_a:
case GDK_A:
if (MOD__CTRL_ONLY) {
break;
}
break;
-
+ }
case GDK_KEY_RELEASE:
{
guint keyval = get_group0_keyval(&event->key);
@@ -942,11 +1081,30 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
if (alt) {
Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_RECT);
}
+ } else {
+ if (alt) { // TODO: Should we have a variable like is_cycling or is it harmless to run this piece of code each time?
+ // quit cycle-selection and reset opacities
+ SPSelectContext *sc = SP_SELECT_CONTEXT(event_context);
+ NRArenaItem *arenaitem;
+ for (GList *l = sc->cycling_items; l != NULL; l = g_list_next(l)) {
+ arenaitem = SP_ITEM(l->data)->get_arenaitem(desktop->dkey);
+ nr_arena_item_set_opacity (arenaitem, 1.0);
+ }
+ g_list_free(sc->cycling_items);
+ g_list_free(sc->cycling_items_selected_before);
+ g_list_free(sc->cycling_items_cmp);
+ sc->cycling_items = NULL;
+ sc->cycling_items_selected_before = NULL;
+ sc->cycling_cur_item = NULL;
+ sc->cycling_items_cmp = NULL;
+ }
}
+
}
// set cursor to default.
- if (!desktop->isWaitingCursor())
+ if (!desktop->isWaitingCursor()) {
gdk_window_set_cursor(GTK_WIDGET(sp_desktop_canvas(desktop))->window, event_context->cursor);
+ }
break;
default:
break;