Переглянути джерело

Moved Overlapped stuff to ApplicationOverlap static class. Fixed nullable warnings.

Tig 1 рік тому
батько
коміт
f37ec5e04f

+ 45 - 0
Terminal.Gui/Application/Application .Screen.cs

@@ -0,0 +1,45 @@
+#nullable enable
+namespace Terminal.Gui;
+
+public static partial class Application // Screen related stuff
+{
+    /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
+    /// <remarks>
+    ///     Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent
+    ///     <see cref="Application"/> from changing it's size to match the new terminal size.
+    /// </remarks>
+    public static event EventHandler<SizeChangedEventArgs>? SizeChanging;
+
+    /// <summary>
+    ///     Called when the application's size changes. Sets the size of all <see cref="Toplevel"/>s and fires the
+    ///     <see cref="SizeChanging"/> event.
+    /// </summary>
+    /// <param name="args">The new size.</param>
+    /// <returns><see lanword="true"/>if the size was changed.</returns>
+    public static bool OnSizeChanging (SizeChangedEventArgs args)
+    {
+        SizeChanging?.Invoke (null, args);
+
+        if (args.Cancel || args.Size is null)
+        {
+            return false;
+        }
+
+        foreach (Toplevel t in TopLevels)
+        {
+            t.SetRelativeLayout (args.Size.Value);
+            t.LayoutSubviews ();
+            t.PositionToplevels ();
+            t.OnSizeChanging (new (args.Size));
+
+            if (PositionCursor (t))
+            {
+                Driver?.UpdateCursor ();
+            }
+        }
+
+        Refresh ();
+
+        return true;
+    }
+}

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

@@ -146,10 +146,10 @@ public static partial class Application // Initialization (Init/Shutdown)
                                                 );
                                                 );
         }
         }
 
 
-        Driver.SizeChanged += (s, args) => OnSizeChanging (args);
-        Driver.KeyDown += (s, args) => OnKeyDown (args);
-        Driver.KeyUp += (s, args) => OnKeyUp (args);
-        Driver.MouseEvent += (s, args) => OnMouseEvent (args);
+        Driver.SizeChanged += Driver_SizeChanged;
+        Driver.KeyDown += Driver_KeyDown;
+        Driver.KeyUp += Driver_KeyUp;
+        Driver.MouseEvent += Driver_MouseEvent;
 
 
         SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext ());
         SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext ());
 
 

+ 7 - 7
Terminal.Gui/Application/Application.Keyboard.cs

@@ -122,7 +122,7 @@ public static partial class Application // Keyboard handling
             return true;
             return true;
         }
         }
 
 
-        foreach (Toplevel topLevel in _topLevels.ToList ())
+        foreach (Toplevel topLevel in TopLevels.ToList ())
         {
         {
             if (topLevel.NewKeyDownEvent (keyEvent))
             if (topLevel.NewKeyDownEvent (keyEvent))
             {
             {
@@ -222,7 +222,7 @@ public static partial class Application // Keyboard handling
             return true;
             return true;
         }
         }
 
 
-        foreach (Toplevel topLevel in _topLevels.ToList ())
+        foreach (Toplevel topLevel in TopLevels.ToList ())
         {
         {
             if (topLevel.NewKeyUpEvent (a))
             if (topLevel.NewKeyUpEvent (a))
             {
             {
@@ -302,7 +302,7 @@ public static partial class Application // Keyboard handling
                     Command.QuitToplevel,  // TODO: IRunnable: Rename to Command.Quit to make more generic.
                     Command.QuitToplevel,  // TODO: IRunnable: Rename to Command.Quit to make more generic.
                     () =>
                     () =>
                     {
                     {
-                        if (OverlappedTop is { })
+                        if (ApplicationOverlapped.OverlappedTop is { })
                         {
                         {
                             RequestStop (Current!);
                             RequestStop (Current!);
                         }
                         }
@@ -330,7 +330,7 @@ public static partial class Application // Keyboard handling
                     () =>
                     () =>
                     {
                     {
                         // TODO: Move this method to Application.Navigation.cs
                         // TODO: Move this method to Application.Navigation.cs
-                        ViewNavigation.MoveNextView ();
+                        ApplicationNavigation.MoveNextView ();
 
 
                         return true;
                         return true;
                     }
                     }
@@ -341,7 +341,7 @@ public static partial class Application // Keyboard handling
                     () =>
                     () =>
                     {
                     {
                         // TODO: Move this method to Application.Navigation.cs
                         // TODO: Move this method to Application.Navigation.cs
-                        ViewNavigation.MovePreviousView ();
+                        ApplicationNavigation.MovePreviousView ();
 
 
                         return true;
                         return true;
                     }
                     }
@@ -352,7 +352,7 @@ public static partial class Application // Keyboard handling
                     () =>
                     () =>
                     {
                     {
                         // TODO: Move this method to Application.Navigation.cs
                         // TODO: Move this method to Application.Navigation.cs
-                        ViewNavigation.MoveNextViewOrTop ();
+                        ApplicationNavigation.MoveNextViewOrTop ();
 
 
                         return true;
                         return true;
                     }
                     }
@@ -363,7 +363,7 @@ public static partial class Application // Keyboard handling
                     () =>
                     () =>
                     {
                     {
                         // TODO: Move this method to Application.Navigation.cs
                         // TODO: Move this method to Application.Navigation.cs
-                        ViewNavigation.MovePreviousViewOrTop ();
+                        ApplicationNavigation.MovePreviousViewOrTop ();
 
 
                         return true;
                         return true;
                     }
                     }

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

@@ -187,20 +187,20 @@ public static partial class Application // Mouse handling
 
 
         if (view is not Adornment)
         if (view is not Adornment)
         {
         {
-            if ((view is null || view == OverlappedTop)
+            if ((view is null || view == ApplicationOverlapped.OverlappedTop)
                 && Current is { Modal: false }
                 && Current is { Modal: false }
-                && OverlappedTop != null
+                && ApplicationOverlapped.OverlappedTop != null
                 && mouseEvent.Flags != MouseFlags.ReportMousePosition
                 && mouseEvent.Flags != MouseFlags.ReportMousePosition
                 && mouseEvent.Flags != 0)
                 && mouseEvent.Flags != 0)
             {
             {
                 // This occurs when there are multiple overlapped "tops"
                 // This occurs when there are multiple overlapped "tops"
                 // E.g. "Mdi" - in the Background Worker Scenario
                 // E.g. "Mdi" - in the Background Worker Scenario
-                View? top = FindDeepestTop (Top!, mouseEvent.Position);
+                View? top = ApplicationOverlapped.FindDeepestTop (Top!, mouseEvent.Position);
                 view = View.FindDeepestView (top, mouseEvent.Position);
                 view = View.FindDeepestView (top, mouseEvent.Position);
 
 
-                if (view is { } && view != OverlappedTop && top != Current && top is { })
+                if (view is { } && view != ApplicationOverlapped.OverlappedTop && top != Current && top is { })
                 {
                 {
-                    MoveCurrent ((Toplevel)top);
+                    ApplicationOverlapped.MoveCurrent ((Toplevel)top);
                 }
                 }
             }
             }
         }
         }
@@ -295,7 +295,7 @@ public static partial class Application // Mouse handling
             };
             };
         }
         }
 
 
-        BringOverlappedTopToFront ();
+        ApplicationOverlapped.BringOverlappedTopToFront ();
     }
     }
 
 
     #endregion Mouse handling
     #endregion Mouse handling

+ 86 - 290
Terminal.Gui/Application/Application.Navigation.cs

@@ -1,366 +1,162 @@
 #nullable enable
 #nullable enable
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
-public static partial class Application
+internal static class ApplicationNavigation
 {
 {
     /// <summary>
     /// <summary>
-    ///     Gets the list of the Overlapped children which are not modal <see cref="Toplevel"/> from the
-    ///     <see cref="OverlappedTop"/>.
+    ///    Gets the deepest focused subview of the specified <paramref name="view"/>.
     /// </summary>
     /// </summary>
-    public static List<Toplevel>? OverlappedChildren
+    /// <param name="view"></param>
+    /// <returns></returns>
+    internal static View? GetDeepestFocusedSubview (View? view)
     {
     {
-        get
+        if (view is null)
         {
         {
-            if (OverlappedTop is { })
-            {
-                List<Toplevel> overlappedChildren = new ();
-
-                lock (_topLevels)
-                {
-                    foreach (Toplevel top in _topLevels)
-                    {
-                        if (top != OverlappedTop && !top.Modal)
-                        {
-                            overlappedChildren.Add (top);
-                        }
-                    }
-                }
-
-                return overlappedChildren;
-            }
-
             return null;
             return null;
         }
         }
-    }
 
 
-    /// <summary>
-    ///     The <see cref="Toplevel"/> object used for the application on startup which
-    ///     <see cref="Toplevel.IsOverlappedContainer"/> is true.
-    /// </summary>
-    public static Toplevel? OverlappedTop
-    {
-        get
+        foreach (View v in view.Subviews)
         {
         {
-            if (Top is { IsOverlappedContainer: true })
+            if (v.HasFocus)
             {
             {
-                return Top;
+                return GetDeepestFocusedSubview (v);
             }
             }
-
-            return null;
         }
         }
+
+        return view;
     }
     }
 
 
-    /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
-    public static void BringOverlappedTopToFront ()
+    /// <summary>
+    ///    Sets the focus to the next view in the <see cref="View.TabIndexes"/> list. If the last view is focused, the first view is focused.
+    /// </summary>
+    /// <param name="viewsInTabIndexes"></param>
+    /// <param name="direction"></param>
+    internal static void FocusNearestView (IEnumerable<View>? viewsInTabIndexes, View.NavigationDirection direction)
     {
     {
-        if (OverlappedTop is { })
+        if (viewsInTabIndexes is null)
         {
         {
             return;
             return;
         }
         }
 
 
-        View? top = FindTopFromView (Top?.MostFocused);
-
-        if (top is Toplevel && Top?.Subviews.Count > 1 && Top.Subviews [^1] != top)
-        {
-            Top.BringSubviewToFront (top);
-        }
-    }
-
-    /// <summary>Gets the current visible Toplevel overlapped child that matches the arguments pattern.</summary>
-    /// <param name="type">The type.</param>
-    /// <param name="exclude">The strings to exclude.</param>
-    /// <returns>The matched view.</returns>
-    public static Toplevel? GetTopOverlappedChild (Type? type = null, string []? exclude = null)
-    {
-        if (OverlappedChildren is null || OverlappedTop is null)
-        {
-            return null;
-        }
+        var found = false;
+        var focusProcessed = false;
+        var idx = 0;
 
 
-        foreach (Toplevel top in OverlappedChildren)
+        foreach (View v in viewsInTabIndexes)
         {
         {
-            if (type is { } && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
+            if (v == Application.Current)
             {
             {
-                return top;
+                found = true;
             }
             }
 
 
-            if ((type is { } && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
+            if (found && v != Application.Current)
+            {
+                if (direction == View.NavigationDirection.Forward)
+                {
+                    Application.Current!.SuperView?.FocusNext ();
+                }
+                else
+                {
+                    Application.Current!.SuperView?.FocusPrev ();
+                }
+
+                focusProcessed = true;
+
+                if (Application.Current.SuperView?.Focused is { } && Application.Current.SuperView.Focused != Application.Current)
+                {
+                    return;
+                }
+            }
+            else if (found && !focusProcessed && idx == viewsInTabIndexes.Count () - 1)
             {
             {
-                continue;
+                viewsInTabIndexes.ToList () [0].SetFocus ();
             }
             }
 
 
-            return top;
+            idx++;
         }
         }
-
-        return null;
     }
     }
-
     /// <summary>
     /// <summary>
-    ///     Move to the next Overlapped child from the <see cref="OverlappedTop"/> and set it as the <see cref="Top"/> if
-    ///     it is not already.
+    ///     Moves the focus to 
     /// </summary>
     /// </summary>
-    /// <param name="top"></param>
-    /// <returns></returns>
-    public static bool MoveToOverlappedChild (Toplevel top)
+    internal static void MoveNextView ()
     {
     {
-        if (top.Visible && OverlappedTop is { } && Current?.Modal == false)
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
-                Current = top;
-            }
+        View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
 
 
-            return true;
+        if (!Application.Current.FocusNext ())
+        {
+            Application.Current.FocusNext ();
         }
         }
 
 
-        return false;
-    }
-
-    /// <summary>Move to the next Overlapped child from the <see cref="OverlappedTop"/>.</summary>
-    public static void OverlappedMoveNext ()
-    {
-        if (OverlappedTop is { } && !Current!.Modal)
+        if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
         {
         {
-            lock (_topLevels)
-            {
-                _topLevels.MoveNext ();
-                var isOverlapped = false;
-
-                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
-                {
-                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        isOverlapped = true;
-                    }
-                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        MoveCurrent (Top!);
-
-                        break;
-                    }
-
-                    _topLevels.MoveNext ();
-                }
-
-                Current = _topLevels.Peek ();
-            }
+            old?.SetNeedsDisplay ();
+            Application.Current.Focused?.SetNeedsDisplay ();
         }
         }
-    }
-
-    /// <summary>Move to the previous Overlapped child from the <see cref="OverlappedTop"/>.</summary>
-    public static void OverlappedMovePrevious ()
-    {
-        if (OverlappedTop is { } && !Current!.Modal)
+        else
         {
         {
-            lock (_topLevels)
-            {
-                _topLevels.MovePrevious ();
-                var isOverlapped = false;
-
-                while (_topLevels.Peek () == OverlappedTop || !_topLevels.Peek ().Visible)
-                {
-                    if (!isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        isOverlapped = true;
-                    }
-                    else if (isOverlapped && _topLevels.Peek () == OverlappedTop)
-                    {
-                        MoveCurrent (Top!);
-
-                        break;
-                    }
-
-                    _topLevels.MovePrevious ();
-                }
-
-                Current = _topLevels.Peek ();
-            }
+            FocusNearestView (Application.Current.SuperView?.TabIndexes, View.NavigationDirection.Forward);
         }
         }
     }
     }
 
 
-    private static bool OverlappedChildNeedsDisplay ()
+    internal static void MoveNextViewOrTop ()
     {
     {
-        if (OverlappedTop is null)
+        if (ApplicationOverlapped.OverlappedTop is null)
         {
         {
-            return false;
-        }
+            Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
+            top!.FocusNext ();
 
 
-        lock (_topLevels)
-        {
-            foreach (Toplevel top in _topLevels)
+            if (top.Focused is null)
             {
             {
-                if (top != Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
-                {
-                    OverlappedTop.SetSubViewNeedsDisplay ();
-
-                    return true;
-                }
+                top.FocusNext ();
             }
             }
-        }
-
-        return false;
-    }
 
 
-    private static bool SetCurrentOverlappedAsTop ()
-    {
-        if (OverlappedTop is null && Current != Top && Current?.SuperView is null && Current?.Modal == false)
+            top.SetNeedsDisplay ();
+            ApplicationOverlapped.BringOverlappedTopToFront ();
+        }
+        else
         {
         {
-            Top = Current;
-
-            return true;
+            ApplicationOverlapped.OverlappedMoveNext ();
         }
         }
-
-        return false;
     }
     }
 
 
-    /// <summary>
-    ///     Finds the first Toplevel in the stack that is Visible and who's Frame contains the <paramref name="location"/>.
-    /// </summary>
-    /// <param name="start"></param>
-    /// <param name="location"></param>
-    /// <returns></returns>
-    private static Toplevel? FindDeepestTop (Toplevel start, in Point location)
+    internal static void MovePreviousView ()
     {
     {
-        if (!start.Frame.Contains (location))
-        {
-            return null;
-        }
+        View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
 
 
-        lock (_topLevels)
+        if (!Application.Current.FocusPrev ())
         {
         {
-            if (_topLevels is not { Count: > 0 })
-            {
-                return start;
-            }
-
-            int rx = location.X - start.Frame.X;
-            int ry = location.Y - start.Frame.Y;
-
-            foreach (Toplevel t in _topLevels)
-            {
-                if (t == Current)
-                {
-                    continue;
-                }
-
-                if (t != start && t.Visible && t.Frame.Contains (rx, ry))
-                {
-                    start = t;
-
-                    break;
-                }
-            }
+            Application.Current.FocusPrev ();
         }
         }
 
 
-        return start;
-    }
-
-    /// <summary>
-    ///     Given <paramref name="view"/>, returns the first Superview up the chain that is <see cref="Top"/>.
-    /// </summary>
-    private static View? FindTopFromView (View? view)
-    {
-        if (view is null)
+        if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
         {
         {
-            return null;
+            old?.SetNeedsDisplay ();
+            Application.Current.Focused?.SetNeedsDisplay ();
         }
         }
-
-        View top = view.SuperView is { } && view.SuperView != Top
-                       ? view.SuperView
-                       : view;
-
-        while (top?.SuperView is { } && top?.SuperView != Top)
+        else
         {
         {
-            top = top!.SuperView;
+            FocusNearestView (Application.Current.SuperView?.TabIndexes?.Reverse (), View.NavigationDirection.Backward);
         }
         }
-
-        return top;
     }
     }
 
 
-    /// <summary>
-    ///     If the <see cref="Current"/> is not the <paramref name="top"/> then <paramref name="top"/> is moved to the top of
-    ///     the Toplevel stack and made Current.
-    /// </summary>
-    /// <param name="top"></param>
-    /// <returns></returns>
-    private static bool MoveCurrent (Toplevel top)
+    internal static void MovePreviousViewOrTop ()
     {
     {
-        // The Current is modal and the top is not modal Toplevel then
-        // the Current must be moved above the first not modal Toplevel.
-        if (OverlappedTop is { }
-            && top != OverlappedTop
-            && top != Current
-            && Current?.Modal == true
-            && !_topLevels.Peek ().Modal)
+        if (ApplicationOverlapped.OverlappedTop is null)
         {
         {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
-            }
-
-            var index = 0;
-            Toplevel [] savedToplevels = _topLevels.ToArray ();
+            Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
+            top!.FocusPrev ();
 
 
-            foreach (Toplevel t in savedToplevels)
+            if (top.Focused is null)
             {
             {
-                if (!t!.Modal && t != Current && t != top && t != savedToplevels [index])
-                {
-                    lock (_topLevels)
-                    {
-                        _topLevels.MoveTo (top, index, new ToplevelEqualityComparer ());
-                    }
-                }
-
-                index++;
+                top.FocusPrev ();
             }
             }
 
 
-            return false;
+            top.SetNeedsDisplay ();
+            ApplicationOverlapped.BringOverlappedTopToFront ();
         }
         }
-
-        // The Current and the top are both not running Toplevel then
-        // the top must be moved above the first not running Toplevel.
-        if (OverlappedTop is { }
-            && top != OverlappedTop
-            && top != Current
-            && Current?.Running == false
-            && top?.Running == false)
+        else
         {
         {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (Current, 0, new ToplevelEqualityComparer ());
-            }
-
-            var index = 0;
-
-            foreach (Toplevel t in _topLevels.ToArray ())
-            {
-                if (!t.Running && t != Current && index > 0)
-                {
-                    lock (_topLevels)
-                    {
-                        _topLevels.MoveTo (top, index - 1, new ToplevelEqualityComparer ());
-                    }
-                }
-
-                index++;
-            }
-
-            return false;
-        }
-
-        if ((OverlappedTop is { } && top?.Modal == true && _topLevels.Peek () != top)
-            || (OverlappedTop is { } && Current != OverlappedTop && Current?.Modal == false && top == OverlappedTop)
-            || (OverlappedTop is { } && Current?.Modal == false && top != Current)
-            || (OverlappedTop is { } && Current?.Modal == true && top == OverlappedTop))
-        {
-            lock (_topLevels)
-            {
-                _topLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
-                Current = top;
-            }
+            ApplicationOverlapped.OverlappedMovePrevious ();
         }
         }
-
-        return true;
     }
     }
 }
 }

+ 297 - 94
Terminal.Gui/Application/Application.Overlapped.cs

@@ -1,170 +1,373 @@
 #nullable enable
 #nullable enable
-using static Terminal.Gui.View;
-using System.Reflection;
-
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
-internal static class ViewNavigation
+/// <summary>
+/// Helper class for managing overlapped views in the application.
+/// </summary>
+public static class ApplicationOverlapped
 {
 {
     /// <summary>
     /// <summary>
-    ///    Gets the deepest focused subview of the specified <paramref name="view"/>.
+    ///     Gets the list of the Overlapped children which are not modal <see cref="Toplevel"/> from the
+    ///     <see cref="OverlappedTop"/>.
     /// </summary>
     /// </summary>
-    /// <param name="view"></param>
-    /// <returns></returns>
-    internal static View? GetDeepestFocusedSubview (View? view)
+    public static List<Toplevel>? OverlappedChildren
     {
     {
-        if (view is null)
+        get
         {
         {
+            if (OverlappedTop is { })
+            {
+                List<Toplevel> overlappedChildren = new ();
+
+                lock (Application.TopLevels)
+                {
+                    foreach (Toplevel top in Application.TopLevels)
+                    {
+                        if (top != OverlappedTop && !top.Modal)
+                        {
+                            overlappedChildren.Add (top);
+                        }
+                    }
+                }
+
+                return overlappedChildren;
+            }
+
             return null;
             return null;
         }
         }
+    }
 
 
-        foreach (View v in view.Subviews)
+    /// <summary>
+    ///     The <see cref="Toplevel"/> object used for the application on startup which
+    ///     <see cref="Toplevel.IsOverlappedContainer"/> is true.
+    /// </summary>
+    public static Toplevel? OverlappedTop
+    {
+        get
         {
         {
-            if (v.HasFocus)
+            if (Application.Top is { IsOverlappedContainer: true })
             {
             {
-                return GetDeepestFocusedSubview (v);
+                return Application.Top;
             }
             }
-        }
 
 
-        return view;
+            return null;
+        }
     }
     }
 
 
-    /// <summary>
-    ///    Sets the focus to the next view in the <see cref="View.TabIndexes"/> list. If the last view is focused, the first view is focused.
-    /// </summary>
-    /// <param name="viewsInTabIndexes"></param>
-    /// <param name="direction"></param>
-    internal static void FocusNearestView (IEnumerable<View>? viewsInTabIndexes, NavigationDirection direction)
+    /// <summary>Brings the superview of the most focused overlapped view is on front.</summary>
+    public static void BringOverlappedTopToFront ()
     {
     {
-        if (viewsInTabIndexes is null)
+        if (OverlappedTop is { })
         {
         {
             return;
             return;
         }
         }
 
 
-        var found = false;
-        var focusProcessed = false;
-        var idx = 0;
+        View? top = FindTopFromView (Application.Top?.MostFocused);
 
 
-        foreach (View v in viewsInTabIndexes)
+        if (top is Toplevel && Application.Top?.Subviews.Count > 1 && Application.Top.Subviews [^1] != top)
         {
         {
-            if (v == Application.Current)
-            {
-                found = true;
-            }
-
-            if (found && v != Application.Current)
-            {
-                if (direction == NavigationDirection.Forward)
-                {
-                    Application.Current!.SuperView?.FocusNext ();
-                }
-                else
-                {
-                    Application.Current!.SuperView?.FocusPrev ();
-                }
+            Application.Top.BringSubviewToFront (top);
+        }
+    }
 
 
-                focusProcessed = true;
+    /// <summary>Gets the current visible Toplevel overlapped child that matches the arguments pattern.</summary>
+    /// <param name="type">The type.</param>
+    /// <param name="exclude">The strings to exclude.</param>
+    /// <returns>The matched view.</returns>
+    public static Toplevel? GetTopOverlappedChild (Type? type = null, string []? exclude = null)
+    {
+        if (OverlappedChildren is null || OverlappedTop is null)
+        {
+            return null;
+        }
 
 
-                if (Application.Current.SuperView?.Focused is { } && Application.Current.SuperView.Focused != Application.Current)
-                {
-                    return;
-                }
+        foreach (Toplevel top in OverlappedChildren)
+        {
+            if (type is { } && top.GetType () == type && exclude?.Contains (top.Data.ToString ()) == false)
+            {
+                return top;
             }
             }
-            else if (found && !focusProcessed && idx == viewsInTabIndexes.Count () - 1)
+
+            if ((type is { } && top.GetType () != type) || exclude?.Contains (top.Data.ToString ()) == true)
             {
             {
-                viewsInTabIndexes.ToList () [0].SetFocus ();
+                continue;
             }
             }
 
 
-            idx++;
+            return top;
         }
         }
+
+        return null;
     }
     }
+
     /// <summary>
     /// <summary>
-    ///     Moves the focus to 
+    ///     Move to the next Overlapped child from the <see cref="OverlappedTop"/> and set it as the <see cref="Top"/> if
+    ///     it is not already.
     /// </summary>
     /// </summary>
-    internal static void MoveNextView ()
+    /// <param name="top"></param>
+    /// <returns></returns>
+    public static bool MoveToOverlappedChild (Toplevel? top)
     {
     {
-        View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
-
-        if (!Application.Current.FocusNext ())
+        if (top is null)
         {
         {
-            Application.Current.FocusNext ();
+            return false;
         }
         }
+        if (top.Visible && OverlappedTop is { } && Application.Current?.Modal == false)
+        {
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
+                Application.Current = top;
+            }
+
+            return true;
+        }
+
+        return false;
+    }
 
 
-        if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
+    /// <summary>Move to the next Overlapped child from the <see cref="OverlappedTop"/>.</summary>
+    public static void OverlappedMoveNext ()
+    {
+        if (OverlappedTop is { } && !Application.Current!.Modal)
         {
         {
-            old?.SetNeedsDisplay ();
-            Application.Current.Focused?.SetNeedsDisplay ();
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MoveNext ();
+                var isOverlapped = false;
+
+                while (Application.TopLevels.Peek () == OverlappedTop || !Application.TopLevels.Peek ().Visible)
+                {
+                    if (!isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
+                    {
+                        isOverlapped = true;
+                    }
+                    else if (isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
+                    {
+                        MoveCurrent (Application.Top!);
+
+                        break;
+                    }
+
+                    Application.TopLevels.MoveNext ();
+                }
+
+                Application.Current = Application.TopLevels.Peek ();
+            }
         }
         }
-        else
+    }
+
+    /// <summary>Move to the previous Overlapped child from the <see cref="OverlappedTop"/>.</summary>
+    public static void OverlappedMovePrevious ()
+    {
+        if (OverlappedTop is { } && !Application.Current!.Modal)
         {
         {
-            FocusNearestView (Application.Current.SuperView?.TabIndexes, NavigationDirection.Forward);
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MovePrevious ();
+                var isOverlapped = false;
+
+                while (Application.TopLevels.Peek () == OverlappedTop || !Application.TopLevels.Peek ().Visible)
+                {
+                    if (!isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
+                    {
+                        isOverlapped = true;
+                    }
+                    else if (isOverlapped && Application.TopLevels.Peek () == OverlappedTop)
+                    {
+                        MoveCurrent (Application.Top!);
+
+                        break;
+                    }
+
+                    Application.TopLevels.MovePrevious ();
+                }
+
+                 Application.Current = Application.TopLevels.Peek ();
+            }
         }
         }
     }
     }
 
 
-    internal static void MoveNextViewOrTop ()
+    internal static bool OverlappedChildNeedsDisplay ()
     {
     {
-        if (Application.OverlappedTop is null)
+        if (OverlappedTop is null)
         {
         {
-            Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
-            top!.FocusNext ();
+            return false;
+        }
 
 
-            if (top.Focused is null)
+        lock (Application.TopLevels)
+        {
+            foreach (Toplevel top in Application.TopLevels)
             {
             {
-                top.FocusNext ();
-            }
+                if (top != Application.Current && top.Visible && (top.NeedsDisplay || top.SubViewNeedsDisplay || top.LayoutNeeded))
+                {
+                    OverlappedTop.SetSubViewNeedsDisplay ();
 
 
-            top.SetNeedsDisplay ();
-            Application.BringOverlappedTopToFront ();
+                    return true;
+                }
+            }
         }
         }
-        else
+
+        return false;
+    }
+
+    internal static bool SetCurrentOverlappedAsTop ()
+    {
+        if (OverlappedTop is null && Application.Current != Application.Top && Application.Current?.SuperView is null && Application.Current?.Modal == false)
         {
         {
-            Application.OverlappedMoveNext ();
+            Application.Top = Application.Current;
+
+            return true;
         }
         }
+
+        return false;
     }
     }
 
 
-    internal static void MovePreviousView ()
+    /// <summary>
+    ///     Finds the first Toplevel in the stack that is Visible and who's Frame contains the <paramref name="location"/>.
+    /// </summary>
+    /// <param name="start"></param>
+    /// <param name="location"></param>
+    /// <returns></returns>
+    internal static Toplevel? FindDeepestTop (Toplevel start, in Point location)
     {
     {
-        View? old = GetDeepestFocusedSubview (Application.Current!.Focused);
+        if (!start.Frame.Contains (location))
+        {
+            return null;
+        }
 
 
-        if (!Application.Current.FocusPrev ())
+        lock (Application.TopLevels)
         {
         {
-            Application.Current.FocusPrev ();
+            if (Application.TopLevels is not { Count: > 0 })
+            {
+                return start;
+            }
+
+            int rx = location.X - start.Frame.X;
+            int ry = location.Y - start.Frame.Y;
+
+            foreach (Toplevel t in Application.TopLevels)
+            {
+                if (t == Application.Current)
+                {
+                    continue;
+                }
+
+                if (t != start && t.Visible && t.Frame.Contains (rx, ry))
+                {
+                    start = t;
+
+                    break;
+                }
+            }
         }
         }
 
 
-        if (old != Application.Current.Focused && old != Application.Current.Focused?.Focused)
+        return start;
+    }
+
+    /// <summary>
+    ///     Given <paramref name="view"/>, returns the first Superview up the chain that is <see cref="Top"/>.
+    /// </summary>
+    internal static View? FindTopFromView (View? view)
+    {
+        if (view is null)
         {
         {
-            old?.SetNeedsDisplay ();
-            Application.Current.Focused?.SetNeedsDisplay ();
+            return null;
         }
         }
-        else
+
+        View top = view.SuperView is { } && view.SuperView != Application.Top
+                       ? view.SuperView
+                       : view;
+
+        while (top?.SuperView is { } && top?.SuperView != Application.Top)
         {
         {
-            FocusNearestView (Application.Current.SuperView?.TabIndexes?.Reverse (), NavigationDirection.Backward);
+            top = top!.SuperView;
         }
         }
+
+        return top;
     }
     }
 
 
-    internal static void MovePreviousViewOrTop ()
+    /// <summary>
+    ///     If the <see cref="Current"/> is not the <paramref name="top"/> then <paramref name="top"/> is moved to the top of
+    ///     the Toplevel stack and made Current.
+    /// </summary>
+    /// <param name="top"></param>
+    /// <returns></returns>
+    internal static bool MoveCurrent (Toplevel top)
     {
     {
-        if (Application.OverlappedTop is null)
+        // The Current is modal and the top is not modal Toplevel then
+        // the Current must be moved above the first not modal Toplevel.
+        if (OverlappedTop is { }
+            && top != OverlappedTop
+            && top != Application.Current
+            && Application.Current?.Modal == true
+            && !Application.TopLevels.Peek ().Modal)
+        {
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MoveTo (Application.Current, 0, new ToplevelEqualityComparer ());
+            }
+
+            var index = 0;
+            Toplevel [] savedToplevels = Application.TopLevels.ToArray ();
+
+            foreach (Toplevel t in savedToplevels)
+            {
+                if (!t!.Modal && t != Application.Current && t != top && t != savedToplevels [index])
+                {
+                    lock (Application.TopLevels)
+                    {
+                        Application.TopLevels.MoveTo (top, index, new ToplevelEqualityComparer ());
+                    }
+                }
+
+                index++;
+            }
+
+            return false;
+        }
+
+        // The Current and the top are both not running Toplevel then
+        // the top must be moved above the first not running Toplevel.
+        if (OverlappedTop is { }
+            && top != OverlappedTop
+            && top != Application.Current
+            && Application.Current?.Running == false
+            && top?.Running == false)
         {
         {
-            Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
-            top!.FocusPrev ();
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MoveTo (Application.Current, 0, new ToplevelEqualityComparer ());
+            }
 
 
-            if (top.Focused is null)
+            var index = 0;
+
+            foreach (Toplevel t in Application.TopLevels.ToArray ())
             {
             {
-                top.FocusPrev ();
+                if (!t.Running && t != Application.Current && index > 0)
+                {
+                    lock (Application.TopLevels)
+                    {
+                        Application.TopLevels.MoveTo (top, index - 1, new ToplevelEqualityComparer ());
+                    }
+                }
+
+                index++;
             }
             }
 
 
-            top.SetNeedsDisplay ();
-            Application.BringOverlappedTopToFront ();
+            return false;
         }
         }
-        else
+
+        if ((OverlappedTop is { } && top?.Modal == true && Application.TopLevels.Peek () != top)
+            || (OverlappedTop is { } && Application.Current != OverlappedTop && Application.Current?.Modal == false && top == OverlappedTop)
+            || (OverlappedTop is { } && Application.Current?.Modal == false && top != Application.Current)
+            || (OverlappedTop is { } && Application.Current?.Modal == true && top == OverlappedTop))
         {
         {
-            Application.OverlappedMovePrevious ();
+            lock (Application.TopLevels)
+            {
+                Application.TopLevels.MoveTo (top, 0, new ToplevelEqualityComparer ());
+                Application.Current = top;
+            }
         }
         }
+
+        return true;
     }
     }
 }
 }
