mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
* Removed resharper settings from editorconfig * Remove constructors with frame parameters from Button class. * Remove constructors with frame parameters from CheckBox class. * Cleanup code. * Remove constructors with frame parameters from ComboBox class. * @BDisp Remove constructors with frame parameters from FrameView class. * Remove constructors with frame parameters from Label class. * Remove constructors with frame parameters from ListView class. * Remove constructors with frame parameters from ScrollBarView class. * Remove constructors with frame parameters from ScrollView class. * Remove namespace braces. * Cleanup code. * Cleanup code. * Cleanup code. * Remove constructors with frame parameters from TextField class. * Remove constructors with frame parameters from TimeField class. * Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty. * Remove constructors with frame parameters from Toplevel class. * Remove constructors with frame parameters from Window class. * Fix merge errors. * Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty." This reverts commitcf9c24b846. * Revert unit test. * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980) * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame * Trying fix this unit test that sometimes fail. * Fixes #2983. View need a alternative DrawFrame for the v2. * Use new DrawFrame method. * Change _lines field to Lines property. * Add TabWindow unit test. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Revert "Change _lines field to Lines property." This reverts commitab6c5f3094. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Force render immediately instead of join. * I will never rely on zero-location-based unit test again. * Fix TestTreeViewColor unit test fail. * Using location of 3 to avoid be divisible by 2 and so avoiding bugs. * Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs." This reverts commitdd3df135d8. * Revert "I will never rely on zero-location-based unit test again." This reverts commit62adf6f285. * Revert "Fix newline conflict errors." This reverts commit4acf72612d. * Revert "Add more unit tests to LineCanvas." This reverts commit66bc6f514e. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit680ba264e1. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit69a7f17f19. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commitdade9fd767. * Reverting this changes to start a new one. * Add horizontal and vertical support for combining glyphs. * Fix text and auto size behavior. * Add TabWidth property. * Add unit test for WordWrap. * Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false. * Using Frame to force read from the get method. * Fix some issues with AutoSize and ForceValidatePosDim. * Fixing broken unit tests. * Restoring code I've broken. * Removing forgotten code. * Only LayoutStyle.Computed can change the Frame. * DateField and TimeField depends on LayoutStyle.Computed. * Fix unit tests related with LayoutStyle. * Implements tabs, left and right arrows as View. * Draws a minimum full border. * Adds missing XML parameter. * Adds assert tests for Frame. * Removes duplicates InlineData. * Adds more unit tests for minimum full border without Left and Right thickness. * Trying to fix the TestTreeViewColor unit test fail. * Prevents a user to set TextDirection to -1. * Prevents any invalid TextDirection value. * Removes (TextDirection)(-1). * Removes unnecessary TextDirection initialization. * Removes LayoutStyle. * Fixing unit tests with border. * Trying to fix TestTreeViewColor again. * Revert "Trying to fix TestTreeViewColor again." This reverts commitc2efa8e42e. * Trying to fix TestTreeViewColor again. * Fix merge errors. * Fix merge errors. * Restoring unit test. * Restores the right XML comment. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Only call OnResizeNeeded if it's LayoutStyle.Computed. * Fix merge errors. * Fix merge errors. * Fix unit tests fail. * Reformat. * Again. * Rename to OnDrawAdornments. * Fix failing unit tests. * Reduces indentation and cleanup code. * Cleanup code. * Fix bug done when cleanup. * Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent. * Removes Tab constructor parameters. --------- Co-authored-by: Tig <tig@users.noreply.github.com> * Fix merge errors. * Remove constructors with parameters from Button. * Remove parenthesis on objects initializers from Button. * Remove constructors with parameters from CheckBox. * Remove parenthesis on objects initializers from CheckBox. * Remove constructors with parameters from ComboBox. * Remove constructors with parameters from FrameView. * Remove parenthesis on objects initializers from FrameView. * Initial commit * Renamed Direction enum for clarity in refactoring unit tests * Moved nav tests to NavigationTests * Moved view tests around * Cleaning up TextFormatter and View.AutoSize code * Fixed latent TextFormatter bug with \n * removed Application dependency on some autosize unit tests * Fixed Label tests to deal with auotsize overriding height/width * Fixed more label tests. WIP * Fixed all places where AutoSize = happend after setting Dims * Started adding new primitive View.Text tests * Code comments * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized. * Changes needed for unit tests pass on remove parameters constructors from the Label class. * Remove constructors with parameters from Label. * Remove parenthesis on objects initializers from Label. * Prefix private fields with underscore. * Renamed to MaxLength. * Remove constructors with parameters from ListView. * MakeWrapper not needed anymore. * Remove parenthesis on objects initializers from ListView. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Fixed messagebox * Remove constructors with parameters from ScrollBarView and ScrollView. * Remove parenthesis on objects initializers from ScrollBarView and ScrollView. * Cleanup code. * Fix merge errors. * Add empty dotsettings for solution and projects. * Set ReSharper language analysis level for projects to C#12 * Make ReSharper consider itself the boss for style * Add rule to enforce property backing fields above the property * Disable auto-detection of naming rules so ReSharper doesn't change them by itself * Don't let someone's VS settings override the indent settings * Explicitly set tab width to 4 spaces and force spaces. * Rules to keep various multi-line constructs aligned within themselves * Curly brace rules (Using K&R style, per current project spec) * Blank line rules Mostly to add breaks in various situations, and also to enforce max of 1 blank line. * Increase auto-wrap to 160 from default of 120 * Line break at end of all files, to make Unixy systems happy * Keep attributes on their own lines except for methods and records that are themselves single-line * Increase attribute auto-wrap to 60 from default of 38 * Wrap/chop rules for long method signatures and record declarations Chop if either already multi-line or if over 8 parameters. Chop AFTER the left paren and BEFORE the first parameter. * Chop rules for generics For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment. * Always enforce enum members on their own lines * One-line functions completely on one line They're usually expression-bodied anyway, here, so this is almost irrelevant * Keep control flow statements on their own lines * Follow same chop rules for method invocation as method declaration * Chop long or multi-line method chains or patterns * Wrap rules for binary operators Operator at beginning of new lines Auto-chop if long or already multi-line * Spaces between keywords and their opening parentheses * Add file layout rules for organization of reorderable items like fields, properties, etc. Ugly XML, so load it up in the UI to look at it It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping. * Deconstructors use per-member types * Use keywords for built-in types and increase severity of inspection for violations Also apply to IntPtr and similar, which should now be nint and similar * Apply syntax style on completion. * Use var when evident for built-in and simple types, but not elsewhere * Increase severity for some minor redundancy and clarity inspections * Enforce braces always required for blocks, and treat as error * Warn if a local function is not statement-bodied * Increase various inspection severities IF Condition => Severity: Attributes not wrapped property => Suggestion Constructors expression-bodied => Error default doesn't have type when it isn't clear => suggestion Namespaces not file-scoped => error Methods not statement-bodied => hint Null check pattern not the object property pattern => Error * Adjust preference order of null check patterns to make object pattern highest * XmlDoc rules to keep tags and contents aligned and wrapped * Add a few custom profiles for code cleanup and make the full profile default * Remove parts for languages not used in this solution * copied in v2_develop changes * Merged v2_develop * Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests * TextFormatter.Lines -> GetLines () * Let ReSharper know we intend to localize things * TextFormatter code cleanup * copied in v2_develop changes * Merged v2_develop * Spaces aren't wanted here either. * Fix merge errors. * Fixes ContentBottomRightCorner related with https://github.com/gui-cs/Terminal.Gui/issues/3211#issue-2098878820 * Remove constructors with parameters from ContextMenu. * Remove commented code. * Remove constructors with parameters from OpenDialog. * Remove constructors with parameters from SaveDialog. * Remove constructors with parameters from TextField. * Remove constructors with parameters from TimeField. * Fix unit test. * Remove unnecessary SetInitialProperties method. * Remove unnecessary SetInitialProperties method. * Remove parenthesis on objects initializers from Toplevel and Window. * Remove constructors with parameters from RadioGroup. * Remove constructors with parameters from TextView. * Remove constructors with parameters from MenuBar. * TEMPORARY: Turn everything that was set to error down to warning or lower * Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled. * Remove constructors with parameters from Menu. * Remove constructors with parameters from View. * Change constructor to internal because is mainly useful for testing. * ReSharper Cleanup Code. * Added format only r# config * Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. * Remove constructors with parameters from Dialog. * Remove constructors with parameters from TextValidateField. * Fixes https://github.com/gui-cs/Terminal.Gui/issues/3224#issuecomment-1924096038 * Fixes #3225. Press CursorDown on TabView doesn't move to the next view. * Fixes #3229. TextFormatter should have a FillRemaining property. * Testing formatting merge in bdisp * Testing formatting merge * Testing formatting merge bdisp * Testing formatting merge 2 * xmldoc format * R# Full Code Cleanup * R# Full Code Cleanup2 * R# Full Code Cleanup2 * Merged! But broke tests * Refixing... * Refixed DrawTests * Refixed ViewTests * Refixed Text Tests * Refixed more unit tests * Refixed scenarios * Refixed rest of scenarios * Refixed ViewsTests * Refixed rest of tests. All unit tests pass again! * Fixed warnings * Updated R# version. Added new code cleanup settings * Applied latest code cleanup to solution * Another code cleanup pass * Tweaked r# settings. .editorconfig now matches. * r# else on separate line * r# - update * r# - full solution * test commit * test commit * test commit * Removed extra profiles * Full cleanup following cleaning up profiles * Null checking pattern rules/inspections * Tabs and extra whitespace are evil * Attributes on their own lines * Code layout rules to put fields first and to put backing fields with their properties * Merged v2_develop * Full cleanup following dodexahedron's PR --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
1477 lines
50 KiB
C#
1477 lines
50 KiB
C#
using Xunit.Abstractions;
|
|
|
|
// Alias Console to MockConsole so we don't accidentally use Console
|
|
using Console = Terminal.Gui.FakeConsole;
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
public class NavigationTests
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
public NavigationTests (ITestOutputHelper output) { _output = output; }
|
|
|
|
[Fact]
|
|
public void BringSubviewForward_Subviews_vs_TabIndexes ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.BringSubviewForward (v1);
|
|
Assert.True (r.Subviews.IndexOf (v1) == 1);
|
|
Assert.True (r.Subviews.IndexOf (v2) == 0);
|
|
Assert.True (r.Subviews.IndexOf (v3) == 2);
|
|
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v2) == 1);
|
|
Assert.True (r.TabIndexes.IndexOf (v3) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void BringSubviewToFront_Subviews_vs_TabIndexes ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.BringSubviewToFront (v1);
|
|
Assert.True (r.Subviews.IndexOf (v1) == 2);
|
|
Assert.True (r.Subviews.IndexOf (v2) == 0);
|
|
Assert.True (r.Subviews.IndexOf (v3) == 1);
|
|
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v2) == 1);
|
|
Assert.True (r.TabIndexes.IndexOf (v3) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanFocus_Container_ToFalse_Turns_All_Subviews_ToFalse_Too ()
|
|
{
|
|
Application.Init (new FakeDriver ());
|
|
|
|
Toplevel t = Application.Top;
|
|
|
|
var w = new Window ();
|
|
var f = new FrameView ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
f.Add (v1, v2);
|
|
w.Add (f);
|
|
t.Add (w);
|
|
|
|
t.Ready += (s, e) =>
|
|
{
|
|
Assert.True (t.CanFocus);
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.True (v1.CanFocus);
|
|
Assert.True (v2.CanFocus);
|
|
|
|
w.CanFocus = false;
|
|
Assert.False (w.CanFocus);
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v1.CanFocus);
|
|
Assert.False (v2.CanFocus);
|
|
};
|
|
|
|
Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
|
Application.Run ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True ()
|
|
{
|
|
Application.Init (new FakeDriver ());
|
|
|
|
Toplevel t = Application.Top;
|
|
|
|
var w = new Window ();
|
|
var f = new FrameView ();
|
|
var v1 = new View ();
|
|
var v2 = new View { CanFocus = true };
|
|
f.Add (v1, v2);
|
|
w.Add (f);
|
|
t.Add (w);
|
|
|
|
t.Ready += (s, e) =>
|
|
{
|
|
Assert.True (t.CanFocus);
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.False (v1.CanFocus);
|
|
Assert.True (v2.CanFocus);
|
|
|
|
w.CanFocus = false;
|
|
Assert.False (w.CanFocus);
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v1.CanFocus);
|
|
Assert.False (v2.CanFocus);
|
|
|
|
w.CanFocus = true;
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.False (v1.CanFocus);
|
|
Assert.True (v2.CanFocus);
|
|
};
|
|
|
|
Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
|
Application.Run ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanFocus_Faced_With_Container ()
|
|
{
|
|
var t = new Toplevel ();
|
|
var w = new Window ();
|
|
var f = new FrameView ();
|
|
var v = new View { CanFocus = true };
|
|
f.Add (v);
|
|
w.Add (f);
|
|
t.Add (w);
|
|
|
|
Assert.True (t.CanFocus);
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
f.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
v.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v.CanFocus);
|
|
|
|
v.CanFocus = true;
|
|
Assert.False (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
t.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanFocus_Faced_With_Container_After_Run ()
|
|
{
|
|
Application.Init (new FakeDriver ());
|
|
|
|
Toplevel t = Application.Top;
|
|
|
|
var w = new Window ();
|
|
var f = new FrameView ();
|
|
var v = new View { CanFocus = true };
|
|
f.Add (v);
|
|
w.Add (f);
|
|
t.Add (w);
|
|
|
|
t.Ready += (s, e) =>
|
|
{
|
|
Assert.True (t.CanFocus);
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
f.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v.CanFocus);
|
|
|
|
v.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v.CanFocus);
|
|
|
|
Assert.Throws<InvalidOperationException> (() => v.CanFocus = true);
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v.CanFocus);
|
|
|
|
f.CanFocus = true;
|
|
Assert.True (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
};
|
|
|
|
Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
|
Application.Run ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanFocus_Faced_With_Container_Before_Run ()
|
|
{
|
|
Application.Init (new FakeDriver ());
|
|
|
|
Toplevel t = Application.Top;
|
|
|
|
var w = new Window ();
|
|
var f = new FrameView ();
|
|
var v = new View { CanFocus = true };
|
|
f.Add (v);
|
|
w.Add (f);
|
|
t.Add (w);
|
|
|
|
Assert.True (t.CanFocus);
|
|
Assert.True (w.CanFocus);
|
|
Assert.True (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
f.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
v.CanFocus = false;
|
|
Assert.False (f.CanFocus);
|
|
Assert.False (v.CanFocus);
|
|
|
|
v.CanFocus = true;
|
|
Assert.False (f.CanFocus);
|
|
Assert.True (v.CanFocus);
|
|
|
|
Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
|
Application.Run ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanFocus_Set_Changes_TabIndex_And_TabStop ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { Text = "1" };
|
|
var v2 = new View { Text = "2" };
|
|
var v3 = new View { Text = "3" };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v2.CanFocus = true;
|
|
Assert.Equal (r.TabIndexes.IndexOf (v2), v2.TabIndex);
|
|
Assert.Equal (0, v2.TabIndex);
|
|
Assert.True (v2.TabStop);
|
|
|
|
v1.CanFocus = true;
|
|
Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
|
|
Assert.Equal (1, v1.TabIndex);
|
|
Assert.True (v1.TabStop);
|
|
|
|
v1.TabIndex = 2;
|
|
Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
|
|
Assert.Equal (1, v1.TabIndex);
|
|
v3.CanFocus = true;
|
|
Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
|
|
Assert.Equal (1, v1.TabIndex);
|
|
Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
|
|
Assert.Equal (2, v3.TabIndex);
|
|
Assert.True (v3.TabStop);
|
|
|
|
v2.CanFocus = false;
|
|
Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
|
|
Assert.Equal (1, v1.TabIndex);
|
|
Assert.True (v1.TabStop);
|
|
Assert.NotEqual (r.TabIndexes.IndexOf (v2), v2.TabIndex);
|
|
Assert.Equal (-1, v2.TabIndex);
|
|
Assert.False (v2.TabStop);
|
|
Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
|
|
Assert.Equal (2, v3.TabIndex);
|
|
Assert.True (v3.TabStop);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanFocus_Sets_To_False_Does_Not_Sets_HasFocus_To_True ()
|
|
{
|
|
var view = new View { CanFocus = true };
|
|
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win.Add (view);
|
|
Application.Top.Add (win);
|
|
Application.Begin (Application.Top);
|
|
|
|
Assert.True (view.CanFocus);
|
|
Assert.True (view.HasFocus);
|
|
|
|
view.CanFocus = false;
|
|
Assert.False (view.CanFocus);
|
|
Assert.False (view.HasFocus);
|
|
Assert.Null (Application.Current.Focused);
|
|
Assert.Null (Application.Current.MostFocused);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanFocus_Sets_To_False_On_Single_View_Focus_View_On_Another_Toplevel ()
|
|
{
|
|
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
|
|
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
|
|
win1.Add (view1);
|
|
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
|
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win2.Add (view2);
|
|
Application.Top.Add (win1, win2);
|
|
Application.Begin (Application.Top);
|
|
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
Assert.True (view2.CanFocus);
|
|
Assert.True (view2.HasFocus);
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
view1.CanFocus = false;
|
|
Assert.False (view1.CanFocus);
|
|
Assert.False (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.True (view2.HasFocus);
|
|
Assert.Equal (win2, Application.Current.Focused);
|
|
Assert.Equal (view2, Application.Current.MostFocused);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanFocus_Sets_To_False_On_Toplevel_Focus_View_On_Another_Toplevel ()
|
|
{
|
|
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
|
|
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
|
|
win1.Add (view1);
|
|
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
|
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win2.Add (view2);
|
|
Application.Top.Add (win1, win2);
|
|
Application.Begin (Application.Top);
|
|
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
Assert.True (view2.CanFocus);
|
|
Assert.True (view2.HasFocus);
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
win1.CanFocus = false;
|
|
Assert.False (view1.CanFocus);
|
|
Assert.False (view1.HasFocus);
|
|
Assert.False (win1.CanFocus);
|
|
Assert.False (win1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.True (view2.HasFocus);
|
|
Assert.Equal (win2, Application.Current.Focused);
|
|
Assert.Equal (view2, Application.Current.MostFocused);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void CanFocus_Sets_To_False_With_Two_Views_Focus_Another_View_On_The_Same_Toplevel ()
|
|
{
|
|
var view1 = new View { Id = "view1", Width = 10, Height = 1, CanFocus = true };
|
|
|
|
var view12 = new View
|
|
{
|
|
Id = "view12",
|
|
Y = 5,
|
|
Width = 10,
|
|
Height = 1,
|
|
CanFocus = true
|
|
};
|
|
var win1 = new Window { Id = "win1", Width = Dim.Percent (50), Height = Dim.Fill () };
|
|
win1.Add (view1, view12);
|
|
var view2 = new View { Id = "view2", Width = 20, Height = 2, CanFocus = true };
|
|
var win2 = new Window { Id = "win2", X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win2.Add (view2);
|
|
Application.Top.Add (win1, win2);
|
|
Application.Begin (Application.Top);
|
|
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.False (view1.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
Assert.True (view2.CanFocus);
|
|
Assert.True (view2.HasFocus);
|
|
|
|
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (view1.CanFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus); // Only one of the most focused toplevels view can have focus
|
|
|
|
view1.CanFocus = false;
|
|
Assert.False (view1.CanFocus);
|
|
Assert.False (view1.HasFocus);
|
|
Assert.True (view2.CanFocus);
|
|
Assert.False (view2.HasFocus);
|
|
Assert.Equal (win1, Application.Current.Focused);
|
|
Assert.Equal (view12, Application.Current.MostFocused);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Enabled_False_Sets_HasFocus_To_False ()
|
|
{
|
|
var wasClicked = false;
|
|
var view = new Button { Text = "Click Me" };
|
|
view.Clicked += (s, e) => wasClicked = !wasClicked;
|
|
Application.Top.Add (view);
|
|
|
|
view.NewKeyDownEvent (new Key (KeyCode.Space));
|
|
Assert.True (wasClicked);
|
|
view.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked });
|
|
Assert.False (wasClicked);
|
|
Assert.True (view.Enabled);
|
|
Assert.True (view.CanFocus);
|
|
Assert.True (view.HasFocus);
|
|
|
|
view.Enabled = false;
|
|
view.NewKeyDownEvent (new Key (KeyCode.Space));
|
|
Assert.False (wasClicked);
|
|
view.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked });
|
|
Assert.False (wasClicked);
|
|
Assert.False (view.Enabled);
|
|
Assert.True (view.CanFocus);
|
|
Assert.False (view.HasFocus);
|
|
view.SetFocus ();
|
|
Assert.False (view.HasFocus);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Enabled_Sets_Also_Sets_Subviews ()
|
|
{
|
|
var wasClicked = false;
|
|
var button = new Button { Text = "Click Me" };
|
|
button.IsDefault = true;
|
|
button.Clicked += (s, e) => wasClicked = !wasClicked;
|
|
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win.Add (button);
|
|
Application.Top.Add (win);
|
|
|
|
var iterations = 0;
|
|
|
|
Application.Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
win.NewKeyDownEvent (new Key (KeyCode.Enter));
|
|
Assert.True (wasClicked);
|
|
button.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked });
|
|
Assert.False (wasClicked);
|
|
Assert.True (button.Enabled);
|
|
Assert.True (button.CanFocus);
|
|
Assert.True (button.HasFocus);
|
|
Assert.True (win.Enabled);
|
|
Assert.True (win.CanFocus);
|
|
Assert.True (win.HasFocus);
|
|
|
|
win.Enabled = false;
|
|
button.NewKeyDownEvent (new Key (KeyCode.Enter));
|
|
Assert.False (wasClicked);
|
|
button.MouseEvent (new MouseEvent { Flags = MouseFlags.Button1Clicked });
|
|
Assert.False (wasClicked);
|
|
Assert.False (button.Enabled);
|
|
Assert.True (button.CanFocus);
|
|
Assert.False (button.HasFocus);
|
|
Assert.False (win.Enabled);
|
|
Assert.True (win.CanFocus);
|
|
Assert.False (win.HasFocus);
|
|
button.SetFocus ();
|
|
Assert.False (button.HasFocus);
|
|
Assert.False (win.HasFocus);
|
|
win.SetFocus ();
|
|
Assert.False (button.HasFocus);
|
|
Assert.False (win.HasFocus);
|
|
|
|
win.Enabled = true;
|
|
win.FocusFirst ();
|
|
Assert.True (button.HasFocus);
|
|
Assert.True (win.HasFocus);
|
|
|
|
Application.RequestStop ();
|
|
};
|
|
|
|
Application.Run ();
|
|
|
|
Assert.Equal (1, iterations);
|
|
}
|
|
|
|
[Fact]
|
|
public void FocusNearestView_Ensure_Focus_Ordered ()
|
|
{
|
|
var top = new Toplevel ();
|
|
|
|
var win = new Window ();
|
|
var winSubview = new View { CanFocus = true, Text = "WindowSubview" };
|
|
win.Add (winSubview);
|
|
top.Add (win);
|
|
|
|
var frm = new FrameView ();
|
|
var frmSubview = new View { CanFocus = true, Text = "FrameSubview" };
|
|
frm.Add (frmSubview);
|
|
top.Add (frm);
|
|
|
|
top.NewKeyDownEvent (new Key (KeyCode.Tab));
|
|
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
|
top.NewKeyDownEvent (new Key (KeyCode.Tab));
|
|
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
|
top.NewKeyDownEvent (new Key (KeyCode.Tab));
|
|
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
|
|
|
top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask));
|
|
Assert.Equal ("FrameSubview", top.MostFocused.Text);
|
|
top.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.ShiftMask));
|
|
Assert.Equal ("WindowSubview", top.MostFocused.Text);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void FocusNext_Does_Not_Throws_If_A_View_Was_Removed_From_The_Collection ()
|
|
{
|
|
Toplevel top1 = Application.Top;
|
|
var view1 = new View { Id = "view1", Width = 10, Height = 5, CanFocus = true };
|
|
var top2 = new Toplevel { Id = "top2", Y = 1, Width = 10, Height = 5 };
|
|
|
|
var view2 = new View
|
|
{
|
|
Id = "view2",
|
|
Y = 1,
|
|
Width = 10,
|
|
Height = 5,
|
|
CanFocus = true
|
|
};
|
|
View view3 = null;
|
|
var removed = false;
|
|
|
|
view2.Enter += (s, e) =>
|
|
{
|
|
if (!removed)
|
|
{
|
|
removed = true;
|
|
view3 = new View { Id = "view3", Y = 1, Width = 10, Height = 5 };
|
|
Application.Current.Add (view3);
|
|
Application.Current.BringSubviewToFront (view3);
|
|
Assert.False (view3.HasFocus);
|
|
}
|
|
};
|
|
|
|
view2.Leave += (s, e) =>
|
|
{
|
|
Application.Current.Remove (view3);
|
|
view3.Dispose ();
|
|
view3 = null;
|
|
};
|
|
top2.Add (view2);
|
|
top1.Add (view1, top2);
|
|
Application.Begin (top1);
|
|
|
|
Assert.True (top1.HasFocus);
|
|
Assert.True (view1.HasFocus);
|
|
Assert.False (view2.HasFocus);
|
|
Assert.False (removed);
|
|
Assert.Null (view3);
|
|
|
|
Assert.True (top1.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.True (top1.HasFocus);
|
|
Assert.False (view1.HasFocus);
|
|
Assert.True (view2.HasFocus);
|
|
Assert.True (removed);
|
|
Assert.NotNull (view3);
|
|
|
|
Exception exception =
|
|
Record.Exception (() => top1.NewKeyDownEvent (new Key (KeyCode.Tab | KeyCode.CtrlMask)));
|
|
Assert.Null (exception);
|
|
Assert.True (removed);
|
|
Assert.Null (view3);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_With_Top_KeyPress_Event ()
|
|
{
|
|
var sbQuiting = false;
|
|
var tfQuiting = false;
|
|
var topQuiting = false;
|
|
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (
|
|
KeyCode.CtrlMask | KeyCode.Q,
|
|
"~^Q~ Quit",
|
|
() => sbQuiting = true
|
|
)
|
|
}
|
|
);
|
|
var tf = new TextField ();
|
|
tf.KeyDown += Tf_KeyPressed;
|
|
|
|
void Tf_KeyPressed (object sender, Key obj)
|
|
{
|
|
if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
|
|
{
|
|
obj.Handled = tfQuiting = true;
|
|
}
|
|
}
|
|
|
|
var win = new Window ();
|
|
win.Add (sb, tf);
|
|
Toplevel top = Application.Top;
|
|
top.KeyDown += Top_KeyPress;
|
|
|
|
void Top_KeyPress (object sender, Key obj)
|
|
{
|
|
if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
|
|
{
|
|
obj.Handled = topQuiting = true;
|
|
}
|
|
}
|
|
|
|
top.Add (win);
|
|
Application.Begin (top);
|
|
|
|
Assert.False (sbQuiting);
|
|
Assert.False (tfQuiting);
|
|
Assert.False (topQuiting);
|
|
|
|
Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true);
|
|
Assert.False (sbQuiting);
|
|
Assert.True (tfQuiting);
|
|
Assert.False (topQuiting);
|
|
|
|
#if BROKE_WITH_2927
|
|
tf.KeyPressed -= Tf_KeyPress;
|
|
tfQuiting = false;
|
|
Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
|
|
Application.MainLoop.RunIteration ();
|
|
Assert.True (sbQuiting);
|
|
Assert.False (tfQuiting);
|
|
Assert.False (topQuiting);
|
|
|
|
sb.RemoveItem (0);
|
|
sbQuiting = false;
|
|
Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
|
|
Application.MainLoop.RunIteration ();
|
|
Assert.False (sbQuiting);
|
|
Assert.False (tfQuiting);
|
|
|
|
// This test is now invalid because `win` is focused, so it will receive the keypress
|
|
Assert.True (topQuiting);
|
|
#endif
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void HotKey_Will_Invoke_KeyPressed_Only_For_The_MostFocused_Without_Top_KeyPress_Event ()
|
|
{
|
|
var sbQuiting = false;
|
|
var tfQuiting = false;
|
|
|
|
var sb = new StatusBar (
|
|
new StatusItem []
|
|
{
|
|
new (
|
|
KeyCode.CtrlMask | KeyCode.Q,
|
|
"~^Q~ Quit",
|
|
() => sbQuiting = true
|
|
)
|
|
}
|
|
);
|
|
var tf = new TextField ();
|
|
tf.KeyDown += Tf_KeyPressed;
|
|
|
|
void Tf_KeyPressed (object sender, Key obj)
|
|
{
|
|
if (obj.KeyCode == (KeyCode.Q | KeyCode.CtrlMask))
|
|
{
|
|
obj.Handled = tfQuiting = true;
|
|
}
|
|
}
|
|
|
|
var win = new Window ();
|
|
win.Add (sb, tf);
|
|
Toplevel top = Application.Top;
|
|
top.Add (win);
|
|
Application.Begin (top);
|
|
|
|
Assert.False (sbQuiting);
|
|
Assert.False (tfQuiting);
|
|
|
|
Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true);
|
|
Assert.False (sbQuiting);
|
|
Assert.True (tfQuiting);
|
|
|
|
tf.KeyDown -= Tf_KeyPressed;
|
|
tfQuiting = false;
|
|
Application.Driver.SendKeys ('Q', ConsoleKey.Q, false, false, true);
|
|
Application.MainLoop.RunIteration ();
|
|
#if BROKE_WITH_2927
|
|
Assert.True (sbQuiting);
|
|
Assert.False (tfQuiting);
|
|
#endif
|
|
}
|
|
|
|
[Fact]
|
|
public void Navigation_With_Null_Focused_View ()
|
|
{
|
|
// Non-regression test for #882 (NullReferenceException during keyboard navigation when Focused is null)
|
|
|
|
Application.Init (new FakeDriver ());
|
|
|
|
Application.Top.Ready += (s, e) => { Assert.Null (Application.Top.Focused); };
|
|
|
|
// Keyboard navigation with tab
|
|
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
|
|
|
|
Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
|
Application.Run ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Remove_Does_Not_Change_Focus ()
|
|
{
|
|
Assert.True (Application.Top.CanFocus);
|
|
Assert.False (Application.Top.HasFocus);
|
|
|
|
var container = new View { Width = 10, Height = 10 };
|
|
var leave = false;
|
|
container.Leave += (s, e) => leave = true;
|
|
Assert.False (container.CanFocus);
|
|
var child = new View { Width = Dim.Fill (), Height = Dim.Fill (), CanFocus = true };
|
|
container.Add (child);
|
|
|
|
Assert.True (container.CanFocus);
|
|
Assert.False (container.HasFocus);
|
|
Assert.True (child.CanFocus);
|
|
Assert.False (child.HasFocus);
|
|
|
|
Application.Top.Add (container);
|
|
Application.Begin (Application.Top);
|
|
|
|
Assert.True (Application.Top.CanFocus);
|
|
Assert.True (Application.Top.HasFocus);
|
|
Assert.True (container.CanFocus);
|
|
Assert.True (container.HasFocus);
|
|
Assert.True (child.CanFocus);
|
|
Assert.True (child.HasFocus);
|
|
|
|
container.Remove (child);
|
|
child.Dispose ();
|
|
child = null;
|
|
Assert.True (Application.Top.HasFocus);
|
|
Assert.True (container.CanFocus);
|
|
Assert.True (container.HasFocus);
|
|
Assert.Null (child);
|
|
Assert.False (leave);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ScreenToView_ViewToScreen_FindDeepestView_Full_Top ()
|
|
{
|
|
Toplevel top = Application.Current;
|
|
top.BorderStyle = LineStyle.Single;
|
|
|
|
var view = new View
|
|
{
|
|
X = 3,
|
|
Y = 2,
|
|
Width = 10,
|
|
Height = 1,
|
|
Text = "0123456789"
|
|
};
|
|
top.Add (view);
|
|
|
|
Application.Begin (top);
|
|
|
|
Assert.Equal (Application.Current, top);
|
|
Assert.Equal (new Rect (0, 0, 80, 25), new Rect (0, 0, View.Driver.Cols, View.Driver.Rows));
|
|
Assert.Equal (new Rect (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
|
|
Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (20, 10);
|
|
Assert.Equal (new Rect (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
|
|
Assert.Equal (new Rect (0, 0, 20, 10), top.Frame);
|
|
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
┌──────────────────┐
|
|
│ │
|
|
│ │
|
|
│ 0123456789 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────┘",
|
|
_output
|
|
);
|
|
|
|
// top
|
|
Assert.Equal (Point.Empty, top.ScreenToFrame (0, 0));
|
|
top.Margin.BoundsToScreen (0, 0, out int col, out int row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.Border.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.Padding.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
top.BoundsToScreen (-1, -1, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 0, 0, out int rx, out int ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (3, 2), top.ScreenToFrame (3, 2));
|
|
top.BoundsToScreen (3, 2, out col, out row);
|
|
Assert.Equal (4, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (view, View.FindDeepestView (top, col, row, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (top, View.FindDeepestView (top, 3, 2, out rx, out ry));
|
|
Assert.Equal (3, rx);
|
|
Assert.Equal (2, ry);
|
|
Assert.Equal (new Point (13, 2), top.ScreenToFrame (13, 2));
|
|
top.BoundsToScreen (12, 2, out col, out row);
|
|
Assert.Equal (13, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (view, View.FindDeepestView (top, col, row, out rx, out ry));
|
|
Assert.Equal (9, rx);
|
|
Assert.Equal (0, ry);
|
|
top.BoundsToScreen (13, 2, out col, out row);
|
|
Assert.Equal (14, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 13, 2, out rx, out ry));
|
|
Assert.Equal (13, rx);
|
|
Assert.Equal (2, ry);
|
|
Assert.Equal (new Point (14, 3), top.ScreenToFrame (14, 3));
|
|
top.BoundsToScreen (14, 3, out col, out row);
|
|
Assert.Equal (15, col);
|
|
Assert.Equal (4, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 14, 3, out rx, out ry));
|
|
Assert.Equal (14, rx);
|
|
Assert.Equal (3, ry);
|
|
|
|
// view
|
|
Assert.Equal (new Point (-4, -3), view.ScreenToFrame (0, 0));
|
|
view.Margin.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.Border.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.Padding.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.BoundsToScreen (-4, -3, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 0, 0, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (-1, -1), view.ScreenToFrame (3, 2));
|
|
view.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (4, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (view, View.FindDeepestView (top, 4, 3, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (9, -1), view.ScreenToFrame (13, 2));
|
|
view.BoundsToScreen (10, 0, out col, out row);
|
|
Assert.Equal (14, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 14, 3, out rx, out ry));
|
|
Assert.Equal (14, rx);
|
|
Assert.Equal (3, ry);
|
|
Assert.Equal (new Point (10, 0), view.ScreenToFrame (14, 3));
|
|
view.BoundsToScreen (11, 1, out col, out row);
|
|
Assert.Equal (15, col);
|
|
Assert.Equal (4, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 15, 4, out rx, out ry));
|
|
Assert.Equal (15, rx);
|
|
Assert.Equal (4, ry);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ScreenToView_ViewToScreen_FindDeepestView_Smaller_Top ()
|
|
{
|
|
var top = new Toplevel
|
|
{
|
|
X = 3,
|
|
Y = 2,
|
|
Width = 20,
|
|
Height = 10,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
|
|
var view = new View
|
|
{
|
|
X = 3,
|
|
Y = 2,
|
|
Width = 10,
|
|
Height = 1,
|
|
Text = "0123456789"
|
|
};
|
|
top.Add (view);
|
|
|
|
Application.Begin (top);
|
|
|
|
Assert.Equal (Application.Current, top);
|
|
Assert.Equal (new Rect (0, 0, 80, 25), new Rect (0, 0, View.Driver.Cols, View.Driver.Rows));
|
|
Assert.NotEqual (new Rect (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
|
|
Assert.Equal (new Rect (3, 2, 20, 10), top.Frame);
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (30, 20);
|
|
Assert.Equal (new Rect (0, 0, 30, 20), new Rect (0, 0, View.Driver.Cols, View.Driver.Rows));
|
|
Assert.NotEqual (new Rect (0, 0, View.Driver.Cols, View.Driver.Rows), top.Frame);
|
|
Assert.Equal (new Rect (3, 2, 20, 10), top.Frame);
|
|
|
|
Rect frame = TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
┌──────────────────┐
|
|
│ │
|
|
│ │
|
|
│ 0123456789 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────┘",
|
|
_output
|
|
);
|
|
|
|
// mean the output started at col 3 and line 2
|
|
// which result with a width of 23 and a height of 10 on the output
|
|
Assert.Equal (new Rect (3, 2, 23, 10), frame);
|
|
|
|
// top
|
|
Assert.Equal (new Point (-3, -2), top.ScreenToFrame (0, 0));
|
|
top.Margin.BoundsToScreen (-3, -2, out int col, out int row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.Border.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.Padding.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
top.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
top.BoundsToScreen (-4, -3, out col, out row);
|
|
Assert.Equal (0, col);
|
|
Assert.Equal (0, row);
|
|
Assert.Null (View.FindDeepestView (top, -4, -3, out int rx, out int ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (Point.Empty, top.ScreenToFrame (3, 2));
|
|
top.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (4, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 3, 2, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (10, 0), top.ScreenToFrame (13, 2));
|
|
top.BoundsToScreen (10, 0, out col, out row);
|
|
Assert.Equal (14, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 13, 2, out rx, out ry));
|
|
Assert.Equal (10, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (11, 1), top.ScreenToFrame (14, 3));
|
|
top.BoundsToScreen (11, 1, out col, out row);
|
|
Assert.Equal (15, col);
|
|
Assert.Equal (4, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 14, 3, out rx, out ry));
|
|
Assert.Equal (11, rx);
|
|
Assert.Equal (1, ry);
|
|
|
|
// view
|
|
Assert.Equal (new Point (-7, -5), view.ScreenToFrame (0, 0));
|
|
view.Margin.BoundsToScreen (-6, -4, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.Border.BoundsToScreen (-6, -4, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.Padding.BoundsToScreen (-6, -4, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
view.BoundsToScreen (-6, -4, out col, out row);
|
|
Assert.Equal (1, col);
|
|
Assert.Equal (1, row);
|
|
Assert.Null (View.FindDeepestView (top, 1, 1, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (-4, -3), view.ScreenToFrame (3, 2));
|
|
view.BoundsToScreen (-3, -2, out col, out row);
|
|
Assert.Equal (4, col);
|
|
Assert.Equal (3, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 4, 3, out rx, out ry));
|
|
Assert.Equal (1, rx);
|
|
Assert.Equal (1, ry);
|
|
Assert.Equal (new Point (-1, -1), view.ScreenToFrame (6, 4));
|
|
view.BoundsToScreen (0, 0, out col, out row);
|
|
Assert.Equal (7, col);
|
|
Assert.Equal (5, row);
|
|
Assert.Equal (view, View.FindDeepestView (top, 7, 5, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (6, -1), view.ScreenToFrame (13, 4));
|
|
view.BoundsToScreen (7, 0, out col, out row);
|
|
Assert.Equal (14, col);
|
|
Assert.Equal (5, row);
|
|
Assert.Equal (view, View.FindDeepestView (top, 14, 5, out rx, out ry));
|
|
Assert.Equal (7, rx);
|
|
Assert.Equal (0, ry);
|
|
Assert.Equal (new Point (7, -2), view.ScreenToFrame (14, 3));
|
|
view.BoundsToScreen (8, -1, out col, out row);
|
|
Assert.Equal (15, col);
|
|
Assert.Equal (4, row);
|
|
Assert.Equal (top, View.FindDeepestView (top, 15, 4, out rx, out ry));
|
|
Assert.Equal (12, rx);
|
|
Assert.Equal (2, ry);
|
|
Assert.Equal (new Point (16, -2), view.ScreenToFrame (23, 3));
|
|
view.BoundsToScreen (17, -1, out col, out row);
|
|
Assert.Equal (24, col);
|
|
Assert.Equal (4, row);
|
|
Assert.Null (View.FindDeepestView (top, 24, 4, out rx, out ry));
|
|
Assert.Equal (0, rx);
|
|
Assert.Equal (0, ry);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendSubviewBackwards_Subviews_vs_TabIndexes ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.SendSubviewBackwards (v3);
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.Subviews.IndexOf (v2) == 2);
|
|
Assert.True (r.Subviews.IndexOf (v3) == 1);
|
|
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v2) == 1);
|
|
Assert.True (r.TabIndexes.IndexOf (v3) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void SendSubviewToBack_Subviews_vs_TabIndexes ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.SendSubviewToBack (v3);
|
|
Assert.True (r.Subviews.IndexOf (v1) == 1);
|
|
Assert.True (r.Subviews.IndexOf (v2) == 2);
|
|
Assert.True (r.Subviews.IndexOf (v3) == 0);
|
|
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v2) == 1);
|
|
Assert.True (r.TabIndexes.IndexOf (v3) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void SetFocus_View_With_Null_Superview_Does_Not_Throw_Exception ()
|
|
{
|
|
Assert.True (Application.Top.CanFocus);
|
|
Assert.False (Application.Top.HasFocus);
|
|
|
|
Exception exception = Record.Exception (Application.Top.SetFocus);
|
|
Assert.Null (exception);
|
|
Assert.True (Application.Top.CanFocus);
|
|
Assert.True (Application.Top.HasFocus);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void SetHasFocus_Do_Not_Throws_If_OnLeave_Remove_Focused_Changing_To_Null ()
|
|
{
|
|
var view1Leave = false;
|
|
var subView1Leave = false;
|
|
var subView1subView1Leave = false;
|
|
Toplevel top = Application.Top;
|
|
var view1 = new View { CanFocus = true };
|
|
var subView1 = new View { CanFocus = true };
|
|
var subView1subView1 = new View { CanFocus = true };
|
|
view1.Leave += (s, e) => { view1Leave = true; };
|
|
|
|
subView1.Leave += (s, e) =>
|
|
{
|
|
subView1.Remove (subView1subView1);
|
|
subView1Leave = true;
|
|
};
|
|
view1.Add (subView1);
|
|
|
|
subView1subView1.Leave += (s, e) =>
|
|
{
|
|
// This is never invoked
|
|
subView1subView1Leave = true;
|
|
};
|
|
subView1.Add (subView1subView1);
|
|
var view2 = new View { CanFocus = true };
|
|
top.Add (view1, view2);
|
|
RunState rs = Application.Begin (top);
|
|
|
|
view2.SetFocus ();
|
|
Assert.True (view1Leave);
|
|
Assert.True (subView1Leave);
|
|
Assert.False (subView1subView1Leave);
|
|
Application.End (rs);
|
|
subView1subView1.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void Subviews_TabIndexes_AreEqual ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.Subviews.IndexOf (v2) == 1);
|
|
Assert.True (r.Subviews.IndexOf (v3) == 2);
|
|
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v2) == 1);
|
|
Assert.True (r.TabIndexes.IndexOf (v3) == 2);
|
|
|
|
Assert.Equal (r.Subviews.IndexOf (v1), r.TabIndexes.IndexOf (v1));
|
|
Assert.Equal (r.Subviews.IndexOf (v2), r.TabIndexes.IndexOf (v2));
|
|
Assert.Equal (r.Subviews.IndexOf (v3), r.TabIndexes.IndexOf (v3));
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabIndex_Set_CanFocus_False ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v1.CanFocus = false;
|
|
v1.TabIndex = 0;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
Assert.Equal (-1, v1.TabIndex);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabIndex_Set_CanFocus_False_To_True ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View ();
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v1.CanFocus = true;
|
|
v1.TabIndex = 1;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 1);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabIndex_Set_CanFocus_HigherValues ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v1.TabIndex = 3;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabIndex_Set_CanFocus_LowerValues ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v1.TabIndex = -1;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 0);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabIndex_Set_CanFocus_ValidValues ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
v1.TabIndex = 1;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 1);
|
|
|
|
v1.TabIndex = 2;
|
|
Assert.True (r.Subviews.IndexOf (v1) == 0);
|
|
Assert.True (r.TabIndexes.IndexOf (v1) == 2);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_All_False_And_All_True_And_Changing_TabStop_Later ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true, TabStop = false };
|
|
var v2 = new View { CanFocus = true, TabStop = false };
|
|
var v3 = new View { CanFocus = true, TabStop = false };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
|
|
v1.TabStop = true;
|
|
r.FocusNext ();
|
|
Assert.True (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
v2.TabStop = true;
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.True (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
v3.TabStop = true;
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.True (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_All_True_And_Changing_CanFocus_Later ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View ();
|
|
var v2 = new View ();
|
|
var v3 = new View ();
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
|
|
v1.CanFocus = true;
|
|
r.FocusNext ();
|
|
Assert.True (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
v2.CanFocus = true;
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.True (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
v3.CanFocus = true;
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.True (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_And_CanFocus_Are_All_True ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true };
|
|
var v2 = new View { CanFocus = true };
|
|
var v3 = new View { CanFocus = true };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.True (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.True (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.True (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_And_CanFocus_Mixed_And_BothFalse ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true, TabStop = false };
|
|
var v2 = new View { CanFocus = false, TabStop = true };
|
|
var v3 = new View { CanFocus = false, TabStop = false };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_Are_All_False_And_CanFocus_Are_All_True ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View { CanFocus = true, TabStop = false };
|
|
var v2 = new View { CanFocus = true, TabStop = false };
|
|
var v3 = new View { CanFocus = true, TabStop = false };
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void TabStop_Are_All_True_And_CanFocus_Are_All_False ()
|
|
{
|
|
var r = new View ();
|
|
var v1 = new View ();
|
|
var v2 = new View ();
|
|
var v3 = new View ();
|
|
|
|
r.Add (v1, v2, v3);
|
|
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.FocusNext ();
|
|
Assert.False (v1.HasFocus);
|
|
Assert.False (v2.HasFocus);
|
|
Assert.False (v3.HasFocus);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void WindowDispose_CanFocusProblem ()
|
|
{
|
|
// Arrange
|
|
Application.Init ();
|
|
using var top = new Toplevel ();
|
|
using var view = new View { X = 0, Y = 1, Text = nameof (WindowDispose_CanFocusProblem) };
|
|
using var window = new Window ();
|
|
top.Add (window);
|
|
window.Add (view);
|
|
|
|
// Act
|
|
RunState rs = Application.Begin (top);
|
|
Application.End (rs);
|
|
Application.Shutdown ();
|
|
|
|
// Assert does Not throw NullReferenceException
|
|
top.SetFocus ();
|
|
}
|
|
}
|