Application.Mouse.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.ComponentModel;
  2. namespace Terminal.Gui.App;
  3. public static partial class Application // Mouse handling
  4. {
  5. /// <summary>Disable or enable the mouse. The mouse is enabled by default.</summary>
  6. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  7. [Obsolete ("The legacy static Application object is going away.")]
  8. public static bool IsMouseDisabled
  9. {
  10. get => Mouse.IsMouseDisabled;
  11. set => Mouse.IsMouseDisabled = value;
  12. }
  13. /// <summary>
  14. /// Gets the <see cref="IMouse"/> instance that manages mouse event handling and state.
  15. /// </summary>
  16. /// <remarks>
  17. /// <para>
  18. /// This property provides access to mouse-related functionality in a way that supports
  19. /// parallel test execution by avoiding static state.
  20. /// </para>
  21. /// </remarks>
  22. [Obsolete ("The legacy static Application object is going away.")]
  23. public static IMouse Mouse => ApplicationImpl.Instance.Mouse;
  24. #pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved
  25. /// <summary>
  26. /// Raised when a mouse event occurs. Can be cancelled by setting <see cref="HandledEventArgs.Handled"/> to
  27. /// <see langword="true"/>.
  28. /// </summary>
  29. /// <remarks>
  30. /// <para>
  31. /// <see cref="MouseEventArgs.ScreenPosition"/> coordinates are screen-relative.
  32. /// </para>
  33. /// <para>
  34. /// <see cref="MouseEventArgs.View"/> will be the deepest view under the mouse.
  35. /// </para>
  36. /// <para>
  37. /// <see cref="MouseEventArgs.Position"/> coordinates are view-relative. Only valid if
  38. /// <see cref="MouseEventArgs.View"/> is set.
  39. /// </para>
  40. /// <para>
  41. /// Use this even to handle mouse events at the application level, before View-specific handling.
  42. /// </para>
  43. /// </remarks>
  44. [Obsolete ("The legacy static Application object is going away.")]
  45. public static event EventHandler<MouseEventArgs>? MouseEvent
  46. {
  47. add => Mouse.MouseEvent += value;
  48. remove => Mouse.MouseEvent -= value;
  49. }
  50. #pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved
  51. /// <summary>
  52. /// INTERNAL: Holds the non-<see cref="ViewportSettingsFlags.TransparentMouse"/> views that are currently under the
  53. /// mouse.
  54. /// </summary>
  55. [Obsolete ("The legacy static Application object is going away.")]
  56. internal static List<View?> CachedViewsUnderMouse => Mouse.CachedViewsUnderMouse;
  57. /// <summary>
  58. /// INTERNAL API: Holds the last mouse position.
  59. /// </summary>
  60. [Obsolete ("The legacy static Application object is going away.")]
  61. internal static Point? LastMousePosition
  62. {
  63. get => Mouse.LastMousePosition;
  64. set => Mouse.LastMousePosition = value;
  65. }
  66. /// <summary>
  67. /// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse.
  68. /// </summary>
  69. /// <param name="screenPosition">The position of the mouse.</param>
  70. /// <param name="currentViewsUnderMouse">The most recent result from GetViewsUnderLocation().</param>
  71. [Obsolete ("The legacy static Application object is going away.")]
  72. internal static void RaiseMouseEnterLeaveEvents (Point screenPosition, List<View?> currentViewsUnderMouse)
  73. {
  74. Mouse.RaiseMouseEnterLeaveEvents (screenPosition, currentViewsUnderMouse);
  75. }
  76. /// <summary>
  77. /// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and
  78. /// calls the appropriate View mouse event handlers.
  79. /// </summary>
  80. /// <remarks>This method can be used to simulate a mouse event, e.g. in unit tests.</remarks>
  81. /// <param name="mouseEvent">The mouse event with coordinates relative to the screen.</param>
  82. [Obsolete ("The legacy static Application object is going away.")]
  83. internal static void RaiseMouseEvent (MouseEventArgs mouseEvent)
  84. {
  85. Mouse.RaiseMouseEvent (mouseEvent);
  86. }
  87. }