using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using TD.SandDock.Rendering;

namespace TD.SandDock
{
	internal class e : j
	{
		public e(SandDockManager A_0, DockContainer A_1, LayoutSystemBase A_2, DockControl A_3, Point A_4, DockingHints A_5, bool A_6) : base(A_0, A_1, A_2, A_3, A_4, A_5, A_6)
		{
			if (base.k() != null && base.k().OwnerForm != null)
			{
				this.d();
				this.e();
			}
		}

		private void e()
		{
			DockContainer dockContainer = base.k().a(DockStyle.Top, base.k().OwnerForm);
			if (dockContainer != null)
			{
				this.g = new e.a(this, this.d, DockStyle.Top, dockContainer);
			}
			dockContainer = base.k().a(DockStyle.Left, base.k().OwnerForm);
			if (dockContainer != null)
			{
				this.e = new e.a(this, this.d, DockStyle.Left, dockContainer);
			}
			dockContainer = base.k().a(DockStyle.Bottom, base.k().OwnerForm);
			if (dockContainer != null)
			{
				this.h = new e.a(this, this.d, DockStyle.Bottom, dockContainer);
			}
			dockContainer = base.k().a(DockStyle.Right, base.k().OwnerForm);
			if (dockContainer != null)
			{
				this.f = new e.a(this, this.d, DockStyle.Right, dockContainer);
			}
			if (this.g != null)
			{
				this.g.h();
			}
			if (this.e != null)
			{
				this.e.h();
			}
			if (this.h != null)
			{
				this.h.h();
			}
			if (this.f != null)
			{
				this.f.h();
			}
		}

		public new static Rectangle a(SandDockManager A_0, bool A_1)
		{
			Rectangle clientRectangle = A_0.OwnerForm.ClientRectangle;
			DockContainer dockContainer = A_0.a(DockStyle.Left, A_0.OwnerForm);
			if (dockContainer != null)
			{
				clientRectangle = new Rectangle(dockContainer.Bounds.Right, clientRectangle.Y, clientRectangle.Width - dockContainer.Bounds.Right, clientRectangle.Height);
			}
			dockContainer = A_0.a(DockStyle.Right, A_0.OwnerForm);
			if (dockContainer != null)
			{
				clientRectangle.Width -= clientRectangle.Right - dockContainer.Bounds.Left;
			}
			dockContainer = A_0.a(DockStyle.Top, A_0.OwnerForm);
			if (dockContainer != null)
			{
				clientRectangle = new Rectangle(clientRectangle.X, dockContainer.Bounds.Bottom, clientRectangle.Width, clientRectangle.Height - dockContainer.Bounds.Bottom);
			}
			dockContainer = A_0.a(DockStyle.Bottom, A_0.OwnerForm);
			if (dockContainer != null)
			{
				clientRectangle.Height -= clientRectangle.Bottom - dockContainer.Bounds.Top;
			}
			clientRectangle = new Rectangle(A_0.OwnerForm.PointToScreen(clientRectangle.Location), clientRectangle.Size);
			if (clientRectangle.Width < 100 && A_1)
			{
				clientRectangle.Inflate((100 - clientRectangle.Width) / 2, 0);
			}
			if (clientRectangle.Height < 100 && A_1)
			{
				clientRectangle.Inflate(0, (100 - clientRectangle.Height) / 2);
			}
			return clientRectangle;
		}

		private void d()
		{
			this.d = TD.SandDock.e.a(base.k(), true);
		}

		protected override j.b b(Point A_0)
		{
			j.b b = null;
			if (!this.c)
			{
				ControlLayoutSystem controlLayoutSystem = this.a(A_0, out b);
				if (controlLayoutSystem == base.f() && base.h() == null)
				{
					controlLayoutSystem = null;
				}
				if (controlLayoutSystem != this.a)
				{
					if (this.b != null)
					{
						this.b.g();
						if (this.b != null)
						{
							this.b.Dispose();
							this.b = null;
						}
					}
					this.a = controlLayoutSystem;
					if (this.a != null)
					{
						this.b = new e.a(this, this.a);
						this.b.j();
					}
				}
			}
			if (b != null && b.a == TD.SandDock.j.c.a)
			{
				b = null;
			}
			if (this.b != null && this.b.i().Contains(A_0) && b == null)
			{
				b = this.b.a(A_0);
			}
			if (this.g != null && this.g.i().Contains(A_0) && b == null)
			{
				b = this.g.a(A_0);
			}
			if (this.h != null && this.h.i().Contains(A_0) && b == null)
			{
				b = this.h.a(A_0);
			}
			if (this.e != null && this.e.i().Contains(A_0) && b == null)
			{
				b = this.e.a(A_0);
			}
			if (this.f != null && this.f.i().Contains(A_0) && b == null)
			{
				b = this.f.a(A_0);
			}
			return b;
		}

