merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ComboBox.cs
index a5b2dfc621b7407396b16d9ecb3e21490c40d376..5c9d713b1307d32c6abae34a57b583abe2403a74 100644 (file)
@@ -22,8 +22,7 @@
 // Authors:
 //     Jordi Mas i Hernandez, jordi@ximian.com
 //     Mike Kestner  <mkestner@novell.com>
-//
-// NOT COMPLETE
+//     Daniel Nauck    (dna(at)mono-project(dot)de)
 
 using System;
 using System.Drawing;
@@ -37,10 +36,14 @@ using System.Runtime.InteropServices;
 
 namespace System.Windows.Forms
 {
-
        [DefaultProperty("Items")]
        [DefaultEvent("SelectedIndexChanged")]
        [Designer ("System.Windows.Forms.Design.ComboBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+#if NET_2_0
+       [DefaultBindingProperty ("Text")]
+       [ClassInterface (ClassInterfaceType.AutoDispatch)]
+       [ComVisible(true)]
+#endif
        public class ComboBox : ListControl
        {
                private DrawMode draw_mode = DrawMode.Normal;
@@ -67,6 +70,11 @@ namespace System.Windows.Forms
                private Rectangle button_area;
                private Rectangle listbox_area;
                private const int button_width = 16;
+#if NET_2_0
+               private AutoCompleteStringCollection auto_complete_custom_source = null;
+               private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
+               private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
+#endif
 
                [ComVisible(true)]
                public class ChildAccessibleObject : AccessibleObject {
@@ -155,6 +163,70 @@ namespace System.Windows.Forms
                #endregion Events
 
                #region Public Properties
+#if NET_2_0
+               [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               [Localizable (true)]
+               [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design,
+                        "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+               public AutoCompleteStringCollection AutoCompleteCustomSource { 
+                       get {
+                               if(auto_complete_custom_source == null) {
+                                       auto_complete_custom_source = new AutoCompleteStringCollection ();
+                                       auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+                               }
+                               return auto_complete_custom_source;
+                       }
+                       set {
+                               if(auto_complete_custom_source == value)
+                                       return;
+
+                               if(auto_complete_custom_source != null) //remove eventhandler from old collection
+                                       auto_complete_custom_source.CollectionChanged -= new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+
+                               auto_complete_custom_source = value;
+
+                               if(auto_complete_custom_source != null)
+                                       auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+                       }
+               }
+
+               [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               [DefaultValue (AutoCompleteMode.None)]
+               public AutoCompleteMode AutoCompleteMode {
+                       get { return auto_complete_mode; }
+                       set {
+                               if(auto_complete_mode == value)
+                                       return;
+
+                               if((value < AutoCompleteMode.None) || (value > AutoCompleteMode.SuggestAppend))
+                                       throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
+
+                               auto_complete_mode = value;
+                       }
+               }
+
+               [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
+               [Browsable (true)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               [DefaultValue (AutoCompleteSource.None)]
+               public AutoCompleteSource AutoCompleteSource {
+                       get { return auto_complete_source; }
+                       set {
+                               if(auto_complete_source == value)
+                                       return;
+
+                               if(!Enum.IsDefined (typeof (AutoCompleteSource), value))
+                                       throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
+
+                               auto_complete_source = value;
+                       }
+               }
+#endif
                public override Color BackColor {
                        get { return base.BackColor; }
                        set {
@@ -244,8 +316,10 @@ namespace System.Windows.Forms
                                        
                                        CreateComboListBox ();
 
-                                       if (IsHandleCreated)
+                                       if (IsHandleCreated) {
                                                Controls.AddImplicit (listbox_ctrl);
+                                               listbox_ctrl.Visible = true;
+                                       }
                                } else {
                                        show_dropdown_button = true;
                                        button_state = ButtonState.Normal;
@@ -286,17 +360,22 @@ namespace System.Windows.Forms
                                        return;
                                        
                                if (value < 1)
-                                       throw new ArgumentException ("The DropDownWidth value is less than one");
+#if NET_2_0
+                                       throw new ArgumentOutOfRangeException ("DropDownWidth",
+                                               "The DropDownWidth value is less than one.");
+#else
+                                       throw new ArgumentException ("The DropDownWidth value is less than one.");
+#endif
 
-                               dropdown_width = value;                         
+                               dropdown_width = value;
                        }
                }
                
                [Browsable (false)]
-               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]              
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool DroppedDown {
                        get { 
-                               if (dropdown_style == ComboBoxStyle.Simple)                             
+                               if (dropdown_style == ComboBoxStyle.Simple)
                                        return true;
                                
                                return dropped_down;
@@ -351,8 +430,13 @@ namespace System.Windows.Forms
                                return item_height;
                        }
                        set {
-                               if (value < 0)
-                                       throw new ArgumentException ("The item height value is less than zero");
+                               if (value < 1)
+#if NET_2_0
+                                       throw new ArgumentOutOfRangeException ("ItemHeight",
+                                               "The item height value is less than one.");
+#else
+                                       throw new ArgumentException ("The item height value is less than one.");
+#endif
 
                                item_height_specified = true;
                                item_height = value;
@@ -365,7 +449,10 @@ namespace System.Windows.Forms
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
                [Localizable (true)]
-               [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]                
+               [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
+#if NET_2_0
+               [MergableProperty (false)]
+#endif
                public ComboBox.ObjectCollection Items {
                        get { return items; }
                }
@@ -480,7 +567,8 @@ namespace System.Windows.Forms
                                if (dropdown_style == ComboBoxStyle.DropDownList) 
                                        return 0;
                                
-                               return textbox_ctrl.SelectionLength;
+                               int result = textbox_ctrl.SelectionLength;
+                               return result == -1 ? 0 : result;
                        }
                        set {
                                if (dropdown_style == ComboBoxStyle.DropDownList) 
@@ -566,6 +654,9 @@ namespace System.Windows.Forms
                #endregion Public Properties
 
                #region Public Methods
+#if NET_2_0
+               [Obsolete ("This method has been deprecated")]
+#endif
                protected virtual void AddItemsCore (object[] value)
                {
                        
@@ -808,9 +899,11 @@ namespace System.Windows.Forms
                {
                        base.OnHandleCreated (e);
 
-                       if (listbox_ctrl != null)
+                       if (listbox_ctrl != null) {
                                Controls.AddImplicit (listbox_ctrl);
-                       
+                               listbox_ctrl.Visible = true;
+                       }
+
                        if (textbox_ctrl != null)
                                Controls.AddImplicit (textbox_ctrl);
 
@@ -885,6 +978,41 @@ namespace System.Windows.Forms
                                item_heights.Remove (Items [index]);
                }
 
+#if NET_2_0
+               protected override bool ProcessKeyEventArgs (ref Message m)
+               {
+                       return base.ProcessKeyEventArgs (ref m);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override void OnKeyDown (KeyEventArgs e)
+               {
+                       base.OnKeyDown (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override void OnValidating (CancelEventArgs e)
+               {
+                       base.OnValidating (e);
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               protected override void OnTextChanged (EventArgs e)
+               {
+                       base.OnTextChanged (e);
+               }
+
+               protected override void OnMouseLeave (EventArgs e)
+               {
+                       base.OnMouseLeave (e);
+               }
+               
+               protected override void OnMouseEnter (EventArgs e)
+               {
+                       base.OnMouseEnter (e);
+               }
+#endif
+
                public void Select (int start, int length)
                {
                        if (start < 0)
@@ -983,6 +1111,13 @@ namespace System.Windows.Forms
                #endregion Public Methods
 
                #region Private Methods
+#if NET_2_0
+               void OnAutoCompleteCustomSourceChanged(object sender, CollectionChangeEventArgs e) {
+                       if(auto_complete_source == AutoCompleteSource.CustomSource) {
+                               //FIXME: handle add, remove and refresh events in AutoComplete algorithm.
+                       }
+               }
+#endif
 
                internal override bool InternalCapture {
                        get { return Capture; }
@@ -1268,8 +1403,13 @@ namespace System.Windows.Forms
                
                void UpdateComboBoxBounds ()
                {
-                       if (requested_height != -1)
-                               SetBounds (0, 0, 0, requested_height, BoundsSpecified.Height);
+                       if (requested_height == -1)
+                               return;
+
+                       // Save the requested height since set bounds can destroy it
+                       int save_height = requested_height;
+                       SetBounds (0, 0, 0, requested_height, BoundsSpecified.Height);
+                       requested_height = save_height;
                }
 
                private void UpdatedItems ()