~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ClickOrDragMouseGesture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.Diagnostics;
 
6
using System.Windows;
 
7
using System.Windows.Input;
 
8
 
 
9
namespace ICSharpCode.WpfDesign.Designer.Services
 
10
{
 
11
        /// <summary>
 
12
        /// Base class for mouse gestures that should start dragging only after a minimum drag distance.
 
13
        /// </summary>
 
14
        abstract class ClickOrDragMouseGesture : MouseGestureBase
 
15
        {
 
16
                protected Point startPoint;
 
17
                protected bool hasDragStarted;
 
18
                protected IInputElement positionRelativeTo;
 
19
                
 
20
                const double MinimumDragDistance = 3;
 
21
                
 
22
                protected sealed override void OnStarted(MouseButtonEventArgs e)
 
23
                {
 
24
                        Debug.Assert(positionRelativeTo != null);
 
25
                        hasDragStarted = false;
 
26
                        startPoint = e.GetPosition(positionRelativeTo);
 
27
                }
 
28
                
 
29
                protected override void OnMouseMove(object sender, MouseEventArgs e)
 
30
                {
 
31
                        if (!hasDragStarted) {
 
32
                                Vector v = e.GetPosition(positionRelativeTo) - startPoint;
 
33
                                if (Math.Abs(v.X) >= SystemParameters.MinimumHorizontalDragDistance
 
34
                                    || Math.Abs(v.Y) >= SystemParameters.MinimumVerticalDragDistance) {
 
35
                                        hasDragStarted = true;
 
36
                                        OnDragStarted(e);
 
37
                                }
 
38
                        }
 
39
                }
 
40
                
 
41
                protected override void OnStopped()
 
42
                {
 
43
                        hasDragStarted = false;
 
44
                }
 
45
                
 
46
                protected virtual void OnDragStarted(MouseEventArgs e) {}
 
47
        }
 
48
}