private void OnMoveNext(object sender, EventArgs e)
        {
            if (_ribbonButton?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupCluster cluster = (KryptonRibbonGroupCluster)_ribbonButton.RibbonContainer;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction(@"KryptonRibbonGroupClusterButton MoveNext");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(cluster)[@"Items"];

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    var index = cluster.Items.IndexOf(_ribbonButton) + 1;
                    index = Math.Min(index, cluster.Items.Count - 1);
                    cluster.Items.Remove(_ribbonButton);
                    cluster.Items.Insert(index, _ribbonButton);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
        private void OnDeleteButton(object sender, EventArgs e)
        {
            if (_ribbonColorButton?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupCluster cluster = (KryptonRibbonGroupCluster)_ribbonColorButton.RibbonContainer;

                // Use a transaction to support undo/redo actions
                DesignerTransaction transaction = _designerHost.CreateTransaction(@"KryptonRibbonGroupColorClusterButton DeleteButton");

                try
                {
                    // Get access to the Items property
                    MemberDescriptor propertyItems = TypeDescriptor.GetProperties(cluster)[@"Items"];

                    // Remove the ribbon group from the ribbon tab
                    RaiseComponentChanging(null);
                    RaiseComponentChanging(propertyItems);

                    // Remove the button from the group
                    cluster.Items.Remove(_ribbonColorButton);

                    // Get designer to destroy it
                    _designerHost.DestroyComponent(_ribbonColorButton);

                    RaiseComponentChanged(propertyItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
 /// <summary>
 /// Initialize a new instance of the ViewDrawRibbonDesignCluster class.
 /// </summary>
 /// <param name="ribbon">Reference to owning ribbon control.</param>
 /// <param name="ribbonCluster">Reference to cluster definition.</param>
 /// <param name="needPaint">Delegate for notifying paint requests.</param>
 public ViewDrawRibbonDesignCluster(KryptonRibbon ribbon,
                                    KryptonRibbonGroupCluster ribbonCluster,
                                    NeedPaintHandler needPaint)
     : base(ribbon, needPaint)
 {
     Debug.Assert(ribbonCluster != null);
     _ribbonCluster = ribbonCluster;
     _padding       = new Padding((int)(1 * FactorDpiX), (int)(2 * FactorDpiY), 0, (int)(2 * FactorDpiY));
 }
Beispiel #4
0
        /// <summary>
        /// Initialize a new instance of the ViewLayoutRibbonGroupCluster class.
        /// </summary>
        /// <param name="ribbon">Owning ribbon control instance.</param>
        /// <param name="ribbonCluster">Reference to cluster definition.</param>
        /// <param name="needPaint">Delegate for notifying paint requests.</param>
        public ViewLayoutRibbonGroupCluster(KryptonRibbon ribbon,
                                            KryptonRibbonGroupCluster ribbonCluster,
                                            NeedPaintHandler needPaint)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(ribbonCluster != null);
            Debug.Assert(needPaint != null);

            // Cache references
            _ribbon        = ribbon;
            _ribbonCluster = ribbonCluster;
            _needPaint     = needPaint;
            _currentSize   = GroupItemSize.Medium;

            // Associate the component with this view element for design time selection
            Component = _ribbonCluster;

            // Create the start and end separators
            _startSep        = new ViewDrawRibbonGroupClusterSeparator(_ribbon, true);
            _endSep          = new ViewDrawRibbonGroupClusterSeparator(_ribbon, false);
            _startSepVisible = false;
            _endSepVisible   = false;

            // Create palette used to supply a width to a border edge view
            PaletteBorderEdgeRedirect borderEdgeRedirect = new(_ribbon.StateCommon.RibbonGroupClusterButton.Border, needPaint);

            _paletteBorderEdge = new PaletteBorderEdge(borderEdgeRedirect, needPaint);
            _lastShape         = PaletteRibbonShape.Office2007;

            // Use hashtable to store relationships
            _itemToView       = new ItemToView();
            _viewToEdge       = new ViewToEdge();
            _viewToSizeMedium = new ViewToSize();
            _viewToSizeSmall  = new ViewToSize();

            // Hook into changes in the ribbon cluster definition
            _ribbonCluster.PropertyChanged += OnClusterPropertyChanged;
            _ribbonCluster.ClusterView      = this;

            // At design time we want to track the mouse and show feedback
            if (_ribbon.InDesignMode)
            {
                ViewHightlightController controller = new(this, needPaint);
                controller.ContextClick += OnContextClick;
                MouseController          = controller;
            }
        }
        private void UpdateVerbStatus()
        {
            // Create verbs first time around
            if (_verbs == null)
            {
                _verbs             = new DesignerVerbCollection();
                _toggleHelpersVerb = new DesignerVerb(@"Toggle Helpers", OnToggleHelpers);
                _moveFirstVerb     = new DesignerVerb(@"Move Cluster Button First", OnMoveFirst);
                _movePrevVerb      = new DesignerVerb(@"Move Cluster Button Previous", OnMovePrevious);
                _moveNextVerb      = new DesignerVerb(@"Move Cluster Button Next", OnMoveNext);
                _moveLastVerb      = new DesignerVerb(@"Move Cluster Button Last", OnMoveLast);
                _deleteButtonVerb  = new DesignerVerb(@"Delete Cluster Button", OnDeleteButton);
                _verbs.AddRange(new[] { _toggleHelpersVerb, _moveFirstVerb, _movePrevVerb,
                                        _moveNextVerb, _moveLastVerb, _deleteButtonVerb });
            }

            var moveFirst = false;
            var movePrev  = false;
            var moveNext  = false;
            var moveLast  = false;

            if (_ribbonButton?.Ribbon != null)
            {
                // Cast container to the correct type
                KryptonRibbonGroupCluster cluster = (KryptonRibbonGroupCluster)_ribbonButton.RibbonContainer;

                moveFirst = cluster.Items.IndexOf(_ribbonButton) > 0;
                movePrev  = cluster.Items.IndexOf(_ribbonButton) > 0;
                moveNext  = cluster.Items.IndexOf(_ribbonButton) < (cluster.Items.Count - 1);
                moveLast  = cluster.Items.IndexOf(_ribbonButton) < (cluster.Items.Count - 1);
            }

            _moveFirstVerb.Enabled = moveFirst;
            _movePrevVerb.Enabled  = movePrev;
            _moveNextVerb.Enabled  = moveNext;
            _moveLastVerb.Enabled  = moveLast;
        }
        /// <summary>
        /// Initializes the designer with the specified component.
        /// </summary>
        /// <param name="component">The IComponent to associate the designer with.</param>
        public override void Initialize(IComponent component)
        {
            // Let base class do standard stuff
            base.Initialize(component);

            Debug.Assert(component != null);

            // Cast to correct type
            _ribbonCluster = component as KryptonRibbonGroupCluster;
            if (_ribbonCluster != null)
            {
                _ribbonCluster.DesignTimeAddButton      += OnAddButton;
                _ribbonCluster.DesignTimeAddColorButton += OnAddColorButton;
                _ribbonCluster.DesignTimeContextMenu    += OnContextMenu;
            }

            // Get access to the services
            _designerHost  = (IDesignerHost)GetService(typeof(IDesignerHost));
            _changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));

            // We need to know when we are being removed/changed
            _changeService.ComponentRemoving += OnComponentRemoving;
            _changeService.ComponentChanged  += OnComponentChanged;
        }