namespace Terminal.Gui; public partial class View { /// Gets or sets a value indicating whether this want continuous button pressed event. public virtual bool WantContinuousButtonPressed { get; set; } /// Gets or sets a value indicating whether this wants mouse position reports. /// if want mouse position reports; otherwise, . public virtual bool WantMousePositionReports { get; set; } /// Event fired when a mouse event occurs. /// /// /// The coordinates are relative to . /// /// public event EventHandler MouseEvent; /// Event fired when a mouse click occurs. /// /// /// Fired when the mouse is either clicked or double-clicked. Check /// to see which button was clicked. /// /// /// The coordinates are relative to . /// /// public event EventHandler MouseClick; /// Event fired when the mouse moves into the View's . public event EventHandler MouseEnter; /// Event fired when the mouse leaves the View's . public event EventHandler MouseLeave; // TODO: OnMouseEnter should not be public virtual, but protected. /// /// Called when the mouse enters the View's . The view will now receive mouse events until the mouse leaves /// the view. At which time, will be called. /// /// /// The coordinates are relative to . /// /// /// , if the event was handled, otherwise. protected internal virtual bool OnMouseEnter (MouseEvent mouseEvent) { if (!Enabled) { return true; } if (!CanBeVisible (this)) { return false; } var args = new MouseEventEventArgs (mouseEvent); MouseEnter?.Invoke (this, args); return args.Handled; } // TODO: OnMouseLeave should not be public virtual, but protected. /// /// Called when the mouse has moved out of the View's . The view will no longer receive mouse events (until the /// mouse moves within the view again and is called). /// /// /// The coordinates are relative to . /// /// /// , if the event was handled, otherwise. protected internal virtual bool OnMouseLeave (MouseEvent mouseEvent) { if (!Enabled) { return true; } if (!CanBeVisible (this)) { return false; } var args = new MouseEventEventArgs (mouseEvent); MouseLeave?.Invoke (this, args); return args.Handled; } // TODO: OnMouseEvent should not be public virtual, but protected. /// Called when a mouse event occurs within the view's . /// /// /// The coordinates are relative to . /// /// /// /// , if the event was handled, otherwise. protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent) { if (!Enabled) { return true; } if (!CanBeVisible (this)) { return false; } var args = new MouseEventEventArgs (mouseEvent); // Clicked support for all buttons and single and double click if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)) { return OnMouseClick (args); } if (mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked) || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked)) { return OnMouseClick (args); } MouseEvent?.Invoke (this, args); return args.Handled == true; } /// Invokes the MouseClick event. /// /// /// Called when the mouse is either clicked or double-clicked. Check /// to see which button was clicked. /// /// protected bool OnMouseClick (MouseEventEventArgs args) { if (!Enabled) { return true; } MouseClick?.Invoke (this, args); if (args.Handled) { return true; } if (!HasFocus && CanFocus) { SetFocus (); } return args.Handled; } }