Fixes #4172 Timeout revamp and remove continuous mouse (#4173)

* Remove continous press code from Application

* WIP prototype code to handle continuous press as subcomponent of View

* Prototype with Button

* Implement CWP

* Move to seperate classes and prevent double entry to Start

* Fix repeat clicking when moving mouse by removing phantom click code (old implementation of WantContinuousButtonPressed)

* Remove initial tick because it results in double activation e.g. button firing twice immediately as mouse is pressed down.

* Refactor DatePicker lamdas

* WIP investigate subcomponents instead of statics

* Add IMouseGrabHandler to IApplication

* Make mouse grabbing non static activity

* Make MouseHeldDown suppress when null fields e.g. app not initialized in tests

* Update test and remove dependency on Application

* Fix other mouse click and hold tests

* Code cleanup

* Update class diagram

* Fix bad xml doc references

* Fix timed events not getting passed through in v2 applications

* Make timed events nullable for tests that dont create an Application

* Remove strange blocking test

* WIP remove all idles and replace with zero timeouts

* Fix build of tests

* Fix unit tests

* Add wakeup call back in

* Comment out incredibly complicated test and fix others

* Fix test

* test fix

* Make Post execute immediately if already on UI thread

* Re enable test and simplify Invoke to just execute if in UI thread (up front)

* Remove xml doc references to idles

* Remove more references to idles

* Make Screen initialization threadsafe

* Add more exciting timeouts

* WIP add tests

* fix log

* fix test

* make continuous key press use smoth acceleration

* Rename _lock to _lockScreen

* Remove section on idles, they are not a thing anymore - and they kinda never were.

* Add nullable enable

* Add xml comment

* Fix namings and cleanup code

* xmldoc fix

* Rename LockAndRunTimers to just RunTimers

* Rename AddTimeout and RemoveTimeout (and event) to just Add/Remove

* Update description of MainLoop

* Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* Again? Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* Revert Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* When mouse is released from MouseHeldDown reset host MouseState

* Fix namespaces in class diagram

* Apply @BDisp suggested fix

* Fix class diagrams

* Add lock

* Make TimeSpan.Zero definetly run

* Fix duplicate entry in package props

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
Thomas Nind
2025-07-10 18:59:27 +01:00
committed by GitHub
parent 23cacaee93
commit ec827e901e
68 changed files with 1788 additions and 1448 deletions

View File

@@ -307,8 +307,7 @@ public class ApplicationTests
// Public Properties
Assert.Null (Application.Top);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.WantContinuousButtonPressedView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Don't check Application.ForceDriver
// Assert.Empty (Application.ForceDriver);
@@ -569,8 +568,7 @@ public class ApplicationTests
Assert.Null (Application.Top);
RunState rs = Application.Begin (new ());
Assert.Equal (Application.Top, rs.Toplevel);
Assert.Null (Application.MouseGrabView); // public
Assert.Null (Application.WantContinuousButtonPressedView); // public
Assert.Null (Application.MouseGrabHandler.MouseGrabView); // public
Application.Top!.Dispose ();
}
@@ -952,7 +950,7 @@ public class ApplicationTests
Assert.Equal (new (0, 0), w.Frame.Location);
Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed });
Assert.Equal (w.Border, Application.MouseGrabView);
Assert.Equal (w.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (0, 0), w.Frame.Location);
// Move down and to the right.
@@ -1116,6 +1114,8 @@ public class ApplicationTests
private class TestToplevel : Toplevel { }
private readonly object _forceDriverLock = new ();
[Theory]
[InlineData ("v2win", typeof (ConsoleDriverFacade<WindowsConsole.InputRecord>))]
[InlineData ("v2net", typeof (ConsoleDriverFacade<ConsoleKeyInfo>))]
@@ -1129,20 +1129,29 @@ public class ApplicationTests
var result = false;
Task.Run (() =>
{
Task.Delay (300).Wait ();
}).ContinueWith (
(t, _) =>
lock (_forceDriverLock)
{
Task.Run (() =>
{
while (!Application.Initialized)
{
Task.Delay (300).Wait ();
}
})
.ContinueWith (
(t, _) =>
{
// no longer loading
Assert.True (Application.Initialized);
Application.Invoke (() =>
{
// no longer loading
Application.Invoke (() =>
{
result = true;
Application.RequestStop ();
});
},
TaskScheduler.FromCurrentSynchronizationContext ());
result = true;
Application.RequestStop ();
});
},
TaskScheduler.FromCurrentSynchronizationContext ());
}
Application.ForceDriver = driverName;
Application.Run<TestToplevel> ();

View File

@@ -29,61 +29,38 @@ public class MainLoopTests
// Idle Handler tests
[Fact]
public void AddIdle_Adds_And_Removes ()
public void AddTimeout_Adds_And_Removes ()
{
var ml = new MainLoop (new FakeMainLoop ());
Func<bool> fnTrue = () => true;
Func<bool> fnFalse = () => false;
ml.AddIdle (fnTrue);
ml.AddIdle (fnFalse);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnTrue);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fnFalse);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.NotEqual (fnFalse, ml.TimedEvents.IdleHandlers [0]);
Assert.Equal (2, ml.TimedEvents.Timeouts.Count);
Assert.Equal (fnTrue, ml.TimedEvents.Timeouts.ElementAt (0).Value.Callback);
Assert.NotEqual (fnFalse, ml.TimedEvents.Timeouts.ElementAt (0).Value.Callback);
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (a));
Assert.Single (ml.TimedEvents.Timeouts);
// BUGBUG: This doesn't throw or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.False (ml.TimedEvents.Remove (a));
Assert.True (ml.TimedEvents.RemoveIdle (fnFalse));
Assert.True (ml.TimedEvents.Remove (b));
// BUGBUG: This doesn't throw an exception or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnFalse));
// Add again, but with dupe
ml.AddIdle (fnTrue);
ml.AddIdle (fnTrue);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.True (ml.TimedEvents.IdleHandlers [0] ());
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [1]);
Assert.True (ml.TimedEvents.IdleHandlers [1] ());
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.NotEqual (fnFalse, ml.TimedEvents.IdleHandlers [0]);
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Empty (ml.TimedEvents.IdleHandlers);
// BUGBUG: This doesn't throw an exception or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.False (ml.TimedEvents.Remove(b));
}
[Fact]
public void AddIdle_Function_GetsCalled_OnIteration ()
public void AddTimeout_Function_GetsCalled_OnIteration ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -96,13 +73,13 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.RunIteration ();
Assert.Equal (1, functionCalled);
}
[Fact]
public void AddIdle_Twice_Returns_False_Called_Twice ()
public void AddTimeout_Twice_Returns_False_Called_Twice ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -130,19 +107,21 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.AddIdle (fn1);
ml.AddIdle (fn1);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn1);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fnStop));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.Equal (2, functionCalled);
Assert.True (ml.TimedEvents.Remove(a));
Assert.False (ml.TimedEvents.Remove (a));
// Cannot remove b because it returned false i.e. auto removes itself
Assert.False (ml.TimedEvents.Remove (b));
Assert.Equal (1, functionCalled);
}
[Fact]
public void AddIdleTwice_Function_CalledTwice ()
public void AddTimeoutTwice_Function_CalledTwice ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -155,24 +134,24 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
ml.AddIdle (fn);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.RunIteration ();
Assert.Equal (2, functionCalled);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (2, ml.TimedEvents.Timeouts.Count);
functionCalled = 0;
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (a));
Assert.Single (ml.TimedEvents.Timeouts);
ml.RunIteration ();
Assert.Equal (1, functionCalled);
functionCalled = 0;
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.Empty (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (b));
Assert.Empty (ml.TimedEvents.Timeouts);
ml.RunIteration ();
Assert.Equal (0, functionCalled);
Assert.False (ml.TimedEvents.RemoveIdle (fn));
Assert.False (ml.TimedEvents.Remove (b));
}
[Fact]
@@ -189,8 +168,8 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
Assert.True (ml.TimedEvents.RemoveIdle (fn));
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
Assert.True (ml.TimedEvents.Remove (a));
ml.RunIteration ();
Assert.Equal (0, functionCalled);
}
@@ -211,13 +190,13 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
// BUGBUG: This should probably fault?
// Must return a boolean.
Assert.False (ml.TimedEvents.RemoveTimeout (token));
Assert.False (ml.TimedEvents.Remove (token));
}
[Fact]
@@ -241,8 +220,8 @@ public class MainLoopTests
return true;
};
var task1 = new Task (() => token1 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback));
var task2 = new Task (() => token2 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback));
var task1 = new Task (() => token1 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback));
var task2 = new Task (() => token2 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback));
Assert.Null (token1);
Assert.Null (token2);
task1.Start ();
@@ -251,8 +230,8 @@ public class MainLoopTests
Assert.NotNull (token1);
Assert.NotNull (token2);
await Task.WhenAll (task1, task2);
Assert.True (ml.TimedEvents.RemoveTimeout (token1));
Assert.True (ml.TimedEvents.RemoveTimeout (token2));
Assert.True (ml.TimedEvents.Remove (token1));
Assert.True (ml.TimedEvents.Remove (token2));
Assert.Equal (2, callbackCount);
}
@@ -278,13 +257,13 @@ public class MainLoopTests
object sender = null;
TimeoutEventArgs args = null;
ml.TimedEvents.TimeoutAdded += (s, e) =>
ml.TimedEvents.Added += (s, e) =>
{
sender = s;
args = e;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
Assert.Same (ml.TimedEvents, sender);
Assert.NotNull (args.Timeout);
@@ -313,14 +292,14 @@ public class MainLoopTests
};
Parallel.Invoke (
() => token1 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback),
() => token2 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback)
() => token1 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback),
() => token2 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback)
);
ml.Run ();
Assert.NotNull (token1);
Assert.NotNull (token2);
Assert.True (ml.TimedEvents.RemoveTimeout (token1));
Assert.True (ml.TimedEvents.RemoveTimeout (token2));
Assert.True (ml.TimedEvents.Remove (token1));
Assert.True (ml.TimedEvents.Remove (token2));
Assert.Equal (2, callbackCount);
}
@@ -345,7 +324,7 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var callbackCount = 0;
@@ -356,8 +335,8 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
Assert.True (ml.TimedEvents.RemoveTimeout (token));
object token = ml.TimedEvents.Add (ms, callback);
Assert.True (ml.TimedEvents.Remove (token));
ml.Run ();
Assert.Equal (0, callbackCount);
}
@@ -383,7 +362,7 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var callbackCount = 0;
@@ -394,11 +373,11 @@ public class MainLoopTests
return false;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
ml.Run ();
Assert.Equal (1, callbackCount);
Assert.Equal (10, stopCount);
Assert.False (ml.TimedEvents.RemoveTimeout (token));
Assert.False (ml.TimedEvents.Remove (token));
}
[Fact]
@@ -417,9 +396,9 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (1, callbackCount);
}
@@ -442,7 +421,7 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
watch.Start ();
ml.Run ();
@@ -450,7 +429,7 @@ public class MainLoopTests
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (1, callbackCount);
}
@@ -476,7 +455,7 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
watch.Start ();
ml.Run ();
@@ -484,7 +463,7 @@ public class MainLoopTests
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (2, callbackCount);
}
@@ -492,7 +471,7 @@ public class MainLoopTests
public void CheckTimersAndIdleHandlers_NoTimers_Returns_False ()
{
var ml = new MainLoop (new FakeMainLoop ());
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
bool retVal = ml.TimedEvents.CheckTimers(out int waitTimeOut);
Assert.False (retVal);
Assert.Equal (-1, waitTimeOut);
}
@@ -503,10 +482,10 @@ public class MainLoopTests
var ml = new MainLoop (new FakeMainLoop ());
Func<bool> fnTrue = () => true;
ml.AddIdle (fnTrue);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
ml.TimedEvents.Add (TimeSpan.Zero, fnTrue);
bool retVal = ml.TimedEvents.CheckTimers(out int waitTimeOut);
Assert.True (retVal);
Assert.Equal (-1, waitTimeOut);
Assert.Equal (0, waitTimeOut);
}
[Fact]
@@ -517,8 +496,8 @@ public class MainLoopTests
static bool Callback () { return false; }
_ = ml.TimedEvents.AddTimeout (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
_ = ml.TimedEvents.Add (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimers (out int waitTimeOut);
Assert.True (retVal);
@@ -534,9 +513,9 @@ public class MainLoopTests
static bool Callback () { return false; }
_ = ml.TimedEvents.AddTimeout (ms, Callback);
_ = ml.TimedEvents.AddTimeout (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
_ = ml.TimedEvents.Add (ms, Callback);
_ = ml.TimedEvents.Add (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimers (out int waitTimeOut);
Assert.True (retVal);
@@ -578,11 +557,11 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.AddIdle (fn1);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn1);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fnStop));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.True (ml.TimedEvents.Remove (a));
Assert.False (ml.TimedEvents.Remove (a));
Assert.Equal (10, functionCalled);
Assert.Equal (20, stopCount);
@@ -594,7 +573,6 @@ public class MainLoopTests
var testMainloop = new TestMainloop ();
var mainloop = new MainLoop (testMainloop);
Assert.Empty (mainloop.TimedEvents.Timeouts);
Assert.Empty (mainloop.TimedEvents.IdleHandlers);
Assert.NotNull (
new App.Timeout { Span = new (), Callback = () => true }
@@ -602,8 +580,8 @@ public class MainLoopTests
}
[Theory]
[MemberData (nameof (TestAddIdle))]
public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (
[MemberData (nameof (TestAddTimeout))]
public void Mainloop_Invoke_Or_AddTimeout_Can_Be_Used_For_Events_Or_Actions (
Action action,
string pclickMe,
string pcancel,
@@ -683,7 +661,7 @@ public class MainLoopTests
Application.Shutdown ();
}
[Fact]
public void RemoveIdle_Function_NotCalled ()
{
@@ -698,7 +676,7 @@ public class MainLoopTests
return true;
};
Assert.False (ml.TimedEvents.RemoveIdle (fn));
Assert.False (ml.TimedEvents.Remove ("flibble"));
ml.RunIteration ();
Assert.Equal (0, functionCalled);
}
@@ -722,14 +700,14 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.True (ml.TimedEvents.Remove (a));
Assert.Equal (10, functionCalled);
}
public static IEnumerable<object []> TestAddIdle
public static IEnumerable<object []> TestAddTimeout
{
get
{

View File

@@ -260,39 +260,39 @@ public class ApplicationMouseTests
// if (iterations == 0)
// {
// Assert.True (tf.HasFocus);
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition });
// Assert.Equal (sv, Application.MouseGrabView);
// Assert.Equal (sv, Application.MouseGrabHandler.MouseGrabView);
// MessageBox.Query ("Title", "Test", "Ok");
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// }
// else if (iterations == 1)
// {
// // Application.MouseGrabView is null because
// // Application.MouseGrabHandler.MouseGrabView is null because
// // another toplevel (Dialog) was opened
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (40, 12), Flags = MouseFlags.ReportMousePosition });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RequestStop ();
// }
// else if (iterations == 2)
// {
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RequestStop ();
// }
@@ -313,33 +313,33 @@ public class ApplicationMouseTests
var view2 = new View { Id = "view2" };
var view3 = new View { Id = "view3" };
Application.GrabbedMouse += Application_GrabbedMouse;
Application.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse += Application_GrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.GrabMouse (view1);
Application.MouseGrabHandler.GrabMouse (view1);
Assert.Equal (0, count);
Assert.Equal (grabView, view1);
Assert.Equal (view1, Application.MouseGrabView);
Assert.Equal (view1, Application.MouseGrabHandler.MouseGrabView);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
Assert.Equal (1, count);
Assert.Equal (grabView, view1);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Application.GrabbedMouse += Application_GrabbedMouse;
Application.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse += Application_GrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.GrabMouse (view2);
Application.MouseGrabHandler.GrabMouse (view2);
Assert.Equal (1, count);
Assert.Equal (grabView, view2);
Assert.Equal (view2, Application.MouseGrabView);
Assert.Equal (view2, Application.MouseGrabHandler.MouseGrabView);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
Assert.Equal (2, count);
Assert.Equal (grabView, view2);
Assert.Equal (view3, Application.MouseGrabView);
Application.UngrabMouse ();
Assert.Null (Application.MouseGrabView);
Assert.Equal (view3, Application.MouseGrabHandler.MouseGrabView);
Application.MouseGrabHandler.UngrabMouse ();
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
void Application_GrabbedMouse (object sender, ViewEventArgs e)
{
@@ -354,7 +354,7 @@ public class ApplicationMouseTests
grabView = view2;
}
Application.GrabbedMouse -= Application_GrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse -= Application_GrabbedMouse;
}
void Application_UnGrabbedMouse (object sender, ViewEventArgs e)
@@ -375,10 +375,10 @@ public class ApplicationMouseTests
if (count > 1)
{
// It's possible to grab another view after the previous was ungrabbed
Application.GrabMouse (view3);
Application.MouseGrabHandler.GrabMouse (view3);
}
Application.UnGrabbedMouse -= Application_UnGrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse -= Application_UnGrabbedMouse;
}
}
@@ -393,18 +393,18 @@ public class ApplicationMouseTests
top.Add (view);
Application.Begin (top);
Assert.Null (Application.MouseGrabView);
Application.GrabMouse (view);
Assert.Equal (view, Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Application.MouseGrabHandler.GrabMouse (view);
Assert.Equal (view, Application.MouseGrabHandler.MouseGrabView);
top.Remove (view);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
view.Dispose ();
#if DEBUG_IDISPOSABLE
Assert.True (view.WasDisposed);
#endif
Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (0, count);
top.Dispose ();
}

