Explorar el Código

Merge pull request #3571 from tig/v2_3570-TextView-ENTER

Fixes #3570 & #3561. Fixes a bunch of `EventArgs` sins
Tig hace 1 año
padre
commit
a6bd533bd4
Se han modificado 86 ficheros con 1363 adiciones y 1598 borrados
  1. 6 4
      Terminal.Gui/Application/Application.cs
  2. 3 3
      Terminal.Gui/Drawing/Glyphs.cs
  3. 0 16
      Terminal.Gui/Drawing/ThicknessEventArgs.cs
  4. 0 26
      Terminal.Gui/Text/StringEventArgs.cs
  5. 13 13
      Terminal.Gui/View/Adornment/Adornment.cs
  6. 4 3
      Terminal.Gui/View/Adornment/Border.cs
  7. 3 3
      Terminal.Gui/View/Adornment/Margin.cs
  8. 35 0
      Terminal.Gui/View/CancelEventArgs.cs
  9. 18 0
      Terminal.Gui/View/EventArgs.cs
  10. 30 0
      Terminal.Gui/View/HighlightStyle.cs
  11. 0 27
      Terminal.Gui/View/StateEventArgs.cs
  12. 67 67
      Terminal.Gui/View/View.cs
  13. 4 3
      Terminal.Gui/View/ViewAdornments.cs
  14. 2 1
      Terminal.Gui/View/ViewEventArgs.cs
  15. 2 0
      Terminal.Gui/View/ViewKeyboard.cs
  16. 282 330
      Terminal.Gui/View/ViewMouse.cs
  17. 7 9
      Terminal.Gui/View/ViewText.cs
  18. 2 2
      Terminal.Gui/Views/Button.cs
  19. 87 56
      Terminal.Gui/Views/CheckBox.cs
  20. 29 18
      Terminal.Gui/Views/ComboBox.cs
  21. 1 1
      Terminal.Gui/Views/DateField.cs
  22. 2 2
      Terminal.Gui/Views/Label.cs
  23. 2 2
      Terminal.Gui/Views/ListView.cs
  24. 3 3
      Terminal.Gui/Views/Menu/Menu.cs
  25. 2 2
      Terminal.Gui/Views/RadioGroup.cs
  26. 4 4
      Terminal.Gui/Views/Shortcut.cs
  27. 4 4
      Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs
  28. 17 14
      Terminal.Gui/Views/TextField.cs
  29. 11 11
      Terminal.Gui/Views/TextValidateField.cs
  30. 25 6
      Terminal.Gui/Views/TextView.cs
  31. 6 5
      Terminal.Gui/Views/Tile.cs
  32. 1 1
      Terminal.Gui/Views/TimeField.cs
  33. 2 2
      Terminal.Gui/Views/Wizard/Wizard.cs
  34. 4 4
      UICatalog/Scenarios/AdornmentEditor.cs
  35. 6 6
      UICatalog/Scenarios/AdornmentsEditor.cs
  36. 2 2
      UICatalog/Scenarios/Bars.cs
  37. 4 4
      UICatalog/Scenarios/BorderEditor.cs
  38. 10 10
      UICatalog/Scenarios/Buttons.cs
  39. 79 85
      UICatalog/Scenarios/CharacterMap.cs
  40. 26 26
      UICatalog/Scenarios/ContentScrolling.cs
  41. 1 1
      UICatalog/Scenarios/CsvEditor.cs
  42. 3 3
      UICatalog/Scenarios/Dialogs.cs
  43. 32 32
      UICatalog/Scenarios/DynamicMenuBar.cs
  44. 8 8
      UICatalog/Scenarios/Editor.cs
  45. 4 3
      UICatalog/Scenarios/ExpanderButton.cs
  46. 16 16
      UICatalog/Scenarios/FileDialogExamples.cs
  47. 2 2
      UICatalog/Scenarios/GraphViewExample.cs
  48. 3 3
      UICatalog/Scenarios/Images.cs
  49. 2 4
      UICatalog/Scenarios/ListColumns.cs
  50. 13 13
      UICatalog/Scenarios/ListViewWithSelection.cs
  51. 2 2
      UICatalog/Scenarios/Localization.cs
  52. 3 3
      UICatalog/Scenarios/MessageBoxes.cs
  53. 4 4
      UICatalog/Scenarios/Mouse.cs
  54. 32 38
      UICatalog/Scenarios/PosAlignDemo.cs
  55. 11 7
      UICatalog/Scenarios/ProgressBarStyles.cs
  56. 17 17
      UICatalog/Scenarios/Scrolling.cs
  57. 3 3
      UICatalog/Scenarios/SendKeys.cs
  58. 9 9
      UICatalog/Scenarios/Shortcuts.cs
  59. 2 2
      UICatalog/Scenarios/Sliders.cs
  60. 10 10
      UICatalog/Scenarios/SpinnerStyles.cs
  61. 14 14
      UICatalog/Scenarios/Text.cs
  62. 8 8
      UICatalog/Scenarios/TextAlignmentAndDirection.cs
  63. 4 4
      UICatalog/Scenarios/TextFormatterDemo.cs
  64. 15 15
      UICatalog/Scenarios/TileViewNesting.cs
  65. 4 3
      UICatalog/Scenarios/TrueColors.cs
  66. 7 7
      UICatalog/Scenarios/Wizards.cs
  67. 4 6
      UICatalog/UICatalog.cs
  68. 4 4
      UnitTests/Application/ApplicationTests.cs
  69. 3 3
      UnitTests/Application/KeyboardTests.cs
  70. 1 1
      UnitTests/Dialogs/WizardTests.cs
  71. 2 2
      UnitTests/UICatalog/ScenarioTests.cs
  72. 0 3
      UnitTests/View/Adornment/AdornmentTests.cs
  73. 4 4
      UnitTests/View/MouseTests.cs
  74. 39 40
      UnitTests/View/TitleTests.cs
  75. 4 4
      UnitTests/View/ViewTests.cs
  76. 3 3
      UnitTests/Views/ButtonTests.cs
  77. 70 70
      UnitTests/Views/CheckBoxTests.cs
  78. 1 0
      UnitTests/Views/ComboBoxTests.cs
  79. 1 1
      UnitTests/Views/LabelTests.cs
  80. 4 4
      UnitTests/Views/ListViewTests.cs
  81. 1 1
      UnitTests/Views/MenuBarTests.cs
  82. 2 2
      UnitTests/Views/RadioGroupTests.cs
  83. 97 12
      UnitTests/Views/TextFieldTests.cs
  84. 75 418
      UnitTests/Views/TextViewTests.cs
  85. 6 6
      UnitTests/Views/TreeTableSourceTests.cs
  86. 8 8
      UnitTests/Views/TreeViewTests.cs

+ 6 - 4
Terminal.Gui/Application/Application.cs

@@ -308,7 +308,7 @@ public static partial class Application
         SupportedCultures = GetSupportedCultures ();
         _mainThreadId = Thread.CurrentThread.ManagedThreadId;
         _initialized = true;
-        InitializedChanged?.Invoke (null, new (false, _initialized));
+        InitializedChanged?.Invoke (null, new (in _initialized));
     }
 
     private static void Driver_SizeChanged (object sender, SizeChangedEventArgs e) { OnSizeChanging (e); }
@@ -349,16 +349,18 @@ public static partial class Application
         // TODO: Throw an exception if Init hasn't been called.
         ResetState ();
         PrintJsonErrors ();
-        InitializedChanged?.Invoke (null, new (true, _initialized));
+        InitializedChanged?.Invoke (null, new (in _initialized));
     }
 
+#nullable enable
     /// <summary>
-    ///     This event is fired after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
+    ///     This event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
     /// </summary>
     /// <remarks>
     ///     Intended to support unit tests that need to know when the application has been initialized.
     /// </remarks>
-    public static event EventHandler<StateEventArgs<bool>> InitializedChanged;
+    public static event EventHandler<EventArgs<bool>>? InitializedChanged;
+#nullable restore
 
     #endregion Initialization (Init/Shutdown)
 

+ 3 - 3
Terminal.Gui/Drawing/Glyphs.cs

@@ -32,13 +32,13 @@ public class GlyphDefinitions
     #region ----------------- Single Glyphs -----------------
 
     /// <summary>Checked indicator (e.g. for <see cref="ListView"/> and <see cref="CheckBox"/>).</summary>
-    public Rune Checked { get; set; } = (Rune)'☑';
+    public Rune CheckStateChecked { get; set; } = (Rune)'☑';
 
     /// <summary>Not Checked indicator (e.g. for <see cref="ListView"/> and <see cref="CheckBox"/>).</summary>
-    public Rune UnChecked { get; set; } = (Rune)'☐';
+    public Rune CheckStateUnChecked { get; set; } = (Rune)'☐';
 
     /// <summary>Null Checked indicator (e.g. for <see cref="ListView"/> and <see cref="CheckBox"/>).</summary>
-    public Rune NullChecked { get; set; } = (Rune)'☒';
+    public Rune CheckStateNone { get; set; } = (Rune)'☒';
 
     /// <summary>Selected indicator  (e.g. for <see cref="ListView"/> and <see cref="RadioGroup"/>).</summary>
     public Rune Selected { get; set; } = (Rune)'◉';

+ 0 - 16
Terminal.Gui/Drawing/ThicknessEventArgs.cs

@@ -1,16 +0,0 @@
-#nullable enable
-
-namespace Terminal.Gui;
-
-/// <summary>Event arguments for the <see cref="Thickness"/> events.</summary>
-public class ThicknessEventArgs : EventArgs
-{
-    /// <summary>Initializes a new instance of <see cref="ThicknessEventArgs"/></summary>
-    public ThicknessEventArgs () { }
-
-    /// <summary>The previous Thickness.</summary>
-    public Thickness PreviousThickness { get; set; } = Thickness.Empty;
-
-    /// <summary>The new Thickness.</summary>
-    public Thickness Thickness { get; set; } = Thickness.Empty;
-}

+ 0 - 26
Terminal.Gui/Text/StringEventArgs.cs

@@ -1,26 +0,0 @@
-using System.ComponentModel;
-
-namespace Terminal.Gui;
-
-/// <summary>Cancellable event args for string-based property change events.</summary>
-public class StringEventArgs : CancelEventArgs
-{
-    /// <summary>
-    /// Initializes a new instance of <see cref="StringEventArgs"/>
-    /// </summary>
-    public StringEventArgs () {}
-
-    /// <summary>Initializes a new instance of <see cref="StringEventArgs"/></summary>
-    /// <param name="oldString">The old string.</param>
-    /// <param name="newString">The new string.</param>
-    public StringEventArgs (string oldString, string newString)
-    {
-        OldValue = oldString;
-        NewValue = newString;
-    }
-    /// <summary>The new string.</summary>
-    public string NewValue { get; set; }
-
-    /// <summary>The old string.</summary>
-    public string OldValue { get; set; }
-}

+ 13 - 13
Terminal.Gui/View/Adornment/Adornment.cs

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+#nullable enable
+using Terminal.Gui;
+using Attribute = Terminal.Gui.Attribute;
 
 /// <summary>
 ///     Adornments are a special form of <see cref="View"/> that appear outside the <see cref="View.Viewport"/>:
@@ -33,7 +35,7 @@ public class Adornment : View
     ///     Adornments are distinguished from typical View classes in that they are not sub-views, but have a parent/child
     ///     relationship with their containing View.
     /// </remarks>
-    public View Parent { get; set; }
+    public View? Parent { get; set; }
 
     #region Thickness
 
@@ -45,10 +47,10 @@ public class Adornment : View
         get => _thickness;
         set
         {
-            Thickness prev = _thickness;
+            Thickness current = _thickness;
             _thickness = value;
 
-            if (prev != _thickness)
+            if (current != _thickness)
             {
                 if (Parent?.IsInitialized == false)
                 {
@@ -61,21 +63,19 @@ public class Adornment : View
                     Parent?.LayoutSubviews ();
                 }
 
-                OnThicknessChanged (prev);
+                OnThicknessChanged ();
             }
         }
     }
 
     /// <summary>Fired whenever the <see cref="Thickness"/> property changes.</summary>
-    public event EventHandler<ThicknessEventArgs> ThicknessChanged;
+    [CanBeNull]
+    public event EventHandler? ThicknessChanged;
 
     /// <summary>Called whenever the <see cref="Thickness"/> property changes.</summary>
-    public void OnThicknessChanged (Thickness previousThickness)
+    public void OnThicknessChanged ()
     {
-        ThicknessChanged?.Invoke (
-                                  this,
-                                  new () { Thickness = Thickness, PreviousThickness = previousThickness }
-                                 );
+        ThicknessChanged?.Invoke (this, EventArgs.Empty);
     }
 
     #endregion Thickness
@@ -88,7 +88,7 @@ public class Adornment : View
     /// </summary>
     public override View SuperView
     {
-        get => null;
+        get => null!;
         set => throw new InvalidOperationException (@"Adornments can not be Subviews or have SuperViews. Use Parent instead.");
     }
 
@@ -137,7 +137,7 @@ public class Adornment : View
     /// <inheritdoc/>
     public override Point ScreenToFrame (in Point location)
     {
-        return Parent.ScreenToFrame (new (location.X - Frame.X, location.Y - Frame.Y));
+        return Parent!.ScreenToFrame (new (location.X - Frame.X, location.Y - Frame.Y));
     }
 
     /// <summary>Does nothing for Adornment</summary>

+ 4 - 3
Terminal.Gui/View/Adornment/Border.cs

@@ -220,7 +220,7 @@ public class Border : Adornment
 
     private Color? _savedForeColor;
 
-    private void Border_Highlight (object sender, HighlightEventArgs e)
+    private void Border_Highlight (object sender, CancelEventArgs<HighlightStyle> e)
     {
         if (!Parent.Arrangement.HasFlag (ViewArrangement.Movable))
         {
@@ -228,7 +228,7 @@ public class Border : Adornment
             return;
         }
 
-        if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
+        if (e.NewValue.HasFlag (HighlightStyle.Pressed))
         {
             if (!_savedForeColor.HasValue)
             {
@@ -252,7 +252,7 @@ public class Border : Adornment
         }
 #endif
 
-        if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
+        if (e.NewValue == HighlightStyle.None && _savedForeColor.HasValue)
         {
             ColorScheme cs = new ColorScheme (ColorScheme)
             {
@@ -299,6 +299,7 @@ public class Border : Adornment
                 _startGrabPoint = new (mouseEvent.Position.X + Frame.X, mouseEvent.Position.Y + Frame.Y);
                 _dragPosition = mouseEvent.Position;
                 Application.GrabMouse (this);
+
                 SetHighlight (HighlightStyle);
             }
 

+ 3 - 3
Terminal.Gui/View/Adornment/Margin.cs

@@ -39,11 +39,11 @@ public class Margin : Adornment
     }
 
     private bool _pressed;
-    private void Margin_Highlight (object? sender, HighlightEventArgs e)
+    private void Margin_Highlight (object? sender, CancelEventArgs<HighlightStyle> e)
     {
         if (ShadowStyle != Gui.ShadowStyle.None)
         {
-            if (_pressed && e.HighlightStyle == HighlightStyle.None)
+            if (_pressed && e.CurrentValue == HighlightStyle.None)
             {
                 Thickness = new (Thickness.Left - 1, Thickness.Top, Thickness.Right + 1, Thickness.Bottom);
 
@@ -61,7 +61,7 @@ public class Margin : Adornment
                 return;
             }
 
-            if (!_pressed && (e.HighlightStyle.HasFlag (HighlightStyle.Pressed) /*|| e.HighlightStyle.HasFlag (HighlightStyle.PressedOutside)*/))
+            if (!_pressed && (e.CurrentValue.HasFlag (HighlightStyle.Pressed) /*|| e.HighlightStyle.HasFlag (HighlightStyle.PressedOutside)*/))
             {
                 Thickness = new (Thickness.Left + 1, Thickness.Top, Thickness.Right - 1, Thickness.Bottom);
                 _pressed = true;

+ 35 - 0
Terminal.Gui/View/CancelEventArgs.cs

@@ -0,0 +1,35 @@
+#nullable enable
+using System.ComponentModel;
+
+namespace Terminal.Gui;
+
+#pragma warning disable CS1711
+
+/// <summary>
+///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
+/// </summary>
+/// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
+/// <remarks>
+///     Events that use this class can be cancellable. Where applicable, the <see cref="CancelEventArgs.Cancel"/> property
+///     should be set to
+///     <see langword="true"/> to prevent the state change from occurring.
+/// </remarks>
+public class CancelEventArgs<T> : CancelEventArgs where T : notnull
+{
+    /// <summary>Initializes a new instance of the <see cref="CancelEventArgs{T}"/> class.</summary>
+    /// <param name="currentValue">The current (old) value of the property.</param>
+    /// <param name="newValue">The value the property will be set to if the event is not cancelled.</param>
+    /// <param name="cancel">Whether the event should be canceled or not.</param>
+    /// <typeparam name="T">The type of the value for the change being canceled.</typeparam>
+    public CancelEventArgs (ref readonly T currentValue, ref T newValue, bool cancel = false) : base (cancel)
+    {
+        CurrentValue = currentValue;
+        NewValue = newValue;
+    }
+
+    /// <summary>The current value of the property.</summary>
+    public T CurrentValue { get; }
+
+    /// <summary>The value the property will be set to if the event is not cancelled.</summary>
+    public T NewValue { get; set; }
+}

+ 18 - 0
Terminal.Gui/View/EventArgs.cs

@@ -0,0 +1,18 @@
+#nullable enable
+namespace Terminal.Gui;
+
+#pragma warning disable CS1711
+/// <summary>
+///     <see cref="EventArgs"/> for events that convey changes to a property of type <typeparamref name="T"/>.
+/// </summary>
+/// <typeparam name="T">The type of the value that was part of the change being canceled.</typeparam>
+public class EventArgs<T> : EventArgs where T : notnull
+{
+    /// <summary>Initializes a new instance of the <see cref="EventArgs{T}"/> class.</summary>
+    /// <param name="currentValue">The current value of the property.</param>
+    /// <typeparam name="T">The type of the value.</typeparam>
+    public EventArgs (ref readonly T currentValue) { CurrentValue = currentValue; }
+
+    /// <summary>The current value of the property.</summary>
+    public T CurrentValue { get; }
+}

+ 30 - 0
Terminal.Gui/View/HighlightStyle.cs

@@ -0,0 +1,30 @@
+namespace Terminal.Gui;
+
+/// <summary>
+/// Describes the highlight style of a view.
+/// </summary>
+[Flags]
+public enum HighlightStyle
+{
+    /// <summary>
+    /// No highlight.
+    /// </summary>
+    None = 0,
+
+#if HOVER
+    /// <summary>
+    /// The mouse is hovering over the view.
+    /// </summary>
+    Hover = 1,
+#endif
+
+    /// <summary>
+    /// The mouse is pressed within the <see cref="View.Viewport"/>.
+    /// </summary>
+    Pressed = 2,
+
+    /// <summary>
+    /// The mouse is pressed but moved outside the <see cref="View.Viewport"/>.
+    /// </summary>
+    PressedOutside = 4
+}

+ 0 - 27
Terminal.Gui/View/StateEventArgs.cs

@@ -1,27 +0,0 @@
-#nullable enable
-using System.ComponentModel;
-
-namespace Terminal.Gui;
-
-/// <summary><see cref="EventArgs"/> for events that convey state changes to a <see cref="View"/> class.</summary>
-/// <remarks>
-/// Events that use this class can be cancellable. The <see cref="CancelEventArgs.Cancel"/> property should be set to
-/// <see langword="true"/> to prevent the state change from occurring.
-/// </remarks>
-public class StateEventArgs<T> : CancelEventArgs
-{
-    /// <summary>Creates a new instance of the <see cref="StateEventArgs{T}"/> class.</summary>
-    /// <param name="oldValue"></param>
-    /// <param name="newValue"></param>
-    public StateEventArgs (T oldValue, T newValue)
-    {
-        OldValue = oldValue;
-        NewValue = newValue;
-    }
-
-    /// <summary>The new state</summary>
-    public T NewValue { get; set; }
-
-    /// <summary>The previous state</summary>
-    public T OldValue { get; }
-}

+ 67 - 67
Terminal.Gui/View/View.cs

@@ -67,7 +67,8 @@ namespace Terminal.Gui;
 ///         a View can be accessed with the <see cref="SuperView"/> property.
 ///     </para>
 ///     <para>
-///         To flag a region of the View's <see cref="Viewport"/> to be redrawn call <see cref="SetNeedsDisplay(Rectangle)"/>
+///         To flag a region of the View's <see cref="Viewport"/> to be redrawn call
+///         <see cref="SetNeedsDisplay(Rectangle)"/>
 ///         .
 ///         To flag the entire view for redraw call <see cref="SetNeedsDisplay()"/>.
 ///     </para>
@@ -106,6 +107,61 @@ namespace Terminal.Gui;
 
 public partial class View : Responder, ISupportInitializeNotification
 {
+    /// <summary>
+    ///     Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
+    ///     <see cref="HandledEventArgs.Handled"/>
+    ///     to cancel the event.
+    /// </summary>
+    public event EventHandler<HandledEventArgs> Accept;
+
+    /// <summary>Gets or sets arbitrary data for the view.</summary>
+    /// <remarks>This property is not used internally.</remarks>
+    public object Data { get; set; }
+
+    /// <summary>Gets or sets an identifier for the view;</summary>
+    /// <value>The identifier.</value>
+    /// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
+    public string Id { get; set; } = "";
+
+    /// <summary>Pretty prints the View</summary>
+    /// <returns></returns>
+    public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }
+
+    /// <inheritdoc/>
+    protected override void Dispose (bool disposing)
+    {
+        LineCanvas.Dispose ();
+
+        DisposeKeyboard ();
+        DisposeAdornments ();
+
+        for (int i = InternalSubviews.Count - 1; i >= 0; i--)
+        {
+            View subview = InternalSubviews [i];
+            Remove (subview);
+            subview.Dispose ();
+        }
+
+        base.Dispose (disposing);
+        Debug.Assert (InternalSubviews.Count == 0);
+    }
+
+    /// <summary>
+    ///     Called when the <see cref="Command.Accept"/> command is invoked. Raises <see cref="Accept"/>
+    ///     event.
+    /// </summary>
+    /// <returns>
+    ///     If <see langword="true"/> the event was canceled. If <see langword="false"/> the event was raised but not canceled.
+    ///     If <see langword="null"/> no event was raised.
+    /// </returns>
+    protected bool? OnAccept ()
+    {
+        var args = new HandledEventArgs ();
+        Accept?.Invoke (this, args);
+
+        return Accept is null ? null : args.Handled;
+    }
+
     #region Constructors and Initialization
 
     /// <summary>
@@ -125,6 +181,7 @@ public partial class View : Responder, ISupportInitializeNotification
     {
         SetupAdornments ();
         SetupKeyboard ();
+
         //SetupMouse ();
         SetupText ();
 
@@ -230,40 +287,10 @@ public partial class View : Responder, ISupportInitializeNotification
         }
 
         Initialized?.Invoke (this, EventArgs.Empty);
-
     }
 
     #endregion Constructors and Initialization
 
-    /// <summary>Gets or sets an identifier for the view;</summary>
-    /// <value>The identifier.</value>
-    /// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
-    public string Id { get; set; } = "";
-
-    /// <summary>Gets or sets arbitrary data for the view.</summary>
-    /// <remarks>This property is not used internally.</remarks>
-    public object Data { get; set; }
-
-    /// <summary>
-    ///     Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
-    ///     <see cref="CancelEventArgs.Cancel"/>
-    ///     to cancel the event.
-    /// </summary>
-    public event EventHandler<CancelEventArgs> Accept;
-
-    /// <summary>
-    ///     Called when the <see cref="Command.Accept"/> command is invoked. Fires the <see cref="Accept"/>
-    ///     event.
-    /// </summary>
-    /// <returns>If <see langword="true"/> the event was canceled.</returns>
-    protected bool? OnAccept ()
-    {
-        var args = new CancelEventArgs ();
-        Accept?.Invoke (this, args);
-
-        return args.Cancel;
-    }
-
     #region Visibility
 
     private bool _enabled = true;
@@ -318,6 +345,7 @@ public partial class View : Responder, ISupportInitializeNotification
     public virtual void OnEnabledChanged () { EnabledChanged?.Invoke (this, EventArgs.Empty); }
 
     private bool _visible = true;
+
     /// <summary>Gets or sets a value indicating whether this <see cref="Responder"/> and all its child controls are displayed.</summary>
     public virtual bool Visible
     {
@@ -349,7 +377,6 @@ public partial class View : Responder, ISupportInitializeNotification
         }
     }
 
-
     /// <summary>Method invoked when the <see cref="Visible"/> property from a view is changed.</summary>
     public virtual void OnVisibleChanged () { VisibleChanged?.Invoke (this, EventArgs.Empty); }
 
@@ -430,7 +457,7 @@ public partial class View : Responder, ISupportInitializeNotification
                 return;
             }
 
-            if (!OnTitleChanging (_title, value))
+            if (!OnTitleChanging (ref value))
             {
                 string old = _title;
                 _title = value;
@@ -445,7 +472,7 @@ public partial class View : Responder, ISupportInitializeNotification
                     Id = _title;
                 }
 #endif // DEBUG
-                OnTitleChanged (old, _title);
+                OnTitleChanged ();
             }
         }
     }
