Fix a few CRLF issues
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DefaultLayoutTest.cs
index 12193c0a366edab76932c7d57ac2e299ae9e5605..8387ff3812d8cbc2e4044a8a20f11988307c1d7c 100644 (file)
@@ -3,7 +3,9 @@ using System.Drawing;
 using System.Windows.Forms;
 
 using NUnit.Framework;
-
+#if NET_2_0
+using System.Collections.Generic;
+#endif
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
@@ -748,6 +750,53 @@ namespace MonoTests.System.Windows.Forms
                                get { return new Rectangle (20, 20, this.Width - 40, this.Height - 40); }
                        }
                }
+
+#if NET_2_0
+               [Test]
+               public void DockingPreferredSize ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.ClientSize = new Size (300, 300);
+
+                       C1 c1 = new C1 ();
+                       c1.Size = new Size (100, 100);
+                       c1.Dock = DockStyle.Left;
+
+                       f.Controls.Add (c1);
+                       f.Show ();
+
+                       Assert.AreEqual (new Size (100, 300), c1.Size, "A1");
+
+                       f.Controls.Clear ();
+                       C2 c2 = new C2 ();
+                       c2.Size = new Size (100, 100);
+                       c2.Dock = DockStyle.Left;
+
+                       f.Controls.Add (c2);
+                       Assert.AreEqual (new Size (100, 300), c1.Size, "A2");
+
+                       f.Dispose ();
+               }
+
+               private class C1 : Panel
+               {
+                       public override Size GetPreferredSize (Size proposedSize)
+                       {
+                               Console.WriteLine ("HOYO!");
+                               return new Size (200, 200);
+                       }
+               }
+
+               private class C2 : Panel
+               {
+                       public override Size GetPreferredSize (Size proposedSize)
+                       {
+                               return Size.Empty;
+                       }
+               }
+#endif
+
                [Test]
                public void ResettingDockToNone ()
                {
@@ -1035,5 +1084,125 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (37, panel.Top, "Top");
                        Assert.AreEqual (37, panel.Width, "Width");
                }
+
+#if NET_2_0
+               [Test]
+               public void AutoSizeGrowOnlyControls_ShrinkWhenDocked ()
+               {
+                       // For most controls that are AutoSized and support the
+                       // AutoSizeMode property, if they are set to GrowOnly,
+                       // they should not shrink.  However, they will shrink 
+                       // even in GrowOnly mode if they are docked.
+                       // Button is one exception to this rule.
+                       Form f = new Form ();
+                       f.ClientSize = new Size (300, 300);
+                       f.ShowInTaskbar = false;
+                       f.Show ();
+
+                       List<Type> types = new List<Type> ();
+                       types.Add (typeof (TableLayoutPanel));
+                       types.Add (typeof (FlowLayoutPanel));
+                       types.Add (typeof (ToolStripContentPanel));
+                       types.Add (typeof (Panel));
+                       types.Add (typeof (GroupBox));
+                       types.Add (typeof (UserControl));
+                       foreach (Type t in types) {
+                               Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
+                               c.AutoSize = true;
+                               t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
+                               c.Bounds = new Rectangle (5, 5, 100, 100);
+                               f.Controls.Add (c);
+                               Assert.AreEqual (100, c.Height, "1 " + t.Name);
+                               c.Dock = DockStyle.Top;
+                               Assert.IsFalse (100 == c.Height, "2 " + t.Name);
+                               f.Controls.Remove (c);
+                               c.Dispose ();
+                       }
+
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void AutoSizeGrowOnlyButtons_DoNotShrinkWhenDocked ()
+               {
+                       // For most controls that are AutoSized and support the
+                       // AutoSizeMode property, if they are set to GrowOnly,
+                       // they should not shrink.  However, they will shrink 
+                       // even in GrowOnly mode if they are docked.
+                       // Button is one exception to this rule.
+                       Form f = new Form ();
+                       f.ClientSize = new Size (300, 300);
+                       f.ShowInTaskbar = false;
+                       f.Show ();
+
+                       List<Type> types = new List<Type> ();
+                       types.Add (typeof (Button));
+                       foreach (Type t in types) {
+                               Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
+                               c.AutoSize = true;
+                               t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
+                               c.Bounds = new Rectangle (5, 5, 100, 100);
+                               f.Controls.Add (c);
+                               Assert.AreEqual (100, c.Height, "1 " + t.Name);
+                               c.Dock = DockStyle.Top;
+                               Assert.AreEqual (100, c.Height, "2 " + t.Name);
+                               f.Controls.Remove (c);
+                               c.Dispose ();
+                       }
+
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void AnchoredAutoSizedControls_SizeInCorrectDirection ()
+               {
+                       Form f = new Form ();
+                       f.ClientSize = new Size (300, 300);
+                       f.ShowInTaskbar = false;
+
+                       Panel p1 = new Panel ();
+                       p1.Bounds = new Rectangle (150, 150, 0, 0);
+                       p1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
+                       p1.AutoSize = true;
+                       f.Controls.Add (p1);
+
+                       Panel p2 = new Panel ();
+                       p2.Bounds = new Rectangle (150, 150, 0, 0);
+                       p2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+                       p2.AutoSize = true;
+                       f.Controls.Add (p2);
+
+                       Panel p3 = new Panel ();
+                       p3.Bounds = new Rectangle (150, 150, 0, 0);
+                       p3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
+                       p3.AutoSize = true;
+                       f.Controls.Add (p3);
+
+                       Panel p4 = new Panel ();
+                       p4.Bounds = new Rectangle (150, 150, 0, 0);
+                       p4.Anchor = AnchorStyles.None;
+                       p4.AutoSize = true;
+                       f.Controls.Add (p4);
+
+                       f.Show ();
+                       // cause the panels to grow
+                       p1.Controls.Add (new TextBox ());
+                       p2.Controls.Add (new TextBox ());
+                       p3.Controls.Add (new TextBox ());
+                       p4.Controls.Add (new TextBox ());
+                       f.PerformLayout ();
+
+                       Assert.AreEqual (150, p1.Top, "1");
+                       Assert.AreEqual (150, p1.Left, "2");
+                       Assert.AreEqual (150, p2.Bottom, "3");
+                       Assert.AreEqual (150, p2.Right, "4");
+                       Assert.AreEqual (150, p3.Top, "5");
+                       Assert.AreEqual (150, p3.Left, "6");
+                       Assert.AreEqual (150, p4.Top, "7");
+                       Assert.AreEqual (150, p4.Left, "8");
+
+                       f.Dispose ();
+               }
+#endif
        }
 }