View File

@@ -15,7 +15,7 @@ public class MainLoopDriverTests
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
public void MainLoop_AddIdle_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType)
public void MainLoop_AddTimeout_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType)
{
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
@@ -29,7 +29,7 @@ public class MainLoopDriverTests
return false;
}
Func<bool> token = mainLoop.AddIdle (IdleHandler);
var token = mainLoop.TimedEvents.Add(TimeSpan.Zero, IdleHandler);
Assert.NotNull (token);
Assert.False (idleHandlerInvoked); // Idle handler should not be invoked immediately
@@ -52,7 +52,7 @@ public class MainLoopDriverTests
var mainLoop = new MainLoop (mainLoopDriver);
var callbackInvoked = false;
object token = mainLoop.TimedEvents.AddTimeout (
object token = mainLoop.TimedEvents.Add (
TimeSpan.FromMilliseconds (100),
() =>
{
@@ -87,11 +87,11 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
mainLoop.AddIdle (() => false);
bool result = mainLoop.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeout);
mainLoop.TimedEvents.Add (TimeSpan.Zero, () => false);
bool result = mainLoop.TimedEvents.CheckTimers (out int waitTimeout);
Assert.True (result);
Assert.Equal (-1, waitTimeout);
Assert.Equal (0, waitTimeout);
mainLoop.Dispose ();
}
@@ -102,7 +102,7 @@ public class MainLoopDriverTests
[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
public void MainLoop_CheckTimersAndIdleHandlers_NoTimersOrIdleHandlers_ReturnsFalse (
public void MainLoop_CheckTimers_NoTimersOrIdleHandlers_ReturnsFalse (
Type driverType,
Type mainLoopDriverType
)
@@ -111,7 +111,7 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
bool result = mainLoop.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeout);
bool result = mainLoop.TimedEvents.CheckTimers (out int waitTimeout);
Assert.False (result);
Assert.Equal (-1, waitTimeout);
@@ -134,8 +134,8 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
mainLoop.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (100), () => false);
bool result = mainLoop.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeout);
mainLoop.TimedEvents.Add (TimeSpan.FromMilliseconds (100), () => false);
bool result = mainLoop.TimedEvents.CheckTimers(out int waitTimeout);
Assert.True (result);
Assert.True (waitTimeout >= 0);
@@ -158,7 +158,6 @@ public class MainLoopDriverTests
// Check default values
Assert.NotNull (mainLoop);
Assert.Equal (mainLoopDriver, mainLoop.MainLoopDriver);
Assert.Empty (mainLoop.TimedEvents.IdleHandlers);
Assert.Empty (mainLoop.TimedEvents.Timeouts);
Assert.False (mainLoop.Running);
@@ -168,7 +167,6 @@ public class MainLoopDriverTests
// TODO: It'd be nice if we could really verify IMainLoopDriver.TearDown was called
// and that it was actually cleaned up.
Assert.Null (mainLoop.MainLoopDriver);
Assert.Empty (mainLoop.TimedEvents.IdleHandlers);
Assert.Empty (mainLoop.TimedEvents.Timeouts);
Assert.False (mainLoop.Running);
}
@@ -186,7 +184,7 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
bool result = mainLoop.TimedEvents.RemoveIdle (() => false);
bool result = mainLoop.TimedEvents.Remove("flibble");
Assert.False (result);
mainLoop.Dispose ();
@@ -207,8 +205,9 @@ public class MainLoopDriverTests
bool IdleHandler () { return false; }
Func<bool> token = mainLoop.AddIdle (IdleHandler);
bool result = mainLoop.TimedEvents.RemoveIdle (token);
var token = mainLoop.TimedEvents.Add (TimeSpan.Zero, IdleHandler);
bool result = mainLoop.TimedEvents.Remove (token);
Assert.True (result);
mainLoop.Dispose ();
@@ -227,7 +226,7 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
bool result = mainLoop.TimedEvents.RemoveTimeout (new object ());
bool result = mainLoop.TimedEvents.Remove (new object ());
Assert.False (result);
}
@@ -245,8 +244,8 @@ public class MainLoopDriverTests
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
var mainLoop = new MainLoop (mainLoopDriver);
object token = mainLoop.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (100), () => false);
bool result = mainLoop.TimedEvents.RemoveTimeout (token);
object token = mainLoop.TimedEvents.Add (TimeSpan.FromMilliseconds (100), () => false);
bool result = mainLoop.TimedEvents.Remove (token);
Assert.True (result);
mainLoop.Dispose ();
@@ -273,7 +272,7 @@ public class MainLoopDriverTests
return false;
};
mainLoop.AddIdle (idleHandler);
mainLoop.TimedEvents.Add (TimeSpan.Zero, idleHandler);
mainLoop.RunIteration (); // Run an iteration to process the idle handler
Assert.True (idleHandlerInvoked);

View File

@@ -401,7 +401,7 @@ public class ApplicationV2Tests
v2.Init ();
v2.AddIdle (IdleExit);
v2.AddTimeout (TimeSpan.Zero, IdleExit);
Assert.Null (Application.Top);
// Blocks until the timeout call is hit
@@ -448,7 +448,7 @@ public class ApplicationV2Tests
Assert.Same (t, a.Toplevel);
};
v2.AddIdle (IdleExit);
v2.AddTimeout(TimeSpan.Zero, IdleExit);
// Blocks until the timeout call is hit

View File

@@ -679,14 +679,7 @@ public class EscSeqUtilsTests
Assert.Equal (new () { MouseFlags.Button1TripleClicked }, _mouseFlags);
Assert.Equal (new (1, 2), _pos);
Assert.False (_isResponse);
var view = new View { Width = Dim.Fill (), Height = Dim.Fill (), WantContinuousButtonPressed = true };
var top = new Toplevel ();
top.Add (view);
Application.Begin (top);
Application.RaiseMouseEvent (new () { Position = new (0, 0), Flags = 0 });
ClearAll ();
_cki = new ConsoleKeyInfo []
@@ -734,26 +727,8 @@ public class EscSeqUtilsTests
Assert.Equal (new (1, 2), _pos);
Assert.False (_isResponse);
Application.Iteration += (s, a) =>
{
if (_actionStarted)
{
// set Application.WantContinuousButtonPressedView to null
view.WantContinuousButtonPressed = false;
Application.RaiseMouseEvent (new () { Position = new (0, 0), Flags = 0 });
Application.RequestStop ();
}
};
Application.Run (top);
top.Dispose ();
Assert.Null (Application.WantContinuousButtonPressedView);
Assert.Equal (MouseFlags.Button1Pressed, _arg1);
Assert.Equal (new (1, 2), _arg2);
Assert.Equal (MouseFlags.None, _arg1);
Assert.Equal (new (0, 0), _arg2);
ClearAll ();

