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

namespace TD.SandDock
{
	internal class m : DockContainer
	{
		private new const int m_a = 64;

		private new const int m_b = 16;

		private new const int m_c = 128;

		private new const int m_d = 4;

		private f m_e = null;

		private ControlLayoutSystem m_f = null;

		private bool m_g = true;

		[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.m_e = new f(this);
			this.m_e.Activated += base.c;
			this.m_e.Deactivate += base.d;
			this.m_e.Closing += a;
			this.m_e.DoubleClick += a;
			LayoutSystem.LayoutSystemsChanged += b;
			b(LayoutSystem, EventArgs.Empty);
			this.m_e.Controls.Add(this);
			Dock = DockStyle.Fill;
		}

		[SpecialName]
		public bool j()
		{
			return this.m_e.Visible;
		}

		[SpecialName]
		public new void c(bool A_0)
		{
			this.m_e.Visible = A_0;
		}

		[SpecialName]
		public bool k()
		{
			return this.m_g;
		}

		[SpecialName]
		public void b(bool A_0)
		{
			this.m_g = A_0;
		}

		[SpecialName]
		public override SplitLayoutSystem b()
		{
			return base.LayoutSystem;
		}

		[SpecialName]
		public override void a(SplitLayoutSystem A_0)
		{
			LayoutSystem.LayoutSystemsChanged -= b;
			base.LayoutSystem = A_0;
			LayoutSystem.LayoutSystemsChanged += b;
			b(LayoutSystem, EventArgs.Empty);
		}

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

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

		public new void c()
		{
			ShowWindow(this.m_e.Handle, 4);
			foreach (Control control in this.m_e.Controls)
			{
				control.Visible = true;
			}
		}

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

		[SpecialName]
		public Form l()
		{
			return this.m_e;
		}

		[SpecialName]
		public Rectangle a()
		{
			return this.m_e.Bounds;
		}

		public void a(Rectangle A_0, bool A_1, bool A_2)
		{
			int num = 0;
			num = ((!A_1) ? (num | 0x80) : (num | 0x40));
			if (!A_2)
			{
				num |= 0x10;
			}
			SetWindowPos(new HandleRef(this, this.m_e.Handle), new HandleRef(this, IntPtr.Zero), A_0.X, A_0.Y, A_0.Width, A_0.Height, num);
			this.m_e.Visible = A_1;
			if (!A_1)
			{
				return;
			}
			foreach (Control control in this.m_e.Controls)
			{
				control.Visible = true;
			}
		}

		[SpecialName]
		public Size g()
		{
			return this.m_e.Size;
		}

		[SpecialName]
		public void a(Size A_0)
		{
			this.m_e.Size = A_0;
		}

		[SpecialName]
		public Point h()
		{
			return ((Control)this.m_e).Location;
		}

		[SpecialName]
		public void a(Point A_0)
		{
			((Control)this.m_e).Location = A_0;
		}

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

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

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

		[SpecialName]
		public override bool d()
		{
			return true;
		}

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

		private void a(object A_0, EventArgs A_1)
		{
			ControlLayoutSystem controlLayoutSystem = b(LayoutSystem);
			if (controlLayoutSystem == null)
			{
				return;
			}
			DockControl selectedControl = controlLayoutSystem.SelectedControl;
			if (selectedControl != null)
			{
				controlLayoutSystem = selectedControl.LastControlLayoutSystem;
				SplitLayoutSystem layoutSystem = LayoutSystem;
				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();
			}
		}
	}
}
