GridItemCollection.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2005 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jonathan Chambers (jonathan.chambers@ansys.com)
  24. //
  25. // COMPLETE
  26. using System.Collections;
  27. namespace System.Windows.Forms
  28. {
  29. public class GridItemCollection : IEnumerable, ICollection
  30. {
  31. #region Local Variables
  32. private System.Collections.SortedList list;
  33. #endregion // Local Variables
  34. #region Public Static Fields
  35. public static GridItemCollection Empty = new GridItemCollection();
  36. #endregion // Public Static Fields
  37. #region Constructors
  38. internal GridItemCollection()
  39. {
  40. list = new SortedList();
  41. }
  42. #endregion // Constructors
  43. #region Internal Properties and Methods
  44. internal void Add (GridItem grid_item)
  45. {
  46. string key = grid_item.Label;
  47. while (list.ContainsKey (key))
  48. key += "_";
  49. list.Add (key, grid_item);
  50. }
  51. internal void AddRange (GridItemCollection items)
  52. {
  53. foreach (GridItem item in items)
  54. Add (item);
  55. }
  56. internal int IndexOf (GridItem grid_item)
  57. {
  58. return list.IndexOfValue (grid_item);
  59. }
  60. #endregion // Internal Properties and Methods
  61. #region Public Instance Properties
  62. public int Count {
  63. get {
  64. return list.Count;
  65. }
  66. }
  67. public GridItem this [int index] {
  68. get {
  69. if (index>=list.Count) {
  70. throw new ArgumentOutOfRangeException("index");
  71. }
  72. return (GridItem)list.GetByIndex(index);
  73. }
  74. }
  75. public GridItem this [string label] {
  76. get {
  77. return (GridItem)list[label];
  78. }
  79. }
  80. #endregion // Public Instance Properties
  81. #region IEnumerable Members
  82. public IEnumerator GetEnumerator()
  83. {
  84. return new GridItemEnumerator (this);
  85. }
  86. #endregion
  87. #region Enumerator Class
  88. internal class GridItemEnumerator : IEnumerator{
  89. int nIndex;
  90. GridItemCollection collection;
  91. public GridItemEnumerator(GridItemCollection coll)
  92. {
  93. collection = coll;
  94. nIndex = -1;
  95. }
  96. public bool MoveNext ()
  97. {
  98. nIndex++;
  99. return (nIndex < collection.Count);
  100. }
  101. public void Reset ()
  102. {
  103. nIndex = -1;
  104. }
  105. object System.Collections.IEnumerator.Current {
  106. get {
  107. return collection [nIndex];
  108. }
  109. }
  110. }
  111. #endregion
  112. #region ICollection Members
  113. bool ICollection.IsSynchronized {
  114. get {
  115. return list.IsSynchronized;
  116. }
  117. }
  118. void ICollection.CopyTo(Array dest, int index)
  119. {
  120. list.CopyTo (dest, index);
  121. }
  122. object ICollection.SyncRoot {
  123. get {
  124. return list.SyncRoot;
  125. }
  126. }
  127. #endregion
  128. internal void Clear ()
  129. {
  130. list.Clear ();
  131. }
  132. }
  133. }