This commit is contained in:
278
PROMS/Volian.Controls.Library/DisplayRTBSimple.cs
Normal file
278
PROMS/Volian.Controls.Library/DisplayRTBSimple.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Volian.Controls.Library
|
||||
{
|
||||
public enum LinkType : int
|
||||
{
|
||||
ReferencedObject = 21,
|
||||
Transition = 9516,
|
||||
TransitionRange = 9574
|
||||
}
|
||||
public partial class DisplayRTBSimple : RichTextBox, IDisplayRTB
|
||||
{
|
||||
#region Fields
|
||||
private IContainer _Container = null;
|
||||
private ItemInfo _MyItem;
|
||||
private Size _AdjustSize;
|
||||
private Rectangle _ContentsRectangle;
|
||||
private E_EditPrintMode _EpMode;
|
||||
private string _MyClassName;
|
||||
private E_ViewMode _VwMode;
|
||||
#endregion
|
||||
#region RTB 4.1 Not being used
|
||||
//[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
//static extern IntPtr LoadLibrary(string lpFileName);
|
||||
|
||||
//protected override CreateParams CreateParams
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// CreateParams prams = base.CreateParams;
|
||||
// if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
|
||||
// {
|
||||
// //prams.ExStyle |= 0x020; // transparent
|
||||
// prams.ClassName = "RICHEDIT50W";
|
||||
// }
|
||||
// return prams;
|
||||
// }
|
||||
//}
|
||||
|
||||
//[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
//static extern IntPtr LoadLibrary(string lpFileName);
|
||||
|
||||
//protected override CreateParams CreateParams
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// CreateParams prams = base.CreateParams;
|
||||
// if (LoadLibrary("riched20.dll") != IntPtr.Zero)
|
||||
// {
|
||||
// //prams.ExStyle |= 0x020; // transparent
|
||||
// prams.ClassName = "RICHEDIT20W";
|
||||
// }
|
||||
// return prams;
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
#region Events
|
||||
public event DisplayRTBLinkEvent LinkGoTo;
|
||||
private void OnLinkGoTo(object sender,LinkClickedEventArgs args)
|
||||
{
|
||||
if (LinkGoTo != null) LinkGoTo(sender, args);
|
||||
}
|
||||
/// <summary>
|
||||
/// Occurs when a content or format change causes the box to get taller or shorter
|
||||
/// </summary>
|
||||
public event DisplayRTBEvent HeightChanged;
|
||||
/// <summary>
|
||||
/// Checks to see if the HeightChanged event is handled and launches it
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
private void OnHeightChanged(object sender, EventArgs args)
|
||||
{
|
||||
if (HeightChanged != null) HeightChanged(sender, args);
|
||||
}
|
||||
#endregion
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// ItemInfo object associated with the control
|
||||
/// </summary>
|
||||
/// <param name="match"></param>
|
||||
/// <returns></returns>
|
||||
public ItemInfo MyItem
|
||||
{
|
||||
get { return _MyItem; }
|
||||
set
|
||||
{
|
||||
_MyItem = value;
|
||||
if (value != null)
|
||||
{
|
||||
//// TIMING: vlnCSLARTB.TimeIt("rtbMyItem Start");
|
||||
//if (value.ItemID == 90)
|
||||
// if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat(value.MyContent.Text);
|
||||
string txt = _MyItem.MyContent.Text;
|
||||
txt = txt.Replace("\n", "\r\n\\par ");
|
||||
//txt = Regex.Replace(txt, "(.){([0-9]*){([0-9 ]*)}}",FixTransition);
|
||||
//txt = Regex.Replace(txt, @"(.)\\v TRAN", FixTransition);
|
||||
MatchCollection mc = Regex.Matches(txt, @"(.)\\v (TRAN|RO)\\v0 ([^\\]*)\\v ([^\\]*)\\v0");
|
||||
//string[] parts = Regex.Split(txt, "(.){{(.*)}{(.*)}}");
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
int lastIndex = 0;
|
||||
foreach (Match m in mc)
|
||||
{
|
||||
if(m.Index > lastIndex) AddRtf(txt.Substring(lastIndex,m.Index - lastIndex));
|
||||
string linkUrl = "Link:" + ((LinkType)Convert.ToInt32(m.Groups[1].Value[0])).ToString() + ":" + m.Groups[4].Value;
|
||||
string linkValue = (m.Groups[2].Value == "TRAN" ? FixTransition(m) : m.Groups[3].Value);
|
||||
if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
AddLink50(linkUrl, linkValue);
|
||||
else
|
||||
AddLink20(linkUrl, linkValue);
|
||||
//AddRtf(string.Format("{0} \\v RO - {1} \\v0",ROValue,ROID));
|
||||
lastIndex = m.Index + m.Length;
|
||||
}
|
||||
AddRtf(txt.Substring(lastIndex, txt.Length - lastIndex));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddRtf(txt);
|
||||
}
|
||||
//// TIMING: vlnCSLARTB.TimeIt("rtbMyItem End");
|
||||
}
|
||||
}
|
||||
}
|
||||
public Size AdjustSize
|
||||
{
|
||||
get { return _AdjustSize; }
|
||||
set { _AdjustSize = value; }
|
||||
}
|
||||
public Rectangle ContentsRectangle
|
||||
{
|
||||
get { return _ContentsRectangle; }
|
||||
set { _ContentsRectangle = value; }
|
||||
}
|
||||
public E_EditPrintMode EpMode
|
||||
{
|
||||
get { return _EpMode; }
|
||||
set { _EpMode = value; }
|
||||
}
|
||||
public string MyClassName
|
||||
{
|
||||
get { return _MyClassName; }
|
||||
set { _MyClassName = value; }
|
||||
}
|
||||
public E_ViewMode VwMode
|
||||
{
|
||||
get { return _VwMode; }
|
||||
set { _VwMode = value; }
|
||||
}
|
||||
#endregion
|
||||
#region Private Methods
|
||||
private string FixTransition(Match match)
|
||||
{
|
||||
//int transitionID = Convert.ToInt32(match.Groups[2].Value);
|
||||
int transitionID = Convert.ToInt32(match.Groups[4].Value.Split(" ".ToCharArray())[1]);
|
||||
// Find the transition
|
||||
foreach (TransitionInfo ti in _MyItem.MyContent.ContentTransitions)
|
||||
{
|
||||
if (ti.TransitionID == transitionID)
|
||||
{
|
||||
string path = ti.PathTo.Replace(" Section PROCEDURE STEPS ", ", ");
|
||||
path = path.Replace(" Section PROCEDURE STEPS", "");
|
||||
return path;
|
||||
}
|
||||
}
|
||||
return match.Value;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds the text and hypertext link and sets the style to link
|
||||
/// </summary>
|
||||
/// <param name="linkUrl">URL - Uniform Resource Locator (Address)</param>
|
||||
/// <param name="linkValue">Text descibing location</param>
|
||||
private void AddLink20(string linkUrl, string linkValue)
|
||||
{
|
||||
this.DetectUrls = false;
|
||||
RTBAPI.CharFormatTwo charFormat = RTBAPI.GetCharFormat(this, RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
int position = SelectionStart = this.TextLength;
|
||||
SelectionLength = 0;
|
||||
SelectedRtf = @"{\rtf1\ansi " + linkValue + @"\v #" + linkUrl + @"\v0}";
|
||||
Select(position, linkValue.Length + linkUrl.Length + 1);
|
||||
// Protect the link text to avoid manual changes
|
||||
charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED;
|
||||
charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED;
|
||||
RTBAPI.SetCharFormat((RichTextBox)this, RTBAPI.RTBSelection.SCF_SELECTION, charFormat);
|
||||
this.SelectionStart = this.TextLength;
|
||||
this.SelectionLength = 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a hypertext link to the Rich Text
|
||||
/// </summary>
|
||||
/// <param name="linkUrl">URL - Uniform Resource Locator (Address)</param>
|
||||
/// <param name="linkValue">Text descibing location</param>
|
||||
private void AddLink50(string linkUrl, string linkValue)
|
||||
{
|
||||
this.DetectUrls = false;
|
||||
int position = SelectionStart = this.TextLength;
|
||||
SelectionLength = 0;
|
||||
SelectedRtf = string.Format(@"{{\rtf\field{{\*\fldinst{{HYPERLINK ""www.volian.com #{0}"" }}}}{{\fldrslt{{\cf2\ul {1}}}}}}}", linkUrl, linkValue);
|
||||
this.SelectionStart = this.TextLength;
|
||||
this.SelectionLength = 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds Rich Text
|
||||
/// </summary>
|
||||
/// <param name="rtf">this is any text and can include RTF commands or not</param>
|
||||
private void AddRtf(string rtf)
|
||||
{
|
||||
this.SelectedRtf = @"{\rtf1 " + rtf + "}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Used by the constructors to do any standard configuration
|
||||
/// </summary>
|
||||
private void SetUp()
|
||||
{
|
||||
BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.DetectUrls = true;
|
||||
//ContextMenuStrip = this.contextMenuStrip1;
|
||||
//ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
|
||||
//this.TextChanged += new EventHandler(VERichTextBox_TextChanged);
|
||||
this.ContentsResized += new ContentsResizedEventHandler(VERichTextBox_ContentsResized);
|
||||
//if (Text != "") ResizeForText();
|
||||
this.LinkClicked += new LinkClickedEventHandler(DisplayRTBSimple_LinkClicked);
|
||||
}
|
||||
|
||||
void DisplayRTBSimple_LinkClicked(object sender, LinkClickedEventArgs e)
|
||||
{
|
||||
OnLinkGoTo(sender, e);
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public DisplayRTBSimple()
|
||||
{
|
||||
InitializeComponent();
|
||||
SetUp();
|
||||
}
|
||||
public DisplayRTBSimple(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
_Container = container;
|
||||
SetUp();
|
||||
}
|
||||
#endregion
|
||||
#region Event Handlers
|
||||
void VERichTextBox_ContentsResized(object sender, ContentsResizedEventArgs e)
|
||||
{
|
||||
this.Height = e.NewRectangle.Height;
|
||||
OnHeightChanged(sender, new EventArgs());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public interface IDisplayRTB
|
||||
{
|
||||
event DisplayRTBEvent HeightChanged;
|
||||
ItemInfo MyItem { get; }
|
||||
Size AdjustSize { get; set; }
|
||||
Rectangle ContentsRectangle { get; set; }
|
||||
E_EditPrintMode EpMode { get; set; }
|
||||
string MyClassName { get; set; }
|
||||
E_ViewMode VwMode { get; set; }
|
||||
// In addition to the HeightChanged event and the MyItem property
|
||||
// the constructors below should be created
|
||||
// public DisplayRTBSimple()
|
||||
// public DisplayRTBSimple(IContainer container)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user