Merge pull request #2916 from ludovic-henry/fix-40306
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / TableCellCollection.cs
index 33b4cf23d6394d2446df3fba9e50220f8fb5db4f..b0e7bdc560c4f9cd68f78973d1f0a84455b228ba 100644 (file)
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class:     TableCellCollection\r
- *\r
- * Author:  Gaurav Vaish\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
- * Implementation: yes\r
- * Status:  100%\r
- *\r
- * (C) Gaurav Vaish (2002)\r
- */\r
-\r
-using System;\r
-using System.Collections;\r
-using System.Web;\r
-using System.Web.UI;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
-       public sealed class TableCellCollection: IList, ICollection, IEnumerable\r
-       {\r
-               private TableRow owner;\r
-\r
-               internal TableCellCollection(TableRow owner)\r
-               {\r
-                       if(owner == null)\r
-                       {\r
-                               throw new ArgumentNullException();\r
-                       }\r
-                       this.owner = owner;\r
-               }\r
-\r
-               public int Count\r
-               {\r
-                       get\r
-                       {\r
-                               return owner.Controls.Count;\r
-                       }\r
-               }\r
-\r
-               public bool IsReadOnly\r
-               {\r
-                       get\r
-                       {\r
-                               return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsSynchronized\r
-               {\r
-                       get\r
-                       {\r
-                               return false;\r
-                       }\r
-               }\r
-\r
-               public TableCell this[int index]\r
-               {\r
-                       get\r
-                       {\r
-                               return (TableCell)owner.Controls[index];\r
-                       }\r
-               }\r
-\r
-               public object SyncRoot\r
-               {\r
-                       get\r
-                       {\r
-                               return this;\r
-                       }\r
-               }\r
-\r
-               public int Add(TableCell cell)\r
-               {\r
-                       AddAt(-1, cell);\r
-                       return owner.Controls.Count;\r
-               }\r
-\r
-               public void AddAt(int index, TableCell cell)\r
-               {\r
-                       owner.Controls.AddAt(index, cell);\r
-               }\r
-\r
-               public void AddRange(TableCell[] cells)\r
-               {\r
-                       foreach(TableCell cell in cells)\r
-                       {\r
-                               Add(cell);\r
-                       }\r
-               }\r
-\r
-               public void Clear()\r
-               {\r
-                       if(owner.HasControls())\r
-                       {\r
-                               owner.Controls.Clear();\r
-                       }\r
-               }\r
-\r
-               public void CopyTo(Array array, int index)\r
-               {\r
-                       foreach(object cell in this)\r
-                       {\r
-                               array.SetValue(cell, index++);\r
-                       }\r
-               }\r
-\r
-               public int GetCellIndex(TableCell cell)\r
-               {\r
-                       if(!owner.HasControls())\r
-                       {\r
-                               return -1;\r
-                       }\r
-                       return owner.Controls.IndexOf(cell);\r
-               }\r
-\r
-               public IEnumerator GetEnumerator()\r
-               {\r
-                       return owner.Controls.GetEnumerator();\r
-               }\r
-\r
-               public void Remove(TableCell cell)\r
-               {\r
-                       owner.Controls.Remove(cell);\r
-               }\r
-\r
-               public void RemoveAt(int index)\r
-               {\r
-                       owner.Controls.RemoveAt(index);\r
-               }\r
-\r
-               int IList.Add(object o)\r
-               {\r
-                       return Add((TableCell)o);\r
-               }\r
-\r
-               bool IList.Contains(object o)\r
-               {\r
-                       return owner.Controls.Contains((TableCell)o);\r
-               }\r
-\r
-               int IList.IndexOf(object o)\r
-               {\r
-                       return owner.Controls.IndexOf((TableCell)o);\r
-               }\r
-\r
-               void IList.Insert(int index, object o)\r
-               {\r
-                       owner.Controls.AddAt(index, (TableCell)o);\r
-               }\r
-\r
-               void IList.Remove(object o)\r
-               {\r
-                       owner.Controls.Remove((TableCell)o);\r
-               }\r
-\r
-               bool IList.IsFixedSize\r
-               {\r
-                       get\r
-                       {\r
-                               return false;\r
-                       }\r
-               }\r
-\r
-               object IList.this[int index]\r
-               {\r
-                       get\r
-                       {\r
-                               return this[index];\r
-                       }\r
-                       set\r
-                       {\r
-                               RemoveAt(index);\r
-                               AddAt(index, (TableCell)value);\r
-                       }\r
-               }\r
-       }\r
-}\r
+//
+// System.Web.UI.WebControls.TableCellCollection.cs
+//
+// Author:
+//     Sebastien Pouliot  <sebastien@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.ComponentModel;
+using System.Collections;
+
+namespace System.Web.UI.WebControls {
+
+       [Editor ("System.Web.UI.Design.WebControls.TableCellsCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+       public sealed class TableCellCollection : IList, ICollection, IEnumerable 
+       {
+               ControlCollection cc;
+
+               internal TableCellCollection (TableRow tr)
+               {
+                       cc = tr.Controls;
+               }
+
+
+               public int Count {
+                       get { return cc.Count; }
+               }
+
+               public bool IsReadOnly {
+                       get { return false; }   // documented as always false
+               }
+
+               public bool IsSynchronized {
+                       get { return false; }   // documented as always false
+               }
+
+               public TableCell this [int index] {
+                       get { return (TableCell) cc [index]; }
+               }
+
+               public object SyncRoot {
+                       get { return this; }    // as documented
+               }
+
+
+               public int Add (TableCell cell)
+               {
+                       int index = cc.IndexOf (cell);
+                       if (index < 0) {
+                               cc.Add (cell);
+                               index = cc.Count;
+                       }
+                       return index;
+               }
+
+               public void AddAt (int index, TableCell cell)
+               {
+                       if (cc.IndexOf (cell) < 0)
+                               cc.AddAt (index, cell);
+               }
+
+               public void AddRange (TableCell[] cells)
+               {
+                       foreach (TableCell td in cells) {
+                               if (cc.IndexOf (td) < 0)
+                                       cc.Add (td);
+                       }
+               }
+
+               public void Clear ()
+               {
+                       cc.Clear ();
+               }
+
+               public void CopyTo (Array array, int index)
+               {
+                       cc.CopyTo (array, index);
+               }
+
+               public int GetCellIndex (TableCell cell)
+               {
+                       return cc.IndexOf (cell);
+               }
+
+               public IEnumerator GetEnumerator ()
+               {
+                       return cc.GetEnumerator ();
+               }
+
+               public void Remove (TableCell cell)
+               {
+                       cc.Remove (cell);
+               }
+
+               public void RemoveAt (int index)
+               {
+                       cc.RemoveAt (index);
+               }
+
+
+               // implements IList but doesn't make some members public
+
+               bool IList.IsFixedSize {
+                       get { return false; }
+               }
+
+               object IList.this [int index] {
+                       get { return cc [index]; }
+                       set {
+                               cc.AddAt (index, (TableRow)value);
+                               cc.RemoveAt (index + 1);
+                       }
+               }
+
+
+               int IList.Add (object value)
+               {
+                       cc.Add ((TableRow)value);
+                       return cc.IndexOf ((TableRow)value);
+               }
+
+               bool IList.Contains (object value)
+               {
+                       return cc.Contains ((TableRow)value);
+               }
+
+               int IList.IndexOf (object value)
+               {
+                       return cc.IndexOf ((TableRow)value);
+               }
+
+               void IList.Insert (int index, object value)
+               {
+                       cc.AddAt (index, (TableRow)value);
+               }
+
+               void IList.Remove (object value)
+               {
+                       cc.Remove ((TableRow)value);
+               }
+       }
+}