Office2007Renderer.cs

Description du code

Office2007Renderer.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. /********************************************************************/
  2. /* Office 2007 Renderer Project */
  3. /* */
  4. /* Use the Office2007Renderer class as a custom renderer by */
  5. /* providing it to the ToolStripManager.Renderer property. Then */
  6. /* all tool strips, menu strips, status strips etc will be drawn */
  7. /* using the Office 2007 style renderer in your application. */
  8. /* */
  9. /* Author: Phil Wright */
  10. /* Website: www.componentfactory.com */
  11. /* Contact: phil.wright@componentfactory.com */
  12. /********************************************************************/
  13.  
  14. using System.Collections.Generic;
  15. using System.Drawing;
  16. using System.Drawing.Drawing2D;
  17. using System.Windows.Forms;
  18.  
  19. namespace Office2007Renderer
  20. {
  21. /// <summary>
  22. /// Draw ToolStrips using the Office 2007 themed appearance.
  23. /// </summary>
  24. public class Office2007Renderer : ToolStripProfessionalRenderer
  25. {
  26. #region GradientItemColors
  27. private class GradientItemColors
  28. {
  29. #region Public Fields
  30. public Color InsideTop1;
  31. public Color InsideTop2;
  32. public Color InsideBottom1;
  33. public Color InsideBottom2;
  34. public Color FillTop1;
  35. public Color FillTop2;
  36. public Color FillBottom1;
  37. public Color FillBottom2;
  38. public Color Border1;
  39. public Color Border2;
  40. #endregion
  41.  
  42. #region Identity
  43. public GradientItemColors(Color insideTop1, Color insideTop2,
  44. Color insideBottom1, Color insideBottom2,
  45. Color fillTop1, Color fillTop2,
  46. Color fillBottom1, Color fillBottom2,
  47. Color border1, Color border2)
  48. {
  49. InsideTop1 = insideTop1;
  50. InsideTop2 = insideTop2;
  51. InsideBottom1 = insideBottom1;
  52. InsideBottom2 = insideBottom2;
  53. FillTop1 = fillTop1;
  54. FillTop2 = fillTop2;
  55. FillBottom1 = fillBottom1;
  56. FillBottom2 = fillBottom2;
  57. Border1 = border1;
  58. Border2 = border2;
  59. }
  60. #endregion
  61. }
  62. #endregion
  63.  
  64. #region Static Metrics
  65. private static int _gripOffset = 1;
  66. private static int _gripSquare = 2;
  67. private static int _gripSize = 3;
  68. private static int _gripMove = 4;
  69. private static int _gripLines = 3;
  70. private static int _checkInset = 1;
  71. private static int _marginInset = 2;
  72. private static int _separatorInset = 31;
  73. private static float _cutToolItemMenu = 1.0f;
  74. private static float _cutContextMenu = 0f;
  75. private static float _cutMenuItemBack = 1.2f;
  76. private static float _contextCheckTickThickness = 1.6f;
  77. private static Blend _statusStripBlend;
  78. #endregion
  79.  
  80. #region Static Colors
  81. private static Color _c1 = Color.FromArgb(167, 167, 167);
  82. private static Color _c2 = Color.FromArgb(21, 66, 139);
  83. private static Color _c3 = Color.FromArgb(76, 83, 92);
  84. private static Color _c4 = Color.FromArgb(250, 250, 250);
  85. private static Color _c5 = Color.FromArgb(248, 248, 248);
  86. private static Color _c6 = Color.FromArgb(243, 243, 243);
  87. private static Color _r1 = Color.FromArgb(255, 255, 251);
  88. private static Color _r2 = Color.FromArgb(255, 249, 227);
  89. private static Color _r3 = Color.FromArgb(255, 242, 201);
  90. private static Color _r4 = Color.FromArgb(255, 248, 181);
  91. private static Color _r5 = Color.FromArgb(255, 252, 229);
  92. private static Color _r6 = Color.FromArgb(255, 235, 166);
  93. private static Color _r7 = Color.FromArgb(255, 213, 103);
  94. private static Color _r8 = Color.FromArgb(255, 228, 145);
  95. private static Color _r9 = Color.FromArgb(160, 188, 228);
  96. private static Color _rA = Color.FromArgb(121, 153, 194);
  97. private static Color _rB = Color.FromArgb(182, 190, 192);
  98. private static Color _rC = Color.FromArgb(155, 163, 167);
  99. private static Color _rD = Color.FromArgb(233, 168, 97);
  100. private static Color _rE = Color.FromArgb(247, 164, 39);
  101. private static Color _rF = Color.FromArgb(246, 156, 24);
  102. private static Color _rG = Color.FromArgb(253, 173, 17);
  103. private static Color _rH = Color.FromArgb(254, 185, 108);
  104. private static Color _rI = Color.FromArgb(253, 164, 97);
  105. private static Color _rJ = Color.FromArgb(252, 143, 61);
  106. private static Color _rK = Color.FromArgb(255, 208, 134);
  107. private static Color _rL = Color.FromArgb(249, 192, 103);
  108. private static Color _rM = Color.FromArgb(250, 195, 93);
  109. private static Color _rN = Color.FromArgb(248, 190, 81);
  110. private static Color _rO = Color.FromArgb(255, 208, 49);
  111. private static Color _rP = Color.FromArgb(254, 214, 168);
  112. private static Color _rQ = Color.FromArgb(252, 180, 100);
  113. private static Color _rR = Color.FromArgb(252, 161, 54);
  114. private static Color _rS = Color.FromArgb(254, 238, 170);
  115. private static Color _rT = Color.FromArgb(249, 202, 113);
  116. private static Color _rU = Color.FromArgb(250, 205, 103);
  117. private static Color _rV = Color.FromArgb(248, 200, 91);
  118. private static Color _rW = Color.FromArgb(255, 218, 59);
  119. private static Color _rX = Color.FromArgb(254, 185, 108);
  120. private static Color _rY = Color.FromArgb(252, 161, 54);
  121. private static Color _rZ = Color.FromArgb(254, 238, 170);
  122.  
  123. // Color scheme values
  124. private static Color _textDisabled = _c1;
  125. private static Color _textMenuStripItem = _c2;
  126. private static Color _textStatusStripItem = _c2;
  127. private static Color _textContextMenuItem = _c2;
  128. private static Color _arrowDisabled = _c1;
  129. private static Color _arrowLight = Color.FromArgb(106, 126, 197);
  130. private static Color _arrowDark = Color.FromArgb(64, 70, 90);
  131. private static Color _separatorMenuLight = Color.FromArgb(245, 245, 245);
  132. private static Color _separatorMenuDark = Color.FromArgb(197, 197, 197);
  133. private static Color _contextMenuBack = _c4;
  134. private static Color _contextCheckBorder = Color.FromArgb(242, 149, 54);
  135. private static Color _contextCheckTick = Color.FromArgb(66, 75, 138);
  136. private static Color _statusStripBorderDark = Color.FromArgb(86, 125, 176);
  137. private static Color _statusStripBorderLight = Color.White;
  138. private static Color _gripDark = Color.FromArgb(114, 152, 204);
  139. private static Color _gripLight = _c5;
  140. private static GradientItemColors _itemContextItemEnabledColors = new GradientItemColors(_r1, _r2, _r3, _r4, _r5, _r6, _r7, _r8, Color.FromArgb(217, 203, 150), Color.FromArgb(192, 167, 118));
  141. private static GradientItemColors _itemDisabledColors = new GradientItemColors(_c4, _c6, Color.FromArgb(236, 236, 236), Color.FromArgb(230, 230, 230), _c6, Color.FromArgb(224, 224, 224), Color.FromArgb(200, 200, 200), Color.FromArgb(210, 210, 210), Color.FromArgb(212, 212, 212), Color.FromArgb(195, 195, 195));
  142. private static GradientItemColors _itemToolItemSelectedColors = new GradientItemColors(_r1, _r2, _r3, _r4, _r5, _r6, _r7, _r8, _r9, _rA);
  143. private static GradientItemColors _itemToolItemPressedColors = new GradientItemColors(_rD, _rE, _rF, _rG, _rH, _rI, _rJ, _rK, _r9, _rA);
  144. private static GradientItemColors _itemToolItemCheckedColors = new GradientItemColors(_rL, _rM, _rN, _rO, _rP, _rQ, _rR, _rS, _r9, _rA);
  145. private static GradientItemColors _itemToolItemCheckPressColors = new GradientItemColors(_rT, _rU, _rV, _rW, _rX, _rI, _rY, _rZ, _r9, _rA);
  146. #endregion
  147.  
  148. #region Identity
  149. static Office2007Renderer()
  150. {
  151. // One time creation of the blend for the status strip gradient brush
  152. _statusStripBlend = new Blend();
  153. _statusStripBlend.Positions = new float[] { 0.0f, 0.25f, 0.25f, 0.57f, 0.86f, 1.0f };
  154. _statusStripBlend.Factors = new float[] { 0.1f, 0.6f, 1.0f, 0.4f, 0.0f, 0.95f };
  155. }
  156.  
  157. /// <summary>
  158. /// Initialize a new instance of the Office2007Renderer class.
  159. /// </summary>
  160. public Office2007Renderer()
  161. : base(new Office2007ColorTable())
  162. {
  163. }
  164. #endregion
  165.  
  166. #region OnRenderArrow
  167. /// <summary>
  168. /// Raises the RenderArrow event.
  169. /// </summary>
  170. /// <param name="e">An ToolStripArrowRenderEventArgs containing the event data.</param>
  171. protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
  172. {
  173. // Cannot paint a zero sized area
  174. if ((e.ArrowRectangle.Width > 0) &&
  175. (e.ArrowRectangle.Height > 0))
  176. {
  177. // Create a path that is used to fill the arrow
  178. using (GraphicsPath arrowPath = CreateArrowPath(e.Item,
  179. e.ArrowRectangle,
  180. e.Direction))
  181. {
  182. // Get the rectangle that encloses the arrow and expand slightly
  183. // so that the gradient is always within the expanding bounds
  184. RectangleF boundsF = arrowPath.GetBounds();
  185. boundsF.Inflate(1f, 1f);
  186.  
  187. Color color1 = (e.Item.Enabled ? _arrowLight : _arrowDisabled);
  188. Color color2 = (e.Item.Enabled ? _arrowDark : _arrowDisabled);
  189.  
  190. float angle = 0;
  191.  
  192. // Use gradient angle to match the arrow direction
  193. switch (e.Direction)
  194. {
  195. case ArrowDirection.Right:
  196. angle = 0;
  197. break;
  198. case ArrowDirection.Left:
  199. angle = 180f;
  200. break;
  201. case ArrowDirection.Down:
  202. angle = 90f;
  203. break;
  204. case ArrowDirection.Up:
  205. angle = 270f;
  206. break;
  207. }
  208.  
  209. // Draw the actual arrow using a gradient
  210. using (LinearGradientBrush arrowBrush = new LinearGradientBrush(boundsF, color1, color2, angle))
  211. e.Graphics.FillPath(arrowBrush, arrowPath);
  212. }
  213. }
  214. }
  215. #endregion
  216.  
  217. #region OnRenderButtonBackground
  218. /// <summary>
  219. /// Raises the RenderButtonBackground event.
  220. /// </summary>
  221. /// <param name="e">An ToolStripItemRenderEventArgs containing the event data.</param>
  222. protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
  223. {
  224. // Cast to correct type
  225. ToolStripButton button = (ToolStripButton)e.Item;
  226.  
  227. if (button.Selected || button.Pressed || button.Checked)
  228. RenderToolButtonBackground(e.Graphics, button, e.ToolStrip);
  229. }
  230. #endregion
  231.  
  232. #region OnRenderDropDownButtonBackground
  233. /// <summary>
  234. /// Raises the RenderDropDownButtonBackground event.
  235. /// </summary>
  236. /// <param name="e">An ToolStripItemRenderEventArgs containing the event data.</param>
  237. protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
  238. {
  239. if (e.Item.Selected || e.Item.Pressed)
  240. RenderToolDropButtonBackground(e.Graphics, e.Item, e.ToolStrip);
  241. }
  242. #endregion
  243.  
  244. #region OnRenderItemCheck
  245. /// <summary>
  246. /// Raises the RenderItemCheck event.
  247. /// </summary>
  248. /// <param name="e">An ToolStripItemImageRenderEventArgs containing the event data.</param>
  249. protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
  250. {
  251. // Staring size of the checkbox is the image rectangle
  252. Rectangle checkBox = e.ImageRectangle;
  253.  
  254. // Make the border of the check box 1 pixel bigger on all sides, as a minimum
  255. checkBox.Inflate(1, 1);
  256.  
  257. // Can we extend upwards?
  258. if (checkBox.Top > _checkInset)
  259. {
  260. int diff = checkBox.Top - _checkInset;
  261. checkBox.Y -= diff;
  262. checkBox.Height += diff;
  263. }
  264.  
  265. // Can we extend downwards?
  266. if (checkBox.Height <= (e.Item.Bounds.Height - (_checkInset * 2)))
  267. {
  268. int diff = e.Item.Bounds.Height - (_checkInset * 2) - checkBox.Height;
  269. checkBox.Height += diff;
  270. }
  271.  
  272. // Drawing with anti aliasing to create smoother appearance
  273. using (UseAntiAlias uaa = new UseAntiAlias(e.Graphics))
  274. {
  275. // Create border path for the check box
  276. using (GraphicsPath borderPath = CreateBorderPath(checkBox, _cutMenuItemBack))
  277. {
  278. // Fill the background in a solid color
  279. using (SolidBrush fillBrush = new SolidBrush(ColorTable.CheckBackground))
  280. e.Graphics.FillPath(fillBrush, borderPath);
  281.  
  282. // Draw the border around the check box
  283. using (Pen borderPen = new Pen(_contextCheckBorder))
  284. e.Graphics.DrawPath(borderPen, borderPath);
  285.  
  286. // If there is not an image, then we can draw the tick, square etc...
  287. if (e.Image != null)
  288. {
  289. CheckState checkState = CheckState.Unchecked;
  290.  
  291. // Extract the check state from the item
  292. if (e.Item is ToolStripMenuItem)
  293. {
  294. ToolStripMenuItem item = (ToolStripMenuItem)e.Item;
  295. checkState = item.CheckState;
  296. }
  297.  
  298. // Decide what graphic to draw
  299. switch (checkState)
  300. {
  301. case CheckState.Checked:
  302. // Create a path for the tick
  303. using (GraphicsPath tickPath = CreateTickPath(checkBox))
  304. {
  305. // Draw the tick with a thickish brush
  306. using (Pen tickPen = new Pen(_contextCheckTick,_contextCheckTickThickness))
  307. e.Graphics.DrawPath(tickPen, tickPath);
  308. }
  309. break;
  310. case CheckState.Indeterminate:
  311. // Create a path for the indeterminate diamond
  312. using (GraphicsPath tickPath = CreateIndeterminatePath(checkBox))
  313. {
  314. // Draw the tick with a thickish brush
  315. using (SolidBrush tickBrush = new SolidBrush(_contextCheckTick))
  316. e.Graphics.FillPath(tickBrush, tickPath);
  317. }
  318. break;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. #endregion
  325.  
  326. #region OnRenderItemText
  327. /// <summary>
  328. /// Raises the RenderItemText event.
  329. /// </summary>
  330. /// <param name="e">An ToolStripItemTextRenderEventArgs containing the event data.</param>
  331. protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
  332. {
  333. if ((e.ToolStrip is MenuStrip) ||
  334. (e.ToolStrip is ToolStrip) ||
  335. (e.ToolStrip is ContextMenuStrip) ||
  336. (e.ToolStrip is ToolStripDropDownMenu))
  337. {
  338. // We set the color depending on the enabled state
  339. if (!e.Item.Enabled)
  340. e.TextColor = _textDisabled;
  341. else
  342. {
  343. if ((e.ToolStrip is MenuStrip) && !e.Item.Pressed && !e.Item.Selected)
  344. e.TextColor = _textMenuStripItem;
  345. else if ((e.ToolStrip is StatusStrip) && !e.Item.Pressed && !e.Item.Selected)
  346. e.TextColor = _textStatusStripItem;
  347. else
  348. e.TextColor = _textContextMenuItem;
  349. }
  350.  
  351. // All text is draw using the ClearTypeGridFit text rendering hint
  352. using (UseClearTypeGridFit clearTypeGridFit = new UseClearTypeGridFit(e.Graphics))
  353. base.OnRenderItemText(e);
  354. }
  355. else
  356. {
  357. base.OnRenderItemText(e);
  358. }
  359. }
  360. #endregion
  361.  
  362. #region OnRenderItemImage
  363. /// <summary>
  364. /// Raises the RenderItemImage event.
  365. /// </summary>
  366. /// <param name="e">An ToolStripItemImageRenderEventArgs containing the event data.</param>
  367. protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
  368. {
  369. // We only override the image drawing for context menus
  370. if ((e.ToolStrip is ContextMenuStrip) ||
  371. (e.ToolStrip is ToolStripDropDownMenu))
  372. {
  373. if (e.Image != null)
  374. {
  375. if (e.Item.Enabled)
  376. e.Graphics.DrawImage(e.Image, e.ImageRectangle);
  377. else
  378. ControlPaint.DrawImageDisabled(e.Graphics, e.Image,
  379. e.ImageRectangle.X,
  380. e.ImageRectangle.Y,
  381. Color.Transparent);
  382. }
  383. }
  384. else
  385. {
  386. base.OnRenderItemImage(e);
  387. }
  388. }
  389. #endregion
  390.  
  391. #region OnRenderMenuItemBackground
  392. /// <summary>
  393. /// Raises the RenderMenuItemBackground event.
  394. /// </summary>
  395. /// <param name="e">An ToolStripItemRenderEventArgs containing the event data.</param>
  396. protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
  397. {
  398. if ((e.ToolStrip is MenuStrip) ||
  399. (e.ToolStrip is ContextMenuStrip) ||
  400. (e.ToolStrip is ToolStripDropDownMenu))
  401. {
  402. if ((e.Item.Pressed) && (e.ToolStrip is MenuStrip))
  403. {
  404. // Draw the menu/tool strip as a header for a context menu item
  405. DrawContextMenuHeader(e.Graphics, e.Item);
  406. }
  407. else
  408. {
  409. // We only draw a background if the item is selected and enabled
  410. if (e.Item.Selected)
  411. {
  412. if (e.Item.Enabled)
  413. {
  414. // Do we draw as a menu strip or context menu item?
  415. if (e.ToolStrip is MenuStrip)
  416. DrawGradientToolItem(e.Graphics, e.Item, _itemToolItemSelectedColors);
  417. else
  418. DrawGradientContextMenuItem(e.Graphics, e.Item, _itemContextItemEnabledColors);
  419. }
  420. else
  421. {
  422. // Get the mouse position in tool strip coordinates
  423. Point mousePos = e.ToolStrip.PointToClient(Control.MousePosition);
  424.  
  425. // If the mouse is not in the item area, then draw disabled
  426. if (!e.Item.Bounds.Contains(mousePos))
  427. {
  428. // Do we draw as a menu strip or context menu item?
  429. if (e.ToolStrip is MenuStrip)
  430. DrawGradientToolItem(e.Graphics, e.Item, _itemDisabledColors);
  431. else
  432. DrawGradientContextMenuItem(e.Graphics, e.Item, _itemDisabledColors);
  433. }
  434. }
  435. }
  436. }
  437. }
  438. else
  439. {
  440. base.OnRenderMenuItemBackground(e);
  441. }
  442. }
  443. #endregion
  444.  
  445. #region OnRenderSplitButtonBackground
  446. /// <summary>
  447. /// Raises the RenderSplitButtonBackground event.
  448. /// </summary>
  449. /// <param name="e">An ToolStripItemRenderEventArgs containing the event data.</param>
  450. protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
  451. {
  452. if (e.Item.Selected || e.Item.Pressed)
  453. {
  454. // Cast to correct type
  455. ToolStripSplitButton splitButton = (ToolStripSplitButton)e.Item;
  456.  
  457. // Draw the border and background
  458. RenderToolSplitButtonBackground(e.Graphics, splitButton, e.ToolStrip);
  459.  
  460. // Get the rectangle that needs to show the arrow
  461. Rectangle arrowBounds = splitButton.DropDownButtonBounds;
  462.  
  463. // Draw the arrow on top of the background
  464. OnRenderArrow(new ToolStripArrowRenderEventArgs(e.Graphics,
  465. splitButton,
  466. arrowBounds,
  467. SystemColors.ControlText,
  468. ArrowDirection.Down));
  469. }
  470. else
  471. {
  472. base.OnRenderSplitButtonBackground(e);
  473. }
  474. }
  475. #endregion
  476.  
  477. #region OnRenderStatusStripSizingGrip
  478. /// <summary>
  479. /// Raises the RenderStatusStripSizingGrip event.
  480. /// </summary>
  481. /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
  482. protected override void OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e)
  483. {
  484. using(SolidBrush darkBrush = new SolidBrush(_gripDark),
  485. lightBrush = new SolidBrush(_gripLight))
  486. {
  487. // Do we need to invert the drawing edge?
  488. bool rtl = (e.ToolStrip.RightToLeft == RightToLeft.Yes);
  489.  
  490. // Find vertical position of the lowest grip line
  491. int y = e.AffectedBounds.Bottom - _gripSize * 2 + 1;
  492.  
  493. // Draw three lines of grips
  494. for (int i = _gripLines; i >= 1; i--)
  495. {
  496. // Find the rightmost grip position on the line
  497. int x = (rtl ? e.AffectedBounds.Left + 1 :
  498. e.AffectedBounds.Right - _gripSize * 2 + 1);
  499.  
  500. // Draw grips from right to left on line
  501. for (int j = 0; j < i; j++)
  502. {
  503. // Just the single grip glyph
  504. DrawGripGlyph(e.Graphics, x, y, darkBrush, lightBrush);
  505.  
  506. // Move left to next grip position
  507. x -= (rtl ? -_gripMove : _gripMove);
  508. }
  509.  
  510. // Move upwards to next grip line
  511. y -= _gripMove;
  512. }
  513. }
  514. }
  515. #endregion
  516.  
  517. #region OnRenderToolStripContentPanelBackground
  518. /// <summary>
  519. /// Raises the RenderToolStripContentPanelBackground event.
  520. /// </summary>
  521. /// <param name="e">An ToolStripContentPanelRenderEventArgs containing the event data.</param>
  522. protected override void OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
  523. {
  524. // Must call base class, otherwise the subsequent drawing does not appear!
  525. base.OnRenderToolStripContentPanelBackground(e);
  526.  
  527. // Cannot paint a zero sized area
  528. if ((e.ToolStripContentPanel.Width > 0) &&
  529. (e.ToolStripContentPanel.Height > 0))
  530. {
  531. using (LinearGradientBrush backBrush = new LinearGradientBrush(e.ToolStripContentPanel.ClientRectangle,
  532. ColorTable.ToolStripContentPanelGradientEnd,
  533. ColorTable.ToolStripContentPanelGradientBegin,
  534. 90f))
  535. {
  536. e.Graphics.FillRectangle(backBrush, e.ToolStripContentPanel.ClientRectangle);
  537. }
  538. }
  539. }
  540. #endregion
  541.  
  542. #region OnRenderSeparator
  543. /// <summary>
  544. /// Raises the RenderSeparator event.
  545. /// </summary>
  546. /// <param name="e">An ToolStripSeparatorRenderEventArgs containing the event data.</param>
  547. protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
  548. {
  549. if ((e.ToolStrip is ContextMenuStrip) ||
  550. (e.ToolStrip is ToolStripDropDownMenu))
  551. {
  552. // Create the light and dark line pens
  553. using (Pen lightPen = new Pen(_separatorMenuLight),
  554. darkPen = new Pen(_separatorMenuDark))
  555. {
  556. DrawSeparator(e.Graphics, e.Vertical, e.Item.Bounds,
  557. lightPen, darkPen, _separatorInset,
  558. (e.ToolStrip.RightToLeft == RightToLeft.Yes));
  559. }
  560. }
  561. else if (e.ToolStrip is StatusStrip)
  562. {
  563. // Create the light and dark line pens
  564. using (Pen lightPen = new Pen(ColorTable.SeparatorLight),
  565. darkPen = new Pen(ColorTable.SeparatorDark))
  566. {
  567. DrawSeparator(e.Graphics, e.Vertical, e.Item.Bounds,
  568. lightPen, darkPen, 0, false);
  569. }
  570. }
  571. else
  572. {
  573. base.OnRenderSeparator(e);
  574. }
  575. }
  576. #endregion
  577.  
  578. #region OnRenderToolStripBackground
  579. /// <summary>
  580. /// Raises the RenderToolStripBackground event.
  581. /// </summary>
  582. /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
  583. protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
  584. {
  585. if ((e.ToolStrip is ContextMenuStrip) ||
  586. (e.ToolStrip is ToolStripDropDownMenu))
  587. {
  588. // Create border and clipping paths
  589. using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, _cutContextMenu),
  590. clipPath = CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
  591. {
  592. // Clip all drawing to within the border path
  593. using (UseClipping clipping = new UseClipping(e.Graphics, clipPath))
  594. {
  595. // Create the background brush
  596. using (SolidBrush backBrush = new SolidBrush(_contextMenuBack))
  597. e.Graphics.FillPath(backBrush, borderPath);
  598. }
  599. }
  600. }
  601. else if (e.ToolStrip is StatusStrip)
  602. {
  603. // We do not paint the top two pixel lines, so are drawn by the status strip border render method
  604. RectangleF backRect = new RectangleF(0, 1.5f, e.ToolStrip.Width, e.ToolStrip.Height - 2);
  605.  
  606. // Cannot paint a zero sized area
  607. if ((backRect.Width > 0) && (backRect.Height > 0))
  608. {
  609. using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
  610. ColorTable.StatusStripGradientBegin,
  611. ColorTable.StatusStripGradientEnd,
  612. 90f))
  613. {
  614. backBrush.Blend = _statusStripBlend;
  615. e.Graphics.FillRectangle(backBrush, backRect);
  616. }
  617. }
  618. }
  619. else
  620. {
  621. base.OnRenderToolStripBackground(e);
  622. }
  623. }
  624. #endregion
  625.  
  626. #region OnRenderImageMargin
  627. /// <summary>
  628. /// Raises the RenderImageMargin event.
  629. /// </summary>
  630. /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
  631. protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
  632. {
  633. if ((e.ToolStrip is ContextMenuStrip) ||
  634. (e.ToolStrip is ToolStripDropDownMenu))
  635. {
  636. // Start with the total margin area
  637. Rectangle marginRect = e.AffectedBounds;
  638.  
  639. // Do we need to draw with separator on the opposite edge?
  640. bool rtl = (e.ToolStrip.RightToLeft == RightToLeft.Yes);
  641.  
  642. marginRect.Y += _marginInset;
  643. marginRect.Height -= _marginInset * 2;
  644.  
  645. // Reduce so it is inside the border
  646. if (!rtl)
  647. marginRect.X += _marginInset;
  648. else
  649. marginRect.X += _marginInset / 2;
  650.  
  651. // Draw the entire margine area in a solid color
  652. using (SolidBrush backBrush = new SolidBrush(ColorTable.ImageMarginGradientBegin))
  653. e.Graphics.FillRectangle(backBrush, marginRect);
  654.  
  655. // Create the light and dark line pens
  656. using (Pen lightPen = new Pen(_separatorMenuLight),
  657. darkPen = new Pen(_separatorMenuDark))
  658. {
  659. if (!rtl)
  660. {
  661. // Draw the light and dark lines on the right hand side
  662. e.Graphics.DrawLine(lightPen, marginRect.Right, marginRect.Top, marginRect.Right, marginRect.Bottom);
  663. e.Graphics.DrawLine(darkPen, marginRect.Right - 1, marginRect.Top, marginRect.Right - 1, marginRect.Bottom);
  664. }
  665. else
  666. {
  667. // Draw the light and dark lines on the left hand side
  668. e.Graphics.DrawLine(lightPen, marginRect.Left - 1, marginRect.Top, marginRect.Left - 1, marginRect.Bottom);
  669. e.Graphics.DrawLine(darkPen, marginRect.Left, marginRect.Top, marginRect.Left, marginRect.Bottom);
  670. }
  671. }
  672. }
  673. else
  674. {
  675. base.OnRenderImageMargin(e);
  676. }
  677. }
  678. #endregion
  679.  
  680. #region OnRenderToolStripBorder
  681. /// <summary>
  682. /// Raises the RenderToolStripBorder event.
  683. /// </summary>
  684. /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
  685. protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
  686. {
  687. if ((e.ToolStrip is ContextMenuStrip) ||
  688. (e.ToolStrip is ToolStripDropDownMenu))
  689. {
  690. // If there is a connected area to be drawn
  691. if (!e.ConnectedArea.IsEmpty)
  692. using (SolidBrush excludeBrush = new SolidBrush(_contextMenuBack))
  693. e.Graphics.FillRectangle(excludeBrush, e.ConnectedArea);
  694.  
  695. // Create border and clipping paths
  696. using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu),
  697. insidePath = CreateInsideBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu),
  698. clipPath = CreateClipBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu))
  699. {
  700. // Create the different pen colors we need
  701. using (Pen borderPen = new Pen(ColorTable.MenuBorder),
  702. insidePen = new Pen(_separatorMenuLight))
  703. {
  704. // Clip all drawing to within the border path
  705. using (UseClipping clipping = new UseClipping(e.Graphics, clipPath))
  706. {
  707. // Drawing with anti aliasing to create smoother appearance
  708. using (UseAntiAlias uaa = new UseAntiAlias(e.Graphics))
  709. {
  710. // Draw the inside area first
  711. e.Graphics.DrawPath(insidePen, insidePath);
  712.  
  713. // Draw the border area second, so any overlapping gives it priority
  714. e.Graphics.DrawPath(borderPen, borderPath);
  715. }
  716.  
  717. // Draw the pixel at the bottom right of the context menu
  718. e.Graphics.DrawLine(borderPen, e.AffectedBounds.Right, e.AffectedBounds.Bottom,
  719. e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1);
  720. }
  721. }
  722. }
  723. }
  724. else if (e.ToolStrip is StatusStrip)
  725. {
  726. // Draw two lines at top of the status strip
  727. using (Pen darkBorder = new Pen(_statusStripBorderDark),
  728. lightBorder = new Pen(_statusStripBorderLight))
  729. {
  730. e.Graphics.DrawLine(darkBorder, 0, 0, e.ToolStrip.Width, 0);
  731. e.Graphics.DrawLine(lightBorder, 0, 1, e.ToolStrip.Width, 1);
  732. }
  733. }
  734. else
  735. {
  736. base.OnRenderToolStripBorder(e);
  737. }
  738. }
  739. #endregion
  740.  
  741. #region Implementation
  742. private void RenderToolButtonBackground(Graphics g,
  743. ToolStripButton button,
  744. ToolStrip toolstrip)
  745. {
  746. // We only draw a background if the item is selected or being pressed
  747. if (button.Enabled)
  748. {
  749. if (button.Checked)
  750. {
  751. if (button.Pressed)
  752. DrawGradientToolItem(g, button, _itemToolItemPressedColors);
  753. else if (button.Selected)
  754. DrawGradientToolItem(g, button, _itemToolItemCheckPressColors);
  755. else
  756. DrawGradientToolItem(g, button, _itemToolItemCheckedColors);
  757. }
  758. else
  759. {
  760. if (button.Pressed)
  761. DrawGradientToolItem(g, button, _itemToolItemPressedColors);
  762. else if (button.Selected)
  763. DrawGradientToolItem(g, button, _itemToolItemSelectedColors);
  764. }
  765. }
  766. else
  767. {
  768. if (button.Selected)
  769. {
  770. // Get the mouse position in tool strip coordinates
  771. Point mousePos = toolstrip.PointToClient(Control.MousePosition);
  772.  
  773. // If the mouse is not in the item area, then draw disabled
  774. if (!button.Bounds.Contains(mousePos))
  775. DrawGradientToolItem(g, button, _itemDisabledColors);
  776. }
  777. }
  778. }
  779.  
  780. private void RenderToolDropButtonBackground(Graphics g,
  781. ToolStripItem item,
  782. ToolStrip toolstrip)
  783. {
  784. // We only draw a background if the item is selected or being pressed
  785. if (item.Selected || item.Pressed)
  786. {
  787. if (item.Enabled)
  788. {
  789. if (item.Pressed)
  790. DrawContextMenuHeader(g, item);
  791. else
  792. DrawGradientToolItem(g, item, _itemToolItemSelectedColors);
  793. }
  794. else
  795. {
  796. // Get the mouse position in tool strip coordinates
  797. Point mousePos = toolstrip.PointToClient(Control.MousePosition);
  798.  
  799. // If the mouse is not in the item area, then draw disabled
  800. if (!item.Bounds.Contains(mousePos))
  801. DrawGradientToolItem(g, item, _itemDisabledColors);
  802. }
  803. }
  804.  
  805. }
  806.  
  807. private void RenderToolSplitButtonBackground(Graphics g,
  808. ToolStripSplitButton splitButton,
  809. ToolStrip toolstrip)
  810. {
  811. // We only draw a background if the item is selected or being pressed
  812. if (splitButton.Selected || splitButton.Pressed)
  813. {
  814. if (splitButton.Enabled)
  815. {
  816. if (!splitButton.Pressed && splitButton.ButtonPressed)
  817. DrawGradientToolSplitItem(g, splitButton,
  818. _itemToolItemPressedColors,
  819. _itemToolItemSelectedColors,
  820. _itemContextItemEnabledColors);
  821. else if (splitButton.Pressed && !splitButton.ButtonPressed)
  822. DrawContextMenuHeader(g, splitButton);
  823. else
  824. DrawGradientToolSplitItem(g, splitButton,
  825. _itemToolItemSelectedColors,
  826. _itemToolItemSelectedColors,
  827. _itemContextItemEnabledColors);
  828. }
  829. else
  830. {
  831. // Get the mouse position in tool strip coordinates
  832. Point mousePos = toolstrip.PointToClient(Control.MousePosition);
  833.  
  834. // If the mouse is not in the item area, then draw disabled
  835. if (!splitButton.Bounds.Contains(mousePos))
  836. DrawGradientToolItem(g, splitButton, _itemDisabledColors);
  837. }
  838. }
  839.  
  840. }
  841.  
  842. private void DrawGradientToolItem(Graphics g,
  843. ToolStripItem item,
  844. GradientItemColors colors)
  845. {
  846. // Perform drawing into the entire background of the item
  847. DrawGradientItem(g, new Rectangle(Point.Empty, item.Bounds.Size), colors);
  848. }
  849.  
  850. private void DrawGradientToolSplitItem(Graphics g,
  851. ToolStripSplitButton splitButton,
  852. GradientItemColors colorsButton,
  853. GradientItemColors colorsDrop,
  854. GradientItemColors colorsSplit)
  855. {
  856. // Create entire area and just the drop button area rectangles
  857. Rectangle backRect = new Rectangle(Point.Empty, splitButton.Bounds.Size);
  858. Rectangle backRectDrop = splitButton.DropDownButtonBounds;
  859.  
  860. // Cannot paint zero sized areas
  861. if ((backRect.Width > 0) && (backRectDrop.Width > 0) &&
  862. (backRect.Height > 0) && (backRectDrop.Height > 0))
  863. {
  864. // Area that is the normal button starts as everything
  865. Rectangle backRectButton = backRect;
  866.  
  867. // The X offset to draw the split line
  868. int splitOffset;
  869.  
  870. // Is the drop button on the right hand side of entire area?
  871. if (backRectDrop.X > 0)
  872. {
  873. backRectButton.Width = backRectDrop.Left;
  874. backRectDrop.X -= 1;
  875. backRectDrop.Width++;
  876. splitOffset = backRectDrop.X;
  877. }
  878. else
  879. {
  880. backRectButton.Width -= backRectDrop.Width - 2;
  881. backRectButton.X = backRectDrop.Right - 1;
  882. backRectDrop.Width++;
  883. splitOffset = backRectDrop.Right - 1;
  884. }
  885.  
  886. // Create border path around the item
  887. using (GraphicsPath borderPath = CreateBorderPath(backRect, _cutMenuItemBack))
  888. {
  889. // Draw the normal button area background
  890. DrawGradientBack(g, backRectButton, colorsButton);
  891.  
  892. // Draw the drop button area background
  893. DrawGradientBack(g, backRectDrop, colorsDrop);
  894.  
  895. // Draw the split line between the areas
  896. using (LinearGradientBrush splitBrush = new LinearGradientBrush(new Rectangle(backRect.X + splitOffset, backRect.Top, 1, backRect.Height + 1),
  897. colorsSplit.Border1, colorsSplit.Border2, 90f))
  898. {
  899. // Sigma curve, so go from color1 to color2 and back to color1 again
  900. splitBrush.SetSigmaBellShape(0.5f);
  901.  
  902. // Convert the brush to a pen for DrawPath call
  903. using (Pen splitPen = new Pen(splitBrush))
  904. g.DrawLine(splitPen, backRect.X + splitOffset, backRect.Top + 1, backRect.X + splitOffset, backRect.Bottom - 1);
  905. }
  906.  
  907. // Draw the border of the entire item
  908. DrawGradientBorder(g, backRect, colorsButton);
  909. }
  910. }
  911. }
  912.  
  913. private void DrawContextMenuHeader(Graphics g, ToolStripItem item)
  914. {
  915. // Get the rectangle the is the items area
  916. Rectangle itemRect = new Rectangle(Point.Empty, item.Bounds.Size);
  917.  
  918. // Create border and clipping paths
  919. using (GraphicsPath borderPath = CreateBorderPath(itemRect, _cutToolItemMenu),
  920. insidePath = CreateInsideBorderPath(itemRect, _cutToolItemMenu),
  921. clipPath = CreateClipBorderPath(itemRect, _cutToolItemMenu))
  922. {
  923. // Clip all drawing to within the border path
  924. using (UseClipping clipping = new UseClipping(g, clipPath))
  925. {
  926. // Draw the entire background area first
  927. using (SolidBrush backBrush = new SolidBrush(_separatorMenuLight))
  928. g.FillPath(backBrush, borderPath);
  929.  
  930. // Draw the border
  931. using (Pen borderPen = new Pen(ColorTable.MenuBorder))
  932. g.DrawPath(borderPen, borderPath);
  933. }
  934. }
  935. }
  936.  
  937. private void DrawGradientContextMenuItem(Graphics g,
  938. ToolStripItem item,
  939. GradientItemColors colors)
  940. {
  941. // Do we need to draw with separator on the opposite edge?
  942. Rectangle backRect = new Rectangle(2, 0, item.Bounds.Width - 3, item.Bounds.Height);
  943.  
  944. // Perform actual drawing into the background
  945. DrawGradientItem(g, backRect, colors);
  946. }
  947.  
  948. private void DrawGradientItem(Graphics g,
  949. Rectangle backRect,
  950. GradientItemColors colors)
  951. {
  952. // Cannot paint a zero sized area
  953. if ((backRect.Width > 0) && (backRect.Height > 0))
  954. {
  955. // Draw the background of the entire item
  956. DrawGradientBack(g, backRect, colors);
  957.  
  958. // Draw the border of the entire item
  959. DrawGradientBorder(g, backRect, colors);
  960. }
  961. }
  962.  
  963. private void DrawGradientBack(Graphics g,
  964. Rectangle backRect,
  965. GradientItemColors colors)
  966. {
  967. // Reduce rect draw drawing inside the border
  968. backRect.Inflate(-1, -1);
  969.  
  970. int y2 = backRect.Height / 2;
  971. Rectangle backRect1 = new Rectangle(backRect.X, backRect.Y, backRect.Width, y2);
  972. Rectangle backRect2 = new Rectangle(backRect.X, backRect.Y + y2, backRect.Width, backRect.Height - y2);
  973. Rectangle backRect1I = backRect1;
  974. Rectangle backRect2I = backRect2;
  975. backRect1I.Inflate(1, 1);
  976. backRect2I.Inflate(1, 1);
  977.  
  978. using (LinearGradientBrush insideBrush1 = new LinearGradientBrush(backRect1I, colors.InsideTop1, colors.InsideTop2, 90f),
  979. insideBrush2 = new LinearGradientBrush(backRect2I, colors.InsideBottom1, colors.InsideBottom2, 90f))
  980. {
  981. g.FillRectangle(insideBrush1, backRect1);
  982. g.FillRectangle(insideBrush2, backRect2);
  983. }
  984.  
  985. y2 = backRect.Height / 2;
  986. backRect1 = new Rectangle(backRect.X, backRect.Y, backRect.Width, y2);
  987. backRect2 = new Rectangle(backRect.X, backRect.Y + y2, backRect.Width, backRect.Height - y2);
  988. backRect1I = backRect1;
  989. backRect2I = backRect2;
  990. backRect1I.Inflate(1, 1);
  991. backRect2I.Inflate(1, 1);
  992.  
  993. using (LinearGradientBrush fillBrush1 = new LinearGradientBrush(backRect1I, colors.FillTop1, colors.FillTop2, 90f),
  994. fillBrush2 = new LinearGradientBrush(backRect2I, colors.FillBottom1, colors.FillBottom2, 90f))
  995. {
  996. // Reduce rect one more time for the innermost drawing
  997. backRect.Inflate(-1, -1);
  998.  
  999. y2 = backRect.Height / 2;
  1000. backRect1 = new Rectangle(backRect.X, backRect.Y, backRect.Width, y2);
  1001. backRect2 = new Rectangle(backRect.X, backRect.Y + y2, backRect.Width, backRect.Height - y2);
  1002.  
  1003. g.FillRectangle(fillBrush1, backRect1);
  1004. g.FillRectangle(fillBrush2, backRect2);
  1005. }
  1006. }
  1007.  
  1008. private void DrawGradientBorder(Graphics g,
  1009. Rectangle backRect,
  1010. GradientItemColors colors)
  1011. {
  1012. // Drawing with anti aliasing to create smoother appearance
  1013. using (UseAntiAlias uaa = new UseAntiAlias(g))
  1014. {
  1015. Rectangle backRectI = backRect;
  1016. backRectI.Inflate(1, 1);
  1017.  
  1018. // Finally draw the border around the menu item
  1019. using (LinearGradientBrush borderBrush = new LinearGradientBrush(backRectI, colors.Border1, colors.Border2, 90f))
  1020. {
  1021. // Sigma curve, so go from color1 to color2 and back to color1 again
  1022. borderBrush.SetSigmaBellShape(0.5f);
  1023.  
  1024. // Convert the brush to a pen for DrawPath call
  1025. using (Pen borderPen = new Pen(borderBrush))
  1026. {
  1027. // Create border path around the entire item
  1028. using (GraphicsPath borderPath = CreateBorderPath(backRect, _cutMenuItemBack))
  1029. g.DrawPath(borderPen, borderPath);
  1030. }
  1031. }
  1032. }
  1033. }
  1034.  
  1035. private void DrawGripGlyph(Graphics g,
  1036. int x,
  1037. int y,
  1038. Brush darkBrush,
  1039. Brush lightBrush)
  1040. {
  1041. g.FillRectangle(lightBrush, x + _gripOffset, y + _gripOffset, _gripSquare, _gripSquare);
  1042. g.FillRectangle(darkBrush, x, y, _gripSquare, _gripSquare);
  1043. }
  1044.  
  1045. private void DrawSeparator(Graphics g,
  1046. bool vertical,
  1047. Rectangle rect,
  1048. Pen lightPen,
  1049. Pen darkPen,
  1050. int horizontalInset,
  1051. bool rtl)
  1052. {
  1053. if (vertical)
  1054. {
  1055. int l = rect.Width / 2;
  1056. int t = rect.Y;
  1057. int b = rect.Bottom;
  1058.  
  1059. // Draw vertical lines centered
  1060. g.DrawLine(darkPen, l, t, l, b);
  1061. g.DrawLine(lightPen, l + 1, t, l + 1, b);
  1062. }
  1063. else
  1064. {
  1065. int y = rect.Height / 2;
  1066. int l = rect.X + (rtl ? 0 : horizontalInset);
  1067. int r = rect.Right - (rtl ? horizontalInset : 0);
  1068.  
  1069. // Draw horizontal lines centered
  1070. g.DrawLine(darkPen, l, y, r, y);
  1071. g.DrawLine(lightPen, l, y + 1, r, y + 1);
  1072. }
  1073. }
  1074.  
  1075. private GraphicsPath CreateBorderPath(Rectangle rect,
  1076. Rectangle exclude,
  1077. float cut)
  1078. {
  1079. // If nothing to exclude, then use quicker method
  1080. if (exclude.IsEmpty)
  1081. return CreateBorderPath(rect, cut);
  1082.  
  1083. // Drawing lines requires we draw inside the area we want
  1084. rect.Width--;
  1085. rect.Height--;
  1086.  
  1087. // Create an array of points to draw lines between
  1088. List<PointF> pts = new List<PointF>();
  1089.  
  1090. float l = rect.X;
  1091. float t = rect.Y;
  1092. float r = rect.Right;
  1093. float b = rect.Bottom;
  1094. float x0 = rect.X + cut;
  1095. float x3 = rect.Right - cut;
  1096. float y0 = rect.Y + cut;
  1097. float y3 = rect.Bottom - cut;
  1098. float cutBack = (cut == 0f ? 1 : cut);
  1099.  
  1100. // Does the exclude intercept the top line
  1101. if ((rect.Y >= exclude.Top) && (rect.Y <= exclude.Bottom))
  1102. {
  1103. float x1 = exclude.X - 1 - cut;
  1104. float x2 = exclude.Right + cut;
  1105.  
  1106. if (x0 <= x1)
  1107. {
  1108. pts.Add(new PointF(x0, t));
  1109. pts.Add(new PointF(x1, t));
  1110. pts.Add(new PointF(x1 + cut, t - cutBack));
  1111. }
  1112. else
  1113. {
  1114. x1 = exclude.X - 1;
  1115. pts.Add(new PointF(x1, t));
  1116. pts.Add(new PointF(x1, t - cutBack));
  1117. }
  1118.  
  1119. if (x3 > x2)
  1120. {
  1121. pts.Add(new PointF(x2 - cut, t - cutBack));
  1122. pts.Add(new PointF(x2, t));
  1123. pts.Add(new PointF(x3, t));
  1124. }
  1125. else
  1126. {
  1127. x2 = exclude.Right;
  1128. pts.Add(new PointF(x2, t - cutBack));
  1129. pts.Add(new PointF(x2, t));
  1130. }
  1131. }
  1132. else
  1133. {
  1134. pts.Add(new PointF(x0, t));
  1135. pts.Add(new PointF(x3, t));
  1136. }
  1137.  
  1138. pts.Add(new PointF(r, y0));
  1139. pts.Add(new PointF(r, y3));
  1140. pts.Add(new PointF(x3, b));
  1141. pts.Add(new PointF(x0, b));
  1142. pts.Add(new PointF(l, y3));
  1143. pts.Add(new PointF(l, y0));
  1144.  
  1145. // Create path using a simple set of lines that cut the corner
  1146. GraphicsPath path = new GraphicsPath();
  1147.  
  1148. // Add a line between each set of points
  1149. for (int i = 1; i < pts.Count; i++)
  1150. path.AddLine(pts[i - 1], pts[i]);
  1151.  
  1152. // Add a line to join the last to the first
  1153. path.AddLine(pts[pts.Count - 1], pts[0]);
  1154.  
  1155. return path;
  1156. }
  1157.  
  1158. private GraphicsPath CreateBorderPath(Rectangle rect, float cut)
  1159. {
  1160. // Drawing lines requires we draw inside the area we want
  1161. rect.Width--;
  1162. rect.Height--;
  1163.  
  1164. // Create path using a simple set of lines that cut the corner
  1165. GraphicsPath path = new GraphicsPath();
  1166. path.AddLine(rect.Left + cut, rect.Top, rect.Right - cut, rect.Top);
  1167. path.AddLine(rect.Right - cut, rect.Top, rect.Right, rect.Top + cut);
  1168. path.AddLine(rect.Right, rect.Top + cut, rect.Right, rect.Bottom - cut);
  1169. path.AddLine(rect.Right, rect.Bottom - cut, rect.Right - cut, rect.Bottom);
  1170. path.AddLine(rect.Right - cut, rect.Bottom, rect.Left + cut, rect.Bottom);
  1171. path.AddLine(rect.Left + cut, rect.Bottom, rect.Left, rect.Bottom - cut);
  1172. path.AddLine(rect.Left, rect.Bottom - cut, rect.Left, rect.Top + cut);
  1173. path.AddLine(rect.Left, rect.Top + cut, rect.Left + cut, rect.Top);
  1174. return path;
  1175. }
  1176.  
  1177. private GraphicsPath CreateInsideBorderPath(Rectangle rect, float cut)
  1178. {
  1179. // Adjust rectangle to be 1 pixel inside the original area
  1180. rect.Inflate(-1, -1);
  1181.  
  1182. // Now create a path based on this inner rectangle
  1183. return CreateBorderPath(rect, cut);
  1184. }
  1185.  
  1186. private GraphicsPath CreateInsideBorderPath(Rectangle rect,
  1187. Rectangle exclude,
  1188. float cut)
  1189. {
  1190. // Adjust rectangle to be 1 pixel inside the original area
  1191. rect.Inflate(-1, -1);
  1192.  
  1193. // Now create a path based on this inner rectangle
  1194. return CreateBorderPath(rect, exclude, cut);
  1195. }
  1196.  
  1197. private GraphicsPath CreateClipBorderPath(Rectangle rect, float cut)
  1198. {
  1199. // Clipping happens inside the rect, so make 1 wider and taller
  1200. rect.Width++;
  1201. rect.Height++;
  1202.  
  1203. // Now create a path based on this inner rectangle
  1204. return CreateBorderPath(rect, cut);
  1205. }
  1206.  
  1207. private GraphicsPath CreateClipBorderPath(Rectangle rect,
  1208. Rectangle exclude,
  1209. float cut)
  1210. {
  1211. // Clipping happens inside the rect, so make 1 wider and taller
  1212. rect.Width++;
  1213. rect.Height++;
  1214.  
  1215. // Now create a path based on this inner rectangle
  1216. return CreateBorderPath(rect, exclude, cut);
  1217. }
  1218.  
  1219. private GraphicsPath CreateArrowPath(ToolStripItem item,
  1220. Rectangle rect,
  1221. ArrowDirection direction)
  1222. {
  1223. int x, y;
  1224.  
  1225. // Find the correct starting position, which depends on direction
  1226. if ((direction == ArrowDirection.Left) ||
  1227. (direction == ArrowDirection.Right))
  1228. {
  1229. x = rect.Right - (rect.Width - 4) / 2;
  1230. y = rect.Y + rect.Height / 2;
  1231. }
  1232. else
  1233. {
  1234. x = rect.X + rect.Width / 2;
  1235. y = rect.Bottom - (rect.Height - 3) / 2;
  1236.  
  1237. // The drop down button is position 1 pixel incorrectly when in RTL
  1238. if ((item is ToolStripDropDownButton) &&
  1239. (item.RightToLeft == RightToLeft.Yes))
  1240. x++;
  1241. }
  1242.  
  1243. // Create triangle using a series of lines
  1244. GraphicsPath path = new GraphicsPath();
  1245.  
  1246. switch (direction)
  1247. {
  1248. case ArrowDirection.Right:
  1249. path.AddLine(x, y, x - 4, y - 4);
  1250. path.AddLine(x - 4, y - 4, x - 4, y + 4);
  1251. path.AddLine(x - 4, y + 4, x, y);
  1252. break;
  1253. case ArrowDirection.Left:
  1254. path.AddLine(x - 4, y, x, y - 4);
  1255. path.AddLine(x, y - 4, x, y + 4);
  1256. path.AddLine(x, y + 4, x - 4, y);
  1257. break;
  1258. case ArrowDirection.Down:
  1259. path.AddLine(x + 3f, y - 3f, x - 2f, y - 3f);
  1260. path.AddLine(x - 2f, y - 3f, x, y);
  1261. path.AddLine(x, y, x + 3f, y - 3f);
  1262. break;
  1263. case ArrowDirection.Up:
  1264. path.AddLine(x + 3f, y, x - 3f, y);
  1265. path.AddLine(x - 3f, y, x, y - 4f);
  1266. path.AddLine(x, y - 4f, x + 3f, y);
  1267. break;
  1268. }
  1269.  
  1270. return path;
  1271. }
  1272.  
  1273. private GraphicsPath CreateTickPath(Rectangle rect)
  1274. {
  1275. // Get the center point of the rect
  1276. int x = rect.X + rect.Width / 2;
  1277. int y = rect.Y + rect.Height / 2;
  1278.  
  1279. GraphicsPath path = new GraphicsPath();
  1280. path.AddLine(x - 4, y, x - 2, y + 4);
  1281. path.AddLine(x - 2, y + 4, x + 3, y - 5);
  1282. return path;
  1283. }
  1284.  
  1285. private GraphicsPath CreateIndeterminatePath(Rectangle rect)
  1286. {
  1287. // Get the center point of the rect
  1288. int x = rect.X + rect.Width / 2;
  1289. int y = rect.Y + rect.Height / 2;
  1290.  
  1291. GraphicsPath path = new GraphicsPath();
  1292. path.AddLine(x - 3, y, x, y - 3);
  1293. path.AddLine(x, y - 3, x + 3, y);
  1294. path.AddLine(x + 3, y, x, y + 3);
  1295. path.AddLine(x, y + 3, x - 3, y);
  1296. return path;
  1297. }
  1298. #endregion
  1299. }
  1300. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/style/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1732533145 25/11/2024 12:12:25
| _vista0 octets1541007202 31/10/2018 18:33:22
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/style/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csOffice2007Renderer.cs58.44 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csStyleHelper.cs1.44 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csProfessionalColorTableFactory.cs57.94 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csControlStyleColors.cs4.76 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csCustomSystemColors.cs14.28 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csStyleFactory.cs18.11 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csRebarRenderer.cs11.97 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOrangeStyleColors.cs14.47 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOffice2007ColorTable.cs13.46 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csXpStyle.cs1.42 Ko31/10/2018 18:33:16-refusé-
Afficher le fichier .cs|.csOffice2007Helpers.cs4.16 Ko31/10/2018 18:33:15-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Version en cache

25/11/2024 12:12:24 Cette version de la page est en cache (à la date du 25/11/2024 12:12:24) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.

Document créé le 16/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-broldev-source-rf-view/style//Office2007Renderer.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.