IMouse.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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="App"/> 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? App { 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 or sets whether the mouse is disabled. The mouse is enabled by default.
  23. /// </summary>
  24. bool IsMouseDisabled { get; set; }
  25. /// <summary>
  26. /// Gets the list of non-<see cref="ViewportSettingsFlags.TransparentMouse"/> views that are currently under the mouse.
  27. /// </summary>
  28. List<View?> CachedViewsUnderMouse { get; }
  29. /// <summary>
  30. /// Raised when a mouse event occurs. Can be cancelled by setting <see cref="HandledEventArgs.Handled"/> to <see langword="true"/>.
  31. /// </summary>
  32. /// <remarks>
  33. /// <para>
  34. /// <see cref="MouseEventArgs.ScreenPosition"/> coordinates are screen-relative.
  35. /// </para>
  36. /// <para>
  37. /// <see cref="MouseEventArgs.View"/> will be the deepest view under the mouse.
  38. /// </para>
  39. /// <para>
  40. /// <see cref="MouseEventArgs.Position"/> coordinates are view-relative. Only valid if <see cref="MouseEventArgs.View"/> is set.
  41. /// </para>
  42. /// <para>
  43. /// Use this even to handle mouse events at the application level, before View-specific handling.
  44. /// </para>
  45. /// </remarks>
  46. event EventHandler<MouseEventArgs>? MouseEvent;
  47. /// <summary>
  48. /// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and
  49. /// calls the appropriate View mouse event handlers.
  50. /// </summary>
  51. /// <remarks>This method can be used to simulate a mouse event, e.g. in unit tests.</remarks>
  52. /// <param name="mouseEvent">The mouse event with coordinates relative to the screen.</param>
  53. void RaiseMouseEvent (MouseEventArgs mouseEvent);
  54. /// <summary>
  55. /// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse.
  56. /// </summary>
  57. /// <param name="screenPosition">The position of the mouse.</param>
  58. /// <param name="currentViewsUnderMouse">The most recent result from GetViewsUnderLocation().</param>
  59. void RaiseMouseEnterLeaveEvents (Point screenPosition, List<View?> currentViewsUnderMouse);
  60. /// <summary>
  61. /// INTERNAL: Resets mouse state, clearing event handlers and cached views.
  62. /// </summary>
  63. void ResetState ();
  64. }