Inheritance: GlobalId, IMouseController, IKeyController, ISourceController, IContextMenuTarget
        /// <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;
            }
        }
示例#2
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;
            _menuItem = menuItem;
            _imageColumn = imageColumn;
            _standardStyle = standardStyle;

            // Give the item object the redirector to use when inheriting values
            _menuItem.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 ? _menuItem.StateNormal : _menuItem.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 ? _menuItem.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);
            _imageCanvas.Add(_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 (_menuItem.ShowShortcutKeys)
            {
                string shortcutString = _menuItem.ShortcutKeyDisplayString;
                if (string.IsNullOrEmpty(shortcutString))
                    shortcutString = (_menuItem.ShortcutKeys != Keys.None) ? new KeysConverter().ConvertToString(_menuItem.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 = (_menuItem.Items.Count > 0) && _menuItem.SplitSubMenu;

            // SubMenu Indicator
            _hasSubMenu = (_menuItem.Items.Count > 0);
            _subMenuContent = new ViewDrawMenuItemContent(menuItemState.ItemImage.Content, new FixedContentValue(null, null, (!_hasSubMenu ? _empty16x16 : provider.ProviderImages.GetContextMenuSubMenuImage()), (_menuItem.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
            _menuItem.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged);

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