using System;
using System.Drawing;
using System.Windows.Forms;
using TD.Util;

namespace TD.SandDock
{
	internal class r : Control
	{
		public r(DockContainer A_0, k A_1)
		{
			this.a = A_0;
			this.c = A_1;
			base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			base.SetStyle(ControlStyles.DoubleBuffer, true);
			base.SetStyle(ControlStyles.ResizeRedraw, true);
			this.g = new a(this);
			this.g.a(false);
			this.g.a(new a.b(this.a));
		}

		private void b(Point A_0)
		{
			this.d = new p(this.a, this, A_0);
			this.d.a(new EventHandler(this.a));
			this.d.b(new p.a(this.a));
		}

		private void a()
		{
			this.d.b(new EventHandler(this.a));
			this.d.a(new p.a(this.a));
			this.d = null;
		}

		private void a(object A_0, EventArgs A_1)
		{
			this.a();
		}

		private void a(int A_0)
		{
			this.a();
			Rectangle bounds = base.Bounds;
			switch (this.a.Dock)
			{
			case DockStyle.Top:
				bounds.Height = A_0;
				break;
			case DockStyle.Bottom:
				bounds.Y = bounds.Bottom - A_0;
				bounds.Height = A_0;
				break;
			case DockStyle.Left:
				bounds.Width = A_0;
				break;
			case DockStyle.Right:
				bounds.X = bounds.Right - A_0;
				bounds.Width = A_0;
				break;
			}
			base.Bounds = bounds;
			this.b.PopupSize = A_0;
		}

		internal int f()
		{
			if (this.a.Dock == DockStyle.Left || this.a.Dock == DockStyle.Right)
			{
				return this.e.Width;
			}
			return this.e.Height;
		}

		public bool c()
		{
			return this.d != null;
		}

		internal void b()
		{
			this.c.b();
		}

		public ControlLayoutSystem d()
		{
			return this.b;
		}

		public void a(ControlLayoutSystem A_0)
		{
			if (this.b != null)
			{
				this.b.PopupContainer = null;
			}
			this.b = A_0;
			if (this.b != null)
			{
				this.b.PopupContainer = this;
			}
			this.e();
		}

		internal void e()
		{
			if (this.b != null)
			{
				this.e = base.ClientRectangle;
				switch (this.a.Dock)
				{
				case DockStyle.Top:
					this.f = new Rectangle(this.e.X, this.e.Bottom - 4, this.e.Width, 4);
					this.e.Height = this.e.Height - 4;
					break;
				case DockStyle.Bottom:
					this.f = new Rectangle(this.e.X, this.e.Y, this.e.Width, 4);
					this.e.Y = this.e.Y + 4;
					this.e.Height = this.e.Height - 4;
					break;
				case DockStyle.Left:
					this.f = new Rectangle(this.e.Right - 4, this.e.Y, 4, this.e.Height);
					this.e.Width = this.e.Width - 4;
					break;
				case DockStyle.Right:
					this.f = new Rectangle(this.e.X, this.e.Y, 4, this.e.Height);
					this.e.X = this.e.X + 4;
					this.e.Width = this.e.Width - 4;
					break;
				default:
					this.f = Rectangle.Empty;
					break;
				}
				foreach (object obj in this.b.Controls)
				{
					DockControl dockControl = (DockControl)obj;
					if (dockControl.Parent != this)
					{
						if (dockControl.Parent != null)
						{
							TD.SandDock.g.a(dockControl);
						}
						base.Controls.Add(dockControl);
					}
				}
				this.b.LayoutCollapsed(this.a.WorkingRenderer, this.e);
				base.Invalidate();
				return;
			}
			if (base.ContainsFocus)
			{
				base.Focus();
			}
			while (base.Controls.Count != 0)
			{
				base.Controls.RemoveAt(0);
			}
		}

		protected virtual void c(EventArgs A_0)
		{
			base.OnResize(A_0);
			this.e();
		}

		protected virtual void a(bool A_0)
		{
			if (A_0)
			{
				this.a = null;
				this.a(null);
				this.c = null;
				if (this.g != null)
				{
					this.g.c();
					this.g = null;
				}
				if (this.d != null)
				{
					this.a();
				}
			}
			base.Dispose(A_0);
		}

		protected virtual void d(EventArgs A_0)
		{
			base.OnEnter(A_0);
			if (this.b != null)
			{
				this.b.InvalidateTitleBar();
			}
		}

		protected virtual void a(EventArgs A_0)
		{
			base.OnLeave(A_0);
			if (this.b != null)
			{
				this.b.InvalidateTitleBar();
			}
		}

		private string a(Point A_0)
		{
			if (this.e.Contains(A_0) && this.b != null)
			{
				return this.b.GetToolTipText(A_0);
			}
			return "";
		}

		protected virtual void c(MouseEventArgs A_0)
		{
			base.OnMouseMove(A_0);
			if (this.f.Contains(A_0.X, A_0.Y) || this.d != null)
			{
				if (this.a.Dock == DockStyle.Left || this.a.Dock == DockStyle.Right)
				{
					this.Cursor = Cursors.VSplit;
				}
				else
				{
					this.Cursor = Cursors.HSplit;
				}
			}
			else
			{
				this.Cursor = Cursors.Default;
			}
			if (base.Capture && this.d != null)
			{
				this.d.a(new Point(A_0.X, A_0.Y));
				return;
			}
			if (this.e.Contains(A_0.X, A_0.Y) && this.b != null)
			{
				this.b.OnMouseMove(A_0);
			}
		}

		protected virtual void b(EventArgs A_0)
		{
			base.OnMouseLeave(A_0);
			this.Cursor = Cursors.Default;
			if (this.b != null)
			{
				this.b.OnMouseLeave();
			}
		}

		protected virtual void b(MouseEventArgs A_0)
		{
			base.OnMouseDown(A_0);
			if (this.f.Contains(A_0.X, A_0.Y) && A_0.Button == MouseButtons.Left)
			{
				this.b(new Point(A_0.X, A_0.Y));
				return;
			}
			if (this.e.Contains(A_0.X, A_0.Y) && this.b != null)
			{
				this.b.OnMouseDown(A_0);
			}
		}

		protected virtual void a(MouseEventArgs A_0)
		{
			base.OnMouseUp(A_0);
			if (this.d != null && A_0.Button == MouseButtons.Left)
			{
				this.d.a();
				return;
			}
			if (this.e.Contains(A_0.X, A_0.Y) && this.b != null)
			{
				this.b.OnMouseUp(A_0);
			}
		}

		protected virtual void a(PaintEventArgs A_0)
		{
			this.a.WorkingRenderer.DrawDockContainerBackground(A_0.Graphics, base.ClientRectangle);
		}

		protected virtual void b(PaintEventArgs A_0)
		{
			try
			{
				this.a.WorkingRenderer.StartRenderSession();
				if (this.b != null)
				{
					this.b.Paint(this.a.WorkingRenderer, A_0.Graphics, this.Font);
				}
				this.a.WorkingRenderer.FinishRenderSession();
			}
			catch
			{
			}
		}

		private DockContainer a = null;

		private ControlLayoutSystem b = null;

		private k c = null;

		private p d = null;

		private Rectangle e;

		private Rectangle f;

		private a g = null;
	}
}
