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 ()
#region Public Properties
[Bindable (true)]
[DefaultValue (false)]
+ [RefreshProperties (RefreshProperties.Repaint)]
public bool Checked {
get {
switch (this.checked_state) {
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);
}
}
}
[Bindable (true)]
[DefaultValue (CheckState.Unchecked)]
- public CheckState CheckState
- {
+ [RefreshProperties (RefreshProperties.Repaint)]
+ public CheckState CheckState {
get { return this.checked_state; }
set
{
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);
}
}
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
#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)
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)
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;
}
}
+ 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)
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)
protected override void OnMouseUp (MouseEventArgs e)
{
- base.OnMouseUp (e);
+ if (!this.HasDropDownItems && Enabled)
+ base.OnMouseUp (e);
}
protected override void OnOwnerChanged (EventArgs e)
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
}
}