event-context.cpp revision b2e46b1363564aa72394ee2feb6a5a6cb49194a5
#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 <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 "selection.h"
#include "file.h"
#include "interface.h"
#include "macros.h"
#include "tools-switch.h"
#include "prefs-utils.h"
#include "message-context.h"
#include "gradient-drag.h"
#include "object-edit.h"
#include "attributes.h"
#include "rubberband.h"
#include "selcue.h"
#include "event-context.h"
static gint sp_event_context_private_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
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.
*/
{
if (!type) {
sizeof(SPEventContextClass),
sizeof(SPEventContext),
4,
NULL, /* value_table */
};
}
return type;
}
/**
* Callback to set up the SPEventContext vtable.
*/
static void
{
}
/**
* Clears all SPEventContext object members.
*/
static void
{
event_context->space_panning = false;
}
/**
* Callback to free and null member variables of SPEventContext object.
*/
static void
{
if (ec->_message_context) {
delete ec->_message_context;
}
}
}
if (ec->prefs_repr) {
}
}
/**
* Recreates and draws cursor on desktop related to SPEventContext.
*/
void
{
if (w->window) {
/* fixme: */
if (ec->cursor_shape) {
}
}
}
}
/**
* Callback that gets called on initialization of SPEventContext object.
* Redraws mouse cursor, at the moment.
*/
static void
{
}
/**
* \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
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
return i;
}
/**
* Toggles current tool between active tool and selector tool.
* Subroutine of sp_event_context_private_root_handler().
*/
static void
{
if (!dt->event_context) return;
if (selector_toggled) {
} else return;
} else {
}
}
/**
* Toggles current tool between active tool and dropper tool.
* Subroutine of sp_event_context_private_root_handler().
*/
static void
{
if (!dt->event_context) return;
if (dropper_toggled) {
} else return;
} else {
}
}
/**
* Calculates and keeps track of scroll acceleration.
* Subroutine of sp_event_context_private_root_handler().
*/
{
/* 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;
"options.dragtolerance","value", 0, 0, 100);
double const zoom_inc = prefs_get_double_attribute_limited(
double const acceleration = prefs_get_double_attribute_limited(
int const key_scroll = prefs_get_int_attribute_limited(
"options.keyscroll", "value", 10, 0, 1000);
int const wheel_scroll = prefs_get_int_attribute_limited(
"options.wheelscroll", "value", 40, 0, 1000);
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) {
panning = 1;
}
break;
case 2:
zoom_rb = 2;
} else {
panning = 2;
}
break;
case 3:
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 {
if ( within_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) {
if ( within_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:
// 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_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) {
int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop)));
}
break;
case GDK_Up: // Ctrl Up
case GDK_KP_Up:
case GDK_KP_8:
if (MOD__CTRL_ONLY) {
int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop)));
}
break;
case GDK_Right: // Ctrl Right
case GDK_KP_Right:
case GDK_KP_6:
if (MOD__CTRL_ONLY) {
int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop)));
}
break;
case GDK_Down: // Ctrl Down
case GDK_KP_Down:
case GDK_KP_2:
if (MOD__CTRL_ONLY) {
int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration, sp_desktop_canvas(desktop)));
}
break;
case GDK_F10:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_space:
event_context->space_panning = true;
event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, _("<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;
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;
}
/**
* Gets called when attribute changes value.
*/
static void
sp_ec_repr_attr_changed(Inkscape::XML::Node */*prefs_repr*/, gchar const *key, gchar const */*oldval*/, gchar const *newval,
{
}
}
NULL, /* Child added */
NULL, /* Child removed */
NULL, /* Content changed */
NULL /* Order changed */
};
/**
* Creates new SPEventContext object and calls its virtual setup() function.
*/
sp_event_context_new(GType type, SPDesktop *desktop, Inkscape::XML::Node *prefs_repr, unsigned int key)
{
if (ec->prefs_repr) {
}
return ec;
}
/**
* Finishes SPEventContext.
*/
void
{
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.
*/
void
{
if (ec->prefs_repr) {
}
}
/**
* Calls virtual activate() function of SPEventContext.
*/
void
{
}
/**
* Calls virtual deactivate() function of SPEventContext.
*/
void
{
}
/**
* Calls virtual root_handler(), the main event handling function.
*/
{
ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->root_handler(event_context, event);
return ret;
}
/**
* Calls virtual item_handler(), the item event handling function.
*/
{
ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->item_handler(event_context, item, event);
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.
*/
void
{
/* 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.
*/
void
{
|| (keyval == GDK_Control_L)
|| (keyval == GDK_Control_R));
&& (MOD__ALT
|| (keyval == GDK_Meta_L)
|| (keyval == GDK_Meta_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).
*/
{
0 /*event->key.group*/,
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 *
{
g_slist_free (temp);
return item_at_point;
}
/**
* Called when SPEventContext subclass node attribute changed.
*/
void
{
if (!name
// no need to regenrate knotholder if only style changed
return;
}
if (ec->shape_knot_holder) {
delete ec->shape_knot_holder;
}
if (item) {
}
}
/*
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 :