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

namespace TD.Util
{
	internal class a : IDisposable
	{
		public delegate string b(Point A_0);

		private class a : Form
		{
			private const int m_a = 32;

			private const int m_b = int.MinValue;

			private const int m_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;

			[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)
			{
				e = A_0;
				SetStyle(ControlStyles.AllPaintingInWmPaint, value: true);
				SetStyle(ControlStyles.DoubleBuffer, value: true);
				f = b();
				h = new StringFormat(StringFormat.GenericDefault);
				h.Alignment = StringAlignment.Center;
				h.LineAlignment = StringAlignment.Center;
				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 && g)
				{
					f.Dispose();
					f = b();
					g = false;
				}
				else if (flag && !g)
				{
					f.Dispose();
					f = new Font("Arial Unicode MS", 8.25f);
					g = true;
				}
				using Graphics graphics = CreateGraphics();
				return graphics.MeasureString(A_0, f, 999, h);
			}

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

			[SpecialName]
			protected override CreateParams c()
			{
				CreateParams createParams = base.CreateParams;
				if (e != null && e.b() && a())
				{
					createParams.ClassStyle |= 131072;
				}
				return createParams;
			}

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

			protected override void a(bool A_0)
			{
				if (A_0)
				{
					f.Dispose();
					h.Dispose();
				}
				Dispose(A_0);
			}

			protected override 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 brush = new SolidBrush(SystemColors.InfoText);
				A_0.Graphics.DrawString(Text, f, brush, base.ClientRectangle, h);
			}
		}

		private const int m_a = 16;

		private const int m_b = 64;

		private const int m_c = 128;

		private const int m_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 a k = null;

		private Timer l = null;

		private Form m = null;

		private b n;

		[MethodImpl(MethodImplOptions.Synchronized)]
		[SpecialName]
		public void a(b A_0)
		{
			n = (b)Delegate.Combine(n, A_0);
		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		[SpecialName]
		public void b(b A_0)
		{
			n = (b)Delegate.Remove(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)
		{
			f = A_0;
			A_0.MouseMove += c;
			A_0.MouseLeave += c;
			A_0.MouseDown += b;
			A_0.Disposed += a;
			k = new a(this);
			k.MouseMove += a;
			l = new Timer();
			l.Interval = 500;
			l.Tick += d;
		}

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

		void IDisposable.Dispose()
		{
			//ILSpy generated this explicit interface implementation from .override directive in c
			this.c();
		}

		[SpecialName]
		public bool b()
		{
			return i;
		}

		[SpecialName]
		public void a(bool A_0)
		{
			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)
		{
			g = A_1;
			k.Text = A_1;
			SizeF sizeF = k.a(A_1);
			Size size = new Size((int)Math.Ceiling(sizeF.Width), (int)Math.Ceiling(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;
			}
			SetWindowPos(k.Handle, 0, A_0.X, A_0.Y, size.Width, size.Height, 80);
			k.Invalidate();
			h = true;
			if (m != null)
			{
				m.Deactivate -= b;
			}
			m = a(f);
			if (m != null)
			{
				m.Deactivate += b;
			}
		}

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

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

		private void d(object A_0, EventArgs A_1)
		{
			l.Enabled = false;
			Form form = a(f);
			if (form != null && Form.ActiveForm == form && f.Visible && n(f.PointToClient(Cursor.Position)) == g)
			{
				a(Cursor.Position, 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 (h)
			{
				d();
			}
			l.Enabled = false;
		}

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

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

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

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