123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- // --------------------------------------------------------------------------------------------------------------------
- // <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));
- }
- }
- }
|