protected virtual void OnDropDown(EventHandler finishDelegate)
{
bool fireDelegate = true;
if (!Ribbon.InDesignMode)
{
// Events only occur when enabled
if (Enabled)
{
if ((ButtonType == GroupButtonType.DropDown) ||
(ButtonType == GroupButtonType.Split))
{
if (KryptonContextMenu != null)
{
ContextMenuArgs contextArgs = new ContextMenuArgs(KryptonContextMenu);
// Generate an event giving a chance for the krypton context menu strip to
// be shown to be provided/modified or the action even to be cancelled
if (DropDown != null)
DropDown(this, contextArgs);
// If user did not cancel and there is still a krypton context menu strip to show
if (!contextArgs.Cancel && (contextArgs.KryptonContextMenu != null))
{
Rectangle screenRect = Rectangle.Empty;
// Convert the view for the button into screen coordinates
if ((Ribbon != null) && (ClusterButtonView != null))
screenRect = Ribbon.ViewRectangleToScreen(ClusterButtonView);
if (CommonHelper.ValidKryptonContextMenu(contextArgs.KryptonContextMenu))
{
// Cache the finish delegate to call when the menu is closed
_kcmFinishDelegate = finishDelegate;
// Show at location we were provided, but need to convert to screen coordinates
contextArgs.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
if (contextArgs.KryptonContextMenu.Show(this, new Point(screenRect.X, screenRect.Bottom + 1)))
fireDelegate = false;
}
}
}
else if (ContextMenuStrip != null)
{
ContextMenuArgs contextArgs = new ContextMenuArgs(ContextMenuStrip);
// Generate an event giving a chance for the context menu strip to be
// shown to be provided/modified or the action even to be cancelled
if (DropDown != null)
DropDown(this, contextArgs);
// If user did not cancel and there is still a context menu strip to show
if (!contextArgs.Cancel && (contextArgs.ContextMenuStrip != null))
{
Rectangle screenRect = Rectangle.Empty;
// Convert the view for the button into screen coordinates
if ((Ribbon != null) && (ClusterButtonView != null))
screenRect = Ribbon.ViewRectangleToScreen(ClusterButtonView);
if (CommonHelper.ValidContextMenuStrip(contextArgs.ContextMenuStrip))
{
// Do not fire the delegate in this routine, wait for the popup manager to show it
fireDelegate = false;
//...show the context menu below and at th left of the button
VisualPopupManager.Singleton.ShowContextMenuStrip(contextArgs.ContextMenuStrip,
new Point(screenRect.X, screenRect.Bottom + 1),
finishDelegate);
}
}
}
}
}
}
// Do we need to fire a delegate stating the click processing has finished?
if (fireDelegate && (finishDelegate != null))
finishDelegate(this, EventArgs.Empty);
}