		private new ControlLayoutSystem a(Point A_0, out j.b A_1)
		{
			A_1 = null;
			foreach (ControlLayoutSystem controlLayoutSystem in base.g())
			{
				Rectangle rectangle = new Rectangle(controlLayoutSystem.DockContainer.PointToScreen(controlLayoutSystem.Bounds.Location), controlLayoutSystem.Bounds.Size);
				if (rectangle.Contains(A_0))
				{
					A_1 = base.a(controlLayoutSystem.DockContainer, controlLayoutSystem, A_0, false);
					ControlLayoutSystem result;
					if (A_1.a == TD.SandDock.j.c.a)
					{
						result = controlLayoutSystem;
					}
					else
					{
						result = null;
					}
					return result;
				}
			}
			return null;
		}

		private new void a(ref e.a A_0)
		{
			if (A_0 != null)
			{
				A_0.Visible = false;
				A_0.Dispose();
				A_0 = null;
			}
		}

		public override void b()
		{
			this.a(ref this.b);
			this.a(ref this.e);
			this.a(ref this.g);
			this.a(ref this.f);
			this.a(ref this.h);
			base.b();
		}

		private new ControlLayoutSystem a = null;

		private new e.a b = null;

		private new bool c = false;

		private Rectangle d = Rectangle.Empty;

		private e.a e;

		private new e.a f;

		private e.a g;

		private e.a h;

		private new class a : i
		{
			[DllImport("user32.dll")]
			private static extern bool SetWindowPos(HandleRef A_0, int A_1, int A_2, int A_3, int A_4, int A_5, int A_6);

			private a()
			{
				base.FormBorderStyle = FormBorderStyle.None;
				base.ShowInTaskbar = false;
				base.StartPosition = FormStartPosition.Manual;
				base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
				base.SetStyle(ControlStyles.DoubleBuffer, true);
				this.BackColor = Color.FromArgb(245, 238, 238);
				this.j = new Bitmap(93, 93, PixelFormat.Format32bppArgb);
			}

			public a(e A_0, Rectangle A_1, DockStyle A_2, DockContainer A_3) : this()
			{
				this.e = A_0;
				this.l = A_2;
				this.k = A_3;
				switch (A_2)
				{
				case DockStyle.Top:
					this.g = new Rectangle(A_1.X + A_1.Width / 2 - 46, A_1.Y + 15, 93, 93);
					break;
				case DockStyle.Bottom:
					this.g = new Rectangle(A_1.X + A_1.Width / 2 - 46, A_1.Bottom - 93 - 15, 93, 93);
					break;
				case DockStyle.Left:
					this.g = new Rectangle(A_1.X + 15, A_1.Y + A_1.Height / 2 - 46, 93, 93);
					break;
				case DockStyle.Right:
					this.g = new Rectangle(A_1.Right - 93 - 15, A_1.Y + A_1.Height / 2 - 46, 93, 93);
					break;
				}
				this.f();
			}

			public a(e A_0, ControlLayoutSystem A_1) : this()
			{
				this.e = A_0;
				this.f = A_1;
				this.k = A_1.DockContainer;
				this.g = new Rectangle(A_1.DockContainer.PointToScreen(A_1.Bounds.Location), A_1.Bounds.Size);
				this.g = new Rectangle(this.g.X + this.g.Width / 2 - 46, this.g.Y + this.g.Height / 2 - 46, 93, 93);
				this.f();
			}

			private void f()
			{
				using (Graphics graphics = Graphics.FromImage(this.j))
				{
					graphics.Clear(Color.Transparent);
					Color highlight = SystemColors.Highlight;
					Color color = RendererBase.InterpolateColors(highlight, Color.Transparent, 0.2f);
					if (this.f != null)
					{
						Point[] points = new Point[]
						{
							new Point(46, 9),
							new Point(83, 46),
							new Point(46, 83),
							new Point(9, 46)
						};
						using (SolidBrush solidBrush = new SolidBrush(this.BackColor))
						{
							graphics.FillPolygon(solidBrush, points);
						}
						graphics.DrawPolygon(SystemPens.ControlDark, points);
					}
					if (this.l == DockStyle.None || this.l == DockStyle.Top)
					{
						this.a(graphics, (this.i && this.h == DockSide.Top) ? highlight : color);
					}
					if (this.l == DockStyle.None || this.l == DockStyle.Right)
					{
						this.b(graphics, (this.i && this.h == DockSide.Right) ? highlight : color);
					}
					if (this.l == DockStyle.None || this.l == DockStyle.Bottom)
					{
						this.c(graphics, (this.i && this.h == DockSide.Bottom) ? highlight : color);
					}
					if (this.l == DockStyle.None || this.l == DockStyle.Left)
					{
						this.d(graphics, (this.i && this.h == DockSide.Left) ? highlight : color);
					}
					if (this.l == DockStyle.None)
					{
						this.e(graphics, (this.i && this.h == DockSide.None) ? highlight : color);
					}
				}
				base.a(this.j, byte.MaxValue);
			}

			protected virtual void a(bool A_0)
			{
				if (A_0)
				{
					this.j.Dispose();
				}
				base.Dispose(A_0);
			}

			public j.b a(Point A_0)
			{
				Point a_ = base.PointToClient(A_0);
				j.b b = new j.b(TD.SandDock.j.c.d);
				b.c = this.f;
				b.b = this.k;
				if (this.a(this.d(), a_) && (this.l == DockStyle.None || this.l == DockStyle.Top))
				{
					b.d = DockSide.Top;
				}
				else if (this.a(this.c(), a_) && (this.l == DockStyle.None || this.l == DockStyle.Right))
				{
					b.d = DockSide.Right;
				}
				else if (this.a(this.b(), a_) && (this.l == DockStyle.None || this.l == DockStyle.Bottom))
				{
					b.d = DockSide.Bottom;
				}
				else if (this.a(this.a(), a_) && (this.l == DockStyle.None || this.l == DockStyle.Left))
				{
					b.d = DockSide.Left;
				}
				else if (this.a(this.e(), a_) && this.l == DockStyle.None)
				{
					b.a = TD.SandDock.j.c.e;
					b.d = DockSide.None;
				}
				else
				{
					b.a = TD.SandDock.j.c.a;
				}
				if (this.l != DockStyle.None)
				{
					if (b.a != TD.SandDock.j.c.a)
					{
						b.a = TD.SandDock.j.c.f;
						b.e = this.e.a(this.k, this.e.f());
					}
				}
				else
				{
					b.e = this.e.a(this.f.DockContainer, this.f, b.d);
				}
				bool flag = b.a != TD.SandDock.j.c.a;
				DockSide dockSide = (b.a == TD.SandDock.j.c.a) ? this.h : b.d;
				if (flag != this.i || dockSide != this.h)
				{
					this.i = flag;
					this.h = dockSide;
					this.f();
				}
				return b;
			}

			private bool a(GraphicsPath A_0, Point A_1)
			{
				Region region = new Region(new Rectangle(0, 0, 93, 93));
				region.Exclude(new Rectangle(0, 0, 93, 93));
				region.Union(A_0);
				return region.IsVisible(A_1);
			}

			private GraphicsPath e()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddEllipse(29, 29, 33, 33);
				return graphicsPath;
			}

