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

namespace TD.SandDock.Rendering
{
	public class Office2003Renderer : RendererBase
	{
		public Color HighlightBorderColor
		{
			get
			{
				return this.b;
			}
			set
			{
				this.b = value;
				base.CustomColors = true;
			}
		}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		protected internal override void FinishRenderSession()
		{
			this.t.Dispose();
			this.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.a);
		}

		private void a(Graphics A_0, Rectangle A_1, DrawItemState A_2)
		{
			if ((A_2 & DrawItemState.HotLight) == DrawItemState.HotLight)
			{
				using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(A_1, this.c, this.d, LinearGradientMode.Vertical))
				{
					A_0.FillRectangle(linearGradientBrush, A_1);
				}
				using (Pen pen = new Pen(this.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--;
			this.a(graphics, bounds, state);
			if ((state & DrawItemState.Selected) == DrawItemState.Selected)
			{
				bounds.Offset(1, 1);
			}
			switch (buttonType)
			{
			case SandDockButtonType.Close:
				TD.SandDock.o.a(graphics, bounds, focused ? SystemPens.ControlText : SystemPens.ControlText);
				return;
			case SandDockButtonType.Pin:
				TD.SandDock.o.a(graphics, bounds, focused ? SystemPens.ControlText : SystemPens.ControlText, toggled);
				return;
			default:
				return;
			}
		}

		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);
			return new LinearGradientBrush(A_0, A_2, A_3, A_1)
			{
				InterpolationColors = new ColorBlend(3)
				{
					Colors = new Color[]
					{
						A_2,
						color,
						A_3
					},
					Positions = new float[]
					{
						0f,
						0.5f,
						1f
					}
				}
			};
		}

		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, this.u);
			}
		}

		protected internal override void DrawTitleBarBackground(Graphics graphics, Rectangle bounds, bool focused)
		{
			if (focused)
			{
				using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(bounds, this.n, this.o, LinearGradientMode.Vertical))
				{
					graphics.FillRectangle(linearGradientBrush, bounds);
					goto IL_54;
				}
			}
			using (Brush brush = this.a(bounds, LinearGradientMode.Vertical, this.p, this.q))
			{
				graphics.FillRectangle(brush, bounds);
			}
			IL_54:
			bounds.Inflate(0, -2);
			using (SolidBrush solidBrush = new SolidBrush(this.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(solidBrush, new Rectangle(num3, i, 2, 2));
				}
			}
		}

		protected internal override BoxModel TitleBarMetrics
		{
			get
			{
				return new BoxModel(0, 25, 4, 0, 0, 0, 0, 0, 0, 1);
			}
		}

		protected internal override TabTextDisplayMode TabTextDisplay
		{
			get
			{
				return TabTextDisplayMode.SelectedTab;
			}
		}

		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.c, this.d, SystemBrushes.ControlDarkDark, this.TabTextDisplay == TabTextDisplayMode.AllTabs);
				return;
			}
			TD.SandDock.Rendering.a.a(graphics, bounds, dockSide, image, text, font, backColor, SystemColors.ControlLightLight, SystemBrushes.ControlDarkDark, this.TabTextDisplay == TabTextDisplayMode.AllTabs);
		}

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

		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.c, this.d, SystemBrushes.ControlText);
				return;
			}
			TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, backColor, SystemColors.ControlLightLight, SystemBrushes.ControlText);
		}

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

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

		protected internal override void DrawDocumentClientBackground(Graphics graphics, Rectangle bounds, Color backColor)
		{
			using (SolidBrush solidBrush = new SolidBrush(backColor))
			{
				graphics.FillRectangle(solidBrush, 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((double)graphics.MeasureString(text, font2, 999, EverettRenderer.StandardStringFormat).Width);
					goto IL_63;
				}
			}
			num = (int)Math.Ceiling((double)graphics.MeasureString(text, font, 999, EverettRenderer.StandardStringFormat).Width);
			IL_63:
			num += 24;
			if (image != null)
			{
				num += 20;
			}
			num += this.DocumentTabExtra;
			return new Size(num, 0);
		}

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

		protected internal override Size DocumentClientPadding
		{
			get
			{
				return new Size(4, 4);
			}
		}

		protected internal override Size ControlClientPadding
		{
			get
			{
				return new Size(0, 0);
			}
		}

		protected internal override int DocumentTabStripSize
		{
			get
			{
				return Control.DefaultFont.Height + 15;
			}
		}

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

		protected internal override void DrawDocumentStripBackground(Graphics graphics, Rectangle bounds)
		{
			using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(bounds.X, bounds.Y - 1), new Point(bounds.X, bounds.Bottom), this.e, this.f))
			{
				graphics.FillRectangle(linearGradientBrush, bounds);
			}
			using (Pen pen = new Pen(this.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, this.g, this.i, this.k, true, this.DocumentTabSize, this.DocumentTabExtra, this.t);
				return;
			}
			TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, a_, backColor, SystemBrushes.ControlText, this.h, this.j, this.l, false, this.DocumentTabSize, this.DocumentTabExtra, this.t);
		}

		protected internal override int DocumentTabSize
		{
			get
			{
				return Control.DefaultFont.Height + 7;
			}
		}

		protected internal override int DocumentTabExtra
		{
			get
			{
				return 18;
			}
		}

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

		private Color a;

		private Color b;

		private Color c;

		private Color 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 Office2003Renderer.Office2003ColorScheme s = Office2003Renderer.Office2003ColorScheme.Automatic;

		private StringFormat t;

		private StringFormat u;

		private BoxModel v;

		private BoxModel w = null;

		public enum Office2003ColorScheme
		{
			Automatic,
			Standard,
			LunaBlue,
			LunaOlive,
			LunaSilver
		}
	}
}
