Author: jpobst
Date: 2007-01-03 16:08:05 -0500 (Wed, 03 Jan 2007)
New Revision: 70437

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiWindowManager.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs
Log:
2007-01-03  Jonathan Pobst  <[EMAIL PROTECTED]>

        * MenuStrip.cs, ToolStripMenuItem.cs: Add MdiWindowListItem
        property and implementation.

        * Form.cs, MdiClient.cs, MdiWindowManager.cs: Add needed hooks
        for MdiWindowListItem property.

        * ToolStripDropDown.cs: Don't consider hidden menu items while
        laying out the menu.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-01-03 20:57:26 UTC (rev 70436)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-01-03 21:08:05 UTC (rev 70437)
@@ -1,3 +1,14 @@
+2007-01-03  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * MenuStrip.cs, ToolStripMenuItem.cs: Add MdiWindowListItem
+       property and implementation.
+
+       * Form.cs, MdiClient.cs, MdiWindowManager.cs: Add needed hooks
+       for MdiWindowListItem property.
+
+       * ToolStripDropDown.cs: Don't consider hidden menu items while
+       laying out the menu.
+
 2007-01-03  Andreia Gaita  <[EMAIL PROTECTED]>
 
        * SendKeys.cs: window handle is not needed in win32, so just

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2007-01-03 20:57:26 UTC (rev 70436)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2007-01-03 21:08:05 UTC (rev 70437)
@@ -521,7 +521,12 @@
                [TypeConverter (typeof (ReferenceConverter))]
                public MenuStrip MainMenuStrip {
                        get { return this.main_menu_strip; }
-                       set { this.main_menu_strip = value; }
+                       set { 
+                               if (this.main_menu_strip != value) {
+                                       this.main_menu_strip = value;
+                                       this.main_menu_strip.RefreshMdiItems ();
+                               }
+                       }
                }
 #endif
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs     
2007-01-03 20:57:26 UTC (rev 70436)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiClient.cs     
2007-01-03 21:08:05 UTC (rev 70437)
@@ -753,6 +753,11 @@
 
                        setting_windowstates = false;
 
+#if NET_2_0
+                       if (form.MdiParent.MainMenuStrip != null)
+                               form.MdiParent.MainMenuStrip.RefreshMdiItems ();
+#endif
+
                        return maximize_this;
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiWindowManager.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiWindowManager.cs  
    2007-01-03 20:57:26 UTC (rev 70436)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MdiWindowManager.cs  
    2007-01-03 21:08:05 UTC (rev 70437)