@@ -461,60 +488,33 @@ public partial class View : Responder, ISupportInitializeNotification
     }
 
     /// <summary>Called when the <see cref="View.Title"/> has been changed. Invokes the <see cref="TitleChanged"/> event.</summary>
-    /// <param name="oldTitle">The <see cref="View.Title"/> that is/has been replaced.</param>
-    /// <param name="newTitle">The new <see cref="View.Title"/> to be replaced.</param>
-    public virtual void OnTitleChanged (string oldTitle, string newTitle)
+    protected void OnTitleChanged ()
     {
-        StateEventArgs<string> args = new (oldTitle, newTitle);
-        TitleChanged?.Invoke (this, args);
+        TitleChanged?.Invoke (this, new (ref _title));
     }
 
     /// <summary>
     ///     Called before the <see cref="View.Title"/> changes. Invokes the <see cref="TitleChanging"/> event, which can
     ///     be cancelled.
     /// </summary>
-    /// <param name="oldTitle">The <see cref="View.Title"/> that is/has been replaced.</param>
     /// <param name="newTitle">The new <see cref="View.Title"/> to be replaced.</param>
     /// <returns>`true` if an event handler canceled the Title change.</returns>
-    public virtual bool OnTitleChanging (string oldTitle, string newTitle)
+    protected bool OnTitleChanging (ref string newTitle)
     {
-        StateEventArgs<string> args = new (oldTitle, newTitle);
+        CancelEventArgs<string> args = new (ref _title, ref newTitle);
         TitleChanging?.Invoke (this, args);
 
         return args.Cancel;
     }
 
     /// <summary>Event fired after the <see cref="View.Title"/> has been changed.</summary>
-    public event EventHandler<StateEventArgs<string>> TitleChanged;
+    public event EventHandler<EventArgs<string>> TitleChanged;
 
     /// <summary>
     ///     Event fired when the <see cref="View.Title"/> is changing. Set <see cref="CancelEventArgs.Cancel"/> to `true`
     ///     to cancel the Title change.
     /// </summary>
-    public event EventHandler<StateEventArgs<string>> TitleChanging;
+    public event EventHandler<CancelEventArgs<string>> TitleChanging;
 
     #endregion
-
-    /// <summary>Pretty prints the View</summary>
-    /// <returns></returns>
-    public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }
-
-    /// <inheritdoc/>
-    protected override void Dispose (bool disposing)
-    {
-        LineCanvas.Dispose ();
-
-        DisposeKeyboard ();
-        DisposeAdornments ();
-
-        for (int i = InternalSubviews.Count - 1; i >= 0; i--)
-        {
-            View subview = InternalSubviews [i];
-            Remove (subview);
-            subview.Dispose ();
-        }
-
-        base.Dispose (disposing);
-        Debug.Assert (InternalSubviews.Count == 0);
-    }
 }

+ 4 - 3
Terminal.Gui/View/ViewAdornments.cs

@@ -124,7 +124,8 @@ public partial class View
         get => Border?.LineStyle ?? LineStyle.Single;
         set
         {
-            StateEventArgs<LineStyle> e = new (Border?.LineStyle ?? LineStyle.None, value);
+            var old = Border?.LineStyle ?? LineStyle.None;
+            CancelEventArgs<LineStyle> e = new (ref old, ref value);
             OnBorderStyleChanging (e);
 
         }
@@ -137,7 +138,7 @@ public partial class View
     ///     Override <see cref="SetBorderStyle"/> to prevent the <see cref="BorderStyle"/> from changing.
     /// </remarks>
     /// <param name="e"></param>
-    protected void OnBorderStyleChanging (StateEventArgs<LineStyle> e)
+    protected void OnBorderStyleChanging (CancelEventArgs<LineStyle> e)
     {
         if (Border is null)
         {
@@ -193,7 +194,7 @@ public partial class View
     /// <summary>
     ///     Fired when the <see cref="BorderStyle"/> is changing. Allows the event to be cancelled.
     /// </summary>
-    public event EventHandler<StateEventArgs<LineStyle>> BorderStyleChanging;
+    public event EventHandler<CancelEventArgs<LineStyle>> BorderStyleChanging;
 
     /// <summary>
     ///     The <see cref="Adornment"/> inside of the view that offsets the <see cref="Viewport"/>

+ 2 - 1
Terminal.Gui/View/ViewEventArgs.cs

@@ -58,7 +58,8 @@ public class DrawEventArgs : EventArgs
 public class FocusEventArgs : EventArgs
 {
     /// <summary>Constructs.</summary>
-    /// <param name="leaving">The view that gets or loses focus.</param>
+    /// <param name="leaving">The view that is losing focus.</param>
+    /// <param name="entering">The view that is gaining focus.</param>
     public FocusEventArgs (View leaving, View entering) {
         Leaving = leaving;
         Entering = entering;

+ 2 - 0
Terminal.Gui/View/ViewKeyboard.cs

@@ -415,6 +415,8 @@ public partial class View
             return true;
         }
 
+        // TODO: NewKeyDownEvent returns bool. It should be bool? so state of InvokeCommand can be reflected up stack
+
         bool? handled = OnInvokingKeyBindings (keyEvent, KeyBindingScope.HotKey | KeyBindingScope.Focused);
 
         if (handled is { } && (bool)handled)

+ 282 - 330
Terminal.Gui/View/ViewMouse.cs

@@ -2,93 +2,77 @@
 
 namespace Terminal.Gui;
 
-/// <summary>
-/// Describes the highlight style of a view.
-/// </summary>
-[Flags]
-public enum HighlightStyle
-{
-    /// <summary>
-    /// No highlight.
-    /// </summary>
-    None = 0,
-
-#if HOVER
-    /// <summary>
-    /// The mouse is hovering over the view.
-    /// </summary>
-    Hover = 1,
-#endif
-
-    /// <summary>
-    /// The mouse is pressed within the <see cref="View.Viewport"/>.
-    /// </summary>
-    Pressed = 2,
-
-    /// <summary>
-    /// The mouse is pressed but moved outside the <see cref="View.Viewport"/>.
-    /// </summary>
-    PressedOutside = 4
-}
-
-/// <summary>
-/// Event arguments for the <see cref="View.Highlight"/> event.
-/// </summary>
-public class HighlightEventArgs : CancelEventArgs
+public partial class View
 {
-    /// <summary>
-    /// Constructs a new instance of <see cref="HighlightEventArgs"/>.
-    /// </summary>
-    /// <param name="style"></param>
-    public HighlightEventArgs (HighlightStyle style)
-    {
-        HighlightStyle = style;
-    }
+    [CanBeNull]
+    private ColorScheme _savedHighlightColorScheme;
 
     /// <summary>
-    /// The highlight style.
+    ///     Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
+    ///     to implement a custom highlight scheme or prevent the view from being highlighted.
     /// </summary>
-    public HighlightStyle HighlightStyle { get; }
-}
+    public event EventHandler<CancelEventArgs<HighlightStyle>> Highlight;
 
-public partial class View
-{
     /// <summary>
     ///     Gets or sets whether the <see cref="View"/> will be highlighted visually while the mouse button is
     ///     pressed.
     /// </summary>
     public HighlightStyle HighlightStyle { get; set; }
 
-    /// <summary>Gets or sets whether the <see cref="View"/> wants continuous button pressed events.</summary>
-    public virtual bool WantContinuousButtonPressed { get; set; }
+    /// <summary>Event fired when a mouse click occurs.</summary>
+    /// <remarks>
+    ///     <para>
+    ///         Fired when the mouse is either clicked or double-clicked. Check
+    ///         <see cref="MouseEvent.Flags"/> to see which button was clicked.
+    ///     </para>
+    ///     <para>
+    ///         The coordinates are relative to <see cref="View.Viewport"/>.
+    ///     </para>
+    /// </remarks>
+    public event EventHandler<MouseEventEventArgs> MouseClick;
 
-    /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
-    /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
-    public virtual bool WantMousePositionReports { get; set; }
+    /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
+    public event EventHandler<MouseEventEventArgs> MouseEnter;
+
+    /// <summary>Event fired when a mouse event occurs.</summary>
+    /// <remarks>
+    ///     <para>
+    ///         The coordinates are relative to <see cref="View.Viewport"/>.
+    ///     </para>
+    /// </remarks>
+    public event EventHandler<MouseEventEventArgs> MouseEvent;
+
+    /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
+    public event EventHandler<MouseEventEventArgs> MouseLeave;
 
     /// <summary>
-    ///     Called by <see cref="Application.OnMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
-    ///     then receive mouse events until <see cref="NewMouseLeaveEvent"/> is called indicating the mouse has left
-    ///     the view.
+    ///     Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
+    ///     event occurs.
     /// </summary>
     /// <remarks>
     ///     <para>
     ///         A view must be both enabled and visible to receive mouse events.
     ///     </para>
     ///     <para>
-    ///         This method calls <see cref="OnMouseEnter"/> to fire the event.
+    ///         This method calls <see cref="OnMouseEvent"/> to process the event. If the event is not handled, and one of the
+    ///         mouse buttons was clicked, it calls <see cref="OnMouseClick"/> to process the click.
     ///     </para>
     ///     <para>
     ///         See <see cref="SetHighlight"/> for more information.
     ///     </para>
+    ///     <para>
+    ///         If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, the <see cref="OnMouseClick"/> event
+    ///         will be invoked repeatedly while the button is pressed.
+    ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
     /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
-    internal bool? NewMouseEnterEvent (MouseEvent mouseEvent)
+    public bool? NewMouseEvent (MouseEvent mouseEvent)
     {
         if (!Enabled)
         {
-            return true;
+            // A disabled view should not eat mouse events
+            return false;
         }
 
         if (!CanBeVisible (this))
@@ -96,104 +80,112 @@ public partial class View
             return false;
         }
 
-        if (OnMouseEnter (mouseEvent) == true)
+        if (OnMouseEvent (mouseEvent))
         {
-            return true;
+            // 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;
         }
 
-#if HOVER
-        if (HighlightStyle.HasFlag(HighlightStyle.Hover))
+        if (HighlightStyle != HighlightStyle.None || WantContinuousButtonPressed)
         {
-            if (SetHighlight (HighlightStyle.Hover))
+            if (HandlePressed (mouseEvent))
             {
-                return true;
+                return mouseEvent.Handled;
+            }
+
+            if (HandleReleased (mouseEvent))
+            {
+                return mouseEvent.Handled;
+            }
+
+            if (HandleClicked (mouseEvent))
+            {
+                return mouseEvent.Handled;
             }
         }
-#endif
+
+        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 it's a click, and we didn't handle it, then we'll call OnMouseClick
+            // 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 false;
     }
 
+    /// <summary>Gets or sets whether the <see cref="View"/> wants continuous button pressed events.</summary>
+    public virtual bool WantContinuousButtonPressed { get; set; }
+
+    /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
+    /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
+    public virtual bool WantMousePositionReports { get; set; }
+
     /// <summary>
     ///     Called by <see cref="NewMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
     ///     then receive mouse events until <see cref="OnMouseLeave"/> is called indicating the mouse has left
     ///     the view.
     /// </summary>
     /// <remarks>
-    /// <para>
-    /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default enter behavior.
-    /// </para>
-    /// <para>
-    ///     The coordinates are relative to <see cref="View.Viewport"/>.
-    /// </para>
+    ///     <para>
+    ///         Override this method or subscribe to <see cref="MouseEnter"/> to change the default enter behavior.
+    ///     </para>
+    ///     <para>
+    ///         The coordinates are relative to <see cref="View.Viewport"/>.
+    ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
     /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
     protected internal virtual bool? OnMouseEnter (MouseEvent mouseEvent)
     {
-
         var args = new MouseEventEventArgs (mouseEvent);
         MouseEnter?.Invoke (this, args);
 
         return args.Handled;
     }
 
-    /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
-    public event EventHandler<MouseEventEventArgs> MouseEnter;
-
-
-    /// <summary>
-    ///     Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Viewport"/>. The view will
-    ///     then no longer receive mouse events.
-    /// </summary>
+    /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
     /// <remarks>
     ///     <para>
-    ///         A view must be both enabled and visible to receive mouse events.
-    ///     </para>
-    ///     <para>
-    ///         This method calls <see cref="OnMouseLeave"/> to fire the event.
-    ///     </para>
-    ///     <para>
-    ///         See <see cref="SetHighlight"/> for more information.
+    ///         The coordinates are relative to <see cref="View.Viewport"/>.
     ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
-    /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
-    internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
+    protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
     {
-        if (!Enabled)
-        {
-            return true;
-        }
-
-        if (!CanBeVisible (this))
-        {
-            return false;
-        }
+        var args = new MouseEventEventArgs (mouseEvent);
 
-        if (OnMouseLeave (mouseEvent) == true)      
-        {
-            return true;
-        }
-#if HOVER
-        if (HighlightStyle.HasFlag (HighlightStyle.Hover))
-        {
-            SetHighlight (HighlightStyle.None);
-        }
-#endif
+        MouseEvent?.Invoke (this, args);
 
-        return false;
+        return args.Handled;
     }
+
     /// <summary>
     ///     Called by <see cref="NewMouseEvent"/> when a mouse leaves <see cref="Viewport"/>. The view will
     ///     no longer receive mouse events.
     /// </summary>
     /// <remarks>
-    /// <para>
-    ///     Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
-    /// </para>
-    /// <para>
-    ///     The coordinates are relative to <see cref="View.Viewport"/>.
-    /// </para>
+    ///     <para>
+    ///         Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
+    ///     </para>
+    ///     <para>
+    ///         The coordinates are relative to <see cref="View.Viewport"/>.
+    ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
     /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
@@ -215,143 +207,90 @@ public partial class View
         return args.Handled;
     }
 
-    /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
-    public event EventHandler<MouseEventEventArgs> MouseLeave;
-
     /// <summary>
-    ///     Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
-    ///     event occurs.
+    ///     Called when the view is to be highlighted.
     /// </summary>
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
+    protected virtual bool? OnHighlight (CancelEventArgs<HighlightStyle> args)
+    {
+        Highlight?.Invoke (this, args);
+
+        if (args.Cancel)
+        {
+            return true;
+        }
+
+        Margin?.Highlight?.Invoke (this, args);
+
+        //args = new (highlight);
+        //Border?.Highlight?.Invoke (this, args);
+
+        //args = new (highlight);
+        //Padding?.Highlight?.Invoke (this, args);
+
+        return args.Cancel;
+    }
+
+    /// <summary>Invokes the MouseClick event.</summary>
     /// <remarks>
     ///     <para>
-    ///         A view must be both enabled and visible to receive mouse events.
-    ///     </para>
-    ///     <para>
-    ///         This method calls <see cref="OnMouseEvent"/> to process the event. If the event is not handled, and one of the
-    ///         mouse buttons was clicked, it calls <see cref="OnMouseClick"/> to process the click.
-    ///     </para>
-    ///     <para>
-    ///         See <see cref="SetHighlight"/> for more information.
-    ///     </para>
-    ///     <para>
-    ///         If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, the <see cref="OnMouseClick"/> event
-    ///         will be invoked repeatedly while the button is pressed.
+    ///         Called when the mouse is either clicked or double-clicked. Check
+    ///         <see cref="MouseEvent.Flags"/> to see which button was clicked.
     ///     </para>
     /// </remarks>
-    /// <param name="mouseEvent"></param>
-    /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
-    public bool? NewMouseEvent (MouseEvent mouseEvent)
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
+    protected bool OnMouseClick (MouseEventEventArgs args)
     {
         if (!Enabled)
         {
-            // A disabled view should not eat mouse events
-            return false;
-        }
-
-        if (!CanBeVisible (this))
-        {
-            return false;
+            // QUESTION: Is this right? Should a disabled view eat mouse clicks?
+            return args.Handled = true;
         }
 
-        if (OnMouseEvent (mouseEvent))
-        {
-            // 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;
-        }
+        MouseClick?.Invoke (this, args);
 
-        if (HighlightStyle != Gui.HighlightStyle.None || WantContinuousButtonPressed)
+        if (args.Handled)
         {
-            if (HandlePressed (mouseEvent))
-            {
-                return mouseEvent.Handled;
-            }
-
-            if (HandleReleased (mouseEvent))
-            {
-                return mouseEvent.Handled;
-            }
-
-            if (HandleClicked (mouseEvent))
-            {
-                return mouseEvent.Handled;
-            }
+            return true;
         }
 
-        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 (!HasFocus && CanFocus)
         {
-            // If it's a click, and we didn't handle it, then we'll call OnMouseClick
-            // 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));
+            args.Handled = true;
+            SetFocus ();
         }
 
-        return false;
+        return args.Handled;
     }
 
     /// <summary>
-    ///     For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
+    ///     For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
     ///     when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
     /// </summary>
     /// <remarks>
-    ///     <para>
-    ///         Marked internal just to support unit tests
-    ///     </para>
+    ///     Marked internal just to support unit tests
     /// </remarks>
     /// <param name="mouseEvent"></param>
-    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>    
-    private bool HandlePressed (MouseEvent mouseEvent)
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
+    internal bool HandleClicked (MouseEvent mouseEvent)
     {
-        if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
-            || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
-            || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
-            || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
+        if (Application.MouseGrabView == this
+            && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
+                || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
+                || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
+                || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
         {
-            // The first time we get pressed event, grab the mouse and set focus
-            if (Application.MouseGrabView != this)
-            {
-                Application.GrabMouse (this);
-
-                if (!HasFocus && CanFocus)
-                {
-                    // Set the focus, but don't invoke Accept
-                    SetFocus ();
-                }
-
-                mouseEvent.Handled = true;
-            }
+            // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
+            Application.UngrabMouse ();
 
-            if (Viewport.Contains (mouseEvent.Position))
-            {
-                if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None) == true)
-                {
-                    return true;
-                }
-            }
-            else
+            if (SetHighlight (HighlightStyle.None))
             {
-                if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None) == true)
-
-                {
-                    return true;
-                }
+                return true;
             }
 
-            if (WantContinuousButtonPressed && Application.MouseGrabView == this)
+            // If mouse is still in bounds, click
+            if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
             {
-                // If this is not the first pressed event, click
                 return OnMouseClick (new (mouseEvent));
             }
 
@@ -389,45 +328,95 @@ public partial class View
     }
 
     /// <summary>
-    ///     For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
-    ///     when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
+    ///     Called by <see cref="Application.OnMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
+    ///     then receive mouse events until <see cref="NewMouseLeaveEvent"/> is called indicating the mouse has left
+    ///     the view.
     /// </summary>
     /// <remarks>
-    ///     Marked internal just to support unit tests
+    ///     <para>
+    ///         A view must be both enabled and visible to receive mouse events.
+    ///     </para>
+    ///     <para>
+    ///         This method calls <see cref="OnMouseEnter"/> to fire the event.
+    ///     </para>
+    ///     <para>
+    ///         See <see cref="SetHighlight"/> for more information.
+    ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
-    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
-    internal bool HandleClicked (MouseEvent mouseEvent)
+    /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
+    internal bool? NewMouseEnterEvent (MouseEvent 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)))
+        if (!Enabled)
         {
-            // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
-            Application.UngrabMouse ();
+            return true;
+        }
 
-            if (SetHighlight (HighlightStyle.None))
+        if (!CanBeVisible (this))
+        {
+            return false;
+        }
+
+        if (OnMouseEnter (mouseEvent) == true)
+        {
+            return true;
+        }
+
+#if HOVER
+        if (HighlightStyle.HasFlag(HighlightStyle.Hover))
+        {
+            if (SetHighlight (HighlightStyle.Hover))
             {
                 return true;
             }
+        }
+#endif
+        return false;
+    }
 
-            // If mouse is still in bounds, click
-            if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
-            {
-                return OnMouseClick (new (mouseEvent));
-            }
+    /// <summary>
+    ///     Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Viewport"/>. The view will
+    ///     then no longer receive mouse events.
+    /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///         A view must be both enabled and visible to receive mouse events.
+    ///     </para>
+    ///     <para>
+    ///         This method calls <see cref="OnMouseLeave"/> to fire the event.
+    ///     </para>
+    ///     <para>
+    ///         See <see cref="SetHighlight"/> for more information.
+    ///     </para>
+    /// </remarks>
+    /// <param name="mouseEvent"></param>
+    /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
+    internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
+    {
+        if (!Enabled)
+        {
+            return true;
+        }
 
-            return mouseEvent.Handled = true;
+        if (!CanBeVisible (this))
+        {
+            return false;
+        }
+
+        if (OnMouseLeave (mouseEvent))
+        {
+            return true;
+        }
+#if HOVER
+        if (HighlightStyle.HasFlag (HighlightStyle.Hover))
+        {
+            SetHighlight (HighlightStyle.None);
         }
+#endif
 
         return false;
     }
 
-    [CanBeNull]
-    private ColorScheme _savedHighlightColorScheme;
-
     /// <summary>
     ///     Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.
     /// </summary>
@@ -443,8 +432,7 @@ public partial class View
     ///     </para>
     /// </remarks>
     /// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
-
-    internal bool SetHighlight (HighlightStyle style)
+    internal bool SetHighlight (HighlightStyle newHighlightStyle)
     {
         // TODO: Make the highlight colors configurable
         if (!CanFocus)
@@ -453,7 +441,10 @@ public partial class View
         }
 
         // Enable override via virtual method and/or event
-        if (OnHighlight (style) == true)
+        HighlightStyle copy = HighlightStyle;
+        var args = new CancelEventArgs<HighlightStyle> (ref copy, ref newHighlightStyle);
+
+        if (OnHighlight (args) == true)
         {
             return true;
         }
@@ -474,8 +465,8 @@ public partial class View
 
             return true;
         }
-#endif 
-        if (style.HasFlag (HighlightStyle.Pressed) || style.HasFlag (HighlightStyle.PressedOutside))
+#endif
+        if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
         {
             if (_savedHighlightColorScheme is null && ColorScheme is { })
             {
@@ -486,7 +477,7 @@ public partial class View
                     var cs = new ColorScheme (ColorScheme)
                     {
                         // Highlight the foreground focus color
-                        Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ()),
+                        Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ())
                     };
                     ColorScheme = cs;
                 }
@@ -500,12 +491,12 @@ public partial class View
                     ColorScheme = cs;
                 }
             }
+
             // Return false since we don't want to eat the event
             return false;
         }
 
-
-        if (style == HighlightStyle.None)
+        if (args.NewValue == HighlightStyle.None)
         {
             // Unhighlight
             if (_savedHighlightColorScheme is { })
@@ -519,103 +510,64 @@ public partial class View
     }
 
     /// <summary>
-    ///     Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
-    ///     to implement a custom highlight scheme or prevent the view from being highlighted.
-    /// </summary>
-    public event EventHandler<HighlightEventArgs> Highlight;
-
-    /// <summary>
-    ///     Called when the view is to be highlighted.
+    ///     For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
+    ///     when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
     /// </summary>
-    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
-    protected virtual bool? OnHighlight (HighlightStyle highlight)
-    {
-        HighlightEventArgs args = new (highlight);
-        Highlight?.Invoke (this, args);
-
-        if (args.Cancel)
-        {
-            return true;
-        }
-
-        args = new (highlight);
-        Margin?.Highlight?.Invoke (this, args);
-
-        //args = new (highlight);
-        //Border?.Highlight?.Invoke (this, args);
-
-        //args = new (highlight);
-        //Padding?.Highlight?.Invoke (this, args);
-
-        return args.Cancel;
-    }
-
-    /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
     /// <remarks>
     ///     <para>
-    ///         The coordinates are relative to <see cref="View.Viewport"/>.
+    ///         Marked internal just to support unit tests
     ///     </para>
     /// </remarks>
     /// <param name="mouseEvent"></param>
     /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
-    protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
+    private bool HandlePressed (MouseEvent mouseEvent)
     {
-        var args = new MouseEventEventArgs (mouseEvent);
-
-        MouseEvent?.Invoke (this, args);
+        if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
+            || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
+            || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
+            || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
+        {
+            // The first time we get pressed event, grab the mouse and set focus
+            if (Application.MouseGrabView != this)
+            {
+                Application.GrabMouse (this);
 
-        return args.Handled;
-    }
+                if (!HasFocus && CanFocus)
+                {
+                    // Set the focus, but don't invoke Accept
+                    SetFocus ();
+                }
 
-    /// <summary>Event fired when a mouse event occurs.</summary>
-    /// <remarks>
-    ///     <para>
-    ///         The coordinates are relative to <see cref="View.Viewport"/>.
-    ///     </para>
-    /// </remarks>
-    public event EventHandler<MouseEventEventArgs> MouseEvent;
+                mouseEvent.Handled = true;
+            }
 
-    /// <summary>Invokes the MouseClick event.</summary>
-    /// <remarks>
-    ///     <para>
-    ///         Called when the mouse is either clicked or double-clicked. Check
-    ///         <see cref="MouseEvent.Flags"/> to see which button was clicked.
-    ///     </para>
-    /// </remarks>
-    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
-    protected bool OnMouseClick (MouseEventEventArgs args)
-    {
-        if (!Enabled)
-        {
-            // QUESTION: Is this right? Should a disabled view eat mouse clicks?
-            return args.Handled = true;
-        }
+            if (Viewport.Contains (mouseEvent.Position))
+            {
+                if (this is not Adornment
+                    && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None))
+                {
+                    return true;
+                }
+            }
+            else
+            {
+                if (this is not Adornment
+                    && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None))
 
-        MouseClick?.Invoke (this, args);
+                {
+                    return true;
+                }
+            }
 
-        if (args.Handled)
-        {
-            return true;
-        }
+            if (WantContinuousButtonPressed && Application.MouseGrabView == this)
+            {
+                // If this is not the first pressed event, click
+                return OnMouseClick (new (mouseEvent));
+            }
 
-        if (!HasFocus && CanFocus)
-        {
-            args.Handled = true;
-            SetFocus ();
+            return mouseEvent.Handled = true;
         }
 
-        return args.Handled;
+        return false;
     }
-
-    /// <summary>Event fired when a mouse click occurs.</summary>
-    /// <remarks>
-    ///     <para>
-    ///         Fired when the mouse is either clicked or double-clicked. Check
-    ///         <see cref="MouseEvent.Flags"/> to see which button was clicked.
-    ///     </para>
-    ///     <para>
-    ///         The coordinates are relative to <see cref="View.Viewport"/>.
-    ///     </para>
-    /// </remarks>
-    public event EventHandler<MouseEventEventArgs> MouseClick;
 }

+ 7 - 9
Terminal.Gui/View/ViewText.cs

@@ -1,4 +1,4 @@
-using static Terminal.Gui.SpinnerStyle;
+#nullable enable
 
 namespace Terminal.Gui;
 
@@ -69,24 +69,22 @@ public partial class View
                 Id = _text;
             }
 #endif
-            OnTextChanged (old, Text);
+            OnTextChanged ();
         }
     }
 
     /// <summary>
     /// Called when the <see cref="Text"/> has changed. Fires the <see cref="TextChanged"/> event.
     /// </summary>
-    /// <param name="oldValue"></param>
-    /// <param name="newValue"></param>
-    public void OnTextChanged (string oldValue, string newValue)
+    public void OnTextChanged ()
     {
-        TextChanged?.Invoke (this, new StateEventArgs<string> (oldValue, newValue));
+        TextChanged?.Invoke (this, EventArgs.Empty);
     }
 
     /// <summary>
     ///     Text changed event, raised when the text has changed.
     /// </summary>
-    public event EventHandler<StateEventArgs<string>> TextChanged;
+    public event EventHandler? TextChanged;
 
     /// <summary>
     ///     Gets or sets how the View's <see cref="Text"/> is aligned horizontally when drawn. Changing this property will
@@ -193,8 +191,8 @@ public partial class View
 
         // TODO: This is a hack. Figure out how to move this into DimDimAuto
         // Use _width & _height instead of Width & Height to avoid debug spew
-        DimAuto widthAuto = _width as DimAuto;
-        DimAuto heightAuto = _height as DimAuto;
+        DimAuto? widthAuto = _width as DimAuto;
+        DimAuto? heightAuto = _height as DimAuto;
         if ((widthAuto is { } && widthAuto.Style.FastHasFlags (DimAutoStyle.Text))
             || (heightAuto is { } && heightAuto.Style.FastHasFlags (DimAutoStyle.Text)))
         {

+ 2 - 2
Terminal.Gui/Views/Button.cs

@@ -110,9 +110,9 @@ public class Button : View
         e.Handled = InvokeCommand (Command.HotKey) == true;
     }
 
-    private void Button_TitleChanged (object sender, StateEventArgs<string> e)
+    private void Button_TitleChanged (object sender, EventArgs<string> e)
     {
-        base.Text = e.NewValue;
+        base.Text = e.CurrentValue;
         TextFormatter.HotKeySpecifier = HotKeySpecifier;
     }
 

+ 87 - 56
Terminal.Gui/Views/CheckBox.cs

@@ -1,32 +1,35 @@
 #nullable enable
 namespace Terminal.Gui;
 
-/// <summary>The <see cref="CheckBox"/> <see cref="View"/> shows an on/off toggle that the user can set</summary>
+/// <summary>
+///     Represents the state of a <see cref="CheckBox"/>.
+/// </summary>
+public enum CheckState
+{
+    None,
+    Checked,
+    UnChecked
+}
+
+/// <summary>Shows a check box that can be toggled.</summary>
 public class CheckBox : View
 {
-    private readonly Rune _charChecked;
-    private readonly Rune _charNullChecked;
-    private readonly Rune _charUnChecked;
-    private bool _allowNullChecked;
-    private bool? _checked = false;
+    private bool _allowNone;
+    private CheckState _checked = CheckState.UnChecked;
 
     /// <summary>
     ///     Initializes a new instance of <see cref="CheckBox"/>.
     /// </summary>
     public CheckBox ()
     {
-        _charNullChecked = Glyphs.NullChecked;
-        _charChecked = Glyphs.Checked;
-        _charUnChecked = Glyphs.UnChecked;
-
         Width = Dim.Auto (DimAutoStyle.Text);
         Height = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 1);
 
         CanFocus = true;
 
         // Things this view knows how to do
-        AddCommand (Command.Accept, OnToggled);
-        AddCommand (Command.HotKey, OnToggled);
+        AddCommand (Command.Accept, OnToggle);
+        AddCommand (Command.HotKey, OnToggle);
 
         // Default keybindings for this view
         KeyBindings.Add (Key.Space, Command.Accept);
@@ -39,12 +42,12 @@ public class CheckBox : View
 
     private void CheckBox_MouseClick (object? sender, MouseEventEventArgs e)
     {
-        e.Handled = OnToggled () == true;
+        e.Handled = OnToggle () == true;
     }
 
-    private void Checkbox_TitleChanged (object? sender, StateEventArgs<string> e)
+    private void Checkbox_TitleChanged (object? sender, EventArgs<string> e)
     {
-        base.Text = e.NewValue;
+        base.Text = e.CurrentValue;
         TextFormatter.HotKeySpecifier = HotKeySpecifier;
     }
 
@@ -63,26 +66,49 @@ public class CheckBox : View
     }
 
     /// <summary>
-    ///     If <see langword="true"/> allows <see cref="Checked"/> to be null, true or false. If <see langword="false"/>
-    ///     only allows <see cref="Checked"/> to be true or false.
+    ///     If <see langword="true"/> allows <see cref="State"/> to be <see cref="CheckState.None"/>.
     /// </summary>
-    public bool AllowNullChecked
+    public bool AllowCheckStateNone
     {
-        get => _allowNullChecked;
+        get => _allowNone;
         set
         {
-            _allowNullChecked = value;
-            Checked ??= false;
+            if (_allowNone == value)
+            {
+                return;
+            }
+            _allowNone = value;
+
+            if (State == CheckState.None)
+            {
+                State = CheckState.UnChecked;
+            }
         }
     }
 
-    /// <summary>The state of the <see cref="CheckBox"/></summary>
-    public bool? Checked
+    /// <summary>
+    ///     The state of the <see cref="CheckBox"/>.
+    /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///        If <see cref="AllowCheckStateNone"/> is <see langword="true"/> and <see cref="CheckState.None"/>, the <see cref="CheckBox"/>
+    ///        will display the <c>ConfigurationManager.Glyphs.CheckStateNone</c> character (☒).
+    ///     </para>
+    ///     <para>
+    ///        If <see cref="CheckState.UnChecked"/>, the <see cref="CheckBox"/>
+    ///        will display the <c>ConfigurationManager.Glyphs.CheckStateUnChecked</c> character (☐).
+    ///     </para>
+    ///     <para>
+    ///        If <see cref="CheckState.Checked"/>, the <see cref="CheckBox"/>
+    ///        will display the <c>ConfigurationManager.Glyphs.CheckStateChecked</c> character (☑).
+    ///     </para>
+    /// </remarks>
+    public CheckState State
     {
         get => _checked;
         set
         {
-            if (value is null && !AllowNullChecked)
+            if (_checked == value || (value is CheckState.None && !AllowCheckStateNone))
             {
                 return;
             }
@@ -93,38 +119,42 @@ public class CheckBox : View
         }
     }
 
-    /// <summary>Called when the <see cref="Checked"/> property changes. Invokes the <see cref="Toggled"/> event.</summary>
+    /// <summary>Called when the <see cref="State"/> property changes. Invokes the cancelable <see cref="Toggle"/> event.</summary>
+    /// <remarks>
+    /// </remarks>
+    /// <returns>If <see langword="true"/> the <see cref="Toggle"/> event was canceled.</returns>
     /// <remarks>
+    ///     Toggling cycles through the states <see cref="CheckState.None"/>, <see cref="CheckState.Checked"/>, and <see cref="CheckState.UnChecked"/>.
     /// </remarks>
-    /// <returns>If <see langword="true"/> the <see cref="Toggled"/> event was canceled.</returns>
-    public bool? OnToggled ()
+    public bool? OnToggle ()
     {
-        StateEventArgs<bool?> e = new (Checked, false);
+        CheckState oldValue = State;
+        CancelEventArgs<CheckState> e = new (ref _checked, ref oldValue);
 
-        if (AllowNullChecked)
+        switch (State)
         {
-            switch (Checked)
-            {
-                case null:
-                    e.NewValue = true;
+            case CheckState.None:
+                e.NewValue = CheckState.Checked;
 
-                    break;
-                case true:
-                    e.NewValue = false;
+                break;
+            case CheckState.Checked:
+                e.NewValue = CheckState.UnChecked;
 
-                    break;
-                case false:
-                    e.NewValue = null;
+                break;
+            case CheckState.UnChecked:
+                if (AllowCheckStateNone)
+                {
+                    e.NewValue = CheckState.None;
+                }
+                else
+                {
+                    e.NewValue = CheckState.Checked;
+                }
 
-                    break;
-            }
-        }
-        else
-        {
-            e.NewValue = !Checked;
+                break;
         }
 
-        Toggled?.Invoke (this, e);
+        Toggle?.Invoke (this, e);
         if (e.Cancel)
         {
             return e.Cancel;
@@ -136,18 +166,18 @@ public class CheckBox : View
             return true;
         }
 
-        Checked = e.NewValue;
+        State = e.NewValue;
 
         return true;
     }
 
-    /// <summary>Toggled event, raised when the <see cref="CheckBox"/> is toggled.</summary>
+    /// <summary>Toggle event, raised when the <see cref="CheckBox"/> is toggled.</summary>
     /// <remarks>
     /// <para>
     ///    This event can be cancelled. If cancelled, the <see cref="CheckBox"/> will not change its state.
     /// </para>
     /// </remarks>
-    public event EventHandler<StateEventArgs<bool?>>? Toggled;
+    public event EventHandler<CancelEventArgs<CheckState>>? Toggle;
 
     /// <inheritdoc/>
     protected override void UpdateTextFormatterText ()
@@ -157,23 +187,24 @@ public class CheckBox : View
             case Alignment.Start:
             case Alignment.Center:
             case Alignment.Fill:
-                TextFormatter.Text = $"{GetCheckedState ()} {Text}";
+                TextFormatter.Text = $"{GetCheckedGlyph ()} {Text}";
 
                 break;
             case Alignment.End:
-                TextFormatter.Text = $"{Text} {GetCheckedState ()}";
+                TextFormatter.Text = $"{Text} {GetCheckedGlyph ()}";
 
                 break;
         }
     }
 
-    private Rune GetCheckedState ()
+    private Rune GetCheckedGlyph ()
     {
-        return Checked switch
+        return State switch
         {
-            true => _charChecked,
-            false => _charUnChecked,
-            var _ => _charNullChecked
+            CheckState.Checked => Glyphs.CheckStateChecked,
+            CheckState.UnChecked => Glyphs.CheckStateUnChecked,
+            CheckState.None => Glyphs.CheckStateNone,
+            _ => throw new ArgumentOutOfRangeException ()
         };
     }
 }

+ 29 - 18
Terminal.Gui/Views/ComboBox.cs

@@ -7,6 +7,7 @@
 
 using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.Diagnostics;
 
 namespace Terminal.Gui;
 
@@ -68,7 +69,7 @@ public class ComboBox : View
 
                      SetNeedsLayout ();
                      SetNeedsDisplay ();
-                     Search_Changed (this, new StateEventArgs<string> (string.Empty, Text));
+                     ShowHideList (Text);
                  };
 
         // Things this view knows how to do
@@ -185,15 +186,13 @@ public class ComboBox : View
             // Only need to refresh list if its been added to a container view
             if (SuperView is { } && SuperView.Subviews.Contains (this))
             {
-                SelectedItem = -1;
-                _search.Text = string.Empty;
-                Search_Changed (this, new StateEventArgs<string> (string.Empty, _search.Text));
+                Text = string.Empty;
                 SetNeedsDisplay ();
             }
         }
     }
 
-    /// <summary>The currently selected list item</summary>
+    /// <summary>The text of the currently selected list item</summary>
     public new string Text
     {
         get => _text;
@@ -243,7 +242,7 @@ public class ComboBox : View
     public event EventHandler Expanded;
 
     /// <inheritdoc/>
-    protected internal override bool OnMouseEvent  (MouseEvent me)
+    protected internal override bool OnMouseEvent (MouseEvent me)
     {
         if (me.Position.X == Viewport.Right - 1
             && me.Position.Y == Viewport.Top
@@ -423,12 +422,12 @@ public class ComboBox : View
 
             if (SelectedItem > -1 && _listview.Source?.Count > 0)
             {
-                _search.Text = _text = _listview.Source.ToList () [SelectedItem].ToString ();
+                Text = _listview.Source.ToList () [SelectedItem]?.ToString ();
             }
         }
         else if (!ReadOnly)
         {
-            _search.Text = _text = "";
+            Text = string.Empty;
             _selectedItem = _lastSelectedItem;
             OnSelectedChanged ();
         }
@@ -658,9 +657,9 @@ public class ComboBox : View
     }
 
     // Tell TextField to handle Accept Command (Enter)
-    void Search_Accept (object sender, CancelEventArgs e) { e.Cancel = true; }
+    void Search_Accept (object sender, HandledEventArgs e) { e.Handled = true; }
 
-    private void Search_Changed (object sender, StateEventArgs<string> e)
+    private void Search_Changed (object sender, EventArgs e)
     {
         if (_source is null)
         {
@@ -668,13 +667,18 @@ public class ComboBox : View
             return;
         }
 
-        if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (e.OldValue))
+        ShowHideList (Text);
+    }
+
+    private void ShowHideList (string oldText)
+    {
+        if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (oldText))
         {
             ResetSearchSet ();
         }
-        else if (_search.Text != e.OldValue)
+        else if (_search.Text != oldText)
         {
-            if (_search.Text.Length < e.OldValue.Length)
+            if (_search.Text.Length < oldText.Length)
             {
                 _selectedItem = -1;
             }
@@ -730,7 +734,7 @@ public class ComboBox : View
 
         SetValue (_listview.SelectedItem > -1 ? _searchSet [_listview.SelectedItem] : _text);
         _search.CursorPosition = _search.Text.GetColumns ();
-        Search_Changed (this, new StateEventArgs<string> (_search.Text, _search.Text));
+        ShowHideList (Text);
         OnOpenSelectedItem ();
         Reset (true);
         HideList ();
@@ -756,11 +760,18 @@ public class ComboBox : View
         _listview.ResumeSuspendCollectionChangedEvent ();
     }
 
-    private void SetSearchText (string value) { _search.Text = _text = value; }
+    // Sets the search text field Text as well as our own Text property
+    private void SetSearchText (string value)
+    {
+        _search.Text = value;
+        _text = value;
+    }
 
     private void SetValue (object text, bool isFromSelectedItem = false)
     {
+        // TOOD: THe fact we have to suspend events to change the text makes this feel very hacky.
         _search.TextChanged -= Search_Changed;
+        // Note we set _text, to avoid set_Text from setting _search.Text again
         _text = _search.Text = text.ToString ();
         _search.CursorPosition = 0;
         _search.TextChanged += Search_Changed;
@@ -813,7 +824,7 @@ public class ComboBox : View
             set => _hideDropdownListOnClick = WantContinuousButtonPressed = value;
         }
 
-        protected internal override bool OnMouseEvent  (MouseEvent me)
+        protected internal override bool OnMouseEvent (MouseEvent me)
         {
             var res = false;
             bool isMousePositionValid = IsMousePositionValid (me);
@@ -918,8 +929,8 @@ public class ComboBox : View
                     if (AllowsMarking)
                     {
                         Driver.AddRune (
-                                        Source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.Checked : Glyphs.Selected :
-                                        AllowsMultipleSelection ? Glyphs.UnChecked : Glyphs.UnSelected
+                                        Source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
+                                        AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
                                        );
                         Driver.AddRune ((Rune)' ');
                     }

+ 1 - 1
Terminal.Gui/Views/DateField.cs

@@ -182,7 +182,7 @@ public class DateField : TextField
         }
     }
 
-    private void DateField_Changing (object sender, StateEventArgs<string> e)
+    private void DateField_Changing (object sender, CancelEventArgs<string> e)
     {
         try
         {

+ 2 - 2
Terminal.Gui/Views/Label.cs

@@ -31,9 +31,9 @@ public class Label : View
         e.Handled = InvokeCommand (Command.HotKey) == true;
     }
 
-    private void Label_TitleChanged (object sender, StateEventArgs<string> e)
+    private void Label_TitleChanged (object sender, EventArgs<string> e)
     {
-        base.Text = e.NewValue;
+        base.Text = e.CurrentValue;
         TextFormatter.HotKeySpecifier = HotKeySpecifier;
     }
 

+ 2 - 2
Terminal.Gui/Views/ListView.cs

@@ -724,8 +724,8 @@ public class ListView : View
                 if (_allowsMarking)
                 {
                     Driver.AddRune (
-                                    _source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.Checked : Glyphs.Selected :
-                                    AllowsMultipleSelection ? Glyphs.UnChecked : Glyphs.UnSelected
+                                    _source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
+                                    AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
                                    );
                     Driver.AddRune ((Rune)' ');
                 }

+ 3 - 3
Terminal.Gui/Views/Menu/Menu.cs

@@ -447,14 +447,14 @@ internal sealed class Menu : View
             }
 
             string textToDraw = null;
-            Rune nullCheckedChar = Glyphs.NullChecked;
+            Rune nullCheckedChar = Glyphs.CheckStateNone;
             Rune checkChar = Glyphs.Selected;
             Rune uncheckedChar = Glyphs.UnSelected;
 
             if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked))
             {
-                checkChar = Glyphs.Checked;
-                uncheckedChar = Glyphs.UnChecked;
+                checkChar = Glyphs.CheckStateChecked;
+                uncheckedChar = Glyphs.CheckStateUnChecked;
             }
 
             // Support Checked even though CheckType wasn't set

+ 2 - 2
Terminal.Gui/Views/RadioGroup.cs

@@ -84,7 +84,7 @@ public class RadioGroup : View
                     {
                         SelectedItem = _cursor;
 
-                        return !OnAccept ();
+                        return OnAccept () is true or null;
                     }
                    );
 
@@ -97,7 +97,7 @@ public class RadioGroup : View
                         {
                             SelectedItem = (int)ctx.KeyBinding?.Context!;
 
-                            return !OnAccept();
+                            return OnAccept () is true or null;
                         }
 
                         return true;

+ 4 - 4
Terminal.Gui/Views/Shortcut.cs

@@ -295,9 +295,9 @@ public class Shortcut : View
 
     private Color? _savedForeColor;
 
-    private void Shortcut_Highlight (object sender, HighlightEventArgs e)
+    private void Shortcut_Highlight (object sender, CancelEventArgs<HighlightStyle> e)
     {
-        if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
+        if (e.CurrentValue.HasFlag (HighlightStyle.Pressed))
         {
             if (!_savedForeColor.HasValue)
             {
@@ -311,7 +311,7 @@ public class Shortcut : View
             base.ColorScheme = cs;
         }
 
-        if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
+        if (e.CurrentValue == HighlightStyle.None && _savedForeColor.HasValue)
         {
             var cs = new ColorScheme (base.ColorScheme)
             {
@@ -446,7 +446,7 @@ public class Shortcut : View
     CommandView.Y = 0; //Pos.Center ();
 }
 
-private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
+private void Shortcut_TitleChanged (object sender, EventArgs<string> e)
 {
     // If the Title changes, update the CommandView text.
     // This is a helper to make it easier to set the CommandView text.

+ 4 - 4
Terminal.Gui/Views/TableView/CheckBoxTableSourceWrapper.cs

@@ -33,9 +33,9 @@ public abstract class CheckBoxTableSourceWrapperBase : ITableSource
     }
 
     /// <summary>
-    ///     Gets or sets the character to use for checked entries. Defaults to <see cref="GlyphDefinitions.Checked"/>
+    ///     Gets or sets the character to use for checked entries. Defaults to <see cref="GlyphDefinitions.CheckStateChecked"/>
     /// </summary>
-    public Rune CheckedRune { get; set; } = Glyphs.Checked;
+    public Rune CheckedRune { get; set; } = Glyphs.CheckStateChecked;
 
     /// <summary>
     ///     Gets or sets the character to use for checked entry when <see cref="UseRadioButtons"/> is true. Defaults to
@@ -50,9 +50,9 @@ public abstract class CheckBoxTableSourceWrapperBase : ITableSource
     public Rune RadioUnCheckedRune { get; set; } = Glyphs.UnSelected;
 
     /// <summary>
-    ///     Gets or sets the character to use for UnChecked entries. Defaults to <see cref="GlyphDefinitions.UnChecked"/>
+    ///     Gets or sets the character to use for UnChecked entries. Defaults to <see cref="GlyphDefinitions.CheckStateUnChecked"/>
     /// </summary>
-    public Rune UnCheckedRune { get; set; } = Glyphs.UnChecked;
+    public Rune UnCheckedRune { get; set; } = Glyphs.CheckStateUnChecked;
 
     /// <summary>Gets or sets whether to only allow a single row to be toggled at once (Radio button).</summary>
     public bool UseRadioButtons { get; set; }

+ 17 - 14
Terminal.Gui/Views/TextField.cs

@@ -334,9 +334,9 @@ public class TextField : View
                     }
                    );
 
-        // OnAccept returns true if the event is canceled.
-        // By Default pressing ENTER should be ignored (Invoke(Command.Accept) should return false).
-        AddCommand (Command.Accept, () => OnAccept () != true);
+        // By Default pressing ENTER should be ignored (OnAccept will return false or null). Only cancel if the
+        // event was fired and set Cancel = true.
+        AddCommand (Command.Accept, () => OnAccept () == false);
 
         // Default keybindings for this view
         // We follow this as closely as possible: https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
@@ -532,9 +532,11 @@ public class TextField : View
                 return;
             }
 
-            StateEventArgs<string> newText = OnTextChanging (value.Replace ("\t", "").Split ("\n") [0]);
+            string newText = value.Replace ("\t", "").Split ("\n") [0];
+            CancelEventArgs<string> args = new (ref oldText, ref newText);
+            OnTextChanging (args);
 
-            if (newText.Cancel)
+            if (args.Cancel)
             {
                 if (_cursorPosition > _text.Count)
                 {
@@ -545,7 +547,9 @@ public class TextField : View
             }
 
             ClearAllSelection ();
-            _text = newText.NewValue.EnumerateRunes ().ToList ();
+
+            // Note we use NewValue here; TextChanging subscribers may have changed it
+            _text = args.NewValue.EnumerateRunes ().ToList ();
 
             if (!Secret && !_historyText.IsFromHistory)
             {
@@ -561,7 +565,7 @@ public class TextField : View
                                  );
             }
 
-            OnTextChanged (oldText, StringExtensions.ToString (_text));
+            OnTextChanged ();
 
             ProcessAutocomplete ();
 
@@ -1101,14 +1105,13 @@ public class TextField : View
     }
 
     /// <summary>Virtual method that invoke the <see cref="TextChanging"/> event if it's defined.</summary>
-    /// <param name="newText">The new text to be replaced.</param>
-    /// <returns>Returns the <see cref="StringEventArgs"/></returns>
-    public virtual StateEventArgs<string> OnTextChanging (string newText)
+    /// <param name="args">The event arguments..</param>
+    /// <returns><see langword="true"/> if the event was cancelled.</returns>
+    public bool OnTextChanging (CancelEventArgs<string> args)
     {
-        StateEventArgs<string> ev = new (string.Empty, newText);
-        TextChanging?.Invoke (this, ev);
+        TextChanging?.Invoke (this, args);
 
-        return ev;
+        return args.Cancel;
     }
 
     /// <summary>Paste the selected text from the clipboard.</summary>
@@ -1195,7 +1198,7 @@ public class TextField : View
     //public event EventHandler<StateEventArgs<string>> TextChanged;
 
     /// <summary>Changing event, raised before the <see cref="Text"/> changes and can be canceled or changing the new text.</summary>
-    public event EventHandler<StateEventArgs<string>> TextChanging;
+    public event EventHandler<CancelEventArgs<string>> TextChanging;
 
     /// <summary>Undoes the latest changes.</summary>
     public void Undo ()

