VS2005DockPaneStrip.cs
上传用户:szlfmled
上传日期:2020-11-22
资源大小:978k
文件大小:54k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5. using System.ComponentModel;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. namespace WeifenLuo.WinFormsUI.Docking
  9. {
  10. internal class VS2005DockPaneStrip : DockPaneStripBase
  11. {
  12.         private class TabVS2005 : Tab
  13.         {
  14.             public TabVS2005(IDockContent content)
  15.                 : base(content)
  16.             {
  17.             }
  18.             private int m_tabX;
  19.             public int TabX
  20.             {
  21.                 get { return m_tabX; }
  22.                 set { m_tabX = value; }
  23.             }
  24.             private int m_tabWidth;
  25.             public int TabWidth
  26.             {
  27.                 get { return m_tabWidth; }
  28.                 set { m_tabWidth = value; }
  29.             }
  30.             private int m_maxWidth;
  31.             public int MaxWidth
  32.             {
  33.                 get { return m_maxWidth; }
  34.                 set { m_maxWidth = value; }
  35.             }
  36.             private bool m_flag;
  37.             protected internal bool Flag
  38.             {
  39.                 get { return m_flag; }
  40.                 set { m_flag = value; }
  41.             }
  42.         }
  43.         protected internal override DockPaneStripBase.Tab CreateTab(IDockContent content)
  44.         {
  45.             return new TabVS2005(content);
  46.         }
  47.         private sealed class InertButton : InertButtonBase
  48.         {
  49.             private Bitmap m_image0, m_image1;
  50.             public InertButton(Bitmap image0, Bitmap image1)
  51.                 : base()
  52.             {
  53.                 m_image0 = image0;
  54.                 m_image1 = image1;
  55.             }
  56.             private int m_imageCategory = 0;
  57.             public int ImageCategory
  58.             {
  59.                 get { return m_imageCategory; }
  60.                 set
  61.                 {
  62.                     if (m_imageCategory == value)
  63.                         return;
  64.                     m_imageCategory = value;
  65.                     Invalidate();
  66.                 }
  67.             }
  68.             public override Bitmap Image
  69.             {
  70.                 get { return ImageCategory == 0 ? m_image0 : m_image1; }
  71.             }
  72.         }
  73. #region consts
  74.         private const int _ToolWindowStripGapTop = 0;
  75.         private const int _ToolWindowStripGapBottom = 1;
  76. private const int _ToolWindowStripGapLeft = 0;
  77. private const int _ToolWindowStripGapRight = 0;
  78. private const int _ToolWindowImageHeight = 16;
  79. private const int _ToolWindowImageWidth = 16;
  80. private const int _ToolWindowImageGapTop = 3;
  81. private const int _ToolWindowImageGapBottom = 1;
  82. private const int _ToolWindowImageGapLeft = 2;
  83. private const int _ToolWindowImageGapRight = 0;
  84. private const int _ToolWindowTextGapRight = 3;
  85. private const int _ToolWindowTabSeperatorGapTop = 3;
  86. private const int _ToolWindowTabSeperatorGapBottom = 3;
  87.         private const int _DocumentStripGapTop = 0;
  88.         private const int _DocumentStripGapBottom = 1;
  89. private const int _DocumentTabMaxWidth = 200;
  90. private const int _DocumentButtonGapTop = 4;
  91. private const int _DocumentButtonGapBottom = 4;
  92. private const int _DocumentButtonGapBetween = 0;
  93. private const int _DocumentButtonGapRight = 3;
  94. private const int _DocumentTabGapTop = 3;
  95. private const int _DocumentTabGapLeft = 3;
  96. private const int _DocumentTabGapRight = 3;
  97.         private const int _DocumentIconGapBottom = 2;
  98. private const int _DocumentIconGapLeft = 8;
  99.         private const int _DocumentIconGapRight = 0;
  100. private const int _DocumentIconHeight = 16;
  101. private const int _DocumentIconWidth = 16;
  102.         private const int _DocumentTextGapRight = 3;
  103. #endregion
  104.         private static Bitmap _imageButtonClose;
  105.         private static Bitmap ImageButtonClose
  106.         {
  107.             get
  108.             {
  109.                 if (_imageButtonClose == null)
  110.                     _imageButtonClose = Resources.DockPane_Close;
  111.                 return _imageButtonClose;
  112.             }
  113.         }
  114.         private InertButton m_buttonClose;
  115.         private InertButton ButtonClose
  116.         {
  117.             get
  118.             {
  119.                 if (m_buttonClose == null)
  120.                 {
  121.                     m_buttonClose = new InertButton(ImageButtonClose, ImageButtonClose);
  122.                     m_toolTip.SetToolTip(m_buttonClose, ToolTipClose);
  123.                     m_buttonClose.Click += new EventHandler(Close_Click);
  124.                     Controls.Add(m_buttonClose);
  125.                 }
  126.                 return m_buttonClose;
  127.             }
  128.         }
  129.         private static Bitmap _imageButtonWindowList;
  130.         private static Bitmap ImageButtonWindowList
  131.         {
  132.             get
  133.             {
  134.                 if (_imageButtonWindowList == null)
  135.                     _imageButtonWindowList = Resources.DockPane_Option;
  136.                 return _imageButtonWindowList;
  137.             }
  138.         }
  139.         private static Bitmap _imageButtonWindowListOverflow;
  140.         private static Bitmap ImageButtonWindowListOverflow
  141.         {
  142.             get
  143.             {
  144.                 if (_imageButtonWindowListOverflow == null)
  145.                     _imageButtonWindowListOverflow = Resources.DockPane_OptionOverflow;
  146.                 return _imageButtonWindowListOverflow;
  147.             }
  148.         }
  149.         private InertButton m_buttonWindowList;
  150.         private InertButton ButtonWindowList
  151.         {
  152.             get
  153.             {
  154.                 if (m_buttonWindowList == null)
  155.                 {
  156.                     m_buttonWindowList = new InertButton(ImageButtonWindowList, ImageButtonWindowListOverflow);
  157.                     m_toolTip.SetToolTip(m_buttonWindowList, ToolTipSelect);
  158.                     m_buttonWindowList.Click += new EventHandler(WindowList_Click);
  159.                     Controls.Add(m_buttonWindowList);
  160.                 }
  161.                 return m_buttonWindowList;
  162.             }
  163.         }
  164.         private static GraphicsPath GraphicsPath
  165.         {
  166.             get { return VS2005AutoHideStrip.GraphicsPath; }
  167.         }
  168. private IContainer m_components;
  169. private ToolTip m_toolTip;
  170. private IContainer Components
  171. {
  172. get { return m_components; }
  173. }
  174. #region Customizable Properties
  175.         private static int ToolWindowStripGapTop
  176.         {
  177.             get { return _ToolWindowStripGapTop; }
  178.         }
  179.         private static int ToolWindowStripGapBottom
  180.         {
  181.             get { return _ToolWindowStripGapBottom; }
  182.         }
  183. private static int ToolWindowStripGapLeft
  184. {
  185. get { return _ToolWindowStripGapLeft; }
  186. }
  187. private static int ToolWindowStripGapRight
  188. {
  189. get { return _ToolWindowStripGapRight; }
  190. }
  191. private static int ToolWindowImageHeight
  192. {
  193. get { return _ToolWindowImageHeight; }
  194. }
  195. private static int ToolWindowImageWidth
  196. {
  197. get { return _ToolWindowImageWidth; }
  198. }
  199. private static int ToolWindowImageGapTop
  200. {
  201. get { return _ToolWindowImageGapTop; }
  202. }
  203. private static int ToolWindowImageGapBottom
  204. {
  205. get { return _ToolWindowImageGapBottom; }
  206. }
  207. private static int ToolWindowImageGapLeft
  208. {
  209. get { return _ToolWindowImageGapLeft; }
  210. }
  211. private static int ToolWindowImageGapRight
  212. {
  213. get { return _ToolWindowImageGapRight; }
  214. }
  215. private static int ToolWindowTextGapRight
  216. {
  217. get { return _ToolWindowTextGapRight; }
  218. }
  219. private static int ToolWindowTabSeperatorGapTop
  220. {
  221. get { return _ToolWindowTabSeperatorGapTop; }
  222. }
  223. private static int ToolWindowTabSeperatorGapBottom
  224. {
  225. get { return _ToolWindowTabSeperatorGapBottom; }
  226. }
  227. private static string _toolTipClose;
  228. private static string ToolTipClose
  229. {
  230. get
  231. {
  232. if (_toolTipClose == null)
  233. _toolTipClose = Strings.DockPaneStrip_ToolTipClose;
  234. return _toolTipClose;
  235. }
  236. }
  237. private static string _toolTipSelect;
  238. private static string ToolTipSelect
  239. {
  240. get
  241. {
  242. if (_toolTipSelect == null)
  243. _toolTipSelect = Strings.DockPaneStrip_ToolTipWindowList;
  244. return _toolTipSelect;
  245. }
  246. }
  247. private TextFormatFlags ToolWindowTextFormat
  248. {
  249. get
  250.             {
  251.                 TextFormatFlags textFormat = TextFormatFlags.EndEllipsis |
  252.                     TextFormatFlags.HorizontalCenter |
  253.                     TextFormatFlags.SingleLine |
  254.                     TextFormatFlags.VerticalCenter;
  255.                 if (RightToLeft == RightToLeft.Yes)
  256.                     return textFormat | TextFormatFlags.RightToLeft | TextFormatFlags.Right;
  257.                 else
  258.                     return textFormat;
  259.             }
  260. }
  261.         private static int DocumentStripGapTop
  262.         {
  263.             get { return _DocumentStripGapTop; }
  264.         }
  265.         private static int DocumentStripGapBottom
  266.         {
  267.             get { return _DocumentStripGapBottom; }
  268.         }
  269. private TextFormatFlags DocumentTextFormat
  270. {
  271.          get
  272.             {
  273.                 TextFormatFlags textFormat = TextFormatFlags.EndEllipsis |
  274.                     TextFormatFlags.SingleLine |
  275.                     TextFormatFlags.VerticalCenter |
  276.                     TextFormatFlags.HorizontalCenter;
  277.                 if (RightToLeft == RightToLeft.Yes)
  278.                     return textFormat | TextFormatFlags.RightToLeft;
  279.                 else
  280.                     return textFormat;
  281.             }
  282. }
  283. private static int DocumentTabMaxWidth
  284. {
  285. get { return _DocumentTabMaxWidth; }
  286. }
  287. private static int DocumentButtonGapTop
  288. {
  289. get { return _DocumentButtonGapTop; }
  290. }
  291. private static int DocumentButtonGapBottom
  292. {
  293. get { return _DocumentButtonGapBottom; }
  294. }
  295. private static int DocumentButtonGapBetween
  296. {
  297. get { return _DocumentButtonGapBetween; }
  298. }
  299. private static int DocumentButtonGapRight
  300. {
  301. get { return _DocumentButtonGapRight; }
  302. }
  303. private static int DocumentTabGapTop
  304. {
  305. get { return _DocumentTabGapTop; }
  306. }
  307. private static int DocumentTabGapLeft
  308. {
  309. get { return _DocumentTabGapLeft; }
  310. }
  311. private static int DocumentTabGapRight
  312. {
  313. get { return _DocumentTabGapRight; }
  314. }
  315.         private static int DocumentIconGapBottom
  316.         {
  317.             get { return _DocumentIconGapBottom; }
  318.         }
  319. private static int DocumentIconGapLeft
  320. {
  321.             get { return _DocumentIconGapLeft; }
  322. }
  323.         private static int DocumentIconGapRight
  324.         {
  325.             get { return _DocumentIconGapRight; }
  326.         }
  327. private static int DocumentIconWidth
  328. {
  329. get { return _DocumentIconWidth; }
  330. }
  331. private static int DocumentIconHeight
  332. {
  333. get { return _DocumentIconHeight; }
  334. }
  335.         private static int DocumentTextGapRight
  336.         {
  337.             get { return _DocumentTextGapRight; }
  338.         }
  339. private static Pen PenToolWindowTabBorder
  340. {
  341. get { return SystemPens.GrayText; }
  342. }
  343.         private static Pen PenDocumentTabActiveBorder
  344.         {
  345.             get { return SystemPens.ControlDarkDark; }
  346.         }
  347.         private static Pen PenDocumentTabInactiveBorder
  348.         {
  349.             get { return SystemPens.GrayText; }
  350.         }
  351. #endregion
  352. public VS2005DockPaneStrip(DockPane pane) : base(pane)
  353. {
  354. SetStyle(ControlStyles.ResizeRedraw |
  355.                 ControlStyles.UserPaint |
  356.                 ControlStyles.AllPaintingInWmPaint |
  357.                 ControlStyles.OptimizedDoubleBuffer, true);
  358. SuspendLayout();
  359. m_components = new Container();
  360. m_toolTip = new ToolTip(Components);
  361.             m_selectMenu = new ContextMenuStrip(Components);
  362. ResumeLayout();
  363. }
  364. protected override void Dispose(bool disposing)
  365. {
  366.             if (disposing)
  367.             {
  368.                 Components.Dispose();
  369.                 if (m_boldFont != null)
  370.                 {
  371.                     m_boldFont.Dispose();
  372.                     m_boldFont = null;
  373.                 }
  374.             }
  375. base.Dispose (disposing);
  376. }
  377.         private static Font TextFont
  378.         {
  379.             get { return SystemInformation.MenuFont; }
  380.         }
  381.         private Font m_font;
  382.         private Font m_boldFont;
  383.         private Font BoldFont
  384.         {
  385.             get
  386.             {
  387.                 if (IsDisposed)
  388.                     return null;
  389.                 if (m_boldFont == null)
  390.                 {
  391.                     m_font = TextFont;
  392.                     m_boldFont = new Font(TextFont, FontStyle.Bold);
  393.                 }
  394.                 else if (m_font != TextFont)
  395.                 {
  396.                     m_boldFont.Dispose();
  397.                     m_font = TextFont;
  398.                     m_boldFont = new Font(TextFont, FontStyle.Bold);
  399.                 }
  400.                 return m_boldFont;
  401.             }
  402.         }
  403.         private int m_startDisplayingTab = 0;
  404.         private int StartDisplayingTab
  405.         {
  406.             get { return m_startDisplayingTab; }
  407.             set
  408.             {
  409.                 m_startDisplayingTab = value;
  410.                 Invalidate();
  411.             }
  412.         }
  413.         private int m_endDisplayingTab = 0;
  414.         private int EndDisplayingTab
  415.         {
  416.             get { return m_endDisplayingTab; }
  417.             set { m_endDisplayingTab = value; }
  418.         }
  419.         private int m_firstDisplayingTab = 0;
  420.         private int FirstDisplayingTab
  421.         {
  422.             get { return m_firstDisplayingTab; }
  423.             set { m_firstDisplayingTab = value; }
  424.         }
  425.         private bool m_documentTabsOverflow = false;
  426.         private bool DocumentTabsOverflow
  427.         {
  428.             set
  429.             {
  430.                 if (m_documentTabsOverflow == value)
  431.                     return;
  432.                 m_documentTabsOverflow = value;
  433.                 if (value)
  434.                     ButtonWindowList.ImageCategory = 1;
  435.                 else
  436.                     ButtonWindowList.ImageCategory = 0;
  437.             }
  438.         }
  439. protected internal override int MeasureHeight()
  440. {
  441. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  442. return MeasureHeight_ToolWindow();
  443. else
  444. return MeasureHeight_Document();
  445. }
  446. private int MeasureHeight_ToolWindow()
  447. {
  448. if (DockPane.IsAutoHide || Tabs.Count <= 1)
  449. return 0;
  450.             int height = Math.Max(TextFont.Height, ToolWindowImageHeight + ToolWindowImageGapTop + ToolWindowImageGapBottom)
  451.                 + ToolWindowStripGapTop + ToolWindowStripGapBottom;
  452. return height;
  453. }
  454. private int MeasureHeight_Document()
  455. {
  456. int height = Math.Max(TextFont.Height + DocumentTabGapTop,
  457. ButtonClose.Height + DocumentButtonGapTop + DocumentButtonGapBottom)
  458.                 + DocumentStripGapBottom + DocumentStripGapTop;
  459. return height;
  460. }
  461. protected override void OnPaint(PaintEventArgs e)
  462. {
  463.             Rectangle rect = TabsRectangle;
  464.             if (Appearance == DockPane.AppearanceStyle.Document)
  465.             {
  466.                 rect.X -= DocumentTabGapLeft;
  467.                 // Add these values back in so that the DockStrip color is drawn
  468.                 // beneath the close button and window list button.
  469.                 rect.Width += DocumentTabGapLeft +
  470.                     DocumentTabGapRight +
  471.                     DocumentButtonGapRight +
  472.                     ButtonClose.Width +
  473.                     ButtonWindowList.Width;
  474.                 // It is possible depending on the DockPanel DocumentStyle to have
  475.                 // a Document without a DockStrip.
  476.                 if (rect.Width > 0 && rect.Height > 0)
  477.                 {
  478.                     Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.StartColor;
  479.                     Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.EndColor;
  480.                     LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.DockStripGradient.LinearGradientMode;
  481.                     using (LinearGradientBrush brush = new LinearGradientBrush(rect, startColor, endColor, gradientMode))
  482.                     {
  483.                         e.Graphics.FillRectangle(brush, rect);
  484.                     }
  485.                 }
  486.             }
  487.             else
  488.             {
  489.                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.StartColor;
  490.                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.EndColor;
  491.                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.DockStripGradient.LinearGradientMode;
  492.                 using (LinearGradientBrush brush = new LinearGradientBrush(rect, startColor, endColor, gradientMode))
  493.                 {
  494.                     e.Graphics.FillRectangle(brush, rect);
  495.                 }
  496.             }
  497. base.OnPaint (e);
  498. CalculateTabs();
  499.             if (Appearance == DockPane.AppearanceStyle.Document && DockPane.ActiveContent != null)
  500.             {
  501.                 if (EnsureDocumentTabVisible(DockPane.ActiveContent, false))
  502.                     CalculateTabs();
  503.             }
  504. DrawTabStrip(e.Graphics);
  505. }
  506. protected override void OnRefreshChanges()
  507. {
  508. SetInertButtons();
  509. Invalidate();
  510. }
  511. protected internal override GraphicsPath GetOutline(int index)
  512. {
  513.             if (Appearance == DockPane.AppearanceStyle.Document)
  514.                 return GetOutline_Document(index);
  515.             else
  516.                 return GetOutline_ToolWindow(index);
  517. }
  518.         private GraphicsPath GetOutline_Document(int index)
  519.         {
  520.             Rectangle rectTab = GetTabRectangle(index);
  521.             rectTab.X -= rectTab.Height / 2;
  522.             rectTab.Intersect(TabsRectangle);
  523.             rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab));
  524.             Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle);
  525.             GraphicsPath path = new GraphicsPath();
  526.             GraphicsPath pathTab = GetTabOutline_Document(Tabs[index], true, true, true);
  527.             path.AddPath(pathTab, true);
  528.             if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  529.             {
  530.                 path.AddLine(rectTab.Right, rectTab.Top, rectPaneClient.Right, rectTab.Top);
  531.                 path.AddLine(rectPaneClient.Right, rectTab.Top, rectPaneClient.Right, rectPaneClient.Top);
  532.                 path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Left, rectPaneClient.Top);
  533.                 path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Left, rectTab.Top);
  534.                 path.AddLine(rectPaneClient.Left, rectTab.Top, rectTab.Right, rectTab.Top);
  535.             }
  536.             else
  537.             {
  538.                 path.AddLine(rectTab.Right, rectTab.Bottom, rectPaneClient.Right, rectTab.Bottom);
  539.                 path.AddLine(rectPaneClient.Right, rectTab.Bottom, rectPaneClient.Right, rectPaneClient.Bottom);
  540.                 path.AddLine(rectPaneClient.Right, rectPaneClient.Bottom, rectPaneClient.Left, rectPaneClient.Bottom);
  541.                 path.AddLine(rectPaneClient.Left, rectPaneClient.Bottom, rectPaneClient.Left, rectTab.Bottom);
  542.                 path.AddLine(rectPaneClient.Left, rectTab.Bottom, rectTab.Right, rectTab.Bottom);
  543.             }
  544.             return path;
  545.         }
  546.         private GraphicsPath GetOutline_ToolWindow(int index)
  547.         {
  548.             Rectangle rectTab = GetTabRectangle(index);
  549.             rectTab.Intersect(TabsRectangle);
  550.             rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab));
  551.             int y = rectTab.Top;
  552.             Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle);
  553.             GraphicsPath path = new GraphicsPath();
  554.             GraphicsPath pathTab = GetTabOutline(Tabs[index], true, true);
  555.             path.AddPath(pathTab, true);
  556.             path.AddLine(rectTab.Left, rectTab.Top, rectPaneClient.Left, rectTab.Top);
  557.             path.AddLine(rectPaneClient.Left, rectTab.Top, rectPaneClient.Left, rectPaneClient.Top);
  558.             path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Right, rectPaneClient.Top);
  559.             path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Right, rectTab.Top);
  560.             path.AddLine(rectPaneClient.Right, rectTab.Top, rectTab.Right, rectTab.Top);
  561.             return path;
  562.         }
  563. private void CalculateTabs()
  564. {
  565. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  566. CalculateTabs_ToolWindow();
  567. else
  568. CalculateTabs_Document();
  569. }
  570. private void CalculateTabs_ToolWindow()
  571. {
  572. if (Tabs.Count <= 1 || DockPane.IsAutoHide)
  573. return;
  574. Rectangle rectTabStrip = TabStripRectangle;
  575. // Calculate tab widths
  576. int countTabs = Tabs.Count;
  577.             foreach (TabVS2005 tab in Tabs)
  578.             {
  579.                 tab.MaxWidth = GetMaxTabWidth(Tabs.IndexOf(tab));
  580.                 tab.Flag = false;
  581.             }
  582. // Set tab whose max width less than average width
  583. bool anyWidthWithinAverage = true;
  584. int totalWidth = rectTabStrip.Width - ToolWindowStripGapLeft - ToolWindowStripGapRight;
  585. int totalAllocatedWidth = 0;
  586. int averageWidth = totalWidth / countTabs;
  587. int remainedTabs = countTabs;
  588. for (anyWidthWithinAverage=true; anyWidthWithinAverage && remainedTabs>0;)
  589. {
  590. anyWidthWithinAverage = false;
  591. foreach (TabVS2005 tab in Tabs)
  592. {
  593. if (tab.Flag)
  594. continue;
  595. if (tab.MaxWidth <= averageWidth)
  596. {
  597. tab.Flag = true;
  598. tab.TabWidth = tab.MaxWidth;
  599. totalAllocatedWidth += tab.TabWidth;
  600. anyWidthWithinAverage = true;
  601. remainedTabs--;
  602. }
  603. }
  604. if (remainedTabs != 0)
  605. averageWidth = (totalWidth - totalAllocatedWidth) / remainedTabs;
  606. }
  607. // If any tab width not set yet, set it to the average width
  608. if (remainedTabs > 0)
  609. {
  610. int roundUpWidth = (totalWidth - totalAllocatedWidth) - (averageWidth * remainedTabs);
  611. foreach (TabVS2005 tab in Tabs)
  612. {
  613. if (tab.Flag)
  614. continue;
  615. tab.Flag = true;
  616. if (roundUpWidth > 0)
  617. {
  618. tab.TabWidth = averageWidth + 1;
  619. roundUpWidth --;
  620. }
  621. else
  622. tab.TabWidth = averageWidth;
  623. }
  624. }
  625. // Set the X position of the tabs
  626. int x = rectTabStrip.X + ToolWindowStripGapLeft;
  627. foreach (TabVS2005 tab in Tabs)
  628. {
  629. tab.TabX = x;
  630. x += tab.TabWidth;
  631. }
  632. }
  633.         private bool CalculateDocumentTab(Rectangle rectTabStrip, ref int x, int index)
  634.         {
  635.             bool overflow = false;
  636.             TabVS2005 tab = Tabs[index] as TabVS2005;
  637.             tab.MaxWidth = GetMaxTabWidth(index);
  638.             int width = Math.Min(tab.MaxWidth, DocumentTabMaxWidth);
  639.             if (x + width < rectTabStrip.Right || index == StartDisplayingTab)
  640.             {
  641.                 tab.TabX = x;
  642.                 tab.TabWidth = width;
  643.                 EndDisplayingTab = index;
  644.             }
  645.             else
  646.             {
  647.                 tab.TabX = 0;
  648.                 tab.TabWidth = 0;
  649.                 overflow = true;
  650.             }
  651.             x += width;
  652.             return overflow;
  653.         }
  654.         /// <summary>
  655.         /// Calculate which tabs are displayed and in what order.
  656.         /// </summary>
  657. private void CalculateTabs_Document()
  658. {
  659.             if (m_startDisplayingTab >= Tabs.Count)
  660.                 m_startDisplayingTab = 0;
  661.             Rectangle rectTabStrip = TabsRectangle;
  662. int x = rectTabStrip.X + rectTabStrip.Height / 2;
  663.             bool overflow = false;
  664.             // Originally all new documents that were considered overflow
  665.             // (not enough pane strip space to show all tabs) were added to
  666.             // the far left (assuming not right to left) and the tabs on the
  667.             // right were dropped from view. If StartDisplayingTab is not 0
  668.             // then we are dealing with making sure a specific tab is kept in focus.
  669.             if (m_startDisplayingTab > 0)
  670.             {
  671.                 int tempX = x;
  672.                 TabVS2005 tab = Tabs[m_startDisplayingTab] as TabVS2005;
  673.                 tab.MaxWidth = GetMaxTabWidth(m_startDisplayingTab);
  674.                 int width = Math.Min(tab.MaxWidth, DocumentTabMaxWidth);
  675.                 // Add the active tab and tabs to the left
  676.                 for (int i = StartDisplayingTab; i >= 0; i--)
  677.                     CalculateDocumentTab(rectTabStrip, ref tempX, i);
  678.                 // Store which tab is the first one displayed so that it
  679.                 // will be drawn correctly (without part of the tab cut off)
  680.                 FirstDisplayingTab = EndDisplayingTab;
  681.                 tempX = x; // Reset X location because we are starting over
  682.                 
  683.                 // Start with the first tab displayed - name is a little misleading.
  684.                 // Loop through each tab and set its location. If there is not enough
  685.                 // room for all of them overflow will be returned.
  686.                 for (int i = EndDisplayingTab; i < Tabs.Count; i++)
  687.                     overflow = CalculateDocumentTab(rectTabStrip, ref tempX, i);
  688.                 // If not all tabs are shown then we have an overflow.
  689.                 if (FirstDisplayingTab != 0)
  690.                     overflow = true;
  691.             }
  692.             else
  693.             {
  694.                 for (int i = StartDisplayingTab; i < Tabs.Count; i++)
  695.                     overflow = CalculateDocumentTab(rectTabStrip, ref x, i);
  696.                 for (int i = 0; i < StartDisplayingTab; i++)
  697.                     overflow = CalculateDocumentTab(rectTabStrip, ref x, i);
  698.                 FirstDisplayingTab = StartDisplayingTab;
  699.             }
  700.             if (!overflow)
  701.             {
  702.                 m_startDisplayingTab = 0;
  703.                 FirstDisplayingTab = 0;
  704.                 x = rectTabStrip.X + rectTabStrip.Height / 2;
  705.                 foreach (TabVS2005 tab in Tabs)
  706.                 {
  707.                     tab.TabX = x;
  708.                     x += tab.TabWidth;
  709.                 }
  710.             }
  711.             DocumentTabsOverflow = overflow;
  712. }
  713.         protected internal override void EnsureTabVisible(IDockContent content)
  714. {
  715.             if (Appearance != DockPane.AppearanceStyle.Document || !Tabs.Contains(content))
  716.                 return;
  717.             CalculateTabs();
  718.             EnsureDocumentTabVisible(content, true);
  719. }
  720.         private bool EnsureDocumentTabVisible(IDockContent content, bool repaint)
  721.         {
  722.             int index = Tabs.IndexOf(content);
  723.             TabVS2005 tab = Tabs[index] as TabVS2005;
  724.             if (tab.TabWidth != 0)
  725.                 return false;
  726.             StartDisplayingTab = index;
  727.             if (repaint)
  728.                 Invalidate();
  729.             return true;
  730.         }
  731. private int GetMaxTabWidth(int index)
  732. {
  733. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  734. return GetMaxTabWidth_ToolWindow(index);
  735. else
  736. return GetMaxTabWidth_Document(index);
  737. }
  738. private int GetMaxTabWidth_ToolWindow(int index)
  739. {
  740. IDockContent content = Tabs[index].Content;
  741. Size sizeString = TextRenderer.MeasureText(content.DockHandler.TabText, TextFont);
  742. return ToolWindowImageWidth + sizeString.Width + ToolWindowImageGapLeft
  743. + ToolWindowImageGapRight + ToolWindowTextGapRight;
  744. }
  745. private int GetMaxTabWidth_Document(int index)
  746. {
  747. IDockContent content = Tabs[index].Content;
  748.             int height = GetTabRectangle_Document(index).Height;
  749.             Size sizeText = TextRenderer.MeasureText(content.DockHandler.TabText, BoldFont, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
  750. if (DockPane.DockPanel.ShowDocumentIcon)
  751. return sizeText.Width + DocumentIconWidth + DocumentIconGapLeft + DocumentIconGapRight + DocumentTextGapRight;
  752. else
  753. return sizeText.Width + DocumentIconGapLeft + DocumentTextGapRight;
  754. }
  755. private void DrawTabStrip(Graphics g)
  756. {
  757. if (Appearance == DockPane.AppearanceStyle.Document)
  758. DrawTabStrip_Document(g);
  759. else
  760. DrawTabStrip_ToolWindow(g);
  761. }
  762. private void DrawTabStrip_Document(Graphics g)
  763. {
  764. int count = Tabs.Count;
  765. if (count == 0)
  766. return;
  767. Rectangle rectTabStrip = TabStripRectangle;
  768.             // Draw the tabs
  769. Rectangle rectTabOnly = TabsRectangle;
  770. Rectangle rectTab = Rectangle.Empty;
  771.             TabVS2005 tabActive = null;
  772. g.SetClip(DrawHelper.RtlTransform(this, rectTabOnly));
  773. for (int i=0; i<count; i++)
  774. {
  775. rectTab = GetTabRectangle(i);
  776.                 if (Tabs[i].Content == DockPane.ActiveContent)
  777.                 {
  778.                     tabActive = Tabs[i] as TabVS2005;
  779.                     continue;
  780.                 }
  781. if (rectTab.IntersectsWith(rectTabOnly))
  782. DrawTab(g, Tabs[i] as TabVS2005, rectTab);
  783. }
  784.             g.SetClip(rectTabStrip);
  785.             if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  786.                 g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Top + 1,
  787.                  rectTabStrip.Right, rectTabStrip.Top + 1);
  788.             else
  789.                 g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Bottom - 1,
  790.                     rectTabStrip.Right, rectTabStrip.Bottom - 1);
  791.             g.SetClip(DrawHelper.RtlTransform(this, rectTabOnly));
  792.             if (tabActive != null)
  793.             {
  794.                 rectTab = GetTabRectangle(Tabs.IndexOf(tabActive));
  795.                 if (rectTab.IntersectsWith(rectTabOnly))
  796.                     DrawTab(g, tabActive, rectTab);
  797.             }
  798. }
  799. private void DrawTabStrip_ToolWindow(Graphics g)
  800. {
  801. Rectangle rectTabStrip = TabStripRectangle;
  802. g.DrawLine(PenToolWindowTabBorder, rectTabStrip.Left, rectTabStrip.Top,
  803. rectTabStrip.Right, rectTabStrip.Top);
  804. for (int i=0; i<Tabs.Count; i++)
  805. DrawTab(g, Tabs[i] as TabVS2005, GetTabRectangle(i));
  806. }
  807. private Rectangle GetTabRectangle(int index)
  808. {
  809. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  810. return GetTabRectangle_ToolWindow(index);
  811. else
  812. return GetTabRectangle_Document(index);
  813. }
  814. private Rectangle GetTabRectangle_ToolWindow(int index)
  815. {
  816. Rectangle rectTabStrip = TabStripRectangle;
  817. TabVS2005 tab = (TabVS2005)(Tabs[index]);
  818. return new Rectangle(tab.TabX, rectTabStrip.Y, tab.TabWidth, rectTabStrip.Height);
  819. }
  820. private Rectangle GetTabRectangle_Document(int index)
  821. {
  822. Rectangle rectTabStrip = TabStripRectangle;
  823. TabVS2005 tab = (TabVS2005)Tabs[index];
  824.             Rectangle rect = new Rectangle();
  825.             rect.X = tab.TabX;
  826.             rect.Width = tab.TabWidth;
  827.             rect.Height = rectTabStrip.Height - DocumentTabGapTop;
  828.             if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  829.                 rect.Y = rectTabStrip.Y + DocumentStripGapBottom;
  830.             else
  831.                 rect.Y = rectTabStrip.Y + DocumentTabGapTop;
  832. return rect;
  833. }
  834.         private void DrawTab(Graphics g, TabVS2005 tab, Rectangle rect)
  835. {
  836. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  837. DrawTab_ToolWindow(g, tab, rect);
  838. else
  839. DrawTab_Document(g, tab, rect);
  840. }
  841.         private GraphicsPath GetTabOutline(Tab tab, bool rtlTransform, bool toScreen)
  842.         {
  843.             if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  844.                 return GetTabOutline_ToolWindow(tab, rtlTransform, toScreen);
  845.             else
  846.                 return GetTabOutline_Document(tab, rtlTransform, toScreen, false);
  847.         }
  848.         private GraphicsPath GetTabOutline_ToolWindow(Tab tab, bool rtlTransform, bool toScreen)
  849.         {
  850.             Rectangle rect = GetTabRectangle(Tabs.IndexOf(tab));
  851.             if (rtlTransform)
  852.                 rect = DrawHelper.RtlTransform(this, rect);
  853.             if (toScreen)
  854.                 rect = RectangleToScreen(rect);
  855.             DrawHelper.GetRoundedCornerTab(GraphicsPath, rect, false);
  856.             return GraphicsPath;
  857.         }
  858.         private GraphicsPath GetTabOutline_Document(Tab tab, bool rtlTransform, bool toScreen, bool full)
  859.         {
  860.             int curveSize = 6;
  861.             GraphicsPath.Reset();
  862.             Rectangle rect = GetTabRectangle(Tabs.IndexOf(tab));
  863.             if (rtlTransform)
  864.                 rect = DrawHelper.RtlTransform(this, rect);
  865.             if (toScreen)
  866.                 rect = RectangleToScreen(rect);
  867.             // Draws the full angle piece for active content (or first tab)
  868.             if (tab.Content == DockPane.ActiveContent || full || Tabs.IndexOf(tab) == FirstDisplayingTab)
  869.             {
  870.                 if (RightToLeft == RightToLeft.Yes)
  871.                 {
  872.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  873.                     {
  874.                         // For some reason the next line draws a line that is not hidden like it is when drawing the tab strip on top.
  875.                         // It is not needed so it has been commented out.
  876.                         //GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right + rect.Height / 2, rect.Bottom);
  877.                         GraphicsPath.AddLine(rect.Right + rect.Height / 2, rect.Top, rect.Right - rect.Height / 2 + curveSize / 2, rect.Bottom - curveSize / 2);
  878.                     }
  879.                     else
  880.                     {
  881.                         GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right + rect.Height / 2, rect.Bottom);
  882.                         GraphicsPath.AddLine(rect.Right + rect.Height / 2, rect.Bottom, rect.Right - rect.Height / 2 + curveSize / 2, rect.Top + curveSize / 2);
  883.                     }
  884.                 }
  885.                 else
  886.                 {
  887.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  888.                     {
  889.                         // For some reason the next line draws a line that is not hidden like it is when drawing the tab strip on top.
  890.                         // It is not needed so it has been commented out.
  891.                         //GraphicsPath.AddLine(rect.Left, rect.Top, rect.Left - rect.Height / 2, rect.Top);
  892.                         GraphicsPath.AddLine(rect.Left - rect.Height / 2, rect.Top, rect.Left + rect.Height / 2 - curveSize / 2, rect.Bottom - curveSize / 2);
  893.                     }
  894.                     else
  895.                     {
  896.                         GraphicsPath.AddLine(rect.Left, rect.Bottom, rect.Left - rect.Height / 2, rect.Bottom);
  897.                         GraphicsPath.AddLine(rect.Left - rect.Height / 2, rect.Bottom, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
  898.                     }
  899.                 }
  900.             }
  901.             // Draws the partial angle for non-active content
  902.             else
  903.             {
  904.                 if (RightToLeft == RightToLeft.Yes)
  905.                 {
  906.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  907.                     {
  908.                         GraphicsPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Top + rect.Height / 2);
  909.                         GraphicsPath.AddLine(rect.Right, rect.Top + rect.Height / 2, rect.Right - rect.Height / 2 + curveSize / 2, rect.Bottom - curveSize / 2);
  910.                     }
  911.                     else
  912.                     {
  913.                         GraphicsPath.AddLine(rect.Right, rect.Bottom, rect.Right, rect.Bottom - rect.Height / 2);
  914.                         GraphicsPath.AddLine(rect.Right, rect.Bottom - rect.Height / 2, rect.Right - rect.Height / 2 + curveSize / 2, rect.Top + curveSize / 2);
  915.                     }
  916.                 }
  917.                 else
  918.                 {
  919.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  920.                     {
  921.                         GraphicsPath.AddLine(rect.Left, rect.Top, rect.Left, rect.Top + rect.Height / 2);
  922.                         GraphicsPath.AddLine(rect.Left, rect.Top + rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Bottom - curveSize / 2);
  923.                     }
  924.                     else
  925.                     {
  926.                         GraphicsPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 2);
  927.                         GraphicsPath.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
  928.                     }
  929.                 }
  930.             }
  931.             if (RightToLeft == RightToLeft.Yes)
  932.             {
  933.                 if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  934.                 {
  935.                     // Draws the bottom horizontal line (short side)
  936.                     GraphicsPath.AddLine(rect.Right - rect.Height / 2 - curveSize / 2, rect.Bottom, rect.Left + curveSize / 2, rect.Bottom);
  937.                     // Drawing the rounded corner is not necessary. The path is automatically connected
  938.                     //GraphicsPath.AddArc(new Rectangle(rect.Left, rect.Top, curveSize, curveSize), 180, 90);
  939.                 }
  940.                 else
  941.                 {
  942.                     // Draws the bottom horizontal line (short side)
  943.                     GraphicsPath.AddLine(rect.Right - rect.Height / 2 - curveSize / 2, rect.Top, rect.Left + curveSize / 2, rect.Top);
  944.                     GraphicsPath.AddArc(new Rectangle(rect.Left, rect.Top, curveSize, curveSize), 180, 90);
  945.                 }
  946.             }
  947.             else
  948.             {
  949.                 if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  950.                 {
  951.                     // Draws the bottom horizontal line (short side)
  952.                     GraphicsPath.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Bottom, rect.Right - curveSize / 2, rect.Bottom);
  953.                     // Drawing the rounded corner is not necessary. The path is automatically connected
  954.                     //GraphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Bottom, curveSize, curveSize), 90, -90);
  955.                 }
  956.                 else
  957.                 {
  958.                     // Draws the top horizontal line (short side)
  959.                     GraphicsPath.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Top, rect.Right - curveSize / 2, rect.Top);
  960.                     // Draws the rounded corner oppposite the angled side
  961.                     GraphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Top, curveSize, curveSize), -90, 90);
  962.                 }
  963.             }
  964.             if (Tabs.IndexOf(tab) != EndDisplayingTab &&
  965.                 (Tabs.IndexOf(tab) != Tabs.Count - 1 && Tabs[Tabs.IndexOf(tab) + 1].Content == DockPane.ActiveContent)
  966.                 && !full)
  967.             {
  968.                 if (RightToLeft == RightToLeft.Yes)
  969.                 {
  970.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  971.                     {
  972.                         GraphicsPath.AddLine(rect.Left, rect.Bottom - curveSize / 2, rect.Left, rect.Bottom - rect.Height / 2);
  973.                         GraphicsPath.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2, rect.Top);
  974.                     }
  975.                     else
  976.                     {
  977.                         GraphicsPath.AddLine(rect.Left, rect.Top + curveSize / 2, rect.Left, rect.Top + rect.Height / 2);
  978.                         GraphicsPath.AddLine(rect.Left, rect.Top + rect.Height / 2, rect.Left + rect.Height / 2, rect.Bottom);
  979.                     }
  980.                 }
  981.                 else
  982.                 {
  983.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  984.                     {
  985.                         GraphicsPath.AddLine(rect.Right, rect.Bottom - curveSize / 2, rect.Right, rect.Bottom - rect.Height / 2);
  986.                         GraphicsPath.AddLine(rect.Right, rect.Bottom - rect.Height / 2, rect.Right - rect.Height / 2, rect.Top);
  987.                     }
  988.                     else
  989.                     {
  990.                         GraphicsPath.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Top + rect.Height / 2);
  991.                         GraphicsPath.AddLine(rect.Right, rect.Top + rect.Height / 2, rect.Right - rect.Height / 2, rect.Bottom);
  992.                     }
  993.                 }
  994.             }
  995.             else
  996.             {
  997.                 // Draw the vertical line opposite the angled side
  998.                 if (RightToLeft == RightToLeft.Yes)
  999.                 {
  1000.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  1001.                         GraphicsPath.AddLine(rect.Left, rect.Bottom - curveSize / 2, rect.Left, rect.Top);
  1002.                     else
  1003.                         GraphicsPath.AddLine(rect.Left, rect.Top + curveSize / 2, rect.Left, rect.Bottom);
  1004.                 }
  1005.                 else
  1006.                 {
  1007.                     if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom)
  1008.                         GraphicsPath.AddLine(rect.Right, rect.Bottom - curveSize / 2, rect.Right, rect.Top);
  1009.                     else
  1010.                         GraphicsPath.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Bottom);
  1011.                 }
  1012.             }
  1013.             return GraphicsPath;
  1014.         }
  1015. private void DrawTab_ToolWindow(Graphics g, TabVS2005 tab, Rectangle rect)
  1016. {
  1017. Rectangle rectIcon = new Rectangle(
  1018. rect.X + ToolWindowImageGapLeft,
  1019. rect.Y + rect.Height - 1 - ToolWindowImageGapBottom - ToolWindowImageHeight,
  1020. ToolWindowImageWidth, ToolWindowImageHeight);
  1021. Rectangle rectText = rectIcon;
  1022. rectText.X += rectIcon.Width + ToolWindowImageGapRight;
  1023. rectText.Width = rect.Width - rectIcon.Width - ToolWindowImageGapLeft - 
  1024. ToolWindowImageGapRight - ToolWindowTextGapRight;
  1025.             Rectangle rectTab = DrawHelper.RtlTransform(this, rect);
  1026.             rectText = DrawHelper.RtlTransform(this, rectText);
  1027.             rectIcon = DrawHelper.RtlTransform(this, rectIcon);
  1028.             GraphicsPath path = GetTabOutline(tab, true, false);
  1029. if (DockPane.ActiveContent == tab.Content)
  1030. {
  1031.                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.StartColor;
  1032.                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.EndColor;
  1033.                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.LinearGradientMode;
  1034. g.FillPath(new LinearGradientBrush(rectTab, startColor, endColor, gradientMode), path);
  1035.                 g.DrawPath(PenToolWindowTabBorder, path);
  1036.                 Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.ActiveTabGradient.TextColor;
  1037.                 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, ToolWindowTextFormat);
  1038. }
  1039. else
  1040. {
  1041.                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.StartColor;
  1042.                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.EndColor;
  1043.                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.LinearGradientMode;
  1044.                 g.FillPath(new LinearGradientBrush(rectTab, startColor, endColor, gradientMode), path);
  1045.                 if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
  1046.                 {
  1047.                     Point pt1 = new Point(rect.Right, rect.Top + ToolWindowTabSeperatorGapTop);
  1048.                     Point pt2 = new Point(rect.Right, rect.Bottom - ToolWindowTabSeperatorGapBottom); 
  1049.                     g.DrawLine(PenToolWindowTabBorder, DrawHelper.RtlTransform(this, pt1), DrawHelper.RtlTransform(this, pt2));
  1050.                 }
  1051.                 Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.ToolWindowGradient.InactiveTabGradient.TextColor;
  1052.                 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, ToolWindowTextFormat);
  1053. }
  1054. if (rectTab.Contains(rectIcon))
  1055. g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
  1056. }
  1057. private void DrawTab_Document(Graphics g, TabVS2005 tab, Rectangle rect)
  1058. {
  1059.             if (tab.TabWidth == 0)
  1060.                 return;
  1061.             Rectangle rectIcon = new Rectangle(
  1062.                 rect.X + DocumentIconGapLeft,
  1063.                 rect.Y + rect.Height - 1 - DocumentIconGapBottom - DocumentIconHeight,
  1064.                 DocumentIconWidth, DocumentIconHeight);
  1065.             Rectangle rectText = rectIcon;
  1066.             if (DockPane.DockPanel.ShowDocumentIcon)
  1067.             {
  1068.                 rectText.X += rectIcon.Width + DocumentIconGapRight;
  1069.                 rectText.Y = rect.Y;
  1070.                 rectText.Width = rect.Width - rectIcon.Width - DocumentIconGapLeft -
  1071.                     DocumentIconGapRight - DocumentTextGapRight;
  1072.                 rectText.Height = rect.Height;
  1073.             }
  1074.             else
  1075.                 rectText.Width = rect.Width - DocumentIconGapLeft - DocumentTextGapRight;
  1076.             Rectangle rectTab = DrawHelper.RtlTransform(this, rect);
  1077.             Rectangle rectBack = DrawHelper.RtlTransform(this, rect);
  1078.             rectBack.Width += rect.X;
  1079.             rectBack.X = 0;
  1080.             rectText = DrawHelper.RtlTransform(this, rectText);
  1081.             rectIcon = DrawHelper.RtlTransform(this, rectIcon);
  1082.             GraphicsPath path = GetTabOutline(tab, true, false);
  1083.             if (DockPane.ActiveContent == tab.Content)
  1084.             {
  1085.                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.StartColor;
  1086.                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.EndColor;
  1087.                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.LinearGradientMode;
  1088.                 g.FillPath(new LinearGradientBrush(rectBack, startColor, endColor, gradientMode), path);
  1089.                 g.DrawPath(PenDocumentTabActiveBorder, path);
  1090.                 Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.ActiveTabGradient.TextColor;
  1091.                 if (DockPane.IsActiveDocumentPane)
  1092.                     TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, BoldFont, rectText, textColor, DocumentTextFormat);
  1093.                 else
  1094.                     TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, DocumentTextFormat);
  1095.             }
  1096.             else
  1097.             {
  1098.                 Color startColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.StartColor;
  1099.                 Color endColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.EndColor;
  1100.                 LinearGradientMode gradientMode = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.LinearGradientMode;
  1101.                 g.FillPath(new LinearGradientBrush(rectBack, startColor, endColor, gradientMode), path);
  1102.                 g.DrawPath(PenDocumentTabInactiveBorder, path);
  1103.                 Color textColor = DockPane.DockPanel.Skin.DockPaneStripSkin.DocumentGradient.InactiveTabGradient.TextColor;
  1104.                 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, TextFont, rectText, textColor, DocumentTextFormat);
  1105.             }
  1106.             if (rectTab.Contains(rectIcon) && DockPane.DockPanel.ShowDocumentIcon)
  1107.                 g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
  1108.         }
  1109.         private Rectangle TabStripRectangle
  1110.         {
  1111.             get
  1112.             {
  1113.                 if (Appearance == DockPane.AppearanceStyle.Document)
  1114.                     return TabStripRectangle_Document;
  1115.                 else
  1116.                     return TabStripRectangle_ToolWindow;
  1117.             }
  1118.         }
  1119.         private Rectangle TabStripRectangle_ToolWindow
  1120.         {
  1121.             get
  1122.             {
  1123.                 Rectangle rect = ClientRectangle;
  1124.                 return new Rectangle(rect.X, rect.Top + ToolWindowStripGapTop, rect.Width, rect.Height - ToolWindowStripGapTop - ToolWindowStripGapBottom);
  1125.             }
  1126.         }
  1127.         private Rectangle TabStripRectangle_Document
  1128.         {
  1129.             get
  1130.             {
  1131.                 Rectangle rect = ClientRectangle;
  1132.                 return new Rectangle(rect.X, rect.Top + DocumentStripGapTop, rect.Width, rect.Height - DocumentStripGapTop - ToolWindowStripGapBottom);
  1133.             }
  1134.         }
  1135. private Rectangle TabsRectangle
  1136. {
  1137. get
  1138. {
  1139. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  1140. return TabStripRectangle;
  1141. Rectangle rectWindow = TabStripRectangle;
  1142. int x = rectWindow.X;
  1143. int y = rectWindow.Y;
  1144. int width = rectWindow.Width;
  1145. int height = rectWindow.Height;
  1146. x += DocumentTabGapLeft;
  1147. width -= DocumentTabGapLeft + 
  1148. DocumentTabGapRight +
  1149. DocumentButtonGapRight +
  1150. ButtonClose.Width +
  1151. ButtonWindowList.Width +
  1152. 2 * DocumentButtonGapBetween;
  1153. return new Rectangle(x, y, width, height);
  1154. }
  1155. }
  1156.         private ContextMenuStrip m_selectMenu;
  1157.         private ContextMenuStrip SelectMenu
  1158.         {
  1159.             get { return m_selectMenu; }
  1160.         }
  1161.         private void WindowList_Click(object sender, EventArgs e)
  1162.         {
  1163.             int x = 0;
  1164.             int y = ButtonWindowList.Location.Y + ButtonWindowList.Height;
  1165.             SelectMenu.Items.Clear();
  1166.             foreach (TabVS2005 tab in Tabs)
  1167.             {
  1168.                 IDockContent content = tab.Content;
  1169.                 ToolStripItem item = SelectMenu.Items.Add(content.DockHandler.TabText, content.DockHandler.Icon.ToBitmap());
  1170.                 item.Tag = tab.Content;
  1171.                 item.Click += new EventHandler(ContextMenuItem_Click);
  1172.             }
  1173.             SelectMenu.Show(ButtonWindowList, x, y);
  1174.         }
  1175.         private void ContextMenuItem_Click(object sender, EventArgs e)
  1176.         {
  1177.             ToolStripMenuItem item = sender as ToolStripMenuItem;
  1178.             if (item != null)
  1179.             {
  1180.                 IDockContent content = (IDockContent)item.Tag;
  1181.                 DockPane.ActiveContent = content;
  1182.             }
  1183. }
  1184. private void SetInertButtons()
  1185. {
  1186.             if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  1187.             {
  1188.                 if (m_buttonClose != null)
  1189.                     m_buttonClose.Left = -m_buttonClose.Width;
  1190.                 if (m_buttonWindowList != null)
  1191.                     m_buttonWindowList.Left = -m_buttonWindowList.Width;
  1192.             }
  1193.             else
  1194.             {
  1195.                 bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
  1196.                 ButtonClose.Enabled = showCloseButton;
  1197.                 ButtonClose.Visible = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButtonVisible;
  1198.                 ButtonClose.RefreshChanges();
  1199.                 ButtonWindowList.RefreshChanges();
  1200.             }
  1201. }
  1202. protected override void OnLayout(LayoutEventArgs levent)
  1203. {
  1204.             if (Appearance != DockPane.AppearanceStyle.Document)
  1205.             {
  1206.                 base.OnLayout(levent);
  1207.                 return;
  1208.             }
  1209. Rectangle rectTabStrip = TabStripRectangle;
  1210.             // Set position and size of the buttons
  1211. int buttonWidth = ButtonClose.Image.Width;
  1212. int buttonHeight = ButtonClose.Image.Height;
  1213.             int height = rectTabStrip.Height - DocumentButtonGapTop - DocumentButtonGapBottom;
  1214. if (buttonHeight < height)
  1215. {
  1216. buttonWidth = buttonWidth * (height / buttonHeight);
  1217. buttonHeight = height;
  1218. }
  1219. Size buttonSize = new Size(buttonWidth, buttonHeight);
  1220. int x = rectTabStrip.X + rectTabStrip.Width - DocumentTabGapLeft
  1221. - DocumentButtonGapRight - buttonWidth;
  1222. int y = rectTabStrip.Y + DocumentButtonGapTop;
  1223.             Point point = new Point(x, y);
  1224. ButtonClose.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
  1225.             
  1226.             // If the close button is not visible draw the window list button overtop.
  1227.             // Otherwise it is drawn to the left of the close button.
  1228.             if (ButtonClose.Visible)
  1229.     point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
  1230.             
  1231.             ButtonWindowList.Bounds = DrawHelper.RtlTransform(this, new Rectangle(point, buttonSize));
  1232. OnRefreshChanges();
  1233. base.OnLayout (levent);
  1234. }
  1235. private void Close_Click(object sender, EventArgs e)
  1236. {
  1237. DockPane.CloseActiveContent();
  1238. }
  1239. protected internal override int HitTest(Point ptMouse)
  1240. {
  1241. Rectangle rectTabStrip = TabsRectangle;
  1242.             if (!TabsRectangle.Contains(ptMouse))
  1243.                 return -1;
  1244.             foreach (Tab tab in Tabs)
  1245.             {
  1246.                 GraphicsPath path = GetTabOutline(tab, true, false);
  1247.                 if (path.IsVisible(ptMouse))
  1248.                     return Tabs.IndexOf(tab);
  1249.             }
  1250.             return -1;
  1251. }
  1252. protected override void OnMouseHover(EventArgs e)
  1253. {
  1254. int index = HitTest(PointToClient(Control.MousePosition));
  1255. string toolTip = string.Empty;
  1256. base.OnMouseHover(e);
  1257.             if (index != -1)
  1258. {
  1259.                 TabVS2005 tab = Tabs[index] as TabVS2005;
  1260.                 if (!String.IsNullOrEmpty(tab.Content.DockHandler.ToolTipText))
  1261.                     toolTip = tab.Content.DockHandler.ToolTipText;
  1262.                 else if (tab.MaxWidth > tab.TabWidth)
  1263.                     toolTip = tab.Content.DockHandler.TabText;
  1264. }
  1265. if (m_toolTip.GetToolTip(this) != toolTip)
  1266. {
  1267. m_toolTip.Active = false;
  1268. m_toolTip.SetToolTip(this, toolTip);
  1269. m_toolTip.Active = true;
  1270. }
  1271.             // requires further tracking of mouse hover behavior,
  1272.             ResetMouseEventArgs();
  1273. }
  1274.         protected override void OnRightToLeftChanged(EventArgs e)
  1275.         {
  1276.             base.OnRightToLeftChanged(e);
  1277.             PerformLayout();
  1278.         }
  1279. }
  1280. }