private void OnAppMenuDisposed(object sender, EventArgs e) { // We always kill keyboard mode when the app button menu is removed _ribbon.KillKeyboardMode(); // Remove the fixed 'pressed' state from the application button _appButtonController.RemoveFixed(); _appTabController.RemoveFixed(); // Should still be caching a reference to actual display control if (_appMenu != null) { // Unhook from control, so it can be garbage collected _appMenu.Disposed -= new EventHandler(OnAppMenuDisposed); // Discover the reason for the menu close ToolStripDropDownCloseReason closeReason = ToolStripDropDownCloseReason.AppFocusChange; if (_appMenu.CloseReason.HasValue) { closeReason = _appMenu.CloseReason.Value; } // No longer need to cache reference _appMenu = null; // Notify event handlers the context menu has been closed and why it closed _ribbon.OnAppButtonMenuClosed(new ToolStripDropDownClosedEventArgs(closeReason)); } }
private void OnAppButtonClicked(object sender, EventArgs e) { // We do not operate the application button at design time if (_ribbon.InDesignMode) { OnAppMenuDisposed(this, EventArgs.Empty); } else { // Give event handler a change to cancel the open request CancelEventArgs cea = new CancelEventArgs(); _ribbon.OnAppButtonMenuOpening(cea); if (cea.Cancel) { OnAppMenuDisposed(this, EventArgs.Empty); } else { // Remove any minimized popup window from display if (_ribbon.RealMinimizedMode) { _ribbon.KillMinimizedPopup(); } // Give popups a change to cleanup Application.DoEvents(); if (!_ribbon.InDesignMode && !_ribbon.IsDisposed) { Rectangle appRectTop; Rectangle appRectBottom; Rectangle appRectShow; if (_ribbon.RibbonShape == PaletteRibbonShape.Office2007) { // Find screen location of the applicaton button lower half Rectangle appButtonRect = _ribbon.RectangleToScreen(_layoutAppButton.AppButton.ClientRectangle); appRectBottom = new Rectangle(appButtonRect.X, appButtonRect.Y + 22, appButtonRect.Width, appButtonRect.Height - 21); appRectTop = new Rectangle(appRectBottom.X, appRectBottom.Y - 21, appRectBottom.Width, 21); appRectShow = appRectBottom; } else { // Find screen location of the applicaton tab lower half Rectangle appButtonRect = _ribbon.RectangleToScreen(_layoutAppTab.AppTab.ClientRectangle); appRectBottom = Rectangle.Empty; appRectTop = appButtonRect; appRectShow = new Rectangle(appButtonRect.X, appButtonRect.Bottom - 1, appButtonRect.Width, 0); } // Create the actual control used to show the context menu _appMenu = new VisualPopupAppMenu(_ribbon, _ribbon.RibbonAppButton, _ribbon.Palette, _ribbon.PaletteMode, _ribbon.GetRedirector(), appRectTop, appRectBottom, _appButtonController.Keyboard); // Need to know when the visual control is removed _appMenu.Disposed += new EventHandler(OnAppMenuDisposed); // Adjust the screen rect of the app button/tab, so we show half way down the button appRectShow.X -= 3; appRectShow.Height = 0; // Request the menu be shown immediately _appMenu.Show(appRectShow); // Indicate the context menu is fully constructed and displayed _ribbon.OnAppButtonMenuOpened(EventArgs.Empty); } } } }