This commit is contained in:
Kathy Ruffing 2009-05-21 13:29:34 +00:00
parent 09733595f3
commit 1db9494a43

View File

@ -90,6 +90,7 @@ namespace Volian.Controls.Library
{
get { return _origDisplayText.TextFont; }
}
public bool ViewRTB = true;
private ItemInfo _MyItemInfo;
public ItemInfo MyItemInfo
{
@ -98,14 +99,23 @@ namespace Volian.Controls.Library
{
_MyItemInfo = value;
if (value != null)
{
RTBFillIn(!ViewRTB);
}
}
}
public void RTBFillIn(bool edit)
{
_InitializingRTB = true;
DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode);
_SelectedRtfSB.Remove(0, _SelectedRtfSB.Length);
DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode, !edit);
_origDisplayText = vlntxt;
#if(DEBUG)
// Use Times New Roman for Debugging
Font = new Font("Times New Roman", 14, FontStyle.Regular);
//Font = _origDisplayText.TextFont.WindowsFont;
//Font = new Font("Times New Roman", 14, FontStyle.Regular);
Font = _origDisplayText.TextFont.WindowsFont;
#elif(RELEASE)
Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format
#else //DEMO
@ -113,7 +123,6 @@ namespace Volian.Controls.Library
// UN-Comment this for testing
//Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format
#endif
Text = ""; // Initialize text before add text
// IMPORTANT: SetLineSpacing must be set before Links, otherwise it
// was confusing the 'handle' of the rtf box.
@ -124,10 +133,9 @@ namespace Volian.Controls.Library
_InitializingRTB = false;
_IsDirty = false;
ClearUndo();
RightMargin = Width;
_MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged);
}
}
}
private bool _ProcessKeystrokes = true;
public bool ProcessKeystrokes
{
@ -244,7 +252,6 @@ namespace Volian.Controls.Library
this.MouseDown += new MouseEventHandler(StepRTB_MouseDown);
this.SelectionChanged +=new EventHandler(StepRTB_SelectionChanged);
}
void MyConfig_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
SaveConfig();
@ -257,8 +264,6 @@ namespace Volian.Controls.Library
void StepRTB_SelectionChanged(object sender, EventArgs e)
{
if (_InitializingRTB) return;
//DebugSelection("SelectionChanged Event ");
if (SelectionStart == 40 && SelectionLength == 1) vlnStackTrace.ShowStack("SELECTIONCHANGED EVENT");
HandleSelectionChange();
}
private bool _MouseDown = false;
@ -285,7 +290,6 @@ namespace Volian.Controls.Library
}
public void InsertRO(string value, string link)
{
Console.WriteLine("Before Insert Called: {0}", Rtf);
AddRtfLink(value, link);
}
public void InsertTran(string value, string link)
@ -298,6 +302,56 @@ namespace Volian.Controls.Library
}
public void SetSelectedCase(char type)
{
// do not change link text
RangeStatus rs = FindRangeStatus();
if (rs == RangeStatus.NoContainedLinks)
{
Console.WriteLine("Text = {0}, Rtf = {1}", Text, Rtf);
Console.WriteLine("SelectedRtf = {0}", SelectedRtf);
switch (type)
{
case 'l':
string tmp=null;
for (int i = 0; i < SelectionLength; i++)
{
char x = SelectedText[i];
if (Char.IsLetter(x))
{
Console.WriteLine("isletter: {0}", x);
x = char.ToLower(x);
}
tmp = string.Format("{0}{1}", tmp, x.ToString());
}
Console.WriteLine("Tolower: text = {0}", tmp);
SelectedText = tmp;
Console.WriteLine("Text = {0}, Rtf = {1}", Text, Rtf);
break;
case 'U':
SelectedText = SelectedText.ToUpper();
break;
case 'T':
SelectedText = SelectedText.Substring(0, 1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower();
break;
}
}
else
{
int start = SelectionStart;
int ostart = SelectionStart;
int end = SelectionStart + SelectionLength;
StringBuilder sb = new StringBuilder();
while (start <= end)
{
bool processed = false;
foreach (LinkLocation ll in LinkLocations)
{
if (ll.Start >= start && ll.End <= end)
{
processed = true;
if (start < ll.Start)
{
SelectionStart = start;
SelectionLength = ll.Start - start;
switch (type)
{
case 'l':
@ -307,10 +361,41 @@ namespace Volian.Controls.Library
SelectedText = SelectedText.ToUpper();
break;
case 'T':
SelectedText = SelectedText.Substring(0, 1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower();
sb.Append(Text.Substring(start, ll.Start - start).Substring(0, 1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower());
break;
}
}
//sb.Append(Text.Substring(ll.Start, ll.End - ll.Start));
start = ll.End + 1;
break;
}
}
// if none were processed, no more links, copy over any remaining text.
if (!processed)
{
SelectionStart = start;
SelectionLength = end-start;
switch (type)
{
case 'l':
SelectedText = SelectedText.ToLower();
break;
case 'U':
SelectedText = SelectedText.ToUpper();
break;
case 'T':
//sb.Append(Text.Substring(start, ll.Start - start).Substring(0, 1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower());
break;
}
start = end + 1;
}
}
SelectionStart = ostart;
SelectionLength = end - ostart;
//SelectedText = sb.ToString();
//FindAllLinks();
}
}
#endregion
#region SaveData
public void SaveText()
@ -374,7 +459,7 @@ namespace Volian.Controls.Library
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(@"{\f1\fnil\fcharset0 Arial Unicode MS;}}"); // {\colortbl ;\red255\green0\blue0;}");
_SelectedRtfSB.Append("\r\n");
// use styles to construct rtf commands to insert into next line (where \b, etc is)
_SelectedRtfSB.Append(@"\viewkind4\uc1\pard\sl-240\slmult0" + sbbeg.ToString() + @"\fs" + this.Font.SizeInPoints * 2 + @" "); // \f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}";
@ -422,6 +507,7 @@ namespace Volian.Controls.Library
Select(position, 1);
RTBAPI.SetFontStyle(this, fs);
Select(position + 1, 0);
SelectionFont = _origDisplayText.TextFont.WindowsFont;
}
private string GetAddSymbolText(string symtxt)
{
@ -434,8 +520,9 @@ namespace Volian.Controls.Library
AddLink50(myDisplayLinkElement.Text, myDisplayLinkElement.Link);
else
{
_SelectedRtfSB.Append(@"\f0\fs20 ");
_SelectedRtfSB.Append(myDisplayLinkElement.TextAndLink);
//_SelectedRtfSB.Append(@"\f0\cf1 ");
_SelectedRtfSB.Append(myDisplayLinkElement.TextAndLink); //.Replace(@"\u916?",@"\f1\u916?\f0 "));
//_SelectedRtfSB.Append(@"\cf0 ");
}
}
public void AddRtfLink(string linkUrl, string linkValue)
@ -788,6 +875,7 @@ namespace Volian.Controls.Library
{
_SendBackSpace = true;
RtbSendKeys("{BS}"); // remove X
this.ClearUndo(); // undo was redisplay 'X' and then deleted text
Application.DoEvents();
DebugSelection("After BS");
}
@ -896,6 +984,8 @@ namespace Volian.Controls.Library
if (e.Shift)
{
int newstart = FindStart(); // find start of link ending on.
// if not link, don't do special processing
if (newstart == SelectionStart - 1) return;
int len = SelectionLength + SelectionStart - newstart;
SetSelection(newstart, len);
e.Handled = true;
@ -930,7 +1020,9 @@ namespace Volian.Controls.Library
}
}
else
{
HandleSelectionChange();
}
break;
case Keys.Right:
// If at beginning of box that starts with a link, don't worry about shift or not,
@ -1161,7 +1253,6 @@ namespace Volian.Controls.Library
// try adding 7 to locEnd
SetSelection(ll.Start, ll.Length + 7);
}
Console.WriteLine(string.Format("\nFindLink Start = {0}, Length = {1}\n", SelectionStart, SelectionLength));
return SelectionStart;
}
}
@ -1258,6 +1349,7 @@ namespace Volian.Controls.Library
}
private void IdentifyLinks()
{
if (_LinkLocations.Count == 0) return;
_IdentifyingLinks = true;
foreach (LinkLocation ll in _LinkLocations)
{
@ -1269,6 +1361,9 @@ namespace Volian.Controls.Library
RTBAPI.SetCharFormat(this, RTBAPI.RTBSelection.SCF_SELECTION, charFormat);
}
_IdentifyingLinks = false;
// changing selections causes 'undo' to be wrong, i.e. it highlights the last selected link.
// if there is way to pop the undo stack, that could be solution.
this.ClearUndo();
}
private LinkLocation FindBetweenLinks()
{
@ -1522,7 +1617,7 @@ namespace Volian.Controls.Library
}
private LinkLocation _RangeStartLink = null;
private LinkLocation _RangeEndLink = null;
private RangeStatus FindRangeStatus()
public RangeStatus FindRangeStatus()
{
_RangeStartLink = null;
_RangeEndLink = null;