diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs index c8310b7801..02351612f0 100644 --- a/Terminal.Gui/Application/Application.Initialization.cs +++ b/Terminal.Gui/Application/Application.Initialization.cs @@ -180,7 +180,7 @@ internal static void InternalInit ( private static void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { OnSizeChanging (e); } private static void Driver_KeyDown (object? sender, Key e) { RaiseKeyDownEvent (e); } private static void Driver_KeyUp (object? sender, Key e) { RaiseKeyUpEvent (e); } - private static void Driver_MouseEvent (object? sender, MouseEvent e) { OnMouseEvent (e); } + private static void Driver_MouseEvent (object? sender, MouseEventArgs e) { RaiseMouseEvent (e); } /// Gets of list of types that are available. /// diff --git a/Terminal.Gui/Application/Application.Mouse.cs b/Terminal.Gui/Application/Application.Mouse.cs index ab1cf428dc..c4477ac85d 100644 --- a/Terminal.Gui/Application/Application.Mouse.cs +++ b/Terminal.Gui/Application/Application.Mouse.cs @@ -1,6 +1,5 @@ #nullable enable using System.ComponentModel; -using System.Diagnostics; namespace Terminal.Gui; @@ -45,12 +44,12 @@ public static partial class Application // Mouse handling /// View that will receive all mouse events until is invoked. public static void GrabMouse (View? view) { - if (view is null || OnGrabbingMouse (view)) + if (view is null || RaiseGrabbingMouseEvent (view)) { return; } - OnGrabbedMouse (view); + RaiseGrabbedMouseEvent (view); MouseGrabView = view; } @@ -66,16 +65,16 @@ public static void UngrabMouse () ObjectDisposedException.ThrowIf (MouseGrabView.WasDisposed, MouseGrabView); #endif - if (!OnUnGrabbingMouse (MouseGrabView)) + if (!RaiseUnGrabbingMouseEvent (MouseGrabView)) { View view = MouseGrabView; MouseGrabView = null; - OnUnGrabbedMouse (view); + RaiseUnGrabbedMouseEvent (view); } } /// A delegate callback throws an exception. - private static bool OnGrabbingMouse (View? view) + private static bool RaiseGrabbingMouseEvent (View? view) { if (view is null) { @@ -89,7 +88,7 @@ private static bool OnGrabbingMouse (View? view) } /// A delegate callback throws an exception. - private static bool OnUnGrabbingMouse (View? view) + private static bool RaiseUnGrabbingMouseEvent (View? view) { if (view is null) { @@ -103,7 +102,7 @@ private static bool OnUnGrabbingMouse (View? view) } /// A delegate callback throws an exception. - private static void OnGrabbedMouse (View? view) + private static void RaiseGrabbedMouseEvent (View? view) { if (view is null) { @@ -114,7 +113,7 @@ private static void OnGrabbedMouse (View? view) } /// A delegate callback throws an exception. - private static void OnUnGrabbedMouse (View? view) + private static void RaiseUnGrabbedMouseEvent (View? view) { if (view is null) { @@ -124,20 +123,14 @@ private static void OnUnGrabbedMouse (View? view) UnGrabbedMouse?.Invoke (view, new (view)); } - /// Event fired when a mouse move or click occurs. Coordinates are screen relative. - /// - /// - /// Use this event to receive mouse events in screen coordinates. Use to - /// receive mouse events relative to a . - /// - /// The will contain the that contains the mouse coordinates. - /// - public static event EventHandler? MouseEvent; - /// Called when a mouse event is raised by the driver. + /// + /// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and + /// calls the appropriate View mouse event handlers. + /// /// This method can be used to simulate a mouse event, e.g. in unit tests. /// The mouse event with coordinates relative to the screen. - internal static void OnMouseEvent (MouseEvent mouseEvent) + internal static void RaiseMouseEvent (MouseEventArgs mouseEvent) { _lastMousePosition = mouseEvent.ScreenPosition; @@ -177,9 +170,6 @@ internal static void OnMouseEvent (MouseEvent mouseEvent) return; } - // We can combine this into the switch expression to reduce cognitive complexity even more and likely - // avoid one or two of these checks in the process, as well. - WantContinuousButtonPressedView = deepestViewUnderMouse switch { { WantContinuousButtonPressed: true } => deepestViewUnderMouse, @@ -194,7 +184,7 @@ internal static void OnMouseEvent (MouseEvent mouseEvent) } // Create a view-relative mouse event to send to the view that is under the mouse. - MouseEvent? viewMouseEvent; + MouseEventArgs? viewMouseEvent; if (deepestViewUnderMouse is Adornment adornment) { @@ -208,7 +198,7 @@ internal static void OnMouseEvent (MouseEvent mouseEvent) View = deepestViewUnderMouse }; } - else if (deepestViewUnderMouse.ViewportToScreen (Rectangle.Empty with { Size = deepestViewUnderMouse.Viewport.Size }).Contains (mouseEvent.Position)) + else if (deepestViewUnderMouse.ViewportToScreen (Rectangle.Empty with { Size = deepestViewUnderMouse.Viewport.Size }).Contains (mouseEvent.ScreenPosition)) { Point viewportLocation = deepestViewUnderMouse.ScreenToViewport (mouseEvent.ScreenPosition); @@ -224,7 +214,7 @@ internal static void OnMouseEvent (MouseEvent mouseEvent) { // The mouse was outside any View's Viewport. - // Debug.Fail ("This should never happen. If it does please file an Issue!!"); + // Debug.Fail ("This should never happen. If it does please file an Issue!!"); return; } @@ -261,7 +251,29 @@ internal static void OnMouseEvent (MouseEvent mouseEvent) } } - internal static bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEvent mouseEvent) + +#pragma warning disable CS1574 // XML comment has cref attribute that could not be resolved + /// + /// Raised when a mouse event occurs. Can be cancelled by setting to . + /// + /// + /// + /// coordinates are screen-relative. + /// + /// + /// will be the deepest view under the under the mouse. + /// + /// + /// coordinates are view-relative. Only valid if is set. + /// + /// + /// Use this evento to handle mouse events at the application level, before View-specific handling. + /// + /// + public static event EventHandler? MouseEvent; +#pragma warning restore CS1574 // XML comment has cref attribute that could not be resolved + + internal static bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEventArgs mouseEvent) { if (MouseGrabView is { }) { @@ -276,7 +288,7 @@ internal static bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEvent mo // The coordinates are relative to the Bounds of the view that grabbed the mouse. Point frameLoc = MouseGrabView.ScreenToViewport (mouseEvent.ScreenPosition); - var viewRelativeMouseEvent = new MouseEvent + var viewRelativeMouseEvent = new MouseEventArgs { Position = frameLoc, Flags = mouseEvent.Flags, @@ -303,7 +315,6 @@ internal static bool HandleMouseGrab (View? deepestViewUnderMouse, MouseEvent mo internal static readonly List _cachedViewsUnderMouse = new (); - // TODO: Refactor MouseEnter/LeaveEvents to not take MouseEvent param. /// /// INTERNAL: Raises the MouseEnter and MouseLeave events for the views that are under the mouse. /// diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 9f2a454654..7d6de3834f 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -588,11 +588,11 @@ public virtual Attribute MakeColor (in Color foreground, in Color background) public void OnKeyUp (Key a) { KeyUp?.Invoke (this, a); } /// Event fired when a mouse event occurs. - public event EventHandler? MouseEvent; + public event EventHandler? MouseEvent; /// Called when a mouse event occurs. Fires the event. /// - public void OnMouseEvent (MouseEvent a) + public void OnMouseEvent (MouseEventArgs a) { // Ensure ScreenPosition is set a.ScreenPosition = a.Position; diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 0b11949a94..b806457d46 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -1004,7 +1004,7 @@ bool IsButtonClickedOrDoubleClicked (MouseFlags flag) _lastMouseFlags = mouseFlag; - var me = new MouseEvent { Flags = mouseFlag, Position = pos }; + var me = new MouseEventArgs { Flags = mouseFlag, Position = pos }; //Debug.WriteLine ($"CursesDriver: ({me.Position}) - {me.Flags}"); OnMouseEvent (me); diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index 1298c1c357..8aaddc3215 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -1154,7 +1154,7 @@ private void ProcessInput (InputResult inputEvent) break; case EventType.Mouse: - MouseEvent me = ToDriverMouse (inputEvent.MouseEvent); + MouseEventArgs me = ToDriverMouse (inputEvent.MouseEvent); //Debug.WriteLine ($"NetDriver: ({me.X},{me.Y}) - {me.Flags}"); OnMouseEvent (me); @@ -1393,7 +1393,7 @@ public void StopReportingMouseMoves () } } - private MouseEvent ToDriverMouse (NetEvents.MouseEvent me) + private MouseEventArgs ToDriverMouse (NetEvents.MouseEvent me) { //System.Diagnostics.Debug.WriteLine ($"X: {me.Position.X}; Y: {me.Position.Y}; ButtonState: {me.ButtonState}"); @@ -1539,7 +1539,7 @@ private MouseEvent ToDriverMouse (NetEvents.MouseEvent me) mouseFlag |= MouseFlags.ButtonAlt; } - return new MouseEvent { Position = me.Position, Flags = mouseFlag }; + return new MouseEventArgs { Position = me.Position, Flags = mouseFlag }; } #endregion Mouse Handling diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 2a9bef0810..fd5c6901c1 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -1483,7 +1483,7 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent) break; case WindowsConsole.EventType.Mouse: - MouseEvent me = ToDriverMouse (inputEvent.MouseEvent); + MouseEventArgs me = ToDriverMouse (inputEvent.MouseEvent); if (me is null || me.Flags == MouseFlags.None) { @@ -1827,9 +1827,9 @@ private async Task ProcessContinuousButtonPressedAsync (MouseFlags mouseFlag) } await Task.Delay (delay); - var me = new MouseEvent + var me = new MouseEventArgs { - Position = _pointMove, + ScreenPosition = _pointMove, Flags = mouseFlag }; @@ -1883,7 +1883,7 @@ private static MouseFlags SetControlKeyStates (WindowsConsole.MouseEventRecord m } [CanBeNull] - private MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent) + private MouseEventArgs ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent) { var mouseFlag = MouseFlags.AllEvents; @@ -2127,7 +2127,7 @@ private MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent) //System.Diagnostics.Debug.WriteLine ( // $"point.X:{(point is { } ? ((Point)point).X : -1)};point.Y:{(point is { } ? ((Point)point).Y : -1)}"); - return new MouseEvent + return new MouseEventArgs { Position = new (mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y), Flags = mouseFlag diff --git a/Terminal.Gui/Input/MouseEventArgs.cs b/Terminal.Gui/Input/MouseEventArgs.cs new file mode 100644 index 0000000000..cdf3aafb1c --- /dev/null +++ b/Terminal.Gui/Input/MouseEventArgs.cs @@ -0,0 +1,101 @@ +#nullable enable +using System.ComponentModel; + +namespace Terminal.Gui; + +/// +/// Specifies the event arguments for . This is a higher-level construct than +/// the wrapped class and is used for the events defined on +/// and subclasses +/// of View (e.g. and ). +/// +public class MouseEventArgs : HandledEventArgs +{ + /// + /// Flags indicating the state of the mouse buttons and the type of event that occurred. + /// + public MouseFlags Flags { get; set; } + + /// + /// The screen-relative mouse position. + /// + public Point ScreenPosition { get; set; } + + /// The deepest View who's contains . + public View? View { get; set; } + + /// + /// The position of the mouse in 's Viewport-relative coordinates. Only valid if + /// is set. + /// + public Point Position { get; set; } + + /// + /// Gets whether contains any of the button pressed related flags. + /// + public bool IsPressed => Flags.HasFlag (MouseFlags.Button1Pressed) + || Flags.HasFlag (MouseFlags.Button2Pressed) + || Flags.HasFlag (MouseFlags.Button3Pressed) + || Flags.HasFlag (MouseFlags.Button4Pressed); + + /// + /// Gets whether contains any of the button released related flags. + /// + public bool IsReleased => Flags.HasFlag (MouseFlags.Button1Released) + || Flags.HasFlag (MouseFlags.Button2Released) + || Flags.HasFlag (MouseFlags.Button3Released) + || Flags.HasFlag (MouseFlags.Button4Released); + + /// + /// Gets whether contains any of the single-clicked related flags. + /// + public bool IsSingleClicked => Flags.HasFlag (MouseFlags.Button1Clicked) + || Flags.HasFlag (MouseFlags.Button2Clicked) + || Flags.HasFlag (MouseFlags.Button3Clicked) + || Flags.HasFlag (MouseFlags.Button4Clicked); + + /// + /// Gets whether contains any of the double-clicked related flags. + /// + public bool IsDoubleClicked => Flags.HasFlag (MouseFlags.Button1DoubleClicked) + || Flags.HasFlag (MouseFlags.Button2DoubleClicked) + || Flags.HasFlag (MouseFlags.Button3DoubleClicked) + || Flags.HasFlag (MouseFlags.Button4DoubleClicked); + + /// + /// Gets whether contains any of the triple-clicked related flags. + /// + public bool IsTripleClicked => Flags.HasFlag (MouseFlags.Button1TripleClicked) + || Flags.HasFlag (MouseFlags.Button2TripleClicked) + || Flags.HasFlag (MouseFlags.Button3TripleClicked) + || Flags.HasFlag (MouseFlags.Button4TripleClicked); + + /// + /// Gets whether contains any of the mouse button clicked related flags. + /// + public bool IsSingleDoubleOrTripleClicked => + Flags.HasFlag (MouseFlags.Button1Clicked) + || Flags.HasFlag (MouseFlags.Button2Clicked) + || Flags.HasFlag (MouseFlags.Button3Clicked) + || Flags.HasFlag (MouseFlags.Button4Clicked) + || Flags.HasFlag (MouseFlags.Button1DoubleClicked) + || Flags.HasFlag (MouseFlags.Button2DoubleClicked) + || Flags.HasFlag (MouseFlags.Button3DoubleClicked) + || Flags.HasFlag (MouseFlags.Button4DoubleClicked) + || Flags.HasFlag (MouseFlags.Button1TripleClicked) + || Flags.HasFlag (MouseFlags.Button2TripleClicked) + || Flags.HasFlag (MouseFlags.Button3TripleClicked) + || Flags.HasFlag (MouseFlags.Button4TripleClicked); + + /// + /// Gets whether contains any of the mouse wheel related flags. + /// + public bool IsWheel => Flags.HasFlag (MouseFlags.WheeledDown) + || Flags.HasFlag (MouseFlags.WheeledUp) + || Flags.HasFlag (MouseFlags.WheeledLeft) + || Flags.HasFlag (MouseFlags.WheeledRight); + + /// Returns a that represents the current . + /// A that represents the current . + public override string ToString () { return $"({ScreenPosition}):{Flags}:{View?.Id}:{Position}"; } +} diff --git a/Terminal.Gui/Input/MouseEventEventArgs.cs b/Terminal.Gui/Input/MouseEventEventArgs.cs deleted file mode 100644 index 89fc168a7e..0000000000 --- a/Terminal.Gui/Input/MouseEventEventArgs.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Terminal.Gui; - -/// -/// Specifies the event arguments for . This is a higher-level construct than -/// the wrapped class and is used for the events defined on and subclasses -/// of View (e.g. and ). -/// -public class MouseEventEventArgs : EventArgs -{ - /// Constructs. - /// The mouse event. - public MouseEventEventArgs (MouseEvent me) { MouseEvent = me; } - - /// - /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other - /// event subscriber. It's important to set this value to true specially when updating any View's layout from inside the - /// subscriber method. - /// - /// - /// This property forwards to the property and is provided as a convenience and - /// for backwards compatibility - /// - public bool Handled - { - get => MouseEvent.Handled; - set => MouseEvent.Handled = value; - } - - // TODO: Merge MouseEvent and MouseEventEventArgs into a single class. - /// The for the event. - public MouseEvent MouseEvent { get; set; } -} diff --git a/Terminal.Gui/Input/Mouse.cs b/Terminal.Gui/Input/MouseFlags.cs similarity index 59% rename from Terminal.Gui/Input/Mouse.cs rename to Terminal.Gui/Input/MouseFlags.cs index 3c8c98e91f..56bed6e886 100644 --- a/Terminal.Gui/Input/Mouse.cs +++ b/Terminal.Gui/Input/MouseFlags.cs @@ -1,12 +1,12 @@ namespace Terminal.Gui; -/// Mouse flags reported in . +/// Mouse flags reported in . /// They just happen to map to the ncurses ones. [Flags] public enum MouseFlags { /// - /// No mouse event. This is the default value for when no mouse event is being reported. + /// No mouse event. This is the default value for when no mouse event is being reported. /// None = 0, @@ -97,50 +97,3 @@ public enum MouseFlags /// Mask that captures all the events. AllEvents = 0x7ffffff } - -// TODO: Merge MouseEvent and MouseEventEventArgs into a single class. - -/// -/// Conveys the details of mouse events, such as coordinates and button state, from -/// ConsoleDrivers up to and Views. -/// -/// -/// The class includes the event which takes a -/// MouseEvent argument. -/// -public class MouseEvent -{ - /// Flags indicating the kind of mouse event that is being posted. - public MouseFlags Flags { get; set; } - - /// The View at the location for the mouse event. - public View View { get; set; } - - /// The position of the mouse in -relative coordinates. - public Point Position { get; set; } - - /// - /// The screen-relative mouse position. - /// - /// - /// - /// is -relative. When the mouse is grabbed by a view, - /// provides the mouse position screen-relative coordinates, enabling the grabbed view to know how much the - /// mouse has moved. - /// - /// - /// Calculated and processed in . - /// - /// - public Point ScreenPosition { get; set; } - - /// - /// Indicates if the current mouse event has been processed. Set this value to to indicate the mouse - /// event was handled. - /// - public bool Handled { get; set; } - - /// Returns a that represents the current . - /// A that represents the current . - public override string ToString () { return $"({Position}):{Flags}"; } -} diff --git a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs index 2fa920e708..9602776f5c 100644 --- a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs @@ -59,7 +59,7 @@ public override void GenerateSuggestions (AutocompleteContext context) } /// - public override bool OnMouseEvent (MouseEvent me, bool fromHost = false) { return false; } + public override bool OnMouseEvent (MouseEventArgs me, bool fromHost = false) { return false; } /// public override bool ProcessKey (Key a) diff --git a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs index 39d725ca4b..ad51d5e225 100644 --- a/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs +++ b/Terminal.Gui/Text/Autocomplete/AutocompleteBase.cs @@ -49,7 +49,7 @@ public abstract class AutocompleteBase : IAutocomplete public virtual AutocompleteContext Context { get; set; } /// - public abstract bool OnMouseEvent (MouseEvent me, bool fromHost = false); + public abstract bool OnMouseEvent (MouseEventArgs me, bool fromHost = false); /// public abstract bool ProcessKey (Key a); diff --git a/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs index 6305386bdb..88d3a80260 100644 --- a/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/IAutocomplete.cs @@ -45,7 +45,7 @@ public interface IAutocomplete /// The mouse event. /// If was called from the popup or from the host. /// trueif the mouse can be handled falseotherwise. - bool OnMouseEvent (MouseEvent me, bool fromHost = false); + bool OnMouseEvent (MouseEventArgs me, bool fromHost = false); /// Gets or sets where the popup will be displayed. bool PopupInsideContainer { get; set; } diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs index 622e6620b9..39bdd7522d 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs @@ -25,6 +25,6 @@ public override void OnDrawContent (Rectangle viewport) _autoComplete.RenderOverlay (_autoComplete.LastPopupPos.Value); } - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) { return _autoComplete.OnMouseEvent (mouseEvent); } + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { return _autoComplete.OnMouseEvent (mouseEvent); } } } diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index c17695ee7e..4f332bd541 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -105,7 +105,7 @@ public override void EnsureSelectedIdxIsValid () /// The mouse event. /// If was called from the popup or from the host. /// trueif the mouse can be handled falseotherwise. - public override bool OnMouseEvent (MouseEvent me, bool fromHost = false) + public override bool OnMouseEvent (MouseEventArgs me, bool fromHost = false) { if (fromHost) { @@ -488,7 +488,7 @@ protected void MoveUp () /// Render the current selection in the Autocomplete context menu by the mouse reporting. /// - protected void RenderSelectedIdxByMouse (MouseEvent me) + protected void RenderSelectedIdxByMouse (MouseEventArgs me) { if (SelectedIdx != me.Position.Y - ScrollOffset) { diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 082df687f7..add7527e66 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -262,13 +262,8 @@ private void Border_Highlight (object? sender, CancelEventArgs e private Point _startGrabPoint; /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { - if (base.OnMouseEvent (mouseEvent)) - { - return true; - } - // BUGBUG: See https://github.com/gui-cs/Terminal.Gui/issues/3312 if (!_dragPosition.HasValue && mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) // HACK: Prevents Window from being draggable if it's Top @@ -1370,7 +1365,7 @@ private void AddArrangeModeKeyBindings () KeyBindings.Add (Key.Tab.WithShift, KeyBindingScope.HotKey, Command.BackTab); } - private void ApplicationOnMouseEvent (object? sender, MouseEvent e) + private void ApplicationOnMouseEvent (object? sender, MouseEventArgs e) { if (e.Flags != MouseFlags.Button1Clicked) { diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index 8f51a4f9b7..7dbc1cd704 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -50,7 +50,7 @@ public override ColorScheme ColorScheme /// /// /// , if the event was handled, otherwise. - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (Parent is null) { diff --git a/Terminal.Gui/View/View.Mouse.cs b/Terminal.Gui/View/View.Mouse.cs index 2fc180ece0..a76de77b34 100644 --- a/Terminal.Gui/View/View.Mouse.cs +++ b/Terminal.Gui/View/View.Mouse.cs @@ -11,7 +11,7 @@ public partial class View // Mouse APIs private ColorScheme? _savedNonHoverColorScheme; /// - /// INTERNAL Called by when the mouse moves over the View's . + /// INTERNAL Called by when the mouse moves over the View's . /// will /// be raised when the mouse is no longer over the . If another View occludes this View, the /// that View will also receive MouseEnter/Leave events. @@ -126,7 +126,7 @@ public partial class View // Mouse APIs public event EventHandler? MouseEnter; /// - /// INTERNAL Called by when the mouse leaves , or is occluded + /// INTERNAL Called by when the mouse leaves , or is occluded /// by another non-SubView. /// /// @@ -196,16 +196,15 @@ protected virtual void OnMouseLeave () { } #region Low Level Mouse Events - /// Event fired when a mouse event occurs. - /// - /// - /// The coordinates are relative to . - /// - /// - public event EventHandler? MouseEvent; + /// Gets or sets whether the wants continuous button pressed events. + public virtual bool WantContinuousButtonPressed { get; set; } + + /// Gets or sets whether the wants mouse position reports. + /// if mouse position reports are wanted; otherwise, . + public bool WantMousePositionReports { get; set; } /// - /// Processes a . This method is called by when a mouse + /// Processes a new . This method is called by when a mouse /// event occurs. /// /// @@ -213,20 +212,20 @@ protected virtual void OnMouseLeave () { } /// A view must be both enabled and visible to receive mouse events. /// /// - /// This method calls to process the event. If the event is not handled, and one of the - /// mouse buttons was clicked, it calls to process the click. + /// This method raises /; if not handled, and one of the + /// mouse buttons was clicked, the / event will be raised /// /// /// See for more information. /// /// - /// If is , the event - /// will be invoked repeatedly while the button is pressed. + /// If is , the / event + /// will be raised on any new mouse event where indicates a button is pressed. /// /// /// /// if the event was handled, otherwise. - public bool? NewMouseEvent (MouseEvent mouseEvent) + public bool? NewMouseEvent (MouseEventArgs mouseEvent) { // Pre-conditions if (!Enabled) @@ -246,17 +245,13 @@ protected virtual void OnMouseLeave () { } } // Cancellable event - if (OnMouseEvent (mouseEvent)) + if (RaiseMouseEvent (mouseEvent) || mouseEvent.Handled) { - // Technically mouseEvent.Handled should already be true if implementers of OnMouseEvent - // follow the rules. But we'll update it just in case. - return mouseEvent.Handled = true; + return true; } - // BUGBUG: MouseEvent should be fired from here. Fix this in https://github.com/gui-cs/Terminal.Gui/issues/3029 - // Post-Conditions - if (HighlightStyle != HighlightStyle.None || (WantContinuousButtonPressed && WantMousePositionReports)) + if (HighlightStyle != HighlightStyle.None || WantContinuousButtonPressed) { if (WhenGrabbedHandlePressed (mouseEvent)) { @@ -274,35 +269,33 @@ protected virtual void OnMouseLeave () { } } } - if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button1TripleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2TripleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3TripleClicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4TripleClicked) - ) + if (mouseEvent.IsSingleDoubleOrTripleClicked) { // If it's a click, and we didn't handle it, then we need to generate a click event // We get here if the view did not handle the mouse event via OnMouseEvent/MouseEvent and // it did not handle the press/release/clicked events via HandlePress/HandleRelease/HandleClicked - return OnMouseClick (new (mouseEvent)); + return RaiseMouseClickEvent (mouseEvent); } return false; } - /// Gets or sets whether the wants continuous button pressed events. - public virtual bool WantContinuousButtonPressed { get; set; } + /// + /// Raises the / event. + /// + /// + /// , if the event was handled, otherwise. + public bool RaiseMouseEvent (MouseEventArgs mouseEvent) + { + if (OnMouseEvent (mouseEvent) || mouseEvent.Handled == true) + { + return true; + } - /// Gets or sets whether the wants mouse position reports. - /// if mouse position reports are wanted; otherwise, . - public virtual bool WantMousePositionReports { get; set; } + MouseEvent?.Invoke (this, mouseEvent); + + return mouseEvent.Handled; + } /// Called when a mouse event occurs within the view's . /// @@ -312,44 +305,36 @@ protected virtual void OnMouseLeave () { } /// /// /// , if the event was handled, otherwise. - protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent) + protected virtual bool OnMouseEvent (MouseEventArgs mouseEvent) { - var args = new MouseEventEventArgs (mouseEvent); - - MouseEvent?.Invoke (this, args); - - return args.Handled; + return false; } - #endregion Low Level Mouse Events - - #region Mouse Click Events - - /// Event fired when a mouse click occurs. - /// + /// Raised when a mouse event occurs. /// /// - /// Fired when the mouse is either clicked or double-clicked. Check - /// to see which button was clicked. - /// - /// /// The coordinates are relative to . /// /// - public event EventHandler? MouseClick; + public event EventHandler? MouseEvent; + + #endregion Low Level Mouse Events - /// Invokes the MouseClick event. + #region Mouse Click Events + + /// Raises the / event. /// /// - /// Called when the mouse is either clicked or double-clicked. Check - /// to see which button was clicked. + /// Called when the mouse is either clicked or double-clicked. + /// + /// + /// If is , will be invoked on every mouse event where + /// the mouse button is pressed. /// /// /// , if the event was handled, otherwise. - protected bool OnMouseClick (MouseEventEventArgs args) + protected bool RaiseMouseClickEvent (MouseEventArgs args) { - // BUGBUG: This should be named NewMouseClickEvent. Fix this in https://github.com/gui-cs/Terminal.Gui/issues/3029 - // Pre-conditions if (!Enabled) { @@ -359,7 +344,10 @@ protected bool OnMouseClick (MouseEventEventArgs args) // Cancellable event - // BUGBUG: There should be a call to a protected virtual OnMouseClick here. Fix this in https://github.com/gui-cs/Terminal.Gui/issues/3029 + if (OnMouseClick (args) || args.Handled) + { + return args.Handled; + } MouseClick?.Invoke (this, args); @@ -372,11 +360,39 @@ protected bool OnMouseClick (MouseEventEventArgs args) // Always invoke Select command on MouseClick // By default, this will raise Selecting/OnSelecting - Subclasses can override this via AddCommand (Command.Select ...). - args.Handled = InvokeCommand (Command.Select, ctx: new (Command.Select, key: null, data: args.MouseEvent)) == true; + args.Handled = InvokeCommand (Command.Select, ctx: new (Command.Select, key: null, data: args)) == true; return args.Handled; } + /// + /// Called when a mouse click occurs. Check to see which button was clicked. + /// + /// + /// + /// Called when the mouse is either clicked or double-clicked. + /// + /// + /// If is , will be called on every mouse event where + /// the mouse button is pressed. + /// + /// + /// + /// , if the event was handled, otherwise. + protected virtual bool OnMouseClick (MouseEventArgs args) { return false; } + + /// Raised when a mouse click occurs. + /// + /// + /// Raised when the mouse is either clicked or double-clicked. + /// + /// + /// If is , will be raised on every mouse event where + /// the mouse button is pressed. + /// + /// + public event EventHandler? MouseClick; + /// /// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically /// when or are set). @@ -386,13 +402,11 @@ protected bool OnMouseClick (MouseEventEventArgs args) /// /// /// , if the event was handled, otherwise. - internal bool WhenGrabbedHandleClicked (MouseEvent mouseEvent) + internal bool WhenGrabbedHandleClicked (MouseEventArgs mouseEvent) { - if (Application.MouseGrabView == this - && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked))) + mouseEvent.Handled = false; + + if (Application.MouseGrabView == this && mouseEvent.IsSingleClicked) { // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab Application.UngrabMouse (); @@ -405,7 +419,7 @@ internal bool WhenGrabbedHandleClicked (MouseEvent mouseEvent) // If mouse is still in bounds, generate a click if (!WantMousePositionReports && Viewport.Contains (mouseEvent.Position)) { - return OnMouseClick (new (mouseEvent)); + return RaiseMouseClickEvent (mouseEvent); } return mouseEvent.Handled = true; @@ -423,12 +437,11 @@ internal bool WhenGrabbedHandleClicked (MouseEvent mouseEvent) /// /// /// , if the event was handled, otherwise. - internal bool WhenGrabbedHandleReleased (MouseEvent mouseEvent) + internal bool WhenGrabbedHandleReleased (MouseEventArgs mouseEvent) { - if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2Released) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3Released) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4Released)) + mouseEvent.Handled = false; + + if (mouseEvent.IsReleased) { if (Application.MouseGrabView == this) { @@ -452,12 +465,11 @@ internal bool WhenGrabbedHandleReleased (MouseEvent mouseEvent) /// /// /// , if the event was handled, otherwise. - private bool WhenGrabbedHandlePressed (MouseEvent mouseEvent) + private bool WhenGrabbedHandlePressed (MouseEventArgs mouseEvent) { - if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) - || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed) - || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed) - || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed)) + mouseEvent.Handled = false; + + if (mouseEvent.IsPressed) { // The first time we get pressed event, grab the mouse and set focus if (Application.MouseGrabView != this) @@ -493,8 +505,7 @@ private bool WhenGrabbedHandlePressed (MouseEvent mouseEvent) if (WantContinuousButtonPressed && Application.MouseGrabView == this) { - // If this is not the first pressed event, generate a click - return OnMouseClick (new (mouseEvent)); + return RaiseMouseClickEvent (mouseEvent); } return mouseEvent.Handled = true; diff --git a/Terminal.Gui/Views/Bar.cs b/Terminal.Gui/Views/Bar.cs index ddaa444365..1511cd68af 100644 --- a/Terminal.Gui/Views/Bar.cs +++ b/Terminal.Gui/Views/Bar.cs @@ -45,27 +45,27 @@ public Bar (IEnumerable shortcuts) } } - private void OnMouseEvent (object? sender, MouseEventEventArgs e) + private void OnMouseEvent (object? sender, MouseEventArgs e) { NavigationDirection direction = NavigationDirection.Backward; - if (e.MouseEvent.Flags == MouseFlags.WheeledDown) + if (e.Flags == MouseFlags.WheeledDown) { e.Handled = true; } - if (e.MouseEvent.Flags == MouseFlags.WheeledUp) + if (e.Flags == MouseFlags.WheeledUp) { direction = NavigationDirection.Forward; e.Handled = true; } - if (e.MouseEvent.Flags == MouseFlags.WheeledRight) + if (e.Flags == MouseFlags.WheeledRight) { e.Handled = true; } - if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) + if (e.Flags == MouseFlags.WheeledLeft) { direction = NavigationDirection.Forward; e.Handled = true; diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index e29043ed9b..f642f23d9c 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -125,7 +125,7 @@ public override bool WantContinuousButtonPressed } } - private void Button_MouseClick (object sender, MouseEventEventArgs e) + private void Button_MouseClick (object sender, MouseEventArgs e) { if (e.Handled) { diff --git a/Terminal.Gui/Views/ColorBar.cs b/Terminal.Gui/Views/ColorBar.cs index 066ad72b2f..581606d175 100644 --- a/Terminal.Gui/Views/ColorBar.cs +++ b/Terminal.Gui/Views/ColorBar.cs @@ -110,7 +110,7 @@ public override void OnDrawContent (Rectangle viewport) public event EventHandler>? ValueChanged; /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)) { @@ -123,10 +123,9 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent) mouseEvent.Handled = true; SetFocus (); - return true; } - return base.OnMouseEvent (mouseEvent); + return mouseEvent.Handled; } /// diff --git a/Terminal.Gui/Views/ColorPicker.16.cs b/Terminal.Gui/Views/ColorPicker.16.cs index c0ae787177..c1cb72cc23 100644 --- a/Terminal.Gui/Views/ColorPicker.16.cs +++ b/Terminal.Gui/Views/ColorPicker.16.cs @@ -181,11 +181,11 @@ private void AddKeyBindings () // TODO: Decouple Cursor from SelectedColor so that mouse press-and-hold can show the color under the cursor. - private void ColorPicker_MouseClick (object sender, MouseEventEventArgs me) + private void ColorPicker_MouseClick (object sender, MouseEventArgs me) { // if (CanFocus) { - Cursor = new (me.MouseEvent.Position.X / _boxWidth, me.MouseEvent.Position.Y / _boxHeight); + Cursor = new (me.Position.X / _boxWidth, me.Position.Y / _boxHeight); SetFocus (); me.Handled = true; } diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 3f92174c82..996056068c 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -253,7 +253,7 @@ public virtual bool Expand () public event EventHandler Expanded; /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (me.Position.X == Viewport.Right - 1 && me.Position.Y == Viewport.Top @@ -836,14 +836,15 @@ public bool HideDropdownListOnClick set => _hideDropdownListOnClick = WantContinuousButtonPressed = value; } - // BUGBUG: OnMouseEvent is internal! - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { - var res = false; bool isMousePositionValid = IsMousePositionValid (me); + var res = false; + if (isMousePositionValid) { + // We're derived from ListView and it overrides OnMouseEvent, so we need to call it res = base.OnMouseEvent (me); } @@ -984,7 +985,7 @@ public override bool OnSelectedChanged () return res; } - private bool IsMousePositionValid (MouseEvent me) + private bool IsMousePositionValid (MouseEventArgs me) { if (me.Position.X >= 0 && me.Position.X < Frame.Width && me.Position.Y >= 0 && me.Position.Y < Frame.Height) { diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 49da4f100e..9490a7b28c 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -114,16 +114,19 @@ public override void DeleteCharRight () } /// - protected internal override bool OnMouseEvent (MouseEvent ev) + protected override bool OnMouseEvent (MouseEventArgs ev) { - bool result = base.OnMouseEvent (ev); + if (base.OnMouseEvent (ev) || ev.Handled) + { + return true; + } - if (result && SelectedLength == 0 && ev.Flags.HasFlag (MouseFlags.Button1Pressed)) + if (SelectedLength == 0 && ev.Flags.HasFlag (MouseFlags.Button1Pressed)) { AdjCursorPosition (ev.Position.X); } - return result; + return ev.Handled; } /// Event firing method for the event. @@ -169,7 +172,7 @@ private void AdjCursorPosition (int point, bool increment = true) CursorPosition = newPoint; } - while (Text [CursorPosition].ToString () == _separator) + while (CursorPosition < Text.GetColumns () - 1 && Text [CursorPosition].ToString () == _separator) { if (increment) { diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index 3bc7bb3863..2ded19418f 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -1007,18 +1007,18 @@ private void New () } } - private void OnTableViewMouseClick (object sender, MouseEventEventArgs e) + private void OnTableViewMouseClick (object sender, MouseEventArgs e) { - Point? clickedCell = _tableView.ScreenToCell (e.MouseEvent.Position.X, e.MouseEvent.Position.Y, out int? clickedCol); + Point? clickedCell = _tableView.ScreenToCell (e.Position.X, e.Position.Y, out int? clickedCol); if (clickedCol is { }) { - if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + if (e.Flags.HasFlag (MouseFlags.Button1Clicked)) { // left click in a header SortColumn (clickedCol.Value); } - else if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + else if (e.Flags.HasFlag (MouseFlags.Button3Clicked)) { // right click in a header ShowHeaderContextMenu (clickedCol.Value, e); @@ -1026,7 +1026,7 @@ private void OnTableViewMouseClick (object sender, MouseEventEventArgs e) } else { - if (clickedCell is { } && e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + if (clickedCell is { } && e.Flags.HasFlag (MouseFlags.Button3Clicked)) { // right click in rest of table ShowCellContextMenu (clickedCell, e); @@ -1198,7 +1198,7 @@ private void RestartSearch () private FileSystemInfoStats RowToStats (int rowIndex) { return State?.Children [rowIndex]; } - private void ShowCellContextMenu (Point? clickedCell, MouseEventEventArgs e) + private void ShowCellContextMenu (Point? clickedCell, MouseEventArgs e) { if (clickedCell is null) { @@ -1207,7 +1207,7 @@ private void ShowCellContextMenu (Point? clickedCell, MouseEventEventArgs e) var contextMenu = new ContextMenu { - Position = new Point (e.MouseEvent.Position.X + 1, e.MouseEvent.Position.Y + 1) + Position = new Point (e.Position.X + 1, e.Position.Y + 1) }; var menuItems = new MenuBarItem ( @@ -1222,13 +1222,13 @@ private void ShowCellContextMenu (Point? clickedCell, MouseEventEventArgs e) contextMenu.Show (menuItems); } - private void ShowHeaderContextMenu (int clickedCol, MouseEventEventArgs e) + private void ShowHeaderContextMenu (int clickedCol, MouseEventArgs e) { string sort = GetProposedNewSortOrder (clickedCol, out bool isAsc); var contextMenu = new ContextMenu { - Position = new Point (e.MouseEvent.Position.X + 1, e.MouseEvent.Position.Y + 1) + Position = new Point (e.Position.X + 1, e.Position.Y + 1) }; var menuItems = new MenuBarItem ( diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index f8b1ffc8bf..de2f862150 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -22,7 +22,7 @@ public FrameView () MouseClick += FrameView_MouseClick; } - private void FrameView_MouseClick (object sender, MouseEventEventArgs e) + private void FrameView_MouseClick (object sender, MouseEventArgs e) { // base sets focus on HotKey e.Handled = InvokeCommand (Command.HotKey, ctx: new (Command.HotKey, key: null, data: this)) == true; diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index a5a213b821..e1cca01ed7 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -250,7 +250,7 @@ public void ApplyEdits (Stream stream = null) public event EventHandler Edited; /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 3a76a8a717..07eca7983c 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -32,7 +32,7 @@ public Label () } // TODO: base raises Select, but we want to raise HotKey. This can be simplified? - private void Label_MouseClick (object sender, MouseEventEventArgs e) + private void Label_MouseClick (object sender, MouseEventArgs e) { if (!CanFocus) { diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index bae3400ced..925bc203ce 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -472,7 +472,7 @@ public bool MarkUnmarkSelectedItem () } /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index b961f68bc7..a8c50755b3 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -1,5 +1,7 @@ #nullable enable +using static System.Formats.Asn1.AsnWriter; + namespace Terminal.Gui; /// @@ -335,7 +337,7 @@ protected override void OnVisibleChanged () } } - private void Application_RootMouseEvent (object? sender, MouseEvent a) + private void Application_RootMouseEvent (object? sender, MouseEventArgs a) { if (a.View is { } and (MenuBar or not Menu)) { @@ -351,7 +353,7 @@ private void Application_RootMouseEvent (object? sender, MouseEvent a) Point boundsPoint = view.ScreenToViewport (new (a.Position.X, a.Position.Y)); - var me = new MouseEvent + var me = new MouseEventArgs { Position = boundsPoint, Flags = a.Flags, @@ -806,7 +808,7 @@ private void SetParentSetNeedsDisplay () _host.SetNeedsDisplay (); } - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!_host._handled && !_host.HandleGrabView (me, this)) { diff --git a/Terminal.Gui/Views/Menu/MenuBar.cs b/Terminal.Gui/Views/Menu/MenuBar.cs index 731edc11ca..a15d1e4633 100644 --- a/Terminal.Gui/Views/Menu/MenuBar.cs +++ b/Terminal.Gui/Views/Menu/MenuBar.cs @@ -137,7 +137,7 @@ public MenuBar () }); AddCommand (Command.Select, ctx => { - if (ctx.Data is MouseEvent) + if (ctx.Data is MouseEventArgs) { // HACK: Work around the fact that View.MouseClick always invokes Select return false; @@ -1400,7 +1400,7 @@ internal void LostFocus (View view) } /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!_handled && !HandleGrabView (me, this)) { @@ -1513,7 +1513,7 @@ protected internal override bool OnMouseEvent (MouseEvent me) internal bool _isContextMenuLoading; private MenuBarItem [] _menus = []; - internal bool HandleGrabView (MouseEvent me, View current) + internal bool HandleGrabView (MouseEventArgs me, View current) { if (Application.MouseGrabView is { }) { @@ -1541,7 +1541,7 @@ internal bool HandleGrabView (MouseEvent me, View current) Application.UngrabMouse (); View v = me.View; Application.GrabMouse (v); - MouseEvent nme; + MouseEventArgs nme; if (me.Position.Y > -1) { diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 5cfd9f72b5..f929d0ce5a 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -220,12 +220,12 @@ private void SetupKeyBindings () /// public bool DoubleClickAccepts { get; set; } = true; - private void RadioGroup_MouseClick (object? sender, MouseEventEventArgs e) + private void RadioGroup_MouseClick (object? sender, MouseEventArgs e) { - if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + if (e.Flags.HasFlag (MouseFlags.Button1Clicked)) { - int viewportX = e.MouseEvent.Position.X; - int viewportY = e.MouseEvent.Position.Y; + int viewportX = e.Position.X; + int viewportY = e.Position.Y; int pos = Orientation == Orientation.Horizontal ? viewportX : viewportY; @@ -249,7 +249,7 @@ private void RadioGroup_MouseClick (object? sender, MouseEventEventArgs e) return; } - if (DoubleClickAccepts && e.MouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)) + if (DoubleClickAccepts && e.Flags.HasFlag (MouseFlags.Button1DoubleClicked)) { // NOTE: Drivers ALWAYS generate a Button1Clicked event before Button1DoubleClicked // NOTE: So, we've already selected an item. diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index ce7bd62eb0..f6e8da2961 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -270,7 +270,7 @@ public int Size public event EventHandler ChangedPosition; /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (mouseEvent.Flags != MouseFlags.Button1Pressed && mouseEvent.Flags != MouseFlags.Button1DoubleClicked @@ -777,16 +777,16 @@ private void ContentBottomRightCorner_DrawContent (object sender, DrawEventArgs // } //} - private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEventArgs me) + private void ContentBottomRightCorner_MouseClick (object sender, MouseEventArgs me) { - if (me.MouseEvent.Flags == MouseFlags.WheeledDown - || me.MouseEvent.Flags == MouseFlags.WheeledUp - || me.MouseEvent.Flags == MouseFlags.WheeledRight - || me.MouseEvent.Flags == MouseFlags.WheeledLeft) + if (me.Flags == MouseFlags.WheeledDown + || me.Flags == MouseFlags.WheeledUp + || me.Flags == MouseFlags.WheeledRight + || me.Flags == MouseFlags.WheeledLeft) { - NewMouseEvent (me.MouseEvent); + NewMouseEvent (me); } - else if (me.MouseEvent.Flags == MouseFlags.Button1Clicked) + else if (me.Flags == MouseFlags.Button1Clicked) { Host.SetFocus (); } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 9ad1a75f1d..35d4409e5d 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -406,7 +406,7 @@ protected override bool OnKeyDown (Key a) } /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!Enabled) { @@ -416,19 +416,19 @@ protected internal override bool OnMouseEvent (MouseEvent me) if (me.Flags == MouseFlags.WheeledDown && ShowVerticalScrollIndicator) { - ScrollDown (1); + return ScrollDown (1); } else if (me.Flags == MouseFlags.WheeledUp && ShowVerticalScrollIndicator) { - ScrollUp (1); + return ScrollUp (1); } else if (me.Flags == MouseFlags.WheeledRight && _showHorizontalScrollIndicator) { - ScrollRight (1); + return ScrollRight (1); } else if (me.Flags == MouseFlags.WheeledLeft && ShowVerticalScrollIndicator) { - ScrollLeft (1); + return ScrollLeft (1); } else if (me.Position.X == _vertical.Frame.X && ShowVerticalScrollIndicator) { @@ -443,7 +443,7 @@ protected internal override bool OnMouseEvent (MouseEvent me) Application.UngrabMouse (); } - return base.OnMouseEvent (me); + return me.Handled; } /// diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 4c331251b6..9cbc785d17 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -1282,7 +1282,7 @@ private void DrawLegends () private Point? _moveRenderPosition; /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { // Note(jmperricone): Maybe we click to focus the cursor, and on next click we set the option. // That will make OptionFocused Event more relevant. @@ -1381,11 +1381,9 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent) mouseEvent.Handled = true; - // BUGBUG: OnMouseClick is/should be internal. - return OnMouseClick (new (mouseEvent)); } - return false; + return mouseEvent.Handled; Point ClampMovePosition (Point position) { diff --git a/Terminal.Gui/Views/TabMouseEventArgs.cs b/Terminal.Gui/Views/TabMouseEventArgs.cs index 6b91a3531c..22a23ad017 100644 --- a/Terminal.Gui/Views/TabMouseEventArgs.cs +++ b/Terminal.Gui/Views/TabMouseEventArgs.cs @@ -6,17 +6,17 @@ public class TabMouseEventArgs : EventArgs /// Creates a new instance of the class. /// that the mouse was over when the event occurred. /// The mouse activity being reported - public TabMouseEventArgs (Tab tab, MouseEvent mouseEvent) + public TabMouseEventArgs (Tab tab, MouseEventArgs mouseEvent) { Tab = tab; MouseEvent = mouseEvent; } /// - /// Gets the actual mouse event. Use to cancel this event and perform custom + /// Gets the actual mouse event. Use to cancel this event and perform custom /// behavior (e.g. show a context menu). /// - public MouseEvent MouseEvent { get; } + public MouseEventArgs MouseEvent { get; } /// Gets the (if any) that the mouse was over when the occurred. /// This will be null if the click is after last tab or before first. diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index 3e63dde536..d605b6fa05 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -508,9 +508,9 @@ private int GetTabHeight (bool top) return Style.ShowTopLine ? 3 : 2; } - private void Tab_MouseClick (object sender, MouseEventEventArgs e) + private void Tab_MouseClick (object sender, MouseEventArgs e) { - e.Handled = _tabsBar.NewMouseEvent (e.MouseEvent) == true; + e.Handled = _tabsBar.NewMouseEvent (e) == true; } private void UnSetCurrentTabs () @@ -569,15 +569,11 @@ public TabRowView (TabView host) Add (_rightScrollIndicator, _leftScrollIndicator); } - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { Tab hit = me.View is Tab ? (Tab)me.View : null; - bool isClick = me.Flags.HasFlag (MouseFlags.Button1Clicked) - || me.Flags.HasFlag (MouseFlags.Button2Clicked) - || me.Flags.HasFlag (MouseFlags.Button3Clicked); - - if (isClick) + if (me.IsSingleClicked) { _host.OnTabClicked (new TabMouseEventArgs (hit, me)); @@ -588,9 +584,7 @@ protected internal override bool OnMouseEvent (MouseEvent me) } } - if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) - && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) - && !me.Flags.HasFlag (MouseFlags.Button1TripleClicked)) + if (!me.IsSingleDoubleOrTripleClicked) { return false; } @@ -600,9 +594,7 @@ protected internal override bool OnMouseEvent (MouseEvent me) SetFocus (); } - if (me.Flags.HasFlag (MouseFlags.Button1Clicked) - || me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) - || me.Flags.HasFlag (MouseFlags.Button1TripleClicked)) + if (me.IsSingleDoubleOrTripleClicked) { var scrollIndicatorHit = 0; diff --git a/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs b/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs index 8be294c1a5..abbb2c704b 100644 --- a/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs +++ b/Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs @@ -150,15 +150,15 @@ private void TableView_CellToggled (object sender, CellToggledEventArgs e) tableView.SetNeedsDisplay (); } - private void TableView_MouseClick (object sender, MouseEventEventArgs e) + private void TableView_MouseClick (object sender, MouseEventArgs e) { // we only care about clicks (not movements) - if (!e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + if (!e.Flags.HasFlag (MouseFlags.Button1Clicked)) { return; } - Point? hit = tableView.ScreenToCell (e.MouseEvent.Position.X, e.MouseEvent.Position.Y, out int? headerIfAny); + Point? hit = tableView.ScreenToCell (e.Position.X, e.Position.Y, out int? headerIfAny); if (headerIfAny.HasValue && headerIfAny.Value == 0) { diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 5617c7c210..a33903d0b1 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -801,7 +801,7 @@ public bool IsSelected (int col, int row) } /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) @@ -902,11 +902,11 @@ protected internal override bool OnMouseEvent (MouseEvent me) if (hit is { }) { - OnCellActivated (new CellActivatedEventArgs (Table, hit.Value.X, hit.Value.Y)); + return OnCellActivated (new CellActivatedEventArgs (Table, hit.Value.X, hit.Value.Y)); } } - return base.OnMouseEvent (me); + return me.Handled; } /// @@ -1646,7 +1646,7 @@ private string GetRepresentation (object value, ColumnStyle colStyle) return colStyle is { } ? colStyle.GetRepresentation (value) : value.ToString (); } - private bool HasControlOrAlt (MouseEvent me) { return me.Flags.HasFlag (MouseFlags.ButtonAlt) || me.Flags.HasFlag (MouseFlags.ButtonCtrl); } + private bool HasControlOrAlt (MouseEventArgs me) { return me.Flags.HasFlag (MouseFlags.ButtonAlt) || me.Flags.HasFlag (MouseFlags.ButtonCtrl); } /// /// Returns true if the given indexes a visible column otherwise false. Returns diff --git a/Terminal.Gui/Views/TableView/TreeTableSource.cs b/Terminal.Gui/Views/TableView/TreeTableSource.cs index f2cab65092..c3458b32d3 100644 --- a/Terminal.Gui/Views/TableView/TreeTableSource.cs +++ b/Terminal.Gui/Views/TableView/TreeTableSource.cs @@ -166,9 +166,9 @@ private void Table_KeyPress (object sender, Key e) } } - private void Table_MouseClick (object sender, MouseEventEventArgs e) + private void Table_MouseClick (object sender, MouseEventArgs e) { - Point? hit = _tableView.ScreenToCell (e.MouseEvent.Position.X, e.MouseEvent.Position.Y, out int? headerIfAny, out int? offsetX); + Point? hit = _tableView.ScreenToCell (e.Position.X, e.Position.Y, out int? headerIfAny, out int? offsetX); if (hit is null || headerIfAny is { } || !IsInTreeColumn (hit.Value.X, false) || offsetX is null) { diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 94f512dedb..0b08e1f04b 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -798,16 +798,15 @@ public virtual void KillWordForwards () } /// - protected internal override bool OnMouseEvent (MouseEvent ev) + protected override bool OnMouseEvent (MouseEventArgs ev) { - if (!ev.Flags.HasFlag (MouseFlags.Button1Pressed) + if (ev is { IsPressed: false, IsReleased: false } && !ev.Flags.HasFlag (MouseFlags.ReportMousePosition) - && !ev.Flags.HasFlag (MouseFlags.Button1Released) && !ev.Flags.HasFlag (MouseFlags.Button1DoubleClicked) && !ev.Flags.HasFlag (MouseFlags.Button1TripleClicked) && !ev.Flags.HasFlag (ContextMenu.MouseFlags)) { - return base.OnMouseEvent (ev); + return false; } if (!CanFocus) @@ -1645,7 +1644,7 @@ private int OffSetBackground () return 0; //offB; } - private int PositionCursor (MouseEvent ev) { return PositionCursor (TextModel.GetColFromX (_text, ScrollOffset, ev.Position.X), false); } + private int PositionCursor (MouseEventArgs ev) { return PositionCursor (TextModel.GetColFromX (_text, ScrollOffset, ev.Position.X), false); } private int PositionCursor (int x, bool getX = true) { diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index c6927b5e3c..289855c30a 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -531,7 +531,7 @@ public ITextValidateProvider Provider } /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)) { diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 54174c4957..132f907a35 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -3274,21 +3274,15 @@ public void Load (List> cellsList) } /// - protected internal override bool OnMouseEvent (MouseEvent ev) + protected override bool OnMouseEvent (MouseEventArgs ev) { - if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked) - && !ev.Flags.HasFlag (MouseFlags.Button1Pressed) + if (ev is { IsSingleDoubleOrTripleClicked: false, IsPressed: false, IsReleased: false, IsWheel: false } && !ev.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) - && !ev.Flags.HasFlag (MouseFlags.Button1Released) && !ev.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ButtonShift) - && !ev.Flags.HasFlag (MouseFlags.WheeledDown) - && !ev.Flags.HasFlag (MouseFlags.WheeledUp) - && !ev.Flags.HasFlag (MouseFlags.Button1DoubleClicked) && !ev.Flags.HasFlag (MouseFlags.Button1DoubleClicked | MouseFlags.ButtonShift) - && !ev.Flags.HasFlag (MouseFlags.Button1TripleClicked) && !ev.Flags.HasFlag (ContextMenu!.MouseFlags)) { - return base.OnMouseEvent (ev); + return false; } if (!CanFocus) @@ -5875,7 +5869,7 @@ private void ProcessKillWordForward () KillWordForward (); } - private void ProcessMouseClick (MouseEvent ev, out List line) + private void ProcessMouseClick (MouseEventArgs ev, out List line) { List? r = null; diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 5400ca0467..60370b2cb5 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -910,7 +910,7 @@ public void DrawSplitterSymbol () } } - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (!dragPosition.HasValue && mouseEvent.Flags == MouseFlags.Button1Pressed) { diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs index 687a8cd719..ecc94a7be4 100644 --- a/Terminal.Gui/Views/TimeField.cs +++ b/Terminal.Gui/Views/TimeField.cs @@ -163,17 +163,20 @@ public override void DeleteCharRight () } /// - protected internal override bool OnMouseEvent (MouseEvent ev) + protected override bool OnMouseEvent (MouseEventArgs ev) { - bool result = base.OnMouseEvent (ev); + if (base.OnMouseEvent (ev) || ev.Handled) + { + return true; + } - if (result && SelectedLength == 0 && ev.Flags.HasFlag (MouseFlags.Button1Pressed)) + if (SelectedLength == 0 && ev.Flags.HasFlag (MouseFlags.Button1Pressed)) { int point = ev.Position.X; AdjCursorPosition (point); } - return result; + return ev.Handled; } /// @@ -227,7 +230,7 @@ private void AdjCursorPosition (int point, bool increment = true) CursorPosition = newPoint; } - while (Text [CursorPosition] == _sepChar [0]) + while (CursorPosition < Text.GetColumns() -1 && Text [CursorPosition] == _sepChar [0]) { if (increment) { diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index cfcdcc14d6..ddee6b0412 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -62,7 +62,7 @@ public Toplevel () /// public bool Modal { get; set; } - private void Toplevel_MouseClick (object? sender, MouseEventEventArgs e) { e.Handled = InvokeCommand (Command.HotKey) == true; } + private void Toplevel_MouseClick (object? sender, MouseEventArgs e) { e.Handled = InvokeCommand (Command.HotKey) == true; } #endregion diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index a1a110cbe3..4e09eba2b5 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -990,18 +990,14 @@ public void GoToFirst () // BUGBUG: OnMouseEvent is internal. TreeView should not be overriding. /// - protected internal override bool OnMouseEvent (MouseEvent me) + protected override bool OnMouseEvent (MouseEventArgs me) { // If it is not an event we care about - if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) - && !me.Flags.HasFlag (ObjectActivationButton ?? MouseFlags.Button1DoubleClicked) - && !me.Flags.HasFlag (MouseFlags.WheeledDown) - && !me.Flags.HasFlag (MouseFlags.WheeledUp) - && !me.Flags.HasFlag (MouseFlags.WheeledRight) - && !me.Flags.HasFlag (MouseFlags.WheeledLeft)) + if (me is { IsSingleClicked: false, IsPressed: false, IsReleased: false, IsWheel: false } + && !me.Flags.HasFlag (ObjectActivationButton ?? MouseFlags.Button1DoubleClicked)) { // do nothing - return base.OnMouseEvent (me); + return false; } if (!HasFocus && CanFocus) diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 661efd80d5..45889f3e8b 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -127,7 +127,7 @@ protected override void OnHasFocusChanged (bool newHasFocus, [CanBeNull] View pr } public event Action PointerEnter; - private void This_MouseClick (object sender, MouseEventEventArgs obj) { NewMouseEvent (obj.MouseEvent); } + private void This_MouseClick (object sender, MouseEventArgs obj) { NewMouseEvent (obj); } } public class ScrollViewTestWindow : Window @@ -310,9 +310,9 @@ private void Button_KeyPress (object sender, Key obj) } } - private void Button_MouseClick (object sender, MouseEventEventArgs obj) + private void Button_MouseClick (object sender, MouseEventArgs obj) { - if (obj.MouseEvent.Flags == MouseFlags.WheeledDown) + if (obj.Flags == MouseFlags.WheeledDown) { _scrollView.ContentOffset = new Point ( _scrollView.ContentOffset.X, @@ -320,7 +320,7 @@ private void Button_MouseClick (object sender, MouseEventEventArgs obj) ); obj.Handled = true; } - else if (obj.MouseEvent.Flags == MouseFlags.WheeledUp) + else if (obj.Flags == MouseFlags.WheeledUp) { _scrollView.ContentOffset = new Point ( _scrollView.ContentOffset.X, diff --git a/UICatalog/Scenarios/AdornmentsEditor.cs b/UICatalog/Scenarios/AdornmentsEditor.cs index 7bd6ec042c..d50714c5fc 100644 --- a/UICatalog/Scenarios/AdornmentsEditor.cs +++ b/UICatalog/Scenarios/AdornmentsEditor.cs @@ -108,7 +108,7 @@ private void NavigationOnFocusedChanged (object? sender, EventArgs e) ViewToEdit = Application.Navigation!.GetFocused (); } - private void ApplicationOnMouseEvent (object? sender, MouseEvent e) + private void ApplicationOnMouseEvent (object? sender, MouseEventArgs e) { if (e.Flags != MouseFlags.Button1Clicked || !AutoSelectViewToEdit) { diff --git a/UICatalog/Scenarios/ArrangementEditor.cs b/UICatalog/Scenarios/ArrangementEditor.cs index 13a48380d6..396c493d60 100644 --- a/UICatalog/Scenarios/ArrangementEditor.cs +++ b/UICatalog/Scenarios/ArrangementEditor.cs @@ -147,7 +147,7 @@ private void NavigationOnFocusedChanged (object? sender, EventArgs e) } } - private void ApplicationOnMouseEvent (object? sender, MouseEvent e) + private void ApplicationOnMouseEvent (object? sender, MouseEventArgs e) { if (e.Flags != MouseFlags.Button1Clicked || !AutoSelectViewToEdit) { diff --git a/UICatalog/Scenarios/Bars.cs b/UICatalog/Scenarios/Bars.cs index 63fdbd85f6..b0d2261486 100644 --- a/UICatalog/Scenarios/Bars.cs +++ b/UICatalog/Scenarios/Bars.cs @@ -187,12 +187,12 @@ void PopOverMenuOnAccept (object o, CommandEventArgs args) menuLikeExamples.MouseClick += MenuLikeExamplesMouseClick; - void MenuLikeExamplesMouseClick (object sender, MouseEventEventArgs e) + void MenuLikeExamplesMouseClick (object sender, MouseEventArgs e) { - if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + if (e.Flags.HasFlag (MouseFlags.Button3Clicked)) { - popOverMenu.X = e.MouseEvent.Position.X; - popOverMenu.Y = e.MouseEvent.Position.Y; + popOverMenu.X = e.Position.X; + popOverMenu.Y = e.Position.Y; popOverMenu.Visible = true; //popOverMenu.Enabled = popOverMenu.Visible; popOverMenu.SetFocus (); @@ -275,7 +275,7 @@ void MenuLikeExamplesMouseClick (object sender, MouseEventEventArgs e) //private void ShowContextMenu (object s, MouseEventEventArgs e) //{ - // if (e.MouseEvent.Flags != MouseFlags.Button3Clicked) + // if (e.Flags != MouseFlags.Button3Clicked) // { // return; // } @@ -283,8 +283,8 @@ void MenuLikeExamplesMouseClick (object sender, MouseEventEventArgs e) // var contextMenu = new Bar // { // Id = "contextMenu", - // X = e.MouseEvent.Position.X, - // Y = e.MouseEvent.Position.Y, + // X = e.Position.X, + // Y = e.Position.Y, // Width = Dim.Auto (DimAutoStyle.Content), // Height = Dim.Auto (DimAutoStyle.Content), // Orientation = Orientation.Vertical, @@ -387,7 +387,7 @@ void MenuLikeExamplesMouseClick (object sender, MouseEventEventArgs e) // contextMenu.Initialized += Menu_Initialized; - // void Application_MouseEvent (object sender, MouseEvent e) + // void Application_MouseEvent (object sender, MouseEventArgs e) // { // // If user clicks outside of the menuWindow, close it // if (!contextMenu.Frame.Contains (e.Position.X, e.Position.Y)) diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 5e246f9dfb..33c64d0038 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -98,9 +98,9 @@ public override void Main () // if user clicks the mouse in TableView _categoryList.MouseClick += (s, e) => { - _categoryList.ScreenToCell (e.MouseEvent.Position, out int? clickedCol); + _categoryList.ScreenToCell (e.Position, out int? clickedCol); - if (clickedCol != null && e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + if (clickedCol != null && e.Flags.HasFlag (MouseFlags.Button1Clicked)) { EnumerableTableSource table = (EnumerableTableSource)_categoryList.Table; string prevSelection = table.Data.ElementAt (_categoryList.SelectedRow).Category; @@ -527,9 +527,9 @@ public CharMap () Padding.Add (up, down, left, right); } - private void Handle_MouseEvent (object sender, MouseEventEventArgs e) + private void Handle_MouseEvent (object sender, MouseEventArgs e) { - if (e.MouseEvent.Flags == MouseFlags.WheeledDown) + if (e.Flags == MouseFlags.WheeledDown) { ScrollVertical (1); e.Handled = true; @@ -537,7 +537,7 @@ private void Handle_MouseEvent (object sender, MouseEventEventArgs e) return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledUp) + if (e.Flags == MouseFlags.WheeledUp) { ScrollVertical (-1); e.Handled = true; @@ -545,7 +545,7 @@ private void Handle_MouseEvent (object sender, MouseEventEventArgs e) return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledRight) + if (e.Flags == MouseFlags.WheeledRight) { ScrollHorizontal (1); e.Handled = true; @@ -553,7 +553,7 @@ private void Handle_MouseEvent (object sender, MouseEventEventArgs e) return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) + if (e.Flags == MouseFlags.WheeledLeft) { ScrollHorizontal (-1); e.Handled = true; @@ -839,10 +839,8 @@ public static string ToCamelCase (string str) private void CopyCodePoint () { Clipboard.Contents = $"U+{SelectedCodePoint:x5}"; } private void CopyGlyph () { Clipboard.Contents = $"{new Rune (SelectedCodePoint)}"; } - private void Handle_MouseClick (object sender, MouseEventEventArgs args) + private void Handle_MouseClick (object sender, MouseEventArgs me) { - MouseEvent me = args.MouseEvent; - if (me.Flags != MouseFlags.ReportMousePosition && me.Flags != MouseFlags.Button1Clicked && me.Flags != MouseFlags.Button1DoubleClicked) { return; @@ -883,7 +881,7 @@ private void Handle_MouseClick (object sender, MouseEventEventArgs args) SetFocus (); } - args.Handled = true; + me.Handled = true; if (me.Flags == MouseFlags.Button1Clicked) { diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs index 028717fcdc..b6986067ec 100644 --- a/UICatalog/Scenarios/ContentScrolling.cs +++ b/UICatalog/Scenarios/ContentScrolling.cs @@ -52,30 +52,30 @@ public ScrollingDemoView () MouseEvent += VirtualDemoView_MouseEvent; } - private void VirtualDemoView_MouseEvent (object sender, MouseEventEventArgs e) + private void VirtualDemoView_MouseEvent (object sender, MouseEventArgs e) { - if (e.MouseEvent.Flags == MouseFlags.WheeledDown) + if (e.Flags == MouseFlags.WheeledDown) { ScrollVertical (1); return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledUp) + if (e.Flags == MouseFlags.WheeledUp) { ScrollVertical (-1); return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledRight) + if (e.Flags == MouseFlags.WheeledRight) { ScrollHorizontal (1); return; } - if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) + if (e.Flags == MouseFlags.WheeledLeft) { ScrollHorizontal (-1); } diff --git a/UICatalog/Scenarios/ContextMenus.cs b/UICatalog/Scenarios/ContextMenus.cs index 816f80384b..63a207d69c 100644 --- a/UICatalog/Scenarios/ContextMenus.cs +++ b/UICatalog/Scenarios/ContextMenus.cs @@ -75,16 +75,16 @@ public override void Main () appWindow.MouseClick += (s, e) => { - if (e.MouseEvent.Flags == _contextMenu.MouseFlags) + if (e.Flags == _contextMenu.MouseFlags) { - ShowContextMenu (e.MouseEvent.Position.X, e.MouseEvent.Position.Y); + ShowContextMenu (e.Position.X, e.Position.Y); e.Handled = true; } }; Application.MouseEvent += ApplicationMouseEvent; - void ApplicationMouseEvent (object sender, MouseEvent a) { mousePos = a.Position; } + void ApplicationMouseEvent (object sender, MouseEventArgs a) { mousePos = a.Position; } appWindow.WantMousePositionReports = true; diff --git a/UICatalog/Scenarios/LineDrawing.cs b/UICatalog/Scenarios/LineDrawing.cs index d2fdb78007..38ea3bbfbb 100644 --- a/UICatalog/Scenarios/LineDrawing.cs +++ b/UICatalog/Scenarios/LineDrawing.cs @@ -8,7 +8,7 @@ namespace UICatalog.Scenarios; public interface ITool { - void OnMouseEvent (DrawingArea area, MouseEvent mouseEvent); + void OnMouseEvent (DrawingArea area, MouseEventArgs mouseEvent); } internal class DrawLineTool : ITool @@ -17,7 +17,7 @@ internal class DrawLineTool : ITool public LineStyle LineStyle { get; set; } = LineStyle.Single; /// - public void OnMouseEvent (DrawingArea area, MouseEvent mouseEvent) + public void OnMouseEvent (DrawingArea area, MouseEventArgs mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)) { @@ -96,6 +96,8 @@ public void OnMouseEvent (DrawingArea area, MouseEvent mouseEvent) area.SetNeedsDisplay (); } } + + mouseEvent.Handled = true; } } @@ -321,11 +323,11 @@ protected override bool OnKeyDown (Key e) return false; } - protected override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { CurrentTool.OnMouseEvent (this, mouseEvent); - return base.OnMouseEvent (mouseEvent); + return mouseEvent.Handled; } internal void AddLayer () @@ -429,7 +431,7 @@ public override void OnDrawContent (Rectangle viewport) } /// - protected override bool OnMouseEvent (MouseEvent mouseEvent) + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) { @@ -441,9 +443,11 @@ protected override bool OnMouseEvent (MouseEvent mouseEvent) { ClickedInBackground (); } + + mouseEvent.Handled = true; } - return base.OnMouseEvent (mouseEvent); + return mouseEvent.Handled; } private bool IsForegroundPoint (int x, int y) { return ForegroundPoints.Contains ((x, y)); } diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 6bd6dd4bea..05859bfbcd 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -248,7 +248,7 @@ public override void Main () }; // if user clicks the mouse in TableView - _listColView.MouseClick += (s, e) => { _listColView.ScreenToCell (e.MouseEvent.Position, out int? clickedCol); }; + _listColView.MouseClick += (s, e) => { _listColView.ScreenToCell (e.Position, out int? clickedCol); }; _listColView.KeyBindings.ReplaceCommands (Key.Space, Command.Accept); diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index 0b07c48e30..dd1a087895 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -251,18 +251,18 @@ void DemoPaddingOnInitialized (object o, EventArgs eventArgs) win.MouseEvent += (sender, a) => { - int i = filterSlider.Options.FindIndex (o => o.Data == a.MouseEvent.Flags); + int i = filterSlider.Options.FindIndex (o => o.Data == a.Flags); if (filterSlider.GetSetOptions ().Contains (i)) { - winLogList.Add ($"MouseEvent: ({a.MouseEvent.Position}) - {a.MouseEvent.Flags} {count++}"); + winLogList.Add ($"MouseEvent: ({a.Position}) - {a.Flags} {count++}"); winLog.MoveDown (); } }; win.MouseClick += (sender, a) => { - winLogList.Add ($"MouseClick: ({a.MouseEvent.Position}) - {a.MouseEvent.Flags} {count++}"); + winLogList.Add ($"MouseClick: ({a.Position}) - {a.Flags} {count++}"); winLog.MoveDown (); }; diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index d127f86109..c676eac239 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -752,16 +752,16 @@ public override void Main () return; } - _tableView.ScreenToCell (e.MouseEvent.Position, out int? clickedCol); + _tableView.ScreenToCell (e.Position, out int? clickedCol); if (clickedCol != null) { - if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) + if (e.Flags.HasFlag (MouseFlags.Button1Clicked)) { // left click in a header SortColumn (clickedCol.Value); } - else if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + else if (e.Flags.HasFlag (MouseFlags.Button3Clicked)) { // right click in a header ShowHeaderContextMenu (clickedCol.Value, e); @@ -1254,7 +1254,7 @@ private void ShowAllColumns () _tableView.Update (); } - private void ShowHeaderContextMenu (int clickedCol, MouseEventEventArgs e) + private void ShowHeaderContextMenu (int clickedCol, MouseEventArgs e) { if (HasCheckboxes () && clickedCol == 0) { @@ -1266,7 +1266,7 @@ private void ShowHeaderContextMenu (int clickedCol, MouseEventEventArgs e) var contextMenu = new ContextMenu { - Position = new (e.MouseEvent.Position.X + 1, e.MouseEvent.Position.Y + 1) + Position = new (e.Position.X + 1, e.Position.Y + 1) }; MenuBarItem menuItems = new ( diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 590af81b1c..6c46a79968 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -484,12 +484,12 @@ private void TreeViewFiles_KeyPress (object sender, Key obj) } } - private void TreeViewFiles_MouseClick (object sender, MouseEventEventArgs obj) + private void TreeViewFiles_MouseClick (object sender, MouseEventArgs obj) { // if user right clicks - if (obj.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) + if (obj.Flags.HasFlag (MouseFlags.Button3Clicked)) { - IFileSystemInfo rightClicked = _treeViewFiles.GetObjectOnRow (obj.MouseEvent.Position.Y); + IFileSystemInfo rightClicked = _treeViewFiles.GetObjectOnRow (obj.Position.Y); // nothing was clicked if (rightClicked == null) @@ -499,8 +499,8 @@ private void TreeViewFiles_MouseClick (object sender, MouseEventEventArgs obj) ShowContextMenu ( new Point ( - obj.MouseEvent.Position.X + _treeViewFiles.Frame.X, - obj.MouseEvent.Position.Y + _treeViewFiles.Frame.Y + 2 + obj.Position.X + _treeViewFiles.Frame.X, + obj.Position.Y + _treeViewFiles.Frame.Y + 2 ), rightClicked ); diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 81209dddb7..215e7e050f 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -856,7 +856,7 @@ public void Run_Toplevel_With_Modal_View_Does_Not_Refresh_If_Not_Dirty () } else if (iteration < 3) { - Application.OnMouseEvent (new () { Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { Flags = MouseFlags.ReportMousePosition }); Assert.False (top.NeedsDisplay); Assert.False (top.SubViewNeedsDisplay); Assert.False (top.LayoutNeeded); @@ -895,12 +895,12 @@ public void Run_A_Modal_Toplevel_Refresh_Background_On_Moving () // Don't use visuals to test as style of border can change over time. Assert.Equal (new (0, 0), w.Frame.Location); - Application.OnMouseEvent (new () { Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed }); Assert.Equal (w.Border, Application.MouseGrabView); Assert.Equal (new (0, 0), w.Frame.Location); // Move down and to the right. - Application.OnMouseEvent (new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); Assert.Equal (new (1, 1), w.Frame.Location); Application.End (rs); diff --git a/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs b/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs index f1d0a78477..60eb8b25eb 100644 --- a/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs +++ b/UnitTests/Application/Mouse/ApplicationMouseEnterLeaveTests.cs @@ -47,7 +47,7 @@ public void RaiseMouseEnterLeaveEvents_MouseEntersView_CallsOnMouseEnter () var mousePosition = new Point (1, 1); List currentViewsUnderMouse = new () { view }; - var mouseEvent = new MouseEvent + var mouseEvent = new MouseEventArgs { Position = mousePosition, ScreenPosition = mousePosition @@ -80,7 +80,7 @@ public void RaiseMouseEnterLeaveEvents_MouseLeavesView_CallsOnMouseLeave () Application.Top.Add (view); var mousePosition = new Point (0, 0); List currentViewsUnderMouse = new (); - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); Application._cachedViewsUnderMouse.Clear (); Application._cachedViewsUnderMouse.Add (view); @@ -203,7 +203,7 @@ public void RaiseMouseEnterLeaveEvents_NoViewsUnderMouse_DoesNotCallOnMouseEnter Application.Top.Add (view); var mousePosition = new Point (0, 0); List currentViewsUnderMouse = new (); - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); Application._cachedViewsUnderMouse.Clear (); diff --git a/UnitTests/Application/Mouse/ApplicationMouseTests.cs b/UnitTests/Application/Mouse/ApplicationMouseTests.cs index c5a86a85cd..64000649d3 100644 --- a/UnitTests/Application/Mouse/ApplicationMouseTests.cs +++ b/UnitTests/Application/Mouse/ApplicationMouseTests.cs @@ -42,10 +42,10 @@ public void MouseEventCoordinatesAreScreenRelative ( bool expectedClicked ) { - var mouseEvent = new MouseEvent { ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Pressed }; + var mouseEvent = new MouseEventArgs { ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Pressed }; var clicked = false; - void OnApplicationOnMouseEvent (object s, MouseEvent e) + void OnApplicationOnMouseEvent (object s, MouseEventArgs e) { Assert.Equal (expectedX, e.ScreenPosition.X); Assert.Equal (expectedY, e.ScreenPosition.Y); @@ -54,7 +54,7 @@ void OnApplicationOnMouseEvent (object s, MouseEvent e) Application.MouseEvent += OnApplicationOnMouseEvent; - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (expectedClicked, clicked); Application.MouseEvent -= OnApplicationOnMouseEvent; } @@ -116,12 +116,12 @@ bool expectedClicked Height = size.Height }; - var mouseEvent = new MouseEvent { ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Clicked }; + var mouseEvent = new MouseEventArgs { ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Clicked }; view.MouseClick += (s, e) => { - Assert.Equal (expectedX, e.MouseEvent.Position.X); - Assert.Equal (expectedY, e.MouseEvent.Position.Y); + Assert.Equal (expectedX, e.Position.X); + Assert.Equal (expectedY, e.Position.Y); clicked = true; }; @@ -129,7 +129,7 @@ bool expectedClicked top.Add (view); Application.Begin (top); - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (expectedClicked, clicked); top.Dispose (); } @@ -218,16 +218,16 @@ bool expectedClicked Application.Top.Add (view); - var mouseEvent = new MouseEvent { Position = new (clickX, clickY), ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Clicked }; + var mouseEvent = new MouseEventArgs { Position = new (clickX, clickY), ScreenPosition = new (clickX, clickY), Flags = MouseFlags.Button1Clicked }; view.MouseClick += (s, e) => { - Assert.Equal (expectedX, e.MouseEvent.Position.X); - Assert.Equal (expectedY, e.MouseEvent.Position.Y); + Assert.Equal (expectedX, e.Position.X); + Assert.Equal (expectedY, e.Position.Y); clicked = true; }; - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (expectedClicked, clicked); Application.Top.Dispose (); Application.ResetState (ignoreDisposed: true); @@ -261,7 +261,7 @@ public void MouseGrabView_WithNullMouseEventView () Assert.True (tf.HasFocus); Assert.Null (Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition }); Assert.Equal (sv, Application.MouseGrabView); @@ -275,15 +275,15 @@ public void MouseGrabView_WithNullMouseEventView () // another toplevel (Dialog) was opened Assert.Null (Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition }); Assert.Null (Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (40, 12), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (40, 12), Flags = MouseFlags.ReportMousePosition }); Assert.Null (Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); Assert.Null (Application.MouseGrabView); @@ -402,7 +402,7 @@ public void View_Is_Responsible_For_Calling_UnGrabMouse_Before_Being_Disposed () Assert.True (view.WasDisposed); #endif - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); Assert.Null (Application.MouseGrabView); Assert.Equal (0, count); top.Dispose (); diff --git a/UnitTests/Input/EscSeqUtilsTests.cs b/UnitTests/Input/EscSeqUtilsTests.cs index 3ac8e4c601..9b811f0026 100644 --- a/UnitTests/Input/EscSeqUtilsTests.cs +++ b/UnitTests/Input/EscSeqUtilsTests.cs @@ -696,7 +696,7 @@ public void DecodeEscSeq_Tests () top.Add (view); Application.Begin (top); - Application.OnMouseEvent (new() { Position = new (0, 0), Flags = 0 }); + Application.RaiseMouseEvent (new() { Position = new (0, 0), Flags = 0 }); ClearAll (); @@ -753,7 +753,7 @@ public void DecodeEscSeq_Tests () // set Application.WantContinuousButtonPressedView to null view.WantContinuousButtonPressed = false; - Application.OnMouseEvent (new() { Position = new (0, 0), Flags = 0 }); + Application.RaiseMouseEvent (new() { Position = new (0, 0), Flags = 0 }); Application.RequestStop (); } diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index cac5c549ef..183e068857 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -234,7 +234,7 @@ public void New_Methods_Return_False () //Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown })); Assert.False (r.NewKeyDownEvent (new Key { KeyCode = KeyCode.Null })); Assert.False (r.NewKeyDownEvent (new Key { KeyCode = KeyCode.Null })); - Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); + Assert.False (r.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.AllEvents })); var v = new View (); //Assert.False (r.OnEnter (v)); diff --git a/UnitTests/View/Mouse/MouseEnterLeaveTests.cs b/UnitTests/View/Mouse/MouseEnterLeaveTests.cs index 28c002ebab..e91154c5d5 100644 --- a/UnitTests/View/Mouse/MouseEnterLeaveTests.cs +++ b/UnitTests/View/Mouse/MouseEnterLeaveTests.cs @@ -63,7 +63,7 @@ public void NewMouseEnterEvent_ViewIsEnabledAndVisible_CallsOnMouseEnter () Visible = true }; - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); var eventArgs = new CancelEventArgs (); @@ -136,7 +136,7 @@ public void NewMouseLeaveEvent_ViewIsVisible_CallsOnMouseLeave () Enabled = true, Visible = true }; - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); // Act view.NewMouseLeaveEvent (); @@ -159,7 +159,7 @@ public void NewMouseLeaveEvent_ViewIsNotVisible_CallsOnMouseLeave () Visible = false }; - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); // Act view.NewMouseLeaveEvent (); @@ -256,7 +256,7 @@ public void NewMouseLeaveEvent_ViewIsVisible_RaisesMouseLeave () Visible = true }; - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); // Act view.NewMouseLeaveEvent (); @@ -279,7 +279,7 @@ public void NewMouseLeaveEvent_ViewIsNotVisible_RaisesMouseLeave () Visible = false }; - var mouseEvent = new MouseEvent (); + var mouseEvent = new MouseEventArgs (); // Act view.NewMouseLeaveEvent (); diff --git a/UnitTests/View/Mouse/MouseTests.cs b/UnitTests/View/Mouse/MouseTests.cs index 8c021e3c4c..c4b10fe956 100644 --- a/UnitTests/View/Mouse/MouseTests.cs +++ b/UnitTests/View/Mouse/MouseTests.cs @@ -106,9 +106,9 @@ public void ButtonPressed_In_Border_Starts_Drag (int marginThickness, int border Application.Begin (top); Assert.Equal (new Point (4, 4), testView.Frame.Location); - Application.OnMouseEvent (new () { ScreenPosition = new (xy, xy), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (xy, xy), Flags = MouseFlags.Button1Pressed }); - Application.OnMouseEvent (new () { ScreenPosition = new (xy + 1, xy + 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (xy + 1, xy + 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); Assert.Equal (expectedMoved, new Point (5, 5) == testView.Frame.Location); top.Dispose (); @@ -121,9 +121,9 @@ public void WheeledLeft_WheeledRight (MouseFlags mouseFlags, MouseFlags expected { MouseFlags mouseFlagsFromEvent = MouseFlags.None; var view = new View (); - view.MouseEvent += (s, e) => mouseFlagsFromEvent = e.MouseEvent.Flags; + view.MouseEvent += (s, e) => mouseFlagsFromEvent = e.Flags; - view.NewMouseEvent (new MouseEvent () { Flags = mouseFlags }); + view.NewMouseEvent (new MouseEventArgs () { Flags = mouseFlags }); Assert.Equal (mouseFlagsFromEvent, expectedMouseFlagsFromEvent); } @@ -142,7 +142,7 @@ public void NewMouseEvent_Invokes_MouseEvent_Properly () e.Handled = true; }; - MouseEvent me = new (); + MouseEventArgs me = new (); view.NewMouseEvent (me); Assert.True (mouseEventInvoked); Assert.True (me.Handled); @@ -163,7 +163,7 @@ public void AllViews_NewMouseEvent_Enabled_False_Does_Not_Set_Handled (Type view } view.Enabled = false; - var me = new MouseEvent (); + var me = new MouseEventArgs (); view.NewMouseEvent (me); Assert.False (me.Handled); view.Dispose (); @@ -182,7 +182,7 @@ public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (T } view.Enabled = false; - var me = new MouseEvent () + var me = new MouseEventArgs () { Flags = MouseFlags.Button1Clicked }; @@ -198,7 +198,7 @@ public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (T [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released, MouseFlags.Button4Clicked)] public void WantContinuousButtonPressed_False_Button_Press_Release_DoesNotClick (MouseFlags pressed, MouseFlags released, MouseFlags clicked) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -241,7 +241,7 @@ public void WantContinuousButtonPressed_False_Button_Press_Release_DoesNotClick [InlineData (MouseFlags.Button4Clicked)] public void WantContinuousButtonPressed_True_Button_Clicked_Raises_MouseClick (MouseFlags clicked) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -269,7 +269,7 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_MouseClick (M [InlineData (MouseFlags.Button4Clicked)] public void WantContinuousButtonPressed_True_Button_Clicked_Raises_Selecting (MouseFlags clicked) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -296,7 +296,7 @@ public void WantContinuousButtonPressed_True_Button_Clicked_Raises_Selecting (Mo [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released)] public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Button_Press_Release_Clicks (MouseFlags pressed, MouseFlags released) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -310,9 +310,15 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B view.MouseClick += (s, e) => clickedCount++; + me.Flags = pressed; + view.NewMouseEvent (me); + Assert.Equal (0, clickedCount); + me.Handled = false; + me.Flags = pressed; view.NewMouseEvent (me); Assert.Equal (1, clickedCount); + me.Handled = false; me.Flags = released; view.NewMouseEvent (me); @@ -328,7 +334,7 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released, MouseFlags.Button4Clicked)] public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Button_Press_Release_Clicks_Repeatedly (MouseFlags pressed, MouseFlags released, MouseFlags clicked) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -344,22 +350,22 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B me.Flags = pressed; view.NewMouseEvent (me); - Assert.Equal (1, clickedCount); + Assert.Equal (0, clickedCount); me.Handled = false; me.Flags = pressed; view.NewMouseEvent (me); - Assert.Equal (2, clickedCount); + Assert.Equal (1, clickedCount); me.Handled = false; me.Flags = released; view.NewMouseEvent (me); - Assert.Equal (2, clickedCount); + Assert.Equal (1, clickedCount); me.Handled = false; me.Flags = clicked; view.NewMouseEvent (me); - Assert.Equal (2, clickedCount); + Assert.Equal (1, clickedCount); view.Dispose (); Application.ResetState (ignoreDisposed: true); @@ -368,7 +374,7 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_B [Fact] public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Move_InViewport_OutOfViewport_Keeps_Counting () { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var view = new View () { @@ -386,21 +392,21 @@ public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_M me.Flags = MouseFlags.Button1Pressed; me.Position = me.Position with { X = 0 }; view.NewMouseEvent (me); - Assert.Equal (1, clickedCount); + Assert.Equal (0, clickedCount); me.Handled = false; // Move out of Viewport me.Flags = MouseFlags.Button1Pressed; me.Position = me.Position with { X = 1 }; view.NewMouseEvent (me); - Assert.Equal (2, clickedCount); + Assert.Equal (1, clickedCount); me.Handled = false; // Move into Viewport me.Flags = MouseFlags.Button1Pressed; me.Position = me.Position with { X = 0 }; view.NewMouseEvent (me); - Assert.Equal (3, clickedCount); + Assert.Equal (2, clickedCount); me.Handled = false; view.Dispose (); diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index e4b4f7efd7..1029acfd68 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -599,7 +599,7 @@ public void Update_Parameterless_Only_On_Or_After_Initialize () [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released, MouseFlags.Button4Clicked)] public void WantContinuousButtonPressed_True_ButtonClick_Accepts (MouseFlags pressed, MouseFlags released, MouseFlags clicked) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var button = new Button () { @@ -618,19 +618,19 @@ public void WantContinuousButtonPressed_True_ButtonClick_Accepts (MouseFlags pre e.Cancel = true; }; - me = new MouseEvent (); + me = new MouseEventArgs (); me.Flags = pressed; button.NewMouseEvent (me); Assert.Equal (0, selectingCount); Assert.Equal (0, acceptedCount); - me = new MouseEvent (); + me = new MouseEventArgs (); me.Flags = released; button.NewMouseEvent (me); Assert.Equal (0, selectingCount); Assert.Equal (0, acceptedCount); - me = new MouseEvent (); + me = new MouseEventArgs (); me.Flags = clicked; button.NewMouseEvent (me); Assert.Equal (1, selectingCount); @@ -646,7 +646,7 @@ public void WantContinuousButtonPressed_True_ButtonClick_Accepts (MouseFlags pre [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released)] public void WantContinuousButtonPressed_True_ButtonPressRelease_Does_Not_Raise_Selected_Or_Accepted (MouseFlags pressed, MouseFlags released) { - var me = new MouseEvent (); + var me = new MouseEventArgs (); var button = new Button () { diff --git a/UnitTests/Views/ColorPickerTests.cs b/UnitTests/Views/ColorPickerTests.cs index 57f4144c9d..754e9e206f 100644 --- a/UnitTests/Views/ColorPickerTests.cs +++ b/UnitTests/Views/ColorPickerTests.cs @@ -120,7 +120,7 @@ public void ColorPicker_RGB_MouseNavigation () Assert.IsAssignableFrom (cp.Focused); - cp.Focused.OnMouseEvent ( + cp.Focused.RaiseMouseEvent ( new () { Flags = MouseFlags.Button1Pressed, @@ -132,7 +132,7 @@ public void ColorPicker_RGB_MouseNavigation () Assert.Equal (3, r.TrianglePosition); Assert.Equal ("#0F0000", hex.Text); - cp.Focused.OnMouseEvent ( + cp.Focused.RaiseMouseEvent ( new () { Flags = MouseFlags.Button1Pressed, @@ -269,7 +269,7 @@ public void ColorPicker_ClickingAtEndOfBar_SetsMaxValue () cp.Draw (); // Click at the end of the Red bar - cp.Focused.OnMouseEvent ( + cp.Focused.RaiseMouseEvent ( new () { Flags = MouseFlags.Button1Pressed, @@ -303,7 +303,7 @@ public void ColorPicker_ClickingBeyondBar_ChangesToMaxValue () cp.Draw (); // Click beyond the bar - cp.Focused.OnMouseEvent ( + cp.Focused.RaiseMouseEvent ( new () { Flags = MouseFlags.Button1Pressed, @@ -434,7 +434,7 @@ public void ColorPicker_ClickingDifferentBars_ChangesFocus () cp.Draw (); // Click on Green bar - Application.OnMouseEvent (new () + Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed, ScreenPosition = new (0, 1) @@ -453,7 +453,7 @@ public void ColorPicker_ClickingDifferentBars_ChangesFocus () Assert.IsAssignableFrom (cp.Focused); // Click on Blue bar - Application.OnMouseEvent (new () + Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed, ScreenPosition = new (0, 2) diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index 99a0576a04..afc435ca49 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -137,7 +137,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_Cu Assert.Equal (-1, cb.SelectedItem); Assert.Equal ("", cb.Text); - Assert.True (cb.NewMouseEvent (new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed })); + Assert.True (cb.NewMouseEvent (new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed })); Assert.Equal ("", selected); Assert.True (cb.IsShow); Assert.Equal (0, cb.SelectedItem); @@ -193,7 +193,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -231,7 +231,7 @@ public void Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -289,7 +289,7 @@ public void HideDropdownListOnClick_Gets_Sets () Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -300,7 +300,7 @@ public void HideDropdownListOnClick_Gets_Sets () Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -311,7 +311,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -324,7 +324,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("Three", selected); @@ -334,14 +334,14 @@ cb.Subviews [1] Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, 2), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("Three", selected); @@ -351,7 +351,7 @@ cb.Subviews [1] Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("Three", selected); @@ -362,7 +362,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("One", selected); @@ -391,14 +391,14 @@ public void HideDropdownListOnClick_True_Colapse_On_Click_Outside_Frame () Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -409,7 +409,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (-1, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (-1, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -422,7 +422,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -433,7 +433,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, -1), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, -1), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -446,7 +446,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -457,7 +457,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (cb.Frame.Width, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (cb.Frame.Width, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -470,7 +470,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -481,7 +481,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .NewMouseEvent ( - new MouseEvent { Position = new (0, cb.Frame.Height), Flags = MouseFlags.Button1Clicked } + new MouseEventArgs { Position = new (0, cb.Frame.Height), Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -515,7 +515,7 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -673,7 +673,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -685,7 +685,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -695,7 +695,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -707,7 +707,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -736,7 +736,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_Cur Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -794,7 +794,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.NewMouseEvent ( - new MouseEvent { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } + new MouseEventArgs { Position = new (cb.Viewport.Right - 1, 0), Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index 3a84d3b566..1bd08ed724 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -115,11 +115,11 @@ public void ContextMenu_Is_Closed_If_Another_MenuBar_Is_Open_Or_Vice_Versa () Assert.True (ContextMenu.IsShow); Assert.Equal (cm.MenuBar, Application.MouseGrabView); Assert.False (menu.IsMenuOpen); - Assert.False (menu.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.ReportMousePosition, View = menu })); + Assert.False (menu.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.ReportMousePosition, View = menu })); Assert.True (ContextMenu.IsShow); Assert.Equal (cm.MenuBar, Application.MouseGrabView); Assert.False (menu.IsMenuOpen); - Assert.True (menu.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1Clicked, View = menu })); + Assert.True (menu.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1Clicked, View = menu })); Assert.False (ContextMenu.IsShow); Assert.Equal (menu, Application.MouseGrabView); Assert.True (menu.IsMenuOpen); @@ -148,7 +148,7 @@ public void Draw_A_ContextMenu_Over_A_Borderless_Top () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (8, 2), Flags = MouseFlags.Button3Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (8, 2), Flags = MouseFlags.Button3Clicked }); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -231,7 +231,7 @@ public void Draw_A_ContextMenu_Over_A_Dialog () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (9, 3), Flags = MouseFlags.Button3Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (9, 3), Flags = MouseFlags.Button3Clicked }); var firstIteration = false; Application.RunIteration (ref rsDialog, ref firstIteration); @@ -287,7 +287,7 @@ public void Draw_A_ContextMenu_Over_A_Top_Dialog () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (9, 3), Flags = MouseFlags.Button3Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (9, 3), Flags = MouseFlags.Button3Clicked }); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -532,7 +532,7 @@ public void Menus_And_SubMenus_Always_Try_To_Be_On_Screen () Assert.True ( top.Subviews [0] .NewMouseEvent ( - new MouseEvent { Position = new (0, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } ) ); Application.Refresh (); @@ -580,7 +580,7 @@ top.Subviews [0] Assert.True ( top.Subviews [0] .NewMouseEvent ( - new MouseEvent { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } ) ); Application.Refresh (); @@ -627,7 +627,7 @@ top.Subviews [0] Assert.True ( top.Subviews [0] .NewMouseEvent ( - new MouseEvent { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } ) ); Application.Refresh (); @@ -671,7 +671,7 @@ top.Subviews [0] Assert.True ( top.Subviews [0] .NewMouseEvent ( - new MouseEvent { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } ) ); Application.Refresh (); @@ -715,7 +715,7 @@ top.Subviews [0] Assert.True ( top.Subviews [0] .NewMouseEvent ( - new MouseEvent { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } + new MouseEventArgs { Position = new (30, 3), Flags = MouseFlags.ReportMousePosition, View = top.Subviews [0] } ) ); Application.Refresh (); @@ -747,7 +747,7 @@ public void MouseFlags_Changing () lbl.MouseClick += (s, e) => { - if (e.MouseEvent.Flags == cm.MouseFlags) + if (e.Flags == cm.MouseFlags) { lbl.Text = "Replaced"; e.Handled = true; @@ -758,12 +758,12 @@ public void MouseFlags_Changing () top.Add (lbl); Application.Begin (top); - Assert.True (lbl.NewMouseEvent (new MouseEvent { Flags = cm.MouseFlags })); + Assert.True (lbl.NewMouseEvent (new MouseEventArgs { Flags = cm.MouseFlags })); Assert.Equal ("Replaced", lbl.Text); lbl.Text = "Original"; cm.MouseFlags = MouseFlags.Button2Clicked; - Assert.True (lbl.NewMouseEvent (new MouseEvent { Flags = cm.MouseFlags })); + Assert.True (lbl.NewMouseEvent (new MouseEventArgs { Flags = cm.MouseFlags })); Assert.Equal ("Replaced", lbl.Text); top.Dispose (); } @@ -1235,7 +1235,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () ); // X=5 is the border and so need to use at least one more - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (6, 13), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (6, 13), Flags = MouseFlags.Button1Clicked }); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -1253,7 +1253,7 @@ public void UseSubMenusSingleFrame_True_By_Mouse () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (6, 12), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (6, 12), Flags = MouseFlags.Button1Clicked }); firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -1327,7 +1327,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (6, 13), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (6, 13), Flags = MouseFlags.ReportMousePosition }); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -1344,7 +1344,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (6, 14), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (6, 14), Flags = MouseFlags.ReportMousePosition }); firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -1362,7 +1362,7 @@ public void UseSubMenusSingleFrame_False_By_Mouse () output ); - Application.OnMouseEvent (new MouseEvent { ScreenPosition = new (6, 13), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new MouseEventArgs { ScreenPosition = new (6, 13), Flags = MouseFlags.ReportMousePosition }); firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -1399,7 +1399,7 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Assert.Empty (Application._cachedViewsUnderMouse); // Right click on tf2 to open context menu - Application.OnMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button3Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button3Clicked }); Assert.False (tf1.HasFocus); Assert.False (tf2.HasFocus); Assert.Equal (5, win.Subviews.Count); @@ -1409,7 +1409,7 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Assert.Equal (tf2, Application._cachedViewsUnderMouse.LastOrDefault ()); // Click on tf1 to focus it, which cause context menu being closed - Application.OnMouseEvent (new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Clicked }); Assert.True (tf1.HasFocus); Assert.False (tf2.HasFocus); Assert.Equal (4, win.Subviews.Count); @@ -1421,7 +1421,7 @@ public void Handling_TextField_With_Opened_ContextMenu_By_Mouse_HasFocus () Assert.Equal (tf1, Application._cachedViewsUnderMouse.LastOrDefault ()); // Click on tf2 to focus it - Application.OnMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked }); Assert.False (tf1.HasFocus); Assert.True (tf2.HasFocus); Assert.Equal (4, win.Subviews.Count); diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index 2eb73d34fd..80f1e2b7cb 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -1364,7 +1364,7 @@ public void CanFocus_False_MouseClick_SetsFocus_Next () Application.Top.SetFocus (); // click on label - Application.OnMouseEvent (new () { ScreenPosition = label.Frame.Location, Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = label.Frame.Location, Flags = MouseFlags.Button1Clicked }); Assert.False (label.HasFocus); Assert.True (nextView.HasFocus); @@ -1442,12 +1442,12 @@ public void CanFocus_True_MouseClick_Focuses () Assert.True (otherView.HasFocus); // label can focus, so clicking on it set focus - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Clicked }); Assert.True (label.HasFocus); Assert.False (otherView.HasFocus); // click on view - Application.OnMouseEvent (new () { ScreenPosition = new (0, 1), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 1), Flags = MouseFlags.Button1Clicked }); Assert.False (label.HasFocus); Assert.True (otherView.HasFocus); diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 3da369db1b..1f5553c2c8 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -737,11 +737,11 @@ public void Clicking_On_Border_Is_Ignored () └─────┘", output); - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Clicked }); Assert.Equal ("", selected); Assert.Equal (-1, lv.SelectedItem); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Clicked @@ -749,7 +749,7 @@ public void Clicking_On_Border_Is_Ignored () Assert.Equal ("One", selected); Assert.Equal (0, lv.SelectedItem); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (1, 2), Flags = MouseFlags.Button1Clicked @@ -757,7 +757,7 @@ public void Clicking_On_Border_Is_Ignored () Assert.Equal ("Two", selected); Assert.Equal (1, lv.SelectedItem); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked @@ -765,7 +765,7 @@ public void Clicking_On_Border_Is_Ignored () Assert.Equal ("Three", selected); Assert.Equal (2, lv.SelectedItem); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (1, 4), Flags = MouseFlags.Button1Clicked diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index 938001fe14..7ef68bfe21 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -243,7 +243,7 @@ public void Click_Another_View_Close_An_Open_Menu () top.Add (menu, btn); Application.Begin (top); - Application.OnMouseEvent (new () { ScreenPosition = new (0, 4), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 4), Flags = MouseFlags.Button1Clicked }); Assert.True (btnClicked); top.Dispose (); } @@ -613,7 +613,7 @@ void ChangeMenuTitle (string title) output ); - Application.OnMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); firstIteration = false; @@ -646,7 +646,7 @@ void ChangeMenuTitle (string title) { menu.OpenMenu (); - Application.OnMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); firstIteration = false; Application.RunIteration (ref rsDialog, ref firstIteration); @@ -809,7 +809,7 @@ void ChangeMenuTitle (string title) output ); - Application.OnMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); firstIteration = false; @@ -831,7 +831,7 @@ void ChangeMenuTitle (string title) { menu.OpenMenu (); - Application.OnMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 989962d00f..51ce8d9651 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1176,7 +1176,7 @@ This is a test _output ); - Application.OnMouseEvent (new MouseEvent { Position = new (15, 0), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { Position = new (15, 0), Flags = MouseFlags.Button1Clicked }); Assert.Null (Application.MouseGrabView); Assert.True (clicked); @@ -1200,7 +1200,7 @@ This is a test _output ); - Application.OnMouseEvent (new MouseEvent { Position = new (15, 0), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new MouseEventArgs { Position = new (15, 0), Flags = MouseFlags.Button1Clicked }); Assert.Null (Application.MouseGrabView); Assert.True (clicked); diff --git a/UnitTests/Views/ShortcutTests.cs b/UnitTests/Views/ShortcutTests.cs index 711ce243fe..160f574397 100644 --- a/UnitTests/Views/ShortcutTests.cs +++ b/UnitTests/Views/ShortcutTests.cs @@ -424,7 +424,7 @@ public void MouseClick_Raises_Accepted (int x, int expectedAccepted) var accepted = 0; shortcut.Accepting += (s, e) => accepted++; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (x, 0), @@ -484,7 +484,7 @@ int expectedShortcutSelected Application.Top.SetRelativeLayout (new (100, 100)); Application.Top.LayoutSubviews (); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (mouseX, 0), @@ -541,7 +541,7 @@ public void MouseClick_Button_CommandView_Raises_Shortcut_Accepted (int mouseX, var accepted = 0; shortcut.Accepting += (s, e) => { accepted++; }; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (mouseX, 0), @@ -616,7 +616,7 @@ public void MouseClick_CheckBox_CommandView_Raises_Shortcut_Accepted_Selected_Co e.Cancel = true; }; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (mouseX, 0), diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index dd1d3546d1..037f106e41 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -138,27 +138,27 @@ public void MouseClick_ChangesTab () top.Add (tv); Application.Begin (top); - MouseEvent args; + MouseEventArgs args; // Waving mouse around does not trigger click for (var i = 0; i < 100; i++) { args = new () { ScreenPosition = new (i, 1), Flags = MouseFlags.ReportMousePosition }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Null (clicked); Assert.Equal (tab1, tv.SelectedTab); } args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Equal (tab1, clicked); Assert.Equal (tab1, tv.SelectedTab); // Click to tab2 args = new () { ScreenPosition = new (6, 1), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Equal (tab2, clicked); Assert.Equal (tab2, tv.SelectedTab); @@ -171,7 +171,7 @@ public void MouseClick_ChangesTab () }; args = new () { ScreenPosition = new (3, 1), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); // Tab 1 was clicked but event handler blocked navigation @@ -179,7 +179,7 @@ public void MouseClick_ChangesTab () Assert.Equal (tab2, tv.SelectedTab); args = new () { ScreenPosition = new (12, 1), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); // Clicking beyond last tab should raise event with null Tab @@ -233,8 +233,8 @@ public void MouseClick_Right_Left_Arrows_ChangesTab () Application.Begin (top); // Click the right arrow - var args = new MouseEvent { ScreenPosition = new (6, 2), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + var args = new MouseEventArgs { ScreenPosition = new (6, 2), Flags = MouseFlags.Button1Clicked }; + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Null (clicked); Assert.Equal (tab1, oldChanged); @@ -254,7 +254,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab () // Click the left arrow args = new () { ScreenPosition = new (0, 2), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Null (clicked); Assert.Equal (tab2, oldChanged); @@ -324,8 +324,8 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () Application.Begin (top); // Click the right arrow - var args = new MouseEvent { ScreenPosition = new (7, 3), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + var args = new MouseEventArgs { ScreenPosition = new (7, 3), Flags = MouseFlags.Button1Clicked }; + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Null (clicked); Assert.Equal (tab1, oldChanged); @@ -347,7 +347,7 @@ public void MouseClick_Right_Left_Arrows_ChangesTab_With_Border () // Click the left arrow args = new () { ScreenPosition = new (1, 3), Flags = MouseFlags.Button1Clicked }; - Application.OnMouseEvent (args); + Application.RaiseMouseEvent (args); Application.Refresh (); Assert.Null (clicked); Assert.Equal (tab2, oldChanged); diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 0de972262d..478e1d00b6 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1178,15 +1178,15 @@ public void MouseEvent_Handled_Prevents_RightClick () top.Add (tf); Application.Begin (top); - var mouseEvent = new MouseEvent { Flags = MouseFlags.Button1Clicked, View = tf }; + var mouseEvent = new MouseEventArgs { Flags = MouseFlags.Button1Clicked, View = tf }; - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (1, clickCounter); // Get a fresh instance that represents a right click. // Should be ignored because of SuppressRightClick callback mouseEvent = new () { Flags = MouseFlags.Button3Clicked, View = tf }; - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (1, clickCounter); Application.MouseEvent -= HandleRightClick; @@ -1199,13 +1199,13 @@ public void MouseEvent_Handled_Prevents_RightClick () // This call causes the context menu to pop, and MouseEvent() returns true. // Thus, the clickCounter is NOT incremented. // Which is correct, because the user did NOT click with the left mouse button. - Application.OnMouseEvent (mouseEvent); + Application.RaiseMouseEvent (mouseEvent); Assert.Equal (1, clickCounter); top.Dispose (); return; - void HandleRightClick (object sender, MouseEvent arg) + void HandleRightClick (object sender, MouseEventArgs arg) { if (arg.Flags.HasFlag (MouseFlags.Button3Clicked)) { @@ -1293,7 +1293,7 @@ public void SpaceHandling () { var tf = new TextField { Width = 10, Text = " " }; - var ev = new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked }; + var ev = new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked }; tf.NewMouseEvent (ev); Assert.Equal (1, tf.SelectedLength); diff --git a/UnitTests/Views/TextValidateFieldTests.cs b/UnitTests/Views/TextValidateFieldTests.cs index 96a0d6d17b..35258bb427 100644 --- a/UnitTests/Views/TextValidateFieldTests.cs +++ b/UnitTests/Views/TextValidateFieldTests.cs @@ -322,7 +322,7 @@ public void MouseClick_Right_X_Greater_Than_Text_Width_Goes_To_Last_Editable_Pos Assert.False (field.IsValid); Assert.Equal ("--(1 )--", field.Provider.Text); - field.NewMouseEvent (new MouseEvent { Position = new (25, 0), Flags = MouseFlags.Button1Pressed }); + field.NewMouseEvent (new MouseEventArgs { Position = new (25, 0), Flags = MouseFlags.Button1Pressed }); field.NewKeyDownEvent (Key.D1); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index a912064f6d..7dc1f98586 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -130,7 +130,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () Assert.False (fv.CanFocus); Assert.False (fv.HasFocus); - tv.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Empty (tv.SelectedText); Assert.False (tv.CanFocus); @@ -140,7 +140,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () fv.CanFocus = true; tv.CanFocus = true; - tv.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Equal ("some ", tv.SelectedText); Assert.True (tv.CanFocus); @@ -149,7 +149,7 @@ public void CanFocus_False_Wont_Focus_With_Mouse () Assert.True (fv.HasFocus); fv.CanFocus = false; - tv.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }); Assert.Equal ("some ", tv.SelectedText); // Setting CanFocus to false don't change the SelectedText Assert.True (tv.CanFocus); // v2: CanFocus is not longer automatically changed @@ -1025,7 +1025,7 @@ public void DesiredCursorVisibility_Horizontal_Navigation () for (var i = 0; i < 12; i++) { - tv.NewMouseEvent (new MouseEvent { Flags = MouseFlags.WheeledRight }); + tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledRight }); Assert.Equal (Math.Min (i + 1, 11), tv.LeftColumn); Application.PositionCursor (); Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility); @@ -1034,7 +1034,7 @@ public void DesiredCursorVisibility_Horizontal_Navigation () for (var i = 11; i > 0; i--) { - tv.NewMouseEvent (new MouseEvent { Flags = MouseFlags.WheeledLeft }); + tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledLeft }); Assert.Equal (i - 1, tv.LeftColumn); Application.PositionCursor (); @@ -1077,7 +1077,7 @@ public void DesiredCursorVisibility_Vertical_Navigation () for (var i = 0; i < 12; i++) { - tv.NewMouseEvent (new MouseEvent { Flags = MouseFlags.WheeledDown }); + tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledDown }); Application.PositionCursor (); Assert.Equal (i + 1, tv.TopRow); Application.Driver!.GetCursorVisibility (out CursorVisibility cursorVisibility); @@ -1086,7 +1086,7 @@ public void DesiredCursorVisibility_Vertical_Navigation () for (var i = 12; i > 0; i--) { - tv.NewMouseEvent (new MouseEvent { Flags = MouseFlags.WheeledUp }); + tv.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.WheeledUp }); Application.PositionCursor (); Assert.Equal (i - 1, tv.TopRow); @@ -6166,7 +6166,7 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True ( _textView.NewMouseEvent ( - new MouseEvent { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } ) ); Assert.Equal (0, _textView.SelectionStartColumn); @@ -6175,7 +6175,7 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump ", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEvent { Position = new (12, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (12, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (new Point (12, 0), _textView.CursorPosition); @@ -6184,7 +6184,7 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True ( _textView.NewMouseEvent ( - new MouseEvent { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } ) ); Assert.Equal (0, _textView.SelectionStartRow); @@ -6193,7 +6193,7 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEvent { Position = new (19, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (19, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (new Point (19, 0), _textView.CursorPosition); @@ -6202,7 +6202,7 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True ( _textView.NewMouseEvent ( - new MouseEvent { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } + new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed | MouseFlags.ButtonShift } ) ); Assert.Equal (0, _textView.SelectionStartRow); @@ -6211,14 +6211,14 @@ public void Mouse_Button_Shift_Preserves_Selection () Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between text", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEvent { Position = new (24, 0), Flags = MouseFlags.Button1Clicked })); + Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Clicked })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (new Point (24, 0), _textView.CursorPosition); Assert.True (_textView.IsSelecting); Assert.Equal ("TAB to jump between text", _textView.SelectedText); - Assert.True (_textView.NewMouseEvent (new MouseEvent { Position = new (24, 0), Flags = MouseFlags.Button1Pressed })); + Assert.True (_textView.NewMouseEvent (new MouseEventArgs { Position = new (24, 0), Flags = MouseFlags.Button1Pressed })); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (0, _textView.SelectionStartRow); Assert.Equal (new Point (24, 0), _textView.CursorPosition); @@ -6972,12 +6972,12 @@ public void TextView_SpaceHandling () { var tv = new TextView { Width = 10, Text = " " }; - var ev = new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked }; + var ev = new MouseEventArgs { Position = new (0, 0), Flags = MouseFlags.Button1DoubleClicked }; tv.NewMouseEvent (ev); Assert.Equal (1, tv.SelectedLength); - ev = new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }; + ev = new MouseEventArgs { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }; tv.NewMouseEvent (ev); Assert.Equal (1, tv.SelectedLength); @@ -7094,7 +7094,7 @@ This is the second line. _output ); - Assert.True (tv.NewMouseEvent (new MouseEvent { Position = new (0, 3), Flags = MouseFlags.Button1Pressed })); + Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (0, 3), Flags = MouseFlags.Button1Pressed })); tv.Draw (); Assert.Equal (new Point (0, 3), tv.CursorPosition); Assert.Equal (new Point (13, 0), cp); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index f5f42b19cf..cbf11e4b28 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -440,7 +440,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null () Assert.Null (Application.MouseGrabView); // Grab the mouse - Application.OnMouseEvent (new () { ScreenPosition = new (3, 2), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (3, 2), Flags = MouseFlags.Button1Pressed }); Assert.Equal (Application.Top!.Border, Application.MouseGrabView); Assert.Equal (new (2, 2, 10, 3), Application.Top.Frame); @@ -450,7 +450,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null () Assert.Equal (Application.Top!.Border, Application.MouseGrabView); // Drag to left - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (2, 2), Flags = MouseFlags.Button1Pressed @@ -473,7 +473,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null () Assert.Equal (Application.Top!.Border, Application.MouseGrabView); // Drag up - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -496,7 +496,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null () Assert.Equal (Application.Top!.Border, Application.MouseGrabView); // Ungrab the mouse - Application.OnMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Released }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Released }); Application.Refresh (); Assert.Null (Application.MouseGrabView); @@ -545,7 +545,7 @@ public void Mouse_Drag_On_Top_With_Superview_Not_Null () Assert.Null (Application.MouseGrabView); // Grab the mouse - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (win.Frame.X, win.Frame.Y), Flags = MouseFlags.Button1Pressed @@ -561,7 +561,7 @@ public void Mouse_Drag_On_Top_With_Superview_Not_Null () movex = 1; movey = 0; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (win.Frame.X + movex, win.Frame.Y + movey), Flags = @@ -586,7 +586,7 @@ public void Mouse_Drag_On_Top_With_Superview_Not_Null () movex = 0; movey = -1; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (win.Frame.X + movex, win.Frame.Y + movey), Flags = @@ -611,7 +611,7 @@ public void Mouse_Drag_On_Top_With_Superview_Not_Null () movex = 0; movey = 0; - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (win.Frame.X + movex, win.Frame.Y + movey), @@ -743,18 +743,18 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () Assert.Equal (new (0, 0, 200, 100), scrollView.Subviews [0].Frame); Assert.Equal (new (3, 3, 194, 94), win.Frame); - Application.OnMouseEvent (new () { ScreenPosition = new (6, 6), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (6, 6), Flags = MouseFlags.Button1Pressed }); Assert.Equal (win.Border, Application.MouseGrabView); Assert.Equal (new (3, 3, 194, 94), win.Frame); - Application.OnMouseEvent (new () { ScreenPosition = new (9, 9), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (9, 9), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition }); Assert.Equal (win.Border, Application.MouseGrabView); top.SetNeedsLayout (); top.LayoutSubviews (); Assert.Equal (new (6, 6, 191, 91), win.Frame); Application.Refresh (); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (5, 5), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -765,12 +765,12 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () Assert.Equal (new (2, 2, 195, 95), win.Frame); Application.Refresh (); - Application.OnMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.Button1Released }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.Button1Released }); // ScrollView always grab the mouse when the container's subview OnMouseEnter don't want grab the mouse Assert.Equal (scrollView, Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (4, 4), Flags = MouseFlags.ReportMousePosition }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (4, 4), Flags = MouseFlags.ReportMousePosition }); Assert.Equal (scrollView, Application.MouseGrabView); top.Dispose (); } @@ -790,11 +790,11 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L Assert.Null (Application.MouseGrabView); - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); Assert.Equal (window.Border, Application.MouseGrabView); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (-11, -4), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -807,7 +807,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L // Changes Top size to same size as Dialog more menu and scroll bar ((FakeDriver)Application.Driver!).SetBufferSize (20, 3); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -820,7 +820,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L // Changes Top size smaller than Dialog size ((FakeDriver)Application.Driver!).SetBufferSize (19, 2); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -830,7 +830,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L Assert.Equal (new (0, 0, 19, 2), top.Frame); Assert.Equal (new (-1, -1, 20, 3), window.Frame); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (18, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -841,7 +841,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L Assert.Equal (new (18, 1, 20, 3), window.Frame); // On a real app we can't go beyond the SuperView bounds - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (19, 2), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -882,7 +882,7 @@ public void Modal_As_Top_Will_Drag_Cleanly () Assert.Null (Application.MouseGrabView); Assert.Equal (new (0, 0, 10, 3), window.Frame); - Application.OnMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed }); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); @@ -890,7 +890,7 @@ public void Modal_As_Top_Will_Drag_Cleanly () Assert.Equal (new (0, 0, 10, 3), window.Frame); - Application.OnMouseEvent ( + Application.RaiseMouseEvent ( new () { ScreenPosition = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition @@ -984,7 +984,7 @@ void OnDrawContentComplete (object sender, DrawEventArgs e) Assert.Equal (new (2, 1, 15, 10), testWindow.Frame); - Application.OnMouseEvent (new () { ScreenPosition = new (5, 2), Flags = MouseFlags.Button1Clicked }); + Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 2), Flags = MouseFlags.Button1Clicked }); Application.Refresh (); diff --git a/UnitTests/Views/TreeTableSourceTests.cs b/UnitTests/Views/TreeTableSourceTests.cs index 3db7a27425..345dffeb03 100644 --- a/UnitTests/Views/TreeTableSourceTests.cs +++ b/UnitTests/Views/TreeTableSourceTests.cs @@ -111,7 +111,7 @@ public void TestTreeTableSource_BasicExpanding_WithMouse () Assert.Equal (0, tv.SelectedRow); Assert.Equal (0, tv.SelectedColumn); - Assert.True (tv.NewMouseEvent (new MouseEvent { Position = new (2, 2), Flags = MouseFlags.Button1Clicked })); + Assert.True (tv.NewMouseEvent (new MouseEventArgs { Position = new (2, 2), Flags = MouseFlags.Button1Clicked })); tv.Draw (); @@ -128,15 +128,15 @@ public void TestTreeTableSource_BasicExpanding_WithMouse () TestHelpers.AssertDriverContentsAre (expected, _output); // Clicking to the right/left of the expand/collapse does nothing - tv.NewMouseEvent (new MouseEvent { Position = new (3, 2), Flags = MouseFlags.Button1Clicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (3, 2), Flags = MouseFlags.Button1Clicked }); tv.Draw (); TestHelpers.AssertDriverContentsAre (expected, _output); - tv.NewMouseEvent (new MouseEvent { Position = new (1, 2), Flags = MouseFlags.Button1Clicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (1, 2), Flags = MouseFlags.Button1Clicked }); tv.Draw (); TestHelpers.AssertDriverContentsAre (expected, _output); // Clicking on the + again should collapse - tv.NewMouseEvent (new MouseEvent { Position = new (2, 2), Flags = MouseFlags.Button1Clicked }); + tv.NewMouseEvent (new MouseEventArgs { Position = new (2, 2), Flags = MouseFlags.Button1Clicked }); tv.Draw (); expected = diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index 507ca35418..12d1ecf976 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -438,7 +438,7 @@ public void ObjectActivationButton_DoubleClick () Assert.False (called); // double click triggers activation - tree.NewMouseEvent (new MouseEvent { Flags = MouseFlags.Button1DoubleClicked }); + tree.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.Button1DoubleClicked }); Assert.True (called); Assert.Same (f, activated); @@ -467,12 +467,12 @@ public void ObjectActivationButton_RightClick () Assert.False (called); // double click does nothing because we changed button binding to right click - tree.NewMouseEvent (new MouseEvent { Position = new (0, 1), Flags = MouseFlags.Button1DoubleClicked }); + tree.NewMouseEvent (new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button1DoubleClicked }); Assert.Null (activated); Assert.False (called); - tree.NewMouseEvent (new MouseEvent { Position = new (0, 1), Flags = MouseFlags.Button2Clicked }); + tree.NewMouseEvent (new MouseEventArgs { Position = new (0, 1), Flags = MouseFlags.Button2Clicked }); Assert.True (called); Assert.Same (car1, activated); @@ -506,7 +506,7 @@ public void ObjectActivationButton_SetToNull () // double click does nothing because we changed button to null - tree.NewMouseEvent (new MouseEvent { Flags = MouseFlags.Button1DoubleClicked }); + tree.NewMouseEvent (new MouseEventArgs { Flags = MouseFlags.Button1DoubleClicked }); Assert.False (called); Assert.Null (activated); diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index 3318aa448a..2239bd7ff0 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -196,7 +196,7 @@ In v1, the `Command` enum had duplicate entries and inconsistent naming. In v2 i The API for mouse input is now internally consistent and easier to use. -* The @Terminal.Gui.MouseEvent class replaces `MouseEventEventArgs`. +* The @Terminal.Gui.MouseEventArgs class replaces `MouseEventEventArgs`. * More granular APIs are provided to ease handling specific mouse actions. See [Mouse API](mouse.md). * Views can use the @Terminal.Gui.View.Highlight event to have the view be visibly highlighted on various mouse events. * Views can set `View.WantContinousButtonPresses = true` to have their @Terminal.Gui.Command.Accept command be invoked repeatedly as the user holds a mouse button down on the view. @@ -213,7 +213,7 @@ The API for mouse input is now internally consistent and easier to use. ```diff - Application.RootMouseEvent(KeyEvent arg) -+ Application.MouseEvent(object? sender, MouseEvent mouseEvent) ++ Application.MouseEvent(object? sender, MouseEventArgs mouseEvent) ``` ## Navigation - `Cursor`, `Focus`, `TabStop` etc... diff --git a/docfx/docs/mouse.md b/docfx/docs/mouse.md index 63ef136964..18ffd2cb0e 100644 --- a/docfx/docs/mouse.md +++ b/docfx/docs/mouse.md @@ -10,9 +10,9 @@ Tenets higher in the list have precedence over tenets lower in the list. ## Mouse APIs -At the core of *Terminal.Gui*'s mouse API is the *[MouseEvent](~/api/Terminal.Gui.MouseEvent.yml)* class. The `MouseEvent` class provides a platform-independent abstraction for common mouse events. Every mouse event can be fully described in a `MouseEvent` instance, and most of the mouse-related APIs are simply helper functions for decoding a `MouseEvent`. +At the core of *Terminal.Gui*'s mouse API is the @Terminal.Gui.MouseEventArgs class. The @Terminal.Gui.MouseEventArgs class provides a platform-independent abstraction for common mouse events. Every mouse event can be fully described in a @Terminal.Gui.MouseEventArgs instance, and most of the mouse-related APIs are simply helper functions for decoding a @Terminal.Gui.MouseEventArgs. -When the user does something with the mouse, the `ConsoleDriver` maps the platform-specific mouse event into a `MouseEvent` and calls `Application.OnMouseEvent`. Then, `Application.OnMouseEvent` determines which `View` the event should go to. The `View.OnMouseEvent` method can be overridden or the `View.MouseEvent` event can be subscribed to, to handle the low-level mouse event. If the low-level event is not handled by a view, `Application` will then call the appropriate high-level helper APIs. For example, if the user double-clicks the mouse, `View.OnMouseClick` will be called/`View.MouseClick` will be fired with the event arguments indicating which mouse button was double-clicked. +When the user does something with the mouse, the `ConsoleDriver` maps the platform-specific mouse event into a `MouseEventArgs` and calls `Application.RaiseMouseEvent`. Then, `Application.RaiseMouseEvent` determines which `View` the event should go to. The `View.OnMouseEvent` method can be overridden or the `View.MouseEvent` event can be subscribed to, to handle the low-level mouse event. If the low-level event is not handled by a view, `Application` will then call the appropriate high-level helper APIs. For example, if the user double-clicks the mouse, `View.OnMouseClick` will be called/`View.MouseClick` will be raised with the event arguments indicating which mouse button was double-clicked. ## Mouse Button and Movement Concepts