diff --git a/Terminal.Gui/Application/Application.Mouse.cs b/Terminal.Gui/Application/Application.Mouse.cs
index ab1cf428d..051e9f4fd 100644
--- a/Terminal.Gui/Application/Application.Mouse.cs
+++ b/Terminal.Gui/Application/Application.Mouse.cs
@@ -1,6 +1,5 @@
#nullable enable
using System.ComponentModel;
-using System.Diagnostics;
namespace Terminal.Gui;
@@ -45,12 +44,12 @@ public static partial class Application // Mouse handling
/// View that will receive all mouse events until is invoked.
public static void GrabMouse (View? view)
{
- if (view is null || OnGrabbingMouse (view))
+ if (view is null || RaiseGrabbingMouseEvent (view))
{
return;
}
- OnGrabbedMouse (view);
+ RaiseGrabbedMouseEvent (view);
MouseGrabView = view;
}
@@ -66,16 +65,16 @@ public static partial class Application // Mouse handling
ObjectDisposedException.ThrowIf (MouseGrabView.WasDisposed, MouseGrabView);
#endif
- if (!OnUnGrabbingMouse (MouseGrabView))
+ if (!RaiseUnGrabbingMouseEvent (MouseGrabView))
{
View view = MouseGrabView;
MouseGrabView = null;
- OnUnGrabbedMouse (view);
+ RaiseUnGrabbedMouseEvent (view);
}
}
/// A delegate callback throws an exception.
- private static bool OnGrabbingMouse (View? view)
+ private static bool RaiseGrabbingMouseEvent (View? view)
{
if (view is null)
{
@@ -89,7 +88,7 @@ public static partial class Application // Mouse handling
}
/// A delegate callback throws an exception.
- private static bool OnUnGrabbingMouse (View? view)
+ private static bool RaiseUnGrabbingMouseEvent (View? view)
{
if (view is null)
{
@@ -103,7 +102,7 @@ public static partial class Application // Mouse handling
}
/// A delegate callback throws an exception.
- private static void OnGrabbedMouse (View? view)
+ private static void RaiseGrabbedMouseEvent (View? view)
{
if (view is null)
{
@@ -114,7 +113,7 @@ public static partial class Application // Mouse handling
}
/// A delegate callback throws an exception.
- private static void OnUnGrabbedMouse (View? view)
+ private static void RaiseUnGrabbedMouseEvent (View? view)
{
if (view is null)
{
@@ -124,20 +123,14 @@ public static partial class Application // Mouse handling
UnGrabbedMouse?.Invoke (view, new (view));
}
- /// Event fired when a mouse move or click occurs. Coordinates are screen relative.
- ///
- ///
- /// Use this event to receive mouse events in screen coordinates. Use to
- /// receive mouse events relative to a .
- ///
- /// The will contain the that contains the mouse coordinates.
- ///
- public static event EventHandler? MouseEvent;
- /// Called when a mouse event is raised by the driver.
+ ///
+ /// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and
+ /// calls the appropriate View mouse event handlers.
+ ///
/// This method can be used to simulate a mouse event, e.g. in unit tests.
/// The mouse event with coordinates relative to the screen.
- internal static void OnMouseEvent (MouseEvent mouseEvent)
+ internal static void RaiseMouseEvent (MouseEvent mouseEvent)
{
_lastMousePosition = mouseEvent.ScreenPosition;
@@ -224,7 +217,7 @@ public static partial class Application // Mouse handling
{
// The mouse was outside any View's Viewport.
- // Debug.Fail ("This should never happen. If it does please file an Issue!!");
+ // Debug.Fail ("This should never happen. If it does please file an Issue!!");
return;
}
@@ -261,6 +254,25 @@ public static partial class Application // Mouse handling
}
}
+ ///
+ /// Raised when a mouse event occurs. Can be cancelled by setting to .
+ ///
+ ///
+ ///
+ /// coordinates are screen-relative.
+ ///
+ ///
+ /// will be the deepest view under the under the mouse.
+ ///
+ ///
+ /// coordinates are view-relative.
+ ///
+ ///
+ /// Use this evento to handle mouse events at the application level, before View-specific handling.
+ ///
+ ///
+ public static event EventHandler? MouseEvent;
+
internal static bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEvent mouseEvent)
{
if (MouseGrabView is { })
@@ -303,7 +315,6 @@ public static partial class Application // Mouse handling
internal static readonly List _cachedViewsUnderMouse = new ();
- // TODO: Refactor MouseEnter/LeaveEvents to not take MouseEvent param.
///
/// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse.
///