2007-09-12 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Wed, 12 Sep 2007 20:15:29 +0000 (20:15 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Wed, 12 Sep 2007 20:15:29 +0000 (20:15 -0000)
* ToolStrip.cs: Fixup preferred size calculations for vertical toolbars.
Override GetPreferredSizeCore to perform calculations.  Remove custom
autosize logic.  [Fixes bug #82739]

svn path=/trunk/mcs/; revision=85701

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs

index 018394d1a6802ccf0a67ca6940681e0a3eaa21e4..195e589ab23f64b9e1420772547fcd720e497b0c 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-12  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStrip.cs: Fixup preferred size calculations for vertical toolbars. 
+       Override GetPreferredSizeCore to perform calculations.  Remove custom
+       autosize logic.  [Fixes bug #82739]
+
 2007-09-12  Jonathan Pobst  <monkey@jpobst.com>
 
        * TextBoxBase.cs: Modified should default to false.
index b68d1b5cb56de99e1aaef5160a60df10743343d0..7eba9d22a43986715f4dcfd3fd5da323d28264d3 100644 (file)
@@ -98,6 +98,7 @@ namespace System.Windows.Forms
                        this.items = new ToolStripItemCollection (this, items, true);
                        this.allow_merge = true;
                        base.AutoSize = true;
+                       base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
                        this.back_color = Control.DefaultBackColor;
                        this.can_overflow = true;
                        base.CausesValidation = false;
@@ -119,7 +120,6 @@ namespace System.Windows.Forms
                        base.TabStop = false;
                        this.text_direction = ToolStripTextDirection.Horizontal;
                        this.ResumeLayout ();
-                       DoAutoSize ();
                        
                        // Register with the ToolStripManager
                        ToolStripManager.AddToolStrip (this);
@@ -785,7 +785,6 @@ namespace System.Windows.Forms
                                e.Item.Available = true;
                                
                        e.Item.SetPlacement (ToolStripItemPlacement.Main);
-                       this.DoAutoSize ();
                        
                        if (this.Created)
                                this.PerformLayout ();
@@ -814,7 +813,6 @@ namespace System.Windows.Forms
 
                protected override void OnLayout (LayoutEventArgs e)
                {
-                       DoAutoSize ();
                        base.OnLayout (e);
 
                        this.SetDisplayedItems ();
@@ -1368,17 +1366,6 @@ namespace System.Windows.Forms
                        // We probably need to redraw for mnemonic underlines
                        this.Invalidate ();
                }
-               
-               private void DoAutoSize ()
-               {
-                       if (this.AutoSize == true && this.Dock == DockStyle.None) {
-                               Size new_size = GetToolStripPreferredSize (Size.Empty);
-                               SetBounds (Left, Top, new_size.Width, new_size.Height, BoundsSpecified.None);
-                       }
-                               
-                       if (this.AutoSize == true && this.Orientation == Orientation.Horizontal && (this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom))
-                               SetBounds (Left, Top, Width, GetToolStripPreferredSize (Size.Empty).Height, BoundsSpecified.None);
-               }
 
                internal ToolStripItem GetCurrentlySelectedItem ()
                {
@@ -1397,6 +1384,11 @@ namespace System.Windows.Forms
 
                        return null;
                }
+
+               internal override Size GetPreferredSizeCore (Size proposedSize)
+               {
+                       return GetToolStripPreferredSize (proposedSize);
+               }
                
                internal virtual Size GetToolStripPreferredSize (Size proposedSize)
                {
@@ -1404,11 +1396,16 @@ namespace System.Windows.Forms
 
                        if (this.orientation == Orientation.Vertical) {
                                foreach (ToolStripItem tsi in this.items)
-                                       if (tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom > new_size.Height)
-                                               new_size.Height = tsi.GetPreferredSize (Size.Empty).Height + tsi.Margin.Top + tsi.Margin.Bottom;
+                                       if (tsi.Available)  {
+                                               Size tsi_preferred = tsi.GetPreferredSize (Size.Empty);
+                                               new_size.Height += tsi_preferred.Height + tsi.Margin.Top + tsi.Margin.Bottom;
+
+                                               if (new_size.Width < (this.Padding.Horizontal + tsi_preferred.Width))
+                                                       new_size.Width = (this.Padding.Horizontal + tsi_preferred.Width);
+                                       }
 
-                               new_size.Height += this.Padding.Top + this.Padding.Bottom;
-                               new_size.Width = this.Width;
+                               new_size.Height += (this.GripRectangle.Height + this.GripMargin.Vertical + this.Padding.Vertical + 4);
+                               return new_size;
                        } else {
                                foreach (ToolStripItem tsi in this.items) 
                                        if (tsi.Available) {