TableCellCollection.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / TableCellCollection.cs / 1305600 / TableCellCollection.cs

                            //---------------------------------------------------------------------------- 
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
// File: TableCellCollection.cs 
//
// Description: Collection of TableCell objects. 
// 
//---------------------------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using MS.Internal.Documents; 

namespace System.Windows.Documents 
{ 
    /// 
    /// A TableCellCollection is an ordered collection of TableCells. 
    /// 
    /// 
    /// TableCellCollection provides public access for TableCells
    /// reading and manipulating. 
    /// 
    public sealed class TableCellCollection : IList, IList 
    { 
        //-----------------------------------------------------
        // 
        //  Constructors
        //
        //-----------------------------------------------------
 
        #region Constructors
 
        internal TableCellCollection(TableRow owner) 
        {
            _cellCollectionInternal = new TableTextElementCollectionInternal(owner); 
        }

        #endregion Constructors
 
        //------------------------------------------------------
        // 
        //  Public Methods 
        //
        //----------------------------------------------------- 

        #region Public Methods

        ///  
        /// 
        ///  
        ///  
        /// 
        ///  
        /// 
        /// 
        /// 
        ///  
        /// 
        ///  
        ///  
        /// 
        public void CopyTo(Array array, int index) 
        {
            _cellCollectionInternal.CopyTo(array, index);
        }
 
        /// 
        /// Strongly typed version of ICollection.CopyTo. 
        ///  
        /// 
        ///  
        /// 
        /// 
        /// 
        ///  
        /// 
        ///  
        ///  
        /// 
        ///  
        /// 
        /// 
        /// 
        public void CopyTo(TableCell[] array, int index) 
        {
            _cellCollectionInternal.CopyTo(array, index); 
        } 

        ///  
        ///     
        /// 
        IEnumerator IEnumerable.GetEnumerator()
        { 
            return _cellCollectionInternal.GetEnumerator();
        } 
 
