namespace Terminal.Gui.App; /// /// Defines a contract for tracking which (if any) has 'grabbed' the mouse, /// giving it exclusive priority for mouse events such as movement, button presses, and release. /// /// This is typically used for scenarios like dragging, scrolling, or any interaction where a view /// needs to receive all mouse events until the operation completes (e.g., a scrollbar thumb being dragged). /// /// /// Usage pattern: /// /// /// Call to route all mouse events to a specific view. /// /// /// Call to release the grab and restore normal mouse routing. /// /// /// /// Listen to , , , /// and for grab lifecycle events. /// /// /// /// /// public interface IMouseGrabHandler { /// /// Occurs after a view has grabbed the mouse. /// /// This event is raised after the mouse grab operation is complete and the specified view will receive all mouse /// events. /// /// public event EventHandler? GrabbedMouse; /// /// Occurs when a view requests to grab the mouse; can be canceled. /// /// Handlers can set e.Cancel to to prevent the grab. /// /// public event EventHandler? GrabbingMouse; /// /// Grabs the mouse, forcing all mouse events to be routed to the specified view until is /// called. /// /// /// The that will receive all mouse events until is invoked. /// If , the grab is released. /// public void GrabMouse (View? view); /// /// Gets the view that currently has grabbed the mouse (e.g., for dragging). /// /// When this property is not , all mouse events are routed to this view until /// is called or the mouse is released. /// /// public View? MouseGrabView { get; } /// /// Occurs after a view has released the mouse grab. /// /// This event is raised after the mouse grab has been released and normal mouse routing resumes. /// /// public event EventHandler? UnGrabbedMouse; /// /// Occurs when a view requests to release the mouse grab; can be canceled. /// /// Handlers can set e.Cancel to to prevent the ungrab. /// /// public event EventHandler? UnGrabbingMouse; /// /// Releases the mouse grab, so mouse events will be routed to the view under the mouse pointer. /// public void UngrabMouse (); /// /// Handles mouse grab logic for a mouse event. /// /// The deepest view under the mouse. /// The mouse event to handle. /// if the event was handled by the grab handler; otherwise . bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEventArgs mouseEvent); }