2007-04-24 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Tue, 24 Apr 2007 17:23:35 +0000 (17:23 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Tue, 24 Apr 2007 17:23:35 +0000 (17:23 -0000)
* ToolStrip.cs: Fully implement GetNextItem.  Call OnParentRightToLeftChanged
for each ToolStripItem when the parent's RightToLeftChanged is called.

2007-04-24  Jonathan Pobst  <monkey@jpobst.com>

* ToolStripDropDownTest.cs: Add Assert for default orientation.
* ToolStripTest.cs: Enable tests for CanOverflow and DefaultDropDownDirection.
Add test for GetNextItem.

svn path=/trunk/mcs/; revision=76204

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStrip.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ToolStripDropDownTest.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ToolStripTest.cs

index 00def3210e40b99a3b388a45212a9181152d1d20..c49633153e3fef7d1accb55032984b6bec3a3b32 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-24  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStrip.cs: Fully implement GetNextItem.  Call OnParentRightToLeftChanged
+       for each ToolStripItem when the parent's RightToLeftChanged is called.
+
 2007-04-24  Rolf Bjarne Kvinge <RKvinge@novell.com> 
 
        * ComboBox.cs: Forward ContextMenu to the underlying textbox, if any.
index fb229696de769e1d6730158d76b987577c28d612..d5916b18d25c7055474f6834b724ab5110c6dc34 100644 (file)
@@ -515,24 +515,88 @@ namespace System.Windows.Forms
                        if (!Enum.IsDefined (typeof (ArrowDirection), direction))
                                throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ArrowDirection", direction));
 
-                       int index = this.items.IndexOf (start);
-
+                       if (this.Items.Count == 1)
+                               return null;
+                               
+                       ToolStripItem current_best = null;
+                       int current_best_point;
+                       
                        switch (direction) {
-                               case ArrowDirection.Left:
-                               case ArrowDirection.Up:
-                                       if (index > 0)
-                                               return this.items[index - 1];
-       
-                                       return this.items[this.items.Count - 1];
                                case ArrowDirection.Right:
+                                       current_best_point = int.MaxValue;
+
+                                       if (start != null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Left >= start.Right && loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Left;
+                                                       }
+                                                       
+                                       if (current_best == null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Left < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Left;
+                                                       }
+                                                       
+                                       break;
+                               case ArrowDirection.Up:
+                                       current_best_point = int.MinValue;
+
+                                       if (start != null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Bottom <= start.Top && loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Top;
+                                                       }
+
+                                       if (current_best == null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Top > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Top;
+                                                       }
+
+                                       break;
+                               case ArrowDirection.Left:
+                                       current_best_point = int.MinValue;
+
+                                       if (start != null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Right <= start.Left && loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Left;
+                                                       }
+
+                                       if (current_best == null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Left > current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Left;
+                                                       }
+
+                                       break;
                                case ArrowDirection.Down:
-                                       if (index + 1 >= this.items.Count)
-                                               return this.items[0];
-
-                                       return this.items[index + 1];
+                                       current_best_point = int.MaxValue;
+
+                                       if (start != null) 
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Top >= start.Bottom && loop_tsi.Bottom < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Top;
+                                                       }
+
+                                       if (current_best == null)
+                                               foreach (ToolStripItem loop_tsi in this.DisplayedItems)
+                                                       if (loop_tsi.Top < current_best_point && loop_tsi.Visible && loop_tsi.CanSelect) {
+                                                               current_best = loop_tsi;
+                                                               current_best_point = loop_tsi.Top;
+                                                       }
+
+                                       break;
                        }
 
-                       return null;
+                       return current_best;
                }
 
                public void ResetMinimumSize ()
@@ -883,6 +947,9 @@ namespace System.Windows.Forms
                protected override void OnRightToLeftChanged (EventArgs e)
                {
                        base.OnRightToLeftChanged (e);
+
+                       foreach (ToolStripItem tsi in this.Items)
+                               tsi.OnParentRightToLeftChanged (e);
                }
 
                protected override void OnScroll (ScrollEventArgs se)
index 1b8b202fbc314d4a38ef1ff1829480c9958656b3..a70662d1a93e46d79f8eb69f67b7b108c1f1cc28 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-24  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStripDropDownTest.cs: Add Assert for default orientation.
+       * ToolStripTest.cs: Enable tests for CanOverflow and DefaultDropDownDirection.
+       Add test for GetNextItem.
+
 2007-04-24  Rolf Bjarne Kvinge <RKvinge@novell.com> 
 
        * MdiFormTest.cs: Added tests for #81409.
