Author: jpobst
Date: 2007-06-01 15:50:24 -0400 (Fri, 01 Jun 2007)
New Revision: 78452
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
Log:
2007-06-01 Jonathan Pobst <[EMAIL PROTECTED]>
* Control.cs: Perform layout when AutoSize changes.
* Form.cs: Implement AutoSizing.
2007-06-01 Jonathan Pobst <[EMAIL PROTECTED]>
* FormTest.cs: Add tests for AutoSize'ing.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-06-01 19:39:56 UTC (rev 78451)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-06-01 19:50:24 UTC (rev 78452)
@@ -1,3 +1,8 @@
+2007-06-01 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * Control.cs: Perform layout when AutoSize changes.
+ * Form.cs: Implement AutoSizing.
+
2007-06-01 Chris Toshok <[EMAIL PROTECTED]>
* DataGrid.cs: remove the XXX'ed check at the top of
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2007-06-01 19:39:56 UTC (rev 78451)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
2007-06-01 19:50:24 UTC (rev 78452)
@@ -2102,6 +2102,12 @@
set {
if (this.auto_size != value) {
auto_size = value;
+
+ // If we're turning this off, reset our
size
+ if (!value)
+ Size = explicit_bounds.Size;
+
+ PerformLayout (this, "AutoSize");
OnAutoSizeChanged (EventArgs.Empty);
}
}
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
2007-06-01 19:39:56 UTC (rev 78451)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
2007-06-01 19:50:24 UTC (rev 78452)
@@ -146,6 +146,32 @@
return cea.Cancel;
#endif
}
+
+#if NET_2_0
+ internal override Size GetPreferredSizeCore (Size proposedSize)
+ {
+ Size retsize = Size.Empty;
+
+ foreach (Control child in Controls) {
+ if (child.Dock == DockStyle.Fill) {
+ if (child.Bounds.Right > retsize.Width)
+ retsize.Width =
child.Bounds.Right;
+ }
+ else if (child.Dock != DockStyle.Top &&
child.Dock != DockStyle.Bottom && (child.Anchor & AnchorStyles.Right) == 0 &&
(child.Bounds.Right + child.Margin.Right) > retsize.Width)
+ retsize.Width = child.Bounds.Right +
child.Margin.Right;
+
+ if (child.Dock == DockStyle.Fill) {
+ if (child.Bounds.Bottom >
retsize.Height)
+ retsize.Height =
child.Bounds.Bottom;
+ }
+ else if (child.Dock != DockStyle.Left &&
child.Dock != DockStyle.Right && (child.Anchor & AnchorStyles.Bottom) == 0 &&
(child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height)
+ retsize.Height = child.Bounds.Bottom +
child.Margin.Bottom;
+ }
+
+ return retsize;
+ }
+#endif
+
internal void OnActivatedInternal ()
{
OnActivated (EventArgs.Empty);
@@ -445,6 +471,27 @@
}
}
+#if NET_2_0
+ public override bool AutoSize {
+ get { return base.AutoSize; }
+ set { base.AutoSize = value; }
+ }
+
+ [Localizable (true)]
+ public AutoSizeMode AutoSizeMode {
+ get { return base.GetAutoSizeMode (); }
+ set {
+ if (base.GetAutoSizeMode () != value) {
+ if (!Enum.IsDefined (typeof
(AutoSizeMode), value))
+ throw new
InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not
valid for AutoSizeMode", value));
+
+ base.SetAutoSizeMode (value);
+ PerformLayout (this, "AutoSizeMode");
+ }
+ }
+ }
+#endif
+
public override Color BackColor {
get {
/* we don't let parents override our
@@ -2965,6 +3012,26 @@
protected override void OnLayout (LayoutEventArgs levent)
{
base.OnLayout (levent);
+
+ if (this.AutoSize) {
+ if (this.AutoSizeMode ==
AutoSizeMode.GrowAndShrink)
+ this.ClientSize = GetPreferredSizeCore
(this.ClientSize);
+ else {
+ Size s = GetPreferredSizeCore
(this.ClientSize);
+
+ if (this.ClientSize.Height > s.Height)
+ s.Height =
this.ClientSize.Height;
+ if (this.ClientSize.Width > s.Width)
+ s.Width = this.ClientSize.Width;
+
+ if (!s.Equals (this.ClientSize)) {
+ Size NewSize =
InternalSizeFromClientSize (s);
+
+ if (NewSize != Size.Empty)
+ SetBounds (bounds.X,
bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.None);
+ }
+ }
+ }
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2007-06-01 19:39:56 UTC (rev 78451)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
2007-06-01 19:50:24 UTC (rev 78452)
@@ -1,3 +1,7 @@
+2007-06-01 Jonathan Pobst <[EMAIL PROTECTED]>
+
+ * FormTest.cs: Add tests for AutoSize'ing.
+
2007-05-23 Everaldo Canuto <[EMAIL PROTECTED]>
* LabelTest.cs: Fix SizeTest for 2.0 profile since autosize theres
Modified:
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
2007-06-01 19:39:56 UTC (rev 78451)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FormTest.cs
2007-06-01 19:50:24 UTC (rev 78452)
@@ -1757,6 +1757,67 @@
f.Dispose ();
}
+#if NET_2_0
+ [Test]
+ public void AutoSizeGrowOnly ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+ f.AutoSize = true;
+
+ Button b = new Button ();
+ b.Size = new Size (200, 200);
+ b.Location = new Point (200, 200);
+ f.Controls.Add (b);
+
+ f.Show ();
+
+ Assert.AreEqual (new Size (403, 403), f.ClientSize,
"A1");
+ }
+
+ [Test]
+ public void AutoSizeReset ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ Button b = new Button ();
+ b.Size = new Size (200, 200);
+ b.Location = new Point (200, 200);
+ f.Controls.Add (b);
+
+ f.Show ();
+
+ Size start_size = f.ClientSize;
+
+ f.AutoSize = true;
+ Assert.AreEqual (new Size (403, 403), f.ClientSize,
"A1");
+
+ f.AutoSize = false;
+ Assert.AreEqual (start_size, f.ClientSize, "A2");
+ }
+
+ [Test]
+ public void AutoSizeGrowAndShrink ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+ f.AutoSize = true;
+ f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+
+ f.Show ();
+
+ Assert.AreEqual (SystemInformation.MinimumWindowSize,
f.Size, "A1");
+
+ Button b = new Button ();
+ b.Size = new Size (200, 200);
+ b.Location = new Point (0, 0);
+ f.Controls.Add (b);
+
+ Assert.AreEqual (new Size (203, 203), f.ClientSize,
"A2");
+ }
+#endif
+
private class MockForm : Form
{
public bool CloseOnLoad {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches