Beispiel #1
0
        protected Size GetDataSize(PreferredSizeData data, bool getRealSize)
        {
            Size size = data.PreferredSize;

            if (getRealSize && (data.Element.AngleTransform != 0f || data.Element.ScaleTransform.Width != 1f || data.Element.ScaleTransform.Height != 1f))
            {
                size = data.Element.GetBoundingRectangle(size).Size;
            }

            return(size);
        }
Beispiel #2
0
        protected virtual int GetSumWidth(List <PreferredSizeData> list)
        {
            int sumWidth = 0;

            for (int i = 0; i < list.Count; i++)
            {
                PreferredSizeData data = list[i];
                sumWidth += data.PreferredSize.Width;
            }
            return(sumWidth);
        }
Beispiel #3
0
        protected virtual int GetSumHeight(List <PreferredSizeData> list)
        {
            int sumHeight = 0;

            for (int i = 0; i < list.Count; i++)
            {
                PreferredSizeData data = list[i];
                sumHeight += data.PreferredSize.Height;
            }
            return(sumHeight);
        }
Beispiel #4
0
        protected PreferredSizeData GetElementToExpand(List <PreferredSizeData> list, int sumWidth, int availableWidth)
        {
            PreferredSizeData elementToExpand = null;

            for (int i = 2; ; i++)
            {
                PreferredSizeData lastElementToExpand = null;
                bool advanceToNextPriority            = false;
                int  maxSumWidth = 0;

                foreach (PreferredSizeData data in list)
                {
                    ICollapsibleElement collapsibleElement = data.Element as ICollapsibleElement;

                    if (collapsibleElement == null)
                    {
                        continue;
                    }

                    if (i < collapsibleElement.CollapseMaxSteps)
                    {
                        advanceToNextPriority = true;
                    }

                    if (collapsibleElement.CollapseStep != i)
                    {
                        continue;
                    }

                    //if (data.Element.Size.Width == collapsibleElement.ExpandedSize.Width)
                    //	continue;

                    int newSumWidth = sumWidth - data.Element.Size.Width + collapsibleElement.ExpandedSize.Width;
                    if ((newSumWidth < availableWidth) && (newSumWidth > maxSumWidth))
                    {
                        lastElementToExpand = data;
                        maxSumWidth         = newSumWidth;
                    }
                }

                if (lastElementToExpand != null)
                {
                    elementToExpand = lastElementToExpand;
                }

                if (!advanceToNextPriority)
                {
                    break;
                }
            }
            return(elementToExpand);
        }
Beispiel #5
0
        protected virtual int GetMaxHeight(List <PreferredSizeData> list)
        {
            int maxHeight = 0;

            for (int i = 0; i < list.Count; i++)
            {
                PreferredSizeData data = list[i];
                if (maxHeight < data.PreferredSize.Height)
                {
                    maxHeight = data.PreferredSize.Height;
                }
            }
            return(maxHeight);
        }
Beispiel #6
0
        protected virtual int GetMaxWidth(List <PreferredSizeData> list)
        {
            int maxWidth = 0;

            for (int i = 0; i < list.Count; i++)
            {
                PreferredSizeData data = list[i];
                if (maxWidth < data.PreferredSize.Width)
                {
                    maxWidth = data.PreferredSize.Width;
                }
            }
            return(maxWidth);
        }
Beispiel #7
0
        protected virtual void FillPrefSizeList(List <PreferredSizeData> prefSizelist, Rectangle bounds)
        {
            // Split children in 2 lists: with own size and with AutoSizeMode == FitToAvailableSize
            // Only for children with own size will be called GetPreferredSize()
            List <RadElement> fitElementsList = new List <RadElement>();
            int leftTopOffset = 0, rightBottomOffset = 0;

            this.maxIntegralHeight = 0;

            foreach (RadElement child in this.GetChildrenForLayout())
            {
                if (child.IsFitInSize())
                {
                    fitElementsList.Add(child);
                }
                else
                {
                    // The constructor of PreferredSizeData will call GetPreferredSize()
                    PreferredSizeData prefSizedata = new PreferredSizeData(child, bounds);
                    StripPosition     pos          = GetInvariantPosition(child.Alignment);
                    if (pos == StripPosition.First)
                    {
                        leftTopOffset += GetInvariantLength(prefSizedata.PreferredSize, child.Margin);
                    }
                    else if (pos == StripPosition.Last)
                    {
                        rightBottomOffset += GetInvariantLength(prefSizedata.PreferredSize, child.Margin);
                    }
                    prefSizelist.Add(prefSizedata);

                    this.maxIntegralWidth  = Math.Max(this.maxIntegralWidth, prefSizedata.PreferredSize.Width);
                    this.maxIntegralHeight = Math.Max(this.maxIntegralHeight, prefSizedata.PreferredSize.Height);
                }
            }

            // Calculate preferred size for "FitToAvailableSize" elements
            Rectangle proposedRect = CalcProposedBounds(bounds, prefSizelist, leftTopOffset, rightBottomOffset);

            // Call GetPreferredSize() for children that are with AutoSizeMode == FitToAvailableSize
            foreach (RadElement child in fitElementsList)
            {
                //prefSizelist.Add(new PreferredSizeData(child, proposedRect));
                prefSizelist.Add(new PreferredSizeData(child, proposedRect.Size, this.forceFitToSizeElements));
            }
        }
