using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace TD.SandDock
{
	internal class SandDockManagerDesigner : ComponentDesigner
	{
		public SandDockManagerDesigner()
		{
			this.b = new DesignerVerbCollection();
			this.b.Add(new DesignerVerb("Add Control", new EventHandler(this.a)));
		}

		private void a(object A_0, EventArgs A_1)
		{
			IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost));
			DockContainer dockContainer = this.a.a(DockStyle.Right);
			if (dockContainer != null)
			{
				DockContainerDesigner dockContainerDesigner = (DockContainerDesigner)designerHost.GetDesigner(dockContainer);
				dockContainerDesigner.e();
			}
		}

		public override void Initialize(IComponent component)
		{
			base.Initialize(component);
			IComponentChangeService componentChangeService = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
			componentChangeService.ComponentRemoving += this.a;
			this.a = (SandDockManager)component;
		}

		protected virtual void a(bool A_0)
		{
			IComponentChangeService componentChangeService = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
			componentChangeService.ComponentRemoving -= this.a;
			base.Dispose(A_0);
		}

		private void a(object A_0, ComponentEventArgs A_1)
		{
			if (A_1.Component == this.a)
			{
				IComponentChangeService componentChangeService = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
				DockContainer[] array = new DockContainer[checked((uint)this.a.a.Count)];
				this.a.a.CopyTo(array);
				foreach (DockContainer dockContainer in array)
				{
					Control parent = dockContainer.Parent;
					if (parent != null)
					{
						componentChangeService.OnComponentChanging(parent, TypeDescriptor.GetProperties(parent)["Controls"]);
						dockContainer.Dispose();
						componentChangeService.OnComponentChanged(parent, TypeDescriptor.GetProperties(parent)["Controls"], null, null);
					}
				}
			}
		}

		private DockContainer a(IDesignerHost A_0, Control A_1, DockStyle A_2, string A_3)
		{
			DockContainer dockContainer = new DockContainer();
			dockContainer.Manager = this.a;
			dockContainer.Size = new Size(0, 0);
			dockContainer.Dock = A_2;
			A_0.Container.Add(dockContainer, A_3);
			A_1.Controls.Add(dockContainer);
			dockContainer.SendToBack();
			return dockContainer;
		}

		public virtual void a()
		{
			base.OnSetComponentDefaults();
			IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost));
			IComponentChangeService componentChangeService = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
			Control control = designerHost.RootComponent as Control;
			if (control == null)
			{
				return;
			}
			componentChangeService.OnComponentChanging(control, null);
			this.a(designerHost, control, DockStyle.Left, "leftSandDock");
			this.a(designerHost, control, DockStyle.Right, "rightSandDock");
			this.a(designerHost, control, DockStyle.Bottom, "bottomSandDock");
			this.a(designerHost, control, DockStyle.Top, "topSandDock");
			componentChangeService.OnComponentChanged(control, null, null, null);
			this.a(designerHost, "leftSandBarDock");
			this.a(designerHost, "rightSandBarDock");
			this.a(designerHost, "bottomSandBarDock");
			this.a(designerHost, "topSandBarDock");
			this.a(null, null);
		}

		private void a(IDesignerHost A_0, string A_1)
		{
			IComponent component = A_0.Container.Components[A_1];
			if (component is Control)
			{
				((Control)component).SendToBack();
			}
		}

		public override DesignerVerbCollection Verbs
		{
			get
			{
				return this.b;
			}
		}

		public virtual ICollection AssociatedComponents
		{
			get
			{
				return this.a.a;
			}
		}

		private SandDockManager a = null;

		private DesignerVerbCollection b = null;
	}
}
