123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- namespace Terminal.Gui;
- public partial class View
- {
- /// <summary>Gets or sets a value indicating whether this <see cref="View"/> want continuous button pressed event.</summary>
- public virtual bool WantContinuousButtonPressed { get; set; }
- /// <summary>Gets or sets a value indicating whether this <see cref="View"/> wants mouse position reports.</summary>
- /// <value><see langword="true"/> if want mouse position reports; otherwise, <see langword="false"/>.</value>
- public virtual bool WantMousePositionReports { get; set; }
- /// <summary>Event fired when a mouse event occurs.</summary>
- /// <remarks>
- /// <para>
- /// The coordinates are relative to <see cref="Viewport"/>.
- /// </para>
- /// </remarks>
- public event EventHandler<MouseEventEventArgs> MouseEvent;
- /// <summary>Event fired when a mouse click occurs.</summary>
- /// <remarks>
- /// <para>
- /// Fired when the mouse is either clicked or double-clicked. Check
- /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
- /// </para>
- /// <para>
- /// The coordinates are relative to <see cref="Viewport"/>.
- /// </para>
- /// </remarks>
- public event EventHandler<MouseEventEventArgs> MouseClick;
- /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
- public event EventHandler<MouseEventEventArgs> MouseEnter;
- /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
- public event EventHandler<MouseEventEventArgs> MouseLeave;
- // TODO: OnMouseEnter should not be public virtual, but protected.
- /// <summary>
- /// Called when the mouse enters the View's <see cref="Viewport"/>. The view will now receive mouse events until the mouse leaves
- /// the view. At which time, <see cref="OnMouseLeave(Gui.MouseEvent)"/> will be called.
- /// </summary>
- /// <remarks>
- /// The coordinates are relative to <see cref="Viewport"/>.
- /// </remarks>
- /// <param name="mouseEvent"></param>
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
- 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.
- /// <summary>
- /// Called when the mouse has moved out of the View's <see cref="Viewport"/>. The view will no longer receive mouse events (until the
- /// mouse moves within the view again and <see cref="OnMouseEnter(Gui.MouseEvent)"/> is called).
- /// </summary>
- /// <remarks>
- /// The coordinates are relative to <see cref="Viewport"/>.
- /// </remarks>
- /// <param name="mouseEvent"></param>
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
- 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.
- /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
- /// <remarks>
- /// <para>
- /// The coordinates are relative to <see cref="Viewport"/>.
- /// </para>
- /// </remarks>
- /// <param name="mouseEvent"></param>
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
- 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;
- }
- /// <summary>Invokes the MouseClick event.</summary>
- /// <remarks>
- /// <para>
- /// Called when the mouse is either clicked or double-clicked. Check
- /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
- /// </para>
- /// </remarks>
- 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;
- }
- }
|