DotNet 4.8.1 build of DotNetBar
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.DotNetBar.Layout
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents class with static functions that provide commonly used utility functions when working with
|
||||
/// Bar objects and items hosted by Bar object.
|
||||
/// </summary>
|
||||
internal class BarUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets whether StringFormat internally used by all DotNetBar controls to render text is GenericDefault. Default value is false
|
||||
/// which indicates that GenericTypographic is used.
|
||||
/// </summary>
|
||||
public static bool UseGenericDefaultStringFormat
|
||||
{
|
||||
get { return TextDrawing.UseGenericDefault; }
|
||||
set { TextDrawing.UseGenericDefault = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the anti-alias text rendering hint that will be used to render text on controls that have AntiAlias property set to true.
|
||||
/// </summary>
|
||||
public static TextRenderingHint AntiAliasTextRenderingHint
|
||||
{
|
||||
get
|
||||
{
|
||||
return DisplayHelp.AntiAliasTextRenderingHint;
|
||||
}
|
||||
set
|
||||
{
|
||||
DisplayHelp.AntiAliasTextRenderingHint = value;
|
||||
}
|
||||
}
|
||||
|
||||
#if FRAMEWORK20
|
||||
/// <summary>
|
||||
/// Gets or sets whether .NET Framework TextRenderer class is used for text rendering instead of Graphics.DrawString.
|
||||
/// Default value is false.
|
||||
/// Using TextRenderer will disable the Fade and Animation effects on controls because of issues in TextRenderer when drawing text on transparent
|
||||
/// surfaces.
|
||||
/// </summary>
|
||||
public static bool UseTextRenderer
|
||||
{
|
||||
get { return TextDrawing.UseTextRenderer; }
|
||||
set { TextDrawing.UseTextRenderer = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
private static bool _AlwaysGenerateAccessibilityFocusEvent = false;
|
||||
/// <summary>
|
||||
/// Gets or sets whether items always generate the Focus accessibility event when mouse enters the item. Default value is false which indicates
|
||||
/// that focus event will be raised only when item is on menu bar.
|
||||
/// </summary>
|
||||
public static bool AlwaysGenerateAccessibilityFocusEvent
|
||||
{
|
||||
get { return _AlwaysGenerateAccessibilityFocusEvent; }
|
||||
set
|
||||
{
|
||||
_AlwaysGenerateAccessibilityFocusEvent = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsModalFormOpen
|
||||
{
|
||||
get
|
||||
{
|
||||
#if (FRAMEWORK20)
|
||||
for (int i = 0; i < System.Windows.Forms.Application.OpenForms.Count; i++)
|
||||
{
|
||||
System.Windows.Forms.Form form = System.Windows.Forms.Application.OpenForms[i];
|
||||
if (form.Modal) return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _AutoRemoveMessageFilter = false;
|
||||
/// <summary>
|
||||
/// Gets or sets whether Application Message Filter that is registered by popup controls
|
||||
/// is automatically unregistered when last control is disposed. Default value is false and
|
||||
/// in most cases should not be changed.
|
||||
/// </summary>
|
||||
public static bool AutoRemoveMessageFilter
|
||||
{
|
||||
get { return _AutoRemoveMessageFilter; }
|
||||
set { _AutoRemoveMessageFilter = value; }
|
||||
}
|
||||
|
||||
private static int _TextMarkupCultureSpecific = 3;
|
||||
/// <summary>
|
||||
/// Get or sets the text-markup padding for text measurement when running on Japanese version of Windows.
|
||||
/// </summary>
|
||||
public static int TextMarkupCultureSpecificPadding
|
||||
{
|
||||
get { return _TextMarkupCultureSpecific; }
|
||||
set
|
||||
{
|
||||
_TextMarkupCultureSpecific = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _DisposeItemImages = false;
|
||||
/// <summary>
|
||||
/// Gets or sets whether Image and Icon resources assigned to items and controls are automatically disposed when
|
||||
/// control or item is disposed. Default value is false.
|
||||
/// </summary>
|
||||
public static bool DisposeItemImages
|
||||
{
|
||||
get
|
||||
{
|
||||
return _DisposeItemImages;
|
||||
}
|
||||
set
|
||||
{
|
||||
_DisposeItemImages = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes image reference and sets it to null.
|
||||
/// </summary>
|
||||
/// <param name="image">Reference to image to dispose.</param>
|
||||
internal static void DisposeImage(ref System.Drawing.Image image)
|
||||
{
|
||||
if (image == null) return;
|
||||
image.Dispose();
|
||||
image = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Disposes image reference and sets it to null.
|
||||
/// </summary>
|
||||
/// <param name="image">Reference to image to dispose.</param>
|
||||
internal static void DisposeImage(ref System.Drawing.Icon icon)
|
||||
{
|
||||
if (icon == null) return;
|
||||
icon.Dispose();
|
||||
icon = null;
|
||||
}
|
||||
|
||||
#region Delayed Invoke
|
||||
/// <summary>
|
||||
/// Invokes the method asynchronously using the WinForms Timer.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to invoke.</param>
|
||||
public static void InvokeDelayed(MethodInvoker method)
|
||||
{
|
||||
InvokeDelayed(method, 10);
|
||||
}
|
||||
/// <summary>
|
||||
/// Invokes the method asynchronously using the WinForms Timer.
|
||||
/// </summary>
|
||||
/// <param name="method">Method to invoke.</param>
|
||||
/// <param name="delayInterval">Time in milliseconds after which method is invoked.</param>
|
||||
public static void InvokeDelayed(MethodInvoker method, int delayInterval)
|
||||
{
|
||||
Timer delayedInvokeTimer = new Timer();
|
||||
delayedInvokeTimer = new Timer();
|
||||
delayedInvokeTimer.Tag = method;
|
||||
delayedInvokeTimer.Interval = delayInterval;
|
||||
delayedInvokeTimer.Tick += new EventHandler(DelayedInvokeTimerTick);
|
||||
delayedInvokeTimer.Start();
|
||||
}
|
||||
private static void DelayedInvokeTimerTick(object sender, EventArgs e)
|
||||
{
|
||||
Timer timer = (Timer)sender;
|
||||
MethodInvoker method = (MethodInvoker)timer.Tag;
|
||||
timer.Stop();
|
||||
timer.Dispose();
|
||||
method.Invoke();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class BarPropertyBagKeys
|
||||
{
|
||||
public static string AutoHideSetting="autohide";
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class BodyElement : ContainerElement
|
||||
{
|
||||
#region Private Variables
|
||||
private MarkupElementCollection m_ActiveElements=null;
|
||||
private IActiveMarkupElement m_MouseOverElement = null;
|
||||
internal bool HasExpandElement = false;
|
||||
internal string PlainText = "";
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
public event EventHandler HyperLinkClick;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public BodyElement()
|
||||
{
|
||||
m_ActiveElements = new MarkupElementCollection(null);
|
||||
}
|
||||
|
||||
public MarkupElementCollection ActiveElements
|
||||
{
|
||||
get { return m_ActiveElements; }
|
||||
}
|
||||
|
||||
public void MouseLeave(Control parent)
|
||||
{
|
||||
if (m_MouseOverElement != null)
|
||||
m_MouseOverElement.MouseLeave(parent);
|
||||
m_MouseOverElement = null;
|
||||
}
|
||||
|
||||
public void MouseMove(Control parent, MouseEventArgs e)
|
||||
{
|
||||
if (m_MouseOverElement != null && m_MouseOverElement.HitTest(e.X, e.Y))
|
||||
return;
|
||||
if (m_MouseOverElement != null)
|
||||
m_MouseOverElement.MouseLeave(parent);
|
||||
|
||||
m_MouseOverElement = null;
|
||||
|
||||
foreach(IActiveMarkupElement el in m_ActiveElements)
|
||||
{
|
||||
if (el.HitTest(e.X, e.Y))
|
||||
{
|
||||
m_MouseOverElement = el;
|
||||
m_MouseOverElement.MouseEnter(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MouseDown(Control parent, MouseEventArgs e)
|
||||
{
|
||||
if (m_MouseOverElement != null)
|
||||
m_MouseOverElement.MouseDown(parent, e);
|
||||
}
|
||||
|
||||
public void MouseUp(Control parent, MouseEventArgs e)
|
||||
{
|
||||
if (m_MouseOverElement != null)
|
||||
m_MouseOverElement.MouseUp(parent, e);
|
||||
}
|
||||
|
||||
public void Click(Control parent)
|
||||
{
|
||||
if (m_MouseOverElement != null)
|
||||
{
|
||||
m_MouseOverElement.Click(parent);
|
||||
if (m_MouseOverElement is HyperLink)
|
||||
{
|
||||
if (HyperLinkClick != null)
|
||||
HyperLinkClick(m_MouseOverElement, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class ContainerElement : MarkupElement
|
||||
{
|
||||
#region Private Variables
|
||||
private SerialContentLayoutManager m_Layout = null;
|
||||
private MarkupLayoutManager m_MarkupLayout = null;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Measure(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
ArrangeInternal(new Rectangle(Point.Empty, availableSize), d);
|
||||
}
|
||||
|
||||
protected virtual SerialContentLayoutManager GetLayoutManager(bool mutliLine)
|
||||
{
|
||||
if (m_Layout == null)
|
||||
{
|
||||
m_Layout = new SerialContentLayoutManager();
|
||||
m_Layout.MultiLine = mutliLine;
|
||||
m_Layout.ContentVerticalAlignment = eContentVerticalAlignment.Top;
|
||||
m_Layout.BlockLineAlignment = eContentVerticalAlignment.Top;
|
||||
m_Layout.BlockSpacing = 0;
|
||||
}
|
||||
|
||||
m_Layout.EvenHeight = true;
|
||||
return m_Layout;
|
||||
}
|
||||
|
||||
private MarkupLayoutManager GetMarkupLayout()
|
||||
{
|
||||
if (m_MarkupLayout == null)
|
||||
{
|
||||
m_MarkupLayout = new MarkupLayoutManager();
|
||||
}
|
||||
return m_MarkupLayout;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Point offset = this.GetContainerOffset();
|
||||
d.Offset.Offset(offset.X, offset.Y);
|
||||
|
||||
try
|
||||
{
|
||||
foreach (MarkupElement e in this.Elements)
|
||||
{
|
||||
e.Render(d);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
d.Offset.Offset(-offset.X, -offset.Y);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Point GetContainerOffset()
|
||||
{
|
||||
return this.Bounds.Location;
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(Rectangle finalRect, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = finalRect;
|
||||
ArrangeInternal(finalRect, d);
|
||||
}
|
||||
|
||||
protected virtual void ArrangeInternal(Rectangle bounds, MarkupDrawContext d)
|
||||
{
|
||||
SerialContentLayoutManager layout = GetLayoutManager(d.AllowMultiLine);
|
||||
layout.RightToLeft = d.RightToLeft;
|
||||
MarkupLayoutManager markupLayout = GetMarkupLayout();
|
||||
markupLayout.MarkupDrawContext = d;
|
||||
try
|
||||
{
|
||||
MarkupElement[] blocks = new MarkupElement[this.Elements.Count];
|
||||
this.Elements.CopyTo(blocks);
|
||||
|
||||
Rectangle r = layout.Layout(new Rectangle(Point.Empty, bounds.Size), blocks, markupLayout);
|
||||
this.Bounds = new Rectangle(bounds.Location, r.Size);
|
||||
}
|
||||
finally
|
||||
{
|
||||
markupLayout.MarkupDrawContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether markup element is an block element that always consumes a whole line in layout.
|
||||
/// </summary>
|
||||
public override bool IsBlockElement
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,932 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System;
|
||||
using System.Drawing.Text;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout
|
||||
#endif
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Display.
|
||||
/// </summary>
|
||||
public class DisplayHelp
|
||||
{
|
||||
private DisplayHelp()
|
||||
{
|
||||
}
|
||||
|
||||
public static LinearGradientBrush CreateLinearGradientBrush(Rectangle r,Color color1, Color color2,float gradientAngle)
|
||||
{
|
||||
if(r.Width<=0)
|
||||
r.Width=1;
|
||||
if(r.Height<=0)
|
||||
r.Height=1;
|
||||
return new LinearGradientBrush(new Rectangle(r.X,r.Y-1,r.Width,r.Height+1),color1,color2,gradientAngle);
|
||||
}
|
||||
|
||||
public static LinearGradientBrush CreateLinearGradientBrush(RectangleF r,Color color1, Color color2,float gradientAngle)
|
||||
{
|
||||
if(r.Width<=0)
|
||||
r.Width=1;
|
||||
if(r.Height<=0)
|
||||
r.Height=1;
|
||||
return new LinearGradientBrush(new RectangleF(r.X,r.Y-1,r.Width,r.Height+1),color1,color2,gradientAngle);
|
||||
}
|
||||
|
||||
public static LinearGradientBrush CreateLinearGradientBrush(Rectangle r,Color color1, Color color2,float gradientAngle, bool isAngleScalable)
|
||||
{
|
||||
if(r.Width<=0)
|
||||
r.Width=1;
|
||||
if(r.Height<=0)
|
||||
r.Height=1;
|
||||
return new LinearGradientBrush(new Rectangle(r.X,r.Y-1,r.Width,r.Height+1),color1,color2,gradientAngle,isAngleScalable);
|
||||
}
|
||||
|
||||
public static Rectangle GetDrawRectangle(Rectangle r)
|
||||
{
|
||||
r.Width--;
|
||||
r.Height--;
|
||||
return r;
|
||||
}
|
||||
|
||||
public static Rectangle GetPathRectangle(Rectangle r)
|
||||
{
|
||||
//r.Width++;
|
||||
//r.Height++;
|
||||
return r;
|
||||
}
|
||||
|
||||
public static void DrawRectangle(System.Drawing.Graphics g, Color color, int x, int y, int width, int height)
|
||||
{
|
||||
using (Pen pen = new Pen(color, 1))
|
||||
DrawRectangle(g, pen, x, y, width, height);
|
||||
}
|
||||
public static void DrawRectangle(System.Drawing.Graphics g, Color color, System.Drawing.Rectangle r)
|
||||
{
|
||||
DrawRectangle(g, color, r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(System.Drawing.Graphics g, System.Drawing.Pen pen, int x, int y, int width, int height)
|
||||
{
|
||||
// Fix for GDI issue
|
||||
width--;
|
||||
height--;
|
||||
g.DrawRectangle(pen,x,y,width,height);
|
||||
}
|
||||
public static void DrawRectangle(System.Drawing.Graphics g, System.Drawing.Pen pen, System.Drawing.Rectangle r)
|
||||
{
|
||||
DrawRectangle(g,pen,r.X,r.Y,r.Width,r.Height);
|
||||
}
|
||||
|
||||
//public static void DrawRoundedRectangle(System.Drawing.Graphics g, Color color, DevComponents.DotNetBar.Rendering.LinearGradientColorTable fillColor, Rectangle bounds, int cornerSize)
|
||||
//{
|
||||
// using (Brush fill = CreateBrush(bounds, fillColor))
|
||||
// {
|
||||
// using (Pen pen = new Pen(color))
|
||||
// DrawRoundedRectangle(g, pen, fill, bounds.X, bounds.Y, bounds.Width, bounds.Height, cornerSize);
|
||||
// }
|
||||
//}
|
||||
#if !LAYOUT
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, Color color, Color fillColor, Rectangle bounds, int cornerSize)
|
||||
{
|
||||
using (Brush fill = new SolidBrush(fillColor))
|
||||
{
|
||||
using (Pen pen = new Pen(color))
|
||||
DrawRoundedRectangle(g, pen, fill, bounds.X, bounds.Y, bounds.Width, bounds.Height, cornerSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, Color color, Rectangle bounds, int cornerSize)
|
||||
{
|
||||
if (!color.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color))
|
||||
DrawRoundedRectangle(g, pen, bounds.X, bounds.Y, bounds.Width, bounds.Height, cornerSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, Color color, int x, int y, int width, int height, int cornerSize)
|
||||
{
|
||||
if (!color.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color))
|
||||
DrawRoundedRectangle(g, pen, x, y, width, height, cornerSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, System.Drawing.Pen pen, Rectangle bounds, int cornerSize)
|
||||
{
|
||||
DrawRoundedRectangle(g, pen, bounds.X, bounds.Y, bounds.Width, bounds.Height, cornerSize);
|
||||
}
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, System.Drawing.Pen pen, int x, int y, int width, int height, int cornerSize)
|
||||
{
|
||||
DrawRoundedRectangle(g, pen, null, x, y, width, height, cornerSize);
|
||||
}
|
||||
public static void DrawRoundedRectangle(System.Drawing.Graphics g, System.Drawing.Pen pen, Brush fill, int x, int y, int width, int height, int cornerSize)
|
||||
{
|
||||
// Fix for GDI issue
|
||||
width--;
|
||||
height--;
|
||||
|
||||
Rectangle r = new Rectangle(x, y, width, height);
|
||||
|
||||
//SmoothingMode sm = g.SmoothingMode;
|
||||
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
|
||||
using (GraphicsPath path = GetRoundedRectanglePath(r, cornerSize))
|
||||
{
|
||||
if (fill != null)
|
||||
g.FillPath(fill, path);
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
|
||||
//g.SmoothingMode = sm;
|
||||
}
|
||||
|
||||
public static GraphicsPath GetRoundedRectanglePath(Rectangle r, int cornerSize)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
if (cornerSize == 0)
|
||||
path.AddRectangle(r);
|
||||
else
|
||||
{
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.TopLeft);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.TopRight);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.BottomRight);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.BottomLeft);
|
||||
path.CloseAllFigures();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static GraphicsPath GetRoundedRectanglePath(Rectangle r, int cornerTopLeft, int cornerTopRight, int cornerBottomRight, int cornerBottomLeft)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerTopLeft, eCornerArc.TopLeft);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerTopRight, eCornerArc.TopRight);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerBottomRight, eCornerArc.BottomRight);
|
||||
ElementStyleDisplay.AddCornerArc(path, r, cornerBottomLeft, eCornerArc.BottomLeft);
|
||||
path.CloseAllFigures();
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
//public static GraphicsPath GetRoundedRectanglePath(Rectangle clientRectangle, int cornerSize, eStyleBackgroundPathPart pathPart,
|
||||
// eCornerType topLeftCornerType, eCornerType topRightCornerType, eCornerType bottomLeftCornerType, eCornerType bottomRightCornerType)
|
||||
//{
|
||||
// return GetRoundedRectanglePath(clientRectangle, cornerSize, pathPart, topLeftCornerType, topRightCornerType, bottomLeftCornerType, bottomRightCornerType, 0);
|
||||
//}
|
||||
|
||||
//public static GraphicsPath GetRoundedRectanglePath(Rectangle clientRectangle, int cornerSize, eStyleBackgroundPathPart pathPart,
|
||||
// eCornerType topLeftCornerType, eCornerType topRightCornerType, eCornerType bottomLeftCornerType, eCornerType bottomRightCornerType, float partSize)
|
||||
//{
|
||||
// return GetRoundedRectanglePath(clientRectangle, cornerSize, cornerSize, cornerSize, cornerSize, pathPart, topLeftCornerType, topRightCornerType, bottomLeftCornerType, bottomRightCornerType, partSize);
|
||||
//}
|
||||
|
||||
//public static GraphicsPath GetRoundedRectanglePath(Rectangle clientRectangle, int topLeftCornerSize, int topRightCornerSize, int bottomLeftCornerSize, int bottomRightCornerSize, eStyleBackgroundPathPart pathPart,
|
||||
// eCornerType topLeftCornerType, eCornerType topRightCornerType, eCornerType bottomLeftCornerType, eCornerType bottomRightCornerType, float partSize)
|
||||
//{
|
||||
// GraphicsPath path = new GraphicsPath();
|
||||
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// {
|
||||
// if (partSize == 0)
|
||||
// clientRectangle.Height = clientRectangle.Height / 2;
|
||||
// else
|
||||
// clientRectangle.Height = (int)(clientRectangle.Height * partSize);
|
||||
// }
|
||||
// else if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// {
|
||||
// int h = clientRectangle.Height;
|
||||
// if (partSize == 0)
|
||||
// clientRectangle.Height = clientRectangle.Height / 2;
|
||||
// else
|
||||
// clientRectangle.Height = (int)(clientRectangle.Height * partSize);
|
||||
// clientRectangle.Y += (h - clientRectangle.Height - 1);
|
||||
// }
|
||||
|
||||
// eCornerType corner = topLeftCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
|
||||
// if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// corner = eCornerType.Square;
|
||||
|
||||
// if (corner == eCornerType.Rounded && topLeftCornerSize>0)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, topLeftCornerSize, eCornerArc.TopLeft);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Y + topLeftCornerSize, clientRectangle.X + topLeftCornerSize, clientRectangle.Y);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Y + 2, clientRectangle.X, clientRectangle.Y);
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Y, clientRectangle.X + 2, clientRectangle.Y);
|
||||
// }
|
||||
|
||||
// corner = topRightCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// corner = eCornerType.Square;
|
||||
// if (corner == eCornerType.Rounded && topRightCornerSize>0)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, topRightCornerSize, eCornerArc.TopRight);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right - topRightCornerSize - 1, clientRectangle.Y, clientRectangle.Right, clientRectangle.Y + topRightCornerSize);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right - 2, clientRectangle.Y, clientRectangle.Right, clientRectangle.Y);
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Y, clientRectangle.Right, clientRectangle.Y + 2);
|
||||
// }
|
||||
|
||||
// corner = bottomRightCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// corner = eCornerType.Square;
|
||||
// if (corner == eCornerType.Rounded && bottomRightCornerSize>0)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, bottomRightCornerSize, eCornerArc.BottomRight);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Bottom - bottomRightCornerSize - 1, clientRectangle.Right - bottomRightCornerSize - 1, clientRectangle.Bottom);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Bottom - 2, clientRectangle.Right, clientRectangle.Bottom);
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Bottom, clientRectangle.Right - 2, clientRectangle.Bottom);
|
||||
// }
|
||||
|
||||
// corner = bottomLeftCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// corner = eCornerType.Square;
|
||||
// if (corner == eCornerType.Rounded && bottomLeftCornerSize>0)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, bottomLeftCornerSize, eCornerArc.BottomLeft);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X + 2, clientRectangle.Bottom, clientRectangle.X, clientRectangle.Bottom - bottomLeftCornerSize - 1);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X + 2, clientRectangle.Bottom, clientRectangle.X, clientRectangle.Bottom);
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Bottom, clientRectangle.X, clientRectangle.Bottom - 2);
|
||||
// }
|
||||
|
||||
// path.CloseAllFigures();
|
||||
// return path;
|
||||
//}
|
||||
|
||||
//public static GraphicsPath GetBorderPath(Rectangle clientRectangle, int cornerSize, eStyleBackgroundPathPart pathPart,
|
||||
// eCornerType topLeftCornerType, eCornerType topRightCornerType, eCornerType bottomLeftCornerType, eCornerType bottomRightCornerType,
|
||||
// bool leftBorder, bool rightBorder, bool topBorder, bool bottomBorder)
|
||||
//{
|
||||
// GraphicsPath path = new GraphicsPath();
|
||||
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// clientRectangle.Height = clientRectangle.Height / 2;
|
||||
// else if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// {
|
||||
// int h = clientRectangle.Height;
|
||||
// clientRectangle.Height = clientRectangle.Height / 2;
|
||||
// clientRectangle.Y += (h - clientRectangle.Height - 1);
|
||||
// }
|
||||
|
||||
// eCornerType corner = topLeftCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
|
||||
// if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// corner = eCornerType.Square;
|
||||
|
||||
// if (leftBorder)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Bottom -
|
||||
// (bottomBorder && (bottomLeftCornerType == eCornerType.Diagonal || bottomLeftCornerType == eCornerType.Rounded) ? cornerSize : 0),
|
||||
// clientRectangle.X, clientRectangle.Y +
|
||||
// (topBorder && (topLeftCornerType == eCornerType.Diagonal || topLeftCornerType == eCornerType.Rounded) ? cornerSize : 0));
|
||||
// }
|
||||
|
||||
// if (leftBorder && topBorder)
|
||||
// {
|
||||
// if (corner == eCornerType.Rounded)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, cornerSize, eCornerArc.TopLeft);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X, clientRectangle.Y + cornerSize, clientRectangle.X + cornerSize, clientRectangle.Y);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (topBorder)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X +
|
||||
// ((topLeftCornerType == eCornerType.Diagonal || topLeftCornerType == eCornerType.Rounded) ? cornerSize : 0)
|
||||
// , clientRectangle.Y, clientRectangle.Right -
|
||||
// (rightBorder && (topRightCornerType == eCornerType.Diagonal || topRightCornerType == eCornerType.Rounded) ? cornerSize : 0),
|
||||
// clientRectangle.Y);
|
||||
// }
|
||||
|
||||
// corner = topRightCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.BottomHalf)
|
||||
// corner = eCornerType.Square;
|
||||
|
||||
// if (topBorder && rightBorder)
|
||||
// {
|
||||
// if (corner == eCornerType.Rounded)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, cornerSize, eCornerArc.TopRight);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right - cornerSize - 1, clientRectangle.Y, clientRectangle.Right, clientRectangle.Y + cornerSize);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (rightBorder)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Y +
|
||||
// ((topRightCornerType == eCornerType.Diagonal || topRightCornerType == eCornerType.Rounded) ? cornerSize : 0),
|
||||
// clientRectangle.Right, clientRectangle.Bottom -
|
||||
// (bottomBorder && (bottomRightCornerType == eCornerType.Diagonal || bottomRightCornerType == eCornerType.Rounded) ? cornerSize : 0));
|
||||
// }
|
||||
|
||||
// corner = bottomRightCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// corner = eCornerType.Square;
|
||||
// if (corner == eCornerType.Rounded)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, cornerSize, eCornerArc.BottomRight);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right, clientRectangle.Bottom - cornerSize - 1, clientRectangle.Right - cornerSize - 1, clientRectangle.Bottom);
|
||||
// }
|
||||
|
||||
// if (bottomBorder)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.Right -
|
||||
// ((bottomRightCornerType == eCornerType.Diagonal || bottomRightCornerType == eCornerType.Rounded) ? cornerSize : 0),
|
||||
// clientRectangle.Bottom,
|
||||
// clientRectangle.X +
|
||||
// ((bottomLeftCornerType == eCornerType.Diagonal || bottomLeftCornerType == eCornerType.Rounded) ? cornerSize : 0),
|
||||
// clientRectangle.Bottom);
|
||||
// }
|
||||
|
||||
// corner = bottomLeftCornerType;
|
||||
// if (corner == eCornerType.Inherit)
|
||||
// corner = eCornerType.Square;
|
||||
// if (pathPart == eStyleBackgroundPathPart.TopHalf)
|
||||
// corner = eCornerType.Square;
|
||||
// if (corner == eCornerType.Rounded)
|
||||
// {
|
||||
// ArcData ad = ElementStyleDisplay.GetCornerArc(clientRectangle, cornerSize, eCornerArc.BottomLeft);
|
||||
// path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
|
||||
// }
|
||||
// else if (corner == eCornerType.Diagonal)
|
||||
// {
|
||||
// path.AddLine(clientRectangle.X + 2, clientRectangle.Bottom, clientRectangle.X, clientRectangle.Bottom - cornerSize - 1);
|
||||
// }
|
||||
|
||||
// return path;
|
||||
//}
|
||||
#if !LAYOUT
|
||||
public static void FillRoundedRectangle(Graphics g, Rectangle bounds, int cornerSize, Color color1, Color color2, int gradientAngle)
|
||||
{
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (LinearGradientBrush brush = CreateLinearGradientBrush(bounds, color1, color2, gradientAngle))
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillRoundedRectangle(Graphics g, Rectangle bounds, int cornerSize, Color color1, Color color2)
|
||||
{
|
||||
FillRoundedRectangle(g, bounds, cornerSize, color1, color2, 90);
|
||||
}
|
||||
|
||||
public static void FillRoundedRectangle(Graphics g, Rectangle bounds, int cornerSize, Color color1)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize);
|
||||
}
|
||||
|
||||
public static void FillRoundedRectangle(Graphics g, Brush brush, Rectangle bounds, int cornerSize)
|
||||
{
|
||||
// Fix for GDI issue
|
||||
bounds.Width--;
|
||||
bounds.Height--;
|
||||
|
||||
using (GraphicsPath path = GetRoundedRectanglePath(bounds, cornerSize))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
public static void FillRectangle(Graphics g, Rectangle bounds, Color color1)
|
||||
{
|
||||
FillRectangle(g, bounds, color1, Color.Empty, 90);
|
||||
}
|
||||
|
||||
public static void FillRectangle(Graphics g, Rectangle bounds, Color color1, Color color2)
|
||||
{
|
||||
FillRectangle(g, bounds, color1, color2, 90);
|
||||
}
|
||||
|
||||
#if DOTNETBAR
|
||||
public static void FillRectangle(Graphics g, Rectangle r, Rendering.LinearGradientColorTable table)
|
||||
{
|
||||
FillRectangle(g, r, table.Start, table.End, table.GradientAngle);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void FillRectangle(Graphics g, Rectangle r, Color color1, Color color2, int gradientAngle)
|
||||
{
|
||||
if (r.Width == 0 || r.Height == 0)
|
||||
return;
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
g.FillRectangle(brush, r);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (LinearGradientBrush brush = CreateLinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
g.FillRectangle(brush, r);
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillRectangle(Graphics g, Rectangle r, Color color1, Color color2, int gradientAngle, float[] factors, float[] positions)
|
||||
{
|
||||
if (r.Width == 0 || r.Height == 0)
|
||||
return;
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
g.FillRectangle(brush, r);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (LinearGradientBrush brush = CreateLinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
{
|
||||
Blend blend = new Blend(factors.Length);
|
||||
blend.Factors = factors;
|
||||
blend.Positions = positions;
|
||||
brush.Blend = blend;
|
||||
g.FillRectangle(brush, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void FillPath(Graphics g, GraphicsPath path, Color color1, Color color2)
|
||||
{
|
||||
FillPath(g, path, color1, color2, 90);
|
||||
}
|
||||
|
||||
#if DOTNETBAR
|
||||
public static void FillPath(Graphics g, GraphicsPath path, Rendering.LinearGradientColorTable table)
|
||||
{
|
||||
FillPath(g, path, table.Start, table.End, table.GradientAngle);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void FillPath(Graphics g, GraphicsPath path, Color color1, Color color2, int gradientAngle)
|
||||
{
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
else if(!color1.IsEmpty)
|
||||
{
|
||||
using (LinearGradientBrush brush = CreateLinearGradientBrush(path.GetBounds(), color1, color2, gradientAngle))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
|
||||
//public static void DrawGradientLine(Graphics g, Point start, Point end, Color color1, Color color2, int gradientAngle, int penWidth)
|
||||
//{
|
||||
// if (color1.IsEmpty || penWidth <= 0 || start == end)
|
||||
// return;
|
||||
|
||||
// using (GraphicsPath path = new GraphicsPath())
|
||||
// {
|
||||
// start.Offset(-1, -1);
|
||||
// end.Offset(-1, -1);
|
||||
// path.AddLine(start, end);
|
||||
// using (Pen pen = new Pen(Color.White, penWidth))
|
||||
// path.Widen(pen);
|
||||
// Rectangle r = Rectangle.Ceiling(path.GetBounds());
|
||||
// r.Inflate(1, 1);
|
||||
// using (LinearGradientBrush brush = CreateLinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
// g.FillPath(brush, path);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static void DrawLine(Graphics g, Point start, Point end, Color color, int penWidth)
|
||||
{
|
||||
if (!color.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color, penWidth))
|
||||
g.DrawLine(pen, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawLine(Graphics g, int x1, int y1, int x2, int y2, Color color, int penWidth)
|
||||
{
|
||||
if (!color.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color, penWidth))
|
||||
g.DrawLine(pen, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
#if DOTNETBAR
|
||||
public static void DrawGradientRectangle(Graphics g, Rectangle bounds, Rendering.LinearGradientColorTable table, int penWidth)
|
||||
{
|
||||
DrawGradientRectangle(g, bounds, table.Start, table.End, table.GradientAngle, penWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void DrawGradientRectangle(Graphics g, Rectangle bounds, Color color1, Color color2, int gradientAngle, int penWidth)
|
||||
{
|
||||
if (color1.IsEmpty || bounds.Width <= 0 || bounds.Height <= 0 || penWidth <= 0)
|
||||
return;
|
||||
|
||||
Rectangle r = bounds;
|
||||
// Workaround for GDI+ bug
|
||||
r.Width--;
|
||||
r.Height--;
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
g.DrawRectangle(pen, r);
|
||||
return;
|
||||
}
|
||||
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddRectangle(r);
|
||||
|
||||
DrawGradientPath(g, path, r, color1, color2, gradientAngle, penWidth);
|
||||
}
|
||||
}
|
||||
|
||||
//public static void DrawGradientPath(Graphics g, GraphicsPath path, Rectangle bounds, Rendering.LinearGradientColorTable table, int penWidth)
|
||||
//{
|
||||
// DrawGradientPath(g, path, bounds, table.Start, table.End, table.GradientAngle, penWidth);
|
||||
//}
|
||||
|
||||
public static void DrawGradientPath(Graphics g, GraphicsPath path, Rectangle bounds, Color color1, Color color2, int gradientAngle, int penWidth)
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
path.Widen(pen);
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
else if (!color1.IsEmpty)
|
||||
{
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(bounds, color1, color2, gradientAngle))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
|
||||
#if DOTNETBAR
|
||||
public static void DrawRoundGradientRectangle(Graphics g, Rectangle bounds, Rendering.LinearGradientColorTable table, int penWidth, int roundCornerSize)
|
||||
{
|
||||
DrawRoundGradientRectangle(g, bounds, table.Start, table.End, table.GradientAngle, penWidth, roundCornerSize);
|
||||
}
|
||||
|
||||
|
||||
public static void DrawRoundGradientRectangle(Graphics g, Rectangle bounds, Color color1, Color color2, int gradientAngle, int penWidth, int roundCornerSize)
|
||||
{
|
||||
if (color1.IsEmpty && color2.IsEmpty || bounds.Width <= 0 || bounds.Height <= 0 || roundCornerSize <= 0 || penWidth <= 0)
|
||||
return;
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
DrawRoundedRectangle(g, pen, bounds, roundCornerSize);
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle r = bounds;
|
||||
// Workaround for GDI+ bug
|
||||
r.Width--;
|
||||
r.Height--;
|
||||
|
||||
using (GraphicsPath roundPath = GetRoundedRectanglePath(r, roundCornerSize))
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
roundPath.Widen(pen);
|
||||
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(bounds, color1, color2, gradientAngle))
|
||||
g.FillPath(brush, roundPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void DrawGradientPathBorder(Graphics g, GraphicsPath path, Rendering.LinearGradientColorTable table, int penWidth)
|
||||
{
|
||||
DrawGradientPathBorder(g, path, table.Start, table.End, table.GradientAngle, penWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void DrawGradientPathBorder(Graphics g, GraphicsPath path, Color color1, Color color2, int gradientAngle, int penWidth)
|
||||
{
|
||||
if (color1.IsEmpty && color2.IsEmpty) return;
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
path.Widen(pen);
|
||||
|
||||
Rectangle r = Rectangle.Ceiling(path.GetBounds());
|
||||
r.Inflate(1, 1);
|
||||
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(color1))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
else if(!color1.IsEmpty)
|
||||
{
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
#if DOTNETBAR
|
||||
public static void DrawGradientLine(Graphics g, Point start, Point end, Rendering.LinearGradientColorTable table, int penWidth)
|
||||
{
|
||||
DrawGradientLine(g, start, end, table.Start, table.End, table.GradientAngle, penWidth);
|
||||
}
|
||||
public static void DrawGradientLine(Graphics g, int x1, int y1, int x2, int y2, Rendering.LinearGradientColorTable table, int penWidth)
|
||||
{
|
||||
DrawGradientLine(g, new Point(x1, y1), new Point(x2, y2), table.Start, table.End, table.GradientAngle, penWidth);
|
||||
}
|
||||
#endif
|
||||
public static void DrawGradientLine(Graphics g, Point start, Point end, Color color1, Color color2, int gradientAngle, int penWidth)
|
||||
{
|
||||
if (color2.IsEmpty || penWidth == 1 && start.Y == end.Y && gradientAngle == 90)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
{
|
||||
g.DrawLine(pen, start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!color1.IsEmpty)
|
||||
{
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
//start.Offset(-1, -1);
|
||||
//end.Offset(-1, -1);
|
||||
path.AddLine(start, end);
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
path.Widen(pen);
|
||||
Rectangle r = Rectangle.Ceiling(path.GetBounds());
|
||||
r.Inflate(1, 1);
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.Default;
|
||||
using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
g.FillPath(brush, path);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawGradientLine(Graphics g, Point start, Point end, Color color1, Color color2, int gradientAngle, int penWidth, float[] factors, float[] positions)
|
||||
{
|
||||
if (color2.IsEmpty)
|
||||
{
|
||||
if (!color1.IsEmpty)
|
||||
{
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
g.DrawLine(pen, start, end);
|
||||
}
|
||||
}
|
||||
else if (!color1.IsEmpty)
|
||||
{
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
start.Offset(-1, -1);
|
||||
end.Offset(-1, -1);
|
||||
path.AddLine(start, end);
|
||||
using (Pen pen = new Pen(color1, penWidth))
|
||||
path.Widen(pen);
|
||||
Rectangle r = Rectangle.Ceiling(path.GetBounds());
|
||||
r.Inflate(1, 1);
|
||||
using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(r, color1, color2, gradientAngle))
|
||||
{
|
||||
Blend blend = new Blend(factors.Length);
|
||||
blend.Factors = factors;
|
||||
blend.Positions = positions;
|
||||
brush.Blend = blend;
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if DOTNETBAR
|
||||
public static Brush CreateBrush(Rectangle bounds, GradientColorTable colorBlend)
|
||||
{
|
||||
return CreateBrush(bounds, colorBlend.Colors, colorBlend.LinearGradientAngle, colorBlend.GradientType);
|
||||
}
|
||||
public static Brush CreateBrush(Rectangle bounds, DevComponents.DotNetBar.Rendering.LinearGradientColorTable colorTable)
|
||||
{
|
||||
if (colorTable.End.IsEmpty) return new SolidBrush(colorTable.Start);
|
||||
return new LinearGradientBrush(bounds, colorTable.Start, colorTable.End, colorTable.GradientAngle);
|
||||
}
|
||||
|
||||
public static Brush CreateBrush(Rectangle bounds, BackgroundColorBlendCollection colorBlend, int gradientAngle, eGradientType gradientType)
|
||||
{
|
||||
eBackgroundColorBlendType blendType = colorBlend.GetBlendType();
|
||||
if (blendType == eBackgroundColorBlendType.Invalid)
|
||||
return null;
|
||||
|
||||
if (blendType == eBackgroundColorBlendType.SolidColor)
|
||||
{
|
||||
return new SolidBrush(colorBlend[0].Color);
|
||||
}
|
||||
else if (blendType == eBackgroundColorBlendType.Relative)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (gradientType == eGradientType.Linear)
|
||||
{
|
||||
bounds.Inflate(1, 1);
|
||||
LinearGradientBrush brush =
|
||||
DisplayHelp.CreateLinearGradientBrush(bounds, colorBlend[0].Color, colorBlend[colorBlend.Count - 1].Color,
|
||||
gradientAngle);
|
||||
brush.InterpolationColors = colorBlend.GetColorBlend();
|
||||
return brush;
|
||||
}
|
||||
else if (gradientType == eGradientType.Radial)
|
||||
{
|
||||
int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) + 4;
|
||||
GraphicsPath fillPath = new GraphicsPath();
|
||||
fillPath.AddEllipse(bounds.X - (d - bounds.Width) / 2, bounds.Y - (d - bounds.Height) / 2, d, d);
|
||||
PathGradientBrush brush = new PathGradientBrush(fillPath);
|
||||
brush.CenterColor = colorBlend[0].Color;
|
||||
brush.SurroundColors = new Color[] { colorBlend[colorBlend.Count - 1].Color };
|
||||
brush.InterpolationColors = colorBlend.GetColorBlend();
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BackgroundColorBlendCollection bc = colorBlend;
|
||||
for (int i = 0; i < bc.Count; i += 2)
|
||||
{
|
||||
BackgroundColorBlend b1 = bc[i];
|
||||
BackgroundColorBlend b2 = null;
|
||||
if (i < bc.Count)
|
||||
b2 = bc[i + 1];
|
||||
if (b1 != null && b2 != null)
|
||||
{
|
||||
Rectangle rb = new Rectangle(bounds.X, bounds.Y + (int)b1.Position, bounds.Width,
|
||||
(b2.Position == 1f ? bounds.Height : (int)b2.Position) - (int)b1.Position);
|
||||
return DisplayHelp.CreateLinearGradientBrush(rb, b1.Color, b2.Color, gradientAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
public static System.Windows.Forms.ControlStyles DoubleBufferFlag
|
||||
{
|
||||
get
|
||||
{
|
||||
#if FRAMEWORK20
|
||||
return System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer;
|
||||
#else
|
||||
return System.Windows.Forms.ControlStyles.DoubleBuffer;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static TextRenderingHint s_AntiAliasTextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
public static TextRenderingHint AntiAliasTextRenderingHint
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_AntiAliasTextRenderingHint;
|
||||
}
|
||||
set
|
||||
{
|
||||
s_AntiAliasTextRenderingHint = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Rectangle[] ExcludeRectangle(Rectangle r1, Rectangle exclude)
|
||||
{
|
||||
if (r1.X >= exclude.X && exclude.Right < r1.Right) // Left aligned
|
||||
return new Rectangle[] { new Rectangle(exclude.Right, r1.Y, r1.Width - (exclude.Right - r1.X), r1.Height) };
|
||||
else if (r1.Right <= exclude.Right && exclude.X > r1.X) // Right aligned
|
||||
return new Rectangle[] { new Rectangle(r1.X, r1.Y, r1.Width - (r1.Right - exclude.X), r1.Height) };
|
||||
else if (exclude.X > r1.X && exclude.Right < r1.Right)
|
||||
{
|
||||
return new Rectangle[] { new Rectangle(r1.X, r1.Y, exclude.X-r1.X, r1.Height),
|
||||
new Rectangle(exclude.Right, r1.Y, r1.Right - exclude.Right, r1.Height)};
|
||||
}
|
||||
else if (exclude.Bottom >= r1.Bottom && exclude.Y > r1.Y) // Bottom Aligned
|
||||
{
|
||||
return new Rectangle[] { new Rectangle(r1.X, r1.Y, r1.Width, Math.Max(0, exclude.Y - r1.Y)) };
|
||||
}
|
||||
else if (exclude.Y <= r1.Y && exclude.Bottom < r1.Bottom) // Top Aligned
|
||||
{
|
||||
return new Rectangle[] { new Rectangle(r1.X, exclude.Bottom, r1.Width, r1.Bottom - exclude.Bottom) };
|
||||
}
|
||||
return new Rectangle[] { };
|
||||
}
|
||||
|
||||
internal static Size MaxSize(Size size1, Size size2)
|
||||
{
|
||||
if (size2.Width > size1.Width) size1.Width = size2.Width;
|
||||
if (size2.Height > size1.Height) size1.Height = size2.Height;
|
||||
return size1;
|
||||
}
|
||||
|
||||
internal static void ExcludeEdgeRect(ref Rectangle captionRect, Rectangle exclude)
|
||||
{
|
||||
if (exclude.X + exclude.Width / 2 < captionRect.X + captionRect.Width / 2)
|
||||
{
|
||||
// Left aligned
|
||||
int r = exclude.Right - captionRect.X;
|
||||
captionRect.X = exclude.Right;
|
||||
captionRect.Width -= r;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Right aligned
|
||||
captionRect.Width -= (captionRect.Right - exclude.X);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Div : ContainerElement
|
||||
{
|
||||
#region Private Variables
|
||||
private eParagraphAlignment m_Align = eParagraphAlignment.Left;
|
||||
private eParagraphVerticalAlignment m_VAlign = eParagraphVerticalAlignment.Top;
|
||||
private int m_Width = 0;
|
||||
private int m_Height = 0;
|
||||
private Padding m_Padding = new Padding(0, 0, 0, 0);
|
||||
private Color m_BackColor = Color.Empty;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
if (!m_BackColor.IsEmpty)
|
||||
{
|
||||
DisplayHelp.FillRectangle(d.Graphics, r, m_BackColor);
|
||||
}
|
||||
|
||||
base.Render(d);
|
||||
}
|
||||
|
||||
public eParagraphAlignment Align
|
||||
{
|
||||
get { return m_Align; }
|
||||
set { m_Align = value; }
|
||||
}
|
||||
|
||||
protected override SerialContentLayoutManager GetLayoutManager(bool multiLine)
|
||||
{
|
||||
SerialContentLayoutManager sm = base.GetLayoutManager(multiLine);
|
||||
if (m_Align == eParagraphAlignment.Left)
|
||||
sm.ContentAlignment = eContentAlignment.Left;
|
||||
else if (m_Align == eParagraphAlignment.Right)
|
||||
sm.ContentAlignment = eContentAlignment.Right;
|
||||
else if (m_Align == eParagraphAlignment.Center)
|
||||
sm.ContentAlignment = eContentAlignment.Center;
|
||||
|
||||
if (m_VAlign != eParagraphVerticalAlignment.Top)
|
||||
{
|
||||
sm.EvenHeight = false;
|
||||
sm.BlockLineAlignment = (m_VAlign == eParagraphVerticalAlignment.Bottom ? eContentVerticalAlignment.Bottom : eContentVerticalAlignment.Middle);
|
||||
}
|
||||
|
||||
return sm;
|
||||
}
|
||||
|
||||
protected override Point GetContainerOffset()
|
||||
{
|
||||
if (m_Padding.Left == 0 && m_Padding.Top == 0)
|
||||
return base.GetContainerOffset();
|
||||
|
||||
Point p = base.GetContainerOffset();
|
||||
p.X += m_Padding.Left;
|
||||
p.Y += m_Padding.Top;
|
||||
return p;
|
||||
}
|
||||
|
||||
protected override void ArrangeInternal(Rectangle bounds, MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = bounds;
|
||||
if (m_Width > 0)
|
||||
r.Width = m_Width;
|
||||
if (m_Height > 0)
|
||||
r.Height = m_Height;
|
||||
if (m_Padding.All == 0)
|
||||
{
|
||||
base.ArrangeInternal(r, d);
|
||||
if (m_Width > 0)
|
||||
this.Bounds = new Rectangle(this.Bounds.X, this.Bounds.Y, m_Width, m_Height > 0 ? m_Height : this.Bounds.Height + m_Padding.Bottom);
|
||||
else if(m_Height>0)
|
||||
this.Bounds = new Rectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width, m_Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
r.X += m_Padding.Left;
|
||||
r.Y += m_Padding.Top;
|
||||
r.Width -= m_Padding.Horizontal;
|
||||
r.Height -= m_Padding.Vertical;
|
||||
base.ArrangeInternal(r, d);
|
||||
|
||||
r = new Rectangle(bounds.X, bounds.Y, this.Bounds.Width + m_Padding.Horizontal, this.Bounds.Height + m_Padding.Vertical);
|
||||
if (m_Width > 0)
|
||||
r.Width = m_Width;
|
||||
if (m_Height > 0)
|
||||
r.Height = m_Height;
|
||||
|
||||
this.Bounds = r;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "align")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "left")
|
||||
m_Align = eParagraphAlignment.Left;
|
||||
else if (s == "right")
|
||||
m_Align = eParagraphAlignment.Right;
|
||||
else if (s == "center")
|
||||
m_Align = eParagraphAlignment.Center;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "valign")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "top")
|
||||
m_VAlign = eParagraphVerticalAlignment.Top;
|
||||
else if (s == "middle")
|
||||
m_VAlign = eParagraphVerticalAlignment.Middle;
|
||||
else if (s == "bottom")
|
||||
m_VAlign = eParagraphVerticalAlignment.Bottom;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "width")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Width = Int32.Parse(reader.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Width = 0;
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "height")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Height = Int32.Parse(reader.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Height = 0;
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "padding")
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] values = reader.Value.Split(',');
|
||||
if (values.Length > 0)
|
||||
m_Padding.Left = Int32.Parse(values[0]);
|
||||
if (values.Length > 1)
|
||||
m_Padding.Right = Int32.Parse(values[1]);
|
||||
if (values.Length > 2)
|
||||
m_Padding.Top = Int32.Parse(values[2]);
|
||||
if (values.Length > 3)
|
||||
m_Padding.Bottom = Int32.Parse(values[3]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Padding = new Padding(0,0,0,0);
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "bgcolor")
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("#"))
|
||||
{
|
||||
if (s.Length == 7)
|
||||
m_BackColor = ColorHelpers.GetColor(s.Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BackColor = Color.FromName(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_BackColor = Color.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region eParagraphAlignment
|
||||
/// <summary>
|
||||
/// Indicates paragraph content alignment
|
||||
/// </summary>
|
||||
internal enum eParagraphAlignment
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Center
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates paragraph content alignment
|
||||
/// </summary>
|
||||
internal enum eParagraphVerticalAlignment
|
||||
{
|
||||
Top,
|
||||
Middle,
|
||||
Bottom
|
||||
}
|
||||
#endregion
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class EndMarkupElement : MarkupElement
|
||||
{
|
||||
#region Internap Implementation
|
||||
private MarkupElement m_StartElement = null;
|
||||
|
||||
public EndMarkupElement(MarkupElement startElement)
|
||||
{
|
||||
m_StartElement = startElement;
|
||||
}
|
||||
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
m_StartElement.MeasureEnd(availableSize, d);
|
||||
this.Bounds = Rectangle.Empty;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
m_StartElement.RenderEnd(d);
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = Rectangle.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets reference to markup start element.
|
||||
/// </summary>
|
||||
public MarkupElement StartElement
|
||||
{
|
||||
get { return m_StartElement; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Xml;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class ExpandElement : MarkupElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
private Size m_DefaultSize = new Size(5, 4);
|
||||
private eExpandDirection m_Direction = eExpandDirection.Default;
|
||||
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = new Rectangle(Point.Empty, m_DefaultSize);
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d) { }
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
|
||||
if (!d.ClipRectangle.IsEmpty && !r.IntersectsWith(d.ClipRectangle))
|
||||
return;
|
||||
|
||||
Graphics g = d.Graphics;
|
||||
Color color = d.CurrentForeColor;
|
||||
//Color shadeColor = Color.FromArgb(96, Color.White);
|
||||
|
||||
eExpandDirection direction = eExpandDirection.Bottom;
|
||||
if (m_Direction != eExpandDirection.Default)
|
||||
direction = m_Direction;
|
||||
|
||||
#if DOTNETBAR
|
||||
if(d.ContextObject is ButtonItem)
|
||||
{
|
||||
if (m_Direction == eExpandDirection.Default)
|
||||
{
|
||||
ButtonItem item = d.ContextObject as ButtonItem;
|
||||
if (item.IsOnMenu)
|
||||
{
|
||||
direction = eExpandDirection.Right;
|
||||
if (item.PopupSide == ePopupSide.Default && d.RightToLeft || item.PopupSide == ePopupSide.Left)
|
||||
direction = eExpandDirection.Left;
|
||||
}
|
||||
else if (item.PopupSide == ePopupSide.Default)
|
||||
direction = eExpandDirection.Bottom;
|
||||
else if (item.PopupSide == ePopupSide.Left)
|
||||
direction = eExpandDirection.Left;
|
||||
else if (item.PopupSide == ePopupSide.Right)
|
||||
direction = eExpandDirection.Right;
|
||||
else if (item.PopupSide == ePopupSide.Bottom)
|
||||
direction = eExpandDirection.Bottom;
|
||||
else if (item.PopupSide == ePopupSide.Top)
|
||||
direction = eExpandDirection.Top;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
|
||||
Rectangle shadeRect = r;
|
||||
if (direction == eExpandDirection.Bottom || direction == eExpandDirection.PopupDropDown)
|
||||
shadeRect.Offset(0, 1);
|
||||
else if (direction == eExpandDirection.Top)
|
||||
shadeRect.Offset(0, -1);
|
||||
else if (direction == eExpandDirection.Left)
|
||||
shadeRect.Offset(1, 0);
|
||||
else if (direction == eExpandDirection.Right)
|
||||
shadeRect.Offset(-1, 0);
|
||||
Point[] p = GetExpandPolygon(shadeRect, direction);
|
||||
//using (SolidBrush brush = new SolidBrush(shadeColor))
|
||||
// g.FillPolygon(brush, p);
|
||||
|
||||
p = GetExpandPolygon(r, direction);
|
||||
using(SolidBrush brush = new SolidBrush(color))
|
||||
g.FillPolygon(brush, p);
|
||||
|
||||
if (direction == eExpandDirection.PopupDropDown)
|
||||
{
|
||||
using (Pen pen = new Pen(color, 1))
|
||||
g.DrawLine(pen, r.X, r.Y - 2, r.Right - 1, r.Y - 2);
|
||||
//using (Pen pen = new Pen(shadeColor, 1))
|
||||
// g.DrawLine(pen, r.X, r.Y - 1, r.Right - 1, r.Y - 1);
|
||||
}
|
||||
|
||||
g.SmoothingMode = sm;
|
||||
|
||||
this.RenderBounds = r;
|
||||
}
|
||||
|
||||
private Point[] GetExpandPolygon(Rectangle r, eExpandDirection direction)
|
||||
{
|
||||
Point[] p = new Point[3];
|
||||
switch (direction)
|
||||
{
|
||||
case eExpandDirection.Right:
|
||||
{
|
||||
p[0].X = r.Left + 1;
|
||||
p[0].Y = r.Top + (r.Height - m_DefaultSize.Height) / 2 - 1;
|
||||
p[1].X = p[0].X;
|
||||
p[1].Y = p[0].Y + 6;
|
||||
p[2].X = p[0].X + 3;
|
||||
p[2].Y = p[0].Y + 3;
|
||||
break;
|
||||
}
|
||||
case eExpandDirection.Left:
|
||||
{
|
||||
p[0].X = r.Left + 3;
|
||||
p[0].Y = r.Top + (r.Height - m_DefaultSize.Height) / 2 - 1;
|
||||
p[1].X = p[0].X;
|
||||
p[1].Y = p[0].Y + 6;
|
||||
p[2].X = p[0].X - 3;
|
||||
p[2].Y = p[0].Y + 3;
|
||||
break;
|
||||
}
|
||||
case eExpandDirection.Top:
|
||||
{
|
||||
p[0].X = r.Left - 1;
|
||||
p[0].Y = r.Top + (r.Height - m_DefaultSize.Height) / 2 + m_DefaultSize.Height;
|
||||
p[1].X = p[0].X + 6;
|
||||
p[1].Y = p[0].Y;
|
||||
p[2].X = p[0].X + 3;
|
||||
p[2].Y = p[0].Y - 4;
|
||||
break;
|
||||
}
|
||||
case eExpandDirection.Bottom:
|
||||
case eExpandDirection.PopupDropDown:
|
||||
{
|
||||
p[0].X = r.Left;
|
||||
p[0].Y = r.Top + (r.Height - m_DefaultSize.Height) / 2 + 1;
|
||||
p[1].X = p[0].X + 5;
|
||||
p[1].Y = p[0].Y;
|
||||
p[2].X = p[0].X + 2;
|
||||
p[2].Y = p[0].Y + 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
m_Direction = eExpandDirection.Default;
|
||||
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "direction")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "left")
|
||||
m_Direction = eExpandDirection.Left;
|
||||
else if (s == "right")
|
||||
m_Direction = eExpandDirection.Right;
|
||||
else if (s == "top")
|
||||
m_Direction = eExpandDirection.Top;
|
||||
else if (s == "bottom")
|
||||
m_Direction = eExpandDirection.Bottom;
|
||||
else if (s == "popup")
|
||||
m_Direction = eExpandDirection.PopupDropDown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum eExpandDirection
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom,
|
||||
Default,
|
||||
PopupDropDown
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether layout manager can start new line with this element.
|
||||
/// </summary>
|
||||
public override bool CanStartNewLine
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class FontChangeElement : MarkupElement
|
||||
{
|
||||
#region Private Variables
|
||||
protected Font m_OldFont = null;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
|
||||
public override void Measure(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = Rectangle.Empty;
|
||||
SetFont(d);
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
SetFont(d);
|
||||
}
|
||||
|
||||
protected virtual void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void RenderEnd(MarkupDrawContext d)
|
||||
{
|
||||
if(m_OldFont!=null)
|
||||
d.CurrentFont = m_OldFont;
|
||||
m_OldFont = null;
|
||||
base.RenderEnd(d);
|
||||
}
|
||||
|
||||
public override void MeasureEnd(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
if (m_OldFont != null)
|
||||
d.CurrentFont = m_OldFont;
|
||||
m_OldFont = null;
|
||||
base.MeasureEnd(availableSize, d);
|
||||
}
|
||||
protected override void ArrangeCore(Rectangle finalRect, MarkupDrawContext d) { }
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
|
||||
#if AdvTree
|
||||
using DevComponents.Tree;
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class FontElement : FontChangeElement
|
||||
{
|
||||
#region Private Variables
|
||||
private Color m_ForeColor = Color.Empty;
|
||||
private Color m_OldForeColor = Color.Empty;
|
||||
private int m_Size = 0;
|
||||
private bool m_RelativeSize = false;
|
||||
private string m_Face = "";
|
||||
private string m_SystemColorName = "";
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
protected override void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
Font font = d.CurrentFont;
|
||||
try
|
||||
{
|
||||
if (m_Face != "" || m_Size != 0 && m_RelativeSize || m_Size>4 && !m_RelativeSize)
|
||||
{
|
||||
if (m_Face != "")
|
||||
d.CurrentFont = new Font(m_Face, ((m_RelativeSize || m_Size == 0)?font.SizeInPoints + m_Size:m_Size), font.Style);
|
||||
else
|
||||
d.CurrentFont = new Font(font.FontFamily, ((m_RelativeSize || m_Size == 0)? font.SizeInPoints + m_Size : m_Size), font.Style);
|
||||
}
|
||||
else
|
||||
font = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
font = null;
|
||||
}
|
||||
|
||||
if (font != null)
|
||||
m_OldFont = font;
|
||||
|
||||
if (!d.IgnoreFormattingColors)
|
||||
{
|
||||
if (!m_ForeColor.IsEmpty)
|
||||
{
|
||||
m_OldForeColor = d.CurrentForeColor;
|
||||
d.CurrentForeColor = m_ForeColor;
|
||||
}
|
||||
else if (m_SystemColorName != "")
|
||||
{
|
||||
#if DOTNETBAR
|
||||
if (Rendering.GlobalManager.Renderer is Rendering.Office2007Renderer)
|
||||
{
|
||||
m_OldForeColor = d.CurrentForeColor;
|
||||
d.CurrentForeColor = ((Rendering.Office2007Renderer)Rendering.GlobalManager.Renderer).ColorTable.Form.Active.CaptionTextExtra;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderEnd(MarkupDrawContext d)
|
||||
{
|
||||
RestoreForeColor(d);
|
||||
|
||||
base.RenderEnd(d);
|
||||
}
|
||||
|
||||
public override void MeasureEnd(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
RestoreForeColor(d);
|
||||
base.MeasureEnd(availableSize, d);
|
||||
}
|
||||
|
||||
protected virtual void RestoreForeColor(MarkupDrawContext d)
|
||||
{
|
||||
if (d == null) return;
|
||||
if (!m_OldForeColor.IsEmpty)
|
||||
d.CurrentForeColor = m_OldForeColor;
|
||||
m_OldForeColor = Color.Empty;
|
||||
}
|
||||
|
||||
public Color ForeColor
|
||||
{
|
||||
get { return m_ForeColor; }
|
||||
set { m_ForeColor = value; }
|
||||
}
|
||||
|
||||
public int Size
|
||||
{
|
||||
get { return m_Size; }
|
||||
set { m_Size = value; }
|
||||
}
|
||||
|
||||
public string Face
|
||||
{
|
||||
get { return m_Face; }
|
||||
set { m_Face = value; }
|
||||
}
|
||||
|
||||
private Color GetColorFromName(string name)
|
||||
{
|
||||
string s = name.ToLower();
|
||||
m_SystemColorName = "";
|
||||
if (s == "syscaptiontextextra")
|
||||
{
|
||||
m_SystemColorName = s;
|
||||
return Color.Empty;
|
||||
}
|
||||
|
||||
return Color.FromName(name);
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
m_RelativeSize = false;
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "color")
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("#"))
|
||||
{
|
||||
if (s.Length == 7)
|
||||
m_ForeColor = ColorHelpers.GetColor(s.Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ForeColor = GetColorFromName(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_ForeColor = Color.Empty;
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "size")
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("+"))
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Size = Int32.Parse(s.Substring(1));
|
||||
m_RelativeSize = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Size = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s.StartsWith("-"))
|
||||
m_RelativeSize = true;
|
||||
try
|
||||
{
|
||||
m_Size = Int32.Parse(s);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "face")
|
||||
{
|
||||
m_Face = reader.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Heading: ContainerElement
|
||||
{
|
||||
#region Private Variables
|
||||
private int m_Level = 1;
|
||||
private Font m_OldFont = null;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public Heading() { }
|
||||
public Heading(int level)
|
||||
{
|
||||
m_Level = level;
|
||||
}
|
||||
|
||||
public override void Measure(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
SetFont(d);
|
||||
base.Measure(availableSize, d);
|
||||
if (m_OldFont != null)
|
||||
d.CurrentFont = m_OldFont;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
SetFont(d);
|
||||
base.Render(d);
|
||||
if (m_OldFont != null)
|
||||
d.CurrentFont = m_OldFont;
|
||||
}
|
||||
|
||||
protected virtual void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
Font font = d.CurrentFont;
|
||||
try
|
||||
{
|
||||
float size = d.CurrentFont.SizeInPoints;
|
||||
if (m_Level == 1)
|
||||
{
|
||||
size += 12;
|
||||
}
|
||||
else if (m_Level == 2)
|
||||
{
|
||||
size += 8;
|
||||
}
|
||||
else if (m_Level == 3)
|
||||
{
|
||||
size += 6;
|
||||
}
|
||||
else if (m_Level == 4)
|
||||
{
|
||||
size += 4;
|
||||
}
|
||||
else if (m_Level == 5)
|
||||
{
|
||||
size += 2;
|
||||
}
|
||||
else if (m_Level == 6)
|
||||
{
|
||||
size += 1;
|
||||
}
|
||||
|
||||
d.CurrentFont = new Font(d.CurrentFont.FontFamily, size, FontStyle.Bold);
|
||||
}
|
||||
catch
|
||||
{
|
||||
font = null;
|
||||
}
|
||||
|
||||
if (font != null)
|
||||
m_OldFont = font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets heading level. Values from 1 to 6 are valid. Default is 1.
|
||||
/// </summary>
|
||||
public int Level
|
||||
{
|
||||
get { return m_Level; }
|
||||
set { m_Level = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,249 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class HyperLink : MarkupElement, IActiveMarkupElement
|
||||
{
|
||||
#region Private Variables
|
||||
private Color m_ForeColor = Color.Empty;
|
||||
private Color m_OldForeColor = Color.Empty;
|
||||
private string m_HRef = "";
|
||||
private string m_Name = "";
|
||||
private Cursor m_OldCursor = null;
|
||||
private bool m_IsMouseOver = false;
|
||||
private bool m_Visited = false;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Measure(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = Rectangle.Empty;
|
||||
SetForeColor(d);
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
d.HyperLink = true;
|
||||
d.HyperlinkStyle = GetHyperlinkStyle();
|
||||
if (!d.HyperlinkStyle.BackColor.IsEmpty)
|
||||
{
|
||||
using (GraphicsPath gp = new GraphicsPath())
|
||||
{
|
||||
MarkupElementCollection col = this.Parent.Elements;
|
||||
int start = col.IndexOf(this) + 1;
|
||||
for (int i = start; i < col.Count; i++)
|
||||
{
|
||||
MarkupElement elem = col[i];
|
||||
if (!elem.Visible) continue;
|
||||
if (elem is EndMarkupElement && ((EndMarkupElement)elem).StartElement == this)
|
||||
break;
|
||||
gp.AddRectangle(elem.RenderBounds);
|
||||
}
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(d.HyperlinkStyle.BackColor))
|
||||
d.Graphics.FillPath(brush, gp);
|
||||
}
|
||||
}
|
||||
SetForeColor(d);
|
||||
}
|
||||
|
||||
private HyperlinkStyle GetHyperlinkStyle()
|
||||
{
|
||||
if (m_IsMouseOver && MarkupSettings.MouseOverHyperlink.IsChanged)
|
||||
return MarkupSettings.MouseOverHyperlink;
|
||||
else if (m_Visited && MarkupSettings.VisitedHyperlink.IsChanged)
|
||||
return MarkupSettings.VisitedHyperlink;
|
||||
|
||||
return MarkupSettings.NormalHyperlink;
|
||||
}
|
||||
|
||||
protected virtual void SetForeColor(MarkupDrawContext d)
|
||||
{
|
||||
Color c = Color.Empty;
|
||||
HyperlinkStyle style = GetHyperlinkStyle();
|
||||
if (style != null && !style.TextColor.IsEmpty)
|
||||
c = style.TextColor;
|
||||
|
||||
if (!m_ForeColor.IsEmpty)
|
||||
c = m_ForeColor;
|
||||
if (!c.IsEmpty)
|
||||
{
|
||||
m_OldForeColor = d.CurrentForeColor;
|
||||
d.CurrentForeColor = c;
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderEnd(MarkupDrawContext d)
|
||||
{
|
||||
RestoreForeColor(d);
|
||||
d.HyperLink = false;
|
||||
d.HyperlinkStyle = null;
|
||||
base.RenderEnd(d);
|
||||
}
|
||||
|
||||
public override void MeasureEnd(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
RestoreForeColor(d);
|
||||
base.MeasureEnd(availableSize, d);
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(Rectangle finalRect, MarkupDrawContext d) { }
|
||||
|
||||
protected virtual void RestoreForeColor(MarkupDrawContext d)
|
||||
{
|
||||
if (d == null) return;
|
||||
if (!m_OldForeColor.IsEmpty)
|
||||
d.CurrentForeColor = m_OldForeColor;
|
||||
m_OldForeColor = Color.Empty;
|
||||
}
|
||||
|
||||
public Color ForeColor
|
||||
{
|
||||
get { return m_ForeColor; }
|
||||
set { m_ForeColor = value; }
|
||||
}
|
||||
|
||||
public string HRef
|
||||
{
|
||||
get { return m_HRef; }
|
||||
set { m_HRef = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_Name; }
|
||||
set { m_Name = value; }
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "href")
|
||||
{
|
||||
m_HRef = reader.Value;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "name")
|
||||
{
|
||||
m_Name = reader.Value;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "color")
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("#"))
|
||||
{
|
||||
if (s.Length == 7)
|
||||
m_ForeColor = ColorHelpers.GetColor(s.Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ForeColor = GetColorFromName(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_ForeColor = Color.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetColorFromName(string name)
|
||||
{
|
||||
return Color.FromName(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether hyper-link contains specified coordinates.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public bool HitTest(int x, int y)
|
||||
{
|
||||
if (this.Parent == null)
|
||||
return false;
|
||||
|
||||
MarkupElementCollection col = this.Parent.Elements;
|
||||
int start = col.IndexOf(this)+1;
|
||||
for (int i = start; i < col.Count; i++)
|
||||
{
|
||||
MarkupElement el = col[i];
|
||||
if (el is EndMarkupElement && ((EndMarkupElement)el).StartElement == this)
|
||||
break;
|
||||
|
||||
if (col[i].RenderBounds.Contains(x, y))
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MouseEnter(Control parent)
|
||||
{
|
||||
m_OldCursor = parent.Cursor;
|
||||
parent.Cursor = Cursors.Hand;
|
||||
m_IsMouseOver = true;
|
||||
if (MarkupSettings.MouseOverHyperlink.IsChanged)
|
||||
{
|
||||
InvalidateElements(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void MouseLeave(Control parent)
|
||||
{
|
||||
if (m_OldCursor != null && parent!=null)
|
||||
parent.Cursor = m_OldCursor;
|
||||
m_OldCursor = null;
|
||||
m_IsMouseOver = false;
|
||||
if (MarkupSettings.MouseOverHyperlink.IsChanged)
|
||||
{
|
||||
InvalidateElements(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void MouseDown(Control parent, MouseEventArgs e) { }
|
||||
public void MouseUp(Control parent, MouseEventArgs e) { }
|
||||
public void Click(Control parent)
|
||||
{
|
||||
m_Visited = true;
|
||||
if (MarkupSettings.VisitedHyperlink.IsChanged)
|
||||
{
|
||||
InvalidateElements(parent);
|
||||
}
|
||||
}
|
||||
|
||||
private void InvalidateElements(Control parent)
|
||||
{
|
||||
if (this.Parent == null) return;
|
||||
MarkupElementCollection col = this.Parent.Elements;
|
||||
int start = col.IndexOf(this) + 1;
|
||||
for (int i = start; i < col.Count; i++)
|
||||
{
|
||||
MarkupElement elem = col[i];
|
||||
if (!elem.Visible) continue;
|
||||
if (elem is EndMarkupElement && ((EndMarkupElement)elem).StartElement == this)
|
||||
break;
|
||||
parent.Invalidate(elem.RenderBounds);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal interface IActiveMarkupElement
|
||||
{
|
||||
bool HitTest(int x, int y);
|
||||
void MouseEnter(Control parent);
|
||||
void MouseLeave(Control parent);
|
||||
void MouseDown(Control parent, MouseEventArgs e);
|
||||
void MouseUp(Control parent, MouseEventArgs e);
|
||||
void Click(Control parent);
|
||||
}
|
||||
}
|
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
using System.Reflection;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
|
||||
{
|
||||
internal class ImageElement : MarkupElement
|
||||
{
|
||||
#region Private Variables
|
||||
private Size m_ImageSize = Size.Empty;
|
||||
private string m_ImageSource = "";
|
||||
private Image m_Image = null;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
if (!m_ImageSize.IsEmpty)
|
||||
this.Bounds = new Rectangle(Point.Empty, m_ImageSize);
|
||||
else if (m_ImageSource.Length == 0)
|
||||
this.Bounds = Rectangle.Empty;
|
||||
else
|
||||
{
|
||||
Image img = this.GetImage();
|
||||
if (img != null)
|
||||
this.Bounds = new Rectangle(Point.Empty, img.Size);
|
||||
else
|
||||
this.Bounds = new Rectangle(Point.Empty, new Size(16,16));
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsBlockElement
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Image GetImage()
|
||||
{
|
||||
if (m_Image != null) return m_Image;
|
||||
Assembly a = null;
|
||||
|
||||
// Try static custom image resolver
|
||||
ResolveImageEventArgs e = new ResolveImageEventArgs();
|
||||
e.Key = m_ImageSource;
|
||||
e.ResolvedImage = null;
|
||||
MarkupSettings.InvokeResolveImage(e);
|
||||
if (e.Handled)
|
||||
return e.ResolvedImage;
|
||||
|
||||
// Load from format: ClassLibrary1/ClassLibrary1.MyImage.png or ClassLibrary1/global::ClassLibrary1.Resources.MyImage
|
||||
if (m_ImageSource.IndexOf('/') >= 0)
|
||||
{
|
||||
string[] parts = m_ImageSource.Split('/');
|
||||
a = Assembly.Load(parts[0]);
|
||||
string ResourceName = parts[1];
|
||||
if (a != null)
|
||||
{
|
||||
m_Image = LoadImageGlobalResource(parts[1], a);
|
||||
if (m_Image == null)
|
||||
m_Image = LoadImageResource(parts[1], a);
|
||||
|
||||
if (m_Image != null) return m_Image;
|
||||
}
|
||||
}
|
||||
|
||||
// Probe Executing Assembly
|
||||
a = Assembly.GetExecutingAssembly();
|
||||
m_Image = LoadImageGlobalResource(m_ImageSource, a);
|
||||
if(m_Image==null)
|
||||
m_Image = LoadImageResource(m_ImageSource, a);
|
||||
|
||||
// Probe Entry Assembly
|
||||
if (m_Image == null)
|
||||
{
|
||||
a = Assembly.GetEntryAssembly();
|
||||
m_Image = LoadImageGlobalResource(m_ImageSource, a);
|
||||
if (m_Image == null)
|
||||
m_Image = LoadImageResource(m_ImageSource, a);
|
||||
}
|
||||
|
||||
return m_Image;
|
||||
}
|
||||
|
||||
private Image LoadImageGlobalResource(string imageSource, Assembly a)
|
||||
{
|
||||
Image img = null;
|
||||
#if FRAMEWORK20
|
||||
if (imageSource.StartsWith("global::"))
|
||||
{
|
||||
string name = imageSource.Substring(8);
|
||||
if (name.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = name.LastIndexOf('.');
|
||||
string resName = name.Substring(0, i);
|
||||
name = name.Substring(i + 1);
|
||||
System.Resources.ResourceManager r = new System.Resources.ResourceManager(resName, a);
|
||||
object obj = r.GetObject(name);
|
||||
img = (Bitmap)obj;
|
||||
}
|
||||
catch
|
||||
{
|
||||
img = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return img;
|
||||
}
|
||||
|
||||
private Image LoadImageResource(string imageSource, Assembly a)
|
||||
{
|
||||
Image img = null;
|
||||
try
|
||||
{
|
||||
img = new Bitmap(a.GetManifestResourceStream(imageSource));
|
||||
}
|
||||
catch { }
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
|
||||
if (!d.ClipRectangle.IsEmpty && !r.IntersectsWith(d.ClipRectangle))
|
||||
return;
|
||||
|
||||
Image img = this.GetImage();
|
||||
if (img != null)
|
||||
{
|
||||
Rectangle imageRect = r;
|
||||
if (m_ImageSize.IsEmpty)
|
||||
imageRect.Size = img.Size;
|
||||
else
|
||||
imageRect.Size = m_ImageSize;
|
||||
d.Graphics.DrawImage(img, imageRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Color.White))
|
||||
{
|
||||
d.Graphics.FillRectangle(brush, r);
|
||||
}
|
||||
using (Pen pen = new Pen(Color.DarkGray, 1))
|
||||
{
|
||||
d.Graphics.DrawRectangle(pen, r);
|
||||
d.Graphics.DrawLine(pen, r.X, r.Y, r.Right, r.Bottom);
|
||||
d.Graphics.DrawLine(pen, r.Right, r.Y, r.X, r.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
this.RenderBounds = r;
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d) { }
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
m_ImageSize = Size.Empty;
|
||||
m_ImageSource = "";
|
||||
m_Image = null;
|
||||
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "width")
|
||||
{
|
||||
string s = reader.Value;
|
||||
m_ImageSize.Width = int.Parse(s);
|
||||
}
|
||||
else if (reader.Name.ToLower() == "height")
|
||||
{
|
||||
string s = reader.Value;
|
||||
m_ImageSize.Height = int.Parse(s);
|
||||
}
|
||||
else if (reader.Name.ToLower() == "src")
|
||||
{
|
||||
m_ImageSource = reader.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Italic : FontChangeElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
protected override void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
Font font = d.CurrentFont;
|
||||
FontStyle style=font.Style | FontStyle.Italic;
|
||||
|
||||
if (!font.Italic && d.CurrentFont.FontFamily.IsStyleAvailable(style))
|
||||
d.CurrentFont = new Font(font, style);
|
||||
else
|
||||
font = null;
|
||||
|
||||
if (font != null)
|
||||
m_OldFont = font;
|
||||
|
||||
base.SetFont(d);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
public class MarkupDrawContext
|
||||
{
|
||||
public Graphics Graphics = null;
|
||||
public Font CurrentFont = null;
|
||||
public Color CurrentForeColor = SystemColors.ControlText;
|
||||
public bool RightToLeft = false;
|
||||
public Point Offset = Point.Empty;
|
||||
public bool HyperLink = false;
|
||||
public HyperlinkStyle HyperlinkStyle = null;
|
||||
public bool Underline = false;
|
||||
public Rectangle ClipRectangle = Rectangle.Empty;
|
||||
public bool HotKeyPrefixVisible = false;
|
||||
public object ContextObject = null;
|
||||
public bool AllowMultiLine = true;
|
||||
public bool IgnoreFormattingColors = false;
|
||||
public bool StrikeOut;
|
||||
|
||||
public MarkupDrawContext(Graphics g, Font currentFont, Color currentForeColor, bool rightToLeft) : this(g, currentFont, currentForeColor, rightToLeft, Rectangle.Empty, false)
|
||||
{
|
||||
}
|
||||
|
||||
public MarkupDrawContext(Graphics g, Font currentFont, Color currentForeColor, bool rightToLeft, Rectangle clipRectangle, bool hotKeyPrefixVisible)
|
||||
{
|
||||
this.Graphics = g;
|
||||
this.CurrentFont = currentFont;
|
||||
this.CurrentForeColor = currentForeColor;
|
||||
this.RightToLeft = rightToLeft;
|
||||
this.ClipRectangle = clipRectangle;
|
||||
this.HotKeyPrefixVisible = hotKeyPrefixVisible;
|
||||
}
|
||||
|
||||
public MarkupDrawContext(Graphics g, Font currentFont, Color currentForeColor, bool rightToLeft, Rectangle clipRectangle, bool hotKeyPrefixVisible, object contextObject)
|
||||
{
|
||||
this.Graphics = g;
|
||||
this.CurrentFont = currentFont;
|
||||
this.CurrentForeColor = currentForeColor;
|
||||
this.RightToLeft = rightToLeft;
|
||||
this.ClipRectangle = clipRectangle;
|
||||
this.HotKeyPrefixVisible = hotKeyPrefixVisible;
|
||||
this.ContextObject = contextObject;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal abstract class MarkupElement : IBlockExtended
|
||||
{
|
||||
#region Private Variables
|
||||
private MarkupElementCollection m_Elements = null;
|
||||
private MarkupElement m_Parent = null;
|
||||
private Rectangle m_Bounds = Rectangle.Empty;
|
||||
private bool m_Visible = true;
|
||||
private bool m_SizeValid = false;
|
||||
private Rectangle m_RenderBounds = Rectangle.Empty;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public MarkupElement()
|
||||
{
|
||||
m_Elements = new MarkupElementCollection(this);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns whether markup element is an container so it receives full available size of parent control for layout.
|
||||
/// </summary>
|
||||
public virtual bool IsBlockContainer
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether markup element is an block element that always consumes a whole line in layout.
|
||||
/// </summary>
|
||||
public virtual bool IsBlockElement
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether layout manager switches to new line after processing this element.
|
||||
/// </summary>
|
||||
public virtual bool IsNewLineAfterElement
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether layout manager can start new line with this element.
|
||||
/// </summary>
|
||||
public virtual bool CanStartNewLine
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of child elements if any for this markup element.
|
||||
/// </summary>
|
||||
public virtual MarkupElementCollection Elements
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Elements == null)
|
||||
m_Elements = new MarkupElementCollection(this);
|
||||
return m_Elements;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InvalidateElementsSize()
|
||||
{
|
||||
this.IsSizeValid = false;
|
||||
if (m_Elements==null || m_Elements.Count == 0)
|
||||
return;
|
||||
foreach (MarkupElement e in m_Elements)
|
||||
{
|
||||
e.InvalidateElementsSize();
|
||||
e.IsSizeValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether element size is valid. When size is not valid element Measure method will be called to validate size.
|
||||
/// </summary>
|
||||
public virtual bool IsSizeValid
|
||||
{
|
||||
get { return m_SizeValid; }
|
||||
set { m_SizeValid = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets element parent or null if parent is not set.
|
||||
/// </summary>
|
||||
public virtual MarkupElement Parent
|
||||
{
|
||||
get { return m_Parent; }
|
||||
}
|
||||
|
||||
internal void SetParent(MarkupElement parent)
|
||||
{
|
||||
m_Parent = parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets actual rendering bounds.
|
||||
/// </summary>
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get { return m_Bounds; }
|
||||
set { m_Bounds = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether markup element is visible.
|
||||
/// </summary>
|
||||
public bool Visible
|
||||
{
|
||||
get { return m_Visible; }
|
||||
set { m_Visible = value; }
|
||||
}
|
||||
|
||||
private Padding _Margin = new Padding(0);
|
||||
/// <summary>
|
||||
/// Gets or sets the element margin.
|
||||
/// </summary>
|
||||
public Padding Margin
|
||||
{
|
||||
get { return _Margin; }
|
||||
set { _Margin = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures the element given available size.
|
||||
/// </summary>
|
||||
/// <param name="availableSize">Size available to element</param>
|
||||
/// <param name="g">Reference to graphics object</param>
|
||||
public abstract void Measure(Size availableSize, MarkupDrawContext d);
|
||||
|
||||
/// <summary>
|
||||
/// Measures the end tag of an element. Most implementations do not need to do anything but implementations like the ones
|
||||
/// that change color should return state back at this time.
|
||||
/// </summary>
|
||||
/// <param name="availableSize"></param>
|
||||
/// <param name="d"></param>
|
||||
public virtual void MeasureEnd(Size availableSize, MarkupDrawContext d) { }
|
||||
|
||||
/// <summary>
|
||||
/// Renders element.
|
||||
/// </summary>
|
||||
/// <param name="d">Provides markup drawing context information.</param>
|
||||
public abstract void Render(MarkupDrawContext d);
|
||||
|
||||
/// <summary>
|
||||
/// Renders element tag end. Most implementations do not need to do anything but mplementations like the ones
|
||||
/// that change color should return state back at this time.
|
||||
/// </summary>
|
||||
/// <param name="d">Provides markup drawing context information.</param>
|
||||
public virtual void RenderEnd(MarkupDrawContext d) { }
|
||||
|
||||
/// <summary>
|
||||
/// Provides final rectangle to element and lets it arrange it's content given new constraint.
|
||||
/// </summary>
|
||||
/// <param name="finalRect">Final rectangle.</param>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void ArrangeCore(Rectangle finalRect, MarkupDrawContext d);
|
||||
|
||||
/// <summary>
|
||||
/// Arranges the element given the final size. Layout is two step process with Measure followed by Arrange.
|
||||
/// </summary>
|
||||
/// <param name="finalSize"></param>
|
||||
/// <param name="g"></param>
|
||||
public void Arrange(Rectangle finalSize, MarkupDrawContext d)
|
||||
{
|
||||
this.ArrangeCore(finalSize, d);
|
||||
}
|
||||
|
||||
public virtual void ReadAttributes(XmlTextReader reader) { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets actual rendered bounds for a give markup element if applicable.
|
||||
/// </summary>
|
||||
public Rectangle RenderBounds
|
||||
{
|
||||
get { return m_RenderBounds; }
|
||||
set { m_RenderBounds = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class MarkupElementCollection : CollectionBase
|
||||
{
|
||||
#region Private Variables
|
||||
private MarkupElement m_Parent = null;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
/// <summary>Creates new instance of the class.</summary>
|
||||
public MarkupElementCollection(MarkupElement parent)
|
||||
{
|
||||
m_Parent = parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection parent element.
|
||||
/// </summary>
|
||||
public MarkupElement Parent
|
||||
{
|
||||
get { return m_Parent; }
|
||||
set { m_Parent = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds new object to the collection.
|
||||
/// </summary>
|
||||
/// <param name="MarkupElement">Object to add.</param>
|
||||
/// <returns>Index of newly added object.</returns>
|
||||
public int Add(MarkupElement MarkupElement)
|
||||
{
|
||||
return List.Add(MarkupElement);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns reference to the object in collection based on it's index.
|
||||
/// </summary>
|
||||
public MarkupElement this[int index]
|
||||
{
|
||||
get {return (MarkupElement)(List[index]);}
|
||||
set {List[index] = value;}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts new object into the collection.
|
||||
/// </summary>
|
||||
/// <param name="index">Position of the object.</param>
|
||||
/// <param name="value">Object to insert.</param>
|
||||
public void Insert(int index, MarkupElement value)
|
||||
{
|
||||
List.Insert(index, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns index of the object inside of the collection.
|
||||
/// </summary>
|
||||
/// <param name="value">Reference to the object.</param>
|
||||
/// <returns>Index of the object.</returns>
|
||||
public int IndexOf(MarkupElement value)
|
||||
{
|
||||
return List.IndexOf(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether collection contains specified object.
|
||||
/// </summary>
|
||||
/// <param name="value">Object to look for.</param>
|
||||
/// <returns>true if object is part of the collection, otherwise false.</returns>
|
||||
public bool Contains(MarkupElement value)
|
||||
{
|
||||
return List.Contains(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes specified object from the collection.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public void Remove(MarkupElement value)
|
||||
{
|
||||
List.Remove(value);
|
||||
}
|
||||
|
||||
protected override void OnRemoveComplete(int index,object value)
|
||||
{
|
||||
base.OnRemoveComplete(index,value);
|
||||
MarkupElement me=value as MarkupElement;
|
||||
if (m_Parent != null)
|
||||
{
|
||||
me.SetParent(null);
|
||||
m_Parent.IsSizeValid = false;
|
||||
}
|
||||
}
|
||||
protected override void OnInsertComplete(int index,object value)
|
||||
{
|
||||
base.OnInsertComplete(index,value);
|
||||
MarkupElement me=value as MarkupElement;
|
||||
if (m_Parent != null)
|
||||
{
|
||||
me.SetParent(m_Parent);
|
||||
m_Parent.IsSizeValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies collection into the specified array.
|
||||
/// </summary>
|
||||
/// <param name="array">Array to copy collection to.</param>
|
||||
/// <param name="index">Starting index.</param>
|
||||
public void CopyTo(MarkupElement[] array, int index)
|
||||
{
|
||||
List.CopyTo(array, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies contained items to the MarkupElement array.
|
||||
/// </summary>
|
||||
/// <param name="array">Array to copy to.</param>
|
||||
internal void CopyTo(MarkupElement[] array)
|
||||
{
|
||||
List.CopyTo(array,0);
|
||||
}
|
||||
|
||||
protected override void OnClear()
|
||||
{
|
||||
base.OnClear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class MarkupLayoutManager : BlockLayoutManager
|
||||
{
|
||||
private MarkupDrawContext m_MarkupDrawContext = null;
|
||||
|
||||
public MarkupDrawContext MarkupDrawContext
|
||||
{
|
||||
get { return m_MarkupDrawContext; }
|
||||
set { m_MarkupDrawContext = value; }
|
||||
}
|
||||
|
||||
public override void Layout(IBlock block, Size availableSize)
|
||||
{
|
||||
if (block is MarkupElement)
|
||||
{
|
||||
MarkupElement m = block as MarkupElement;
|
||||
if(!m.IsSizeValid)
|
||||
m.Measure(availableSize, m_MarkupDrawContext);
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle FinalizeLayout(Rectangle containerBounds, Rectangle blocksBounds, ArrayList lines)
|
||||
{
|
||||
return (blocksBounds);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,256 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class MarkupParser
|
||||
{
|
||||
#region Private Variables
|
||||
private static string TextElementName = "text";
|
||||
private static string BodyTag = "body";
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public static BodyElement Parse(string text)
|
||||
{
|
||||
StringBuilder plainText = new StringBuilder(text.Length);
|
||||
BodyElement root = new BodyElement();
|
||||
root.HasExpandElement = false;
|
||||
MarkupElement currentParent = root;
|
||||
Stack openTags = new Stack();
|
||||
openTags.Push(root);
|
||||
// Input text is not wrapped into the container tag so we wrap it here
|
||||
text = text.Replace(" ", "{ent_nbsp}");
|
||||
text = text.Replace("&zwsp;", "{ent_zwsp}");
|
||||
text = text.Replace("<", "{ent_lt}");
|
||||
text = text.Replace(">", "{ent_gt}");
|
||||
text = text.Replace("&", "{ent_amp}");
|
||||
text = text.Replace("|", "{ent_l}");
|
||||
text = text.Replace("&", "|");
|
||||
text = text.Replace("{ent_nbsp}", " ");
|
||||
text = text.Replace("{ent_zwsp}", "&zwsp;");
|
||||
text = text.Replace("{ent_lt}", "<");
|
||||
text = text.Replace("{ent_gt}", ">");
|
||||
StringReader sr = new StringReader("<"+BodyTag+">" + text + "</"+BodyTag+">");
|
||||
#if !DEBUG
|
||||
try
|
||||
#endif
|
||||
{
|
||||
XmlTextReader reader = new XmlTextReader(sr);
|
||||
//reader.EntityHandling = EntityHandling.ExpandCharEntities;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
if (reader.Name == BodyTag)
|
||||
continue;
|
||||
MarkupElement el = CreateMarkupElement(reader.Name);
|
||||
if (el == null)
|
||||
{
|
||||
reader.Skip();
|
||||
continue;
|
||||
}
|
||||
else if (el is ExpandElement)
|
||||
root.HasExpandElement = true;
|
||||
|
||||
if (el is IActiveMarkupElement)
|
||||
root.ActiveElements.Add(el);
|
||||
|
||||
// Parse any attributes here
|
||||
if (reader.AttributeCount > 0)
|
||||
{
|
||||
el.ReadAttributes(reader);
|
||||
reader.MoveToElement();
|
||||
}
|
||||
|
||||
currentParent.Elements.Add(el);
|
||||
|
||||
if (el is ContainerElement)
|
||||
currentParent = el;
|
||||
|
||||
if (!reader.IsEmptyElement)
|
||||
openTags.Push(el);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Text)
|
||||
{
|
||||
if (reader.Value.Length == 1)
|
||||
{
|
||||
TextElement el = CreateMarkupElement(TextElementName) as TextElement;
|
||||
if (reader.Value == " ")
|
||||
{
|
||||
el.TrailingSpace = true;
|
||||
plainText.Append(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
el.Text = reader.Value;
|
||||
el.Text = el.Text.Replace("|", "&");
|
||||
el.Text = el.Text.Replace("{ent_l}", "|");
|
||||
el.Text = el.Text.Replace("{ent_amp}", "&&");
|
||||
plainText.Append(el.Text+" ");
|
||||
}
|
||||
currentParent.Elements.Add(el);
|
||||
}
|
||||
else
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("\r\n"))
|
||||
s = s.TrimStart(new char[] { '\r', '\n' });
|
||||
s = s.Replace("\r\n", " ");
|
||||
string[] words = s.Split(' ');
|
||||
bool space = false;
|
||||
if (currentParent.Elements.Count > 0 && currentParent.Elements[currentParent.Elements.Count - 1] is NewLine)
|
||||
space = true;
|
||||
for (int i = 0; i < words.Length; i++)
|
||||
{
|
||||
if (words[i].Length == 0)
|
||||
{
|
||||
if (space)
|
||||
continue;
|
||||
space = true;
|
||||
}
|
||||
else
|
||||
space = false;
|
||||
|
||||
TextElement el = CreateMarkupElement(TextElementName) as TextElement;
|
||||
el.Text = words[i].Replace("|","&");
|
||||
el.Text = el.Text.Replace("{ent_l}", "|");
|
||||
el.Text = el.Text.Replace("{ent_amp}", "&&");
|
||||
plainText.Append(el.Text + " ");
|
||||
if (i < words.Length - 1)
|
||||
{
|
||||
el.TrailingSpace = true;
|
||||
space = true;
|
||||
}
|
||||
|
||||
currentParent.Elements.Add(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Whitespace)
|
||||
{
|
||||
if (reader.Value.IndexOf(' ') >= 0)
|
||||
{
|
||||
TextElement el = CreateMarkupElement(TextElementName) as TextElement;
|
||||
el.TrailingSpace = true;
|
||||
currentParent.Elements.Add(el);
|
||||
}
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EntityReference)
|
||||
{
|
||||
TextElement el = CreateMarkupElement(TextElementName) as TextElement;
|
||||
if (reader.Name == "nbsp")
|
||||
{
|
||||
el.TrailingSpace = true;
|
||||
}
|
||||
else if (reader.Name == "zwsp")
|
||||
{
|
||||
el.TrailingSpace = false;
|
||||
}
|
||||
else
|
||||
el.Text = reader.Name;
|
||||
el.EnablePrefixHandling = false;
|
||||
currentParent.Elements.Add(el);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EndElement)
|
||||
{
|
||||
MarkupElement el = openTags.Pop() as MarkupElement;
|
||||
if (el != currentParent)
|
||||
{
|
||||
currentParent.Elements.Add(new EndMarkupElement(el));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentParent != root)
|
||||
currentParent = currentParent.Parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if !DEBUG
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
root.PlainText = plainText.ToString();
|
||||
return root;
|
||||
}
|
||||
|
||||
public static MarkupElement CreateMarkupElement(string elementName)
|
||||
{
|
||||
if (elementName == "b" || elementName == "strong")
|
||||
return new Strong();
|
||||
else if (elementName == "i" || elementName == "em")
|
||||
return new Italic();
|
||||
else if (elementName == "u")
|
||||
return new Underline();
|
||||
else if (elementName == "br")
|
||||
return new NewLine();
|
||||
else if (elementName == "expand")
|
||||
return new ExpandElement();
|
||||
else if (elementName == "a")
|
||||
return new HyperLink();
|
||||
else if (elementName == "p")
|
||||
return new Paragraph();
|
||||
else if (elementName == "div")
|
||||
return new Div();
|
||||
else if (elementName == "span")
|
||||
return new Span();
|
||||
else if (elementName == "img")
|
||||
return new ImageElement();
|
||||
else if (elementName == "h1")
|
||||
return new Heading();
|
||||
else if (elementName == "h2")
|
||||
return new Heading(2);
|
||||
else if (elementName == "h3")
|
||||
return new Heading(3);
|
||||
else if (elementName == "h4")
|
||||
return new Heading(4);
|
||||
else if (elementName == "h5")
|
||||
return new Heading(5);
|
||||
else if (elementName == "h6")
|
||||
return new Heading(6);
|
||||
else if (elementName == "font")
|
||||
return new FontElement();
|
||||
else if (elementName == "s" || elementName == "strike")
|
||||
return new Strike();
|
||||
else if (elementName == TextElementName)
|
||||
return new TextElement();
|
||||
else if (elementName == "symbol")
|
||||
return new SymbolElement();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether input text could be markup text.
|
||||
/// </summary>
|
||||
/// <param name="text">Text to test.</param>
|
||||
/// <returns>true if text could be markup, otherwise false</returns>
|
||||
public static bool IsMarkup(ref string text)
|
||||
{
|
||||
if (text.IndexOf("</") < 0 && text.IndexOf("/>") < 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static string RemoveExpand(string text)
|
||||
{
|
||||
return Regex.Replace(text, "<expand.*?>", "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
#if FRAMEWORK20
|
||||
public static class MarkupSettings
|
||||
#else
|
||||
public class MarkupSettings
|
||||
#endif
|
||||
{
|
||||
private static HyperlinkStyle _NormalHyperlink = new HyperlinkStyle(Color.Blue, eHyperlinkUnderlineStyle.SolidLine);
|
||||
/// <summary>
|
||||
/// Gets the style of the hyperlink in its default state.
|
||||
/// </summary>
|
||||
public static HyperlinkStyle NormalHyperlink
|
||||
{
|
||||
get { return _NormalHyperlink; }
|
||||
}
|
||||
|
||||
private static HyperlinkStyle _MouseOverHyperlink = new HyperlinkStyle();
|
||||
/// <summary>
|
||||
/// Gets the style of the hyperlink when mouse is over the link.
|
||||
/// </summary>
|
||||
public static HyperlinkStyle MouseOverHyperlink
|
||||
{
|
||||
get { return _MouseOverHyperlink; }
|
||||
}
|
||||
|
||||
private static HyperlinkStyle _VisitedHyperlink = new HyperlinkStyle();
|
||||
/// <summary>
|
||||
/// Gets the style of the visited hyperlink.
|
||||
/// </summary>
|
||||
public static HyperlinkStyle VisitedHyperlink
|
||||
{
|
||||
get { return _VisitedHyperlink; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the method that will handle the ResolveImage event.
|
||||
/// </summary>
|
||||
public delegate void ResolveImageEventHandler(object sender, ResolveImageEventArgs e);
|
||||
// <summary>
|
||||
/// Occurs when DotNetBar is looking for an image for one of the internal img tags that is
|
||||
/// used within the minimarkup. You need to set Handled=true if you want your custom image
|
||||
/// to be used instead of the built-in resource resolving mechanism.
|
||||
/// </summary>
|
||||
public static event ResolveImageEventHandler ResolveImage;
|
||||
internal static void InvokeResolveImage(ResolveImageEventArgs e)
|
||||
{
|
||||
if (ResolveImage != null)
|
||||
ResolveImage(null, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the text-markup hyperlink appearance style.
|
||||
/// </summary>
|
||||
public class HyperlinkStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HyperlinkStyle class.
|
||||
/// </summary>
|
||||
public HyperlinkStyle()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HyperlinkStyle class.
|
||||
/// </summary>
|
||||
/// <param name="textColor"></param>
|
||||
/// <param name="underlineStyle"></param>
|
||||
public HyperlinkStyle(Color textColor, eHyperlinkUnderlineStyle underlineStyle)
|
||||
{
|
||||
_TextColor = textColor;
|
||||
_UnderlineStyle = underlineStyle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HyperlinkStyle class.
|
||||
/// </summary>
|
||||
/// <param name="textColor"></param>
|
||||
/// <param name="backColor"></param>
|
||||
/// <param name="underlineStyle"></param>
|
||||
public HyperlinkStyle(Color textColor, Color backColor, eHyperlinkUnderlineStyle underlineStyle)
|
||||
{
|
||||
_TextColor = textColor;
|
||||
_BackColor = backColor;
|
||||
_UnderlineStyle = underlineStyle;
|
||||
}
|
||||
private Color _TextColor = Color.Empty;
|
||||
/// <summary>
|
||||
/// Gets or sets hyperlink text color.
|
||||
/// </summary>
|
||||
public Color TextColor
|
||||
{
|
||||
get { return _TextColor; }
|
||||
set
|
||||
{
|
||||
if (_TextColor != value)
|
||||
{
|
||||
_TextColor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _BackColor = Color.Empty;
|
||||
/// <summary>
|
||||
/// Gets or sets hyperlink back color.
|
||||
/// </summary>
|
||||
public Color BackColor
|
||||
{
|
||||
get { return _BackColor; }
|
||||
set
|
||||
{
|
||||
if (_BackColor != value)
|
||||
{
|
||||
_BackColor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private eHyperlinkUnderlineStyle _UnderlineStyle = eHyperlinkUnderlineStyle.None;
|
||||
/// <summary>
|
||||
/// Gets or sets the underline style for the hyperlink.
|
||||
/// </summary>
|
||||
public eHyperlinkUnderlineStyle UnderlineStyle
|
||||
{
|
||||
get { return _UnderlineStyle; }
|
||||
set
|
||||
{
|
||||
if (_UnderlineStyle != value)
|
||||
{
|
||||
_UnderlineStyle = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether style has been changed from its default state.
|
||||
/// </summary>
|
||||
public bool IsChanged
|
||||
{
|
||||
get { return !_TextColor.IsEmpty || !_BackColor.IsEmpty || _UnderlineStyle != eHyperlinkUnderlineStyle.None; }
|
||||
}
|
||||
}
|
||||
|
||||
public enum eHyperlinkUnderlineStyle
|
||||
{
|
||||
None,
|
||||
SolidLine,
|
||||
DashedLine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Event arguments for ResolveImage event.
|
||||
/// </summary>
|
||||
public class ResolveImageEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that event has been handled and that ResolvedImage should be used.
|
||||
/// </summary>
|
||||
public bool Handled = false;
|
||||
/// <summary>
|
||||
/// Indicates the string key parameters in url-style for the image that needs to be resolved.
|
||||
/// </summary>
|
||||
public string Key = "";
|
||||
/// <summary>
|
||||
/// Indicates the resolved image value.
|
||||
/// you need to set this value to the resolved image and you need to set Handled property to true.
|
||||
/// </summary>
|
||||
public Image ResolvedImage = null;
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public ResolveImageEventArgs() { }
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class NewLine : MarkupElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
// Causes layout manager to switch to the new line
|
||||
this.Bounds = new Rectangle(0, 0, 0, d.CurrentFont.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether element size is valid. When size is not valid element Measure method will be called to validate size.
|
||||
/// </summary>
|
||||
public override bool IsSizeValid
|
||||
{
|
||||
get { return false; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d) {}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d) { }
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether layout manager switches to new line after processing this element.
|
||||
/// </summary>
|
||||
public override bool IsNewLineAfterElement
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Paragraph : Div
|
||||
{
|
||||
#region Internal Implementation
|
||||
protected override void ArrangeInternal(Rectangle bounds, MarkupDrawContext d)
|
||||
{
|
||||
base.ArrangeInternal(bounds, d);
|
||||
this.Bounds = new Rectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width , this.Bounds.Height + d.CurrentFont.Height);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
#if AdvTree
|
||||
using DevComponents.Tree;
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Span : Div
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns whether markup element is an block element that always consumes a whole line in layout.
|
||||
/// </summary>
|
||||
public override bool IsBlockElement
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Strike : MarkupElement
|
||||
{
|
||||
public override void Measure(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
Bounds = Rectangle.Empty;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
d.StrikeOut = true;
|
||||
}
|
||||
|
||||
public override void RenderEnd(MarkupDrawContext d)
|
||||
{
|
||||
d.StrikeOut = false;
|
||||
|
||||
base.RenderEnd(d);
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(Rectangle finalRect, MarkupDrawContext d)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Strong : FontChangeElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
protected override void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
Font font = d.CurrentFont;
|
||||
FontStyle style = d.CurrentFont.Style | FontStyle.Bold;
|
||||
|
||||
if (!font.Bold && font.FontFamily.IsStyleAvailable(style))
|
||||
d.CurrentFont = new Font(d.CurrentFont, style);
|
||||
else
|
||||
font = null;
|
||||
|
||||
if (font != null)
|
||||
m_OldFont = font;
|
||||
|
||||
base.SetFont(d);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Xml;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class SymbolElement : MarkupElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
private Size _DefaultSize = new Size(16, 16);
|
||||
private eSymbol _Symbol = eSymbol.XInCircle;
|
||||
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
this.Bounds = new Rectangle(Point.Empty, _DefaultSize);
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d) { }
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
|
||||
if (!d.ClipRectangle.IsEmpty && !r.IntersectsWith(d.ClipRectangle))
|
||||
return;
|
||||
|
||||
Graphics g = d.Graphics;
|
||||
Color color = d.CurrentForeColor;
|
||||
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
|
||||
if (_Symbol == eSymbol.XInCircle)
|
||||
{
|
||||
Rectangle sr = new Rectangle(r.X + (r.Width - 14) / 2, r.Y + (r.Height - 14) / 2, 14, 14);
|
||||
using (Pen pen = new Pen(color, 1.51f))
|
||||
{
|
||||
//sr.Width-=2;
|
||||
//sr.Height-=2;
|
||||
g.DrawEllipse(pen, sr);
|
||||
g.DrawLine(pen, sr.X + 4, sr.Y + 4, sr.X + 10, sr.Y + 10);
|
||||
g.DrawLine(pen, sr.X + 10, sr.Y + 4, sr.X + 4, sr.Y + 10);
|
||||
}
|
||||
}
|
||||
|
||||
g.SmoothingMode = sm;
|
||||
|
||||
this.RenderBounds = r;
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
_Symbol = eSymbol.XInCircle;
|
||||
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "type")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "xincircle")
|
||||
_Symbol = eSymbol.XInCircle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum eSymbol
|
||||
{
|
||||
XInCircle
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether layout manager can start new line with this element.
|
||||
/// </summary>
|
||||
public override bool CanStartNewLine
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Text;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class TextElement : MarkupElement
|
||||
{
|
||||
private static bool PadText = false;
|
||||
static TextElement()
|
||||
{
|
||||
string lc = System.Windows.Forms.Application.CurrentCulture.TwoLetterISOLanguageName;
|
||||
if (lc == "ja")
|
||||
PadText = true;
|
||||
}
|
||||
#region Private Variables
|
||||
private string m_Text = "";
|
||||
private bool m_TrailingSpace = false;
|
||||
private bool m_EnablePrefixHandling = true;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Measure(System.Drawing.Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
#if (FRAMEWORK20)
|
||||
if (BarUtilities.UseTextRenderer)
|
||||
{
|
||||
eTextFormat format = eTextFormat.Default | eTextFormat.NoPadding;
|
||||
if (!d.HotKeyPrefixVisible || m_EnablePrefixHandling)
|
||||
format |= eTextFormat.HidePrefix;
|
||||
Size size = Size.Empty;
|
||||
if (m_TrailingSpace)
|
||||
{
|
||||
if (d.CurrentFont.Italic)
|
||||
{
|
||||
size = Size.Ceiling(TextDrawing.MeasureString(d.Graphics, m_Text, d.CurrentFont, 0, format));
|
||||
size.Width += (int)(d.Graphics.MeasureString("||", d.CurrentFont).Width / 4);
|
||||
}
|
||||
else
|
||||
size = Size.Ceiling(TextDrawing.MeasureString(d.Graphics, m_Text + (BarFunctions.IsVista && m_Text.Length > 0 ? "|" : "||"), d.CurrentFont, 0, format));
|
||||
}
|
||||
else
|
||||
size = Size.Ceiling(TextDrawing.MeasureString(d.Graphics, m_Text, d.CurrentFont, 0, format));
|
||||
if (PadText)
|
||||
{
|
||||
size.Width += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
size.Height += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
}
|
||||
this.Bounds = new Rectangle(Point.Empty, size);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
using (StringFormat format = new StringFormat(StringFormat.GenericTypographic))
|
||||
{
|
||||
format.FormatFlags = StringFormatFlags.NoWrap;
|
||||
if (d.HotKeyPrefixVisible || !m_EnablePrefixHandling)
|
||||
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
|
||||
else
|
||||
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
|
||||
|
||||
if (m_TrailingSpace)
|
||||
{
|
||||
if (d.CurrentFont.Italic)
|
||||
{
|
||||
Size size = Size.Ceiling(d.Graphics.MeasureString(m_Text, d.CurrentFont, 0, format));
|
||||
size.Width += (int)(d.Graphics.MeasureString("|", d.CurrentFont).Width / 4);
|
||||
if (PadText)
|
||||
{
|
||||
size.Width += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
size.Height += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
}
|
||||
this.Bounds = new Rectangle(Point.Empty, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Size size = Size.Ceiling(d.Graphics.MeasureString(m_Text + "|", d.CurrentFont, 0, format));
|
||||
if (PadText)
|
||||
{
|
||||
size.Width += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
size.Height += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
}
|
||||
this.Bounds = new Rectangle(Point.Empty, size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Size size = Size.Ceiling(d.Graphics.MeasureString(m_Text, d.CurrentFont, 0, format));
|
||||
if (PadText)
|
||||
{
|
||||
size.Width += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
size.Height += BarUtilities.TextMarkupCultureSpecificPadding;
|
||||
}
|
||||
this.Bounds = new Rectangle(Point.Empty, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
IsSizeValid = true;
|
||||
}
|
||||
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
|
||||
if (!d.ClipRectangle.IsEmpty && !r.IntersectsWith(d.ClipRectangle))
|
||||
return;
|
||||
|
||||
Graphics g = d.Graphics;
|
||||
#if (FRAMEWORK20)
|
||||
if (BarUtilities.UseTextRenderer)
|
||||
{
|
||||
eTextFormat format = eTextFormat.Default | eTextFormat.NoClipping | eTextFormat.NoPadding;
|
||||
if (d.RightToLeft) format |= eTextFormat.RightToLeft;
|
||||
if (!d.HotKeyPrefixVisible)
|
||||
format |= eTextFormat.HidePrefix;
|
||||
|
||||
if (!d.ClipRectangle.IsEmpty && r.Right > d.ClipRectangle.Right)
|
||||
{
|
||||
format|= eTextFormat.EndEllipsis;
|
||||
r.Width -= (r.Right - d.ClipRectangle.Right);
|
||||
}
|
||||
TextDrawing.DrawString(g, m_Text, d.CurrentFont, d.CurrentForeColor, r, format);
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
using (StringFormat format = new StringFormat(StringFormat.GenericTypographic))
|
||||
{
|
||||
format.FormatFlags |= StringFormatFlags.NoWrap;
|
||||
if (d.RightToLeft) format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
|
||||
if (d.HotKeyPrefixVisible)
|
||||
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
|
||||
else
|
||||
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
|
||||
if (!d.ClipRectangle.IsEmpty && r.Right > d.ClipRectangle.Right)
|
||||
{
|
||||
format.Trimming = StringTrimming.EllipsisCharacter;
|
||||
r.Width -= (r.Right - d.ClipRectangle.Right);
|
||||
}
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(d.CurrentForeColor))
|
||||
g.DrawString(m_Text, d.CurrentFont, brush, r, format);
|
||||
}
|
||||
}
|
||||
|
||||
if (d.StrikeOut == true)
|
||||
{
|
||||
// StrikeOut
|
||||
|
||||
float descent = d.CurrentFont.FontFamily.GetCellDescent(d.CurrentFont.Style) *
|
||||
d.CurrentFont.Size / d.CurrentFont.FontFamily.GetEmHeight(d.CurrentFont.Style) + 1;
|
||||
|
||||
using (Pen pen = new Pen(d.CurrentForeColor, 1))
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.Default;
|
||||
|
||||
float y = r.Top + (r.Height + descent) / 2;
|
||||
|
||||
g.DrawLine(pen, r.X, y, r.Right - 1, y);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
|
||||
if ((d.HyperLink && (d.HyperlinkStyle == null || d.HyperlinkStyle.UnderlineStyle != eHyperlinkUnderlineStyle.None)) || d.Underline)
|
||||
{
|
||||
// Underline Hyperlink
|
||||
float descent = d.CurrentFont.FontFamily.GetCellDescent(d.CurrentFont.Style) * d.CurrentFont.Size / d.CurrentFont.FontFamily.GetEmHeight(d.CurrentFont.Style);
|
||||
using (Pen pen = new Pen(d.CurrentForeColor, 1))
|
||||
{
|
||||
if (d.HyperLink && d.HyperlinkStyle != null && d.HyperlinkStyle.UnderlineStyle == eHyperlinkUnderlineStyle.DashedLine)
|
||||
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
descent -= 1;
|
||||
System.Drawing.Drawing2D.SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
|
||||
g.DrawLine(pen, r.X, r.Bottom - descent, r.Right - 1, r.Bottom - descent);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
}
|
||||
|
||||
this.RenderBounds = r;
|
||||
}
|
||||
|
||||
protected override void ArrangeCore(System.Drawing.Rectangle finalRect, MarkupDrawContext d) {}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return m_Text; }
|
||||
set
|
||||
{
|
||||
m_Text = value;
|
||||
this.IsSizeValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrailingSpace
|
||||
{
|
||||
get { return m_TrailingSpace; }
|
||||
set
|
||||
{
|
||||
m_TrailingSpace = value;
|
||||
this.IsSizeValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnablePrefixHandling
|
||||
{
|
||||
get { return m_EnablePrefixHandling; }
|
||||
set { m_EnablePrefixHandling = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Underline : FontChangeElement
|
||||
{
|
||||
#region Internal Implementation
|
||||
protected override void SetFont(MarkupDrawContext d)
|
||||
{
|
||||
d.Underline = true;
|
||||
//Font font = d.CurrentFont;
|
||||
//FontStyle style = d.CurrentFont.Style | FontStyle.Underline;
|
||||
|
||||
//if (!font.Underline && font.FontFamily.IsStyleAvailable(style))
|
||||
// d.CurrentFont = new Font(font, style);
|
||||
//else
|
||||
// font = null;
|
||||
|
||||
//if (font != null)
|
||||
// m_OldFont = font;
|
||||
|
||||
base.SetFont(d);
|
||||
}
|
||||
|
||||
public override void MeasureEnd(Size availableSize, MarkupDrawContext d)
|
||||
{
|
||||
d.Underline = false;
|
||||
base.MeasureEnd(availableSize, d);
|
||||
}
|
||||
|
||||
public override void RenderEnd(MarkupDrawContext d)
|
||||
{
|
||||
d.Underline = false;
|
||||
base.RenderEnd(d);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user