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

namespace TD.SandDock.Rendering
{
	public class WhidbeyRenderer : RendererBase
	{
		public WhidbeyRenderer()
		{
			this.c = Color.FromArgb(127, 157, 185);
			this.d = SystemColors.ControlDark;
			this.e = SystemColors.ControlLightLight;
			this.f = SystemColors.ControlLightLight;
			this.g = SystemColors.ControlLightLight;
			this.h = SystemColors.Control;
			this.i = Color.FromArgb(231, 227, 214);
		}

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

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

		internal virtual void DrawButtonHighlight(Graphics graphics, Rectangle bounds, DrawItemState state)
		{
			if ((state & DrawItemState.HotLight) == DrawItemState.HotLight)
			{
				Pen pen;
				Pen pen2;
				if ((state & DrawItemState.Selected) == DrawItemState.Selected)
				{
					pen = SystemPens.ControlDark;
					pen2 = SystemPens.ControlLightLight;
				}
				else
				{
					pen2 = SystemPens.ControlDark;
					pen = SystemPens.ControlLightLight;
				}
				graphics.DrawLine(pen, bounds.Left, bounds.Top, bounds.Right - 1, bounds.Top);
				graphics.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 1);
				graphics.DrawLine(pen2, bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 1, bounds.Top);
				graphics.DrawLine(pen2, bounds.Right - 1, bounds.Bottom - 1, bounds.Left, bounds.Bottom - 1);
			}
		}

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

		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 void DrawDocumentStripBackground(Graphics graphics, Rectangle bounds)
		{
			using (SolidBrush solidBrush = new SolidBrush(this.i))
			{
				graphics.FillRectangle(solidBrush, bounds);
			}
			using (Pen pen = new Pen(this.c))
			{
				graphics.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
			}
		}

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

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

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

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

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

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

		protected internal override void DrawDocumentStripTab(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, SystemColors.ControlLightLight, SystemColors.ControlLightLight, SystemBrushes.ControlText, this.c, this.e, this.g, true, this.DocumentTabSize, this.DocumentTabExtra, this.l);
				return;
			}
			TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, SystemColors.ControlLightLight, backColor, SystemBrushes.ControlText, this.d, this.f, this.h, false, this.DocumentTabSize, this.DocumentTabExtra, this.l);
		}

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

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

		protected override void CalculateBaseColors()
		{
			base.CalculateBaseColors();
		}

		protected internal override void StartRenderSession()
		{
			this.j = new Pen(this.a);
			this.k = new SolidBrush(this.b);
			this.l = new StringFormat(StringFormat.GenericDefault);
			this.l.FormatFlags = StringFormatFlags.NoWrap;
			this.l.Alignment = StringAlignment.Center;
			this.l.LineAlignment = StringAlignment.Center;
		}

		protected internal override void DrawSplitter(Graphics graphics, Rectangle bounds, Orientation orientation)
		{
			using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(bounds.X - 1, bounds.Y), new Point(bounds.Right, bounds.Y), SystemColors.Control, SystemColors.Window))
			{
				graphics.FillRectangle(linearGradientBrush, bounds);
			}
		}

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

		protected internal override void DrawTabStripBackground(Graphics graphics, Rectangle bounds, int selectedTabOffset)
		{
			using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(bounds.X - 1, bounds.Y), new Point(bounds.Right, bounds.Y), SystemColors.Control, SystemColors.Window))
			{
				graphics.FillRectangle(linearGradientBrush, 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, SystemColors.ControlLightLight, SystemColors.ControlLightLight, SystemBrushes.ControlText);
				return;
			}
			TD.SandDock.Rendering.a.a(graphics, bounds, image, text, font, backColor, SystemColors.ControlLightLight, SystemBrushes.ControlText);
		}

		protected internal override BoxModel TitleBarMetrics
		{
			get
			{
				if (this.o == null)
				{
					this.o = new BoxModel(0, SystemInformation.ToolWindowCaptionHeight, 0, 0, 0, 0, 0, 0, 0, 0);
				}
				return this.o;
			}
		}

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

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

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

		protected internal override void DrawCollapsedBackground(Graphics graphics, Rectangle bounds)
		{
			using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(bounds, SystemColors.Control, SystemColors.Window, LinearGradientMode.Horizontal))
			{
				graphics.FillRectangle(linearGradientBrush, bounds);
			}
		}

		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 (dockSide == DockSide.Left || dockSide == DockSide.Right)
			{
				using (Image image2 = new Bitmap(image))
				{
					image2.RotateFlip(RotateFlipType.Rotate90FlipNone);
					TD.SandDock.Rendering.a.a(graphics, bounds, dockSide, image2, text, font, backColor, SystemColors.ControlLightLight, 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 void DrawTitleBarButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state, bool focused, bool toggled)
		{
			this.DrawButtonHighlight(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.ActiveCaptionText : SystemPens.ControlText);
				return;
			case SandDockButtonType.Pin:
				TD.SandDock.o.a(graphics, bounds, focused ? SystemPens.ActiveCaptionText : SystemPens.ControlText, toggled);
				return;
			default:
				return;
			}
		}

		protected internal override void DrawTitleBarBackground(Graphics graphics, Rectangle bounds, bool focused)
		{
			if (focused)
			{
				using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(bounds.X - 1, bounds.Y), new Point(bounds.Right, bounds.Y), SystemColors.ActiveCaption, TD.SandDock.d.a()))
				{
					graphics.FillRectangle(linearGradientBrush, bounds);
					return;
				}
			}
			using (LinearGradientBrush linearGradientBrush2 = new LinearGradientBrush(new Point(bounds.X - 1, bounds.Y), new Point(bounds.Right, bounds.Y), SystemColors.ControlDark, SystemColors.ControlLight))
			{
				graphics.FillRectangle(linearGradientBrush2, bounds);
			}
		}

		protected internal override void DrawTitleBarText(Graphics graphics, Rectangle bounds, bool focused, string text, Font font)
		{
			bounds.Inflate(-3, 0);
			if (focused)
			{
				graphics.DrawString(text, font, SystemBrushes.ActiveCaptionText, bounds, EverettRenderer.StandardStringFormat);
				return;
			}
			using (SolidBrush solidBrush = new SolidBrush(SystemColors.ControlText))
			{
				graphics.DrawString(text, font, solidBrush, bounds, EverettRenderer.StandardStringFormat);
			}
		}

		protected internal override void FinishRenderSession()
		{
			this.j.Dispose();
			this.k.Dispose();
			this.l.Dispose();
		}

		public override string ToString()
		{
			return "Whidbey";
		}

		private Color a = SystemColors.ControlDark;

		private Color b = SystemColors.ControlDarkDark;

		private Color c;

		private Color d;

		private Color e;

		private Color f;

		private Color g;

		private Color h;

		private Color i;

		private Pen j;

		private SolidBrush k;

		private StringFormat l;

		private BoxModel m = null;

		private BoxModel n = null;

		private BoxModel o = null;
	}
}
