event-context.cpp revision ec6318247c57f041ede7a34a88d59c636edc2d90
#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 <gdk/gdkkeysyms.h>
#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;
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
{
}
/**
* 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) {
if (
)
{
}
}
else
{
}
}
}
}
}
/**
* 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,
// kill it
// get next
event_next = gdk_event_get();
i ++;
}
// 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 {
}
}
/**
* Calculates and keeps track of scroll acceleration.
* Subroutine of sp_event_context_private_root_handler().
*/
{
/* key pressed within 500ms ? (1/2 second) */
scroll_multiply = 1;
} else {
}
return scroll_multiply;
}
// This is a hack that is necessary because when middle-clicking too fast,
// button_press events come for all clicks but there's button_release only
// for the first one. So after a release, we must prohibit the next grab for
// some time, or the grab will be stuck. Perhaps this is caused by some
// wrong handling of events among contexts and not by a GDK bug;
// if someone can fix this properly this would be great.
static bool
{
dontgrab--;
return FALSE; // so that it is only called once
}
/**
* 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 2:
if (dontgrab)
// double-click, still not permitted to grab;
// increase the counter to guard against triple click
{
dontgrab ++;
break;
}
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;
dontgrab = 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
}
if (within_tolerance) {
} else {
}
// 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;
}
break;
case GDK_BUTTON_RELEASE:
dontgrab ++;
}
panning = 0;
zoom_rb = 0;
}
}
break;
case GDK_KEY_PRESS:
unsigned int shortcut;
case GDK_F1:
/* Grab it away from Gtk */
break;
case GDK_ISO_Left_Tab: // they will get different functions
} else {
/* Grab it away from Gtk */
}
break;
case GDK_W:
case GDK_w:
case GDK_F4:
/* Close view */
if (MOD__CTRL_ONLY) {
}
break;
// FIXME: make import a verb
case GDK_i: // Ctrl i - import file
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:
break;
case GDK_z:
case GDK_Z:
if (MOD__ALT_ONLY) {
}
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) {
}
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 :