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

namespace TD.SandDock.Rendering
{
	public class Office2003Renderer : RendererBase
	{
		public enum Office2003ColorScheme
		{
			Automatic,
			Standard,
			LunaBlue,
			LunaOlive,
			LunaSilver
		}

		private Color m_a;

		private Color m_b;

		private Color m_c;

		private Color m_d;

		internal Color e;

		internal Color f;

		internal Color g;

		internal Color h;

		internal Color i;

		internal Color j;

		internal Color k;

		internal Color l;

		private Color m;

		private Color n;

		private Color o;

		private Color p;

		private Color q;

		private Color r;

		private Office2003ColorScheme s = Office2003ColorScheme.Automatic;

		private StringFormat t;

		private StringFormat u;

		private BoxModel v;

		private BoxModel w = null;

		public Color HighlightBorderColor
		{
			get
			{
				return this.m_b;
			}
			set
			{
				this.m_b = value;
				base.CustomColors = true;
			}
		}

		public Color HighlightBackgroundColor1
		{
			get
			{
				return this.m_c;
			}
			set
			{
				this.m_c = value;
				base.CustomColors = true;
			}
		}

		public Color HighlightBackgroundColor2
		{
			get
			{
				return this.m_d;
			}
			set
			{
				this.m_d = value;
				base.CustomColors = true;
			}
		}

		public Color BackgroundColor
		{
			get
			{
				return this.m_a;
			}
			set
			{
				this.m_a = value;
				base.CustomColors = true;
			}
		}

		public Color InactiveTitleBarColor1
		{
			get
			{
				return p;
			}
			set
			{
				p = value;
				base.CustomColors = true;
			}
		}

		public Color InactiveTitleBarColor2
		{
			get
			{
				return q;
			}
			set
			{
				q = value;
				base.CustomColors = true;
			}
		}

		public Color ActiveTitleBarColor1
		{
			get
			{
				return n;
			}
			set
			{
				n = value;
				base.CustomColors = true;
			}
		}

		public Color ActiveTitleBarColor2
		{
			get
			{
				return o;
			}
			set
			{
				o = value;
				base.CustomColors = true;
			}
		}

		public Color GripperColor
		{
			get
			{
				return r;
			}
			set
			{
				r = value;
				base.CustomColors = true;
			}
		}

		public Color DocumentStripBackgroundColor1
		{
			get
			{
				return e;
			}
			set
			{
				e = value;
				base.CustomColors = true;
			}
		}

		public Color DocumentStripBackgroundColor2
		{
			get
			{
				return f;
			}
			set
			{
				f = value;
				base.CustomColors = true;
			}
		}

		public Color ActiveDocumentBorderColor
		{
			get
			{
				return g;
			}
			set
			{
				g = value;
				base.CustomColors = true;
			}
		}

		public Color InactiveDocumentBorderColor
		{
			get
			{
				return h;
			}
			set
			{
				h = value;
				base.CustomColors = true;
			}
		}

		public Color ActiveDocumentHighlightColor
		{
			get
			{
				return i;
			}
			set
			{
				i = value;
				base.CustomColors = true;
			}
		}

		public Color InactiveDocumentHighlightColor
		{
			get
			{
				return j;
			}
			set
			{
				j = value;
				base.CustomColors = true;
			}
		}

		public Color ActiveDocumentShadowColor
		{
			get
			{
				return k;
			}
			set
			{
				k = value;
				base.CustomColors = true;
			}
		}

		public Color InactiveDocumentShadowColor
		{
			get
			{
				return l;
			}
			set
			{
				l = value;
				base.CustomColors = true;
			}
		}

		public Color WidgetColor
		{
			get
			{
				return m;
			}
			set
			{
				m = value;
				base.CustomColors = true;
			}
		}

		public Office2003ColorScheme ColorScheme
		{
			get
			{
				return s;
			}
			set
			{
				s = value;
				CalculateBaseColors();
			}
		}

		protected internal override BoxModel TitleBarMetrics => new BoxModel(0, 25, 4, 0, 0, 0, 0, 0, 0, 1);

		protected internal override TabTextDisplayMode TabTextDisplay => TabTextDisplayMode.SelectedTab;

		protected internal override BoxModel TabMetrics
		{
			get
			{
				if (w == null)
				{
					w = new BoxModel(0, 0, 0, 0, 0, 0, 0, 0, -1, 0);
				}
				return w;
			}
		}

