|
@@ -898,23 +898,27 @@ namespace Terminal.Gui {
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
public override bool HasFocus {
|
|
public override bool HasFocus {
|
|
get {
|
|
get {
|
|
- return base.HasFocus;
|
|
|
|
|
|
+ return hasFocus;
|
|
}
|
|
}
|
|
- internal set {
|
|
|
|
- if (base.HasFocus != value)
|
|
|
|
- if (value)
|
|
|
|
- OnEnter ();
|
|
|
|
- else
|
|
|
|
- OnLeave ();
|
|
|
|
- SetNeedsDisplay ();
|
|
|
|
- base.HasFocus = value;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- // Remove focus down the chain of subviews if focus is removed
|
|
|
|
- if (!value && focused != null) {
|
|
|
|
- focused.OnLeave ();
|
|
|
|
- focused.HasFocus = false;
|
|
|
|
- focused = null;
|
|
|
|
- }
|
|
|
|
|
|
+ void SetHasFocus (bool value, View view)
|
|
|
|
+ {
|
|
|
|
+ if (hasFocus != value) {
|
|
|
|
+ hasFocus = value;
|
|
|
|
+ }
|
|
|
|
+ if (value) {
|
|
|
|
+ OnEnter (view);
|
|
|
|
+ } else {
|
|
|
|
+ OnLeave (view);
|
|
|
|
+ }
|
|
|
|
+ SetNeedsDisplay ();
|
|
|
|
+
|
|
|
|
+ // Remove focus down the chain of subviews if focus is removed
|
|
|
|
+ if (!value && focused != null) {
|
|
|
|
+ focused.OnLeave (focused);
|
|
|
|
+ focused.hasFocus = false;
|
|
|
|
+ focused = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -925,35 +929,40 @@ namespace Terminal.Gui {
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Constructs.
|
|
/// Constructs.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public FocusEventArgs () { }
|
|
|
|
|
|
+ /// <param name="view">The view that gets or loses focus.</param>
|
|
|
|
+ public FocusEventArgs (View view) { View = view; }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber.
|
|
/// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber.
|
|
/// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
|
|
/// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
|
|
/// </summary>
|
|
/// </summary>
|
|
public bool Handled { get; set; }
|
|
public bool Handled { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Indicates the current view that gets or loses focus.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public View View { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public override bool OnEnter ()
|
|
|
|
|
|
+ public override bool OnEnter (View view)
|
|
{
|
|
{
|
|
- FocusEventArgs args = new FocusEventArgs ();
|
|
|
|
|
|
+ FocusEventArgs args = new FocusEventArgs (view);
|
|
Enter?.Invoke (args);
|
|
Enter?.Invoke (args);
|
|
if (args.Handled)
|
|
if (args.Handled)
|
|
return true;
|
|
return true;
|
|
- if (base.OnEnter ())
|
|
|
|
|
|
+ if (base.OnEnter (view))
|
|
return true;
|
|
return true;
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public override bool OnLeave ()
|
|
|
|
|
|
+ public override bool OnLeave (View view)
|
|
{
|
|
{
|
|
- FocusEventArgs args = new FocusEventArgs ();
|
|
|
|
|
|
+ FocusEventArgs args = new FocusEventArgs (view);
|
|
Leave?.Invoke (args);
|
|
Leave?.Invoke (args);
|
|
if (args.Handled)
|
|
if (args.Handled)
|
|
return true;
|
|
return true;
|
|
- if (base.OnLeave ())
|
|
|
|
|
|
+ if (base.OnLeave (view))
|
|
return true;
|
|
return true;
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -1123,10 +1132,10 @@ namespace Terminal.Gui {
|
|
throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
|
|
throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
|
|
|
|
|
|
if (focused != null)
|
|
if (focused != null)
|
|
- focused.HasFocus = false;
|
|
|
|
|
|
+ focused.SetHasFocus (false, view);
|
|
|
|
|
|
focused = view;
|
|
focused = view;
|
|
- focused.HasFocus = true;
|
|
|
|
|
|
+ focused.SetHasFocus (true, view);
|
|
focused.EnsureFocus ();
|
|
focused.EnsureFocus ();
|
|
|
|
|
|
// Send focus upwards
|
|
// Send focus upwards
|
|
@@ -1320,7 +1329,7 @@ namespace Terminal.Gui {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if (w.CanFocus && focused_idx != -1) {
|
|
if (w.CanFocus && focused_idx != -1) {
|
|
- focused.HasFocus = false;
|
|
|
|
|
|
+ focused.SetHasFocus (false, w);
|
|
|
|
|
|
if (w != null && w.CanFocus)
|
|
if (w != null && w.CanFocus)
|
|
w.FocusLast ();
|
|
w.FocusLast ();
|
|
@@ -1330,7 +1339,7 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (focused != null) {
|
|
if (focused != null) {
|
|
- focused.HasFocus = false;
|
|
|
|
|
|
+ focused.SetHasFocus (false, focused);
|
|
focused = null;
|
|
focused = null;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
@@ -1362,7 +1371,7 @@ namespace Terminal.Gui {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if (w.CanFocus && focused_idx != -1) {
|
|
if (w.CanFocus && focused_idx != -1) {
|
|
- focused.HasFocus = false;
|
|
|
|
|
|
+ focused.SetHasFocus (false, w);
|
|
|
|
|
|
if (w != null && w.CanFocus)
|
|
if (w != null && w.CanFocus)
|
|
w.FocusFirst ();
|
|
w.FocusFirst ();
|
|
@@ -1372,7 +1381,7 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (focused != null) {
|
|
if (focused != null) {
|
|
- focused.HasFocus = false;
|
|
|
|
|
|
+ focused.SetHasFocus (false, focused);
|
|
focused = null;
|
|
focused = null;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|