using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TD.SandDock
{
	internal class m : DockContainer
	{
		[DllImport("user32.dll")]
		private static extern bool SetWindowPos(HandleRef A_0, HandleRef A_1, int A_2, int A_3, int A_4, int A_5, int A_6);

		[DllImport("user32.dll")]
		private static extern bool ShowWindow(IntPtr A_0, int A_1);

		public m()
		{
			this.e = new f(this);
			this.e.Activated += base.c;
			this.e.Deactivate += base.d;
			this.e.Closing += this.a;
			this.e.DoubleClick += this.a;
			this.LayoutSystem.LayoutSystemsChanged += this.b;
			this.b(this.LayoutSystem, EventArgs.Empty);
			this.e.Controls.Add(this);
			this.Dock = DockStyle.Fill;
		}

		public bool j()
		{
			return this.e.Visible;
		}

		public new void c(bool A_0)
		{
			this.e.Visible = A_0;
		}

		public bool k()
		{
			return this.g;
		}

		public void b(bool A_0)
		{
			this.g = A_0;
		}

		public virtual SplitLayoutSystem b()
		{
			return base.LayoutSystem;
		}

		public virtual void a(SplitLayoutSystem A_0)
		{
			this.LayoutSystem.LayoutSystemsChanged -= this.b;
			base.LayoutSystem = A_0;
			this.LayoutSystem.LayoutSystemsChanged += this.b;
			this.b(this.LayoutSystem, EventArgs.Empty);
		}

		protected virtual void a(bool A_0)
		{
			if (A_0)
			{
				this.LayoutSystem.LayoutSystemsChanged -= this.b;
				this.e.Activated -= base.c;
				this.e.Deactivate -= base.d;
				this.e.Closing -= this.a;
				this.e.DoubleClick -= this.a;
				this.e.Controls.Remove(this);
				this.e.Dispose();
			}
			base.Dispose(A_0);
		}

		public void i()
		{
			this.e.Show();
		}

		public new void c()
		{
			TD.SandDock.m.ShowWindow(this.e.Handle, 4);
			foreach (object obj in this.e.Controls)
			{
				Control control = (Control)obj;
				control.Visible = true;
			}
		}

		public void f()
		{
			this.e.Hide();
		}

		public Form l()
		{
			return this.e;
		}

		public Rectangle a()
		{
			return this.e.Bounds;
		}

		public void a(Rectangle A_0, bool A_1, bool A_2)
		{
			int num = 0;
			if (A_1)
			{
				num |= 64;
			}
			else
			{
				num |= 128;
			}
			if (!A_2)
			{
				num |= 16;
			}
			TD.SandDock.m.SetWindowPos(new HandleRef(this, this.e.Handle), new HandleRef(this, IntPtr.Zero), A_0.X, A_0.Y, A_0.Width, A_0.Height, num);
			this.e.Visible = A_1;
			if (A_1)
			{
				foreach (object obj in this.e.Controls)
				{
					Control control = (Control)obj;
					control.Visible = true;
				}
			}
		}

		public Size g()
		{
			return this.e.Size;
		}

		public void a(Size A_0)
		{
			this.e.Size = A_0;
		}

		public Point h()
		{
			return this.e.Location;
		}

		public void a(Point A_0)
		{
			this.e.Location = A_0;
		}

		private void a(DockControl A_0, DockControl A_1)
		{
			if (A_1 != null && !A_1.p)
			{
				this.f.Controls[0].OnBeforeFirstShown(EventArgs.Empty);
				this.f.Controls[0].p = true;
			}
			if (A_1 != null)
			{
				this.e.Text = A_1.Text;
				return;
			}
			this.e.Text = "";
		}

		public void e()
		{
			this.b(null, null);
		}

		private void b(object A_0, EventArgs A_1)
		{
			if (this.f != null)
			{
				this.f.SelectedControlChanged -= this.a;
			}
			if (base.HasSingleControlLayoutSystem)
			{
				this.f = (ControlLayoutSystem)this.LayoutSystem.LayoutSystems[0];
				this.f.SelectedControlChanged += this.a;
				this.a(null, this.f.SelectedControl);
				return;
			}
			this.e.Text = "";
			this.f = null;
		}

		public virtual bool d()
		{
			return true;
		}

		private void a(object A_0, CancelEventArgs A_1)
		{
			if (this.g)
			{
				A_1.Cancel = true;
				DockControl[] array = base.r();
				foreach (DockControl dockControl in array)
				{
					if (!dockControl.Closable)
					{
						return;
					}
				}
				CancelEventArgs cancelEventArgs = new CancelEventArgs();
				foreach (DockControl dockControl2 in array)
				{
					dockControl2.OnClosing(cancelEventArgs);
					if (cancelEventArgs.Cancel)
					{
						return;
					}
				}
				this.f();
				foreach (DockControl dockControl3 in array)
				{
					dockControl3.OnClosed(EventArgs.Empty);
				}
			}
		}

		private void a(object A_0, EventArgs A_1)
		{
			ControlLayoutSystem controlLayoutSystem = base.b(this.LayoutSystem);
			if (controlLayoutSystem == null)
			{
				return;
			}
			DockControl selectedControl = controlLayoutSystem.SelectedControl;
			if (selectedControl == null)
			{
				return;
			}
			controlLayoutSystem = selectedControl.LastControlLayoutSystem;
			SplitLayoutSystem layoutSystem = this.LayoutSystem;
			this.LayoutSystem = new SplitLayoutSystem();
			base.Manager.a(this);
			int num = selectedControl.LastIndexInFixedLayoutSystem;
			if (num < 0)
			{
				num = 0;
			}
			if (num > controlLayoutSystem.Controls.Count)
			{
				num = controlLayoutSystem.Controls.Count;
			}
			layoutSystem.MoveToLayoutSystem(controlLayoutSystem, num);
			selectedControl.Activate();
		}

		private new const int a = 64;

		private new const int b = 16;

		private new const int c = 128;

		private new const int d = 4;

		private f e = null;

		private ControlLayoutSystem f = null;

		private bool g = true;
	}
}