        /// 
        ///      
        /// 
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)_cellCollectionInternal).GetEnumerator(); 
        }
 
        ///  
        /// Appends a TableCell to the end of the TableCellCollection.
        ///  
        /// The TableCell to be added to the end of the TableCellCollection.
        /// The TableCellCollection index at which the TableCell has been added.
        /// Adding a null is prohibited.
        ///  
        /// If the item value is null.
        ///  
        ///  
        /// If the new child already has a parent.
        ///  
        public void Add(TableCell item)
        {
            _cellCollectionInternal.Add(item);
        } 

        ///  
        /// Removes all elements from the TableCellCollection. 
        /// 
        ///  
        /// Count is set to zero. Capacity remains unchanged.
        /// To reset the capacity of the TableCellCollection, call TrimToSize
        /// or set the Capacity property directly.
        ///  
        public void Clear()
        { 
            _cellCollectionInternal.Clear(); 
        }
 
        /// 
        /// Determines whether a TableCell is in the TableCellCollection.
        /// 
        /// The TableCell to locate in the TableCellCollection. 
        /// The value can be a null reference.
        /// true if TableCell is found in the TableCellCollection; 
        /// otherwise, false. 
        public bool Contains(TableCell item)
        { 
            return _cellCollectionInternal.Contains(item);
        }

        ///  
        /// Returns the zero-based index of the TableCell. If the TableCell is not
        /// in the TableCellCollection, -1 is returned. 
        ///  
        /// The TableCell to locate in the TableCellCollection.
        public int IndexOf(TableCell item) 
        {
            return _cellCollectionInternal.IndexOf(item);
        }
 
        /// 
        /// Inserts a TableCell into the TableCellCollection at the specified index. 
        ///  
        /// The zero-based index at which value should be inserted.
        /// The TableCell to insert.  
        /// 
        /// indexc> is less than zero.
        /// -or-
        /// index is greater than Count. 
        /// 
        ///  
        /// If the item value is null. 
        /// 
        ///  
        /// If Count already equals Capacity, the capacity of the
        /// TableCellCollection is increased before the new TableCell is inserted.
        ///
        /// If index is equal to Count, TableCell is added to the 
        /// end of TableCellCollection.
        /// 
        /// The TableCells that follow the insertion point move down to 
        /// accommodate the new TableCell. The indexes of the TableCells that are
        /// moved are also updated. 
        /// 
        public void Insert(int index, TableCell item)
        {
            _cellCollectionInternal.Insert(index, item); 
        }
 
        ///  
        /// Removes the specified TableCell from the TableCellCollection.
        ///  
        /// The TableCell to remove from the TableCellCollection.
        /// 
        /// If the item value is null.
        ///  
        /// 
        /// If the specified TableCell is not in this collection. 
        ///  
        /// 
        /// The TableCells that follow the removed TableCell move up to occupy 
        /// the vacated spot. The indices of the TableCells that are moved
        /// also updated.
        /// 
        public bool Remove(TableCell item) 
        {
            return _cellCollectionInternal.Remove(item); 
        } 

        ///  
        /// Removes the TableCell at the specified index.
        /// 
        /// The zero-based index of the TableCell to remove.
        ///  
        /// index is less than zero
        /// - or - 
        /// index is equal or greater than count. 
        /// 
        ///  
        /// The TableCells that follow the removed TableCell move up to occupy
        /// the vacated spot. The indices of the TableCells that are moved
        /// also updated.
        ///  
        public void RemoveAt(int index)
        { 
            _cellCollectionInternal.RemoveAt(index); 
        }
 

        /// 
        /// Removes a range of TableCells from the TableCellCollection.
        ///  
        /// The zero-based index of the range
        /// of TableCells to remove 
        /// The number of TableCells to remove. 
        /// 
        /// index is less than zero. 
        /// -or-
        /// count is less than zero.
        /// 
        ///  
        /// index and count do not denote a valid range of TableCells in the TableCellCollection.
        ///  
        ///  
        /// The TableCells that follow the removed TableCells move up to occupy
        /// the vacated spot. The indices of the TableCells that are moved are 
        /// also updated.
        /// 
        public void RemoveRange(int index, int count)
        { 
            _cellCollectionInternal.RemoveRange(index, count);
        } 
 
        /// 
        /// Sets the capacity to the actual number of elements in the TableCellCollection. 
        /// 
        /// 
        /// This method can be used to minimize a TableCellCollection's memory overhead
        /// if no new elements will be added to the collection. 
        ///
        /// To completely clear all elements in a TableCellCollection, call the Clear method 
        /// before calling TrimToSize. 
        /// 
        public void TrimToSize() 
        {
            _cellCollectionInternal.TrimToSize();
        }
 
        #endregion Public Methods
 
        //-------------------------------------------------------------------- 
        //
        //  IList Members 
        //
        //--------------------------------------------------------------------

        #region IList Members 

        int IList.Add(object value) 
        { 
            return ((IList)_cellCollectionInternal).Add(value);
        } 

        void IList.Clear()
        {
            this.Clear(); 
        }
 
        bool IList.Contains(object value) 
        {
            return ((IList)_cellCollectionInternal).Contains(value); 
        }

        int IList.IndexOf(object value)
        { 
            return ((IList)_cellCollectionInternal).IndexOf(value);
        } 
 
        void IList.Insert(int index, object value)
        { 
            ((IList)_cellCollectionInternal).Insert(index, value);
        }

        bool IList.IsFixedSize 
        {
            get 
            { 
                return ((IList)_cellCollectionInternal).IsFixedSize;
            } 
        }

        bool IList.IsReadOnly
        { 
            get
            { 
                return ((IList)_cellCollectionInternal).IsReadOnly; 
            }
        } 

        void IList.Remove(object value)
        {
            ((IList)_cellCollectionInternal).Remove(value); 
        }
 
        void IList.RemoveAt(int index) 
        {
            ((IList)_cellCollectionInternal).RemoveAt(index); 
        }

        object IList.this[int index]
        { 
            get
            { 
                return ((IList)_cellCollectionInternal)[index]; 
            }
 
            set
            {
                ((IList)_cellCollectionInternal)[index] = value;
            } 
        }
 
        #endregion IList Members 

 
        //-----------------------------------------------------
        //
        //  Public Properties
        // 
        //------------------------------------------------------
 
        #region Public Properties 

        ///  
        /// 
        /// 
        public int Count
        { 
            get
            { 
                return _cellCollectionInternal.Count; 
            }
        } 

        /// 
        ///     
        ///  
        public bool IsReadOnly
        { 
            get 
            {
                return ((IList)_cellCollectionInternal).IsReadOnly; 
            }
        }

        ///  
        /// 
        ///  
        /// Always returns false. 
        /// 
        ///  
        public bool IsSynchronized
        {
            get
            { 
                return ((IList)_cellCollectionInternal).IsSynchronized;
            } 
        } 

        ///  
        /// 
        /// 
        public object SyncRoot
        { 
            get
            { 
                return ((IList)_cellCollectionInternal).SyncRoot; 
            }
        } 

        /// 
        /// Gets or sets the number of elements that the TableRowGroupCollection can contain.
        ///  
        /// 
        /// The number of elements that the TableRowGroupCollection can contain. 
        ///  
        /// 
        /// Capacity is the number of elements that the TableRowGroupCollection is capable of storing. 
        /// Count is the number of Visuals that are actually in the TableRowGroupCollection.
        ///
        /// Capacity is always greater than or equal to Count. If Count exceeds
        /// Capacity while adding elements, the capacity of the TableRowGroupCollection is increased. 
        ///
        /// By default the capacity is 8. 
        ///  
        /// 
        /// Capacity is set to a value that is less than Count. 
        /// 
        /// 
        public int Capacity
        { 
            get
            { 
                return _cellCollectionInternal.Capacity; 
            }
            set 
            {
                _cellCollectionInternal.Capacity = value;
            }
        } 

        ///  
        /// Indexer for the TableCellCollection. Gets the TableCell stored at the 
        /// zero-based index of the TableCellCollection.
        ///  
        /// This property provides the ability to access a specific TableCell in the
        /// TableCellCollection by using the following systax: TableCell myTableCell = myTableCellCollection[index].
        /// 
        ///  
        /// index is less than zero -or- index is equal to or greater than Count.
        ///  
        public TableCell this[int index] 
        {
            get 
            {
                return _cellCollectionInternal[index];
            }
            set 
            {
                _cellCollectionInternal[index] = value; 
            } 
        }
 
        #endregion Public Properties

        #region Internal Methods
 
        /// 
        /// Performs the actual work of adding the item into the array, and notifying it when it is connected 
        ///  
        internal void InternalAdd(TableCell item)
        { 
            _cellCollectionInternal.InternalAdd(item);
        }

        ///  
        /// Performs the actual work of notifying item it is leaving the array, and disconnecting it.
        ///  
        internal void InternalRemove(TableCell item) 
        {
            _cellCollectionInternal.InternalRemove(item); 
        }

        #endregion Internal Methods
 
        //-----------------------------------------------------
        // 
        //  Private Methods 
        //
        //----------------------------------------------------- 

        #region Private Methods

        ///  
        /// Ensures that the capacity of this list is at least the given minimum
        /// value. If the currect capacity of the list is less than min, the 
        /// capacity is increased to min. 
        /// 
        private void EnsureCapacity(int min) 
        {
            _cellCollectionInternal.EnsureCapacity(min);
        }
 
        /// 
        /// Sets the specified TableCell at the specified index; 
        /// Connects the item to the model tree; 
        /// Notifies the TableCell about the event.
        ///  
        /// 
        /// If the new item has already a parent or if the slot at the specified index is not null.
        /// 
        ///  
        /// Note that the function requires that _item[index] == null and
        /// it also requires that the passed in item is not included into another TableCellCollection. 
        ///  
        private void PrivateConnectChild(int index, TableCell item)
        { 
            _cellCollectionInternal.PrivateConnectChild(index, item);
        }

 
        /// 
        /// Removes specified TableCell from the TableCellCollection. 
        ///  
        /// TableCell to remove.
        private void PrivateDisconnectChild(TableCell item) 
        {
            _cellCollectionInternal.PrivateDisconnectChild(item);
        }
 
        // helper method: return true if the item belongs to the collection's owner
        private bool BelongsToOwner(TableCell item) 
        { 
            return _cellCollectionInternal.BelongsToOwner(item);
        } 

        // Helper method - Searches the children collection for the index an item currently exists at -
        // NOTE - ITEM MUST BE IN TEXT TREE WHEN THIS IS CALLED.
        private int FindInsertionIndex(TableCell item) 
        {
            return _cellCollectionInternal.FindInsertionIndex(item); 
        } 

 
        #endregion Private Methods

        //-----------------------------------------------------
        // 
        //  Private Properties
        // 
        //------------------------------------------------------ 

        #region Private Properties 

        /// 
        /// PrivateCapacity sets/gets the Capacity of the collection.
        ///  
        private int PrivateCapacity
        { 
            get 
            {
                return _cellCollectionInternal.PrivateCapacity; 
            }
            set
            {
                _cellCollectionInternal.PrivateCapacity = value; 
            }
        } 
 
        #endregion Private Properties
 
        private TableTextElementCollectionInternal _cellCollectionInternal;
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK