GetPreferredSize() public méthode

public GetPreferredSize ( Size constrainingSize ) : Size
constrainingSize System.Drawing.Size
Résultat System.Drawing.Size
Exemple #1
0
        private void CalculatePlacementsVertical()
        {
            this.ResetItemPlacements();
            System.Windows.Forms.ToolStrip toolStrip = this.ToolStrip;
            int num = 0;

            if (this.ToolStrip.CanOverflow)
            {
                this.ForwardsWalkingIndex = 0;
                while (this.ForwardsWalkingIndex < this.ToolStrip.Items.Count)
                {
                    ToolStripItem item = toolStrip.Items[this.ForwardsWalkingIndex];
                    if (((IArrangedElement)item).ParticipatesInLayout)
                    {
                        if (item.Overflow == ToolStripItemOverflow.Always)
                        {
                            this.OverflowRequired = true;
                        }
                        if ((item.Overflow != ToolStripItemOverflow.Always) && (item.Placement == ToolStripItemPlacement.None))
                        {
                            Size size = item.AutoSize ? item.GetPreferredSize(this.displayRectangle.Size) : item.Size;
                            int  num2 = this.OverflowRequired ? this.OverflowButtonSize.Height : 0;
                            num += size.Height + item.Margin.Vertical;
                            if (num > (this.displayRectangle.Height - num2))
                            {
                                int num3 = this.SendNextItemToOverflow(num - this.displayRectangle.Height, false);
                                num -= num3;
                            }
                        }
                    }
                    this.ForwardsWalkingIndex++;
                }
            }
            this.PlaceItems();
        }
Exemple #2
0
        /// <summary>
        /// This method will mark whether items should be placed in the overflow or on the main ToolStrip.
        /// </summary>
        private void CalculatePlacementsHorizontal()
        {
            ResetItemPlacements();

            ToolStrip toolStrip    = ToolStrip;
            int       currentWidth = 0;

            if (ToolStrip.CanOverflow)
            {
                // determine the locations of all the items.
                for (ForwardsWalkingIndex = 0; ForwardsWalkingIndex < toolStrip.Items.Count; ForwardsWalkingIndex++)
                {
                    ToolStripItem item = toolStrip.Items[ForwardsWalkingIndex];

                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // if we have something set to overflow always we need to show an overflow button
                    if (item.Overflow == ToolStripItemOverflow.Always)
                    {
#if DEBUG
                        if (DebugLayoutTraceSwitch.TraceVerbose)
                        {
                            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "OverflowRequired - item set to alaways overflow: {0} ", item));
                        }
#endif
                        OverflowRequired = true;
                    }

                    if (item.Overflow != ToolStripItemOverflow.Always && item.Placement == ToolStripItemPlacement.None)
                    {
                        // since we havent parented the item yet - the auto size wont have reset the size yet.
                        Size itemSize = item.AutoSize ? item.GetPreferredSize(displayRectangle.Size) : item.Size;

                        currentWidth += itemSize.Width + item.Margin.Horizontal;

                        int overflowWidth = (OverflowRequired) ? OverflowButtonSize.Width : 0;

                        if (currentWidth > displayRectangle.Width - overflowWidth)
                        {
#if DEBUG
                            if (DebugLayoutTraceSwitch.TraceVerbose)
                            {
                                Debug.WriteLine("SendNextItemToOverflow to fres space for " + item.ToString());
                            }
#endif
                            int spaceRecovered = SendNextItemToOverflow((currentWidth + overflowWidth) - displayRectangle.Width, true);

                            currentWidth -= spaceRecovered;
                        }
                    }
                }
            }

            PlaceItems();
        }
