private bool DropDownFilter(ref Message message)
{
if (state != State.HotTracking)
{
throw new InvalidOperationException();
}
// comctl32 sometimes steals the hot item for unknown reasons.
this.SetHotItem(this.trackHotItem);
if (message.Msg == NativeMethods.WM_KEYDOWN)
{
Keys keyData = (Keys)(int) message.WParam | ModifierKeys;
if (keyData == Keys.Left)
{
this.TrackDropDownNext(this.GetPreviousItem(trackHotItem));
return true;
}
// Only move right if there is no submenu on the current selected item.
if ((keyData == Keys.Right) && ((this.contextMenu.SelectedMenuItem == null) || (this.contextMenu.SelectedMenuItem.MenuItems.Count == 0)))
{
this.TrackDropDownNext(GetNextItem(trackHotItem));
return true;
}
if (keyData == Keys.Escape)
{
trackEscapePressed = true;
}
}
else if ((message.Msg == NativeMethods.WM_MOUSEMOVE) || (message.Msg == NativeMethods.WM_LBUTTONDOWN))
{
Point point = new Point(((int) message.LParam) & 0xffff, ((int) message.LParam) >> 16);
point = this.PointToClient(point);
if (message.Msg == NativeMethods.WM_MOUSEMOVE)
{
if (point != lastMousePosition)
{
int index = HitTest(point);
if ((this.IsValid(index)) && (index != trackHotItem))
this.TrackDropDownNext(index);
lastMousePosition = point;
}
}
else if (message.Msg == NativeMethods.WM_LBUTTONDOWN)
{
if (HitTest(point) == trackHotItem)
{
this.TrackDropDownNext(-1);
return true;
}
}
}
return false;
}