2007-09-06 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Thu, 6 Sep 2007 17:23:45 +0000 (17:23 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Thu, 6 Sep 2007 17:23:45 +0000 (17:23 -0000)
* DefaultLayout.cs: Only LayoutAutoSizeContainer if the container is
a Form, others should be taken care of by their parent.
* TableLayout.cs: If a control is AutoSize, default to its preferred
size if possible.  [Fixes bug #82605]

2007-09-06  Jonathan Pobst  <monkey@jpobst.com>

* TableLayoutTest.cs: Add test for bug #82605.

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/DefaultLayout.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs

index 3845b5c5e8de1e868f891d5409d96155ab2944d9..6480010552fd06b0172131f53c021d0cd8bd97bf 100644 (file)
@@ -1,3 +1,10 @@
+2007-09-06  Jonathan Pobst  <monkey@jpobst.com>
+
+       * DefaultLayout.cs: Only LayoutAutoSizeContainer if the container is
+       a Form, others should be taken care of by their parent.
+       * TableLayout.cs: If a control is AutoSize, default to its preferred
+       size if possible.  [Fixes bug #82605]
+
 2007-07-31  Jonathan Pobst  <monkey@jpobst.com>
 
        * ArrangedElementCollection.cs: Rename internal method RemoveAt
index 728ea3e9fa64175e888a45229950311e2a12164f..4258bfc577cc7174969b6ec8deaf9a2ac9f4a35d 100644 (file)
@@ -260,7 +260,7 @@ namespace System.Windows.Forms.Layout
                        LayoutAnchoredChildren (parent, controls);
 #if NET_2_0
                        LayoutAutoSizedChildren (parent, controls);
-                       LayoutAutoSizeContainer (parent);
+                       if (parent is Form) LayoutAutoSizeContainer (parent);
 #endif
 
                        return false;
index 7bfa7452284a0fa41f1954ef83b17a89a81109e2..af0b68cf4a30d18d04f0736cc3ac591d5bf525f4 100644 (file)
@@ -407,9 +407,14 @@ namespace System.Windows.Forms.Layout
                                {
                                        Control c = panel.actual_positions[x,y];
                                        
-                                       if(c != null && c != dummy_control)
-                                       
-                                       {               
+                                       if(c != null && c != dummy_control) {
+                                               Size preferred;
+                                               
+                                               if (c.AutoSize)
+                                                       preferred = c.PreferredSize;
+                                               else
+                                                       preferred = c.Size;
+                                               
                                                int new_x = 0;
                                                int new_y = 0;
                                                int new_width = 0;
@@ -424,7 +429,7 @@ namespace System.Windows.Forms.Layout
                                                if (c.Dock == DockStyle.Fill || c.Dock == DockStyle.Top || c.Dock == DockStyle.Bottom || ((c.Anchor & AnchorStyles.Left) == AnchorStyles.Left && (c.Anchor & AnchorStyles.Right) == AnchorStyles.Right))
                                                        new_width = column_width - c.Margin.Left - c.Margin.Right;
                                                else
-                                                       new_width = Math.Min (c.Width, column_width - c.Margin.Left - c.Margin.Right);
+                                                       new_width = Math.Min (preferred.Width, column_width - c.Margin.Left - c.Margin.Right);
                                                        
                                                // Figure out the height of the control
                                                int column_height = panel.row_heights[y];
@@ -435,7 +440,7 @@ namespace System.Windows.Forms.Layout
                                                if (c.Dock == DockStyle.Fill || c.Dock == DockStyle.Left || c.Dock == DockStyle.Right || ((c.Anchor & AnchorStyles.Top) == AnchorStyles.Top && (c.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom))
                                                        new_height = column_height - c.Margin.Top - c.Margin.Bottom;
                                                else
-                                                       new_height = Math.Min (c.Height, column_height - c.Margin.Top - c.Margin.Bottom);
+                                                       new_height = Math.Min (preferred.Height, column_height - c.Margin.Top - c.Margin.Bottom);
 
                                                // Figure out the left location of the control
                                                if (c.Dock == DockStyle.Left || c.Dock == DockStyle.Fill || (c.Anchor & AnchorStyles.Left) == AnchorStyles.Left)
index 57036f491e0d0a72a8b62773129c7f78636711d0..77d30ba5eeb00c2fa4a78e667e03d65359ca844f 100644 (file)
@@ -1,3 +1,7 @@
+2007-09-06  Jonathan Pobst  <monkey@jpobst.com>
+
+       * TableLayoutTest.cs: Add test for bug #82605.
+
 2007-08-31  Jonathan Pobst  <monkey@jpobst.com>
 
        * ToolStripItemTest.cs: Added test to show that Enabled can
index 90d9141d63fb81a5d3b903a238aa8c49ba0194b5..6b272b1b7ae06acae5d89d670e8e582d7d2c7c1c 100644 (file)
@@ -1090,6 +1090,40 @@ namespace MonoTests.System.Windows.Forms
                        f.Dispose ();\r
                }\r
 \r
+               [Test]\r
+               public void Bug82605 ()\r
+               {\r
+                       Form f = new Form ();\r
+                       f.ShowInTaskbar = false;\r
+                       \r
+                       Label l = new Label ();\r
+\r
+                       TableLayoutPanel table = new TableLayoutPanel ();\r
+                       table.ColumnCount = 1;\r
+                       table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));\r
+\r
+                       table.RowCount = 2;\r
+                       table.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
+                       table.RowStyles.Add (new RowStyle (SizeType.Absolute, 20F));\r
+\r
+                       table.Controls.Add (l, 0, 1);\r
+                       table.Location = new Point (0, 0);\r
+                       table.Width = 250;\r
+\r
+                       l.Anchor = AnchorStyles.Left | AnchorStyles.Right;\r
+                       l.AutoSize = true;\r
+                       l.Location = new Point (3, 352);\r
+                       l.Size = new Size (578, 13);\r
+                       l.Text = "label1";\r
+                       l.TextAlign = ContentAlignment.MiddleCenter;\r
+\r
+                       f.Controls.Add (table);\r
+                       f.Show ();\r
+                       \r
+                       \r
+                       Assert.AreEqual (new Size (244, 17), l.Size, "A1");\r
+               }\r
+               \r
                [Test] // bug #82040\r
                public void ShowNoChildren ()\r
                {\r