Skip to content

Commit 6d92966

Browse files
committed
don't set Handled=true in PlotController (#446)
1 parent 899ea5b commit 6d92966

8 files changed

Lines changed: 162 additions & 37 deletions

File tree

Source/Examples/ExampleLibrary/Examples/PlotControllerExamples.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ public static Example MouseHandlingExample()
5454
model.Series.Add(series);
5555

5656
// Create a command that adds points to the scatter series
57-
var command = new DelegatePlotCommand<OxyMouseEventArgs>(
57+
var command = new DelegatePlotCommand<OxyMouseDownEventArgs>(
5858
(v, c, a) =>
5959
{
60+
a.Handled = true;
6061
var point = series.InverseTransform(a.Position);
6162
series.Points.Add(new ScatterPoint(point.X, point.Y));
6263
model.InvalidatePlot(true);
@@ -99,6 +100,7 @@ public static Example ClickingOnAnAnnotation()
99100
var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation);
100101
if (firstHit != null)
101102
{
103+
e.Handled = true;
102104
plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text;
103105
plotModel.InvalidatePlot(false);
104106
}

Source/OxyPlot/Graphics/ControllerBase.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public virtual bool HandleMouseLeave(IView view, OxyMouseEventArgs args)
140140
this.MouseHoverManipulators.Remove(m);
141141
}
142142

143-
return true;
143+
return args.Handled;
144144
}
145145
}
146146

@@ -173,7 +173,7 @@ public virtual bool HandleMouseMove(IView view, OxyMouseEventArgs args)
173173
m.Delta(args);
174174
}
175175

176-
return true;
176+
return args.Handled;
177177
}
178178
}
179179

@@ -202,7 +202,7 @@ public virtual bool HandleMouseUp(IView view, OxyMouseEventArgs args)
202202
this.MouseDownManipulators.Remove(m);
203203
}
204204

205-
return true;
205+
return args.Handled;
206206
}
207207
}
208208

@@ -269,7 +269,7 @@ public bool HandleTouchDelta(IView view, OxyTouchEventArgs args)
269269
m.Delta(args);
270270
}
271271

272-
return true;
272+
return args.Handled;
273273
}
274274
}
275275

@@ -298,7 +298,7 @@ public bool HandleTouchCompleted(IView view, OxyTouchEventArgs args)
298298
this.TouchManipulators.Remove(m);
299299
}
300300

301-
return true;
301+
return args.Handled;
302302
}
303303
}
304304

@@ -508,9 +508,7 @@ protected virtual bool HandleCommand(IViewCommand command, IView view, OxyInputE
508508
}
509509

510510
command.Execute(view, this, args);
511-
512-
args.Handled = true;
513-
return true;
511+
return args.Handled;
514512
}
515513

516514
/// <summary>

Source/OxyPlot/PlotController/Manipulators/PanManipulator.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,33 @@ public PanManipulator(IPlotView plotView)
2828
/// </summary>
2929
private ScreenPoint PreviousPosition { get; set; }
3030

31+
/// <summary>
32+
/// Gets or sets a value indicating whether panning is enabled.
33+
/// </summary>
34+
private bool IsPanEnabled { get; set; }
35+
36+
/// <summary>
37+
/// Occurs when a manipulation is complete.
38+
/// </summary>
39+
/// <param name="e">The <see cref="OxyInputEventArgs" /> instance containing the event data.</param>
40+
public override void Completed(OxyMouseEventArgs e)
41+
{
42+
base.Completed(e);
43+
e.Handled |= this.IsPanEnabled;
44+
}
45+
3146
/// <summary>
3247
/// Occurs when the input device changes position during a manipulation.
3348
/// </summary>
3449
/// <param name="e">The <see cref="OxyPlot.OxyMouseEventArgs" /> instance containing the event data.</param>
3550
public override void Delta(OxyMouseEventArgs e)
3651
{
3752
base.Delta(e);
53+
if (!this.IsPanEnabled)
54+
{
55+
return;
56+
}
57+
3858
if (this.XAxis != null)
3959
{
4060
this.XAxis.Pan(this.PreviousPosition, e.Position);
@@ -47,6 +67,7 @@ public override void Delta(OxyMouseEventArgs e)
4767

4868
this.PlotView.InvalidatePlot(false);
4969
this.PreviousPosition = e.Position;
70+
e.Handled = true;
5071
}
5172

5273
/// <summary>
@@ -66,6 +87,11 @@ public override void Started(OxyMouseEventArgs e)
6687
{
6788
base.Started(e);
6889
this.PreviousPosition = e.Position;
90+
91+
this.IsPanEnabled = (this.XAxis != null && this.XAxis.IsPanEnabled)
92+
|| (this.YAxis != null && this.YAxis.IsPanEnabled);
93+
94+
e.Handled |= this.IsPanEnabled;
6995
}
7096
}
7197
}

Source/OxyPlot/PlotController/Manipulators/TouchManipulator.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,37 @@ public TouchManipulator(IPlotView plotView)
2323
{
2424
}
2525

26+
/// <summary>
27+
/// Gets or sets a value indicating whether panning is enabled.
28+
/// </summary>
29+
private bool IsPanEnabled { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets a value indicating whether zooming is enabled.
33+
/// </summary>
34+
private bool IsZoomEnabled { get; set; }
35+
36+
/// <summary>
37+
/// Occurs when a manipulation is complete.
38+
/// </summary>
39+
/// <param name="e">The <see cref="OxyInputEventArgs" /> instance containing the event data.</param>
40+
public override void Completed(OxyTouchEventArgs e)
41+
{
42+
base.Completed(e);
43+
e.Handled |= this.IsPanEnabled || this.IsZoomEnabled;
44+
}
45+
2646
/// <summary>
2747
/// Occurs when a touch delta event is handled.
2848
/// </summary>
2949
/// <param name="e">The <see cref="OxyPlot.OxyTouchEventArgs" /> instance containing the event data.</param>
3050
public override void Delta(OxyTouchEventArgs e)
3151
{
3252
base.Delta(e);
53+
if (!this.IsPanEnabled && !this.IsZoomEnabled)
54+
{
55+
return;
56+
}
3357

3458
var newPosition = e.Position;
3559
var previousPosition = newPosition - e.DeltaTranslation;
@@ -57,6 +81,7 @@ public override void Delta(OxyTouchEventArgs e)
5781
}
5882

5983
this.PlotView.InvalidatePlot(false);
84+
e.Handled = true;
6085
}
6186

6287
/// <summary>
@@ -67,6 +92,14 @@ public override void Started(OxyTouchEventArgs e)
6792
{
6893
this.AssignAxes(e.Position);
6994
base.Started(e);
95+
96+
this.IsPanEnabled = (this.XAxis != null && this.XAxis.IsPanEnabled)
97+
|| (this.YAxis != null && this.YAxis.IsPanEnabled);
98+
99+
this.IsZoomEnabled = (this.XAxis != null && this.XAxis.IsZoomEnabled)
100+
|| (this.YAxis != null && this.YAxis.IsZoomEnabled);
101+
102+
e.Handled |= this.IsPanEnabled || this.IsZoomEnabled;
70103
}
71104
}
72105
}

