// 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;
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;
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 {
#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 {
CreateComboListBox ();
- if (IsHandleCreated)
+ if (IsHandleCreated) {
Controls.AddImplicit (listbox_ctrl);
+ listbox_ctrl.Visible = true;
+ }
} else {
show_dropdown_button = true;
button_state = ButtonState.Normal;
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;
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;
[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; }
}
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)
#endregion Public Properties
#region Public Methods
+#if NET_2_0
+ [Obsolete ("This method has been deprecated")]
+#endif
protected virtual void AddItemsCore (object[] value)
{
{
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);
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)
#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; }
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 ()