-
-public static partial class Application // App-level View Navigation
-{
- 
-}

+ 58 - 58
Terminal.Gui/Application/Application.Run.cs

@@ -54,7 +54,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         }
         }
 #endif
 #endif
 
 
-        if (toplevel.IsOverlappedContainer && OverlappedTop != toplevel && OverlappedTop is { })
+        if (toplevel.IsOverlappedContainer && ApplicationOverlapped.OverlappedTop != toplevel && ApplicationOverlapped.OverlappedTop is { })
         {
         {
             throw new InvalidOperationException ("Only one Overlapped Container is allowed.");
             throw new InvalidOperationException ("Only one Overlapped Container is allowed.");
         }
         }
@@ -72,7 +72,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         }
         }
 
 
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
-        if (Top is { } && toplevel != Top && !_topLevels.Contains (Top))
+        if (Top is { } && toplevel != Top && !TopLevels.Contains (Top))
         {
         {
             // This assertion confirm if the Top was already disposed
             // This assertion confirm if the Top was already disposed
             Debug.Assert (Top.WasDisposed);
             Debug.Assert (Top.WasDisposed);
@@ -80,9 +80,9 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         }
         }
 #endif
 #endif
 
 
-        lock (_topLevels)
+        lock (TopLevels)
         {
         {
-            if (Top is { } && toplevel != Top && !_topLevels.Contains (Top))
+            if (Top is { } && toplevel != Top && !TopLevels.Contains (Top))
             {
             {
                 // If Top was already disposed and isn't on the Toplevels Stack,
                 // If Top was already disposed and isn't on the Toplevels Stack,
                 // clean it up here if is the same as _cachedRunStateToplevel
                 // clean it up here if is the same as _cachedRunStateToplevel
@@ -96,7 +96,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
                     throw new ObjectDisposedException (Top.GetType ().FullName);
                     throw new ObjectDisposedException (Top.GetType ().FullName);
                 }
                 }
             }
             }
-            else if (OverlappedTop is { } && toplevel != Top && _topLevels.Contains (Top!))
+            else if (ApplicationOverlapped.OverlappedTop is { } && toplevel != Top && TopLevels.Contains (Top!))
             {
             {
                 Top!.OnLeave (toplevel);
                 Top!.OnLeave (toplevel);
             }
             }
@@ -106,29 +106,29 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             if (string.IsNullOrEmpty (toplevel.Id))
             if (string.IsNullOrEmpty (toplevel.Id))
             {
             {
                 var count = 1;
                 var count = 1;
-                var id = (_topLevels.Count + count).ToString ();
+                var id = (TopLevels.Count + count).ToString ();
 
 
-                while (_topLevels.Count > 0 && _topLevels.FirstOrDefault (x => x.Id == id) is { })
+                while (TopLevels.Count > 0 && TopLevels.FirstOrDefault (x => x.Id == id) is { })
                 {
                 {
                     count++;
                     count++;
-                    id = (_topLevels.Count + count).ToString ();
+                    id = (TopLevels.Count + count).ToString ();
                 }
                 }
 
 
-                toplevel.Id = (_topLevels.Count + count).ToString ();
+                toplevel.Id = (TopLevels.Count + count).ToString ();
 
 
-                _topLevels.Push (toplevel);
+                TopLevels.Push (toplevel);
             }
             }
             else
             else
             {
             {
-                Toplevel? dup = _topLevels.FirstOrDefault (x => x.Id == toplevel.Id);
+                Toplevel? dup = TopLevels.FirstOrDefault (x => x.Id == toplevel.Id);
 
 
                 if (dup is null)
                 if (dup is null)
                 {
                 {
-                    _topLevels.Push (toplevel);
+                    TopLevels.Push (toplevel);
                 }
                 }
             }
             }
 
 
-            if (_topLevels.FindDuplicates (new ToplevelEqualityComparer ()).Count > 0)
+            if (TopLevels.FindDuplicates (new ToplevelEqualityComparer ()).Count > 0)
             {
             {
                 throw new ArgumentException ("There are duplicates Toplevel IDs");
                 throw new ArgumentException ("There are duplicates Toplevel IDs");
             }
             }
@@ -141,7 +141,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
 
 
         var refreshDriver = true;
         var refreshDriver = true;
 
 
-        if (OverlappedTop is null
+        if (ApplicationOverlapped.OverlappedTop is null
             || toplevel.IsOverlappedContainer
             || toplevel.IsOverlappedContainer
             || (Current?.Modal == false && toplevel.Modal)
             || (Current?.Modal == false && toplevel.Modal)
             || (Current?.Modal == false && !toplevel.Modal)
             || (Current?.Modal == false && !toplevel.Modal)
@@ -154,25 +154,25 @@ public static partial class Application // Run (Begin, Run, End, Stop)
                 Current = toplevel;
                 Current = toplevel;
                 Current.OnActivate (previousCurrent);
                 Current.OnActivate (previousCurrent);
 
 
-                SetCurrentOverlappedAsTop ();
+                ApplicationOverlapped.SetCurrentOverlappedAsTop ();
             }
             }
             else
             else
             {
             {
                 refreshDriver = false;
                 refreshDriver = false;
             }
             }
         }
         }
