using System;
using System.Drawing;
using System.Windows.Forms;

namespace TD.SandDock
{
	internal class f : Form
	{
		private const int m_a = 132;

		private const int m_b = 2;

		private const int c = 1;

		private const int d = 517;

		private m e = null;

		private Point m_f;

		public f(m A_0)
		{
			e = A_0;
			base.FormBorderStyle = FormBorderStyle.SizableToolWindow;
			base.StartPosition = FormStartPosition.Manual;
			base.ShowInTaskbar = false;
		}

		protected override void a(EventArgs A_0)
		{
			base.OnActivated(A_0);
		}

		protected override void b(EventArgs A_0)
		{
			OnResize(A_0);
			if (e != null)
			{
				DockControl[] array = e.r();
				foreach (DockControl dockControl in array)
				{
					dockControl.FloatingSize = base.Size;
				}
			}
		}

		protected override void OnMove(EventArgs e)
		{
			base.OnMove(e);
			if (this.e != null)
			{
				DockControl[] array = this.e.r();
				foreach (DockControl dockControl in array)
				{
					dockControl.FloatingLocation = ((Control)this).Location;
				}
			}
		}

		protected override void OnMouseDown(MouseEventArgs e)
		{
			base.OnMouseDown(e);
			if (e.Button == MouseButtons.Left)
			{
				ref Point reference = ref m_f;
				reference = new Point(e.X, e.Y);
			}
		}

		protected override void OnDoubleClick(EventArgs e)
		{
			base.OnDoubleClick(e);
		}

		private bool a()
		{
			if (e.HasSingleControlLayoutSystem)
			{
				ControlLayoutSystem controlLayoutSystem = (ControlLayoutSystem)e.LayoutSystem.LayoutSystems[0];
				if (controlLayoutSystem.SelectedControl != null)
				{
					e.OnShowControlContextMenu(new ShowControlContextMenuEventArgs(controlLayoutSystem.SelectedControl, controlLayoutSystem.SelectedControl.PointToClient(Cursor.Position)));
					return true;
				}
			}
			return false;
		}

		protected override void OnMouseUp(MouseEventArgs e)
		{
			base.OnMouseUp(e);
			m_f = Point.Empty;
		}

		protected override void OnMouseMove(MouseEventArgs e)
		{
			base.OnMouseMove(e);
			if (e.Button == MouseButtons.Left && m_f != Point.Empty)
			{
				Rectangle rectangle = new Rectangle(m_f, SystemInformation.DragSize);
				rectangle.Offset(-SystemInformation.DragSize.Width / 2, -SystemInformation.DragSize.Height / 2);
				if (!rectangle.Contains(e.X, e.Y))
				{
					m_f.Y += SystemInformation.ToolWindowCaptionHeight + SystemInformation.FrameBorderSize.Height;
					this.e.LayoutSystem.a(this.e.Manager, this.e, this.e.LayoutSystem, null, m_f, this.e.Manager.DockingHints, this.e.Manager.DockingManager);
					this.e.x = this.e.LayoutSystem;
					base.Capture = false;
					this.e.Capture = true;
					m_f = Point.Empty;
				}
			}
		}

		protected override void a(ref Message A_0)
		{
			if (A_0.Msg == 132)
			{
				WndProc(ref A_0);
				if (A_0.Result.ToInt32() == 2)
				{
					A_0.Result = new IntPtr(1);
				}
			}
			else if (A_0.Msg == 517 && a())
			{
				A_0.Result = IntPtr.Zero;
			}
			else
			{
				WndProc(ref A_0);
			}
		}
	}
}
