PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/Managed.Windows.Forms/System.Windows.Forms/AutoCompleteStringCollection.cs

https://bitbucket.org/danipen/mono
C# | 203 lines | 140 code | 37 blank | 26 comment | 4 complexity | 9bc55f39acefbc035f74ca70d3e302ab MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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. using System;
  28. using System.Collections;
  29. using System.ComponentModel;
  30. using System.Reflection;
  31. namespace System.Windows.Forms
  32. {
  33. public class AutoCompleteStringCollection : IList, ICollection, IEnumerable
  34. {
  35. private ArrayList list = null;
  36. public AutoCompleteStringCollection ()
  37. {
  38. list = new ArrayList ();
  39. }
  40. public event CollectionChangeEventHandler CollectionChanged;
  41. protected void OnCollectionChanged (CollectionChangeEventArgs e)
  42. {
  43. if(CollectionChanged == null)
  44. return;
  45. CollectionChanged (this, e);
  46. }
  47. #region IEnumerable Members
  48. public IEnumerator GetEnumerator ()
  49. {
  50. return list.GetEnumerator ();
  51. }
  52. #endregion
  53. #region ICollection Members
  54. void ICollection.CopyTo (Array array, int index)
  55. {
  56. list.CopyTo (array, index);
  57. }
  58. public void CopyTo (string[] array, int index)
  59. {
  60. list.CopyTo (array, index);
  61. }
  62. public int Count
  63. {
  64. get { return list.Count; }
  65. }
  66. public bool IsSynchronized
  67. {
  68. get { return false; }
  69. }
  70. public object SyncRoot
  71. {
  72. get { return this; }
  73. }
  74. #endregion
  75. #region IList Members
  76. int IList.Add (object value)
  77. {
  78. return Add ((string)value);
  79. }
  80. public int Add (string value)
  81. {
  82. int index = list.Add (value);
  83. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
  84. return index;
  85. }
  86. public void AddRange (string[] value)
  87. {
  88. if (value == null)
  89. throw new ArgumentNullException ("value", "Argument cannot be null!");
  90. list.AddRange (value);
  91. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
  92. }
  93. public void Clear ()
  94. {
  95. list.Clear ();
  96. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
  97. }
  98. bool IList.Contains (object value)
  99. {
  100. return Contains ((string)value);
  101. }
  102. public bool Contains (string value)
  103. {
  104. return list.Contains (value);
  105. }
  106. int IList.IndexOf (object value)
  107. {
  108. return IndexOf ((string)value);
  109. }
  110. public int IndexOf (string value)
  111. {
  112. return list.IndexOf (value);
  113. }
  114. void IList.Insert (int index, object value)
  115. {
  116. Insert (index, (string)value);
  117. }
  118. public void Insert (int index, string value)
  119. {
  120. list.Insert (index, value);
  121. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
  122. }
  123. bool IList.IsFixedSize
  124. {
  125. get { return false; }
  126. }
  127. bool IList.IsReadOnly
  128. {
  129. get { return false; }
  130. }
  131. public bool IsReadOnly
  132. {
  133. get { return false; }
  134. }
  135. void IList.Remove (object value)
  136. {
  137. Remove((string)value);
  138. }
  139. public void Remove (string value)
  140. {
  141. list.Remove (value);
  142. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
  143. }
  144. public void RemoveAt (int index)
  145. {
  146. string value = this[index];
  147. list.RemoveAt (index);
  148. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
  149. }
  150. object IList.this[int index]
  151. {
  152. get { return this[index]; }
  153. set { this[index] = (string)value; }
  154. }
  155. public string this[int index]
  156. {
  157. get { return (string)list[index]; }
  158. set {
  159. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, list[index]));
  160. list[index] = value;
  161. OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
  162. }
  163. }
  164. #endregion
  165. }
  166. }