Exemple #1
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Always update to the latest correct check state
            if (_imageCanvas != null)
            {
                if (ResolveChecked)
                {
                    _imageCanvas.ElementState = PaletteState.CheckedNormal;
                    _imageCanvas.Enabled      = ResolveEnabled;
                }
                else
                {
                    _imageCanvas.ElementState = PaletteState.Normal;
                    _imageCanvas.Enabled      = true;
                }
            }

            PaletteDouble splitPalette;

            // Make sure we are using the correct palette for state
            switch (State)
            {
            default:
            case PaletteState.Normal:
                SetPalettes(KryptonContextMenuItem.StateNormal.ItemHighlight.Back,
                            KryptonContextMenuItem.StateNormal.ItemHighlight.Border,
                            KryptonContextMenuItem.StateNormal.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateNormal.ItemSplit;
                break;

            case PaletteState.Disabled:
                SetPalettes(KryptonContextMenuItem.StateDisabled.ItemHighlight.Back,
                            KryptonContextMenuItem.StateDisabled.ItemHighlight.Border,
                            KryptonContextMenuItem.StateDisabled.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateDisabled.ItemSplit;
                break;

            case PaletteState.Tracking:
                SetPalettes(KryptonContextMenuItem.StateHighlight.ItemHighlight.Back,
                            KryptonContextMenuItem.StateHighlight.ItemHighlight.Border,
                            KryptonContextMenuItem.StateHighlight.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateHighlight.ItemSplit;
                break;
            }


            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // If we have image display
            if (_fixedImage != null)
            {
                Image itemColumnImage      = ResolveImage;
                Color itemImageTransparent = ResolveImageTransparentColor;

                // If no image found then...
                if (itemColumnImage == null)
                {
                    // Ensure we have a fixed size if we are showing an image column
                    if (_imageColumn)
                    {
                        itemColumnImage      = _empty16x16;
                        itemImageTransparent = Color.Magenta;
                    }

                    switch (ResolveCheckState)
                    {
                    case CheckState.Checked:
                        itemColumnImage      = _provider.ProviderImages.GetContextMenuCheckedImage();
                        itemImageTransparent = Color.Empty;
                        break;

                    case CheckState.Indeterminate:
                        itemColumnImage      = _provider.ProviderImages.GetContextMenuIndeterminateImage();
                        itemImageTransparent = Color.Empty;
                        break;
                    }
                }

                // Decide on the enabled state of the display
                ItemEnabled = _provider.ProviderEnabled && ResolveEnabled;
                PaletteContextMenuItemState menuItemState = (ItemEnabled ? KryptonContextMenuItem.StateNormal : KryptonContextMenuItem.StateDisabled);

                // Update palettes based on Checked state
                PaletteTripleJustImage justImage = (ResolveChecked ? KryptonContextMenuItem.StateChecked.ItemImage : menuItemState.ItemImage);
                _imageCanvas?.SetPalettes(justImage.Back, justImage.Border);

                // Update the Enabled state
                _imageContent.SetPalette(justImage.Content);
                _imageContent.Enabled   = ItemEnabled;
                _textContent.Enabled    = ItemEnabled;
                SplitSeparator.Enabled  = ItemEnabled;
                _subMenuContent.Enabled = ItemEnabled;
                if (_shortcutContent != null)
                {
                    _shortcutContent.Enabled = ItemEnabled;
                }

                // Update the Text/ExtraText
                _fixedTextExtraText.ShortText = ResolveText;
                _fixedTextExtraText.LongText  = ResolveExtraText;

                // Update the Image
                _fixedImage.Image = itemColumnImage;
                _fixedImage.ImageTransparentColor = itemImageTransparent;
            }

            SplitSeparator?.SetPalettes(splitPalette.Back, splitPalette.Border);

            return(base.GetPreferredSize(context));
        }
 /// <summary>
 /// Initialize a new instance of the PaletteContextMenuItemStateChecked class.
 /// </summary>
 public PaletteContextMenuItemStateChecked(PaletteTripleJustImageRedirect redirectItemImage)
 {
     ItemImage = new PaletteTripleJustImage(redirectItemImage);
 }
Exemple #3
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuItem class.
        /// </summary>
        /// <param name="provider">Provider of context menu information.</param>
        /// <param name="menuItem">Menu item definition.</param>
        /// <param name="columns">Containing columns.</param>
        /// <param name="standardStyle">Draw items with standard or alternate style.</param>
        /// <param name="imageColumn">Draw an image background for the item images.</param>
        public ViewDrawMenuItem(IContextMenuProvider provider,
                                KryptonContextMenuItem menuItem,
                                ViewLayoutStack columns,
                                bool standardStyle,
                                bool imageColumn)
            : base(menuItem.StateNormal.ItemHighlight.Back,
                   menuItem.StateNormal.ItemHighlight.Border,
                   menuItem.StateNormal.ItemHighlight,
                   PaletteMetricPadding.ContextMenuItemHighlight,
                   VisualOrientation.Top)
        {
            // Remember values
            _provider = provider;
            KryptonContextMenuItem = menuItem;
            _imageColumn           = imageColumn;
            _standardStyle         = standardStyle;

            // Give the item object the redirector to use when inheriting values
            KryptonContextMenuItem.SetPaletteRedirect(provider);

            // Create a stack of horizontal items inside the item
            ViewLayoutDocker docker = new ViewLayoutDocker();

            // Decide on the enabled state of the display
            ItemEnabled = provider.ProviderEnabled && ResolveEnabled;
            PaletteContextMenuItemState menuItemState = (ItemEnabled ? KryptonContextMenuItem.StateNormal : KryptonContextMenuItem.StateDisabled);

            // Calculate the image to show inside in the image column
            Image itemColumnImage      = ResolveImage;
            Color itemImageTransparent = ResolveImageTransparentColor;

            // If no image found then...
            if (itemColumnImage != null)
            {
                // Ensure we have a fixed size if we are showing an image column
                if (_imageColumn)
                {
                    itemColumnImage      = _empty16x16;
                    itemImageTransparent = Color.Magenta;
                }

                switch (ResolveCheckState)
                {
                case CheckState.Checked:
                    itemColumnImage      = provider.ProviderImages.GetContextMenuCheckedImage();
                    itemImageTransparent = Color.Empty;
                    break;

                case CheckState.Indeterminate:
                    itemColumnImage      = provider.ProviderImages.GetContextMenuIndeterminateImage();
                    itemImageTransparent = Color.Empty;
                    break;
                }
            }

            // Column Image
            PaletteTripleJustImage justImage = (ResolveChecked ? KryptonContextMenuItem.StateChecked.ItemImage : menuItemState.ItemImage);

            _fixedImage   = new FixedContentValue(null, null, itemColumnImage, itemImageTransparent);
            _imageContent = new ViewDrawContent(justImage.Content, _fixedImage, VisualOrientation.Top);
            _imageCanvas  = new ViewDrawMenuImageCanvas(justImage.Back, justImage.Border, 0, false)
            {
                _imageContent
            };
            docker.Add(new ViewLayoutCenter(_imageCanvas), ViewDockStyle.Left);
            _imageContent.Enabled = ItemEnabled;

            // Text/Extra Text
            PaletteContentJustText menuItemStyle = (standardStyle ? menuItemState.ItemTextStandard : menuItemState.ItemTextAlternate);

            _fixedTextExtraText = new FixedContentValue(ResolveText, ResolveExtraText, null, Color.Empty);
            _textContent        = new ViewDrawMenuItemContent(menuItemStyle, _fixedTextExtraText, 1);
            docker.Add(_textContent, ViewDockStyle.Fill);
            _textContent.Enabled = ItemEnabled;

            // Shortcut
            if (KryptonContextMenuItem.ShowShortcutKeys)
            {
                string shortcutString = KryptonContextMenuItem.ShortcutKeyDisplayString;
                if (string.IsNullOrEmpty(shortcutString))
                {
                    shortcutString = (KryptonContextMenuItem.ShortcutKeys != Keys.None) ? new KeysConverter().ConvertToString(KryptonContextMenuItem.ShortcutKeys) : string.Empty;
                }

                if (shortcutString.Length > 0)
                {
                    _shortcutContent = new ViewDrawMenuItemContent(menuItemState.ItemShortcutText, new FixedContentValue(shortcutString, null, null, Color.Empty), 2);
                    docker.Add(_shortcutContent, ViewDockStyle.Right);
                    _shortcutContent.Enabled = ItemEnabled;
                }
            }

            // Add split item separator
            SplitSeparator = new ViewDrawMenuSeparator(menuItemState.ItemSplit);
            docker.Add(SplitSeparator, ViewDockStyle.Right);
            SplitSeparator.Enabled = ItemEnabled;
            SplitSeparator.Draw    = (KryptonContextMenuItem.Items.Count > 0) && KryptonContextMenuItem.SplitSubMenu;

            // SubMenu Indicator
            HasSubMenu      = (KryptonContextMenuItem.Items.Count > 0);
            _subMenuContent = new ViewDrawMenuItemContent(menuItemState.ItemImage.Content, new FixedContentValue(null, null, (!HasSubMenu ? _empty16x16 : provider.ProviderImages.GetContextMenuSubMenuImage()), (KryptonContextMenuItem.Items.Count == 0 ? Color.Magenta : Color.Empty)), 3);
            docker.Add(new ViewLayoutCenter(_subMenuContent), ViewDockStyle.Right);
            _subMenuContent.Enabled = ItemEnabled;

            Add(docker);

            // Add a controller for handing mouse and keyboard events
            MenuItemController mic = new MenuItemController(provider.ProviderViewManager, this, provider.ProviderNeedPaintDelegate);

            MouseController = mic;
            KeyController   = mic;

            // Want to know when a property changes whilst displayed
            KryptonContextMenuItem.PropertyChanged += OnPropertyChanged;

            // We need to know if a property of the command changes
            if (KryptonContextMenuItem.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuItem.KryptonCommand;
                KryptonContextMenuItem.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }
        }