+ 11 - 11
Terminal.Gui/Views/TextValidateField.cs

@@ -64,8 +64,8 @@ namespace Terminal.Gui
 
             /// <summary>Method that invoke the <see cref="TextChanged"/> event if it's defined.</summary>
             /// <param name="oldValue">The previous text before replaced.</param>
-            /// <returns>Returns the <see cref="StringEventArgs"/></returns>
-            void OnTextChanged (StringEventArgs oldValue);
+            /// <returns>Returns the <see cref="EventArgs{T}"/></returns>
+            void OnTextChanged (EventArgs<string> oldValue);
 
             /// <summary>
             ///     Changed event, raised when the text has changed.
@@ -74,7 +74,7 @@ namespace Terminal.Gui
             ///         <see cref="string"/> containing the old value.
             ///     </remarks>
             /// </summary>
-            event EventHandler<StringEventArgs> TextChanged;
+            event EventHandler<EventArgs<string>> TextChanged;
         }
 
         //////////////////////////////////////////////////////////////////////////////
@@ -125,7 +125,7 @@ namespace Terminal.Gui
             }
 
             /// <inheritdoc/>
-            public event EventHandler<StringEventArgs> TextChanged;
+            public event EventHandler<EventArgs<string>> TextChanged;
 
             /// <inheritdoc/>
             public string Text
@@ -206,7 +206,7 @@ namespace Terminal.Gui
 
                 if (result)
                 {
-                    OnTextChanged (new StringEventArgs { NewValue = oldValue });
+                    OnTextChanged (new EventArgs<string> (ref oldValue));
                 }
 
                 return result;
@@ -220,14 +220,14 @@ namespace Terminal.Gui
 
                 if (result)
                 {
-                    OnTextChanged (new StringEventArgs { NewValue = oldValue });
+                    OnTextChanged (new EventArgs<string> (ref oldValue));
                 }
 
                 return result;
             }
 
             /// <inheritdoc/>
-            public void OnTextChanged (StringEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); }
+            public void OnTextChanged (EventArgs<string> args) { TextChanged?.Invoke (this, args); }
         }
 
         #endregion
@@ -260,7 +260,7 @@ namespace Terminal.Gui
             public bool ValidateOnInput { get; set; } = true;
 
             /// <inheritdoc/>
-            public event EventHandler<StringEventArgs> TextChanged;
+            public event EventHandler<EventArgs<string>> TextChanged;
 
             /// <inheritdoc/>
             public string Text
@@ -333,7 +333,7 @@ namespace Terminal.Gui
                 {
                     string oldValue = Text;
                     _text.RemoveAt (pos);
-                    OnTextChanged (new StringEventArgs { NewValue = Text, OldValue = oldValue });
+                    OnTextChanged (new EventArgs<string> (ref oldValue));
                 }
 
                 return true;
@@ -349,7 +349,7 @@ namespace Terminal.Gui
                 {
                     string oldValue = Text;
                     _text.Insert (pos, (Rune)ch);
-                    OnTextChanged (new StringEventArgs { NewValue = Text, OldValue = oldValue });
+                    OnTextChanged (new EventArgs<string> (ref oldValue));
 
                     return true;
                 }
@@ -358,7 +358,7 @@ namespace Terminal.Gui
             }
 
             /// <inheritdoc/>
-            public void OnTextChanged (StringEventArgs oldValue) { TextChanged?.Invoke (this, oldValue); }
+            public void OnTextChanged (EventArgs<string> args) { TextChanged?.Invoke (this, args); }
 
             /// <summary>Compiles the regex pattern for validation./></summary>
             private void CompileMask () { _regex = new Regex (StringExtensions.ToString (_pattern), RegexOptions.Compiled); }

+ 25 - 6
Terminal.Gui/Views/TextView.cs

@@ -2523,10 +2523,21 @@ public class TextView : View
         KeyBindings.Add ((KeyCode)ContextMenu.Key, KeyBindingScope.HotKey, Command.ShowContextMenu);
     }
 
+    // BUGBUG: AllowsReturn is mis-named. It should be EnterKeyAccepts.
     /// <summary>
-    ///     Gets or sets a value indicating whether pressing ENTER in a <see cref="TextView"/> creates a new line of text
-    ///     in the view or activates the default button for the Toplevel.
+    ///     Gets or sets whether pressing ENTER in a <see cref="TextView"/> creates a new line of text
+    ///     in the view or invokes the <see cref="View.Accept"/> event.
     /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///         Setting this property alters <see cref="Multiline"/>.
+    ///         If <see cref="AllowsReturn"/> is set to <see langword="true"/>, then <see cref="Multiline"/> is also set to `true` and
+    ///         vice-versa.
+    ///     </para>
+    ///     <para>
+    ///         If <see cref="AllowsReturn"/> is set to <see langword="false"/>, then <see cref="AllowsTab"/> gets set to <see langword="false"/>.
+    ///     </para>
+    /// </remarks>
     public bool AllowsReturn
     {
         get => _allowsReturn;
@@ -2536,12 +2547,14 @@ public class TextView : View
 
             if (_allowsReturn && !_multiline)
             {
+                // BUGBUG: Seting properties should not have side-effects like this. Multiline and AllowsReturn should be independent.
                 Multiline = true;
             }
 
             if (!_allowsReturn && _multiline)
             {
                 Multiline = false;
+                // BUGBUG: Seting properties should not have side-effects like this. Multiline and AlowsTab should be independent.
                 AllowsTab = false;
             }
 
@@ -2807,7 +2820,6 @@ public class TextView : View
         }
         set
         {
-            string old = Text;
             ResetPosition ();
             _model.LoadString (value);
 
@@ -2817,7 +2829,7 @@ public class TextView : View
                 _model = _wrapManager.WrapModel (Viewport.Width, out _, out _, out _, out _);
             }
 
-            OnTextChanged (old, Text);
+            OnTextChanged ();
             SetNeedsDisplay ();
 
             _historyText.Clear (Text);
@@ -6050,15 +6062,22 @@ public class TextView : View
         Paste ();
     }
 
-    private bool ProcessReturn ()
+    private bool? ProcessReturn ()
     {
         ResetColumnTrack ();
 
-        if (!AllowsReturn || _isReadOnly)
+        if (_isReadOnly)
         {
             return false;
         }
 
+        if (!AllowsReturn)
+        {
+            // By Default pressing ENTER should be ignored (OnAccept will return false or null). Only cancel if the
+            // event was fired and set Cancel = true.
+            return OnAccept () == false;
+        }
+
         SetWrapModel ();
 
         List<RuneCell> currentLine = GetCurrentLine ();

+ 6 - 5
Terminal.Gui/Views/Tile.cs

@@ -1,4 +1,5 @@
-using System.ComponentModel;
+#nullable enable
+using System.ComponentModel;
 
 namespace Terminal.Gui;
 
@@ -61,7 +62,7 @@ public class Tile
     /// <param name="newTitle">The new <see cref="Title"/> to be replaced.</param>
     public virtual void OnTitleChanged (string oldTitle, string newTitle)
     {
-        var args = new StringEventArgs (oldTitle, newTitle);
+        var args = new EventArgs<string> (ref newTitle);
         TitleChanged?.Invoke (this, args);
     }
 
@@ -74,18 +75,18 @@ public class Tile
     /// <returns><c>true</c> if an event handler cancelled the Title change.</returns>
     public virtual bool OnTitleChanging (string oldTitle, string newTitle)
     {
-        var args = new StringEventArgs (oldTitle, newTitle);
+        var args = new CancelEventArgs<string> (ref oldTitle, ref newTitle);
         TitleChanging?.Invoke (this, args);
 
         return args.Cancel;
     }
 
     /// <summary>Event fired after the <see cref="Title"/> has been changed.</summary>
-    public event EventHandler<StringEventArgs> TitleChanged;
+    public event EventHandler? TitleChanged;
 
     /// <summary>
     ///     Event fired when the <see cref="Title"/> is changing.
     ///     <see cref="CancelEventArgs.Cancel"/> can be set to <c>true</c> to cancel the change.
     /// </summary>
-    public event EventHandler<StringEventArgs> TitleChanging;
+    public event EventHandler<CancelEventArgs<string>>? TitleChanging;
 }

+ 1 - 1
Terminal.Gui/Views/TimeField.cs

@@ -430,7 +430,7 @@ public class TimeField : TextField
         return true;
     }
 
-    private void TextField_TextChanging (object sender, StateEventArgs<string> e)
+    private void TextField_TextChanging (object sender, CancelEventArgs<string> e)
     {
         try
         {

+ 2 - 2
Terminal.Gui/Views/Wizard/Wizard.cs

@@ -562,11 +562,11 @@ public class Wizard : Dialog
         // gets the first step if CurrentStep == null
     }
 
-    private void Wizard_TitleChanged (object sender, StateEventArgs<string> e)
+    private void Wizard_TitleChanged (object sender, EventArgs<string> e)
     {
         if (string.IsNullOrEmpty (_wizardTitle))
         {
-            _wizardTitle = e.NewValue;
+            _wizardTitle = e.CurrentValue;
         }
     }
 }

+ 4 - 4
UICatalog/Scenarios/AdornmentEditor.cs

@@ -186,7 +186,7 @@ public class AdornmentEditor : View
                };
     }
 
-    private void Top_ValueChanging (object sender, StateEventArgs<int> e)
+    private void Top_ValueChanging (object sender, CancelEventArgs<int> e)
     {
         if (e.NewValue < 0 || AdornmentToEdit is null)
         {
@@ -198,7 +198,7 @@ public class AdornmentEditor : View
         AdornmentToEdit.Thickness = new (AdornmentToEdit.Thickness.Left, e.NewValue, AdornmentToEdit.Thickness.Right, AdornmentToEdit.Thickness.Bottom);
     }
 
-    private void Left_ValueChanging (object sender, StateEventArgs<int> e)
+    private void Left_ValueChanging (object sender, CancelEventArgs<int> e)
     {
         if (e.NewValue < 0 || AdornmentToEdit is null)
         {
@@ -210,7 +210,7 @@ public class AdornmentEditor : View
         AdornmentToEdit.Thickness = new (e.NewValue, AdornmentToEdit.Thickness.Top, AdornmentToEdit.Thickness.Right, AdornmentToEdit.Thickness.Bottom);
     }
 
-    private void Right_ValueChanging (object sender, StateEventArgs<int> e)
+    private void Right_ValueChanging (object sender, CancelEventArgs<int> e)
     {
         if (e.NewValue < 0 || AdornmentToEdit is null)
         {
@@ -222,7 +222,7 @@ public class AdornmentEditor : View
         AdornmentToEdit.Thickness = new (AdornmentToEdit.Thickness.Left, AdornmentToEdit.Thickness.Top, e.NewValue, AdornmentToEdit.Thickness.Bottom);
     }
 
-    private void Bottom_ValueChanging (object sender, StateEventArgs<int> e)
+    private void Bottom_ValueChanging (object sender, CancelEventArgs<int> e)
     {
         if (e.NewValue < 0 || AdornmentToEdit is null)
         {

+ 6 - 6
UICatalog/Scenarios/AdornmentsEditor.cs

@@ -90,11 +90,11 @@ public class AdornmentsEditor : View
         Add (_paddingEditor);
 
         _diagPaddingCheckBox = new () { Text = "_Diagnostic Padding" };
-        _diagPaddingCheckBox.Checked = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Padding);
+        _diagPaddingCheckBox.State = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Padding) ? CheckState.Checked : CheckState.UnChecked;
 
-        _diagPaddingCheckBox.Toggled += (s, e) =>
+        _diagPaddingCheckBox.Toggle += (s, e) =>
                                         {
-                                            if (e.NewValue == true)
+                                            if (e.NewValue == CheckState.Checked)
                                             {
                                                 Diagnostics |= ViewDiagnosticFlags.Padding;
                                             }
@@ -108,11 +108,11 @@ public class AdornmentsEditor : View
         _diagPaddingCheckBox.Y = Pos.Bottom (_paddingEditor);
 
         _diagRulerCheckBox = new () { Text = "_Diagnostic Ruler" };
-        _diagRulerCheckBox.Checked = Diagnostics.FastHasFlags (ViewDiagnosticFlags.Ruler);
+        _diagRulerCheckBox.State = Diagnostics.FastHasFlags(ViewDiagnosticFlags.Ruler) ? CheckState.Checked : CheckState.UnChecked;
 
-        _diagRulerCheckBox.Toggled += (s, e) =>
+        _diagRulerCheckBox.Toggle += (s, e) =>
                                       {
-                                          if (e.NewValue == true)
+                                          if (e.NewValue == CheckState.Checked)
                                           {
                                               Diagnostics |= ViewDiagnosticFlags.Ruler;
                                           }

+ 2 - 2
UICatalog/Scenarios/Bars.cs

@@ -193,7 +193,7 @@ public class Bars : Scenario
                                  {
                                      eventSource.Add ($"Accept: {sh!.SuperView.Id} {sh!.CommandView.Text}");
                                      eventLog.MoveDown ();
-                                     args.Cancel = true;
+                                     args.Handled = true;
                                  };
                 }
             }
@@ -453,7 +453,7 @@ public class Bars : Scenario
                                                     {
                                                         button1.Visible = !button1.Visible;
                                                         button1.Enabled = button1.Visible;
-                                                        e.Cancel = false;
+                                                        e.Handled = false;
                                                     };
 
         bar.Add (new Label

+ 4 - 4
UICatalog/Scenarios/BorderEditor.cs

@@ -20,7 +20,7 @@ public class BorderEditor : AdornmentEditor
 
     private void BorderEditor_AdornmentChanged (object sender, EventArgs e)
     {
-        _ckbTitle.Checked = ((Border)AdornmentToEdit).ShowTitle;
+        _ckbTitle.State = ((Border)AdornmentToEdit).ShowTitle ? CheckState.Checked : CheckState.UnChecked;
         _rbBorderStyle.SelectedItem = (int)((Border)AdornmentToEdit).LineStyle;
     }
 
@@ -51,14 +51,14 @@ public class BorderEditor : AdornmentEditor
             X = 0,
             Y = Pos.Bottom (_rbBorderStyle),
 
-            Checked = true,
+            State = CheckState.Checked,
             SuperViewRendersLineCanvas = true,
             Text = "Show Title",
             Enabled = AdornmentToEdit is { }
         };
 
 
-        _ckbTitle.Toggled += OnCkbTitleOnToggled;
+        _ckbTitle.Toggle += OnCkbTitleOnToggle;
         Add (_ckbTitle);
 
         return;
@@ -81,6 +81,6 @@ public class BorderEditor : AdornmentEditor
             LayoutSubviews ();
         }
 
-        void OnCkbTitleOnToggled (object sender, StateEventArgs<bool?> args) { ((Border)AdornmentToEdit).ShowTitle = args.NewValue!.Value; }
+        void OnCkbTitleOnToggle (object sender, CancelEventArgs<CheckState> args) { ((Border)AdornmentToEdit).ShowTitle = args.NewValue == CheckState.Checked; }
     }
 }

+ 10 - 10
UICatalog/Scenarios/Buttons.cs

@@ -341,7 +341,7 @@ public class Buttons : Scenario
         };
         numericUpDown.ValueChanged += NumericUpDown_ValueChanged;
 
-        void NumericUpDown_ValueChanged (object sender, StateEventArgs<int> e) { }
+        void NumericUpDown_ValueChanged (object sender, EventArgs<int> e) { }
 
         main.Add (label, numericUpDown);
 
@@ -385,9 +385,9 @@ public class Buttons : Scenario
             X = Pos.Right (repeatButton) + 1,
             Y = Pos.Top (repeatButton),
             Title = "Enabled",
-            Checked = true
+            State = CheckState.Checked
         };
-        enableCB.Toggled += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; };
+        enableCB.Toggle += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; };
         main.Add (label, repeatButton, enableCB);
 
         main.Ready += (s, e) => radioGroup.Refresh ();
@@ -486,12 +486,12 @@ public class Buttons : Scenario
 
             return;
 
-            void OnDownButtonOnAccept (object s, CancelEventArgs e)
+            void OnDownButtonOnAccept (object s, HandledEventArgs e)
             {
                 InvokeCommand (Command.ScrollDown);
             }
 
-            void OnUpButtonOnAccept (object s, CancelEventArgs e)
+            void OnUpButtonOnAccept (object s, HandledEventArgs e)
             {
                 InvokeCommand (Command.ScrollUp);
             }
@@ -518,7 +518,7 @@ public class Buttons : Scenario
                 }
 
                 T oldValue = value;
-                StateEventArgs<T> args = new StateEventArgs<T> (_value, value);
+                CancelEventArgs<T> args = new (ref _value, ref value);
                 ValueChanging?.Invoke (this, args);
 
                 if (args.Cancel)
@@ -528,21 +528,21 @@ public class Buttons : Scenario
 
                 _value = value;
                 _number.Text = _value.ToString ();
-                ValueChanged?.Invoke (this, new (oldValue, _value));
+                ValueChanged?.Invoke (this, new (ref _value));
             }
         }
 
         /// <summary>
-        /// Fired when the value is about to change. Set <see cref="StateEventArgs{T}.Cancel"/> to true to prevent the change.
+        /// Fired when the value is about to change. Set <see cref="CancelEventArgs{T}.Cancel"/> to true to prevent the change.
         /// </summary>
         [CanBeNull]
-        public event EventHandler<StateEventArgs<T>> ValueChanging;
+        public event EventHandler<CancelEventArgs<T>> ValueChanging;
 
         /// <summary>
         /// Fired when the value has changed.
         /// </summary>
         [CanBeNull]
-        public event EventHandler<StateEventArgs<T>> ValueChanged;
+        public event EventHandler<EventArgs<T>> ValueChanged;
 
         /// <summary>
         /// The number of digits to display. The <see cref="View.Viewport"/> will be resized to fit this number of characters plus the buttons. The default is 3.

+ 79 - 85
UICatalog/Scenarios/CharacterMap.cs

@@ -77,19 +77,8 @@ public class CharacterMap : Scenario
         };
         top.Add (_errorLabel);
 
-#if TEXT_CHANGED_TO_JUMP
-        jumpEdit.TextChanged += JumpEdit_TextChanged;
-#else
         jumpEdit.Accept += JumpEditOnAccept;
 
-        void JumpEditOnAccept (object sender, CancelEventArgs e)
-        {
-            JumpEdit_TextChanged (sender, new (jumpEdit.Text, jumpEdit.Text));
-
-            // Cancel the event to prevent ENTER from being handled elsewhere
-            e.Cancel = true;
-        }
-#endif
         _categoryList = new () { X = Pos.Right (_charMap), Y = Pos.Bottom (jumpLabel), Height = Dim.Fill () };
         _categoryList.FullRowSelect = true;
 
@@ -181,6 +170,83 @@ public class CharacterMap : Scenario
         Application.Run (top);
         top.Dispose ();
         Application.Shutdown ();
+
+        return;
+
+        void JumpEditOnAccept (object sender, HandledEventArgs e)
+        {
+            if (jumpEdit.Text.Length == 0)
+            {
+                return;
+            }
+
+            uint result = 0;
+
+            if (jumpEdit.Text.StartsWith ("U+", StringComparison.OrdinalIgnoreCase) || jumpEdit.Text.StartsWith ("\\u"))
+            {
+                try
+                {
+                    result = uint.Parse (jumpEdit.Text [2..], NumberStyles.HexNumber);
+                }
+                catch (FormatException)
+                {
+                    _errorLabel.Text = "Invalid hex value";
+
+                    return;
+                }
+            }
+            else if (jumpEdit.Text.StartsWith ("0", StringComparison.OrdinalIgnoreCase) || jumpEdit.Text.StartsWith ("\\u"))
+            {
+                try
+                {
+                    result = uint.Parse (jumpEdit.Text, NumberStyles.HexNumber);
+                }
+                catch (FormatException)
+                {
+                    _errorLabel.Text = "Invalid hex value";
+
+                    return;
+                }
+            }
+            else
+            {
+                try
+                {
+                    result = uint.Parse (jumpEdit.Text, NumberStyles.Integer);
+                }
+                catch (FormatException)
+                {
+                    _errorLabel.Text = "Invalid value";
+
+                    return;
+                }
+            }
+
+            if (result > RuneExtensions.MaxUnicodeCodePoint)
+            {
+                _errorLabel.Text = "Beyond maximum codepoint";
+
+                return;
+            }
+
+            _errorLabel.Text = $"U+{result:x5}";
+
+            EnumerableTableSource<UnicodeRange> table = (EnumerableTableSource<UnicodeRange>)_categoryList.Table;
+
+            _categoryList.SelectedRow = table.Data
+                                             .Select ((item, index) => new { item, index })
+                                             .FirstOrDefault (x => x.item.Start <= result && x.item.End >= result)
+                                             ?.index
+                                        ?? -1;
+            _categoryList.EnsureSelectedCellIsVisible ();
+
+            // Ensure the typed glyph is selected 
+            _charMap.SelectedCodePoint = (int)result;
+
+
+            // Cancel the event to prevent ENTER from being handled elsewhere
+            e.Handled = true;
+        }
     }
 
     private void _categoryList_Initialized (object sender, EventArgs e) { _charMap.Width = Dim.Fill () - _categoryList.Width; }
@@ -240,78 +306,6 @@ public class CharacterMap : Scenario
         return item;
     }
 
-    private void JumpEdit_TextChanged (object sender, StateEventArgs<string> e)
-    {
-        var jumpEdit = sender as TextField;
-
-        if (jumpEdit.Text.Length == 0)
-        {
-            return;
-        }
-
-        uint result = 0;
-
-        if (jumpEdit.Text.StartsWith ("U+", StringComparison.OrdinalIgnoreCase) || jumpEdit.Text.StartsWith ("\\u"))
-        {
-            try
-            {
-                result = uint.Parse (jumpEdit.Text [2..], NumberStyles.HexNumber);
-            }
-            catch (FormatException)
-            {
-                _errorLabel.Text = "Invalid hex value";
-
-                return;
-            }
-        }
-        else if (jumpEdit.Text.StartsWith ("0", StringComparison.OrdinalIgnoreCase) || jumpEdit.Text.StartsWith ("\\u"))
-        {
-            try
-            {
-                result = uint.Parse (jumpEdit.Text, NumberStyles.HexNumber);
-            }
-            catch (FormatException)
-            {
-                _errorLabel.Text = "Invalid hex value";
-
-                return;
-            }
-        }
-        else
-        {
-            try
-            {
-                result = uint.Parse (jumpEdit.Text, NumberStyles.Integer);
-            }
-            catch (FormatException)
-            {
-                _errorLabel.Text = "Invalid value";
-
-                return;
-            }
-        }
-
-        if (result > RuneExtensions.MaxUnicodeCodePoint)
-        {
-            _errorLabel.Text = "Beyond maximum codepoint";
-
-            return;
-        }
-
-        _errorLabel.Text = $"U+{result:x5}";
-
-        EnumerableTableSource<UnicodeRange> table = (EnumerableTableSource<UnicodeRange>)_categoryList.Table;
-
-        _categoryList.SelectedRow = table.Data
-                                         .Select ((item, index) => new { item, index })
-                                         .FirstOrDefault (x => x.item.Start <= result && x.item.End >= result)
-                                         ?.index
-                                    ?? -1;
-        _categoryList.EnsureSelectedCellIsVisible ();
-
-        // Ensure the typed glyph is selected 
-        _charMap.SelectedCodePoint = (int)result;
-    }
 }
 
 internal class CharMap : View
@@ -483,7 +477,7 @@ internal class CharMap : View
             WantContinuousButtonPressed = true,
             CanFocus = false
         };
-        up.Accept += (sender, args) => { args.Cancel = ScrollVertical (-1) == true; };
+        up.Accept += (sender, args) => { args.Handled = ScrollVertical (-1) == true; };
 
         var down = new Button
         {
@@ -1005,7 +999,7 @@ internal class CharMap : View
                                                         document.RootElement,
                                                         new
                                                             JsonSerializerOptions
-                                                            { WriteIndented = true }
+                                                        { WriteIndented = true }
                                                        );
             }
 

+ 26 - 26
UICatalog/Scenarios/ContentScrolling.cs

@@ -135,12 +135,12 @@ public class ContentScrolling : Scenario
             Y = 0,
             CanFocus = false
         };
-        cbAllowNegativeX.Checked = view.ViewportSettings.HasFlag (ViewportSettings.AllowNegativeX);
-        cbAllowNegativeX.Toggled += AllowNegativeX_Toggled;
+        cbAllowNegativeX.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeX) ? CheckState.Checked : CheckState.UnChecked;
+        cbAllowNegativeX.Toggle += AllowNegativeX_Toggle;
 
-        void AllowNegativeX_Toggled (object sender, StateEventArgs<bool?> e)
+        void AllowNegativeX_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.AllowNegativeX;
             }
@@ -159,12 +159,12 @@ public class ContentScrolling : Scenario
             Y = 0,
             CanFocus = false
         };
