Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripItem.cs
index d6643e744c6dbf37fcae331a70e0e25ec2233596..68b6091cbaefa7a94373a957b115420ed05a2022 100644 (file)
 // Authors:
 //     Jonathan Pobst (monkey@jpobst.com)
 //
-#if NET_2_0
+
 
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
 
 namespace System.Windows.Forms
 {
@@ -37,6 +38,7 @@ namespace System.Windows.Forms
        [DefaultProperty ("Text")]
        [DesignTimeVisible (false)]
        [ToolboxItem (false)]
+       [Designer ("System.Windows.Forms.Design.ToolStripItemDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
        public abstract class ToolStripItem : Component, IDropTarget, IComponent, IDisposable
        {
                #region Private Variables
@@ -45,6 +47,7 @@ namespace System.Windows.Forms
                private bool allow_drop;
                private ToolStripItemAlignment alignment;
                private AnchorStyles anchor;
+               private bool available;
                private bool auto_size;
                private bool auto_tool_tip;
                private Color back_color;
@@ -69,6 +72,8 @@ namespace System.Windows.Forms
                internal bool is_pressed;
                private bool is_selected;
                private Padding margin;
+               private MergeAction merge_action;
+               private int merge_index;
                private string name;
                private ToolStripItemOverflow overflow;
                private ToolStrip owner;
@@ -76,13 +81,16 @@ namespace System.Windows.Forms
                private Padding padding;
                private ToolStripItemPlacement placement;
                private RightToLeft right_to_left;
+               private bool right_to_left_auto_mirror_image;
                private Object tag;
                private string text;
                private ContentAlignment text_align;
+               private ToolStripTextDirection text_direction;
                private TextImageRelation text_image_relation;
                private string tool_tip_text;
                private bool visible;
 
+               private EventHandler frame_handler;     // For animating images
                private ToolStrip parent;
                private Size text_size;
                #endregion
@@ -104,14 +112,14 @@ namespace System.Windows.Forms
                        this.anchor = AnchorStyles.Left | AnchorStyles.Top;
                        this.auto_size = true;
                        this.auto_tool_tip = this.DefaultAutoToolTip;
-                       this.back_color = Control.DefaultBackColor;
+                       this.available = true;
+                       this.back_color = Color.Empty;
                        this.background_image_layout = ImageLayout.Tile;
                        this.can_select = true;
                        this.display_style = this.DefaultDisplayStyle;
                        this.dock = DockStyle.None;
                        this.enabled = true;
-                       this.font = new Font ("Tahoma", 8.25f);
-                       this.fore_color = Control.DefaultForeColor;
+                       this.fore_color = Color.Empty;
                        this.image = image;
                        this.image_align = ContentAlignment.MiddleCenter;
                        this.image_index = -1;
@@ -119,6 +127,8 @@ namespace System.Windows.Forms
                        this.image_scaling = ToolStripItemImageScaling.SizeToFit;
                        this.image_transparent_color = Color.Empty;
                        this.margin = this.DefaultMargin;
+                       this.merge_action = MergeAction.Append;
+                       this.merge_index = -1;
                        this.name = name;
                        this.overflow = ToolStripItemOverflow.AsNeeded;
                        this.padding = this.DefaultPadding;
@@ -127,6 +137,7 @@ namespace System.Windows.Forms
                        this.bounds.Size = this.DefaultSize;
                        this.text = text;
                        this.text_align = ContentAlignment.MiddleCenter;
+                       this.text_direction = DefaultTextDirection;
                        this.text_image_relation = TextImageRelation.ImageBeforeText;
                        this.visible = true;
 
@@ -197,7 +208,6 @@ namespace System.Windows.Forms
                        set { this.AccessibilityObject.role = value; }
                }
                
-               [MonoTODO]
                [DefaultValue (ToolStripItemAlignment.Left)]
                public ToolStripItemAlignment Alignment {
                        get { return this.alignment; }
@@ -205,26 +215,26 @@ namespace System.Windows.Forms
                                if (!Enum.IsDefined (typeof (ToolStripItemAlignment), value))
                                        throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripItemAlignment", value));
 
-                               this.alignment = value;
+                               if (this.alignment != value) {
+                                       this.alignment = value;
+                                       this.CalculateAutoSize (); 
+                               }
                        }
                }
 
-               [MonoTODO]
+               [MonoTODO ("Stub, does nothing")]
+               [Browsable (false)]
+               [DefaultValue (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual bool AllowDrop {
-                       get {
-                               return this.allow_drop;
-                       }
-                       
-                       set {
-                               this.allow_drop = value;
-                       }
+                       get { return this.allow_drop; }
+                       set { this.allow_drop = value; }
                }
                
                [Browsable (false)]
                [DefaultValue (AnchorStyles.Top | AnchorStyles.Left)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               public AnchorStyles Anchor
-               {
+               public AnchorStyles Anchor {
                        get { return this.anchor; }
                        set { this.anchor = value; }
                }
@@ -241,7 +251,6 @@ namespace System.Windows.Forms
                        }
                }
 
-               [MonoTODO ("Need 2.0 ToolTip to implement tool tips.")]
                [DefaultValue (false)]
                public bool AutoToolTip {
                        get { return this.auto_tool_tip; }
@@ -251,9 +260,10 @@ namespace System.Windows.Forms
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool Available {
-                       get { return this.visible; }
+                       get { return this.available; }
                        set {
-                               if (this.visible != value) {
+                               if (this.available != value) {
+                                       available = value;
                                        visible = value;
 
                                        if (this.parent != null)
@@ -266,7 +276,15 @@ namespace System.Windows.Forms
                }
 
                public virtual Color BackColor {
-                       get { return this.back_color; }
+                       get {
+                               if (back_color != Color.Empty)
+                                       return back_color;
+
+                               if (Parent != null)
+                                       return parent.BackColor;
+
+                               return Control.DefaultBackColor;
+                       }
                        set {
                                if (this.back_color != value) {
                                        back_color = value;
@@ -331,12 +349,11 @@ namespace System.Windows.Forms
                                        this.display_style = value; 
                                        this.CalculateAutoSize (); 
                                        OnDisplayStyleChanged (EventArgs.Empty);
-                                       if (this.Parent != null)
-                                               this.Parent.PerformLayout ();
                                }
                        }
                }
 
+               [Browsable (false)]
                public bool IsDisposed {
                        get { return this.is_disposed; }
                }
@@ -365,7 +382,17 @@ namespace System.Windows.Forms
                [Localizable (true)]
                [DefaultValue (true)]
                public virtual bool Enabled {
-                       get { return enabled; }
+                       get { 
+                               if (Parent != null)
+                                       if (!Parent.Enabled)
+                                               return false;
+
+                               if (Owner != null)
+                                       if (!Owner.Enabled)
+                                               return false;
+                                               
+                               return enabled;
+                       }
                        set { 
                                if (this.enabled != value) {
                                        this.enabled = value; 
@@ -376,9 +403,16 @@ namespace System.Windows.Forms
                }
 
                [Localizable (true)]
-               public virtual Font Font
-               {
-                       get { return this.font; }
+               public virtual Font Font {
+                       get { 
+                               if (font != null)
+                                       return font;
+                                       
+                               if (Parent != null)
+                                       return Parent.Font;
+                                       
+                               return DefaultFont;
+                       }
                        set { 
                                if (this.font != value) {
                                        this.font = value; 
@@ -390,7 +424,15 @@ namespace System.Windows.Forms
                }
 
                public virtual Color ForeColor {
-                       get { return this.fore_color; }
+                       get { 
+                               if (fore_color != Color.Empty)
+                                       return fore_color;
+                                       
+                               if (Parent != null)
+                                       return parent.ForeColor;
+                                       
+                               return Control.DefaultForeColor;
+                       }
                        set { 
                                if (this.fore_color != value) {
                                        this.fore_color = value; 
@@ -406,7 +448,7 @@ namespace System.Windows.Forms
                public int Height {
                        get { return this.Size.Height; }
                        set { 
-                               this.bounds.Height = value
+                               this.Size = new Size (this.Size.Width, value)
                                this.explicit_size.Height = value;
                                
                                if (this.Visible) {
@@ -424,23 +466,27 @@ namespace System.Windows.Forms
                                        return this.image;
                                        
                                if (this.image_index >= 0)
-                                       if (this.owner != null && this.owner.ImageList != null)
+                                       if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
                                                return this.owner.ImageList.Images[this.image_index];
 
 
                                if (!string.IsNullOrEmpty (this.image_key))
-                                       if (this.owner != null && this.owner.ImageList != null)
+                                       if (this.owner != null && this.owner.ImageList != null && this.owner.ImageList.Images.Count > this.image_index)
                                                return this.owner.ImageList.Images[this.image_key];
                                                
                                return null;
                        }
                        set {
                                if (this.image != value) {
+                                       StopAnimation ();
+                                       
                                        this.image = value; 
                                        this.image_index = -1;
                                        this.image_key = string.Empty;
                                        this.CalculateAutoSize (); 
                                        this.Invalidate ();
+                                       
+                                       BeginAnimation ();
                                }
                        }
                }
@@ -453,15 +499,19 @@ namespace System.Windows.Forms
                                if (!Enum.IsDefined (typeof (ContentAlignment), value))
                                        throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
 
-                               this.image_align = value;
-                               this.Invalidate ();
+                               if (image_align != value) {
+                                       this.image_align = value;
+                                       this.CalculateAutoSize (); 
+                               }
                        }
                }
 
                [Localizable (true)]
                [Browsable (false)]
                [RelatedImageList ("Owner.ImageList")]
+               [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
                [RefreshProperties (RefreshProperties.Repaint)]
+               [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
                public int ImageIndex {
                        get { return this.image_index; }
                        set {
@@ -482,9 +532,10 @@ namespace System.Windows.Forms
                [Localizable (true)]
                [Browsable (false)]
                [RelatedImageList ("Owner.ImageList")]
+               [TypeConverter (typeof (ImageKeyConverter))]
                [RefreshProperties (RefreshProperties.Repaint)]
-               public string ImageKey
-               {
+               [Editor ("System.Windows.Forms.Design.ToolStripImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
+               public string ImageKey {
                        get { return this.image_key; }
                        set { 
                                if (this.image_key != value) {
@@ -502,14 +553,14 @@ namespace System.Windows.Forms
                public ToolStripItemImageScaling ImageScaling {
                        get { return this.image_scaling; }
                        set { 
-                               this.image_scaling = value; 
-                               this.CalculateAutoSize (); 
-                               this.Invalidate (); 
+                               if (image_scaling != value) {
+                                       this.image_scaling = value; 
+                                       this.CalculateAutoSize (); 
+                               }
                        }
                }
 
                [Localizable (true)]
-               [MonoTODO ("Stub, doesn't actually do anything yet.")]
                public Color ImageTransparentColor {
                        get { return this.image_transparent_color; }
                        set { this.image_transparent_color = value; }
@@ -538,6 +589,23 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DefaultValue (MergeAction.Append)]
+               public MergeAction MergeAction {
+                       get { return this.merge_action; }
+                       set {
+                               if (!Enum.IsDefined (typeof (MergeAction), value))
+                                       throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for MergeAction", value));
+                                       
+                               this.merge_action = value;
+                       }
+               }
+
+               [DefaultValue (-1)]
+               public int MergeIndex {
+                       get { return this.merge_index; }
+                       set { this.merge_index = value; }
+               }
+
                [DefaultValue (null)]
                [Browsable (false)]
                public string Name {
@@ -567,9 +635,13 @@ namespace System.Windows.Forms
                        get { return this.owner; }
                        set { 
                                if (this.owner != value) {
-                                       this.owner = value; 
-                                       this.CalculateAutoSize (); 
-                                       OnOwnerChanged (EventArgs.Empty);
+                                       if (this.owner != null)
+                                               this.owner.Items.Remove (this);
+                                       
+                                       if (value != null)      
+                                               value.Items.Add (this);
+                                       else
+                                               this.owner = null;
                                }
                        }
                }
@@ -598,11 +670,28 @@ namespace System.Windows.Forms
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public virtual bool Pressed { get { return this.is_pressed; } }
 
-               [MonoTODO ("Stub, not implemented")]
+               [MonoTODO ("RTL not implemented")]
                [Localizable (true)]
                public virtual RightToLeft RightToLeft {
                        get { return this.right_to_left; }
-                       set { this.right_to_left = value; }
+                       set { 
+                               if (this.right_to_left != value) {
+                                       this.right_to_left = value;
+                                       this.OnRightToLeftChanged (EventArgs.Empty);
+                               }
+                       }
+               }
+               
+               [Localizable (true)]
+               [DefaultValue (false)]
+               public bool RightToLeftAutoMirrorImage {
+                       get { return this.right_to_left_auto_mirror_image; }
+                       set { 
+                               if (this.right_to_left_auto_mirror_image != value) {
+                                       this.right_to_left_auto_mirror_image = value;
+                                       this.Invalidate ();
+                               }
+                       }
                }
                
                [Browsable (false)]
@@ -645,9 +734,10 @@ namespace System.Windows.Forms
                        set { 
                                if (this.text != value) { 
                                        this.text = value; 
+                                       this.Invalidate (); 
                                        this.CalculateAutoSize (); 
+                                       this.Invalidate ();
                                        this.OnTextChanged (EventArgs.Empty); 
-                                       this.Invalidate (); 
                                } 
                        }
                }
@@ -659,9 +749,35 @@ namespace System.Windows.Forms
                        set {
                                if (!Enum.IsDefined (typeof (ContentAlignment), value))
                                        throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
-                               this.text_align = value;
-                               this.Invalidate ();
+
+                               if (this.text_align != value) {
+                                       this.text_align = value;
+                                       this.CalculateAutoSize (); 
+                               }
+                       }
+               }
+
+               public virtual ToolStripTextDirection TextDirection {
+                       get {
+                               if (this.text_direction == ToolStripTextDirection.Inherit) {
+                                       if (this.Parent != null)
+                                               return this.Parent.TextDirection;
+                                       else
+                                               return ToolStripTextDirection.Horizontal;
+                               }
+
+                               return this.text_direction;
                        }
+                       set {
+                               if (!Enum.IsDefined (typeof (ToolStripTextDirection), value))
+                                       throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ToolStripTextDirection", value));
+                               
+                               if (this.text_direction != value) {
+                                       this.text_direction = value;
+                                       this.CalculateAutoSize ();
+                                       this.Invalidate ();
+                               }
+                       }       
                }
 
                [Localizable (true)]
@@ -676,6 +792,8 @@ namespace System.Windows.Forms
                }
 
                [Localizable (true)]
+               [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
+                        "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                public string ToolTipText {
                        get { return this.tool_tip_text; }
                        set { this.tool_tip_text = value; }
@@ -691,7 +809,10 @@ namespace System.Windows.Forms
                        }
                        set { 
                                if (this.visible != value) {
+                                       this.available = value;
                                        this.SetVisibleCore (value);
+                                       if (this.Owner != null)
+                                               this.Owner.PerformLayout ();
                                }
                        }
                }
@@ -702,7 +823,7 @@ namespace System.Windows.Forms
                public int Width {
                        get { return this.Size.Width; }
                        set { 
-                               this.bounds.Width = value
+                               this.Size = new Size (value, this.Size.Height)
                                this.explicit_size.Width = value;
                                
                                if (this.Visible) {
@@ -726,15 +847,24 @@ namespace System.Windows.Forms
                protected internal ToolStrip Parent {
                        get { return this.parent; }
                        set { 
-                               ToolStrip old_parent = this.parent;
-                               this.parent = value; 
-                               OnParentChanged(old_parent, this.parent);
+                               if (this.parent != value) {
+                                       ToolStrip old_parent = this.parent;
+                                       this.parent = value; 
+                                       OnParentChanged(old_parent, this.parent);
+                               }
                        }
                }
                protected internal virtual bool ShowKeyboardCues { get { return false; } }
                #endregion
 
                #region Public Methods
+               [MonoTODO ("Stub, does nothing")]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public DragDropEffects DoDragDrop (Object data, DragDropEffects allowedEffects)
+               {
+                       return allowedEffects;
+               }
+               
                public ToolStrip GetCurrentParent ()
                { 
                        return this.parent; 
@@ -763,16 +893,16 @@ namespace System.Windows.Forms
                }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
-               public virtual void ResetBackColor () { this.BackColor = Control.DefaultBackColor; }
+               public virtual void ResetBackColor () { this.BackColor = Color.Empty; }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
                public virtual void ResetDisplayStyle () { this.display_style = this.DefaultDisplayStyle; }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
-               public virtual void ResetFont () { this.font = new Font ("Tahoma", 8.25f); }
+               public virtual void ResetFont () { this.font = null; }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
-               public virtual void ResetForeColor () { this.ForeColor = Control.DefaultForeColor; }
+               public virtual void ResetForeColor () { this.ForeColor = Color.Empty; }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
                public virtual void ResetImage () { this.image = null; }
@@ -783,12 +913,25 @@ namespace System.Windows.Forms
                [EditorBrowsable (EditorBrowsableState.Never)]
                public void ResetPadding () { this.padding = this.DefaultPadding; }
 
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
+               
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public virtual void ResetTextDirection () { this.TextDirection = this.DefaultTextDirection; }
+
                public void Select ()
                {
                        if (!this.is_selected && this.CanSelect) {
                                this.is_selected = true;
-                               this.Invalidate ();
-                               this.Parent.NotifySelectedChanged (this);
+                               
+                               if (this.Parent != null) {
+                                       if (this.Visible && this.Parent.Focused && this is ToolStripControlHost)
+                                               (this as ToolStripControlHost).Focus ();
+                                               
+                                       this.Invalidate ();
+                                       this.Parent.NotifySelectedChanged (this);
+                               }
+                               OnUIASelectionChanged ();
                        }
                }
 
@@ -809,10 +952,28 @@ namespace System.Windows.Forms
                {
                        if (!is_disposed && disposing)
                                is_disposed = true;
-                               
+
+                       if (image != null) {
+                               StopAnimation ();
+                               image = null;
+                       }
+
+                       if (owner != null)
+                               owner.Items.Remove (this);
+                       
                        base.Dispose (disposing);
                }
                
+               protected internal virtual bool IsInputChar (char charCode)
+               {
+                       return false;
+               }
+               
+               protected internal virtual bool IsInputKey (Keys keyData)
+               {
+                       return false;
+               }
+               
                protected virtual void OnAvailableChanged (EventArgs e)
                {
                        EventHandler eh = (EventHandler)(Events [AvailableChangedEvent]);
@@ -830,7 +991,7 @@ namespace System.Windows.Forms
 
                protected virtual void OnBoundsChanged ()
                {
-                       OnLayout (new LayoutEventArgs(null, ""));
+                       OnLayout (new LayoutEventArgs(null, string.Empty));
                }
 
                protected virtual void OnClick (EventArgs e)
@@ -853,29 +1014,38 @@ namespace System.Windows.Forms
                        EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
                        if (eh != null)
                                eh (this, e);
-
-                       if (!double_click_enabled)
-                               OnClick (e);
                }
 
-               void IDropTarget.OnDragDrop (DragEventArgs e)
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnDragDrop (DragEventArgs dragEvent)
                {
-                       // XXX
+                       DragEventHandler eh = (DragEventHandler)(Events[DragDropEvent]);
+                       if (eh != null)
+                               eh (this, dragEvent);
                }
 
-               void IDropTarget.OnDragEnter (DragEventArgs e)
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnDragEnter (DragEventArgs dragEvent)
                {
-                       // XXX
+                       DragEventHandler eh = (DragEventHandler)(Events[DragEnterEvent]);
+                       if (eh != null)
+                               eh (this, dragEvent);
                }
 
-               void IDropTarget.OnDragLeave (EventArgs e)
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnDragLeave (EventArgs e)
                {
-                       // XXX
+                       EventHandler eh = (EventHandler)(Events[DragLeaveEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
-               void IDropTarget.OnDragOver (DragEventArgs e)
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnDragOver (DragEventArgs dragEvent)
                {
-                       // XXX
+                       DragEventHandler eh = (DragEventHandler)(Events[DragOverEvent]);
+                       if (eh != null)
+                               eh (this, dragEvent);
                }
 
                protected virtual void OnEnabledChanged (EventArgs e)
@@ -898,6 +1068,14 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnGiveFeedback (GiveFeedbackEventArgs giveFeedbackEvent)
+               {
+                       GiveFeedbackEventHandler eh = (GiveFeedbackEventHandler)(Events[GiveFeedbackEvent]);
+                       if (eh != null)
+                               eh (this, giveFeedbackEvent);
+               }
+
                protected virtual void OnLayout (LayoutEventArgs e)
                {
                }
@@ -945,6 +1123,7 @@ namespace System.Windows.Forms
                                this.is_selected = false;
                                this.is_pressed = false;
                                this.Invalidate ();
+                               OnUIASelectionChanged ();
                        }
 
                        EventHandler eh = (EventHandler)(Events [MouseLeaveEvent]);
@@ -952,12 +1131,12 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
-               protected virtual void OnMouseMove (MouseEventArgs e)
+               protected virtual void OnMouseMove (MouseEventArgs mea)
                {
                        if (this.Enabled) {
                                MouseEventHandler eh = (MouseEventHandler)(Events [MouseMoveEvent]);
                                if (eh != null)
-                                       eh (this, e);
+                                       eh (this, mea);
                        }
                }
 
@@ -968,7 +1147,7 @@ namespace System.Windows.Forms
                                this.Invalidate ();
 
                                if (this.IsOnDropDown)
-                                       if (!(this is ToolStripDropDownItem) || (this as ToolStripDropDownItem).DropDown.Visible == false) {
+                                       if (!(this is ToolStripDropDownItem) || !(this as ToolStripDropDownItem).HasDropDownItems || (this as ToolStripDropDownItem).DropDown.Visible == false) {
                                                if ((this.Parent as ToolStripDropDown).OwnerItem != null)
                                                        ((this.Parent as ToolStripDropDown).OwnerItem as ToolStripDropDownItem).HideDropDown ();
                                                else
@@ -989,27 +1168,39 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected internal virtual void OnOwnerFontChanged (EventArgs e)
                {
+                       this.CalculateAutoSize ();
+                       OnFontChanged (EventArgs.Empty);
                }
-               
-               protected virtual void OnPaint (PaintEventArgs e)
+
+               void OnPaintInternal (PaintEventArgs e)
                {
+                       // Have the background rendered independently from OnPaint
                        if (this.parent != null)
                                this.parent.Renderer.DrawItemBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
-                               
+
+                       OnPaint (e);
+               }
+
+               protected virtual void OnPaint (PaintEventArgs e)
+               {
                        PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
                        if (eh != null)
                                eh (this, e);
                }
 
                // This is never called.
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnParentBackColorChanged (EventArgs e)
                {
                }
                
                protected virtual void OnParentChanged (ToolStrip oldParent, ToolStrip newParent)
                {
+                       this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty : this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
+                       
                        if (oldParent != null)
                                oldParent.PerformLayout ();
                                
@@ -1023,10 +1214,32 @@ namespace System.Windows.Forms
                }
 
                // This is never called.
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnParentForeColorChanged (EventArgs e)
                {
                }
-       
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected internal virtual void OnParentRightToLeftChanged (EventArgs e)
+               {
+                       this.OnRightToLeftChanged (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected virtual void OnQueryContinueDrag (QueryContinueDragEventArgs queryContinueDragEvent)
+               {
+                       QueryContinueDragEventHandler eh = (QueryContinueDragEventHandler)(Events[QueryContinueDragEvent]);
+                       if (eh != null)
+                               eh (this, queryContinueDragEvent);
+               }
+               
+               protected virtual void OnRightToLeftChanged (EventArgs e)
+               {
+                       EventHandler eh = (EventHandler)(Events[RightToLeftChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
+               }
+               
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected virtual void OnTextChanged (EventArgs e)
                {
@@ -1047,6 +1260,25 @@ namespace System.Windows.Forms
                        return false;
                }
                
+               protected internal virtual bool ProcessDialogKey (Keys keyData)
+               {
+                       if (this.Selected && keyData == Keys.Enter) {
+                               this.FireEvent (EventArgs.Empty, ToolStripItemEventType.Click);
+                               return true;
+                       }
+                               
+                       return false;
+               }
+               
+               // ProcessMnemonic will only be called if we are supposed to handle
+               // it.  None of that fancy "thinking" needed!
+               protected internal virtual bool ProcessMnemonic (char charCode)
+               {
+                       ToolStripManager.SetActiveToolStrip (this.Parent, true);
+                       this.PerformClick ();
+                       return true;
+               }
+               
                protected internal virtual void SetBounds (Rectangle bounds)
                {
                        if (this.bounds != bounds) {
@@ -1059,6 +1291,11 @@ namespace System.Windows.Forms
                {
                        this.visible = visible;
                        this.OnVisibleChanged (EventArgs.Empty);
+                       
+                       if (this.visible)
+                               BeginAnimation ();
+                       else
+                               StopAnimation ();
                        this.Invalidate ();
                }
                #endregion
@@ -1069,8 +1306,13 @@ namespace System.Windows.Forms
                static object ClickEvent = new object ();
                static object DisplayStyleChangedEvent = new object ();
                static object DoubleClickEvent = new object ();
+               static object DragDropEvent = new object ();
+               static object DragEnterEvent = new object ();
+               static object DragLeaveEvent = new object ();
+               static object DragOverEvent = new object ();
                static object EnabledChangedEvent = new object ();
                static object ForeColorChangedEvent = new object ();
+               static object GiveFeedbackEvent = new object ();
                static object LocationChangedEvent = new object ();
                static object MouseDownEvent = new object ();
                static object MouseEnterEvent = new object ();
@@ -1080,6 +1322,9 @@ namespace System.Windows.Forms
                static object MouseUpEvent = new object ();
                static object OwnerChangedEvent = new object ();
                static object PaintEvent = new object ();
+               static object QueryAccessibilityHelpEvent = new object ();
+               static object QueryContinueDragEvent = new object ();
+               static object RightToLeftChangedEvent = new object ();
                static object TextChangedEvent = new object ();
                static object VisibleChangedEvent = new object ();
 
@@ -1109,6 +1354,38 @@ namespace System.Windows.Forms
                        remove {Events.RemoveHandler (DoubleClickEvent, value); }
                }
 
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event DragEventHandler DragDrop {
+                       add { Events.AddHandler (DragDropEvent, value); }
+                       remove { Events.RemoveHandler (DragDropEvent, value); }
+               }
+
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event DragEventHandler DragEnter {
+                       add { Events.AddHandler (DragEnterEvent, value); }
+                       remove { Events.RemoveHandler (DragEnterEvent, value); }
+               }
+
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event EventHandler DragLeave {
+                       add { Events.AddHandler (DragLeaveEvent, value); }
+                       remove { Events.RemoveHandler (DragLeaveEvent, value); }
+               }
+
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event DragEventHandler DragOver {
+                       add { Events.AddHandler (DragOverEvent, value); }
+                       remove { Events.RemoveHandler (DragOverEvent, value); }
+               }
+
                public event EventHandler EnabledChanged {
                        add { Events.AddHandler (EnabledChangedEvent, value); }
                        remove {Events.RemoveHandler (EnabledChangedEvent, value); }
@@ -1119,6 +1396,14 @@ namespace System.Windows.Forms
                        remove {Events.RemoveHandler (ForeColorChangedEvent, value); }
                }
 
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event GiveFeedbackEventHandler GiveFeedback {
+                       add { Events.AddHandler (GiveFeedbackEvent, value); }
+                       remove { Events.RemoveHandler (GiveFeedbackEvent, value); }
+               }
+
                public event EventHandler LocationChanged {
                        add { Events.AddHandler (LocationChangedEvent, value); }
                        remove {Events.RemoveHandler (LocationChangedEvent, value); }
@@ -1164,6 +1449,25 @@ namespace System.Windows.Forms
                        remove {Events.RemoveHandler (PaintEvent, value); }
                }
 
+               [MonoTODO ("Event never raised")]
+               public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp {
+                       add { Events.AddHandler (QueryAccessibilityHelpEvent, value); }
+                       remove { Events.RemoveHandler (QueryAccessibilityHelpEvent, value); }
+               }
+
+               [MonoTODO ("Event never raised")]
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public event QueryContinueDragEventHandler QueryContinueDrag {
+                       add { Events.AddHandler (QueryContinueDragEvent, value); }
+                       remove { Events.RemoveHandler (QueryContinueDragEvent, value); }
+               }
+
+               public event EventHandler RightToLeftChanged {
+                       add { Events.AddHandler (RightToLeftChangedEvent, value); }
+                       remove { Events.RemoveHandler (RightToLeftChangedEvent, value); }
+               }
+               
                public event EventHandler TextChanged {
                        add { Events.AddHandler (TextChangedEvent, value); }
                        remove {Events.RemoveHandler (TextChangedEvent, value); }
@@ -1201,6 +1505,12 @@ namespace System.Windows.Forms
                {
                        this.text_size = TextRenderer.MeasureText (this.Text == null ? string.Empty: this.text, this.Font, Size.Empty, TextFormatFlags.HidePrefix);
 
+                       // If our text is rotated, flip the width and height
+                       ToolStripTextDirection direction = this.TextDirection;
+                       
+                       if (direction == ToolStripTextDirection.Vertical270 || direction == ToolStripTextDirection.Vertical90)
+                               this.text_size = new Size (this.text_size.Height, this.text_size.Width);
+                       
                        if (!this.auto_size || this is ToolStripControlHost)
                                return;
                        //this.text_size.Width += 6;
@@ -1228,16 +1538,16 @@ namespace System.Windows.Forms
                                        preferred_size = new Size (width, height);
                                        break;
                                case ToolStripItemDisplayStyle.Image:
-                                       if (this.Image == null)
+                                       if (this.GetImageSize () == Size.Empty)
                                                preferred_size = this.DefaultSize;
                                        else {
                                                switch (this.image_scaling) {
                                                        case ToolStripItemImageScaling.None:
-                                                               preferred_size = this.Image.Size;
+                                                               preferred_size = this.GetImageSize ();
                                                                break;
                                                        case ToolStripItemImageScaling.SizeToFit:
                                                                if (this.parent == null)
-                                                                       preferred_size = this.Image.Size;
+                                                                       preferred_size = this.GetImageSize ();
                                                                else
                                                                        preferred_size = this.parent.ImageScalingSize;
                                                                break;
@@ -1248,21 +1558,26 @@ namespace System.Windows.Forms
                                        int width2 = text_size.Width + this.padding.Horizontal;
                                        int height2 = text_size.Height + this.padding.Vertical;
 
-                                       if (this.Image != null) {
+                                       if (this.GetImageSize () != Size.Empty) {
+                                               Size image_size = this.GetImageSize ();
+                                               
+                                               if (this.image_scaling == ToolStripItemImageScaling.SizeToFit && this.parent != null)
+                                                       image_size = this.parent.ImageScalingSize;
+                                               
                                                switch (this.text_image_relation) {
                                                        case TextImageRelation.Overlay:
-                                                               width2 = Math.Max (width2, this.Image.Width);
-                                                               height2 = Math.Max (height2, this.Image.Height);
+                                                               width2 = Math.Max (width2, image_size.Width);
+                                                               height2 = Math.Max (height2, image_size.Height);
                                                                break;
                                                        case TextImageRelation.ImageAboveText:
                                                        case TextImageRelation.TextAboveImage:
-                                                               width2 = Math.Max (width2, this.Image.Width);
-                                                               height2 += this.Image.Height;
+                                                               width2 = Math.Max (width2, image_size.Width);
+                                                               height2 += image_size.Height;
                                                                break;
                                                        case TextImageRelation.ImageBeforeText:
                                                        case TextImageRelation.TextBeforeImage:
-                                                               height2 = Math.Max (height2, this.Image.Height);
-                                                               width2 += this.Image.Width;
+                                                               height2 = Math.Max (height2, image_size.Height);
+                                                               width2 += image_size.Width;
                                                                break;
                                                }
                                        }
@@ -1275,10 +1590,6 @@ namespace System.Windows.Forms
                                preferred_size.Height += 4;
                                preferred_size.Width += 4;
                        }
-                       
-                       // Account for ToolStripDropDownButton's drop down arrow
-                       if (this is ToolStripDropDownButton && (this as ToolStripDropDownButton).ShowDropDownArrow)
-                               preferred_size.Width += 9;
 
                        return preferred_size;
                }
@@ -1301,16 +1612,16 @@ namespace System.Windows.Forms
                                                text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
                                        break;
                                case ToolStripItemDisplayStyle.Image:
-                                       if (this.Image != null)
+                                       if (this.Image != null && this.UseImageMargin)
                                                image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
                                        break;
                                case ToolStripItemDisplayStyle.ImageAndText:
-                                       if (this.text != string.Empty && this.Image == null)
+                                       if (this.text != string.Empty && (this.Image == null || !this.UseImageMargin))
                                                text_rect = AlignInRectangle (contentRectangle, this.text_size, this.text_align);
+                                       else if (this.text == string.Empty && (this.Image == null || !this.UseImageMargin))
+                                               break;
                                        else if (this.text == string.Empty && this.Image != null)
                                                image_rect = AlignInRectangle (contentRectangle, GetImageSize (), this.image_align);
-                                       else if (this.text == string.Empty && this.Image == null)
-                                               break;
                                        else {
                                                Rectangle text_area;
                                                Rectangle image_area;
@@ -1346,6 +1657,27 @@ namespace System.Windows.Forms
                        }
                }
 
+               private static Font DefaultFont { get { return new Font ("Tahoma", 8.25f); } }
+               
+               internal virtual ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Inherit; } }
+
+               internal virtual void Dismiss (ToolStripDropDownCloseReason reason)
+               {
+                       if (is_selected) {
+                               this.is_selected = false;
+                               this.Invalidate ();
+                               OnUIASelectionChanged ();
+                       }
+               }
+               
+               internal virtual ToolStrip GetTopLevelToolStrip ()
+               {
+                       if (this.Parent != null)
+                               return this.Parent.GetTopLevelToolStrip ();
+                               
+                       return null;
+               }
+
                private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, ContentAlignment textAlign, ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
                {
                        int element_spacing = 0;        // Spacing between the Text and the Image
@@ -1400,34 +1732,51 @@ namespace System.Windows.Forms
                        return HorizontalAlignment.Left;
                }
                
-               private Size GetImageSize ()
+               internal Size GetImageSize ()
                {
-                       if (this.Image == null)
-                               return Size.Empty;
+                       // Get the actual size of our internal image -or-
+                       // Get the ImageList.ImageSize if we are using ImageLists
+                       if (this.image_scaling == ToolStripItemImageScaling.None) {
+                               if (this.image != null)
+                                       return image.Size;
+                                       
+                               if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
+                                       if (this.owner != null && this.owner.ImageList != null)
+                                               return this.owner.ImageList.ImageSize;
+                       } else {
+                               // If we have an image and a parent, return ImageScalingSize
+                               if (this.Parent == null)
+                                       return Size.Empty;
+                                       
+                               if (this.image != null)
+                                       return this.Parent.ImageScalingSize;
+
+                               if (this.image_index >= 0 || !string.IsNullOrEmpty (this.image_key))
+                                       if (this.owner != null && this.owner.ImageList != null)
+                                               return this.Parent.ImageScalingSize;
+                       }
                        
-                       if (this.image_scaling == ToolStripItemImageScaling.None)
-                               return this.Image.Size;
-                               
-                       if (this.Parent == null)
-                               return Size.Empty;
-                               
-                       return this.Parent.ImageScalingSize;
+                       return Size.Empty;
                }
                
                internal string GetToolTip ()
                {
                        if (this.auto_tool_tip && string.IsNullOrEmpty (this.tool_tip_text))
-                               return this.text;
+                               return this.Text;
                                
                        return this.tool_tip_text;
                }
                
                internal void FireEvent (EventArgs e, ToolStripItemEventType met)
                {
+                       // If we're disabled, don't fire any of these events, except Paint
+                       if (!this.Enabled && met != ToolStripItemEventType.Paint)
+                               return;
+                               
                        switch (met) {
                                case ToolStripItemEventType.MouseUp:
+                                       this.HandleClick (((MouseEventArgs)e).Clicks, e);
                                        this.OnMouseUp ((MouseEventArgs)e);
-                                       this.OnClick ((MouseEventArgs)e);
                                        break;
                                case ToolStripItemEventType.MouseDown:
                                        this.OnMouseDown ((MouseEventArgs)e);
@@ -1445,19 +1794,115 @@ namespace System.Windows.Forms
                                        this.OnMouseMove ((MouseEventArgs)e);
                                        break;
                                case ToolStripItemEventType.Paint:
-                                       this.OnPaint ((PaintEventArgs)e);
+                                       this.OnPaintInternal ((PaintEventArgs)e);
                                        break;
                                case ToolStripItemEventType.Click:
-                                       this.OnClick (e);
+                                       this.HandleClick (1, e);
                                        break;
                        }
                }
                
+               internal virtual void HandleClick (int mouse_clicks, EventArgs e)
+               {
+                       if (Parent == null)
+                               return;
+                       this.Parent.HandleItemClick (this);
+                       if (mouse_clicks == 2 && double_click_enabled)
+                               this.OnDoubleClick (e);
+                       else
+                               this.OnClick (e);
+               }
+               
                internal virtual void SetPlacement (ToolStripItemPlacement placement)
                {
                        this.placement = placement;
                }
 
+               private void BeginAnimation ()
+               {
+                       if (image != null && ImageAnimator.CanAnimate (image)) {
+                               frame_handler = new EventHandler (OnAnimateImage);
+                               ImageAnimator.Animate (image, frame_handler);
+                       }
+               }
+
+               private void OnAnimateImage (object sender, EventArgs e)
+               {
+                       // This is called from a worker thread,BeginInvoke is used
+                       // so the control is updated from the correct thread
+
+                       // Check if we have a handle again, since it may have gotten
+                       // destroyed since the last time we checked.
+                       if (Parent == null || !Parent.IsHandleCreated)
+                               return;
+
+                       Parent.BeginInvoke (new EventHandler (UpdateAnimatedImage), new object[] { this, e });
+               }
+
+               private void StopAnimation ()
+               {
+                       if (frame_handler == null)
+                               return;
+                               
+                       ImageAnimator.StopAnimate (image, frame_handler);
+                       frame_handler = null;
+               }
+
+               private void UpdateAnimatedImage (object sender, EventArgs e)
+               {
+                       // Check if we have a handle again, since it may have gotten
+                       // destroyed since the last time we checked.
+                       if (Parent == null || !Parent.IsHandleCreated)
+                               return;
+
+                       ImageAnimator.UpdateFrames (image);
+                       Invalidate ();
+               }
+
+               internal bool ShowMargin {
+                       get {
+                               if (!this.IsOnDropDown)
+                                       return true;
+
+                               if (!(this.Owner is ToolStripDropDownMenu))
+                                       return false;
+
+                               ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
+
+                               return tsddm.ShowCheckMargin || tsddm.ShowImageMargin;
+                       }
+               }
+
+               internal bool UseImageMargin {
+                       get {
+                               if (!this.IsOnDropDown)
+                                       return true;
+
+                               if (!(this.Owner is ToolStripDropDownMenu))
+                                       return false;
+
+                               ToolStripDropDownMenu tsddm = (ToolStripDropDownMenu)this.Owner;
+
+                               return tsddm.ShowImageMargin || tsddm.ShowCheckMargin;
+                       }
+               }
+
+               internal virtual bool InternalVisible {
+                       get { return this.visible; }
+                       set { this.visible = value; Invalidate (); }
+               }
+
+               internal ToolStrip InternalOwner {
+                       set {
+                               if (this.owner != value) {
+                                       this.owner = value;
+                                       if (this.owner != null)
+                                               this.CalculateAutoSize ();
+                                       OnOwnerChanged (EventArgs.Empty);
+                               }
+                       }
+               }
+
                internal Point Location {
                        get { return this.bounds.Location; }
                        set {
@@ -1491,10 +1936,51 @@ namespace System.Windows.Forms
                internal int Right { get { return this.bounds.Right; } }
                internal int Bottom { get { return this.bounds.Bottom; } }
                #endregion
+
+               #region IDropTarget Members
+               void IDropTarget.OnDragDrop (DragEventArgs dragEvent)
+               {
+                       OnDragDrop (dragEvent);
+               }
+
+               void IDropTarget.OnDragEnter (DragEventArgs dragEvent)
+               {
+                       OnDragEnter (dragEvent);
+               }
+
+               void IDropTarget.OnDragLeave (EventArgs e)
+               {
+                       OnDragLeave (e);
+               }
+
+               void IDropTarget.OnDragOver (DragEventArgs dragEvent)
+               {
+                       OnDragOver (dragEvent);
+               }
+               #endregion
+
+               #region UIA Framework: Methods, Properties and Events
+
+               static object UIASelectionChangedEvent = new object ();
+
+               internal event EventHandler UIASelectionChanged {
+                       add { Events.AddHandler (UIASelectionChangedEvent, value); }
+                       remove { Events.RemoveHandler (UIASelectionChangedEvent, value); }
+               }
+
+               internal void OnUIASelectionChanged ()
+               {
+                       EventHandler eh = (EventHandler)(Events [UIASelectionChangedEvent]);
+                       if (eh != null)
+                               eh (this, EventArgs.Empty);
+               }
                
+               #endregion
+
+               [ComVisible (true)]
                public class ToolStripItemAccessibleObject : AccessibleObject
                {
-                       private ToolStripItem owner_item;
+                       internal ToolStripItem owner_item;
                        
                        public ToolStripItemAccessibleObject (ToolStripItem ownerItem)
                        {
@@ -1565,14 +2051,14 @@ namespace System.Windows.Forms
                                base.DoDefaultAction ();
                        }
 
-                       public override int GetHelpTopic (out string FileName)
+                       public override int GetHelpTopic (out string fileName)
                        {
-                               return base.GetHelpTopic (out FileName);
+                               return base.GetHelpTopic (out fileName);
                        }
 
-                       public override AccessibleObject Navigate (AccessibleNavigation navdir)
+                       public override AccessibleObject Navigate (AccessibleNavigation navigationDirection)
                        {
-                               return base.Navigate (navdir);
+                               return base.Navigate (navigationDirection);
                        }
 
                        public override string ToString ()
@@ -1582,5 +2068,8 @@ namespace System.Windows.Forms
                        #endregion
                }
        }
+
+       internal class NoneExcludedImageIndexConverter : ImageIndexConverter
+       {
+       }
 }
-#endif