Beispiel #1
0
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case @"Text":
            case @"ExtraText":
            case @"Image":
            case @"ImageTransparentColor":
            case @"Enabled":
            case @"Checked":
            case @"CheckState":
                // Update to show new state
                _provider.ProviderNeedPaintDelegate(this, new NeedLayoutEventArgs(true));
                break;

            case @"KryptonCommand":
                // Unhook from any existing command
                if (_cachedCommand != null)
                {
                    _cachedCommand.PropertyChanged -= OnCommandPropertyChanged;
                }

                // Hook into the new command
                _cachedCommand = KryptonContextMenuCheckBox.KryptonCommand;
                if (_cachedCommand != null)
                {
                    _cachedCommand.PropertyChanged += OnCommandPropertyChanged;
                }

                // Update to show new state
                _provider.ProviderNeedPaintDelegate(this, new NeedLayoutEventArgs(true));
                break;
            }
        }
Beispiel #2
0
        private void AddMenuItemForPluginUIElement(KryptonCommand command, KryptonContextMenuItems rootItem, IEnumerable <IPluginUIElement> childrens, bool isFirst)
        {
            MainFormMenuItemControl mainFormMenuItem = new MainFormMenuItemControl(command, rootItem);

            // Add childrens
            KryptonContextMenuItems childrenItems = new KryptonContextMenuItems();

            if (childrens != null)
            {
                foreach (IPluginUIElement children in childrens)
                {
                    AddMenuItemForPluginUIElement(CreateCommandForPluginUIElement(children), childrenItems, children.Childrens, false);
                }

                if (childrenItems.Items.Count > 0)
                {
                    mainFormMenuItem.Items.Add(childrenItems);
                }
            }

            // Insert into "all items container" which is in 0 position
            if (isFirst)
            {
                rootItem.Items.Insert(0, new KryptonContextMenuSeparator());
            }

            rootItem.Items.Insert(0, mainFormMenuItem);
        }
        public MainFormMenuItemControl(KryptonCommand command, KryptonContextMenuItems parent)
        {
            Parent = parent;

            _command           = command;
            _command.Disposed += CommandDisposed;
        }
Beispiel #4
0
        /// <summary>
        /// Raises the Click event.
        /// </summary>
        /// <param name="finishDelegate">Delegate fired during event processing.</param>
        protected virtual void OnClick(EventHandler finishDelegate)
        {
            bool fireDelegate = true;

            if (!Ribbon.InDesignMode)
            {
                // Events only occur when enabled
                if (Enabled)
                {
                    // A check button should always toggle state
                    if (ButtonType == GroupButtonType.Check)
                    {
                        // Push back the change to the attached command
                        if (KryptonCommand != null)
                        {
                            KryptonCommand.Checked = !KryptonCommand.Checked;
                        }
                        else
                        {
                            Checked = !Checked;
                        }
                    }

                    // In showing a popup we fire the delegate before the click so that the
                    // minimized popup is removed out of the way before the event is handled
                    // because if the event shows a dialog then it would appear behind the popup
                    if (VisualPopupManager.Singleton.CurrentPopup != null)
                    {
                        // Do we need to fire a delegate stating the click processing has finished?
                        if (fireDelegate && (finishDelegate != null))
                        {
                            finishDelegate(this, EventArgs.Empty);
                        }

                        fireDelegate = false;
                    }

                    // Generate actual click event
                    if (Click != null)
                    {
                        Click(this, EventArgs.Empty);
                    }

                    // Clicking the button should execute the associated command
                    if (KryptonCommand != null)
                    {
                        KryptonCommand.PerformExecute();
                    }
                }
            }

            // Do we need to fire a delegate stating the click processing has finished?
            if (fireDelegate && (finishDelegate != null))
            {
                finishDelegate(this, EventArgs.Empty);
            }
        }
        public ToolStripUIElementButton(KryptonCommand command)
        {
            _command = command;

            _command.PropertyChanged += OnPropertyChanged;
            _command.Execute         += OnExecute;
            _command.Disposed        += OnDisposed;

            UpdateUI();
        }
Beispiel #6
0
        /// <summary>
        /// Raises the Click event.
        /// </summary>
        /// <param name="e">An EventArgs containing the event data.</param>
        protected virtual void OnClick(EventArgs e)
        {
            // Perform processing that is common to any action that would dismiss
            // any popup controls such as the showing minimized group popup
            Ribbon?.ActionOccured();

            Click?.Invoke(this, e);

            // Clicking the button should execute the associated command
            KryptonCommand?.PerformExecute();
        }
Beispiel #7
0
 private void AssignCommand(KryptonCommand command)
 {
     buttonSpecAny1.KryptonCommand      = command;
     kryptonButton1.KryptonCommand      = command;
     kryptonCheckButton1.KryptonCommand = command;
     kryptonDropButton1.KryptonCommand  = command;
     kryptonColorButton1.KryptonCommand = command;
     kryptonLabel1.KryptonCommand       = command;
     kryptonLinkLabel1.KryptonCommand   = command;
     kryptonCheckBox1.KryptonCommand    = command;
 }
Beispiel #8
0
 private void AssignCommand(KryptonCommand command)
 {
     buttonSpecAny1.KryptonCommand = command;
     kryptonButton1.KryptonCommand = command;
     kryptonCheckButton1.KryptonCommand = command;
     kryptonDropButton1.KryptonCommand = command;
     kryptonColorButton1.KryptonCommand = command;
     kryptonLabel1.KryptonCommand = command;
     kryptonLinkLabel1.KryptonCommand = command;
     kryptonCheckBox1.KryptonCommand = command;
 }
Beispiel #9
0
        private void AddToolbarButtonForPluginUIElement(KryptonCommand command)
        {
            ToolStripUIElementButton button = new ToolStripUIElementButton(command)
            {
                ImageAlign         = ContentAlignment.MiddleCenter,
                ImageScaling       = ToolStripItemImageScaling.None,
                CheckOnClick       = false,
                DoubleClickEnabled = false,
            };

            toolStripMain.Items.Add(button);
            toolStripMain.Refresh();
        }
Beispiel #10
0
        private void AddMenuItemForPluginUIElement(KryptonCommand command, IEnumerable <IPluginUIElement> childrens, bool isFirst)
        {
            KryptonContextMenuItems rootItem;

            if (contextMenuMain.Items.Count > 0 && contextMenuMain.Items[0] is KryptonContextMenuItems)
            {
                rootItem = (KryptonContextMenuItems)contextMenuMain.Items[0];

                AddMenuItemForPluginUIElement(command, rootItem, childrens, isFirst);
            }
            else
            {
                throw new InvalidOperationException("Can't find menu root item for plugins");
            }
        }
Beispiel #11
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Unhook from events
                KryptonContextMenuCheckBox.PropertyChanged -= OnPropertyChanged;

                if (_cachedCommand != null)
                {
                    _cachedCommand.PropertyChanged -= OnCommandPropertyChanged;
                    _cachedCommand = null;
                }
            }

            base.Dispose(disposing);
        }
        /// <summary>
        /// Raises the Click event.
        /// </summary>
        /// <param name="e">An EventArgs containing the event data.</param>
        protected virtual void OnClick(EventArgs e)
        {
            // Perform processing that is common to any action that would dismiss
            // any popup controls such as the showing minimized group popup
            if (Ribbon != null)
            {
                Ribbon.ActionOccured();
            }

            if (Click != null)
            {
                Click(this, e);
            }

            // Clicking the button should execute the associated command
            if (KryptonCommand != null)
            {
                KryptonCommand.PerformExecute();
            }
        }
Beispiel #13
0
        private void LoadPluginUIElements(IPlugin plugin)
        {
            if (plugin.UIElements == null)
            {
                return;
            }

            UnloadUIElements(plugin.UIElements);

            lock (_uiElementsCommands)
            {
                bool hasMenuItems = false;

                foreach (IPluginUIElement uiElement in plugin.UIElements)
                {
                    if (!_uiElementsCommands.ContainsKey(uiElement.Id))
                    {
                        KryptonCommand command = CreateCommandForPluginUIElement(uiElement);

                        try
                        {
                            if (uiElement.ShowInToolBar)
                            {
                                AddToolbarButtonForPluginUIElement(command);
                            }
                            if (uiElement.ShowInMenu)
                            {
                                AddMenuItemForPluginUIElement(command, uiElement.Childrens, !hasMenuItems);

                                hasMenuItems = true;
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.LogWarn(e);
                        }
                    }
                }
            }
        }
        /// <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;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Raises the Click event.
        /// </summary>
        /// <param name="finishDelegate">Delegate fired during event processing.</param>
        protected virtual void OnClick(EventHandler finishDelegate)
        {
            bool fireDelegate = true;

            if (!Ribbon.InDesignMode)
            {
                if (Enabled)
                {
                    if (AutoCheck)
                    {
                        // Find current state
                        CheckState checkState = CheckState.Unchecked;
                        if (KryptonCommand != null)
                        {
                            checkState = KryptonCommand.CheckState;
                        }
                        else
                        {
                            checkState = CheckState;
                        }

                        // Find new state based on the current state
                        switch (checkState)
                        {
                        case CheckState.Unchecked:
                            checkState = CheckState.Checked;
                            break;

                        case CheckState.Checked:
                            checkState = (ThreeState ? CheckState.Indeterminate : CheckState.Unchecked);
                            break;

                        case CheckState.Indeterminate:
                            checkState = CheckState.Unchecked;
                            break;
                        }

                        // Push back the change to the attached command
                        if (KryptonCommand != null)
                        {
                            KryptonCommand.CheckState = checkState;
                        }
                        else
                        {
                            CheckState = checkState;
                        }
                    }

                    // In showing a popup we fire the delegate before the click so that the
                    // minimized popup is removed out of the way before the event is handled
                    // because if the event shows a dialog then it would appear behind the popup
                    if (VisualPopupManager.Singleton.CurrentPopup != null)
                    {
                        // Do we need to fire a delegate stating the click processing has finished?
                        if (fireDelegate && (finishDelegate != null))
                        {
                            finishDelegate(this, EventArgs.Empty);
                        }

                        fireDelegate = false;
                    }

                    // Generate actual click event
                    if (Click != null)
                    {
                        Click(this, EventArgs.Empty);
                    }

                    // Clicking the button should execute the associated command
                    if (KryptonCommand != null)
                    {
                        KryptonCommand.PerformExecute();
                    }
                }
            }

            // Do we need to fire a delegate stating the click processing has finished?
            if (fireDelegate && (finishDelegate != null))
            {
                finishDelegate(this, EventArgs.Empty);
            }
        }
        /// <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;
            _checkButton = 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
            _checkButton.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the view button instance
            _drawButton = 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
            _drawButton.SetCheckedPalettes(checkButton.OverrideCheckedNormal,
                                           checkButton.OverrideCheckedTracking,
                                           checkButton.OverrideCheckedPressed);

            _drawButton.Enabled = _itemEnabled;
            _drawButton.Checked = ResolveChecked;

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

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

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

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

            // Want to know when a property changes whilst displayed
            _checkButton.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged);

            // We need to know if a property of the command changes
            if (_checkButton.KryptonCommand != null)
            {
                _cachedCommand = _checkButton.KryptonCommand;
                _checkButton.KryptonCommand.PropertyChanged += new PropertyChangedEventHandler(OnCommandPropertyChanged);
            }
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuLinkLabel class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="linkLabel">Reference to owning link label entry.</param>
        public ViewDrawMenuLinkLabel(IContextMenuProvider provider,
                                     KryptonContextMenuLinkLabel linkLabel)
        {
            _provider = provider;
            _linkLabel = linkLabel;

            // Create fixed storage of the content values
            _contentValues = new FixedContentValue(linkLabel.Text,
                                                   linkLabel.ExtraText,
                                                   linkLabel.Image,
                                                   linkLabel.ImageTransparentColor);

            // Decide on the enabled state of the display
            _itemEnabled = provider.ProviderEnabled;

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

            // Create the content for the actual heading text/image
            _drawContent = new ViewDrawContent(linkLabel.OverrideFocusNotVisited, _contentValues, VisualOrientation.Top);
            _drawContent.UseMnemonic = true;
            _drawContent.Enabled = _itemEnabled;

            // Place label link in the center of the area but inside some separator to add spacing
            _innerDocker = new ViewLayoutDocker();
            _innerDocker.Add(_drawContent, ViewDockStyle.Fill);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Right);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Left);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Top);
            _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Bottom);

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

            // Use context menu specific version of the link label controller
            MenuLinkLabelController mllc = new MenuLinkLabelController(provider.ProviderViewManager, _drawContent, this, provider.ProviderNeedPaintDelegate);
            mllc.Click += new EventHandler(OnClick);
            _drawContent.MouseController = mllc;
            _drawContent.KeyController = mllc;

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

            // Want to know when a property changes whilst displayed
            _linkLabel.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged);

            // We need to know if a property of the command changes
            if (_linkLabel.KryptonCommand != null)
            {
                _cachedCommand = _linkLabel.KryptonCommand;
                _linkLabel.KryptonCommand.PropertyChanged += new PropertyChangedEventHandler(OnCommandPropertyChanged);
            }
        }
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "Text":
                case "ExtraText":
                case "Image":
                case "ImageTransparentColor":
                    // Update to show new state
                    _provider.ProviderNeedPaintDelegate(this, new NeedLayoutEventArgs(true));
                    break;
                case "KryptonCommand":
                    // Unhook from any existing command
                    if (_cachedCommand != null)
                        _cachedCommand.PropertyChanged -= new PropertyChangedEventHandler(OnCommandPropertyChanged);

                    // Hook into the new command
                    _cachedCommand = _linkLabel.KryptonCommand;
                    if (_cachedCommand != null)
                        _cachedCommand.PropertyChanged += new PropertyChangedEventHandler(OnCommandPropertyChanged);

                    // Update to show new state
                    _provider.ProviderNeedPaintDelegate(this, new NeedLayoutEventArgs(true));
                    break;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuCheckBox class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="checkBox">Reference to owning check box entry.</param>
        public ViewDrawMenuCheckBox(IContextMenuProvider provider,
                                    KryptonContextMenuCheckBox checkBox)
        {
            _provider = provider;
            KryptonContextMenuCheckBox = checkBox;

            // 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
            KryptonContextMenuCheckBox.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the content for the actual heading text/image
            ViewDrawContent = new ViewDrawContent(ItemEnabled ? KryptonContextMenuCheckBox.OverrideNormal : KryptonContextMenuCheckBox.OverrideDisabled,
                                                  _contentValues, VisualOrientation.Top)
            {
                UseMnemonic = true,
                Enabled     = ItemEnabled
            };

            // Create the check box image drawer and place inside element so it is always centered
            ViewDrawCheckBox = new ViewDrawCheckBox(KryptonContextMenuCheckBox.StateCheckBoxImages)
            {
                CheckState = ResolveCheckState,
                Enabled    = ItemEnabled
            };
            _layoutCenter = new ViewLayoutCenter
            {
                ViewDrawCheckBox
            };

            // Place the check box on the left of the available space but inside separators
            _innerDocker = new ViewLayoutDocker
            {
                { ViewDrawContent, ViewDockStyle.Fill },
                { _layoutCenter, ViewDockStyle.Left },
                { new ViewLayoutSeparator(1), ViewDockStyle.Right },
                { new ViewLayoutSeparator(3), 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
            MenuCheckBoxController 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
            KryptonContextMenuCheckBox.PropertyChanged += OnPropertyChanged;

            // We need to know if a property of the command changes
            if (KryptonContextMenuCheckBox.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuCheckBox.KryptonCommand;
                KryptonContextMenuCheckBox.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }
        }
Beispiel #20
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);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Unhook from events
                _menuItem.PropertyChanged -= new PropertyChangedEventHandler(OnPropertyChanged);

                if (_cachedCommand != null)
                {
                    _cachedCommand.PropertyChanged -= new PropertyChangedEventHandler(OnCommandPropertyChanged);
                    _cachedCommand = null;
                }
            }

            base.Dispose(disposing);
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuCheckBox class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="checkBox">Reference to owning check box entry.</param>
        public ViewDrawMenuCheckBox(IContextMenuProvider provider,
                                    KryptonContextMenuCheckBox checkBox)
        {
            _provider = provider;
            _checkBox = checkBox;

            // 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
            _checkBox.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the content for the actual heading text/image
            _drawContent = new ViewDrawContent((_itemEnabled ? (IPaletteContent)_checkBox.OverrideNormal : (IPaletteContent)_checkBox.OverrideDisabled),
                                               _contentValues, VisualOrientation.Top);
            _drawContent.UseMnemonic = true;
            _drawContent.Enabled = _itemEnabled;

            // Create the check box image drawer and place inside element so it is always centered
            _drawCheckBox = new ViewDrawCheckBox(_checkBox.StateCheckBoxImages);
            _drawCheckBox.CheckState = ResolveCheckState;
            _drawCheckBox.Enabled = _itemEnabled;
            _layoutCenter = new ViewLayoutCenter();
            _layoutCenter.Add(_drawCheckBox);

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

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

            // Use context menu specific version of the check box controller
            MenuCheckBoxController mcbc = new MenuCheckBoxController(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate);
            mcbc.Click += new EventHandler(OnClick);
            _innerDocker.MouseController = mcbc;
            _innerDocker.KeyController = mcbc;

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

            // Want to know when a property changes whilst displayed
            _checkBox.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged);

            // We need to know if a property of the command changes
            if (_checkBox.KryptonCommand != null)
            {
                _cachedCommand = _checkBox.KryptonCommand;
                _checkBox.KryptonCommand.PropertyChanged += new PropertyChangedEventHandler(OnCommandPropertyChanged);
            }
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuLinkLabel class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="linkLabel">Reference to owning link label entry.</param>
        public ViewDrawMenuLinkLabel(IContextMenuProvider provider,
                                     KryptonContextMenuLinkLabel linkLabel)
        {
            _provider = provider;
            KryptonContextMenuLinkLabel = linkLabel;

            // Create fixed storage of the content values
            _contentValues = new FixedContentValue(linkLabel.Text,
                                                   linkLabel.ExtraText,
                                                   linkLabel.Image,
                                                   linkLabel.ImageTransparentColor);

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

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

            // Create the content for the actual heading text/image
            _drawContent = new ViewDrawContent(linkLabel.OverrideFocusNotVisited, _contentValues, VisualOrientation.Top)
            {
                UseMnemonic = true,
                Enabled     = ItemEnabled
            };

            // Place label link in the center of the area but inside some separator to add spacing
            _innerDocker = new ViewLayoutDocker
            {
                { _drawContent, 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 link label controller
            MenuLinkLabelController mllc = new(provider.ProviderViewManager, _drawContent, this, provider.ProviderNeedPaintDelegate);

            mllc.Click += OnClick;
            _drawContent.MouseController = mllc;
            _drawContent.KeyController   = mllc;

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

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

            // We need to know if a property of the command changes
            if (KryptonContextMenuLinkLabel.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuLinkLabel.KryptonCommand;
                KryptonContextMenuLinkLabel.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }
        }
Beispiel #24
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuRadioButton class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="radioButton">Reference to owning radio button entry.</param>
        public ViewDrawMenuRadioButton(IContextMenuProvider provider,
                                       KryptonContextMenuRadioButton radioButton)
        {
            _provider = provider;
            KryptonContextMenuRadioButton = radioButton;

            // Create fixed storage of the content values
            _contentValues = new FixedContentValue(radioButton.Text,
                                                   radioButton.ExtraText,
                                                   radioButton.Image,
                                                   radioButton.ImageTransparentColor);

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

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

            // Create the content for the actual heading text/image
            ViewDrawContent = new ViewDrawContent(ItemEnabled ? KryptonContextMenuRadioButton.OverrideNormal : KryptonContextMenuRadioButton.OverrideDisabled,
                                                  _contentValues, VisualOrientation.Top)
            {
                UseMnemonic = true,
                Enabled     = ItemEnabled
            };

            // Create the radio button image drawer and place inside element so it is always centered
            ViewDrawRadioButton = new ViewDrawRadioButton(KryptonContextMenuRadioButton.StateRadioButtonImages)
            {
                CheckState = KryptonContextMenuRadioButton.Checked,
                Enabled    = ItemEnabled
            };
            _layoutCenter = new ViewLayoutCenter
            {
                ViewDrawRadioButton
            };

            // Place the radio button on the left of the available space but inside separators
            _innerDocker = new ViewLayoutDocker
            {
                { ViewDrawContent, ViewDockStyle.Fill },
                { _layoutCenter, ViewDockStyle.Left },
                { new ViewLayoutSeparator(1), ViewDockStyle.Right },
                { new ViewLayoutSeparator(3), 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 radio button controller
            MenuRadioButtonController mrbc = new(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate);

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

            // We need to be notified whenever the checked state changes
            KryptonContextMenuRadioButton.CheckedChanged += OnCheckedChanged;

            if (KryptonContextMenuRadioButton.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuRadioButton.KryptonCommand;

                KryptonContextMenuRadioButton.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }

            // Add docker as the composite content
            Add(_outerDocker);
        }
Beispiel #25
0
 private void AddMenuItemForPluginUIElement(KryptonCommand command, IEnumerable <IPluginUIElement> childrens)
 {
     AddMenuItemForPluginUIElement(command, childrens, false);
 }
 /// <summary>
 /// Initialize a new instance of the KryptonCommandActionList class.
 /// </summary>
 /// <param name="owner">Designer that owns this action list instance.</param>
 public KryptonCommandActionList(KryptonCommandDesigner owner)
     : base(owner.Component)
 {
     // Remember the panel instance
     _command = owner.Component as KryptonCommand;
 }