Example #1
0
 /// <summary>
 /// Raises the DropDown event.
 /// </summary>
 /// <param name="e">An ContextPositionMenuArgs containing the event data.</param>
 protected virtual void OnDropDown(ContextPositionMenuArgs e)
 {
     if (DropDown != null)
     {
         DropDown(this, e);
     }
 }
 /// <summary>
 /// Raises the OverflowDropDown event.
 /// </summary>
 /// <param name="e">An ContextPositionMenuArgs containing the event data.</param>
 internal protected virtual void OnOverflowDropDown(ContextPositionMenuArgs e)
 {
     if (OverflowDropDown != null)
     {
         OverflowDropDown(this, e);
     }
 }
Example #3
0
        private bool ShowDropDown()
        {
            bool showingContextMenu = false;

            // Update the krypton menu with this controls palette state
            if (KryptonContextMenu != null)
            {
                if (PaletteMode != PaletteMode.Custom)
                {
                    KryptonContextMenu.PaletteMode = PaletteMode;
                }
                else
                {
                    KryptonContextMenu.Palette = Palette;
                }
            }

            // Package up the context menu and positioning values we will use later
            ContextPositionMenuArgs cpma = new ContextPositionMenuArgs(ContextMenuStrip,
                                                                       KryptonContextMenu,
                                                                       GetPositionH(),
                                                                       GetPositionV());

            // Let use examine and later values
            OnDropDown(cpma);

            // If we still want to show a context menu
            if (!cpma.Cancel)
            {
                if (cpma.KryptonContextMenu != null)
                {
                    // Convert the client rect to screen coords
                    Rectangle screenRect = RectangleToScreen(ClientRectangle);
                    if (CommonHelper.ValidKryptonContextMenu(cpma.KryptonContextMenu))
                    {
                        // Modify the screen rect so that we have a pixel gap between button and menu
                        switch (cpma.PositionV)
                        {
                        case KryptonContextMenuPositionV.Above:
                            screenRect.Y -= 1;
                            break;

                        case KryptonContextMenuPositionV.Below:
                            screenRect.Height += 1;
                            break;
                        }

                        switch (cpma.PositionH)
                        {
                        case KryptonContextMenuPositionH.Before:
                            screenRect.X -= 1;
                            break;

                        case KryptonContextMenuPositionH.After:
                            screenRect.Width += 1;
                            break;
                        }

                        // We are showing a drop down
                        showingContextMenu = true;

                        // Show relative to the screen rectangle
                        cpma.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
                        cpma.KryptonContextMenu.Show(this, screenRect, cpma.PositionH, cpma.PositionV);
                    }
                }
                else if (cpma.ContextMenuStrip != null)
                {
                    // Convert the client rect to screen coords
                    Rectangle screenRect = RectangleToScreen(ClientRectangle);
                    if (CommonHelper.ValidContextMenuStrip(cpma.ContextMenuStrip))
                    {
                        // We are showing a drop down
                        showingContextMenu = true;

                        //...show the context menu below and at th left of the button
                        VisualPopupManager.Singleton.ShowContextMenuStrip(cpma.ContextMenuStrip,
                                                                          new Point(screenRect.X, screenRect.Bottom + 1),
                                                                          new EventHandler(OnContextMenuClosed));
                    }
                }
            }

            return(showingContextMenu);
        }
