ViewSubViews.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. namespace Terminal.Gui;
  2. public partial class View
  3. {
  4. private static readonly IList<View> _empty = new List<View> (0).AsReadOnly ();
  5. internal bool _addingView;
  6. private List<View> _subviews; // This is null, and allocated on demand.
  7. private View _superView;
  8. /// <summary>Indicates whether the view was added to <see cref="SuperView"/>.</summary>
  9. public bool IsAdded { get; private set; }
  10. /// <summary>Returns a value indicating if this View is currently on Top (Active)</summary>
  11. public bool IsCurrentTop => Application.Current == this;
  12. /// <summary>This returns a list of the subviews contained by this view.</summary>
  13. /// <value>The subviews.</value>
  14. public IList<View> Subviews => _subviews?.AsReadOnly () ?? _empty;
  15. /// <summary>Returns the container for this view, or null if this view has not been added to a container.</summary>
  16. /// <value>The super view.</value>
  17. public virtual View SuperView
  18. {
  19. get => _superView;
  20. set => throw new NotImplementedException ();
  21. }
  22. // Internally, we use InternalSubviews rather than subviews, as we do not expect us
  23. // to make the same mistakes our users make when they poke at the Subviews.
  24. internal IList<View> InternalSubviews => _subviews ?? _empty;
  25. /// <summary>Adds a subview (child) to this view.</summary>
  26. /// <remarks>
  27. /// The Views that have been added to this view can be retrieved via the <see cref="Subviews"/> property. See also
  28. /// <seealso cref="Remove(View)"/> <seealso cref="RemoveAll"/>
  29. /// </remarks>
  30. public virtual void Add (View view)
  31. {
  32. if (view is null)
  33. {
  34. return;
  35. }
  36. if (_subviews is null)
  37. {
  38. _subviews = new List<View> ();
  39. }
  40. if (_tabIndexes is null)
  41. {
  42. _tabIndexes = new List<View> ();
  43. }
  44. _subviews.Add (view);
  45. _tabIndexes.Add (view);
  46. view._superView = this;
  47. if (view.CanFocus)
  48. {
  49. _addingView = true;
  50. if (SuperView?.CanFocus == false)
  51. {
  52. SuperView._addingView = true;
  53. SuperView.CanFocus = true;
  54. SuperView._addingView = false;
  55. }
  56. CanFocus = true;
  57. view._tabIndex = _tabIndexes.IndexOf (view);
  58. _addingView = false;
  59. }
  60. if (view.Enabled && !Enabled)
  61. {
  62. view._oldEnabled = true;
  63. view.Enabled = false;
  64. }
  65. OnAdded (new SuperViewChangedEventArgs (this, view));
  66. if (IsInitialized && !view.IsInitialized)
  67. {
  68. view.BeginInit ();
  69. view.EndInit ();
  70. }
  71. SetNeedsLayout ();
  72. SetNeedsDisplay ();
  73. }
  74. /// <summary>Adds the specified views (children) to the view.</summary>
  75. /// <param name="views">Array of one or more views (can be optional parameter).</param>
  76. /// <remarks>
  77. /// The Views that have been added to this view can be retrieved via the <see cref="Subviews"/> property. See also
  78. /// <seealso cref="Remove(View)"/> <seealso cref="RemoveAll"/>
  79. /// </remarks>
  80. public void Add (params View [] views)
  81. {
  82. if (views is null)
  83. {
  84. return;
  85. }
  86. foreach (View view in views)
  87. {
  88. Add (view);
  89. }
  90. }
  91. /// <summary>Event fired when this view is added to another.</summary>
  92. public event EventHandler<SuperViewChangedEventArgs> Added;
  93. /// <summary>Moves the subview backwards in the hierarchy, only one step</summary>
  94. /// <param name="subview">The subview to send backwards</param>
  95. /// <remarks>If you want to send the view all the way to the back use SendSubviewToBack.</remarks>
  96. public void BringSubviewForward (View subview)
  97. {
  98. PerformActionForSubview (
  99. subview,
  100. x =>
  101. {
  102. int idx = _subviews.IndexOf (x);
  103. if (idx + 1 < _subviews.Count)
  104. {
  105. _subviews.Remove (x);
  106. _subviews.Insert (idx + 1, x);
  107. }
  108. }
  109. );
  110. }
  111. /// <summary>Brings the specified subview to the front so it is drawn on top of any other views.</summary>
  112. /// <param name="subview">The subview to send to the front</param>
  113. /// <remarks><seealso cref="SendSubviewToBack"/>.</remarks>
  114. public void BringSubviewToFront (View subview)
  115. {
  116. PerformActionForSubview (
  117. subview,
  118. x =>
  119. {
  120. _subviews.Remove (x);
  121. _subviews.Add (x);
  122. }
  123. );
  124. }
  125. /// <summary>Get the top superview of a given <see cref="View"/>.</summary>
  126. /// <returns>The superview view.</returns>
  127. public View GetTopSuperView (View view = null, View superview = null)
  128. {
  129. View top = superview ?? Application.Top;
  130. for (View v = view?.SuperView ?? this?.SuperView; v != null; v = v.SuperView)
  131. {
  132. top = v;
  133. if (top == superview)
  134. {
  135. break;
  136. }
  137. }
  138. return top;
  139. }
  140. /// <summary>Method invoked when a subview is being added to this view.</summary>
  141. /// <param name="e">Event where <see cref="ViewEventArgs.View"/> is the subview being added.</param>
  142. public virtual void OnAdded (SuperViewChangedEventArgs e)
  143. {
  144. View view = e.Child;
  145. view.IsAdded = true;
  146. view.OnResizeNeeded ();
  147. view.Added?.Invoke (this, e);
  148. }
  149. /// <summary>Method invoked when a subview is being removed from this view.</summary>
  150. /// <param name="e">Event args describing the subview being removed.</param>
  151. public virtual void OnRemoved (SuperViewChangedEventArgs e)
  152. {
  153. View view = e.Child;
  154. view.IsAdded = false;
  155. view.Removed?.Invoke (this, e);
  156. }
  157. /// <summary>Removes a subview added via <see cref="Add(View)"/> or <see cref="Add(View[])"/> from this View.</summary>
  158. /// <remarks></remarks>
  159. public virtual void Remove (View view)
  160. {
  161. if (view is null || _subviews is null)
  162. {
  163. return;
  164. }
  165. Rectangle touched = view.Frame;
  166. _subviews.Remove (view);
  167. _tabIndexes.Remove (view);
  168. view._superView = null;
  169. view._tabIndex = -1;
  170. SetNeedsLayout ();
  171. SetNeedsDisplay ();
  172. foreach (View v in _subviews)
  173. {
  174. if (v.Frame.IntersectsWith (touched))
  175. {
  176. view.SetNeedsDisplay ();
  177. }
  178. }
  179. OnRemoved (new SuperViewChangedEventArgs (this, view));
  180. if (Focused == view)
  181. {
  182. Focused = null;
  183. }
  184. }
  185. /// <summary>Removes all subviews (children) added via <see cref="Add(View)"/> or <see cref="Add(View[])"/> from this View.</summary>
  186. public virtual void RemoveAll ()
  187. {
  188. if (_subviews is null)
  189. {
  190. return;
  191. }
  192. while (_subviews.Count > 0)
  193. {
  194. Remove (_subviews [0]);
  195. }
  196. }
  197. /// <summary>Event fired when this view is removed from another.</summary>
  198. public event EventHandler<SuperViewChangedEventArgs> Removed;
  199. /// <summary>Moves the subview backwards in the hierarchy, only one step</summary>
  200. /// <param name="subview">The subview to send backwards</param>
  201. /// <remarks>If you want to send the view all the way to the back use SendSubviewToBack.</remarks>
  202. public void SendSubviewBackwards (View subview)
  203. {
  204. PerformActionForSubview (
  205. subview,
  206. x =>
  207. {
  208. int idx = _subviews.IndexOf (x);
  209. if (idx > 0)
  210. {
  211. _subviews.Remove (x);
  212. _subviews.Insert (idx - 1, x);
  213. }
  214. }
  215. );
  216. }
  217. /// <summary>Sends the specified subview to the front so it is the first view drawn</summary>
  218. /// <param name="subview">The subview to send to the front</param>
  219. /// <remarks><seealso cref="BringSubviewToFront(View)"/>.</remarks>
  220. public void SendSubviewToBack (View subview)
  221. {
  222. PerformActionForSubview (
  223. subview,
  224. x =>
  225. {
  226. _subviews.Remove (x);
  227. _subviews.Insert (0, subview);
  228. }
  229. );
  230. }
  231. private void PerformActionForSubview (View subview, Action<View> action)
  232. {
  233. if (_subviews.Contains (subview))
  234. {
  235. action (subview);
  236. }
  237. SetNeedsDisplay ();
  238. subview.SetNeedsDisplay ();
  239. }
  240. #region Focus
  241. /// <summary>Exposed as `internal` for unit tests. Indicates focus navigation direction.</summary>
  242. internal enum NavigationDirection
  243. {
  244. /// <summary>Navigate forward.</summary>
  245. Forward,
  246. /// <summary>Navigate backwards.</summary>
  247. Backward
  248. }
  249. /// <summary>Event fired when the view gets focus.</summary>
  250. public event EventHandler<FocusEventArgs> Enter;
  251. /// <summary>Event fired when the view looses focus.</summary>
  252. public event EventHandler<FocusEventArgs> Leave;
  253. private NavigationDirection _focusDirection;
  254. internal NavigationDirection FocusDirection
  255. {
  256. get => SuperView?.FocusDirection ?? _focusDirection;
  257. set
  258. {
  259. if (SuperView is { })
  260. {
  261. SuperView.FocusDirection = value;
  262. }
  263. else
  264. {
  265. _focusDirection = value;
  266. }
  267. }
  268. }
  269. private bool _hasFocus;
  270. /// <inheritdoc/>
  271. public bool HasFocus
  272. {
  273. set => SetHasFocus (value, this, true);
  274. get => _hasFocus;
  275. }
  276. private void SetHasFocus (bool value, View view, bool force = false)
  277. {
  278. if (HasFocus != value || force)
  279. {
  280. _hasFocus = value;
  281. if (value)
  282. {
  283. OnEnter (view);
  284. }
  285. else
  286. {
  287. OnLeave (view);
  288. }
  289. SetNeedsDisplay ();
  290. }
  291. // Remove focus down the chain of subviews if focus is removed
  292. if (!value && Focused is { })
  293. {
  294. View f = Focused;
  295. f.OnLeave (view);
  296. f.SetHasFocus (false, view);
  297. Focused = null;
  298. }
  299. }
  300. /// <summary>Event fired when the <see cref="CanFocus"/> value is being changed.</summary>
  301. public event EventHandler CanFocusChanged;
  302. /// <summary>Method invoked when the <see cref="CanFocus"/> property from a view is changed.</summary>
  303. public virtual void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
  304. private bool _oldCanFocus;
  305. private bool _canFocus;
  306. /// <summary>Gets or sets a value indicating whether this <see cref="View"/> can focus.</summary>
  307. public bool CanFocus
  308. {
  309. get => _canFocus;
  310. set
  311. {
  312. if (!_addingView && IsInitialized && SuperView?.CanFocus == false && value)
  313. {
  314. throw new InvalidOperationException ("Cannot set CanFocus to true if the SuperView CanFocus is false!");
  315. }
  316. if (_canFocus == value)
  317. {
  318. return;
  319. }
  320. _canFocus = value;
  321. switch (_canFocus)
  322. {
  323. case false when _tabIndex > -1:
  324. TabIndex = -1;
  325. break;
  326. case true when SuperView?.CanFocus == false && _addingView:
  327. SuperView.CanFocus = true;
  328. break;
  329. }
  330. if (_canFocus && _tabIndex == -1)
  331. {
  332. TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
  333. }
  334. TabStop = _canFocus;
  335. if (!_canFocus && SuperView?.Focused == this)
  336. {
  337. SuperView.Focused = null;
  338. }
  339. if (!_canFocus && HasFocus)
  340. {
  341. SetHasFocus (false, this);
  342. SuperView?.EnsureFocus ();
  343. if (SuperView is { } && SuperView.Focused is null)
  344. {
  345. SuperView.FocusNext ();
  346. if (SuperView.Focused is null && Application.Current is { })
  347. {
  348. Application.Current.FocusNext ();
  349. }
  350. Application.BringOverlappedTopToFront ();
  351. }
  352. }
  353. if (_subviews is { } && IsInitialized)
  354. {
  355. foreach (View view in _subviews)
  356. {
  357. if (view.CanFocus != value)
  358. {
  359. if (!value)
  360. {
  361. view._oldCanFocus = view.CanFocus;
  362. view._oldTabIndex = view._tabIndex;
  363. view.CanFocus = false;
  364. view._tabIndex = -1;
  365. }
  366. else
  367. {
  368. if (_addingView)
  369. {
  370. view._addingView = true;
  371. }
  372. view.CanFocus = view._oldCanFocus;
  373. view._tabIndex = view._oldTabIndex;
  374. view._addingView = false;
  375. }
  376. }
  377. }
  378. }
  379. OnCanFocusChanged ();
  380. SetNeedsDisplay ();
  381. }
  382. }
  383. /// <summary>Method invoked when a view gets focus.</summary>
  384. /// <param name="view">The view that is losing focus.</param>
  385. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  386. public virtual bool OnEnter (View view)
  387. {
  388. var args = new FocusEventArgs (view);
  389. Enter?.Invoke (this, args);
  390. if (args.Handled)
  391. {
  392. return true;
  393. }
  394. return false;
  395. }
  396. /// <summary>Method invoked when a view loses focus.</summary>
  397. /// <param name="view">The view that is getting focus.</param>
  398. /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
  399. public virtual bool OnLeave (View view)
  400. {
  401. var args = new FocusEventArgs (view);
  402. Leave?.Invoke (this, args);
  403. if (args.Handled)
  404. {
  405. return true;
  406. }
  407. Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  408. return false;
  409. }
  410. /// <summary>Returns the currently focused view inside this view, or null if nothing is focused.</summary>
  411. /// <value>The focused.</value>
  412. public View Focused { get; private set; }
  413. /// <summary>Returns the most focused view in the chain of subviews (the leaf view that has the focus).</summary>
  414. /// <value>The most focused View.</value>
  415. public View MostFocused
  416. {
  417. get
  418. {
  419. if (Focused is null)
  420. {
  421. return null;
  422. }
  423. View most = Focused.MostFocused;
  424. if (most is { })
  425. {
  426. return most;
  427. }
  428. return Focused;
  429. }
  430. }
  431. /// <summary>Causes the specified subview to have focus.</summary>
  432. /// <param name="view">View.</param>
  433. private void SetFocus (View view)
  434. {
  435. if (view is null)
  436. {
  437. return;
  438. }
  439. //Console.WriteLine ($"Request to focus {view}");
  440. if (!view.CanFocus || !view.Visible || !view.Enabled)
  441. {
  442. return;
  443. }
  444. if (Focused?._hasFocus == true && Focused == view)
  445. {
  446. return;
  447. }
  448. if ((Focused?._hasFocus == true && Focused?.SuperView == view) || view == this)
  449. {
  450. if (!view._hasFocus)
  451. {
  452. view._hasFocus = true;
  453. }
  454. return;
  455. }
  456. // Make sure that this view is a subview
  457. View c;
  458. for (c = view._superView; c != null; c = c._superView)
  459. {
  460. if (c == this)
  461. {
  462. break;
  463. }
  464. }
  465. if (c is null)
  466. {
  467. throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
  468. }
  469. if (Focused is { })
  470. {
  471. Focused.SetHasFocus (false, view);
  472. }
  473. View f = Focused;
  474. Focused = view;
  475. Focused.SetHasFocus (true, f);
  476. Focused.EnsureFocus ();
  477. // Send focus upwards
  478. if (SuperView is { })
  479. {
  480. SuperView.SetFocus (this);
  481. }
  482. else
  483. {
  484. SetFocus (this);
  485. }
  486. }
  487. /// <summary>Causes the specified view and the entire parent hierarchy to have the focused order updated.</summary>
  488. public void SetFocus ()
  489. {
  490. if (!CanBeVisible (this) || !Enabled)
  491. {
  492. if (HasFocus)
  493. {
  494. SetHasFocus (false, this);
  495. }
  496. return;
  497. }
  498. if (SuperView is { })
  499. {
  500. SuperView.SetFocus (this);
  501. }
  502. else
  503. {
  504. SetFocus (this);
  505. }
  506. }
  507. /// <summary>
  508. /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise,
  509. /// does nothing.
  510. /// </summary>
  511. public void EnsureFocus ()
  512. {
  513. if (Focused is null && _subviews?.Count > 0)
  514. {
  515. if (FocusDirection == NavigationDirection.Forward)
  516. {
  517. FocusFirst ();
  518. }
  519. else
  520. {
  521. FocusLast ();
  522. }
  523. }
  524. }
  525. /// <summary>Focuses the first focusable subview if one exists.</summary>
  526. public void FocusFirst ()
  527. {
  528. if (!CanBeVisible (this))
  529. {
  530. return;
  531. }
  532. if (_tabIndexes is null)
  533. {
  534. SuperView?.SetFocus (this);
  535. return;
  536. }
  537. foreach (View view in _tabIndexes)
  538. {
  539. if (view.CanFocus && view._tabStop && view.Visible && view.Enabled)
  540. {
  541. SetFocus (view);
  542. return;
  543. }
  544. }
  545. }
  546. /// <summary>Focuses the last focusable subview if one exists.</summary>
  547. public void FocusLast ()
  548. {
  549. if (!CanBeVisible (this))
  550. {
  551. return;
  552. }
  553. if (_tabIndexes is null)
  554. {
  555. SuperView?.SetFocus (this);
  556. return;
  557. }
  558. for (int i = _tabIndexes.Count; i > 0;)
  559. {
  560. i--;
  561. View v = _tabIndexes [i];
  562. if (v.CanFocus && v._tabStop && v.Visible && v.Enabled)
  563. {
  564. SetFocus (v);
  565. return;
  566. }
  567. }
  568. }
  569. /// <summary>Focuses the previous view.</summary>
  570. /// <returns><see langword="true"/> if previous was focused, <see langword="false"/> otherwise.</returns>
  571. public bool FocusPrev ()
  572. {
  573. if (!CanBeVisible (this))
  574. {
  575. return false;
  576. }
  577. FocusDirection = NavigationDirection.Backward;
  578. if (_tabIndexes is null || _tabIndexes.Count == 0)
  579. {
  580. return false;
  581. }
  582. if (Focused is null)
  583. {
  584. FocusLast ();
  585. return Focused != null;
  586. }
  587. int focusedIdx = -1;
  588. for (int i = _tabIndexes.Count; i > 0;)
  589. {
  590. i--;
  591. View w = _tabIndexes [i];
  592. if (w.HasFocus)
  593. {
  594. if (w.FocusPrev ())
  595. {
  596. return true;
  597. }
  598. focusedIdx = i;
  599. continue;
  600. }
  601. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  602. {
  603. Focused.SetHasFocus (false, w);
  604. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  605. {
  606. w.FocusLast ();
  607. }
  608. SetFocus (w);
  609. return true;
  610. }
  611. }
  612. if (Focused is { })
  613. {
  614. Focused.SetHasFocus (false, this);
  615. Focused = null;
  616. }
  617. return false;
  618. }
  619. /// <summary>Focuses the next view.</summary>
  620. /// <returns><see langword="true"/> if next was focused, <see langword="false"/> otherwise.</returns>
  621. public bool FocusNext ()
  622. {
  623. if (!CanBeVisible (this))
  624. {
  625. return false;
  626. }
  627. FocusDirection = NavigationDirection.Forward;
  628. if (_tabIndexes is null || _tabIndexes.Count == 0)
  629. {
  630. return false;
  631. }
  632. if (Focused is null)
  633. {
  634. FocusFirst ();
  635. return Focused != null;
  636. }
  637. int focusedIdx = -1;
  638. for (var i = 0; i < _tabIndexes.Count; i++)
  639. {
  640. View w = _tabIndexes [i];
  641. if (w.HasFocus)
  642. {
  643. if (w.FocusNext ())
  644. {
  645. return true;
  646. }
  647. focusedIdx = i;
  648. continue;
  649. }
  650. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  651. {
  652. Focused.SetHasFocus (false, w);
  653. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  654. {
  655. w.FocusFirst ();
  656. }
  657. SetFocus (w);
  658. return true;
  659. }
  660. }
  661. if (Focused is { })
  662. {
  663. Focused.SetHasFocus (false, this);
  664. Focused = null;
  665. }
  666. return false;
  667. }
  668. private View GetMostFocused (View view)
  669. {
  670. if (view is null)
  671. {
  672. return null;
  673. }
  674. return view.Focused is { } ? GetMostFocused (view.Focused) : view;
  675. }
  676. /// <summary>Positions the cursor in the right position based on the currently focused view in the chain.</summary>
  677. /// Views that are focusable should override
  678. /// <see cref="PositionCursor"/>
  679. /// to ensure
  680. /// the cursor is placed in a location that makes sense. Unix terminals do not have
  681. /// a way of hiding the cursor, so it can be distracting to have the cursor left at
  682. /// the last focused view. Views should make sure that they place the cursor
  683. /// in a visually sensible place.
  684. public virtual void PositionCursor ()
  685. {
  686. if (!CanBeVisible (this) || !Enabled)
  687. {
  688. return;
  689. }
  690. // BUGBUG: v2 - This needs to support Subviews of Adornments too
  691. if (Focused is null && SuperView is { })
  692. {
  693. SuperView.EnsureFocus ();
  694. }
  695. else if (Focused is { Visible: true, Enabled: true, Frame: { Width: > 0, Height: > 0 } })
  696. {
  697. Focused.PositionCursor ();
  698. }
  699. else if (Focused?.Visible == true && Focused?.Enabled == false)
  700. {
  701. Focused = null;
  702. }
  703. else if (CanFocus && HasFocus && Visible && Frame.Width > 0 && Frame.Height > 0)
  704. {
  705. Move (TextFormatter.HotKeyPos == -1 ? 0 : TextFormatter.CursorPosition, 0);
  706. }
  707. else
  708. {
  709. Move (_frame.X, _frame.Y);
  710. }
  711. }
  712. #endregion Focus
  713. }