diff --git a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs index 54b6d454..75f417da 100644 --- a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs @@ -243,14 +243,18 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int { switch (msg) { - case Win32Helper.WM_NCLBUTTONDOWN: //Left button down on title -> start dragging over docking manager - if (wParam.ToInt32() == Win32Helper.HT_CAPTION) + case Win32Helper.WM_ACTIVATE: + var anchorablePane = _model.Descendents().OfType() + .FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null); + + if (anchorablePane != null) { - var anchorablePane = _model.Descendents().OfType() - .FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null); - if (anchorablePane != null) anchorablePane.SelectedContent.IsActive = true; + var isActive = !(((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE); + anchorablePane.SelectedContent.IsActive = isActive; + handled = true; } + break; case Win32Helper.WM_NCRBUTTONUP: diff --git a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs index 5c25b593..17ea136c 100644 --- a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs @@ -113,22 +113,117 @@ private void Model_PropertyChanged(object sender, System.ComponentModel.Property if (e.PropertyName == nameof(LayoutDocumentFloatingWindow.RootPanel) && _model.RootPanel == null) InternalClose(); } - /// - protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + private void ActiveOfSinglePane(bool isActive) { - switch (msg) + var layoutDocumentPane = _model.Descendents().OfType() + .FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null); + + layoutDocumentPane.SelectedContent.IsActive = isActive; + } + + private static LayoutDocumentPaneControl FindDocumentPaneControlByPoint(IEnumerable areaHosts, Point point) + { + foreach (var areaHost in areaHosts) { - case Win32Helper.WM_NCLBUTTONDOWN: //Left button down on title -> start dragging over docking manager - if (wParam.ToInt32() == Win32Helper.HT_CAPTION) + var area = areaHost.GetScreenArea(); + var pos = areaHost.TransformFromDeviceDPI(point); + var b = area.Contains(pos); + + if (b) + { + return areaHost; + } + } + + return null; + } + + private void ActiveOfMultiPane(bool isActive) + { + var mousePosition = Win32Helper.GetMousePosition(); + var rootVisual = ((FloatingWindowContentHost)Content).RootVisual; + var areaHosts = rootVisual.FindVisualChildren(); + + if (isActive) + { + var documentPane = FindDocumentPaneControlByPoint(areaHosts, mousePosition); + if (documentPane != null) + { + var model = (LayoutDocumentPane)documentPane.Model; + if (model.SelectedContent != null) { - LayoutDocumentPane layoutDocumentPane = _model.Descendents().OfType().FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null); - if (layoutDocumentPane != null) + model.SelectedContent.IsActive = true; + return; + } + // AnchorablePane + else + { + var index = 0; + for (var i = 0; i < model.Children.Count; i++) { - layoutDocumentPane.SelectedContent.IsActive = true; + var item = model.Children[i]; + if (item.IsLastFocusedDocument) + { + index = i; + } } - handled = true; + model.SelectedContentIndex = index; + return; + } + } + else + { + // Active the Last Focus + foreach (var areaHost in areaHosts) + { + var model = (LayoutDocumentPane)areaHost.Model; + for (var i = 0; i < model.Children.Count; i++) + { + var item = model.Children[i]; + if (item.IsLastFocusedDocument) + { + item.IsActive = true; + return; + } + } + } + } + } + else + { + foreach (var areaHost in areaHosts) + { + var model = (LayoutDocumentPane)areaHost.Model; + for (var i = 0; i < model.Children.Count; i++) + { + var item = model.Children[i]; + if (item.IsActive) + { + item.IsActive = false; + } + } + } + } + } + + /// + protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + switch (msg) + { + case Win32Helper.WM_ACTIVATE: + var isInactive = ((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE; + if (_model.IsSinglePane) + { + ActiveOfSinglePane(!isInactive); } + else + { + ActiveOfMultiPane(!isInactive); + } + + handled = true; break; case Win32Helper.WM_NCRBUTTONUP: diff --git a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs index ab398e1b..c1377a92 100644 --- a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs @@ -348,16 +348,7 @@ protected virtual IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntP switch (msg) { case Win32Helper.WM_ACTIVATE: - if (((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE) - { - if (lParam == this.GetParentWindowHandle()) - { - Win32Helper.SetActiveWindow(_hwndSrc.Handle); - handled = true; - } - } UpdateWindowsSizeBasedOnMinSize(); - break; case Win32Helper.WM_EXITSIZEMOVE: