ToplevelTests.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. using System;
  2. using Xunit;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.Core {
  5. public class ToplevelTests {
  6. readonly ITestOutputHelper output;
  7. public ToplevelTests (ITestOutputHelper output)
  8. {
  9. this.output = output;
  10. }
  11. [Fact]
  12. [AutoInitShutdown]
  13. public void Constructor_Default ()
  14. {
  15. var top = new Toplevel ();
  16. Assert.Equal (Colors.TopLevel, top.ColorScheme);
  17. Assert.Equal ("Dim.Fill(margin=0)", top.Width.ToString ());
  18. Assert.Equal ("Dim.Fill(margin=0)", top.Height.ToString ());
  19. Assert.False (top.Running);
  20. Assert.False (top.Modal);
  21. Assert.Null (top.MenuBar);
  22. Assert.Null (top.StatusBar);
  23. Assert.False (top.IsMdiContainer);
  24. Assert.False (top.IsMdiChild);
  25. }
  26. [Fact]
  27. [AutoInitShutdown]
  28. public void Create_Toplevel ()
  29. {
  30. var top = Toplevel.Create ();
  31. Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
  32. }
  33. [Fact]
  34. [AutoInitShutdown]
  35. public void Application_Top_EnsureVisibleBounds_To_Driver_Rows_And_Cols ()
  36. {
  37. var iterations = 0;
  38. Application.Iteration += () => {
  39. if (iterations == 0) {
  40. Assert.False (Application.Top.AutoSize);
  41. Assert.Equal ("Top1", Application.Top.Text);
  42. Assert.Equal (0, Application.Top.Frame.X);
  43. Assert.Equal (0, Application.Top.Frame.Y);
  44. Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
  45. Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
  46. Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.R, new KeyModifiers ()));
  47. } else if (iterations == 1) {
  48. Assert.Equal ("Top2", Application.Top.Text);
  49. Assert.Equal (0, Application.Top.Frame.X);
  50. Assert.Equal (0, Application.Top.Frame.Y);
  51. Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
  52. Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
  53. Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.C, new KeyModifiers ()));
  54. } else if (iterations == 3) {
  55. Assert.Equal ("Top1", Application.Top.Text);
  56. Assert.Equal (0, Application.Top.Frame.X);
  57. Assert.Equal (0, Application.Top.Frame.Y);
  58. Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
  59. Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
  60. Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.R, new KeyModifiers ()));
  61. } else if (iterations == 4) {
  62. Assert.Equal ("Top2", Application.Top.Text);
  63. Assert.Equal (0, Application.Top.Frame.X);
  64. Assert.Equal (0, Application.Top.Frame.Y);
  65. Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
  66. Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
  67. Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.C, new KeyModifiers ()));
  68. } else if (iterations == 6) {
  69. Assert.Equal ("Top1", Application.Top.Text);
  70. Assert.Equal (0, Application.Top.Frame.X);
  71. Assert.Equal (0, Application.Top.Frame.Y);
  72. Assert.Equal (Application.Driver.Cols, Application.Top.Frame.Width);
  73. Assert.Equal (Application.Driver.Rows, Application.Top.Frame.Height);
  74. Application.Top.ProcessHotKey (new KeyEvent (Key.CtrlMask | Key.Q, new KeyModifiers ()));
  75. }
  76. iterations++;
  77. };
  78. Application.Run (Top1 ());
  79. Toplevel Top1 ()
  80. {
  81. var top = Application.Top;
  82. top.Text = "Top1";
  83. var menu = new MenuBar (new MenuBarItem [] {
  84. new MenuBarItem ("_Options", new MenuItem [] {
  85. new MenuItem ("_Run Top2", "", () => Application.Run (Top2 ()), null, null, Key.CtrlMask | Key.R),
  86. new MenuItem ("_Quit", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.Q)
  87. })
  88. });
  89. top.Add (menu);
  90. var statusBar = new StatusBar (new [] {
  91. new StatusItem(Key.CtrlMask | Key.R, "~^R~ Run Top2", () => Application.Run (Top2 ())),
  92. new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Application.RequestStop())
  93. });
  94. top.Add (statusBar);
  95. var t1 = new Toplevel ();
  96. top.Add (t1);
  97. return top;
  98. }
  99. Toplevel Top2 ()
  100. {
  101. var top = new Toplevel (Application.Top.Frame);
  102. top.Text = "Top2";
  103. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  104. var menu = new MenuBar (new MenuBarItem [] {
  105. new MenuBarItem ("_Stage", new MenuItem [] {
  106. new MenuItem ("_Close", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.C)
  107. })
  108. });
  109. top.Add (menu);
  110. var statusBar = new StatusBar (new [] {
  111. new StatusItem(Key.CtrlMask | Key.C, "~^C~ Close", () => Application.RequestStop()),
  112. });
  113. top.Add (statusBar);
  114. win.Add (new ListView () {
  115. X = 0,
  116. Y = 0,
  117. Width = Dim.Fill (),
  118. Height = Dim.Fill ()
  119. });
  120. top.Add (win);
  121. return top;
  122. }
  123. }
  124. [Fact]
  125. [AutoInitShutdown]
  126. public void Internal_Tests ()
  127. {
  128. var top = new Toplevel ();
  129. var eventInvoked = "";
  130. top.ChildUnloaded += (e) => eventInvoked = "ChildUnloaded";
  131. top.OnChildUnloaded (top);
  132. Assert.Equal ("ChildUnloaded", eventInvoked);
  133. top.ChildLoaded += (e) => eventInvoked = "ChildLoaded";
  134. top.OnChildLoaded (top);
  135. Assert.Equal ("ChildLoaded", eventInvoked);
  136. top.Closed += (e) => eventInvoked = "Closed";
  137. top.OnClosed (top);
  138. Assert.Equal ("Closed", eventInvoked);
  139. top.Closing += (e) => eventInvoked = "Closing";
  140. top.OnClosing (new ToplevelClosingEventArgs (top));
  141. Assert.Equal ("Closing", eventInvoked);
  142. top.AllChildClosed += () => eventInvoked = "AllChildClosed";
  143. top.OnAllChildClosed ();
  144. Assert.Equal ("AllChildClosed", eventInvoked);
  145. top.ChildClosed += (e) => eventInvoked = "ChildClosed";
  146. top.OnChildClosed (top);
  147. Assert.Equal ("ChildClosed", eventInvoked);
  148. top.Deactivate += (e) => eventInvoked = "Deactivate";
  149. top.OnDeactivate (top);
  150. Assert.Equal ("Deactivate", eventInvoked);
  151. top.Activate += (e) => eventInvoked = "Activate";
  152. top.OnActivate (top);
  153. Assert.Equal ("Activate", eventInvoked);
  154. top.Loaded += () => eventInvoked = "Loaded";
  155. top.OnLoaded ();
  156. Assert.Equal ("Loaded", eventInvoked);
  157. top.Ready += () => eventInvoked = "Ready";
  158. top.OnReady ();
  159. Assert.Equal ("Ready", eventInvoked);
  160. top.Unloaded += () => eventInvoked = "Unloaded";
  161. top.OnUnloaded ();
  162. Assert.Equal ("Unloaded", eventInvoked);
  163. top.AddMenuStatusBar (new MenuBar ());
  164. Assert.NotNull (top.MenuBar);
  165. top.AddMenuStatusBar (new StatusBar ());
  166. Assert.NotNull (top.StatusBar);
  167. top.RemoveMenuStatusBar (top.MenuBar);
  168. Assert.Null (top.MenuBar);
  169. top.RemoveMenuStatusBar (top.StatusBar);
  170. Assert.Null (top.StatusBar);
  171. Application.Begin (top);
  172. Assert.Equal (top, Application.Top);
  173. // top is Application.Top without menu and status bar.
  174. var supView = top.EnsureVisibleBounds (top, 2, 2, out int nx, out int ny, out View mb, out View sb);
  175. Assert.Equal (Application.Top, supView);
  176. Assert.Equal (0, nx);
  177. Assert.Equal (0, ny);
  178. Assert.Null (mb);
  179. Assert.Null (sb);
  180. top.AddMenuStatusBar (new MenuBar ());
  181. Assert.NotNull (top.MenuBar);
  182. // top is Application.Top with a menu and without status bar.
  183. top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
  184. Assert.Equal (0, nx);
  185. Assert.Equal (1, ny);
  186. Assert.NotNull (mb);
  187. Assert.Null (sb);
  188. top.AddMenuStatusBar (new StatusBar ());
  189. Assert.NotNull (top.StatusBar);
  190. // top is Application.Top with a menu and status bar.
  191. top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
  192. Assert.Equal (0, nx);
  193. Assert.Equal (1, ny);
  194. Assert.NotNull (mb);
  195. Assert.NotNull (sb);
  196. top.RemoveMenuStatusBar (top.MenuBar);
  197. Assert.Null (top.MenuBar);
  198. // top is Application.Top without a menu and with a status bar.
  199. top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
  200. Assert.Equal (0, nx);
  201. Assert.Equal (0, ny);
  202. Assert.Null (mb);
  203. Assert.NotNull (sb);
  204. top.RemoveMenuStatusBar (top.StatusBar);
  205. Assert.Null (top.StatusBar);
  206. Assert.Null (top.MenuBar);
  207. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  208. top.Add (win);
  209. top.LayoutSubviews ();
  210. // The SuperView is always the same regardless of the caller.
  211. supView = top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  212. Assert.Equal (Application.Top, supView);
  213. supView = win.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  214. Assert.Equal (Application.Top, supView);
  215. // top is Application.Top without menu and status bar.
  216. top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  217. Assert.Equal (0, nx);
  218. Assert.Equal (0, ny);
  219. Assert.Null (mb);
  220. Assert.Null (sb);
  221. top.AddMenuStatusBar (new MenuBar ());
  222. Assert.NotNull (top.MenuBar);
  223. // top is Application.Top with a menu and without status bar.
  224. top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
  225. Assert.Equal (0, nx);
  226. Assert.Equal (1, ny);
  227. Assert.NotNull (mb);
  228. Assert.Null (sb);
  229. top.AddMenuStatusBar (new StatusBar ());
  230. Assert.NotNull (top.StatusBar);
  231. // top is Application.Top with a menu and status bar.
  232. top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
  233. Assert.Equal (0, nx);
  234. Assert.Equal (1, ny);
  235. Assert.NotNull (mb);
  236. Assert.NotNull (sb);
  237. top.RemoveMenuStatusBar (top.MenuBar);
  238. top.RemoveMenuStatusBar (top.StatusBar);
  239. Assert.Null (top.StatusBar);
  240. Assert.Null (top.MenuBar);
  241. top.Remove (win);
  242. win = new Window () { Width = 60, Height = 15 };
  243. top.Add (win);
  244. // top is Application.Top without menu and status bar.
  245. top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  246. Assert.Equal (0, nx);
  247. Assert.Equal (0, ny);
  248. Assert.Null (mb);
  249. Assert.Null (sb);
  250. top.AddMenuStatusBar (new MenuBar ());
  251. Assert.NotNull (top.MenuBar);
  252. // top is Application.Top with a menu and without status bar.
  253. top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
  254. Assert.Equal (2, nx);
  255. Assert.Equal (2, ny);
  256. Assert.NotNull (mb);
  257. Assert.Null (sb);
  258. top.AddMenuStatusBar (new StatusBar ());
  259. Assert.NotNull (top.StatusBar);
  260. // top is Application.Top with a menu and status bar.
  261. top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
  262. Assert.Equal (20, nx); // 20+60=80
  263. Assert.Equal (9, ny); // 9+15+1(mb)=25
  264. Assert.NotNull (mb);
  265. Assert.NotNull (sb);
  266. top.PositionToplevels ();
  267. Assert.Equal (new Rect (0, 1, 60, 15), win.Frame);
  268. Assert.Null (Toplevel.dragPosition);
  269. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
  270. Assert.Equal (new Point (6, 0), Toplevel.dragPosition);
  271. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Released });
  272. Assert.Null (Toplevel.dragPosition);
  273. win.CanFocus = false;
  274. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
  275. Assert.Null (Toplevel.dragPosition);
  276. }
  277. [Fact]
  278. [AutoInitShutdown]
  279. public void KeyBindings_Command ()
  280. {
  281. var isRunning = false;
  282. var win1 = new Window ("Win1") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  283. var lblTf1W1 = new Label ("Enter text in TextField on Win1:");
  284. var tf1W1 = new TextField ("Text1 on Win1") { X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill () };
  285. var lblTvW1 = new Label ("Enter text in TextView on Win1:") { Y = Pos.Bottom (lblTf1W1) + 1 };
  286. var tvW1 = new TextView () { X = Pos.Left (tf1W1), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win1" };
  287. var lblTf2W1 = new Label ("Enter text in TextField on Win1:") { Y = Pos.Bottom (lblTvW1) + 1 };
  288. var tf2W1 = new TextField ("Text2 on Win1") { X = Pos.Left (tf1W1), Width = Dim.Fill () };
  289. win1.Add (lblTf1W1, tf1W1, lblTvW1, tvW1, lblTf2W1, tf2W1);
  290. var win2 = new Window ("Win2") { X = Pos.Right (win1) + 1, Width = Dim.Percent (50f), Height = Dim.Fill () };
  291. var lblTf1W2 = new Label ("Enter text in TextField on Win2:");
  292. var tf1W2 = new TextField ("Text1 on Win2") { X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill () };
  293. var lblTvW2 = new Label ("Enter text in TextView on Win2:") { Y = Pos.Bottom (lblTf1W2) + 1 };
  294. var tvW2 = new TextView () { X = Pos.Left (tf1W2), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win2" };
  295. var lblTf2W2 = new Label ("Enter text in TextField on Win2:") { Y = Pos.Bottom (lblTvW2) + 1 };
  296. var tf2W2 = new TextField ("Text2 on Win2") { X = Pos.Left (tf1W2), Width = Dim.Fill () };
  297. win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2);
  298. var top = Application.Top;
  299. top.Add (win1, win2);
  300. top.Loaded += () => isRunning = true;
  301. top.Closing += (_) => isRunning = false;
  302. Application.Begin (top);
  303. top.Running = true;
  304. Assert.Equal (new Rect (0, 0, 40, 25), win1.Frame);
  305. Assert.Equal (new Rect (41, 0, 40, 25), win2.Frame);
  306. Assert.Equal (win1, top.Focused);
  307. Assert.Equal (tf1W1, top.MostFocused);
  308. Assert.True (isRunning);
  309. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.QuitKey, new KeyModifiers ())));
  310. Assert.False (isRunning);
  311. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  312. Assert.False (top.Focused.ProcessKey (new KeyEvent (Key.F5, new KeyModifiers ())));
  313. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  314. Assert.Equal (win1, top.Focused);
  315. Assert.Equal (tvW1, top.MostFocused);
  316. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  317. Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  318. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  319. Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  320. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  321. Assert.Equal (win1, top.Focused);
  322. Assert.Equal (tf2W1, top.MostFocused);
  323. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  324. Assert.Equal (win1, top.Focused);
  325. Assert.Equal (tf1W1, top.MostFocused);
  326. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  327. Assert.Equal (win1, top.Focused);
  328. Assert.Equal (tf1W1, top.MostFocused);
  329. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  330. Assert.Equal (win1, top.Focused);
  331. Assert.Equal (tvW1, top.MostFocused);
  332. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.I | Key.CtrlMask, new KeyModifiers ())));
  333. Assert.Equal (win1, top.Focused);
  334. Assert.Equal (tf2W1, top.MostFocused);
  335. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  336. Assert.Equal (win1, top.Focused);
  337. Assert.Equal (tvW1, top.MostFocused);
  338. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  339. Assert.Equal (win1, top.Focused);
  340. Assert.Equal (tf1W1, top.MostFocused);
  341. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  342. Assert.Equal (win1, top.Focused);
  343. Assert.Equal (tf2W1, top.MostFocused);
  344. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  345. Assert.Equal (win2, top.Focused);
  346. Assert.Equal (tf1W2, top.MostFocused);
  347. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  348. Assert.Equal (win1, top.Focused);
  349. Assert.Equal (tf2W1, top.MostFocused);
  350. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  351. Assert.Equal (win2, top.Focused);
  352. Assert.Equal (tf1W2, top.MostFocused);
  353. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  354. Assert.Equal (win1, top.Focused);
  355. Assert.Equal (tf2W1, top.MostFocused);
  356. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  357. Assert.Equal (win1, top.Focused);
  358. Assert.Equal (tvW1, top.MostFocused);
  359. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  360. Assert.Equal (win1, top.Focused);
  361. Assert.Equal (tf1W1, top.MostFocused);
  362. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  363. Assert.Equal (win1, top.Focused);
  364. Assert.Equal (tvW1, top.MostFocused);
  365. Assert.Equal (new Point (0, 0), tvW1.CursorPosition);
  366. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  367. Assert.Equal (win1, top.Focused);
  368. Assert.Equal (tvW1, top.MostFocused);
  369. Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
  370. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  371. Assert.Equal (win1, top.Focused);
  372. Assert.Equal (tf2W1, top.MostFocused);
  373. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.L | Key.CtrlMask, new KeyModifiers ())));
  374. }
  375. [Fact]
  376. [AutoInitShutdown]
  377. public void KeyBindings_Command_With_MdiTop ()
  378. {
  379. var top = Application.Top;
  380. Assert.Null (Application.MdiTop);
  381. top.IsMdiContainer = true;
  382. Application.Begin (top);
  383. Assert.Equal (Application.Top, Application.MdiTop);
  384. var isRunning = true;
  385. var win1 = new Window ("Win1") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  386. var lblTf1W1 = new Label ("Enter text in TextField on Win1:");
  387. var tf1W1 = new TextField ("Text1 on Win1") { X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill () };
  388. var lblTvW1 = new Label ("Enter text in TextView on Win1:") { Y = Pos.Bottom (lblTf1W1) + 1 };
  389. var tvW1 = new TextView () { X = Pos.Left (tf1W1), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win1" };
  390. var lblTf2W1 = new Label ("Enter text in TextField on Win1:") { Y = Pos.Bottom (lblTvW1) + 1 };
  391. var tf2W1 = new TextField ("Text2 on Win1") { X = Pos.Left (tf1W1), Width = Dim.Fill () };
  392. win1.Add (lblTf1W1, tf1W1, lblTvW1, tvW1, lblTf2W1, tf2W1);
  393. var win2 = new Window ("Win2") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  394. var lblTf1W2 = new Label ("Enter text in TextField on Win2:");
  395. var tf1W2 = new TextField ("Text1 on Win2") { X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill () };
  396. var lblTvW2 = new Label ("Enter text in TextView on Win2:") { Y = Pos.Bottom (lblTf1W2) + 1 };
  397. var tvW2 = new TextView () { X = Pos.Left (tf1W2), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win2" };
  398. var lblTf2W2 = new Label ("Enter text in TextField on Win2:") { Y = Pos.Bottom (lblTvW2) + 1 };
  399. var tf2W2 = new TextField ("Text2 on Win2") { X = Pos.Left (tf1W2), Width = Dim.Fill () };
  400. win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2);
  401. win1.Closing += (_) => isRunning = false;
  402. Assert.Null (top.Focused);
  403. Assert.Equal (top, Application.Current);
  404. Assert.True (top.IsCurrentTop);
  405. Assert.Equal (top, Application.MdiTop);
  406. Application.Begin (win1);
  407. Assert.Equal (new Rect (0, 0, 40, 25), win1.Frame);
  408. Assert.NotEqual (top, Application.Current);
  409. Assert.False (top.IsCurrentTop);
  410. Assert.Equal (win1, Application.Current);
  411. Assert.True (win1.IsCurrentTop);
  412. Assert.True (win1.IsMdiChild);
  413. Assert.Null (top.Focused);
  414. Assert.Null (top.MostFocused);
  415. Assert.Equal (win1.Subviews [0], win1.Focused);
  416. Assert.Equal (tf1W1, win1.MostFocused);
  417. Assert.True (win1.IsMdiChild);
  418. Assert.Single (Application.MdiChildes);
  419. Application.Begin (win2);
  420. Assert.Equal (new Rect (0, 0, 40, 25), win2.Frame);
  421. Assert.NotEqual (top, Application.Current);
  422. Assert.False (top.IsCurrentTop);
  423. Assert.Equal (win2, Application.Current);
  424. Assert.True (win2.IsCurrentTop);
  425. Assert.True (win2.IsMdiChild);
  426. Assert.Null (top.Focused);
  427. Assert.Null (top.MostFocused);
  428. Assert.Equal (win2.Subviews [0], win2.Focused);
  429. Assert.Equal (tf1W2, win2.MostFocused);
  430. Assert.Equal (2, Application.MdiChildes.Count);
  431. Application.ShowChild (win1);
  432. Assert.Equal (win1, Application.Current);
  433. Assert.Equal (win1, Application.MdiChildes [0]);
  434. win1.Running = true;
  435. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.QuitKey, new KeyModifiers ())));
  436. Assert.False (isRunning);
  437. Assert.False (win1.Running);
  438. Assert.Equal (win1, Application.MdiChildes [0]);
  439. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  440. Assert.False (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.F5, new KeyModifiers ())));
  441. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  442. Assert.True (win1.IsCurrentTop);
  443. Assert.Equal (tvW1, win1.MostFocused);
  444. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  445. Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  446. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  447. Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  448. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  449. Assert.Equal (win1, Application.MdiChildes [0]);
  450. Assert.Equal (tf2W1, win1.MostFocused);
  451. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  452. Assert.Equal (win1, Application.MdiChildes [0]);
  453. Assert.Equal (tf1W1, win1.MostFocused);
  454. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  455. Assert.Equal (win1, Application.MdiChildes [0]);
  456. Assert.Equal (tf1W1, win1.MostFocused);
  457. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  458. Assert.Equal (win1, Application.MdiChildes [0]);
  459. Assert.Equal (tvW1, win1.MostFocused);
  460. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.I | Key.CtrlMask, new KeyModifiers ())));
  461. Assert.Equal (win1, Application.MdiChildes [0]);
  462. Assert.Equal (tf2W1, win1.MostFocused);
  463. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  464. Assert.Equal (win1, Application.MdiChildes [0]);
  465. Assert.Equal (tvW1, win1.MostFocused);
  466. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  467. Assert.Equal (win1, Application.MdiChildes [0]);
  468. Assert.Equal (tf1W1, win1.MostFocused);
  469. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  470. Assert.Equal (win1, Application.MdiChildes [0]);
  471. Assert.Equal (tf2W1, win1.MostFocused);
  472. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  473. Assert.Equal (win1, Application.MdiChildes [0]);
  474. Assert.Equal (tf1W1, win1.MostFocused);
  475. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  476. Assert.Equal (win2, Application.MdiChildes [0]);
  477. Assert.Equal (tf1W2, win2.MostFocused);
  478. tf2W2.SetFocus ();
  479. Assert.True (tf2W2.HasFocus);
  480. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  481. Assert.Equal (win1, Application.MdiChildes [0]);
  482. Assert.Equal (tf1W1, win1.MostFocused);
  483. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  484. Assert.Equal (win2, Application.MdiChildes [0]);
  485. Assert.Equal (tf2W2, win2.MostFocused);
  486. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  487. Assert.Equal (win1, Application.MdiChildes [0]);
  488. Assert.Equal (tf1W1, win1.MostFocused);
  489. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  490. Assert.Equal (win1, Application.MdiChildes [0]);
  491. Assert.Equal (tvW1, win1.MostFocused);
  492. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  493. Assert.Equal (win1, Application.MdiChildes [0]);
  494. Assert.Equal (tf1W1, win1.MostFocused);
  495. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  496. Assert.Equal (win1, Application.MdiChildes [0]);
  497. Assert.Equal (tvW1, win1.MostFocused);
  498. Assert.Equal (new Point (0, 0), tvW1.CursorPosition);
  499. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  500. Assert.Equal (win1, Application.MdiChildes [0]);
  501. Assert.Equal (tvW1, win1.MostFocused);
  502. Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
  503. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  504. Assert.Equal (win1, Application.MdiChildes [0]);
  505. Assert.Equal (tf2W1, win1.MostFocused);
  506. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.L | Key.CtrlMask, new KeyModifiers ())));
  507. }
  508. [Fact]
  509. public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events ()
  510. {
  511. Key alternateForwardKey = default;
  512. Key alternateBackwardKey = default;
  513. Key quitKey = default;
  514. var wasAdded = false;
  515. var view = new View ();
  516. view.Added += View_Added;
  517. void View_Added (View obj)
  518. {
  519. Assert.Throws<NullReferenceException> (() => Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e);
  520. Assert.Throws<NullReferenceException> (() => Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e);
  521. Assert.Throws<NullReferenceException> (() => Application.Top.QuitKeyChanged += (e) => quitKey = e);
  522. Assert.False (wasAdded);
  523. wasAdded = true;
  524. view.Added -= View_Added;
  525. }
  526. var win = new Window ();
  527. win.Add (view);
  528. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  529. var top = Application.Top;
  530. top.Add (win);
  531. Assert.True (wasAdded);
  532. Application.Shutdown ();
  533. }
  534. [Fact]
  535. [AutoInitShutdown]
  536. public void AlternateForwardKeyChanged_AlternateBackwardKeyChanged_QuitKeyChanged_Events ()
  537. {
  538. Key alternateForwardKey = default;
  539. Key alternateBackwardKey = default;
  540. Key quitKey = default;
  541. var view = new View ();
  542. view.Initialized += View_Initialized;
  543. void View_Initialized (object sender, EventArgs e)
  544. {
  545. Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e;
  546. Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e;
  547. Application.Top.QuitKeyChanged += (e) => quitKey = e;
  548. }
  549. var win = new Window ();
  550. win.Add (view);
  551. var top = Application.Top;
  552. top.Add (win);
  553. Application.Begin (top);
  554. Assert.Equal (Key.Null, alternateForwardKey);
  555. Assert.Equal (Key.Null, alternateBackwardKey);
  556. Assert.Equal (Key.Null, quitKey);
  557. Assert.Equal (Key.PageDown | Key.CtrlMask, Application.AlternateForwardKey);
  558. Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
  559. Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
  560. Application.AlternateForwardKey = Key.A;
  561. Application.AlternateBackwardKey = Key.B;
  562. Application.QuitKey = Key.C;
  563. Assert.Equal (Key.PageDown | Key.CtrlMask, alternateForwardKey);
  564. Assert.Equal (Key.PageUp | Key.CtrlMask, alternateBackwardKey);
  565. Assert.Equal (Key.Q | Key.CtrlMask, quitKey);
  566. Assert.Equal (Key.A, Application.AlternateForwardKey);
  567. Assert.Equal (Key.B, Application.AlternateBackwardKey);
  568. Assert.Equal (Key.C, Application.QuitKey);
  569. // Replacing the defaults keys to avoid errors on others unit tests that are using it.
  570. Application.AlternateForwardKey = Key.PageDown | Key.CtrlMask;
  571. Application.AlternateBackwardKey = Key.PageUp | Key.CtrlMask;
  572. Application.QuitKey = Key.Q | Key.CtrlMask;
  573. Assert.Equal (Key.PageDown | Key.CtrlMask, Application.AlternateForwardKey);
  574. Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
  575. Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
  576. }
  577. [Fact]
  578. [AutoInitShutdown]
  579. public void FileDialog_FileSystemWatcher ()
  580. {
  581. for (int i = 0; i < 256; i++) {
  582. var fd = new FileDialog ();
  583. fd.Ready += () => Application.RequestStop ();
  584. Application.Run (fd);
  585. }
  586. }
  587. [Fact, AutoInitShutdown]
  588. public void Mouse_Drag_On_Top_With_Superview_Null ()
  589. {
  590. var menu = new MenuBar (new MenuBarItem [] {
  591. new MenuBarItem("File", new MenuItem [] {
  592. new MenuItem("New", "", null)
  593. })
  594. });
  595. var sbar = new StatusBar (new StatusItem [] {
  596. new StatusItem(Key.N, "~CTRL-N~ New", null)
  597. });
  598. var win = new Window ("Window");
  599. var top = Application.Top;
  600. top.Add (menu, sbar, win);
  601. var iterations = -1;
  602. Application.Iteration = () => {
  603. iterations++;
  604. if (iterations == 0) {
  605. ((FakeDriver)Application.Driver).SetBufferSize (40, 15);
  606. MessageBox.Query ("About", "Hello Word", "Ok");
  607. } else if (iterations == 1) {
  608. TestHelpers.AssertDriverContentsWithFrameAre (@"
  609. File
  610. ┌ Window ──────────────────────────────┐
  611. │ │
  612. │ │
  613. │ │
  614. │ ┌ About ───────────────┐ │
  615. │ │ Hello Word │ │
  616. │ │ │ │
  617. │ │ [◦ Ok ◦] │ │
  618. │ └──────────────────────┘ │
  619. │ │
  620. │ │
  621. │ │
  622. └──────────────────────────────────────┘
  623. CTRL-N New ", output);
  624. } else if (iterations == 2) {
  625. Assert.Null (Application.MouseGrabView);
  626. // Grab the mouse
  627. ReflectionTools.InvokePrivate (
  628. typeof (Application),
  629. "ProcessMouseEvent",
  630. new MouseEvent () {
  631. X = 8,
  632. Y = 5,
  633. Flags = MouseFlags.Button1Pressed
  634. });
  635. Assert.Equal (Application.Current, Application.MouseGrabView);
  636. Assert.Equal (new Rect (8, 5, 24, 5), Application.MouseGrabView.Frame);
  637. } else if (iterations == 3) {
  638. Assert.Equal (Application.Current, Application.MouseGrabView);
  639. // Grab to left
  640. ReflectionTools.InvokePrivate (
  641. typeof (Application),
  642. "ProcessMouseEvent",
  643. new MouseEvent () {
  644. X = 7,
  645. Y = 5,
  646. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  647. });
  648. Assert.Equal (Application.Current, Application.MouseGrabView);
  649. Assert.Equal (new Rect (7, 5, 24, 5), Application.MouseGrabView.Frame);
  650. } else if (iterations == 4) {
  651. Assert.Equal (Application.Current, Application.MouseGrabView);
  652. TestHelpers.AssertDriverContentsWithFrameAre (@"
  653. File
  654. ┌ Window ──────────────────────────────┐
  655. │ │
  656. │ │
  657. │ │
  658. │ ┌ About ───────────────┐ │
  659. │ │ Hello Word │ │
  660. │ │ │ │
  661. │ │ [◦ Ok ◦] │ │
  662. │ └──────────────────────┘ │
  663. │ │
  664. │ │
  665. │ │
  666. └──────────────────────────────────────┘
  667. CTRL-N New ", output);
  668. Assert.Equal (Application.Current, Application.MouseGrabView);
  669. } else if (iterations == 5) {
  670. Assert.Equal (Application.Current, Application.MouseGrabView);
  671. // Grab to top
  672. ReflectionTools.InvokePrivate (
  673. typeof (Application),
  674. "ProcessMouseEvent",
  675. new MouseEvent () {
  676. X = 7,
  677. Y = 4,
  678. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  679. });
  680. Assert.Equal (Application.Current, Application.MouseGrabView);
  681. Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame);
  682. } else if (iterations == 6) {
  683. Assert.Equal (Application.Current, Application.MouseGrabView);
  684. TestHelpers.AssertDriverContentsWithFrameAre (@"
  685. File
  686. ┌ Window ──────────────────────────────┐
  687. │ │
  688. │ │
  689. │ ┌ About ───────────────┐ │
  690. │ │ Hello Word │ │
  691. │ │ │ │
  692. │ │ [◦ Ok ◦] │ │
  693. │ └──────────────────────┘ │
  694. │ │
  695. │ │
  696. │ │
  697. │ │
  698. └──────────────────────────────────────┘
  699. CTRL-N New ", output);
  700. Assert.Equal (Application.Current, Application.MouseGrabView);
  701. Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame);
  702. } else if (iterations == 7) {
  703. Assert.Equal (Application.Current, Application.MouseGrabView);
  704. // Ungrab the mouse
  705. ReflectionTools.InvokePrivate (
  706. typeof (Application),
  707. "ProcessMouseEvent",
  708. new MouseEvent () {
  709. X = 7,
  710. Y = 4,
  711. Flags = MouseFlags.Button1Released
  712. });
  713. Assert.Null (Application.MouseGrabView);
  714. } else if (iterations == 8) {
  715. Application.RequestStop ();
  716. } else if (iterations == 9) {
  717. Application.RequestStop ();
  718. }
  719. };
  720. Application.Run ();
  721. }
  722. [Fact, AutoInitShutdown]
  723. public void Mouse_Drag_On_Top_With_Superview_Not_Null ()
  724. {
  725. var menu = new MenuBar (new MenuBarItem [] {
  726. new MenuBarItem("File", new MenuItem [] {
  727. new MenuItem("New", "", null)
  728. })
  729. });
  730. var sbar = new StatusBar (new StatusItem [] {
  731. new StatusItem(Key.N, "~CTRL-N~ New", null)
  732. });
  733. var win = new Window ("Window") {
  734. X = 3,
  735. Y = 2,
  736. Width = Dim.Fill (10),
  737. Height = Dim.Fill (5)
  738. };
  739. var top = Application.Top;
  740. top.Add (menu, sbar, win);
  741. var iterations = -1;
  742. Application.Iteration = () => {
  743. iterations++;
  744. if (iterations == 0) {
  745. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  746. Assert.Null (Application.MouseGrabView);
  747. // Grab the mouse
  748. ReflectionTools.InvokePrivate (
  749. typeof (Application),
  750. "ProcessMouseEvent",
  751. new MouseEvent () {
  752. X = 4,
  753. Y = 2,
  754. Flags = MouseFlags.Button1Pressed
  755. });
  756. Assert.Equal (win, Application.MouseGrabView);
  757. Assert.Equal (new Rect (3, 2, 7, 3), Application.MouseGrabView.Frame);
  758. TestHelpers.AssertDriverContentsWithFrameAre (@"
  759. File
  760. ┌─────┐
  761. │ │
  762. └─────┘
  763. CTRL-N New", output);
  764. } else if (iterations == 1) {
  765. Assert.Equal (win, Application.MouseGrabView);
  766. // Grab to left
  767. ReflectionTools.InvokePrivate (
  768. typeof (Application),
  769. "ProcessMouseEvent",
  770. new MouseEvent () {
  771. X = 5,
  772. Y = 2,
  773. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  774. });
  775. Assert.Equal (win, Application.MouseGrabView);
  776. } else if (iterations == 2) {
  777. Assert.Equal (win, Application.MouseGrabView);
  778. TestHelpers.AssertDriverContentsWithFrameAre (@"
  779. File
  780. ┌────┐
  781. │ │
  782. └────┘
  783. CTRL-N New", output);
  784. Assert.Equal (win, Application.MouseGrabView);
  785. Assert.Equal (new Rect (4, 2, 6, 3), Application.MouseGrabView.Frame);
  786. } else if (iterations == 3) {
  787. Assert.Equal (win, Application.MouseGrabView);
  788. // Grab to top
  789. ReflectionTools.InvokePrivate (
  790. typeof (Application),
  791. "ProcessMouseEvent",
  792. new MouseEvent () {
  793. X = 5,
  794. Y = 1,
  795. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  796. });
  797. Assert.Equal (win, Application.MouseGrabView);
  798. } else if (iterations == 4) {
  799. Assert.Equal (win, Application.MouseGrabView);
  800. TestHelpers.AssertDriverContentsWithFrameAre (@"
  801. File
  802. ┌────┐
  803. │ │
  804. │ │
  805. └────┘
  806. CTRL-N New", output);
  807. Assert.Equal (win, Application.MouseGrabView);
  808. Assert.Equal (new Rect (4, 1, 6, 4), Application.MouseGrabView.Frame);
  809. } else if (iterations == 5) {
  810. Assert.Equal (win, Application.MouseGrabView);
  811. // Ungrab the mouse
  812. ReflectionTools.InvokePrivate (
  813. typeof (Application),
  814. "ProcessMouseEvent",
  815. new MouseEvent () {
  816. X = 7,
  817. Y = 4,
  818. Flags = MouseFlags.Button1Released
  819. });
  820. Assert.Null (Application.MouseGrabView);
  821. } else if (iterations == 8) {
  822. Application.RequestStop ();
  823. }
  824. };
  825. Application.Run ();
  826. }
  827. }
  828. }