private void CreateOverflowButton()
        {
            // Create a button used when we overflow the available area
            _overflowButton = new ViewDrawButton(_kryptonBreadCrumb.StateDisabled.BreadCrumb,
                                                 _kryptonBreadCrumb.StateNormal.BreadCrumb,
                                                 _kryptonBreadCrumb.StateTracking.BreadCrumb,
                                                 _kryptonBreadCrumb.StatePressed.BreadCrumb,
                                                 _kryptonBreadCrumb.GetStateCommon(),
                                                 this, VisualOrientation.Top, false)
            {
                Splitter         = true,
                TestForFocusCues = true,
                DropDownPalette  = _kryptonBreadCrumb.GetRedirector()
            };

            // Create controller for operating the button
            ButtonController crumbButtonController = new(_overflowButton, _needPaintDelegate)
            {
                Tag          = this,
                BecomesFixed = true
            };

            crumbButtonController.Click    += OnOverflowButtonClick;
            _overflowButton.MouseController = crumbButtonController;
        }
        /// <summary>
        /// Gets the view for the previous visible and enabled button spec of the defined edge.
        /// </summary>
        /// <param name="align">Edge of buttons caller is interested in searching.</param>
        /// <param name="current">Current button that is the marker for searching.</param>
        /// <returns>ViewDrawButton reference; otherwise false.</returns>
        public virtual ViewDrawButton GetPreviousVisibleViewButton(PaletteRelativeEdgeAlign align,
                                                                   ViewDrawButton current)
        {
            var specLookups = new ButtonSpecView[_specLookup.Count];

            _specLookup.Values.CopyTo(specLookups, 0);

            var found = false;

            for (var i = _specLookup.Count - 1; i >= 0; i--)
            {
                ButtonSpecView specView = specLookups[i];

                if (!found)
                {
                    found = specView.ViewButton == current;
                }
                else
                {
                    // Is the button actually visible/enabled
                    if (specView.ViewCenter.Visible &&
                        specView.ViewButton.Enabled)
                    {
                        if (specView.ButtonSpec.Edge == align)
                        {
                            return(specView.ViewButton);
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Gets the view for the next visible and enabled button spec of the defined edge.
        /// </summary>
        /// <param name="align">Edge of buttons caller is interested in searching.</param>
        /// <param name="current">Current button that is the marker for searching.</param>
        /// <returns>ViewDrawButton reference; otherwise false.</returns>
        public virtual ViewDrawButton GetNextVisibleViewButton(PaletteRelativeEdgeAlign align,
                                                               ViewDrawButton current)
        {
            var found = false;

            foreach (ButtonSpecView specView in _specLookup.Values)
            {
                if (!found)
                {
                    found = specView.ViewButton == current;
                }
                else
                {
                    // Is the button actually visible/enabled
                    if (specView.ViewCenter.Visible &&
                        specView.ViewButton.Enabled)
                    {
                        if (specView.ButtonSpec.Edge == align)
                        {
                            return(specView.ViewButton);
                        }
                    }
                }
            }

            return(null);
        }
예제 #4
0
 /// <summary>
 /// Initialize a new instance of the ButtonSpecAppButtonController class.
 /// </summary>
 /// <param name="viewManager">Owning view manager instance.</param>
 /// <param name="target">Target for state changes.</param>
 /// <param name="needPaint">Delegate for notifying paint requests.</param>
 public ButtonSpecAppButtonController(ViewContextMenuManager viewManager,
                                      ViewDrawButton target,
                                      NeedPaintHandler needPaint)
     : base(target, needPaint)
 {
     _target      = target;
     _viewManager = viewManager;
 }
        private void SyncBreadCrumbs()
        {
            // Remove all existing children
            Clear();

            // Walk up the bread crumb trail
            KryptonBreadCrumbItem item = _kryptonBreadCrumb.SelectedItem;

            while (item != null)
            {
                // If we do not have a button to represent this crumb...
                if (!_crumbToButton.TryGetValue(item, out ViewDrawButton crumbButton))
                {
                    // Setup the button for drawing as a drop down button if required
                    crumbButton = new ViewDrawButton(_kryptonBreadCrumb.StateDisabled.BreadCrumb,
                                                     _kryptonBreadCrumb.StateNormal.BreadCrumb,
                                                     _kryptonBreadCrumb.StateTracking.BreadCrumb,
                                                     _kryptonBreadCrumb.StatePressed.BreadCrumb,
                                                     _kryptonBreadCrumb.GetStateCommon(),
                                                     item, VisualOrientation.Top, false)
                    {
                        Splitter         = true,
                        TestForFocusCues = true,
                        DropDownPalette  = _kryptonBreadCrumb.GetRedirector()
                    };

                    // Create controller for operating the button
                    ButtonController crumbButtonController = new(crumbButton, _needPaintDelegate)
                    {
                        Tag          = item,
                        BecomesFixed = true
                    };
                    crumbButtonController.Click += OnButtonClick;
                    crumbButton.MouseController  = crumbButtonController;

                    // Add to cache for future use
                    _crumbToButton.Add(item, crumbButton);
                    _buttonToCrumb.Add(crumbButton, item);
                }

                // Only show a drop down button if we have some children to choose from
                crumbButton.DropDown = _kryptonBreadCrumb.DropDownNavigation && (item.Items.Count > 0);

                // Add crumb to end of child collection
                Insert(0, crumbButton);

                // Move up another level
                item = item.Parent;
            }

            // Always add the overflow to the first item
            Insert(0, _overflowButton);
        }
        /// <summary>
        /// Find the ButtonSpec definition associated with the provided button view.
        /// </summary>
        /// <param name="viewButton">View to use when searching.</param>
        /// <returns>ButtonSpec reference if found; otherwise null.</returns>
        public virtual ButtonSpec GetButtonSpecFromView(ViewDrawButton viewButton)
        {
            foreach (ButtonSpecView specView in _specLookup.Values)
            {
                if (specView.ViewButton == viewButton)
                {
                    return(specView.ButtonSpec);
                }
            }

            return(null);
        }
예제 #7
0
        /// <summary>
        /// Initialize a new instance of the KryptonCheckButton class.
        /// </summary>
        public KryptonCheckButton()
        {
            // Create the extra state needed for the checked additions the the base button
            StateCheckedNormal   = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateCheckedTracking = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateCheckedPressed  = new PaletteTriple(StateCommon, NeedPaintDelegate);

            // Create the override handling classes
            _overrideCheckedFocus    = new PaletteTripleOverride(OverrideFocus, StateCheckedNormal, PaletteState.FocusOverride);
            _overrideCheckedNormal   = new PaletteTripleOverride(OverrideDefault, _overrideCheckedFocus, PaletteState.NormalDefaultOverride);
            _overrideCheckedTracking = new PaletteTripleOverride(OverrideFocus, StateCheckedTracking, PaletteState.FocusOverride);
            _overrideCheckedPressed  = new PaletteTripleOverride(OverrideFocus, StateCheckedPressed, PaletteState.FocusOverride);

            // Add the checked specific palettes to the existing view button
            ViewDrawButton.SetCheckedPalettes(_overrideCheckedNormal,
                                              _overrideCheckedTracking,
                                              _overrideCheckedPressed);
        }
예제 #8
0
        /// <summary>
        /// Create a button controller for the view.
        /// </summary>
        /// <param name="viewButton">View to be controlled.</param>
        /// <param name="needPaint">Paint delegate.</param>
        /// <param name="clickHandler">Reference to click handler.</param>
        /// <returns>Controller instance.</returns>
        public override ButtonSpecViewControllers CreateController(ViewDrawButton viewButton,
                                                                   NeedPaintHandler needPaint,
                                                                   MouseEventHandler clickHandler)
        {
            // Create a ribbon specific button controller
            _controller = new ButtonSpecRibbonController(viewButton, needPaint);
            _controller.BecomesFixed = true;
            _controller.Click       += clickHandler;

            // If associated with a tooltip manager then pass mouse messages onto tooltip manager
            IMouseController mouseController = (IMouseController)_controller;

            if (Manager.ToolTipManager != null)
            {
                mouseController = new ToolTipController(Manager.ToolTipManager, viewButton, _controller);
            }

            // Return a collection of controllers
            return(new ButtonSpecViewControllers(mouseController, _controller, _controller));
        }
        /// <summary>
        /// Initialize a new instance of the ButtonSpecView class.
        /// </summary>
        /// <param name="redirector">Palette redirector.</param>
        /// <param name="paletteMetric">Source for metric values.</param>
        /// <param name="metricPadding">Padding metric for border padding.</param>
        /// <param name="manager">Reference to owning manager.</param>
        /// <param name="buttonSpec">Access</param>
        public ButtonSpecView(PaletteRedirect redirector,
                              IPaletteMetric paletteMetric,
                              PaletteMetricPadding metricPadding,
                              ButtonSpecManagerBase manager,
                              ButtonSpec buttonSpec)
        {
            Debug.Assert(redirector != null);
            Debug.Assert(manager != null);
            Debug.Assert(buttonSpec != null);

            // Remember references
            _redirector     = redirector;
            Manager         = manager;
            ButtonSpec      = buttonSpec;
            _finishDelegate = OnFinishDelegate;

            // Create delegate for paint notifications
            NeedPaintHandler needPaint = OnNeedPaint;

            // Intercept calls from the button for color remapping and instead use
            // the button spec defined map and the container foreground color
            RemapPalette = Manager.CreateButtonSpecRemap(redirector, buttonSpec);

            // Use a redirector to get button values directly from palette
            _palette = new PaletteTripleRedirect(RemapPalette,
                                                 PaletteBackStyle.ButtonButtonSpec,
                                                 PaletteBorderStyle.ButtonButtonSpec,
                                                 PaletteContentStyle.ButtonButtonSpec,
                                                 needPaint);


            // Create the view for displaying a button
            ViewButton = new ViewDrawButton(_palette, _palette, _palette, _palette,
                                            paletteMetric, this, VisualOrientation.Top, false);

            // Associate the view with the source component (for design time support)
            if (buttonSpec.AllowComponent)
            {
                ViewButton.Component = buttonSpec;
            }

            // Use a view center to place button in centre of given space
            ViewCenter = new ViewLayoutCenter(paletteMetric, metricPadding, VisualOrientation.Top)
            {
                ViewButton
            };

            // Create a controller for managing button behavior
            ButtonSpecViewControllers controllers = CreateController(ViewButton, needPaint, OnClick);

            ViewButton.MouseController  = controllers.MouseController;
            ViewButton.SourceController = controllers.SourceController;
            ViewButton.KeyController    = controllers.KeyController;

            // We need notifying whenever a button specification property changes
            ButtonSpec.ButtonSpecPropertyChanged += OnPropertyChanged;

            // Associate the button spec with the view that is drawing it
            ButtonSpec.SetView(ViewButton);

            // Finally update view with current button spec settings
            UpdateButtonStyle();
            UpdateVisible();
            UpdateEnabled();
            UpdateChecked();
        }
        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()
                {
                    // Use same palette settings for context menu as the main control
                    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();
                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 (var i = 3; i < Count; i++)
                {
                    if (!this[i].Visible)
                    {
                        KryptonBreadCrumbItem  childCrumb = _buttonToCrumb[(ViewDrawButton)this[i]];
                        KryptonContextMenuItem childMenu  = new();

                        // 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                += OnChildCrumbClick;

                        items.Items.Add(childMenu);
                    }
                }

                // Create a new menu item to represent each of the roots children
                var 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();

                    // 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                += OnChildCrumbClick;

                    items.Items.Add(childMenu);
                }

                // Allow the user a chance to alter the menu contents or cancel it entirely
                ContextPositionMenuArgs cpma = new(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 += 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;
                }
            }
        }

        #endregion
    }
        private void OnButtonClick(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;
                KryptonBreadCrumbItem breadCrumb = controller.Tag as KryptonBreadCrumbItem;

                // Do we need to show a drop down menu?
                if (viewButton.DropDown && viewButton.SplitRectangle.Contains(e.Location))
                {
                    // Create a context menu with a items collection
                    KryptonContextMenu kcm = new()
                    {
                        // Use same palette settings for context menu as the main control
                        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();
                    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 child crumb
                    foreach (KryptonBreadCrumbItem childCrumb in breadCrumb.Items)
                    {
                        KryptonContextMenuItem childMenu = new();

                        // 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                += OnChildCrumbClick;

                        items.Items.Add(childMenu);
                    }

                    // Allow the user a chance to alter the menu contents or cancel it entirely
                    BreadCrumbMenuArgs bcma = new(breadCrumb, kcm, KryptonContextMenuPositionH.Left, KryptonContextMenuPositionV.Below);
                    _kryptonBreadCrumb.OnCrumbDropDown(bcma);

                    // Is there still the need to show a menu that is not empty?
                    if (!bcma.Cancel &&
                        (bcma.KryptonContextMenu != null) &&
                        CommonHelper.ValidKryptonContextMenu(bcma.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
                        bcma.KryptonContextMenu.Closed += OnKryptonContextMenuClosed;
                        bcma.KryptonContextMenu.Show(_kryptonBreadCrumb, _kryptonBreadCrumb.RectangleToScreen(new Rectangle(viewButton.SplitRectangle.X - viewButton.SplitRectangle.Width,
                                                                                                                            viewButton.SplitRectangle.Y,
                                                                                                                            viewButton.SplitRectangle.Width * 2,
                                                                                                                            viewButton.SplitRectangle.Height)),
                                                     bcma.PositionH,
                                                     bcma.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();
                    }
                }
                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 = breadCrumb;
                }
            }
        }
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        public override void KeyDown(Control c, KeyEventArgs e)
        {
            ViewBase      newView = null;
            KryptonRibbon ribbon  = (KryptonRibbon)c;

            // Get the button spec associated with this controller
            ViewDrawButton viewButton = (ViewDrawButton)Target;
            ButtonSpec     buttonSpec = ribbon.TabsArea.ButtonSpecManager.GetButtonSpecFromView(viewButton);

            // Note if we are on the near edge
            bool isNear = (buttonSpec.Edge == PaletteRelativeEdgeAlign.Near);

            switch (e.KeyData)
            {
            case Keys.Tab:
            case Keys.Right:
                // Logic depends on the edge this button is on
                if (isNear)
                {
                    // Try getting the previous near edge button (previous on near gets the next right hand side!)
                    newView = ribbon.TabsArea.ButtonSpecManager.GetPreviousVisibleViewButton(PaletteRelativeEdgeAlign.Near, viewButton);

                    if (newView == null)
                    {
                        if ((e.KeyData == Keys.Tab) && (ribbon.SelectedTab != null))
                        {
                            // Get the currently selected tab page
                            newView = ribbon.TabsArea.LayoutTabs.GetViewForRibbonTab(ribbon.SelectedTab);
                        }
                        else
                        {
                            // Get the first visible tab page
                            newView = ribbon.TabsArea.LayoutTabs.GetViewForFirstRibbonTab();
                        }
                    }

                    // Get the first far edge button
                    if (newView == null)
                    {
                        newView = ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Far);
                    }

                    // Get the first inherit edge button
                    if (newView == null)
                    {
                        newView = ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Inherit);
                    }

                    // Rotate around to application button
                    if (newView == null)
                    {
                        if (ribbon.TabsArea.LayoutAppButton.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppButton.AppButton;
                        }
                        else if (ribbon.TabsArea.LayoutAppTab.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppTab.AppTab;
                        }
                    }
                }
                else
                {
                    // Try using the next far edge button
                    newView = ribbon.TabsArea.ButtonSpecManager.GetNextVisibleViewButton(PaletteRelativeEdgeAlign.Far, viewButton);

                    // Try using the next inherit edge button
                    if (newView == null)
                    {
                        newView = ribbon.TabsArea.ButtonSpecManager.GetNextVisibleViewButton(PaletteRelativeEdgeAlign.Inherit, viewButton);
                    }

                    // Rotate around to application button
                    if (newView == null)
                    {
                        if (ribbon.TabsArea.LayoutAppButton.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppButton.AppButton;
                        }
                        else if (ribbon.TabsArea.LayoutAppTab.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppTab.AppTab;
                        }
                    }
                }
                break;

            case Keys.Tab | Keys.Shift:
            case Keys.Left:
                // Logic depends on the edge this button is on
                if (isNear)
                {
                    // Try using the previous near edge button (next for a near edge is the left hand side!)
                    newView = ribbon.TabsArea.ButtonSpecManager.GetNextVisibleViewButton(PaletteRelativeEdgeAlign.Near, viewButton);

                    // Get the last qat button
                    if (newView == null)
                    {
                        newView = ribbon.GetLastQATView();
                    }

                    // Rotate around to application button
                    if (newView == null)
                    {
                        if (ribbon.TabsArea.LayoutAppButton.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppButton.AppButton;
                        }
                        else if (ribbon.TabsArea.LayoutAppTab.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppTab.AppTab;
                        }
                    }
                }
                else
                {
                    // Try getting the previous far edge button
                    newView = ribbon.TabsArea.ButtonSpecManager.GetPreviousVisibleViewButton(PaletteRelativeEdgeAlign.Far, viewButton);

                    // Try getting the previous inherit edge button
                    if (newView == null)
                    {
                        newView = ribbon.TabsArea.ButtonSpecManager.GetPreviousVisibleViewButton(PaletteRelativeEdgeAlign.Inherit, viewButton);
                    }

                    if (newView == null)
                    {
                        if (e.KeyData != Keys.Left)
                        {
                            // Get the last control on the selected tab
                            newView = ribbon.GroupsArea.ViewGroups.GetLastFocusItem();

                            // Get the currently selected tab page
                            if (newView == null)
                            {
                                if (ribbon.SelectedTab != null)
                                {
                                    newView = ribbon.TabsArea.LayoutTabs.GetViewForRibbonTab(ribbon.SelectedTab);
                                }
                                else
                                {
                                    newView = ribbon.TabsArea.LayoutTabs.GetViewForLastRibbonTab();
                                }
                            }
                        }
                        else
                        {
                            // Get the last visible tab page
                            newView = ribbon.TabsArea.LayoutTabs.GetViewForLastRibbonTab();
                        }
                    }

                    // Get the last near edge button
                    if (newView == null)
                    {
                        newView = ribbon.TabsArea.ButtonSpecManager.GetFirstVisibleViewButton(PaletteRelativeEdgeAlign.Near);
                    }

                    // Get the last qat button
                    if (newView == null)
                    {
                        newView = ribbon.GetLastQATView();
                    }

                    // Rotate around to application button
                    if (newView == null)
                    {
                        if (ribbon.TabsArea.LayoutAppButton.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppButton.AppButton;
                        }
                        else if (ribbon.TabsArea.LayoutAppTab.Visible)
                        {
                            newView = ribbon.TabsArea.LayoutAppTab.AppTab;
                        }
                    }
                }
                break;

            case Keys.Space:
            case Keys.Enter:
                // Exit keyboard mode when you click the button spec
                ribbon.KillKeyboardMode();

                // Generate a click event
                OnClick(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
                break;
            }

            // If we have a new view to focus and it is not ourself...
            if ((newView != null) && (newView != Target))
            {
                // If the new view is a tab then select that tab unless in minimized mode
                if (!ribbon.RealMinimizedMode && (newView is ViewDrawRibbonTab tab))
                {
                    ribbon.SelectedTab = tab.RibbonTab;
                }

                // Finally we switch focus to new view
                ribbon.FocusView = newView;
            }
        }
        /// <summary>
        /// Initialize a new instance of the KryptonDropButton class.
        /// </summary>
        public KryptonDropButton()
        {
            // We generate click events manually, suppress default
            // production of them by the base Control class
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick, false);

            // Set default button properties
            _style       = ButtonStyle.Standalone;
            DialogResult = DialogResult.None;
            _useMnemonic = true;

            // Create content storage
            Values              = CreateButtonValues(NeedPaintDelegate);
            Values.TextChanged += OnButtonTextChanged;
            Images              = new DropDownButtonImages(NeedPaintDelegate);

            // Image need an extra redirector to check the local images first
            _paletteDropDownButtonImages = new PaletteRedirectDropDownButton(Redirector, Images);

            // Create the palette storage
            StateCommon     = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            StateDisabled   = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateNormal     = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateTracking   = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StatePressed    = new PaletteTriple(StateCommon, NeedPaintDelegate);
            OverrideDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            OverrideFocus   = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);

            // Create the override handling classes
            _overrideFocus    = new PaletteTripleOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride);
            _overrideNormal   = new PaletteTripleOverride(OverrideDefault, _overrideFocus, PaletteState.NormalDefaultOverride);
            _overrideTracking = new PaletteTripleOverride(OverrideFocus, StateTracking, PaletteState.FocusOverride);
            _overridePressed  = new PaletteTripleOverride(OverrideFocus, StatePressed, PaletteState.FocusOverride);

            // Create the view button instance
            _drawButton = new ViewDrawButton(StateDisabled,
                                             _overrideNormal,
                                             _overrideTracking,
                                             _overridePressed,
                                             new PaletteMetricRedirect(Redirector),
                                             this,
                                             VisualOrientation.Top,
                                             UseMnemonic)
            {
                // Set default button state
                DropDown         = true,
                Splitter         = true,
                TestForFocusCues = true,
                DropDownPalette  = _paletteDropDownButtonImages
            };

            // Create a button controller to handle button style behaviour
            _buttonController = new ButtonController(_drawButton, NeedPaintDelegate)
            {
                BecomesFixed = true
            };

            // Assign the controller to the view element to treat as a button
            _drawButton.MouseController  = _buttonController;
            _drawButton.KeyController    = _buttonController;
            _drawButton.SourceController = _buttonController;

            // Need to know when user clicks the button view or mouse selects it
            _buttonController.Click       += OnButtonClick;
            _buttonController.MouseSelect += OnButtonSelect;

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawButton);
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuCheckButton class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="checkButton">Reference to owning check button entry.</param>
        public ViewDrawMenuCheckButton(IContextMenuProvider provider,
                                       KryptonContextMenuCheckButton checkButton)
        {
            _provider = provider;
            KryptonContextMenuCheckButton = checkButton;

            // Create fixed storage of the content values
            _contentValues = new FixedContentValue(ResolveText,
                                                   ResolveExtraText,
                                                   ResolveImage,
                                                   ResolveImageTransparentColor);

            // Decide on the enabled state of the display
            ItemEnabled = provider.ProviderEnabled && ResolveEnabled;

            // Give the heading object the redirector to use when inheriting values
            KryptonContextMenuCheckButton.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the view button instance
            ViewDrawButton = new ViewDrawButton(checkButton.OverrideDisabled,
                                                checkButton.OverrideNormal,
                                                checkButton.OverrideTracking,
                                                checkButton.OverridePressed,
                                                new PaletteMetricRedirect(provider.ProviderRedirector),
                                                _contentValues,
                                                VisualOrientation.Top,
                                                true);

            // Add the checked specific palettes to the existing view button
            ViewDrawButton.SetCheckedPalettes(checkButton.OverrideCheckedNormal,
                                              checkButton.OverrideCheckedTracking,
                                              checkButton.OverrideCheckedPressed);

            ViewDrawButton.Enabled = ItemEnabled;
            ViewDrawButton.Checked = ResolveChecked;

            // Place the check box on the left of the available space but inside separators
            _innerDocker = new ViewLayoutDocker
            {
                { ViewDrawButton, ViewDockStyle.Fill },
                { new ViewLayoutSeparator(1), ViewDockStyle.Right },
                { new ViewLayoutSeparator(1), ViewDockStyle.Left },
                { new ViewLayoutSeparator(1), ViewDockStyle.Top },
                { new ViewLayoutSeparator(1), ViewDockStyle.Bottom }
            };

            // Use outer docker so that any extra space not needed is used by the null
            _outerDocker = new ViewLayoutDocker
            {
                { _innerDocker, ViewDockStyle.Top },
                { new ViewLayoutNull(), ViewDockStyle.Fill }
            };

            // Use context menu specific version of the check box controller
            MenuCheckButtonController mcbc = new(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate);

            mcbc.Click += OnClick;
            _innerDocker.MouseController = mcbc;
            _innerDocker.KeyController   = mcbc;

            // Add docker as the composite content
            Add(_outerDocker);

            // Want to know when a property changes whilst Displayed
            KryptonContextMenuCheckButton.PropertyChanged += OnPropertyChanged;

            // We need to know if a property of the command changes
            if (KryptonContextMenuCheckButton.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuCheckButton.KryptonCommand;
                KryptonContextMenuCheckButton.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }
        }
        public KryptonListView()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint
                     | ControlStyles.OptimizedDoubleBuffer
                     | ControlStyles.SupportsTransparentBackColor // Cannot get thi sto work (Code removed)!!
                     | ControlStyles.EnableNotifyMessage
                     , true);

            base.OwnerDraw = true;
            // We need to repaint entire control whenever resized
            SetStyle(ControlStyles.ResizeRedraw, true);
            // Yes, we want to be drawn double buffered by default
            DoubleBuffered = true;

            // Default fields
            _alwaysActive    = true;
            _style           = ButtonStyle.ListItem;
            Padding          = new Padding(1);
            base.BorderStyle = System.Windows.Forms.BorderStyle.None;

            // We need to create and cache a device context compatible with the display
            _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);

            // Set the palette and renderer to the defaults as specified by the manager
            Redirector = new PaletteRedirect(null);
            CacheNewPalette(KryptonManager.CurrentGlobalPalette);

            KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged;

            NeedPaintDelegate = OnNeedPaint;

            // Create the palette storage
            Images = new CheckBoxImages(NeedPaintDelegate);
            _paletteCheckBoxImages = new PaletteRedirectCheckBox(Redirector, Images);
            StateCommon            = new PaletteListStateRedirect(Redirector, PaletteBackStyle.InputControlStandalone, PaletteBorderStyle.InputControlStandalone, NeedPaintDelegate);
            OverrideFocus          = new PaletteListItemTripleRedirect(Redirector, PaletteBackStyle.ButtonListItem, PaletteBorderStyle.ButtonListItem, PaletteContentStyle.ButtonListItem, NeedPaintDelegate);
            StateDisabled          = new PaletteListState(StateCommon, NeedPaintDelegate);
            StateActive            = new PaletteDouble(StateCommon, NeedPaintDelegate);
            StateNormal            = new PaletteListState(StateCommon, NeedPaintDelegate);
            StateTracking          = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate);
            StatePressed           = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate);
            StateCheckedNormal     = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate);
            StateCheckedTracking   = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate);
            StateCheckedPressed    = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate);
            // Create manager and view for drawing the background
            ViewDrawPanel = new ViewDrawPanel(StateNormal.Back);

            // Create the override handling classes
            _overrideNormal          = new PaletteTripleOverride(OverrideFocus.Item, StateNormal.Item, PaletteState.FocusOverride);
            _overrideTracking        = new PaletteTripleOverride(OverrideFocus.Item, StateTracking.Item, PaletteState.FocusOverride);
            _overridePressed         = new PaletteTripleOverride(OverrideFocus.Item, StatePressed.Item, PaletteState.FocusOverride);
            _overrideCheckedNormal   = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedNormal.Item, PaletteState.FocusOverride);
            _overrideCheckedTracking = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedTracking.Item, PaletteState.FocusOverride);
            _overrideCheckedPressed  = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedPressed.Item, PaletteState.FocusOverride);

            // Create the check box image drawer and place inside element so it is always centered
            _drawCheckBox   = new ViewDrawCheckBox(_paletteCheckBoxImages);
            _layoutCheckBox = new ViewLayoutCenter
            {
                _drawCheckBox
            };
            _layoutCheckBoxAfter = new ViewLayoutSeparator(3, 0);
            _layoutCheckBoxStack = new ViewLayoutStack(true)
            {
                _layoutCheckBox,
                _layoutCheckBoxAfter
            };
            // Stack used to layout the location of the node image
            _layoutImage       = new ViewLayoutSeparator(0, 0);
            _layoutImageAfter  = new ViewLayoutSeparator(3, 0);
            _layoutImageCenter = new ViewLayoutCenter(_layoutImage);
            _layoutImageStack  = new ViewLayoutStack(true)
            {
                _layoutImageCenter,
                _layoutImageAfter
            };
            _layoutImageState       = new ViewLayoutSeparator(16, 16);
            _layoutImageCenterState = new ViewLayoutCenter(_layoutImageState);
            // Create the draw element for owner drawing individual items
            _contentValues = new ShortTextValue();
            _drawButton    = new ViewDrawButton(StateDisabled.Item, _overrideNormal,
                                                _overrideTracking, _overridePressed,
                                                _overrideCheckedNormal, _overrideCheckedTracking,
                                                _overrideCheckedPressed,
                                                new PaletteMetricRedirect(Redirector),
                                                _contentValues, VisualOrientation.Top, false);

            // Place check box on the left and the label in the remainder
            _layoutDockerTile = new ViewLayoutDocker
            {
                { _layoutImageStack, ViewDockStyle.Left },
                { _layoutImageCenterState, ViewDockStyle.Left },
                { _layoutCheckBoxStack, ViewDockStyle.Left },
                { _drawButton, ViewDockStyle.Fill }
            };

            _layoutDockerSmall = new ViewLayoutDocker
            {
                { _drawButton, ViewDockStyle.Left },
                { _layoutImageStack, ViewDockStyle.Left },
                { _layoutImageCenterState, ViewDockStyle.Left },
                { _layoutCheckBoxStack, ViewDockStyle.Left }
            };

            // Place check box on the left and the text to match the width
            _layoutDockerCheckLarge = new ViewLayoutDocker
            {
                { _layoutImageStack, ViewDockStyle.Left },
                { _layoutImageCenterState, ViewDockStyle.Left },
                { _layoutCheckBoxStack, ViewDockStyle.Left },
                { _drawButton, ViewDockStyle.Bottom }
            };

            // Create the element that fills the remainder space and remembers fill rectangle
            _layoutFill = new ViewLayoutFill(this)
            {
                DisplayPadding = new Padding(1)
            };

            // Create inner view for placing inside the drawing docker
            _drawDockerInner = new ViewLayoutDocker
            {
                { _layoutFill, ViewDockStyle.Fill }
            };

            // Create view for the control border and background
            _drawDockerOuter = new ViewDrawDocker(StateNormal.Back, StateNormal.Border)
            {
                { _drawDockerInner, ViewDockStyle.Fill }
            };

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawDockerOuter);
            // We need to create and cache a device context compatible with the display
            _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);
            StateCommon.Item.Content.ShortText.MultiLine  = InheritBool.True;
            StateCommon.Item.Content.ShortText.MultiLineH = PaletteRelativeAlign.Center;
            StateCommon.Item.Content.ShortText.TextH      = PaletteRelativeAlign.Center;
        }