This commit is contained in:
@@ -59,6 +59,11 @@ namespace Volian.Controls.Library
|
||||
get { return _vwMode; }
|
||||
set { _vwMode = value; }
|
||||
}
|
||||
private VE_Font _MyStyleFont;
|
||||
public VE_Font MyStyleFont
|
||||
{
|
||||
get { return _origDisplayText.TextFont; }
|
||||
}
|
||||
private ItemInfo _MyItemInfo;
|
||||
public ItemInfo MyItemInfo
|
||||
{
|
||||
@@ -71,12 +76,28 @@ namespace Volian.Controls.Library
|
||||
//_InitializingRTB = true;
|
||||
DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode);
|
||||
_origDisplayText = vlntxt;
|
||||
Font = _origDisplayText.TextFont.WindowsFont;
|
||||
//Font = _origDisplayText.TextFont.WindowsFont;
|
||||
|
||||
Text = ""; // Initialize text before add text
|
||||
//if (_MyStepItem.MyID == 168)
|
||||
// IMPORTANT: SetLineSpacing must be set before Link/protect, otherwise it
|
||||
// was confusing the 'handle' of the rtf box.
|
||||
RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT);
|
||||
|
||||
//SelectionStart = 1;
|
||||
AddRtfText(vlntxt);
|
||||
//AddRtfStyles();
|
||||
ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit);
|
||||
RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT);
|
||||
if (_MyStepItem.MyID == 168)
|
||||
RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT);
|
||||
if (_MyStepItem.MyID == 168)
|
||||
Console.WriteLine("After Linespacing\r\n {0}", Rtf);
|
||||
//if (((_origDisplayText.TextFont.Style & E_Style.Bold) != 0) || ((_origDisplayText.TextFont.Style & E_Style.MmBold) != 0))
|
||||
// RTBAPI.ToggleBold(true, this, RTBAPI.RTBSelection.SCF_ALL);
|
||||
//if ((_origDisplayText.TextFont.Style & E_Style.Italics) != 0)
|
||||
// RTBAPI.ToggleItalic(true, this, RTBAPI.RTBSelection.SCF_ALL);
|
||||
//if ((_origDisplayText.TextFont.Style & E_Style.Underline) != 0)
|
||||
// RTBAPI.ToggleUnderline(true, this, RTBAPI.RTBSelection.SCF_ALL);
|
||||
//_InitializingRTB = false;
|
||||
_IsDirty = false;
|
||||
ClearUndo();
|
||||
@@ -213,6 +234,7 @@ namespace Volian.Controls.Library
|
||||
if (inRoAdd)
|
||||
Console.WriteLine("SelectionStart {0}, SelectionLength {1}", SelectionStart, SelectionLength);
|
||||
if (!SelectionProtected && MyLinkText != null) MyLinkText = null;
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region ApplicationSupport
|
||||
@@ -281,6 +303,7 @@ namespace Volian.Controls.Library
|
||||
#region AddRtfTextAndStyles
|
||||
private void AddRtfText(DisplayText myDisplayText)
|
||||
{
|
||||
AddFontTable();
|
||||
foreach (displayTextElement vte in myDisplayText.DisplayTextElementList)
|
||||
{
|
||||
if (vte.Type == E_TextElementType.Text)
|
||||
@@ -290,41 +313,142 @@ namespace Volian.Controls.Library
|
||||
else
|
||||
AddRtfLink((displayLinkElement)vte);
|
||||
}
|
||||
if (_MyStepItem.MyID == 168)
|
||||
Console.WriteLine("_SelectedRtbSB\r\n {0}", _SelectedRtfSB.ToString());
|
||||
SelectedRtf = _SelectedRtfSB.ToString() + "}";
|
||||
if (_MyStepItem.MyID == 168)
|
||||
Console.WriteLine("Rtf\r\n {0}", Rtf);
|
||||
//if (_LinkPosition > -1)
|
||||
FormatLinks();
|
||||
}
|
||||
|
||||
private void FormatLinks()
|
||||
{
|
||||
if (_LinkLocations != null)
|
||||
{
|
||||
foreach (LinkLocation ll in _LinkLocations)
|
||||
{
|
||||
Select(ll.Position, ll.Length);
|
||||
|
||||
RTBAPI.CharFormatTwo charFormat = RTBAPI.GetCharFormat(this, RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
// 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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
private StringBuilder _SelectedRtfSB = new StringBuilder();
|
||||
|
||||
private void AddFontTable()
|
||||
{
|
||||
StringBuilder sbbeg = new StringBuilder();
|
||||
StringBuilder sbend = new StringBuilder();
|
||||
if (Font.Bold)
|
||||
{
|
||||
sbbeg.Append(@"\b");
|
||||
sbend.Append(@"\b0");
|
||||
}
|
||||
if (Font.Underline)
|
||||
{
|
||||
sbbeg.Append(@"\ul");
|
||||
sbend.Insert(0, @"\ulnone");
|
||||
}
|
||||
if (Font.Italic)
|
||||
{
|
||||
sbbeg.Append(@"\i");
|
||||
sbend.Insert(0, @"\i0");
|
||||
}
|
||||
_SelectedRtfSB.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 " + this.Font.FontFamily.Name + @";}"); //}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}";
|
||||
_SelectedRtfSB.Append(@"{\f1\fnil\fcharset0 Arial Unicode MS;}}");
|
||||
_SelectedRtfSB.Append("\r\n");
|
||||
// use styles to construct rtf commands to insert into next line (where \b is)
|
||||
_SelectedRtfSB.Append(@"\viewkind4\uc1\pard\sl-240\slmult0" + sbbeg.ToString() + @"\fs" + this.Font.SizeInPoints * 2 + @" "); // \f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}";
|
||||
//SelectedRtf = _SelectedRtfSB.ToString();
|
||||
}
|
||||
private void AddRtf(displayTextElement myDisplayTextElement)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 "+this.Font.FontFamily.Name+@";}}\f0\fs" + this.Font.SizeInPoints*2 + " " + myDisplayTextElement.Text + @"}}";
|
||||
// try later, i.e. adding bold to font name: SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 " + this.Font.FontFamily.Name + @",Bold;}}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}";
|
||||
//SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 " + this.Font.FontFamily.Name + @";}}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}";
|
||||
//_SelectedRtfSB.Append(@"\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text); // + @"}");
|
||||
_SelectedRtfSB.Append(@"\f0 " + myDisplayTextElement.Text); // + @"}");
|
||||
}
|
||||
private void AddRtf(string str)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 " + this.Font.FontFamily.Name + @";}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + str + @"}}";
|
||||
SelectedText = str;
|
||||
// SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 " + this.Font.FontFamily.Name + @";}}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + str + @"}}";
|
||||
}
|
||||
private void AddSymbol(displayTextElement myDisplayTextElement)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + myDisplayTextElement.Text + @"}";
|
||||
//_SelectedRtfSB.Append(@"\f1\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text);
|
||||
_SelectedRtfSB.Append(@"\f1 " + myDisplayTextElement.Text);
|
||||
//SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}";
|
||||
}
|
||||
private void AddSymbol(string str)
|
||||
{
|
||||
//MessageBox.Show(SelectedRtf);
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + /* ConvertUnicodeChar(str) */ str + @"}";
|
||||
Font selfont = this.SelectionFont;
|
||||
StringBuilder sbbeg = new StringBuilder();
|
||||
StringBuilder sbend = new StringBuilder();
|
||||
if (selfont.Bold)
|
||||
{
|
||||
sbbeg.Append(@"\b");
|
||||
sbend.Append(@"\b0");
|
||||
}
|
||||
if (selfont.Underline)
|
||||
{
|
||||
sbbeg.Append(@"\ul");
|
||||
sbend.Insert(0,@"\ulnone");
|
||||
}
|
||||
if (selfont.Italic)
|
||||
{
|
||||
sbbeg.Append(@"\i");
|
||||
sbend.Insert(0, @"\i0");
|
||||
}
|
||||
if (sbend.Length > 0) sbbeg.Append(" ");
|
||||
|
||||
// sub/superscript???
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + sbbeg.ToString() + str + sbend.ToString() + @"}";
|
||||
}
|
||||
private List<LinkLocation> _LinkLocations = null;
|
||||
private void AddLinkLocation(string location, string url)
|
||||
{
|
||||
SelectedRtf = _SelectedRtfSB.ToString() + "}";
|
||||
int linkPosition = this.TextLength;
|
||||
this.Text = "";
|
||||
if (_LinkLocations == null) _LinkLocations = new List<LinkLocation>();
|
||||
_LinkLocations.Add(new LinkLocation(linkPosition, location.Length + url.Length));
|
||||
}
|
||||
private int _LinkPosition = -1;
|
||||
private int _LinkLength;
|
||||
private void AddRtfLink(displayLinkElement myDisplayLinkElement)
|
||||
{
|
||||
if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
|
||||
AddLink50(myDisplayLinkElement.Text, myDisplayLinkElement.Link);
|
||||
else
|
||||
|
||||
AddLink20(myDisplayLinkElement.Text, myDisplayLinkElement.Link);
|
||||
{
|
||||
AddLinkLocation(myDisplayLinkElement.Text, myDisplayLinkElement.Link);
|
||||
_SelectedRtfSB.Append(@"\f0\fs20 ");
|
||||
_SelectedRtfSB.Append(myDisplayLinkElement.Text);
|
||||
_SelectedRtfSB.Append(@"\v ");
|
||||
_SelectedRtfSB.Append(myDisplayLinkElement.Link);
|
||||
_SelectedRtfSB.Append(@"\v0 ");
|
||||
//_SelectedRtfSB.Append(@"\sl-240\slmult0\f0\fs20 0POP05-EO-ES00, REDIAGNOSIS, COVER\v #Link:Transition:5 7 198\v0");
|
||||
//AddLink20(myDisplayLinkElement.Text, myDisplayLinkElement.Link);
|
||||
}
|
||||
}
|
||||
public void AddRtfLink(string linkUrl, string linkValue)
|
||||
{
|
||||
if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
//if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
|
||||
AddLink50(linkUrl, linkValue);
|
||||
else
|
||||
//AddLink50(linkUrl, linkValue);
|
||||
//else
|
||||
|
||||
AddLink20(linkUrl, linkValue);
|
||||
//AddLink20(linkUrl, linkValue);
|
||||
}
|
||||
private void AddLink20(string linkValue, string linkUrl)
|
||||
{
|
||||
@@ -332,13 +456,15 @@ namespace Volian.Controls.Library
|
||||
RTBAPI.CharFormatTwo charFormat = RTBAPI.GetCharFormat(this, RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
int position = SelectionStart; // before inserttran = this.TextLength;
|
||||
SelectionLength = 0;
|
||||
SelectedRtf = @"{\rtf1\ansi " + linkValue + @"\v " + linkUrl + @"\v0}";
|
||||
//SelectedRtf = @"{\rtf1\ansi " + linkValue + @"\v " + linkUrl + @"\v0}";
|
||||
SelectedRtf = linkValue + @"\v " + linkUrl + @"\v0";
|
||||
Select(position, linkValue.Length + linkUrl.Length);
|
||||
// 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;
|
||||
// \protect\fs20 0POP05-EO-ES00, REDIAGNOSIS, COVER\v #Link:Transition:5 7 198\protect0\v0
|
||||
this.SelectionLength = 0;
|
||||
}
|
||||
private void AddLink50(string linkValue, string linkUrl)
|
||||
@@ -355,7 +481,6 @@ namespace Volian.Controls.Library
|
||||
if ((_origDisplayText.TextFont.Style & E_Style.Bold) > 0)
|
||||
{
|
||||
this.SelectAll();
|
||||
|
||||
RTBAPI.ToggleBold(true, this, RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
this.Select(0, 0);
|
||||
}
|
||||
@@ -662,8 +787,14 @@ namespace Volian.Controls.Library
|
||||
if (e.KeyChar == '\b') return; // return on backspace otherwise, get a block char
|
||||
if (e.KeyChar == '-')
|
||||
AddSymbol(@"\u8209?");
|
||||
else if (e.KeyChar == '{')
|
||||
AddRtf("\\{");
|
||||
else if (e.KeyChar == '}')
|
||||
AddRtf("\\}");
|
||||
else if (e.KeyChar == '[')
|
||||
AddRtf(@"\b ");
|
||||
else
|
||||
AddRtf(e.KeyChar.ToString());
|
||||
return; // AddRtf(e.KeyChar.ToString());
|
||||
e.Handled = true; // flag that it's been handled, otherwise, will get 2 chars.
|
||||
}
|
||||
IsControlChar = false;
|
||||
@@ -801,4 +932,27 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#region LinkLocation Class
|
||||
internal class LinkLocation
|
||||
{
|
||||
private int _Position;
|
||||
public int Position
|
||||
{
|
||||
get { return _Position; }
|
||||
set { _Position = value; }
|
||||
}
|
||||
private int _Length;
|
||||
public int Length
|
||||
{
|
||||
get { return _Length; }
|
||||
set { _Length = value; }
|
||||
}
|
||||
|
||||
public LinkLocation(int position, int length)
|
||||
{
|
||||
_Position = position;
|
||||
_Length = length;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user