Author: jpobst
Date: 2008-01-24 16:47:46 -0500 (Thu, 24 Jan 2008)
New Revision: 93847

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
   
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs
Log:
2008-01-24  Jonathan Pobst  <[EMAIL PROTECTED]>

        * TableLayoutPanel.cs: Enhance GetPreferredSize to take into account
        when all contained controls are autosize or dock-fill.  Also take into
        account when the total percentage of column/row sizes is not 100%.
        [Fixes bug #354672]

2008-01-24  Jonathan Pobst  <[EMAIL PROTECTED]>

        * TableLayoutTest.cs: Add tests for bug #354672.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-01-24 21:44:46 UTC (rev 93846)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-01-24 21:47:46 UTC (rev 93847)
@@ -1,3 +1,10 @@
+2008-01-24  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * TableLayoutPanel.cs: Enhance GetPreferredSize to take into account
+       when all contained controls are autosize or dock-fill.  Also take into
+       account when the total percentage of column/row sizes is not 100%.
+       [Fixes bug #354672]
+
 2008-01-24  Andreia Gaita <[EMAIL PROTECTED]>
 
        * HtmlDocument.cs:

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs  
    2008-01-24 21:44:46 UTC (rev 93846)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs  
    2008-01-24 21:47:46 UTC (rev 93847)
@@ -513,16 +513,24 @@
                        
                        // Figure out how wide the panel needs to be
                        int[] column_widths = new int[ColumnCount];
-
+                       float total_column_percentage = 0f;
+                       
                        // Figure out how tall each column wants to be
                        for (int i = 0; i < ColumnCount; i++) {
+                               if (i < ColumnStyles.Count && 
ColumnStyles[i].SizeType == SizeType.Percent)
+                                       total_column_percentage += 
ColumnStyles[i].Width;
+                                       
                                int biggest = 0;
 
                                for (int j = 0; j < RowCount; j++) {
                                        Control c = actual_positions[i, j];
 
-                                       if (c != null && !c.AutoSize)
-                                               biggest = Math.Max (biggest, 
c.ExplicitBounds.Width + c.Margin.Horizontal + Padding.Horizontal);
+                                       if (c != null) {
+                                               if (!c.AutoSize)
+                                                       biggest = Math.Max 
(biggest, c.ExplicitBounds.Width + c.Margin.Horizontal + Padding.Horizontal);
+                                               else
+                                                       biggest = Math.Max 
(biggest, c.ExplicitBounds.Width + c.Margin.Horizontal + Padding.Horizontal);
+                                       }
                                }
 
                                column_widths[i] = biggest;
@@ -535,8 +543,8 @@
                        int percent_total_width = 0;
 
                        for (int i = 0; i < ColumnCount; i++) {
-                               if (ColumnStyles[i].SizeType == 
SizeType.Percent)
-                                       percent_total_width = Math.Max 
(percent_total_width, (int)(column_widths[i] / ((ColumnStyles[i].Width) / 
100)));
+                               if (i < ColumnStyles.Count && 
ColumnStyles[i].SizeType == SizeType.Percent)
+                                       percent_total_width = Math.Max 
(percent_total_width, (int)(column_widths[i] / ((ColumnStyles[i].Width) / 
total_column_percentage)));
                                else
                                        non_percent_total_width += 
column_widths[i];
                        }
@@ -544,16 +552,24 @@
 
                        // Figure out how tall the panel needs to be
                        int[] row_heights = new int[RowCount];
-                       
+                       float total_row_percentage = 0f;
+               
                        // Figure out how tall each row wants to be
                        for (int j = 0; j < RowCount; j++) {
+                               if (j < RowStyles.Count && 
RowStyles[j].SizeType == SizeType.Percent)
+                                       total_row_percentage += 
RowStyles[j].Height;
+                                       
                                int biggest = 0;
                                
                                for (int i = 0; i < ColumnCount; i++) {
                                        Control c = actual_positions[i, j];
 
-                                       if (c != null && !c.AutoSize)
-                                               biggest = Math.Max (biggest, 
c.ExplicitBounds.Height + c.Margin.Vertical + Padding.Vertical);
+                                       if (c != null) {
+                                               if (!c.AutoSize)
+                                                       biggest = Math.Max 
(biggest, c.ExplicitBounds.Height + c.Margin.Vertical + Padding.Vertical);
+                                               else
+                                                       biggest = Math.Max 
(biggest, c.PreferredSize.Height + c.Margin.Vertical + Padding.Vertical);
+                                       }
                                }
 
                                row_heights[j] = biggest;
@@ -566,8 +582,8 @@
                        int percent_total_height = 0;
                        
                        for (int j = 0; j < RowCount; j++) {
-                               if (RowStyles[j].SizeType == SizeType.Percent)
-                                       percent_total_height = Math.Max 
(percent_total_height, (int)(row_heights[j] / ((RowStyles[j].Height) / 100)));
+                               if (j < RowStyles.Count && 
RowStyles[j].SizeType == SizeType.Percent)
+                                       percent_total_height = Math.Max 
(percent_total_height, (int)(row_heights[j] / ((RowStyles[j].Height) / 
total_row_percentage)));
                                else
                                        non_percent_total_height += 
row_heights[j];
                        }

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-01-24 21:44:46 UTC (rev 93846)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-01-24 21:47:46 UTC (rev 93847)
@@ -1,3 +1,7 @@
+2008-01-24  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * TableLayoutTest.cs: Add tests for bug #354672.
+
 2008-01-23  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * FormTest.cs: Add test for bug 355703.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs
  2008-01-24 21:44:46 UTC (rev 93846)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs
  2008-01-24 21:47:46 UTC (rev 93847)
@@ -1324,6 +1324,59 @@
                        f.Close ();
                        f.Dispose ();
                }
+               
+               [Test]
+               public void Bug354672 ()
+               {
+                       Form f = new Form ();
+                       f.ClientSize = new Size (300, 300);
+
+                       TableLayoutPanel tlp = new TableLayoutPanel ();
+                       tlp.AutoSize = true;
+                       tlp.ColumnCount = 2;
+                       tlp.RowCount = 1;
+                       f.Controls.Add (tlp);
+
+                       TextBox t1 = new TextBox ();
+                       t1.Dock = DockStyle.Fill;
+                       tlp.Controls.Add (t1);
+
+                       TextBox t2 = new TextBox ();
+                       t2.Dock = DockStyle.Fill;
+                       tlp.Controls.Add (t2);
+
+                       Assert.AreEqual (new Size (212, 26), tlp.PreferredSize, 
"A1");
+
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void Bug354672More ()
+               {
+                       Form f = new Form ();
+                       f.ClientSize = new Size (300, 300);
+
+                       TableLayoutPanel tlp = new TableLayoutPanel ();
+                       tlp.AutoSize = true;
+                       tlp.ColumnCount = 2;
+                       tlp.RowCount = 1;
+                       tlp.ColumnStyles.Add (new ColumnStyle 
(SizeType.AutoSize));
+                       tlp.ColumnStyles.Add (new ColumnStyle 
(SizeType.Percent, 50f));
+                       
+                       f.Controls.Add (tlp);
+
+                       TextBox t1 = new TextBox ();
+                       t1.Dock = DockStyle.Fill;
+                       tlp.Controls.Add (t1);
+
+                       TextBox t2 = new TextBox ();
+                       t2.Dock = DockStyle.Fill;
+                       tlp.Controls.Add (t2);
+
+                       Assert.AreEqual (new Size (212, 26), tlp.PreferredSize, 
"A1");
+
+                       f.Dispose ();
+               }
        }
 }
 #endif

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

Reply via email to