private void OnComponentRemoving(object sender, ComponentEventArgs e)
        {
            // If our cluster is being removed
            if (e.Component == _ribbonCluster)
            {
                // Need access to host in order to delete a component
                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

                // We need to remove all items from the cluster
                for (int j = _ribbonCluster.Items.Count - 1; j >= 0; j--)
                {
                    IRibbonGroupItem item = _ribbonCluster.Items[j] as IRibbonGroupItem;

                    if (item != null)
                    {
                        _ribbonCluster.Items.Remove(item);
                        host.DestroyComponent(item as Component);
                    }
                    else
                    {
                        IRibbonGroupContainer container = _ribbonCluster.Items[j] as IRibbonGroupContainer;
                        _ribbonCluster.Items.Remove(container);
                        host.DestroyComponent(container as Component);
                    }
                }
            }
        }
Beispiel #2
0
        public virtual int ItemGap(IRibbonGroupItem previousItem)
        {
            // If the previous item is a group button cluster then we want 3 pixels
            return(previousItem is KryptonRibbonGroupCluster ? 3 : 1);

            // By default we just want a single pixel gap
        }
Beispiel #3
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            // Sync child elements to the current group items
            SyncChildrenToRibbonGroupItems();

            // Clear down the cache of item sizes
            _sizeList.Clear();
            _viewList.Clear();
            _viewToGap.Clear();

            int      totalWidth    = 0;
            ViewBase previousChild = null;

            // Find the size of each individual visible child item
            for (int i = 0; i < this.Count; i++)
            {
                ViewBase child = this[i];

                // Only interested in visible items
                if (child.Visible)
                {
                    // Are we positioning a cluster?
                    if (child is ViewLayoutRibbonGroupCluster)
                    {
                        // Inform cluster if it is immediatley after another cluster (and so potentially needs a separator)
                        ViewLayoutRibbonGroupCluster clusterChild = (ViewLayoutRibbonGroupCluster)child;
                        clusterChild.StartSeparator = (previousChild != null) && !(previousChild is ViewLayoutRibbonGroupCluster);
                        clusterChild.EndSeparator   = true;
                    }

                    // Can we calculate the spacing gap between the previous and this item
                    if (previousChild != null)
                    {
                        if (_viewToItem.ContainsKey(child) &&
                            _viewToItem.ContainsKey(previousChild))
                        {
                            // Cast to correct type
                            IRibbonGroupItem childItem    = _viewToItem[child] as IRibbonGroupItem;
                            IRibbonGroupItem previousItem = _viewToItem[previousChild] as IRibbonGroupItem;

                            // Find the requested gap between them
                            _viewToGap.Add(child, childItem.ItemGap(previousItem));
                        }
                        else
                        {
                            // Default the gap
                            _viewToGap.Add(child, DEFAULT_GAP);
                        }
                    }

                    // Get requested size of the child
                    Size childSize = child.GetPreferredSize(context);

                    // Add to list of visible child sizes
                    _sizeList.Add(childSize);
                    _viewList.Add(child);

                    // Cache total visible width for later
                    totalWidth += childSize.Width;

                    // This is now the previous child
                    previousChild = child;
                }
            }

            // Find the item size specific preferred calculation
            switch (_currentSize)
            {
            case GroupItemSize.Large:
                return(LargeMediumPreferredSize(totalWidth, ref _split1Large));

            case GroupItemSize.Medium:
                return(LargeMediumPreferredSize(totalWidth, ref _split1Medium));

            case GroupItemSize.Small:
                return(SmallPreferredSize(totalWidth));

            default:
                // Should never happen!
                Debug.Assert(false);
                return(Size.Empty);
            }
        }
        public virtual int ItemGap(IRibbonGroupItem previousItem)
        {
            // If the previous item is a group button cluster then we want 3 pixels
            if (previousItem is KryptonRibbonGroupCluster)
                return 3;

            // By default we just want a single pixel gap
            return 1;
        }
Beispiel #5
0
 public override int ItemGap(IRibbonGroupItem previousItem)
 {
     // We always want 3 pixels space between previous item and us
     return(3);
 }
 public override int ItemGap(IRibbonGroupItem previousItem)
 {
     // We always want 3 pixels space between previous item and us
     return 3;
 }
 public virtual int ItemGap(IRibbonGroupItem previousItem) =>
 // If the previous item is a group button cluster then we want 3 pixels
 previousItem is KryptonRibbonGroupCluster ? 3 : 1;