@@ -98,6 +98,11 @@
                private void FormTextChangedHandler (object sender, EventArgs e)
                {
                        mdi_container.SetParentText (false);
+
+#if NET_2_0
+                       if (form.MdiParent.MainMenuStrip != null)
+                               form.MdiParent.MainMenuStrip.RefreshMdiItems ();
+#endif
                }
 
                private void FormLocationChangedHandler (object sender, 
EventArgs e)
@@ -356,6 +361,11 @@
                private void FormClosed (object sender, EventArgs e)
                {
                        mdi_container.CloseChildForm (form);
+
+#if NET_2_0
+                       if (form.MdiParent.MainMenuStrip != null)
+                               form.MdiParent.MainMenuStrip.RefreshMdiItems ();
+#endif
                }
 
                public override void DrawMaximizedButtons (object sender, 
PaintEventArgs pe)

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs     
2007-01-03 20:57:26 UTC (rev 70436)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/MenuStrip.cs     
2007-01-03 21:08:05 UTC (rev 70437)
@@ -39,6 +39,7 @@
        public class MenuStrip : ToolStrip
        {
                private bool can_overflow;
+               private ToolStripMenuItem mdi_window_list_item;
 
                public MenuStrip () : base ()
                {
@@ -61,6 +62,16 @@
                        set { base.GripStyle = value; }
                }
 
+               public ToolStripMenuItem MdiWindowListItem {
+                       get { return this.mdi_window_list_item; }
+                       set { 
+                               if (this.mdi_window_list_item != value) {
+                                       this.mdi_window_list_item = value;
+                                       this.RefreshMdiItems ();
+                               }
+                       }
+               }
+               
                [DefaultValue (false)]
                public new bool ShowItemToolTips {
                        get { return base.ShowItemToolTips; }
@@ -155,6 +166,114 @@
                {
                        this.HideMenus (true, 
ToolStripDropDownCloseReason.AppClicked);
                }
+               
+               internal void RefreshMdiItems ()
+               {
+                       if (this.mdi_window_list_item == null)
+                               return;
+                       
+                       Form parent_form = this.FindForm ();
+                       
+                       if (parent_form == null || parent_form.MainMenuStrip != 
this)
+                               return;
+                               
+                       MdiClient mdi = parent_form.MdiContainer;
+                       
+                       // Make a copy so we can delete from the real one
+                       ToolStripItem[] loopitems = new 
ToolStripItem[this.mdi_window_list_item.DropDownItems.Count];
+                       this.mdi_window_list_item.DropDownItems.CopyTo 
(loopitems, 0);
+
+                       // If the mdi child has been removed, remove our menu 
item
+                       foreach (ToolStripItem tsi in loopitems)
+                               if (tsi is ToolStripMenuItem && (tsi as 
ToolStripMenuItem).IsMdiWindowListEntry)
+                                       if (!mdi.mdi_child_list.Contains ((tsi 
as ToolStripMenuItem).MdiClientForm) || !(tsi as 
ToolStripMenuItem).MdiClientForm.Visible)
+                                               
this.mdi_window_list_item.DropDownItems.Remove (tsi);
+
+                       // Add the new forms and update state
+                       for (int i = 0; i < mdi.mdi_child_list.Count; i++) {
+                               Form mdichild = (Form)mdi.mdi_child_list[i];
+                               ToolStripMenuItem tsi;
+                               
+                               if (!mdichild.Visible)
+                                       continue;
+                                       
+                               if ((tsi = FindMdiMenuItemOfForm (mdichild)) == 
null) {
+                                       if (CountMdiMenuItems () == 0 && 
this.mdi_window_list_item.DropDownItems.Count > 0)
+                                               
this.mdi_window_list_item.DropDownItems.Add (new ToolStripSeparator ());
+                                               
+                                       tsi = new ToolStripMenuItem ();
+                                       tsi.MdiClientForm = mdichild;
+                                       
this.mdi_window_list_item.DropDownItems.Add (tsi);
+                               }
+                               
+                               tsi.Text = string.Format ("&{0} {1}", i + 1, 
mdichild.Text);
+                               tsi.Checked = parent_form.ActiveMdiChild == 
mdichild;
+                       }
+                       
+                       // Check that everything is in the correct order
+                       if (NeedToReorderMdi ())
+                               ReorderMdiMenu ();
+               }
+               
+               private ToolStripMenuItem FindMdiMenuItemOfForm (Form f)
+               {
+                       // Not terribly efficient, but Mdi window lists 
shouldn't get too big
+                       foreach (ToolStripItem tsi in 
this.mdi_window_list_item.DropDownItems)
+                               if (tsi is ToolStripMenuItem && (tsi as 
ToolStripMenuItem).MdiClientForm == f)
+                                       return (ToolStripMenuItem)tsi;
+                                       
+                       return null;
+               }
+
+               private int CountMdiMenuItems ()
+               {
+                       int count = 0;
+                       
+                       foreach (ToolStripItem tsi in 
this.mdi_window_list_item.DropDownItems)
+                               if (tsi is ToolStripMenuItem && (tsi as 
ToolStripMenuItem).IsMdiWindowListEntry)
+                                       count++;
+                                       
+                       return count;
+               }
+               
+               private bool NeedToReorderMdi ()
+               {
+                       // Mdi menus must be: User Items, Separator, Mdi Items
+                       bool seenMdi = false;
+                       
+                       foreach (ToolStripItem tsi in 
this.mdi_window_list_item.DropDownItems) {
+                               if (tsi is ToolStripMenuItem) {
+                                       if (!(tsi as 
ToolStripMenuItem).IsMdiWindowListEntry) {
+                                               if (seenMdi)
+                                                       return true;
+                                       } else 
+                                               seenMdi = true;
+                               }
+                       }
+                       
+                       return false;
+               }
+               
+               private void ReorderMdiMenu ()
+               {
+                       ToolStripItem[] loopitems = new 
ToolStripItem[this.mdi_window_list_item.DropDownItems.Count];
+                       this.mdi_window_list_item.DropDownItems.CopyTo 
(loopitems, 0);
+
+                       this.mdi_window_list_item.DropDownItems.Clear ();
+
+                       foreach (ToolStripItem tsi in loopitems)
+                               if (tsi is ToolStripSeparator || !(tsi as 
ToolStripMenuItem).IsMdiWindowListEntry)
+                                       
this.mdi_window_list_item.DropDownItems.Add (tsi);
+       
+                       int count = 
this.mdi_window_list_item.DropDownItems.Count;
+                       
+                       if (count > 0 && 
!(this.mdi_window_list_item.DropDownItems[count - 1] is ToolStripSeparator))
+                               this.mdi_window_list_item.DropDownItems.Add 
(new ToolStripSeparator ());
+
+                       foreach (ToolStripItem tsi in loopitems)
+                               if (tsi is ToolStripMenuItem && (tsi as 
ToolStripMenuItem).IsMdiWindowListEntry)
+                                       
this.mdi_window_list_item.DropDownItems.Add (tsi);
+               }
                #endregion
        }
 }

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs 
    2007-01-03 20:57:26 UTC (rev 70436)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDown.cs 
    2007-01-03 21:08:05 UTC (rev 70437)