			private GraphicsPath d()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[]
				{
					new Point(25, 19),
					new Point(44, 0),
					new Point(48, 0),
					new Point(67, 19),
					new Point(57, 29),
					new Point(56, 28),
					new Point(50, 25),
					new Point(42, 25),
					new Point(36, 28),
					new Point(35, 29)
				});
				return graphicsPath;
			}

			private GraphicsPath c()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[]
				{
					new Point(73, 25),
					new Point(92, 44),
					new Point(92, 48),
					new Point(73, 67),
					new Point(63, 57),
					new Point(64, 56),
					new Point(67, 50),
					new Point(67, 42),
					new Point(64, 36),
					new Point(63, 35)
				});
				return graphicsPath;
			}

			private GraphicsPath b()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[]
				{
					new Point(67, 73),
					new Point(48, 92),
					new Point(44, 92),
					new Point(25, 73),
					new Point(35, 63),
					new Point(36, 64),
					new Point(42, 67),
					new Point(50, 67),
					new Point(56, 64),
					new Point(57, 63)
				});
				return graphicsPath;
			}

			private GraphicsPath a()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[]
				{
					new Point(29, 57),
					new Point(19, 67),
					new Point(0, 48),
					new Point(0, 44),
					new Point(19, 25),
					new Point(29, 35),
					new Point(28, 36),
					new Point(25, 42),
					new Point(25, 50),
					new Point(28, 56)
				});
				return graphicsPath;
			}

			public Rectangle i()
			{
				return this.g;
			}

			private void e(Graphics A_0, Color A_1)
			{
				Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
				RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(this.e()))
				{
					pathGradientBrush.CenterColor = A_1;
					pathGradientBrush.SurroundColors = new Color[]
					{
						color
					};
					A_0.FillPath(pathGradientBrush, this.e());
				}
				SmoothingMode smoothingMode = A_0.SmoothingMode;
				A_0.SmoothingMode = SmoothingMode.AntiAlias;
				using (Pen pen = new Pen(RendererBase.InterpolateColors(A_1, Color.Black, 0.1f)))
				{
					A_0.DrawPath(pen, this.e());
				}
				A_0.SmoothingMode = smoothingMode;
				using (Pen pen2 = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawLine(pen2, 39, 53, 39, 39);
					A_0.DrawLine(pen2, 39, 39, 54, 39);
					A_0.DrawLine(pen2, 54, 39, 54, 53);
					A_0.DrawLine(pen2, 40, 54, 46, 54);
					A_0.DrawLine(pen2, 48, 54, 53, 54);
					A_0.DrawLine(pen2, 47, 53, 47, 51);
					A_0.DrawLine(pen2, 47, 51, 54, 51);
				}
				using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight)))
				{
					A_0.FillRectangle(solidBrush, 40, 40, 14, 11);
					A_0.FillRectangle(solidBrush, 40, 51, 7, 3);
				}
			}

			private void d(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(this.a()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[]
					{
						color2,
						color2,
						A_1,
						color,
						color
					};
					A_0.FillPath(pathGradientBrush, this.a());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 9, 39, 12, 14);
					A_0.DrawLine(pen, 13, 39, 13, 53);
					A_0.DrawLine(pen, 15, 46, 19, 46);
					A_0.DrawLine(pen, 16, 45, 16, 47);
					A_0.DrawLine(pen, 17, 44, 17, 48);
				}
				using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight)))
				{
					A_0.FillRectangle(solidBrush, 10, 40, 3, 13);
				}
			}

			private void c(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(this.b()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[]
					{
						color2,
						color2,
						A_1,
						color,
						color
					};
					A_0.FillPath(pathGradientBrush, this.b());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 39, 71, 14, 12);
					A_0.DrawLine(pen, 39, 79, 53, 79);
					A_0.DrawLine(pen, 46, 73, 46, 77);
					A_0.DrawLine(pen, 44, 75, 48, 75);
					A_0.DrawLine(pen, 45, 76, 47, 76);
				}
				using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight)))
				{
					A_0.FillRectangle(solidBrush, 40, 80, 13, 3);
				}
			}

			private void b(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(this.c()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[]
					{
						color,
						A_1,
						color2,
						color2,
						color,
						color,
						color,
						color,
						color
					};
					A_0.FillPath(pathGradientBrush, this.c());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 71, 39, 12, 14);
					A_0.DrawLine(pen, 79, 39, 79, 53);
					A_0.DrawLine(pen, 73, 46, 77, 46);
					A_0.DrawLine(pen, 75, 44, 75, 48);
					A_0.DrawLine(pen, 76, 45, 76, 47);
				}
				using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight)))
				{
					A_0.FillRectangle(solidBrush, 80, 40, 3, 13);
				}
			}

			private void a(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(this.d()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[]
					{
						color,
						color,
						A_1,
						color2,
						color2
					};
					A_0.FillPath(pathGradientBrush, this.d());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 39, 9, 14, 12);
					A_0.DrawLine(pen, 39, 13, 53, 13);
					A_0.DrawLine(pen, 46, 15, 46, 19);
					A_0.DrawLine(pen, 44, 17, 48, 17);
					A_0.DrawLine(pen, 45, 16, 47, 16);
				}
				using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight)))
				{
					A_0.FillRectangle(solidBrush, 40, 10, 13, 3);
				}
			}

			private void a(double A_0, double A_1)
			{
				this.e.c = true;
				int tickCount = Environment.TickCount;
				for (;;)
				{
					int num = Environment.TickCount - tickCount;
					if (num > 200)
					{
						goto IL_55;
					}
					double num2 = (double)num / 200.0;
					num2 = A_0 + (A_1 - A_0) * num2;
					if (base.IsDisposed)
					{
						break;
					}
					base.a(this.j, (byte)num2);
					Application.DoEvents();
				}
				return;
				IL_55:
				this.e.c = false;
				if (!base.IsDisposed)
				{
					base.a(this.j, (byte)A_1);
				}
			}

			public void g()
			{
				this.a(255.0, 0.0);
				base.Hide();
			}

			public void j()
			{
				base.a(this.j, 0);
				this.h();
				this.a(0.0, 255.0);
			}

			public void h()
			{
				TD.SandDock.e.a.SetWindowPos(new HandleRef(this, base.Handle), -1, this.g.X, this.g.Y, this.g.Width, this.g.Height, 80);
			}

			private new const int a = 93;

			private const int b = 93;

			private const int c = 16;

			private const int d = 64;

			private e e = null;

			private ControlLayoutSystem f = null;

			private Rectangle g = Rectangle.Empty;

			private DockSide h = DockSide.None;

			private bool i = false;

			private Bitmap j = null;

			private DockContainer k = null;

			private DockStyle l = DockStyle.None;
		}
	}
}
