Skip to content

Commit 76603fc

Browse files
authored
Merge pull request #410 from Noisrev/fix-issue408
Improved activation of floating Windows
2 parents 9b56fe2 + db7d869 commit 76603fc

File tree

3 files changed

+113
-23
lines changed

3 files changed

+113
-23
lines changed

source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,18 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int
243243
{
244244
switch (msg)
245245
{
246-
case Win32Helper.WM_NCLBUTTONDOWN: //Left button down on title -> start dragging over docking manager
247-
if (wParam.ToInt32() == Win32Helper.HT_CAPTION)
246+
case Win32Helper.WM_ACTIVATE:
247+
var anchorablePane = _model.Descendents().OfType<LayoutAnchorablePane>()
248+
.FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);
249+
250+
if (anchorablePane != null)
248251
{
249-
var anchorablePane = _model.Descendents().OfType<LayoutAnchorablePane>()
250-
.FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);
251-
if (anchorablePane != null) anchorablePane.SelectedContent.IsActive = true;
252+
var isActive = !(((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE);
253+
anchorablePane.SelectedContent.IsActive = isActive;
254+
252255
handled = true;
253256
}
257+
254258
break;
255259

256260
case Win32Helper.WM_NCRBUTTONUP:

source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs

+104-9
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,117 @@ private void Model_PropertyChanged(object sender, System.ComponentModel.Property
113113
if (e.PropertyName == nameof(LayoutDocumentFloatingWindow.RootPanel) && _model.RootPanel == null) InternalClose();
114114
}
115115

116-
/// <inheritdoc />
117-
protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
116+
private void ActiveOfSinglePane(bool isActive)
118117
{
119-
switch (msg)
118+
var layoutDocumentPane = _model.Descendents().OfType<LayoutDocumentPane>()
119+
.FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);
120+
121+
layoutDocumentPane.SelectedContent.IsActive = isActive;
122+
}
123+
124+
private static LayoutDocumentPaneControl FindDocumentPaneControlByPoint(IEnumerable<LayoutDocumentPaneControl> areaHosts, Point point)
125+
{
126+
foreach (var areaHost in areaHosts)
120127
{
121-
case Win32Helper.WM_NCLBUTTONDOWN: //Left button down on title -> start dragging over docking manager
122-
if (wParam.ToInt32() == Win32Helper.HT_CAPTION)
128+
var area = areaHost.GetScreenArea();
129+
var pos = areaHost.TransformFromDeviceDPI(point);
130+
var b = area.Contains(pos);
131+
132+
if (b)
133+
{
134+
return areaHost;
135+
}
136+
}
137+
138+
return null;
139+
}
140+
141+
private void ActiveOfMultiPane(bool isActive)
142+
{
143+
var mousePosition = Win32Helper.GetMousePosition();
144+
var rootVisual = ((FloatingWindowContentHost)Content).RootVisual;
145+
var areaHosts = rootVisual.FindVisualChildren<LayoutDocumentPaneControl>();
146+
147+
if (isActive)
148+
{
149+
var documentPane = FindDocumentPaneControlByPoint(areaHosts, mousePosition);
150+
if (documentPane != null)
151+
{
152+
var model = (LayoutDocumentPane)documentPane.Model;
153+
if (model.SelectedContent != null)
123154
{
124-
LayoutDocumentPane layoutDocumentPane = _model.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault(p => p.ChildrenCount > 0 && p.SelectedContent != null);
125-
if (layoutDocumentPane != null)
155+
model.SelectedContent.IsActive = true;
156+
return;
157+
}
158+
// AnchorablePane
159+
else
160+
{
161+
var index = 0;
162+
for (var i = 0; i < model.Children.Count; i++)
126163
{
127-
layoutDocumentPane.SelectedContent.IsActive = true;
164+
var item = model.Children[i];
165+
if (item.IsLastFocusedDocument)
166+
{
167+
index = i;
168+
}
128169
}
129170

130-
handled = true;
171+
model.SelectedContentIndex = index;
172+
return;
173+
}
174+
}
175+
else
176+
{
177+
// Active the Last Focus
178+
foreach (var areaHost in areaHosts)
179+
{
180+
var model = (LayoutDocumentPane)areaHost.Model;
181+
for (var i = 0; i < model.Children.Count; i++)
182+
{
183+
var item = model.Children[i];
184+
if (item.IsLastFocusedDocument)
185+
{
186+
item.IsActive = true;
187+
return;
188+
}
189+
}
190+
}
191+
}
192+
}
193+
else
194+
{
195+
foreach (var areaHost in areaHosts)
196+
{
197+
var model = (LayoutDocumentPane)areaHost.Model;
198+
for (var i = 0; i < model.Children.Count; i++)
199+
{
200+
var item = model.Children[i];
201+
if (item.IsActive)
202+
{
203+
item.IsActive = false;
204+
}
205+
}
206+
}
207+
}
208+
}
209+
210+
/// <inheritdoc />
211+
protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
212+
{
213+
switch (msg)
214+
{
215+
case Win32Helper.WM_ACTIVATE:
216+
var isInactive = ((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE;
217+
if (_model.IsSinglePane)
218+
{
219+
ActiveOfSinglePane(!isInactive);
131220
}
221+
else
222+
{
223+
ActiveOfMultiPane(!isInactive);
224+
}
225+
226+
handled = true;
132227
break;
133228

134229
case Win32Helper.WM_NCRBUTTONUP:

source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs

-9
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,7 @@ protected virtual IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntP
348348
switch (msg)
349349
{
350350
case Win32Helper.WM_ACTIVATE:
351-
if (((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE)
352-
{
353-
if (lParam == this.GetParentWindowHandle())
354-
{
355-
Win32Helper.SetActiveWindow(_hwndSrc.Handle);
356-
handled = true;
357-
}
358-
}
359351
UpdateWindowsSizeBasedOnMinSize();
360-
361352
break;
362353

363354
case Win32Helper.WM_EXITSIZEMOVE:

0 commit comments

Comments
 (0)