-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling menu navigation and respecting focus on WindowsForms controls …
- Loading branch information
Showing
5 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace Fluent.Internal | ||
{ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
|
||
internal class FocusWrapper | ||
{ | ||
private readonly IInputElement inputElement; | ||
private readonly IntPtr handle; | ||
|
||
private FocusWrapper(IInputElement inputElement) | ||
{ | ||
this.inputElement = inputElement; | ||
} | ||
|
||
private FocusWrapper(IntPtr handle) | ||
{ | ||
this.handle = handle; | ||
} | ||
|
||
public void Focus() | ||
{ | ||
if (this.inputElement != null) | ||
{ | ||
this.inputElement.Focus(); | ||
return; | ||
} | ||
|
||
if (this.handle != IntPtr.Zero) | ||
{ | ||
NativeMethods.SetFocus(this.handle); | ||
return; | ||
} | ||
} | ||
|
||
public static FocusWrapper GetWrapperForCurrentFocus() | ||
{ | ||
if (Keyboard.FocusedElement != null) | ||
{ | ||
return new FocusWrapper(Keyboard.FocusedElement); | ||
} | ||
|
||
var handle = NativeMethods.GetFocus(); | ||
|
||
if (handle != IntPtr.Zero) | ||
{ | ||
return new FocusWrapper(handle); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters