public bool PreFilterMessage(ref Message msg)
{
Form parentForm = this.FindForm();
Form parentMdi = (parentForm != null ? parentForm.MdiParent : null);
// Only interested in snooping messages if....
// The Form we are inside is the active form AND
// If an MDI Child Form then we must be the active MDI Child Form AND
// We are not in the hidden state AND
// We have an associated auto hidden group control that is not disposed AND
// We are not disposed
if ((parentForm != null) && ((parentForm == Form.ActiveForm) || (parentMdi != null && parentMdi.ActiveMdiChild == parentForm)) &&
parentForm.ContainsFocus && (_state != DockingAutoHiddenShowState.Hidden) && (_group != null) && !_group.IsDisposed && !IsDisposed)
{
switch (msg.Msg)
{
case PI.WM_KEYDOWN:
// Pressing escape removes the auto hidden window
if ((int)msg.WParam == PI.VK_ESCAPE)
{
MakeHidden();
return(true);
}
break;
case PI.WM_MOUSELEAVE:
// If the mouse is leaving a control then we start the dismiss timer so that a mouse move is required
// to cancel the mouse move and prevent the actual dismissal occuring. The exception to this is if the
// slide out dockspace has the focus, in which case we do nothing.
if (!_dismissRunning && !DockspaceControl.ContainsFocus)
{
_dismissTimer.Stop();
_dismissTimer.Start();
_dismissRunning = true;
}
break;
case PI.WM_MOUSEMOVE:
// Convert the mouse position into a screen location
Point screenPt = CommonHelper.ClientMouseMessageToScreenPt(msg);
// Is the mouse over ourself or over the associated auto hiiden group
if (RectangleToScreen(ClientRectangle).Contains(screenPt) ||
_group.RectangleToScreen(_group.ClientRectangle).Contains(screenPt))
{
// We do not dismiss while the mouse is over ourself
if (_dismissRunning)
{
_dismissTimer.Stop();
_dismissRunning = false;
}
}
else
{
// When mouse not over a relevant area we need to start the dismiss process
// unless the slide out dockspace has the focus, in which case we do nothing.
if (!_dismissRunning && !DockspaceControl.ContainsFocus)
{
_dismissTimer.Stop();
_dismissTimer.Start();
_dismissRunning = true;
}
}
// If first message for this window then need to track to get the mouse leave
if (_mouseTrackWindow != msg.HWnd)
{
_mouseTrackWindow = msg.HWnd;
// This structure needs to know its own size in bytes
PI.TRACKMOUSEEVENTS tme = new PI.TRACKMOUSEEVENTS();
tme.cbSize = (uint)Marshal.SizeOf(typeof(PI.TRACKMOUSEEVENTS));
tme.dwHoverTime = 100;
tme.dwFlags = (int)(PI.TME_LEAVE);
tme.hWnd = Handle;
// Call Win32 API to start tracking
PI.TrackMouseEvent(ref tme);
}
break;
}
}
return(false);
}