2007-06-07 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Thu, 7 Jun 2007 15:18:42 +0000 (15:18 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Thu, 7 Jun 2007 15:18:42 +0000 (15:18 -0000)
* 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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ScrollableControl.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ScrollableControlTest.cs

index 38feee9a9c2ae74623fe240a3f8c84b062050d47..8fd42a7f76a4d0330ed6b01cb657874881c6f00d 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 64a9a587a7dfc11eb9471650a426f88cd2fbf3e4..9fb95d7f6396c54c39f1212f3b348ad3774edefd 100644 (file)
@@ -632,6 +632,49 @@ namespace System.Windows.Forms {
                        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
@@ -952,8 +995,9 @@ namespace System.Windows.Forms {
                        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);
                        }
 
@@ -977,6 +1021,11 @@ namespace System.Windows.Forms {
                                eh (this, se);
                }
 
+               protected override void OnPaddingChanged (EventArgs e)
+               {
+                       base.OnPaddingChanged (e);
+               }
+               
                protected override void OnPaintBackground (PaintEventArgs e)
                {
                        base.OnPaintBackground (e);
index f97469a3a0af7a5ab9f88798b55fb9cd924d0827..aba52752d9de8eaf90500b484b08319444a0af82 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 328e33e85b55d2ba8154011ad4a7e8f0fbb308ec..fd2922e01a9cdf64481984a94f6033ac5eb6dbc6 100644 (file)
@@ -36,7 +36,7 @@ namespace MonoTests.System.Windows.Forms
                        TestHelper.RemoveWarning (h);
                }
                [Test]
-               public void AutoSize ()
+               public void AutoScroll ()
                {
                        ScrollableControl sc = new ScrollableControl ();
                        Assert.IsFalse (sc.AutoScroll, "#A1");
@@ -94,5 +94,59 @@ namespace MonoTests.System.Windows.Forms
                        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
        }
 }