Browse Source

remove disabledBy array on win32.

pull/3943/head
Dan Walmsley 6 years ago
parent
commit
0116f7ad96
  1. 20
      src/Avalonia.Controls/Window.cs
  2. 22
      src/Windows/Avalonia.Win32/WindowImpl.cs

20
src/Avalonia.Controls/Window.cs

@ -69,6 +69,9 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot
{ {
private List<Window> _children = new List<Window>();
private Window _owner;
/// <summary> /// <summary>
/// Defines the <see cref="SizeToContent"/> property. /// Defines the <see cref="SizeToContent"/> property.
/// </summary> /// </summary>
@ -366,6 +369,12 @@ namespace Avalonia.Controls
{ {
if (close) if (close)
{ {
if(_owner != null)
{
_owner._children.Remove(this);
_owner = null;
}
PlatformImpl?.Dispose(); PlatformImpl?.Dispose();
} }
} }
@ -408,6 +417,14 @@ namespace Avalonia.Controls
using (BeginAutoSizing()) using (BeginAutoSizing())
{ {
Renderer?.Stop(); Renderer?.Stop();
if (_owner != null)
{
_owner._children.Remove(this);
// update enabled state of parent.
_owner = null;
}
PlatformImpl?.Hide(); PlatformImpl?.Hide();
} }
@ -521,7 +538,8 @@ namespace Avalonia.Controls
using (BeginAutoSizing()) using (BeginAutoSizing())
{ {
PlatformImpl.SetParent(owner.PlatformImpl); PlatformImpl.SetParent(owner.PlatformImpl);
owner.PlatformImpl.SetEnabled(false); owner._children.Add(this);
owner.PlatformImpl.SetEnabled(false);
PlatformImpl?.Show(); PlatformImpl?.Show();
Renderer?.Start(); Renderer?.Start();

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

@ -44,8 +44,7 @@ namespace Avalonia.Win32
private readonly ManagedWindowResizeDragHelper _managedDrag; private readonly ManagedWindowResizeDragHelper _managedDrag;
#endif #endif
private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE); private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE);
private readonly List<WindowImpl> _disabledBy;
private readonly TouchDevice _touchDevice; private readonly TouchDevice _touchDevice;
private readonly MouseDevice _mouseDevice; private readonly MouseDevice _mouseDevice;
private readonly ManagedDeferredRendererLock _rendererLock; private readonly ManagedDeferredRendererLock _rendererLock;
@ -70,7 +69,6 @@ namespace Avalonia.Win32
public WindowImpl() public WindowImpl()
{ {
_disabledBy = new List<WindowImpl>();
_touchDevice = new TouchDevice(); _touchDevice = new TouchDevice();
_mouseDevice = new WindowsMouseDevice(); _mouseDevice = new WindowsMouseDevice();
@ -342,13 +340,6 @@ namespace Avalonia.Win32
public void Hide() public void Hide()
{ {
if (_parent != null)
{
_parent._disabledBy.Remove(this);
_parent.UpdateEnabled();
_parent = null;
}
UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide); UnmanagedMethods.ShowWindow(_hwnd, ShowWindowCommand.Hide);
} }
@ -363,7 +354,7 @@ namespace Avalonia.Win32
public void SetParent(IWindowImpl parent) public void SetParent(IWindowImpl parent)
{ {
_parent = (WindowImpl)parent; _parent = (WindowImpl)parent;
_parent._disabledBy.Add(this); SetOwnerHandle(_parent._hwnd);
} }
public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable); public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable);
@ -665,7 +656,9 @@ namespace Avalonia.Win32
SetWindowPos(_hwnd, WindowPosZOrder.HWND_NOTOPMOST, x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW); SetWindowPos(_hwnd, WindowPosZOrder.HWND_NOTOPMOST, x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);
} }
} }
} }
private void SetOwnerHandle(IntPtr handle) => SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, handle);
private WindowStyles GetWindowStateStyles () private WindowStyles GetWindowStateStyles ()
{ {
@ -722,11 +715,6 @@ namespace Avalonia.Win32
} }
} }
private void UpdateEnabled()
{
SetEnabled(_disabledBy.Count == 0);
}
private void UpdateWindowProperties(WindowProperties newProperties, bool forceChanges = false) private void UpdateWindowProperties(WindowProperties newProperties, bool forceChanges = false)
{ {
var oldProperties = _windowProperties; var oldProperties = _windowProperties;

Loading…
Cancel
Save