Skip to content

Commit

Permalink
Merge pull request #410 from Noisrev/fix-issue408
Browse files Browse the repository at this point in the history
Improved activation of floating Windows
  • Loading branch information
Dirkster99 authored Dec 25, 2022
2 parents 9b56fe2 + db7d869 commit 76603fc
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LayoutAnchorablePane>()
.FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);

if (anchorablePane != null)
{
var anchorablePane = _model.Descendents().OfType<LayoutAnchorablePane>()
.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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,117 @@ private void Model_PropertyChanged(object sender, System.ComponentModel.Property
if (e.PropertyName == nameof(LayoutDocumentFloatingWindow.RootPanel) && _model.RootPanel == null) InternalClose();
}

/// <inheritdoc />
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<LayoutDocumentPane>()
.FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);

layoutDocumentPane.SelectedContent.IsActive = isActive;
}

private static LayoutDocumentPaneControl FindDocumentPaneControlByPoint(IEnumerable<LayoutDocumentPaneControl> 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<LayoutDocumentPaneControl>();

if (isActive)
{
var documentPane = FindDocumentPaneControlByPoint(areaHosts, mousePosition);
if (documentPane != null)
{
var model = (LayoutDocumentPane)documentPane.Model;
if (model.SelectedContent != null)
{
LayoutDocumentPane layoutDocumentPane = _model.Descendents().OfType<LayoutDocumentPane>().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;
}
}
}
}
}

/// <inheritdoc />
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 76603fc

Please # to comment.