using System;
using System.Collections;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
    /// 
    /// Represents the collection of WizardPage objects which determines the flow of the wizard.
    /// 
    public class WizardPageCollection : CollectionBase
    {
        #region Private Variables
		private Wizard m_Parent=null;
        [EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool IgnoreEvents = false;
		#endregion
		#region Internal Implementation
        public WizardPageCollection()
		{
		}
		/// 
		/// Gets the parent this collection is associated with.
		/// 
		[Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public Wizard Parent
		{
			get {return m_Parent;}
		}
		internal Wizard ParentWizard
		{
            get { return m_Parent; }
            set { m_Parent = value; }
		}
		/// 
		/// Adds new object to the collection.
		/// 
		/// Object to add.
		/// Index of newly added object.
		public int Add(WizardPage WizardPage)
		{
			return List.Add(WizardPage);
		}
		
		/// 
		/// Adds an array of objects to the collection. 
		/// 
		/// Array of WizardPage objects.
		public void AddRange(WizardPage[] WizardPages)
		{
			foreach(WizardPage WizardPage in WizardPages)
				List.Add(WizardPage);
		}
		
		/// 
		/// Returns reference to the object in collection based on it's index.
		/// 
		public WizardPage this[int index]
		{
			get {return (WizardPage)(List[index]);}
			set {List[index] = value;}
		}
        /// 
        /// Returns reference to the object in collection based on it's name.
        /// 
        public WizardPage this[string name]
        {
            get
            {
                foreach(WizardPage page in this.List)
                {
                    if (page.Name == name)
                        return page;
                }
                return null;
            }
        }
		/// 
		/// Inserts new object into the collection.
		/// 
		/// Position of the object.
		/// Object to insert.
		public void Insert(int index, WizardPage 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(WizardPage 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(WizardPage value) 
		{
			return List.Contains(value);
		}
		/// 
		/// Removes specified object from the collection.
		/// 
		/// 
		public void Remove(WizardPage value) 
		{
			List.Remove(value);
		}
		
		protected override void OnRemove(int index, object value)
		{
			
			base.OnRemove (index, value);
		}
		protected override void OnRemoveComplete(int index,object value)
		{
			base.OnRemoveComplete(index,value);
            if (IgnoreEvents)
                return;
            if (m_Parent != null)
                m_Parent.OnWizardPageRemoved(value as WizardPage);
		}
		
		protected override void OnInsertComplete(int index,object value)
		{
			base.OnInsertComplete(index,value);
            if (IgnoreEvents)
                return;
            if (m_Parent != null)
                m_Parent.OnWizardPageAdded(value as WizardPage);
		}
		/// 
		/// Copies collection into the specified array.
		/// 
		/// Array to copy collection to.
		/// Starting index.
		public void CopyTo(WizardPage[] array, int index) 
		{
			List.CopyTo(array, index);
		}
		/// 
		/// Copies contained items to the WizardPage array.
		/// 
		/// Array to copy to.
        [EditorBrowsable(EditorBrowsableState.Never)]
		public void CopyTo(WizardPage[] array)
		{
			List.CopyTo(array,0);
		}
        /// 
        /// Copies contained items to the WizardPage array.
        /// 
        /// Array to copy to.
        [EditorBrowsable(EditorBrowsableState.Never)]
        public void CopyTo(WizardPageCollection col)
        {
            foreach (WizardPage page in this.List)
                col.Add(page);
        }
		protected override void OnClear()
		{
            if (!IgnoreEvents)
            {
                if (m_Parent != null)
                {
                    foreach (WizardPage page in this.List)
                    {
                        m_Parent.OnWizardPageRemoved(page);
                    }
                }
            }
			base.OnClear();
		}
		
		#endregion
    }
}