Files
@ 65c134a3d619
Branch filter:
Location: seniordesign-ui/Demo.WindowsForms/BSE.Windows.Forms/Renderer/Office2007Renderer.cs
65c134a3d619
8.7 KiB
text/x-csharp
Initial import of mapping source (huge commit)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | /********************************************************************/
/* Office 2007 Renderer Project */
/* */
/* Use the Office2007Renderer class as a custom renderer by */
/* providing it to the ToolStripManager.Renderer property. Then */
/* all tool strips, menu strips, status strips etc will be drawn */
/* using the Office 2007 style renderer in your application. */
/* */
/* Author: Phil Wright */
/* Website: www.componentfactory.com */
/* Contact: phil.wright@componentfactory.com */
/********************************************************************/
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Diagnostics;
namespace BSE.Windows.Forms
{
/// <summary>
/// Draw ToolStrips using the Office 2007 themed appearance.
/// </summary>
public class Office2007Renderer : ToolStripProfessionalRenderer
{
#region FieldsPrivate
private static int MarginInset;
private static Blend StatusStripBlend;
#endregion
#region MethodsPublic
static Office2007Renderer()
{
MarginInset = 2;
// One time creation of the blend for the status strip gradient brush
StatusStripBlend = new Blend();
StatusStripBlend.Positions = new float[] { 0.0F, 0.2F, 0.3F, 0.4F, 0.8F, 1.0F };
StatusStripBlend.Factors = new float[] { 0.3F, 0.4F, 0.5F, 1.0F, 0.8F, 0.7F };
}
/// <summary>
/// Initialize a new instance of the Office2007Renderer class.
/// </summary>
public Office2007Renderer()
: base(new BSE.Windows.Forms.Office2007BlueColorTable())
{
this.ColorTable.UseSystemColors = false;
}
/// <summary>
/// Initializes a new instance of the Office2007Renderer class.
/// </summary>
/// <param name="professionalColorTable">A <see cref="ProfessionalColorTable"/> to be used for painting.</param>
public Office2007Renderer(ProfessionalColorTable professionalColorTable)
: base(professionalColorTable)
{
}
#endregion
#region MethodsProtected
/// <summary>
/// Raises the RenderArrow event.
/// </summary>
/// <param name="e">A ToolStripArrowRenderEventArgs that contains the event data.</param>
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
if (ColorTable.UseSystemColors == false)
{
ProfessionalColorTable colorTable = ColorTable as BSE.Windows.Forms.ProfessionalColorTable;
if (colorTable != null)
{
if ((e.Item.Owner.GetType() == typeof(MenuStrip)) && (e.Item.Selected == false) && e.Item.Pressed == false)
{
if (colorTable.MenuItemText != Color.Empty)
{
e.ArrowColor = colorTable.MenuItemText;
}
}
if ((e.Item.Owner.GetType() == typeof(StatusStrip)) && (e.Item.Selected == false) && e.Item.Pressed == false)
{
if (colorTable.StatusStripText != Color.Empty)
{
e.ArrowColor = colorTable.StatusStripText;
}
}
}
}
base.OnRenderArrow(e);
}
/// <summary>
/// Raises the RenderItemText event.
/// </summary>
/// <param name="e">A ToolStripItemTextRenderEventArgs that contains the event data.</param>
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
if (ColorTable.UseSystemColors == false)
{
ProfessionalColorTable colorTable = ColorTable as BSE.Windows.Forms.ProfessionalColorTable;
if (colorTable != null)
{
if ((e.ToolStrip is MenuStrip) && (e.Item.Selected == false) && e.Item.Pressed == false)
{
if (colorTable.MenuItemText != Color.Empty)
{
e.TextColor = colorTable.MenuItemText;
}
}
if ((e.ToolStrip is StatusStrip) && (e.Item.Selected == false) && e.Item.Pressed == false)
{
if (colorTable.StatusStripText != Color.Empty)
{
e.TextColor = colorTable.StatusStripText;
}
}
}
}
base.OnRenderItemText(e);
}
/// <summary>
/// Raises the RenderToolStripContentPanelBackground event.
/// </summary>
/// <param name="e">An ToolStripContentPanelRenderEventArgs containing the event data.</param>
protected override void OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
{
// Must call base class, otherwise the subsequent drawing does not appear!
base.OnRenderToolStripContentPanelBackground(e);
if (ColorTable.UseSystemColors == false)
{
// Cannot paint a zero sized area
if ((e.ToolStripContentPanel.Width > 0) &&
(e.ToolStripContentPanel.Height > 0))
{
using (LinearGradientBrush backBrush = new LinearGradientBrush(e.ToolStripContentPanel.ClientRectangle,
ColorTable.ToolStripContentPanelGradientBegin,
ColorTable.ToolStripContentPanelGradientEnd,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(backBrush, e.ToolStripContentPanel.ClientRectangle);
}
}
}
}
/// <summary>
/// Raises the RenderSeparator event.
/// </summary>
/// <param name="e">An ToolStripSeparatorRenderEventArgs containing the event data.</param>
protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
{
if (ColorTable.UseSystemColors == false)
{
e.Item.ForeColor = ColorTable.RaftingContainerGradientBegin;
}
base.OnRenderSeparator(e);
}
/// <summary>
/// Raises the RenderToolStripBackground event.
/// </summary>
/// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
if (ColorTable.UseSystemColors == true)
{
base.OnRenderToolStripBackground(e);
}
else
{
if (e.ToolStrip is StatusStrip)
{
// We do not paint the top two pixel lines, so are drawn by the status strip border render method
//RectangleF backRectangle = new RectangleF(0, 1.5f, e.ToolStrip.Width, e.ToolStrip.Height - 2);
RectangleF backRectangle = new RectangleF(0, 0, e.ToolStrip.Width, e.ToolStrip.Height);
// Cannot paint a zero sized area
if ((backRectangle.Width > 0) && (backRectangle.Height > 0))
{
using (LinearGradientBrush backBrush = new LinearGradientBrush(backRectangle,
ColorTable.StatusStripGradientBegin,
ColorTable.StatusStripGradientEnd,
LinearGradientMode.Vertical))
{
backBrush.Blend = StatusStripBlend;
e.Graphics.FillRectangle(backBrush, backRectangle);
}
}
}
else
{
base.OnRenderToolStripBackground(e);
}
}
}
/// <summary>
/// Raises the RenderImageMargin event.
/// </summary>
/// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
{
if (ColorTable.UseSystemColors == true)
{
base.OnRenderToolStripBackground(e);
}
else
{
if ((e.ToolStrip is ContextMenuStrip) ||
(e.ToolStrip is ToolStripDropDownMenu))
{
// Start with the total margin area
Rectangle marginRectangle = e.AffectedBounds;
// Do we need to draw with separator on the opposite edge?
bool bIsRightToLeft = (e.ToolStrip.RightToLeft == RightToLeft.Yes);
marginRectangle.Y += MarginInset;
marginRectangle.Height -= MarginInset * 2;
// Reduce so it is inside the border
if (bIsRightToLeft == false)
{
marginRectangle.X += MarginInset;
}
else
{
marginRectangle.X += MarginInset / 2;
}
// Draw the entire margine area in a solid color
using (SolidBrush backBrush = new SolidBrush(
ColorTable.ImageMarginGradientBegin))
e.Graphics.FillRectangle(backBrush, marginRectangle);
}
else
{
base.OnRenderImageMargin(e);
}
}
}
#endregion
#region MethodsPrivate
#endregion
}
}
|