static public bool TrackPopupMenu(Menu menu, Point pnt)
{
if (menu.MenuItems.Count <= 0) // No submenus to track
{
return(true);
}
MenuTracker tracker = menu.tracker;
tracker.active = true;
tracker.popup_active = true;
// Set GrabControl
Control src_ctrl = (tracker.TopMenu as ContextMenu).SourceControl;
tracker.GrabControl = src_ctrl.FindForm();
if (tracker.GrabControl == null)
{
tracker.GrabControl = src_ctrl.FindRootParent();
}
tracker.GrabControl.ActiveTracker = tracker;
menu.Wnd = new PopUpWindow(tracker.GrabControl, menu);
menu.Wnd.Location = menu.Wnd.PointToClient(pnt);
((PopUpWindow)menu.Wnd).ShowWindow();
bool no_quit = true;
Object queue_id = XplatUI.StartLoop(Thread.CurrentThread);
while ((menu.Wnd != null) && menu.Wnd.Visible && no_quit)
{
MSG msg = new MSG();
no_quit = XplatUI.GetMessage(queue_id, ref msg, IntPtr.Zero, 0, 0);
switch ((Msg)msg.message)
{
case Msg.WM_KEYDOWN:
case Msg.WM_SYSKEYDOWN:
case Msg.WM_CHAR:
case Msg.WM_SYSCHAR:
case Msg.WM_KEYUP:
case Msg.WM_SYSKEYUP:
Control c = Control.FromHandle(msg.hwnd);
if (c != null)
{
Message m = Message.Create(msg.hwnd, (int)msg.message, msg.wParam, msg.lParam);
c.PreProcessControlMessageInternal(ref m);
}
break;
default:
XplatUI.TranslateMessage(ref msg);
XplatUI.DispatchMessage(ref msg);
break;
}
}
if (tracker.GrabControl.IsDisposed)
{
return(true);
}
if (!no_quit)
{
XplatUI.PostQuitMessage(0);
}
if (menu.Wnd != null)
{
menu.Wnd.Dispose();
menu.Wnd = null;
}
return(true);
}