Grasshopper project system now uses csproj extension
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripMenuItem.cs
index 1eadd46de969a7ebb9c00480d07b1916028537d4..4374b6353285de7a59faa68f7f2f3106bd07ab37 100644 (file)
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.Windows.Forms.Design;
 
 namespace System.Windows.Forms
 {
+       [ToolStripItemDesignerAvailability (ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
        public class ToolStripMenuItem : ToolStripDropDownItem
        {
                private CheckState checked_state;
                private bool check_on_click;
+               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 ()
@@ -86,6 +92,7 @@ namespace System.Windows.Forms
                #region Public Properties
                [Bindable (true)]
                [DefaultValue (false)]
+               [RefreshProperties (RefreshProperties.Repaint)]
                public bool Checked {
                        get {
                                switch (this.checked_state) {
@@ -100,8 +107,8 @@ namespace System.Windows.Forms
                        set {
                                if (this.checked_state != (value ? CheckState.Checked : CheckState.Unchecked)) {
                                        this.checked_state = value ? CheckState.Checked : CheckState.Unchecked;
-                                       this.OnCheckedChanged (EventArgs.Empty);
                                        this.Invalidate ();
+                                       this.OnCheckedChanged (EventArgs.Empty);
                                }
                        }
                }
@@ -114,8 +121,8 @@ namespace System.Windows.Forms
 
                [Bindable (true)]
                [DefaultValue (CheckState.Unchecked)]
-               public CheckState CheckState
-               {
+               [RefreshProperties (RefreshProperties.Repaint)]
+               public CheckState CheckState {
                        get { return this.checked_state; }
                        set
                        {
@@ -123,8 +130,8 @@ namespace System.Windows.Forms
                                        throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for CheckState", value));
 
                                this.checked_state = value;
-                               OnCheckStateChanged (EventArgs.Empty);
                                this.Invalidate ();
+                               this.OnCheckStateChanged (EventArgs.Empty);
                        }
                }
 
@@ -132,6 +139,32 @@ namespace System.Windows.Forms
                        get { return base.Enabled; }
                        set { base.Enabled = value; }
                }
+
+               [Browsable (false)]
+               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 {
+                       get { return this.show_shortcut_keys; }
+                       set { this.show_shortcut_keys = value; }
+               }
+               
+               [MonoTODO ("Keyboard navigation not implemented.")]
+               [Localizable (true)]
+               public string ShortcutKeyDisplayString {
+                       get { return this.shortcut_display_string; }
+                       set { this.shortcut_display_string = value; }
+               }
+               
+               [MonoTODO ("Keyboard navigation not implemented.")]
+               [Localizable (true)]
+               public Keys ShortcutKeys {
+                       get { return this.shortcut_keys; }
+                       set { this.shortcut_keys = value; }
+               }
                #endregion
 
                #region Protected Properties
@@ -151,7 +184,9 @@ namespace System.Windows.Forms
                #region Protected Methods
                protected override ToolStripDropDown CreateDefaultDropDown ()
                {
-                       return base.CreateDefaultDropDown ();
+                       ToolStripDropDownMenu tsddm = new ToolStripDropDownMenu ();
+                       tsddm.OwnerItem = this;
+                       return tsddm;
                }
 
                protected override void Dispose (bool disposing)
@@ -161,12 +196,16 @@ namespace System.Windows.Forms
 
                protected virtual void OnCheckedChanged (EventArgs e)
                {
-                       if (CheckedChanged != null) CheckedChanged (this, e);
+                       EventHandler eh = (EventHandler)Events [CheckedChangedEvent];
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual void OnCheckStateChanged (EventArgs e)
                {
-                       if (CheckStateChanged != null) CheckStateChanged (this, e);
+                       EventHandler eh = (EventHandler)Events [CheckStateChangedEvent];
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected override void OnClick (EventArgs e)
@@ -174,14 +213,14 @@ namespace System.Windows.Forms
                        if (!this.Enabled)
                                return;
                                
-                       base.OnClick (e);
-
                        if (this.IsOnDropDown) {
                                if (this.HasDropDownItems)
                                        return;
 
                                this.HideDropDown (ToolStripDropDownCloseReason.ItemClicked);
+                               
                                (this.Parent as ToolStripDropDown).Close (ToolStripDropDownCloseReason.ItemClicked);
+                               ToolStripManager.FireAppFocusChanged (this.Parent);
 
                                Object parent = this.Parent;
 
@@ -200,8 +239,15 @@ namespace System.Windows.Forms
                                }
                        }
 
+                       if (this.IsMdiWindowListEntry) {
+                               this.mdi_client_form.MdiParent.MdiContainer.ActivateChild (this.mdi_client_form);
+                               return;
+                       }
+                       
                        if (this.check_on_click)
                                this.Checked = !this.Checked;
+
+                       base.OnClick (e);
                }
 
                protected override void OnDropDownHide (EventArgs e)
@@ -221,19 +267,19 @@ namespace System.Windows.Forms
 
                protected override void OnMouseDown (MouseEventArgs e)
                {
-                       base.OnMouseDown (e);
-
-                       if (this.HasDropDownItems)
+                       if (this.HasDropDownItems && Enabled)
                                if (!this.DropDown.Visible)
                                        this.ShowDropDown ();
+
+                       base.OnMouseDown (e);
                }
 
                protected override void OnMouseEnter (EventArgs e)
                {
-                       base.OnMouseEnter (e);
-
-                       if (this.IsOnDropDown && this.HasDropDownItems)
+                       if (this.IsOnDropDown && this.HasDropDownItems && Enabled)
                                this.ShowDropDown ();
+
+                       base.OnMouseEnter (e);
                }
 
                protected override void OnMouseLeave (EventArgs e)
@@ -243,7 +289,8 @@ namespace System.Windows.Forms
 
                protected override void OnMouseUp (MouseEventArgs e)
                {
-                       base.OnMouseUp (e);
+                       if (!this.HasDropDownItems && Enabled)
+                               base.OnMouseUp (e);
                }
 
                protected override void OnOwnerChanged (EventArgs e)
@@ -288,11 +335,33 @@ namespace System.Windows.Forms
                                return;
                        }
                }
+
+               protected internal override void SetBounds (Rectangle bounds)
+               {
+                       base.SetBounds (bounds);
+               }
                #endregion
 
                #region Public Events
-               public event EventHandler CheckedChanged;
-               public event EventHandler CheckStateChanged;
+               static object CheckedChangedEvent = new object ();
+               static object CheckStateChangedEvent = new object ();
+
+               public event EventHandler CheckedChanged {
+                       add { Events.AddHandler (CheckedChangedEvent, value); }
+                       remove {Events.RemoveHandler (CheckedChangedEvent, value); }
+               }
+
+               public event EventHandler CheckStateChanged {
+                       add { Events.AddHandler (CheckStateChangedEvent, value); }
+                       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
        }
 }