Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / AutoCompleteStringCollection.cs
1 //
2 //  AutoCompleteStringCollection.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2006 Daniel Nauck
24 //
25 // Author:
26 //      Daniel Nauck    (dna(at)mono-project(dot)de)
27
28
29 using System;
30 using System.Collections;
31 using System.ComponentModel;
32 using System.Reflection;
33
34 namespace System.Windows.Forms
35 {
36         public class AutoCompleteStringCollection : IList, ICollection, IEnumerable
37         {
38                 private ArrayList list = null;
39
40                 public AutoCompleteStringCollection ()
41                 {
42                         list = new ArrayList ();
43                 }
44
45                 public event CollectionChangeEventHandler CollectionChanged;
46
47                 protected void OnCollectionChanged (CollectionChangeEventArgs e)
48                 {
49                         if(CollectionChanged == null)
50                                 return;
51
52                         CollectionChanged (this, e);
53                 }
54
55                 #region IEnumerable Members
56
57                 public IEnumerator GetEnumerator ()
58                 {
59                         return list.GetEnumerator ();
60                 }
61
62                 #endregion
63
64                 #region ICollection Members
65
66                 void ICollection.CopyTo (Array array, int index)
67                 {
68                         list.CopyTo (array, index);
69                 }
70
71                 public void CopyTo (string[] array, int index)
72                 {
73                         list.CopyTo (array, index);
74                 }
75
76                 public int Count
77                 {
78                         get { return list.Count; }
79                 }
80
81                 public bool IsSynchronized
82                 {
83                         get { return false; }
84                 }
85
86                 public object SyncRoot
87                 {
88                         get { return this; }
89                 }
90
91                 #endregion
92
93                 #region IList Members
94
95                 int IList.Add (object value)
96                 {
97                         return Add ((string)value);
98                 }
99
100                 public int Add (string value)
101                 {
102                         int index = list.Add (value);
103                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
104                         return index;
105                 }
106
107                 public void AddRange (string[] value)
108                 {
109                         if (value == null)
110                                 throw new ArgumentNullException ("value", "Argument cannot be null!");
111
112                         list.AddRange (value);
113                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
114                 }
115
116                 public void Clear ()
117                 {
118                         list.Clear ();
119                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
120                 }
121
122                 bool IList.Contains (object value)
123                 {
124                         return Contains ((string)value);
125                 }
126
127                 public bool Contains (string value)
128                 {
129                         return list.Contains (value);
130                 }
131
132                 int IList.IndexOf (object value)
133                 {
134                         return IndexOf ((string)value);
135                 }
136
137                 public int IndexOf (string value)
138                 {
139                         return list.IndexOf (value);
140                 }
141
142                 void IList.Insert (int index, object value)
143                 {
144                         Insert (index, (string)value);
145                 }
146
147                 public void Insert (int index, string value)
148                 {
149                         list.Insert (index, value);
150                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
151                 }
152
153                 bool IList.IsFixedSize
154                 {
155                         get { return false; }
156                 }
157
158                 bool IList.IsReadOnly
159                 {
160                         get { return false; }
161                 }
162
163                 public bool IsReadOnly
164                 {
165                         get { return false; }
166                 }
167
168                 void IList.Remove (object value)
169                 {
170                         Remove((string)value);
171                 }
172
173                 public void Remove (string value)
174                 {
175                         list.Remove (value);
176                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
177                 }
178
179                 public void RemoveAt (int index)
180                 {
181                         string value = this[index];
182                         list.RemoveAt (index);
183                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
184                 }
185
186                 object IList.this[int index]
187                 {
188                         get { return this[index]; }
189                         set { this[index] = (string)value; }
190                 }
191
192                 public string this[int index]
193                 {
194                         get { return (string)list[index]; }
195                         set {
196                                 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, list[index]));
197                                 list[index] = value;
198                                 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
199                         }
200                 }
201                 #endregion
202         }
203 }