Beispiel #8
0
        protected bool ExpandElements(List <PreferredSizeData> list, Size availableSize)
        {
            if (!ShouldExpandElements(list, availableSize))
            {
                return(false);
            }

            int sumWidth = GetSumWidth(list);

            PreferredSizeData elementToExpand = GetElementToExpand(list, sumWidth, availableSize.Width);

            if (elementToExpand == null)
            {
                return(false);
            }

            bool expandedSuccessfully = ((ICollapsibleElement)elementToExpand.Element).ExpandElement();

            return(expandedSuccessfully);
        }
Beispiel #9
0
        protected PreferredSizeData GetElementToCollapse(List <PreferredSizeData> list)
        {
            for (int i = 1; ; i++)
            {
                PreferredSizeData lastElementToCollapse = null;
                bool advanceToNextPriority = false;

                foreach (PreferredSizeData data in list)
                {
                    ICollapsibleElement collapsibleElement = data.Element as ICollapsibleElement;

                    if (collapsibleElement == null)
                    {
                        continue;
                    }

                    if ((collapsibleElement.CollapseStep == i) && (collapsibleElement.CollapseStep < collapsibleElement.CollapseMaxSteps))
                    {
                        lastElementToCollapse = data;
                    }

                    if (i < collapsibleElement.CollapseMaxSteps)
                    {
                        advanceToNextPriority = true;
                    }
                }

                if (lastElementToCollapse != null)
                {
                    return(lastElementToCollapse);
                }

                if (!advanceToNextPriority)
                {
                    break;
                }
            }
            return(null);
        }
Beispiel #10
0
        protected virtual void SetElementBoundsAuto(Rectangle bounds, PreferredSizeData data, int offset)
        {
            Point location = ItemsOffset;

            if (this.Orientation == Orientation.Horizontal)
            {
                location.X += offset;
            }
            else
            {
                location.Y += offset;
            }

            if (data.Element.AutoSize && data.Element.ElementState == ElementState.Loaded)
            {
                Size prefSize = this.GetElementPreferredSize(bounds, data);
                if (this.IsFitInSize())
                {
                    Size availableSize = Size.Subtract(bounds.Size, this.LayoutEngine.GetBorderSize());
                    availableSize = Size.Subtract(availableSize, data.Element.Margin.Size);

                    prefSize = TelerikLayoutEngine.CheckSize(prefSize, availableSize, Size.Empty);
                }
                Size tempSize = Size.Subtract(this.Size, data.Element.Margin.Size);
                if (this.ForceElementsWidth && prefSize.Width < tempSize.Width)
                {
                    prefSize.Width = tempSize.Width;
                }
                if (this.ForceElementsHeight && prefSize.Height < tempSize.Height)
                {
                    prefSize.Height = tempSize.Height;
                }
                data.Element.SetBounds(new Rectangle(location, prefSize));
            }
            else
            {
                data.Element.Location = location;
            }
        }
Beispiel #11
0
        protected virtual Size GetElementPreferredSize(Rectangle bounds, PreferredSizeData data)
        {
            int width  = 0;
            int height = 0;

            if (this.EqualChildrenWidth)
            {
                if (this.Orientation == Orientation.Horizontal)
                {
                    width = this.maxIntegralWidth;
                }
                else
                {
                    width = bounds.Width;
                }
            }
            else
            {
                width = data.PreferredSize.Width;
            }
            if (this.EqualChildrenHeight)
            {
                if (this.Orientation == Orientation.Horizontal)
                {
                    height = bounds.Height;
                }
                else
                {
                    height = this.maxIntegralHeight;
                }
            }
            else
            {
                height = data.PreferredSize.Height;
            }

            return(new Size(width, height));
        }
Beispiel #12
0
        protected bool CollapseElements(List <PreferredSizeData> list, Size availableSize)
        {
            if (!ShouldCollapseElements(list, availableSize))
            {
                return(false);
            }

            bool collapsedSuccessfully = false;

            while (!collapsedSuccessfully)
            {
                PreferredSizeData elementToCollapse = GetElementToCollapse(list);

                if (elementToCollapse == null)
                {
                    return(false);
                }

                collapsedSuccessfully           = ((ICollapsibleElement)elementToCollapse.Element).CollapseElement(elementToCollapse.PreferredSize);
                elementToCollapse.PreferredSize = elementToCollapse.Element.GetPreferredSize(availableSize);
            }

            return(collapsedSuccessfully);
        }