using System;
using System.Text;
using System.Collections;
namespace DevComponents.DotNetBar
{
    /// 
    /// Represents the GalleryGroup typed collection.
    /// 
    public class GalleryGroupCollection : CollectionBase
    {
        #region Private Variables and Events
		public event EventHandler GroupRemoved;
		public event EventHandler GroupAdded;
		private GalleryContainer m_Owner=null;
		#endregion
		#region Internal Implementation
		/// 
		/// Adds new object to the collection.
		/// 
		/// Object to add.
		/// Index of newly added object.
		public int Add(GalleryGroup tab)
		{
			return List.Add(tab);
		}
		/// 
		/// Adds new objects to the collection.
		/// 
		/// Array of groups to add.
		public void AddRange(GalleryGroup[] groups)
		{
			foreach(GalleryGroup doc in groups)
				List.Add(doc);
		}
		/// 
		/// Returns reference to the object in collection based on it's index.
		/// 
		public GalleryGroup this[int index]
		{
			get {return (GalleryGroup)(List[index]);}
			set {List[index] = value;}
		}
        /// 
        /// Returns reference to the object in collection based on it's name.
        /// 
        public GalleryGroup this[string name]
        {
            get
            {
                foreach (GalleryGroup g in this.List)
                {
                    if (g.Name == name)
                        return g;
                }
                return null;
            }
        }
		/// 
		/// Inserts new object into the collection.
		/// 
		/// Position of the object.
		/// Object to insert.
		public void Insert(int index, GalleryGroup value) 
		{
			List.Insert(index, value);
		}
		/// 
		/// Returns index of the object inside of the collection.
		/// 
		/// Reference to the object.
		/// Index of the object.
		public int IndexOf(GalleryGroup value) 
		{
			return List.IndexOf(value);
		}
		/// 
		/// Returns whether collection contains specified object.
		/// 
		/// Object to look for.
		/// true if object is part of the collection, otherwise false.
		public bool Contains(GalleryGroup value) 
		{
			return List.Contains(value);
		}
		/// 
		/// Removes specified object from the collection.
		/// 
		/// 
		public void Remove(GalleryGroup value) 
		{
			List.Remove(value);
		}
		protected override void OnRemoveComplete(int index,object value)
		{
			base.OnRemoveComplete(index,value);
			GalleryGroup item=value as GalleryGroup;
			item.SetParentGallery(null);
			if(GroupRemoved!=null)
				GroupRemoved(item,new EventArgs());
		}
		protected override void OnInsertComplete(int index,object value)
		{
			base.OnInsertComplete(index,value);
			GalleryGroup item=value as GalleryGroup;
			if(m_Owner!=null)
				item.SetParentGallery(m_Owner);
			if(GroupAdded!=null)
				GroupAdded(item,new EventArgs());
		}
		/// 
		/// Copies collection into the specified array.
		/// 
		/// Array to copy collection to.
		/// Starting index.
		public void CopyTo(GalleryGroup[] array, int index) 
		{
			List.CopyTo(array, index);
		}
		/// 
		/// Copies contained items to the GalleryGroup array.
		/// 
		/// Array to copy to.
		internal void CopyTo(GalleryGroup[] array)
		{
			List.CopyTo(array,0);
		}
		internal GalleryContainer Owner
		{
			get {return m_Owner;}
			set {m_Owner=value;}
		}
		protected override void OnClear()
		{
			base.OnClear();
		}
		#endregion
	}
}