@@ -387,15 +387,21 @@
                        // Find the widest menu item
                        int widest = 0;
 
-                       foreach (ToolStripItem tsi in this.Items)
+                       foreach (ToolStripItem tsi in this.Items) {
+                               if (!tsi.Visible) 
+                                       continue;
                                if (tsi.GetPreferredSize (Size.Empty).Width > 
widest)
                                        widest = tsi.GetPreferredSize 
(Size.Empty).Width;
-
+                       }
+                       
                        int x = this.Padding.Left;
                        widest += 68 - this.Padding.Horizontal;
                        int y = this.Padding.Top;
 
                        foreach (ToolStripItem tsi in this.Items) {
+                               if (!tsi.Visible)
+                                       continue;
+
                                y += tsi.Margin.Top;
 
                                int height = 0;
@@ -614,7 +620,7 @@
 
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
-               public event ScrollEventHandler Scroll {
+               public new event ScrollEventHandler Scroll {
                        add { Events.AddHandler (ScrollEvent, value); }
                        remove { Events.RemoveHandler (ScrollEvent, value); }
                }

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs 
    2007-01-03 20:57:26 UTC (rev 70436)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs 
    2007-01-03 21:08:05 UTC (rev 70437)
@@ -40,6 +40,7 @@
                private string shortcut_display_string;
                private Keys shortcut_keys = Keys.None;
                private bool show_shortcut_keys = true;
+               private Form mdi_client_form;
 
                #region Public Constructors
                public ToolStripMenuItem ()
@@ -136,6 +137,10 @@
                        set { base.Enabled = value; }
                }
 
+               public bool IsMdiWindowListEntry {
+                       get { return this.mdi_client_form != null; }
+               }
+               
                [MonoTODO ("Renderer doesn't support shortcut keys yet, they 
will never show.")]
                [Localizable (true)]
                public bool ShowShortcutKeys {
@@ -228,6 +233,11 @@
                                }
                        }
 
+                       if (this.IsMdiWindowListEntry) {
+                               
this.mdi_client_form.MdiParent.MdiContainer.ActivateChild 
(this.mdi_client_form);
+                               return;
+                       }
+                       
                        if (this.check_on_click)
                                this.Checked = !this.Checked;
 
@@ -334,6 +344,13 @@
                        remove {Events.RemoveHandler (CheckStateChangedEvent, 
value); }
                }
                #endregion
+
+               #region Internal Properties
+               internal Form MdiClientForm {
+                       get { return this.mdi_client_form; }
+                       set { this.mdi_client_form = value; }
+               }
+               #endregion
        }
 }
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to