//------------------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//                                                                 
//------------------------------------------------------------------------------
/*
 * HtmlTableCellCollection.cs
 *
 * Copyright (c) 2000 Microsoft Corporation
 */
namespace System.Web.UI.HtmlControls {
    using System.Runtime.InteropServices;
    using System;
    using System.Collections;
    using System.Web;
    using System.Web.UI;
    using System.Security.Permissions;
/// 
///    
///       The  contains all of the table
///       cells, both <td> and <th> elements, found within an 
///       server control.
///    
/// 
    public sealed class HtmlTableCellCollection : ICollection {
        /// 
        /// 
        /// 
        private HtmlTableRow owner;
        internal HtmlTableCellCollection(HtmlTableRow owner) {
            this.owner = owner;
        }
        /*
         * The number of cells in the row.
         */
        /// 
        ///    
        ///       Gets the number of items in the 
        ///       collection.
        ///    
        /// 
        public int Count {
            get {
                if (owner.HasControls())
                    return owner.Controls.Count;
                return 0;
            }
        }
        /// 
        ///    
        ///       Gets an  control from an
        ///     control thorugh the cell's ordinal index value. 
        ///    
        /// 
        public HtmlTableCell this[int index]
        {
            get {
                return(HtmlTableCell)owner.Controls[index];
            }
        }
        /// 
        ///    
        ///       Adds the specified  control to the end of the
        ///       collection.
        ///    
        /// 
        public void Add(HtmlTableCell cell) {
            Insert(-1, cell);
        }
        /// 
        ///    
        ///       Adds an  control to a specified location in the
        ///       collection.
        ///    
        /// 
        public void Insert(int index, HtmlTableCell cell) {
            owner.Controls.AddAt(index, cell);
        }
        /// 
        ///    
        ///       Deletes all 
        ///       controls from the collection.
        ///    
        /// 
        public void Clear() {
            if (owner.HasControls())
                owner.Controls.Clear();
        }
        /*
         * Returns an enumerator that enumerates over the cells in a table row in order.
         */
        /// 
        /// 
        public IEnumerator GetEnumerator() {
            return owner.Controls.GetEnumerator();
        }
        /// 
        /// 
        public void CopyTo(Array array, int index) {
            for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
                array.SetValue(e.Current, index++);
        }
        /// 
        /// 
        public Object SyncRoot {
            get { return this;}
        }
        /// 
        /// 
        public bool IsReadOnly {
            get { return false;}
        }
        /// 
        /// 
        public bool IsSynchronized {
            get { return false;}
        }
        /// 
        ///    
        ///       Deletes the specified  control from the
        ///       collection.
        ///    
        /// 
        public void Remove(HtmlTableCell cell) {
            owner.Controls.Remove(cell);
        }
        /// 
        ///    
        ///       Deletes the  control at the specified index
        ///       location from the collection.
        ///    
        /// 
        public void RemoveAt(int index) {
            owner.Controls.RemoveAt(index);
        }
    }
}