-        cbAllowNegativeY.Checked = view.ViewportSettings.HasFlag (ViewportSettings.AllowNegativeY);
-        cbAllowNegativeY.Toggled += AllowNegativeY_Toggled;
+        cbAllowNegativeY.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowNegativeY) ? CheckState.Checked : CheckState.UnChecked;
+        cbAllowNegativeY.Toggle += AllowNegativeY_Toggle;
 
-        void AllowNegativeY_Toggled (object sender, StateEventArgs<bool?> e)
+        void AllowNegativeY_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.AllowNegativeY;
             }
@@ -182,12 +182,12 @@ public class ContentScrolling : Scenario
             Y = Pos.Bottom (cbAllowNegativeX),
             CanFocus = false
         };
-        cbAllowXGreaterThanContentWidth.Checked = view.ViewportSettings.HasFlag (ViewportSettings.AllowXGreaterThanContentWidth);
-        cbAllowXGreaterThanContentWidth.Toggled += AllowXGreaterThanContentWidth_Toggled;
+        cbAllowXGreaterThanContentWidth.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowXGreaterThanContentWidth) ? CheckState.Checked : CheckState.UnChecked;
+        cbAllowXGreaterThanContentWidth.Toggle += AllowXGreaterThanContentWidth_Toggle;
 
-        void AllowXGreaterThanContentWidth_Toggled (object sender, StateEventArgs<bool?> e)
+        void AllowXGreaterThanContentWidth_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.AllowXGreaterThanContentWidth;
             }
@@ -206,12 +206,12 @@ public class ContentScrolling : Scenario
             Y = Pos.Bottom (cbAllowNegativeX),
             CanFocus = false
         };
-        cbAllowYGreaterThanContentHeight.Checked = view.ViewportSettings.HasFlag (ViewportSettings.AllowYGreaterThanContentHeight);
-        cbAllowYGreaterThanContentHeight.Toggled += AllowYGreaterThanContentHeight_Toggled;
+        cbAllowYGreaterThanContentHeight.State = view.ViewportSettings.HasFlag(ViewportSettings.AllowYGreaterThanContentHeight) ? CheckState.Checked : CheckState.UnChecked;
+        cbAllowYGreaterThanContentHeight.Toggle += AllowYGreaterThanContentHeight_Toggle;
 
-        void AllowYGreaterThanContentHeight_Toggled (object sender, StateEventArgs<bool?> e)
+        void AllowYGreaterThanContentHeight_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.AllowYGreaterThanContentHeight;
             }
@@ -237,7 +237,7 @@ public class ContentScrolling : Scenario
         };
         contentSizeWidth.ValueChanging += ContentSizeWidth_ValueChanged;
 
-        void ContentSizeWidth_ValueChanged (object sender, StateEventArgs<int> e)
+        void ContentSizeWidth_ValueChanged (object sender, CancelEventArgs<int> e)
         {
             if (e.NewValue < 0)
             {
@@ -265,7 +265,7 @@ public class ContentScrolling : Scenario
         };
         contentSizeHeight.ValueChanging += ContentSizeHeight_ValueChanged;
 
-        void ContentSizeHeight_ValueChanged (object sender, StateEventArgs<int> e)
+        void ContentSizeHeight_ValueChanged (object sender, CancelEventArgs<int> e)
         {
             if (e.NewValue < 0)
             {
@@ -284,12 +284,12 @@ public class ContentScrolling : Scenario
             Y = Pos.Top (labelContentSize),
             CanFocus = false
         };
-        cbClearOnlyVisible.Checked = view.ViewportSettings.HasFlag (ViewportSettings.ClearContentOnly);
-        cbClearOnlyVisible.Toggled += ClearVisibleContentOnly_Toggled;
+        cbClearOnlyVisible.State = view.ViewportSettings.HasFlag(ViewportSettings.ClearContentOnly) ? CheckState.Checked : CheckState.UnChecked;
+        cbClearOnlyVisible.Toggle += ClearVisibleContentOnly_Toggle;
 
-        void ClearVisibleContentOnly_Toggled (object sender, StateEventArgs<bool?> e)
+        void ClearVisibleContentOnly_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.ClearContentOnly;
             }
@@ -306,12 +306,12 @@ public class ContentScrolling : Scenario
             Y = Pos.Top (labelContentSize),
             CanFocus = false
         };
-        cbDoNotClipContent.Checked = view.ViewportSettings.HasFlag (ViewportSettings.ClipContentOnly);
-        cbDoNotClipContent.Toggled += ClipVisibleContentOnly_Toggled;
+        cbDoNotClipContent.State = view.ViewportSettings.HasFlag (ViewportSettings.ClipContentOnly) ? CheckState.Checked : CheckState.UnChecked;
+        cbDoNotClipContent.Toggle += ClipVisibleContentOnly_Toggle;
 
-        void ClipVisibleContentOnly_Toggled (object sender, StateEventArgs<bool?> e)
+        void ClipVisibleContentOnly_Toggle (object sender, CancelEventArgs<CheckState> e)
         {
-            if (e.NewValue == true)
+            if (e.NewValue == CheckState.Checked)
             {
                 view.ViewportSettings |= ViewportSettings.ClipContentOnly;
             }

+ 1 - 1
UICatalog/Scenarios/CsvEditor.cs

@@ -565,7 +565,7 @@ public class CsvEditor : Scenario
         }
     }
 
-    private void SelectedCellLabel_TextChanged (object sender, StateEventArgs<string> e)
+    private void SelectedCellLabel_TextChanged (object sender, EventArgs e)
     {
         // if user is in the text control and editing the selected cell
         if (!_selectedCellTextField.HasFocus)

+ 3 - 3
UICatalog/Scenarios/Dialogs.cs

@@ -131,7 +131,7 @@ public class Dialogs : Scenario
             Y = Pos.Bottom (numButtonsLabel),
             TextAlignment = Alignment.End,
             Text = $"_Add {char.ConvertFromUtf32 (CODE_POINT)} to button text to stress wide char support",
-            Checked = false
+            State = CheckState.UnChecked
         };
         frame.Add (glyphsNotWords);
 
@@ -230,7 +230,7 @@ public class Dialogs : Scenario
                 int buttonId = i;
                 Button button = null;
 
-                if (glyphsNotWords.Checked == true)
+                if (glyphsNotWords.State == CheckState.Checked)
                 {
                     buttonId = i;
 
@@ -281,7 +281,7 @@ public class Dialogs : Scenario
                               int buttonId = buttons.Count;
                               Button button;
 
-                              if (glyphsNotWords.Checked == true)
+                              if (glyphsNotWords.State == CheckState.Checked)
                               {
                                   button = new ()
                                   {

+ 32 - 32
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -142,7 +142,7 @@ public class DynamicMenuBar : Scenario
             {
                 X = Pos.Left (_lblTitle),
                 Y = Pos.Bottom (CkbIsTopLevel),
-                Checked = _menuItem == null ? !_hasParent : HasSubMenus (_menuItem),
+                State = (_menuItem == null ? !_hasParent : HasSubMenus (_menuItem)) ? CheckState.Checked : CheckState.UnChecked,
                 Text = "Has sub-menus"
             };
             Add (CkbSubMenu);
@@ -249,36 +249,36 @@ public class DynamicMenuBar : Scenario
             _btnShortcut.Accept += (s, e) => { TextShortcut.Text = ""; };
             Add (_btnShortcut);
 
-            CkbIsTopLevel.Toggled += (s, e) =>
+            CkbIsTopLevel.Toggle += (s, e) =>
                                      {
-                                         if ((_menuItem != null && _menuItem.Parent != null && (bool)CkbIsTopLevel.Checked)
-                                             || (_menuItem == null && _hasParent && (bool)CkbIsTopLevel.Checked))
+                                         if ((_menuItem != null && _menuItem.Parent != null && CkbIsTopLevel.State == CheckState.Checked)
+                                             || (_menuItem == null && _hasParent && CkbIsTopLevel.State == CheckState.Checked))
                                          {
                                              MessageBox.ErrorQuery (
                                                                     "Invalid IsTopLevel",
                                                                     "Only menu bar can have top level menu item!",
                                                                     "Ok"
                                                                    );
-                                             CkbIsTopLevel.Checked = false;
+                                             CkbIsTopLevel.State = CheckState.UnChecked;
 
                                              return;
                                          }
 
-                                         if (CkbIsTopLevel.Checked == true)
+                                         if (CkbIsTopLevel.State == CheckState.Checked)
                                          {
-                                             CkbSubMenu.Checked = false;
+                                             CkbSubMenu.State = CheckState.UnChecked;
                                              CkbSubMenu.SetNeedsDisplay ();
                                              TextHelp.Enabled = true;
                                              TextAction.Enabled = true;
 
                                              TextShortcut.Enabled =
-                                                 CkbIsTopLevel.Checked == false && CkbSubMenu.Checked == false;
+                                                 CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked;
                                          }
                                          else
                                          {
                                              if ((_menuItem == null && !_hasParent) || _menuItem.Parent == null)
                                              {
-                                                 CkbSubMenu.Checked = true;
+                                                 CkbSubMenu.State = CheckState.Checked;
                                                  CkbSubMenu.SetNeedsDisplay ();
                                                  TextShortcut.Enabled = false;
                                              }
@@ -290,11 +290,11 @@ public class DynamicMenuBar : Scenario
                                          }
                                      };
 
-            CkbSubMenu.Toggled += (s, e) =>
+            CkbSubMenu.Toggle += (s, e) =>
                                   {
-                                      if ((bool)CkbSubMenu.Checked)
+                                      if (e.NewValue == CheckState.Checked)
                                       {
-                                          CkbIsTopLevel.Checked = false;
+                                          CkbIsTopLevel.State = CheckState.UnChecked;
                                           CkbIsTopLevel.SetNeedsDisplay ();
                                           TextHelp.Text = "";
                                           TextHelp.Enabled = false;
@@ -307,7 +307,7 @@ public class DynamicMenuBar : Scenario
                                       {
                                           if (!_hasParent)
                                           {
-                                              CkbIsTopLevel.Checked = true;
+                                              CkbIsTopLevel.State = CheckState.Checked;
                                               CkbIsTopLevel.SetNeedsDisplay ();
                                               TextShortcut.Enabled = false;
                                           }
@@ -316,15 +316,15 @@ public class DynamicMenuBar : Scenario
                                           TextAction.Enabled = true;
 
                                           TextShortcut.Enabled =
-                                              CkbIsTopLevel.Checked == false && CkbSubMenu.Checked == false;
+                                              CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked;
                                       }
                                   };
 
-            CkbNullCheck.Toggled += (s, e) =>
+            CkbNullCheck.Toggle += (s, e) =>
                                     {
                                         if (_menuItem != null)
                                         {
-                                            _menuItem.AllowNullChecked = (bool)CkbNullCheck.Checked;
+                                            _menuItem.AllowNullChecked = e.NewValue == CheckState.Checked;
                                         }
                                     };
 
@@ -394,14 +394,14 @@ public class DynamicMenuBar : Scenario
             TextAction.Text = menuItem != null && menuItem.Action != null
                                   ? GetTargetAction (menuItem.Action)
                                   : string.Empty;
-            CkbIsTopLevel.Checked = IsTopLevel (menuItem);
-            CkbSubMenu.Checked = HasSubMenus (menuItem);
-            CkbNullCheck.Checked = menuItem.AllowNullChecked;
-            TextHelp.Enabled = (bool)!CkbSubMenu.Checked;
-            TextAction.Enabled = (bool)!CkbSubMenu.Checked;
+            CkbIsTopLevel.State = IsTopLevel (menuItem) ? CheckState.Checked : CheckState.UnChecked;
+            CkbSubMenu.State = HasSubMenus (menuItem) ? CheckState.Checked : CheckState.UnChecked;
+            CkbNullCheck.State = menuItem.AllowNullChecked ? CheckState.Checked : CheckState.UnChecked;
+            TextHelp.Enabled = CkbSubMenu.State == CheckState.Checked;
+            TextAction.Enabled = CkbSubMenu.State == CheckState.Checked;
             RbChkStyle.SelectedItem = (int)(menuItem?.CheckType ?? MenuItemCheckStyle.NoCheck);
             TextShortcut.Text = menuItem?.ShortcutTag ?? "";
-            TextShortcut.Enabled = CkbIsTopLevel.Checked == false && CkbSubMenu.Checked == false;
+            TextShortcut.Enabled = CkbIsTopLevel.State == CheckState.UnChecked && CkbSubMenu.State == CheckState.UnChecked;
         }
 
         public DynamicMenuItem EnterMenuItem ()
@@ -414,9 +414,9 @@ public class DynamicMenuBar : Scenario
                 TextTitle.Text = m.Title;
                 TextHelp.Text = m.Help;
                 TextAction.Text = m.Action;
-                CkbIsTopLevel.Checked = false;
-                CkbSubMenu.Checked = !_hasParent;
-                CkbNullCheck.Checked = false;
+                CkbIsTopLevel.State = CheckState.UnChecked;
+                CkbSubMenu.State = !_hasParent ? CheckState.Checked : CheckState.UnChecked;
+                CkbNullCheck.State = CheckState.UnChecked;
                 TextHelp.Enabled = _hasParent;
                 TextAction.Enabled = _hasParent;
                 TextShortcut.Enabled = _hasParent;
@@ -466,13 +466,13 @@ public class DynamicMenuBar : Scenario
                     Title = TextTitle.Text,
                     Help = TextHelp.Text,
                     Action = TextAction.Text,
-                    IsTopLevel = CkbIsTopLevel?.Checked ?? false,
-                    HasSubMenu = CkbSubMenu?.Checked ?? false,
+                    IsTopLevel = CkbIsTopLevel?.State == CheckState.Checked,
+                    HasSubMenu = CkbSubMenu?.State == CheckState.UnChecked,
                     CheckStyle = RbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck :
                                  RbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked :
                                  MenuItemCheckStyle.Radio,
                     Shortcut = TextShortcut.Text,
-                    AllowNullChecked = CkbNullCheck.Checked != null && (bool)CkbNullCheck.Checked
+                    AllowNullChecked = CkbNullCheck?.State == CheckState.Checked,
                 };
             }
 
@@ -515,8 +515,8 @@ public class DynamicMenuBar : Scenario
             TextTitle.Text = "";
             TextHelp.Text = "";
             TextAction.Text = "";
-            CkbIsTopLevel.Checked = false;
-            CkbSubMenu.Checked = false;
+            CkbIsTopLevel.State = CheckState.UnChecked;
+            CkbSubMenu.State = CheckState.UnChecked;
             RbChkStyle.SelectedItem = (int)MenuItemCheckStyle.NoCheck;
             TextShortcut.Text = "";
         }
@@ -835,8 +835,8 @@ public class DynamicMenuBar : Scenario
                                          Title = _frmMenuDetails.TextTitle.Text,
                                          Help = _frmMenuDetails.TextHelp.Text,
                                          Action = _frmMenuDetails.TextAction.Text,
-                                         IsTopLevel = _frmMenuDetails.CkbIsTopLevel?.Checked ?? false,
-                                         HasSubMenu = _frmMenuDetails.CkbSubMenu?.Checked ?? false,
+                                         IsTopLevel = _frmMenuDetails.CkbIsTopLevel?.State == CheckState.UnChecked,
+                                         HasSubMenu = _frmMenuDetails.CkbSubMenu?.State == CheckState.UnChecked,
                                          CheckStyle = _frmMenuDetails.RbChkStyle.SelectedItem == 0
                                                           ? MenuItemCheckStyle.NoCheck
                                                           : _frmMenuDetails.RbChkStyle.SelectedItem == 1

+ 8 - 8
UICatalog/Scenarios/Editor.cs

@@ -895,16 +895,16 @@ public class Editor : Scenario
 
         var ckbMatchCase = new CheckBox
         {
-            X = 0, Y = Pos.Top (txtToFind) + 2, Checked = _matchCase, Text = "Match c_ase"
+            X = 0, Y = Pos.Top (txtToFind) + 2, State = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase"
         };
-        ckbMatchCase.Toggled += (s, e) => _matchCase = (bool)ckbMatchCase.Checked;
+        ckbMatchCase.Toggle += (s, e) => _matchCase = e.NewValue == CheckState.Checked;
         d.Add (ckbMatchCase);
 
         var ckbMatchWholeWord = new CheckBox
         {
-            X = 0, Y = Pos.Top (ckbMatchCase) + 1, Checked = _matchWholeWord, Text = "Match _whole word"
+            X = 0, Y = Pos.Top (ckbMatchCase) + 1, State = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word"
         };
-        ckbMatchWholeWord.Toggled += (s, e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked;
+        ckbMatchWholeWord.Toggle += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked;
         d.Add (ckbMatchWholeWord);
         return d;
     }
@@ -1153,16 +1153,16 @@ public class Editor : Scenario
 
         var ckbMatchCase = new CheckBox
         {
-            X = 0, Y = Pos.Top (txtToFind) + 2, Checked = _matchCase, Text = "Match c_ase"
+            X = 0, Y = Pos.Top (txtToFind) + 2, State = _matchCase ? CheckState.Checked : CheckState.UnChecked, Text = "Match c_ase"
         };
-        ckbMatchCase.Toggled += (s, e) => _matchCase = (bool)ckbMatchCase.Checked;
+        ckbMatchCase.Toggle += (s, e) => _matchCase = e.NewValue == CheckState.Checked;
         d.Add (ckbMatchCase);
 
         var ckbMatchWholeWord = new CheckBox
         {
-            X = 0, Y = Pos.Top (ckbMatchCase) + 1, Checked = _matchWholeWord, Text = "Match _whole word"
+            X = 0, Y = Pos.Top (ckbMatchCase) + 1, State = _matchWholeWord ? CheckState.Checked : CheckState.UnChecked, Text = "Match _whole word"
         };
-        ckbMatchWholeWord.Toggled += (s, e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked;
+        ckbMatchWholeWord.Toggle += (s, e) => _matchWholeWord = e.NewValue == CheckState.Checked;
         d.Add (ckbMatchWholeWord);
 
         return d;

+ 4 - 3
UICatalog/Scenarios/ExpanderButton.cs

@@ -133,15 +133,16 @@ public class ExpanderButton : Button
 
     /// <summary>Called when the orientation is changing. Invokes the <see cref="OrientationChanging"/> event.</summary>
     /// <param name="newOrientation"></param>
+    /// <param name="newValue"></param>
     /// <returns>True of the event was cancelled.</returns>
     protected virtual bool OnCollapsedChanging (bool newValue)
     {
-        StateEventArgs<bool> args = new (Collapsed, newValue);
+        CancelEventArgs<bool> args = new (ref _collapsed, ref newValue);
         CollapsedChanging?.Invoke (this, args);
 
         if (!args.Cancel)
         {
-            _collapsed = newValue;
+            _collapsed = args.NewValue;
 
             ExpandOrCollapse (_collapsed);
 
@@ -168,7 +169,7 @@ public class ExpanderButton : Button
     ///     Fired when the orientation has changed. Can be cancelled by setting
     ///     <see cref="OrientationEventArgs.Cancel"/> to true.
     /// </summary>
-    public event EventHandler<StateEventArgs<bool>> CollapsedChanging;
+    public event EventHandler<CancelEventArgs<bool>> CollapsedChanging;
 
     /// <summary>
     ///     Collapses or Expands the view.

+ 16 - 16
UICatalog/Scenarios/FileDialogExamples.cs

@@ -31,25 +31,25 @@ public class FileDialogExamples : Scenario
         var y = 0;
         var x = 1;
 
-        _cbMustExist = new CheckBox { Checked = true, Y = y++, X = x, Text = "Must Exist" };
+        _cbMustExist = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Must Exist" };
         Win.Add (_cbMustExist);
 
-        _cbUseColors = new CheckBox { Checked = FileDialogStyle.DefaultUseColors, Y = y++, X = x, Text = "Use Colors" };
+        _cbUseColors = new CheckBox { State = FileDialogStyle.DefaultUseColors ? CheckState.Checked : CheckState.UnChecked, Y = y++, X = x, Text = "Use Colors" };
         Win.Add (_cbUseColors);
 
-        _cbCaseSensitive = new CheckBox { Checked = false, Y = y++, X = x, Text = "Case Sensitive Search" };
+        _cbCaseSensitive = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Case Sensitive Search" };
         Win.Add (_cbCaseSensitive);
 
-        _cbAllowMultipleSelection = new CheckBox { Checked = false, Y = y++, X = x, Text = "Multiple" };
+        _cbAllowMultipleSelection = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Multiple" };
         Win.Add (_cbAllowMultipleSelection);
 
-        _cbShowTreeBranchLines = new CheckBox { Checked = true, Y = y++, X = x, Text = "Tree Branch Lines" };
+        _cbShowTreeBranchLines = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Tree Branch Lines" };
         Win.Add (_cbShowTreeBranchLines);
 
-        _cbAlwaysTableShowHeaders = new CheckBox { Checked = true, Y = y++, X = x, Text = "Always Show Headers" };
+        _cbAlwaysTableShowHeaders = new CheckBox { State = CheckState.Checked, Y = y++, X = x, Text = "Always Show Headers" };
         Win.Add (_cbAlwaysTableShowHeaders);
 
-        _cbDrivesOnlyInTree = new CheckBox { Checked = false, Y = y++, X = x, Text = "Only Show Drives" };
+        _cbDrivesOnlyInTree = new CheckBox { State = CheckState.UnChecked, Y = y++, X = x, Text = "Only Show Drives" };
         Win.Add (_cbDrivesOnlyInTree);
 
         y = 0;
@@ -145,8 +145,8 @@ public class FileDialogExamples : Scenario
             OpenMode = Enum.Parse<OpenMode> (
                                              _rgOpenMode.RadioLabels [_rgOpenMode.SelectedItem]
                                             ),
-            MustExist = _cbMustExist.Checked ?? false,
-            AllowsMultipleSelection = _cbAllowMultipleSelection.Checked ?? false
+            MustExist = _cbMustExist.State == CheckState.Checked,
+            AllowsMultipleSelection = _cbAllowMultipleSelection.State == CheckState.Checked
         };
 
         fd.Style.OkButtonText = _rgCaption.RadioLabels [_rgCaption.SelectedItem];
@@ -160,19 +160,19 @@ public class FileDialogExamples : Scenario
         fd.Style.IconProvider.UseUnicodeCharacters = _rgIcons.SelectedItem == 1;
         fd.Style.IconProvider.UseNerdIcons = _rgIcons.SelectedItem == 2;
 
-        if (_cbCaseSensitive.Checked ?? false)
+        if (_cbCaseSensitive.State == CheckState.Checked)
         {
             fd.SearchMatcher = new CaseSensitiveSearchMatcher ();
         }
 
-        fd.Style.UseColors = _cbUseColors.Checked ?? false;
+        fd.Style.UseColors = _cbUseColors.State == CheckState.Checked;
 
-        fd.Style.TreeStyle.ShowBranchLines = _cbShowTreeBranchLines.Checked ?? false;
-        fd.Style.TableStyle.AlwaysShowHeaders = _cbAlwaysTableShowHeaders.Checked ?? false;
+        fd.Style.TreeStyle.ShowBranchLines = _cbShowTreeBranchLines.State == CheckState.Checked;
+        fd.Style.TableStyle.AlwaysShowHeaders = _cbAlwaysTableShowHeaders.State == CheckState.Checked;
 
         IDirectoryInfoFactory dirInfoFactory = new FileSystem ().DirectoryInfo;
 
-        if (_cbDrivesOnlyInTree.Checked ?? false)
+        if (_cbDrivesOnlyInTree.State == CheckState.Checked)
         {
             fd.Style.TreeRootGetter = () => { return Environment.GetLogicalDrives ().ToDictionary (dirInfoFactory.New, k => k); };
         }
@@ -197,7 +197,7 @@ public class FileDialogExamples : Scenario
             fd.Style.CancelButtonText = _tbCancelButton.Text;
         }
 
-        if (_cbFlipButtonOrder.Checked ?? false)
+        if (_cbFlipButtonOrder.State == CheckState.Checked)
         {
             fd.Style.FlipOkCancelButtonLayoutOrder = true;
         }
@@ -219,7 +219,7 @@ public class FileDialogExamples : Scenario
                               "Ok"
                              );
         }
