Hello,
attached is the new version.
I also implemented "Locale.GetText (string msg, params object [] args)"
for MWF.
Please review.
by,
Daniel
Miguel de Icaza schrieb:
> ello,
>
>> Any suggestions?
>
> Instead of using String.Format for the calls that will throw a
> user-visible error, use Locale.GetText (it takes the same arguments).
> When we do localization, this will reduce the work we do at that time.
>
> In general, I do not like Enum.IsDefined because it boxes the value on
> every call. I would rather compare to upper/lower ranges which is
> faster (and besides, in Mono, we are guilty of not really doing Enum
> parameter checks in a number of places, which one day we might want to
> do).
>
> If this was a common pattern, I wonder if it would be worth having the
> compiler inline Enum.IsDefined to avoid the boxing? Worth considering.
>
> Miguel
Index: Test/System.Windows.Forms/ComboBoxTest.cs
===================================================================
--- Test/System.Windows.Forms/ComboBoxTest.cs (Revision 69846)
+++ Test/System.Windows.Forms/ComboBoxTest.cs (Arbeitskopie)
@@ -54,7 +54,7 @@
Assert.AreEqual (8, mycmbbox.MaxDropDownItems, "#8");
Assert.AreEqual (0, mycmbbox.MaxLength, "#9");
//Assert.AreEqual (20, mycmbbox.PreferredHeight, "#10");
-// Note: Item height depends on the current font.
+ // Note: Item height depends on the current font.
Assert.AreEqual (-1, mycmbbox.SelectedIndex, "#11");
Assert.AreEqual (null, mycmbbox.SelectedItem, "#12");
Assert.AreEqual ("", mycmbbox.SelectedText, "#13");
@@ -62,6 +62,14 @@
Assert.AreEqual (0, mycmbbox.SelectionStart, "#15");
Assert.AreEqual (false, mycmbbox.Sorted, "#16");
Assert.AreEqual ("", mycmbbox.Text, "#17");
+#if NET_2_0
+ Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#18");
+ Assert.AreEqual (AutoCompleteMode.None, mycmbbox.AutoCompleteMode, "#19");
+ Assert.AreEqual (AutoCompleteSource.None, mycmbbox.AutoCompleteSource, "#20");
+
+ mycmbbox.AutoCompleteCustomSource = null;
+ Assert.AreEqual (true, mycmbbox.AutoCompleteCustomSource != null, "#21");
+#endif
}
[Test]
Index: Test/System.Windows.Forms/TextBoxTest.cs
===================================================================
--- Test/System.Windows.Forms/TextBoxTest.cs (Revision 69846)
+++ Test/System.Windows.Forms/TextBoxTest.cs (Arbeitskopie)
@@ -87,6 +87,14 @@
Assert.AreEqual (ScrollBars.None, textBox.ScrollBars, "#24");
Assert.AreEqual (-1, textBox.SelectionLength, "#25");
Assert.AreEqual (HorizontalAlignment.Left , textBox.TextAlign, "#26");
+#if NET_2_0
+ Assert.AreEqual (true, textBox.AutoCompleteCustomSource != null, "#27");
+ Assert.AreEqual (AutoCompleteMode.None, textBox.AutoCompleteMode, "#28");
+ Assert.AreEqual (AutoCompleteSource.None, textBox.AutoCompleteSource, "#29");
+
+ textBox.AutoCompleteCustomSource = null;
+ Assert.AreEqual (true, textBox.AutoCompleteCustomSource != null, "#30");
+#endif
}
#if NET_2_0
Index: Assembly/Locale.cs
===================================================================
--- Assembly/Locale.cs (Revision 69846)
+++ Assembly/Locale.cs (Arbeitskopie)
@@ -67,6 +67,11 @@
return msg;
}
+ public static string GetText (string msg, params object [] args)
+ {
+ return String.Format (GetText (msg), args);
+ }
+
public static object GetResource(string name) {
return rm.GetObject(name);
}
Index: System.Windows.Forms/ComboBox.cs
===================================================================
--- System.Windows.Forms/ComboBox.cs (Revision 69846)
+++ System.Windows.Forms/ComboBox.cs (Arbeitskopie)
@@ -22,6 +22,7 @@
// Authors:
// Jordi Mas i Hernandez, [EMAIL PROTECTED]
// Mike Kestner <[EMAIL PROTECTED]>
+// Daniel Nauck (dna(at)mono-project(dot)de)
//
// NOT COMPLETE
@@ -37,10 +38,12 @@
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
+ [ComVisible(true)]
+#endif
public class ComboBox : ListControl
{
private DrawMode draw_mode = DrawMode.Normal;
@@ -67,6 +70,11 @@
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,68 @@
#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)]
+ 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 {
@@ -1020,6 +1090,13 @@
#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; }
Index: System.Windows.Forms/TextBox.cs
===================================================================
--- System.Windows.Forms/TextBox.cs (Revision 69846)
+++ System.Windows.Forms/TextBox.cs (Arbeitskopie)
@@ -21,8 +21,8 @@
//
// Authors:
// Peter Bartok [EMAIL PROTECTED]
+// Daniel Nauck (dna(at)mono-project(dot)de)
//
-//
// NOT COMPLETE
@@ -30,8 +30,15 @@
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
+#if NET_2_0
+using System.Runtime.InteropServices;
+#endif
namespace System.Windows.Forms {
+
+#if NET_2_0
+ [ComVisible(true)]
+#endif
public class TextBox : TextBoxBase {
#region Variables
private ContextMenu menu;
@@ -41,6 +48,12 @@
private MenuItem paste;
private MenuItem delete;
private MenuItem select_all;
+#if NET_2_0
+ private bool use_system_password_char = false;
+ private AutoCompleteStringCollection auto_complete_custom_source = null;
+ private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
+ private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
+#endif
#endregion // Variables
#region Public Constructors
@@ -80,12 +93,78 @@
private void TextBox_LostFocus(object sender, EventArgs e) {
Invalidate();
}
+#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
#endregion // Private & Internal Methods
#region Public Instance Properties
#if NET_2_0
- private bool use_system_password_char = false;
+ [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
+ [Browsable (true)]
+ [EditorBrowsable (EditorBrowsableState.Always)]
+ [Localizable (true)]
+ 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;
+ }
+ }
+
[DefaultValue(false)]
public bool UseSystemPasswordChar {
get {
_______________________________________________
Mono-winforms-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list