View File

@@ -160,7 +160,7 @@ public class ShadowStyleTests (ITestOutputHelper output)
view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released, Position = new (0, 0) });
Assert.Equal (origThickness, view.Margin.Thickness);
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
}

View File

@@ -1,4 +1,5 @@
using UnitTests;
using Moq;
using UnitTests;
namespace Terminal.Gui.ViewMouseTests;
@@ -95,7 +96,7 @@ public class MouseTests : TestsAllViews
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -125,7 +126,7 @@ public class MouseTests : TestsAllViews
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -155,7 +156,7 @@ public class MouseTests : TestsAllViews
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -166,7 +167,6 @@ public class MouseTests : TestsAllViews
[InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released)]
public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Button_Press_Release_Clicks (MouseFlags pressed, MouseFlags released)
{
Application.Init (new FakeDriver ());
var me = new MouseEventArgs ();
var view = new View
@@ -177,28 +177,43 @@ public class MouseTests : TestsAllViews
WantMousePositionReports = true
};
// Setup components for mouse held down
var timed = new TimedEvents ();
var grab = new MouseGrabHandler ();
view.MouseHeldDown = new MouseHeldDown (view, timed, grab);
// Register callback for what to do when the mouse is held down
var clickedCount = 0;
view.MouseHeldDown.MouseIsHeldDownTick += (_, _) => clickedCount++;
view.MouseClick += (s, e) => clickedCount++;
// Mouse is currently not held down so should be no timers running
Assert.Empty(timed.Timeouts);
// When mouse is held down
me.Flags = pressed;
view.NewMouseEvent (me);
Assert.Equal (0, clickedCount);
me.Handled = false;
me.Flags = pressed;
view.NewMouseEvent (me);
Assert.Equal (1, clickedCount);
me.Handled = false;
// A timer should begin
var t = Assert.Single (timed.Timeouts);
// Invoke the timer
t.Value.Callback.Invoke ();
// Event should have been raised
Assert.Equal (1, clickedCount);
Assert.NotEmpty(timed.Timeouts);
// When mouse is released
me.Flags = released;
view.NewMouseEvent (me);
// timer should stop
Assert.Empty (timed.Timeouts);
Assert.Equal (1, clickedCount);
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
Application.ResetState (true);
}
[Theory]
@@ -212,7 +227,6 @@ public class MouseTests : TestsAllViews
MouseFlags clicked
)
{
Application.Init (new FakeDriver ());
var me = new MouseEventArgs ();
var view = new View
@@ -223,39 +237,49 @@ public class MouseTests : TestsAllViews
WantMousePositionReports = true
};
var clickedCount = 0;
// Setup components for mouse held down
var timed = new TimedEvents ();
var grab = new MouseGrabHandler ();
view.MouseHeldDown = new MouseHeldDown (view, timed, grab);
view.MouseClick += (s, e) => clickedCount++;
// Register callback for what to do when the mouse is held down
var clickedCount = 0;
view.MouseHeldDown.MouseIsHeldDownTick += (_, _) => clickedCount++;
Assert.Empty (timed.Timeouts);
me.Flags = pressed;
view.NewMouseEvent (me);
Assert.Equal (0, clickedCount);
me.Handled = false;
Assert.NotEmpty(timed.Timeouts);
Assert.Single (timed.Timeouts).Value.Callback.Invoke ();
me.Flags = pressed;
view.NewMouseEvent (me);
Assert.Equal (1, clickedCount);
me.Handled = false;
Assert.NotEmpty (timed.Timeouts);
me.Flags = released;
view.NewMouseEvent (me);
Assert.Equal (1, clickedCount);
me.Handled = false;
Assert.Empty (timed.Timeouts);
me.Flags = clicked;
view.NewMouseEvent (me);
Assert.Equal (1, clickedCount);
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
Application.ResetState (true);
}
[Fact]
public void WantContinuousButtonPressed_True_And_WantMousePositionReports_True_Move_InViewport_OutOfViewport_Keeps_Counting ()
{
Application.Init (new FakeDriver ());
var me = new MouseEventArgs ();
var view = new View
@@ -266,9 +290,14 @@ public class MouseTests : TestsAllViews
WantMousePositionReports = true
};
var clickedCount = 0;
// Setup components for mouse held down
var timed = new TimedEvents ();
var grab = new MouseGrabHandler ();
view.MouseHeldDown = new MouseHeldDown (view, timed, grab);
view.MouseClick += (s, e) => clickedCount++;
// Register callback for what to do when the mouse is held down
var clickedCount = 0;
view.MouseHeldDown.MouseIsHeldDownTick += (_, _) => clickedCount++;
// Start in Viewport
me.Flags = MouseFlags.Button1Pressed;
@@ -277,17 +306,30 @@ public class MouseTests : TestsAllViews
Assert.Equal (0, clickedCount);
me.Handled = false;
// Mouse is held down so timer should be ticking
Assert.NotEmpty (timed.Timeouts);
Assert.Equal (clickedCount,0);
// Don't wait, just force it to expire
Assert.Single (timed.Timeouts).Value.Callback.Invoke ();
Assert.Equal (clickedCount, 1);
// Move out of Viewport
me.Flags = MouseFlags.Button1Pressed;
me.Position = me.Position with { X = 1 };
view.NewMouseEvent (me);
Assert.Equal (1, clickedCount);
Assert.Single (timed.Timeouts).Value.Callback.Invoke ();
Assert.Equal (clickedCount, 2);
me.Handled = false;
// Move into Viewport
me.Flags = MouseFlags.Button1Pressed;
me.Position = me.Position with { X = 0 };
view.NewMouseEvent (me);
Assert.NotEmpty (timed.Timeouts);
Assert.Equal (2, clickedCount);
me.Handled = false;
@@ -295,13 +337,13 @@ public class MouseTests : TestsAllViews
me.Flags = MouseFlags.Button1Pressed;
me.Position = me.Position with { X = 0 };
view.NewMouseEvent (me);
Assert.Single (timed.Timeouts).Value.Callback.Invoke ();
Assert.Equal (3, clickedCount);
me.Handled = false;
view.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
Application.ResetState (true);
}
//[Theory]
@@ -335,7 +377,7 @@ public class MouseTests : TestsAllViews
// testView.Dispose ();
// // Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// // Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
// Application.ResetState (true);
//}
@@ -400,7 +442,7 @@ public class MouseTests : TestsAllViews
testView.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -462,7 +504,7 @@ public class MouseTests : TestsAllViews
testView.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -525,7 +567,7 @@ public class MouseTests : TestsAllViews
testView.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
@@ -589,7 +631,7 @@ public class MouseTests : TestsAllViews
testView.Dispose ();
// Button1Pressed, Button1Released cause Application.MouseGrabView to be set
// Button1Pressed, Button1Released cause Application.MouseGrabHandler.MouseGrabView to be set
Application.ResetState (true);
}
private class MouseEventTestView : View

