Exemple #1
0
        public virtual void Update(Graphics g, RibbonThemaSettingsBase settings)
        {
            this.realGroups.Clear();
            this.realGroups.AddRange(this.Groups);

            if (this.realGroups.Count > 0)
            {
                foreach (var group in this.realGroups)
                {
                    UpdateGroup(group, g, settings);
                }
                int maxHeaderHeight = this.realGroups.Select(group => group.HeaderMinHeight).Max();
                foreach (var group in this.realGroups)
                {
                    group.HeaderHeight = maxHeaderHeight;
                }

                int maxWidth = this.Owner.Container.GetTabPanelBounds().Width;
                while (true)
                {
                    int currentWidth = (this.realGroups.Count + 1) * RibbonGroup.GroupPadding + this.realGroups.Select(group => group.GetWidth(group.WidthLevel)).Sum();
                    if (currentWidth > maxWidth)
                    {
                        RibbonGroup longeastGroup = null;
                        foreach (var group in this.realGroups)
                        {
                            if (group.WidthLevel > 0)
                            {
                                if (longeastGroup == null || group.GetWidth(group.WidthLevel) >= longeastGroup.GetWidth(longeastGroup.WidthLevel))
                                {
                                    longeastGroup = group;
                                }
                            }
                        }
                        if (longeastGroup != null)
                        {
                            longeastGroup.WidthLevel--;
                            continue;
                        }
                    }
                    break;
                }
                while (true)
                {
                    int currentWidth = (this.realGroups.Count + 1) * RibbonGroup.GroupPadding + this.realGroups.Select(group => group.GetWidth(group.WidthLevel)).Sum();
                    if (currentWidth > maxWidth)
                    {
                        int index = -1;
                        for (int i = this.realGroups.Count - 1; i >= 0; i--)
                        {
                            if (this.realGroups[i] == this.Groups[i])
                            {
                                index = i;
                                break;
                            }
                        }
                        if (index != -1)
                        {
                            RibbonGroup group = this.Groups[index].CompactedGroup;
                            this.realGroups[index] = group;
                            UpdateGroup(group, g, settings);
                            continue;
                        }
                    }
                    break;
                }
                {
                    int currentWidth = (this.realGroups.Count + 1) * RibbonGroup.GroupPadding + this.realGroups.Select(group => group.GetWidth(group.WidthLevel)).Sum();
                    if (currentWidth > maxWidth)
                    {
                        if (this.mostCompactGroup == null)
                        {
                            this.mostCompactGroup      = new RibbonButtonGroup();
                            this.mostCompactGroup.Name = this.Owner.Name;
                            foreach (var item in this.realGroups.SelectMany(group => group.Items))
                            {
                                this.mostCompactGroup.BigItems.Add(item);
                            }
                            UpdateGroup(this.mostCompactGroup, g, settings);
                        }
                        this.realGroups.Clear();
                        this.realGroups.Add(this.mostCompactGroup.CompactedGroup);
                        UpdateGroup(mostCompactGroup.CompactedGroup, g, settings);
                    }
                }

                foreach (var group in this.realGroups)
                {
                    group.UpdateWithSizeDecided(g, settings);
                }
            }
        }
 protected override System.Drawing.Size GetSuggestedSize()
 {
     RibbonGroup group = (RibbonGroup)this.RibbonItems;
     return new Size(group.GetWidth(group.WidthLevel), 102);
 }