Пример #1
0
        /// <summary>
        /// Show the context menu relative to the provided screen rectangle.
        /// </summary>
        /// <param name="caller">Reference to object causing the context menu to be shown.</param>
        /// <param name="screenRect">Screen rectangle.</param>
        /// <param name="horz">Horizontal location relative to screen rectangle.</param>
        /// <param name="vert">Vertical location relative to screen rectangle.</param>
        /// <param name="keyboardActivated">Was context menu initiated via a keyboard action.</param>
        /// <param name="constrain">Should size and position of menu be constrained by display size.</param>
        /// <returns>Has the context menu become displayed.</returns>
        public bool Show(object caller,
                         Rectangle screenRect,
                         KryptonContextMenuPositionH horz,
                         KryptonContextMenuPositionV vert,
                         bool keyboardActivated,
                         bool constrain)
        {
            bool displayed = false;

            // Only need to show if not already displaying it
            if (VisualContextMenu == null)
            {
                // Remember the caller for us in events
                Caller = caller;

                // Give event handler a change to cancel the open request
                CancelEventArgs cea = new CancelEventArgs();
                OnOpening(cea);

                if (!cea.Cancel)
                {
                    // Set a default reason for the menu being dismissed
                    CloseReason = ToolStripDropDownCloseReason.AppFocusChange;

                    // Create the actual control used to show the context menu
                    VisualContextMenu = CreateContextMenu(this, Palette, PaletteMode,
                                                          _redirector, _redirectorImages,
                                                          Items, Enabled, keyboardActivated);

                    // Need to know when the visual control is removed
                    VisualContextMenu.Disposed += OnContextMenuDisposed;

                    // Request the menu be shown immediately
                    VisualContextMenu.Show(screenRect, horz, vert, false, constrain);

                    // Override the horz, vert setting so that sub menus appear right and below
                    VisualContextMenu.ShowHorz = KryptonContextMenuPositionH.After;
                    VisualContextMenu.ShowVert = KryptonContextMenuPositionV.Top;

                    // Indicate the context menu is fully constructed and displayed
                    OnOpened(EventArgs.Empty);

                    // The menu has actually become displayed
                    displayed = true;
                }
            }

            return(displayed);
        }
Пример #2
0
        private void OnContextMenuDisposed(object sender, EventArgs e)
        {
            // Should still be caching a reference to actual display control
            if (_contextMenu != null)
            {
                // Unhook from control, so it can be garbage collected
                _contextMenu.Disposed -= OnContextMenuDisposed;

                // No longer need to cache reference
                _contextMenu = null;

                // Tell our view manager that we no longer show a sub menu
                _provider.ProviderViewManager.ClearTargetSubMenu((IContextMenuTarget)KeyController);
            }
        }
Пример #3
0
        private void OnContextMenuDisposed(object sender, EventArgs e)
        {
            // Should still be caching a reference to actual display control
            if (VisualContextMenu != null)
            {
                // Unhook from control, so it can be garbage collected
                VisualContextMenu.Disposed -= OnContextMenuDisposed;

                // Copy to self the close reason
                if (VisualContextMenu.CloseReason.HasValue)
                {
                    CloseReason = VisualContextMenu.CloseReason.Value;
                }

                // No longer need to cache reference
                VisualContextMenu = null;

                // Notify event handlers the context menu has been closed and why it closed
                OnClosed(new ToolStripDropDownClosedEventArgs(CloseReason));
            }
        }
Пример #4
0
        /// <summary>
        /// Ask the menu item to show the associated child collection as a menu.
        /// </summary>
        public void ShowSubMenu(bool keyboardActivated)
        {
            // Only need to show if not already doing so
            if ((_contextMenu == null) || (_contextMenu.IsDisposed))
            {
                // No need for the sub menu timer anymore, we are showing
                _provider.ProviderViewManager.SetTargetSubMenu((IContextMenuTarget)KeyController);

                // Only show a sub menu if there is one to be shown!
                if (HasSubMenu)
                {
                    // Create the actual control used to show the context menu
                    _contextMenu = new VisualContextMenu(_provider, KryptonContextMenuItem.Items, keyboardActivated);

                    // Need to know when the visual control is removed
                    _contextMenu.Disposed += OnContextMenuDisposed;

                    // Get the screen rectangle for the drawing element
                    Rectangle menuDrawRect = OwningControl.RectangleToScreen(ClientRectangle);

                    // Should this menu item be shown at a fixed screen rectangle?
                    if (_provider.ProviderShowSubMenuFixed(KryptonContextMenuItem))
                    {
                        // Request the menu be shown at fixed screen rectangle
                        _contextMenu.ShowFixed(_provider.ProviderShowSubMenuFixedRect(KryptonContextMenuItem),
                                               _provider.ProviderShowHorz,
                                               _provider.ProviderShowVert);
                    }
                    else
                    {
                        // Request the menu be shown immediately
                        _contextMenu.Show(menuDrawRect,
                                          _provider.ProviderShowHorz,
                                          _provider.ProviderShowVert,
                                          true, false);
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Get the renderer.
        /// </summary>
        /// <returns>Render instance.</returns>
        public IRenderer GetRenderer()
        {
            VisualContextMenu contextMenu = (VisualContextMenu)_provider.ProviderViewManager.Control;

            return(contextMenu.Renderer);
        }