-        else if ((toplevel != OverlappedTop
+        else if ((toplevel != ApplicationOverlapped.OverlappedTop
                   && Current?.Modal == true
                   && Current?.Modal == true
-                  && !_topLevels.Peek ().Modal)
-                 || (toplevel != OverlappedTop && Current?.Running == false))
+                  && !TopLevels.Peek ().Modal)
+                 || (toplevel != ApplicationOverlapped.OverlappedTop && Current?.Running == false))
         {
         {
             refreshDriver = false;
             refreshDriver = false;
-            MoveCurrent (toplevel);
+            ApplicationOverlapped.MoveCurrent (toplevel);
         }
         }
         else
         else
         {
         {
             refreshDriver = false;
             refreshDriver = false;
-            MoveCurrent (Current!);
+            ApplicationOverlapped.MoveCurrent (Current!);
         }
         }
 
 
         toplevel.SetRelativeLayout (Driver!.Screen.Size);
         toplevel.SetRelativeLayout (Driver!.Screen.Size);
@@ -180,11 +180,11 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         toplevel.LayoutSubviews ();
         toplevel.LayoutSubviews ();
         toplevel.PositionToplevels ();
         toplevel.PositionToplevels ();
         toplevel.FocusFirst ();
         toplevel.FocusFirst ();
