using System;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar
{
	/// 
	/// Represents Document container base class.
	/// 
	public abstract class DocumentBaseContainer
	{
		#region Private Variables and Constructor
		private Rectangle m_LayoutBounds=Rectangle.Empty;
		private Rectangle m_DisplayBounds=Rectangle.Empty;
		private DocumentBaseContainer m_Parent=null;
        private static long IdCounter = 0;
        private long _Id = 0;
		/// 
		/// Creates new instance of the class.
		/// 
		public DocumentBaseContainer()
		{
            IdCounter++;
            _Id = IdCounter;
		}
		#endregion
		#region Internal Implementation
        /// 
        /// Gets the unique ID for the container.
        /// 
        public long Id
        {
            get { return _Id; }
        }
        
		/// 
		/// Returns actual display bounds of the document.
		/// 
		[Browsable(false)]
		public virtual Rectangle DisplayBounds
		{
			get {return m_DisplayBounds;}
		}
		/// 
		/// Returns layout bounds of the document. Layout bounds are proposed bounds of the layout and might not be the same
		/// as DisplayBounds.
		/// 
		[Browsable(false)]
		public virtual Rectangle LayoutBounds
		{
			get {return m_LayoutBounds;}
		}
		/// 
		/// Gets the parent container.
		/// 
		public virtual DocumentBaseContainer Parent
		{
			get {return m_Parent;}
		}
		/// 
		/// Resizes the document within specified bounds.
		/// 
		/// Area available for the document.
		public abstract void Layout(Rectangle bounds);
		/// 
		/// Sets the display bounds.
		/// 
		/// New display bounds.
		internal void SetDisplayBounds(Rectangle r)
		{
			m_DisplayBounds=r;
		}
		/// 
		/// Sets layout bounds.
		/// 
		/// New layout bounds.
		internal void SetLayoutBounds(Rectangle r)
		{
			m_LayoutBounds=r;
		}
        /// 
        /// Resets the layout bounds for the document base container to the empty bounds.
        /// 
        public void ResetLayoutBounds()
        {
            m_LayoutBounds = Rectangle.Empty;
        }
        /// 
        /// Resets the layout bounds for the document base container to the empty bounds.
        /// 
        public void ResetDisplayBounds()
        {
            m_DisplayBounds = Rectangle.Empty;
        }
		/// 
		/// Sets the parent document.
		/// 
		/// Parent container.
		internal void SetParent(DocumentBaseContainer parent)
		{
			m_Parent=parent;
		}
		/// 
		/// Sets the width of the document.
		/// 
		/// Width in pixels
		public virtual void SetWidth(int width)
		{
			if(m_Parent!=null)
			{
				//if(!m_Parent.OnSetWidth(this,width))
					//return;
                m_Parent.OnSetWidth(this, width);
			}
            if (width >= this.MinimumSize.Width || this.MinimumSize.Width == 0)
            {
                ResetDisplayBounds();
                m_LayoutBounds.Width = width;
            }
		}
		/// 
		/// Sets the height of the document.
		/// 
		/// Height in pixels.
		public virtual void SetHeight(int height)
		{
			if(m_Parent!=null)
				m_Parent.OnSetHeight(this,height);
            if (height >= this.MinimumSize.Height || this.MinimumSize.Height == 0)
            {
                ResetDisplayBounds();
                m_LayoutBounds.Height = height;
            }
		}
		/// 
		/// Occurs when width is being set on child document.
		/// 
		/// Reference document being changed
		/// Width in pixels
		/// True if width was applied by parent otherwise false
		protected internal virtual bool OnSetWidth(DocumentBaseContainer doc, int width){return false;}
		/// 
		/// Occurs when height is being set on child document.
		/// 
		/// Reference document being changed
		/// Height in pixels
		/// True if width was applied by parent otherwise false
		protected internal virtual bool OnSetHeight(DocumentBaseContainer doc, int height){return false;}
		/// 
		/// Gets whether document is visible or not.
		/// 
		public abstract bool Visible {get;}
		/// 
		/// Gets minimum size of the document.
		/// 
		protected internal abstract System.Drawing.Size MinimumSize {get;}
        /// 
        /// Updates bounds of the item in response to the scrolling of LayoutControl.
        /// 
        /// 
        /// 
        internal virtual void UpdateScrollBounds(int xScroll, int yScroll, bool moveControls)
        {
            m_DisplayBounds.Offset(xScroll, yScroll);
        }
		#endregion
	}
}