public void Show(Point position, ToolStripDropDownDirection direction)
{
this.PerformLayout();
Point show_point = CalculateShowPoint(position, direction, Size);
if (this.Location != show_point)
{
this.Location = show_point;
}
// Prevents recursion
if (Visible)
{
return;
}
CancelEventArgs e = new CancelEventArgs();
this.OnOpening(e);
if (e.Cancel)
{
return;
}
// The tracker lets us know when the form is clicked or loses focus
ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked);
ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange);
bool useNativeMenu = true;
foreach (var item in this.Items)
{
useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator;
}
if (useNativeMenu)
{
currentMenu = ToNSMenu();
((MonoMenuDelegate)currentMenu.Delegate).BeforePopup();
show_point = CalculateShowPoint(position, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height));
NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate {
Size displaySize;
XplatUI.GetDisplaySize(out displaySize);
currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null);
});
}
base.Show();
ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard);
// Called from NSMenuDelegate for native menus
if (!useNativeMenu)
{
this.OnOpened(EventArgs.Empty);
}
}