ComponentFactory.Krypton.Ribbon.ViewDrawRibbonGroupGallery.GetPossibleSizes C# (CSharp) Method

GetPossibleSizes() public method

Gets an array of the allowed possible sizes of the container.
public GetPossibleSizes ( ViewLayoutContext context ) : ItemSizeWidth[]
context ViewLayoutContext Context used to calculate the sizes.
return ItemSizeWidth[]
        public ItemSizeWidth[] GetPossibleSizes(ViewLayoutContext context)
        {
            // Ensure the control has the correct parent
            UpdateParent(context.Control);

            if (LastGallery != null)
            {
                Size originalItemSize = LastGallery.PreferredItemSize;
                GroupItemSize originalSize = _currentSize;

                // Create a list of results
                List<ItemSizeWidth> results = new List<ItemSizeWidth>();

                // Are we allowed to be in the large size?
                if (_ribbonGallery.ItemSizeMaximum == GroupItemSize.Large)
                {
                    // Allow a maximum of 39 steps between the large and medium values (with a minimum of 1)
                    int step = Math.Max(1, (_ribbonGallery.LargeItemCount - _ribbonGallery.MediumItemCount) / 20);

                    // Process each step from large to medium
                    int itemCount = _ribbonGallery.LargeItemCount;
                    while (itemCount > _ribbonGallery.MediumItemCount)
                    {
                        LastGallery.InternalPreferredItemSize = new Size(itemCount, 1);
                        results.Add(new ItemSizeWidth(GroupItemSize.Large, GetPreferredSize(context).Width, itemCount));
                        itemCount -= step;
                    }
                }

                // Are we allowed to be in the medium size?
                if (((int)_ribbonGallery.ItemSizeMaximum >= (int)GroupItemSize.Medium) &&
                    ((int)_ribbonGallery.ItemSizeMinimum <= (int)GroupItemSize.Medium))
                {
                    LastGallery.InternalPreferredItemSize = new Size(_ribbonGallery.MediumItemCount, 1);
                    ItemSizeWidth mediumWidth = new ItemSizeWidth(GroupItemSize.Medium, GetPreferredSize(context).Width);

                    if (_ribbon.InDesignHelperMode)
                    {
                        // Only add if we are the first calculation, as in design mode we
                        // always provide a single possible size which is the largest item
                        if (results.Count == 0)
                            results.Add(mediumWidth);
                    }
                    else
                    {
                        // Only add the medium size if there is no other entry or we are
                        // smaller than the existing size and so represent a useful shrinkage
                        if ((results.Count == 0) || (results[results.Count - 1].Width > mediumWidth.Width))
                            results.Add(mediumWidth);
                    }
                }

                // Are we allowed to be in the small size?
                if ((int)_ribbonGallery.ItemSizeMinimum == (int)GroupItemSize.Small)
                {
                    // Temporary set the item size to be size
                    _viewLarge.Visible = true;
                    _currentSize = GroupItemSize.Small;

                    // Get the width of the large button view
                    ItemSizeWidth smallWidth = new ItemSizeWidth(GroupItemSize.Small, GetPreferredSize(context).Width);

                    if (_ribbon.InDesignHelperMode)
                    {
                        // Only add if we are the first calculation, as in design mode we
                        // always provide a single possible size which is the largest item
                        if (results.Count == 0)
                            results.Add(smallWidth);
                    }
                    else
                    {
                        // Only add the medium size if there is no other entry or we are
                        // smaller than the existing size and so represent a useful shrinkage
                        if ((results.Count == 0) || (results[results.Count - 1].Width > smallWidth.Width))
                            results.Add(smallWidth);
                    }
                }

                // Ensure original value is put back
                LastGallery.InternalPreferredItemSize = originalItemSize;
                _currentSize = originalSize;

                return results.ToArray();
            }
            else
                return new ItemSizeWidth[] { new ItemSizeWidth(GroupItemSize.Large, NULL_CONTROL_WIDTH) };
        }