IMouse.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.ComponentModel;
  2. namespace Terminal.Gui.App;
  3. /// <summary>
  4. /// Defines a contract for mouse event handling and state management in a Terminal.Gui application.
  5. /// <para>
  6. /// This interface allows for decoupling of mouse-related functionality from the static <see cref="Application"/> class,
  7. /// enabling better testability and parallel test execution.
  8. /// </para>
  9. /// </summary>
  10. public interface IMouse : IMouseGrabHandler
  11. {
  12. /// <summary>
  13. /// Sets the application instance that this mouse handler is associated with.
  14. /// This provides access to application state without coupling to static Application class.
  15. /// </summary>
  16. IApplication? Application { get; set; }
  17. /// <summary>
  18. /// Gets or sets the last known position of the mouse.
  19. /// </summary>
  20. Point? LastMousePosition { get; set; }
  21. /// <summary>
  22. /// Gets the most recent position of the mouse.
  23. /// </summary>
  24. Point? GetLastMousePosition ();
  25. /// <summary>
  26. /// Gets or sets whether the mouse is disabled. The mouse is enabled by default.
  27. /// </summary>
  28. bool IsMouseDisabled { get; set; }
  29. /// <summary>
  30. /// Gets the list of non-<see cref="ViewportSettingsFlags.TransparentMouse"/> views that are currently under the mouse.
  31. /// </summary>
  32. List<View?> CachedViewsUnderMouse { get; }
  33. /// <summary>
  34. /// Raised when a mouse event occurs. Can be cancelled by setting <see cref="HandledEventArgs.Handled"/> to <see langword="true"/>.
  35. /// </summary>
  36. /// <remarks>
  37. /// <para>
  38. /// <see cref="MouseEventArgs.ScreenPosition"/> coordinates are screen-relative.
  39. /// </para>
  40. /// <para>
  41. /// <see cref="MouseEventArgs.View"/> will be the deepest view under the mouse.
  42. /// </para>
  43. /// <para>
  44. /// <see cref="MouseEventArgs.Position"/> coordinates are view-relative. Only valid if <see cref="MouseEventArgs.View"/> is set.
  45. /// </para>
  46. /// <para>
  47. /// Use this even to handle mouse events at the application level, before View-specific handling.
  48. /// </para>
  49. /// </remarks>
  50. event EventHandler<MouseEventArgs>? MouseEvent;
  51. /// <summary>
  52. /// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and
  53. /// calls the appropriate View mouse event handlers.
  54. /// </summary>
  55. /// <remarks>This method can be used to simulate a mouse event, e.g. in unit tests.</remarks>
  56. /// <param name="mouseEvent">The mouse event with coordinates relative to the screen.</param>
  57. void RaiseMouseEvent (MouseEventArgs mouseEvent);
  58. /// <summary>
  59. /// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse.
  60. /// </summary>
  61. /// <param name="screenPosition">The position of the mouse.</param>
  62. /// <param name="currentViewsUnderMouse">The most recent result from GetViewsUnderLocation().</param>
  63. void RaiseMouseEnterLeaveEvents (Point screenPosition, List<View?> currentViewsUnderMouse);
  64. /// <summary>
  65. /// INTERNAL: Resets mouse state, clearing event handlers and cached views.
  66. /// </summary>
  67. void ResetState ();
  68. }