-        BringOverlappedTopToFront ();
+        ApplicationOverlapped.BringOverlappedTopToFront ();
 
 
         if (refreshDriver)
         if (refreshDriver)
         {
         {
-            OverlappedTop?.OnChildLoaded (toplevel);
+            ApplicationOverlapped.OverlappedTop?.OnChildLoaded (toplevel);
             toplevel.OnLoaded ();
             toplevel.OnLoaded ();
             toplevel.SetNeedsDisplay ();
             toplevel.SetNeedsDisplay ();
             toplevel.Draw ();
             toplevel.Draw ();
@@ -427,7 +427,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             if (runState.Toplevel is null)
             if (runState.Toplevel is null)
             {
             {
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
-                Debug.Assert (_topLevels.Count == 0);
+                Debug.Assert (TopLevels.Count == 0);
 #endif
 #endif
                 runState.Dispose ();
                 runState.Dispose ();
 
 
@@ -499,7 +499,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         // TODO: Figure out how to remove this call to ClearContents. Refresh should just repaint damaged areas, not clear
         // TODO: Figure out how to remove this call to ClearContents. Refresh should just repaint damaged areas, not clear
         Driver!.ClearContents ();
         Driver!.ClearContents ();
 
 
-        foreach (Toplevel v in _topLevels.Reverse ())
+        foreach (Toplevel v in TopLevels.Reverse ())
         {
         {
             if (v.Visible)
             if (v.Visible)
             {
             {
@@ -577,9 +577,9 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             // TODO: Overlapped - Move elsewhere
             // TODO: Overlapped - Move elsewhere
             if (state.Toplevel != Current)
             if (state.Toplevel != Current)
             {
             {
-                OverlappedTop?.OnDeactivate (state.Toplevel);
+                ApplicationOverlapped.OverlappedTop?.OnDeactivate (state.Toplevel);
                 state.Toplevel = Current;
                 state.Toplevel = Current;
-                OverlappedTop?.OnActivate (state.Toplevel);
+                ApplicationOverlapped.OverlappedTop?.OnActivate (state.Toplevel);
                 Top!.SetSubViewNeedsDisplay ();
                 Top!.SetSubViewNeedsDisplay ();
                 Refresh ();
                 Refresh ();
             }
             }
@@ -597,7 +597,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             state.Toplevel!.SetNeedsDisplay (state.Toplevel.Frame);
             state.Toplevel!.SetNeedsDisplay (state.Toplevel.Frame);
             Top.Draw ();
             Top.Draw ();
 
 
-            foreach (Toplevel top in _topLevels.Reverse ())
+            foreach (Toplevel top in TopLevels.Reverse ())
             {
             {
                 if (top != Top && top != state.Toplevel)
                 if (top != Top && top != state.Toplevel)
                 {
                 {
@@ -608,7 +608,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             }
             }
         }
         }
 
 
-        if (_topLevels.Count == 1
+        if (TopLevels.Count == 1
             && state.Toplevel == Top
             && state.Toplevel == Top
             && (Driver!.Cols != state.Toplevel!.Frame.Width
             && (Driver!.Cols != state.Toplevel!.Frame.Width
                 || Driver!.Rows != state.Toplevel.Frame.Height)
                 || Driver!.Rows != state.Toplevel.Frame.Height)
@@ -619,7 +619,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             Driver.ClearContents ();
             Driver.ClearContents ();
         }
         }
 
 
-        if (state.Toplevel!.NeedsDisplay || state.Toplevel.SubViewNeedsDisplay || state.Toplevel.LayoutNeeded || OverlappedChildNeedsDisplay ())
+        if (state.Toplevel!.NeedsDisplay || state.Toplevel.SubViewNeedsDisplay || state.Toplevel.LayoutNeeded || ApplicationOverlapped.OverlappedChildNeedsDisplay ())
         {
         {
             state.Toplevel.SetNeedsDisplay ();
             state.Toplevel.SetNeedsDisplay ();
             state.Toplevel.Draw ();
             state.Toplevel.Draw ();
@@ -659,19 +659,19 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     /// </remarks>
     /// </remarks>
     public static void RequestStop (Toplevel? top = null)
     public static void RequestStop (Toplevel? top = null)
     {
     {
-        if (OverlappedTop is null || top is null)
+        if (ApplicationOverlapped.OverlappedTop is null || top is null)
         {
         {
             top = Current;
             top = Current;
         }
         }
 
 
-        if (OverlappedTop != null
+        if (ApplicationOverlapped.OverlappedTop != null
             && top!.IsOverlappedContainer
             && top!.IsOverlappedContainer
             && top?.Running == true
             && top?.Running == true
             && (Current?.Modal == false || Current is { Modal: true, Running: false }))
             && (Current?.Modal == false || Current is { Modal: true, Running: false }))
         {
         {
-            OverlappedTop.RequestStop ();
+            ApplicationOverlapped.OverlappedTop.RequestStop ();
         }
         }
-        else if (OverlappedTop != null
+        else if (ApplicationOverlapped.OverlappedTop != null
                  && top != Current
                  && top != Current
                  && Current is { Running: true, Modal: true }
                  && Current is { Running: true, Modal: true }
                  && top!.Modal
                  && top!.Modal
@@ -698,21 +698,21 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             top.Running = false;
             top.Running = false;
             OnNotifyStopRunState (top);
             OnNotifyStopRunState (top);
         }
         }
-        else if ((OverlappedTop != null
-                  && top != OverlappedTop
+        else if ((ApplicationOverlapped.OverlappedTop != null
+                  && top != ApplicationOverlapped.OverlappedTop
                   && top != Current
                   && top != Current
                   && Current is { Modal: false, Running: true }
                   && Current is { Modal: false, Running: true }
                   && !top!.Running)
                   && !top!.Running)
-                 || (OverlappedTop != null
-                     && top != OverlappedTop
+                 || (ApplicationOverlapped.OverlappedTop != null
+                     && top != ApplicationOverlapped.OverlappedTop
                      && top != Current
                      && top != Current
                      && Current is { Modal: false, Running: false }
                      && Current is { Modal: false, Running: false }
                      && !top!.Running
                      && !top!.Running
-                     && _topLevels.ToArray () [1].Running))
+                     && TopLevels.ToArray () [1].Running))
         {
         {
-            MoveCurrent (top);
+            ApplicationOverlapped.MoveCurrent (top);
         }
         }
-        else if (OverlappedTop != null
+        else if (ApplicationOverlapped.OverlappedTop != null
                  && Current != top
                  && Current != top
                  && Current?.Running == true
                  && Current?.Running == true
                  && !top!.Running
                  && !top!.Running
@@ -723,9 +723,9 @@ public static partial class Application // Run (Begin, Run, End, Stop)
             Current.Running = false;
             Current.Running = false;
             OnNotifyStopRunState (Current);
             OnNotifyStopRunState (Current);
         }
         }
-        else if (OverlappedTop != null
+        else if (ApplicationOverlapped.OverlappedTop != null
                  && Current == top
                  && Current == top
-                 && OverlappedTop?.Running == true
+                 && ApplicationOverlapped.OverlappedTop?.Running == true
                  && Current?.Running == true
                  && Current?.Running == true
                  && top!.Running
                  && top!.Running
                  && Current?.Modal == true
                  && Current?.Modal == true
@@ -784,9 +784,9 @@ public static partial class Application // Run (Begin, Run, End, Stop)
     {
     {
         ArgumentNullException.ThrowIfNull (runState);
         ArgumentNullException.ThrowIfNull (runState);
 
 
-        if (OverlappedTop is { })
+        if (ApplicationOverlapped.OverlappedTop is { })
         {
         {
-            OverlappedTop.OnChildUnloaded (runState.Toplevel);
+            ApplicationOverlapped.OverlappedTop.OnChildUnloaded (runState.Toplevel);
         }
         }
         else
         else
         {
         {
@@ -795,16 +795,16 @@ public static partial class Application // Run (Begin, Run, End, Stop)
 
 
         // End the RunState.Toplevel
         // End the RunState.Toplevel
         // First, take it off the Toplevel Stack
         // First, take it off the Toplevel Stack
-        if (_topLevels.Count > 0)
+        if (TopLevels.Count > 0)
         {
         {
-            if (_topLevels.Peek () != runState.Toplevel)
+            if (TopLevels.Peek () != runState.Toplevel)
             {
             {
                 // If the top of the stack is not the RunState.Toplevel then
                 // If the top of the stack is not the RunState.Toplevel then
                 // this call to End is not balanced with the call to Begin that started the RunState
                 // this call to End is not balanced with the call to Begin that started the RunState
                 throw new ArgumentException ("End must be balanced with calls to Begin");
                 throw new ArgumentException ("End must be balanced with calls to Begin");
             }
             }
 
 
-            _topLevels.Pop ();
+            TopLevels.Pop ();
         }
         }
 
 
         // Notify that it is closing
         // Notify that it is closing
@@ -812,32 +812,32 @@ public static partial class Application // Run (Begin, Run, End, Stop)
 
 
         // If there is a OverlappedTop that is not the RunState.Toplevel then RunState.Toplevel
         // If there is a OverlappedTop that is not the RunState.Toplevel then RunState.Toplevel
         // is a child of MidTop, and we should notify the OverlappedTop that it is closing
         // is a child of MidTop, and we should notify the OverlappedTop that it is closing
-        if (OverlappedTop is { } && !runState.Toplevel!.Modal && runState.Toplevel != OverlappedTop)
+        if (ApplicationOverlapped.OverlappedTop is { } && !runState.Toplevel!.Modal && runState.Toplevel != ApplicationOverlapped.OverlappedTop)
         {
         {
-            OverlappedTop.OnChildClosed (runState.Toplevel);
+            ApplicationOverlapped.OverlappedTop.OnChildClosed (runState.Toplevel);
         }
         }
 
 
         // Set Current and Top to the next TopLevel on the stack
         // Set Current and Top to the next TopLevel on the stack
-        if (_topLevels.Count == 0)
+        if (TopLevels.Count == 0)
         {
         {
             Current = null;
             Current = null;
         }
         }
         else
         else
         {
         {
-            if (_topLevels.Count > 1 && _topLevels.Peek () == OverlappedTop && OverlappedChildren?.Any (t => t.Visible) != null)
+            if (TopLevels.Count > 1 && TopLevels.Peek () == ApplicationOverlapped.OverlappedTop && ApplicationOverlapped.OverlappedChildren?.Any (t => t.Visible) != null)
             {
             {
-                OverlappedMoveNext ();
+                ApplicationOverlapped.OverlappedMoveNext ();
             }
             }
 
 
-            Current = _topLevels.Peek ();
+            Current = TopLevels.Peek ();
 
 
-            if (_topLevels.Count == 1 && Current == OverlappedTop)
+            if (TopLevels.Count == 1 && Current == ApplicationOverlapped.OverlappedTop)
             {
             {
-                OverlappedTop.OnAllChildClosed ();
+                ApplicationOverlapped.OverlappedTop.OnAllChildClosed ();
             }
             }
             else
             else
             {
             {
-                SetCurrentOverlappedAsTop ();
+                ApplicationOverlapped.SetCurrentOverlappedAsTop ();
                 runState.Toplevel!.OnLeave (Current);
                 runState.Toplevel!.OnLeave (Current);
                 Current.OnEnter (runState.Toplevel);
                 Current.OnEnter (runState.Toplevel);
             }
             }
@@ -848,9 +848,9 @@ public static partial class Application // Run (Begin, Run, End, Stop)
         // Don't dispose runState.Toplevel. It's up to caller dispose it
         // Don't dispose runState.Toplevel. It's up to caller dispose it
         // If it's not the same as the current in the RunIteration,
         // If it's not the same as the current in the RunIteration,
         // it will be fixed later in the next RunIteration.
         // it will be fixed later in the next RunIteration.
-        if (OverlappedTop is { } && !_topLevels.Contains (OverlappedTop))
+        if (ApplicationOverlapped.OverlappedTop is { } && !TopLevels.Contains (ApplicationOverlapped.OverlappedTop))
         {
         {
-            _cachedRunStateToplevel = OverlappedTop;
+            _cachedRunStateToplevel = ApplicationOverlapped.OverlappedTop;
         }
         }
         else
         else
         {
         {

+ 9 - 48
Terminal.Gui/Application/Application.Toplevel.cs

@@ -4,13 +4,13 @@ namespace Terminal.Gui;
 public static partial class Application // Toplevel handling
 public static partial class Application // Toplevel handling
 {
 {
     // BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What
     // BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What
+
     /// <summary>Holds the stack of TopLevel views.</summary>
     /// <summary>Holds the stack of TopLevel views.</summary>
-    // about TopLevels that are just a SubView of another View?
-    internal static readonly Stack<Toplevel> _topLevels = new ();
+    internal static Stack<Toplevel> TopLevels { get; } = new ();
 
 
     /// <summary>The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Top"/>)</summary>
     /// <summary>The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Top"/>)</summary>
     /// <value>The top.</value>
     /// <value>The top.</value>
-    public static Toplevel? Top { get; private set; }
+    public static Toplevel? Top { get; internal set; }
 
 
     // TODO: Determine why this can't just return _topLevels.Peek()?
     // TODO: Determine why this can't just return _topLevels.Peek()?
     /// <summary>
     /// <summary>
@@ -22,7 +22,7 @@ public static partial class Application // Toplevel handling
     ///     This will only be distinct from <see cref="Application.Top"/> in scenarios where <see cref="Toplevel.IsOverlappedContainer"/> is <see langword="true"/>.
     ///     This will only be distinct from <see cref="Application.Top"/> in scenarios where <see cref="Toplevel.IsOverlappedContainer"/> is <see langword="true"/>.
     /// </remarks>
     /// </remarks>
     /// <value>The current.</value>
     /// <value>The current.</value>
-    public static Toplevel? Current { get; private set; }
+    public static Toplevel? Current { get; internal set; }
 
 
     /// <summary>
     /// <summary>
     ///     If <paramref name="topLevel"/> is not already Current and visible, finds the last Modal Toplevel in the stack and makes it Current.
     ///     If <paramref name="topLevel"/> is not already Current and visible, finds the last Modal Toplevel in the stack and makes it Current.
@@ -31,17 +31,17 @@ public static partial class Application // Toplevel handling
     {
     {
         if (!topLevel.Running
         if (!topLevel.Running
             || (topLevel == Current && topLevel.Visible)
             || (topLevel == Current && topLevel.Visible)
-            || OverlappedTop == null
-            || _topLevels.Peek ().Modal)
+            || ApplicationOverlapped.OverlappedTop == null
+            || TopLevels.Peek ().Modal)
         {
         {
             return;
             return;
         }
         }
 
 
-        foreach (Toplevel top in _topLevels.Reverse ())
+        foreach (Toplevel top in TopLevels.Reverse ())
         {
         {
             if (top.Modal && top != Current)
             if (top.Modal && top != Current)
             {
             {
-                MoveCurrent (top);
+                ApplicationOverlapped.MoveCurrent (top);
 
 
                 return;
                 return;
             }
             }
@@ -49,47 +49,8 @@ public static partial class Application // Toplevel handling
 
 
         if (!topLevel.Visible && topLevel == Current)
         if (!topLevel.Visible && topLevel == Current)
         {
         {
-            OverlappedMoveNext ();
+            ApplicationOverlapped.OverlappedMoveNext ();
         }
         }
     }
     }
 
 
-    /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
-    /// <remarks>
-    ///     Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent
-    ///     <see cref="Application"/> from changing it's size to match the new terminal size.
-    /// </remarks>
-    public static event EventHandler<SizeChangedEventArgs>? SizeChanging;
-
-    /// <summary>
-    ///     Called when the application's size changes. Sets the size of all <see cref="Toplevel"/>s and fires the
-    ///     <see cref="SizeChanging"/> event.
-    /// </summary>
-    /// <param name="args">The new size.</param>
-    /// <returns><see lanword="true"/>if the size was changed.</returns>
-    public static bool OnSizeChanging (SizeChangedEventArgs args)
-    {
-        SizeChanging?.Invoke (null, args);
-
-        if (args.Cancel || args.Size is null)
-        {
-            return false;
-        }
-
-        foreach (Toplevel t in _topLevels)
-        {
-            t.SetRelativeLayout (args.Size.Value);
-            t.LayoutSubviews ();
-            t.PositionToplevels ();
-            t.OnSizeChanging (new (args.Size));
-
-            if (PositionCursor (t))
-            {
-                Driver?.UpdateCursor ();
-            }
-        }
-
-        Refresh ();
-
-        return true;
-    }
 }
 }

+ 2 - 2
Terminal.Gui/Application/Application.cs

@@ -56,12 +56,12 @@ public static partial class Application
         // Shutdown is the bookend for Init. As such it needs to clean up all resources
         // Shutdown is the bookend for Init. As such it needs to clean up all resources
         // Init created. Apps that do any threading will need to code defensively for this.
         // Init created. Apps that do any threading will need to code defensively for this.
         // e.g. see Issue #537
         // e.g. see Issue #537
-        foreach (Toplevel? t in _topLevels)
+        foreach (Toplevel? t in TopLevels)
         {
         {
             t!.Running = false;
             t!.Running = false;
         }
         }
 
 
-        _topLevels.Clear ();
+        TopLevels.Clear ();
         Current = null;
         Current = null;
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
 
 

+ 1 - 1
Terminal.Gui/View/Adornment/Border.cs

@@ -293,7 +293,7 @@ public class Border : Adornment
         if (!_dragPosition.HasValue && mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed))
         if (!_dragPosition.HasValue && mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed))
         {
         {
             Parent.SetFocus ();
             Parent.SetFocus ();
-            Application.BringOverlappedTopToFront ();
+            ApplicationOverlapped.BringOverlappedTopToFront ();
 
 
             // Only start grabbing if the user clicks in the Thickness area
             // Only start grabbing if the user clicks in the Thickness area
             // Adornment.Contains takes Parent SuperView=relative coords.
             // Adornment.Contains takes Parent SuperView=relative coords.

+ 2 - 2
Terminal.Gui/View/ViewSubViews.cs

@@ -456,7 +456,7 @@ public partial class View
                         Application.Current.FocusNext ();
                         Application.Current.FocusNext ();
                     }
                     }
 
 
-                    Application.BringOverlappedTopToFront ();
+                    ApplicationOverlapped.BringOverlappedTopToFront ();
                 }
                 }
             }
             }
 
 
@@ -489,7 +489,7 @@ public partial class View
 
 
                 if (this is Toplevel && Application.Current.Focused != this)
                 if (this is Toplevel && Application.Current.Focused != this)
                 {
                 {
-                    Application.BringOverlappedTopToFront ();
+                    ApplicationOverlapped.BringOverlappedTopToFront ();
                 }
                 }
             }
             }
 
 

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

@@ -908,7 +908,7 @@ public class TileView : View
             {
             {
                 // Start a Drag
                 // Start a Drag
                 SetFocus ();
                 SetFocus ();
-                Application.BringOverlappedTopToFront ();
+                ApplicationOverlapped.BringOverlappedTopToFront ();
 
 
                 if (mouseEvent.Flags == MouseFlags.Button1Pressed)
                 if (mouseEvent.Flags == MouseFlags.Button1Pressed)
                 {
                 {

+ 5 - 5
Terminal.Gui/Views/Toplevel.cs

@@ -239,7 +239,7 @@ public partial class Toplevel : View
                 || Application.Current?.Modal == false
                 || Application.Current?.Modal == false
                 || (Application.Current?.Modal == true && Application.Current?.Running == false)))
                 || (Application.Current?.Modal == true && Application.Current?.Running == false)))
         {
         {
-            foreach (Toplevel child in Application.OverlappedChildren)
+            foreach (Toplevel child in ApplicationOverlapped.OverlappedChildren!)
             {
             {
                 var ev = new ToplevelClosingEventArgs (this);
                 var ev = new ToplevelClosingEventArgs (this);
 
 
@@ -369,10 +369,10 @@ public partial class Toplevel : View
             //LayoutSubviews ();
             //LayoutSubviews ();
             PositionToplevels ();
             PositionToplevels ();
 
 
-            if (this == Application.OverlappedTop)
+            if (this == ApplicationOverlapped.OverlappedTop)
             {
             {
                 // This enables correct draw behavior when switching between overlapped subviews
                 // This enables correct draw behavior when switching between overlapped subviews
-                foreach (Toplevel top in Application.OverlappedChildren.AsEnumerable ().Reverse ())
+                foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!.AsEnumerable ().Reverse ())
                 {
                 {
                     if (top.Frame.IntersectsWith (Viewport))
                     if (top.Frame.IntersectsWith (Viewport))
                     {
                     {
@@ -437,7 +437,7 @@ public partial class Toplevel : View
         if (Focused is null)
         if (Focused is null)
         {
         {
             // TODO: this is an Overlapped hack
             // TODO: this is an Overlapped hack
-            foreach (Toplevel top in Application.OverlappedChildren)
+            foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!)
             {
             {
                 if (top != this && top.Visible)
                 if (top != this && top.Visible)
                 {
                 {
@@ -607,7 +607,7 @@ public class ToplevelEqualityComparer : IEqualityComparer<Toplevel>
 
 
 /// <summary>
 /// <summary>
 ///     Implements the <see cref="IComparer{T}"/> to sort the <see cref="Toplevel"/> from the
 ///     Implements the <see cref="IComparer{T}"/> to sort the <see cref="Toplevel"/> from the
-///     <see cref="Application.OverlappedChildren"/> if needed.
+///     <see cref="ApplicationOverlapped.OverlappedChildren"/> if needed.
 /// </summary>
 /// </summary>
 public sealed class ToplevelComparer : IComparer<Toplevel>
 public sealed class ToplevelComparer : IComparer<Toplevel>
 {
 {

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

@@ -3,7 +3,7 @@
 public partial class Toplevel
 public partial class Toplevel
 {
 {
     /// <summary>Gets or sets if this Toplevel is in overlapped mode within a Toplevel container.</summary>
     /// <summary>Gets or sets if this Toplevel is in overlapped mode within a Toplevel container.</summary>
-    public bool IsOverlapped => Application.OverlappedTop is { } && Application.OverlappedTop != this && !Modal;
+    public bool IsOverlapped => ApplicationOverlapped.OverlappedTop is { } && ApplicationOverlapped.OverlappedTop != this && !Modal;
 
 
     /// <summary>Gets or sets if this Toplevel is a container for overlapped children.</summary>
     /// <summary>Gets or sets if this Toplevel is a container for overlapped children.</summary>
     public bool IsOverlappedContainer { get; set; }
     public bool IsOverlappedContainer { get; set; }

+ 13 - 13
UICatalog/Scenarios/BackgroundWorkerCollection.cs

@@ -20,10 +20,10 @@ public class BackgroundWorkerCollection : Scenario
         Application.Run<OverlappedMain> ().Dispose ();
         Application.Run<OverlappedMain> ().Dispose ();
 
 
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
-        if (Application.OverlappedChildren is { })
+        if (ApplicationOverlapped.OverlappedChildren is { })
         {
         {
-            Debug.Assert (Application.OverlappedChildren?.Count == 0);
-            Debug.Assert (Application.Top == Application.OverlappedTop);
+            Debug.Assert (ApplicationOverlapped.OverlappedChildren?.Count == 0);
+            Debug.Assert (Application.Top == ApplicationOverlapped.OverlappedTop);
         }
         }
 #endif
 #endif
 
 
@@ -134,7 +134,7 @@ public class BackgroundWorkerCollection : Scenario
         {
         {
             var index = 1;
             var index = 1;
             List<MenuItem> menuItems = new ();
             List<MenuItem> menuItems = new ();
-            List<Toplevel> sortedChildren = Application.OverlappedChildren;
+            List<Toplevel> sortedChildren = ApplicationOverlapped.OverlappedChildren;
             sortedChildren.Sort (new ToplevelComparer ());
             sortedChildren.Sort (new ToplevelComparer ());
 
 
             foreach (Toplevel top in sortedChildren)
             foreach (Toplevel top in sortedChildren)
@@ -151,7 +151,7 @@ public class BackgroundWorkerCollection : Scenario
                 string topTitle = top is Window ? ((Window)top).Title : top.Data.ToString ();
                 string topTitle = top is Window ? ((Window)top).Title : top.Data.ToString ();
                 string itemTitle = item.Title.Substring (index.ToString ().Length + 1);
                 string itemTitle = item.Title.Substring (index.ToString ().Length + 1);
 
 
-                if (top == Application.GetTopOverlappedChild () && topTitle == itemTitle)
+                if (top == ApplicationOverlapped.GetTopOverlappedChild () && topTitle == itemTitle)
                 {
                 {
                     item.Checked = true;
                     item.Checked = true;
                 }
                 }
@@ -160,7 +160,7 @@ public class BackgroundWorkerCollection : Scenario
                     item.Checked = false;
                     item.Checked = false;
                 }
                 }
 
 
-                item.Action += () => { Application.MoveToOverlappedChild (top); };
+                item.Action += () => { ApplicationOverlapped.MoveToOverlappedChild (top); };
                 menuItems.Add (item);
                 menuItems.Add (item);
             }
             }
 
 
@@ -188,7 +188,7 @@ public class BackgroundWorkerCollection : Scenario
         {
         {
             List<MenuItem> menuItems = new ();
             List<MenuItem> menuItems = new ();
             var item = new MenuItem { Title = "WorkerApp", CheckType = MenuItemCheckStyle.Checked };
             var item = new MenuItem { Title = "WorkerApp", CheckType = MenuItemCheckStyle.Checked };
-            Toplevel top = Application.OverlappedChildren?.Find (x => x.Data.ToString () == "WorkerApp");
+            Toplevel top = ApplicationOverlapped.OverlappedChildren?.Find (x => x.Data.ToString () == "WorkerApp");
 
 
             if (top != null)
             if (top != null)
             {
             {
@@ -197,16 +197,16 @@ public class BackgroundWorkerCollection : Scenario
 
 
             item.Action += () =>
             item.Action += () =>
                            {
                            {
-                               Toplevel top = Application.OverlappedChildren.Find (x => x.Data.ToString () == "WorkerApp");
+                               Toplevel top = ApplicationOverlapped.OverlappedChildren.Find (x => x.Data.ToString () == "WorkerApp");
                                item.Checked = top.Visible = (bool)!item.Checked;
                                item.Checked = top.Visible = (bool)!item.Checked;
 
 
                                if (top.Visible)
                                if (top.Visible)
                                {
                                {
-                                   Application.MoveToOverlappedChild (top);
+                                   ApplicationOverlapped.MoveToOverlappedChild (top);
                                }
                                }
                                else
                                else
                                {
                                {
-                                   Application.OverlappedTop.SetNeedsDisplay ();
+                                   ApplicationOverlapped.OverlappedTop!.SetNeedsDisplay ();
                                }
                                }
                            };
                            };
             menuItems.Add (item);
             menuItems.Add (item);
@@ -373,14 +373,14 @@ public class BackgroundWorkerCollection : Scenario
         }
         }
         private void WorkerApp_Closing (object sender, ToplevelClosingEventArgs e)
         private void WorkerApp_Closing (object sender, ToplevelClosingEventArgs e)
         {
         {
-            Toplevel top = Application.OverlappedChildren.Find (x => x.Data.ToString () == "WorkerApp");
+            Toplevel top = ApplicationOverlapped.OverlappedChildren!.Find (x => x.Data.ToString () == "WorkerApp");
 
 
             if (Visible && top == this)
             if (Visible && top == this)
             {
             {
                 Visible = false;
                 Visible = false;
                 e.Cancel = true;
                 e.Cancel = true;
 
 
-                Application.OverlappedMoveNext ();
+                ApplicationOverlapped.OverlappedMoveNext ();
             }
             }
         }
         }
 
 
@@ -481,7 +481,7 @@ public class BackgroundWorkerCollection : Scenario
                                                  _stagingsUi.Add (stagingUI);
                                                  _stagingsUi.Add (stagingUI);
                                                  _stagingWorkers.Remove (staging);
                                                  _stagingWorkers.Remove (staging);
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
-                                                 if (Application.OverlappedTop is null)
+                                                 if (ApplicationOverlapped.OverlappedTop is null)
                                                  {
                                                  {
                                                      stagingUI.Dispose ();
                                                      stagingUI.Dispose ();
                                                      return;
                                                      return;

+ 12 - 12
UnitTests/Application/ApplicationTests.cs

@@ -89,12 +89,12 @@ public class ApplicationTests
 
 
         RunState runstate = null;
         RunState runstate = null;
 
 
-        EventHandler<RunStateEventArgs> NewRunStateFn = (s, e) =>
+        EventHandler<RunStateEventArgs> newRunStateFn = (s, e) =>
                                                         {
                                                         {
                                                             Assert.NotNull (e.State);
                                                             Assert.NotNull (e.State);
                                                             runstate = e.State;
                                                             runstate = e.State;
                                                         };
                                                         };
-        Application.NotifyNewRunState += NewRunStateFn;
+        Application.NotifyNewRunState += newRunStateFn;
 
 
         var topLevel = new Toplevel ();
         var topLevel = new Toplevel ();
         RunState rs = Application.Begin (topLevel);
         RunState rs = Application.Begin (topLevel);
@@ -105,7 +105,7 @@ public class ApplicationTests
         Assert.Equal (topLevel, Application.Top);
         Assert.Equal (topLevel, Application.Top);
         Assert.Equal (topLevel, Application.Current);
         Assert.Equal (topLevel, Application.Current);
 
 
-        Application.NotifyNewRunState -= NewRunStateFn;
+        Application.NotifyNewRunState -= newRunStateFn;
         Application.End (runstate);
         Application.End (runstate);
 
 
         Assert.Null (Application.Current);
         Assert.Null (Application.Current);
@@ -187,15 +187,15 @@ public class ApplicationTests
             Assert.Equal (Key.Empty, Application.AlternateBackwardKey);
             Assert.Equal (Key.Empty, Application.AlternateBackwardKey);
             Assert.Equal (Key.Empty, Application.AlternateForwardKey);
             Assert.Equal (Key.Empty, Application.AlternateForwardKey);
             Assert.Equal (Key.Empty, Application.QuitKey);
             Assert.Equal (Key.Empty, Application.QuitKey);
-            Assert.Null (Application.OverlappedChildren);
-            Assert.Null (Application.OverlappedTop);
+            Assert.Null (ApplicationOverlapped.OverlappedChildren);
+            Assert.Null (ApplicationOverlapped.OverlappedTop);
 
 
             // Internal properties
             // Internal properties
             Assert.False (Application.IsInitialized);
             Assert.False (Application.IsInitialized);
             Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures);
             Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures);
             Assert.False (Application._forceFakeConsole);
             Assert.False (Application._forceFakeConsole);
             Assert.Equal (-1, Application.MainThreadId);
             Assert.Equal (-1, Application.MainThreadId);
-            Assert.Empty (Application._topLevels);
+            Assert.Empty (Application.TopLevels);
             Assert.Null (Application.MouseEnteredView);
             Assert.Null (Application.MouseEnteredView);
 
 
             // Keyboard
             // Keyboard
@@ -235,8 +235,8 @@ public class ApplicationTests
         Application.QuitKey = Key.C;
         Application.QuitKey = Key.C;
         Application.KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Cancel);
         Application.KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Cancel);
 
 
-        //Application.OverlappedChildren = new List<View> ();
-        //Application.OverlappedTop = 
+        //ApplicationOverlapped.OverlappedChildren = new List<View> ();
+        //ApplicationOverlapped.OverlappedTop = 
         Application.MouseEnteredView = new ();
         Application.MouseEnteredView = new ();
 
 
         //Application.WantContinuousButtonPressedView = new View ();
         //Application.WantContinuousButtonPressedView = new View ();
@@ -378,12 +378,12 @@ public class ApplicationTests
 
 
         RunState runstate = null;
         RunState runstate = null;
 
 
-        EventHandler<RunStateEventArgs> NewRunStateFn = (s, e) =>
+        EventHandler<RunStateEventArgs> newRunStateFn = (s, e) =>
                                                         {
                                                         {
                                                             Assert.NotNull (e.State);
                                                             Assert.NotNull (e.State);
                                                             runstate = e.State;
                                                             runstate = e.State;
                                                         };
                                                         };
-        Application.NotifyNewRunState += NewRunStateFn;
+        Application.NotifyNewRunState += newRunStateFn;
 
 
         RunState rs = Application.Begin (topLevel);
         RunState rs = Application.Begin (topLevel);
         Assert.NotNull (rs);
         Assert.NotNull (rs);
@@ -393,7 +393,7 @@ public class ApplicationTests
         Assert.Equal (topLevel, Application.Top);
         Assert.Equal (topLevel, Application.Top);
         Assert.Equal (topLevel, Application.Current);
         Assert.Equal (topLevel, Application.Current);
 
 
-        Application.NotifyNewRunState -= NewRunStateFn;
+        Application.NotifyNewRunState -= newRunStateFn;
         Application.End (runstate);
         Application.End (runstate);
 
 
         Assert.Null (Application.Current);
         Assert.Null (Application.Current);
@@ -419,7 +419,7 @@ public class ApplicationTests
         Assert.Equal (Application.Top, rs.Toplevel);
         Assert.Equal (Application.Top, rs.Toplevel);
         Assert.Null (Application.MouseGrabView); // public
         Assert.Null (Application.MouseGrabView); // public
         Assert.Null (Application.WantContinuousButtonPressedView); // public
         Assert.Null (Application.WantContinuousButtonPressedView); // public
-        Assert.False (Application.MoveToOverlappedChild (Application.Top));
+        Assert.False (ApplicationOverlapped.MoveToOverlappedChild (Application.Top!));
         Application.Top.Dispose ();
         Application.Top.Dispose ();
     }
     }
 
 

+ 135 - 134
UnitTests/Views/OverlappedTests.cs

@@ -1,4 +1,5 @@
-using System.Threading;
+#nullable enable
+using System.Threading;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 namespace Terminal.Gui.ViewsTests;
 namespace Terminal.Gui.ViewsTests;
@@ -30,25 +31,25 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         c3.RequestStop ();
                         c3.RequestStop ();
                         c2.RequestStop ();
                         c2.RequestStop ();
                         c1.RequestStop ();
                         c1.RequestStop ();
@@ -66,31 +67,31 @@ public class OverlappedTests
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
 
 
                                          // But the Children order were reorder by Running = false
                                          // But the Children order were reorder by Running = false
-                                         Assert.True (Application.OverlappedChildren [0] == c3);
-                                         Assert.True (Application.OverlappedChildren [1] == c2);
-                                         Assert.True (Application.OverlappedChildren [^1] == c1);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren! [0] == c3);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [1] == c2);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [^1] == c1);
                                      }
                                      }
                                      else if (iterations == 2)
                                      else if (iterations == 2)
                                      {
                                      {
                                          // The Current is c2 and Current.Running is false.
                                          // The Current is c2 and Current.Running is false.
                                          Assert.True (Application.Current == c2);
                                          Assert.True (Application.Current == c2);
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
-                                         Assert.True (Application.OverlappedChildren [0] == c2);
-                                         Assert.True (Application.OverlappedChildren [^1] == c1);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren ![0] == c2);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [^1] == c1);
                                      }
                                      }
                                      else if (iterations == 1)
                                      else if (iterations == 1)
                                      {
                                      {
                                          // The Current is c1 and Current.Running is false.
                                          // The Current is c1 and Current.Running is false.
                                          Assert.True (Application.Current == c1);
                                          Assert.True (Application.Current == c1);
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
-                                         Assert.True (Application.OverlappedChildren [^1] == c1);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren! [^1] == c1);
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
                                          // The Current is overlapped.
                                          // The Current is overlapped.
                                          Assert.True (Application.Current == overlapped);
                                          Assert.True (Application.Current == overlapped);
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
-                                         Assert.Empty (Application.OverlappedChildren);
+                                         Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                      }
                                      }
 
 
                                      iterations--;
                                      iterations--;
@@ -98,8 +99,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -119,31 +120,31 @@ public class OverlappedTests
 
 
         top1.Ready += (s, e) =>
         top1.Ready += (s, e) =>
                       {
                       {
-                          Assert.Null (Application.OverlappedChildren);
+                          Assert.Null (ApplicationOverlapped.OverlappedChildren);
                           Application.Run (top2);
                           Application.Run (top2);
                       };
                       };
 
 
         top2.Ready += (s, e) =>
         top2.Ready += (s, e) =>
                       {
                       {
-                          Assert.Null (Application.OverlappedChildren);
+                          Assert.Null (ApplicationOverlapped.OverlappedChildren);
                           Application.Run (top3);
                           Application.Run (top3);
                       };
                       };
 
 
         top3.Ready += (s, e) =>
         top3.Ready += (s, e) =>
                       {
                       {
-                          Assert.Null (Application.OverlappedChildren);
+                          Assert.Null (ApplicationOverlapped.OverlappedChildren);
                           Application.Run (top4);
                           Application.Run (top4);
                       };
                       };
 
 
         top4.Ready += (s, e) =>
         top4.Ready += (s, e) =>
                       {
                       {
-                          Assert.Null (Application.OverlappedChildren);
+                          Assert.Null (ApplicationOverlapped.OverlappedChildren);
                           Application.Run (d);
                           Application.Run (d);
                       };
                       };
 
 
         d.Ready += (s, e) =>
         d.Ready += (s, e) =>
                    {
                    {
-                       Assert.Null (Application.OverlappedChildren);
+                       Assert.Null (ApplicationOverlapped.OverlappedChildren);
 
 
                        // This will close the d because on a not OverlappedContainer the Application.Current it always used.
                        // This will close the d because on a not OverlappedContainer the Application.Current it always used.
                        Application.RequestStop (top1);
                        Application.RequestStop (top1);
@@ -154,7 +155,7 @@ public class OverlappedTests
 
 
         Application.Iteration += (s, a) =>
         Application.Iteration += (s, a) =>
                                  {
                                  {
-                                     Assert.Null (Application.OverlappedChildren);
+                                     Assert.Null (ApplicationOverlapped.OverlappedChildren);
 
 
                                      if (iterations == 4)
                                      if (iterations == 4)
                                      {
                                      {
@@ -183,7 +184,7 @@ public class OverlappedTests
 
 
         Application.Run (top1);
         Application.Run (top1);
 
 
-        Assert.Null (Application.OverlappedChildren);
+        Assert.Null (ApplicationOverlapped.OverlappedChildren);
         top1.Dispose ();
         top1.Dispose ();
     }
     }
 
 
@@ -261,37 +262,37 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d1);
                         Application.Run (d1);
                     };
                     };
 
 
         d1.Ready += (s, e) =>
         d1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d2);
                         Application.Run (d2);
                     };
                     };
 
 
         d2.Ready += (s, e) =>
         d2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Assert.True (Application.Current == d2);
                         Assert.True (Application.Current == d2);
                         Assert.True (Application.Current.Running);
                         Assert.True (Application.Current.Running);
 
 
@@ -326,11 +327,11 @@ public class OverlappedTests
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                          for (var i = 0; i < iterations; i++)
                                          for (var i = 0; i < iterations; i++)
                                          {
                                          {
-                                             Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
+                                             Assert.Equal ((iterations - i + 1).ToString (), ApplicationOverlapped.OverlappedChildren [i].Id);
                                          }
                                          }
                                      }
                                      }
 
 
@@ -339,8 +340,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -363,37 +364,37 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d1);
                         Application.Run (d1);
                     };
                     };
 
 
         d1.Ready += (s, e) =>
         d1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c4);
                         Application.Run (c4);
                     };
                     };
 
 
         c4.Ready += (s, e) =>
         c4.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (4, Application.OverlappedChildren.Count);
+                        Assert.Equal (4, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                         // Trying to close the Dialog1
                         // Trying to close the Dialog1
                         d1.RequestStop ();
                         d1.RequestStop ();
@@ -415,13 +416,13 @@ public class OverlappedTests
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                          for (var i = 0; i < iterations; i++)
                                          for (var i = 0; i < iterations; i++)
                                          {
                                          {
                                              Assert.Equal (
                                              Assert.Equal (
                                                            (iterations - i + (iterations == 4 && i == 0 ? 2 : 1)).ToString (),
                                                            (iterations - i + (iterations == 4 && i == 0 ? 2 : 1)).ToString (),
-                                                           Application.OverlappedChildren [i].Id
+                                                           ApplicationOverlapped.OverlappedChildren [i].Id
                                                           );
                                                           );
                                          }
                                          }
                                      }
                                      }
@@ -431,8 +432,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -441,7 +442,7 @@ public class OverlappedTests
     [AutoInitShutdown]
     [AutoInitShutdown]
     public void MoveCurrent_Returns_False_If_The_Current_And_Top_Parameter_Are_Both_With_Running_Set_To_False ()
     public void MoveCurrent_Returns_False_If_The_Current_And_Top_Parameter_Are_Both_With_Running_Set_To_False ()
     {
     {
-        var overlapped = new Overlapped ();
+        Overlapped? overlapped = new Overlapped ();
         var c1 = new Toplevel ();
         var c1 = new Toplevel ();
         var c2 = new Window ();
         var c2 = new Window ();
         var c3 = new Window ();
         var c3 = new Window ();
@@ -451,25 +452,25 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         c3.RequestStop ();
                         c3.RequestStop ();
                         c1.RequestStop ();
                         c1.RequestStop ();
                     };
                     };
@@ -486,30 +487,30 @@ public class OverlappedTests
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
 
 
                                          // But the Children order were reorder by Running = false
                                          // But the Children order were reorder by Running = false
-                                         Assert.True (Application.OverlappedChildren [0] == c3);
-                                         Assert.True (Application.OverlappedChildren [1] == c1);
-                                         Assert.True (Application.OverlappedChildren [^1] == c2);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren! [0] == c3);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [1] == c1);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [^1] == c2);
                                      }
                                      }
                                      else if (iterations == 2)
                                      else if (iterations == 2)
                                      {
                                      {
                                          // The Current is c1 and Current.Running is false.
                                          // The Current is c1 and Current.Running is false.
                                          Assert.True (Application.Current == c1);
                                          Assert.True (Application.Current == c1);
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
-                                         Assert.True (Application.OverlappedChildren [0] == c1);
-                                         Assert.True (Application.OverlappedChildren [^1] == c2);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren! [0] == c1);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren [^1] == c2);
                                      }
                                      }
                                      else if (iterations == 1)
                                      else if (iterations == 1)
                                      {
                                      {
                                          // The Current is c2 and Current.Running is false.
                                          // The Current is c2 and Current.Running is false.
                                          Assert.True (Application.Current == c2);
                                          Assert.True (Application.Current == c2);
                                          Assert.False (Application.Current.Running);
                                          Assert.False (Application.Current.Running);
-                                         Assert.True (Application.OverlappedChildren [^1] == c2);
+                                         Assert.True (ApplicationOverlapped.OverlappedChildren! [^1] == c2);
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
                                          // The Current is overlapped.
                                          // The Current is overlapped.
                                          Assert.True (Application.Current == overlapped);
                                          Assert.True (Application.Current == overlapped);
-                                         Assert.Empty (Application.OverlappedChildren);
+                                         Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                      }
                                      }
 
 
                                      iterations--;
                                      iterations--;
@@ -517,8 +518,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -526,7 +527,7 @@ public class OverlappedTests
     [Fact]
     [Fact]
     public void MoveToOverlappedChild_Throw_NullReferenceException_Passing_Null_Parameter ()
     public void MoveToOverlappedChild_Throw_NullReferenceException_Passing_Null_Parameter ()
     {
     {
-        Assert.Throws<NullReferenceException> (delegate { Application.MoveToOverlappedChild (null); });
+        Assert.Throws<NullReferenceException> (delegate { ApplicationOverlapped.MoveToOverlappedChild (null); });
     }
     }
 
 
     [Fact]
     [Fact]
@@ -544,11 +545,11 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (logger);
                                 Application.Run (logger);
                             };
                             };
 
 
-        logger.Ready += (s, e) => Assert.Single (Application.OverlappedChildren);
+        logger.Ready += (s, e) => Assert.Single (ApplicationOverlapped.OverlappedChildren!);
 
 
         Application.Iteration += (s, a) =>
         Application.Iteration += (s, a) =>
                                  {
                                  {
@@ -559,7 +560,7 @@ public class OverlappedTests
 
 
                                          stage.Ready += (s, e) =>
                                          stage.Ready += (s, e) =>
                                                         {
                                                         {
-                                                            Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                                            Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
                                                             stage.RequestStop ();
                                                             stage.RequestStop ();
                                                         };
                                                         };
 
 
@@ -570,7 +571,7 @@ public class OverlappedTests
                                                                  allStageClosed = true;
                                                                  allStageClosed = true;
                                                              }
                                                              }
 
 
-                                                             Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                                             Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                                              if (running)
                                                              if (running)
                                                              {
                                                              {
@@ -581,7 +582,7 @@ public class OverlappedTests
                                                                  rpt.Ready += (s, e) =>
                                                                  rpt.Ready += (s, e) =>
                                                                               {
                                                                               {
                                                                                   iterations++;
                                                                                   iterations++;
-                                                                                  Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                                                                  Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren.Count);
                                                                               };
                                                                               };
 
 
                                                                  Application.Run (rpt);
                                                                  Application.Run (rpt);
@@ -593,28 +594,28 @@ public class OverlappedTests
                                      else if (iterations == 11 && running)
                                      else if (iterations == 11 && running)
                                      {
                                      {
                                          running = false;
                                          running = false;
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
                                      }
                                      }
                                      else if (!overlappedRequestStop && running && !allStageClosed)
                                      else if (!overlappedRequestStop && running && !allStageClosed)
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
                                      }
                                      }
                                      else if (!overlappedRequestStop && !running && allStageClosed)
                                      else if (!overlappedRequestStop && !running && allStageClosed)
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
                                          overlappedRequestStop = true;
                                          overlappedRequestStop = true;
-                                         overlapped.RequestStop ();
+                                         overlapped?.RequestStop ();
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Empty (Application.OverlappedChildren);
+                                         Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                      }
                                      }
                                  };
                                  };
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -652,32 +653,32 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d);
                         Application.Run (d);
                     };
                     };
 
 
         // Also easy because the Overlapped Container handles all at once
         // Also easy because the Overlapped Container handles all at once
         d.Ready += (s, e) =>
         d.Ready += (s, e) =>
                    {
                    {
-                       Assert.Equal (3, Application.OverlappedChildren.Count);
+                       Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                        // This will not close the OverlappedContainer because d is a modal Toplevel
                        // This will not close the OverlappedContainer because d is a modal Toplevel
                        Application.RequestStop (overlapped);
                        Application.RequestStop (overlapped);
@@ -696,11 +697,11 @@ public class OverlappedTests
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                          for (var i = 0; i < iterations; i++)
                                          for (var i = 0; i < iterations; i++)
                                          {
                                          {
-                                             Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
+                                             Assert.Equal ((iterations - i + 1).ToString (), ApplicationOverlapped.OverlappedChildren [i].Id);
                                          }
                                          }
                                      }
                                      }
 
 
