-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathPlotViewBase.Events.cs
More file actions
197 lines (171 loc) · 7.9 KB
/
Copy pathPlotViewBase.Events.cs
File metadata and controls
197 lines (171 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PlotViewBase.Events.cs" company="OxyPlot">
// Copyright (c) 2020 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace OxyPlot.Wpf
{
using System;
using System.Windows.Input;
/// <summary>
/// Base class for WPF PlotView implementations.
/// </summary>
public abstract partial class PlotViewBase
{
/// <summary>
/// Called before the <see cref="E:System.Windows.UIElement.KeyDown" /> event occurs.
/// </summary>
/// <param name="e">The data for the event.</param>
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Handled)
{
return;
}
var args = new OxyKeyEventArgs { ModifierKeys = Keyboard.GetModifierKeys(), Key = e.Key.Convert() };
e.Handled = this.ActualController.HandleKeyDown(this, args);
}
/// <summary>
/// Called when the <see cref="E:System.Windows.UIElement.ManipulationStarted" /> event occurs.
/// </summary>
/// <param name="e">The data for the event.</param>
protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
{
base.OnManipulationStarted(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleTouchStarted(this, e.ToTouchEventArgs(this));
}
/// <summary>
/// Called when the <see cref="E:System.Windows.UIElement.ManipulationDelta" /> event occurs.
/// </summary>
/// <param name="e">The data for the event.</param>
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
{
base.OnManipulationDelta(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleTouchDelta(this, e.ToTouchEventArgs(this));
}
/// <summary>
/// Called when the <see cref="E:System.Windows.UIElement.ManipulationCompleted" /> event occurs.
/// </summary>
/// <param name="e">The data for the event.</param>
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
{
base.OnManipulationCompleted(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleTouchCompleted(this, e.ToTouchEventArgs(this));
}
/// <summary>
/// Called before the <see cref="E:System.Windows.UIElement.MouseWheel" /> event occurs to provide handling for the event in a derived class without attaching a delegate.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Input.MouseWheelEventArgs" /> that contains the event data.</param>
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (e.Handled || !this.IsMouseWheelEnabled)
{
return;
}
e.Handled = this.ActualController.HandleMouseWheel(this, e.ToMouseWheelEventArgs(this));
}
/// <summary>
/// Invoked when an unhandled MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param>
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.Handled)
{
return;
}
this.Focus();
this.CaptureMouse();
// store the mouse down point, check it when mouse button is released to determine if the context menu should be shown
this.mouseDownPoint = e.GetPosition(this).ToScreenPoint();
e.Handled = this.ActualController.HandleMouseDown(this, e.ToMouseDownEventArgs(this));
}
/// <summary>
/// Invoked when an unhandled MouseMove attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseEventArgs" /> that contains the event data.</param>
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleMouseMove(this, e.ToMouseEventArgs(this));
}
/// <summary>
/// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the mouse button was released.</param>
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
if (e.Handled)
{
return;
}
this.ReleaseMouseCapture();
e.Handled = this.ActualController.HandleMouseUp(this, e.ToMouseReleasedEventArgs(this));
// Open the context menu
var p = e.GetPosition(this).ToScreenPoint();
var d = p.DistanceTo(this.mouseDownPoint);
if (this.ContextMenu != null)
{
if (Math.Abs(d) < 1e-8 && e.ChangedButton == MouseButton.Right)
{
// TODO: why is the data context not passed to the context menu??
this.ContextMenu.DataContext = this.DataContext;
this.ContextMenu.PlacementTarget = this;
this.ContextMenu.Visibility = System.Windows.Visibility.Visible;
this.ContextMenu.IsOpen = true;
}
else
{
this.ContextMenu.Visibility = System.Windows.Visibility.Collapsed;
this.ContextMenu.IsOpen = false;
}
}
}
/// <summary>
/// Invoked when an unhandled <see cref="E:System.Windows.Input.Mouse.MouseEnter" /> attached event is raised on this element. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseEventArgs" /> that contains the event data.</param>
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleMouseEnter(this, e.ToMouseEventArgs(this));
}
/// <summary>
/// Invoked when an unhandled <see cref="E:System.Windows.Input.Mouse.MouseLeave" /> attached event is raised on this element. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseEventArgs" /> that contains the event data.</param>
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseEnter(e);
if (e.Handled)
{
return;
}
e.Handled = this.ActualController.HandleMouseLeave(this, e.ToMouseEventArgs(this));
}
}
}