using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;

using DigitalPlatform.IO;

namespace DigitalPlatform.Xml
{
	public class Attributes: BoxExpandable
	{
		#region ÖØÐ´»ùÀàµÄÐéº¯Êý

		public override ItemRegion GetRegionName()
		{
			if (this.bExpand == true)
				return ItemRegion.Attributes;
			else
				return ItemRegion.Text ;
		}


		public override void InitialVisual()
		{
			ElementItem item = (ElementItem)this.GetItem();
			if (item == null)
				return;

            // ÊÕËõÌ¬
			if (item.m_attrsExpand == ExpandStyle.Collapse)
			{
				this.childrenVisual = null;

				this.MyText.container = this.container ;
				this.MyText.Name = "attributes";
				this.MyText.Text = "ÉÐÎ´³õÊ¼»¯"; //item.strAttrsValue;


				// °Ñthis.MyText¼Ó½ø±¾¶ÔÏóµÄ¸¸Ç×ÖÐ,°Ñthis´Ó¸¸Ç×ÖÐÉ¾³ý
				((Box)this.container).AddChildVisual(this.MyText);
				((Box)this.container).childrenVisual.Remove (this);

				item.Flush();
			}
			else if (item.m_attrsExpand == ExpandStyle.Expand)
			{
				foreach(AttrItem attr in item.attrs)
				{
					Debug.Assert(attr.GetValue() != null,"×¼±¸Öµ²»ÄÜÎªnull");
					attr.m_paraValue1 = attr.GetValue();
				}

				if (this.childrenVisual != null)
				{
					this.childrenVisual.Clear();
				}

                // ÊúÏòÅÅÁÐ
				this.LayoutStyle = LayoutStyle.Vertical;

				foreach(AttrItem attr in item.attrs)
				{
					// Éè×ÓÔªËØµÄstyleÑùÊ½Óë¸¸Ç×ÏàÍ¬
					attr.LayoutStyle = item.LayoutStyle ;
						
					// °Ñchild¼Óµ½contentÀï×÷ÎªChildVisual
					attr.container = this;
					this.AddChildVisual(attr);

					// ´Ë´¦
					Debug.Assert(attr.m_paraValue1 != null,"´ËÊ±²»Ó¦Îªnull");
					// ÊµÏÖÇ¶¹é
					attr.InitialVisual();//elementStyle);
				}
			}
			else 
			{
				Debug.Assert(false, "");
			}
		}


		#endregion
	}

}