@@ -709,8 +710,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -731,32 +732,32 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d);
                         Application.Run (d);
                     };
                     };
 
 
         //More harder because it's sequential.
         //More harder because it's sequential.
         d.Ready += (s, e) =>
         d.Ready += (s, e) =>
                    {
                    {
-                       Assert.Equal (3, Application.OverlappedChildren.Count);
+                       Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                        // Close the Dialog
                        // Close the Dialog
                        Application.RequestStop ();
                        Application.RequestStop ();
@@ -776,11 +777,11 @@ public class OverlappedTests
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                          for (var i = 0; i < iterations; i++)
                                          for (var i = 0; i < iterations; i++)
                                          {
                                          {
-                                             Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
+                                             Assert.Equal ((iterations - i + 1).ToString (), ApplicationOverlapped.OverlappedChildren [i].Id);
                                          }
                                          }
                                      }
                                      }
 
 
@@ -789,8 +790,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -811,32 +812,32 @@ public class OverlappedTests
 
 
         overlapped.Ready += (s, e) =>
         overlapped.Ready += (s, e) =>
                             {
                             {
-                                Assert.Empty (Application.OverlappedChildren);
+                                Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
                                 Application.Run (c1);
                                 Application.Run (c1);
                             };
                             };
 
 
         c1.Ready += (s, e) =>
         c1.Ready += (s, e) =>
                     {
                     {
-                        Assert.Single (Application.OverlappedChildren);
+                        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
                         Application.Run (c2);
                         Application.Run (c2);
                     };
                     };
 
 
         c2.Ready += (s, e) =>
         c2.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (2, Application.OverlappedChildren.Count);
