Skip to content

Commit

Permalink
Fix several bugs relating to ToolStrips with Flow layout
Browse files Browse the repository at this point in the history
Specifically:
  - Do not take into account unavailable ToolStripItems.
  - Use preferred size of ToolStripItems instead of current size.
  - Take into account the ToolStrip's padding.
  - Do not fill the ToolStrip height during layout, which is wrong
    for multi-row ToolStrips.  This reverts commit f124ea3, which
    fixed Novell bug #469196.  As an alternative fix for that issue,
    set ToolStripSeparator's Dock to Fill in its constructor.
  • Loading branch information
pcc committed Mar 19, 2012
1 parent c64a76e commit fbe0f6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Expand Up @@ -358,13 +358,9 @@ private bool LayoutToolStrip (ToolStrip parent)
// Only apply layout to visible controls.
if (!c.Available) { continue; }

// Resize any AutoSize controls to their preferred width
// (the height should fill the ToolStrip)
if (c.AutoSize == true) {
Size preferred_size = c.GetPreferredSize (c.Size);
preferred_size.Height = parentDisplayRectangle.Height;
c.SetBounds (new Rectangle (c.Location, preferred_size));
}
// Resize any AutoSize controls to their preferred size
if (c.AutoSize == true)
c.SetBounds (new Rectangle (c.Location, c.GetPreferredSize (c.Size)));

switch (settings.FlowDirection) {
case FlowDirection.BottomUp:
Expand Down
31 changes: 17 additions & 14 deletions mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
Expand Up @@ -1429,25 +1429,28 @@ internal virtual Size GetToolStripPreferredSize (Size proposedSize)
Point currentLocation = Point.Empty;
int tallest = 0;

foreach (ToolStripItem tsi in items) {
if ((DisplayRectangle.Width - currentLocation.X) < (tsi.Width + tsi.Margin.Horizontal)) {
foreach (ToolStripItem tsi in items)
if (tsi.Available) {
Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);

if ((DisplayRectangle.Width - currentLocation.X) < (tsi_preferred.Width + tsi.Margin.Horizontal)) {

currentLocation.Y += tallest;
tallest = 0;

currentLocation.X = DisplayRectangle.Left;
}

currentLocation.Y += tallest;
tallest = 0;
// Offset the left margin and set the control to our point
currentLocation.Offset (tsi.Margin.Left, 0);
tallest = Math.Max (tallest, tsi_preferred.Height + tsi.Margin.Vertical);

currentLocation.X = DisplayRectangle.Left;
// Update our location pointer
currentLocation.X += tsi_preferred.Width + tsi.Margin.Right;
}

// Offset the left margin and set the control to our point
currentLocation.Offset (tsi.Margin.Left, 0);
tallest = Math.Max (tallest, tsi.Height + tsi.Margin.Vertical);

// Update our location pointer
currentLocation.X += tsi.Width + tsi.Margin.Right;
}

currentLocation.Y += tallest;
return new Size (currentLocation.X, currentLocation.Y);
return new Size (currentLocation.X + this.Padding.Horizontal, currentLocation.Y + this.Padding.Vertical);
}

if (this.orientation == Orientation.Vertical) {
Expand Down
Expand Up @@ -37,6 +37,7 @@ public class ToolStripSeparator : ToolStripItem
{
public ToolStripSeparator () : base ()
{
Dock = DockStyle.Fill;
}

#region Public Properties
Expand Down

0 comments on commit fbe0f6a

Please sign in to comment.