-        else if (_cbAllowMultipleSelection.Checked ?? false)
+        else if (_cbAllowMultipleSelection.State == CheckState.Checked)
         {
             MessageBox.Query (
                               "Chosen!",

+ 2 - 2
UICatalog/Scenarios/GraphViewExample.cs

@@ -196,13 +196,13 @@ public class GraphViewExample : Scenario
         Application.Shutdown ();
     }
 
-    private void DiagShortcut_Accept (object sender, CancelEventArgs e)
+    private void DiagShortcut_Accept (object sender, HandledEventArgs e)
     {
         ToggleDiagnostics ();
 
         if (sender is Shortcut shortcut && shortcut.CommandView is CheckBox checkBox)
         {
-            checkBox.Checked = _miDiags.Checked;
+            checkBox.State = _miDiags.Checked ?? false ? CheckState.Checked : CheckState.UnChecked;
         }
     }
 

+ 3 - 3
UICatalog/Scenarios/Images.cs

@@ -28,7 +28,7 @@ public class Images : Scenario
         {
             X = Pos.Right (lblDriverName) + 2,
             Y = 0,
-            Checked = canTrueColor,
+            State = canTrueColor ? CheckState.Checked : CheckState.UnChecked,
             CanFocus = false,
             Text = "supports true color "
         };
@@ -38,11 +38,11 @@ public class Images : Scenario
         {
             X = Pos.Right (cbSupportsTrueColor) + 2,
             Y = 0,
-            Checked = !Application.Force16Colors,
+            State = !Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
             Enabled = canTrueColor,
             Text = "Use true color"
         };
-        cbUseTrueColor.Toggled += (_, evt) => Application.Force16Colors = !evt.NewValue ?? false;
+        cbUseTrueColor.Toggle += (_, evt) => Application.Force16Colors = evt.NewValue == CheckState.UnChecked;
         Win.Add (cbUseTrueColor);
 
         var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" };

+ 2 - 4
UICatalog/Scenarios/ListColumns.cs

@@ -120,8 +120,7 @@ public class ListColumns : Scenario
                          {
                              Checked = _listColView.Style
                                                    .ShowHorizontalBottomline,
-                             CheckType = MenuItemCheckStyle
-                                 .Checked
+                             CheckType = MenuItemCheckStyle.Checked
                          },
                          _miCellLines = new (
                                              "_CellLines",
@@ -131,8 +130,7 @@ public class ListColumns : Scenario
                          {
                              Checked = _listColView.Style
                                                    .ShowVerticalCellLines,
-                             CheckType = MenuItemCheckStyle
-                                 .Checked
+                             CheckType = MenuItemCheckStyle.Checked
                          },
                          _miExpandLastColumn = new (
                                                     "_ExpandLastColumn",

+ 13 - 13
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -34,24 +34,24 @@ public class ListViewWithSelection : Scenario
 
         _customRenderCB = new CheckBox { X = 0, Y = 0, Text = "Use custom rendering" };
         _appWindow.Add (_customRenderCB);
-        _customRenderCB.Toggled += _customRenderCB_Toggled;
+        _customRenderCB.Toggle += _customRenderCB_Toggle;
 
         _allowMarkingCB = new CheckBox
         {
-            X = Pos.Right (_customRenderCB) + 1, Y = 0, Text = "Allow Marking", AllowNullChecked = false
+            X = Pos.Right (_customRenderCB) + 1, Y = 0, Text = "Allow Marking", AllowCheckStateNone = false
         };
         _appWindow.Add (_allowMarkingCB);
-        _allowMarkingCB.Toggled += AllowMarkingCB_Toggled;
+        _allowMarkingCB.Toggle += AllowMarkingCB_Toggle;
 
         _allowMultipleCB = new CheckBox
         {
             X = Pos.Right (_allowMarkingCB) + 1,
             Y = 0,
-            Visible = (bool)_allowMarkingCB.Checked,
+            Visible = _allowMarkingCB.State == CheckState.Checked,
             Text = "Allow Multi-Select"
         };
         _appWindow.Add (_allowMultipleCB);
-        _allowMultipleCB.Toggled += AllowMultipleCB_Toggled;
+        _allowMultipleCB.Toggle += AllowMultipleCB_Toggle;
 
         _listView = new ListView
         {
@@ -108,9 +108,9 @@ public class ListViewWithSelection : Scenario
 
         var keepCheckBox = new CheckBox
         {
-            X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, Checked = scrollBar.AutoHideScrollBars
+            X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, State = scrollBar.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked
         };
-        keepCheckBox.Toggled += (s, e) => scrollBar.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
+        keepCheckBox.Toggle += (s, e) => scrollBar.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked;
         _appWindow.Add (keepCheckBox);
 
         Application.Run (_appWindow);
@@ -118,9 +118,9 @@ public class ListViewWithSelection : Scenario
         Application.Shutdown ();
     }
 
-    private void _customRenderCB_Toggled (object sender, StateEventArgs<bool?> stateEventArgs)
+    private void _customRenderCB_Toggle (object sender, CancelEventArgs<CheckState> stateEventArgs)
     {
-        if (stateEventArgs.OldValue == true)
+        if (stateEventArgs.CurrentValue == CheckState.Checked)
         {
             _listView.SetSource (_scenarios);
         }
@@ -132,16 +132,16 @@ public class ListViewWithSelection : Scenario
         _appWindow.SetNeedsDisplay ();
     }
 
-    private void AllowMarkingCB_Toggled (object sender, [NotNull] StateEventArgs<bool?> stateEventArgs)
+    private void AllowMarkingCB_Toggle (object sender, [NotNull] CancelEventArgs<CheckState> stateEventArgs)
     {
-        _listView.AllowsMarking = (bool)!stateEventArgs.OldValue;
+        _listView.AllowsMarking = stateEventArgs.NewValue == CheckState.Checked;
         _allowMultipleCB.Visible = _listView.AllowsMarking;
         _appWindow.SetNeedsDisplay ();
     }
 
-    private void AllowMultipleCB_Toggled (object sender, [NotNull] StateEventArgs<bool?> stateEventArgs)
+    private void AllowMultipleCB_Toggle (object sender, [NotNull] CancelEventArgs<CheckState> stateEventArgs)
     {
-        _listView.AllowsMultipleSelection = (bool)!stateEventArgs.OldValue;
+        _listView.AllowsMultipleSelection = stateEventArgs.NewValue == CheckState.Checked;
         _appWindow.SetNeedsDisplay ();
     }
 

+ 2 - 2
UICatalog/Scenarios/Localization.cs

@@ -141,7 +141,7 @@ public class Localization : Scenario
         {
             X = Pos.Right (textField) + 1,
             Y = Pos.Bottom (textAndFileDialogLabel) + 1,
-            Checked = false,
+            State = CheckState.UnChecked,
             Text = "Allow any"
         };
         Win.Add (_allowAnyCheckBox);
@@ -183,7 +183,7 @@ public class Localization : Scenario
 
         dialog.AllowedTypes =
         [
-            _allowAnyCheckBox.Checked ?? false
+            _allowAnyCheckBox.State == CheckState.Checked
                 ? new AllowedTypeAny ()
                 : new AllowedType ("Dynamic link library", ".dll"),
             new AllowedType ("Json", ".json"),

+ 3 - 3
UICatalog/Scenarios/MessageBoxes.cs

@@ -186,7 +186,7 @@ public class MessageBoxes : Scenario
 
         var ckbWrapMessage = new CheckBox
         {
-            X = Pos.Right (label) + 1, Y = Pos.Bottom (styleRadioGroup), Text = "_Wrap Message", Checked = true
+            X = Pos.Right (label) + 1, Y = Pos.Bottom (styleRadioGroup), Text = "_Wrap Message", State = CheckState.Checked
         };
         frame.Add (ckbWrapMessage);
 
@@ -237,7 +237,7 @@ public class MessageBoxes : Scenario
                                                                              titleEdit.Text,
                                                                              messageEdit.Text,
                                                                              defaultButton,
-                                                                             (bool)ckbWrapMessage.Checked,
+                                                                             ckbWrapMessage.State == CheckState.Checked,
                                                                              btns.ToArray ()
                                                                             )}";
                                                }
@@ -250,7 +250,7 @@ public class MessageBoxes : Scenario
                                                                                   titleEdit.Text,
                                                                                   messageEdit.Text,
                                                                                   defaultButton,
-                                                                                  (bool)ckbWrapMessage.Checked,
+                                                                                  ckbWrapMessage.State == CheckState.Checked,
                                                                                   btns.ToArray ()
                                                                                  )}";
                                                }

+ 4 - 4
UICatalog/Scenarios/Mouse.cs

@@ -67,7 +67,7 @@ public class Mouse : Scenario
             Y = Pos.Bottom (ml),
             Title = "_Want Continuous Button Pressed"
         };
-        cbWantContinuousPresses.Toggled += (s, e) => { win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed; };
+        cbWantContinuousPresses.Toggle += (s, e) => { win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed; };
 
         win.Add (cbWantContinuousPresses);
 
@@ -77,11 +77,11 @@ public class Mouse : Scenario
             Y = Pos.Bottom (cbWantContinuousPresses),
             Title = "_Highlight on Press"
         };
-        cbHighlightOnPress.Checked = win.HighlightStyle == (HighlightStyle.Pressed | HighlightStyle.PressedOutside);
+        cbHighlightOnPress.State = win.HighlightStyle == (HighlightStyle.Pressed | HighlightStyle.PressedOutside) ? CheckState.Checked : CheckState.UnChecked;
 
-        cbHighlightOnPress.Toggled += (s, e) =>
+        cbHighlightOnPress.Toggle += (s, e) =>
                                       {
-                                          if (e.NewValue == true)
+                                          if (e.NewValue == CheckState.Checked)
                                           {
                                               win.HighlightStyle = HighlightStyle.Pressed | HighlightStyle.PressedOutside;
                                           }

+ 32 - 38
UICatalog/Scenarios/PosAlignDemo.cs

@@ -87,33 +87,31 @@ public sealed class PosAlignDemo : Scenario
 
         if (dimension == Dimension.Width)
         {
-            endToStartCheckBox.Checked = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart);
+            endToStartCheckBox.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked;
             endToStartCheckBox.X = Pos.Align (_horizAligner.Alignment);
             endToStartCheckBox.Y = Pos.Top (alignRadioGroup);
         }
         else
         {
-            endToStartCheckBox.Checked = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart);
+            endToStartCheckBox.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.EndToStart) ? CheckState.Checked : CheckState.UnChecked;
             endToStartCheckBox.X = Pos.Left (alignRadioGroup);
             endToStartCheckBox.Y = Pos.Align (_vertAligner.Alignment);
         }
 
-        endToStartCheckBox.Toggled += (s, e) =>
+        endToStartCheckBox.Toggle += (s, e) =>
                                       {
                                           if (dimension == Dimension.Width)
                                           {
-                                              _horizAligner.AlignmentModes =
-                                                  e.NewValue is { } && e.NewValue.Value
-                                                      ? _horizAligner.AlignmentModes | AlignmentModes.EndToStart
-                                                      : _horizAligner.AlignmentModes & ~AlignmentModes.EndToStart;
+                                              _horizAligner.AlignmentModes = e.NewValue == CheckState.Checked
+                                                                                 ? _horizAligner.AlignmentModes | AlignmentModes.EndToStart
+                                                                                 : _horizAligner.AlignmentModes & ~AlignmentModes.EndToStart;
                                               UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                                           }
                                           else
                                           {
-                                              _vertAligner.AlignmentModes =
-                                                  e.NewValue is { } && e.NewValue.Value
-                                                      ? _vertAligner.AlignmentModes | AlignmentModes.EndToStart
-                                                      : _vertAligner.AlignmentModes & ~AlignmentModes.EndToStart;
+                                              _vertAligner.AlignmentModes = e.NewValue == CheckState.Checked
+                                                                                ? _vertAligner.AlignmentModes | AlignmentModes.EndToStart
+                                                                                : _vertAligner.AlignmentModes & ~AlignmentModes.EndToStart;
                                               UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                                           }
                                       };
@@ -127,33 +125,31 @@ public sealed class PosAlignDemo : Scenario
 
         if (dimension == Dimension.Width)
         {
-            ignoreFirstOrLast.Checked = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast);
+            ignoreFirstOrLast.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked;
             ignoreFirstOrLast.X = Pos.Align (_horizAligner.Alignment);
             ignoreFirstOrLast.Y = Pos.Top (alignRadioGroup);
         }
         else
         {
-            ignoreFirstOrLast.Checked = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast);
+            ignoreFirstOrLast.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast) ? CheckState.Checked : CheckState.UnChecked;
             ignoreFirstOrLast.X = Pos.Left (alignRadioGroup);
             ignoreFirstOrLast.Y = Pos.Align (_vertAligner.Alignment);
         }
 
-        ignoreFirstOrLast.Toggled += (s, e) =>
+        ignoreFirstOrLast.Toggle += (s, e) =>
                                      {
                                          if (dimension == Dimension.Width)
                                          {
-                                             _horizAligner.AlignmentModes =
-                                                 e.NewValue is { } && e.NewValue.Value
+                                             _horizAligner.AlignmentModes = e.NewValue == CheckState.Checked
                                                      ? _horizAligner.AlignmentModes | AlignmentModes.IgnoreFirstOrLast
                                                      : _horizAligner.AlignmentModes & ~AlignmentModes.IgnoreFirstOrLast;
                                              UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                                          }
                                          else
                                          {
-                                             _vertAligner.AlignmentModes =
-                                                 e.NewValue is { } && e.NewValue.Value
-                                                     ? _vertAligner.AlignmentModes | AlignmentModes.IgnoreFirstOrLast
-                                                     : _vertAligner.AlignmentModes & ~AlignmentModes.IgnoreFirstOrLast;
+                                             _vertAligner.AlignmentModes = e.NewValue == CheckState.Checked
+                                                                               ? _vertAligner.AlignmentModes | AlignmentModes.IgnoreFirstOrLast
+                                                                               : _vertAligner.AlignmentModes & ~AlignmentModes.IgnoreFirstOrLast;
                                              UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                                          }
                                      };
@@ -167,33 +163,31 @@ public sealed class PosAlignDemo : Scenario
 
         if (dimension == Dimension.Width)
         {
-            addSpacesBetweenItems.Checked = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems);
+            addSpacesBetweenItems.State = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked;
             addSpacesBetweenItems.X = Pos.Align (_horizAligner.Alignment);
             addSpacesBetweenItems.Y = Pos.Top (alignRadioGroup);
         }
         else
         {
-            addSpacesBetweenItems.Checked = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems);
+            addSpacesBetweenItems.State = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems) ? CheckState.Checked : CheckState.UnChecked;
             addSpacesBetweenItems.X = Pos.Left (alignRadioGroup);
             addSpacesBetweenItems.Y = Pos.Align (_vertAligner.Alignment);
         }
 
-        addSpacesBetweenItems.Toggled += (s, e) =>
+        addSpacesBetweenItems.Toggle += (s, e) =>
                                          {
                                              if (dimension == Dimension.Width)
                                              {
-                                                 _horizAligner.AlignmentModes =
-                                                     e.NewValue is { } && e.NewValue.Value
-                                                         ? _horizAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems
-                                                         : _horizAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
+                                                 _horizAligner.AlignmentModes = e.NewValue == CheckState.Checked
+                                                                                    ? _horizAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems
+                                                                                    : _horizAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
                                                  UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                                              }
                                              else
                                              {
-                                                 _vertAligner.AlignmentModes =
-                                                     e.NewValue is { } && e.NewValue.Value
-                                                         ? _vertAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems
-                                                         : _vertAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
+                                                 _vertAligner.AlignmentModes = e.NewValue == CheckState.Checked
+                                                                                   ? _vertAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems
+                                                                                   : _vertAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
                                                  UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                                              }
                                          };
@@ -217,16 +211,16 @@ public sealed class PosAlignDemo : Scenario
             margin.Y = Pos.Align (_vertAligner.Alignment);
         }
 
-        margin.Toggled += (s, e) =>
+        margin.Toggle += (s, e) =>
                           {
                               if (dimension == Dimension.Width)
                               {
-                                  _leftMargin = e.NewValue is { } && e.NewValue.Value ? 1 : 0;
+                                  _leftMargin = e.NewValue == CheckState.Checked ? 1 : 0;
                                   UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                               }
                               else
                               {
-                                  _topMargin = e.NewValue is { } && e.NewValue.Value ? 1 : 0;
+                                  _topMargin = e.NewValue == CheckState.Checked ? 1 : 0;
                                   UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                               }
                           };
@@ -274,10 +268,10 @@ public sealed class PosAlignDemo : Scenario
                                               }
 
                                               // Add or remove buttons
-                                              if (e.NewValue < e.OldValue)
+                                              if (e.NewValue < e.CurrentValue)
                                               {
                                                   // Remove buttons
-                                                  for (int i = e.OldValue - 1; i >= e.NewValue; i--)
+                                                  for (int i = e.CurrentValue - 1; i >= e.NewValue; i--)
                                                   {
                                                       Button button = addedViews [i];
                                                       appWindow.Remove (button);
@@ -286,10 +280,10 @@ public sealed class PosAlignDemo : Scenario
                                                   }
                                               }
 
-                                              if (e.NewValue > e.OldValue)
+                                              if (e.NewValue > e.CurrentValue)
                                               {
                                                   // Add buttons
-                                                  for (int i = e.OldValue; i < e.NewValue; i++)
+                                                  for (int i = e.CurrentValue; i < e.NewValue; i++)
                                                   {
                                                       var button = new Button
                                                       {

+ 11 - 7
UICatalog/Scenarios/ProgressBarStyles.cs

@@ -233,7 +233,10 @@ public class ProgressBarStyles : Scenario
 
         var ckbBidirectional = new CheckBox
         {
-            X = Pos.Center (), Y = Pos.Bottom (continuousPB) + 1, Text = "BidirectionalMarquee", Checked = true
+            X = Pos.Center (),
+            Y = Pos.Bottom (continuousPB),
+            Text = "BidirectionalMarquee", 
+            State = CheckState.Checked
         };
         container.Add (ckbBidirectional);
 
@@ -276,7 +279,7 @@ public class ProgressBarStyles : Scenario
                                                                                             && v.Title == (string)e.Value
                                                                                        );
                                       };
-        
+
 
         rbPBFormat.SelectedItemChanged += (s, e) =>
                                           {
@@ -286,11 +289,12 @@ public class ProgressBarStyles : Scenario
                                               marqueesContinuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem;
                                           };
 
-        ckbBidirectional.Toggled += (s, e) =>
-                                    {
-                                        ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee =
-                                                                       marqueesContinuousPB.BidirectionalMarquee = (bool)!e.OldValue;
-                                    };
+        ckbBidirectional.Toggle += (s, e) =>
+                                   {
+                                       ckbBidirectional.State = e.NewValue;
+                                       marqueesBlocksPB.BidirectionalMarquee =
+                                                                  marqueesContinuousPB.BidirectionalMarquee = e.NewValue == CheckState.Checked;
+                                   };
 
 
 

+ 17 - 17
UICatalog/Scenarios/Scrolling.cs

@@ -148,7 +148,7 @@ public class Scrolling : Scenario
             X = Pos.X (scrollView),
             Y = Pos.Bottom (scrollView),
             Text = "Horizontal Scrollbar",
-            Checked = scrollView.ShowHorizontalScrollIndicator
+            State = scrollView.ShowHorizontalScrollIndicator ? CheckState.Checked : CheckState.UnChecked
         };
         app.Add (hCheckBox);
 
@@ -157,7 +157,7 @@ public class Scrolling : Scenario
             X = Pos.Right (hCheckBox) + 3,
             Y = Pos.Bottom (scrollView),
             Text = "Vertical Scrollbar",
-            Checked = scrollView.ShowVerticalScrollIndicator
+            State = scrollView.ShowVerticalScrollIndicator ? CheckState.Checked : CheckState.UnChecked
         };
         app.Add (vCheckBox);
 
@@ -165,50 +165,50 @@ public class Scrolling : Scenario
 
         var ahCheckBox = new CheckBox
         {
-            X = Pos.Left (scrollView), Y = Pos.Bottom (hCheckBox), Text = t, Checked = scrollView.AutoHideScrollBars
+            X = Pos.Left (scrollView), Y = Pos.Bottom (hCheckBox), Text = t, State = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked
         };
         var k = "Keep Content Always In Viewport";
 
         var keepCheckBox = new CheckBox
         {
-            X = Pos.Left (scrollView), Y = Pos.Bottom (ahCheckBox), Text = k, Checked = scrollView.AutoHideScrollBars
+            X = Pos.Left (scrollView), Y = Pos.Bottom (ahCheckBox), Text = k, State = scrollView.AutoHideScrollBars ? CheckState.Checked : CheckState.UnChecked
         };
 
-        hCheckBox.Toggled += (s, e) =>
+        hCheckBox.Toggle += (s, e) =>
                              {
-                                 if (ahCheckBox.Checked == false)
+                                 if (ahCheckBox.State == CheckState.UnChecked)
                                  {
-                                     scrollView.ShowHorizontalScrollIndicator = (bool)hCheckBox.Checked;
+                                     scrollView.ShowHorizontalScrollIndicator = e.NewValue == CheckState.Checked;
                                  }
                                  else
                                  {
-                                     hCheckBox.Checked = true;
+                                     hCheckBox.State = CheckState.Checked;
                                      MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok");
                                  }
                              };
 
-        vCheckBox.Toggled += (s, e) =>
+        vCheckBox.Toggle += (s, e) =>
                              {
-                                 if (ahCheckBox.Checked == false)
+                                 if (ahCheckBox.State == CheckState.UnChecked)
                                  {
-                                     scrollView.ShowVerticalScrollIndicator = (bool)vCheckBox.Checked;
+                                     scrollView.ShowVerticalScrollIndicator = e.NewValue == CheckState.Checked;
                                  }
                                  else
                                  {
-                                     vCheckBox.Checked = true;
+                                     vCheckBox.State = CheckState.Checked;
                                      MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok");
                                  }
                              };
 
-        ahCheckBox.Toggled += (s, e) =>
+        ahCheckBox.Toggle += (s, e) =>
                               {
-                                  scrollView.AutoHideScrollBars = (bool)ahCheckBox.Checked;
-                                  hCheckBox.Checked = true;
-                                  vCheckBox.Checked = true;
+                                  scrollView.AutoHideScrollBars = e.NewValue == CheckState.Checked;
+                                  hCheckBox.State = CheckState.Checked;
+                                  vCheckBox.State = CheckState.Checked;
                               };
         app.Add (ahCheckBox);
 
-        keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
+        keepCheckBox.Toggle += (s, e) => scrollView.KeepContentAlwaysInViewport = e.NewValue == CheckState.Checked;
         app.Add (keepCheckBox);
 
         var count = 0;

+ 3 - 3
UICatalog/Scenarios/SendKeys.cs

@@ -87,9 +87,9 @@ public class SendKeys : Scenario
                 Application.Driver.SendKeys (
                                              r,
                                              ck,
-                                             (bool)ckbShift.Checked,
-                                             (bool)ckbAlt.Checked,
-                                             (bool)ckbControl.Checked
+                                             ckbShift.State == CheckState.Checked,
+                                             ckbAlt.State == CheckState.Checked,
+                                             ckbControl.State == CheckState.Checked
                                             );
             }
 

+ 9 - 9
UICatalog/Scenarios/Shortcuts.cs

@@ -107,17 +107,17 @@ public class Shortcuts : Scenario
             KeyBindingScope = KeyBindingScope.HotKey,
         };
 