+                        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (c3);
                         Application.Run (c3);
                     };
                     };
 
 
         c3.Ready += (s, e) =>
         c3.Ready += (s, e) =>
                     {
                     {
-                        Assert.Equal (3, Application.OverlappedChildren.Count);
+                        Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
                         Application.Run (d);
                         Application.Run (d);
                     };
                     };
 
 
         // More easy because the Overlapped Container handles all at once
         // More easy because the Overlapped Container handles all at once
         d.Ready += (s, e) =>
         d.Ready += (s, e) =>
                    {
                    {
-                       Assert.Equal (3, Application.OverlappedChildren.Count);
+                       Assert.Equal (3, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                        // This will not close the OverlappedContainer because d is a modal Toplevel and will be closed.
                        // This will not close the OverlappedContainer because d is a modal Toplevel and will be closed.
                        overlapped.RequestStop ();
                        overlapped.RequestStop ();
@@ -855,11 +856,11 @@ public class OverlappedTests
                                      }
                                      }
                                      else
                                      else
                                      {
                                      {
-                                         Assert.Equal (iterations, Application.OverlappedChildren.Count);
+                                         Assert.Equal (iterations, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
                                          for (var i = 0; i < iterations; i++)
                                          for (var i = 0; i < iterations; i++)
                                          {
                                          {
-                                             Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
+                                             Assert.Equal ((iterations - i + 1).ToString (), ApplicationOverlapped.OverlappedChildren [i].Id);
                                          }
                                          }
                                      }
                                      }
 
 
@@ -868,8 +869,8 @@ public class OverlappedTests
 
 
         Application.Run (overlapped);
         Application.Run (overlapped);
 
 
-        Assert.Empty (Application.OverlappedChildren);
-        Assert.NotNull (Application.OverlappedTop);
+        Assert.Empty (ApplicationOverlapped.OverlappedChildren!);
+        Assert.NotNull (ApplicationOverlapped.OverlappedTop);
         Assert.NotNull (Application.Top);
         Assert.NotNull (Application.Top);
         overlapped.Dispose ();
         overlapped.Dispose ();
     }
     }