View File

@@ -2571,11 +2571,11 @@ Edit
if (i is < 0 or > 0)
{
Assert.Equal (menu, Application.MouseGrabView);
Assert.Equal (menu, Application.MouseGrabHandler.MouseGrabView);
}
else
{
Assert.Equal (menuBar, Application.MouseGrabView);
Assert.Equal (menuBar, Application.MouseGrabHandler.MouseGrabView);
}
Assert.Equal ("_Edit", miCurrent.Parent.Title);

View File

@@ -106,6 +106,9 @@ public class SpinnerViewTests (ITestOutputHelper output)
top.Add (view);
Application.Begin (top);
// Required to clear the initial 'Invoke nothing' that Begin does
Application.MainLoop.TimedEvents.Timeouts.Clear ();
Assert.Equal (1, view.Frame.Width);
Assert.Equal (1, view.Frame.Height);

View File

@@ -305,17 +305,17 @@ public class ToplevelTests
}
else if (iterations == 2)
{
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Grab the mouse
Application.RaiseMouseEvent (new () { ScreenPosition = new (3, 2), Flags = MouseFlags.Button1Pressed });
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (2, 2, 10, 3), Application.Top.Frame);
}
else if (iterations == 3)
{
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
// Drag to left
Application.RaiseMouseEvent (
@@ -326,19 +326,19 @@ public class ToplevelTests
});
Application.LayoutAndDraw ();
Assert.Equal (Application.Top.Border, Application.MouseGrabView);
Assert.Equal (Application.Top.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 2, 10, 3), Application.Top.Frame);
}
else if (iterations == 4)
{
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 2), Application.Top.Frame.Location);
Assert.Equal (Application.Top.Border, Application.MouseGrabView);
Assert.Equal (Application.Top.Border, Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 5)
{
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
// Drag up
Application.RaiseMouseEvent (
@@ -349,26 +349,26 @@ public class ToplevelTests
});
Application.LayoutAndDraw ();
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 1, 10, 3), Application.Top.Frame);
}
else if (iterations == 6)
{
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 1), Application.Top.Frame.Location);
Assert.Equal (Application.Top.Border, Application.MouseGrabView);
Assert.Equal (Application.Top.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 1, 10, 3), Application.Top.Frame);
}
else if (iterations == 7)
{
Assert.Equal (Application.Top!.Border, Application.MouseGrabView);
Assert.Equal (Application.Top!.Border, Application.MouseGrabHandler.MouseGrabView);
// Ungrab the mouse
Application.RaiseMouseEvent (new () { ScreenPosition = new (2, 1), Flags = MouseFlags.Button1Released });
Application.LayoutAndDraw ();
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 8)
{
@@ -411,7 +411,7 @@ public class ToplevelTests
{
location = win.Frame;
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Grab the mouse
Application.RaiseMouseEvent (
@@ -420,11 +420,11 @@ public class ToplevelTests
ScreenPosition = new (win.Frame.X, win.Frame.Y), Flags = MouseFlags.Button1Pressed
});
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 2)
{
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
// Drag to left
movex = 1;
@@ -438,18 +438,18 @@ public class ToplevelTests
| MouseFlags.ReportMousePosition
});
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 3)
{
// we should have moved +1, +0
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
location.Offset (movex, movey);
}
else if (iterations == 4)
{
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
// Drag up
movex = 0;
@@ -463,18 +463,18 @@ public class ToplevelTests
| MouseFlags.ReportMousePosition
});
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 5)
{
// we should have moved +0, -1
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
location.Offset (movex, movey);
Assert.Equal (location, win.Frame);
}
else if (iterations == 6)
{
Assert.Equal (win.Border, Application.MouseGrabView);
Assert.Equal (win.Border, Application.MouseGrabHandler.MouseGrabView);
// Ungrab the mouse
movex = 0;
@@ -487,7 +487,7 @@ public class ToplevelTests
Flags = MouseFlags.Button1Released
});
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
}
else if (iterations == 7)
{
@@ -602,11 +602,11 @@ public class ToplevelTests
Assert.Equal (new (0, 0, 40, 10), top.Frame);
Assert.Equal (new (0, 0, 20, 3), window.Frame);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
Assert.Equal (window.Border, Application.MouseGrabView);
Assert.Equal (window.Border, Application.MouseGrabHandler.MouseGrabView);
Application.RaiseMouseEvent (
new ()
@@ -694,14 +694,14 @@ public class ToplevelTests
RunState rs = Application.Begin (window);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (0, 0, 10, 3), window.Frame);
Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
var firstIteration = false;
Application.RunIteration (ref rs, firstIteration);
Assert.Equal (window.Border, Application.MouseGrabView);
Assert.Equal (window.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (0, 0, 10, 3), window.Frame);
@@ -713,7 +713,7 @@ public class ToplevelTests
firstIteration = false;
Application.RunIteration (ref rs, firstIteration);
Assert.Equal (window.Border, Application.MouseGrabView);
Assert.Equal (window.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (1, 1, 10, 3), window.Frame);
Application.End (rs);