1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
9
using System.Windows.Input;
10
using System.Diagnostics;
12
namespace ICSharpCode.WpfDesign.Designer.Controls
14
public delegate void DragHandler(DragListener drag);
16
public class DragListener
20
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
23
public DragListener(IInputElement target)
27
Target.PreviewMouseLeftButtonDown += Target_MouseDown;
28
Target.PreviewMouseMove += Target_MouseMove;
29
Target.PreviewMouseLeftButtonUp += Target_MouseUp;
32
static DragListener CurrentListener;
34
static void PostProcessInput(object sender, ProcessInputEventArgs e)
36
if (CurrentListener != null) {
37
var a = e.StagingItem.Input as KeyEventArgs;
38
if (a != null && a.Key == Key.Escape) {
40
CurrentListener.IsDown = false;
41
CurrentListener.IsCanceled = true;
42
CurrentListener.Complete();
47
void Target_MouseDown(object sender, MouseButtonEventArgs e)
49
StartPoint = Mouse.GetPosition(null);
50
CurrentPoint = StartPoint;
51
DeltaDelta = new Vector();
56
void Target_MouseMove(object sender, MouseEventArgs e)
59
DeltaDelta = e.GetPosition(null) - CurrentPoint;
60
CurrentPoint += DeltaDelta;
63
if (Math.Abs(Delta.X) >= SystemParameters.MinimumHorizontalDragDistance ||
64
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance) {
66
CurrentListener = this;
68
if (Started != null) {
74
if (IsActive && Changed != null) {
80
void Target_MouseUp(object sender, MouseButtonEventArgs e)
91
CurrentListener = null;
93
if (Completed != null) {
98
public event DragHandler Started;
99
public event DragHandler Changed;
100
public event DragHandler Completed;
102
public IInputElement Target { get; private set; }
103
public Point StartPoint { get; private set; }
104
public Point CurrentPoint { get; private set; }
105
public Vector DeltaDelta { get; private set; }
106
public bool IsActive { get; private set; }
107
public bool IsDown { get; private set; }
108
public bool IsCanceled { get; private set; }
110
public Vector Delta {
111
get { return CurrentPoint - StartPoint; }