Browse Source

Merged LostFocus to ITopLevelImpl

pull/3866/head
Nikita Tsukanov 7 years ago
parent
commit
636c6800cf
  1. 2
      src/Android/Avalonia.Android/AndroidPlatform.cs
  2. 4
      src/Android/Avalonia.Android/AvaloniaView.cs
  3. 2
      src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
  4. 5
      src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs
  5. 1
      src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs
  6. 8
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  7. 12
      src/Avalonia.Controls/Platform/IEmbeddableWindowImpl.cs
  8. 5
      src/Avalonia.Controls/Platform/ITopLevelImpl.cs
  9. 2
      src/Avalonia.Controls/Platform/IWindowingPlatform.cs
  10. 2
      src/Avalonia.Controls/Platform/PlatformManager.cs
  11. 3
      src/Avalonia.Controls/Primitives/Popup.cs
  12. 4
      src/Avalonia.Controls/Remote/RemoteServer.cs
  13. 3
      src/Avalonia.Controls/TopLevel.cs
  14. 7
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  15. 2
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowingPlatform.cs
  16. 1
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  17. 2
      src/Avalonia.Native/AvaloniaNativePlatform.cs
  18. 5
      src/Avalonia.Native/WindowImplBase.cs
  19. 2
      src/Avalonia.X11/X11Platform.cs
  20. 1
      src/Avalonia.X11/X11Window.cs
  21. 8
      src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs
  22. 2
      src/Windows/Avalonia.Win32/Win32Platform.cs
  23. 5
      src/Windows/Avalonia.Win32/WindowImpl.cs
  24. 8
      src/iOS/Avalonia.iOS/EmbeddableImpl.cs
  25. 2
      src/iOS/Avalonia.iOS/TopLevelImpl.cs
  26. 2
      src/iOS/Avalonia.iOS/WindowingPlatformImpl.cs
  27. 4
      tests/Avalonia.Controls.UnitTests/WindowingPlatformMock.cs
  28. 2
      tests/Avalonia.UnitTests/MockWindowingPlatform.cs

2
src/Android/Avalonia.Android/AndroidPlatform.cs

@ -67,7 +67,7 @@ namespace Avalonia.Android
throw new NotSupportedException(); throw new NotSupportedException();
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

4
src/Android/Avalonia.Android/AvaloniaView.cs

@ -33,10 +33,8 @@ namespace Avalonia.Android
return _view.View.DispatchKeyEvent(e); return _view.View.DispatchKeyEvent(e);
} }
class ViewImpl : TopLevelImpl, IEmbeddableWindowImpl class ViewImpl : TopLevelImpl
{ {
public event Action LostFocus;
public ViewImpl(Context context) : base(context) public ViewImpl(Context context) : base(context)
{ {
View.Focusable = true; View.Focusable = true;

2
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

@ -194,6 +194,8 @@ namespace Avalonia.Android.Platform.SkiaPlatform
} }
public IPopupImpl CreatePopup() => null; public IPopupImpl CreatePopup() => null;
public Action LostFocus { get; set; }
ILockedFramebuffer IFramebufferPlatformSurface.Lock()=>new AndroidFramebuffer(_view.Holder.Surface); ILockedFramebuffer IFramebufferPlatformSurface.Lock()=>new AndroidFramebuffer(_view.Holder.Surface);
} }

5
src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs

@ -10,7 +10,7 @@ namespace Avalonia.Controls.Embedding
{ {
public class EmbeddableControlRoot : TopLevel, IStyleable, IFocusScope, IDisposable public class EmbeddableControlRoot : TopLevel, IStyleable, IFocusScope, IDisposable
{ {
public EmbeddableControlRoot(IEmbeddableWindowImpl impl) : base(impl) public EmbeddableControlRoot(ITopLevelImpl impl) : base(impl)
{ {
} }
@ -19,9 +19,6 @@ namespace Avalonia.Controls.Embedding
{ {
} }
[CanBeNull]
public new IEmbeddableWindowImpl PlatformImpl => (IEmbeddableWindowImpl) base.PlatformImpl;
protected bool EnforceClientSize { get; set; } = true; protected bool EnforceClientSize { get; set; } = true;
public void Prepare() public void Prepare()

1
src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevelImpl.cs

@ -60,6 +60,7 @@ namespace Avalonia.Controls.Embedding.Offscreen
} }
public Action Closed { get; set; } public Action Closed { get; set; }
public Action LostFocus { get; set; }
public abstract IMouseDevice MouseDevice { get; } public abstract IMouseDevice MouseDevice { get; }
public IPopupImpl CreatePopup() => null; public IPopupImpl CreatePopup() => null;
} }

8
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -67,8 +67,8 @@ namespace Avalonia.Controls.Platform
window.Deactivated += WindowDeactivated; window.Deactivated += WindowDeactivated;
} }
if (_root is TopLevel tl && tl.PlatformImpl is IEmbeddableWindowImpl eimpl) if (_root is TopLevel tl)
eimpl.LostFocus += TopLevelLostPlatformFocus; tl.PlatformImpl.LostFocus += TopLevelLostPlatformFocus;
_inputManagerSubscription = InputManager?.Process.Subscribe(RawInput); _inputManagerSubscription = InputManager?.Process.Subscribe(RawInput);
} }
@ -100,8 +100,8 @@ namespace Avalonia.Controls.Platform
root.Deactivated -= WindowDeactivated; root.Deactivated -= WindowDeactivated;
} }
if (_root is TopLevel tl && tl.PlatformImpl is IEmbeddableWindowImpl eimpl) if (_root is TopLevel tl)
eimpl.LostFocus -= TopLevelLostPlatformFocus; tl.PlatformImpl.LostFocus -= TopLevelLostPlatformFocus;
_inputManagerSubscription?.Dispose(); _inputManagerSubscription?.Dispose();

12
src/Avalonia.Controls/Platform/IEmbeddableWindowImpl.cs

@ -1,12 +0,0 @@
using System;
namespace Avalonia.Platform
{
/// <summary>
/// Defines a platform-specific embeddable window implementation.
/// </summary>
public interface IEmbeddableWindowImpl : ITopLevelImpl
{
event Action LostFocus;
}
}

5
src/Avalonia.Controls/Platform/ITopLevelImpl.cs

@ -98,6 +98,11 @@ namespace Avalonia.Platform
/// Gets or sets a method called when the underlying implementation is destroyed. /// Gets or sets a method called when the underlying implementation is destroyed.
/// </summary> /// </summary>
Action Closed { get; set; } Action Closed { get; set; }
/// <summary>
/// Gets or sets a method called when the input focus is lost.
/// </summary>
Action LostFocus { get; set; }
/// <summary> /// <summary>
/// Gets a mouse device associated with toplevel /// Gets a mouse device associated with toplevel

2
src/Avalonia.Controls/Platform/IWindowingPlatform.cs

@ -3,6 +3,6 @@ namespace Avalonia.Platform
public interface IWindowingPlatform public interface IWindowingPlatform
{ {
IWindowImpl CreateWindow(); IWindowImpl CreateWindow();
IEmbeddableWindowImpl CreateEmbeddableWindow(); IWindowImpl CreateEmbeddableWindow();
} }
} }

2
src/Avalonia.Controls/Platform/PlatformManager.cs

@ -34,7 +34,7 @@ namespace Avalonia.Controls.Platform
return s_designerMode ? (IWindowImpl)platform.CreateEmbeddableWindow() : platform.CreateWindow(); return s_designerMode ? (IWindowImpl)platform.CreateEmbeddableWindow() : platform.CreateWindow();
} }
public static IEmbeddableWindowImpl CreateEmbeddableWindow() public static IWindowImpl CreateEmbeddableWindow()
{ {
var platform = AvaloniaLocator.Current.GetService<IWindowingPlatform>(); var platform = AvaloniaLocator.Current.GetService<IWindowingPlatform>();
if (platform == null) if (platform == null)

3
src/Avalonia.Controls/Primitives/Popup.cs

@ -265,8 +265,7 @@ namespace Avalonia.Controls.Primitives
(x, handler) => x.Deactivated += handler, (x, handler) => x.Deactivated += handler,
(x, handler) => x.Deactivated -= handler)); (x, handler) => x.Deactivated -= handler));
if (window.PlatformImpl is IEmbeddableWindowImpl reportsFocus) DeferCleanup(SubscribeToEventHandler<IWindowImpl, Action>(window.PlatformImpl, WindowLostFocus,
DeferCleanup(SubscribeToEventHandler<IEmbeddableWindowImpl, Action>(reportsFocus, WindowLostFocus,
(x, handler) => x.LostFocus += handler, (x, handler) => x.LostFocus += handler,
(x, handler) => x.LostFocus -= handler)); (x, handler) => x.LostFocus -= handler));
} }

4
src/Avalonia.Controls/Remote/RemoteServer.cs

@ -10,13 +10,13 @@ namespace Avalonia.Controls.Remote
{ {
private EmbeddableControlRoot _topLevel; private EmbeddableControlRoot _topLevel;
class EmbeddableRemoteServerTopLevelImpl : RemoteServerTopLevelImpl, IEmbeddableWindowImpl class EmbeddableRemoteServerTopLevelImpl : RemoteServerTopLevelImpl
{ {
public EmbeddableRemoteServerTopLevelImpl(IAvaloniaRemoteTransportConnection transport) : base(transport) public EmbeddableRemoteServerTopLevelImpl(IAvaloniaRemoteTransportConnection transport) : base(transport)
{ {
} }
#pragma warning disable 67 #pragma warning disable 67
public event Action LostFocus; public Action LostFocus { get; set; }
} }

3
src/Avalonia.Controls/TopLevel.cs

@ -136,8 +136,7 @@ namespace Avalonia.Controls
this); this);
} }
if (impl is IEmbeddableWindowImpl embeddableWindowImpl) impl.LostFocus += PlatformImpl_LostFocus;
embeddableWindowImpl.LostFocus += PlatformImpl_LostFocus;
} }
/// <summary> /// <summary>

7
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -10,7 +10,7 @@ using Avalonia.Threading;
namespace Avalonia.DesignerSupport.Remote namespace Avalonia.DesignerSupport.Remote
{ {
class PreviewerWindowImpl : RemoteServerTopLevelImpl, IWindowImpl, IEmbeddableWindowImpl class PreviewerWindowImpl : RemoteServerTopLevelImpl, IWindowImpl
{ {
private readonly IAvaloniaRemoteTransportConnection _transport; private readonly IAvaloniaRemoteTransportConnection _transport;
@ -45,11 +45,6 @@ namespace Avalonia.DesignerSupport.Remote
public WindowState WindowState { get; set; } public WindowState WindowState { get; set; }
public Action<WindowState> WindowStateChanged { get; set; } public Action<WindowState> WindowStateChanged { get; set; }
public Size MaxClientSize { get; } = new Size(4096, 4096); public Size MaxClientSize { get; } = new Size(4096, 4096);
public event Action LostFocus
{
add {}
remove {}
}
protected override void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj) protected override void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj)
{ {

2
src/Avalonia.DesignerSupport/Remote/PreviewerWindowingPlatform.cs

@ -19,7 +19,7 @@ namespace Avalonia.DesignerSupport.Remote
public IWindowImpl CreateWindow() => new WindowStub(); public IWindowImpl CreateWindow() => new WindowStub();
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
if (s_lastWindow != null) if (s_lastWindow != null)
{ {

1
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@ -29,6 +29,7 @@ namespace Avalonia.DesignerSupport.Remote
public Action<double> ScalingChanged { get; set; } public Action<double> ScalingChanged { get; set; }
public Func<bool> Closing { get; set; } public Func<bool> Closing { get; set; }
public Action Closed { get; set; } public Action Closed { get; set; }
public Action LostFocus { get; set; }
public IMouseDevice MouseDevice { get; } = new MouseDevice(); public IMouseDevice MouseDevice { get; } = new MouseDevice();
public IPopupImpl CreatePopup() => new WindowStub(this); public IPopupImpl CreatePopup() => new WindowStub(this);

2
src/Avalonia.Native/AvaloniaNativePlatform.cs

@ -112,7 +112,7 @@ namespace Avalonia.Native
return new WindowImpl(_factory, _options, _glFeature); return new WindowImpl(_factory, _options, _glFeature);
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

5
src/Avalonia.Native/WindowImplBase.cs

@ -43,8 +43,7 @@ namespace Avalonia.Native
} }
public abstract class WindowBaseImpl : IWindowBaseImpl, public abstract class WindowBaseImpl : IWindowBaseImpl,
IFramebufferPlatformSurface, ITopLevelImplWithNativeControlHost, IFramebufferPlatformSurface, ITopLevelImplWithNativeControlHost
IEmbeddableWindowImpl
{ {
IInputRoot _inputRoot; IInputRoot _inputRoot;
IAvnWindowBase _native; IAvnWindowBase _native;
@ -122,7 +121,7 @@ namespace Avalonia.Native
}, (int)w, (int)h, new Vector(dpi, dpi)); }, (int)w, (int)h, new Vector(dpi, dpi));
} }
public event Action LostFocus; public Action LostFocus { get; set; }
public Action<Rect> Paint { get; set; } public Action<Rect> Paint { get; set; }
public Action<Size> Resized { get; set; } public Action<Size> Resized { get; set; }

2
src/Avalonia.X11/X11Platform.cs

@ -83,7 +83,7 @@ namespace Avalonia.X11
return new X11Window(this, null); return new X11Window(this, null);
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

1
src/Avalonia.X11/X11Window.cs

@ -310,6 +310,7 @@ namespace Avalonia.X11
public Action<WindowState> WindowStateChanged { get; set; } public Action<WindowState> WindowStateChanged { get; set; }
public Action Closed { get; set; } public Action Closed { get; set; }
public Action<PixelPoint> PositionChanged { get; set; } public Action<PixelPoint> PositionChanged { get; set; }
public Action LostFocus { get; set; }
public IRenderer CreateRenderer(IRenderRoot root) public IRenderer CreateRenderer(IRenderRoot root)
{ {

8
src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs

@ -9,7 +9,7 @@ using Avalonia.Rendering;
namespace Avalonia.LinuxFramebuffer namespace Avalonia.LinuxFramebuffer
{ {
class FramebufferToplevelImpl : IEmbeddableWindowImpl, IScreenInfoProvider class FramebufferToplevelImpl : ITopLevelImpl, IScreenInfoProvider
{ {
private readonly IOutputBackend _outputBackend; private readonly IOutputBackend _outputBackend;
private readonly IInputBackend _inputBackend; private readonly IInputBackend _inputBackend;
@ -71,11 +71,7 @@ namespace Avalonia.LinuxFramebuffer
public Action<Size> Resized { get; set; } public Action<Size> Resized { get; set; }
public Action<double> ScalingChanged { get; set; } public Action<double> ScalingChanged { get; set; }
public Action Closed { get; set; } public Action Closed { get; set; }
public event Action LostFocus public Action LostFocus { get; set; }
{
add {}
remove {}
}
public Size ScaledSize => _outputBackend.PixelSize.ToSize(Scaling); public Size ScaledSize => _outputBackend.PixelSize.ToSize(Scaling);
} }

2
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -204,7 +204,7 @@ namespace Avalonia.Win32
return new WindowImpl(); return new WindowImpl();
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
var embedded = new EmbeddedWindowImpl(); var embedded = new EmbeddedWindowImpl();
embedded.Show(); embedded.Show();

5
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -19,8 +19,7 @@ namespace Avalonia.Win32
/// Window implementation for Win32 platform. /// Window implementation for Win32 platform.
/// </summary> /// </summary>
public partial class WindowImpl : IWindowImpl, EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo, public partial class WindowImpl : IWindowImpl, EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo,
ITopLevelImplWithNativeControlHost, ITopLevelImplWithNativeControlHost
IEmbeddableWindowImpl
{ {
private static readonly List<WindowImpl> s_instances = new List<WindowImpl>(); private static readonly List<WindowImpl> s_instances = new List<WindowImpl>();
@ -126,7 +125,7 @@ namespace Avalonia.Win32
public Action<WindowState> WindowStateChanged { get; set; } public Action<WindowState> WindowStateChanged { get; set; }
public event Action LostFocus; public Action LostFocus { get; set; }
public Thickness BorderThickness public Thickness BorderThickness
{ {

8
src/iOS/Avalonia.iOS/EmbeddableImpl.cs

@ -4,7 +4,7 @@ using Avalonia.Platform;
namespace Avalonia.iOS namespace Avalonia.iOS
{ {
class EmbeddableImpl : TopLevelImpl, IEmbeddableWindowImpl class EmbeddableImpl : TopLevelImpl
{ {
public void SetTitle(string title) public void SetTitle(string title)
{ {
@ -23,11 +23,5 @@ namespace Avalonia.iOS
public void SetSystemDecorations(SystemDecorations enabled) public void SetSystemDecorations(SystemDecorations enabled)
{ {
} }
public event Action LostFocus
{
add {}
remove {}
}
} }
} }

2
src/iOS/Avalonia.iOS/TopLevelImpl.cs

@ -139,5 +139,7 @@ namespace Avalonia.iOS
public ILockedFramebuffer Lock() => new EmulatedFramebuffer(this); public ILockedFramebuffer Lock() => new EmulatedFramebuffer(this);
public IPopupImpl CreatePopup() => null; public IPopupImpl CreatePopup() => null;
public Action LostFocus { get; set; }
} }
} }

2
src/iOS/Avalonia.iOS/WindowingPlatformImpl.cs

@ -10,7 +10,7 @@ namespace Avalonia.iOS
throw new NotSupportedException(); throw new NotSupportedException();
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public WindowImpl CreateEmbeddableWindow()
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }

4
tests/Avalonia.Controls.UnitTests/WindowingPlatformMock.cs

@ -20,11 +20,11 @@ namespace Avalonia.Controls.UnitTests
return _windowImpl?.Invoke() ?? Mock.Of<IWindowImpl>(x => x.Scaling == 1); return _windowImpl?.Invoke() ?? Mock.Of<IWindowImpl>(x => x.Scaling == 1);
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? Mock.Of<IPopupImpl>(x => x.Scaling == 1); public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? Mock.Of<IPopupImpl>(x => x.Scaling == 1);
} }
} }

2
tests/Avalonia.UnitTests/MockWindowingPlatform.cs

@ -116,7 +116,7 @@ namespace Avalonia.UnitTests
} }
} }
public IEmbeddableWindowImpl CreateEmbeddableWindow() public IWindowImpl CreateEmbeddableWindow()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

Loading…
Cancel
Save