index 3111372f22998e58437d078a210fdf5f5036059c..c27d11a661e3ca3f296f7e8a7a3edddbd8d38682 100644 (file)
@@ -50,6 +50,7 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (true, tsdd.DropShadowEnabled, "A5");\r
                        Assert.AreEqual (false, tsdd.IsAutoGenerated, "A6");\r
                        Assert.AreEqual (1, tsdd.Opacity, "A7");\r
+                       Assert.AreEqual (Orientation.Horizontal, tsdd.Orientation, "A7-2");\r
                        Assert.AreEqual (null, tsdd.OwnerItem, "A8");\r
                        Assert.AreEqual (null, tsdd.Region, "A9");\r
                        Assert.AreEqual (RightToLeft.No, tsdd.RightToLeft, "A10");\r
index 743b25b35b45758e3d392feefa4a9992eaf46b7f..d47075c8233ca8629cace0b637119e1a9a56180b 100644 (file)
@@ -255,16 +255,16 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
                }
 
-               //[Test]
-               //public void PropertyCanOverflow ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               public void PropertyCanOverflow ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.CanOverflow = false;
-               //        Assert.AreEqual (false, ts.CanOverflow, "B1");
-               //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
-               //}
+                       ts.CanOverflow = false;
+                       Assert.AreEqual (false, ts.CanOverflow, "B1");
+                       Assert.AreEqual (string.Empty, ew.ToString (), "B2");
+               }
 
                [Test]
                public void PropertyCausesValidation ()
@@ -296,26 +296,26 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (string.Empty, ew.ToString (), "B3");
                }
 
-               //[Test]
-               //public void PropertyDefaultDropDownDirection ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               public void PropertyDefaultDropDownDirection ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
-               //        Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
-               //        Assert.AreEqual (string.Empty, ew.ToString (), "B2");
-               //}
+                       ts.DefaultDropDownDirection = ToolStripDropDownDirection.AboveLeft;
+                       Assert.AreEqual (ToolStripDropDownDirection.AboveLeft, ts.DefaultDropDownDirection, "B1");
+                       Assert.AreEqual (string.Empty, ew.ToString (), "B2");
+               }
 
-               //[Test]
-               //[ExpectedException (typeof (InvalidEnumArgumentException))]
-               //public void PropertyDefaultDropDownDirectionIEAE ()
-               //{
-               //        ToolStrip ts = new ToolStrip ();
-               //        EventWatcher ew = new EventWatcher (ts);
+               [Test]
+               [ExpectedException (typeof (InvalidEnumArgumentException))]
+               public void PropertyDefaultDropDownDirectionIEAE ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       EventWatcher ew = new EventWatcher (ts);
 
-               //        ts.DefaultDropDownDirection = (ToolStripDropDownDirection) 42;
-               //}
+                       ts.DefaultDropDownDirection = (ToolStripDropDownDirection)42;
+               }
 
                [Test]
                [ExpectedException (typeof (InvalidEnumArgumentException))]
@@ -634,6 +634,39 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (null, ts.PublicCreateLayoutSettings (ToolStripLayoutStyle.VerticalStackWithOverflow), "A5");
                }
                
+               [Test]
+               public void MethodGetNextItem ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ts.Items.Add ("Test Item 1");
+                       
+
+                       Assert.AreEqual (null, ts.GetNextItem (null, ArrowDirection.Right), "A1");
+                       Assert.AreEqual (null, ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A2");
+
+                       ts.Items.Add ("Test Item 2");
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A3");
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A4");
+
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.Controls.Add (ts);
+                       f.Show ();
+                       
+                       Assert.AreEqual (ts.Items[0], ts.GetNextItem (null, ArrowDirection.Right), "A5");
+                       Assert.AreEqual (ts.Items[1], ts.GetNextItem (ts.Items[0], ArrowDirection.Right), "A6");
+                       
+                       f.Dispose ();
+               }
+               
+               [Test]
+               [ExpectedException (typeof (InvalidEnumArgumentException))]
+               public void MethodGetNextItemIEAE ()
+               {
+                       ToolStrip ts = new ToolStrip ();
+                       ts.GetNextItem (null, (ArrowDirection)42);
+               }
+               
                [Test]
                public void TestToolStrip ()
                {