|
|
|
@ -2,6 +2,8 @@ |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Windows.Forms; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Avalonia.Win32.Interop; |
|
|
|
using Control = System.Windows.Forms.Control; |
|
|
|
|
|
|
|
@ -22,7 +24,10 @@ namespace Avalonia.Win32.Embedding |
|
|
|
value.PlatformImpl.Handle.HandleDescriptor); |
|
|
|
if (_child != null) |
|
|
|
{ |
|
|
|
_child.GotFocus -= _child_GotFocus; |
|
|
|
_child.PlatformImpl.LostFocus -= PlatformImpl_LostFocus; |
|
|
|
_child.PlatformImpl.Hide(); |
|
|
|
Unfocus(); |
|
|
|
UnmanagedMethods.SetParent(_child.PlatformImpl.Handle.Handle, EmbeddedWindowImpl.DefaultParentWindow); |
|
|
|
} |
|
|
|
_child = value; |
|
|
|
@ -30,12 +35,51 @@ namespace Avalonia.Win32.Embedding |
|
|
|
{ |
|
|
|
UnmanagedMethods.SetParent(_child.PlatformImpl.Handle.Handle, Handle); |
|
|
|
_child.Prepare(); |
|
|
|
if (_child.IsFocused) |
|
|
|
FocusManager.Instance.Focus(null); |
|
|
|
_child.GotFocus += _child_GotFocus; |
|
|
|
_child.PlatformImpl.LostFocus += PlatformImpl_LostFocus; |
|
|
|
FixPosition(); |
|
|
|
|
|
|
|
if(Focused) |
|
|
|
UnmanagedMethods.SetFocus(_child.PlatformImpl.Handle.Handle); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Unfocus() |
|
|
|
{ |
|
|
|
var focused = (IVisual)FocusManager.Instance.Current; |
|
|
|
if (focused == null) |
|
|
|
return; |
|
|
|
while (focused.VisualParent != null) |
|
|
|
focused = focused.VisualParent; |
|
|
|
|
|
|
|
if (focused == _child) |
|
|
|
KeyboardDevice.Instance.SetFocusedElement(null, NavigationMethod.Unspecified, InputModifiers.None); |
|
|
|
} |
|
|
|
|
|
|
|
private void PlatformImpl_LostFocus() |
|
|
|
{ |
|
|
|
Unfocus(); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void Dispose(bool disposing) |
|
|
|
{ |
|
|
|
Child = null; |
|
|
|
base.Dispose(disposing); |
|
|
|
} |
|
|
|
|
|
|
|
private void _child_GotFocus(object sender, Interactivity.RoutedEventArgs e) |
|
|
|
{ |
|
|
|
UnmanagedMethods.SetFocus(_child.PlatformImpl.Handle.Handle); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnGotFocus(EventArgs e) |
|
|
|
{ |
|
|
|
if (_child != null) |
|
|
|
UnmanagedMethods.SetFocus(_child.PlatformImpl.Handle.Handle); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FixPosition() |
|
|
|
{ |
|
|
|
|