-        ((CheckBox)vShortcut3.CommandView).Toggled += (s, e) =>
+        ((CheckBox)vShortcut3.CommandView).Toggle += (s, e) =>
                                                       {
                                                           if (vShortcut3.CommandView is CheckBox cb)
                                                           {
-                                                              eventSource.Add ($"Toggled: {cb.Text}");
+                                                              eventSource.Add ($"Toggle: {cb.Text}");
                                                               eventLog.MoveDown ();
 
                                                               var max = 0;
                                                               var toAlign = Application.Top.Subviews.Where (v => v is Shortcut { Orientation: Orientation.Vertical, Width: not DimAbsolute });
 
-                                                              if (e.NewValue == true)
+                                                              if (e.NewValue == CheckState.Checked)
                                                               {
                                                                   foreach (Shortcut peer in toAlign)
                                                                   {
@@ -166,18 +166,18 @@ public class Shortcuts : Scenario
             CommandView = new CheckBox { Text = "_CanFocus" },
         };
 
-        ((CheckBox)vShortcut5.CommandView).Toggled += (s, e) =>
+        ((CheckBox)vShortcut5.CommandView).Toggle += (s, e) =>
                                                      {
                                                          if (vShortcut5.CommandView is CheckBox cb)
                                                          {
-                                                             eventSource.Add ($"Toggled: {cb.Text}");
+                                                             eventSource.Add ($"Toggle: {cb.Text}");
                                                              eventLog.MoveDown ();
 
                                                              foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
                                                              {
                                                                  if (peer.CanFocus)
                                                                  {
-                                                                     peer.CommandView.CanFocus = e.NewValue == true;
+                                                                     peer.CommandView.CanFocus = e.NewValue == CheckState.Checked;
                                                                  }
                                                              }
                                                          }
@@ -361,7 +361,7 @@ public class Shortcuts : Scenario
                                    {
                                        eventSource.Add ($"Accept: {shortcut!.CommandView.Text}");
                                        eventLog.MoveDown ();
-                                       args.Cancel = true;
+                                       args.Handled = true;
                                    };
 
                 shortcut.CommandView.Accept += (o, args) =>
@@ -372,10 +372,10 @@ public class Shortcuts : Scenario
             }
         }
 
-        //((CheckBox)vShortcut5.CommandView).OnToggled ();
+        //((CheckBox)vShortcut5.CommandView).OnToggle ();
     }
 
-    private void Button_Clicked (object sender, CancelEventArgs e)
+    private void Button_Clicked (object sender, HandledEventArgs e)
     {
         //e.Cancel = true;
         MessageBox.Query ("Hi", $"You clicked {sender}"); 

+ 2 - 2
UICatalog/Scenarios/Sliders.cs

@@ -236,7 +236,7 @@ public class Sliders : Scenario
             Y = Pos.Bottom (optionsSlider)
         };
 
-        dimAutoUsesMin.Toggled += (sender, e) =>
+        dimAutoUsesMin.Toggle += (sender, e) =>
                                   {
                                       foreach (Slider s in app.Subviews.OfType<Slider> ())
                                       {
@@ -599,7 +599,7 @@ public class Sliders : Scenario
                              {
                                  eventSource.Add ($"Accept: {string.Join(",", slider.GetSetOptions ())}");
                                  eventLog.MoveDown ();
-                                 args.Cancel = true;
+                                 args.Handled = true;
                              };
             slider.OptionsChanged += (o, args) =>
                              {

+ 10 - 10
UICatalog/Scenarios/SpinnerStyles.cs

@@ -53,7 +53,7 @@ public class SpinnerViewStyles : Scenario
             X = Pos.Center () - 7,
             Y = Pos.Bottom (preview),
             Enabled = false,
-            Checked = true,
+            State = CheckState.Checked,
             Text = "Ascii Only"
         };
         app.Add (ckbAscii);
@@ -63,20 +63,20 @@ public class SpinnerViewStyles : Scenario
             X = Pos.Center () + 7,
             Y = Pos.Bottom (preview),
             Enabled = false,
-            Checked = true,
+            State = CheckState.Checked,
             Text = "No Special"
         };
         app.Add (ckbNoSpecial);
 
         var ckbReverse = new CheckBox
         {
-            X = Pos.Center () - 22, Y = Pos.Bottom (preview) + 1, Checked = false, Text = "Reverse"
+            X = Pos.Center () - 22, Y = Pos.Bottom (preview) + 1, State = CheckState.UnChecked, Text = "Reverse"
         };
         app.Add (ckbReverse);
 
         var ckbBounce = new CheckBox
         {
-            X = Pos.Right (ckbReverse) + 2, Y = Pos.Bottom (preview) + 1, Checked = false, Text = "Bounce"
+            X = Pos.Right (ckbReverse) + 2, Y = Pos.Bottom (preview) + 1, State = CheckState.UnChecked, Text = "Bounce"
         };
         app.Add (ckbBounce);
 
@@ -157,16 +157,16 @@ public class SpinnerViewStyles : Scenario
                                               spinner.Visible = true;
                                               spinner.Style = (SpinnerStyle)Activator.CreateInstance (styleDict [e.Item].Value);
                                               delayField.Text = spinner.SpinDelay.ToString ();
-                                              ckbBounce.Checked = spinner.SpinBounce;
-                                              ckbNoSpecial.Checked = !spinner.HasSpecialCharacters;
-                                              ckbAscii.Checked = spinner.IsAsciiOnly;
-                                              ckbReverse.Checked = false;
+                                              ckbBounce.State = spinner.SpinBounce ? CheckState.Checked : CheckState.UnChecked;
+                                              ckbNoSpecial.State = !spinner.HasSpecialCharacters ? CheckState.Checked : CheckState.UnChecked;
+                                              ckbAscii.State = spinner.IsAsciiOnly ? CheckState.Checked : CheckState.UnChecked;
+                                              ckbReverse.State = CheckState.UnChecked;
                                           }
                                       };
 
-        ckbReverse.Toggled += (s, e) => { spinner.SpinReverse = (bool)!e.OldValue; };
+        ckbReverse.Toggle += (s, e) => { spinner.SpinReverse = e.NewValue == CheckState.Checked; };
 
-        ckbBounce.Toggled += (s, e) => { spinner.SpinBounce = (bool)!e.OldValue; };
+        ckbBounce.Toggle += (s, e) => { spinner.SpinBounce = e.NewValue == CheckState.Checked; };
 
         app.Unloaded += App_Unloaded;
 

+ 14 - 14
UICatalog/Scenarios/Text.cs

@@ -35,7 +35,7 @@ public class Text : Scenario
         textField.Autocomplete.SuggestionGenerator = singleWordGenerator;
         textField.TextChanging += TextField_TextChanging;
 
-        void TextField_TextChanging (object sender, StateEventArgs<string> e)
+        void TextField_TextChanging (object sender, CancelEventArgs<string> e)
         {
             singleWordGenerator.AllSuggestions = Regex.Matches (e.NewValue, "\\w+")
                                                       .Select (s => s.Value)
@@ -105,7 +105,7 @@ public class Text : Scenario
         // single-line mode.
         var chxMultiline = new CheckBox
         {
-            X = Pos.Left (textView), Y = Pos.Bottom (textView), Checked = textView.Multiline, Text = "_Multiline"
+            X = Pos.Left (textView), Y = Pos.Bottom (textView), State = textView.Multiline ? CheckState.Checked : CheckState.UnChecked, Text = "_Multiline"
         };
         Win.Add (chxMultiline);
 
@@ -113,10 +113,10 @@ public class Text : Scenario
         {
             X = Pos.Right (chxMultiline) + 2,
             Y = Pos.Top (chxMultiline),
-            Checked = textView.WordWrap,
+            State = textView.WordWrap ? CheckState.Checked : CheckState.UnChecked,
             Text = "_Word Wrap"
         };
-        chxWordWrap.Toggled += (s, e) => textView.WordWrap = (bool)e.NewValue;
+        chxWordWrap.Toggle += (s, e) => textView.WordWrap = e.NewValue == CheckState.Checked;
         Win.Add (chxWordWrap);
 
         // TextView captures Tabs (so users can enter /t into text) by default;
@@ -126,31 +126,31 @@ public class Text : Scenario
         {
             X = Pos.Right (chxWordWrap) + 2,
             Y = Pos.Top (chxWordWrap),
-            Checked = textView.AllowsTab,
+            State = textView.AllowsTab ? CheckState.Checked : CheckState.UnChecked,
             Text = "_Capture Tabs"
         };
 
-        chxMultiline.Toggled += (s, e) =>
+        chxMultiline.Toggle += (s, e) =>
                                 {
-                                    textView.Multiline = (bool)e.NewValue;
+                                    textView.Multiline = e.NewValue == CheckState.Checked;
 
-                                    if (!textView.Multiline && (bool)chxWordWrap.Checked)
+                                    if (!textView.Multiline && chxWordWrap.State == CheckState.Checked)
                                     {
-                                        chxWordWrap.Checked = false;
+                                        chxWordWrap.State = CheckState.UnChecked;
                                     }
 
-                                    if (!textView.Multiline && (bool)chxCaptureTabs.Checked)
+                                    if (!textView.Multiline && chxCaptureTabs.State == CheckState.Checked)
                                     {
-                                        chxCaptureTabs.Checked = false;
+                                        chxCaptureTabs.State = CheckState.UnChecked;
                                     }
                                 };
 
         Key keyTab = textView.KeyBindings.GetKeyFromCommands (Command.Tab);
         Key keyBackTab = textView.KeyBindings.GetKeyFromCommands (Command.BackTab);
 
-        chxCaptureTabs.Toggled += (s, e) =>
+        chxCaptureTabs.Toggle += (s, e) =>
                                   {
-                                      if (e.NewValue == true)
+                                      if (e.NewValue == CheckState.Checked)
                                       {
                                           textView.KeyBindings.Add (keyTab, Command.Tab);
                                           textView.KeyBindings.Add (keyBackTab, Command.BackTab);
@@ -161,7 +161,7 @@ public class Text : Scenario
                                           textView.KeyBindings.Remove (keyBackTab);
                                       }
 
-                                      textView.AllowsTab = (bool)e.NewValue;
+                                      textView.AllowsTab = e.NewValue == CheckState.Checked;
                                   };
         Win.Add (chxCaptureTabs);
 

+ 8 - 8
UICatalog/Scenarios/TextAlignmentAndDirection.cs

@@ -484,7 +484,7 @@ public class TextAlignmentAndDirection : Scenario
             Enabled = false
         };
 
-        justifyCheckbox.Toggled += (s, e) => ToggleJustify (e.OldValue is { } && (bool)e.OldValue);
+        justifyCheckbox.Toggle += (s, e) => ToggleJustify (e.NewValue != CheckState.Checked);
 
         justifyOptions.SelectedItemChanged += (s, e) => { ToggleJustify (false, true); };
 
@@ -500,11 +500,11 @@ public class TextAlignmentAndDirection : Scenario
             Height = 1,
             Text = "Word Wrap"
         };
-        wrapCheckbox.Checked = wrapCheckbox.TextFormatter.WordWrap;
+        wrapCheckbox.State = wrapCheckbox.TextFormatter.WordWrap ? CheckState.Checked : CheckState.UnChecked;
 
-        wrapCheckbox.Toggled += (s, e) =>
+        wrapCheckbox.Toggle += (s, e) =>
                                 {
-                                    if (e.OldValue == true)
+                                    if (e.CurrentValue == CheckState.Checked)
                                     {
                                         foreach (Label t in multiLineLabels)
                                         {
@@ -532,11 +532,11 @@ public class TextAlignmentAndDirection : Scenario
             Height = 1,
             Text = "AutoSize"
         };
-        autoSizeCheckbox.Checked = autoSizeCheckbox.TextFormatter.AutoSize;
+        autoSizeCheckbox.State = autoSizeCheckbox.TextFormatter.AutoSize ? CheckState.Checked : CheckState.UnChecked;
 
-        autoSizeCheckbox.Toggled += (s, e) =>
+        autoSizeCheckbox.Toggle += (s, e) =>
                                     {
-                                        if (e.OldValue == true)
+                                        if (e.CurrentValue == CheckState.Checked)
                                         {
                                             foreach (Label t in multiLineLabels)
                                             {
@@ -570,7 +570,7 @@ public class TextAlignmentAndDirection : Scenario
 
         directionOptions.SelectedItemChanged += (s, ev) =>
                                                 {
-                                                    bool justChecked = justifyCheckbox.Checked is { } && (bool)justifyCheckbox.Checked;
+                                                    bool justChecked = justifyCheckbox.State == CheckState.Checked;
 
                                                     if (justChecked)
                                                     {

+ 4 - 4
UICatalog/Scenarios/TextFormatterDemo.cs

@@ -58,7 +58,7 @@ public class TextFormatterDemo : Scenario
             X = 0,
             Y = Pos.Bottom (blockText) + 1,
             Text = "Unicode",
-            Checked = app.HotKeySpecifier == (Rune)' '
+            State = app.HotKeySpecifier == (Rune)' ' ? CheckState.Checked : CheckState.UnChecked
         };
 
         app.Add (unicodeCheckBox);
@@ -133,12 +133,12 @@ public class TextFormatterDemo : Scenario
             label = multipleLines [i];
         }
 
-        unicodeCheckBox.Toggled += (s, e) =>
+        unicodeCheckBox.Toggle += (s, e) =>
                                    {
                                        for (int i = 0; i < alignments.Count; i++)
                                        {
-                                           singleLines [i].Text = e.OldValue == true ? text : unicode;
-                                           multipleLines [i].Text = e.OldValue == true ? text : unicode;
+                                           singleLines [i].Text = e.CurrentValue == CheckState.Checked ? text : unicode;
+                                           multipleLines [i].Text = e.CurrentValue == CheckState.Checked ? text : unicode;
                                        }
                                    };
 

+ 15 - 15
UICatalog/Scenarios/TileViewNesting.cs

@@ -31,16 +31,16 @@ public class TileViewNesting : Scenario
         _textField.TextChanged += (s, e) => SetupTileView ();
 
         _cbHorizontal = new() { X = Pos.Right (_textField) + 1, Text = "Horizontal" };
-        _cbHorizontal.Toggled += (s, e) => SetupTileView ();
+        _cbHorizontal.Toggle += (s, e) => SetupTileView ();
 
         _cbBorder = new() { X = Pos.Right (_cbHorizontal) + 1, Text = "Border" };
-        _cbBorder.Toggled += (s, e) => SetupTileView ();
+        _cbBorder.Toggle += (s, e) => SetupTileView ();
 
         _cbTitles = new() { X = Pos.Right (_cbBorder) + 1, Text = "Titles" };
-        _cbTitles.Toggled += (s, e) => SetupTileView ();
+        _cbTitles.Toggle += (s, e) => SetupTileView ();
 
         _cbUseLabels = new() { X = Pos.Right (_cbTitles) + 1, Text = "Use Labels" };
-        _cbUseLabels.Toggled += (s, e) => SetupTileView ();
+        _cbUseLabels.Toggle += (s, e) => SetupTileView ();
 
         _workArea = new() { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill () };
 
@@ -91,7 +91,7 @@ public class TileViewNesting : Scenario
         }
     }
 
-    private View CreateContentControl (int number) { return (bool)_cbUseLabels.Checked ? CreateLabelView (number) : CreateTextView (number); }
+    private View CreateContentControl (int number) { return _cbUseLabels.State == CheckState.Checked ? CreateLabelView (number) : CreateTextView (number); }
 
     private View CreateLabelView (int number)
     {
@@ -126,8 +126,8 @@ public class TileViewNesting : Scenario
             Orientation = orientation
         };
 
-        toReturn.Tiles.ElementAt (0).Title = (bool)_cbTitles.Checked ? $"View {titleNumber}" : string.Empty;
-        toReturn.Tiles.ElementAt (1).Title = (bool)_cbTitles.Checked ? $"View {titleNumber + 1}" : string.Empty;
+        toReturn.Tiles.ElementAt (0).Title = _cbTitles.State == CheckState.Checked ? $"View {titleNumber}" : string.Empty;
+        toReturn.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? $"View {titleNumber + 1}" : string.Empty;
 
         return toReturn;
     }
@@ -148,9 +148,9 @@ public class TileViewNesting : Scenario
     {
         int numberOfViews = GetNumberOfViews ();
 
-        bool? titles = _cbTitles.Checked;
-        bool? border = _cbBorder.Checked;
-        bool? startHorizontal = _cbHorizontal.Checked;
+        CheckState titles = _cbTitles.State;
+        CheckState border = _cbBorder.State;
+        CheckState startHorizontal = _cbHorizontal.State;
 
         foreach (View sub in _workArea.Subviews)
         {
@@ -164,14 +164,14 @@ public class TileViewNesting : Scenario
             return;
         }
 
-        TileView root = CreateTileView (1, (bool)startHorizontal ? Orientation.Horizontal : Orientation.Vertical);
+        TileView root = CreateTileView (1, startHorizontal == CheckState.Checked ? Orientation.Horizontal : Orientation.Vertical);
 
         root.Tiles.ElementAt (0).ContentView.Add (CreateContentControl (1));
-        root.Tiles.ElementAt (0).Title = (bool)_cbTitles.Checked ? "View 1" : string.Empty;
+        root.Tiles.ElementAt (0).Title = _cbTitles.State == CheckState.Checked ? "View 1" : string.Empty;
         root.Tiles.ElementAt (1).ContentView.Add (CreateContentControl (2));
-        root.Tiles.ElementAt (1).Title = (bool)_cbTitles.Checked ? "View 2" : string.Empty;
+        root.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? "View 2" : string.Empty;
 
-        root.LineStyle = (bool)border ? LineStyle.Rounded : LineStyle.None;
+        root.LineStyle = border  == CheckState.Checked? LineStyle.Rounded : LineStyle.None;
 
         _workArea.Add (root);
 
@@ -215,7 +215,7 @@ public class TileViewNesting : Scenario
 
         // During splitting the old Title will have been migrated to View1 so we only need
         // to set the Title on View2 (the one that gets our new TextView)
-        newView.Tiles.ElementAt (1).Title = (bool)_cbTitles.Checked ? $"View {_viewsCreated}" : string.Empty;
+        newView.Tiles.ElementAt (1).Title = _cbTitles.State == CheckState.Checked ? $"View {_viewsCreated}" : string.Empty;
 
         // Flip orientation
         newView.Orientation = to.Orientation == Orientation.Vertical

+ 4 - 3
UICatalog/Scenarios/TrueColors.cs

@@ -32,8 +32,9 @@ public class TrueColors : Scenario
         {
             X = x,
             Y = y++,
-            Checked = canTrueColor,
+            State = canTrueColor ? CheckState.Checked : CheckState.UnChecked,
             CanFocus = false,
+            Enabled = false,
             Text = "Driver supports true color "
         };
         app.Add (cbSupportsTrueColor);
@@ -42,11 +43,11 @@ public class TrueColors : Scenario
         {
             X = x,
             Y = y++,
-            Checked = Application.Force16Colors,
+            State = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
             Enabled = canTrueColor,
             Text = "Force 16 colors"
         };
-        cbUseTrueColor.Toggled += (_, evt) => { Application.Force16Colors = evt.NewValue ?? false; };
+        cbUseTrueColor.Toggle += (_, evt) => { Application.Force16Colors = evt.NewValue == CheckState.Checked; };
         app.Add (cbUseTrueColor);
 
         y += 2;

+ 7 - 7
UICatalog/Scenarios/Wizards.cs

@@ -195,7 +195,7 @@ public class Wizards : Scenario
                                            var thirdStepEnabledCeckBox = new CheckBox
                                            {
                                                Text = "Enable Step _3",
-                                               Checked = false,
+                                               State = CheckState.UnChecked,
                                                X = Pos.Left (lastNameField),
                                                Y = Pos.Bottom (lastNameField)
                                            };
@@ -242,8 +242,8 @@ public class Wizards : Scenario
                                                X = Pos.Right (progLbl), Y = Pos.Top (progLbl), Width = 40, Fraction = 0.42F
                                            };
                                            thirdStep.Add (progLbl, progressBar);
-                                           thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked;
-                                           thirdStepEnabledCeckBox.Toggled += (s, e) => { thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked; };
+                                           thirdStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked;
+                                           thirdStepEnabledCeckBox.Toggle += (s, e) => { thirdStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked; };
 
                                            // Add 4th step
                                            var fourthStep = new WizardStep { Title = "Step Four" };
@@ -320,7 +320,7 @@ public class Wizards : Scenario
                                                "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing ESC will cancel the wizard.";
 
                                            var finalFinalStepEnabledCeckBox =
-                                               new CheckBox { Text = "Enable _Final Final Step", Checked = false, X = 0, Y = 1 };
+                                               new CheckBox { Text = "Enable _Final Final Step", State = CheckState.UnChecked, X = 0, Y = 1 };
                                            lastStep.Add (finalFinalStepEnabledCeckBox);
 
                                            // Add an optional FINAL last step
@@ -329,11 +329,11 @@ public class Wizards : Scenario
 
                                            finalFinalStep.HelpText =
                                                "This step only shows if it was enabled on the other last step.";
-                                           finalFinalStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked;
+                                           finalFinalStep.Enabled = thirdStepEnabledCeckBox.State == CheckState.Checked;
 
-                                           finalFinalStepEnabledCeckBox.Toggled += (s, e) =>
+                                           finalFinalStepEnabledCeckBox.Toggle += (s, e) =>
                                                                                    {
-                                                                                       finalFinalStep.Enabled = (bool)finalFinalStepEnabledCeckBox.Checked;
+                                                                                       finalFinalStep.Enabled = finalFinalStepEnabledCeckBox.State == CheckState.Checked;
                                                                                    };
 
                                            Application.Run (wizard);

+ 4 - 6
UICatalog/UICatalog.cs

@@ -475,20 +475,18 @@ internal class UICatalogApp
                     CommandView = new CheckBox ()
                     {
                         Title = "16 color mode",
-                        Checked = Application.Force16Colors,
+                        State = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
                         CanFocus = false,
                     },
                     HelpText = "",
                     Key = Key.F6,
                 };
 
-                ShForce16Colors.Accept += (sender, args) =>
+                ((CheckBox)ShForce16Colors.CommandView).Toggle += (sender, args) =>
                                           {
-                                              ((CheckBox)ShForce16Colors.CommandView).Checked =
-                                                  Application.Force16Colors = (bool)!((CheckBox)ShForce16Colors.CommandView).Checked!;
+                                              Application.Force16Colors = args.NewValue == CheckState.Checked;
                                               MiForce16Colors!.Checked = Application.Force16Colors;
                                               Application.Refresh ();
-
                                           };
 
                 //ShDiagnostics = new Shortcut ()
@@ -1008,7 +1006,7 @@ internal class UICatalogApp
             MiForce16Colors.Action += () =>
                                       {
                                           MiForce16Colors.Checked = Application.Force16Colors = (bool)!MiForce16Colors.Checked!;
-                                          ((CheckBox)ShForce16Colors!.CommandView!).Checked = Application.Force16Colors;
+                                          ((CheckBox)ShForce16Colors!.CommandView!).State = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
                                           Application.Refresh ();
                                       };
             menuItems.Add (MiForce16Colors);

+ 4 - 4
UnitTests/Application/ApplicationTests.cs

@@ -295,9 +295,9 @@ public class ApplicationTests
 
         return;
 
-        void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
+        void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
         {
-            if (a.NewValue)
+            if (a.CurrentValue)
             {
                 initialized = true;
             }
@@ -1151,9 +1151,9 @@ public class ApplicationTests
 
         return;
 
-        void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
+        void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
         {
-            if (a.NewValue)
+            if (a.CurrentValue)
             {
                 Application.Iteration += OnApplicationOnIteration;
                 initialized = true;

+ 3 - 3
UnitTests/Application/KeyboardTests.cs

@@ -129,10 +129,10 @@ public class KeyboardTests
 
         return;
 
-        void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
+        void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
         {
-            _output.WriteLine ("OnApplicationOnInitializedChanged: {0}", a.NewValue);
-            if (a.NewValue)
+            _output.WriteLine ("OnApplicationOnInitializedChanged: {0}", a.CurrentValue);
+            if (a.CurrentValue)
             {
                 Application.Iteration += OnApplicationOnIteration;
                 initialized = true;

+ 1 - 1
UnitTests/Dialogs/WizardTests.cs

@@ -597,7 +597,7 @@ public class WizardTests ()
         Assert.Equal (string.Empty, r.Title);
 
         var expected = string.Empty;
-        r.TitleChanged += (s, args) => { Assert.Equal (r.Title, args.NewValue); };
+        r.TitleChanged += (s, args) => { Assert.Equal (r.Title, args.CurrentValue); };
 
         expected = "title";
         r.Title = expected;

+ 2 - 2
UnitTests/UICatalog/ScenarioTests.cs

@@ -73,9 +73,9 @@ public class ScenarioTests : TestsAllViews
 
         return;
 
-        void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
+        void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
         {
-            if (a.NewValue)
+            if (a.CurrentValue)
             {
                 Application.Iteration += OnApplicationOnIteration;
                 initialized = true;

+ 0 - 3
UnitTests/View/Adornment/AdornmentTests.cs

@@ -322,12 +322,9 @@ public class AdornmentTests (ITestOutputHelper output)
         var adornment = new Adornment (null);
         var super = new View ();
         var raised = false;
-
         adornment.ThicknessChanged += (s, e) =>
                                       {
                                           raised = true;
-                                          Assert.Equal (Thickness.Empty, e.PreviousThickness);
-                                          Assert.Equal (new Thickness (1, 2, 3, 4), e.Thickness);
                                           Assert.Equal (new Thickness (1, 2, 3, 4), adornment.Thickness);
                                       };
         adornment.Thickness = new Thickness (1, 2, 3, 4);

+ 4 - 4
UnitTests/View/MouseTests.cs

@@ -566,9 +566,9 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews
 
         return;
 
-        void View_Highlight (object sender, HighlightEventArgs e)
+        void View_Highlight (object sender, CancelEventArgs<HighlightStyle> e)
         {
-            if (e.HighlightStyle == HighlightStyle.None)
+            if (e.NewValue == HighlightStyle.None)
             {
                 disablingHighlight++;
             }
@@ -635,9 +635,9 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews
 
         return;
 
-        void View_Highlight (object sender, HighlightEventArgs e)
+        void View_Highlight (object sender, CancelEventArgs<HighlightStyle> e)
         {
-            if (e.HighlightStyle == HighlightStyle.None)
+            if (e.NewValue == HighlightStyle.None)
             {
                 disablingHighlight++;
             }

+ 39 - 40
UnitTests/View/TitleTests.cs

@@ -5,6 +5,43 @@ namespace Terminal.Gui.ViewTests;
 
 public class TitleTests (ITestOutputHelper output)
 {
+    [SetupFakeDriver]
+    [Fact]
+    public void Change_View_Size_Update_Title_Size ()
+    {
+        var view = new View
+        {
+            Title = "_Hello World",
+            Width = Dim.Auto (),
+            Height = Dim.Auto (),
+            BorderStyle = LineStyle.Single
+        };
+        var top = new Toplevel ();
+        top.Add (view);
+        top.BeginInit ();
+        top.EndInit ();
+
+        Assert.Equal (string.Empty, view.Text);
+        Assert.Equal (new (2, 2), view.Frame.Size);
+        top.Draw ();
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
+┌┐
+└┘",
+                                                      output);
+
+        var text = "This text will increment the view size and display the title.";
+        view.Text = text;
+        top.Draw ();
+        Assert.Equal (text, view.Text);
+
+        // SetupFakeDriver only create a screen with 25 cols and 25 rows
+        Assert.Equal (new (text.Length, 1), view.GetContentSize ());
+
+        top.Dispose ();
+    }
+
     [Fact]
     public void Set_Title_Fires_TitleChanged ()
     {
@@ -16,8 +53,7 @@ public class TitleTests (ITestOutputHelper output)
 
         r.TitleChanged += (s, args) =>
                           {
-                              Assert.Equal (expectedOld, args.OldValue);
-                              Assert.Equal (r.Title, args.NewValue);
+                              Assert.Equal (r.Title, args.CurrentValue);
                           };
 
         expected = "title";
@@ -40,7 +76,7 @@ public class TitleTests (ITestOutputHelper output)
 
         r.TitleChanging += (s, args) =>
                            {
-                               Assert.Equal (expectedOld, args.OldValue);
+                               Assert.Equal (expectedOld, args.CurrentValue);
                                Assert.Equal (expectedDuring, args.NewValue);
                                args.Cancel = cancel;
                            };
@@ -69,41 +105,4 @@ public class TitleTests (ITestOutputHelper output)
 
         Assert.Equal (Key.H, view.HotKey);
     }
-
-    [SetupFakeDriver]
-    [Fact]
-    public void Change_View_Size_Update_Title_Size ()
-    {
-        var view = new View
-        {
-            Title = "_Hello World",
-            Width = Dim.Auto (),
-            Height = Dim.Auto (),
-            BorderStyle = LineStyle.Single
-        };
-        var top = new Toplevel ();
-        top.Add (view);
-        top.BeginInit ();
-        top.EndInit ();
-
-        Assert.Equal (string.Empty, view.Text);
-        Assert.Equal (new (2, 2), view.Frame.Size);
-        top.Draw ();
-
-        TestHelpers.AssertDriverContentsWithFrameAre (
-                                                      @"
-┌┐
-└┘",
-                                                      output);
-
-        var text = "This text will increment the view size and display the title.";
-        view.Text = text;
-        top.Draw ();
-        Assert.Equal (text, view.Text);
-
-        // SetupFakeDriver only create a screen with 25 cols and 25 rows
-        Assert.Equal (new (text.Length, 1), view.GetContentSize ());
-
-        top.Dispose ();
-    }
 }

+ 4 - 4
UnitTests/View/ViewTests.cs

@@ -1198,7 +1198,7 @@ At 0,0
 
         return;
 
-        void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void ViewOnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -1215,10 +1215,10 @@ At 0,0
 
         return;
 
-        void ViewOnAccept (object sender, CancelEventArgs e)
+        void ViewOnAccept (object sender, HandledEventArgs e)
         {
             acceptInvoked = true;
-            e.Cancel = true;
+            e.Handled = true;
         }
     }
 
@@ -1235,7 +1235,7 @@ At 0,0
 
         return;
 
-        void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void ViewOnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]

+ 3 - 3
UnitTests/Views/ButtonTests.cs

@@ -484,7 +484,7 @@ public class ButtonTests (ITestOutputHelper output)
 
         return;
 
-        void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void ButtonOnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -503,10 +503,10 @@ public class ButtonTests (ITestOutputHelper output)
 
         return;
 
-        void ButtonAccept (object sender, CancelEventArgs e)
+        void ButtonAccept (object sender, HandledEventArgs e)
         {
             acceptInvoked = true;
-            e.Cancel = true;
+            e.Handled = true;
         }
     }
 

+ 70 - 70
UnitTests/Views/CheckBoxTests.cs

@@ -77,7 +77,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         Assert.Equal ("Hello", view.TitleTextFormatter.Text);
 
         Assert.Equal ("Hello", view.Text);
-        Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} Hello", view.TextFormatter.Text);
     }
 
     [Fact]
@@ -86,7 +86,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         var view = new CheckBox ();
         view.Text = "Hello";
         Assert.Equal ("Hello", view.Text);
-        Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} Hello", view.TextFormatter.Text);
 
         Assert.Equal ("Hello", view.Title);
         Assert.Equal ("Hello", view.TitleTextFormatter.Text);
@@ -94,35 +94,35 @@ public class CheckBoxTests (ITestOutputHelper output)
 
     [Fact]
     [SetupFakeDriver]
-    public void AllowNullChecked_Get_Set ()
+    public void AllowNoneChecked_Get_Set ()
     {
         var checkBox = new CheckBox { Text = "Check this out 你" };
 
-        Assert.False (checkBox.Checked);
+        Assert.Equal (CheckState.UnChecked, checkBox.State);
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
-        Assert.True (checkBox.Checked);
-        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
-        Assert.False (checkBox.Checked);
+        Assert.Equal (CheckState.Checked, checkBox.State);
+        Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.Equal (CheckState.UnChecked, checkBox.State);
 
-        checkBox.AllowNullChecked = true;
+        checkBox.AllowCheckStateNone = true;
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
-        Assert.Null (checkBox.Checked);
-        checkBox.Draw();
+        Assert.Equal (CheckState.None, checkBox.State);
+        checkBox.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @$"
-{CM.Glyphs.NullChecked} Check this out 你",
+{CM.Glyphs.CheckStateNone} Check this out 你",
                                                       output
                                                      );
-        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
-        Assert.True (checkBox.Checked);
+        Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.Equal (CheckState.Checked, checkBox.State);
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
-        Assert.False (checkBox.Checked);
-        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
-        Assert.Null (checkBox.Checked);
+        Assert.Equal (CheckState.UnChecked, checkBox.State);
+        Assert.True (checkBox.NewMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.Equal (CheckState.None, checkBox.State);
 
-        checkBox.AllowNullChecked = false;
-        Assert.False (checkBox.Checked);
+        checkBox.AllowCheckStateNone = false;
+        Assert.Equal (CheckState.UnChecked, checkBox.State);
     }
 
     [Fact]
@@ -131,40 +131,40 @@ public class CheckBoxTests (ITestOutputHelper output)
         var ckb = new CheckBox ();
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
-        Assert.False (ckb.Checked);
-        Assert.False (ckb.AllowNullChecked);
+        Assert.Equal (CheckState.UnChecked, ckb.State);
+        Assert.False (ckb.AllowCheckStateNone);
         Assert.Equal (string.Empty, ckb.Text);
-        Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} ", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
         Assert.Equal (new (0, 0, 2, 1), ckb.Frame);
 
-        ckb = new() { Text = "Test", Checked = true };
+        ckb = new () { Text = "Test", State = CheckState.Checked };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
-        Assert.True (ckb.Checked);
-        Assert.False (ckb.AllowNullChecked);
+        Assert.Equal (CheckState.Checked, ckb.State);
+        Assert.False (ckb.AllowCheckStateNone);
         Assert.Equal ("Test", ckb.Text);
-        Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateChecked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
         Assert.Equal (new (0, 0, 6, 1), ckb.Frame);
 
-        ckb = new() { Text = "Test", X = 1, Y = 2 };
+        ckb = new () { Text = "Test", X = 1, Y = 2 };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
-        Assert.False (ckb.Checked);
-        Assert.False (ckb.AllowNullChecked);
+        Assert.Equal (CheckState.UnChecked, ckb.State);
+        Assert.False (ckb.AllowCheckStateNone);
         Assert.Equal ("Test", ckb.Text);
-        Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateUnChecked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
         Assert.Equal (new (1, 2, 6, 1), ckb.Frame);
 
-        ckb = new() { Text = "Test", X = 3, Y = 4, Checked = true };
+        ckb = new () { Text = "Test", X = 3, Y = 4, State = CheckState.Checked };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
-        Assert.True (ckb.Checked);
-        Assert.False (ckb.AllowNullChecked);
+        Assert.Equal (CheckState.Checked, ckb.State);
+        Assert.False (ckb.AllowCheckStateNone);
         Assert.Equal ("Test", ckb.Text);
-        Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
+        Assert.Equal ($"{CM.Glyphs.CheckStateChecked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
         Assert.Equal (new (3, 4, 6, 1), ckb.Frame);
     }
@@ -174,16 +174,16 @@ public class CheckBoxTests (ITestOutputHelper output)
     {
         var toggled = false;
         var ckb = new CheckBox ();
-        ckb.Toggled += (s, e) => toggled = true;
+        ckb.Toggle += (s, e) => toggled = true;
 
-        Assert.False (ckb.Checked);
+        Assert.Equal (CheckState.UnChecked, ckb.State);
         Assert.False (toggled);
         Assert.Equal (Key.Empty, ckb.HotKey);
 
         ckb.Text = "_Test";
         Assert.Equal (Key.T, ckb.HotKey);
         Assert.True (ckb.NewKeyDownEvent (Key.T));
-        Assert.True (ckb.Checked);
+        Assert.Equal (CheckState.Checked, ckb.State);
         Assert.True (toggled);
 
         ckb.Text = "T_est";
@@ -191,28 +191,28 @@ public class CheckBoxTests (ITestOutputHelper output)
         Assert.Equal (Key.E, ckb.HotKey);
         Assert.True (ckb.NewKeyDownEvent (Key.E.WithAlt));
         Assert.True (toggled);
-        Assert.False (ckb.Checked);
+        Assert.Equal (CheckState.UnChecked, ckb.State);
 
         toggled = false;
         Assert.Equal (Key.E, ckb.HotKey);
         Assert.True (ckb.NewKeyDownEvent (Key.E));
         Assert.True (toggled);
-        Assert.True (ckb.Checked);
+        Assert.Equal (CheckState.Checked, ckb.State);
 
         toggled = false;
         Assert.True (ckb.NewKeyDownEvent (Key.Space));
         Assert.True (toggled);
-        Assert.False (ckb.Checked);
+        Assert.Equal (CheckState.UnChecked, ckb.State);
 
         toggled = false;
         Assert.True (ckb.NewKeyDownEvent (Key.Space));
         Assert.True (toggled);
-        Assert.True (ckb.Checked);
+        Assert.Equal (CheckState.Checked, ckb.State);
 
         toggled = false;
         Assert.False (ckb.NewKeyDownEvent (Key.Enter));
         Assert.False (toggled);
-        Assert.True (ckb.Checked);
+        Assert.Equal (CheckState.Checked, ckb.State);
     }
 
     [Fact]
@@ -229,10 +229,10 @@ public class CheckBoxTests (ITestOutputHelper output)
 
         return;
 
-        void ViewOnAccept (object sender, CancelEventArgs e)
+        void ViewOnAccept (object sender, HandledEventArgs e)
         {
             acceptInvoked = true;
-            e.Cancel = true;
+            e.Handled = true;
         }
     }
 
@@ -263,7 +263,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         var expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│    {CM.Glyphs.UnChecked} Check this out 你     │
+│    {CM.Glyphs.CheckStateUnChecked} Check this out 你     │
 │                            │
 └────────────────────────────┘
 ";
@@ -271,13 +271,13 @@ public class CheckBoxTests (ITestOutputHelper output)
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
-        checkBox.Checked = true;
+        checkBox.State = CheckState.Checked;
         Application.Refresh ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│    {CM.Glyphs.Checked} Check this out 你     │
+│    {CM.Glyphs.CheckStateChecked} Check this out 你     │
 │                            │
 └────────────────────────────┘
 ";
@@ -324,8 +324,8 @@ public class CheckBoxTests (ITestOutputHelper output)
         var expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│ {CM.Glyphs.UnChecked}   Check  first  out  你  │
-│ {CM.Glyphs.UnChecked}  Check  second  out  你  │
+│ {CM.Glyphs.CheckStateUnChecked}   Check  first  out  你  │
+│ {CM.Glyphs.CheckStateUnChecked}  Check  second  out  你  │
 │                            │
 └────────────────────────────┘
 ";
@@ -333,10 +333,10 @@ public class CheckBoxTests (ITestOutputHelper output)
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 6), pos);
 
