Example #1
0
        /// <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);
        }
Example #2
0
        /// <summary>
        /// Change the RibbonSize for every IRibbonControl inside this group.
        /// </summary>
        private void ChangeControlSizes()
        {
            int  level     = ReductionLevel;
            int  maxLevels = GetMaxLevel();
            bool minimized = level >= maxLevels;

            IsMinimized = minimized;
            if (minimized)
            {
                level = 0;
            }

            for (int i = 0; i < Controls.Count; i++)
            {
                UIElement      e       = Controls[i];
                IRibbonGallery gallery = e as IRibbonGallery;
                if (gallery != null)
                {
                    int columns = GetGalleryColumns(e, level, maxLevels);
                    gallery.Columns     = columns;
                    gallery.IsCollapsed = columns == 0;
                    gallery.SetDropDownColumns(GetGalleryColumns(e, 0, maxLevels));
                }
                else
                {
                    if (e is IRibbonControl)
                    {
                        RibbonSize size = GetControlSize(e, level, i);
                        RibbonBar.SetSize(e, size);
                    }
                }
            }
            InvalidateMeasure();
            UpdateLayout();
        }
Example #3
0
 private bool CanControlBeSmall(UIElement e)
 {
     if ((e is IRibbonControl) && !(e is IRibbonLargeControl))
     {
         RibbonSize min = RibbonBar.GetMinSize(e);
         return(min < RibbonSize.Large);
     }
     return(e.DesiredSize.Height <= InternalGroupPanel.MaxSmallHeight);
 }
Example #4
0
        private Size ArrangeOrMeasure(bool arrange)
        {
            double left     = 0;
            int    rowIndex = 0;
            int    maxRows  = 3;

            List <UIElement> rowElements = new List <UIElement>(maxRows);

            foreach (UIElement e in Children)
            {
                if (e.Visibility != Visibility.Visible)
                {
                    continue;
                }
                IRibbonControl ribbonControl = e as IRibbonControl;
                Size           dsize         = e.DesiredSize;
                if (dsize.Height > smallHeight)
                {
                    if (rowIndex > 0)
                    {
                        left    += ArrangeRow(rowElements, left, arrange);
                        rowIndex = 0;
                    }
                    if (arrange)
                    {
                        Size   size = e.DesiredSize;
                        double h    = Math.Max(smallHeight, size.Height);
                        e.Arrange(new Rect(left, 0, size.Width, h));
                    }
                    left += e.DesiredSize.Width;
                }
                else
                {
                    RibbonSize size = RibbonBar.GetSize(e);
                    if (size != RibbonSize.Minimized)
                    {
                        rowElements.Add(e);
                        if (++rowIndex == maxRows)
                        {
                            left    += ArrangeRow(rowElements, left, arrange);
                            rowIndex = 0;
                        }
                    }
                }
            }
            left += ArrangeRow(rowElements, left, arrange);

            left = Math.Max(32, left);
            return(new Size(left, smallHeight * 3));
        }
Example #5
0
        /// <summary>
        /// Gets the RibbonSize for a control for a specific level.
        /// </summary>
        /// <param name="control">The control for which to retreive a RibbonSize.</param>
        /// <param name="level">The reduction Level (0=large, 2=medium,3=small,4=minimized,...).</param>
        /// <param name="index">The index of the control in the group.</param>
        /// <returns>The RibbonSize for the control.</returns>
        RibbonSize GetControlSize(DependencyObject control, int level, int index)
        {
            RibbonSizeCollection reductions = RibbonBar.GetReduction(control);

            if (reductions != null && reductions.Count > 0)
            {
                level = Math.Max(0, Math.Min(level, reductions.Count - 1));
                return(reductions[level]);
            }
            RibbonSize size;

            switch (level)
            {
            case 0: size = GetDefaultSizeForLevel0(index); break;

            case 1: size = GetDefaultSizeForLevel1(index); break;

            case 2: size = GetDefaultSizeForLevel2(index); break;

            default: size = RibbonSize.Minimized; break;
            }

            RibbonSize min = RibbonBar.GetMinSize(control);
            RibbonSize max = RibbonBar.GetMaxSize(control);

            if (size < min)
            {
                size = min;
            }
            if (size > max)
            {
                size = max;
            }

            return(size);
        }
 /// <summary>
 /// Sets the maximum size for a IRibbonControl.
 /// This is an attached dependency property.
 /// </summary>        
 public static void SetMaxSize(DependencyObject obj, RibbonSize value)
 {
     obj.SetValue(MaxSizeProperty, value);
 }