ViewSubViews.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. Rect 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. // BUGBUG: v2 - Seems weird that this is in View and not Responder.
  270. private bool _hasFocus;
  271. /// <inheritdoc/>
  272. public override bool HasFocus => _hasFocus;
  273. private void SetHasFocus (bool value, View view, bool force = false)
  274. {
  275. if (_hasFocus != value || force)
  276. {
  277. _hasFocus = value;
  278. if (value)
  279. {
  280. OnEnter (view);
  281. }
  282. else
  283. {
  284. OnLeave (view);
  285. }
  286. SetNeedsDisplay ();
  287. }
  288. // Remove focus down the chain of subviews if focus is removed
  289. if (!value && Focused is { })
  290. {
  291. View f = Focused;
  292. f.OnLeave (view);
  293. f.SetHasFocus (false, view);
  294. Focused = null;
  295. }
  296. }
  297. /// <summary>Event fired when the <see cref="CanFocus"/> value is being changed.</summary>
  298. public event EventHandler CanFocusChanged;
  299. /// <inheritdoc/>
  300. public override void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
  301. private bool _oldCanFocus;
  302. /// <summary>Gets or sets a value indicating whether this <see cref="View"/> can focus.</summary>
  303. /// <remarks>
  304. /// Override of <see cref="Responder"/>.<see cref="Responder.CanFocus"/>.
  305. /// <para/>
  306. /// Get accessor directly returns <see cref="Responder"/>.<see cref="Responder.CanFocus"/>.
  307. /// <para/>
  308. /// Set accessor validates <see langword="value"/> before setting <see cref="Responder"/>.
  309. /// <see cref="Responder.CanFocus"/>.
  310. /// </remarks>
  311. public override bool CanFocus
  312. {
  313. get => base.CanFocus;
  314. set
  315. {
  316. if (!_addingView && IsInitialized && SuperView?.CanFocus == false && value)
  317. {
  318. throw new InvalidOperationException ("Cannot set CanFocus to true if the SuperView CanFocus is false!");
  319. }
  320. if (base.CanFocus != value)
  321. {
  322. base.CanFocus = value;
  323. switch (value)
  324. {
  325. case false when _tabIndex > -1:
  326. TabIndex = -1;
  327. break;
  328. case true when SuperView?.CanFocus == false && _addingView:
  329. SuperView.CanFocus = true;
  330. break;
  331. }
  332. if (value && _tabIndex == -1)
  333. {
  334. TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
  335. }
  336. TabStop = value;
  337. if (!value && SuperView?.Focused == this)
  338. {
  339. SuperView.Focused = null;
  340. }
  341. if (!value && HasFocus)
  342. {
  343. SetHasFocus (false, this);
  344. SuperView?.EnsureFocus ();
  345. if (SuperView is { } && SuperView.Focused is null)
  346. {
  347. SuperView.FocusNext ();
  348. if (SuperView.Focused is null && Application.Current is { })
  349. {
  350. Application.Current.FocusNext ();
  351. }
  352. Application.BringOverlappedTopToFront ();
  353. }
  354. }
  355. if (_subviews is { } && IsInitialized)
  356. {
  357. foreach (View view in _subviews)
  358. {
  359. if (view.CanFocus != value)
  360. {
  361. if (!value)
  362. {
  363. view._oldCanFocus = view.CanFocus;
  364. view._oldTabIndex = view._tabIndex;
  365. view.CanFocus = false;
  366. view._tabIndex = -1;
  367. }
  368. else
  369. {
  370. if (_addingView)
  371. {
  372. view._addingView = true;
  373. }
  374. view.CanFocus = view._oldCanFocus;
  375. view._tabIndex = view._oldTabIndex;
  376. view._addingView = false;
  377. }
  378. }
  379. }
  380. }
  381. OnCanFocusChanged ();
  382. SetNeedsDisplay ();
  383. }
  384. }
  385. }
  386. /// <inheritdoc/>
  387. public override bool OnEnter (View view)
  388. {
  389. var args = new FocusEventArgs (view);
  390. Enter?.Invoke (this, args);
  391. if (args.Handled)
  392. {
  393. return true;
  394. }
  395. if (base.OnEnter (view))
  396. {
  397. return true;
  398. }
  399. return false;
  400. }
  401. /// <inheritdoc/>
  402. public override bool OnLeave (View view)
  403. {
  404. var args = new FocusEventArgs (view);
  405. Leave?.Invoke (this, args);
  406. if (args.Handled)
  407. {
  408. return true;
  409. }
  410. if (base.OnLeave (view))
  411. {
  412. return true;
  413. }
  414. Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  415. return false;
  416. }
  417. /// <summary>Returns the currently focused view inside this view, or null if nothing is focused.</summary>
  418. /// <value>The focused.</value>
  419. public View Focused { get; private set; }
  420. /// <summary>Returns the most focused view in the chain of subviews (the leaf view that has the focus).</summary>
  421. /// <value>The most focused View.</value>
  422. public View MostFocused
  423. {
  424. get
  425. {
  426. if (Focused is null)
  427. {
  428. return null;
  429. }
  430. View most = Focused.MostFocused;
  431. if (most is { })
  432. {
  433. return most;
  434. }
  435. return Focused;
  436. }
  437. }
  438. /// <summary>Causes the specified subview to have focus.</summary>
  439. /// <param name="view">View.</param>
  440. private void SetFocus (View view)
  441. {
  442. if (view is null)
  443. {
  444. return;
  445. }
  446. //Console.WriteLine ($"Request to focus {view}");
  447. if (!view.CanFocus || !view.Visible || !view.Enabled)
  448. {
  449. return;
  450. }
  451. if (Focused?._hasFocus == true && Focused == view)
  452. {
  453. return;
  454. }
  455. if ((Focused?._hasFocus == true && Focused?.SuperView == view) || view == this)
  456. {
  457. if (!view._hasFocus)
  458. {
  459. view._hasFocus = true;
  460. }
  461. return;
  462. }
  463. // Make sure that this view is a subview
  464. View c;
  465. for (c = view._superView; c != null; c = c._superView)
  466. {
  467. if (c == this)
  468. {
  469. break;
  470. }
  471. }
  472. if (c is null)
  473. {
  474. throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
  475. }
  476. if (Focused is { })
  477. {
  478. Focused.SetHasFocus (false, view);
  479. }
  480. View f = Focused;
  481. Focused = view;
  482. Focused.SetHasFocus (true, f);
  483. Focused.EnsureFocus ();
  484. // Send focus upwards
  485. if (SuperView is { })
  486. {
  487. SuperView.SetFocus (this);
  488. }
  489. else
  490. {
  491. SetFocus (this);
  492. }
  493. }
  494. /// <summary>Causes the specified view and the entire parent hierarchy to have the focused order updated.</summary>
  495. public void SetFocus ()
  496. {
  497. if (!CanBeVisible (this) || !Enabled)
  498. {
  499. if (HasFocus)
  500. {
  501. SetHasFocus (false, this);
  502. }
  503. return;
  504. }
  505. if (SuperView is { })
  506. {
  507. SuperView.SetFocus (this);
  508. }
  509. else
  510. {
  511. SetFocus (this);
  512. }
  513. }
  514. /// <summary>
  515. /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise,
  516. /// does nothing.
  517. /// </summary>
  518. public void EnsureFocus ()
  519. {
  520. if (Focused is null && _subviews?.Count > 0)
  521. {
  522. if (FocusDirection == NavigationDirection.Forward)
  523. {
  524. FocusFirst ();
  525. }
  526. else
  527. {
  528. FocusLast ();
  529. }
  530. }
  531. }
  532. /// <summary>Focuses the first focusable subview if one exists.</summary>
  533. public void FocusFirst ()
  534. {
  535. if (!CanBeVisible (this))
  536. {
  537. return;
  538. }
  539. if (_tabIndexes is null)
  540. {
  541. SuperView?.SetFocus (this);
  542. return;
  543. }
  544. foreach (View view in _tabIndexes)
  545. {
  546. if (view.CanFocus && view._tabStop && view.Visible && view.Enabled)
  547. {
  548. SetFocus (view);
  549. return;
  550. }
  551. }
  552. }
  553. /// <summary>Focuses the last focusable subview if one exists.</summary>
  554. public void FocusLast ()
  555. {
  556. if (!CanBeVisible (this))
  557. {
  558. return;
  559. }
  560. if (_tabIndexes is null)
  561. {
  562. SuperView?.SetFocus (this);
  563. return;
  564. }
  565. for (int i = _tabIndexes.Count; i > 0;)
  566. {
  567. i--;
  568. View v = _tabIndexes [i];
  569. if (v.CanFocus && v._tabStop && v.Visible && v.Enabled)
  570. {
  571. SetFocus (v);
  572. return;
  573. }
  574. }
  575. }
  576. /// <summary>Focuses the previous view.</summary>
  577. /// <returns><see langword="true"/> if previous was focused, <see langword="false"/> otherwise.</returns>
  578. public bool FocusPrev ()
  579. {
  580. if (!CanBeVisible (this))
  581. {
  582. return false;
  583. }
  584. FocusDirection = NavigationDirection.Backward;
  585. if (_tabIndexes is null || _tabIndexes.Count == 0)
  586. {
  587. return false;
  588. }
  589. if (Focused is null)
  590. {
  591. FocusLast ();
  592. return Focused != null;
  593. }
  594. int focusedIdx = -1;
  595. for (int i = _tabIndexes.Count; i > 0;)
  596. {
  597. i--;
  598. View w = _tabIndexes [i];
  599. if (w.HasFocus)
  600. {
  601. if (w.FocusPrev ())
  602. {
  603. return true;
  604. }
  605. focusedIdx = i;
  606. continue;
  607. }
  608. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  609. {
  610. Focused.SetHasFocus (false, w);
  611. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  612. {
  613. w.FocusLast ();
  614. }
  615. SetFocus (w);
  616. return true;
  617. }
  618. }
  619. if (Focused is { })
  620. {
  621. Focused.SetHasFocus (false, this);
  622. Focused = null;
  623. }
  624. return false;
  625. }
  626. /// <summary>Focuses the next view.</summary>
  627. /// <returns><see langword="true"/> if next was focused, <see langword="false"/> otherwise.</returns>
  628. public bool FocusNext ()
  629. {
  630. if (!CanBeVisible (this))
  631. {
  632. return false;
  633. }
  634. FocusDirection = NavigationDirection.Forward;
  635. if (_tabIndexes is null || _tabIndexes.Count == 0)
  636. {
  637. return false;
  638. }
  639. if (Focused is null)
  640. {
  641. FocusFirst ();
  642. return Focused != null;
  643. }
  644. int focusedIdx = -1;
  645. for (var i = 0; i < _tabIndexes.Count; i++)
  646. {
  647. View w = _tabIndexes [i];
  648. if (w.HasFocus)
  649. {
  650. if (w.FocusNext ())
  651. {
  652. return true;
  653. }
  654. focusedIdx = i;
  655. continue;
  656. }
  657. if (w.CanFocus && focusedIdx != -1 && w._tabStop && w.Visible && w.Enabled)
  658. {
  659. Focused.SetHasFocus (false, w);
  660. if (w.CanFocus && w._tabStop && w.Visible && w.Enabled)
  661. {
  662. w.FocusFirst ();
  663. }
  664. SetFocus (w);
  665. return true;
  666. }
  667. }
  668. if (Focused is { })
  669. {
  670. Focused.SetHasFocus (false, this);
  671. Focused = null;
  672. }
  673. return false;
  674. }
  675. private View GetMostFocused (View view)
  676. {
  677. if (view is null)
  678. {
  679. return null;
  680. }
  681. return view.Focused is { } ? GetMostFocused (view.Focused) : view;
  682. }
  683. /// <summary>Positions the cursor in the right position based on the currently focused view in the chain.</summary>
  684. /// Views that are focusable should override
  685. /// <see cref="PositionCursor"/>
  686. /// to ensure
  687. /// the cursor is placed in a location that makes sense. Unix terminals do not have
  688. /// a way of hiding the cursor, so it can be distracting to have the cursor left at
  689. /// the last focused view. Views should make sure that they place the cursor
  690. /// in a visually sensible place.
  691. public virtual void PositionCursor ()
  692. {
  693. if (!CanBeVisible (this) || !Enabled)
  694. {
  695. return;
  696. }
  697. // BUGBUG: v2 - This needs to support children of Frames too
  698. if (Focused is null && SuperView is { })
  699. {
  700. SuperView.EnsureFocus ();
  701. }
  702. else if (Focused?.Visible == true
  703. && Focused?.Enabled == true
  704. && Focused?.Frame.Width > 0
  705. && Focused.Frame.Height > 0)
  706. {
  707. Focused.PositionCursor ();
  708. }
  709. else if (Focused?.Visible == true && Focused?.Enabled == false)
  710. {
  711. Focused = null;
  712. }
  713. else if (CanFocus && HasFocus && Visible && Frame.Width > 0 && Frame.Height > 0)
  714. {
  715. Move (TextFormatter.HotKeyPos == -1 ? 0 : TextFormatter.CursorPosition, 0);
  716. }
  717. else
  718. {
  719. Move (_frame.X, _frame.Y);
  720. }
  721. }
  722. #endregion Focus
  723. }