Example #4
0
        private void OnOverflowButtonClick(object sender, MouseEventArgs e)
        {
            // Only allow a single context menu at a time
            if (!_showingContextMenu)
            {
                // Get access to the controller, view and crumb item
                ViewDrawButton   viewButton = sender as ViewDrawButton;
                ButtonController controller = viewButton.MouseController as ButtonController;

                // Create a context menu with a items collection
                KryptonContextMenu kcm = new KryptonContextMenu();

                // Use same palette settings for context menu as the main control
                kcm.Palette = _kryptonBreadCrumb.Palette;
                if (kcm.Palette == null)
                {
                    kcm.PaletteMode = _kryptonBreadCrumb.PaletteMode;
                }

                // Add an items collection as the root item of the context menu
                KryptonContextMenuItems items = new KryptonContextMenuItems();
                kcm.Items.Add(items);

                // Store lookup between each menu item and the crumb it represents. Prevents
                // needing to use the menu item tag for remembering association. Leaving the
                // tag free for use by the user.
                _menuItemToCrumb = new MenuItemToCrumb();

                // Create a new menu item to represent each of the invisible crumbs not children of the root
                // (item 0=overflow button, 1=root; 2=child of root, so we start at index 3)
                for (int i = 3; i < Count; i++)
                {
                    if (!this[i].Visible)
                    {
                        KryptonBreadCrumbItem  childCrumb = _buttonToCrumb[(ViewDrawButton)this[i]];
                        KryptonContextMenuItem childMenu  = new KryptonContextMenuItem();

                        // Store 1-to-1 association
                        _menuItemToCrumb.Add(childMenu, childCrumb);

                        // Copy across the display details of the child crumb item
                        childMenu.Text                  = childCrumb.ShortText;
                        childMenu.ExtraText             = childCrumb.LongText;
                        childMenu.Image                 = childCrumb.Image;
                        childMenu.ImageTransparentColor = childCrumb.ImageTransparentColor;
                        childMenu.Click                += new EventHandler(OnChildCrumbClick);

                        items.Items.Add(childMenu);
                    }
                }

                // Create a new menu item to represent each of the roots children
                bool firstRoot = true;
                foreach (KryptonBreadCrumbItem childCrumb in _kryptonBreadCrumb.RootItem.Items)
                {
                    // The first time we add an entry
                    if (firstRoot)
                    {
                        // Add a separator if entries already exist
                        if (items.Items.Count > 0)
                        {
                            items.Items.Add(new KryptonContextMenuSeparator());
                        }

                        firstRoot = false;
                    }

                    KryptonContextMenuItem childMenu = new KryptonContextMenuItem();

                    // Store 1-to-1 association
                    _menuItemToCrumb.Add(childMenu, childCrumb);

                    // Copy across the display details of the child crumb item
                    childMenu.Text                  = childCrumb.ShortText;
                    childMenu.ExtraText             = childCrumb.LongText;
                    childMenu.Image                 = childCrumb.Image;
                    childMenu.ImageTransparentColor = childCrumb.ImageTransparentColor;
                    childMenu.Click                += new EventHandler(OnChildCrumbClick);

                    items.Items.Add(childMenu);
                }

                // Allow the user a chance to alter the menu contents or cancel it entirely
                ContextPositionMenuArgs cpma = new ContextPositionMenuArgs(kcm, KryptonContextMenuPositionH.Left, KryptonContextMenuPositionV.Below);
                _kryptonBreadCrumb.OnOverflowDropDown(cpma);

                // Is there still the need to show a menu that is not empty?
                if (!cpma.Cancel &&
                    (cpma.KryptonContextMenu != null) &&
                    CommonHelper.ValidKryptonContextMenu(cpma.KryptonContextMenu))
                {
                    // Cache the controller for use in menu close processing, prevents the need to
                    // store anything in the KryptonContextMenu tag and so free up its use to the user.
                    _pressedButtonController = controller;

                    // Show the context menu so user can select the next item for selection
                    cpma.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
                    cpma.KryptonContextMenu.Show(_kryptonBreadCrumb, _kryptonBreadCrumb.RectangleToScreen(new Rectangle(viewButton.ClientRectangle.X,
                                                                                                                        viewButton.ClientRectangle.Y,
                                                                                                                        viewButton.ClientRectangle.Width * 2,
                                                                                                                        viewButton.ClientRectangle.Height)),
                                                 cpma.PositionH,
                                                 cpma.PositionV);

                    // do not show another context menu whilst this one is visible
                    _showingContextMenu = true;
                }
                else
                {
                    // Button gives a fixed appearance when pressed, without a context menu that is not necessary
                    controller.RemoveFixed();

                    // Clicking item makes it become the selected crumb
                    _kryptonBreadCrumb.SelectedItem = _kryptonBreadCrumb.RootItem;
                }
            }
        }