/// <summary> /// Raises the DropDown event. /// </summary> /// <param name="finishDelegate">Delegate fired during event processing.</param> 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) && (ButtonView != null)) { screenRect = Ribbon.ViewRectangleToScreen(ButtonView); } 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) && (ButtonView != null)) { screenRect = Ribbon.ViewRectangleToScreen(ButtonView); } 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); } }
void HandleContextMenuRequest(object sender, ContextMenuArgs e) { e.RetVal = !ContextMenuEnabled; }
/// <summary> /// Raises the DropDown event. /// </summary> /// <param name="finishDelegate">Delegate fired during event processing.</param> protected virtual void OnDropDown(EventHandler finishDelegate) { bool fireDelegate = true; if (!Ribbon.InDesignMode && Enabled && IsDropDownButton) { 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 ViewBase qatView = _ribbon?.GetViewForQATButton(this); if (qatView != null) { screenRect = Ribbon.RectangleToScreen(qatView.ClientRectangle); if (_ribbon.QATLocation == QATLocation.Above) { var ownerForm = _ribbon.FindForm() as VisualForm; // If integrated into the caption area if ((ownerForm != null) && !ownerForm.ApplyComposition) { // Adjust for the height/width of borders Padding borders = ownerForm.WindowMargin; screenRect.X -= borders.Left; screenRect.Y -= borders.Top; } } } 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; } } } } //TODO: ContextMenuStrip not supported. //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 // ViewBase qatView = _ribbon?.GetViewForQATButton(this); // if (qatView != null) // screenRect = Ribbon.ViewRectangleToScreen(qatView); // 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); } }
/// <summary> /// Raises the DropDown event. /// </summary> /// <param name="finishDelegate">Delegate fired during event processing.</param> 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) { UpdateContextMenu(); 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 DropDown?.Invoke(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) && (ClusterColorButtonView != null)) { screenRect = Ribbon.ViewRectangleToScreen(ClusterColorButtonView); } if (CommonHelper.ValidKryptonContextMenu(contextArgs.KryptonContextMenu)) { // Cache the finish delegate to call when the menu is closed _kcmFinishDelegate = finishDelegate; // Decide which separators are needed DecideOnVisible(_separatorTheme, _colorsTheme); DecideOnVisible(_separatorStandard, _colorsStandard); DecideOnVisible(_separatorRecent, _colorsRecent); DecideOnVisible(_separatorNoColor, _itemsNoColor); DecideOnVisible(_separatorMoreColors, _itemsMoreColors); // Monitor relevant events inside the context menu HookContextMenuEvents(_kryptonContextMenu.Items, true); // 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; } } } } } } } // Do we need to fire a delegate stating the click processing has finished? if (fireDelegate) { finishDelegate?.Invoke(this, EventArgs.Empty); } }