event-context.cpp revision f200d31b8a03050faa7243929bbd5698db488399
#define __SP_EVENT_CONTEXT_C__
/** \file
* Main event handling, and related helper functions.
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2005 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/** \class SPEventContext
* SPEventContext is an abstract base class of all tools. As the name
* indicates, event context implementations process UI events (mouse
* movements and keypresses) and take actions (like creating or modifying
* objects). There is one event context implementation for each tool,
* plus few abstract base classes. Writing a new tool involves
* subclassing SPEventContext.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "event-context.h"
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include <cstring>
#include <string>
#include "display/sp-canvas.h"
#include "xml/node-event-vector.h"
#include "sp-cursor.h"
#include "shortcuts.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "sp-namedview.h"
#include "selection.h"
#include "file.h"
#include "interface.h"
#include "macros.h"
#include "tools-switch.h"
#include "preferences.h"
#include "message-context.h"
#include "gradient-drag.h"
#include "object-edit.h"
#include "attributes.h"
#include "rubberband.h"
#include "selcue.h"
#include "lpe-tool-context.h"
#include "ui/tool/control-point.h"
static GObjectClass *parent_class;
// globals for temporary switching to selector by space
static bool selector_toggled = FALSE;
static int switch_selector_to = 0;
// globals for temporary switching to dropper by 'D'
static bool dropper_toggled = FALSE;
static int switch_dropper_to = 0;
static bool within_tolerance = false;
// globals for keeping track of keyboard scroll events in order to accelerate
static guint32 scroll_event_time = 0;
static guint scroll_keyval = 0;
/**
* Registers the SPEventContext class with Glib and returns its type number.
*/
GType sp_event_context_get_type(void) {
if (!type) {
sizeof(SPEventContext), 4,
};
(GTypeFlags) 0);
}
return type;
}
/**
* Callback to set up the SPEventContext vtable.
*/
}
/**
* Clears all SPEventContext object members.
*/
event_context->space_panning = false;
}
/**
* Callback to free and null member variables of SPEventContext object.
*/
if (ec->_message_context) {
delete ec->_message_context;
}
}
}
if (ec->pref_observer) {
delete ec->pref_observer;
}
if (ec->_delayed_snap_event) {
delete ec->_delayed_snap_event;
}
}
/**
* Recreates and draws cursor on desktop related to SPEventContext.
*/
if (w->window) {
/* fixme: */
if (ec->cursor_shape) {
}
}
gdk_flush();
}
}
/**
* Callback that gets called on initialization of SPEventContext object.
* Redraws mouse cursor, at the moment.
*/
}
/**
* \brief Gobbles next key events on the queue with the same keyval and mask. Returns the number of events consumed.
*/
gint i = 0;
event_next = gdk_event_get();
// while the next event is also a key notify with the same keyval and mask,
i++;
// kill it
// get next
event_next = gdk_event_get();
}
// otherwise, put it back onto the queue
if (event_next)
return i;
}
/**
* \brief Gobbles next motion notify events on the queue with the same mask. Returns the number of events consumed.
*/
gint i = 0;
event_next = gdk_event_get();
// while the next event is also a key notify with the same keyval and mask,
// kill it
// get next
event_next = gdk_event_get();
i++;
}
// otherwise, put it back onto the queue
if (event_next)
return i;
}
/**
* Toggles current tool between active tool and selector tool.
* Subroutine of sp_event_context_private_root_handler().
*/
if (!dt->event_context)
return;
if (selector_toggled) {
if (switch_selector_to)
} else
return;
} else {
}
}
/**
* Toggles current tool between active tool and dropper tool.
* Subroutine of sp_event_context_private_root_handler().
*/
if (!dt->event_context)
return;
if (dropper_toggled) {
if (switch_dropper_to)
} else
return;
} else {
}
}
/**
* Calculates and keeps track of scroll acceleration.
* Subroutine of sp_event_context_private_root_handler().
*/
SPCanvas */*canvas*/) {
/* key pressed within 500ms ? (1/2 second) */
} else {
}
return scroll_multiply;
}
/**
* Main event dispatch, gets called from Gdk.
*/
static unsigned int panning = 0;
static unsigned int zoom_rb = 0;
/// @todo REmove redundant /value in preference keys
case GDK_2BUTTON_PRESS:
if (panning) {
panning = 0;
} else {
/* sp_desktop_dialog(); */
}
break;
case GDK_BUTTON_PRESS:
// save drag origin
within_tolerance = true;
case 1:
if (event_context->space_panning) {
// When starting panning, make sure there are no snap events pending because these might disable the panning again
panning = 1;
}
break;
case 2:
zoom_rb = 2;
} else {
// When starting panning, make sure there are no snap events pending because these might disable the panning again
panning = 2;
}
break;
case 3:
& GDK_CONTROL_MASK) {
// When starting panning, make sure there are no snap events pending because these might disable the panning again
panning = 3;
} else {
}
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
if (panning) {
/* Gdk seems to lose button release for us sometimes :-( */
panning = 0;
} else {
< tolerance)) {
// do not drag if we're within tolerance from origin
break;
}
// Once the user has moved farther than tolerance from
// the original location (indicating they intend to move
// the object, not click), then always process the motion
// notify coordinates as given (no snapping back to origin)
within_tolerance = false;
// gobble subsequent motion events to prevent "sticking"
// when scrolling is slow
}
} else if (zoom_rb) {
< tolerance)) {
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
within_tolerance = false;
} else {
}
if (zoom_rb == 2)
}
break;
case GDK_BUTTON_RELEASE:
zoom_rb = 0;
if (panning) {
panning = 0;
}
panning = 0;
// in slow complex drawings, some of the motion events are lost;
// to make up for this, we scroll it once again to the button-up event coordinates
// (i.e. canvas will always get scrolled all the way to the mouse release point,
// even if few intermediate steps were visible)
zoom_rb = 0;
if (b && !within_tolerance) {
}
}
break;
case GDK_KEY_PRESS: {
"/options/scrollingacceleration/value", 0, 0, 6);
10, 0, 1000);
// GDK insists on stealing these keys (F1 for no idea what, tab for cycling widgets
// in the editing window). So we resteal them back and run our regular shortcut
// invoker on them.
unsigned int shortcut;
case GDK_Tab:
case GDK_ISO_Left_Tab:
case GDK_F1:
break;
case GDK_D:
case GDK_d:
}
break;
case GDK_Q:
case GDK_q:
if (desktop->quick_zoomed()) {
}
desktop->zoom_quick(true);
}
break;
case GDK_W:
case GDK_w:
case GDK_F4:
/* Close view */
if (MOD__CTRL_ONLY) {
}
break;
case GDK_Left: // Ctrl Left
case GDK_KP_Left:
case GDK_KP_4:
if (MOD__CTRL_ONLY) {
}
break;
case GDK_Up: // Ctrl Up
case GDK_KP_Up:
case GDK_KP_8:
if (MOD__CTRL_ONLY) {
}
break;
case GDK_Right: // Ctrl Right
case GDK_KP_Right:
case GDK_KP_6:
if (MOD__CTRL_ONLY) {
}
break;
case GDK_Down: // Ctrl Down
case GDK_KP_Down:
case GDK_KP_2:
if (MOD__CTRL_ONLY) {
}
break;
case GDK_F10:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_space:
event_context->space_panning = true;
_("<b>Space+mouse drag</b> to pan canvas"));
} else {
}
break;
case GDK_z:
case GDK_Z:
if (MOD__ALT_ONLY) {
}
break;
default:
break;
}
}
break;
case GDK_KEY_RELEASE:
case GDK_space:
if (event_context->space_panning) {
event_context->space_panning = false;
if (panning == 1) {
panning = 0;
}
}
break;
case GDK_Q:
case GDK_q:
if (desktop->quick_zoomed()) {
desktop->zoom_quick(false);
}
break;
default:
break;
}
break;
case GDK_SCROLL: {
/* shift + wheel, pan left--right */
case GDK_SCROLL_UP:
break;
case GDK_SCROLL_DOWN:
break;
default:
break;
}
/* ctrl + wheel, zoom in--out */
double rel_zoom;
case GDK_SCROLL_UP:
break;
case GDK_SCROLL_DOWN:
break;
default:
rel_zoom = 0.0;
break;
}
if (rel_zoom != 0.0) {
}
/* no modifier, pan up--down (left--right on multiwheel mice?) */
} else {
case GDK_SCROLL_UP:
break;
case GDK_SCROLL_DOWN:
break;
case GDK_SCROLL_LEFT:
break;
case GDK_SCROLL_RIGHT:
break;
}
}
break;
}
default:
break;
}
return ret;
}
/**
* Handles item specific events. Gets called from Gdk.
*
* Only reacts to right mouse button at the moment.
* \todo Fixme: do context sensitive popup menu on items.
*/
case GDK_BUTTON_PRESS:
}
break;
default:
break;
}
return ret;
}
/**
* @brief An observer that relays pref changes to the derived classes
*/
public:
}
}
}
private:
SPEventContext * const _ec;
};
/**
* Creates new SPEventContext object and calls its virtual setup() function.
* @todo This is bogus. pref_path should be a private property of the inheriting objects.
*/
unsigned int key) {
if (pref_path) {
}
return ec;
}
/**
* Finishes SPEventContext.
*/
ec->enableSelectionCue(false);
g_warning("Finishing event context with active link\n");
}
}
//-------------------------------member functions
/**
*/
if (enable) {
if (!_selcue) {
}
} else {
delete _selcue;
}
}
/**
*/
if (enable) {
if (!_grdrag) {
}
} else {
if (_grdrag) {
delete _grdrag;
}
}
}
/**
* Calls virtual set() function of SPEventContext.
*/
}
}
/**
* Calls virtual activate() function of SPEventContext.
*/
// Make sure no delayed snapping events are carried over after switching contexts
// (this is only an additional safety measure against sloppy coding, because each
// context should take care of this by itself.
}
/**
* Calls virtual deactivate() function of SPEventContext.
*/
}
/**
* Calls virtual root_handler(), the main event handling function.
*/
case GDK_MOTION_NOTIFY:
(GdkEventMotion *) event,
break;
case GDK_BUTTON_RELEASE:
if (event_context->_delayed_snap_event) {
// If we have any pending snapping action, then invoke it now
}
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
// Snapping will be on hold if we're moving the mouse at high speeds. When starting
// drawing a new shape we really should snap though.
false);
break;
default:
break;
}
}
ret =
return ret;
}
/**
* Calls virtual item_handler(), the item event handling function.
*/
case GDK_MOTION_NOTIFY:
(GdkEventMotion *) event,
break;
case GDK_BUTTON_RELEASE:
if (event_context->_delayed_snap_event) {
// If we have any pending snapping action, then invoke it now
}
break;
/*case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
// Snapping will be on hold if we're moving the mouse at high speeds. When starting
// drawing a new shape we really should snap though.
event_context->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false);
break;
*/
default:
break;
}
}
ret =
if (!ret) {
} else {
}
return ret;
}
/**
* Emits 'position_set' signal on desktop and shows coordinates on status bar.
*/
return;
}
}
//-------------------------------------------------------------------
/**
* Create popup menu and tell Gtk to show it.
*/
/* fixme: This is not what I want but works for now (Lauris) */
}
case GDK_BUTTON_PRESS:
break;
case GDK_KEY_PRESS:
break;
default:
break;
}
}
/**
* Show tool context specific modifier tip.
*/
== GDK_Control_R));
== GDK_Shift_R));
}
}
/**
* Return the keyval corresponding to the key event in group 0, i.e.,
* in the main (English) layout.
*
* Use this instead of simply event->keyval, so that your keyboard shortcuts
* work regardless of layouts (e.g., in Cyrillic).
*/
return keyval;
}
/**
* Returns item at point p in desktop.
*
* If state includes alt key mask, cyclically selects under; honors
* into_groups.
*/
SPItem *
bool select_under, bool into_groups) {
if (select_under) {
}
} else
return item;
}
/**
* Returns item if it is under point p in desktop, at any depth; otherwise returns NULL.
*
* Honors into_groups.
*/
SPItem *
return item_at_point;
}
return ec->shape_editor;
}
case GDK_BUTTON_PRESS:
g_print("GDK_BUTTON_PRESS");
break;
case GDK_2BUTTON_PRESS:
g_print("GDK_2BUTTON_PRESS");
break;
case GDK_3BUTTON_PRESS:
g_print("GDK_3BUTTON_PRESS");
break;
case GDK_MOTION_NOTIFY:
g_print("GDK_MOTION_NOTIFY");
break;
case GDK_ENTER_NOTIFY:
g_print("GDK_ENTER_NOTIFY");
break;
case GDK_LEAVE_NOTIFY:
g_print("GDK_LEAVE_NOTIFY");
break;
case GDK_BUTTON_RELEASE:
g_print("GDK_BUTTON_RELEASE");
break;
case GDK_KEY_PRESS:
break;
case GDK_KEY_RELEASE:
break;
default:
//g_print ("even type not recognized");
break;
}
if (print_return) {
g_print("\n");
}
}
// Snapping occurs when dragging with the left mouse button down, or when hovering e.g. in the pen tool with left mouse button up
bool const c1 = event->state & GDK_BUTTON2_MASK; // We shouldn't hold back any events when other mouse buttons have been
bool const c2 = event->state & GDK_BUTTON3_MASK; // pressed, e.g. when scrolling with the middle mouse button; if we do then
// Inkscape will get stuck in an unresponsive state
// The snap delay will repeat the last motion event, which will lead to
// erroneous points in the calligraphy context. And because we don't snap
// in this context, we might just as well disable the snap delay all together
// Make sure that we don't send any pending snap events to a context if we know in advance
// that we're not going to snap any way (e.g. while scrolling with middle mouse button)
// Any motion event might affect the state of the context, leading to unexpected behavior
// Snap when speed drops below e.g. 0.02 px/msec, or when no motion events have occurred for some period.
// i.e. snap when we're at stand still. A speed threshold enforces snapping for tablets, which might never
// be fully at stand still and might keep spitting out motion events.
true); // put snapping on hold
if (prev_pos) {
// We're moving fast, so postpone any snapping until the next GDK_MOTION_NOTIFY event. We
// will keep on postponing the snapping as long as the speed is high.
// We must snap at some point in time though, so set a watchdog timer at some time from
// now, just in case there's no future motion event that drops under the speed limit (when
// stopping abruptly)
delete ec->_delayed_snap_event;
// If the watchdog expires before a new motion event is received, we will snap (as explained
// above). This means however that when the timer is too short, we will always snap and that the
// speed threshold is ineffective. In the extreme case the delay is set to zero, and snapping will
// be immediate, as it used to be in the old days ;-).
} else { // Speed is very low, so we're virtually at stand still
// But if we're really standing still, then we should snap now. We could use some low-pass filtering,
// otherwise snapping occurs for each jitter movement. For this filtering we'll leave the watchdog to expire,
// snap, and set a new watchdog again.
// it might have already expired, so we'll set a new one; the snapping frequency will be limited this way
} // else: watchdog has been set before and we'll wait for it to expire
}
} else {
// This is the first GDK_MOTION_NOTIFY event, so postpone snapping and set the watchdog
}
}
}
// Snap NOW! For this the "postponed" flag will be reset and the last motion event will be repeated
// This might occur when this method is called directly, i.e. not through the timer
// E.g. on GDK_BUTTON_RELEASE in sp_event_context_root_handler()
return FALSE;
}
return false;
}
break;
}
}
break;
case DelayedSnapEvent::KNOT_HANDLER: {
}
}
break;
case DelayedSnapEvent::CONTROL_POINT_HANDLER: {
}
break;
default:
g_warning("Origin of snap-delay event has not been defined!;");
break;
}
delete dse;
return FALSE; //Kills the timer and stops it from executing this callback over and over again.
}
delete ec->_delayed_snap_event;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :