Exemplo n.º 1
0
 /// <summary>
 /// Update the group with the provided sizing solution.
 /// </summary>
 /// <param name="size">Value for the container.</param>
 public void SetSolutionSize(ItemSizeWidth size)
 {
     // Update the container definition
     GroupGallery.ItemSizeCurrent   = size.GroupItemSize;
     GroupGallery.InternalItemCount = size.Tag;
     _viewLarge.Visible             = (size.GroupItemSize == GroupItemSize.Small);
 }
 /// <summary>
 /// Update the group with the provided sizing solution.
 /// </summary>
 /// <param name="size">Value for the container.</param>
 public void SetSolutionSize(ItemSizeWidth size)
 {
     // Solution should always be the large, the only size we can be
     Debug.Assert(size.GroupItemSize == GroupItemSize.Large);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get an array of available widths for the group with associated sizing values.
        /// </summary>
        /// <param name="context">Context used to calculate the sizes.</param>
        /// <returns>Array of size values.</returns>
        public GroupSizeWidth[] GetPossibleSizes(ViewLayoutContext context)
        {
            // Sync child elements to the current group items
            SyncChildrenToRibbonGroupItems();

            // Get the permutations available for each child container
            _listWidths = new List <ItemSizeWidth[]>();

            // Scan all child containers
            int pixelGaps  = 0;
            int maxEntries = 0;

            for (int i = 0; i < Count; i++)
            {
                if (this[i].Visible && (this[i] is IRibbonViewGroupContainerView))
                {
                    // Cast child view to correct interface
                    IRibbonViewGroupContainerView container = (IRibbonViewGroupContainerView)this[i];

                    // Find list of possible sizes for this container
                    ItemSizeWidth[] widths = container.GetPossibleSizes(context);

                    // Track how many extra pixels are needed for inter container gaps
                    if (_listWidths.Count > 0)
                    {
                        pixelGaps++;
                    }

                    // Add into list of all container values
                    _listWidths.Add(widths);

                    // Track the longest list found
                    maxEntries = Math.Max(maxEntries, widths.Length);
                }
            }

            // Create list for holding resultant permutations
            List <GroupSizeWidth> retSizes = new List <GroupSizeWidth>();

            // Create array of indexes into each of the containers and set to zero
            int[] indexes = new int[_listWidths.Count];

            // Cycle around and around the indexes to create permutations
            int cycleMax     = _listWidths.Count - 1;
            int cycleCurrent = cycleMax;

            // Decide if we need to break out the process and generate a new perm
            bool breakOut;
            bool tags = true;

            do
            {
                // Generate permutation from current set of indexes
                int permTotalWidth = pixelGaps;
                new List <int>().Clear();

                // Per-permutation values
                List <ItemSizeWidth> permSize = new List <ItemSizeWidth>();
                permSize.Clear();

                // Generate permutation by taking cell values
                for (int k = _listWidths.Count - 1; k >= 0; k--)
                {
                    // Find width and size of the entry
                    ItemSizeWidth size = _listWidths[k][indexes[k]];

                    // Track the total width of this permutation
                    permTotalWidth += size.Width;
                    new List <int>().Insert(0, size.Width);
                    permSize.Insert(0, size);
                }

                // Only add this as a new permutation if the first entry added or if a smaller
                // size than the last entry. Permutations should be getting progressively smaller
                if ((retSizes.Count == 0) || (retSizes[retSizes.Count - 1].Width != permTotalWidth))
                {
                    retSizes.Add(new GroupSizeWidth(permTotalWidth, permSize.ToArray()));
                }

                // Do a full cycle looking for a tagged entry to consume
                breakOut = false;

                // Do we need to process tags?
                if (tags)
                {
                    for (int i = 0; i <= cycleMax; i++)
                    {
                        // Is this column not at the end of the options?
                        if (_listWidths[cycleCurrent].Length > (indexes[cycleCurrent] + 1))
                        {
                            // Does the entry have a tag value?
                            if (_listWidths[cycleCurrent][indexes[cycleCurrent]].Tag >= 0)
                            {
                                // Advance this column one onwards
                                indexes[cycleCurrent]++;

                                // Break out to generate this permutation
                                breakOut = true;
                            }
                        }

                        // Move cycle around one place
                        cycleCurrent--;
                        if (cycleCurrent < 0)
                        {
                            cycleCurrent = cycleMax;
                        }

                        if (breakOut)
                        {
                            break;
                        }
                    }

                    // If no tag based permutation found then turn off processing tags
                    if (!breakOut)
                    {
                        tags = false;
                    }
                }

                // If no perm found yet...
                if (!breakOut)
                {
                    for (int i = 0; i <= cycleMax; i++)
                    {
                        // Is this column not at the end of the options?
                        if (_listWidths[cycleCurrent].Length > (indexes[cycleCurrent] + 1))
                        {
                            // Advance this column one onwards
                            indexes[cycleCurrent]++;

                            // Break out to generate this permutation
                            breakOut = true;
                        }

                        // Move cycle around one place
                        cycleCurrent--;
                        if (cycleCurrent < 0)
                        {
                            cycleCurrent = cycleMax;
                        }

                        if (breakOut)
                        {
                            break;
                        }
                    }
                }
            }while (breakOut);

            // If we have produced nothing then we add a single
            // entry which is the minimum width of a group
            if (retSizes.Count == 0)
            {
                retSizes.Add(new GroupSizeWidth(EMPTY_WIDTH, new ItemSizeWidth[] { }));
            }

            // If adding the extra design time entry
            if (_ribbon.InDesignHelperMode)
            {
                // Get the requested width of the add view
                int viewAddWidth = _viewAddContainer.GetPreferredSize(context).Width;

                // Add it onto each permutation
                foreach (GroupSizeWidth retSize in retSizes)
                {
                    retSize.Width += viewAddWidth;
                }
            }

            return(retSizes.ToArray());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets an array of the allowed possible sizes of the container.
        /// </summary>
        /// <param name="context">Context used to calculate the sizes.</param>
        /// <returns>Array of size values.</returns>
        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 (GroupGallery.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, (GroupGallery.LargeItemCount - GroupGallery.MediumItemCount) / 20);

                    // Process each step from large to medium
                    int itemCount = GroupGallery.LargeItemCount;
                    while (itemCount > GroupGallery.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)GroupGallery.ItemSizeMaximum >= (int)GroupItemSize.Medium) &&
                    ((int)GroupGallery.ItemSizeMinimum <= (int)GroupItemSize.Medium))
                {
                    LastGallery.InternalPreferredItemSize = new Size(GroupGallery.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)GroupGallery.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) });
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Update the group with the provided sizing solution.
 /// </summary>
 /// <param name="size">Value for the container.</param>
 public void SetSolutionSize(ItemSizeWidth size)
 {
     // Update the container definition, which itself will then
     // update all the child items inside the container for us
     _ribbonTriple.ItemSizeCurrent = size.GroupItemSize;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets an array of the allowed possible sizes of the container.
        /// </summary>
        /// <param name="context">Context used to calculate the sizes.</param>
        /// <returns>Array of size values.</returns>
        public ItemSizeWidth[] GetPossibleSizes(ViewLayoutContext context)
        {
            // Sync child elements to the current group items
            SyncChildrenToRibbonGroupItems();

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

            // Are we allowed to be in the large size?
            if (_ribbonTriple.ItemSizeMaximum == GroupItemSize.Large)
            {
                ApplySize(GroupItemSize.Large);
                results.Add(new ItemSizeWidth(GroupItemSize.Large, GetPreferredSize(context).Width));
            }

            // Are we allowed to be in the medium size?
            if (((int)_ribbonTriple.ItemSizeMaximum >= (int)GroupItemSize.Medium) &&
                ((int)_ribbonTriple.ItemSizeMinimum <= (int)GroupItemSize.Medium))
            {
                ApplySize(GroupItemSize.Medium);
                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[0].Width > mediumWidth.Width))
                    {
                        results.Add(mediumWidth);
                    }
                }
            }

            // Are we allowed to be in the small size?
            if (_ribbonTriple.ItemSizeMinimum == GroupItemSize.Small)
            {
                ApplySize(GroupItemSize.Small);
                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 small 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
            ResetSize();

            return(results.ToArray());
        }