2007-01-03 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripComboBox.cs
index bc5dd05c052847df46b06309f9adf5db64969738..fc850a2cea5b105999b7598140bcc62c7c5e3616 100644 (file)
 #if NET_2_0
 using System.Drawing;
 using System.ComponentModel;
+using System.Windows.Forms.Design;
 
 namespace System.Windows.Forms
 {
        [DefaultProperty ("Items")]
+       [ToolStripItemDesignerAvailability (ToolStripItemDesignerAvailability.ToolStrip)]
        public class ToolStripComboBox : ToolStripControlHost
        {
                #region Public Constructors
@@ -39,6 +41,7 @@ namespace System.Windows.Forms
                {
                }
 
+               [EditorBrowsable (EditorBrowsableState.Never)]
                public ToolStripComboBox (Control c) : base (c)
                {
                        throw new NotSupportedException ();
@@ -46,17 +49,44 @@ namespace System.Windows.Forms
 
                public ToolStripComboBox (string name) : this ()
                {
-                       base.Control.Name = name;
+                       base.Name = name;
                }
                #endregion
 
                #region Public Properties
                [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public override Image BackgroundImage {
+                       get { return base.BackgroundImage; }
+                       set { base.BackgroundImage = value; }
+               }
+
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public override ImageLayout BackgroundImageLayout {
+                       get { return base.BackgroundImageLayout; }
+                       set { base.BackgroundImageLayout = value; }
+               }
+               
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public ComboBox ComboBox {
                        get { return (ComboBox)base.Control; }
                }
 
+               [MonoTODO ("Stub, will not actually affect anything.")]
+               [Browsable (false)]
+               [DefaultValue (106)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public int DropDownHeight {
+                       get { return 106; }
+                       set { }
+               }
+               
                [DefaultValue (ComboBoxStyle.DropDown)]
+               [RefreshProperties (RefreshProperties.All)]
                public ComboBoxStyle DropDownStyle {
                        get { return this.ComboBox.DropDownStyle; }
                        set { this.ComboBox.DropDownStyle = value; }
@@ -68,6 +98,7 @@ namespace System.Windows.Forms
                }
 
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool DroppedDown {
                        get { return this.ComboBox.DroppedDown; }
                        set { this.ComboBox.DroppedDown = value; }
@@ -81,6 +112,8 @@ namespace System.Windows.Forms
                }
 
                [Localizable (true)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
+               [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
                public ComboBox.ObjectCollection Items {
                        get { return this.ComboBox.Items; }
                }
@@ -100,31 +133,39 @@ namespace System.Windows.Forms
                }
 
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public int SelectedIndex {
                        get { return this.ComboBox.SelectedIndex; }
-                       set { this.ComboBox.SelectedIndex = value; }
+                       set {
+                               this.ComboBox.SelectedIndex = value;
+                               Text = Items [value].ToString ();
+                       }
                }
 
                [Bindable (true)]
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public Object SelectedItem {
                        get { return this.ComboBox.SelectedItem; }
                        set { this.ComboBox.SelectedItem = value; }
                }
 
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public string SelectedText {
                        get { return this.ComboBox.SelectedText; }
                        set { this.ComboBox.SelectedText = value; }
                }
 
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public int SelectionLength {
                        get { return this.ComboBox.SelectionLength; }
                        set { this.ComboBox.SelectionLength = value; }
                }
 
                [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public int SelectionStart {
                        get { return this.ComboBox.SelectionStart; }
                        set { this.ComboBox.SelectionStart = value; }
@@ -138,7 +179,7 @@ namespace System.Windows.Forms
                #endregion
 
                #region Protected Properties
-               protected internal override Padding DefaultMargin { get { return new Padding (2); } }
+               protected internal override Padding DefaultMargin { get { return new Padding (1, 0, 1, 0); } }
                protected override Size DefaultSize { get { return new Size (100, 22); } }
                #endregion
 
@@ -202,22 +243,30 @@ namespace System.Windows.Forms
                #region Protected Methods
                protected virtual void OnDropDown (EventArgs e)
                {
-                       if (DropDown != null) DropDown (this, e);
+                       EventHandler eh = (EventHandler)(Events [DropDownEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual void OnDropDownClosed (EventArgs e)
                {
-                       if (DropDownClosed != null) DropDownClosed (this, e);
+                       EventHandler eh = (EventHandler)(Events [DropDownClosedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual void OnDropDownStyleChanged (EventArgs e)
                {
-                       if (DropDownStyleChanged != null) DropDownStyleChanged (this, e);
+                       EventHandler eh = (EventHandler)(Events [DropDownStyleChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual void OnSelectedIndexChanged (EventArgs e)
                {
-                       if (SelectedIndexChanged != null) SelectedIndexChanged (this, e);
+                       EventHandler eh = (EventHandler)(Events [SelectedIndexChangedEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual void OnSelectionChangeCommitted (EventArgs e)
@@ -236,7 +285,9 @@ namespace System.Windows.Forms
 
                protected virtual void OnTextUpdate (EventArgs e)
                {
-                       if (TextUpdate != null) TextUpdate (this, e);
+                       EventHandler eh = (EventHandler)(Events [TextUpdateEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected override void OnUnsubscribeControlEvents (Control control)
@@ -246,14 +297,43 @@ namespace System.Windows.Forms
                #endregion
 
                #region Public Events
+               static object DropDownEvent = new object ();
+               static object DropDownClosedEvent = new object ();
+               static object DropDownStyleChangedEvent = new object ();
+               static object SelectedIndexChangedEvent = new object ();
+               static object TextUpdateEvent = new object ();
+
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
-               public event EventHandler DoubleClick;
-               public event EventHandler DropDown;
-               public event EventHandler DropDownClosed;
-               public event EventHandler DropDownStyleChanged;
-               public event EventHandler SelectedIndexChanged;
-               public event EventHandler TextUpdate;
+               public new event EventHandler DoubleClick {
+                       add { base.DoubleClick += value; }
+                       remove { base.DoubleClick -= value; }
+               }
+
+               public event EventHandler DropDown {
+                       add { Events.AddHandler (DropDownEvent, value); }
+                       remove { Events.RemoveHandler (DropDownEvent, value); }
+               }
+
+               public event EventHandler DropDownClosed {
+                       add { Events.AddHandler (DropDownClosedEvent, value); }
+                       remove { Events.RemoveHandler (DropDownClosedEvent, value); }
+               }
+
+               public event EventHandler DropDownStyleChanged {
+                       add { Events.AddHandler (DropDownStyleChangedEvent, value); }
+                       remove { Events.RemoveHandler (DropDownStyleChangedEvent, value); }
+               }
+
+               public event EventHandler SelectedIndexChanged {
+                       add { Events.AddHandler (SelectedIndexChangedEvent, value); }
+                       remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
+               }
+
+               public event EventHandler TextUpdate {
+                       add { Events.AddHandler (TextUpdateEvent, value); }
+                       remove { Events.RemoveHandler (TextUpdateEvent, value); }
+               }
                #endregion
 
                #region Private Methods
@@ -264,7 +344,7 @@ namespace System.Windows.Forms
 
                private void HandleDropDownStyleChanged (object sender, EventArgs e)
                {
-                       OnDisplayStyleChanged (e);
+                       OnDropDownStyleChanged (e);
                }
 
                private void HandleSelectedIndexChanged (object sender, EventArgs e)