Exemple #3
0
        private int SendNextItemToOverflow(int spaceNeeded, bool horizontal)
        {
            int num = 0;
            int backwardsWalkingIndex = this.BackwardsWalkingIndex;

            this.BackwardsWalkingIndex = (backwardsWalkingIndex == -1) ? (this.ToolStrip.Items.Count - 1) : (backwardsWalkingIndex - 1);
            while (this.BackwardsWalkingIndex >= 0)
            {
                ToolStripItem item = this.ToolStrip.Items[this.BackwardsWalkingIndex];
                if (((IArrangedElement)item).ParticipatesInLayout)
                {
                    Padding margin = item.Margin;
                    if ((item.Overflow == ToolStripItemOverflow.AsNeeded) && (item.Placement != ToolStripItemPlacement.Overflow))
                    {
                        Size size = item.AutoSize ? item.GetPreferredSize(this.displayRectangle.Size) : item.Size;
                        if (this.BackwardsWalkingIndex <= this.ForwardsWalkingIndex)
                        {
                            num += horizontal ? (size.Width + margin.Horizontal) : (size.Height + margin.Vertical);
                        }
                        item.SetPlacement(ToolStripItemPlacement.Overflow);
                        if (!this.OverflowRequired)
                        {
                            spaceNeeded          += horizontal ? this.OverflowButtonSize.Width : this.OverflowButtonSize.Height;
                            this.OverflowRequired = true;
                        }
                        this.OverflowSpace += horizontal ? (size.Width + margin.Horizontal) : (size.Height + margin.Vertical);
                    }
                    if (num > spaceNeeded)
                    {
                        return(num);
                    }
                }
                this.BackwardsWalkingIndex--;
            }
            return(num);
        }
Exemple #4
0
        /// <summary>
        /// This method is called when we are walking through the item collection and we have realized that we
        /// need to free up "X" amount of space to be able to fit an item onto the ToolStrip.
        /// </summary>
        private int SendNextItemToOverflow(int spaceNeeded, bool horizontal)
        {
#if DEBUG
            if (DebugLayoutTraceSwitch.TraceVerbose)
            {
                Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "SendNextItemToOverflow attempting to free {0}", spaceNeeded));
            }
#endif
            Debug.Indent();

            int freedSpace = 0;
            int backIndex  = BackwardsWalkingIndex;

            BackwardsWalkingIndex = (backIndex == -1) ? ToolStrip.Items.Count - 1 : backIndex - 1;
            for (; BackwardsWalkingIndex >= 0; BackwardsWalkingIndex--)
            {
                ToolStripItem item = ToolStrip.Items[BackwardsWalkingIndex];
                if (!((IArrangedElement)item).ParticipatesInLayout)
                {
                    // skip over items not participating in layout.  E.G. not visible items
                    continue;
                }

                Padding itemMargin = item.Margin;

                // look for items that say they're ok for overflowing.
                // not looking at ones that Always overflow - as the forward walker already skips these.
                if (item.Overflow == ToolStripItemOverflow.AsNeeded && item.Placement != ToolStripItemPlacement.Overflow)
                {
#if DEBUG
                    if (DebugLayoutTraceSwitch.TraceVerbose)
                    {
                        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Found candidate for sending to overflow {0}", item.ToString()));
                    }
#endif

                    // since we havent parented the item yet - the auto size wont have reset the size yet.
                    Size itemSize = item.AutoSize ? item.GetPreferredSize(displayRectangle.Size) : item.Size;

                    if (BackwardsWalkingIndex <= ForwardsWalkingIndex)
                    {
                        // we've found an item that the forwards walking guy has already marched past,
                        // we need to let him know how much space we're freeing by sending this guy over
                        // to the overflow.
                        freedSpace += (horizontal) ? itemSize.Width + itemMargin.Horizontal : itemSize.Height + itemMargin.Vertical;
#if DEBUG
                        if (DebugLayoutTraceSwitch.TraceVerbose)
                        {
                            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Sweet! {0} FreedSpace - which is now {1}", itemSize, freedSpace.ToString(CultureInfo.InvariantCulture)));
                        }
#endif
                    }

                    // send the item to the overflow.
                    item.SetPlacement(ToolStripItemPlacement.Overflow);
                    if (OverflowRequired == false)
                    {
                        // this is the first item we're sending down.
                        // we now need to account for the width or height of the overflow button
                        spaceNeeded += (horizontal) ? OverflowButtonSize.Width : OverflowButtonSize.Height;
#if DEBUG
                        if (DebugLayoutTraceSwitch.TraceVerbose)
                        {
                            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Turns out we now need an overflow button, space needed now: {0}", spaceNeeded.ToString(CultureInfo.InvariantCulture)));
                        }
#endif
                        OverflowRequired = true;
                    }

                    OverflowSpace += (horizontal) ? itemSize.Width + itemMargin.Horizontal : itemSize.Height + itemMargin.Vertical;
                }

                if (freedSpace > spaceNeeded)
                {
                    break;
                }
            }

            Debug.Unindent();
            return(freedSpace);
        }
