ToplevelTests.cs 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017
  1. using System;
  2. using Xunit;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.TopLevelTests {
  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. // top is Application.Top and doesn't need to positioned itself.
  186. Assert.Equal (0, ny);
  187. Assert.NotNull (mb);
  188. Assert.Null (sb);
  189. top.AddMenuStatusBar (new StatusBar ());
  190. Assert.NotNull (top.StatusBar);
  191. // top is Application.Top with a menu and status bar.
  192. top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
  193. Assert.Equal (0, nx);
  194. // top is Application.Top and doesn't need to positioned itself.
  195. Assert.Equal (0, ny);
  196. Assert.NotNull (mb);
  197. Assert.NotNull (sb);
  198. top.RemoveMenuStatusBar (top.MenuBar);
  199. Assert.Null (top.MenuBar);
  200. // top is Application.Top without a menu and with a status bar.
  201. top.EnsureVisibleBounds (top, 2, 2, out nx, out ny, out mb, out sb);
  202. Assert.Equal (0, nx);
  203. // top is Application.Top and doesn't need to positioned itself.
  204. Assert.Equal (0, ny);
  205. Assert.Null (mb);
  206. Assert.NotNull (sb);
  207. top.RemoveMenuStatusBar (top.StatusBar);
  208. Assert.Null (top.StatusBar);
  209. Assert.Null (top.MenuBar);
  210. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  211. top.Add (win);
  212. top.LayoutSubviews ();
  213. // The SuperView is always the same regardless of the caller.
  214. supView = top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  215. Assert.Equal (Application.Top, supView);
  216. supView = win.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  217. Assert.Equal (Application.Top, supView);
  218. // top is Application.Top without menu and status bar.
  219. top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  220. Assert.Equal (0, nx);
  221. Assert.Equal (0, ny);
  222. Assert.Null (mb);
  223. Assert.Null (sb);
  224. top.AddMenuStatusBar (new MenuBar ());
  225. Assert.NotNull (top.MenuBar);
  226. // top is Application.Top with a menu and without status bar.
  227. top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
  228. Assert.Equal (0, nx);
  229. Assert.Equal (1, ny);
  230. Assert.NotNull (mb);
  231. Assert.Null (sb);
  232. top.AddMenuStatusBar (new StatusBar ());
  233. Assert.NotNull (top.StatusBar);
  234. // top is Application.Top with a menu and status bar.
  235. top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
  236. Assert.Equal (0, nx);
  237. Assert.Equal (1, ny);
  238. Assert.NotNull (mb);
  239. Assert.NotNull (sb);
  240. top.RemoveMenuStatusBar (top.MenuBar);
  241. top.RemoveMenuStatusBar (top.StatusBar);
  242. Assert.Null (top.StatusBar);
  243. Assert.Null (top.MenuBar);
  244. top.Remove (win);
  245. win = new Window () { Width = 60, Height = 15 };
  246. top.Add (win);
  247. // top is Application.Top without menu and status bar.
  248. top.EnsureVisibleBounds (win, 0, 0, out nx, out ny, out mb, out sb);
  249. Assert.Equal (0, nx);
  250. Assert.Equal (0, ny);
  251. Assert.Null (mb);
  252. Assert.Null (sb);
  253. top.AddMenuStatusBar (new MenuBar ());
  254. Assert.NotNull (top.MenuBar);
  255. // top is Application.Top with a menu and without status bar.
  256. top.EnsureVisibleBounds (win, 2, 2, out nx, out ny, out mb, out sb);
  257. Assert.Equal (2, nx);
  258. Assert.Equal (2, ny);
  259. Assert.NotNull (mb);
  260. Assert.Null (sb);
  261. top.AddMenuStatusBar (new StatusBar ());
  262. Assert.NotNull (top.StatusBar);
  263. // top is Application.Top with a menu and status bar.
  264. top.EnsureVisibleBounds (win, 30, 20, out nx, out ny, out mb, out sb);
  265. Assert.Equal (20, nx); // 20+60=80
  266. Assert.Equal (9, ny); // 9+15+1(mb)=25
  267. Assert.NotNull (mb);
  268. Assert.NotNull (sb);
  269. top.PositionToplevels ();
  270. Assert.Equal (new Rect (0, 1, 60, 15), win.Frame);
  271. Assert.Null (Toplevel.dragPosition);
  272. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
  273. Assert.Equal (new Point (6, 0), Toplevel.dragPosition);
  274. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Released });
  275. Assert.Null (Toplevel.dragPosition);
  276. win.CanFocus = false;
  277. win.MouseEvent (new MouseEvent () { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed });
  278. Assert.Null (Toplevel.dragPosition);
  279. }
  280. [Fact]
  281. [AutoInitShutdown]
  282. public void KeyBindings_Command ()
  283. {
  284. var isRunning = false;
  285. var win1 = new Window ("Win1") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  286. var lblTf1W1 = new Label ("Enter text in TextField on Win1:");
  287. var tf1W1 = new TextField ("Text1 on Win1") { X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill () };
  288. var lblTvW1 = new Label ("Enter text in TextView on Win1:") { Y = Pos.Bottom (lblTf1W1) + 1 };
  289. var tvW1 = new TextView () { X = Pos.Left (tf1W1), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win1" };
  290. var lblTf2W1 = new Label ("Enter text in TextField on Win1:") { Y = Pos.Bottom (lblTvW1) + 1 };
  291. var tf2W1 = new TextField ("Text2 on Win1") { X = Pos.Left (tf1W1), Width = Dim.Fill () };
  292. win1.Add (lblTf1W1, tf1W1, lblTvW1, tvW1, lblTf2W1, tf2W1);
  293. var win2 = new Window ("Win2") { X = Pos.Right (win1) + 1, Width = Dim.Percent (50f), Height = Dim.Fill () };
  294. var lblTf1W2 = new Label ("Enter text in TextField on Win2:");
  295. var tf1W2 = new TextField ("Text1 on Win2") { X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill () };
  296. var lblTvW2 = new Label ("Enter text in TextView on Win2:") { Y = Pos.Bottom (lblTf1W2) + 1 };
  297. var tvW2 = new TextView () { X = Pos.Left (tf1W2), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win2" };
  298. var lblTf2W2 = new Label ("Enter text in TextField on Win2:") { Y = Pos.Bottom (lblTvW2) + 1 };
  299. var tf2W2 = new TextField ("Text2 on Win2") { X = Pos.Left (tf1W2), Width = Dim.Fill () };
  300. win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2);
  301. var top = Application.Top;
  302. top.Add (win1, win2);
  303. top.Loaded += () => isRunning = true;
  304. top.Closing += (_) => isRunning = false;
  305. Application.Begin (top);
  306. top.Running = true;
  307. Assert.Equal (new Rect (0, 0, 40, 25), win1.Frame);
  308. Assert.Equal (new Rect (41, 0, 40, 25), win2.Frame);
  309. Assert.Equal (win1, top.Focused);
  310. Assert.Equal (tf1W1, top.MostFocused);
  311. Assert.True (isRunning);
  312. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.QuitKey, new KeyModifiers ())));
  313. Assert.False (isRunning);
  314. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  315. Assert.False (top.Focused.ProcessKey (new KeyEvent (Key.F5, new KeyModifiers ())));
  316. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  317. Assert.Equal (win1, top.Focused);
  318. Assert.Equal (tvW1, top.MostFocused);
  319. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  320. Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  321. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  322. Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  323. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  324. Assert.Equal (win1, top.Focused);
  325. Assert.Equal (tf2W1, top.MostFocused);
  326. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  327. Assert.Equal (win1, top.Focused);
  328. Assert.Equal (tf1W1, top.MostFocused);
  329. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  330. Assert.Equal (win1, top.Focused);
  331. Assert.Equal (tf1W1, top.MostFocused);
  332. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  333. Assert.Equal (win1, top.Focused);
  334. Assert.Equal (tvW1, top.MostFocused);
  335. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.I | Key.CtrlMask, new KeyModifiers ())));
  336. Assert.Equal (win1, top.Focused);
  337. Assert.Equal (tf2W1, top.MostFocused);
  338. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  339. Assert.Equal (win1, top.Focused);
  340. Assert.Equal (tvW1, top.MostFocused);
  341. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  342. Assert.Equal (win1, top.Focused);
  343. Assert.Equal (tf1W1, top.MostFocused);
  344. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  345. Assert.Equal (win1, top.Focused);
  346. Assert.Equal (tf2W1, top.MostFocused);
  347. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  348. Assert.Equal (win2, top.Focused);
  349. Assert.Equal (tf1W2, top.MostFocused);
  350. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  351. Assert.Equal (win1, top.Focused);
  352. Assert.Equal (tf2W1, top.MostFocused);
  353. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  354. Assert.Equal (win2, top.Focused);
  355. Assert.Equal (tf1W2, top.MostFocused);
  356. Assert.True (top.Focused.ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  357. Assert.Equal (win1, top.Focused);
  358. Assert.Equal (tf2W1, top.MostFocused);
  359. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  360. Assert.Equal (win1, top.Focused);
  361. Assert.Equal (tvW1, top.MostFocused);
  362. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  363. Assert.Equal (win1, top.Focused);
  364. Assert.Equal (tf1W1, top.MostFocused);
  365. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  366. Assert.Equal (win1, top.Focused);
  367. Assert.Equal (tvW1, top.MostFocused);
  368. Assert.Equal (new Point (0, 0), tvW1.CursorPosition);
  369. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  370. Assert.Equal (win1, top.Focused);
  371. Assert.Equal (tvW1, top.MostFocused);
  372. Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
  373. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  374. Assert.Equal (win1, top.Focused);
  375. Assert.Equal (tf2W1, top.MostFocused);
  376. Assert.True (top.Focused.ProcessKey (new KeyEvent (Key.L | Key.CtrlMask, new KeyModifiers ())));
  377. }
  378. [Fact]
  379. [AutoInitShutdown]
  380. public void KeyBindings_Command_With_MdiTop ()
  381. {
  382. var top = Application.Top;
  383. Assert.Null (Application.MdiTop);
  384. top.IsMdiContainer = true;
  385. Application.Begin (top);
  386. Assert.Equal (Application.Top, Application.MdiTop);
  387. var isRunning = true;
  388. var win1 = new Window ("Win1") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  389. var lblTf1W1 = new Label ("Enter text in TextField on Win1:");
  390. var tf1W1 = new TextField ("Text1 on Win1") { X = Pos.Right (lblTf1W1) + 1, Width = Dim.Fill () };
  391. var lblTvW1 = new Label ("Enter text in TextView on Win1:") { Y = Pos.Bottom (lblTf1W1) + 1 };
  392. var tvW1 = new TextView () { X = Pos.Left (tf1W1), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win1" };
  393. var lblTf2W1 = new Label ("Enter text in TextField on Win1:") { Y = Pos.Bottom (lblTvW1) + 1 };
  394. var tf2W1 = new TextField ("Text2 on Win1") { X = Pos.Left (tf1W1), Width = Dim.Fill () };
  395. win1.Add (lblTf1W1, tf1W1, lblTvW1, tvW1, lblTf2W1, tf2W1);
  396. var win2 = new Window ("Win2") { Width = Dim.Percent (50f), Height = Dim.Fill () };
  397. var lblTf1W2 = new Label ("Enter text in TextField on Win2:");
  398. var tf1W2 = new TextField ("Text1 on Win2") { X = Pos.Right (lblTf1W2) + 1, Width = Dim.Fill () };
  399. var lblTvW2 = new Label ("Enter text in TextView on Win2:") { Y = Pos.Bottom (lblTf1W2) + 1 };
  400. var tvW2 = new TextView () { X = Pos.Left (tf1W2), Width = Dim.Fill (), Height = 2, Text = "First line Win1\nSecond line Win2" };
  401. var lblTf2W2 = new Label ("Enter text in TextField on Win2:") { Y = Pos.Bottom (lblTvW2) + 1 };
  402. var tf2W2 = new TextField ("Text2 on Win2") { X = Pos.Left (tf1W2), Width = Dim.Fill () };
  403. win2.Add (lblTf1W2, tf1W2, lblTvW2, tvW2, lblTf2W2, tf2W2);
  404. win1.Closing += (_) => isRunning = false;
  405. Assert.Null (top.Focused);
  406. Assert.Equal (top, Application.Current);
  407. Assert.True (top.IsCurrentTop);
  408. Assert.Equal (top, Application.MdiTop);
  409. Application.Begin (win1);
  410. Assert.Equal (new Rect (0, 0, 40, 25), win1.Frame);
  411. Assert.NotEqual (top, Application.Current);
  412. Assert.False (top.IsCurrentTop);
  413. Assert.Equal (win1, Application.Current);
  414. Assert.True (win1.IsCurrentTop);
  415. Assert.True (win1.IsMdiChild);
  416. Assert.Null (top.Focused);
  417. Assert.Null (top.MostFocused);
  418. Assert.Equal (win1.Subviews [0], win1.Focused);
  419. Assert.Equal (tf1W1, win1.MostFocused);
  420. Assert.True (win1.IsMdiChild);
  421. Assert.Single (Application.MdiChildes);
  422. Application.Begin (win2);
  423. Assert.Equal (new Rect (0, 0, 40, 25), win2.Frame);
  424. Assert.NotEqual (top, Application.Current);
  425. Assert.False (top.IsCurrentTop);
  426. Assert.Equal (win2, Application.Current);
  427. Assert.True (win2.IsCurrentTop);
  428. Assert.True (win2.IsMdiChild);
  429. Assert.Null (top.Focused);
  430. Assert.Null (top.MostFocused);
  431. Assert.Equal (win2.Subviews [0], win2.Focused);
  432. Assert.Equal (tf1W2, win2.MostFocused);
  433. Assert.Equal (2, Application.MdiChildes.Count);
  434. Application.ShowChild (win1);
  435. Assert.Equal (win1, Application.Current);
  436. Assert.Equal (win1, Application.MdiChildes [0]);
  437. win1.Running = true;
  438. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.QuitKey, new KeyModifiers ())));
  439. Assert.False (isRunning);
  440. Assert.False (win1.Running);
  441. Assert.Equal (win1, Application.MdiChildes [0]);
  442. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
  443. Assert.False (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.F5, new KeyModifiers ())));
  444. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  445. Assert.True (win1.IsCurrentTop);
  446. Assert.Equal (tvW1, win1.MostFocused);
  447. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  448. Assert.Equal ($"\tFirst line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  449. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  450. Assert.Equal ($"First line Win1{Environment.NewLine}Second line Win1", tvW1.Text);
  451. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  452. Assert.Equal (win1, Application.MdiChildes [0]);
  453. Assert.Equal (tf2W1, win1.MostFocused);
  454. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, 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.CursorRight, new KeyModifiers ())));
  458. Assert.Equal (win1, Application.MdiChildes [0]);
  459. Assert.Equal (tf1W1, win1.MostFocused);
  460. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  461. Assert.Equal (win1, Application.MdiChildes [0]);
  462. Assert.Equal (tvW1, win1.MostFocused);
  463. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.I | Key.CtrlMask, new KeyModifiers ())));
  464. Assert.Equal (win1, Application.MdiChildes [0]);
  465. Assert.Equal (tf2W1, win1.MostFocused);
  466. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ())));
  467. Assert.Equal (win1, Application.MdiChildes [0]);
  468. Assert.Equal (tvW1, win1.MostFocused);
  469. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
  470. Assert.Equal (win1, Application.MdiChildes [0]);
  471. Assert.Equal (tf1W1, win1.MostFocused);
  472. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
  473. Assert.Equal (win1, Application.MdiChildes [0]);
  474. Assert.Equal (tf2W1, win1.MostFocused);
  475. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
  476. Assert.Equal (win1, Application.MdiChildes [0]);
  477. Assert.Equal (tf1W1, win1.MostFocused);
  478. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask, new KeyModifiers ())));
  479. Assert.Equal (win2, Application.MdiChildes [0]);
  480. Assert.Equal (tf1W2, win2.MostFocused);
  481. tf2W2.SetFocus ();
  482. Assert.True (tf2W2.HasFocus);
  483. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.Tab | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ())));
  484. Assert.Equal (win1, Application.MdiChildes [0]);
  485. Assert.Equal (tf1W1, win1.MostFocused);
  486. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.AlternateForwardKey, new KeyModifiers ())));
  487. Assert.Equal (win2, Application.MdiChildes [0]);
  488. Assert.Equal (tf2W2, win2.MostFocused);
  489. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Application.AlternateBackwardKey, new KeyModifiers ())));
  490. Assert.Equal (win1, Application.MdiChildes [0]);
  491. Assert.Equal (tf1W1, win1.MostFocused);
  492. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  493. Assert.Equal (win1, Application.MdiChildes [0]);
  494. Assert.Equal (tvW1, win1.MostFocused);
  495. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.B | Key.CtrlMask, new KeyModifiers ())));
  496. Assert.Equal (win1, Application.MdiChildes [0]);
  497. Assert.Equal (tf1W1, win1.MostFocused);
  498. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  499. Assert.Equal (win1, Application.MdiChildes [0]);
  500. Assert.Equal (tvW1, win1.MostFocused);
  501. Assert.Equal (new Point (0, 0), tvW1.CursorPosition);
  502. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
  503. Assert.Equal (win1, Application.MdiChildes [0]);
  504. Assert.Equal (tvW1, win1.MostFocused);
  505. Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
  506. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
  507. Assert.Equal (win1, Application.MdiChildes [0]);
  508. Assert.Equal (tf2W1, win1.MostFocused);
  509. Assert.True (Application.MdiChildes [0].ProcessKey (new KeyEvent (Key.L | Key.CtrlMask, new KeyModifiers ())));
  510. }
  511. [Fact]
  512. public void Added_Event_Should_Not_Be_Used_To_Initialize_Toplevel_Events ()
  513. {
  514. Key alternateForwardKey = default;
  515. Key alternateBackwardKey = default;
  516. Key quitKey = default;
  517. var wasAdded = false;
  518. var view = new View ();
  519. view.Added += View_Added;
  520. void View_Added (View obj)
  521. {
  522. Assert.Throws<NullReferenceException> (() => Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e);
  523. Assert.Throws<NullReferenceException> (() => Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e);
  524. Assert.Throws<NullReferenceException> (() => Application.Top.QuitKeyChanged += (e) => quitKey = e);
  525. Assert.False (wasAdded);
  526. wasAdded = true;
  527. view.Added -= View_Added;
  528. }
  529. var win = new Window ();
  530. win.Add (view);
  531. Application.Init (new FakeDriver ());
  532. var top = Application.Top;
  533. top.Add (win);
  534. Assert.True (wasAdded);
  535. Application.Shutdown ();
  536. }
  537. [Fact]
  538. [AutoInitShutdown]
  539. public void AlternateForwardKeyChanged_AlternateBackwardKeyChanged_QuitKeyChanged_Events ()
  540. {
  541. Key alternateForwardKey = default;
  542. Key alternateBackwardKey = default;
  543. Key quitKey = default;
  544. var view = new View ();
  545. view.Initialized += View_Initialized;
  546. void View_Initialized (object sender, EventArgs e)
  547. {
  548. Application.Top.AlternateForwardKeyChanged += (e) => alternateForwardKey = e;
  549. Application.Top.AlternateBackwardKeyChanged += (e) => alternateBackwardKey = e;
  550. Application.Top.QuitKeyChanged += (e) => quitKey = e;
  551. }
  552. var win = new Window ();
  553. win.Add (view);
  554. var top = Application.Top;
  555. top.Add (win);
  556. Application.Begin (top);
  557. Assert.Equal (Key.Null, alternateForwardKey);
  558. Assert.Equal (Key.Null, alternateBackwardKey);
  559. Assert.Equal (Key.Null, quitKey);
  560. Assert.Equal (Key.PageDown | Key.CtrlMask, Application.AlternateForwardKey);
  561. Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
  562. Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
  563. Application.AlternateForwardKey = Key.A;
  564. Application.AlternateBackwardKey = Key.B;
  565. Application.QuitKey = Key.C;
  566. Assert.Equal (Key.PageDown | Key.CtrlMask, alternateForwardKey);
  567. Assert.Equal (Key.PageUp | Key.CtrlMask, alternateBackwardKey);
  568. Assert.Equal (Key.Q | Key.CtrlMask, quitKey);
  569. Assert.Equal (Key.A, Application.AlternateForwardKey);
  570. Assert.Equal (Key.B, Application.AlternateBackwardKey);
  571. Assert.Equal (Key.C, Application.QuitKey);
  572. // Replacing the defaults keys to avoid errors on others unit tests that are using it.
  573. Application.AlternateForwardKey = Key.PageDown | Key.CtrlMask;
  574. Application.AlternateBackwardKey = Key.PageUp | Key.CtrlMask;
  575. Application.QuitKey = Key.Q | Key.CtrlMask;
  576. Assert.Equal (Key.PageDown | Key.CtrlMask, Application.AlternateForwardKey);
  577. Assert.Equal (Key.PageUp | Key.CtrlMask, Application.AlternateBackwardKey);
  578. Assert.Equal (Key.Q | Key.CtrlMask, Application.QuitKey);
  579. }
  580. [Fact]
  581. [AutoInitShutdown]
  582. public void FileDialog_FileSystemWatcher ()
  583. {
  584. for (int i = 0; i < 8; i++) {
  585. var fd = new FileDialog ();
  586. fd.Ready += () => Application.RequestStop ();
  587. Application.Run (fd);
  588. }
  589. }
  590. [Fact, AutoInitShutdown]
  591. public void Mouse_Drag_On_Top_With_Superview_Null ()
  592. {
  593. var menu = new MenuBar (new MenuBarItem [] {
  594. new MenuBarItem("File", new MenuItem [] {
  595. new MenuItem("New", "", null)
  596. })
  597. });
  598. var sbar = new StatusBar (new StatusItem [] {
  599. new StatusItem(Key.N, "~CTRL-N~ New", null)
  600. });
  601. var win = new Window ("Window");
  602. var top = Application.Top;
  603. top.Add (menu, sbar, win);
  604. var iterations = -1;
  605. Application.Iteration = () => {
  606. iterations++;
  607. if (iterations == 0) {
  608. ((FakeDriver)Application.Driver).SetBufferSize (40, 15);
  609. MessageBox.Query ("About", "Hello Word", "Ok");
  610. } else if (iterations == 1) TestHelpers.AssertDriverContentsWithFrameAre (@"
  611. File
  612. ┌ Window ──────────────────────────────┐
  613. │ │
  614. │ │
  615. │ │
  616. │ ┌ About ───────────────┐ │
  617. │ │ Hello Word │ │
  618. │ │ │ │
  619. │ │ [◦ Ok ◦] │ │
  620. │ └──────────────────────┘ │
  621. │ │
  622. │ │
  623. │ │
  624. └──────────────────────────────────────┘
  625. CTRL-N New ", output);
  626. else if (iterations == 2) {
  627. Assert.Null (Application.MouseGrabView);
  628. // Grab the mouse
  629. ReflectionTools.InvokePrivate (
  630. typeof (Application),
  631. "ProcessMouseEvent",
  632. new MouseEvent () {
  633. X = 8,
  634. Y = 5,
  635. Flags = MouseFlags.Button1Pressed
  636. });
  637. Assert.Equal (Application.Current, Application.MouseGrabView);
  638. Assert.Equal (new Rect (8, 5, 24, 5), Application.MouseGrabView.Frame);
  639. } else if (iterations == 3) {
  640. Assert.Equal (Application.Current, Application.MouseGrabView);
  641. // Grab to left
  642. ReflectionTools.InvokePrivate (
  643. typeof (Application),
  644. "ProcessMouseEvent",
  645. new MouseEvent () {
  646. X = 7,
  647. Y = 5,
  648. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  649. });
  650. Assert.Equal (Application.Current, Application.MouseGrabView);
  651. Assert.Equal (new Rect (7, 5, 24, 5), Application.MouseGrabView.Frame);
  652. } else if (iterations == 4) {
  653. Assert.Equal (Application.Current, Application.MouseGrabView);
  654. TestHelpers.AssertDriverContentsWithFrameAre (@"
  655. File
  656. ┌ Window ──────────────────────────────┐
  657. │ │
  658. │ │
  659. │ │
  660. │ ┌ About ───────────────┐ │
  661. │ │ Hello Word │ │
  662. │ │ │ │
  663. │ │ [◦ Ok ◦] │ │
  664. │ └──────────────────────┘ │
  665. │ │
  666. │ │
  667. │ │
  668. └──────────────────────────────────────┘
  669. CTRL-N New ", output);
  670. Assert.Equal (Application.Current, Application.MouseGrabView);
  671. } else if (iterations == 5) {
  672. Assert.Equal (Application.Current, Application.MouseGrabView);
  673. // Grab to top
  674. ReflectionTools.InvokePrivate (
  675. typeof (Application),
  676. "ProcessMouseEvent",
  677. new MouseEvent () {
  678. X = 7,
  679. Y = 4,
  680. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  681. });
  682. Assert.Equal (Application.Current, Application.MouseGrabView);
  683. Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame);
  684. } else if (iterations == 6) {
  685. Assert.Equal (Application.Current, Application.MouseGrabView);
  686. TestHelpers.AssertDriverContentsWithFrameAre (@"
  687. File
  688. ┌ Window ──────────────────────────────┐
  689. │ │
  690. │ │
  691. │ ┌ About ───────────────┐ │
  692. │ │ Hello Word │ │
  693. │ │ │ │
  694. │ │ [◦ Ok ◦] │ │
  695. │ └──────────────────────┘ │
  696. │ │
  697. │ │
  698. │ │
  699. │ │
  700. └──────────────────────────────────────┘
  701. CTRL-N New ", output);
  702. Assert.Equal (Application.Current, Application.MouseGrabView);
  703. Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame);
  704. } else if (iterations == 7) {
  705. Assert.Equal (Application.Current, Application.MouseGrabView);
  706. // Ungrab the mouse
  707. ReflectionTools.InvokePrivate (
  708. typeof (Application),
  709. "ProcessMouseEvent",
  710. new MouseEvent () {
  711. X = 7,
  712. Y = 4,
  713. Flags = MouseFlags.Button1Released
  714. });
  715. Assert.Null (Application.MouseGrabView);
  716. } else if (iterations == 8) Application.RequestStop ();
  717. else if (iterations == 9) Application.RequestStop ();
  718. };
  719. Application.Run ();
  720. }
  721. [Fact, AutoInitShutdown]
  722. public void Mouse_Drag_On_Top_With_Superview_Not_Null ()
  723. {
  724. var menu = new MenuBar (new MenuBarItem [] {
  725. new MenuBarItem("File", new MenuItem [] {
  726. new MenuItem("New", "", null)
  727. })
  728. });
  729. var sbar = new StatusBar (new StatusItem [] {
  730. new StatusItem(Key.N, "~CTRL-N~ New", null)
  731. });
  732. var win = new Window ("Window") {
  733. X = 3,
  734. Y = 2,
  735. Width = Dim.Fill (10),
  736. Height = Dim.Fill (5)
  737. };
  738. var top = Application.Top;
  739. top.Add (menu, sbar, win);
  740. var iterations = -1;
  741. Application.Iteration = () => {
  742. iterations++;
  743. if (iterations == 0) {
  744. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  745. Assert.Null (Application.MouseGrabView);
  746. // Grab the mouse
  747. ReflectionTools.InvokePrivate (
  748. typeof (Application),
  749. "ProcessMouseEvent",
  750. new MouseEvent () {
  751. X = 4,
  752. Y = 2,
  753. Flags = MouseFlags.Button1Pressed
  754. });
  755. Assert.Equal (win, Application.MouseGrabView);
  756. Assert.Equal (new Rect (3, 2, 7, 3), Application.MouseGrabView.Frame);
  757. TestHelpers.AssertDriverContentsWithFrameAre (@"
  758. File
  759. ┌─────┐
  760. │ │
  761. └─────┘
  762. CTRL-N New", output);
  763. } else if (iterations == 1) {
  764. Assert.Equal (win, Application.MouseGrabView);
  765. // Grab to left
  766. ReflectionTools.InvokePrivate (
  767. typeof (Application),
  768. "ProcessMouseEvent",
  769. new MouseEvent () {
  770. X = 5,
  771. Y = 2,
  772. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  773. });
  774. Assert.Equal (win, Application.MouseGrabView);
  775. } else if (iterations == 2) {
  776. Assert.Equal (win, Application.MouseGrabView);
  777. TestHelpers.AssertDriverContentsWithFrameAre (@"
  778. File
  779. ┌────┐
  780. │ │
  781. └────┘
  782. CTRL-N New", output);
  783. Assert.Equal (win, Application.MouseGrabView);
  784. Assert.Equal (new Rect (4, 2, 6, 3), Application.MouseGrabView.Frame);
  785. } else if (iterations == 3) {
  786. Assert.Equal (win, Application.MouseGrabView);
  787. // Grab to top
  788. ReflectionTools.InvokePrivate (
  789. typeof (Application),
  790. "ProcessMouseEvent",
  791. new MouseEvent () {
  792. X = 5,
  793. Y = 1,
  794. Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
  795. });
  796. Assert.Equal (win, Application.MouseGrabView);
  797. } else if (iterations == 4) {
  798. Assert.Equal (win, Application.MouseGrabView);
  799. TestHelpers.AssertDriverContentsWithFrameAre (@"
  800. File
  801. ┌────┐
  802. │ │
  803. │ │
  804. └────┘
  805. CTRL-N New", output);
  806. Assert.Equal (win, Application.MouseGrabView);
  807. Assert.Equal (new Rect (4, 1, 6, 4), Application.MouseGrabView.Frame);
  808. } else if (iterations == 5) {
  809. Assert.Equal (win, Application.MouseGrabView);
  810. // Ungrab the mouse
  811. ReflectionTools.InvokePrivate (
  812. typeof (Application),
  813. "ProcessMouseEvent",
  814. new MouseEvent () {
  815. X = 7,
  816. Y = 4,
  817. Flags = MouseFlags.Button1Released
  818. });
  819. Assert.Null (Application.MouseGrabView);
  820. } else if (iterations == 8) Application.RequestStop ();
  821. };
  822. Application.Run ();
  823. }
  824. [Fact, AutoInitShutdown]
  825. public void EnsureVisibleBounds_With_Border_Null_Not_Throws ()
  826. {
  827. var top = new Toplevel ();
  828. Application.Begin (top);
  829. var exception = Record.Exception (() => ((FakeDriver)Application.Driver).SetBufferSize (0, 10));
  830. Assert.Null (exception);
  831. exception = Record.Exception (() => ((FakeDriver)Application.Driver).SetBufferSize (10, 0));
  832. Assert.Null (exception);
  833. }
  834. [Fact, AutoInitShutdown]
  835. public void OnEnter_OnLeave_Triggered_On_Application_Begin_End ()
  836. {
  837. var isEnter = false;
  838. var isLeave = false;
  839. var v = new View ();
  840. v.Enter += (_) => isEnter = true;
  841. v.Leave += (_) => isLeave = true;
  842. var top = Application.Top;
  843. top.Add (v);
  844. Assert.False (v.CanFocus);
  845. var exception = Record.Exception (() => top.OnEnter (top));
  846. Assert.Null (exception);
  847. exception = Record.Exception (() => top.OnLeave (top));
  848. Assert.Null (exception);
  849. v.CanFocus = true;
  850. Application.Begin (top);
  851. Assert.True (isEnter);
  852. Assert.False (isLeave);
  853. isEnter = false;
  854. var d = new Dialog ();
  855. var rs = Application.Begin (d);
  856. Assert.False (isEnter);
  857. Assert.True (isLeave);
  858. isLeave = false;
  859. Application.End (rs);
  860. Assert.True (isEnter);
  861. Assert.False (isLeave); // Leave event cannot be trigger because it v.Enter was performed and v is focused
  862. Assert.True (v.HasFocus);
  863. }
  864. [Fact, AutoInitShutdown]
  865. public void OnEnter_OnLeave_Triggered_On_Application_Begin_End_With_More_Toplevels ()
  866. {
  867. var iterations = 0;
  868. var steps = new int [5];
  869. var isEnterTop = false;
  870. var isLeaveTop = false;
  871. var vt = new View ();
  872. var top = Application.Top;
  873. var diag = new Dialog ();
  874. vt.Enter += (e) => {
  875. iterations++;
  876. isEnterTop = true;
  877. if (iterations == 1) {
  878. steps [0] = iterations;
  879. Assert.Null (e.View);
  880. } else {
  881. steps [4] = iterations;
  882. Assert.Equal (diag, e.View);
  883. }
  884. };
  885. vt.Leave += (e) => {
  886. iterations++;
  887. steps [1] = iterations;
  888. isLeaveTop = true;
  889. Assert.Equal (diag, e.View);
  890. };
  891. top.Add (vt);
  892. Assert.False (vt.CanFocus);
  893. var exception = Record.Exception (() => top.OnEnter (top));
  894. Assert.Null (exception);
  895. exception = Record.Exception (() => top.OnLeave (top));
  896. Assert.Null (exception);
  897. vt.CanFocus = true;
  898. Application.Begin (top);
  899. Assert.True (isEnterTop);
  900. Assert.False (isLeaveTop);
  901. isEnterTop = false;
  902. var isEnterDiag = false;
  903. var isLeaveDiag = false;
  904. var vd = new View ();
  905. vd.Enter += (e) => {
  906. iterations++;
  907. steps [2] = iterations;
  908. isEnterDiag = true;
  909. Assert.Null (e.View);
  910. };
  911. vd.Leave += (e) => {
  912. iterations++;
  913. steps [3] = iterations;
  914. isLeaveDiag = true;
  915. Assert.Equal (top, e.View);
  916. };
  917. diag.Add (vd);
  918. Assert.False (vd.CanFocus);
  919. exception = Record.Exception (() => diag.OnEnter (diag));
  920. Assert.Null (exception);
  921. exception = Record.Exception (() => diag.OnLeave (diag));
  922. Assert.Null (exception);
  923. vd.CanFocus = true;
  924. var rs = Application.Begin (diag);
  925. Assert.True (isEnterDiag);
  926. Assert.False (isLeaveDiag);
  927. Assert.False (isEnterTop);
  928. Assert.True (isLeaveTop);
  929. isEnterDiag = false;
  930. isLeaveTop = false;
  931. Application.End (rs);
  932. Assert.False (isEnterDiag);
  933. Assert.True (isLeaveDiag);
  934. Assert.True (isEnterTop);
  935. Assert.False (isLeaveTop); // Leave event cannot be trigger because it v.Enter was performed and v is focused
  936. Assert.True (vt.HasFocus);
  937. Assert.Equal (1, steps [0]);
  938. Assert.Equal (2, steps [1]);
  939. Assert.Equal (3, steps [2]);
  940. Assert.Equal (4, steps [3]);
  941. Assert.Equal (5, steps [^1]);
  942. }
  943. [Fact, AutoInitShutdown]
  944. public void PositionCursor_SetCursorVisibility_To_Invisible_If_Focused_Is_Null ()
  945. {
  946. var tf = new TextField ("test") { Width = 5 };
  947. var view = new View () { Width = 10, Height = 10 };
  948. view.Add (tf);
  949. Application.Top.Add (view);
  950. Application.Begin (Application.Top);
  951. Assert.True (tf.HasFocus);
  952. Application.Driver.GetCursorVisibility (out CursorVisibility cursor);
  953. Assert.Equal (CursorVisibility.Default, cursor);
  954. view.Enabled = false;
  955. Assert.False (tf.HasFocus);
  956. Application.Refresh ();
  957. Application.Driver.GetCursorVisibility (out cursor);
  958. Assert.Equal (CursorVisibility.Invisible, cursor);
  959. }
  960. [Fact, AutoInitShutdown]
  961. public void Activating_MenuBar_By_Alt_Key_Does_Not_Throw ()
  962. {
  963. var menu = new MenuBar (new MenuBarItem [] {
  964. new MenuBarItem ("Child", new MenuItem [] {
  965. new MenuItem ("_Create Child", "", null)
  966. })
  967. });
  968. var topChild = new Toplevel ();
  969. topChild.Add (menu);
  970. Application.Top.Add (topChild);
  971. Application.Begin (Application.Top);
  972. var exception = Record.Exception (() => topChild.ProcessHotKey (new KeyEvent (Key.AltMask, new KeyModifiers { Alt = true })));
  973. Assert.Null (exception);
  974. }
  975. private Window Top_With_MenuBar_And_StatusBar (bool borderless = false, bool isMdiContainer = false, bool resize = true)
  976. {
  977. var top = new Window ();
  978. if (borderless) {
  979. top.Border.BorderStyle = BorderStyle.None;
  980. top.Border.DrawMarginFrame = false;
  981. }
  982. if (isMdiContainer) {
  983. top.IsMdiContainer = true;
  984. }
  985. var menu = new MenuBar (new MenuBarItem [] {
  986. new MenuBarItem("File", new MenuItem [] {
  987. new MenuItem ("New", "", null)
  988. })
  989. });
  990. var statusBar = new StatusBar (new StatusItem [] {
  991. new StatusItem(Key.F2, "~F2~ File", null)
  992. });
  993. top.Add (menu, statusBar);
  994. if (resize) {
  995. ((FakeDriver)Application.Driver).SetBufferSize (20, 20);
  996. }
  997. return top;
  998. }
  999. private Window Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (
  1000. bool isDimFill = false, bool borderless = false, bool isModal = false)
  1001. {
  1002. Window win;
  1003. if (isDimFill) {
  1004. win = new Window () { Width = Dim.Fill (10), Height = Dim.Fill (10), ColorScheme = Colors.TopLevel };
  1005. } else {
  1006. win = new Window () { Width = 10, Height = 10, ColorScheme = Colors.TopLevel };
  1007. }
  1008. if (borderless) {
  1009. win.Border.BorderStyle = BorderStyle.None;
  1010. win.Border.DrawMarginFrame = false;
  1011. }
  1012. if (isModal) {
  1013. win.Modal = true;
  1014. }
  1015. win.Add (new Label ("TL"),
  1016. new Label ("TR") { X = Pos.AnchorEnd (2) },
  1017. new Label ("BL") { Y = Pos.AnchorEnd (1) },
  1018. new Label ("BR") { X = Pos.AnchorEnd (2), Y = Pos.AnchorEnd (1) }
  1019. );
  1020. return win;
  1021. }
  1022. private string TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border = @"
  1023. ┌──────────────────┐
  1024. │ File │
  1025. │┌────────┐ │
  1026. ││TL TR│ │
  1027. ││ │ │
  1028. ││ │ │
  1029. ││ │ │
  1030. ││ │ │
  1031. ││ │ │
  1032. ││ │ │
  1033. ││BL BR│ │
  1034. │└────────┘ │
  1035. │ │
  1036. │ │
  1037. │ │
  1038. │ │
  1039. │ │
  1040. │ │
  1041. │ F2 File │
  1042. └──────────────────┘";
  1043. private string BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border = @"
  1044. ┌──────────────────┐
  1045. │ File │
  1046. │ │
  1047. │ │
  1048. │ │
  1049. │ │
  1050. │ │
  1051. │ │
  1052. │ ┌────────┐│
  1053. │ │TL TR││
  1054. │ │ ││
  1055. │ │ ││
  1056. │ │ ││
  1057. │ │ ││
  1058. │ │ ││
  1059. │ │ ││
  1060. │ │BL BR││
  1061. │ └────────┘│
  1062. │ F2 File │
  1063. └──────────────────┘";
  1064. private string TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1065. ┌──────────────────┐
  1066. │ File │
  1067. │┌──────┐ │
  1068. ││TL TR│ │
  1069. ││ │ │
  1070. ││ │ │
  1071. ││ │ │
  1072. ││BL BR│ │
  1073. │└──────┘ │
  1074. │ │
  1075. │ │
  1076. │ │
  1077. │ │
  1078. │ │
  1079. │ │
  1080. │ │
  1081. │ │
  1082. │ │
  1083. │ F2 File │
  1084. └──────────────────┘";
  1085. private string TopLeft_MdiTop_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1086. ┌──────────────────┐
  1087. │ File │
  1088. │┌───────┐ │
  1089. ││TL TR│ │
  1090. ││ │ │
  1091. ││ │ │
  1092. ││ │ │
  1093. ││ │ │
  1094. ││BL BR│ │
  1095. │└───────┘ │
  1096. │ │
  1097. │ │
  1098. │ │
  1099. │ │
  1100. │ │
  1101. │ │
  1102. │ │
  1103. │ │
  1104. │ F2 File │
  1105. └──────────────────┘";
  1106. private string BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1107. ┌──────────────────┐
  1108. │ File │
  1109. │ │
  1110. │ │
  1111. │ │
  1112. │ ┌──┐ │
  1113. │ │TR│ │
  1114. │ │BR│ │
  1115. │ └──┘ │
  1116. │ │
  1117. │ │
  1118. │ │
  1119. │ │
  1120. │ │
  1121. │ │
  1122. │ │
  1123. │ │
  1124. │ │
  1125. │ F2 File │
  1126. └──────────────────┘";
  1127. private string BottomRight_MdiTop_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1128. ┌──────────────────┐
  1129. │ File │
  1130. │ │
  1131. │ │
  1132. │ ┌────┐ │
  1133. │ │TLTR│ │
  1134. │ │ │ │
  1135. │ │ │ │
  1136. │ │BLBR│ │
  1137. │ └────┘ │
  1138. │ │
  1139. │ │
  1140. │ │
  1141. │ │
  1142. │ │
  1143. │ │
  1144. │ │
  1145. │ │
  1146. │ F2 File │
  1147. └──────────────────┘";
  1148. private string TopLeft_Top_With_Border_And_Modal_With_Border = @"
  1149. ┌──────────────────┐
  1150. │┌────────┐ │
  1151. ││TL TR│ │
  1152. ││ │ │
  1153. ││ │ │
  1154. ││ │ │
  1155. ││ │ │
  1156. ││ │ │
  1157. ││ │ │
  1158. ││BL BR│ │
  1159. │└────────┘ │
  1160. │ │
  1161. │ │
  1162. │ │
  1163. │ │
  1164. │ │
  1165. │ │
  1166. │ │
  1167. │ │
  1168. └──────────────────┘";
  1169. private string BottomRight_Top_With_Border_And_Modal_With_Border = @"
  1170. ┌──────────────────┐
  1171. │ │
  1172. │ │
  1173. │ │
  1174. │ │
  1175. │ │
  1176. │ │
  1177. │ │
  1178. │ │
  1179. │ ┌────────┐│
  1180. │ │TL TR││
  1181. │ │ ││
  1182. │ │ ││
  1183. │ │ ││
  1184. │ │ ││
  1185. │ │ ││
  1186. │ │ ││
  1187. │ │BL BR││
  1188. │ └────────┘│
  1189. └──────────────────┘";
  1190. private string TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border = @"
  1191. ┌──────────────────┐
  1192. │ File │
  1193. │TL TR │
  1194. │ │
  1195. │ │
  1196. │ │
  1197. │ │
  1198. │ │
  1199. │ │
  1200. │ │
  1201. │ │
  1202. │BL BR │
  1203. │ │
  1204. │ │
  1205. │ │
  1206. │ │
  1207. │ │
  1208. │ │
  1209. │ F2 File │
  1210. └──────────────────┘";
  1211. private string BottonRight_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border = @"
  1212. ┌──────────────────┐
  1213. │ File │
  1214. │ │
  1215. │ │
  1216. │ │
  1217. │ │
  1218. │ │
  1219. │ │
  1220. │ TL TR│
  1221. │ │
  1222. │ │
  1223. │ │
  1224. │ │
  1225. │ │
  1226. │ │
  1227. │ │
  1228. │ │
  1229. │ BL BR│
  1230. │ F2 File │
  1231. └──────────────────┘";
  1232. private string TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1233. ┌──────────────────┐
  1234. │ File │
  1235. │TL TR │
  1236. │ │
  1237. │ │
  1238. │ │
  1239. │ │
  1240. │ │
  1241. │BL BR │
  1242. │ │
  1243. │ │
  1244. │ │
  1245. │ │
  1246. │ │
  1247. │ │
  1248. │ │
  1249. │ │
  1250. │ │
  1251. │ F2 File │
  1252. └──────────────────┘";
  1253. private string TopLeft_MdiTop_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1254. ┌──────────────────┐
  1255. │ File │
  1256. │TL TR │
  1257. │ │
  1258. │ │
  1259. │ │
  1260. │ │
  1261. │ │
  1262. │ │
  1263. │BL BR │
  1264. │ │
  1265. │ │
  1266. │ │
  1267. │ │
  1268. │ │
  1269. │ │
  1270. │ │
  1271. │ │
  1272. │ F2 File │
  1273. └──────────────────┘";
  1274. private string BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1275. ┌──────────────────┐
  1276. │ File │
  1277. │ │
  1278. │ │
  1279. │ │
  1280. │ TLTR │
  1281. │ │
  1282. │ │
  1283. │ BLBR │
  1284. │ │
  1285. │ │
  1286. │ │
  1287. │ │
  1288. │ │
  1289. │ │
  1290. │ │
  1291. │ │
  1292. │ │
  1293. │ F2 File │
  1294. └──────────────────┘";
  1295. private string BottomRight_MdiTop_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1296. ┌──────────────────┐
  1297. │ File │
  1298. │ │
  1299. │ │
  1300. │ TL TR │
  1301. │ │
  1302. │ │
  1303. │ │
  1304. │ │
  1305. │ BL BR │
  1306. │ │
  1307. │ │
  1308. │ │
  1309. │ │
  1310. │ │
  1311. │ │
  1312. │ │
  1313. │ │
  1314. │ F2 File │
  1315. └──────────────────┘";
  1316. private string TopLeft_Top_With_Border_And_Modal_Without_Border = @"
  1317. ┌──────────────────┐
  1318. │TL TR │
  1319. │ │
  1320. │ │
  1321. │ │
  1322. │ │
  1323. │ │
  1324. │ │
  1325. │ │
  1326. │ │
  1327. │BL BR │
  1328. │ │
  1329. │ │
  1330. │ │
  1331. │ │
  1332. │ │
  1333. │ │
  1334. │ │
  1335. │ │
  1336. └──────────────────┘";
  1337. private string BottomRight_Top_With_Border_And_Modal_Without_Border = @"
  1338. ┌──────────────────┐
  1339. │ │
  1340. │ │
  1341. │ │
  1342. │ │
  1343. │ │
  1344. │ │
  1345. │ │
  1346. │ │
  1347. │ TL TR│
  1348. │ │
  1349. │ │
  1350. │ │
  1351. │ │
  1352. │ │
  1353. │ │
  1354. │ │
  1355. │ │
  1356. │ BL BR│
  1357. └──────────────────┘";
  1358. private string TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border = @"
  1359. File
  1360. ┌────────┐
  1361. │TL TR│
  1362. │ │
  1363. │ │
  1364. │ │
  1365. │ │
  1366. │ │
  1367. │ │
  1368. │BL BR│
  1369. └────────┘
  1370. F2 File ";
  1371. private string BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border = @"
  1372. File
  1373. ┌────────┐
  1374. │TL TR│
  1375. │ │
  1376. │ │
  1377. │ │
  1378. │ │
  1379. │ │
  1380. │ │
  1381. │BL BR│
  1382. └────────┘
  1383. F2 File ";
  1384. private string TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1385. File
  1386. ┌────────┐
  1387. │TL TR│
  1388. │ │
  1389. │ │
  1390. │ │
  1391. │ │
  1392. │ │
  1393. │BL BR│
  1394. └────────┘
  1395. F2 File ";
  1396. private string BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill = @"
  1397. File
  1398. ┌────┐
  1399. │TLTR│
  1400. │ │
  1401. │ │
  1402. │BLBR│
  1403. └────┘
  1404. F2 File ";
  1405. private string TopLeft_Top_Without_Border_And_Modal_With_Border = @"
  1406. ┌────────┐
  1407. │TL TR│
  1408. │ │
  1409. │ │
  1410. │ │
  1411. │ │
  1412. │ │
  1413. │ │
  1414. │BL BR│
  1415. └────────┘";
  1416. private string BottomRight_Top_Without_Border_And_Modal_With_Border = @"
  1417. ┌────────┐
  1418. │TL TR│
  1419. │ │
  1420. │ │
  1421. │ │
  1422. │ │
  1423. │ │
  1424. │ │
  1425. │BL BR│
  1426. └────────┘";
  1427. private string TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border = @"
  1428. File
  1429. TL TR
  1430. BL BR
  1431. F2 File ";
  1432. private string BottomRigt_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border = @"
  1433. File
  1434. TL TR
  1435. BL BR
  1436. F2 File ";
  1437. private string TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1438. File
  1439. TL TR
  1440. BL BR
  1441. F2 File ";
  1442. private string BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill = @"
  1443. File
  1444. TL TR
  1445. BL BR
  1446. F2 File ";
  1447. private string TopLeft_Top_Without_Border_And_Modal_Without_Border = @"
  1448. TL TR
  1449. BL BR";
  1450. private string BottomRight_Top_Without_Border_And_Modal_Without_Border = @"
  1451. TL TR
  1452. BL BR";
  1453. [Theory, AutoInitShutdown]
  1454. [InlineData (false, false, 0, 1, 8, 7)]
  1455. [InlineData (false, true, 1, 2, 9, 8)]
  1456. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border (
  1457. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1458. {
  1459. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1460. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  1461. if (!isMdiContainer) {
  1462. top.Add (win);
  1463. }
  1464. Application.Begin (top);
  1465. if (isMdiContainer) {
  1466. Application.Begin (win);
  1467. }
  1468. Assert.NotNull (top.MenuBar);
  1469. Assert.NotNull (top.StatusBar);
  1470. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1471. // left + top
  1472. win.X = 0;
  1473. win.Y = 0;
  1474. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1475. Assert.Equal (topLeftX, nx);
  1476. Assert.Equal (topLeftY, ny);
  1477. win.X = nx;
  1478. win.Y = ny;
  1479. Application.Refresh ();
  1480. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1481. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1482. // right + bottom
  1483. win.X = 100;
  1484. win.Y = 40;
  1485. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1486. Assert.Equal (bottomRightX, nx);
  1487. Assert.Equal (bottomRightY, ny);
  1488. win.X = nx;
  1489. win.Y = ny;
  1490. Application.Refresh ();
  1491. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1492. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1493. }
  1494. [Theory, AutoInitShutdown]
  1495. [InlineData (false, false, 1, 2, 9, 8)]
  1496. [InlineData (false, true, 1, 2, 9, 8)]
  1497. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Modal_With_Border (
  1498. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1499. {
  1500. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1501. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, false, true);
  1502. Application.Begin (top);
  1503. Application.Begin (win);
  1504. Assert.NotNull (top.MenuBar);
  1505. Assert.NotNull (top.StatusBar);
  1506. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1507. Assert.True (win.Modal);
  1508. // left + top
  1509. win.X = 0;
  1510. win.Y = 0;
  1511. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1512. Assert.Equal (topLeftX, nx);
  1513. Assert.Equal (topLeftY, ny);
  1514. win.X = nx;
  1515. win.Y = ny;
  1516. Application.Refresh ();
  1517. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1518. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1519. // right + bottom
  1520. win.X = 100;
  1521. win.Y = 40;
  1522. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1523. Assert.Equal (bottomRightX, nx);
  1524. Assert.Equal (bottomRightY, ny);
  1525. win.X = nx;
  1526. win.Y = ny;
  1527. Application.Refresh ();
  1528. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1529. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1530. }
  1531. [Theory, AutoInitShutdown]
  1532. [InlineData (false, false, 0, 1, 4, 4)]
  1533. [InlineData (false, true, 1, 2, 4, 4)]
  1534. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill (
  1535. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1536. {
  1537. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1538. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (true);
  1539. if (!isMdiContainer) {
  1540. top.Add (win);
  1541. }
  1542. Application.Begin (top);
  1543. if (isMdiContainer) {
  1544. Application.Begin (win);
  1545. }
  1546. Assert.NotNull (top.MenuBar);
  1547. Assert.NotNull (top.StatusBar);
  1548. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1549. Assert.False (win.Modal);
  1550. // left + top
  1551. win.X = 0;
  1552. win.Y = 0;
  1553. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1554. Assert.Equal (topLeftX, nx);
  1555. Assert.Equal (topLeftY, ny);
  1556. win.X = nx;
  1557. win.Y = ny;
  1558. Application.Refresh ();
  1559. if (!isMdiContainer) {
  1560. Assert.Equal (new Rect (topLeftX, topLeftY, 8, 7), win.Frame);
  1561. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1562. } else {
  1563. Assert.Equal (new Rect (topLeftX, topLeftY, 9, 8), win.Frame);
  1564. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_MdiTop_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1565. }
  1566. // right + bottom
  1567. win.X = 4;
  1568. win.Y = 4;
  1569. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1570. Assert.Equal (bottomRightX, nx);
  1571. Assert.Equal (bottomRightY, ny);
  1572. win.X = nx;
  1573. win.Y = ny;
  1574. Application.Refresh ();
  1575. if (!isMdiContainer) {
  1576. Assert.Equal (new Rect (bottomRightX, bottomRightY, 4, 4), win.Frame);
  1577. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1578. } else {
  1579. Assert.Equal (new Rect (bottomRightX, bottomRightY, 6, 6), win.Frame);
  1580. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_MdiTop_With_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1581. }
  1582. }
  1583. [Theory, AutoInitShutdown]
  1584. [InlineData (false, false, 1, 1, 9, 9)]
  1585. [InlineData (false, true, 1, 1, 9, 9)]
  1586. public void EnsureVisibleBounds_Top_With_Border_And_Modal_With_Border (
  1587. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1588. {
  1589. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1590. top.MenuBar.Visible = false;
  1591. top.StatusBar.Visible = false;
  1592. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, false, true);
  1593. Application.Begin (top);
  1594. Application.Begin (win);
  1595. Assert.False (top.MenuBar.Visible);
  1596. Assert.False (top.StatusBar.Visible);
  1597. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1598. Assert.True (win.Modal);
  1599. // left + top
  1600. win.X = 0;
  1601. win.Y = 0;
  1602. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1603. Assert.Equal (topLeftX, nx);
  1604. Assert.Equal (topLeftY, ny);
  1605. win.X = nx;
  1606. win.Y = ny;
  1607. Application.Refresh ();
  1608. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1609. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_And_Modal_With_Border, output);
  1610. // right + bottom
  1611. win.X = 100;
  1612. win.Y = 40;
  1613. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1614. Assert.Equal (bottomRightX, nx);
  1615. Assert.Equal (bottomRightY, ny);
  1616. win.X = nx;
  1617. win.Y = ny;
  1618. Application.Refresh ();
  1619. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1620. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_And_Modal_With_Border, output);
  1621. }
  1622. [Theory, AutoInitShutdown]
  1623. [InlineData (false, false, 0, 1, 8, 7)]
  1624. [InlineData (false, true, 1, 2, 9, 8)]
  1625. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border (
  1626. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1627. {
  1628. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1629. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true);
  1630. if (!isMdiContainer) {
  1631. top.Add (win);
  1632. }
  1633. Application.Begin (top);
  1634. if (isMdiContainer) {
  1635. Application.Begin (win);
  1636. }
  1637. Assert.NotNull (top.MenuBar);
  1638. Assert.NotNull (top.StatusBar);
  1639. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1640. Assert.False (win.Modal);
  1641. // left + top
  1642. win.X = 0;
  1643. win.Y = 0;
  1644. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1645. Assert.Equal (topLeftX, nx);
  1646. Assert.Equal (topLeftY, ny);
  1647. win.X = nx;
  1648. win.Y = ny;
  1649. Application.Refresh ();
  1650. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1651. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1652. // right + bottom
  1653. win.X = 100;
  1654. win.Y = 40;
  1655. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1656. Assert.Equal (bottomRightX, nx);
  1657. Assert.Equal (bottomRightY, ny);
  1658. win.X = nx;
  1659. win.Y = ny;
  1660. Application.Refresh ();
  1661. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1662. TestHelpers.AssertDriverContentsWithFrameAre (BottonRight_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1663. }
  1664. [Theory, AutoInitShutdown]
  1665. [InlineData (false, false, 1, 2, 9, 8)]
  1666. [InlineData (false, true, 1, 2, 9, 8)]
  1667. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Modal_Without_Border (
  1668. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1669. {
  1670. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1671. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true, true);
  1672. Application.Begin (top);
  1673. Application.Begin (win);
  1674. Assert.NotNull (top.MenuBar);
  1675. Assert.NotNull (top.StatusBar);
  1676. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1677. Assert.True (win.Modal);
  1678. // left + top
  1679. win.X = 0;
  1680. win.Y = 0;
  1681. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1682. Assert.Equal (topLeftX, nx);
  1683. Assert.Equal (topLeftY, ny);
  1684. win.X = nx;
  1685. win.Y = ny;
  1686. Application.Refresh ();
  1687. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1688. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1689. // right + bottom
  1690. win.X = 100;
  1691. win.Y = 40;
  1692. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1693. Assert.Equal (bottomRightX, nx);
  1694. Assert.Equal (bottomRightY, ny);
  1695. win.X = nx;
  1696. win.Y = ny;
  1697. Application.Refresh ();
  1698. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1699. TestHelpers.AssertDriverContentsWithFrameAre (BottonRight_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1700. }
  1701. [Theory, AutoInitShutdown]
  1702. [InlineData (false, false, 0, 1, 4, 4)]
  1703. [InlineData (false, true, 1, 2, 4, 4)]
  1704. public void EnsureVisibleBounds_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill (
  1705. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1706. {
  1707. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1708. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (true, true);
  1709. if (!isMdiContainer) {
  1710. top.Add (win);
  1711. }
  1712. Application.Begin (top);
  1713. if (isMdiContainer) {
  1714. Application.Begin (win);
  1715. }
  1716. Assert.NotNull (top.MenuBar);
  1717. Assert.NotNull (top.StatusBar);
  1718. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1719. Assert.False (win.Modal);
  1720. // left + top
  1721. win.X = 0;
  1722. win.Y = 0;
  1723. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1724. Assert.Equal (topLeftX, nx);
  1725. Assert.Equal (topLeftY, ny);
  1726. win.X = nx;
  1727. win.Y = ny;
  1728. Application.Refresh ();
  1729. if (!isMdiContainer) {
  1730. Assert.Equal (new Rect (topLeftX, topLeftY, 8, 7), win.Frame);
  1731. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  1732. } else {
  1733. Assert.Equal (new Rect (topLeftX, topLeftY, 9, 8), win.Frame);
  1734. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_MdiTop_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  1735. }
  1736. // right + bottom
  1737. win.X = 4;
  1738. win.Y = 4;
  1739. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1740. Assert.Equal (bottomRightX, nx);
  1741. Assert.Equal (bottomRightY, ny);
  1742. win.X = nx;
  1743. win.Y = ny;
  1744. Application.Refresh ();
  1745. if (!isMdiContainer) {
  1746. Assert.Equal (new Rect (bottomRightX, bottomRightY, 4, 4), win.Frame);
  1747. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  1748. } else {
  1749. Assert.Equal (new Rect (bottomRightX, bottomRightY, 6, 6), win.Frame);
  1750. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_MdiTop_With_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  1751. }
  1752. }
  1753. [Theory, AutoInitShutdown]
  1754. [InlineData (false, false, 1, 1, 9, 9)]
  1755. [InlineData (false, true, 1, 1, 9, 9)]
  1756. public void EnsureVisibleBounds_Top_With_Border_And_Modal_Without_Border (
  1757. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1758. {
  1759. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1760. top.MenuBar.Visible = false;
  1761. top.StatusBar.Visible = false;
  1762. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true, true);
  1763. Application.Begin (top);
  1764. Application.Begin (win);
  1765. Assert.NotNull (top.MenuBar);
  1766. Assert.NotNull (top.StatusBar);
  1767. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1768. Assert.True (win.Modal);
  1769. // left + top
  1770. win.X = 0;
  1771. win.Y = 0;
  1772. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1773. Assert.Equal (topLeftX, nx);
  1774. Assert.Equal (topLeftY, ny);
  1775. win.X = nx;
  1776. win.Y = ny;
  1777. Application.Refresh ();
  1778. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1779. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_And_Modal_Without_Border, output);
  1780. // right + bottom
  1781. win.X = 100;
  1782. win.Y = 40;
  1783. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1784. Assert.Equal (bottomRightX, nx);
  1785. Assert.Equal (bottomRightY, ny);
  1786. win.X = nx;
  1787. win.Y = ny;
  1788. Application.Refresh ();
  1789. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1790. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_With_Border_And_Modal_Without_Border, output);
  1791. }
  1792. [Theory, AutoInitShutdown]
  1793. [InlineData (true, false, 0, 1, 10, 9)]
  1794. [InlineData (true, true, 0, 1, 10, 9)]
  1795. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border (
  1796. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1797. {
  1798. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1799. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  1800. if (!isMdiContainer) {
  1801. top.Add (win);
  1802. }
  1803. Application.Begin (top);
  1804. if (isMdiContainer) {
  1805. Application.Begin (win);
  1806. }
  1807. Assert.NotNull (top.MenuBar);
  1808. Assert.NotNull (top.StatusBar);
  1809. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1810. Assert.False (win.Modal);
  1811. // left + top
  1812. win.X = 0;
  1813. win.Y = 0;
  1814. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1815. Assert.Equal (topLeftX, nx);
  1816. Assert.Equal (topLeftY, ny);
  1817. win.X = nx;
  1818. win.Y = ny;
  1819. Application.Refresh ();
  1820. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1821. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1822. // right + bottom
  1823. win.X = 100;
  1824. win.Y = 40;
  1825. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1826. Assert.Equal (bottomRightX, nx);
  1827. Assert.Equal (bottomRightY, ny);
  1828. win.X = nx;
  1829. win.Y = ny;
  1830. Application.Refresh ();
  1831. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1832. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1833. }
  1834. [Theory, AutoInitShutdown]
  1835. [InlineData (true, false, 0, 1, 10, 9)]
  1836. [InlineData (true, true, 0, 1, 10, 9)]
  1837. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Modal_With_Border (
  1838. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1839. {
  1840. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1841. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, false, true);
  1842. Application.Begin (top);
  1843. Application.Begin (win);
  1844. Assert.NotNull (top.MenuBar);
  1845. Assert.NotNull (top.StatusBar);
  1846. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1847. Assert.True (win.Modal);
  1848. // left + top
  1849. win.X = 0;
  1850. win.Y = 0;
  1851. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1852. Assert.Equal (topLeftX, nx);
  1853. Assert.Equal (topLeftY, ny);
  1854. win.X = nx;
  1855. win.Y = ny;
  1856. Application.Refresh ();
  1857. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1858. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1859. // right + bottom
  1860. win.X = 100;
  1861. win.Y = 40;
  1862. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1863. Assert.Equal (bottomRightX, nx);
  1864. Assert.Equal (bottomRightY, ny);
  1865. win.X = nx;
  1866. win.Y = ny;
  1867. Application.Refresh ();
  1868. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1869. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  1870. }
  1871. [Theory, AutoInitShutdown]
  1872. [InlineData (true, false, 0, 1, 4, 4)]
  1873. [InlineData (true, true, 0, 1, 4, 4)]
  1874. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill (
  1875. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1876. {
  1877. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1878. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (true);
  1879. if (!isMdiContainer) {
  1880. top.Add (win);
  1881. }
  1882. Application.Begin (top);
  1883. if (isMdiContainer) {
  1884. Application.Begin (win);
  1885. }
  1886. Assert.NotNull (top.MenuBar);
  1887. Assert.NotNull (top.StatusBar);
  1888. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1889. Assert.False (win.Modal);
  1890. // left + top
  1891. win.X = 0;
  1892. win.Y = 0;
  1893. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1894. Assert.Equal (topLeftX, nx);
  1895. Assert.Equal (topLeftY, ny);
  1896. win.X = nx;
  1897. win.Y = ny;
  1898. Application.Refresh ();
  1899. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 9), win.Frame);
  1900. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1901. // right + bottom
  1902. win.X = 4;
  1903. win.Y = 4;
  1904. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1905. Assert.Equal (bottomRightX, nx);
  1906. Assert.Equal (bottomRightY, ny);
  1907. win.X = nx;
  1908. win.Y = ny;
  1909. Application.Refresh ();
  1910. Assert.Equal (new Rect (bottomRightX, bottomRightY, 6, 6), win.Frame);
  1911. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_With_Border_And_Dim_Fill, output);
  1912. }
  1913. [Theory, AutoInitShutdown]
  1914. [InlineData (true, false, 0, 0, 10, 10)]
  1915. [InlineData (true, true, 0, 0, 10, 10)]
  1916. public void EnsureVisibleBounds_Top_Without_Border_And_Modal_With_Border (
  1917. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1918. {
  1919. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1920. top.MenuBar.Visible = false;
  1921. top.StatusBar.Visible = false;
  1922. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, false, true);
  1923. Application.Begin (top);
  1924. Application.Begin (win);
  1925. Assert.False (top.MenuBar.Visible);
  1926. Assert.False (top.StatusBar.Visible);
  1927. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1928. Assert.True (win.Modal);
  1929. // left + top
  1930. win.X = 0;
  1931. win.Y = 0;
  1932. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1933. Assert.Equal (topLeftX, nx);
  1934. Assert.Equal (topLeftY, ny);
  1935. win.X = nx;
  1936. win.Y = ny;
  1937. Application.Refresh ();
  1938. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1939. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_And_Modal_With_Border, output);
  1940. // right + bottom
  1941. win.X = 100;
  1942. win.Y = 40;
  1943. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1944. Assert.Equal (bottomRightX, nx);
  1945. Assert.Equal (bottomRightY, ny);
  1946. win.X = nx;
  1947. win.Y = ny;
  1948. Application.Refresh ();
  1949. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1950. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_And_Modal_With_Border, output);
  1951. }
  1952. [Theory, AutoInitShutdown]
  1953. [InlineData (true, false, 0, 1, 10, 9)]
  1954. [InlineData (true, true, 0, 1, 10, 9)]
  1955. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border (
  1956. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1957. {
  1958. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  1959. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true);
  1960. if (!isMdiContainer) {
  1961. top.Add (win);
  1962. }
  1963. Application.Begin (top);
  1964. if (isMdiContainer) {
  1965. Application.Begin (win);
  1966. }
  1967. Assert.NotNull (top.MenuBar);
  1968. Assert.NotNull (top.StatusBar);
  1969. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  1970. Assert.False (win.Modal);
  1971. // left + top
  1972. win.X = 0;
  1973. win.Y = 0;
  1974. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  1975. Assert.Equal (topLeftX, nx);
  1976. Assert.Equal (topLeftY, ny);
  1977. win.X = nx;
  1978. win.Y = ny;
  1979. Application.Refresh ();
  1980. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  1981. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1982. // right + bottom
  1983. win.X = 100;
  1984. win.Y = 40;
  1985. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  1986. Assert.Equal (bottomRightX, nx);
  1987. Assert.Equal (bottomRightY, ny);
  1988. win.X = nx;
  1989. win.Y = ny;
  1990. Application.Refresh ();
  1991. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  1992. TestHelpers.AssertDriverContentsWithFrameAre (BottomRigt_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  1993. }
  1994. [Theory, AutoInitShutdown]
  1995. [InlineData (true, false, 0, 1, 10, 9)]
  1996. [InlineData (true, true, 0, 1, 10, 9)]
  1997. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Modal_Without_Border (
  1998. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  1999. {
  2000. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  2001. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true, true);
  2002. Application.Begin (top);
  2003. Application.Begin (win);
  2004. Assert.NotNull (top.MenuBar);
  2005. Assert.NotNull (top.StatusBar);
  2006. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  2007. Assert.True (win.Modal);
  2008. // left + top
  2009. win.X = 0;
  2010. win.Y = 0;
  2011. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  2012. Assert.Equal (topLeftX, nx);
  2013. Assert.Equal (topLeftY, ny);
  2014. win.X = nx;
  2015. win.Y = ny;
  2016. Application.Refresh ();
  2017. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  2018. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  2019. // right + bottom
  2020. win.X = 100;
  2021. win.Y = 40;
  2022. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  2023. Assert.Equal (bottomRightX, nx);
  2024. Assert.Equal (bottomRightY, ny);
  2025. win.X = nx;
  2026. win.Y = ny;
  2027. Application.Refresh ();
  2028. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  2029. TestHelpers.AssertDriverContentsWithFrameAre (BottomRigt_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  2030. }
  2031. [Theory, AutoInitShutdown]
  2032. [InlineData (true, false, 0, 1, 4, 4)]
  2033. [InlineData (true, true, 0, 1, 4, 4)]
  2034. public void EnsureVisibleBounds_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill (
  2035. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  2036. {
  2037. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  2038. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (true, true);
  2039. if (!isMdiContainer) {
  2040. top.Add (win);
  2041. }
  2042. Application.Begin (top);
  2043. if (isMdiContainer) {
  2044. Application.Begin (win);
  2045. }
  2046. Assert.NotNull (top.MenuBar);
  2047. Assert.NotNull (top.StatusBar);
  2048. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  2049. Assert.False (win.Modal);
  2050. // left + top
  2051. win.X = 0;
  2052. win.Y = 0;
  2053. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  2054. Assert.Equal (topLeftX, nx);
  2055. Assert.Equal (topLeftY, ny);
  2056. win.X = nx;
  2057. win.Y = ny;
  2058. Application.Refresh ();
  2059. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 9), win.Frame);
  2060. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  2061. // right + bottom
  2062. win.X = 4;
  2063. win.Y = 4;
  2064. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  2065. Assert.Equal (bottomRightX, nx);
  2066. Assert.Equal (bottomRightY, ny);
  2067. win.X = nx;
  2068. win.Y = ny;
  2069. Application.Refresh ();
  2070. Assert.Equal (new Rect (bottomRightX, bottomRightY, 6, 6), win.Frame);
  2071. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border_And_Dim_Fill, output);
  2072. }
  2073. [Theory, AutoInitShutdown]
  2074. [InlineData (true, false, 0, 0, 10, 10)]
  2075. [InlineData (true, true, 0, 0, 10, 10)]
  2076. public void EnsureVisibleBounds_Top_Without_Border_And_Modal_Without_Border (
  2077. bool borderless, bool isMdiContainer, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
  2078. {
  2079. var top = Top_With_MenuBar_And_StatusBar (borderless, isMdiContainer);
  2080. top.MenuBar.Visible = false;
  2081. top.StatusBar.Visible = false;
  2082. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true, true);
  2083. Application.Begin (top);
  2084. Application.Begin (win);
  2085. Assert.False (top.MenuBar.Visible);
  2086. Assert.False (top.StatusBar.Visible);
  2087. Assert.Equal (isMdiContainer, top.IsMdiContainer);
  2088. Assert.True (win.Modal);
  2089. // left + top
  2090. win.X = 0;
  2091. win.Y = 0;
  2092. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out int nx, out int ny, out _, out _);
  2093. Assert.Equal (topLeftX, nx);
  2094. Assert.Equal (topLeftY, ny);
  2095. win.X = nx;
  2096. win.Y = ny;
  2097. Application.Refresh ();
  2098. Assert.Equal (new Rect (topLeftX, topLeftY, 10, 10), win.Frame);
  2099. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_And_Modal_Without_Border, output);
  2100. // right + bottom
  2101. win.X = 100;
  2102. win.Y = 40;
  2103. top.EnsureVisibleBounds (win, win.Frame.X, win.Frame.Y, out nx, out ny, out _, out _);
  2104. Assert.Equal (bottomRightX, nx);
  2105. Assert.Equal (bottomRightY, ny);
  2106. win.X = nx;
  2107. win.Y = ny;
  2108. Application.Refresh ();
  2109. Assert.Equal (new Rect (bottomRightX, bottomRightY, 10, 10), win.Frame);
  2110. TestHelpers.AssertDriverContentsWithFrameAre (BottomRight_Top_Without_Border_And_Modal_Without_Border, output);
  2111. }
  2112. [Fact, AutoInitShutdown]
  2113. public void RunMainLoopIteration_Mdi_IsTopNeedsDisplay ()
  2114. {
  2115. var menu = new MenuBar (new MenuBarItem [] {
  2116. new MenuBarItem("File", Array.Empty<MenuItem> ())
  2117. }) { Visible = false };
  2118. var statusBar = new StatusBar (new StatusItem []{
  2119. new StatusItem(Key.F2, "~F2~ File", null)
  2120. }) { Visible = false };
  2121. var top = new Toplevel ();
  2122. top.IsMdiContainer = true;
  2123. top.Add (menu, statusBar);
  2124. Application.Begin (top);
  2125. var childWin = new Window () { Width = 5, Height = 5 };
  2126. var rs = Application.Begin (childWin);
  2127. Assert.Single (Application.MdiChildes);
  2128. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2129. ┌───┐
  2130. │ │
  2131. │ │
  2132. │ │
  2133. └───┘", output);
  2134. Assert.Equal (0, childWin.Frame.Y);
  2135. menu.Visible = true;
  2136. var firstIteration = false;
  2137. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2138. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2139. File
  2140. ┌───┐
  2141. │ │
  2142. │ │
  2143. │ │
  2144. └───┘", output);
  2145. Assert.Equal (1, childWin.Frame.Y);
  2146. menu.Visible = false;
  2147. childWin.Y = 25;
  2148. firstIteration = false;
  2149. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2150. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2151. ┌───┐
  2152. │ │
  2153. │ │
  2154. │ │
  2155. └───┘", output);
  2156. Assert.Equal (20, childWin.Frame.Y);
  2157. statusBar.Visible = true;
  2158. firstIteration = false;
  2159. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2160. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2161. ┌───┐
  2162. │ │
  2163. │ │
  2164. │ │
  2165. └───┘
  2166. F2 File", output);
  2167. Assert.Equal (19, childWin.Frame.Y);
  2168. }
  2169. [Fact, AutoInitShutdown]
  2170. public void Show_Menu_On_Front_MdiChild_By_Keyboard_And_Mouse_With_Run_Action ()
  2171. {
  2172. var top = Top_With_MenuBar_And_StatusBar (false, true);
  2173. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  2174. Application.Begin (top);
  2175. Application.Begin (win);
  2176. var isNew = false;
  2177. var menu = top.MenuBar;
  2178. var mi = menu.Menus [0].Children [0];
  2179. mi.Action = () => isNew = true;
  2180. Assert.False (menu.IsMenuOpen);
  2181. var expectedClosed = @"
  2182. ┌──────────────────┐
  2183. │ File │
  2184. │┌────────┐ │
  2185. ││TL TR│ │
  2186. ││ │ │
  2187. ││ │ │
  2188. ││ │ │
  2189. ││ │ │
  2190. ││ │ │
  2191. ││ │ │
  2192. ││BL BR│ │
  2193. │└────────┘ │
  2194. │ │
  2195. │ │
  2196. │ │
  2197. │ │
  2198. │ │
  2199. │ │
  2200. │ F2 File │
  2201. └──────────────────┘";
  2202. TestHelpers.AssertDriverContentsWithFrameAre (expectedClosed, output);
  2203. var expectedOpened = @"
  2204. ┌──────────────────┐
  2205. │ File │
  2206. │┌──────┐─┐ │
  2207. ││ New │R│ │
  2208. │└──────┘ │ │
  2209. ││ │ │
  2210. ││ │ │
  2211. ││ │ │
  2212. ││ │ │
  2213. ││ │ │
  2214. ││BL BR│ │
  2215. │└────────┘ │
  2216. │ │
  2217. │ │
  2218. │ │
  2219. │ │
  2220. │ │
  2221. │ │
  2222. │ F2 File │
  2223. └──────────────────┘";
  2224. // using keyboard
  2225. ReflectionTools.InvokePrivate (
  2226. typeof (Application),
  2227. "ProcessKeyEvent",
  2228. new KeyEvent (menu.Key, new KeyModifiers ()));
  2229. Application.Refresh ();
  2230. Assert.True (menu.IsMenuOpen);
  2231. TestHelpers.AssertDriverContentsWithFrameAre (expectedOpened, output);
  2232. // run action
  2233. ReflectionTools.InvokePrivate (
  2234. typeof (Application),
  2235. "ProcessKeyEvent",
  2236. new KeyEvent (Key.Enter, new KeyModifiers ()));
  2237. Application.MainLoop.MainIteration ();
  2238. Application.Refresh ();
  2239. Assert.False (menu.IsMenuOpen);
  2240. Assert.True (isNew);
  2241. TestHelpers.AssertDriverContentsWithFrameAre (expectedClosed, output);
  2242. // using mouse
  2243. ReflectionTools.InvokePrivate (
  2244. typeof (Application),
  2245. "ProcessMouseEvent",
  2246. new MouseEvent () {
  2247. X = 1,
  2248. Y = 1,
  2249. Flags = MouseFlags.Button1Pressed
  2250. });
  2251. Application.Refresh ();
  2252. Assert.True (menu.IsMenuOpen);
  2253. TestHelpers.AssertDriverContentsWithFrameAre (expectedOpened, output);
  2254. // run action
  2255. isNew = false;
  2256. ReflectionTools.InvokePrivate (
  2257. typeof (Application),
  2258. "ProcessMouseEvent",
  2259. new MouseEvent () {
  2260. X = 2,
  2261. Y = 4,
  2262. Flags = MouseFlags.Button1Clicked
  2263. });
  2264. Application.MainLoop.MainIteration ();
  2265. Application.Refresh ();
  2266. Assert.False (menu.IsMenuOpen);
  2267. Assert.True (isNew);
  2268. TestHelpers.AssertDriverContentsWithFrameAre (expectedClosed, output);
  2269. }
  2270. [Fact, AutoInitShutdown]
  2271. public void Toggle_MdiTop_Border_Redraw_MdiChild_Without_Border_On_Position_Changed ()
  2272. {
  2273. var top = Top_With_MenuBar_And_StatusBar (true, true);
  2274. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels (false, true);
  2275. Application.Begin (top);
  2276. var rs = Application.Begin (win);
  2277. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_Without_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  2278. var attributes = new Attribute [] {
  2279. // 0
  2280. Colors.Base.Normal,
  2281. // 1
  2282. Colors.Menu.Normal,
  2283. // 2
  2284. Colors.TopLevel.Normal,
  2285. // 3
  2286. Colors.Menu.HotNormal
  2287. };
  2288. TestHelpers.AssertDriverColorsAre (@"
  2289. 11111111111111111111
  2290. 22222222220000000000
  2291. 22222222220000000000
  2292. 22222222220000000000
  2293. 22222222220000000000
  2294. 22222222220000000000
  2295. 22222222220000000000
  2296. 22222222220000000000
  2297. 22222222220000000000
  2298. 22222222220000000000
  2299. 22222222220000000000
  2300. 00000000000000000000
  2301. 00000000000000000000
  2302. 00000000000000000000
  2303. 00000000000000000000
  2304. 00000000000000000000
  2305. 00000000000000000000
  2306. 00000000000000000000
  2307. 00000000000000000000
  2308. 13311111111111111111", attributes);
  2309. top.Border.BorderStyle = BorderStyle.Single;
  2310. var firstIteration = false;
  2311. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2312. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_Without_Border, output);
  2313. TestHelpers.AssertDriverColorsAre (@"
  2314. 00000000000000000000
  2315. 01111111111111111110
  2316. 02222222222000000000
  2317. 02222222222000000000
  2318. 02222222222000000000
  2319. 02222222222000000000
  2320. 02222222222000000000
  2321. 02222222222000000000
  2322. 02222222222000000000
  2323. 02222222222000000000
  2324. 02222222222000000000
  2325. 02222222222000000000
  2326. 00000000000000000000
  2327. 00000000000000000000
  2328. 00000000000000000000
  2329. 00000000000000000000
  2330. 00000000000000000000
  2331. 00000000000000000000
  2332. 01331111111111111110
  2333. 00000000000000000000", attributes);
  2334. }
  2335. [Fact, AutoInitShutdown]
  2336. public void MdiTop_Border_Redraw_MdiChild_With_Border_On_Position_Changed ()
  2337. {
  2338. var top = Top_With_MenuBar_And_StatusBar (false, true);
  2339. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  2340. Application.Begin (top);
  2341. var rs = Application.Begin (win);
  2342. TestHelpers.AssertDriverContentsWithFrameAre (TopLeft_Top_With_Border_MenuBar_StatusBar_And_Window_With_Border, output);
  2343. var attributes = new Attribute [] {
  2344. // 0
  2345. Colors.Base.Normal,
  2346. // 1
  2347. Colors.Menu.Normal,
  2348. // 2
  2349. Colors.TopLevel.Normal,
  2350. // 3
  2351. Colors.Menu.HotNormal
  2352. };
  2353. TestHelpers.AssertDriverColorsAre (@"
  2354. 00000000000000000000
  2355. 01111111111111111110
  2356. 02222222222000000000
  2357. 02222222222000000000
  2358. 02222222222000000000
  2359. 02222222222000000000
  2360. 02222222222000000000
  2361. 02222222222000000000
  2362. 02222222222000000000
  2363. 02222222222000000000
  2364. 02222222222000000000
  2365. 02222222222000000000
  2366. 00000000000000000000
  2367. 00000000000000000000
  2368. 00000000000000000000
  2369. 00000000000000000000
  2370. 00000000000000000000
  2371. 00000000000000000000
  2372. 01331111111111111110
  2373. 00000000000000000000", attributes);
  2374. win.X = Pos.Center ();
  2375. win.Y = Pos.Center ();
  2376. Application.Refresh ();
  2377. TestHelpers.AssertDriverContentsWithFrameAre (@"
  2378. ┌──────────────────┐
  2379. │ File │
  2380. │ │
  2381. │ │
  2382. │ │
  2383. │ ┌────────┐ │
  2384. │ │TL TR│ │
  2385. │ │ │ │
  2386. │ │ │ │
  2387. │ │ │ │
  2388. │ │ │ │
  2389. │ │ │ │
  2390. │ │ │ │
  2391. │ │BL BR│ │
  2392. │ └────────┘ │
  2393. │ │
  2394. │ │
  2395. │ │
  2396. │ F2 File │
  2397. └──────────────────┘", output);
  2398. TestHelpers.AssertDriverColorsAre (@"
  2399. 00000000000000000000
  2400. 01111111111111111110
  2401. 00000000000000000000
  2402. 00000000000000000000
  2403. 00000000000000000000
  2404. 00000222222222200000
  2405. 00000222222222200000
  2406. 00000222222222200000
  2407. 00000222222222200000
  2408. 00000222222222200000
  2409. 00000222222222200000
  2410. 00000222222222200000
  2411. 00000222222222200000
  2412. 00000222222222200000
  2413. 00000222222222200000
  2414. 00000000000000000000
  2415. 00000000000000000000
  2416. 00000000000000000000
  2417. 01331111111111111110
  2418. 00000000000000000000", attributes);
  2419. }
  2420. [Fact, AutoInitShutdown]
  2421. public void Application_QuitKey_Close_Current_MdiChild ()
  2422. {
  2423. var top = Top_With_MenuBar_And_StatusBar (false, true);
  2424. var win = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  2425. Assert.True (top.IsMdiContainer);
  2426. var iterations = -1;
  2427. Application.Iteration += () => {
  2428. iterations++;
  2429. if (iterations == 0) {
  2430. Assert.True (top.Running);
  2431. Assert.False (win.Running);
  2432. Assert.Equal (top, Application.Current);
  2433. Application.Run (win);
  2434. } else if (iterations == 1) {
  2435. Assert.True (top.Running);
  2436. Assert.True (win.Running);
  2437. Assert.Equal (win, Application.Current);
  2438. ReflectionTools.InvokePrivate (
  2439. typeof (Application),
  2440. "ProcessKeyEvent",
  2441. new KeyEvent (Application.QuitKey, new KeyModifiers ()));
  2442. } else if (iterations == 2) {
  2443. Assert.True (top.Running);
  2444. Assert.False (win.Running);
  2445. Assert.Equal (top, Application.Current);
  2446. ReflectionTools.InvokePrivate (
  2447. typeof (Application),
  2448. "ProcessKeyEvent",
  2449. new KeyEvent (Application.QuitKey, new KeyModifiers ()));
  2450. }
  2451. };
  2452. Application.Run (top);
  2453. Assert.False (top.Running);
  2454. Assert.False (win.Running);
  2455. Assert.Null (Application.Current);
  2456. Assert.Equal (2, iterations);
  2457. }
  2458. [Fact, AutoInitShutdown]
  2459. public void Clicking_On_MdiContainer_With_MostFocused_Null_Or_Invalid_Maintain_Current_Child_Focused ()
  2460. {
  2461. var top = Top_With_MenuBar_And_StatusBar (false, true, false);
  2462. var win1 = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  2463. var tf1 = new TextField () { Width = 6 };
  2464. win1.Add (tf1);
  2465. var win2 = Window_With_TopLeft_TopRight_BottomLeft_BottomRight_Labels ();
  2466. var tf2 = new TextField () { Width = 6 };
  2467. win2.Add (tf2);
  2468. win2.X = Pos.Right (win1);
  2469. Assert.True (top.IsMdiContainer);
  2470. var iterations = -1;
  2471. Application.Iteration += () => {
  2472. iterations++;
  2473. if (iterations == 0) {
  2474. Assert.True (top.Running);
  2475. Assert.False (win1.Running);
  2476. Assert.False (win2.Running);
  2477. Assert.Equal (top, Application.Current);
  2478. Application.Run (win1);
  2479. } else if (iterations == 1) {
  2480. Assert.True (top.Running);
  2481. Assert.True (win1.Running);
  2482. Assert.False (win2.Running);
  2483. Assert.Equal (win1, Application.Current);
  2484. Application.Run (win2);
  2485. } else if (iterations == 2) {
  2486. Assert.True (top.Running);
  2487. Assert.True (win1.Running);
  2488. Assert.True (win2.Running);
  2489. Assert.Equal (win2, Application.Current);
  2490. Assert.Equal (tf2, win2.MostFocused);
  2491. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  2492. Assert.Equal (new Rect (1, 2, 10, 10), win1.Frame);
  2493. Assert.Equal (new Rect (11, 2, 10, 10), win2.Frame);
  2494. ReflectionTools.InvokePrivate (
  2495. typeof (Application),
  2496. "ProcessMouseEvent",
  2497. new MouseEvent () {
  2498. X = 30,
  2499. Y = 2,
  2500. Flags = MouseFlags.Button1Clicked
  2501. });
  2502. } else if (iterations == 3) {
  2503. Assert.True (top.Running);
  2504. Assert.True (win1.Running);
  2505. Assert.True (win2.Running);
  2506. Assert.Equal (win2, Application.Current);
  2507. Assert.Equal (tf2, win2.MostFocused);
  2508. ReflectionTools.InvokePrivate (
  2509. typeof (Application),
  2510. "ProcessMouseEvent",
  2511. new MouseEvent () {
  2512. X = 1,
  2513. Y = 2,
  2514. Flags = MouseFlags.Button1Clicked
  2515. });
  2516. } else if (iterations == 4) {
  2517. Assert.True (top.Running);
  2518. Assert.True (win1.Running);
  2519. Assert.True (win2.Running);
  2520. Assert.Equal (win1, Application.Current);
  2521. Assert.Equal (tf1, win1.MostFocused);
  2522. ReflectionTools.InvokePrivate (
  2523. typeof (Application),
  2524. "ProcessMouseEvent",
  2525. new MouseEvent () {
  2526. X = 30,
  2527. Y = 2,
  2528. Flags = MouseFlags.Button1Clicked
  2529. });
  2530. } else if (iterations == 5) {
  2531. Assert.True (top.Running);
  2532. Assert.True (win1.Running);
  2533. Assert.True (win2.Running);
  2534. Assert.Equal (win1, Application.Current);
  2535. Assert.Equal (tf1, win1.MostFocused);
  2536. ReflectionTools.InvokePrivate (
  2537. typeof (Application),
  2538. "ProcessKeyEvent",
  2539. new KeyEvent (Application.QuitKey, new KeyModifiers ()));
  2540. } else if (iterations == 6) {
  2541. Assert.True (top.Running);
  2542. Assert.False (win1.Running);
  2543. Assert.True (win2.Running);
  2544. Assert.Equal (win2, Application.Current);
  2545. Assert.Equal (tf2, win2.MostFocused);
  2546. ReflectionTools.InvokePrivate (
  2547. typeof (Application),
  2548. "ProcessKeyEvent",
  2549. new KeyEvent (Application.QuitKey, new KeyModifiers ()));
  2550. } else if (iterations == 7) {
  2551. Assert.True (top.Running);
  2552. Assert.False (win1.Running);
  2553. Assert.False (win2.Running);
  2554. Assert.Equal (top, Application.Current);
  2555. Assert.Equal (top.Subviews [0], top.MostFocused);
  2556. Assert.Equal ("ContentView", top.Subviews [0].GetType ().Name);
  2557. ReflectionTools.InvokePrivate (
  2558. typeof (Application),
  2559. "ProcessKeyEvent",
  2560. new KeyEvent (Application.QuitKey, new KeyModifiers ()));
  2561. }
  2562. };
  2563. Application.Run (top);
  2564. Assert.False (top.Running);
  2565. Assert.False (win1.Running);
  2566. Assert.False (win2.Running);
  2567. Assert.Null (Application.Current);
  2568. Assert.Equal (7, iterations);
  2569. }
  2570. [Fact, AutoInitShutdown]
  2571. public void MdiChildes_Null_Does_Not_Throws ()
  2572. {
  2573. var top = Top_With_MenuBar_And_StatusBar (false, true);
  2574. Assert.True (top.IsMdiContainer);
  2575. Application.Begin (top);
  2576. var mdiChildes = Application.MdiChildes;
  2577. Assert.Empty (mdiChildes);
  2578. top.IsMdiContainer = false;
  2579. var exception = Record.Exception (() => mdiChildes = Application.MdiChildes);
  2580. Assert.Null (exception);
  2581. Assert.Empty (mdiChildes);
  2582. }
  2583. }
  2584. }