IMouse.cs 3.2 KB

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