VS2005DockPaneStrip.cs 59 KB

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