Author: jpobst
Date: 2007-04-02 12:04:20 -0400 (Mon, 02 Apr 2007)
New Revision: 75284

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripPanel.cs
Log:
2007-04-02  Jonathan Pobst  <[EMAIL PROTECTED]>

        * ToolStripPanel.cs: Fixes for better layouts in PDN.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-04-02 15:32:00 UTC (rev 75283)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-04-02 16:04:20 UTC (rev 75284)
@@ -1,3 +1,7 @@
+2007-04-02  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * ToolStripPanel.cs: Fixes for better layouts in PDN.
+
 2007-03-31  Gert Driesen  <[EMAIL PROTECTED]>
 
        * TextBox.cs: Added internal ChangeBackColor method to special-case

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripPanel.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripPanel.cs    
    2007-04-02 15:32:00 UTC (rev 75283)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripPanel.cs    
    2007-04-02 16:04:20 UTC (rev 75284)
@@ -260,10 +260,10 @@
 
                protected override void OnControlAdded (ControlEventArgs e)
                {
+                       if (done_first_layout && e.Control is ToolStrip)
+                               this.AddControlToRows (e.Control);
+                       
                        base.OnControlAdded (e);
-
-                       if (done_first_layout)
-                               this.AddControlToRows (e.Control);
                }
 
                protected override void OnControlRemoved (ControlEventArgs e)
@@ -279,42 +279,47 @@
                {
                        base.OnDockChanged (e);
                }
-
+               
                protected override void OnLayout (LayoutEventArgs levent)
                {
-                       if (this.Width == 0)
+                       // Don't see any reason to layout if we aren't created
+                       if (!this.Created)
                                return;
-
-                       if (!done_first_layout && (this.FindForm() == null || 
this.Visible == false))
-                               return;
                                
+                       // The first time through, we have to layout everything 
where it belongs.
+                       // The key is that when we resize and stuff, we don't 
resize or move toolstrips.
+                       if (!done_first_layout) {
+                               ArrayList al = new ArrayList (this.Controls);
+                               al.Sort (new TabIndexComparer ());
+                               
+                               foreach (ToolStrip ts in al)
+                                       this.AddControlToRows (ts);
+                                       
+                               done_first_layout = true;                       
+                       }
+                       
+                       // Lay out all the rows
                        Point position = this.DisplayRectangle.Location;
-                       
+
                        foreach (ToolStripPanelRow row in this.rows) {
                                row.SetBounds (new Rectangle (position, new 
Size (this.Width, row.Bounds.Height)));
 
                                position.Y += row.Bounds.Height;
                        }
+
+                       // Find how big we are so we can autosize ourself
+                       int height = 0;
+                               
+                       if (this.rows.Count > 0) {
+                               int last_row_bottom = this.rows[this.rows.Count 
- 1].Bounds.Bottom;
                        
-                       if (!done_first_layout)
-                       {
-                               foreach (ToolStrip ts in this.Controls)
-                                       this.AddControlToRows (ts);
+                               if (last_row_bottom != this.Height)
+                                       this.SetBounds (bounds.X, bounds.Y, 
bounds.Width, last_row_bottom);
+                       }
                        
-                               done_first_layout = true;
-                               this.OnLayout (levent);
-                               return;
-                       }
-
-                       int height = 0;
-
-                       foreach (ToolStripPanelRow row in this.rows)
-                               height += row.Bounds.Height;
-
-                       if (height != this.Height)
-                               this.Height = height;
-
-                       this.Invalidate (FindBackgroundRegion ());
+                       this.Invalidate ();
+                       
+                       return;
                }
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]
@@ -510,6 +515,19 @@
                        {
                        }
                }
+
+               private class TabIndexComparer : IComparer
+               {
+                       #region IComparer Members
+                       public int Compare (object x, object y)
+                       {
+                               if (!(x is Control) || !(y is Control))
+                                       throw new ArgumentException ();
+
+                               return (x as Control).TabIndex - (y as 
Control).TabIndex;
+                       }
+                       #endregion
+               }
                #endregion
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to