mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Cleaned up MouseClick related stuff.
This commit is contained in:
@@ -9,17 +9,35 @@ public partial class View
|
||||
/// <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 is generated.</summary>
|
||||
/// <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="View.Bounds"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public event EventHandler<MouseEventEventArgs> MouseClick;
|
||||
|
||||
/// <summary>Event fired when the view receives the mouse event for the first time.</summary>
|
||||
/// <summary>Event fired when the mouse moves into the View's <see cref="Bounds"/>.</summary>
|
||||
public event EventHandler<MouseEventEventArgs> MouseEnter;
|
||||
|
||||
/// <summary>Event fired when the view receives a mouse event for the last time.</summary>
|
||||
/// <summary>Event fired when the mouse leaves the View's <see cref="Bounds"/>.</summary>
|
||||
public event EventHandler<MouseEventEventArgs> MouseLeave;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool OnMouseEnter (MouseEvent mouseEvent)
|
||||
// TODO: OnMouseEnter should not be public virtual, but protected.
|
||||
/// <summary>
|
||||
/// Called when the mouse enters the View's <see cref="Bounds"/>. 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="View.Bounds"/>.
|
||||
/// </remarks>
|
||||
/// <param name="mouseEvent"></param>
|
||||
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
||||
public virtual bool OnMouseEnter (MouseEvent mouseEvent)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
@@ -34,20 +52,44 @@ public partial class View
|
||||
var args = new MouseEventEventArgs (mouseEvent);
|
||||
MouseEnter?.Invoke (this, args);
|
||||
|
||||
return args.Handled || base.OnMouseEnter (mouseEvent);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Method invoked when a mouse event is generated</summary>
|
||||
// TODO: OnMouseLeave should not be public virtual, but protected.
|
||||
/// <summary>
|
||||
/// Called when the mouse has moved out of the View's <see cref="Bounds"/>. 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="View.Bounds"/>.
|
||||
/// </remarks>
|
||||
/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
|
||||
/// <param name="mouseEvent">Contains the details about the mouse event.</param>
|
||||
//public virtual bool MouseEvent (MouseEvent mouseEvent) { return false; }
|
||||
/// <param name="mouseEvent"></param>
|
||||
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
||||
public virtual bool OnMouseLeave (MouseEvent mouseEvent)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!CanBeVisible (this))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Method invoked when a mouse event is generated</summary>
|
||||
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="Bounds"/>.</summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The coordinates are relative to <see cref="View.Bounds"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="mouseEvent"></param>
|
||||
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
||||
public virtual bool OnMouseEvent (MouseEvent mouseEvent)
|
||||
@@ -64,33 +106,19 @@ public partial class View
|
||||
|
||||
var args = new MouseEventEventArgs (mouseEvent);
|
||||
|
||||
//if (MouseEvent (mouseEvent))
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
|
||||
if (mouseEvent.Flags == MouseFlags.Button1Clicked)
|
||||
{
|
||||
if (CanFocus && !HasFocus && SuperView is { })
|
||||
{
|
||||
SuperView.SetFocus (this);
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
return OnMouseClick (args);
|
||||
}
|
||||
|
||||
if (mouseEvent.Flags == MouseFlags.Button2Clicked)
|
||||
// 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 == MouseFlags.Button3Clicked)
|
||||
{
|
||||
return OnMouseClick (args);
|
||||
}
|
||||
|
||||
if (mouseEvent.Flags == MouseFlags.Button4Clicked)
|
||||
if (mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked))
|
||||
{
|
||||
return OnMouseClick (args);
|
||||
}
|
||||
@@ -98,26 +126,13 @@ public partial class View
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override 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 || base.OnMouseLeave (mouseEvent);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
@@ -126,6 +141,10 @@ public partial class View
|
||||
}
|
||||
|
||||
MouseClick?.Invoke (this, args);
|
||||
if (args.Handled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user