Exemple #5
0
        private bool LayoutVertical()
        {
#if DEBUG
            if (DebugLayoutTraceSwitch.TraceVerbose)
            {
                Debug.WriteLine("_________________________\r\nVertical Layout" + displayRectangle.ToString());
            }
#endif

            ToolStrip toolStrip         = ToolStrip;
            Rectangle clientRectangle   = toolStrip.ClientRectangle;
            int       lastBottom        = displayRectangle.Bottom;
            int       lastTop           = displayRectangle.Top;
            bool      needsMoreSpace    = false;
            Size      itemSize          = Size.Empty;
            Rectangle alignedLeftItems  = Rectangle.Empty;
            Rectangle alignedRightItems = Rectangle.Empty;

            Size      toolStripPreferredSize = displayRectangle.Size;
            DockStyle dock = toolStrip.Dock;
            if (toolStrip.AutoSize && (!toolStrip.IsInToolStripPanel && (dock == DockStyle.Left) || (dock == DockStyle.Right)))
            {
                // if we're autosizing, make sure we pad out items to the preferred width, not the
                // width of the display rectangle.
                toolStripPreferredSize = ToolStrip.GetPreferredSizeVertical(toolStrip, Size.Empty) - toolStrip.Padding.Size;
            }

            CalculatePlacementsVertical();

            bool needOverflow = toolStrip.CanOverflow && ((OverflowRequired) || (OverflowSpace >= OverflowButtonSize.Height));

            toolStrip.OverflowButton.Visible = needOverflow;

            for (int j = -1; j < ToolStrip.Items.Count; j++)
            {
                ToolStripItem item = null;

                if (j == -1)
                {
                    // the first time through place the overflow button if its required.
                    if (needOverflow)
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.Main);
                    }
                    else
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.None);
                        continue;
                    }

                    itemSize = OverflowButtonSize;
                }
                else
                {
                    item = toolStrip.Items[j];
                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // since we havent parented the item yet - the auto size wont have reset the size yet.
                    itemSize = item.AutoSize ? item.GetPreferredSize(Size.Empty) : item.Size;
                }

                // if it turns out we dont need the overflow (because there are no Overflow.Always items and the height of everything
                // in the overflow is less than the width of the overflow button then reset the placement of the as needed items to
                // main.
                if (!needOverflow && (item.Overflow == ToolStripItemOverflow.AsNeeded && item.Placement == ToolStripItemPlacement.Overflow))
                {
#if DEBUG
                    if (DebugLayoutTraceSwitch.TraceVerbose)
                    {
                        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Resetting {0} to Main - we dont need it to overflow", item));
                    }
#endif
                    item.SetPlacement(ToolStripItemPlacement.Main);
                }

                // Now do the guts of setting X, Y and parenting.
                // Vertical split stack management ignores left to right.
                //      Items aligned to the Head are placed from Top to Bottom
                //      Items aligned to the Tail are placed from Bottom to Top
                if ((item != null) && (item.Placement == ToolStripItemPlacement.Main))
                {
                    Padding itemMargin = item.Margin;
                    int     x          = displayRectangle.Left + itemMargin.Left;
                    int     y          = displayRectangle.Top;

                    switch (item.Alignment)
                    {
                    case ToolStripItemAlignment.Right:
                        y                 = lastBottom - (itemMargin.Bottom + itemSize.Height);
                        lastBottom        = y - itemMargin.Top;
                        alignedRightItems = (alignedRightItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedRightItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                        break;

                    case ToolStripItemAlignment.Left:
                    default:
                        y                = lastTop + itemMargin.Top;
                        lastTop          = y + itemSize.Height + itemMargin.Bottom;
                        alignedLeftItems = (alignedLeftItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                    : Rectangle.Union(alignedLeftItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                        break;
                    }
                    item.ParentInternal = ToolStrip;
                    Point itemLocation = new Point(x, y);


                    if (!clientRectangle.Contains(x, y))
                    {
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (alignedRightItems.Width > 0 && alignedLeftItems.Width > 0 && alignedRightItems.IntersectsWith(alignedLeftItems))
                    {
                        itemLocation = noMansLand;
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }

                    if (item.AutoSize)
                    {
                        // autosized items stretch from edge-edge
                        itemSize.Width = Math.Max(toolStripPreferredSize.Width - itemMargin.Horizontal - 1, 0);
                    }
                    else
                    {
                        // non autosized items are horizontally centered
                        Rectangle bounds = LayoutUtils.HAlign(item.Size, displayRectangle, AnchorStyles.None);
                        itemLocation.X = bounds.X;
                    }

                    SetItemLocation(item, itemLocation, itemSize);
                }
                else
                {
                    item.ParentInternal = (item.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
                }
#if DEBUG
                if (DebugLayoutTraceSwitch.TraceVerbose)
                {
                    Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Item {0} Placement {1} Bounds {2} Parent {3}", item.ToString(), item.Placement.ToString(), item.Bounds.ToString(), (item.ParentInternal == null) ? "null" : item.ParentInternal.ToString()));
                }
#endif
            }

            return(needsMoreSpace);
        }
Exemple #6
0
        private bool LayoutHorizontal()
        {
            ToolStrip toolStrip       = ToolStrip;
            Rectangle clientRectangle = toolStrip.ClientRectangle;

#if DEBUG
            if (DebugLayoutTraceSwitch.TraceVerbose)
            {
                Debug.WriteLine("_________________________\r\nHorizontal Layout:" + toolStrip.ToString() + displayRectangle.ToString());
            }
#endif

            int       lastRight         = displayRectangle.Right;
            int       lastLeft          = displayRectangle.Left;
            bool      needsMoreSpace    = false;
            Size      itemSize          = Size.Empty;
            Rectangle alignedLeftItems  = Rectangle.Empty;
            Rectangle alignedRightItems = Rectangle.Empty;

            // this will determine where the item should be placed.
            CalculatePlacementsHorizontal();

            bool needOverflow = toolStrip.CanOverflow && ((OverflowRequired) || (OverflowSpace >= OverflowButtonSize.Width));
            toolStrip.OverflowButton.Visible = needOverflow;

            // if we require the overflow, it should stick up against the edge of the toolstrip.
            if (needOverflow)
            {
                if (toolStrip.RightToLeft == RightToLeft.No)
                {
                    lastRight = clientRectangle.Right;
                }
                else
                {
                    lastLeft = clientRectangle.Left;
                }
            }

            for (int j = -1; j < toolStrip.Items.Count; j++)
            {
                ToolStripItem item = null;

                if (j == -1)
                {
                    // the first time through place the overflow button if its required.
                    if (needOverflow)
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.Main);
                        itemSize = OverflowButtonSize;
                    }
                    else
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.None);
                        continue;
                    }
                }
                else
                {
                    item = toolStrip.Items[j];

                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // since we havent parented the item yet - the auto size wont have reset the size yet.
                    itemSize = item.AutoSize ? item.GetPreferredSize(Size.Empty) : item.Size;
                }

                // if it turns out we dont need the overflow (because there are no Overflow.Always items and the width of everything
                // in the overflow is less than the width of the overflow button then reset the placement of the as needed items to
                // main.
                if (!needOverflow && (item.Overflow == ToolStripItemOverflow.AsNeeded && item.Placement == ToolStripItemPlacement.Overflow))
                {
#if DEBUG
                    if (DebugLayoutTraceSwitch.TraceVerbose)
                    {
                        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Resetting {0} to Main - we dont need it to overflow", item));
                    }
#endif
                    item.SetPlacement(ToolStripItemPlacement.Main);
                }

                // Now do the guts of setting X, Y and parenting.
                // We need to honor left to right and head and tail.
                //      In RTL.Yes, Head is to the Right, Tail is to the Left
                //      In RTL.No,  Head is to the Left,  Tail is to the Right
                if ((item != null) && (item.Placement == ToolStripItemPlacement.Main))
                {
                    int     x          = displayRectangle.Left;
                    int     y          = displayRectangle.Top;
                    Padding itemMargin = item.Margin;

                    if (((item.Alignment == ToolStripItemAlignment.Right) && (toolStrip.RightToLeft == RightToLeft.No)) || ((item.Alignment == ToolStripItemAlignment.Left) && (toolStrip.RightToLeft == RightToLeft.Yes)))
                    {
                        //                  lastRight   x     Margin.Right
                        //             [Item]<----------[Item]----------->|
                        //                   Margin.Left
                        // this item should be placed to the right
                        // we work backwards from the right edge - that is place items from right to left.
                        x                 = lastRight - (itemMargin.Right + itemSize.Width);
                        y                += itemMargin.Top;
                        lastRight         = x - itemMargin.Left;
                        alignedRightItems = (alignedRightItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedRightItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                    }
                    else
                    {
                        //             x     Margin.Right lastLeft
                        // |<----------[Item]------------>|
                        //  Margin.Left
                        // this item should be placed to the left
                        // we work forwards from the left - that is place items from left to right
                        x                = lastLeft + itemMargin.Left;
                        y               += itemMargin.Top;
                        lastLeft         = x + itemSize.Width + itemMargin.Right;
                        alignedLeftItems = (alignedLeftItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedLeftItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                    }

                    item.ParentInternal = ToolStrip;

                    Point itemLocation = new Point(x, y);
                    if (!clientRectangle.Contains(x, y))
                    {
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (alignedRightItems.Width > 0 && alignedLeftItems.Width > 0 && alignedRightItems.IntersectsWith(alignedLeftItems))
                    {
                        itemLocation = noMansLand;
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }

                    if (item.AutoSize)
                    {
                        // autosized items stretch from edge-edge
                        itemSize.Height = Math.Max(displayRectangle.Height - itemMargin.Vertical, 0);
                    }
                    else
                    {
                        // non autosized items are vertically centered
                        Rectangle bounds = LayoutUtils.VAlign(item.Size, displayRectangle, AnchorStyles.None);
                        itemLocation.Y = bounds.Y;
                    }

                    SetItemLocation(item, itemLocation, itemSize);
                }
                else
                {
                    item.ParentInternal = (item.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
                }
#if DEBUG
                if (DebugLayoutTraceSwitch.TraceVerbose)
                {
                    Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Item {0} Placement {1} Bounds {2} Parent {3}", item.ToString(), item.Placement.ToString(), item.Bounds.ToString(), (item.ParentInternal == null) ? "null" : item.ParentInternal.ToString()));
                }
#endif
            }

            return(needsMoreSpace);
        }
Exemple #7
0
        /// <summary>
        /// This method will mark whether items should be placed in the overflow or on the main ToolStrip.
        /// </summary>
        private void CalculatePlacementsVertical()
        {
            ResetItemPlacements();

            ToolStrip toolStrip     = ToolStrip;
            int       currentHeight = 0; //toolStrip.Padding.Vertical;

            if (ToolStrip.CanOverflow)
            {
                // determine the locations of all the items.
                for (ForwardsWalkingIndex = 0; ForwardsWalkingIndex < ToolStrip.Items.Count; ForwardsWalkingIndex++)
                {
                    ToolStripItem item = toolStrip.Items[ForwardsWalkingIndex];

                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // if we have something set to overflow always we need to show an overflow button
                    if (item.Overflow == ToolStripItemOverflow.Always)
                    {
                        OverflowRequired = true;
#if DEBUG
                        if (DebugLayoutTraceSwitch.TraceVerbose)
                        {
                            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "OverflowRequired - item set to always overflow: {0} ", item));
                        }
#endif
                    }

                    if (item.Overflow != ToolStripItemOverflow.Always && item.Placement == ToolStripItemPlacement.None)
                    {
                        // since we havent parented the item yet - the auto size wont have reset the size yet.
                        Size itemSize      = item.AutoSize ? item.GetPreferredSize(displayRectangle.Size) : item.Size;
                        int  overflowWidth = (OverflowRequired) ? OverflowButtonSize.Height : 0;

                        currentHeight += itemSize.Height + item.Margin.Vertical;
#if DEBUG
                        if (DebugLayoutTraceSwitch.TraceVerbose)
                        {
                            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Adding {0} Size {1} to currentHeight = {2}", item.ToString(), itemSize, currentHeight));
                        }
#endif
                        if (currentHeight > displayRectangle.Height - overflowWidth)
                        {
#if DEBUG
                            if (DebugLayoutTraceSwitch.TraceVerbose)
                            {
                                Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Got to {0} and realized that currentHeight = {1} is larger than displayRect {2} minus overflow {3}", item.ToString(), currentHeight, displayRectangle, overflowWidth));
                            }
#endif
                            int spaceRecovered = SendNextItemToOverflow(currentHeight - displayRectangle.Height, false);

                            currentHeight -= spaceRecovered;
                        }
                    }
                }
            }

            PlaceItems();
        }
 private static Size GetPreferredItemSize(ToolStripItem item)
 {
     if (!item.AutoSize)
     {
         return item.Size;
     }
     return item.GetPreferredSize(Size.Empty);
 }
Exemple #9
0
        private bool LayoutVertical()
        {
            System.Windows.Forms.ToolStrip toolStrip = this.ToolStrip;
            Rectangle clientRectangle = toolStrip.ClientRectangle;
            int       bottom          = this.displayRectangle.Bottom;
            int       top             = this.displayRectangle.Top;
            Size      empty           = Size.Empty;
            Rectangle a          = Rectangle.Empty;
            Rectangle rectangle3 = Rectangle.Empty;
            Size      size       = this.displayRectangle.Size;
            DockStyle dock       = toolStrip.Dock;

            if (toolStrip.AutoSize && ((!toolStrip.IsInToolStripPanel && (dock == DockStyle.Left)) || (dock == DockStyle.Right)))
            {
                size = System.Windows.Forms.ToolStrip.GetPreferredSizeVertical(toolStrip, Size.Empty) - toolStrip.Padding.Size;
            }
            this.CalculatePlacementsVertical();
            bool flag2 = toolStrip.CanOverflow && (this.OverflowRequired || (this.OverflowSpace >= this.OverflowButtonSize.Height));

            toolStrip.OverflowButton.Visible = flag2;
            for (int i = -1; i < this.ToolStrip.Items.Count; i++)
            {
                ToolStripItem overflowButton = null;
                if (i == -1)
                {
                    if (flag2)
                    {
                        overflowButton = toolStrip.OverflowButton;
                        overflowButton.SetPlacement(ToolStripItemPlacement.Main);
                    }
                    else
                    {
                        toolStrip.OverflowButton.SetPlacement(ToolStripItemPlacement.None);
                        continue;
                    }
                    empty = this.OverflowButtonSize;
                }
                else
                {
                    overflowButton = toolStrip.Items[i];
                    if (!((IArrangedElement)overflowButton).ParticipatesInLayout)
                    {
                        continue;
                    }
                    empty = overflowButton.AutoSize ? overflowButton.GetPreferredSize(Size.Empty) : overflowButton.Size;
                }
                if ((!flag2 && (overflowButton.Overflow == ToolStripItemOverflow.AsNeeded)) && (overflowButton.Placement == ToolStripItemPlacement.Overflow))
                {
                    overflowButton.SetPlacement(ToolStripItemPlacement.Main);
                }
                if ((overflowButton != null) && (overflowButton.Placement == ToolStripItemPlacement.Main))
                {
                    Padding margin = overflowButton.Margin;
                    int     x      = this.displayRectangle.Left + margin.Left;
                    int     y      = this.displayRectangle.Top;
                    switch (overflowButton.Alignment)
                    {
                    case ToolStripItemAlignment.Right:
                        y          = bottom - (margin.Bottom + empty.Height);
                        bottom     = y - margin.Top;
                        rectangle3 = (rectangle3 == Rectangle.Empty) ? new Rectangle(x, y, empty.Width, empty.Height) : Rectangle.Union(rectangle3, new Rectangle(x, y, empty.Width, empty.Height));
                        break;

                    default:
                        y   = top + margin.Top;
                        top = (y + empty.Height) + margin.Bottom;
                        a   = (a == Rectangle.Empty) ? new Rectangle(x, y, empty.Width, empty.Height) : Rectangle.Union(a, new Rectangle(x, y, empty.Width, empty.Height));
                        break;
                    }
                    overflowButton.ParentInternal = this.ToolStrip;
                    Point itemLocation = new Point(x, y);
                    if (!clientRectangle.Contains(x, y))
                    {
                        overflowButton.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (((rectangle3.Width > 0) && (a.Width > 0)) && rectangle3.IntersectsWith(a))
                    {
                        itemLocation = this.noMansLand;
                        overflowButton.SetPlacement(ToolStripItemPlacement.None);
                    }
                    if (overflowButton.AutoSize)
                    {
                        empty.Width = Math.Max((size.Width - margin.Horizontal) - 1, 0);
                    }
                    else
                    {
                        Rectangle rectangle4 = LayoutUtils.HAlign(overflowButton.Size, this.displayRectangle, AnchorStyles.None);
                        itemLocation.X = rectangle4.X;
                    }
                    this.SetItemLocation(overflowButton, itemLocation, empty);
                    continue;
                }
                overflowButton.ParentInternal = (overflowButton.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
            }
            return(false);
        }
Exemple #10
0
        private bool LayoutHorizontal()
        {
            System.Windows.Forms.ToolStrip toolStrip = this.ToolStrip;
            Rectangle clientRectangle = toolStrip.ClientRectangle;
            int       right           = this.displayRectangle.Right;
            int       left            = this.displayRectangle.Left;
            Size      empty           = Size.Empty;
            Rectangle a          = Rectangle.Empty;
            Rectangle rectangle3 = Rectangle.Empty;

            this.CalculatePlacementsHorizontal();
            bool flag2 = toolStrip.CanOverflow && (this.OverflowRequired || (this.OverflowSpace >= this.OverflowButtonSize.Width));

            toolStrip.OverflowButton.Visible = flag2;
            if (flag2)
            {
                if (toolStrip.RightToLeft == RightToLeft.No)
                {
                    right = clientRectangle.Right;
                }
                else
                {
                    left = clientRectangle.Left;
                }
            }
            for (int i = -1; i < toolStrip.Items.Count; i++)
            {
                ToolStripItem overflowButton = null;
                if (i == -1)
                {
                    if (flag2)
                    {
                        overflowButton = toolStrip.OverflowButton;
                        overflowButton.SetPlacement(ToolStripItemPlacement.Main);
                        empty = this.OverflowButtonSize;
                        goto Label_011F;
                    }
                    toolStrip.OverflowButton.SetPlacement(ToolStripItemPlacement.None);
                    continue;
                }
                overflowButton = toolStrip.Items[i];
                if (!((IArrangedElement)overflowButton).ParticipatesInLayout)
                {
                    continue;
                }
                empty = overflowButton.AutoSize ? overflowButton.GetPreferredSize(Size.Empty) : overflowButton.Size;
Label_011F:
                if ((!flag2 && (overflowButton.Overflow == ToolStripItemOverflow.AsNeeded)) && (overflowButton.Placement == ToolStripItemPlacement.Overflow))
                {
                    overflowButton.SetPlacement(ToolStripItemPlacement.Main);
                }
                if ((overflowButton != null) && (overflowButton.Placement == ToolStripItemPlacement.Main))
                {
                    int     x      = this.displayRectangle.Left;
                    int     top    = this.displayRectangle.Top;
                    Padding margin = overflowButton.Margin;
                    if (((overflowButton.Alignment == ToolStripItemAlignment.Right) && (toolStrip.RightToLeft == RightToLeft.No)) || ((overflowButton.Alignment == ToolStripItemAlignment.Left) && (toolStrip.RightToLeft == RightToLeft.Yes)))
                    {
                        x          = right - (margin.Right + empty.Width);
                        top       += margin.Top;
                        right      = x - margin.Left;
                        rectangle3 = (rectangle3 == Rectangle.Empty) ? new Rectangle(x, top, empty.Width, empty.Height) : Rectangle.Union(rectangle3, new Rectangle(x, top, empty.Width, empty.Height));
                    }
                    else
                    {
                        x    = left + margin.Left;
                        top += margin.Top;
                        left = (x + empty.Width) + margin.Right;
                        a    = (a == Rectangle.Empty) ? new Rectangle(x, top, empty.Width, empty.Height) : Rectangle.Union(a, new Rectangle(x, top, empty.Width, empty.Height));
                    }
                    overflowButton.ParentInternal = this.ToolStrip;
                    Point itemLocation = new Point(x, top);
                    if (!clientRectangle.Contains(x, top))
                    {
                        overflowButton.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (((rectangle3.Width > 0) && (a.Width > 0)) && rectangle3.IntersectsWith(a))
                    {
                        itemLocation = this.noMansLand;
                        overflowButton.SetPlacement(ToolStripItemPlacement.None);
                    }
                    if (overflowButton.AutoSize)
                    {
                        empty.Height = Math.Max(this.displayRectangle.Height - margin.Vertical, 0);
                    }
                    else
                    {
                        Rectangle rectangle4 = LayoutUtils.VAlign(overflowButton.Size, this.displayRectangle, AnchorStyles.None);
                        itemLocation.Y = rectangle4.Y;
                    }
                    this.SetItemLocation(overflowButton, itemLocation, empty);
                }
                else
                {
                    overflowButton.ParentInternal = (overflowButton.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
                }
            }
            return(false);
        }