Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improved activation of floating Windows #410

Merged
merged 3 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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