|
@@ -353,24 +353,17 @@ public partial class View
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>Event fired when the <see cref="CanFocus"/> value is being changed.</summary>
|
|
|
public event EventHandler CanFocusChanged;
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
- public override void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
|
|
|
+ /// <summary>Method invoked when the <see cref="CanFocus"/> property from a view is changed.</summary>
|
|
|
+ public virtual void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
|
|
|
|
|
|
private bool _oldCanFocus;
|
|
|
private bool _canFocus;
|
|
|
|
|
|
/// <summary>Gets or sets a value indicating whether this <see cref="View"/> can focus.</summary>
|
|
|
- /// <remarks>
|
|
|
- /// Override of <see cref="Responder"/>.<see cref="Responder.CanFocus"/>.
|
|
|
- /// <para/>
|
|
|
- /// Get accessor directly returns <see cref="Responder"/>.<see cref="Responder.CanFocus"/>.
|
|
|
- /// <para/>
|
|
|
- /// Set accessor validates <see langword="value"/> before setting <see cref="Responder"/>.
|
|
|
- /// <see cref="Responder.CanFocus"/>.
|
|
|
- /// </remarks>
|
|
|
public bool CanFocus
|
|
|
{
|
|
|
get => _canFocus;
|
|
@@ -381,88 +374,92 @@ public partial class View
|
|
|
throw new InvalidOperationException ("Cannot set CanFocus to true if the SuperView CanFocus is false!");
|
|
|
}
|
|
|
|
|
|
- if (_canFocus != value)
|
|
|
+ if (_canFocus == value)
|
|
|
{
|
|
|
- _canFocus = value;
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- switch (value)
|
|
|
- {
|
|
|
- case false when _tabIndex > -1:
|
|
|
- TabIndex = -1;
|
|
|
+ _canFocus = value;
|
|
|
|
|
|
- break;
|
|
|
- case true when SuperView?.CanFocus == false && _addingView:
|
|
|
- SuperView.CanFocus = true;
|
|
|
+ switch (_canFocus)
|
|
|
+ {
|
|
|
+ case false when _tabIndex > -1:
|
|
|
+ TabIndex = -1;
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
+ break;
|
|
|
+ case true when SuperView?.CanFocus == false && _addingView:
|
|
|
+ SuperView.CanFocus = true;
|
|
|
|
|
|
- if (value && _tabIndex == -1)
|
|
|
- {
|
|
|
- TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
|
|
|
- }
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- TabStop = value;
|
|
|
+ if (_canFocus && _tabIndex == -1)
|
|
|
+ {
|
|
|
+ TabIndex = SuperView is { } ? SuperView._tabIndexes.IndexOf (this) : -1;
|
|
|
+ }
|
|
|
|
|
|
- if (!value && SuperView?.Focused == this)
|
|
|
- {
|
|
|
- SuperView.Focused = null;
|
|
|
- }
|
|
|
+ TabStop = _canFocus;
|
|
|
|
|
|
- if (!value && HasFocus)
|
|
|
- {
|
|
|
- SetHasFocus (false, this);
|
|
|
- SuperView?.EnsureFocus ();
|
|
|
+ if (!_canFocus && SuperView?.Focused == this)
|
|
|
+ {
|
|
|
+ SuperView.Focused = null;
|
|
|
+ }
|
|
|
|
|
|
- if (SuperView is { } && SuperView.Focused is null)
|
|
|
- {
|
|
|
- SuperView.FocusNext ();
|
|
|
+ if (!_canFocus && HasFocus)
|
|
|
+ {
|
|
|
+ SetHasFocus (false, this);
|
|
|
+ SuperView?.EnsureFocus ();
|
|
|
|
|
|
- if (SuperView.Focused is null && Application.Current is { })
|
|
|
- {
|
|
|
- Application.Current.FocusNext ();
|
|
|
- }
|
|
|
+ if (SuperView is { } && SuperView.Focused is null)
|
|
|
+ {
|
|
|
+ SuperView.FocusNext ();
|
|
|
|
|
|
- Application.BringOverlappedTopToFront ();
|
|
|
+ if (SuperView.Focused is null && Application.Current is { })
|
|
|
+ {
|
|
|
+ Application.Current.FocusNext ();
|
|
|
}
|
|
|
+
|
|
|
+ Application.BringOverlappedTopToFront ();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (_subviews is { } && IsInitialized)
|
|
|
+ if (_subviews is { } && IsInitialized)
|
|
|
+ {
|
|
|
+ foreach (View view in _subviews)
|
|
|
{
|
|
|
- foreach (View view in _subviews)
|
|
|
+ if (view.CanFocus != value)
|
|
|
{
|
|
|
- if (view.CanFocus != value)
|
|
|
+ if (!value)
|
|
|
{
|
|
|
- if (!value)
|
|
|
- {
|
|
|
- view._oldCanFocus = view.CanFocus;
|
|
|
- view._oldTabIndex = view._tabIndex;
|
|
|
- view.CanFocus = false;
|
|
|
- view._tabIndex = -1;
|
|
|
- }
|
|
|
- else
|
|
|
+ view._oldCanFocus = view.CanFocus;
|
|
|
+ view._oldTabIndex = view._tabIndex;
|
|
|
+ view.CanFocus = false;
|
|
|
+ view._tabIndex = -1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (_addingView)
|
|
|
{
|
|
|
- if (_addingView)
|
|
|
- {
|
|
|
- view._addingView = true;
|
|
|
- }
|
|
|
-
|
|
|
- view.CanFocus = view._oldCanFocus;
|
|
|
- view._tabIndex = view._oldTabIndex;
|
|
|
- view._addingView = false;
|
|
|
+ view._addingView = true;
|
|
|
}
|
|
|
+
|
|
|
+ view.CanFocus = view._oldCanFocus;
|
|
|
+ view._tabIndex = view._oldTabIndex;
|
|
|
+ view._addingView = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- OnCanFocusChanged ();
|
|
|
- SetNeedsDisplay ();
|
|
|
}
|
|
|
+
|
|
|
+ OnCanFocusChanged ();
|
|
|
+ SetNeedsDisplay ();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
- public override bool OnEnter (View view)
|
|
|
+ /// <summary>Method invoked when a view gets focus.</summary>
|
|
|
+ /// <param name="view">The view that is losing focus.</param>
|
|
|
+ /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
|
|
|
+ public virtual bool OnEnter (View view)
|
|
|
{
|
|
|
var args = new FocusEventArgs (view);
|
|
|
Enter?.Invoke (this, args);
|
|
@@ -472,16 +469,14 @@ public partial class View
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if (base.OnEnter (view))
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
- public override bool OnLeave (View view)
|
|
|
+
|
|
|
+ /// <summary>Method invoked when a view loses focus.</summary>
|
|
|
+ /// <param name="view">The view that is getting focus.</param>
|
|
|
+ /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
|
|
|
+ public virtual bool OnLeave (View view)
|
|
|
{
|
|
|
var args = new FocusEventArgs (view);
|
|
|
Leave?.Invoke (this, args);
|
|
@@ -491,11 +486,6 @@ public partial class View
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if (base.OnLeave (view))
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
Driver?.SetCursorVisibility (CursorVisibility.Invisible);
|
|
|
|
|
|
return false;
|