desktop-events.cpp revision 0ce918f80fe50c422e3cb9918b5fb0c3b4613ab7
/**
* @file
* Event handlers for SPDesktop.
*/
/* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Abhishek Sharma
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 1999-2010 Others
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <map>
#include <string>
#include "desktop.h"
#include "desktop-handles.h"
#include "dialogs/dialog-events.h"
#include "display/canvas-axonomgrid.h"
#include "display/canvas-grid.h"
#include "display/guideline.h"
#include "display/snap-indicator.h"
#include "document.h"
#include "document-undo.h"
#include "event-context.h"
#include "helper/unit-menu.h"
#include "message-context.h"
#include "preferences.h"
#include "snap.h"
#include "display/sp-canvas.h"
#include "sp-guide.h"
#include "sp-metrics.h"
#include "sp-namedview.h"
#include "tools-switch.h"
#include "verbs.h"
#include "widgets/desktop-widget.h"
using Inkscape::DocumentUndo;
static void init_extended();
void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem *guide, Geom::Point &event_dt, Geom::Point &normal);
/* Root item handler */
{
static bool watch = false;
static bool first = true;
if ( first ) {
watch = true;
}
first = false;
}
if ( watch ) {
}
}
{
static bool dragging = false;
gdk_window_get_geometry(gtk_widget_get_window (GTK_WIDGET(dtw->canvas)), NULL /*x*/, NULL /*y*/, &width, &height, NULL/*depth*/);
case GDK_BUTTON_PRESS:
dragging = true;
// explicitly show guidelines; if I draw a guide, I want them on
// calculate the normal of the guidelines when dragged from the edges of rulers.
// guidelines normal to gridlines
} else {
}
}
if (horiz) {
if (wx < 50) {
} else {
}
} else {
if (wy < 50) {
} else {
}
}
}
break;
case GDK_MOTION_NOTIFY:
if (dragging) {
}
}
break;
case GDK_BUTTON_RELEASE:
}
dragging = false;
_("Create guide"));
}
}
default:
break;
}
return FALSE;
}
{
sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_HRULER);
}
}
{
sp_event_context_snap_delay_handler(dtw->desktop->event_context, (gpointer) widget, (gpointer) dtw, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_VRULER);
}
}
//static bool reset_drag_origin = false; // when Ctrl is pressed while dragging, this is used to trigger resetting of the
// // drag origin to that location so that constrained movement is more intuitive
// Min distance from anchor to initiate rotation, measured in screenpixels
#define tol 40.0
{
static bool moved = false;
SPDesktop *desktop = static_cast<SPDesktop*>(g_object_get_data(G_OBJECT(item->canvas), "SPDesktop"));
case GDK_2BUTTON_PRESS:
}
break;
case GDK_BUTTON_PRESS:
// Due to the tolerance allowed when grabbing a guide, event_dt will generally
// be close to the guide but not just exactly on it. The drag origin calculated
// here must be exactly on the guide line though, otherwise
// small errors will occur once we snap, see
// with shift we rotate the guide
} else {
} else {
}
}
NULL,
}
}
break;
case GDK_MOTION_NOTIFY:
if (drag_type != SP_DRAG_NONE) {
sp_event_context_snap_delay_handler(desktop->event_context, (gpointer) item, data, (GdkEventMotion *)event, DelayedSnapEvent::GUIDE_HANDLER);
// This is for snapping while dragging existing guidelines. New guidelines,
// which are dragged off the ruler, are being snapped in sp_dt_ruler_event
if (drag_type == SP_DRAG_MOVE_ORIGIN) {
// If we snap in guideConstrainedSnap() below, then motion_dt will
// be forced to be on the guide. If we don't snap however, then
// the origin should still be constrained to the guide. So let's do
// that explicitly first:
}
// cannot use shift here to disable snapping, because we already use it for rotating the guide
if (drag_type == SP_DRAG_ROTATE) {
} else {
}
}
m.unSetup();
switch (drag_type) {
case SP_DRAG_TRANSLATE:
{
break;
}
case SP_DRAG_ROTATE:
{
if (snaps) {
if (relative_snaps) {
} else {
}
}
}
break;
}
case SP_DRAG_MOVE_ORIGIN:
{
break;
}
case SP_DRAG_NONE:
break;
}
moved = true;
}
break;
case GDK_BUTTON_RELEASE:
if (moved) {
if (drag_type == SP_DRAG_MOVE_ORIGIN) {
// If we snap in guideConstrainedSnap() below, then motion_dt will
// be forced to be on the guide. If we don't snap however, then
// the origin should still be constrained to the guide. So let's
// do that explicitly first:
}
// cannot use shift here to disable snapping, because we already use it for rotating the guide
if (drag_type == SP_DRAG_ROTATE) {
} else {
}
}
m.unSetup();
switch (drag_type) {
case SP_DRAG_TRANSLATE:
{
break;
}
case SP_DRAG_ROTATE:
{
if (snaps) {
if (relative_snaps) {
} else {
}
}
}
break;
}
case SP_DRAG_MOVE_ORIGIN:
{
break;
}
case SP_DRAG_NONE:
break;
}
_("Move guide"));
} else {
/* Undo movement of any attached shapes. */
_("Delete guide"));
}
moved = false;
}
}
case GDK_ENTER_NOTIFY:
{
// set move or rotate cursor
gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor);
}
desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("<b>Guideline</b>: %s"), guide_description);
break;
}
case GDK_LEAVE_NOTIFY:
// restore event context's cursor
gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), desktop->event_context->cursor);
break;
case GDK_KEY_PRESS:
case GDK_Delete:
case GDK_KP_Delete:
case GDK_BackSpace:
{
break;
}
case GDK_Shift_L:
case GDK_Shift_R:
if (drag_type != SP_DRAG_MOVE_ORIGIN) {
gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor);
break;
}
default:
// do nothing;
break;
}
break;
case GDK_KEY_RELEASE:
case GDK_Shift_L:
case GDK_Shift_R:
gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), guide_cursor);
break;
default:
// do nothing;
break;
}
default:
break;
}
return ret;
}
//static std::map<GdkInputSource, std::string> switchMap;
static void init_extended()
{
if ( devices ) {
#else
#endif
if ( devName
&& (devSrc != GDK_SOURCE_MOUSE) ) {
// g_message("Adding '%s' as [%d]", devName, devSrc);
// Set the initial tool for the device
switch ( devSrc ) {
case GDK_SOURCE_PEN:
break;
case GDK_SOURCE_ERASER:
break;
case GDK_SOURCE_CURSOR:
break;
default:
; // do not add
}
// } else if (devName) {
// g_message("Skippn '%s' as [%d]", devName, devSrc);
}
}
}
}
{
case GDK_MOTION_NOTIFY:
{
#else
#endif
}
}
break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
{
#else
#endif
}
}
break;
case GDK_SCROLL:
{
#else
#endif
}
}
break;
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
{
#else
#endif
}
}
break;
default:
;
}
// The device switched. See if it is one we 'count'
//g_message("Changed device %s -> %s", lastName.c_str(), name.c_str());
// Save the tool currently selected for next time the input
// device shows up.
}
}
}
}
}
void sp_dt_ruler_snap_new_guide(SPDesktop *desktop, SPCanvasItem * /*guide*/, Geom::Point &event_dt, Geom::Point &normal)
{
// We're dragging a brand new guide, just pulled of the rulers seconds ago. When snapping to a
// path this guide will change it slope to become either tangential or perpendicular to that path. It's
// therefore not useful to try tangential or perpendicular snapping, so this will be disabled temporarily
m.snapprefs.setSnapPerp(false);
m.snapprefs.setSnapTang(false);
// We only have a temporary guide which is not stored in our document yet.
// Because the guide snapper only looks in the document for guides to snap to,
// we don't have to worry about a guide snapping to itself here
// After snapping, both event_dt and normal have been modified accordingly; we'll take the normal (of the
// curve we snapped to) to set the normal the guide. And rotate it by 90 deg. if needed
if (pref_perp) { // Perpendicular snapping to paths is requested by the user, so let's do that
if (normal != normal_orig) {
}
}
if (!(pref_tang || pref_perp)) { // if we don't want to snap either perpendicularly or tangentially, then
}
// Restore the preferences
m.unSetup();
}
/*
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:fileencoding=utf-8:textwidth=99 :