ScrollView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. //
  2. // ScrollView.cs: ScrollView and ScrollBarView views.
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. //
  8. // TODO:
  9. // - focus in scrollview
  10. // - focus handling in scrollview to auto scroll to focused view
  11. // - Raise events
  12. // - Perhaps allow an option to not display the scrollbar arrow indicators?
  13. using System;
  14. using System.Reflection;
  15. namespace Terminal.Gui {
  16. /// <summary>
  17. /// ScrollBarViews are views that display a 1-character scrollbar, either horizontal or vertical
  18. /// </summary>
  19. /// <remarks>
  20. /// <para>
  21. /// The scrollbar is drawn to be a representation of the Size, assuming that the
  22. /// scroll position is set at Position.
  23. /// </para>
  24. /// <para>
  25. /// If the region to display the scrollbar is larger than three characters,
  26. /// arrow indicators are drawn.
  27. /// </para>
  28. /// </remarks>
  29. public class ScrollBarView : View {
  30. bool vertical = false;
  31. int size = 0, position = 0;
  32. /// <summary>
  33. /// If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal.
  34. /// </summary>
  35. public bool IsVertical {
  36. get => vertical;
  37. set {
  38. vertical = value;
  39. SetNeedsDisplay ();
  40. }
  41. }
  42. /// <summary>
  43. /// The size of content the scrollbar represents.
  44. /// </summary>
  45. /// <value>The size.</value>
  46. /// <remarks>The <see cref="Size"/> is typically the size of the virtual content. E.g. when a Scrollbar is
  47. /// part of a <see cref="ScrollView"/> the Size is set to the appropriate dimension of <see cref="ScrollView.ContentSize"/>.</remarks>
  48. public int Size {
  49. get => size;
  50. set {
  51. size = value;
  52. SetNeedsDisplay ();
  53. }
  54. }
  55. /// <summary>
  56. /// This event is raised when the position on the scrollbar has changed.
  57. /// </summary>
  58. public Action ChangedPosition;
  59. /// <summary>
  60. /// The position, relative to <see cref="Size"/>, to set the scrollbar at.
  61. /// </summary>
  62. /// <value>The position.</value>
  63. public int Position {
  64. get => position;
  65. set {
  66. position = value;
  67. SetNeedsDisplay ();
  68. }
  69. }
  70. void SetPosition (int newPos)
  71. {
  72. Position = newPos;
  73. ChangedPosition?.Invoke ();
  74. }
  75. /// <summary>
  76. /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Absolute"/> layout.
  77. /// </summary>
  78. /// <param name="rect">Frame for the scrollbar.</param>
  79. public ScrollBarView (Rect rect) : this (rect, 0, 0, false) { }
  80. /// <summary>
  81. /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Absolute"/> layout.
  82. /// </summary>
  83. /// <param name="rect">Frame for the scrollbar.</param>
  84. /// <param name="size">The size that this scrollbar represents. Sets the <see cref="Size"/> property.</param>
  85. /// <param name="position">The position within this scrollbar. Sets the <see cref="Position"/> property.</param>
  86. /// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal. Sets the <see cref="IsVertical"/> property.</param>
  87. public ScrollBarView (Rect rect, int size, int position, bool isVertical) : base (rect)
  88. {
  89. Init (size, position, isVertical);
  90. }
  91. /// <summary>
  92. /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Computed"/> layout.
  93. /// </summary>
  94. public ScrollBarView () : this (0, 0, false) { }
  95. /// <summary>
  96. /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Computed"/> layout.
  97. /// </summary>
  98. /// <param name="size">The size that this scrollbar represents.</param>
  99. /// <param name="position">The position within this scrollbar.</param>
  100. /// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal.</param>
  101. public ScrollBarView (int size, int position, bool isVertical) : base ()
  102. {
  103. Init (size, position, isVertical);
  104. }
  105. void Init (int size, int position, bool isVertical)
  106. {
  107. vertical = isVertical;
  108. this.position = position;
  109. this.size = size;
  110. WantContinuousButtonPressed = true;
  111. }
  112. int posTopTee;
  113. int posLeftTee;
  114. int posBottomTee;
  115. int posRightTee;
  116. ///<inheritdoc/>
  117. public override void Redraw (Rect region)
  118. {
  119. if (ColorScheme == null || Size == 0)
  120. return;
  121. Driver.SetAttribute (ColorScheme.Normal);
  122. if (Bounds.Height == 0) {
  123. return;
  124. }
  125. if (vertical) {
  126. if (region.Right < Bounds.Width - 1)
  127. return;
  128. var col = Bounds.Width - 1;
  129. var bh = Bounds.Height;
  130. Rune special;
  131. if (bh < 4) {
  132. var by1 = position * bh / Size;
  133. var by2 = (position + bh) * bh / Size;
  134. Move (col, 0);
  135. Driver.AddRune (Driver.UpArrow);
  136. if (Bounds.Height == 3) {
  137. Move (col, 1);
  138. Driver.AddRune (Driver.Diamond);
  139. }
  140. Move (col, Bounds.Height - 1);
  141. Driver.AddRune (Driver.DownArrow);
  142. } else {
  143. bh -= 2;
  144. var by1 = position * bh / Size;
  145. var by2 = (position + bh) * bh / Size;
  146. Move (col, 0);
  147. Driver.AddRune (Driver.UpArrow);
  148. Move (col, Bounds.Height - 1);
  149. Driver.AddRune (Driver.DownArrow);
  150. bool hasTopTee = false;
  151. bool hasDiamond = false;
  152. bool hasBottomTee = false;
  153. for (int y = 0; y < bh; y++) {
  154. Move (col, y + 1);
  155. if ((y < by1 || y > by2) && ((position > 0 && !hasTopTee) || (hasTopTee && hasBottomTee))) {
  156. special = Driver.Stipple;
  157. } else {
  158. if (y != by2 && y > 1 && by2 - by1 == 0 && by1 < bh - 1 && hasTopTee && !hasDiamond) {
  159. hasDiamond = true;
  160. special = Driver.Diamond;
  161. } else {
  162. if (y == by1 && !hasTopTee) {
  163. hasTopTee = true;
  164. posTopTee = y;
  165. special = Driver.TopTee;
  166. } else if ((y >= by2 || by2 == 0) && !hasBottomTee) {
  167. hasBottomTee = true;
  168. posBottomTee = y;
  169. special = Driver.BottomTee;
  170. } else {
  171. special = Driver.VLine;
  172. }
  173. }
  174. }
  175. Driver.AddRune (special);
  176. }
  177. if (!hasTopTee) {
  178. Move (col, Bounds.Height - 2);
  179. Driver.AddRune (Driver.TopTee);
  180. }
  181. }
  182. } else {
  183. if (region.Bottom < Bounds.Height - 1)
  184. return;
  185. var row = Bounds.Height - 1;
  186. var bw = Bounds.Width;
  187. Rune special;
  188. if (bw < 4) {
  189. var bx1 = position * bw / Size;
  190. var bx2 = (position + bw) * bw / Size;
  191. Move (0, row);
  192. Driver.AddRune (Driver.LeftArrow);
  193. Driver.AddRune (Driver.RightArrow);
  194. } else {
  195. bw -= 2;
  196. var bx1 = position * bw / Size;
  197. var bx2 = (position + bw) * bw / Size;
  198. Move (0, row);
  199. Driver.AddRune (Driver.LeftArrow);
  200. bool hasLeftTee = false;
  201. bool hasDiamond = false;
  202. bool hasRightTee = false;
  203. for (int x = 0; x < bw; x++) {
  204. if ((x < bx1 || x >= bx2 + 1) && ((position > 0 && !hasLeftTee) || (hasLeftTee && hasRightTee))) {
  205. special = Driver.Stipple;
  206. } else {
  207. if (x != bx2 && x > 1 && bx2 - bx1 == 0 && bx1 < bw - 1 && hasLeftTee && !hasDiamond) {
  208. hasDiamond = true;
  209. special = Driver.Diamond;
  210. } else {
  211. if (x == bx1 && !hasLeftTee) {
  212. hasLeftTee = true;
  213. posLeftTee = x;
  214. special = Driver.LeftTee;
  215. } else if ((x >= bx2 || bx2 == 0) && !hasRightTee) {
  216. hasRightTee = true;
  217. posRightTee = x;
  218. special = Driver.RightTee;
  219. } else {
  220. special = Driver.HLine;
  221. }
  222. }
  223. }
  224. Driver.AddRune (special);
  225. }
  226. if (!hasLeftTee) {
  227. Move (Bounds.Width -2, row);
  228. Driver.AddRune (Driver.LeftTee);
  229. }
  230. Driver.AddRune (Driver.RightArrow);
  231. }
  232. }
  233. }
  234. ///<inheritdoc/>
  235. public override bool MouseEvent (MouseEvent me)
  236. {
  237. if (me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked &&
  238. !me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))
  239. return false;
  240. int location = vertical ? me.Y : me.X;
  241. int barsize = vertical ? Bounds.Height : Bounds.Width;
  242. int posTopLeftTee = vertical ? posTopTee : posLeftTee;
  243. int posBottomRightTee = vertical ? posBottomTee : posRightTee;
  244. barsize -= 2;
  245. var pos = Position;
  246. if (location == 0) {
  247. if (pos > 0)
  248. SetPosition (pos - 1);
  249. } else if (location == barsize + 1) {
  250. if (pos + 1 < Size)
  251. SetPosition (pos + 1);
  252. } else {
  253. var b1 = pos * barsize / Size;
  254. var b2 = (pos + barsize) * barsize / Size;
  255. if (b1 == 0 && location == 1 && pos == 0 || (location >= posTopLeftTee + 1 && location <= posBottomRightTee + 1 && (pos != 0 || pos != Size - 1) && location != 1 && location != barsize) ||
  256. (b2 == barsize + (b2 - b1 - 1) && location == barsize && pos == Size - 1)) {
  257. return true;
  258. } else if (location <= barsize) {
  259. if (location > 1 && location > posTopLeftTee && location > posBottomRightTee)
  260. SetPosition (Math.Min (pos + (Size / location), Size - 1));
  261. else if (location <= b2 && pos > 0 || pos > 0)
  262. SetPosition (Math.Max (pos - (Size / barsize), 0));
  263. }
  264. }
  265. return true;
  266. }
  267. }
  268. /// <summary>
  269. /// Scrollviews are views that present a window into a virtual space where subviews are added. Similar to the iOS UIScrollView.
  270. /// </summary>
  271. /// <remarks>
  272. /// <para>
  273. /// The subviews that are added to this <see cref="Gui.ScrollView"/> are offset by the
  274. /// <see cref="ContentOffset"/> property. The view itself is a window into the
  275. /// space represented by the <see cref="ContentSize"/>.
  276. /// </para>
  277. /// <para>
  278. /// Use the
  279. /// </para>
  280. /// </remarks>
  281. public class ScrollView : View {
  282. View contentView = null;
  283. ScrollBarView vertical, horizontal;
  284. /// <summary>
  285. /// Initializes a new instance of the <see cref="Gui.ScrollView"/> class using <see cref="LayoutStyle.Absolute"/> positioning.
  286. /// </summary>
  287. /// <param name="frame"></param>
  288. public ScrollView (Rect frame) : base (frame)
  289. {
  290. Init (frame);
  291. }
  292. /// <summary>
  293. /// Initializes a new instance of the <see cref="Gui.ScrollView"/> class using <see cref="LayoutStyle.Computed"/> positioning.
  294. /// </summary>
  295. public ScrollView () : base ()
  296. {
  297. Init (new Rect (0, 0, 0, 0));
  298. }
  299. void Init (Rect frame)
  300. {
  301. contentView = new View (frame);
  302. vertical = new ScrollBarView (1, 0, isVertical: true) {
  303. X = Pos.AnchorEnd (1),
  304. Y = 0,
  305. Width = 1,
  306. Height = Dim.Fill (showHorizontalScrollIndicator ? 1 : 0)
  307. };
  308. vertical.ChangedPosition += delegate {
  309. ContentOffset = new Point (ContentOffset.X, vertical.Position);
  310. };
  311. horizontal = new ScrollBarView (1, 0, isVertical: false) {
  312. X = 0,
  313. Y = Pos.AnchorEnd (1),
  314. Width = Dim.Fill (showVerticalScrollIndicator ? 1 : 0),
  315. Height = 1
  316. };
  317. horizontal.ChangedPosition += delegate {
  318. ContentOffset = new Point (horizontal.Position, ContentOffset.Y);
  319. };
  320. base.Add (contentView);
  321. CanFocus = true;
  322. MouseEnter += View_MouseEnter;
  323. MouseLeave += View_MouseLeave;
  324. }
  325. Size contentSize;
  326. Point contentOffset;
  327. bool showHorizontalScrollIndicator;
  328. bool showVerticalScrollIndicator;
  329. /// <summary>
  330. /// Represents the contents of the data shown inside the scrolview
  331. /// </summary>
  332. /// <value>The size of the content.</value>
  333. public Size ContentSize {
  334. get {
  335. return contentSize;
  336. }
  337. set {
  338. contentSize = value;
  339. contentView.Frame = new Rect (contentOffset, value);
  340. vertical.Size = contentSize.Height;
  341. horizontal.Size = contentSize.Width;
  342. SetNeedsDisplay ();
  343. }
  344. }
  345. /// <summary>
  346. /// Represents the top left corner coordinate that is displayed by the scrollview
  347. /// </summary>
  348. /// <value>The content offset.</value>
  349. public Point ContentOffset {
  350. get {
  351. return contentOffset;
  352. }
  353. set {
  354. contentOffset = new Point (-Math.Abs (value.X), -Math.Abs (value.Y));
  355. contentView.Frame = new Rect (contentOffset, contentSize);
  356. vertical.Position = Math.Max (0, -contentOffset.Y);
  357. horizontal.Position = Math.Max (0, -contentOffset.X);
  358. SetNeedsDisplay ();
  359. }
  360. }
  361. /// <summary>
  362. /// If true the vertical/horizontal scroll bars won't be showed if it's not needed.
  363. /// </summary>
  364. public bool AutoHideScrollBars { get; set; } = true;
  365. /// <summary>
  366. /// Adds the view to the scrollview.
  367. /// </summary>
  368. /// <param name="view">The view to add to the scrollview.</param>
  369. public override void Add (View view)
  370. {
  371. if (!IsOverridden (view)) {
  372. view.MouseEnter += View_MouseEnter;
  373. view.MouseLeave += View_MouseLeave;
  374. }
  375. contentView.Add (view);
  376. SetNeedsLayout ();
  377. }
  378. void View_MouseLeave (MouseEventArgs e)
  379. {
  380. Application.UngrabMouse ();
  381. }
  382. void View_MouseEnter (MouseEventArgs e)
  383. {
  384. Application.GrabMouse (this);
  385. }
  386. bool IsOverridden (View view)
  387. {
  388. Type t = view.GetType ();
  389. MethodInfo m = t.GetMethod ("MouseEvent");
  390. return m.DeclaringType == t && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
  391. }
  392. /// <summary>
  393. /// Gets or sets the visibility for the horizontal scroll indicator.
  394. /// </summary>
  395. /// <value><c>true</c> if show vertical scroll indicator; otherwise, <c>false</c>.</value>
  396. public bool ShowHorizontalScrollIndicator {
  397. get => showHorizontalScrollIndicator;
  398. set {
  399. if (value == showHorizontalScrollIndicator)
  400. return;
  401. showHorizontalScrollIndicator = value;
  402. SetNeedsLayout ();
  403. if (value) {
  404. base.Add (horizontal);
  405. horizontal.MouseEnter += View_MouseEnter;
  406. horizontal.MouseLeave += View_MouseLeave;
  407. } else {
  408. Remove (horizontal);
  409. horizontal.MouseEnter -= View_MouseEnter;
  410. horizontal.MouseLeave -= View_MouseLeave;
  411. }
  412. vertical.Height = Dim.Fill (showHorizontalScrollIndicator ? 1 : 0);
  413. }
  414. }
  415. /// <summary>
  416. /// Removes all widgets from this container.
  417. /// </summary>
  418. /// <remarks>
  419. /// </remarks>
  420. public override void RemoveAll ()
  421. {
  422. contentView.RemoveAll ();
  423. }
  424. /// <summary>
  425. /// /// Gets or sets the visibility for the vertical scroll indicator.
  426. /// </summary>
  427. /// <value><c>true</c> if show vertical scroll indicator; otherwise, <c>false</c>.</value>
  428. public bool ShowVerticalScrollIndicator {
  429. get => showVerticalScrollIndicator;
  430. set {
  431. if (value == showVerticalScrollIndicator)
  432. return;
  433. showVerticalScrollIndicator = value;
  434. SetNeedsLayout ();
  435. if (value) {
  436. base.Add (vertical);
  437. vertical.MouseEnter += View_MouseEnter;
  438. vertical.MouseLeave += View_MouseLeave;
  439. } else {
  440. Remove (vertical);
  441. vertical.MouseEnter -= View_MouseEnter;
  442. vertical.MouseLeave -= View_MouseLeave;
  443. }
  444. horizontal.Width = Dim.Fill (showVerticalScrollIndicator ? 1 : 0);
  445. }
  446. }
  447. /// <inheritdoc/>
  448. public override void Redraw (Rect region)
  449. {
  450. Driver.SetAttribute (ColorScheme.Normal);
  451. SetViewsNeedsDisplay ();
  452. Clear ();
  453. var savedClip = ClipToBounds ();
  454. OnDrawContent (new Rect (ContentOffset,
  455. new Size (Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0),
  456. Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0))));
  457. contentView.Redraw (contentView.Frame);
  458. Driver.Clip = savedClip;
  459. if (AutoHideScrollBars) {
  460. ShowHideScrollBars ();
  461. } else {
  462. if (ShowVerticalScrollIndicator) {
  463. vertical.Redraw (vertical.Bounds);
  464. }
  465. if (ShowHorizontalScrollIndicator) {
  466. horizontal.Redraw (horizontal.Bounds);
  467. }
  468. }
  469. // Fill in the bottom left corner
  470. if (ShowVerticalScrollIndicator && ShowHorizontalScrollIndicator) {
  471. AddRune (Bounds.Width - 1, Bounds.Height - 1, ' ');
  472. }
  473. Driver.SetAttribute (ColorScheme.Normal);
  474. }
  475. void ShowHideScrollBars ()
  476. {
  477. bool v = false, h = false;
  478. if (Bounds.Height == 0 || Bounds.Height > contentSize.Height) {
  479. if (ShowVerticalScrollIndicator) {
  480. ShowVerticalScrollIndicator = false;
  481. }
  482. v = false;
  483. } else {
  484. if (!ShowVerticalScrollIndicator) {
  485. ShowVerticalScrollIndicator = true;
  486. }
  487. v = true;
  488. }
  489. if (Bounds.Width == 0 || Bounds.Width > contentSize.Width) {
  490. if (ShowHorizontalScrollIndicator) {
  491. ShowHorizontalScrollIndicator = false;
  492. }
  493. h = false;
  494. } else {
  495. if (!ShowHorizontalScrollIndicator) {
  496. ShowHorizontalScrollIndicator = true;
  497. }
  498. h = true;
  499. }
  500. vertical.Height = Dim.Fill (h ? 1 : 0);
  501. horizontal.Width = Dim.Fill (v ? 1 : 0);
  502. if (v) {
  503. vertical.SetRelativeLayout (Bounds);
  504. vertical.Redraw (vertical.Bounds);
  505. }
  506. if (h) {
  507. horizontal.SetRelativeLayout (Bounds);
  508. horizontal.Redraw (horizontal.Bounds);
  509. }
  510. }
  511. void SetViewsNeedsDisplay ()
  512. {
  513. foreach (View view in contentView) {
  514. view.SetNeedsDisplay ();
  515. }
  516. }
  517. ///<inheritdoc/>
  518. public override void PositionCursor ()
  519. {
  520. if (InternalSubviews.Count == 0)
  521. Move (0, 0);
  522. else
  523. base.PositionCursor ();
  524. }
  525. /// <summary>
  526. /// Scrolls the view up.
  527. /// </summary>
  528. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  529. /// <param name="lines">Number of lines to scroll.</param>
  530. public bool ScrollUp (int lines)
  531. {
  532. if (contentOffset.Y < 0) {
  533. ContentOffset = new Point (contentOffset.X, Math.Min (contentOffset.Y + lines, 0));
  534. return true;
  535. }
  536. return false;
  537. }
  538. /// <summary>
  539. /// Scrolls the view to the left
  540. /// </summary>
  541. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  542. /// <param name="cols">Number of columns to scroll by.</param>
  543. public bool ScrollLeft (int cols)
  544. {
  545. if (contentOffset.X < 0) {
  546. ContentOffset = new Point (Math.Min (contentOffset.X + cols, 0), contentOffset.Y);
  547. return true;
  548. }
  549. return false;
  550. }
  551. /// <summary>
  552. /// Scrolls the view down.
  553. /// </summary>
  554. /// <returns><c>true</c>, if left was scrolled, <c>false</c> otherwise.</returns>
  555. /// <param name="lines">Number of lines to scroll.</param>
  556. public bool ScrollDown (int lines)
  557. {
  558. var ny = Math.Max (-contentSize.Height, contentOffset.Y - lines);
  559. if (ny == contentOffset.Y)
  560. return false;
  561. ContentOffset = new Point (contentOffset.X, ny);
  562. return true;
  563. }
  564. /// <summary>
  565. /// Scrolls the view to the right.
  566. /// </summary>
  567. /// <returns><c>true</c>, if right was scrolled, <c>false</c> otherwise.</returns>
  568. /// <param name="cols">Number of columns to scroll by.</param>
  569. public bool ScrollRight (int cols)
  570. {
  571. var nx = Math.Max (-contentSize.Width, contentOffset.X - cols);
  572. if (nx == contentOffset.X)
  573. return false;
  574. ContentOffset = new Point (nx, contentOffset.Y);
  575. return true;
  576. }
  577. ///<inheritdoc/>
  578. public override bool ProcessKey (KeyEvent kb)
  579. {
  580. if (base.ProcessKey (kb))
  581. return true;
  582. switch (kb.Key) {
  583. case Key.CursorUp:
  584. return ScrollUp (1);
  585. case (Key)'v' | Key.AltMask:
  586. case Key.PageUp:
  587. return ScrollUp (Bounds.Height);
  588. case Key.ControlV:
  589. case Key.PageDown:
  590. return ScrollDown (Bounds.Height);
  591. case Key.CursorDown:
  592. return ScrollDown (1);
  593. case Key.CursorLeft:
  594. return ScrollLeft (1);
  595. case Key.CursorRight:
  596. return ScrollRight (1);
  597. case Key.Home:
  598. return ScrollUp (contentSize.Height);
  599. case Key.End:
  600. return ScrollDown (contentSize.Height);
  601. }
  602. return false;
  603. }
  604. ///<inheritdoc/>
  605. public override bool MouseEvent (MouseEvent me)
  606. {
  607. if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp &&
  608. me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked &&
  609. !me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))
  610. return false;
  611. if (me.Flags == MouseFlags.WheeledDown && ShowVerticalScrollIndicator)
  612. ScrollDown (1);
  613. else if (me.Flags == MouseFlags.WheeledUp && ShowVerticalScrollIndicator)
  614. ScrollUp (1);
  615. else if (me.X == vertical.Frame.X && ShowVerticalScrollIndicator)
  616. vertical.MouseEvent (me);
  617. else if (me.Y == horizontal.Frame.Y && ShowHorizontalScrollIndicator)
  618. horizontal.MouseEvent (me);
  619. else if (IsOverridden (me.View)) {
  620. Application.UngrabMouse ();
  621. return false;
  622. }
  623. return true;
  624. }
  625. }
  626. }