using System.Windows.Forms;
using NUnit.Framework;
-
+#if NET_2_0
+using System.Collections.Generic;
+#endif
namespace MonoTests.System.Windows.Forms
{
[TestFixture]
- public class DefaultLayoutTest
+ public class DefaultLayoutTest : TestHelper
{
int event_count;
LayoutEventArgs most_recent_args;
Assert.AreEqual (new Rectangle (0, 0, 0, 0), c.Bounds, "N1");
}
+
+ [Test] // bug 81694
+ public void TestNestedControls ()
+ {
+ MainForm f = new MainForm ();
+ f.ShowInTaskbar = false;
+
+ f.Show ();
+ Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
+
+ f.Dispose ();
+ }
+
+ [Test] // bug 81695
+ public void TestNestedControls2 ()
+ {
+ MainForm f = new MainForm ();
+ f.ShowInTaskbar = false;
+
+ f.Show ();
+
+ Size s = f.Size;
+ f.Size = new Size (10, 10);
+ f.Size = s;
+
+ Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
+
+ f.Dispose ();
+ }
+
+ private class MainForm : Form
+ {
+ public UserControl1 _userControl;
+
+ public MainForm ()
+ {
+ SuspendLayout ();
+ //
+ // _userControl
+ //
+ _userControl = new UserControl1 ();
+ _userControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right);
+ _userControl.BackColor = Color.White;
+ _userControl.Location = new Point (8, 8);
+ _userControl.Size = new Size (288, 238);
+ _userControl.TabIndex = 0;
+ Controls.Add (_userControl);
+ //
+ // MainForm
+ //
+ ClientSize = new Size (304, 280);
+ Location = new Point (250, 100);
+ StartPosition = FormStartPosition.Manual;
+ Text = "bug #81694";
+ ResumeLayout (false);
+ }
+ }
+
+ private class UserControl1 : UserControl
+ {
+ private Button _button1;
+ public Button _button2;
+
+ public UserControl1 ()
+ {
+ SuspendLayout ();
+ //
+ // _button1
+ //
+ _button1 = new Button ();
+ _button1.Location = new Point (4, 4);
+ _button1.Size = new Size (75, 23);
+ _button1.TabIndex = 0;
+ _button1.Text = "Button1";
+ Controls.Add (_button1);
+ //
+ // _button2
+ //
+ _button2 = new Button ();
+ _button2.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
+ _button2.Location = new Point (210, 212);
+ _button2.Size = new Size (75, 23);
+ _button2.TabIndex = 1;
+ _button2.Text = "Button2";
+ Controls.Add (_button2);
+ //
+ // UserControl1
+ //
+ BackColor = Color.White;
+ ClientSize = new Size (288, 238);
+ ResumeLayout (false);
+ }
+ }
+
+#if NET_2_0
+ [Test]
+ public void TestDockFillWithPadding ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+ f.Padding = new Padding (15, 15, 15, 15);
+
+ Control c = new Control ();
+ c.Dock = DockStyle.Fill;
+ f.Controls.Add (c);
+
+ f.Show ();
+ Assert.AreEqual (new Size (f.ClientSize.Width - 30, f.ClientSize.Height - 30), c.Size, "K1");
+
+ f.Dispose ();
+ }
+#endif
+
+ [Test]
+ public void Bug82762 ()
+ {
+ if (TestHelper.RunningOnUnix)
+ Assert.Ignore ("WM Size dependent");
+
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ Button b = new Button ();
+ b.Size = new Size (100, 100);
+ b.Anchor = AnchorStyles.None;
+ f.Controls.Add (b);
+
+ f.Show ();
+
+ Assert.AreEqual (new Rectangle (0, 0, 100, 100), b.Bounds, "A1");
+
+ f.ClientSize = new Size (600, 600);
+
+ Assert.AreEqual (new Rectangle (158, 168, 100, 100), b.Bounds, "A2");
+
+ f.Close ();
+ f.Dispose ();
+ }
+
+ [Test]
+ public void Bug82805 ()
+ {
+ Control c1 = new Control ();
+ c1.Size = new Size (100, 100);
+ Control c2 = new Control ();
+ c2.Size = new Size (100, 100);
+
+ c2.SuspendLayout ();
+ c1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
+ c2.Controls.Add (c1);
+ c2.Size = new Size (200, 200);
+ c2.ResumeLayout ();
+
+ Assert.AreEqual (200, c1.Width, "A1");
+ }
+
+#if NET_2_0
+ [Test]
+ public void DockedAutoSizeControls ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ Button b = new Button ();
+ b.Text = "Yo";
+ b.AutoSize = true;
+ b.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+ b.Width = 200;
+ b.Dock = DockStyle.Left;
+ f.Controls.Add (b);
+
+ f.Show ();
+
+ if (b.Width >= 200)
+ Assert.Fail ("button should be less than 200 width: actual {0}", b.Width);
+
+ f.Close ();
+ f.Dispose ();
+ }
+#endif
+
+ [Test] // bug #81199
+ public void NestedControls ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ MyUserControl c = new MyUserControl ();
+ c.Dock = DockStyle.Fill;
+ c.Size = new Size (500, 500);
+
+ f.SuspendLayout ();
+ f.Controls.Add (c);
+ f.ClientSize = new Size (500, 500);
+ f.ResumeLayout (false);
+
+ f.Show ();
+
+ Assert.AreEqual (new Size (600, 600), c.lv.Size, "I1");
+ f.Close ();
+ }
+
+ private class MyUserControl : UserControl
+ {
+ public ListView lv;
+
+ public MyUserControl ()
+ {
+ lv = new ListView ();
+ SuspendLayout ();
+ lv.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
+ lv.Size = new Size (300, 300);
+
+ Controls.Add (lv);
+ Size = new Size (200, 200);
+ ResumeLayout (false);
+ }
+ }
}
[TestFixture]
- public class DockingTests
+ public class DockingTests : TestHelper
{
Form form;
Panel panel;
int event_count;
[SetUp]
- public void Init ()
- {
+ protected override void SetUp () {
form = new Form ();
form.ShowInTaskbar = false;
form.Size = new Size (400, 400);
panel = new Panel ();
form.Controls.Add (panel);
event_count = 0;
+ base.SetUp ();
}
[TearDown]
- public void Cleanup ()
- {
+ protected override void TearDown () {
form.Dispose ();
+ base.TearDown ();
}
void IncrementEventCount (object o, EventArgs args)
Assert.AreEqual (new Rectangle (0, 0, 200, f.ClientRectangle.Height), b2.Bounds, "B2");
f.Dispose ();
}
+
+ [Test] // bug #81397
+ public void TestDockingWithCustomDisplayRectangle ()
+ {
+ MyControl mc = new MyControl ();
+ mc.Size = new Size (200, 200);
+
+ Control c = new Control ();
+ c.Dock = DockStyle.Fill;
+
+ mc.Controls.Add (c);
+
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+
+ f.Controls.Add (mc);
+ f.Show ();
+
+ Assert.AreEqual (new Point (20, 20), c.Location, "A1");
+ Assert.AreEqual (new Size (160, 160), c.Size, "A2");
+
+ f.Dispose ();
+ }
+
+ private class MyControl : Control
+ {
+ public override Rectangle DisplayRectangle {
+ 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 ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+ f.ClientSize = new Size (300, 300);
+
+ Control c = new Control ();
+ c.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+
+ f.Controls.Add (c);
+
+ f.Show ();
+
+ f.ClientSize = new Size (350, 350);
+
+ Assert.IsTrue (c.Left > 0, string.Format ("A1: c.Left ({0}) must be greater than 0", c.Left));
+ Assert.IsTrue (c.Top > 0, string.Format ("A2: c.Top ({0}) must be greater than 0", c.Top));
+
+ c.Dock = DockStyle.None;
+ Assert.IsTrue (c.Left > 0, string.Format ("A3: c.Left ({0}) must be greater than 0", c.Left));
+ Assert.IsTrue (c.Top > 0, string.Format ("A4: c.Top ({0}) must be greater than 0", c.Top));
+
+ f.ClientSize = new Size (400, 400);
+ Assert.IsTrue (c.Left > 70, string.Format ("A5: c.Left ({0}) must be greater than 70", c.Left));
+ Assert.IsTrue (c.Top > 70, string.Format ("A6: c.Top ({0}) must be greater than 70", c.Top));
+
+ f.Dispose ();
+ }
}
[TestFixture]
- public class UndockingTests
+ public class UndockingTests : TestHelper
{
class TestPanel : Panel {
TestPanel panel;
[SetUp]
- public void Init ()
- {
+ protected override void SetUp () {
form = new Form ();
form.ShowInTaskbar = false;
form.Size = new Size (400, 400);
panel = new TestPanel ();
form.Controls.Add (panel);
+ base.SetUp ();
}
[TearDown]
- public void Cleanup ()
+ protected override void TearDown ()
{
form.Dispose ();
+ base.TearDown ();
}
[Test]
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
}
}