/// <summary> /// Gets a Dictionary of all control indexs (from Controls) which can be reduced and to which size. /// </summary> /// <remarks> /// To automatically determine which controls can be reduced and to which level, the controls are first grouped into buckets that contain continous controls /// that can be reduced to a small size so that 3 of them can share a row. For each of this buckets, the available RibbonSize is determined of where the /// control is placed inside the bucket. /// </remarks> /// <returns></returns> private Dictionary <int, RibbonSize> GetReducableControlIndexes() { Dictionary <int, RibbonSize> reducable = new Dictionary <int, RibbonSize>(); GroupBucketCollection buckets = GetBuckets(); foreach (GroupBucket b in buckets) { int smallLevel = Math.Max(0, b.Count - 3); int startIndex = Controls.Count == 2 ? 0 : b.Count % 3; for (int i = startIndex; i < b.Count; i++) { RibbonSize minSize = i >= smallLevel ? RibbonSize.Small : RibbonSize.Medium; reducable.Add(b[i], minSize); } } int index = 0; foreach (UIElement e in Controls) { if (e is IRibbonLargeControl) { reducable.Add(index, RibbonSize.Small); } index++; } return(reducable); }
GroupBucketCollection GetBuckets() { GroupBucketCollection buckets = new GroupBucketCollection(); GroupBucket bucket = new GroupBucket(); buckets.Add(bucket); int index = 0; foreach (UIElement e in Controls) { bool canBeSmall = CanControlBeSmall(e); if (!canBeSmall && bucket.Count > 0) { bucket = new GroupBucket(); buckets.Add(bucket); } else { bucket.Add(index); } index++; } return(buckets); }