2007-09-11 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Tue, 11 Sep 2007 14:47:56 +0000 (14:47 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Tue, 11 Sep 2007 14:47:56 +0000 (14:47 -0000)
* ToolStripManager.cs: When we have added MDI buttons onto a MenuStrip, we
can't let them count as real items when calculating where to merge in the
user's items.  [Fixed bug #82786]

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripManager.cs

index e8509e339d4be371c83b805de25c9ba8f818f1eb..fa8cce5b809aed6125b1d4eed8967be0a2ff3cf0 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-11  Jonathan Pobst  <monkey@jpobst.com>
+
+       * ToolStripManager.cs: When we have added MDI buttons onto a MenuStrip, we
+       can't let them count as real items when calculating where to merge in the
+       user's items.  [Fixed bug #82786]
+
 2007-09-10  Jonathan Pobst  <monkey@jpobst.com>
 
        * ToolStripMenuItem.cs: Add a parent type check so we don't crash on people
index e2137d5f8bcaae266b601186fc71900a617d2ab8..a2ac1f75a4909a697a5dcd7eead5561c66843139 100644 (file)
@@ -511,6 +511,8 @@ namespace System.Windows.Forms
                                        throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
                                }
                                
+                               value.recalculate_distances = true;
+                               
                                if (Contains (value)) {
                                        owner.PerformLayout();
                                        return;
index 9fd0776a4078f8c81652aca43de6b83723bed0fa..cb75136dada9fbfc66a355e3d335228082f6af23 100644 (file)
@@ -275,10 +275,10 @@ namespace System.Windows.Forms
 
                                                if (tsi.MergeIndex == -1)
                                                        continue;
-                                               else if (tsi.MergeIndex >= targetToolStrip.Items.Count)
+                                               else if (tsi.MergeIndex >= CountRealToolStripItems (targetToolStrip))
                                                        targetToolStrip.Items.AddNoOwnerOrLayout (tsi);                                         
                                                else
-                                                       targetToolStrip.Items.InsertNoOwnerOrLayout (tsi.MergeIndex, tsi);
+                                                       targetToolStrip.Items.InsertNoOwnerOrLayout (AdjustItemMergeIndex (targetToolStrip, tsi), tsi);
 
                                                tsi.Parent = targetToolStrip;
                                                
@@ -433,6 +433,28 @@ namespace System.Windows.Forms
                                toolstrips.Add (ts);
                }
 
+               // When we have merged in MDI items like the min/max/close buttons, we
+               // can't count them for the sake of menu merging or it will mess up
+               // where people are trying to put them
+               private static int AdjustItemMergeIndex (ToolStrip ts, ToolStripItem tsi)
+               {                       
+                       if (ts.Items[0] is MdiControlStrip.SystemMenuItem)
+                               return tsi.MergeIndex + 1;
+                               
+                       return tsi.MergeIndex;
+               }
+               
+               private static int CountRealToolStripItems (ToolStrip ts)
+               {
+                       int count = 0;
+                       
+                       foreach (ToolStripItem tsi in ts.Items)
+                               if (!(tsi is MdiControlStrip.ControlBoxMenuItem) && !(tsi is MdiControlStrip.SystemMenuItem))
+                                       count++;
+                                       
+                       return count; 
+               }
+               
                internal static ToolStrip GetNextToolStrip (ToolStrip ts, bool forward)
                {
                        lock (toolstrips) {