Application.Mouse.cs 4.4 KB

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