ScrollBarViewTests.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Reflection;
  5. using Xunit;
  6. using Xunit.Abstractions;
  7. namespace Terminal.Gui.ViewTests {
  8. public class ScrollBarViewTests {
  9. readonly ITestOutputHelper output;
  10. public ScrollBarViewTests (ITestOutputHelper output)
  11. {
  12. this.output = output;
  13. }
  14. // This class enables test functions annotated with the [InitShutdown] attribute
  15. // to have a function called before the test function is called and after.
  16. //
  17. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  18. // as a pair, and b) all unit test functions should be atomic.
  19. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  20. public class ScrollBarAutoInitShutdownAttribute : AutoInitShutdownAttribute {
  21. public override void Before (MethodInfo methodUnderTest)
  22. {
  23. base.Before (methodUnderTest);
  24. ScrollBarViewTests._hostView = new HostView () {
  25. Width = Dim.Fill (),
  26. Height = Dim.Fill (),
  27. Top = 0,
  28. Lines = 30,
  29. Left = 0,
  30. Cols = 100
  31. };
  32. Application.Top.Add (ScrollBarViewTests._hostView);
  33. }
  34. public override void After (MethodInfo methodUnderTest)
  35. {
  36. ScrollBarViewTests._hostView = null;
  37. base.After (methodUnderTest);
  38. }
  39. }
  40. public class HostView : View {
  41. public int Top { get; set; }
  42. public int Lines { get; set; }
  43. public int Left { get; set; }
  44. public int Cols { get; set; }
  45. }
  46. private static HostView _hostView;
  47. private ScrollBarView _scrollBar;
  48. private bool _added;
  49. private void AddHandlers ()
  50. {
  51. if (!_added) {
  52. _hostView.DrawContent += _hostView_DrawContent;
  53. _scrollBar.ChangedPosition += _scrollBar_ChangedPosition;
  54. _scrollBar.OtherScrollBarView.ChangedPosition += _scrollBar_OtherScrollBarView_ChangedPosition;
  55. }
  56. _added = true;
  57. }
  58. private void RemoveHandlers ()
  59. {
  60. if (_added) {
  61. _hostView.DrawContent -= _hostView_DrawContent;
  62. _scrollBar.ChangedPosition -= _scrollBar_ChangedPosition;
  63. _scrollBar.OtherScrollBarView.ChangedPosition -= _scrollBar_OtherScrollBarView_ChangedPosition;
  64. }
  65. _added = false;
  66. }
  67. private void _hostView_DrawContent (Rect obj)
  68. {
  69. _scrollBar.Size = _hostView.Lines;
  70. _scrollBar.Position = _hostView.Top;
  71. _scrollBar.OtherScrollBarView.Size = _hostView.Cols;
  72. _scrollBar.OtherScrollBarView.Position = _hostView.Left;
  73. _scrollBar.Refresh ();
  74. }
  75. private void _scrollBar_ChangedPosition ()
  76. {
  77. _hostView.Top = _scrollBar.Position;
  78. if (_hostView.Top != _scrollBar.Position) {
  79. _scrollBar.Position = _hostView.Top;
  80. }
  81. _hostView.SetNeedsDisplay ();
  82. }
  83. private void _scrollBar_OtherScrollBarView_ChangedPosition ()
  84. {
  85. _hostView.Left = _scrollBar.OtherScrollBarView.Position;
  86. if (_hostView.Left != _scrollBar.OtherScrollBarView.Position) {
  87. _scrollBar.OtherScrollBarView.Position = _hostView.Left;
  88. }
  89. _hostView.SetNeedsDisplay ();
  90. }
  91. [Fact]
  92. [ScrollBarAutoInitShutdown]
  93. public void Hosting_A_Null_View_To_A_ScrollBarView_Throws_ArgumentNullException ()
  94. {
  95. Assert.Throws<ArgumentNullException> ("The host parameter can't be null.",
  96. () => new ScrollBarView (null, true));
  97. Assert.Throws<ArgumentNullException> ("The host parameter can't be null.",
  98. () => new ScrollBarView (null, false));
  99. }
  100. [Fact]
  101. [ScrollBarAutoInitShutdown]
  102. public void Hosting_A_Null_SuperView_View_To_A_ScrollBarView_Throws_ArgumentNullException ()
  103. {
  104. Assert.Throws<ArgumentNullException> ("The host SuperView parameter can't be null.",
  105. () => new ScrollBarView (new View (), true));
  106. Assert.Throws<ArgumentNullException> ("The host SuperView parameter can't be null.",
  107. () => new ScrollBarView (new View (), false));
  108. }
  109. [Fact]
  110. [ScrollBarAutoInitShutdown]
  111. public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException ()
  112. {
  113. var top = new Toplevel ();
  114. var host = new View ();
  115. top.Add (host);
  116. var v = new ScrollBarView (host, true);
  117. var h = new ScrollBarView (host, true);
  118. Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
  119. Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
  120. }
  121. [Fact]
  122. [ScrollBarAutoInitShutdown]
  123. public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException ()
  124. {
  125. var top = new Toplevel ();
  126. var host = new View ();
  127. top.Add (host);
  128. var v = new ScrollBarView (host, false);
  129. var h = new ScrollBarView (host, false);
  130. Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
  131. Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
  132. }
  133. [Fact]
  134. [ScrollBarAutoInitShutdown]
  135. public void Scrolling_With_Default_Constructor_Do_Not_Scroll ()
  136. {
  137. var sbv = new ScrollBarView {
  138. Position = 1
  139. };
  140. Assert.NotEqual (1, sbv.Position);
  141. Assert.Equal (0, sbv.Position);
  142. }
  143. [Fact]
  144. [ScrollBarAutoInitShutdown]
  145. public void Hosting_A_View_To_A_ScrollBarView ()
  146. {
  147. RemoveHandlers ();
  148. _scrollBar = new ScrollBarView (_hostView, true);
  149. Assert.True (_scrollBar.IsVertical);
  150. Assert.False (_scrollBar.OtherScrollBarView.IsVertical);
  151. Assert.Equal (_scrollBar.Position, _hostView.Top);
  152. Assert.NotEqual (_scrollBar.Size, _hostView.Lines);
  153. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  154. Assert.NotEqual (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
  155. AddHandlers ();
  156. _hostView.SuperView.LayoutSubviews ();
  157. _hostView.Redraw (_hostView.Bounds);
  158. Assert.Equal (_scrollBar.Position, _hostView.Top);
  159. Assert.Equal (_scrollBar.Size, _hostView.Lines);
  160. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  161. Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
  162. }
  163. [Fact]
  164. [ScrollBarAutoInitShutdown]
  165. public void ChangedPosition_Update_The_Hosted_View ()
  166. {
  167. Hosting_A_View_To_A_ScrollBarView ();
  168. AddHandlers ();
  169. _scrollBar.Position = 2;
  170. Assert.Equal (_scrollBar.Position, _hostView.Top);
  171. _scrollBar.OtherScrollBarView.Position = 5;
  172. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  173. }
  174. [Fact]
  175. [ScrollBarAutoInitShutdown]
  176. public void ChangedPosition_Scrolling ()
  177. {
  178. Hosting_A_View_To_A_ScrollBarView ();
  179. AddHandlers ();
  180. for (int i = 0; i < _scrollBar.Size; i++) {
  181. _scrollBar.Position += 1;
  182. Assert.Equal (_scrollBar.Position, _hostView.Top);
  183. }
  184. for (int i = _scrollBar.Size - 1; i >= 0; i--) {
  185. _scrollBar.Position -= 1;
  186. Assert.Equal (_scrollBar.Position, _hostView.Top);
  187. }
  188. for (int i = 0; i < _scrollBar.OtherScrollBarView.Size; i++) {
  189. _scrollBar.OtherScrollBarView.Position += i;
  190. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  191. }
  192. for (int i = _scrollBar.OtherScrollBarView.Size - 1; i >= 0; i--) {
  193. _scrollBar.OtherScrollBarView.Position -= 1;
  194. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  195. }
  196. }
  197. [Fact]
  198. [ScrollBarAutoInitShutdown]
  199. public void ChangedPosition_Negative_Value ()
  200. {
  201. Hosting_A_View_To_A_ScrollBarView ();
  202. AddHandlers ();
  203. _scrollBar.Position = -20;
  204. Assert.Equal (0, _scrollBar.Position);
  205. Assert.Equal (_scrollBar.Position, _hostView.Top);
  206. _scrollBar.OtherScrollBarView.Position = -50;
  207. Assert.Equal (0, _scrollBar.OtherScrollBarView.Position);
  208. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  209. }
  210. [Fact]
  211. [ScrollBarAutoInitShutdown]
  212. public void DrawContent_Update_The_ScrollBarView_Position ()
  213. {
  214. Hosting_A_View_To_A_ScrollBarView ();
  215. AddHandlers ();
  216. _hostView.Top = 3;
  217. _hostView.Redraw (_hostView.Bounds);
  218. Assert.Equal (_scrollBar.Position, _hostView.Top);
  219. _hostView.Left = 6;
  220. _hostView.Redraw (_hostView.Bounds);
  221. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  222. }
  223. [Fact]
  224. [ScrollBarAutoInitShutdown]
  225. public void OtherScrollBarView_Not_Null ()
  226. {
  227. Hosting_A_View_To_A_ScrollBarView ();
  228. AddHandlers ();
  229. Assert.NotNull (_scrollBar.OtherScrollBarView);
  230. Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView);
  231. Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar);
  232. }
  233. [Fact]
  234. [ScrollBarAutoInitShutdown]
  235. public void ShowScrollIndicator_Check ()
  236. {
  237. Hosting_A_View_To_A_ScrollBarView ();
  238. AddHandlers ();
  239. Assert.True (_scrollBar.ShowScrollIndicator);
  240. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  241. }
  242. [Fact]
  243. [ScrollBarAutoInitShutdown]
  244. public void KeepContentAlwaysInViewport_True ()
  245. {
  246. Hosting_A_View_To_A_ScrollBarView ();
  247. AddHandlers ();
  248. Assert.Equal (80, _hostView.Bounds.Width);
  249. Assert.Equal (25, _hostView.Bounds.Height);
  250. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  251. Assert.Equal (24, _scrollBar.Bounds.Height);
  252. Assert.Equal (30, _scrollBar.Size);
  253. Assert.Equal (100, _scrollBar.OtherScrollBarView.Size);
  254. Assert.True (_scrollBar.ShowScrollIndicator);
  255. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  256. Assert.True (_scrollBar.Visible);
  257. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  258. _scrollBar.Position = 50;
  259. Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height);
  260. Assert.Equal (_scrollBar.Position, _hostView.Top);
  261. Assert.Equal (6, _scrollBar.Position);
  262. Assert.Equal (6, _hostView.Top);
  263. Assert.True (_scrollBar.ShowScrollIndicator);
  264. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  265. Assert.True (_scrollBar.Visible);
  266. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  267. _scrollBar.OtherScrollBarView.Position = 150;
  268. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width);
  269. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  270. Assert.Equal (21, _scrollBar.OtherScrollBarView.Position);
  271. Assert.Equal (21, _hostView.Left);
  272. Assert.True (_scrollBar.ShowScrollIndicator);
  273. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  274. Assert.True (_scrollBar.Visible);
  275. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  276. }
  277. [Fact]
  278. [ScrollBarAutoInitShutdown]
  279. public void KeepContentAlwaysInViewport_False ()
  280. {
  281. Hosting_A_View_To_A_ScrollBarView ();
  282. AddHandlers ();
  283. _scrollBar.KeepContentAlwaysInViewport = false;
  284. _scrollBar.Position = 50;
  285. Assert.Equal (_scrollBar.Position, _scrollBar.Size - 1);
  286. Assert.Equal (_scrollBar.Position, _hostView.Top);
  287. Assert.Equal (29, _scrollBar.Position);
  288. Assert.Equal (29, _hostView.Top);
  289. _scrollBar.OtherScrollBarView.Position = 150;
  290. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1);
  291. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  292. Assert.Equal (99, _scrollBar.OtherScrollBarView.Position);
  293. Assert.Equal (99, _hostView.Left);
  294. }
  295. [Fact]
  296. [ScrollBarAutoInitShutdown]
  297. public void AutoHideScrollBars_Check ()
  298. {
  299. Hosting_A_View_To_A_ScrollBarView ();
  300. AddHandlers ();
  301. _hostView.Redraw (_hostView.Bounds);
  302. Assert.True (_scrollBar.ShowScrollIndicator);
  303. Assert.True (_scrollBar.Visible);
  304. Assert.Equal ("Dim.Absolute(1)", _scrollBar.Width.ToString ());
  305. Assert.Equal (1, _scrollBar.Bounds.Width);
  306. Assert.Equal ("Dim.Combine(DimView(side=Height, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  307. _scrollBar.Height.ToString ());
  308. Assert.Equal (24, _scrollBar.Bounds.Height);
  309. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  310. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  311. Assert.Equal ("Dim.Combine(DimView(side=Width, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  312. _scrollBar.OtherScrollBarView.Width.ToString ());
  313. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  314. Assert.Equal ("Dim.Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  315. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  316. _hostView.Lines = 10;
  317. _hostView.Redraw (_hostView.Bounds);
  318. Assert.False (_scrollBar.ShowScrollIndicator);
  319. Assert.False (_scrollBar.Visible);
  320. Assert.Equal ("Dim.Absolute(1)", _scrollBar.Width.ToString ());
  321. Assert.Equal (1, _scrollBar.Bounds.Width);
  322. Assert.Equal ("Dim.Combine(DimView(side=Height, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  323. _scrollBar.Height.ToString ());
  324. Assert.Equal (24, _scrollBar.Bounds.Height);
  325. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  326. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  327. Assert.Equal ("Dim.Combine(DimView(side=Width, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(0))",
  328. _scrollBar.OtherScrollBarView.Width.ToString ());
  329. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  330. Assert.Equal ("Dim.Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  331. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  332. _hostView.Cols = 60;
  333. _hostView.Redraw (_hostView.Bounds);
  334. Assert.False (_scrollBar.ShowScrollIndicator);
  335. Assert.False (_scrollBar.Visible);
  336. Assert.Equal ("Dim.Absolute(1)", _scrollBar.Width.ToString ());
  337. Assert.Equal (1, _scrollBar.Bounds.Width);
  338. Assert.Equal ("Dim.Combine(DimView(side=Height, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  339. _scrollBar.Height.ToString ());
  340. Assert.Equal (24, _scrollBar.Bounds.Height);
  341. Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  342. Assert.False (_scrollBar.OtherScrollBarView.Visible);
  343. Assert.Equal ("Dim.Combine(DimView(side=Width, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(0))",
  344. _scrollBar.OtherScrollBarView.Width.ToString ());
  345. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  346. Assert.Equal ("Dim.Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  347. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  348. _hostView.Lines = 40;
  349. _hostView.Redraw (_hostView.Bounds);
  350. Assert.True (_scrollBar.ShowScrollIndicator);
  351. Assert.True (_scrollBar.Visible);
  352. Assert.Equal ("Dim.Absolute(1)", _scrollBar.Width.ToString ());
  353. Assert.Equal (1, _scrollBar.Bounds.Width);
  354. Assert.Equal ("Dim.Combine(DimView(side=Height, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(0))",
  355. _scrollBar.Height.ToString ());
  356. Assert.Equal (25, _scrollBar.Bounds.Height);
  357. Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  358. Assert.False (_scrollBar.OtherScrollBarView.Visible);
  359. Assert.Equal ("Dim.Combine(DimView(side=Width, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(0))",
  360. _scrollBar.OtherScrollBarView.Width.ToString ());
  361. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  362. Assert.Equal ("Dim.Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  363. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  364. _hostView.Cols = 120;
  365. _hostView.Redraw (_hostView.Bounds);
  366. Assert.True (_scrollBar.ShowScrollIndicator);
  367. Assert.True (_scrollBar.Visible);
  368. Assert.Equal ("Dim.Absolute(1)", _scrollBar.Width.ToString ());
  369. Assert.Equal (1, _scrollBar.Bounds.Width);
  370. Assert.Equal ("Dim.Combine(DimView(side=Height, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  371. _scrollBar.Height.ToString ());
  372. Assert.Equal (24, _scrollBar.Bounds.Height);
  373. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  374. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  375. Assert.Equal ("Dim.Combine(DimView(side=Width, target=HostView()({X=0,Y=0,Width=80,Height=25}))-Dim.Absolute(1))",
  376. _scrollBar.OtherScrollBarView.Width.ToString ());
  377. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  378. Assert.Equal ("Dim.Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  379. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  380. }
  381. [Fact]
  382. public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refresh_Does_Not_Throws_An_Object_Null_Exception ()
  383. {
  384. var exception = Record.Exception (() => {
  385. Application.Init (new FakeDriver ());
  386. var top = Application.Top;
  387. var win = new Window () {
  388. X = 0,
  389. Y = 0,
  390. Width = Dim.Fill (),
  391. Height = Dim.Fill ()
  392. };
  393. List<string> source = new List<string> ();
  394. for (int i = 0; i < 50; i++) {
  395. source.Add ($"item {i}");
  396. }
  397. var listView = new ListView (source) {
  398. X = 0,
  399. Y = 0,
  400. Width = Dim.Fill (),
  401. Height = Dim.Fill ()
  402. };
  403. win.Add (listView);
  404. var newScrollBarView = new ScrollBarView (listView, true, false) {
  405. KeepContentAlwaysInViewport = true
  406. };
  407. win.Add (newScrollBarView);
  408. newScrollBarView.ChangedPosition += () => {
  409. listView.TopItem = newScrollBarView.Position;
  410. if (listView.TopItem != newScrollBarView.Position) {
  411. newScrollBarView.Position = listView.TopItem;
  412. }
  413. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  414. listView.SetNeedsDisplay ();
  415. };
  416. listView.DrawContent += (e) => {
  417. newScrollBarView.Size = listView.Source.Count;
  418. Assert.Equal (newScrollBarView.Size, listView.Source.Count);
  419. newScrollBarView.Position = listView.TopItem;
  420. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  421. newScrollBarView.Refresh ();
  422. };
  423. top.Ready += () => {
  424. newScrollBarView.Position = 45;
  425. Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.TopItem + (listView.TopItem - listView.Bounds.Height));
  426. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  427. Assert.Equal (27, newScrollBarView.Position);
  428. Assert.Equal (27, listView.TopItem);
  429. Application.RequestStop ();
  430. };
  431. top.Add (win);
  432. Application.Run ();
  433. Application.Shutdown ();
  434. });
  435. Assert.Null (exception);
  436. }
  437. [Fact]
  438. public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refresh_Does_Not_Throws_An_Object_Null_Exception ()
  439. {
  440. var exception = Record.Exception (() => {
  441. Application.Init (new FakeDriver ());
  442. var top = Application.Top;
  443. var win = new Window () {
  444. X = 0,
  445. Y = 0,
  446. Width = Dim.Fill (),
  447. Height = Dim.Fill ()
  448. };
  449. List<string> source = new List<string> ();
  450. for (int i = 0; i < 50; i++) {
  451. var text = $"item {i} - ";
  452. for (int j = 0; j < 160; j++) {
  453. var col = j.ToString ();
  454. text += col.Length == 1 ? col [0] : col [1];
  455. }
  456. source.Add (text);
  457. }
  458. var listView = new ListView (source) {
  459. X = 0,
  460. Y = 0,
  461. Width = Dim.Fill (),
  462. Height = Dim.Fill ()
  463. };
  464. win.Add (listView);
  465. var newScrollBarView = new ScrollBarView (listView, false, false) {
  466. KeepContentAlwaysInViewport = true
  467. };
  468. win.Add (newScrollBarView);
  469. newScrollBarView.ChangedPosition += () => {
  470. listView.LeftItem = newScrollBarView.Position;
  471. if (listView.LeftItem != newScrollBarView.Position) {
  472. newScrollBarView.Position = listView.LeftItem;
  473. }
  474. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  475. listView.SetNeedsDisplay ();
  476. };
  477. listView.DrawContent += (e) => {
  478. newScrollBarView.Size = listView.Maxlength;
  479. Assert.Equal (newScrollBarView.Size, listView.Maxlength);
  480. newScrollBarView.Position = listView.LeftItem;
  481. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  482. newScrollBarView.Refresh ();
  483. };
  484. top.Ready += () => {
  485. newScrollBarView.Position = 100;
  486. Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width));
  487. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  488. Assert.Equal (92, newScrollBarView.Position);
  489. Assert.Equal (92, listView.LeftItem);
  490. Application.RequestStop ();
  491. };
  492. top.Add (win);
  493. Application.Run ();
  494. Application.Shutdown ();
  495. });
  496. Assert.Null (exception);
  497. }
  498. [Fact]
  499. [AutoInitShutdown]
  500. public void Internal_Tests ()
  501. {
  502. var top = Application.Top;
  503. Assert.Equal (new Rect (0, 0, 80, 25), top.Bounds);
  504. var view = new View () { Width = Dim.Fill (), Height = Dim.Fill () };
  505. top.Add (view);
  506. var sbv = new ScrollBarView (view, true);
  507. top.Add (sbv);
  508. Assert.Equal (view, sbv.Host);
  509. sbv.Size = 40;
  510. sbv.Position = 0;
  511. sbv.OtherScrollBarView.Size = 100;
  512. sbv.OtherScrollBarView.Position = 0;
  513. // Host bounds is empty.
  514. Assert.False (sbv.CanScroll (10, out int max, sbv.IsVertical));
  515. Assert.Equal (0, max);
  516. Assert.False (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical));
  517. Assert.Equal (0, max);
  518. // They aren't visible so they aren't drawn.
  519. Assert.False (sbv.Visible);
  520. Assert.False (sbv.OtherScrollBarView.Visible);
  521. top.LayoutSubviews ();
  522. // Now the host bounds is not empty.
  523. Assert.True (sbv.CanScroll (10, out max, sbv.IsVertical));
  524. Assert.Equal (10, max);
  525. Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical));
  526. Assert.Equal (10, max);
  527. Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical));
  528. Assert.Equal (40, sbv.Size);
  529. Assert.Equal (15, max); // 15+25=40
  530. Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical));
  531. Assert.Equal (100, sbv.OtherScrollBarView.Size);
  532. Assert.Equal (20, max); // 20+80=100
  533. Assert.False (sbv.Visible);
  534. Assert.False (sbv.OtherScrollBarView.Visible);
  535. sbv.KeepContentAlwaysInViewport = false;
  536. sbv.OtherScrollBarView.KeepContentAlwaysInViewport = false;
  537. Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical));
  538. Assert.Equal (39, max);
  539. Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical));
  540. Assert.Equal (99, max);
  541. Assert.True (sbv.Visible);
  542. Assert.True (sbv.OtherScrollBarView.Visible);
  543. }
  544. private class TextViewScrollBarView : ScrollBarView {
  545. private TextView _textView;
  546. public TextViewScrollBarView (TextView textView) : base (textView, true)
  547. {
  548. _textView = textView;
  549. ChangedPosition += TextViewScrollBarView_ChangedPosition;
  550. OtherScrollBarView.ChangedPosition += OtherScrollBarView_ChangedPosition;
  551. VisibleChanged += TextViewScrollBarView_VisibleChanged;
  552. OtherScrollBarView.VisibleChanged += OtherScrollBarView_VisibleChanged;
  553. _textView.DrawContent += TextView_DrawContent;
  554. Initialized += TextViewScrollBarView_Initialized;
  555. OtherScrollBarView.Initialized += OtherScrollBarView_Initialized;
  556. }
  557. private void OtherScrollBarView_Initialized (object sender, EventArgs e)
  558. {
  559. OtherScrollBarView_VisibleChanged ();
  560. }
  561. private void TextViewScrollBarView_Initialized (object sender, EventArgs e)
  562. {
  563. TextViewScrollBarView_VisibleChanged ();
  564. }
  565. private void TextView_DrawContent (Rect obj)
  566. {
  567. Size = _textView.Lines;
  568. Position = _textView.TopRow;
  569. if (OtherScrollBarView != null) {
  570. OtherScrollBarView.Size = _textView.Maxlength;
  571. OtherScrollBarView.Position = _textView.LeftColumn;
  572. }
  573. LayoutSubviews ();
  574. Refresh ();
  575. }
  576. private void OtherScrollBarView_VisibleChanged ()
  577. {
  578. if (OtherScrollBarView.Visible && _textView.BottomOffset == 0) {
  579. _textView.BottomOffset = 1;
  580. } else if (!OtherScrollBarView.Visible && _textView.BottomOffset == 1) {
  581. _textView.BottomOffset = 0;
  582. }
  583. }
  584. private void TextViewScrollBarView_VisibleChanged ()
  585. {
  586. if (Visible && _textView.RightOffset == 0) {
  587. _textView.RightOffset = 1;
  588. } else if (!Visible && _textView.RightOffset == 1) {
  589. _textView.RightOffset = 0;
  590. }
  591. }
  592. private void OtherScrollBarView_ChangedPosition ()
  593. {
  594. _textView.LeftColumn = OtherScrollBarView.Position;
  595. if (_textView.LeftColumn != OtherScrollBarView.Position) {
  596. OtherScrollBarView.Position = _textView.LeftColumn;
  597. }
  598. _textView.SetNeedsDisplay ();
  599. }
  600. private void TextViewScrollBarView_ChangedPosition ()
  601. {
  602. _textView.TopRow = Position;
  603. if (_textView.TopRow != Position) {
  604. Position = _textView.TopRow;
  605. }
  606. _textView.SetNeedsDisplay ();
  607. }
  608. }
  609. [Fact, AutoInitShutdown]
  610. public void Hosting_ShowBothScrollIndicator_Invisible ()
  611. {
  612. var textView = new TextView () {
  613. Width = Dim.Fill (),
  614. Height = Dim.Fill (),
  615. Text = "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too."
  616. };
  617. var win = new Window ("Test") {
  618. Width = Dim.Fill (),
  619. Height = Dim.Fill ()
  620. };
  621. win.Add (textView);
  622. var scrollBar = new TextViewScrollBarView (textView);
  623. Application.Top.Add (win);
  624. Application.Begin (Application.Top);
  625. ((FakeDriver)Application.Driver).SetBufferSize (45, 20);
  626. Assert.True (scrollBar.AutoHideScrollBars);
  627. Assert.Equal (5, textView.Lines);
  628. Assert.Equal (42, textView.Maxlength);
  629. Assert.Equal (0, textView.LeftColumn);
  630. Assert.Equal (0, scrollBar.Position);
  631. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  632. var expected = @"
  633. ┌ Test ─────────────────────────────────────┐
  634. │This is the help text for the Second Step. │
  635. │ │
  636. │Press the button to see a message box. │
  637. │ │
  638. │Enter name too. │
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. │ │
  651. │ │
  652. └───────────────────────────────────────────┘
  653. ";
  654. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  655. Assert.Equal (new Rect (0, 0, 45, 20), pos);
  656. textView.WordWrap = true;
  657. ((FakeDriver)Application.Driver).SetBufferSize (26, 20);
  658. Application.Refresh ();
  659. Assert.True (textView.WordWrap);
  660. Assert.True (scrollBar.AutoHideScrollBars);
  661. Assert.Equal (7, textView.Lines);
  662. Assert.Equal (22, textView.Maxlength);
  663. Assert.Equal (0, textView.LeftColumn);
  664. Assert.Equal (0, scrollBar.Position);
  665. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  666. expected = @"
  667. ┌ Test ──────────────────┐
  668. │This is the help text │
  669. │for the Second Step. │
  670. │ │
  671. │Press the button to │
  672. │see a message box. │
  673. │ │
  674. │Enter name too. │
  675. │ │
  676. │ │
  677. │ │
  678. │ │
  679. │ │
  680. │ │
  681. │ │
  682. │ │
  683. │ │
  684. │ │
  685. │ │
  686. └────────────────────────┘
  687. ";
  688. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  689. Assert.Equal (new Rect (0, 0, 26, 20), pos);
  690. ((FakeDriver)Application.Driver).SetBufferSize (10, 10);
  691. Application.Refresh ();
  692. Assert.True (textView.WordWrap);
  693. Assert.True (scrollBar.AutoHideScrollBars);
  694. Assert.Equal (20, textView.Lines);
  695. Assert.Equal (7, textView.Maxlength);
  696. Assert.Equal (0, textView.LeftColumn);
  697. Assert.Equal (0, scrollBar.Position);
  698. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  699. expected = @"
  700. ┌ Test ──┐
  701. │This ▲│
  702. │is the ┬│
  703. │help ││
  704. │text ┴│
  705. │for ░│
  706. │the ░│
  707. │Second ░│
  708. │Step. ▼│
  709. └────────┘
  710. ";
  711. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  712. Assert.Equal (new Rect (0, 0, 10, 10), pos);
  713. }
  714. [Fact, AutoInitShutdown]
  715. public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero ()
  716. {
  717. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  718. var label = new Label (text);
  719. Application.Top.Add (label);
  720. var sbv = new ScrollBarView (label, true, true) {
  721. Size = 100,
  722. };
  723. sbv.OtherScrollBarView.Size = 100;
  724. Application.Begin (Application.Top);
  725. Assert.Equal (100, sbv.Size);
  726. Assert.Equal (100, sbv.OtherScrollBarView.Size);
  727. Assert.True (sbv.ShowScrollIndicator);
  728. Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator);
  729. Assert.True (sbv.Visible);
  730. Assert.True (sbv.OtherScrollBarView.Visible);
  731. TestHelpers.AssertDriverContentsWithFrameAre (@"
  732. This is a tes▲
  733. This is a tes┬
  734. This is a tes┴
  735. This is a tes░
  736. This is a tes▼
  737. ◄├─┤░░░░░░░░►
  738. ", output);
  739. sbv.Size = 0;
  740. sbv.OtherScrollBarView.Size = 0;
  741. Assert.Equal (0, sbv.Size);
  742. Assert.Equal (0, sbv.OtherScrollBarView.Size);
  743. Assert.False (sbv.ShowScrollIndicator);
  744. Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator);
  745. Assert.False (sbv.Visible);
  746. Assert.False (sbv.OtherScrollBarView.Visible);
  747. Application.Top.Redraw (Application.Top.Bounds);
  748. TestHelpers.AssertDriverContentsWithFrameAre (@"
  749. This is a test
  750. This is a test
  751. This is a test
  752. This is a test
  753. This is a test
  754. This is a test
  755. ", output);
  756. sbv.Size = 50;
  757. sbv.OtherScrollBarView.Size = 50;
  758. Assert.Equal (50, sbv.Size);
  759. Assert.Equal (50, sbv.OtherScrollBarView.Size);
  760. Assert.True (sbv.ShowScrollIndicator);
  761. Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator);
  762. Assert.True (sbv.Visible);
  763. Assert.True (sbv.OtherScrollBarView.Visible);
  764. Application.Top.Redraw (Application.Top.Bounds);
  765. TestHelpers.AssertDriverContentsWithFrameAre (@"
  766. This is a tes▲
  767. This is a tes┬
  768. This is a tes┴
  769. This is a tes░
  770. This is a tes▼
  771. ◄├──┤░░░░░░░►
  772. ", output);
  773. }
  774. [Fact, AutoInitShutdown]
  775. public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero ()
  776. {
  777. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  778. var label = new Label (text);
  779. Application.Top.Add (label);
  780. var sbv = new ScrollBarView (label, true, false) {
  781. Size = 100,
  782. };
  783. Application.Begin (Application.Top);
  784. Assert.Equal (100, sbv.Size);
  785. Assert.Null (sbv.OtherScrollBarView);
  786. Assert.True (sbv.ShowScrollIndicator);
  787. Assert.True (sbv.Visible);
  788. TestHelpers.AssertDriverContentsWithFrameAre (@"
  789. This is a tes▲
  790. This is a tes┬
  791. This is a tes┴
  792. This is a tes░
  793. This is a tes░
  794. This is a tes▼
  795. ", output);
  796. sbv.Size = 0;
  797. Assert.Equal (0, sbv.Size);
  798. Assert.False (sbv.ShowScrollIndicator);
  799. Assert.False (sbv.Visible);
  800. Application.Top.Redraw (Application.Top.Bounds);
  801. TestHelpers.AssertDriverContentsWithFrameAre (@"
  802. This is a test
  803. This is a test
  804. This is a test
  805. This is a test
  806. This is a test
  807. This is a test
  808. ", output);
  809. }
  810. [Fact, AutoInitShutdown]
  811. public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Respond_To_Events ()
  812. {
  813. var clicked = false;
  814. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  815. var label = new Label (text) { Width = 14, Height = 5 };
  816. var btn = new Button (14, 0, "Click Me!");
  817. btn.Clicked += () => clicked = true;
  818. Application.Top.Add (label, btn);
  819. var sbv = new ScrollBarView (label, true, false) {
  820. Size = 5,
  821. };
  822. Application.Begin (Application.Top);
  823. Assert.Equal (5, sbv.Size);
  824. Assert.Null (sbv.OtherScrollBarView);
  825. Assert.False (sbv.ShowScrollIndicator);
  826. Assert.False (sbv.Visible);
  827. TestHelpers.AssertDriverContentsWithFrameAre (@"
  828. This is a test[ Click Me! ]
  829. This is a test
  830. This is a test
  831. This is a test
  832. This is a test
  833. ", output);
  834. ReflectionTools.InvokePrivate (
  835. typeof (Application),
  836. "ProcessMouseEvent",
  837. new MouseEvent () {
  838. X = 15,
  839. Y = 0,
  840. Flags = MouseFlags.Button1Clicked
  841. });
  842. Assert.Null (Application.MouseGrabView);
  843. Assert.True (clicked);
  844. clicked = false;
  845. sbv.Visible = true;
  846. Assert.Equal (5, sbv.Size);
  847. Assert.False (sbv.ShowScrollIndicator);
  848. Assert.True (sbv.Visible);
  849. Application.Top.Redraw (Application.Top.Bounds);
  850. TestHelpers.AssertDriverContentsWithFrameAre (@"
  851. This is a test[ Click Me! ]
  852. This is a test
  853. This is a test
  854. This is a test
  855. This is a test
  856. ", output);
  857. ReflectionTools.InvokePrivate (
  858. typeof (Application),
  859. "ProcessMouseEvent",
  860. new MouseEvent () {
  861. X = 15,
  862. Y = 0,
  863. Flags = MouseFlags.Button1Clicked
  864. });
  865. Assert.Null (Application.MouseGrabView);
  866. Assert.True (clicked);
  867. Assert.Equal (5, sbv.Size);
  868. Assert.False (sbv.ShowScrollIndicator);
  869. Assert.False (sbv.Visible);
  870. }
  871. [Fact, AutoInitShutdown]
  872. public void ScrollBarView_Inside_TextView_Always_Scroll ()
  873. {
  874. var text = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n1234567890\n";
  875. var tv1 = new TextView () {
  876. Id = "tv1",
  877. Width = Dim.Fill (),
  878. Height = Dim.Fill (),
  879. Text = text
  880. };
  881. var f1 = new FrameView () {
  882. Width = Dim.Fill (),
  883. Height = Dim.Percent (70)
  884. };
  885. f1.Add (tv1);
  886. var sBar1 = new TextViewScrollBarView (tv1);
  887. var tv2 = new TextView () {
  888. Id = "tv2",
  889. Width = Dim.Fill (),
  890. Height = Dim.Fill (),
  891. Text = text,
  892. ReadOnly = true
  893. };
  894. var f2 = new FrameView () {
  895. Y = Pos.Bottom (f1),
  896. Width = Dim.Fill (),
  897. Height = Dim.Fill ()
  898. };
  899. f2.Add (tv2);
  900. var sBar2 = new TextViewScrollBarView (tv2);
  901. var win = new Window () {
  902. Width = Dim.Fill (),
  903. Height = Dim.Fill ()
  904. };
  905. win.Add (f1, f2);
  906. Application.Top.Add (win);
  907. Application.Begin (Application.Top);
  908. ((FakeDriver)Application.Driver).SetBufferSize (10, 20);
  909. // sBar1
  910. Assert.True (sBar1.Visible);
  911. Assert.Equal (0, sBar1.Position);
  912. Assert.Equal (0, tv1.TopRow);
  913. Assert.False (sBar1.OtherScrollBarView.Visible);
  914. Assert.Equal (0, sBar1.OtherScrollBarView.Position);
  915. Assert.Equal (0, tv1.LeftColumn);
  916. Assert.Equal (0, tv1.BottomOffset);
  917. Assert.Equal (1, tv1.RightOffset);
  918. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  919. // sBar2
  920. Assert.True (sBar2.Visible);
  921. Assert.Equal (0, sBar2.Position);
  922. Assert.Equal (0, tv2.TopRow);
  923. Assert.False (sBar2.OtherScrollBarView.Visible);
  924. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  925. Assert.Equal (0, tv2.LeftColumn);
  926. Assert.Equal (0, tv2.BottomOffset);
  927. Assert.Equal (1, tv2.RightOffset);
  928. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  929. TestHelpers.AssertDriverContentsWithFrameAre (@"
  930. ┌────────┐
  931. │┌──────┐│
  932. ││1 ▲││
  933. ││2 ┬││
  934. ││3 │││
  935. ││4 │││
  936. ││5 │││
  937. ││6 │││
  938. ││7 │││
  939. ││8 ┴││
  940. ││9 ░││
  941. ││10 ▼││
  942. │└──────┘│
  943. │┌──────┐│
  944. ││1 ▲││
  945. ││2 ┬││
  946. ││3 ┴││
  947. ││4 ▼││
  948. │└──────┘│
  949. └────────┘", output);
  950. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 9, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  951. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 9, Flags = MouseFlags.Button1Released, View = sBar1 }));
  952. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  953. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  954. win.Redraw (win.Bounds);
  955. Application.MainLoop.MainIteration ();
  956. win.Redraw (win.Bounds);
  957. // sBar1
  958. Assert.True (sBar1.Visible);
  959. Assert.Equal (2, sBar1.Position);
  960. Assert.Equal (2, tv1.TopRow);
  961. Assert.True (sBar1.OtherScrollBarView.Visible);
  962. Assert.Equal (0, sBar1.OtherScrollBarView.Position);
  963. Assert.Equal (0, tv1.LeftColumn);
  964. Assert.Equal (1, tv1.BottomOffset);
  965. Assert.Equal (1, tv1.RightOffset);
  966. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  967. // sBar2
  968. Assert.True (sBar2.Visible);
  969. Assert.Equal (1, sBar2.Position);
  970. Assert.Equal (1, tv2.TopRow);
  971. Assert.False (sBar2.OtherScrollBarView.Visible);
  972. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  973. Assert.Equal (0, tv2.LeftColumn);
  974. Assert.Equal (0, tv2.BottomOffset);
  975. Assert.Equal (1, tv2.RightOffset);
  976. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  977. TestHelpers.AssertDriverContentsWithFrameAre (@"
  978. ┌────────┐
  979. │┌──────┐│
  980. ││3 ▲││
  981. ││4 ░││
  982. ││5 ┬││
  983. ││6 │││
  984. ││7 │││
  985. ││8 │││
  986. ││9 │││
  987. ││10 ┴││
  988. ││12345▼││
  989. ││◄├┤░► ││
  990. │└──────┘│
  991. │┌──────┐│
  992. ││2 ▲││
  993. ││3 ┬││
  994. ││4 ┴││
  995. ││5 ▼││
  996. │└──────┘│
  997. └────────┘", output);
  998. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 8, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  999. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 8, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1000. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1001. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1002. win.Redraw (win.Bounds);
  1003. Application.MainLoop.MainIteration ();
  1004. win.Redraw (win.Bounds);
  1005. // sBar1
  1006. Assert.True (sBar1.Visible);
  1007. Assert.Equal (3, sBar1.Position);
  1008. Assert.Equal (3, tv1.TopRow);
  1009. Assert.True (sBar1.OtherScrollBarView.Visible);
  1010. Assert.Equal (0, sBar1.OtherScrollBarView.Position);
  1011. Assert.Equal (0, tv1.LeftColumn);
  1012. Assert.Equal (1, tv1.BottomOffset);
  1013. Assert.Equal (1, tv1.RightOffset);
  1014. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1015. // sBar2
  1016. Assert.True (sBar2.Visible);
  1017. Assert.Equal (2, sBar2.Position);
  1018. Assert.Equal (2, tv2.TopRow);
  1019. Assert.False (sBar2.OtherScrollBarView.Visible);
  1020. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1021. Assert.Equal (0, tv2.LeftColumn);
  1022. Assert.Equal (0, tv2.BottomOffset);
  1023. Assert.Equal (1, tv2.RightOffset);
  1024. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1025. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1026. ┌────────┐
  1027. │┌──────┐│
  1028. ││4 ▲││
  1029. ││5 ░││
  1030. ││6 ┬││
  1031. ││7 │││
  1032. ││8 │││
  1033. ││9 │││
  1034. ││10 │││
  1035. ││12345┴││
  1036. ││ ▼││
  1037. ││◄├┤░► ││
  1038. │└──────┘│
  1039. │┌──────┐│
  1040. ││3 ▲││
  1041. ││4 ┬││
  1042. ││5 ┴││
  1043. ││6 ▼││
  1044. │└──────┘│
  1045. └────────┘", output);
  1046. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1047. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1048. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1049. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1050. win.Redraw (win.Bounds);
  1051. Application.MainLoop.MainIteration ();
  1052. win.Redraw (win.Bounds);
  1053. // sBar1
  1054. Assert.True (sBar1.Visible);
  1055. Assert.Equal (3, sBar1.Position);
  1056. Assert.Equal (3, tv1.TopRow);
  1057. Assert.True (sBar1.OtherScrollBarView.Visible);
  1058. Assert.Equal (1, sBar1.OtherScrollBarView.Position);
  1059. Assert.Equal (1, tv1.LeftColumn);
  1060. Assert.Equal (1, tv1.BottomOffset);
  1061. Assert.Equal (1, tv1.RightOffset);
  1062. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1063. // sBar2
  1064. Assert.True (sBar2.Visible);
  1065. Assert.Equal (3, sBar2.Position);
  1066. Assert.Equal (3, tv2.TopRow);
  1067. Assert.False (sBar2.OtherScrollBarView.Visible);
  1068. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1069. Assert.Equal (0, tv2.LeftColumn);
  1070. Assert.Equal (0, tv2.BottomOffset);
  1071. Assert.Equal (1, tv2.RightOffset);
  1072. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1073. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1074. ┌────────┐
  1075. │┌──────┐│
  1076. ││ ▲││
  1077. ││ ░││
  1078. ││ ┬││
  1079. ││ │││
  1080. ││ │││
  1081. ││ │││
  1082. ││0 │││
  1083. ││23456┴││
  1084. ││ ▼││
  1085. ││◄├─┤► ││
  1086. │└──────┘│
  1087. │┌──────┐│
  1088. ││4 ▲││
  1089. ││5 ┬││
  1090. ││6 ┴││
  1091. ││7 ▼││
  1092. │└──────┘│
  1093. └────────┘", output);
  1094. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1095. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1096. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1097. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1098. win.Redraw (win.Bounds);
  1099. Application.MainLoop.MainIteration ();
  1100. win.Redraw (win.Bounds);
  1101. // sBar1
  1102. Assert.True (sBar1.Visible);
  1103. Assert.Equal (3, sBar1.Position);
  1104. Assert.Equal (3, tv1.TopRow);
  1105. Assert.True (sBar1.OtherScrollBarView.Visible);
  1106. Assert.Equal (2, sBar1.OtherScrollBarView.Position);
  1107. Assert.Equal (2, tv1.LeftColumn);
  1108. Assert.Equal (1, tv1.BottomOffset);
  1109. Assert.Equal (1, tv1.RightOffset);
  1110. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1111. // sBar2
  1112. Assert.True (sBar2.Visible);
  1113. Assert.Equal (4, sBar2.Position);
  1114. Assert.Equal (4, tv2.TopRow);
  1115. Assert.False (sBar2.OtherScrollBarView.Visible);
  1116. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1117. Assert.Equal (0, tv2.LeftColumn);
  1118. Assert.Equal (0, tv2.BottomOffset);
  1119. Assert.Equal (1, tv2.RightOffset);
  1120. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1121. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1122. ┌────────┐
  1123. │┌──────┐│
  1124. ││ ▲││
  1125. ││ ░││
  1126. ││ ┬││
  1127. ││ │││
  1128. ││ │││
  1129. ││ │││
  1130. ││ │││
  1131. ││34567┴││
  1132. ││ ▼││
  1133. ││◄├─┤► ││
  1134. │└──────┘│
  1135. │┌──────┐│
  1136. ││5 ▲││
  1137. ││6 ┬││
  1138. ││7 ┴││
  1139. ││8 ▼││
  1140. │└──────┘│
  1141. └────────┘", output);
  1142. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1143. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1144. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1145. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1146. win.Redraw (win.Bounds);
  1147. Application.MainLoop.MainIteration ();
  1148. win.Redraw (win.Bounds);
  1149. // sBar1
  1150. Assert.True (sBar1.Visible);
  1151. Assert.Equal (3, sBar1.Position);
  1152. Assert.Equal (3, tv1.TopRow);
  1153. Assert.True (sBar1.OtherScrollBarView.Visible);
  1154. Assert.Equal (3, sBar1.OtherScrollBarView.Position);
  1155. Assert.Equal (3, tv1.LeftColumn);
  1156. Assert.Equal (1, tv1.BottomOffset);
  1157. Assert.Equal (1, tv1.RightOffset);
  1158. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1159. // sBar2
  1160. Assert.True (sBar2.Visible);
  1161. Assert.Equal (5, sBar2.Position);
  1162. Assert.Equal (5, tv2.TopRow);
  1163. Assert.False (sBar2.OtherScrollBarView.Visible);
  1164. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1165. Assert.Equal (0, tv2.LeftColumn);
  1166. Assert.Equal (0, tv2.BottomOffset);
  1167. Assert.Equal (1, tv2.RightOffset);
  1168. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1169. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1170. ┌────────┐
  1171. │┌──────┐│
  1172. ││ ▲││
  1173. ││ ░││
  1174. ││ ┬││
  1175. ││ │││
  1176. ││ │││
  1177. ││ │││
  1178. ││ │││
  1179. ││45678┴││
  1180. ││ ▼││
  1181. ││◄├─┤► ││
  1182. │└──────┘│
  1183. │┌──────┐│
  1184. ││6 ▲││
  1185. ││7 ┬││
  1186. ││8 ┴││
  1187. ││9 ▼││
  1188. │└──────┘│
  1189. └────────┘", output);
  1190. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1191. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1192. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1193. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1194. win.Redraw (win.Bounds);
  1195. Application.MainLoop.MainIteration ();
  1196. win.Redraw (win.Bounds);
  1197. // sBar1
  1198. Assert.True (sBar1.Visible);
  1199. Assert.Equal (3, sBar1.Position);
  1200. Assert.Equal (3, tv1.TopRow);
  1201. Assert.True (sBar1.OtherScrollBarView.Visible);
  1202. Assert.Equal (4, sBar1.OtherScrollBarView.Position);
  1203. Assert.Equal (4, tv1.LeftColumn);
  1204. Assert.Equal (1, tv1.BottomOffset);
  1205. Assert.Equal (1, tv1.RightOffset);
  1206. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1207. // sBar2
  1208. Assert.True (sBar2.Visible);
  1209. Assert.Equal (6, sBar2.Position);
  1210. Assert.Equal (6, tv2.TopRow);
  1211. Assert.False (sBar2.OtherScrollBarView.Visible);
  1212. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1213. Assert.Equal (0, tv2.LeftColumn);
  1214. Assert.Equal (0, tv2.BottomOffset);
  1215. Assert.Equal (1, tv2.RightOffset);
  1216. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1217. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1218. ┌────────┐
  1219. │┌──────┐│
  1220. ││ ▲││
  1221. ││ ░││
  1222. ││ ┬││
  1223. ││ │││
  1224. ││ │││
  1225. ││ │││
  1226. ││ │││
  1227. ││56789┴││
  1228. ││ ▼││
  1229. ││◄░├┤► ││
  1230. │└──────┘│
  1231. │┌──────┐│
  1232. ││7 ▲││
  1233. ││8 ┬││
  1234. ││9 ┴││
  1235. ││10 ▼││
  1236. │└──────┘│
  1237. └────────┘", output);
  1238. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1239. Assert.True (sBar1.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1240. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1241. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 3, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1242. win.Redraw (win.Bounds);
  1243. Application.MainLoop.MainIteration ();
  1244. win.Redraw (win.Bounds);
  1245. // sBar1
  1246. Assert.True (sBar1.Visible);
  1247. Assert.Equal (3, sBar1.Position);
  1248. Assert.Equal (3, tv1.TopRow);
  1249. Assert.True (sBar1.OtherScrollBarView.Visible);
  1250. Assert.Equal (5, sBar1.OtherScrollBarView.Position);
  1251. Assert.Equal (5, tv1.LeftColumn);
  1252. Assert.Equal (1, tv1.BottomOffset);
  1253. Assert.Equal (1, tv1.RightOffset);
  1254. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1255. // sBar2
  1256. Assert.True (sBar2.Visible);
  1257. Assert.Equal (8, sBar2.Position);
  1258. Assert.Equal (8, tv2.TopRow);
  1259. Assert.True (sBar2.OtherScrollBarView.Visible);
  1260. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1261. Assert.Equal (0, tv2.LeftColumn);
  1262. Assert.Equal (1, tv2.BottomOffset);
  1263. Assert.Equal (1, tv2.RightOffset);
  1264. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1265. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1266. ┌────────┐
  1267. │┌──────┐│
  1268. ││ ▲││
  1269. ││ ░││
  1270. ││ ┬││
  1271. ││ │││
  1272. ││ │││
  1273. ││ │││
  1274. ││ │││
  1275. ││67890┴││
  1276. ││ ▼││
  1277. ││◄░├┤► ││
  1278. │└──────┘│
  1279. │┌──────┐│
  1280. ││9 ▲││
  1281. ││10 ◊││
  1282. ││12345▼││
  1283. ││◄├┤░► ││
  1284. │└──────┘│
  1285. └────────┘", output);
  1286. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1287. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1288. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 2, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1289. Assert.True (sBar2.MouseEvent (new MouseEvent { X = 0, Y = 2, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1290. win.Redraw (win.Bounds);
  1291. Application.MainLoop.MainIteration ();
  1292. win.Redraw (win.Bounds);
  1293. // sBar1
  1294. Assert.True (sBar1.Visible);
  1295. Assert.Equal (2, sBar1.Position);
  1296. Assert.Equal (2, tv1.TopRow);
  1297. Assert.True (sBar1.OtherScrollBarView.Visible);
  1298. Assert.Equal (5, sBar1.OtherScrollBarView.Position);
  1299. Assert.Equal (5, tv1.LeftColumn);
  1300. Assert.Equal (1, tv1.BottomOffset);
  1301. Assert.Equal (1, tv1.RightOffset);
  1302. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1303. // sBar2
  1304. Assert.True (sBar2.Visible);
  1305. Assert.Equal (9, sBar2.Position);
  1306. Assert.Equal (9, tv2.TopRow);
  1307. Assert.True (sBar2.OtherScrollBarView.Visible);
  1308. Assert.Equal (0, sBar2.OtherScrollBarView.Position);
  1309. Assert.Equal (0, tv2.LeftColumn);
  1310. Assert.Equal (1, tv2.BottomOffset);
  1311. Assert.Equal (1, tv2.RightOffset);
  1312. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1313. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1314. ┌────────┐
  1315. │┌──────┐│
  1316. ││ ▲││
  1317. ││ ░││
  1318. ││ ┬││
  1319. ││ │││
  1320. ││ │││
  1321. ││ │││
  1322. ││ │││
  1323. ││ ┴││
  1324. ││67890▼││
  1325. ││◄░├┤► ││
  1326. │└──────┘│
  1327. │┌──────┐│
  1328. ││10 ▲││
  1329. ││12345◊││
  1330. ││ ▼││
  1331. ││◄├┤░► ││
  1332. │└──────┘│
  1333. └────────┘", output);
  1334. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1335. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1336. Assert.True (sBar2.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1337. Assert.True (sBar2.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1338. win.Redraw (win.Bounds);
  1339. Application.MainLoop.MainIteration ();
  1340. win.Redraw (win.Bounds);
  1341. // sBar1
  1342. Assert.True (sBar1.Visible);
  1343. Assert.Equal (1, sBar1.Position);
  1344. Assert.Equal (1, tv1.TopRow);
  1345. Assert.True (sBar1.OtherScrollBarView.Visible);
  1346. Assert.Equal (5, sBar1.OtherScrollBarView.Position);
  1347. Assert.Equal (5, tv1.LeftColumn);
  1348. Assert.Equal (1, tv1.BottomOffset);
  1349. Assert.Equal (1, tv1.RightOffset);
  1350. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1351. // sBar2
  1352. Assert.True (sBar2.Visible);
  1353. Assert.Equal (9, sBar2.Position);
  1354. Assert.Equal (9, tv2.TopRow);
  1355. Assert.True (sBar2.OtherScrollBarView.Visible);
  1356. Assert.Equal (1, sBar2.OtherScrollBarView.Position);
  1357. Assert.Equal (1, tv2.LeftColumn);
  1358. Assert.Equal (1, tv2.BottomOffset);
  1359. Assert.Equal (1, tv2.RightOffset);
  1360. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1361. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1362. ┌────────┐
  1363. │┌──────┐│
  1364. ││ ▲││
  1365. ││ ┬││
  1366. ││ │││
  1367. ││ │││
  1368. ││ │││
  1369. ││ │││
  1370. ││ ┴││
  1371. ││ ░││
  1372. ││ ▼││
  1373. ││◄░├┤► ││
  1374. │└──────┘│
  1375. │┌──────┐│
  1376. ││0 ▲││
  1377. ││23456◊││
  1378. ││ ▼││
  1379. ││◄├─┤► ││
  1380. │└──────┘│
  1381. └────────┘", output);
  1382. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar1 }));
  1383. Assert.True (sBar1.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Released, View = sBar1 }));
  1384. Assert.True (sBar2.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Pressed, View = sBar2 }));
  1385. Assert.True (sBar2.OtherScrollBarView.MouseEvent (new MouseEvent { X = 4, Y = 0, Flags = MouseFlags.Button1Released, View = sBar2 }));
  1386. win.Redraw (win.Bounds);
  1387. Application.MainLoop.MainIteration ();
  1388. win.Redraw (win.Bounds);
  1389. // sBar1
  1390. Assert.True (sBar1.Visible);
  1391. Assert.Equal (0, sBar1.Position);
  1392. Assert.Equal (0, tv1.TopRow);
  1393. Assert.False (sBar1.OtherScrollBarView.Visible);
  1394. Assert.Equal (0, sBar1.OtherScrollBarView.Position);
  1395. Assert.Equal (0, tv1.LeftColumn);
  1396. Assert.Equal (0, tv1.BottomOffset);
  1397. Assert.Equal (1, tv1.RightOffset);
  1398. Assert.Equal (new Point (0, 0), tv1.CursorPosition);
  1399. // sBar2
  1400. Assert.True (sBar2.Visible);
  1401. Assert.Equal (9, sBar2.Position);
  1402. Assert.Equal (9, tv2.TopRow);
  1403. Assert.True (sBar2.OtherScrollBarView.Visible);
  1404. Assert.Equal (2, sBar2.OtherScrollBarView.Position);
  1405. Assert.Equal (2, tv2.LeftColumn);
  1406. Assert.Equal (1, tv2.BottomOffset);
  1407. Assert.Equal (1, tv2.RightOffset);
  1408. Assert.Equal (new Point (0, 0), tv2.CursorPosition);
  1409. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1410. ┌────────┐
  1411. │┌──────┐│
  1412. ││1 ▲││
  1413. ││2 ┬││
  1414. ││3 │││
  1415. ││4 │││
  1416. ││5 │││
  1417. ││6 │││
  1418. ││7 │││
  1419. ││8 ┴││
  1420. ││9 ░││
  1421. ││10 ▼││
  1422. │└──────┘│
  1423. │┌──────┐│
  1424. ││ ▲││
  1425. ││34567◊││
  1426. ││ ▼││
  1427. ││◄├─┤► ││
  1428. │└──────┘│
  1429. └────────┘", output);
  1430. }
  1431. }
  1432. }