2007-08-28 Jonathan Pobst <monkey@jpobst.com>
[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 #if NET_2_0
29
30 using System;
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Reflection;
34
35 namespace System.Windows.Forms
36 {
37         public class AutoCompleteStringCollection : IList, ICollection, IEnumerable
38         {
39                 private ArrayList list = null;
40
41                 public AutoCompleteStringCollection ()
42                 {
43                         list = new ArrayList ();
44                 }
45
46                 public event CollectionChangeEventHandler CollectionChanged;
47
48                 protected void OnCollectionChanged (CollectionChangeEventArgs e)
49                 {
50                         if(CollectionChanged == null)
51                                 return;
52
53                         CollectionChanged (this, e);
54                 }
55
56                 #region IEnumerable Members
57
58                 public IEnumerator GetEnumerator ()
59                 {
60                         return list.GetEnumerator ();
61                 }
62
63                 #endregion
64
65                 #region ICollection Members
66
67                 void ICollection.CopyTo (Array array, int index)
68                 {
69                         list.CopyTo (array, index);
70                 }
71
72                 public void CopyTo (string[] array, int index)
73                 {
74                         list.CopyTo (array, index);
75                 }
76
77                 public int Count
78                 {
79                         get { return list.Count; }
80                 }
81
82                 public bool IsSynchronized
83                 {
84                         get { return false; }
85                 }
86
87                 public object SyncRoot
88                 {
89                         get { return this; }
90                 }
91
92                 #endregion
93
94                 #region IList Members
95
96                 int IList.Add (object value)
97                 {
98                         return Add ((string)value);
99                 }
100
101                 public int Add (string value)
102                 {
103                         int index = list.Add (value);
104                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
105                         return index;
106                 }
107
108                 public void AddRange (string[] value)
109                 {
110                         if (value == null)
111                                 throw new ArgumentNullException ("value", "Argument cannot be null!");
112
113                         list.AddRange (value);
114                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
115                 }
116
117                 public void Clear ()
118                 {
119                         list.Clear ();
120                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
121                 }
122
123                 bool IList.Contains (object value)
124                 {
125                         return Contains ((string)value);
126                 }
127
128                 public bool Contains (string value)
129                 {
130                         return list.Contains (value);
131                 }
132
133                 int IList.IndexOf (object value)
134                 {
135                         return IndexOf ((string)value);
136                 }
137
138                 public int IndexOf (string value)
139                 {
140                         return list.IndexOf (value);
141                 }
142
143                 void IList.Insert (int index, object value)
144                 {
145                         Insert (index, (string)value);
146                 }
147
148                 public void Insert (int index, string value)
149                 {
150                         list.Insert (index, value);
151                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
152                 }
153
154                 bool IList.IsFixedSize
155                 {
156                         get { return false; }
157                 }
158
159                 bool IList.IsReadOnly
160                 {
161                         get { return false; }
162                 }
163
164                 public bool IsReadOnly
165                 {
166                         get { return false; }
167                 }
168
169                 void IList.Remove (object value)
170                 {
171                         Remove((string)value);
172                 }
173
174                 public void Remove (string value)
175                 {
176                         list.Remove (value);
177                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
178                 }
179
180                 public void RemoveAt (int index)
181                 {
182                         string value = this[index];
183                         list.RemoveAt (index);
184                         OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
185                 }
186
187                 object IList.this[int index]
188                 {
189                         get { return this[index]; }
190                         set { this[index] = (string)value; }
191                 }
192
193                 public string this[int index]
194                 {
195                         get { return (string)list[index]; }
196                         set {
197                                 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, list[index]));
198                                 list[index] = value;
199                                 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
200                         }
201                 }
202                 #endregion
203         }
204 }
205 #endif