-        checkBox1.Checked = true;
+        checkBox1.State = CheckState.Checked;
         Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
         Assert.Equal (_size25x1, checkBox1.TextFormatter.Size);
-        checkBox2.Checked = true;
+        checkBox2.State = CheckState.Checked;
         Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
         Assert.Equal (_size25x1, checkBox2.TextFormatter.Size);
         Application.Refresh ();
@@ -344,8 +344,8 @@ public class CheckBoxTests (ITestOutputHelper output)
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│ {CM.Glyphs.Checked}   Check  first  out  你  │
-│ {CM.Glyphs.Checked}  Check  second  out  你  │
+│ {CM.Glyphs.CheckStateChecked}   Check  first  out  你  │
+│ {CM.Glyphs.CheckStateChecked}  Check  second  out  你  │
 │                            │
 └────────────────────────────┘
 ";
@@ -381,7 +381,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         var expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│ {CM.Glyphs.UnChecked} Check this out 你        │
+│ {CM.Glyphs.CheckStateUnChecked} Check this out 你        │
 │                            │
 └────────────────────────────┘
 ";
@@ -389,13 +389,13 @@ public class CheckBoxTests (ITestOutputHelper output)
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
-        checkBox.Checked = true;
+        checkBox.State = CheckState.Checked;
         Application.Refresh ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│ {CM.Glyphs.Checked} Check this out 你        │
+│ {CM.Glyphs.CheckStateChecked} Check this out 你        │
 │                            │
 └────────────────────────────┘
 ";
@@ -432,7 +432,7 @@ public class CheckBoxTests (ITestOutputHelper output)
         var expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│       Check this out 你 {CM.Glyphs.UnChecked}  │
+│       Check this out 你 {CM.Glyphs.CheckStateUnChecked}  │
 │                            │
 └────────────────────────────┘
 ";
@@ -440,13 +440,13 @@ public class CheckBoxTests (ITestOutputHelper output)
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
-        checkBox.Checked = true;
+        checkBox.State = CheckState.Checked;
         Application.Refresh ();
 
         expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
-│       Check this out 你 {CM.Glyphs.Checked}  │
+│       Check this out 你 {CM.Glyphs.CheckStateChecked}  │
 │                            │
 └────────────────────────────┘
 ";
@@ -469,30 +469,30 @@ public class CheckBoxTests (ITestOutputHelper output)
 
         return;
 
-        void CheckBoxOnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void CheckBoxOnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Theory]
-    [InlineData (true)]
-    [InlineData (false)]
-    [InlineData (null)]
-    public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
+    [InlineData (CheckState.Checked)]
+    [InlineData (CheckState.UnChecked)]
+    [InlineData (CheckState.None)]
+    public void Toggled_Cancel_Event_Prevents_Toggle (CheckState initialState)
     {
-        var ckb = new CheckBox { AllowNullChecked = true };
+        var ckb = new CheckBox { AllowCheckStateNone = true };
         var checkedInvoked = false;
 
-        ckb.Toggled += CheckBoxToggled;
+        ckb.Toggle += CheckBoxToggle;
 
-        ckb.Checked = initialState;
-        Assert.Equal (initialState, ckb.Checked);
-        bool? ret = ckb.OnToggled ();
+        ckb.State = initialState;
+        Assert.Equal (initialState, ckb.State);
+        bool? ret = ckb.OnToggle ();
         Assert.True (ret);
         Assert.True (checkedInvoked);
-        Assert.Equal (initialState, ckb.Checked);
+        Assert.Equal (initialState, ckb.State);
 
         return;
 
-        void CheckBoxToggled (object sender, CancelEventArgs e)
+        void CheckBoxToggle (object sender, CancelEventArgs e)
         {
             checkedInvoked = true;
             e.Cancel = true;

+ 1 - 0
UnitTests/Views/ComboBoxTests.cs

@@ -828,6 +828,7 @@ Three ",
         Assert.Equal ("Tw", cb.Text);
         Assert.False (cb.IsShow);
         cb.SetSource<string> (null);
+        Assert.False (cb.IsShow);
         Assert.False (cb.NewKeyDownEvent (Key.Enter));
         Assert.True (cb.NewKeyDownEvent (Key.F4)); // with no source also expand empty
         Assert.True (cb.IsShow);

+ 1 - 1
UnitTests/Views/LabelTests.cs

@@ -81,7 +81,7 @@ public class LabelTests (ITestOutputHelper output)
 
         return;
 
-        void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void LabelOnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]

+ 4 - 4
UnitTests/Views/ListViewTests.cs

@@ -420,7 +420,7 @@ Item 6",
 
         return;
 
-        void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void OnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -451,7 +451,7 @@ Item 6",
             selectedValue = e.Value.ToString ();
         }
 
-        void Accept (object sender, CancelEventArgs e) { accepted = true; }
+        void Accept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -482,10 +482,10 @@ Item 6",
             selectedValue = e.Value.ToString ();
         }
 
-        void Accept (object sender, CancelEventArgs e)
+        void Accept (object sender, HandledEventArgs e)
         {
             accepted = true;
-            e.Cancel = true;
+            e.Handled = true;
         }
     }
 

+ 1 - 1
UnitTests/Views/MenuBarTests.cs

@@ -64,7 +64,7 @@ public class MenuBarTests (ITestOutputHelper output)
  Nullable Checked       
 ┌──────────────────────┐
 │ {
-    CM.Glyphs.NullChecked
+    CM.Glyphs.CheckStateNone
 } Check this out 你  │
 └──────────────────────┘",
                                                       output

+ 2 - 2
UnitTests/Views/RadioGroupTests.cs

@@ -189,7 +189,7 @@ public class RadioGroupTests (ITestOutputHelper output)
 
         return;
 
-        void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void OnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -205,7 +205,7 @@ public class RadioGroupTests (ITestOutputHelper output)
 
         return;
 
-        void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void OnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]

+ 97 - 12
UnitTests/Views/TextFieldTests.cs

@@ -363,7 +363,7 @@ public class TextFieldTests (ITestOutputHelper output)
 
         _textField.TextChanging += _textField_TextChanging;
 
-        void _textField_TextChanging (object sender, StateEventArgs<string> e)
+        void _textField_TextChanging (object sender, CancelEventArgs<string> e)
         {
             if (e.NewValue.GetRuneCount () > 11)
             {
@@ -429,8 +429,11 @@ public class TextFieldTests (ITestOutputHelper output)
         var oldText = "";
         var tf = new TextField { Width = 10, Text = "-1" };
 
-        tf.TextChanging += (s, e) => newText = e.NewValue;
-        tf.TextChanged += (s, e) => oldText = e.OldValue;
+        tf.TextChanging += (s, e) =>
+                           {
+                               newText = e.NewValue;
+                               oldText = e.CurrentValue;
+                           };
 
         var top = new Toplevel ();
         top.Add (tf);
@@ -771,7 +774,7 @@ public class TextFieldTests (ITestOutputHelper output)
 
         return;
 
-        void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
+        void OnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -786,7 +789,86 @@ public class TextFieldTests (ITestOutputHelper output)
 
         return;
 
-        void Accept (object sender, CancelEventArgs e) { accepted = true; }
+        void Accept (object sender, HandledEventArgs e) { accepted = true; }
+    }
+
+    [Theory]
+    [InlineData (false, 0)]
+    [InlineData (true, 1)]
+    public void Accept_Handler_Handled_Prevents_Default_Button_Accept (bool handleAccept, int expectedButtonAccepts)
+    {
+        var superView = new Window ();
+        var tf = new TextField ();
+        var button = new Button ()
+        {
+            IsDefault = true,
+        };
+
+        superView.Add (tf, button);
+
+        var buttonAccept = 0;
+        button.Accept += ButtonAccept;
+
+        var textFieldAccept = 0;
+        tf.Accept += TextFieldAccept;
+
+        tf.SetFocus ();
+        Assert.True (tf.HasFocus);
+
+        superView.NewKeyDownEvent (Key.Enter);
+        Assert.Equal (1, textFieldAccept);
+        Assert.Equal (expectedButtonAccepts, buttonAccept);
+
+        button.SetFocus ();
+        superView.NewKeyDownEvent (Key.Enter);
+        Assert.Equal (1, textFieldAccept);
+        Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
+
+        return;
+
+        void TextFieldAccept (object sender, HandledEventArgs e)
+        {
+            textFieldAccept++;
+            e.Handled = handleAccept;
+        }
+
+        void ButtonAccept (object sender, HandledEventArgs e)
+        {
+            buttonAccept++;
+        }
+    }
+
+    [Fact]
+    public void Accept_No_Handler_Enables_Default_Button_Accept ()
+    {
+        var superView = new Window ();
+        var tf = new TextField ();
+        var button = new Button ()
+        {
+            IsDefault = true,
+        };
+
+        superView.Add (tf, button);
+
+        var buttonAccept = 0;
+        button.Accept += ButtonAccept;
+
+        tf.SetFocus ();
+        Assert.True (tf.HasFocus);
+
+        superView.NewKeyDownEvent (Key.Enter);
+        Assert.Equal (1, buttonAccept);
+
+        button.SetFocus ();
+        superView.NewKeyDownEvent (Key.Enter);
+        Assert.Equal (2, buttonAccept);
+
+        return;
+
+        void ButtonAccept (object sender, HandledEventArgs e)
+        {
+            buttonAccept++;
+        }
     }
 
     [Fact]
@@ -800,23 +882,23 @@ public class TextFieldTests (ITestOutputHelper output)
         //var superAcceptedInvoked = false;
 
         var tfAcceptedInvoked = false;
-        var cancel = false;
+        var handle = false;
         view.Accept += TextViewAccept;
         Assert.True (view.InvokeCommand (Command.Accept));
         Assert.True (tfAcceptedInvoked);
 
         tfAcceptedInvoked = false;
-        cancel = true;
+        handle = true;
         view.Accept += TextViewAccept;
         Assert.False (view.InvokeCommand (Command.Accept));
         Assert.True (tfAcceptedInvoked);
 
         return;
 
-        void TextViewAccept (object sender, CancelEventArgs e)
+        void TextViewAccept (object sender, HandledEventArgs e)
         {
             tfAcceptedInvoked = true;
-            e.Cancel = cancel;
+            e.Handled = handle;
         }
     }
 
@@ -1112,10 +1194,13 @@ public class TextFieldTests (ITestOutputHelper output)
     [TextFieldTestsAutoInitShutdown]
     public void TextChanged_Event ()
     {
-        _textField.TextChanged += (s, e) => { Assert.Equal ("TAB to jump between text fields.", e.OldValue); };
+        bool eventFired = false;
+        _textField.TextChanged += (s, e) => eventFired = true;
 
         _textField.Text = "changed";
+        Assert.True (eventFired);
         Assert.Equal ("changed", _textField.Text);
+
     }
 
     [Fact]
@@ -1823,8 +1908,8 @@ public class TextFieldTests (ITestOutputHelper output)
     public void Words_With_Accents_Incorrect_Order_Will_Result_With_Wrong_Accent_Place ()
     {
         var tf = new TextField { Width = 30, Text = "Les Misérables" };
-        tf.SetRelativeLayout(new Size(100,100));
-        tf.Draw();
+        tf.SetRelativeLayout (new Size (100, 100));
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 75 - 418
UnitTests/Views/TextViewTests.cs


+ 6 - 6
UnitTests/Views/TreeTableSourceTests.cs

@@ -13,16 +13,16 @@ public class TreeTableSourceTests : IDisposable
     {
         _output = output;
 
-        _origChecked = ConfigurationManager.Glyphs.Checked;
-        _origUnchecked = ConfigurationManager.Glyphs.UnChecked;
-        ConfigurationManager.Glyphs.Checked = new Rune ('☑');
-        ConfigurationManager.Glyphs.UnChecked = new Rune ('☐');
+        _origChecked = ConfigurationManager.Glyphs.CheckStateChecked;
+        _origUnchecked = ConfigurationManager.Glyphs.CheckStateUnChecked;
+        ConfigurationManager.Glyphs.CheckStateChecked = new Rune ('☑');
+        ConfigurationManager.Glyphs.CheckStateUnChecked = new Rune ('☐');
     }
 
     public void Dispose ()
     {
-        ConfigurationManager.Glyphs.Checked = _origChecked;
-        ConfigurationManager.Glyphs.UnChecked = _origUnchecked;
+        ConfigurationManager.Glyphs.CheckStateChecked = _origChecked;
+        ConfigurationManager.Glyphs.CheckStateUnChecked = _origUnchecked;
     }
 
     [Fact]

+ 8 - 8
UnitTests/Views/TreeViewTests.cs

@@ -1338,13 +1338,13 @@ oot two
         var treeView = new TreeView ();
         var accepted = false;
 
-        treeView.Accept += OnAccept;
-        treeView.InvokeCommand (Command.HotKey);
+treeView.Accept += OnAccept;
+treeView.InvokeCommand (Command.HotKey);
 
-        Assert.False (accepted);
+Assert.False (accepted);
 
-        return;
-        void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
+return;
+void OnAccept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
 
@@ -1375,7 +1375,7 @@ oot two
             activated = true;
             selectedObject = e.ActivatedObject;
         }
-        void Accept (object sender, CancelEventArgs e) { accepted = true; }
+        void Accept (object sender, HandledEventArgs e) { accepted = true; }
     }
 
     [Fact]
@@ -1404,10 +1404,10 @@ oot two
             selectedObject = e.ActivatedObject;
         }
 
-        void Accept (object sender, CancelEventArgs e)
+        void Accept (object sender, HandledEventArgs e)
         {
             accepted = true;
-            e.Cancel = true;
+            e.Handled = true;
         }
     }
 }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio