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

namespace TD.Util
{
	internal class a : IDisposable
	{
		[MethodImpl(MethodImplOptions.Synchronized)]
		public void a(TD.Util.a.b A_0)
		{
			this.n = (TD.Util.a.b)Delegate.Combine(this.n, A_0);
		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		public void b(TD.Util.a.b A_0)
		{
			this.n = (TD.Util.a.b)Delegate.Remove(this.n, A_0);
		}

		[DllImport("user32.dll")]
		private static extern bool SetWindowPos(IntPtr A_0, int A_1, int A_2, int A_3, int A_4, int A_5, int A_6);

		public a(Control A_0)
		{
			this.f = A_0;
			A_0.MouseMove += this.c;
			A_0.MouseLeave += this.c;
			A_0.MouseDown += this.b;
			A_0.Disposed += this.a;
			this.k = new TD.Util.a.a(this);
			this.k.MouseMove += this.a;
			this.l = new Timer();
			this.l.Interval = 500;
			this.l.Tick += this.d;
		}

		public void c()
		{
			if (!this.j)
			{
				this.d();
				this.k.MouseMove -= this.a;
				this.k.Dispose();
				this.k = null;
				this.f.MouseMove -= this.c;
				this.f.MouseLeave -= this.c;
				this.f.MouseDown -= this.b;
				this.f.Disposed -= this.a;
				this.f = null;
				this.l.Tick -= this.d;
				this.l.Dispose();
				this.j = true;
			}
		}

		public bool b()
		{
			return this.i;
		}

		public void a(bool A_0)
		{
			this.i = A_0;
		}

		private static bool a()
		{
			bool result = false;
			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
			{
				result = (Environment.OSVersion.Version >= new Version(5, 1, 0, 0));
			}
			return result;
		}

		public void a(Point A_0, string A_1)
		{
			this.g = A_1;
			this.k.Text = A_1;
			SizeF sizeF = this.k.a(A_1);
			Size size = new Size((int)Math.Ceiling((double)sizeF.Width), (int)Math.Ceiling((double)sizeF.Height));
			size.Height += 4;
			size.Width += 4;
			A_0.Y += 19;
			Screen screen = Screen.FromPoint(A_0);
			if (A_0.X + size.Width > screen.Bounds.Right)
			{
				A_0.X = screen.Bounds.Right - size.Width;
			}
			if (A_0.X < screen.Bounds.Left)
			{
				A_0.X = screen.Bounds.Left;
			}
			if (A_0.Y < screen.Bounds.Top)
			{
				A_0.Y = screen.Bounds.Top;
			}
			if (A_0.Y + size.Height > screen.Bounds.Bottom)
			{
				A_0.Y -= 38;
			}
			TD.Util.a.SetWindowPos(this.k.Handle, 0, A_0.X, A_0.Y, size.Width, size.Height, 80);
			this.k.Invalidate();
			this.h = true;
			if (this.m != null)
			{
				this.m.Deactivate -= this.b;
			}
			this.m = this.a(this.f);
			if (this.m != null)
			{
				this.m.Deactivate += this.b;
			}
		}

		public void d()
		{
			TD.Util.a.SetWindowPos(this.k.Handle, 0, 0, 0, 0, 0, 147);
			this.h = false;
			if (this.m != null)
			{
				this.m.Deactivate -= this.b;
				this.m = null;
			}
		}

		private void c(object A_0, MouseEventArgs A_1)
		{
			if (A_1.Button != MouseButtons.None)
			{
				return;
			}
			string text = this.n(new Point(A_1.X, A_1.Y));
			if (this.h)
			{
				if (text.Length == 0)
				{
					this.d();
					return;
				}
				if (text == this.g)
				{
					return;
				}
				if (text.Length != 0)
				{
					this.a(Cursor.Position, text);
					return;
				}
			}
			else if (text.Length != 0)
			{
				this.g = text;
				this.l.Enabled = false;
				this.l.Enabled = true;
				return;
			}
		}

		private void d(object A_0, EventArgs A_1)
		{
			this.l.Enabled = false;
			Form form = this.a(this.f);
			if (form != null && Form.ActiveForm == form && this.f.Visible && this.n(this.f.PointToClient(Cursor.Position)) == this.g)
			{
				this.a(Cursor.Position, this.g);
			}
		}

		private Form a(Control A_0)
		{
			while (A_0.Parent != null)
			{
				A_0 = A_0.Parent;
			}
			return A_0 as Form;
		}

		private void c(object A_0, EventArgs A_1)
		{
			if (this.h)
			{
				this.d();
			}
			this.l.Enabled = false;
		}

		private void b(object A_0, MouseEventArgs A_1)
		{
			if (this.h)
			{
				this.d();
			}
			this.l.Enabled = false;
		}

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

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

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

		private const int a = 16;

		private const int b = 64;

		private const int c = 128;

		private const int d = 2;

		private const int e = 1;

		private Control f = null;

		private string g = "";

		private bool h = false;

		private bool i = true;

		private bool j = false;

		private TD.Util.a.a k = null;

		private Timer l = null;

		private Form m = null;

		private TD.Util.a.b n;

		public delegate string b(Point A_0);

		private class a : Form
		{
			[DllImport("user32.dll")]
			private static extern bool SystemParametersInfo(int A_0, int A_1, ref int A_2, int A_3);

			public a(TD.Util.a A_0)
			{
				this.e = A_0;
				base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
				base.SetStyle(ControlStyles.DoubleBuffer, true);
				this.f = this.b();
				this.h = new StringFormat(StringFormat.GenericDefault);
				this.h.Alignment = StringAlignment.Center;
				this.h.LineAlignment = StringAlignment.Center;
				this.h.FormatFlags = (StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
				base.ShowInTaskbar = false;
				base.FormBorderStyle = FormBorderStyle.None;
				base.ControlBox = false;
				base.StartPosition = FormStartPosition.Manual;
			}

			public SizeF a(string A_0)
			{
				bool flag = false;
				for (int i = 0; i < A_0.Length; i++)
				{
					if (A_0[i] > 'ÿ')
					{
						flag = true;
						break;
					}
				}
				if (!flag && this.g)
				{
					this.f.Dispose();
					this.f = this.b();
					this.g = false;
				}
				else if (flag && !this.g)
				{
					this.f.Dispose();
					this.f = new Font("Arial Unicode MS", 8.25f);
					this.g = true;
				}
				SizeF result;
				using (Graphics graphics = base.CreateGraphics())
				{
					result = graphics.MeasureString(A_0, this.f, 999, this.h);
				}
				return result;
			}

			private Font b()
			{
				Font result;
				try
				{
					Font font = new Font("Tahoma", 8.25f);
					result = font;
				}
				catch
				{
					result = new Font(Control.DefaultFont, Control.DefaultFont.Style);
				}
				return result;
			}

			protected virtual CreateParams c()
			{
				CreateParams createParams = base.CreateParams;
				if (this.e != null && this.e.b() && TD.Util.a.a.a())
				{
					createParams.ClassStyle |= 131072;
				}
				return createParams;
			}

			private static bool a()
			{
				int value = 0;
				if (!TD.Util.a.a())
				{
					return false;
				}
				TD.Util.a.a.SystemParametersInfo(4132, 0, ref value, 0);
				return Convert.ToBoolean(value);
			}

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

			protected virtual void a(PaintEventArgs A_0)
			{
				A_0.Graphics.FillRectangle(SystemBrushes.Info, base.ClientRectangle);
				A_0.Graphics.DrawLine(SystemPens.Control, base.ClientRectangle.Left, base.ClientRectangle.Top, base.ClientRectangle.Right, base.ClientRectangle.Top);
				A_0.Graphics.DrawLine(SystemPens.Control, base.ClientRectangle.Left, base.ClientRectangle.Top, base.ClientRectangle.Left, base.ClientRectangle.Bottom);
				A_0.Graphics.DrawLine(SystemPens.InfoText, base.ClientRectangle.Left, base.ClientRectangle.Bottom - 1, base.ClientRectangle.Right, base.ClientRectangle.Bottom - 1);
				A_0.Graphics.DrawLine(SystemPens.InfoText, base.ClientRectangle.Right - 1, base.ClientRectangle.Top, base.ClientRectangle.Right - 1, base.ClientRectangle.Bottom);
				using (SolidBrush solidBrush = new SolidBrush(SystemColors.InfoText))
				{
					A_0.Graphics.DrawString(this.Text, this.f, solidBrush, base.ClientRectangle, this.h);
				}
			}

			private const int a = 32;

			private const int b = -2147483648;

			private const int c = 131072;

			private const int d = 4132;

			private TD.Util.a e = null;

			private Font f = null;

			private bool g = false;

			private StringFormat h = null;
		}
	}
}
