/// <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)
        {
            Debug.Assert(component != null);

            // Validate the parameter reference
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            // Let base class do standard stuff
            base.Initialize(component);

            // Cast to correct type
            _ribbonCluster = (KryptonRibbonGroupCluster)component;
            _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;
        }
Exemple #2
0
        private void OnDeleteButton(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 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(_ribbonButton);

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

                    RaiseComponentChanged(propertyItems, null, null);
                    RaiseComponentChanged(null, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    transaction?.Commit();
                }
            }
        }
Exemple #3
0
        private void OnMoveLast(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 MoveLast");

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

                    RaiseComponentChanging(propertyItems);

                    // Move position of the triple
                    cluster.Items.Remove(_ribbonButton);
                    cluster.Items.Insert(cluster.Items.Count, _ribbonButton);
                    UpdateVerbStatus();

                    RaiseComponentChanged(propertyItems, null, null);
                }
                finally
                {
                    // If we managed to create the transaction, then do it
                    if (transaction != null)
                    {
                        transaction.Commit();
                    }
                }
            }
        }
Exemple #4
0
 /// <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;
 }
Exemple #5
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 PaletteBorderEdgeRedirect(_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 ViewHightlightController(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 DesignerVerb[] { _toggleHelpersVerb, _moveFirstVerb, _movePrevVerb,
                                                     _moveNextVerb, _moveLastVerb, _deleteButtonVerb });
            }

            bool moveFirst = false;
            bool movePrev  = false;
            bool moveNext  = false;
            bool 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;
        }