context: using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Windows.Forms;
  using System.ComponentModel;
  
  namespace WeifenLuo.WinFormsUI.Docking
  {
      using WeifenLuo.WinFormsUI.ThemeVS2012;
  
      internal class VS2012DockPaneCaption : DockPaneCaptionBase
      {
          #region consts
          private const int TextGapTop = 3;
          private const int TextGapBottom = 2;
          private const int TextGapLeft = 2;
          private const int TextGapRight = 3;
          private const int ButtonGapTop = 3;
          private const int ButtonGapBottom = 3;
          private const int ButtonGapBetween = 1;
          private const int ButtonGapLeft = 1;
          private const int ButtonGapRight = 4;
          #endregion
  
          private InertButtonBase m_buttonClose;
          private InertButtonBase ButtonClose
          {
              get
              {
                  if (m_buttonClose == null)
                  {
                      m_buttonClose = new VS2012DockPaneCaptionInertButton(this, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneHover_Close, 
                          DockPane.DockPanel.Theme.ImageService.DockPane_Close,
                          DockPane.DockPanel.Theme.ImageService.DockPanePress_Close,
                          DockPane.DockPanel.Theme.ImageService.DockPaneActiveHover_Close, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneActive_Close);
                      m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
                      m_buttonClose.Click += new EventHandler(Close_Click);
                      Controls.Add(m_buttonClose);
                  }
  
                  return m_buttonClose;
              }
          }
  
          private InertButtonBase m_buttonAutoHide;
          private InertButtonBase ButtonAutoHide
          {
              get
              {
                  if (m_buttonAutoHide == null)
                  {
                      m_buttonAutoHide = new VS2012DockPaneCaptionInertButton(this, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneHover_Dock, 
                          DockPane.DockPanel.Theme.ImageService.DockPane_Dock,
                          DockPane.DockPanel.Theme.ImageService.DockPanePress_Dock,
                          DockPane.DockPanel.Theme.ImageService.DockPaneActiveHover_Dock, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneActive_Dock,
                          DockPane.DockPanel.Theme.ImageService.DockPaneActiveHover_AutoHide, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneActive_AutoHide,
                          DockPane.DockPanel.Theme.ImageService.DockPanePress_AutoHide);
                      m_toolTip.SetToolTip(m_buttonAutoHide, ToolTipAutoHide);
                      m_buttonAutoHide.Click += new EventHandler(AutoHide_Click);
                      Controls.Add(m_buttonAutoHide);
                  }
  
                  return m_buttonAutoHide;
              }
          }
  
          private InertButtonBase m_buttonOptions;
          private InertButtonBase ButtonOptions
          {
              get
              {
                  if (m_buttonOptions == null)
                  {
                      m_buttonOptions = new VS2012DockPaneCaptionInertButton(this, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneHover_Option, 
                          DockPane.DockPanel.Theme.ImageService.DockPane_Option,
                          DockPane.DockPanel.Theme.ImageService.DockPanePress_Option,
                          DockPane.DockPanel.Theme.ImageService.DockPaneActiveHover_Option, 
                          DockPane.DockPanel.Theme.ImageService.DockPaneActive_Option);
                      m_toolTip.SetToolTip(m_buttonOptions, ToolTipOptions);
                      m_buttonOptions.Click += new EventHandler(Options_Click);
                      Controls.Add(m_buttonOptions);
                  }
                  return m_buttonOptions;
              }
          }
  
          private IContainer m_components;
          private IContainer Components
          {
              get { return m_components; }
          }
  
          private ToolTip m_toolTip;
  
          public VS2012DockPaneCaption(DockPane pane) : base(pane)
          {
              SuspendLayout();
  
              m_components = new Container();
              m_toolTip = new ToolTip(Components);
  
              ResumeLayout();
          }
  
          protected override void Dispose(bool disposing)
          {
              if (disposing)
                  Components.Dispose();
              base.Dispose(disposing);
          }
  
          public Font TextFont
          {
              get { return DockPane.DockPanel.Theme.Skin.DockPaneStripSkin.TextFont; }
          }
  
          private static string _toolTipClose;
          private static string ToolTipClose
          {
              get
              {	
                  if (_toolTipClose == null)
                      _toolTipClose = Strings.DockPaneCaption_ToolTipClose;
                  return _toolTipClose;
              }
          }
  
          private static string _toolTipOptions;
          private static string ToolTipOptions
          {
              get
              {
                  if (_toolTipOptions == null)
                      _toolTipOptions = Strings.DockPaneCaption_ToolTipOptions;
  
                  return _toolTipOptions;
              }
          }
  
          private static string _toolTipAutoHide;
          private static string ToolTipAutoHide
          {
              get
              {	
                  if (_toolTipAutoHide == null)
                      _toolTipAutoHide = Strings.DockPaneCaption_ToolTipAutoHide;
                  return _toolTipAutoHide;
              }
          }
  
          private Color TextColor
          {
              get
              {
                  if (DockPane.IsActivePane)
                      return DockPane.DockPanel.Theme.ColorPalette.ToolWindowCaptionActive.Text;
                  else
                      return DockPane.DockPanel.Theme.ColorPalette.ToolWindowCaptionInactive.Text;
              }
          }
  
          private static TextFormatFlags _textFormat =
              TextFormatFlags.SingleLine |
              TextFormatFlags.EndEllipsis |
              TextFormatFlags.VerticalCenter;
          private TextFormatFlags TextFormat
          {
              get
              {
                  if (RightToLeft == RightToLeft.No)
                      return _textFormat;
                  else
                      return _textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
              }
          }
  
          protected override int MeasureHeight()
          {
              int height = TextFont.Height + TextGapTop + TextGapBottom;
  
              if (height < ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom)
                  height = ButtonClose.Image.Height + ButtonGapTop + ButtonGapBottom;
  
              return height;
          }
  
          protected override void OnPaint(PaintEventArgs e)
          {
              base.OnPaint (e);
              DrawCaption(e.Graphics);
          }
  
          private void DrawCaption(Graphics g)
          {
              if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
                  return;
  
              Rectangle rect = ClientRectangle;
              Color captionColor;
  
              if (DockPane.IsActivePane)
                  captionColor = DockPane.DockPanel.Theme.ColorPalette.ToolWindowCaptionActive.Background;
              else
                  captionColor = DockPane.DockPanel.Theme.ColorPalette.ToolWindowCaptionInactive.Background;
  
              SolidBrush captionBrush = DockPane.DockPanel.Theme.PaintingService.GetBrush(captionColor);
              g.FillRectangle(captionBrush, rect);
  
              Rectangle rectCaption = rect;
  
              Rectangle rectCaptionText = rectCaption;
              rectCaptionText.X += TextGapLeft;
              rectCaptionText.Width -= TextGapLeft + TextGapRight;
              rectCaptionText.Width -= ButtonGapLeft + ButtonClose.Width + ButtonGapRight;
              if (ShouldShowAutoHideButton)
                  rectCaptionText.Width -= ButtonAutoHide.Width + ButtonGapBetween;
              if (HasTabPageContextMenu)
  
gt:                 rectCaptionText.Width -= ButtonOptions.Width + ButtonGapBetween;