private SetPlacement ( ToolStripItemPlacement placement ) : void | ||
placement | ToolStripItemPlacement | |
return | void |
protected override void SetDisplayedItems() { if (this.state[stateCalledSpringTableLayout]) { if (base.Orientation == Orientation.Horizontal) { RightToLeft rightToLeft = this.RightToLeft; } Point location = this.DisplayRectangle.Location; location.X += base.ClientSize.Width + 1; location.Y += base.ClientSize.Height + 1; bool flag = false; Rectangle empty = Rectangle.Empty; ToolStripItem item = null; for (int i = 0; i < this.Items.Count; i++) { ToolStripItem item2 = this.Items[i]; if (flag || ((IArrangedElement)item2).ParticipatesInLayout) { if (flag || (this.SizingGrip && item2.Bounds.IntersectsWith(this.SizeGripBounds))) { base.SetItemLocation(item2, location); item2.SetPlacement(ToolStripItemPlacement.None); } } else if ((item != null) && empty.IntersectsWith(item2.Bounds)) { base.SetItemLocation(item2, location); item2.SetPlacement(ToolStripItemPlacement.None); } else if (item2.Bounds.Width == 1) { ToolStripStatusLabel label = item2 as ToolStripStatusLabel; if ((label != null) && label.Spring) { base.SetItemLocation(item2, location); item2.SetPlacement(ToolStripItemPlacement.None); } } if (item2.Bounds.Location != location) { item = item2; empty = item.Bounds; } else if (((IArrangedElement)item2).ParticipatesInLayout) { flag = true; } } } base.SetDisplayedItems(); }
private void SetItemLocation(ToolStripItem item, Point itemLocation, Size itemSize) { // make sure that things that dont fit within the display rectangle arent laid out. if ((item.Placement == ToolStripItemPlacement.Main) && !(item is ToolStripOverflowButton)) // overflow buttons can be placed outside the display rect. { bool horizontal = (ToolStrip.LayoutStyle == ToolStripLayoutStyle.HorizontalStackWithOverflow); Rectangle displayRect = displayRectangle; Rectangle itemBounds = new Rectangle(itemLocation, itemSize); // in horizontal if something bleeds over the top/bottom that's ok - its left/right we care about // same in vertical. if (horizontal) { if ((itemBounds.Right > displayRectangle.Right) || (itemBounds.Left < displayRectangle.Left)) { #if DEBUG if (DebugLayoutTraceSwitch.TraceVerbose) { Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "[SplitStack.SetItemLocation] Sending Item {0} to NoMansLand as it doesnt fit horizontally within the DRect", item)); } #endif itemLocation = noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } else { if ((itemBounds.Bottom > displayRectangle.Bottom) || (itemBounds.Top < displayRectangle.Top)) { #if DEBUG if (DebugLayoutTraceSwitch.TraceVerbose) { Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "[SplitStack.SetItemLocation] Sending Item {0} to NoMansLand as it doesnt fit verticallu within the DRect", item)); } #endif itemLocation = noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } } item.SetBounds(new Rectangle(itemLocation, itemSize)); }
private void PlaceItems() { System.Windows.Forms.ToolStrip toolStrip = this.ToolStrip; for (int i = 0; i < toolStrip.Items.Count; i++) { ToolStripItem item = toolStrip.Items[i]; if (item.Placement == ToolStripItemPlacement.None) { if (item.Overflow != ToolStripItemOverflow.Always) { item.SetPlacement(ToolStripItemPlacement.Main); } else { item.SetPlacement(ToolStripItemPlacement.Overflow); } } } }
private void SetItemLocation(ToolStripItem item, Point itemLocation, Size itemSize) { if ((item.Placement == ToolStripItemPlacement.Main) && !(item is ToolStripOverflowButton)) { bool flag = this.ToolStrip.LayoutStyle == ToolStripLayoutStyle.HorizontalStackWithOverflow; Rectangle rectangle = new Rectangle(itemLocation, itemSize); if (flag) { if ((rectangle.Right > this.displayRectangle.Right) || (rectangle.Left < this.displayRectangle.Left)) { itemLocation = this.noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } else if ((rectangle.Bottom > this.displayRectangle.Bottom) || (rectangle.Top < this.displayRectangle.Top)) { itemLocation = this.noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } item.SetBounds(new Rectangle(itemLocation, itemSize)); }
private void PlaceItems() { ToolStrip toolStrip = ToolStrip; for (int i = 0; i < toolStrip.Items.Count; i++) { ToolStripItem item = toolStrip.Items[i]; // if we havent placed the items, place them now. if (item.Placement == ToolStripItemPlacement.None) { if (item.Overflow != ToolStripItemOverflow.Always) { // as needed items will have already been placed into the overflow if they // needed to move over. item.SetPlacement(ToolStripItemPlacement.Main); } else { item.SetPlacement(ToolStripItemPlacement.Overflow); } } } }
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); }
/// <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); }
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); }
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); }
protected override void SetDisplayedItems() { if (state[stateCalledSpringTableLayout]) { bool rightToLeft = ((Orientation == Orientation.Horizontal) && (RightToLeft == RightToLeft.Yes)); // shove all items that dont fit one pixel outside the displayed region Rectangle displayRect = DisplayRectangle; Point noMansLand = displayRect.Location; noMansLand.X += ClientSize.Width + 1; noMansLand.Y += ClientSize.Height + 1; bool overflow = false; Rectangle lastItemBounds = Rectangle.Empty; ToolStripItem lastItem = null; for (int i = 0; i < Items.Count; i++) { ToolStripItem item = Items[i]; // using spring layout we can get into a situation where there's extra items which arent // visible. if (overflow || ((IArrangedElement)item).ParticipatesInLayout) { if (overflow || (SizingGrip && item.Bounds.IntersectsWith(SizeGripBounds))) { // if the item collides with the size grip, set the location to nomansland. SetItemLocation(item, noMansLand); item.SetPlacement(ToolStripItemPlacement.None); } } else if (lastItem != null && (lastItemBounds.IntersectsWith(item.Bounds))) { // if it overlaps the previous element, set the location to nomansland. SetItemLocation(item, noMansLand); item.SetPlacement(ToolStripItemPlacement.None); } else if (item.Bounds.Width == 1) { ToolStripStatusLabel panel = item as ToolStripStatusLabel; if (panel != null && panel.Spring) { // once we get down to one pixel, there can always be a one pixel // distribution problem with the TLP - there's usually a spare one around. // so set this off to nomansland as well. SetItemLocation(item, noMansLand); item.SetPlacement(ToolStripItemPlacement.None); } } if (item.Bounds.Location != noMansLand) { // set the next item to inspect for collisions lastItem = item; lastItemBounds = lastItem.Bounds; } else { // we cant fit an item, everything else after it should not be displayed if (((IArrangedElement)item).ParticipatesInLayout) { overflow = true; } } } } base.SetDisplayedItems(); }
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); }
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); }
private void SetItemLocation(ToolStripItem item, Point itemLocation, Size itemSize) { if ((item.Placement == ToolStripItemPlacement.Main) && !(item is ToolStripOverflowButton)) { bool flag = this.ToolStrip.LayoutStyle == ToolStripLayoutStyle.HorizontalStackWithOverflow; Rectangle rectangle = new Rectangle(itemLocation, itemSize); if (flag) { if ((rectangle.Right > this.displayRectangle.Right) || (rectangle.Left < this.displayRectangle.Left)) { itemLocation = this.noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } else if ((rectangle.Bottom > this.displayRectangle.Bottom) || (rectangle.Top < this.displayRectangle.Top)) { itemLocation = this.noMansLand; item.SetPlacement(ToolStripItemPlacement.None); } } item.SetBounds(new Rectangle(itemLocation, itemSize)); }