* ScrollableControl.cs: Add 2.0 stuffs.
2007-06-07 Jonathan Pobst <monkey@jpobst.com>
* ScrollableControl.cs: Add test for ScrollToControl.
svn path=/trunk/mcs/; revision=78848
+2007-06-07 Jonathan Pobst <monkey@jpobst.com>
+
+ * ScrollableControl.cs: Add 2.0 stuffs.
+
2007-06-06 Jonathan Pobst <monkey@jpobst.com>
* ScrollBar.cs: Add 2.0 stuffs.
base.ScaleCore(dx, dy);
}
+#if NET_2_0
+ protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
+ {
+ base.ScaleControl (factor, specified);
+ }
+
+ protected virtual Point ScrollToControl (Control activeControl)
+ {
+ int corner_x;
+ int corner_y;
+
+ Rectangle within = new Rectangle ();
+ within.Size = ClientSize;
+
+ if (vscrollbar.Visible)
+ within.Width -= vscrollbar.Width;
+
+ if (hscrollbar.Visible)
+ within.Height -= hscrollbar.Height;
+
+ // If the control is above the top or the left, move it down and right until it aligns
+ // with the top/left.
+ // If the control is below the bottom or to the right, move it up/left until it aligns
+ // with the bottom/right, but do never move it further than the top/left side.
+ int x_diff = 0, y_diff = 0;
+
+ if (activeControl.Top <= 0 || activeControl.Height >= within.Height)
+ y_diff = -activeControl.Top;
+ else if (activeControl.Bottom > within.Height)
+ y_diff = within.Height - activeControl.Bottom;
+
+ if (activeControl.Left <= 0 || activeControl.Width >= within.Width)
+ x_diff = -activeControl.Left;
+ else if (activeControl.Right > within.Width)
+ x_diff = within.Width - activeControl.Right;
+
+ corner_x = AutoScrollPosition.X + x_diff;
+ corner_y = AutoScrollPosition.Y + y_diff;
+
+ return new Point (corner_x, corner_y);
+ }
+#endif
+
protected void SetDisplayRectLocation(int x, int y) {
// This method is weird. MS documents that the scrollbars are not
// updated. We need to move stuff, but leave the scrollbars as is
num_of_children = Controls.Count;
for (int i = 0; i < num_of_children; i++) {
- Controls[i].Left -= XOffset;
- Controls[i].Top -= YOffset;
+ Controls[i].Location = new Point (Controls[i].Left - XOffset, Controls[i].Top - YOffset);
+ //Controls[i].Left -= XOffset;
+ //Controls[i].Top -= YOffset;
// Is this faster? Controls[i].Location -= new Size(XOffset, YOffset);
}
eh (this, se);
}
+ protected override void OnPaddingChanged (EventArgs e)
+ {
+ base.OnPaddingChanged (e);
+ }
+
protected override void OnPaintBackground (PaintEventArgs e)
{
base.OnPaintBackground (e);
+2007-06-07 Jonathan Pobst <monkey@jpobst.com>
+
+ * ScrollableControlTest.cs: Add test for ScrollToControl.
+
2007-06-06 Jonathan Pobst <monkey@jpobst.com>
* ScrollBarTest.cs, SplitterTest.cs: Add some 2.0 tests.
TestHelper.RemoveWarning (h);
}
[Test]
- public void AutoSize ()
+ public void AutoScroll ()
{
ScrollableControl sc = new ScrollableControl ();
Assert.IsFalse (sc.AutoScroll, "#A1");
Assert.AreEqual (Size.Empty, sc.AutoScrollMinSize, "#J1");
Assert.IsTrue (sc.AutoScroll, "#J2");
}
+
+#if NET_2_0
+ [Test]
+ public void MethodScrollToControl ()
+ {
+ Form f = new Form ();
+ f.ShowInTaskbar = false;
+ f.Show ();
+
+ PublicScrollableControl sc = new PublicScrollableControl ();
+ sc.Size = new Size (200, 200);
+ sc.AutoScroll = true;
+
+ f.Controls.Add (sc);
+
+ Button b = new Button ();
+ b.Top = 15;
+ sc.Controls.Add (b);
+
+ Button b2 = new Button ();
+ b2.Top = 340;
+ sc.Controls.Add (b2);
+
+ Button b3 = new Button ();
+ b3.Left = 280;
+ sc.Controls.Add (b3);
+
+ Assert.AreEqual (new Point (0, 0), sc.PublicScrollToControl (b), "A1");
+ Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A2");
+ Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A3");
+
+ sc.AutoScrollPosition = new Point (50, 70);
+
+ Assert.AreEqual (new Point (0, -15), sc.PublicScrollToControl (b), "A4");
+ Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A5");
+ Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A6");
+
+ sc.AutoScrollPosition = new Point (150, 150);
+
+ Assert.AreEqual (new Point (0, -15), sc.PublicScrollToControl (b), "A7");
+ Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A8");
+ Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A9");
+
+ f.Dispose ();
+ }
+
+ private class PublicScrollableControl : ScrollableControl
+ {
+ public Point PublicScrollToControl (Control activeControl)
+ {
+ return base.ScrollToControl (activeControl);
+ }
+ }
+#endif
}
}