		protected internal override BoxModel TabStripMetrics
		{
			get
			{
				if (v == null)
				{
					v = new BoxModel(0, Control.DefaultFont.Height + 10, 0, 0, 0, 1, 0, 0, 0, 0);
				}
				return v;
			}
		}

		protected internal override Size DocumentClientPadding => new Size(4, 4);

		protected internal override Size ControlClientPadding => new Size(0, 0);

		protected internal override int DocumentTabStripSize => Control.DefaultFont.Height + 15;

		protected internal override int DocumentTabSize => Control.DefaultFont.Height + 7;

		protected internal override int DocumentTabExtra => 18;

		private void d()
		{
			this.m_b = SystemColors.Highlight;
			this.m_c = RendererBase.InterpolateColors(this.m_b, SystemColors.Window, 0.7f);
			this.m_d = this.m_c;
			this.m_a = RendererBase.InterpolateColors(SystemColors.Control, SystemColors.Window, 0.8f);
			p = this.m_a;
			q = RendererBase.InterpolateColors(SystemColors.Control, Color.Black, 0.03f);
			n = Color.FromArgb(212, 213, 216);
			o = Color.FromArgb(212, 213, 216);
			r = SystemColors.ControlDark;
			e = SystemColors.Control;
			f = SystemColors.ControlLightLight;
			g = SystemColors.ControlDark;
			h = SystemColors.ControlDark;
			i = SystemColors.ControlLightLight;
			j = SystemColors.Control;
			k = SystemColors.ControlLightLight;
			l = SystemColors.Control;
			m = SystemColors.ControlText;
		}

		private void c()
		{
			this.m_b = Color.FromArgb(0, 0, 128);
			this.m_c = Color.FromArgb(255, 244, 204);
			this.m_d = Color.FromArgb(255, 211, 142);
			this.m_a = Color.FromArgb(195, 218, 249);
			p = Color.FromArgb(221, 236, 254);
			q = Color.FromArgb(129, 169, 226);
			n = Color.FromArgb(255, 211, 142);
			o = Color.FromArgb(254, 145, 78);
			r = Color.FromArgb(39, 65, 118);
			e = Color.FromArgb(196, 218, 250);
			f = SystemColors.ControlLightLight;
			g = Color.FromArgb(59, 97, 156);
			h = Color.FromArgb(0, 53, 154);
			i = SystemColors.ControlLightLight;
			j = SystemColors.ControlLightLight;
			k = SystemColors.ControlLightLight;
			l = Color.FromArgb(117, 166, 241);
			m = SystemColors.ControlText;
		}

		private void b()
		{
			this.m_b = Color.FromArgb(63, 93, 56);
			this.m_c = Color.FromArgb(255, 244, 204);
			this.m_d = Color.FromArgb(255, 211, 142);
			this.m_a = Color.FromArgb(242, 240, 228);
			p = Color.FromArgb(244, 247, 222);
			q = Color.FromArgb(183, 198, 145);
			n = Color.FromArgb(255, 211, 142);
			o = Color.FromArgb(254, 145, 78);
			r = Color.FromArgb(81, 94, 51);
			e = Color.FromArgb(242, 241, 228);
			f = SystemColors.ControlLightLight;
			g = Color.FromArgb(96, 128, 88);
			h = Color.FromArgb(96, 119, 107);
			i = SystemColors.ControlLightLight;
			j = SystemColors.ControlLightLight;
			k = SystemColors.ControlLightLight;
			l = Color.FromArgb(176, 194, 140);
			m = SystemColors.ControlText;
		}

		private void a()
		{
			this.m_b = Color.FromArgb(75, 75, 111);
			this.m_c = Color.FromArgb(255, 244, 204);
			this.m_d = Color.FromArgb(255, 211, 142);
			this.m_a = Color.FromArgb(243, 243, 247);
			p = Color.FromArgb(243, 244, 250);
			q = Color.FromArgb(140, 138, 172);
			n = Color.FromArgb(255, 211, 142);
			o = Color.FromArgb(254, 145, 78);
			r = Color.FromArgb(84, 84, 117);
			e = Color.FromArgb(243, 243, 247);
			f = SystemColors.ControlLightLight;
			g = Color.FromArgb(124, 124, 148);
			h = Color.FromArgb(118, 116, 146);
			i = SystemColors.ControlLightLight;
			j = SystemColors.ControlLightLight;
			k = SystemColors.ControlLightLight;
			l = Color.FromArgb(186, 185, 206);
			m = SystemColors.ControlText;
		}

		protected override void CalculateBaseColors()
		{
			base.CalculateBaseColors();
			switch (s)
			{
			case Office2003ColorScheme.Standard:
				d();
				break;
			case Office2003ColorScheme.Automatic:
				if (WhidbeyRenderer.a())
				{
					b b = new b();
					if (b.a())
					{
						string str;
						if ((str = b.c()) == null)
						{
							break;
						}
						str = string.IsInterned(str);
						if ((object)str != "NormalColor")
						{
							if ((object)str != "HomeStead")
							{
								if ((object)str == "Metallic")
								{
									a();
								}
							}
							else
							{
								this.b();
							}
						}
						else
						{
							c();
						}
					}
					else
					{
						d();
					}
				}
				else
				{
					d();
				}
				break;
			case Office2003ColorScheme.LunaBlue:
				c();
				break;
			case Office2003ColorScheme.LunaOlive:
				this.b();
				break;
			case Office2003ColorScheme.LunaSilver:
				a();
				break;
			}
		}

		protected internal override void StartRenderSession()
		{
			t = new StringFormat(StringFormat.GenericDefault);
			t.FormatFlags = StringFormatFlags.NoWrap;
			t.Alignment = StringAlignment.Center;
			t.LineAlignment = StringAlignment.Center;
			u = new StringFormat(StringFormat.GenericDefault);
			u.FormatFlags = StringFormatFlags.NoWrap;
			u.LineAlignment = StringAlignment.Center;
			u.Trimming = StringTrimming.EllipsisCharacter;
		}

		protected internal override void FinishRenderSession()
		{
			t.Dispose();
			u.Dispose();
		}

		protected internal override void DrawSplitter(Graphics graphics, Rectangle bounds, Orientation orientation)
		{
		}

		protected internal override void DrawDockContainerBackground(Graphics graphics, Rectangle bounds)
		{
			graphics.Clear(this.m_a);
		}

		private void a(Graphics A_0, Rectangle A_1, DrawItemState A_2)
		{
			if ((A_2 & DrawItemState.HotLight) == DrawItemState.HotLight)
			{
				using (LinearGradientBrush brush = new LinearGradientBrush(A_1, this.m_c, this.m_d, LinearGradientMode.Vertical))
				{
					A_0.FillRectangle(brush, A_1);
				}
				using Pen pen = new Pen(this.m_b);
				A_0.DrawRectangle(pen, A_1);
			}
		}

