diff --git a/ReactiveExample/ReactiveExample.csproj b/ReactiveExample/ReactiveExample.csproj index b3c0c5558..921465ed4 100644 --- a/ReactiveExample/ReactiveExample.csproj +++ b/ReactiveExample/ReactiveExample.csproj @@ -11,8 +11,8 @@ 2.0 - - + + diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index af906ecf7..bfe79d389 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -40,7 +40,7 @@ - + diff --git a/Terminal.Gui/View/ViewMouse.cs b/Terminal.Gui/View/ViewMouse.cs index 2bed5f1dd..7b602acb3 100644 --- a/Terminal.Gui/View/ViewMouse.cs +++ b/Terminal.Gui/View/ViewMouse.cs @@ -1,114 +1,120 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -namespace Terminal.Gui { - public partial class View { - /// - /// Event fired when the view receives the mouse event for the first time. - /// - public event EventHandler MouseEnter; +namespace Terminal.Gui; - /// - /// Event fired when the view receives a mouse event for the last time. - /// - public event EventHandler MouseLeave; +public partial class View { - /// - /// Event fired when a mouse event is generated. - /// - public event EventHandler MouseClick; + /// + /// Gets or sets a value indicating whether this wants mouse position reports. + /// + /// if want mouse position reports; otherwise, . + public virtual bool WantMousePositionReports { get; set; } - /// - public override bool OnMouseEnter (MouseEvent mouseEvent) - { - if (!Enabled) { - return true; - } + /// + /// Gets or sets a value indicating whether this want continuous button pressed event. + /// + public virtual bool WantContinuousButtonPressed { get; set; } - if (!CanBeVisible (this)) { - return false; - } + /// + /// Event fired when the view receives the mouse event for the first time. + /// + public event EventHandler MouseEnter; - var args = new MouseEventEventArgs (mouseEvent); - MouseEnter?.Invoke (this, args); + /// + /// Event fired when the view receives a mouse event for the last time. + /// + public event EventHandler MouseLeave; - return args.Handled || base.OnMouseEnter (mouseEvent); + /// + /// Event fired when a mouse event is generated. + /// + public event EventHandler MouseClick; + + /// + public override bool OnMouseEnter (MouseEvent mouseEvent) + { + if (!Enabled) { + return true; } - /// - public override bool OnMouseLeave (MouseEvent mouseEvent) - { - if (!Enabled) { - return true; - } - - if (!CanBeVisible (this)) { - return false; - } - - var args = new MouseEventEventArgs (mouseEvent); - MouseLeave?.Invoke (this, args); - - return args.Handled || base.OnMouseLeave (mouseEvent); - } - - /// - /// Method invoked when a mouse event is generated - /// - /// - /// , if the event was handled, otherwise. - public virtual bool OnMouseEvent (MouseEvent mouseEvent) - { - if (!Enabled) { - return true; - } - - if (!CanBeVisible (this)) { - return false; - } - - var args = new MouseEventEventArgs (mouseEvent); - if (OnMouseClick (args)) - return true; - if (MouseEvent (mouseEvent)) - return true; - - if (mouseEvent.Flags == MouseFlags.Button1Clicked) { - if (CanFocus && !HasFocus && SuperView != null) { - SuperView.SetFocus (this); - SetNeedsDisplay (); - } - - return true; - } + if (!CanBeVisible (this)) { return false; } - /// - /// Invokes the MouseClick event. - /// - protected bool OnMouseClick (MouseEventEventArgs args) - { - if (!Enabled) { - return true; - } + var args = new MouseEventEventArgs (mouseEvent); + MouseEnter?.Invoke (this, args); - MouseClick?.Invoke (this, args); - return args.Handled; + return args.Handled || base.OnMouseEnter (mouseEvent); + } + + /// + public override bool OnMouseLeave (MouseEvent mouseEvent) + { + if (!Enabled) { + return true; } - /// - /// Gets or sets a value indicating whether this wants mouse position reports. - /// - /// if want mouse position reports; otherwise, . - public virtual bool WantMousePositionReports { get; set; } + if (!CanBeVisible (this)) { + return false; + } - /// - /// Gets or sets a value indicating whether this want continuous button pressed event. - /// - public virtual bool WantContinuousButtonPressed { get; set; } + var args = new MouseEventEventArgs (mouseEvent); + MouseLeave?.Invoke (this, args); + + return args.Handled || base.OnMouseLeave (mouseEvent); } -} + + /// + /// Method invoked when a mouse event is generated + /// + /// + /// , if the event was handled, otherwise. + public virtual bool OnMouseEvent (MouseEvent mouseEvent) + { + if (!Enabled) { + return true; + } + + if (!CanBeVisible (this)) { + return false; + } + + var args = new MouseEventEventArgs (mouseEvent); + if (MouseEvent (mouseEvent)) { + return true; + } + + if (mouseEvent.Flags == MouseFlags.Button1Clicked) { + if (CanFocus && !HasFocus && SuperView != null) { + SuperView.SetFocus (this); + SetNeedsDisplay (); + } + + return OnMouseClick (args); + } + if (mouseEvent.Flags == MouseFlags.Button2Clicked) { + return OnMouseClick (args); + } + if (mouseEvent.Flags == MouseFlags.Button3Clicked) { + return OnMouseClick (args); + } + if (mouseEvent.Flags == MouseFlags.Button4Clicked) { + return OnMouseClick (args); + } + + return false; + } + + /// + /// Invokes the MouseClick event. + /// + protected bool OnMouseClick (MouseEventEventArgs args) + { + if (!Enabled) { + return true; + } + + MouseClick?.Invoke (this, args); + return args.Handled; + } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index bc23a6c44..c64331c5e 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -7,7 +7,7 @@ namespace Terminal.Gui; /// /// The is a that by default is centered and contains one -/// or more s. It defaults to the color scheme and has a 1 cell padding around the edges. +/// or more s. It defaults to the Colors.ColorSchemes ["Dialog"] color scheme and has a 1 cell padding around the edges. /// /// /// To run the modally, create the , and pass it to . diff --git a/UICatalog/UICatalog.csproj b/UICatalog/UICatalog.csproj index a717e41bc..082140a75 100644 --- a/UICatalog/UICatalog.csproj +++ b/UICatalog/UICatalog.csproj @@ -28,8 +28,8 @@ - - + + diff --git a/UnitTests/Application/MouseTests.cs b/UnitTests/Application/MouseTests.cs index 298533877..657cbcc12 100644 --- a/UnitTests/Application/MouseTests.cs +++ b/UnitTests/Application/MouseTests.cs @@ -102,7 +102,7 @@ public class MouseTests { var mouseEvent = new MouseEvent () { X = clickX, Y = clickY, - Flags = MouseFlags.Button1Pressed + Flags = MouseFlags.Button1Clicked }; var mouseEventArgs = new MouseEventEventArgs (mouseEvent); @@ -194,7 +194,7 @@ public class MouseTests { var mouseEvent = new MouseEvent () { X = clickX, Y = clickY, - Flags = MouseFlags.Button1Pressed + Flags = MouseFlags.Button1Clicked }; var mouseEventArgs = new MouseEventEventArgs (mouseEvent); diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 48f79fce3..3ebb10a02 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -25,7 +25,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index e8ce064b9..785cb975b 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1307,8 +1307,12 @@ public class TextFieldTests { View = tf }; + // In #3183 OnMouseClicked is no longer called before MouseEvent(). + // 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 (new MouseEventEventArgs (mouseEvent)); - Assert.Equal (2, clickCounter); + Assert.Equal (1, clickCounter); } private void SuppressKey (object s, Key arg)