2007-03-12 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripButton.cs
index 35c08bad9cda0d73347cc72007fcc32dc3b79bec..556a682c14216496c23e670d5fc302c8c46803c8 100644 (file)
 using System;
 using System.Drawing;
 using System.ComponentModel;
+using System.Windows.Forms.Design;
 
 namespace System.Windows.Forms
 {
+       [ToolStripItemDesignerAvailability (ToolStripItemDesignerAvailability.ToolStrip)]
        public class ToolStripButton : ToolStripItem
        {
                private CheckState checked_state;
@@ -40,12 +42,12 @@ namespace System.Windows.Forms
 
                #region Public Constructors
                public ToolStripButton ()
-                       : this (String.Empty, null, null, String.Empty)
+                       : this (null, null, null, String.Empty)
                {
                }
 
                public ToolStripButton (Image image)
-                       : this (String.Empty, image, null, String.Empty)
+                       : this (null, image, null, String.Empty)
                {
                }
 
@@ -73,9 +75,8 @@ namespace System.Windows.Forms
                #endregion
 
                #region Public Properties
-               [MonoTODO ("Need 2.0 ToolTip to implement tool tips.")]
                [DefaultValue (true)]
-               public bool AutoToolTip {
+               public new bool AutoToolTip {
                        get { return base.AutoToolTip; }
                        set { base.AutoToolTip = value; }
                }
@@ -100,6 +101,7 @@ namespace System.Windows.Forms
                                if (this.checked_state != (value ? CheckState.Checked : CheckState.Unchecked)) {
                                        this.checked_state = value ? CheckState.Checked : CheckState.Unchecked;
                                        this.OnCheckedChanged (EventArgs.Empty);
+                                       this.OnCheckStateChanged (EventArgs.Empty);
                                        this.Invalidate ();
                                }
                        }
@@ -115,12 +117,15 @@ namespace System.Windows.Forms
                public CheckState CheckState {
                        get { return this.checked_state; }
                        set {
-                               if (!Enum.IsDefined (typeof (CheckState), value))
-                                       throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for CheckState", value));
+                               if (this.checked_state != value) {
+                                       if (!Enum.IsDefined (typeof (CheckState), value))
+                                               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.checked_state = value;
+                                       this.OnCheckedChanged (EventArgs.Empty);
+                                       this.OnCheckStateChanged (EventArgs.Empty);
+                                       this.Invalidate ();
+                               }
                        }
                }
                #endregion
@@ -132,11 +137,17 @@ namespace System.Windows.Forms
                #region Public Methods
                public override Size GetPreferredSize (Size constrainingSize)
                {
-                       return base.GetPreferredSize (constrainingSize);
+                       Size retval = base.GetPreferredSize (constrainingSize);
+                       
+                       if (retval.Width < 23)
+                               retval.Width = 23;
+                               
+                       return retval;
                }
                #endregion
 
                #region Protected Methods
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                protected override AccessibleObject CreateAccessibilityInstance ()
                {
                        ToolStripItemAccessibleObject ao = new ToolStripItemAccessibleObject (this);
@@ -150,12 +161,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)
@@ -192,8 +207,18 @@ namespace System.Windows.Forms
                #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
        }
 }