		protected internal override void DrawTitleBarButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state, bool focused, bool toggled)
		{
			bounds.Width--;
			bounds.Height--;
			a(graphics, bounds, state);
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				bounds.Offset(1, 1);
			}
			switch (buttonType)
			{
			case SandDockButtonType.Pin:
				TD.SandDock.o.a(graphics, bounds, focused ? SystemPens.ControlText : SystemPens.ControlText, toggled);
				break;
			case SandDockButtonType.Close:
				TD.SandDock.o.a(graphics, bounds, focused ? SystemPens.ControlText : SystemPens.ControlText);
				break;
			}
		}

		private Brush a(Rectangle A_0, LinearGradientMode A_1, Color A_2, Color A_3)
		{
			Color color = RendererBase.InterpolateColors(A_2, A_3, 0.25f);
			LinearGradientBrush linearGradientBrush = new LinearGradientBrush(A_0, A_2, A_3, A_1);
			ColorBlend colorBlend = new ColorBlend(3);
			colorBlend.Colors = new Color[3] { A_2, color, A_3 };
			colorBlend.Positions = new float[3] { 0f, 0.5f, 1f };
			linearGradientBrush.InterpolationColors = colorBlend;
			return linearGradientBrush;
		}

		protected internal override void DrawTitleBarText(Graphics graphics, Rectangle bounds, bool focused, string text, Font font)
		{
			bounds.Inflate(-3, 0);
			using Font font2 = new Font(font, FontStyle.Bold);
			graphics.DrawString(text, font2, SystemBrushes.ControlText, bounds, u);
		}

		protected internal override void DrawTitleBarBackground(Graphics graphics, Rectangle bounds, bool focused)
		{
			if (focused)
			{
				using LinearGradientBrush brush = new LinearGradientBrush(bounds, n, o, LinearGradientMode.Vertical);
				graphics.FillRectangle(brush, bounds);
			}
			else
			{
				using Brush brush2 = a(bounds, LinearGradientMode.Vertical, p, q);
				graphics.FillRectangle(brush2, bounds);
			}
			bounds.Inflate(0, -2);
			using SolidBrush brush3 = new SolidBrush(r);
			int num = (bounds.Height - 2) / 4;
			int num2 = num * 4 - 2;
			int num3 = bounds.X + 3;
			int num4 = bounds.Y + bounds.Height / 2 - num2 / 2;
			for (int i = num4; i <= num4 + num2; i += 4)
			{
				graphics.FillRectangle(SystemBrushes.ControlLightLight, new Rectangle(num3 + 1, i + 1, 2, 2));
				graphics.FillRectangle(brush3, new Rectangle(num3, i, 2, 2));
			}
		}

		protected internal override void DrawCollapsedTab(Graphics graphics, Rectangle bounds, DockSide dockSide, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool vertical)
		{
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, dockSide, image, text, font, this.m_c, this.m_d, SystemBrushes.ControlDarkDark, TabTextDisplay == TabTextDisplayMode.AllTabs);
			}
			else
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, dockSide, image, text, font, backColor, SystemColors.ControlLightLight, SystemBrushes.ControlDarkDark, TabTextDisplay == TabTextDisplayMode.AllTabs);
			}
		}

		protected internal override void DrawTabStripBackground(Graphics graphics, Rectangle bounds, int selectedTabOffset)
		{
		}

		protected internal override void DrawCollapsedBackground(Graphics graphics, Rectangle bounds)
		{
		}

		protected internal override void DrawTabStripTab(Graphics graphics, Rectangle bounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator)
		{
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, this.m_c, this.m_d, SystemBrushes.ControlText);
			}
			else
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, backColor, SystemColors.ControlLightLight, SystemBrushes.ControlText);
			}
		}

		protected internal override void DrawControlClientBackground(Graphics graphics, Rectangle bounds, Color backColor)
		{
		}

		protected internal override void DrawDocumentClientBackground(Graphics graphics, Rectangle bounds, Color backColor)
		{
			using SolidBrush brush = new SolidBrush(backColor);
			graphics.FillRectangle(brush, bounds);
		}

		protected internal override Size MeasureDocumentStripTab(Graphics graphics, Image image, string text, Font font, DrawItemState state)
		{
			int num;
			if ((state & DrawItemState.Focus) == DrawItemState.Focus)
			{
				using Font font2 = new Font(font, FontStyle.Bold);
				num = (int)Math.Ceiling(graphics.MeasureString(text, font2, 999, EverettRenderer.StandardStringFormat).Width);
			}
			else
			{
				num = (int)Math.Ceiling(graphics.MeasureString(text, font, 999, EverettRenderer.StandardStringFormat).Width);
			}
			num += 24;
			if (image != null)
			{
				num += 20;
			}
			num += DocumentTabExtra;
			return new Size(num, 0);
		}

		protected internal override void DrawDocumentContainerBackground(Graphics graphics, Rectangle bounds)
		{
			graphics.Clear(this.m_a);
		}

		protected internal override void DrawDocumentStripButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state)
		{
			a(graphics, bounds, state);
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				bounds.Offset(1, 1);
			}
			switch (buttonType)
			{
			case SandDockButtonType.ScrollLeft:
				TD.SandDock.o.b(graphics, bounds, m, (state & DrawItemState.Disabled) != DrawItemState.Disabled);
				break;
			case SandDockButtonType.ScrollRight:
				TD.SandDock.o.a(graphics, bounds, m, (state & DrawItemState.Disabled) != DrawItemState.Disabled);
				break;
			case SandDockButtonType.Close:
			{
				using Pen a_ = new Pen(m);
				TD.SandDock.o.b(graphics, bounds, a_);
				break;
			}
			case SandDockButtonType.Pin:
				break;
			}
		}

		protected internal override void DrawDocumentStripBackground(Graphics graphics, Rectangle bounds)
		{
			using (LinearGradientBrush brush = new LinearGradientBrush(new Point(bounds.X, bounds.Y - 1), new Point(bounds.X, bounds.Bottom), e, f))
			{
				graphics.FillRectangle(brush, bounds);
			}
			using Pen pen = new Pen(g);
			graphics.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
		}

		protected internal override void DrawDocumentStripTab(Graphics graphics, Rectangle bounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator)
		{
			Color a_ = RendererBase.InterpolateColors(backColor, SystemColors.ControlLightLight, 0.78f);
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, a_, backColor, SystemBrushes.ControlText, g, i, k, A_11: true, DocumentTabSize, DocumentTabExtra, t);
			}
			else
			{
				TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, a_, backColor, SystemBrushes.ControlText, h, j, l, A_11: false, DocumentTabSize, DocumentTabExtra, t);
			}
		}

		public override string ToString()
		{
			return "Office 2003";
		}
	}
}