Source/OxyPlot/PlotController/Manipulators/TrackerManipulator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public TrackerManipulator(IPlotView plotView)
5454
public override void Completed(OxyMouseEventArgs e)
5555
{
5656
base.Completed(e);
57+
e.Handled = true;
5758

5859
this.currentSeries = null;
5960
this.PlotView.HideTracker();
@@ -70,6 +71,7 @@ public override void Completed(OxyMouseEventArgs e)
7071
public override void Delta(OxyMouseEventArgs e)
7172
{
7273
base.Delta(e);
74+
e.Handled = true;
7375

7476
if (this.currentSeries == null || !this.LockToInitialSeries)
7577
{

Source/OxyPlot/PlotController/Manipulators/ZoomRectangleManipulator.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ public ZoomRectangleManipulator(IPlotView plotView)
3030
{
3131
}
3232

33+
/// <summary>
34+
/// Gets or sets a value indicating whether zooming is enabled.
35+
/// </summary>
36+
private bool IsZoomEnabled { get; set; }
37+
3338
/// <summary>
3439
/// Occurs when a manipulation is complete.
3540
/// </summary>
3641
/// <param name="e">The <see cref="OxyPlot.OxyMouseEventArgs" /> instance containing the event data.</param>
3742
public override void Completed(OxyMouseEventArgs e)
3843
{
3944
base.Completed(e);
45+
if (!this.IsZoomEnabled)
46+
{
47+
return;
48+
}
4049

4150
this.PlotView.HideZoomRectangle();
4251

@@ -57,6 +66,8 @@ public override void Completed(OxyMouseEventArgs e)
5766

5867
this.PlotView.InvalidatePlot();
5968
}
69+
70+
e.Handled = true;
6071
}
6172

6273
/// <summary>
@@ -66,13 +77,17 @@ public override void Completed(OxyMouseEventArgs e)
6677
public override void Delta(OxyMouseEventArgs e)
6778
{
6879
base.Delta(e);
80+
if (!this.IsZoomEnabled)
81+
{
82+
return;
83+
}
6984

7085
var plotArea = this.PlotView.ActualModel.PlotArea;
7186

72-
double x = Math.Min(this.StartPosition.X, e.Position.X);
73-
double w = Math.Abs(this.StartPosition.X - e.Position.X);
74-
double y = Math.Min(this.StartPosition.Y, e.Position.Y);
75-
double h = Math.Abs(this.StartPosition.Y - e.Position.Y);
87+
var x = Math.Min(this.StartPosition.X, e.Position.X);
88+
var w = Math.Abs(this.StartPosition.X - e.Position.X);
89+
var y = Math.Min(this.StartPosition.Y, e.Position.Y);
90+
var h = Math.Abs(this.StartPosition.Y - e.Position.Y);
7691

7792
if (this.XAxis == null || !this.XAxis.IsZoomEnabled)
7893
{
@@ -88,6 +103,7 @@ public override void Delta(OxyMouseEventArgs e)
88103

89104
this.zoomRectangle = new OxyRect(x, y, w, h);
90105
this.PlotView.ShowZoomRectangle(this.zoomRectangle);
106+
e.Handled = true;
91107
}
92108

93109
/// <summary>
@@ -116,8 +132,17 @@ public override CursorType GetCursorType()
116132
public override void Started(OxyMouseEventArgs e)
117133
{
118134
base.Started(e);
119-
this.zoomRectangle = new OxyRect(this.StartPosition.X, this.StartPosition.Y, 0, 0);
120-
this.PlotView.ShowZoomRectangle(this.zoomRectangle);
135+
136+
this.IsZoomEnabled = (this.XAxis != null && this.XAxis.IsZoomEnabled)
137+
|| (this.YAxis != null && this.YAxis.IsZoomEnabled);
138+
139+
if (this.IsZoomEnabled)
140+
{
141+
this.zoomRectangle = new OxyRect(this.StartPosition.X, this.StartPosition.Y, 0, 0);
142+
this.PlotView.ShowZoomRectangle(this.zoomRectangle);
143+
}
144+
145+
e.Handled |= this.IsZoomEnabled;
121146
}
122147
}
123148
}

Source/OxyPlot/PlotController/Manipulators/ZoomStepManipulator.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ public override void Started(OxyMouseEventArgs e)
4141
{
4242
base.Started(e);
4343

44+
var isZoomEnabled = (this.XAxis != null && this.XAxis.IsZoomEnabled)
45+
|| (this.YAxis != null && this.YAxis.IsZoomEnabled);
46+
47+
if (!isZoomEnabled)
48+
{
49+
return;
50+
}
51+
4452
var current = this.InverseTransform(e.Position.X, e.Position.Y);
4553

46-
double scale = this.Step;
54+
var scale = this.Step;
4755
if (this.FineControl)
4856
{
4957
scale *= 3;
@@ -68,6 +76,7 @@ public override void Started(OxyMouseEventArgs e)
6876
}
6977

7078
this.PlotView.InvalidatePlot(false);
79+
e.Handled = true;
7180
}
7281
}
7382
}

0 commit comments

Comments
 (0)