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

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 WeifenLuo.WinFormsUI.Docking;
  7. namespace DockSample.Customization
  8. {
  9. internal class VS2003DockPaneStrip : DockPaneStripBase
  10. {
  11.         private class TabVS2003 : Tab
  12.         {
  13.             internal TabVS2003(IDockContent content)
  14.                 : base(content)
  15.             {
  16.             }
  17.             private int m_tabX;
  18.             protected internal int TabX
  19.             {
  20.                 get { return m_tabX; }
  21.                 set { m_tabX = value; }
  22.             }
  23.             private int m_tabWidth;
  24.             protected internal int TabWidth
  25.             {
  26.                 get { return m_tabWidth; }
  27.                 set { m_tabWidth = value; }
  28.             }
  29.             private int m_maxWidth;
  30.             protected internal int MaxWidth
  31.             {
  32.                 get { return m_maxWidth; }
  33.                 set { m_maxWidth = value; }
  34.             }
  35.             private bool m_flag;
  36.             protected internal bool Flag
  37.             {
  38.                 get { return m_flag; }
  39.                 set { m_flag = value; }
  40.             }
  41.         }
  42.         protected override DockPaneStripBase.Tab CreateTab(IDockContent content)
  43.         {
  44.             return new TabVS2003(content);
  45.         }
  46.         private class DocumentButton : Label
  47.         {
  48.             public DocumentButton(Image image)
  49.             {
  50.                 Image = image;
  51.             }
  52.         }
  53. #region consts
  54. private const int _ToolWindowStripGapLeft = 4;
  55. private const int _ToolWindowStripGapRight = 3;
  56. private const int _ToolWindowImageHeight = 16;
  57. private const int _ToolWindowImageWidth = 16;
  58. private const int _ToolWindowImageGapTop = 3;
  59. private const int _ToolWindowImageGapBottom = 1;
  60. private const int _ToolWindowImageGapLeft = 3;
  61. private const int _ToolWindowImageGapRight = 2;
  62. private const int _ToolWindowTextGapRight = 1;
  63. private const int _ToolWindowTabSeperatorGapTop = 3;
  64. private const int _ToolWindowTabSeperatorGapBottom = 3;
  65. private const int _DocumentTabMaxWidth = 200;
  66. private const int _DocumentButtonGapTop = 5;
  67. private const int _DocumentButtonGapBottom = 5;
  68. private const int _DocumentButtonGapBetween = 0;
  69. private const int _DocumentButtonGapRight = 3;
  70. private const int _DocumentTabGapTop = 3;
  71. private const int _DocumentTabGapLeft = 3;
  72. private const int _DocumentTabGapRight = 3;
  73. private const int _DocumentIconGapLeft = 6;
  74. private const int _DocumentIconHeight = 16;
  75. private const int _DocumentIconWidth = 16;
  76. #endregion
  77. private InertButton m_buttonClose, m_buttonScrollLeft, m_buttonScrollRight;
  78. private IContainer m_components;
  79. private ToolTip m_toolTip;
  80. /// <exclude/>
  81. protected IContainer Components
  82. {
  83. get { return m_components; }
  84. }
  85. private int m_offsetX = 0;
  86. private int OffsetX
  87. {
  88. get { return m_offsetX; }
  89. set
  90. {
  91. m_offsetX = value;
  92. #if DEBUG
  93. if (m_offsetX > 0)
  94. throw new InvalidOperationException();
  95. #endif
  96. }
  97. }
  98. #region Customizable Properties
  99. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowStripGapLeft"]/*'/>
  100. protected virtual int ToolWindowStripGapLeft
  101. {
  102. get { return _ToolWindowStripGapLeft; }
  103. }
  104. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowStripGapRight"]/*'/>
  105. protected virtual int ToolWindowStripGapRight
  106. {
  107. get { return _ToolWindowStripGapRight; }
  108. }
  109. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageHeight"]/*'/>
  110. protected virtual int ToolWindowImageHeight
  111. {
  112. get { return _ToolWindowImageHeight; }
  113. }
  114. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageWidth"]/*'/>
  115. protected virtual int ToolWindowImageWidth
  116. {
  117. get { return _ToolWindowImageWidth; }
  118. }
  119. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapTop"]/*'/>
  120. protected virtual int ToolWindowImageGapTop
  121. {
  122. get { return _ToolWindowImageGapTop; }
  123. }
  124. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapBottom"]/*'/>
  125. protected virtual int ToolWindowImageGapBottom
  126. {
  127. get { return _ToolWindowImageGapBottom; }
  128. }
  129. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapLeft"]/*'/>
  130. protected virtual int ToolWindowImageGapLeft
  131. {
  132. get { return _ToolWindowImageGapLeft; }
  133. }
  134. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowImageGapRight"]/*'/>
  135. protected virtual int ToolWindowImageGapRight
  136. {
  137. get { return _ToolWindowImageGapRight; }
  138. }
  139. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowTextGapRight"]/*'/>
  140. protected virtual int ToolWindowTextGapRight
  141. {
  142. get { return _ToolWindowTextGapRight; }
  143. }
  144. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowSeperatorGaptop"]/*'/>
  145. protected virtual int ToolWindowTabSeperatorGapTop
  146. {
  147. get { return _ToolWindowTabSeperatorGapTop; }
  148. }
  149. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowSeperatorGapBottom"]/*'/>
  150. protected virtual int ToolWindowTabSeperatorGapBottom
  151. {
  152. get { return _ToolWindowTabSeperatorGapBottom; }
  153. }
  154. private static Image _imageCloseEnabled = null;
  155. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageCloseEnabled"]/*'/>
  156. protected virtual Image ImageCloseEnabled
  157. {
  158. get
  159. {
  160. if (_imageCloseEnabled == null)
  161. _imageCloseEnabled = Resources.DockPaneStrip_CloseEnabled;
  162. return _imageCloseEnabled;
  163. }
  164. }
  165. private static Image _imageCloseDisabled = null;
  166. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageCloseDisabled"]/*'/>
  167. protected virtual Image ImageCloseDisabled
  168. {
  169. get
  170. {
  171. if (_imageCloseDisabled == null)
  172. _imageCloseDisabled = Resources.DockPaneStrip_CloseDisabled;
  173. return _imageCloseDisabled;
  174. }
  175. }
  176. private static Image _imageScrollLeftEnabled = null;
  177. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollLeftEnabled"]/*'/>
  178. protected virtual Image ImageScrollLeftEnabled
  179. {
  180. get
  181. {
  182. if (_imageScrollLeftEnabled == null)
  183. _imageScrollLeftEnabled = Resources.DockPaneStrip_ScrollLeftEnabled;
  184. return _imageScrollLeftEnabled;
  185. }
  186. }
  187. private static Image _imageScrollLeftDisabled = null;
  188. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollLeftDisabled"]/*'/>
  189. protected virtual Image ImageScrollLeftDisabled
  190. {
  191. get
  192. {
  193. if (_imageScrollLeftDisabled == null)
  194. _imageScrollLeftDisabled = Resources.DockPaneStrip_ScrollLeftDisabled;
  195. return _imageScrollLeftDisabled;
  196. }
  197. }
  198. private static Image _imageScrollRightEnabled = null;
  199. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollRightEnabled"]/*'/>
  200. protected virtual Image ImageScrollRightEnabled
  201. {
  202. get
  203. {
  204. if (_imageScrollRightEnabled == null)
  205. _imageScrollRightEnabled = Resources.DockPaneStrip_ScrollRightEnabled;
  206. return _imageScrollRightEnabled;
  207. }
  208. }
  209. private static Image _imageScrollRightDisabled = null;
  210. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ImageScrollRightDisabled"]/*'/>
  211. protected virtual Image ImageScrollRightDisabled
  212. {
  213. get
  214. {
  215. if (_imageScrollRightDisabled == null)
  216. _imageScrollRightDisabled = Resources.DockPaneStrip_ScrollRightDisabled;
  217. return _imageScrollRightDisabled;
  218. }
  219. }
  220. private static string _toolTipClose = null;
  221. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipClose"]/*'/>
  222. protected virtual string ToolTipClose
  223. {
  224. get
  225. {
  226. if (_toolTipClose == null)
  227. _toolTipClose = Strings.DockPaneStrip_ToolTipClose;
  228. return _toolTipClose;
  229. }
  230. }
  231. private static string _toolTipScrollLeft = null;
  232. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipScrollLeft"]/*'/>
  233. protected virtual string ToolTipScrollLeft
  234. {
  235. get
  236. {
  237. if (_toolTipScrollLeft == null)
  238. _toolTipScrollLeft = Strings.DockPaneStrip_ToolTipScrollLeft;
  239. return _toolTipScrollLeft;
  240. }
  241. }
  242. private static string _toolTipScrollRight = null;
  243. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolTipScrollRight"]/*'/>
  244. protected virtual string ToolTipScrollRight
  245. {
  246. get
  247. {
  248. if (_toolTipScrollRight == null)
  249. _toolTipScrollRight = Strings.DockPaneStrip_ToolTipScrollRight;
  250. return _toolTipScrollRight;
  251. }
  252. }
  253.         private static TextFormatFlags _toolWindowTextFormat =
  254.             TextFormatFlags.EndEllipsis |
  255.             TextFormatFlags.HorizontalCenter |
  256.             TextFormatFlags.SingleLine |
  257.             TextFormatFlags.VerticalCenter;
  258. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ToolWindowTextStringFormat"]/*'/>
  259. protected virtual TextFormatFlags ToolWindowTextFormat
  260. {
  261. get { return _toolWindowTextFormat; }
  262. }
  263.         private static TextFormatFlags _documentTextFormat =
  264.             TextFormatFlags.PathEllipsis |
  265.             TextFormatFlags.SingleLine |
  266.             TextFormatFlags.VerticalCenter;
  267. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTextStringFormat"]/*'/>
  268. public static TextFormatFlags DocumentTextFormat
  269. {
  270.          get { return _documentTextFormat; }
  271. }
  272. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabMaxWidth"]/*'/>
  273. protected virtual int DocumentTabMaxWidth
  274. {
  275. get { return _DocumentTabMaxWidth; }
  276. }
  277. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapTop"]/*'/>
  278. protected virtual int DocumentButtonGapTop
  279. {
  280. get { return _DocumentButtonGapTop; }
  281. }
  282. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapBottom"]/*'/>
  283. protected virtual int DocumentButtonGapBottom
  284. {
  285. get { return _DocumentButtonGapBottom; }
  286. }
  287. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapBetween"]/*'/>
  288. protected virtual int DocumentButtonGapBetween
  289. {
  290. get { return _DocumentButtonGapBetween; }
  291. }
  292. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentButtonGapRight"]/*'/>
  293. protected virtual int DocumentButtonGapRight
  294. {
  295. get { return _DocumentButtonGapRight; }
  296. }
  297. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapTop"]/*'/>
  298. protected virtual int DocumentTabGapTop
  299. {
  300. get { return _DocumentTabGapTop; }
  301. }
  302. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapLeft"]/*'/>
  303. protected virtual int DocumentTabGapLeft
  304. {
  305. get { return _DocumentTabGapLeft; }
  306. }
  307. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentTabGapRight"]/*'/>
  308. protected virtual int DocumentTabGapRight
  309. {
  310. get { return _DocumentTabGapRight; }
  311. }
  312. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconGapLeft"]/*'/>
  313. protected virtual int DocumentIconGapLeft
  314. {
  315. get { return _DocumentIconGapLeft; }
  316. }
  317. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconWidth"]/*'/>
  318. protected virtual int DocumentIconWidth
  319. {
  320. get { return _DocumentIconWidth; }
  321. }
  322. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="DocumentIconHeight"]/*'/>
  323. protected virtual int DocumentIconHeight
  324. {
  325. get { return _DocumentIconHeight; }
  326. }
  327. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="OutlineInnerPen"]/*'/>
  328. protected virtual Pen OutlineInnerPen
  329. {
  330. get { return SystemPens.ControlText; }
  331. }
  332. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="OutlineOuterPen"]/*'/>
  333. protected virtual Pen OutlineOuterPen
  334. {
  335. get { return SystemPens.ActiveCaptionText; }
  336. }
  337. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ActiveBackBrush"]/*'/>
  338. protected virtual Brush ActiveBackBrush
  339. {
  340. get { return SystemBrushes.Control; }
  341. }
  342. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="ActiveTextBrush"]/*'/>
  343. protected virtual Color ActiveTextColor
  344. {
  345. get { return SystemColors.ControlText; }
  346. }
  347. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="TabSeperatorPen"]/*'/>
  348. protected virtual Pen TabSeperatorPen
  349. {
  350. get { return SystemPens.GrayText; }
  351. }
  352. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Property[@name="InactiveTextBrush"]/*'/>
  353. protected virtual Color InactiveTextColor
  354. {
  355. get { return SystemColors.ControlDarkDark; }
  356. }
  357. #endregion
  358. public VS2003DockPaneStrip(DockPane pane) : base(pane)
  359. {
  360. SetStyle(ControlStyles.ResizeRedraw, true);
  361. SetStyle(ControlStyles.UserPaint, true);
  362. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  363. SuspendLayout();
  364. Font = SystemInformation.MenuFont;
  365. BackColor = Color.WhiteSmoke;
  366. m_components = new Container();
  367. m_toolTip = new ToolTip(Components);
  368. m_buttonClose = new InertButton(ImageCloseEnabled, ImageCloseDisabled);
  369. m_buttonScrollLeft = new InertButton(ImageScrollLeftEnabled, ImageScrollLeftDisabled);
  370. m_buttonScrollRight = new InertButton(ImageScrollRightEnabled, ImageScrollRightDisabled);
  371. m_buttonClose.ToolTipText = ToolTipClose;
  372. m_buttonClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
  373. m_buttonClose.Click += new EventHandler(Close_Click);
  374. m_buttonScrollLeft.Enabled = false;
  375. m_buttonScrollLeft.RepeatClick = true;
  376. m_buttonScrollLeft.ToolTipText = ToolTipScrollLeft;
  377. m_buttonScrollLeft.Anchor = AnchorStyles.Top | AnchorStyles.Right;
  378. m_buttonScrollLeft.Click += new EventHandler(ScrollLeft_Click);
  379. m_buttonScrollRight.Enabled = false;
  380. m_buttonScrollRight.RepeatClick = true;
  381. m_buttonScrollRight.ToolTipText = ToolTipScrollRight;
  382. m_buttonScrollRight.Anchor = AnchorStyles.Top | AnchorStyles.Right;
  383. m_buttonScrollRight.Click += new EventHandler(ScrollRight_Click);
  384. Controls.AddRange(new Control[] { m_buttonClose,
  385. m_buttonScrollLeft,
  386. m_buttonScrollRight });
  387. ResumeLayout();
  388. }
  389. protected override void Dispose(bool disposing)
  390. {
  391. if (disposing)
  392. {
  393. Components.Dispose();
  394. }
  395. base.Dispose (disposing);
  396. }
  397. protected override int MeasureHeight()
  398. {
  399. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  400. return MeasureHeight_ToolWindow();
  401. else
  402. return MeasureHeight_Document();
  403. }
  404. private int MeasureHeight_ToolWindow()
  405. {
  406. if (DockPane.IsAutoHide || Tabs.Count <= 1)
  407. return 0;
  408. int height = Math.Max(Font.Height, ToolWindowImageHeight)
  409. + ToolWindowImageGapTop + ToolWindowImageGapBottom;
  410. return height;
  411. }
  412. private int MeasureHeight_Document()
  413. {
  414. int height = Math.Max(Font.Height + DocumentTabGapTop,
  415. ImageCloseEnabled.Height + DocumentButtonGapTop + DocumentButtonGapBottom);
  416. return height;
  417. }
  418. protected override void OnPaint(PaintEventArgs e)
  419. {
  420. base.OnPaint (e);
  421. CalculateTabs();
  422. DrawTabStrip(e.Graphics);
  423. }
  424. protected override void OnRefreshChanges()
  425. {
  426. CalculateTabs();
  427. SetInertButtons();
  428. Invalidate();
  429. }
  430. protected override GraphicsPath GetOutline(int index)
  431. {
  432. Point[] pts = new Point[8];
  433. if (Appearance == DockPane.AppearanceStyle.Document)
  434. {
  435. Rectangle rectTab = GetTabRectangle(index);
  436. rectTab.Intersect(TabsRectangle);
  437. int y = DockPane.PointToClient(PointToScreen(new Point(0, rectTab.Bottom))).Y;
  438. Rectangle rectPaneClient = DockPane.ClientRectangle;
  439. pts[0] = DockPane.PointToScreen(new Point(rectPaneClient.Left, y));
  440. pts[1] = PointToScreen(new Point(rectTab.Left, rectTab.Bottom));
  441. pts[2] = PointToScreen(new Point(rectTab.Left, rectTab.Top));
  442. pts[3] = PointToScreen(new Point(rectTab.Right, rectTab.Top));
  443. pts[4] = PointToScreen(new Point(rectTab.Right, rectTab.Bottom));
  444. pts[5] = DockPane.PointToScreen(new Point(rectPaneClient.Right, y));
  445. pts[6] = DockPane.PointToScreen(new Point(rectPaneClient.Right, rectPaneClient.Bottom));
  446. pts[7] = DockPane.PointToScreen(new Point(rectPaneClient.Left, rectPaneClient.Bottom));
  447. }
  448. else
  449. {
  450. Rectangle rectTab = GetTabRectangle(index);
  451. rectTab.Intersect(TabsRectangle);
  452. int y = DockPane.PointToClient(PointToScreen(new Point(0, rectTab.Top))).Y;
  453. Rectangle rectPaneClient = DockPane.ClientRectangle;
  454. pts[0] = DockPane.PointToScreen(new Point(rectPaneClient.Left, rectPaneClient.Top));
  455. pts[1] = DockPane.PointToScreen(new Point(rectPaneClient.Right, rectPaneClient.Top));
  456. pts[2] = DockPane.PointToScreen(new Point(rectPaneClient.Right, y));
  457. pts[3] = PointToScreen(new Point(rectTab.Right, rectTab.Top));
  458. pts[4] = PointToScreen(new Point(rectTab.Right, rectTab.Bottom));
  459. pts[5] = PointToScreen(new Point(rectTab.Left, rectTab.Bottom));
  460. pts[6] = PointToScreen(new Point(rectTab.Left, rectTab.Top));
  461. pts[7] = DockPane.PointToScreen(new Point(rectPaneClient.Left, y));
  462. }
  463. GraphicsPath path = new GraphicsPath();
  464. path.AddLines(pts);
  465. return path;
  466. }
  467. private void CalculateTabs()
  468. {
  469. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  470. CalculateTabs_ToolWindow();
  471. else
  472. CalculateTabs_Document();
  473. }
  474. private void CalculateTabs_ToolWindow()
  475. {
  476. if (Tabs.Count <= 1 || DockPane.IsAutoHide)
  477. return;
  478. Rectangle rectTabStrip = ClientRectangle;
  479. // Calculate tab widths
  480. int countTabs = Tabs.Count;
  481. foreach (TabVS2003 tab in Tabs)
  482. {
  483. tab.MaxWidth = GetTabOriginalWidth(Tabs.IndexOf(tab));
  484. tab.Flag = false;
  485. }
  486. // Set tab whose max width less than average width
  487. bool anyWidthWithinAverage = true;
  488. int totalWidth = rectTabStrip.Width - ToolWindowStripGapLeft - ToolWindowStripGapRight;
  489. int totalAllocatedWidth = 0;
  490. int averageWidth = totalWidth / countTabs;
  491. int remainedTabs = countTabs;
  492. for (anyWidthWithinAverage=true; anyWidthWithinAverage && remainedTabs>0;)
  493. {
  494. anyWidthWithinAverage = false;
  495. foreach (TabVS2003 tab in Tabs)
  496. {
  497. if (tab.Flag)
  498. continue;
  499. if (tab.MaxWidth <= averageWidth)
  500. {
  501. tab.Flag = true;
  502. tab.TabWidth = tab.MaxWidth;
  503. totalAllocatedWidth += tab.TabWidth;
  504. anyWidthWithinAverage = true;
  505. remainedTabs--;
  506. }
  507. }
  508. if (remainedTabs != 0)
  509. averageWidth = (totalWidth - totalAllocatedWidth) / remainedTabs;
  510. }
  511. // If any tab width not set yet, set it to the average width
  512. if (remainedTabs > 0)
  513. {
  514. int roundUpWidth = (totalWidth - totalAllocatedWidth) - (averageWidth * remainedTabs);
  515. foreach (TabVS2003 tab in Tabs)
  516. {
  517. if (tab.Flag)
  518. continue;
  519. tab.Flag = true;
  520. if (roundUpWidth > 0)
  521. {
  522. tab.TabWidth = averageWidth + 1;
  523. roundUpWidth --;
  524. }
  525. else
  526. tab.TabWidth = averageWidth;
  527. }
  528. }
  529. // Set the X position of the tabs
  530. int x = rectTabStrip.X + ToolWindowStripGapLeft;
  531. foreach (TabVS2003 tab in Tabs)
  532. {
  533. tab.TabX = x;
  534. x += tab.TabWidth;
  535. }
  536. }
  537. private void CalculateTabs_Document()
  538. {
  539. Rectangle rectTabStrip = TabsRectangle;
  540. int totalWidth = 0;
  541. foreach (TabVS2003 tab in Tabs)
  542. {
  543. tab.TabWidth = Math.Min(GetTabOriginalWidth(Tabs.IndexOf(tab)), DocumentTabMaxWidth);
  544. totalWidth += tab.TabWidth;
  545. }
  546. if (totalWidth + OffsetX < rectTabStrip.Width && OffsetX < 0)
  547. OffsetX = Math.Min(0, rectTabStrip.Width - totalWidth);
  548. int x = rectTabStrip.X + OffsetX;
  549. foreach (TabVS2003 tab in Tabs)
  550. {
  551. tab.TabX = x;
  552. x += tab.TabWidth;
  553. }
  554. }
  555. protected override void EnsureTabVisible(IDockContent content)
  556. {
  557. if (Appearance != DockPane.AppearanceStyle.Document || !Tabs.Contains(content))
  558. return;
  559. Rectangle rectTabStrip = TabsRectangle;
  560. Rectangle rectTab = GetTabRectangle(Tabs.IndexOf(content));
  561. if (rectTab.Right > rectTabStrip.Right)
  562. {
  563. OffsetX -= rectTab.Right - rectTabStrip.Right;
  564. rectTab.X -= rectTab.Right - rectTabStrip.Right;
  565. }
  566. if (rectTab.Left < rectTabStrip.Left)
  567. OffsetX += rectTabStrip.Left - rectTab.Left;
  568. OnRefreshChanges();
  569. }
  570. private int GetTabOriginalWidth(int index)
  571. {
  572. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  573. return GetTabOriginalWidth_ToolWindow(index);
  574. else
  575. return GetTabOriginalWidth_Document(index);
  576. }
  577. private int GetTabOriginalWidth_ToolWindow(int index)
  578. {
  579. IDockContent content = Tabs[index].Content;
  580. using (Graphics g = CreateGraphics())
  581. {
  582. Size sizeString = TextRenderer.MeasureText(g, content.DockHandler.TabText, Font);
  583. return ToolWindowImageWidth + sizeString.Width + ToolWindowImageGapLeft
  584. + ToolWindowImageGapRight + ToolWindowTextGapRight;
  585. }
  586. }
  587. private int GetTabOriginalWidth_Document(int index)
  588. {
  589. IDockContent content = Tabs[index].Content;
  590.             int height = GetTabRectangle_Document(index).Height;
  591. using (Graphics g = CreateGraphics())
  592. {
  593. Size sizeText;
  594. if (content == DockPane.ActiveContent && DockPane.IsActiveDocumentPane)
  595. {
  596. using (Font boldFont = new Font(this.Font, FontStyle.Bold))
  597. {
  598. sizeText = TextRenderer.MeasureText(g, content.DockHandler.TabText, boldFont, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
  599. }
  600. }
  601. else
  602. sizeText = TextRenderer.MeasureText(content.DockHandler.TabText, Font, new Size(DocumentTabMaxWidth, height), DocumentTextFormat);
  603. if (DockPane.DockPanel.ShowDocumentIcon)
  604. return sizeText.Width + DocumentIconWidth + DocumentIconGapLeft;
  605. else
  606. return sizeText.Width;
  607. }
  608. }
  609. private void DrawTabStrip(Graphics g)
  610. {
  611. OnBeginDrawTabStrip();
  612. if (Appearance == DockPane.AppearanceStyle.Document)
  613. DrawTabStrip_Document(g);
  614. else
  615. DrawTabStrip_ToolWindow(g);
  616. OnEndDrawTabStrip();
  617. }
  618. private void DrawTabStrip_Document(Graphics g)
  619. {
  620. int count = Tabs.Count;
  621. if (count == 0)
  622. return;
  623. Rectangle rectTabStrip = ClientRectangle;
  624. g.DrawLine(OutlineOuterPen, rectTabStrip.Left, rectTabStrip.Bottom - 1,
  625. rectTabStrip.Right, rectTabStrip.Bottom - 1);
  626. // Draw the tabs
  627. Rectangle rectTabOnly = TabsRectangle;
  628. Rectangle rectTab = Rectangle.Empty;
  629. g.SetClip(rectTabOnly);
  630. for (int i=0; i<count; i++)
  631. {
  632. rectTab = GetTabRectangle(i);
  633. if (rectTab.IntersectsWith(rectTabOnly))
  634. DrawTab(g, Tabs[i] as TabVS2003, rectTab);
  635. }
  636. }
  637. private void DrawTabStrip_ToolWindow(Graphics g)
  638. {
  639. Rectangle rectTabStrip = ClientRectangle;
  640. g.DrawLine(OutlineInnerPen, rectTabStrip.Left, rectTabStrip.Top,
  641. rectTabStrip.Right, rectTabStrip.Top);
  642. for (int i=0; i<Tabs.Count; i++)
  643. DrawTab(g, Tabs[i] as TabVS2003, GetTabRectangle(i));
  644. }
  645. private Rectangle GetTabRectangle(int index)
  646. {
  647. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  648. return GetTabRectangle_ToolWindow(index);
  649. else
  650. return GetTabRectangle_Document(index);
  651. }
  652. private Rectangle GetTabRectangle_ToolWindow(int index)
  653. {
  654. Rectangle rectTabStrip = ClientRectangle;
  655. TabVS2003 tab = (TabVS2003)(Tabs[index]);
  656. return new Rectangle(tab.TabX, rectTabStrip.Y, tab.TabWidth, rectTabStrip.Height);
  657. }
  658. private Rectangle GetTabRectangle_Document(int index)
  659. {
  660. Rectangle rectTabStrip = ClientRectangle;
  661. TabVS2003 tab = (TabVS2003)Tabs[index];
  662. return new Rectangle(tab.TabX, rectTabStrip.Y + DocumentTabGapTop, tab.TabWidth, rectTabStrip.Height - DocumentTabGapTop);
  663. }
  664.         private void DrawTab(Graphics g, TabVS2003 tab, Rectangle rect)
  665. {
  666. OnBeginDrawTab(tab);
  667. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  668. DrawTab_ToolWindow(g, tab, rect);
  669. else
  670. DrawTab_Document(g, tab, rect);
  671. OnEndDrawTab(tab);
  672. }
  673. private void DrawTab_ToolWindow(Graphics g, TabVS2003 tab, Rectangle rect)
  674. {
  675. Rectangle rectIcon = new Rectangle(
  676. rect.X + ToolWindowImageGapLeft,
  677. rect.Y + rect.Height - 1 - ToolWindowImageGapBottom - ToolWindowImageHeight,
  678. ToolWindowImageWidth, ToolWindowImageHeight);
  679. Rectangle rectText = rectIcon;
  680. rectText.X += rectIcon.Width + ToolWindowImageGapRight;
  681. rectText.Width = rect.Width - rectIcon.Width - ToolWindowImageGapLeft - 
  682. ToolWindowImageGapRight - ToolWindowTextGapRight;
  683. if (DockPane.ActiveContent == tab.Content)
  684. {
  685. g.FillRectangle(ActiveBackBrush, rect);
  686. g.DrawLine(OutlineOuterPen,
  687. rect.X, rect.Y, rect.X, rect.Y + rect.Height - 1);
  688. g.DrawLine(OutlineInnerPen,
  689. rect.X, rect.Y + rect.Height - 1, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
  690. g.DrawLine(OutlineInnerPen,
  691. rect.X + rect.Width - 1, rect.Y, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
  692.                 TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, ActiveTextColor, ToolWindowTextFormat);
  693. }
  694. else
  695. {
  696. if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
  697. g.DrawLine(TabSeperatorPen,
  698. rect.X + rect.Width - 1,
  699. rect.Y + ToolWindowTabSeperatorGapTop,
  700. rect.X + rect.Width - 1,
  701. rect.Y + rect.Height - 1 - ToolWindowTabSeperatorGapBottom);
  702. TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, ToolWindowTextFormat);
  703. }
  704. if (rect.Contains(rectIcon))
  705. g.DrawIcon(tab.Content.DockHandler.Icon, rectIcon);
  706. }
  707. private void DrawTab_Document(Graphics g, TabVS2003 tab, Rectangle rect)
  708. {
  709. Rectangle rectText = rect;
  710. if (DockPane.DockPanel.ShowDocumentIcon)
  711. {
  712. rectText.X += DocumentIconWidth + DocumentIconGapLeft;
  713. rectText.Width -= DocumentIconWidth + DocumentIconGapLeft;
  714. }
  715. if (DockPane.ActiveContent == tab.Content)
  716. {
  717. g.FillRectangle(ActiveBackBrush, rect);
  718. g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X, rect.Y + rect.Height);
  719. g.DrawLine(OutlineOuterPen, rect.X, rect.Y, rect.X + rect.Width - 1, rect.Y);
  720. g.DrawLine(OutlineInnerPen,
  721. rect.X + rect.Width - 1, rect.Y,
  722. rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
  723. if (DockPane.DockPanel.ShowDocumentIcon)
  724. {
  725. Icon icon = (tab.Content as Form).Icon;
  726. Rectangle rectIcon = new Rectangle(
  727. rect.X + DocumentIconGapLeft,
  728. rect.Y + (rect.Height - DocumentIconHeight) / 2,
  729. DocumentIconWidth, DocumentIconHeight);
  730. g.DrawIcon(tab.ContentForm.Icon, rectIcon);
  731. }
  732. if (DockPane.IsActiveDocumentPane)
  733. {
  734. using (Font boldFont = new Font(this.Font, FontStyle.Bold))
  735. {
  736. TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, boldFont, rectText, ActiveTextColor, DocumentTextFormat);
  737. }
  738. }
  739. else
  740. TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, DocumentTextFormat);
  741. }
  742. else
  743. {
  744. if (Tabs.IndexOf(DockPane.ActiveContent) != Tabs.IndexOf(tab) + 1)
  745. g.DrawLine(TabSeperatorPen,
  746. rect.X + rect.Width - 1, rect.Y,
  747. rect.X + rect.Width - 1, rect.Y + rect.Height - 1 - DocumentTabGapTop);
  748. if (DockPane.DockPanel.ShowDocumentIcon)
  749. {
  750. Icon icon = tab.ContentForm.Icon;
  751. Rectangle rectIcon = new Rectangle(
  752. rect.X + DocumentIconGapLeft,
  753. rect.Y + (rect.Height - DocumentIconHeight) / 2,
  754. DocumentIconWidth, DocumentIconHeight);
  755. g.DrawIcon(tab.ContentForm.Icon, rectIcon);
  756. }
  757. TextRenderer.DrawText(g, tab.Content.DockHandler.TabText, Font, rectText, InactiveTextColor, DocumentTextFormat);
  758. }
  759. }
  760. private Rectangle TabsRectangle
  761. {
  762. get
  763. {
  764. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  765. return ClientRectangle;
  766. Rectangle rectWindow = ClientRectangle;
  767. int x = rectWindow.X;
  768. int y = rectWindow.Y;
  769. int width = rectWindow.Width;
  770. int height = rectWindow.Height;
  771. x += DocumentTabGapLeft;
  772. width -= DocumentTabGapLeft + 
  773. DocumentTabGapRight +
  774. DocumentButtonGapRight +
  775. m_buttonClose.Width +
  776. m_buttonScrollRight.Width +
  777. m_buttonScrollLeft.Width +
  778. 2 * DocumentButtonGapBetween;
  779. return new Rectangle(x, y, width, height);
  780. }
  781. }
  782. private void ScrollLeft_Click(object sender, EventArgs e)
  783. {
  784. Rectangle rectTabStrip = TabsRectangle;
  785. int index;
  786. for (index=0; index<Tabs.Count; index++)
  787. if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
  788. break;
  789. Rectangle rectTab = GetTabRectangle(index);
  790. if (rectTab.Left < rectTabStrip.Left)
  791. OffsetX += rectTabStrip.Left - rectTab.Left;
  792. else if (index == 0)
  793. OffsetX = 0;
  794. else
  795. OffsetX += rectTabStrip.Left - GetTabRectangle(index - 1).Left;
  796. OnRefreshChanges();
  797. }
  798. private void ScrollRight_Click(object sender, EventArgs e)
  799. {
  800. Rectangle rectTabStrip = TabsRectangle;
  801. int index;
  802. int count = Tabs.Count;
  803. for (index=0; index<count; index++)
  804. if (GetTabRectangle(index).IntersectsWith(rectTabStrip))
  805. break;
  806. if (index + 1 < count)
  807. {
  808. OffsetX -= GetTabRectangle(index + 1).Left - rectTabStrip.Left;
  809. CalculateTabs();
  810. }
  811. Rectangle rectLastTab = GetTabRectangle(count - 1);
  812. if (rectLastTab.Right < rectTabStrip.Right)
  813. OffsetX += rectTabStrip.Right - rectLastTab.Right;
  814. OnRefreshChanges();
  815. }
  816. private void SetInertButtons()
  817. {
  818. // Set the visibility of the inert buttons
  819. m_buttonScrollLeft.Visible = m_buttonScrollRight.Visible = m_buttonClose.Visible = (DockPane.DockState == DockState.Document);
  820. m_buttonClose.ForeColor = m_buttonScrollRight.ForeColor = m_buttonScrollLeft.ForeColor = SystemColors.ControlDarkDark;
  821. m_buttonClose.BorderColor = m_buttonScrollRight.BorderColor = m_buttonScrollLeft.BorderColor = SystemColors.ControlDarkDark;
  822. // Enable/disable scroll buttons
  823. int count = Tabs.Count;
  824. Rectangle rectTabOnly = TabsRectangle;
  825. Rectangle rectTab = (count == 0) ? Rectangle.Empty : GetTabRectangle(count - 1);
  826. m_buttonScrollLeft.Enabled = (OffsetX < 0);
  827. m_buttonScrollRight.Enabled = rectTab.Right > rectTabOnly.Right;
  828. // show/hide close button
  829. if (Appearance == DockPane.AppearanceStyle.ToolWindow)
  830. m_buttonClose.Visible = false;
  831. else
  832. {
  833. bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
  834. if (m_buttonClose.Visible != showCloseButton)
  835. {
  836. m_buttonClose.Visible = showCloseButton;
  837. PerformLayout();
  838. }
  839. }
  840. }
  841. /// <exclude/>
  842. protected override void OnLayout(LayoutEventArgs levent)
  843. {
  844. Rectangle rectTabStrip = ClientRectangle;
  845. // Set position and size of the buttons
  846. int buttonWidth = ImageCloseEnabled.Width;
  847. int buttonHeight = ImageCloseEnabled.Height;
  848. int height = rectTabStrip.Height - DocumentButtonGapTop - DocumentButtonGapBottom;
  849. if (buttonHeight < height)
  850. {
  851. buttonWidth = buttonWidth * (height / buttonHeight);
  852. buttonHeight = height;
  853. }
  854. Size buttonSize = new Size(buttonWidth, buttonHeight);
  855. m_buttonClose.Size = m_buttonScrollLeft.Size = m_buttonScrollRight.Size = buttonSize;
  856. int x = rectTabStrip.X + rectTabStrip.Width - DocumentTabGapLeft
  857. - DocumentButtonGapRight - buttonWidth;
  858. int y = rectTabStrip.Y + DocumentButtonGapTop;
  859. m_buttonClose.Location = new Point(x, y);
  860. Point point = m_buttonClose.Location;
  861. bool showCloseButton = DockPane.ActiveContent == null ? true : DockPane.ActiveContent.DockHandler.CloseButton;
  862. if (showCloseButton)
  863. point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
  864. m_buttonScrollRight.Location = point;
  865. point.Offset(-(DocumentButtonGapBetween + buttonWidth), 0);
  866. m_buttonScrollLeft.Location = point;
  867. OnRefreshChanges();
  868. base.OnLayout (levent);
  869. }
  870. private void Close_Click(object sender, EventArgs e)
  871. {
  872. DockPane.CloseActiveContent();
  873. }
  874. /// <exclude/>
  875. protected override int HitTest(Point ptMouse)
  876. {
  877. Rectangle rectTabStrip = TabsRectangle;
  878. for (int i=0; i<Tabs.Count; i++)
  879. {
  880. Rectangle rectTab = GetTabRectangle(i);
  881. rectTab.Intersect(rectTabStrip);
  882. if (rectTab.Contains(ptMouse))
  883. return i;
  884. }
  885. return -1;
  886. }
  887. /// <exclude/>
  888. protected override void OnMouseMove(MouseEventArgs e)
  889. {
  890. int index = HitTest(PointToClient(Control.MousePosition));
  891. string toolTip = string.Empty;
  892. base.OnMouseMove(e);
  893. if (index != -1)
  894. {
  895. Rectangle rectTab = GetTabRectangle(index);
  896. if (Tabs[index].Content.DockHandler.ToolTipText != null)
  897. toolTip = Tabs[index].Content.DockHandler.ToolTipText;
  898. else if (rectTab.Width < GetTabOriginalWidth(index))
  899. toolTip = Tabs[index].Content.DockHandler.TabText;
  900. }
  901. if (m_toolTip.GetToolTip(this) != toolTip)
  902. {
  903. m_toolTip.Active = false;
  904. m_toolTip.SetToolTip(this, toolTip);
  905. m_toolTip.Active = true;
  906. }
  907. }
  908. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTabStrip()"]/*'/>
  909. protected virtual void OnBeginDrawTabStrip()
  910. {
  911. }
  912. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTabStrip()"]/*'/>
  913. protected virtual void OnEndDrawTabStrip()
  914. {
  915. }
  916. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnBeginDrawTab(DockPaneTab)"]/*'/>
  917. protected virtual void OnBeginDrawTab(Tab tab)
  918. {
  919. }
  920. /// <include file='CodeDoc/DockPaneStripVS2003.xml' path='//CodeDoc/Class[@name="DockPaneStripVS2003"]/Method[@name="OnEndDrawTab(DockPaneTab)"]/*'/>
  921. protected virtual void OnEndDrawTab(Tab tab)
  922. {
  923. }
  924. }
  925. }