Skip to content

Commit

Permalink
Merge pull request #350 from mpondo/mr15-OverlayAndOwnership
Browse files Browse the repository at this point in the history
Fix window going behind main window when dragging
  • Loading branch information
Dirkster99 committed Jul 23, 2022
2 parents b3f7dc2 + fff172f commit 99b7e8d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Expand Up @@ -162,7 +162,7 @@ void IOverlayWindowHost.HideOverlayWindow()

IOverlayWindow IOverlayWindowHost.ShowOverlayWindow(LayoutFloatingWindowControl draggingWindow)
{
CreateOverlayWindow();
CreateOverlayWindow(draggingWindow);
_overlayWindow.EnableDropTargets();
_overlayWindow.Show();
return _overlayWindow;
Expand Down Expand Up @@ -295,10 +295,20 @@ private void _model_IsVisibleChanged(object sender, EventArgs e)
if (!IsVisible && _model.IsVisible) Show();
}

private void CreateOverlayWindow()
private void CreateOverlayWindow(LayoutFloatingWindowControl draggingWindow)
{
if (_overlayWindow == null) _overlayWindow = new OverlayWindow(this);
_overlayWindow.Owner = Window.GetWindow(this);

// Usually, the overlay window is made a child of the main window. However, if the floating
// window being dragged isn't also a child of the main window (because OwnedByDockingManagerWindow
// is set to false to allow the parent window to be minimized independently of floating windows),
// this causes the floating window to be moved behind the main window. Just not setting the parent
// seems to work acceptably here in that case.
if (draggingWindow?.OwnedByDockingManagerWindow ?? true)
_overlayWindow.Owner = Window.GetWindow(this);
else
_overlayWindow.Owner = null;

var rectWindow = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
_overlayWindow.Left = rectWindow.Left;
_overlayWindow.Top = rectWindow.Top;
Expand Down Expand Up @@ -417,4 +427,4 @@ private void OnExecuteCloseWindowCommand(object parameter)

#endregion Private Methods
}
}
}
Expand Up @@ -225,10 +225,20 @@ bool HitTest(Point dragPoint)

private OverlayWindow _overlayWindow = null;

private void CreateOverlayWindow()
private void CreateOverlayWindow(LayoutFloatingWindowControl draggingWindow)
{
if (_overlayWindow == null) _overlayWindow = new OverlayWindow(this);
_overlayWindow.Owner = Window.GetWindow(this);

// Usually, the overlay window is made a child of the main window. However, if the floating
// window being dragged isn't also a child of the main window (because OwnedByDockingManagerWindow
// is set to false to allow the parent window to be minimized independently of floating windows),
// this causes the floating window to be moved behind the main window. Just not setting the parent
// seems to work acceptably here in that case.
if (draggingWindow?.OwnedByDockingManagerWindow ?? true)
_overlayWindow.Owner = Window.GetWindow(this);
else
_overlayWindow.Owner = null;

var rectWindow = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
_overlayWindow.Left = rectWindow.Left;
_overlayWindow.Top = rectWindow.Top;
Expand All @@ -238,7 +248,7 @@ private void CreateOverlayWindow()

IOverlayWindow IOverlayWindowHost.ShowOverlayWindow(LayoutFloatingWindowControl draggingWindow)
{
CreateOverlayWindow();
CreateOverlayWindow(draggingWindow);
_overlayWindow.EnableDropTargets();
_overlayWindow.Show();
return _overlayWindow;
Expand Down Expand Up @@ -419,4 +429,4 @@ private void OnExecuteCloseWindowCommand(object parameter)

#endregion Private Methods
}
}
}
15 changes: 12 additions & 3 deletions source/Components/AvalonDock/DockingManager.cs
Expand Up @@ -1436,7 +1436,7 @@ bool HitTest(Point dragPoint)
/// <inheritdoc/>
IOverlayWindow IOverlayWindowHost.ShowOverlayWindow(LayoutFloatingWindowControl draggingWindow)
{
CreateOverlayWindow();
CreateOverlayWindow(draggingWindow);
_overlayWindow.EnableDropTargets();
_overlayWindow.Show();
return _overlayWindow;
Expand Down Expand Up @@ -2095,13 +2095,22 @@ private void SetupAutoHideWindow()
SetAutoHideWindow(new LayoutAutoHideWindowControl());
}

private void CreateOverlayWindow()
private void CreateOverlayWindow(LayoutFloatingWindowControl draggingWindow = null)
{
if (_overlayWindow == null)
{
_overlayWindow = new OverlayWindow(this);
}
_overlayWindow.Owner = Window.GetWindow(this);

// Usually, the overlay window is made a child of the main window. However, if the floating
// window being dragged isn't also a child of the main window (because OwnedByDockingManagerWindow
// is set to false to allow the parent window to be minimized independently of floating windows),
// this causes the floating window to be moved behind the main window. Just not setting the parent
// seems to work acceptably here in that case.
if (draggingWindow?.OwnedByDockingManagerWindow ?? true)
_overlayWindow.Owner = Window.GetWindow(this);
else
_overlayWindow.Owner = null;

var rectWindow = new Rect(this.PointToScreenDPIWithoutFlowDirection(new Point()), this.TransformActualSizeToAncestor());
_overlayWindow.Left = rectWindow.Left;
Expand Down

0 comments on commit 99b7e8d

Please sign in to comment.