private void ArrangeStretchedElements(
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered,
            SizeF finalSize)
        {
            float num1  = this.Orientation == Orientation.Horizontal ? finalSize.Width : finalSize.Height;
            int   count = elementsOrdered.Count;

            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo1 = index - 1 >= 0 ? elementsOrdered[index - 1] : (RadCommandBarStripPanelLayoutInfo)null;
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo2 = elementsOrdered[index];
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo3 = index + 1 < count ? elementsOrdered[index + 1] : (RadCommandBarStripPanelLayoutInfo)null;
                if (stripPanelLayoutInfo2.commandBarStripElement.VisibleInCommandBar && stripPanelLayoutInfo2.commandBarStripElement.Visibility != ElementVisibility.Collapsed && (this.Orientation == Orientation.Horizontal && stripPanelLayoutInfo2.commandBarStripElement.StretchHorizontally || this.Orientation == Orientation.Vertical && stripPanelLayoutInfo2.commandBarStripElement.StretchVertically))
                {
                    float num2 = num1;
                    if (stripPanelLayoutInfo3 != null)
                    {
                        num2 = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo3.ArrangeRectangle.X : stripPanelLayoutInfo3.ArrangeRectangle.Y;
                    }
                    float num3 = 0.0f;
                    if (stripPanelLayoutInfo1 != null)
                    {
                        num3 = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo1.ArrangeRectangle.X + stripPanelLayoutInfo1.ArrangeRectangle.Width : stripPanelLayoutInfo1.ArrangeRectangle.Y + stripPanelLayoutInfo1.ArrangeRectangle.Height;
                    }
                    float  num4   = num2 - num3;
                    SizeF  sizeF  = this.Orientation == Orientation.Horizontal ? new SizeF(num4, finalSize.Height) : new SizeF(finalSize.Width, num4);
                    PointF pointF = this.Orientation == Orientation.Horizontal ? new PointF(num3, stripPanelLayoutInfo2.ArrangeRectangle.Y) : new PointF(stripPanelLayoutInfo2.ArrangeRectangle.X, num3);
                    stripPanelLayoutInfo2.ArrangeRectangle.Location = pointF;
                    stripPanelLayoutInfo2.ArrangeRectangle.Size     = sizeF;
                }
            }
        }
        private void ArrangeElementsWithFreeSpace(
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered,
            SizeF finalSize)
        {
            float num1  = this.Orientation == Orientation.Horizontal ? finalSize.Width : finalSize.Height;
            int   count = elementsOrdered.Count;
            float num2  = 0.0f;

            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo = elementsOrdered[index];
                PointF desiredLocation = stripPanelLayoutInfo.DesiredLocation;
                float  num3            = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Width : stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Height;
                float  num4            = Math.Max(this.Orientation == Orientation.Horizontal ? desiredLocation.X : desiredLocation.Y, num2);
                if ((double)stripPanelLayoutInfo.IntersectionSpaceToEnd > 0.0)
                {
                    float num5 = Math.Min(num4 - num2, stripPanelLayoutInfo.IntersectionSpaceToEnd);
                    num4 = Math.Max(num2, num4 - num5);
                }
                float num6 = num1 - num4 - stripPanelLayoutInfo.DesiredSpaceToEnd;
                if ((double)num6 < 0.0)
                {
                    num4 += num6;
                }
                num2 = num4 + num3;
                PointF location = this.Orientation == Orientation.Horizontal ? new PointF(num4, 0.0f) : new PointF(0.0f, num4);
                SizeF  size     = this.Orientation == Orientation.Horizontal ? new SizeF(num3, finalSize.Height) : new SizeF(finalSize.Width, num3);
                stripPanelLayoutInfo.ArrangeRectangle = new RectangleF(location, size);
            }
        }
        private void ArrangeElementsWithoutFreeSpace(
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered,
            SizeF finalSize)
        {
            int   count = elementsOrdered.Count;
            float num1  = 0.0f;
            float num2  = this.Orientation == Orientation.Horizontal ? finalSize.Width : finalSize.Height;

            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo = elementsOrdered[index];
                float  num3     = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Width : stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Height;
                PointF location = this.Orientation == Orientation.Horizontal ? new PointF(num1, 0.0f) : new PointF(0.0f, num1);
                SizeF  size     = this.Orientation == Orientation.Horizontal ? new SizeF(num3, finalSize.Height) : new SizeF(finalSize.Width, num3);
                if (index + 1 == count)
                {
                    if (this.Orientation == Orientation.Horizontal)
                    {
                        size.Width = num2 - num1;
                    }
                    else
                    {
                        size.Height = num2 - num1;
                    }
                }
                stripPanelLayoutInfo.ArrangeRectangle = new RectangleF(location, size);
                num1 += num3;
            }
        }
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            int barsCount = this.Children.Count;
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered = null;

            if (this.orientation == Orientation.Horizontal)
            {
                elementsOrdered = this.GetChildrenOrdered(CompareCommandBarStripElementByX, SizeF.Empty, false);
            }
            else
            {
                elementsOrdered = this.GetChildrenOrdered(CompareCommandBarStripElementByY, SizeF.Empty, false);
            }

            this.ArrangeElements(elementsOrdered, finalSize);

            for (int i = 0; i < barsCount; ++i)
            {
                RadCommandBarStripPanelLayoutInfo layoutInfo = elementsOrdered[i];
                this.AdjustDesiredLocationIfEmpty(layoutInfo);
                if (this.RightToLeft && this.Orientation == System.Windows.Forms.Orientation.Horizontal)
                {
                    layoutInfo.ArrangeRectangle.X = finalSize.Width - layoutInfo.ArrangeRectangle.X - layoutInfo.ArrangeRectangle.Width;
                }
                layoutInfo.commandBarStripElement.Arrange(layoutInfo.ArrangeRectangle);
            }

            return(finalSize);
        }
        private SizeF MeasureElementsWithoutFreeSpace(
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered,
            SizeF availableSize)
        {
            int   count = this.Strips.Count;
            float num1  = this.Orientation == Orientation.Horizontal ? availableSize.Width : availableSize.Height;
            SizeF empty = SizeF.Empty;
            float num2  = 0.0f;

            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo1 = elementsOrdered[index];
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo2 = index + 1 < count ? elementsOrdered[index + 1] : (RadCommandBarStripPanelLayoutInfo)null;
                if (!stripPanelLayoutInfo1.commandBarStripElement.VisibleInCommandBar && this.Site == null)
                {
                    stripPanelLayoutInfo1.commandBarStripElement.Measure(SizeF.Empty);
                }
                else
                {
                    float num3 = num1;
                    if (stripPanelLayoutInfo2 != null)
                    {
                        num3 = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo2.DesiredLocation.X : stripPanelLayoutInfo2.DesiredLocation.Y;
                    }
                    float num4   = num1 - num2;
                    float val1_1 = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo1.ExpectedDesiredSize.Width : stripPanelLayoutInfo1.ExpectedDesiredSize.Height;
                    float num5   = stripPanelLayoutInfo1.DesiredSpaceToEnd - val1_1;
                    float val2_1 = this.Orientation == Orientation.Horizontal ? (float)stripPanelLayoutInfo1.commandBarStripElement.MinSize.Width : (float)stripPanelLayoutInfo1.commandBarStripElement.MinSize.Height;
                    float val1_2 = Math.Min(val1_1, num3 - num2);
                    if ((double)num5 < (double)num4 - (double)val1_2)
                    {
                        float val2_2 = Math.Min(val1_1, val1_2 + num4 - val1_2 - num5);
                        val1_2 = Math.Max(val1_2, val2_2);
                    }
                    if (stripPanelLayoutInfo2 != null && (double)stripPanelLayoutInfo2.MinSpaceToEnd > (double)num4 - (double)val1_2)
                    {
                        val1_2 = Math.Min(val1_2, val1_2 - (stripPanelLayoutInfo2.MinSpaceToEnd - num4 + val1_2));
                    }
                    float num6           = Math.Max(val1_2, val2_1);
                    SizeF availableSize1 = this.Orientation == Orientation.Horizontal ? new SizeF(num6, availableSize.Height) : new SizeF(availableSize.Width, num6);
                    stripPanelLayoutInfo1.commandBarStripElement.Measure(availableSize1);
                    float num7 = this.Orientation == Orientation.Horizontal ? stripPanelLayoutInfo1.commandBarStripElement.DesiredSize.Width : stripPanelLayoutInfo1.commandBarStripElement.DesiredSize.Height;
                    num2 += num7;
                    if (this.Orientation == Orientation.Horizontal)
                    {
                        empty.Width += num7;
                        empty.Height = Math.Max(empty.Height, stripPanelLayoutInfo1.commandBarStripElement.DesiredSize.Height);
                    }
                    else
                    {
                        empty.Height += num7;
                        empty.Width   = Math.Max(empty.Width, stripPanelLayoutInfo1.commandBarStripElement.DesiredSize.Width);
                    }
                }
            }
            return(empty);
        }
 private static int CompareCommandBarStripElementByY(
     RadCommandBarStripPanelLayoutInfo a,
     RadCommandBarStripPanelLayoutInfo b)
 {
     if ((double)a.DesiredLocation.Y > (double)b.DesiredLocation.Y)
     {
         return(1);
     }
     return((double)a.DesiredLocation.Y < (double)b.DesiredLocation.Y ? -1 : 0);
 }
        private static int CompareCommandBarStripElementByY(RadCommandBarStripPanelLayoutInfo a, RadCommandBarStripPanelLayoutInfo b)
        {
            if (a.DesiredLocation.Y > b.DesiredLocation.Y)
            {
                return(1);
            }

            if (a.DesiredLocation.Y < b.DesiredLocation.Y)
            {
                return(-1);
            }

            return(0);
        }
        private void ArrangeStretchedElements(List <RadCommandBarStripPanelLayoutInfo> elementsOrdered, SizeF finalSize)
        {
            float availableSpace = (this.Orientation == Orientation.Horizontal) ? finalSize.Width : finalSize.Height;
            int   barsCount      = elementsOrdered.Count;

            for (int i = 0; i < barsCount; ++i)
            {
                RadCommandBarStripPanelLayoutInfo previousElement = (i - 1 >= 0) ? elementsOrdered[i - 1] : null;
                RadCommandBarStripPanelLayoutInfo currentElement  = elementsOrdered[i];
                RadCommandBarStripPanelLayoutInfo nextElement     = (i + 1 < barsCount) ? elementsOrdered[i + 1] : null;

                if (!currentElement.commandBarStripElement.VisibleInCommandBar ||
                    currentElement.commandBarStripElement.Visibility == ElementVisibility.Collapsed)
                {
                    continue;
                }

                if ((this.orientation == System.Windows.Forms.Orientation.Horizontal && currentElement.commandBarStripElement.StretchHorizontally) ||
                    (this.orientation == System.Windows.Forms.Orientation.Vertical && currentElement.commandBarStripElement.StretchVertically))
                {
                    float nextElementPlace = availableSpace;
                    if (nextElement != null)
                    {
                        nextElementPlace = (this.orientation == Orientation.Horizontal) ?
                                           nextElement.ArrangeRectangle.X :
                                           nextElement.ArrangeRectangle.Y;
                    }

                    float previousElementPlace = 0;
                    if (previousElement != null)
                    {
                        previousElementPlace = (this.orientation == Orientation.Horizontal) ?
                                               previousElement.ArrangeRectangle.X + previousElement.ArrangeRectangle.Width :
                                               previousElement.ArrangeRectangle.Y + previousElement.ArrangeRectangle.Height;
                    }

                    float desiredSpace = nextElementPlace - previousElementPlace;
                    SizeF arrangeSize  = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                         new SizeF(desiredSpace, finalSize.Height) :
                                         new SizeF(finalSize.Width, desiredSpace);
                    PointF arrangePoint = (this.orientation == Orientation.Horizontal) ?
                                          new PointF(previousElementPlace, currentElement.ArrangeRectangle.Y) :
                                          new PointF(currentElement.ArrangeRectangle.X, previousElementPlace);

                    currentElement.ArrangeRectangle.Location = arrangePoint;
                    currentElement.ArrangeRectangle.Size     = arrangeSize;
                }
            }
        }
        private void ArrangeElementsWithFreeSpace(List <RadCommandBarStripPanelLayoutInfo> elementsOrdered, SizeF finalSize)
        {
            float availableSpace = (this.Orientation == Orientation.Horizontal) ? finalSize.Width : finalSize.Height;
            int   barsCount      = elementsOrdered.Count;
            float sumOfSpace     = 0;

            for (int i = 0; i < barsCount; ++i)
            {
                RadCommandBarStripPanelLayoutInfo currentElement = elementsOrdered[i];

                PointF desiredLocation = currentElement.DesiredLocation;
                float  desiredSpace    = (this.orientation == Orientation.Horizontal) ?
                                         currentElement.commandBarStripElement.DesiredSize.Width :
                                         currentElement.commandBarStripElement.DesiredSize.Height;

                float arrangedPlace = (this.orientation == Orientation.Horizontal) ?
                                      desiredLocation.X :
                                      desiredLocation.Y;

                arrangedPlace = Math.Max(arrangedPlace, sumOfSpace);

                if (currentElement.IntersectionSpaceToEnd > 0)
                {
                    float freeSpace = arrangedPlace - sumOfSpace;
                    float offset    = Math.Min(freeSpace, currentElement.IntersectionSpaceToEnd);
                    arrangedPlace = Math.Max(sumOfSpace, arrangedPlace - offset);
                }

                float spaceToEnd = availableSpace - arrangedPlace;
                float spaceLeft  = spaceToEnd - currentElement.DesiredSpaceToEnd;
                if (spaceLeft < 0)
                {
                    arrangedPlace += spaceLeft;
                }

                sumOfSpace = arrangedPlace + desiredSpace;

                PointF arrangePoint = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                      new PointF(arrangedPlace, 0) :
                                      new PointF(0, arrangedPlace);

                SizeF arrangeSize = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                    new SizeF(desiredSpace, finalSize.Height) :
                                    new SizeF(finalSize.Width, desiredSpace);

                currentElement.ArrangeRectangle = new RectangleF(arrangePoint, arrangeSize);
            }
        }
 private void AdjustDesiredLocationIfEmpty(RadCommandBarStripPanelLayoutInfo layoutInfo)
 {
     if (this.Site != null)
     {
         return;
     }
     if ((double)layoutInfo.commandBarStripElement.DesiredLocation.X < 0.0 || (double)layoutInfo.commandBarStripElement.DesiredLocation.Y < 0.0 || (float.IsInfinity(layoutInfo.commandBarStripElement.DesiredLocation.X) || float.IsInfinity(layoutInfo.commandBarStripElement.DesiredLocation.Y)))
     {
         layoutInfo.commandBarStripElement.cachedDesiredLocation = new PointF(-1f, -1f);
     }
     if (!(layoutInfo.commandBarStripElement.DesiredLocation == new PointF(-1f, -1f)) && ((double)layoutInfo.commandBarStripElement.DesiredLocation.X != 0.0 || this.Orientation != Orientation.Horizontal) && ((double)layoutInfo.commandBarStripElement.DesiredLocation.Y != 0.0 || this.Orientation != Orientation.Vertical))
     {
         return;
     }
     layoutInfo.commandBarStripElement.cachedDesiredLocation = layoutInfo.ArrangeRectangle.Location;
 }
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            int count = this.Strips.Count;
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered = this.Orientation != Orientation.Horizontal ? this.GetChildrenOrdered(new Comparison <RadCommandBarStripPanelLayoutInfo>(CommandBarRowElement.CompareCommandBarStripElementByY), SizeF.Empty, false) : this.GetChildrenOrdered(new Comparison <RadCommandBarStripPanelLayoutInfo>(CommandBarRowElement.CompareCommandBarStripElementByX), SizeF.Empty, false);

            this.ArrangeElements(elementsOrdered, finalSize);
            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo layoutInfo = elementsOrdered[index];
                this.AdjustDesiredLocationIfEmpty(layoutInfo);
                if (this.RightToLeft && this.Orientation == Orientation.Horizontal)
                {
                    layoutInfo.ArrangeRectangle.X = finalSize.Width - layoutInfo.ArrangeRectangle.X - layoutInfo.ArrangeRectangle.Width;
                }
                layoutInfo.commandBarStripElement.Arrange(layoutInfo.ArrangeRectangle);
            }
            return(finalSize);
        }
        private void AdjustDesiredLocationIfEmpty(RadCommandBarStripPanelLayoutInfo layoutInfo)
        {
            if (this.Site != null)
            {
                return;
            }

            if (layoutInfo.commandBarStripElement.DesiredLocation.X < 0 || layoutInfo.commandBarStripElement.DesiredLocation.Y < 0 ||
                float.IsInfinity(layoutInfo.commandBarStripElement.DesiredLocation.X) || float.IsInfinity(layoutInfo.commandBarStripElement.DesiredLocation.Y))
            {
                layoutInfo.commandBarStripElement.cachedDesiredLocation = new PointF(NOT_SET, NOT_SET);
            }

            if (layoutInfo.commandBarStripElement.DesiredLocation == new PointF(NOT_SET, NOT_SET) ||
                (layoutInfo.commandBarStripElement.DesiredLocation.X == 0 && this.orientation == Orientation.Horizontal) ||
                (layoutInfo.commandBarStripElement.DesiredLocation.Y == 0 && this.orientation == Orientation.Vertical))
            {
                layoutInfo.commandBarStripElement.cachedDesiredLocation = layoutInfo.ArrangeRectangle.Location;
            }
        }
        private void StableSort(List <RadCommandBarStripPanelLayoutInfo> elements, Comparison <RadCommandBarStripPanelLayoutInfo> comparison)
        {
            int  elementsCount = elements.Count - 1;
            bool madeSwaps     = false;

            do
            {
                madeSwaps = false;

                for (int i = 0; i < elementsCount; i++)
                {
                    if (comparison.Invoke(elements[i], elements[i + 1]) > 0)
                    {
                        madeSwaps = true;
                        RadCommandBarStripPanelLayoutInfo temp = elements[i];
                        elements[i]     = elements[i + 1];
                        elements[i + 1] = temp;
                    }
                }
            }while (madeSwaps);
        }
        private void StableSort(
            List <RadCommandBarStripPanelLayoutInfo> elements,
            Comparison <RadCommandBarStripPanelLayoutInfo> comparison)
        {
            int  num = elements.Count - 1;
            bool flag;

            do
            {
                flag = false;
                for (int index = 0; index < num; ++index)
                {
                    if (comparison(elements[index], elements[index + 1]) > 0)
                    {
                        flag = true;
                        RadCommandBarStripPanelLayoutInfo element = elements[index];
                        elements[index]     = elements[index + 1];
                        elements[index + 1] = element;
                    }
                }
            }while (flag);
        }
        private SizeF MeasureElementWithFreeSpace(List <RadCommandBarStripPanelLayoutInfo> elementsOrdered, SizeF availableSize)
        {
            int   barsCount    = this.strips.Count;
            SizeF measuredSize = SizeF.Empty;

            for (int i = 0; i < barsCount; i++)
            {
                RadCommandBarStripPanelLayoutInfo currentElement = elementsOrdered[i];
                if (!currentElement.commandBarStripElement.VisibleInCommandBar && this.Site == null)
                {
                    currentElement.commandBarStripElement.Measure(SizeF.Empty);
                }
                else
                {
                    currentElement.commandBarStripElement.Measure(availableSize);
                }

                measuredSize.Width  = Math.Max(measuredSize.Width, currentElement.commandBarStripElement.DesiredSize.Width);
                measuredSize.Height = Math.Max(measuredSize.Height, currentElement.commandBarStripElement.DesiredSize.Height);
            }

            return(measuredSize);
        }
        private SizeF MeasureElementWithFreeSpace(
            List <RadCommandBarStripPanelLayoutInfo> elementsOrdered,
            SizeF availableSize)
        {
            int   count = this.Strips.Count;
            SizeF empty = SizeF.Empty;

            for (int index = 0; index < count; ++index)
            {
                RadCommandBarStripPanelLayoutInfo stripPanelLayoutInfo = elementsOrdered[index];
                if (!stripPanelLayoutInfo.commandBarStripElement.VisibleInCommandBar && this.Site == null)
                {
                    stripPanelLayoutInfo.commandBarStripElement.Measure(SizeF.Empty);
                }
                else
                {
                    stripPanelLayoutInfo.commandBarStripElement.Measure(availableSize);
                }
                empty.Width  = Math.Max(empty.Width, stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Width);
                empty.Height = Math.Max(empty.Height, stripPanelLayoutInfo.commandBarStripElement.DesiredSize.Height);
            }
            return(empty);
        }
        private void ArrangeElementsWithoutFreeSpace(List <RadCommandBarStripPanelLayoutInfo> elementsOrdered, SizeF finalSize)
        {
            int   barsCount      = elementsOrdered.Count;
            float sumOfSpace     = 0;
            float availableSpace = (this.Orientation == Orientation.Horizontal) ? finalSize.Width : finalSize.Height;

            for (int i = 0; i < barsCount; ++i)
            {
                RadCommandBarStripPanelLayoutInfo currentElement = elementsOrdered[i];

                float desiredSpace = (this.orientation == Orientation.Horizontal) ?
                                     currentElement.commandBarStripElement.DesiredSize.Width :
                                     currentElement.commandBarStripElement.DesiredSize.Height;

                PointF arrangePoint = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                      new PointF(sumOfSpace, 0) : new PointF(0, sumOfSpace);
                SizeF arrangeSize = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                    new SizeF(desiredSpace, finalSize.Height) :
                                    new SizeF(finalSize.Width, desiredSpace);

                if (i + 1 == barsCount)
                {
                    if (this.orientation == System.Windows.Forms.Orientation.Horizontal)
                    {
                        arrangeSize.Width = availableSpace - sumOfSpace;
                    }
                    else
                    {
                        arrangeSize.Height = availableSpace - sumOfSpace;
                    }
                }

                currentElement.ArrangeRectangle = new RectangleF(arrangePoint, arrangeSize);

                sumOfSpace += desiredSpace;
            }
        }
        private SizeF MeasureElementsWithoutFreeSpace(List <RadCommandBarStripPanelLayoutInfo> elementsOrdered, SizeF availableSize)
        {
            int   barsCount           = this.strips.Count;
            float totalAvailableSpace = (this.orientation == Orientation.Horizontal) ? availableSize.Width : availableSize.Height;
            SizeF measuredSize        = SizeF.Empty;
            float currentLocation     = 0;

            for (int i = 0; i < barsCount; i++)
            {
                RadCommandBarStripPanelLayoutInfo currentElement = elementsOrdered[i];
                RadCommandBarStripPanelLayoutInfo nextElement    = (i + 1 < barsCount) ? elementsOrdered[i + 1] : null;

                if (!currentElement.commandBarStripElement.VisibleInCommandBar && this.Site == null)
                {
                    currentElement.commandBarStripElement.Measure(SizeF.Empty);
                    continue;
                }

                float nextLocation = totalAvailableSpace;

                if (nextElement != null)
                {
                    nextLocation = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                   nextElement.DesiredLocation.X :
                                   nextElement.DesiredLocation.Y;
                }

                float availableSpaceToEnd = (totalAvailableSpace - currentLocation);
                float desiredSpace        = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                            currentElement.ExpectedDesiredSize.Width :
                                            currentElement.ExpectedDesiredSize.Height;
                float desiredSpaceToEnd = currentElement.DesiredSpaceToEnd - desiredSpace;
                float minSpace          = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                          currentElement.commandBarStripElement.MinSize.Width :
                                          currentElement.commandBarStripElement.MinSize.Height;
                float arrangeSpace = Math.Min(desiredSpace, nextLocation - currentLocation);

                if (desiredSpaceToEnd < availableSpaceToEnd - arrangeSpace)
                {
                    float shouldGrow = Math.Min(desiredSpace, arrangeSpace + availableSpaceToEnd - arrangeSpace - desiredSpaceToEnd);
                    arrangeSpace = Math.Max(arrangeSpace, shouldGrow);
                }

                if (nextElement != null && nextElement.MinSpaceToEnd > availableSpaceToEnd - arrangeSpace)
                {
                    arrangeSpace = Math.Min(arrangeSpace, arrangeSpace - (nextElement.MinSpaceToEnd - availableSpaceToEnd + arrangeSpace));
                }

                arrangeSpace = Math.Max(arrangeSpace, minSpace);
                SizeF measureSize = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                    new SizeF(arrangeSpace, availableSize.Height) :
                                    new SizeF(availableSize.Width, arrangeSpace);

                currentElement.commandBarStripElement.Measure(measureSize);

                float actualDesiredSpace = (this.orientation == System.Windows.Forms.Orientation.Horizontal) ?
                                           currentElement.commandBarStripElement.DesiredSize.Width :
                                           currentElement.commandBarStripElement.DesiredSize.Height;
                currentLocation += actualDesiredSpace;

                if (this.orientation == System.Windows.Forms.Orientation.Horizontal)
                {
                    measuredSize.Width += actualDesiredSpace;
                    measuredSize.Height = Math.Max(measuredSize.Height, currentElement.commandBarStripElement.DesiredSize.Height);
                }
                else
                {
                    measuredSize.Height += actualDesiredSpace;
                    measuredSize.Width   = Math.Max(measuredSize.Width, currentElement.commandBarStripElement.DesiredSize.Width);
                }
            }

            return(measuredSize);
        }