@@ -885,7 +886,7 @@ public class OverlappedTests
         RunState rsOverlapped = Application.Begin (overlapped);
         RunState rsOverlapped = Application.Begin (overlapped);
 
 
         // Need to fool MainLoop into thinking it's running
         // Need to fool MainLoop into thinking it's running
-        Application.MainLoop.Running = true;
+        Application.MainLoop!.Running = true;
 
 
         // RunIteration must be call on each iteration because
         // RunIteration must be call on each iteration because
         // it's using the Begin and not the Run method
         // it's using the Begin and not the Run method
@@ -894,7 +895,7 @@ public class OverlappedTests
 
 
         Assert.Equal (overlapped, rsOverlapped.Toplevel);
         Assert.Equal (overlapped, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, rsOverlapped.Toplevel);
-        Assert.Equal (Application.OverlappedTop, rsOverlapped.Toplevel);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, rsOverlapped.Toplevel);
         Assert.Equal (Application.Current, rsOverlapped.Toplevel);
         Assert.Equal (Application.Current, rsOverlapped.Toplevel);
         Assert.Equal (overlapped, Application.Current);
         Assert.Equal (overlapped, Application.Current);
 
 
@@ -903,7 +904,7 @@ public class OverlappedTests
 
 
         Assert.Equal (overlapped, rsOverlapped.Toplevel);
         Assert.Equal (overlapped, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, rsOverlapped.Toplevel);
-        Assert.Equal (Application.OverlappedTop, rsOverlapped.Toplevel);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, rsOverlapped.Toplevel);
         // The win1 Visible is false and cannot be set as the Current
         // The win1 Visible is false and cannot be set as the Current
         Assert.Equal (Application.Current, rsOverlapped.Toplevel);
         Assert.Equal (Application.Current, rsOverlapped.Toplevel);
         Assert.Equal (overlapped, Application.Current);
         Assert.Equal (overlapped, Application.Current);
@@ -916,7 +917,7 @@ public class OverlappedTests
         // and not the original overlapped
         // and not the original overlapped
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win1, rsWin1.Toplevel);
         Assert.Equal (win1, rsWin1.Toplevel);
@@ -931,7 +932,7 @@ public class OverlappedTests
 
 
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win1, rsWin1.Toplevel);
         Assert.Equal (win1, rsWin1.Toplevel);
@@ -945,7 +946,7 @@ public class OverlappedTests
 
 
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (win2, rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (Application.Current, rsWin2.Toplevel);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win2, Application.Current);
         Assert.Equal (win1, rsWin1.Toplevel);
         Assert.Equal (win1, rsWin1.Toplevel);
@@ -963,7 +964,7 @@ public class OverlappedTests
 #endif
 #endif
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Equal (Application.Current, rsWin1.Toplevel);
         Assert.Equal (Application.Current, rsWin1.Toplevel);
         Assert.Equal (win1, Application.Current);
         Assert.Equal (win1, Application.Current);
         Assert.Equal (win1, rsWin1.Toplevel);
         Assert.Equal (win1, rsWin1.Toplevel);
@@ -978,7 +979,7 @@ public class OverlappedTests
 #endif
 #endif
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Equal (Application.Current, overlapped);
         Assert.Equal (Application.Current, overlapped);
         Assert.Null (rsWin1.Toplevel);
         Assert.Null (rsWin1.Toplevel);
         // See here that the only Toplevel that needs to End is the overlapped
         // See here that the only Toplevel that needs to End is the overlapped
@@ -994,7 +995,7 @@ public class OverlappedTests
 #endif
 #endif
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Null (rsOverlapped.Toplevel);
         Assert.Equal (Application.Top, overlapped);
         Assert.Equal (Application.Top, overlapped);
-        Assert.Equal (Application.OverlappedTop, overlapped);
+        Assert.Equal (ApplicationOverlapped.OverlappedTop, overlapped);
         Assert.Null (Application.Current);
         Assert.Null (Application.Current);
         Assert.Null (rsWin1.Toplevel);
         Assert.Null (rsWin1.Toplevel);
         Assert.Null (rsWin2.Toplevel);
         Assert.Null (rsWin2.Toplevel);
@@ -1021,10 +1022,10 @@ public class OverlappedTests
     public void KeyBindings_Command_With_OverlappedTop ()
     public void KeyBindings_Command_With_OverlappedTop ()
     {
     {
         Toplevel top = new ();
         Toplevel top = new ();
-        Assert.Null (Application.OverlappedTop);
+        Assert.Null (ApplicationOverlapped.OverlappedTop);
         top.IsOverlappedContainer = true;
         top.IsOverlappedContainer = true;
         Application.Begin (top);
         Application.Begin (top);
-        Assert.Equal (Application.Top, Application.OverlappedTop);
+        Assert.Equal (Application.Top, ApplicationOverlapped.OverlappedTop);
 
 
         var isRunning = true;
         var isRunning = true;
 
 
@@ -1060,7 +1061,7 @@ public class OverlappedTests
         Assert.Null (top.Focused);
         Assert.Null (top.Focused);
         Assert.Equal (top, Application.Current);
         Assert.Equal (top, Application.Current);
         Assert.True (top.IsCurrentTop);
         Assert.True (top.IsCurrentTop);
-        Assert.Equal (top, Application.OverlappedTop);
+        Assert.Equal (top, ApplicationOverlapped.OverlappedTop);
         Application.Begin (win1);
         Application.Begin (win1);
         Assert.Equal (new (0, 0, 40, 25), win1.Frame);
         Assert.Equal (new (0, 0, 40, 25), win1.Frame);
         Assert.NotEqual (top, Application.Current);
         Assert.NotEqual (top, Application.Current);
@@ -1072,7 +1073,7 @@ public class OverlappedTests
         Assert.Null (top.MostFocused);
         Assert.Null (top.MostFocused);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.True (win1.IsOverlapped);
         Assert.True (win1.IsOverlapped);
-        Assert.Single (Application.OverlappedChildren);
+        Assert.Single (ApplicationOverlapped.OverlappedChildren!);
         Application.Begin (win2);
         Application.Begin (win2);
         Assert.Equal (new (0, 0, 40, 25), win2.Frame);
         Assert.Equal (new (0, 0, 40, 25), win2.Frame);
         Assert.NotEqual (top, Application.Current);
         Assert.NotEqual (top, Application.Current);
@@ -1083,16 +1084,16 @@ public class OverlappedTests
         Assert.Null (top.Focused);
         Assert.Null (top.Focused);
         Assert.Null (top.MostFocused);
         Assert.Null (top.MostFocused);
         Assert.Equal (tf1W2, win2.MostFocused);
         Assert.Equal (tf1W2, win2.MostFocused);
-        Assert.Equal (2, Application.OverlappedChildren.Count);
+        Assert.Equal (2, ApplicationOverlapped.OverlappedChildren!.Count);
 
 
-        Application.MoveToOverlappedChild (win1);
+        ApplicationOverlapped.MoveToOverlappedChild (win1);
         Assert.Equal (win1, Application.Current);
         Assert.Equal (win1, Application.Current);
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         win1.Running = true;
         win1.Running = true;
         Assert.True (Application.OnKeyDown (Application.QuitKey));
         Assert.True (Application.OnKeyDown (Application.QuitKey));
         Assert.False (isRunning);
         Assert.False (isRunning);
         Assert.False (win1.Running);
         Assert.False (win1.Running);
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
 
 
         Assert.True (
         Assert.True (
                      Application.OnKeyDown (Key.Z.WithCtrl)
                      Application.OnKeyDown (Key.Z.WithCtrl)
@@ -1110,77 +1111,77 @@ public class OverlappedTests
         Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
         Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
 
 
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));    // move to win2
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl));    // move to win2
-        Assert.Equal (win2, Application.OverlappedChildren [0]);
+        Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
 
 
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));    // move back to win1
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));    // move back to win1
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
 
 
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.Tab));    // text view eats tab
         Assert.True (Application.OnKeyDown (Key.Tab));    // text view eats tab
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
 
 
         tvW1.AllowsTab = false;
         tvW1.AllowsTab = false;
         Assert.True (Application.OnKeyDown (Key.Tab));    // text view eats tab
         Assert.True (Application.OnKeyDown (Key.Tab));    // text view eats tab
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
 
 
         Assert.True (Application.OnKeyDown (Key.CursorRight));
         Assert.True (Application.OnKeyDown (Key.CursorRight));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.CursorDown));
         Assert.True (Application.OnKeyDown (Key.CursorDown));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.Equal (tf1W1, win1.MostFocused);
 #if UNIX_KEY_BINDINGS
 #if UNIX_KEY_BINDINGS
-        Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.I.WithCtrl)));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.True (ApplicationOverlapped.OverlappedChildren [0].ProcessKeyDown (new (Key.I.WithCtrl)));
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
 #endif
 #endif
         Assert.True (Application.OnKeyDown (Key.Tab));
         Assert.True (Application.OnKeyDown (Key.Tab));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.CursorLeft));  // The view to the left of tvW1 is tf2W1, but tvW1 is still focused and eats cursor keys
         Assert.True (Application.OnKeyDown (Key.CursorLeft));  // The view to the left of tvW1 is tf2W1, but tvW1 is still focused and eats cursor keys
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.CursorUp));
         Assert.True (Application.OnKeyDown (Key.CursorUp));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.Tab));
         Assert.True (Application.OnKeyDown (Key.Tab));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
 
 
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // Move to win2
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl)); // Move to win2
-        Assert.Equal (win2, Application.OverlappedChildren [0]);
+        Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf1W2, win2.MostFocused);
         Assert.Equal (tf1W2, win2.MostFocused);
         tf2W2.SetFocus ();
         tf2W2.SetFocus ();
         Assert.True (tf2W2.HasFocus);
         Assert.True (tf2W2.HasFocus);
 
 
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));
         Assert.True (Application.OnKeyDown (Key.Tab.WithCtrl.WithShift));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Application.AlternateForwardKey));
         Assert.True (Application.OnKeyDown (Application.AlternateForwardKey));
-        Assert.Equal (win2, Application.OverlappedChildren [0]);
+        Assert.Equal (win2, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W2, win2.MostFocused);
         Assert.Equal (tf2W2, win2.MostFocused);
         Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey));
         Assert.True (Application.OnKeyDown (Application.AlternateBackwardKey));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.Equal (tf2W1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.CursorDown));
         Assert.True (Application.OnKeyDown (Key.CursorDown));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.Equal (tf1W1, win1.MostFocused);
 #if UNIX_KEY_BINDINGS
 #if UNIX_KEY_BINDINGS
         Assert.True (Application.OnKeyDown (new (Key.B.WithCtrl)));
         Assert.True (Application.OnKeyDown (new (Key.B.WithCtrl)));
 #else
 #else
         Assert.True (Application.OnKeyDown (Key.CursorLeft));
         Assert.True (Application.OnKeyDown (Key.CursorLeft));
 #endif
 #endif
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.Equal (tf1W1, win1.MostFocused);
         Assert.True (Application.OnKeyDown (Key.CursorDown));
         Assert.True (Application.OnKeyDown (Key.CursorDown));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (Point.Empty, tvW1.CursorPosition);
         Assert.Equal (Point.Empty, tvW1.CursorPosition);
 
 
         Assert.True (Application.OnKeyDown (Key.End.WithCtrl));
         Assert.True (Application.OnKeyDown (Key.End.WithCtrl));
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (new (16, 1), tvW1.CursorPosition);
         Assert.Equal (new (16, 1), tvW1.CursorPosition);
 #if UNIX_KEY_BINDINGS
 #if UNIX_KEY_BINDINGS
@@ -1188,11 +1189,11 @@ public class OverlappedTests
 #else
 #else
         Assert.True (Application.OnKeyDown (Key.CursorRight));
         Assert.True (Application.OnKeyDown (Key.CursorRight));
 #endif
 #endif
-        Assert.Equal (win1, Application.OverlappedChildren [0]);
+        Assert.Equal (win1, ApplicationOverlapped.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
         Assert.Equal (tvW1, win1.MostFocused);
 
 
 #if UNIX_KEY_BINDINGS
 #if UNIX_KEY_BINDINGS
-        Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.L.WithCtrl)));
+        Assert.True (ApplicationOverlapped.OverlappedChildren [0].ProcessKeyDown (new (Key.L.WithCtrl)));
 #endif
 #endif
         win2.Dispose ();
         win2.Dispose ();
         win1.Dispose ();
         win1.Dispose ();