ViewSubViews.cs 24 KB

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