Author: jpobst
Date: 2007-12-13 12:36:25 -0500 (Thu, 13 Dec 2007)
New Revision: 91245
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
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:
2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
* TableLayoutPanel.cs: Override GetPreferredSizeCore so
we can provide an implementation of AutoSize.
[Fixes bug #346246]
2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
* TableLayout.cs: Use ExplicitBounds so that we get the user requested
size, not the AutoSize/Dock size. Make CalculateControlPositions
internal so that TableLayoutPanel can call it.
[Fixes bug #346246]
2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
* TableLayoutTest.cs: Add tests for bug #346246.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-12-13 17:32:05 UTC (rev 91244)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-12-13 17:36:25 UTC (rev 91245)
@@ -1,3 +1,9 @@
+2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * TableLayoutPanel.cs: Override GetPreferredSizeCore so
+ we can provide an implementation of AutoSize.
+ [Fixes bug #346246]
+
2007-12-12 Carlos Alberto Cortez <[EMAIL PROTECTED]>
* ListBox.cs: Add the internal overload Sort (bool paint),
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs
2007-12-13 17:32:05 UTC (rev 91244)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TableLayoutPanel.cs
2007-12-13 17:36:25 UTC (rev 91245)
@@ -504,6 +504,80 @@
g.DrawLine (ThemeEngine.Current.ResPool.GetPen
(BackColor), new Point (3, y + 1), new Point (Right - 4, y + 1));
}
}
+
+ internal override Size GetPreferredSizeCore (Size proposedSize)
+ {
+ // If the tablelayoutpanel is autosize, we have to make
sure it is big enough
+ // to hold every non-autosize control
+ actual_positions = (LayoutEngine as
TableLayout).CalculateControlPositions (this, Math.Max (ColumnCount, 1),
Math.Max (RowCount, 1));
+
+ // Figure out how wide the panel needs to be
+ int[] column_widths = new int[ColumnCount];
+
+ // Figure out how tall each column wants to be
+ for (int i = 0; i < ColumnCount; i++) {
+ int biggest = 0;
+ int percent_pixels = 0;
+ float enlarge_factor = 0f;
+
+ 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);
+ }
+
+ column_widths[i] = biggest;
+ }
+
+ // Because percentage based rows divy up the remaining
space,
+ // we have to make the panel big enough so that all the
rows
+ // get bigger, even if we only need one to be bigger.
+ int non_percent_total_width = 0;
+ 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)));
+ else
+ non_percent_total_width +=
column_widths[i];
+ }
+
+
+ // Figure out how tall the panel needs to be
+ int[] row_heights = new int[RowCount];
+
+ // Figure out how tall each row wants to be
+ for (int j = 0; j < RowCount; j++) {
+ int biggest = 0;
+ int percent_pixels = 0;
+ float enlarge_factor = 0f;
+
+ 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);
+ }
+
+ row_heights[j] = biggest;
+ }
+
+ // Because percentage based rows divy up the remaining
space,
+ // we have to make the panel big enough so that all the
rows
+ // get bigger, even if we only need one to be bigger.
+ int non_percent_total_height = 0;
+ 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)));
+ else
+ non_percent_total_height +=
row_heights[j];
+ }
+
+ return new Size (non_percent_total_width +
percent_total_width, non_percent_total_height + percent_total_height);
+ }
#endregion
#region Public Events
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/ChangeLog
2007-12-13 17:32:05 UTC (rev 91244)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/ChangeLog
2007-12-13 17:36:25 UTC (rev 91245)
@@ -1,3 +1,10 @@
+2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * TableLayout.cs: Use ExplicitBounds so that we get the user requested
+ size, not the AutoSize/Dock size. Make CalculateControlPositions
+ internal so that TableLayoutPanel can call it.
+ [Fixes bug #346246]
+
2007-10-16 Jonathan Pobst <[EMAIL PROTECTED]>
* TableLayout.cs: Revert the last change to TableLayout. It breaks
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
2007-12-13 17:32:05 UTC (rev 91244)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
2007-12-13 17:36:25 UTC (rev 91245)
@@ -75,7 +75,7 @@
return false;
}
- private Control[,] CalculateControlPositions (TableLayoutPanel
panel, int columns, int rows)
+ internal Control[,] CalculateControlPositions (TableLayoutPanel
panel, int columns, int rows)
{
Control[,] grid = new Control[columns, rows];
@@ -417,7 +417,7 @@
if (c.AutoSize)
preferred =
c.PreferredSize;
else
- preferred = c.Size;
+ preferred =
c.ExplicitBounds.Size;
int new_x = 0;
int new_y = 0;
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2007-12-13 17:32:05 UTC (rev 91244)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2007-12-13 17:36:25 UTC (rev 91245)
@@ -1,3 +1,7 @@
+2007-12-13 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * TableLayoutTest.cs: Add tests for bug #346246.
+
2007-12-11 Jonathan Pobst <[EMAIL PROTECTED]>
* ControlTest.cs: Add a test for bug #347282.
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
2007-12-13 17:32:05 UTC (rev 91244)
+++
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs
2007-12-13 17:36:25 UTC (rev 91245)
@@ -1159,6 +1159,110 @@
form.Refresh ();
form.Dispose ();
}
+
+ [Test] // bug #346246
+ public void AutoSizePanelVerical ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ TableLayoutPanel tlp = new TableLayoutPanel ();
+ tlp.AutoSize = true;
+ tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+ tlp.ColumnCount = 1;
+ tlp.ColumnStyles.Add (new ColumnStyle
(SizeType.Percent, 100F));
+ tlp.Location = new Point (12, 12);
+ tlp.Name = "tableLayoutPanel1";
+ tlp.RowCount = 2;
+ tlp.RowStyles.Add (new RowStyle (SizeType.Percent,
50F));
+ tlp.RowStyles.Add (new RowStyle (SizeType.Percent,
50F));
+ tlp.Size = new Size (139, 182);
+ tlp.TabIndex = 0;
+
+ f.Controls.Add (tlp);
+
+ Button b = new Button ();
+ b.Size = new Size (100, 100);
+ tlp.Controls.Add (b, 0, 0);
+
+ PictureBox p = new PictureBox ();
+ p.Size = new Size (100, 100);
+ tlp.Controls.Add (p,0,1);
+
+ f.Show ();
+
+ Assert.AreEqual (new Rectangle (12, 12, 106, 212),
tlp.Bounds, "A1");
+ Assert.AreEqual (new Rectangle (3, 3, 100, 100),
b.Bounds, "A2");
+ Assert.AreEqual (new Rectangle (3, 109, 100, 100),
p.Bounds, "A3");
+
+ b.Width += 20;
+ b.Height += 20;
+
+ Assert.AreEqual (new Rectangle (12, 12, 126, 252),
tlp.Bounds, "B1");
+ Assert.AreEqual (new Rectangle (3, 3, 120, 120),
b.Bounds, "B2");
+ Assert.AreEqual (new Rectangle (3, 129, 100, 100),
p.Bounds, "B3");
+
+ p.Width += 20;
+ p.Height += 20;
+
+ Assert.AreEqual (new Rectangle (12, 12, 126, 252),
tlp.Bounds, "C1");
+ Assert.AreEqual (new Rectangle (3, 3, 120, 120),
b.Bounds, "C2");
+ Assert.AreEqual (new Rectangle (3, 129, 120, 120),
p.Bounds, "C3");
+
+ f.Dispose ();
+ }
+
+ [Test] // bug #346246
+ public void AutoSizePanelHorizontal ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ TableLayoutPanel tlp = new TableLayoutPanel ();
+ tlp.AutoSize = true;
+ tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+ tlp.ColumnCount = 2;
+ tlp.ColumnStyles.Add (new ColumnStyle
(SizeType.Percent, 50F));
+ tlp.ColumnStyles.Add (new ColumnStyle
(SizeType.Percent, 50F));
+ tlp.Location = new Point (12, 12);
+ tlp.Name = "tableLayoutPanel1";
+ tlp.RowCount = 1;
+ tlp.RowStyles.Add (new RowStyle (SizeType.Percent,
100F));
+ tlp.Size = new Size (139, 182);
+ tlp.TabIndex = 0;
+
+ f.Controls.Add (tlp);
+
+ Button b = new Button ();
+ b.Size = new Size (100, 100);
+ tlp.Controls.Add (b, 0, 0);
+
+ PictureBox p = new PictureBox ();
+ p.Size = new Size (100, 100);
+ tlp.Controls.Add (p, 1, 0);
+
+ f.Show ();
+
+ Assert.AreEqual (new Rectangle (12, 12, 212, 106),
tlp.Bounds, "A1");
+ Assert.AreEqual (new Rectangle (3, 3, 100, 100),
b.Bounds, "A2");
+ Assert.AreEqual (new Rectangle (109, 3, 100, 100),
p.Bounds, "A3");
+
+ b.Width += 20;
+ b.Height += 20;
+
+ Assert.AreEqual (new Rectangle (12, 12, 252, 126),
tlp.Bounds, "B1");
+ Assert.AreEqual (new Rectangle (3, 3, 120, 120),
b.Bounds, "B2");
+ Assert.AreEqual (new Rectangle (129, 3, 100, 100),
p.Bounds, "B3");
+
+ p.Width += 20;
+ p.Height += 20;
+
+ Assert.AreEqual (new Rectangle (12, 12, 252, 126),
tlp.Bounds, "C1");
+ Assert.AreEqual (new Rectangle (3, 3, 120, 120),
b.Bounds, "C2");
+ Assert.AreEqual (new Rectangle (129, 3, 120, 120),
p.Bounds, "C3");
+
+ f.Dispose ();
+ }
}
}
#endif
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches