#nullable enable
using System.ComponentModel;
namespace Terminal.Gui.App;
public static partial class Application // Mouse handling
{
///
/// Gets the most recent position of the mouse.
///
public static Point? GetLastMousePosition () { return Mouse.GetLastMousePosition (); }
/// Disable or enable the mouse. The mouse is enabled by default.
[ConfigurationProperty (Scope = typeof (SettingsScope))]
public static bool IsMouseDisabled
{
get => Mouse.IsMouseDisabled;
set => Mouse.IsMouseDisabled = value;
}
///
/// Gets the instance that manages mouse event handling and state.
///
///
///
/// This property provides access to mouse-related functionality in a way that supports
/// parallel test execution by avoiding static state.
///
///
/// New code should use Application.Mouse instead of the static properties and methods
/// for better testability. Legacy static properties like and
/// are retained for backward compatibility.
///
///
public static IMouse Mouse => ApplicationImpl.Instance.Mouse;
#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
///
/// Raised when a mouse event occurs. Can be cancelled by setting to
/// .
///
///
///
/// coordinates are screen-relative.
///
///
/// will be the deepest view under the mouse.
///
///
/// coordinates are view-relative. Only valid if
/// is set.
///
///
/// Use this even to handle mouse events at the application level, before View-specific handling.
///
///
public static event EventHandler? MouseEvent
{
add => Mouse.MouseEvent += value;
remove => Mouse.MouseEvent -= value;
}
#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
///
/// INTERNAL: Holds the non- views that are currently under the
/// mouse.
///
internal static List CachedViewsUnderMouse => Mouse.CachedViewsUnderMouse;
///
/// INTERNAL API: Holds the last mouse position.
///
internal static Point? LastMousePosition
{
get => Mouse.LastMousePosition;
set => Mouse.LastMousePosition = value;
}
///
/// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse.
///
/// The position of the mouse.
/// The most recent result from GetViewsUnderLocation().
internal static void RaiseMouseEnterLeaveEvents (Point screenPosition, List currentViewsUnderMouse)
{
Mouse.RaiseMouseEnterLeaveEvents (screenPosition, currentViewsUnderMouse);
}
///
/// 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 RaiseMouseEvent (MouseEventArgs mouseEvent)
{
Mouse.RaiseMouseEvent (mouseEvent);
}
}