diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index b8cbb7f1f..1901bba2a 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1486,7 +1486,7 @@ public static partial class Application if (MouseGrabView.Bounds.Contains (viewRelativeMouseEvent.X, viewRelativeMouseEvent.Y) is false) { // The mouse has moved outside the bounds of the view that grabbed the mouse - _mouseEnteredView?.OnMouseLeave (mouseEvent); + _mouseEnteredView?.NewMouseLeaveEvent (mouseEvent); } //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}"); @@ -1568,12 +1568,12 @@ public static partial class Application if (_mouseEnteredView is null) { _mouseEnteredView = view; - view.OnMouseEnter (me); + view.NewMouseEnterEvent (me); } else if (_mouseEnteredView != view) { - _mouseEnteredView.OnMouseLeave (me); - view.OnMouseEnter (me); + _mouseEnteredView.NewMouseLeaveEvent (me); + view.NewMouseEnterEvent (me); _mouseEnteredView = view; } diff --git a/Terminal.Gui/View/ViewMouse.cs b/Terminal.Gui/View/ViewMouse.cs index 944928c8c..4b7e4f146 100644 --- a/Terminal.Gui/View/ViewMouse.cs +++ b/Terminal.Gui/View/ViewMouse.cs @@ -29,6 +29,9 @@ public enum HighlightStyle PressedOutside = 4 } +/// +/// Event arguments for the event. +/// public class HighlightEventArgs : CancelEventArgs { public HighlightEventArgs (HighlightStyle style) @@ -36,6 +39,9 @@ public class HighlightEventArgs : CancelEventArgs HighlightStyle = style; } + /// + /// The highlight style. + /// public HighlightStyle HighlightStyle { get; } } @@ -55,16 +61,24 @@ public partial class View public virtual bool WantMousePositionReports { get; set; } /// - /// Called when the mouse enters the View's . The view will now receive mouse events until the - /// mouse leaves - /// the view. At which time, will be called. + /// Called by when the mouse enters . The view will + /// then receive mouse events until is called indicating the mouse has left + /// the view. /// /// - /// The coordinates are relative to . + /// + /// A view must be both enabled and visible to receive mouse events. + /// + /// + /// This method calls to fire the event. + /// + /// + /// See for more information. + /// /// /// - /// , if the event was handled, otherwise. - protected internal virtual bool OnMouseEnter (MouseEvent mouseEvent) + /// if the event was handled, otherwise. + internal bool? NewMouseEnterEvent (MouseEvent mouseEvent) { if (!Enabled) { @@ -76,6 +90,27 @@ public partial class View return false; } + return OnMouseEnter (mouseEvent); + } + + /// + /// Called by when the mouse enters . The view will + /// then receive mouse events until is called indicating the mouse has left + /// the view. + /// + /// + /// + /// Override this method or subscribe to to change the default enter behavior. + /// + /// + /// The coordinates are relative to . + /// + /// + /// + /// , if the event was handled, otherwise. + protected internal virtual bool OnMouseEnter (MouseEvent mouseEvent) + { + var args = new MouseEventEventArgs (mouseEvent); MouseEnter?.Invoke (this, args); @@ -85,13 +120,49 @@ public partial class View /// Event fired when the mouse moves into the View's . public event EventHandler MouseEnter; + /// - /// Called when the mouse has moved out of the View's . The view will no longer receive mouse - /// events (until the - /// mouse moves within the view again and is called). + /// Called by when the mouse leaves . The view will + /// then no longer receive mouse events. /// /// + /// + /// A view must be both enabled and visible to receive mouse events. + /// + /// + /// This method calls to fire the event. + /// + /// + /// See for more information. + /// + /// + /// + /// if the event was handled, otherwise. + internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent) + { + if (!Enabled) + { + return true; + } + + if (!CanBeVisible (this)) + { + return false; + } + + return OnMouseLeave (mouseEvent); + } + /// + /// Called by when a mouse leaves . The view will + /// no longer receive mouse events. + /// + /// + /// + /// Override this method or subscribe to to change the default leave behavior. + /// + /// /// The coordinates are relative to . + /// /// /// /// , if the event was handled, otherwise. diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 4bc5b111d..69bcb2d4d 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -444,7 +444,7 @@ public partial class Toplevel : View /// perform tasks when the has been laid out and focus has been set. changes. /// /// A Ready event handler is a good place to finalize initialization after calling - /// on this . + /// on this . /// /// public event EventHandler Ready; diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index 3a1d53076..6801aa991 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -235,8 +235,8 @@ public class ResponderTests Assert.False (r.OnKeyDown (new Key { KeyCode = KeyCode.Null })); Assert.False (r.OnKeyUp (new Key { KeyCode = KeyCode.Null })); Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); - Assert.False (r.OnMouseEnter (new MouseEvent { Flags = MouseFlags.AllEvents })); - Assert.False (r.OnMouseLeave (new MouseEvent { Flags = MouseFlags.AllEvents })); + Assert.False (r.NewMouseEnterEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); + Assert.False (r.NewMouseLeaveEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); var v = new View (); Assert.False (r.OnEnter (v)); diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index ae6c82c3d..87b9f5359 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -866,8 +866,8 @@ At 0,0 //Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown })); Assert.False (r.OnKeyUp (new Key { KeyCode = KeyCode.Null })); Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); - Assert.False (r.OnMouseEnter (new MouseEvent { Flags = MouseFlags.AllEvents })); - Assert.False (r.OnMouseLeave (new MouseEvent { Flags = MouseFlags.AllEvents })); + Assert.False (r.NewMouseEnterEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); + Assert.False (r.NewMouseLeaveEvent (new MouseEvent { Flags = MouseFlags.AllEvents })); var v1 = new View (); Assert.False (r.OnEnter (v1));