From 1db9494a43091bed3d558bc689fadc7db658a6cb Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 21 May 2009 13:29:34 +0000 Subject: [PATCH] --- PROMS/Volian.Controls.Library/StepRTB.cs | 189 +++++++++++++++++------ 1 file changed, 142 insertions(+), 47 deletions(-) diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index fa331c5b..62e64eeb 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -90,6 +90,7 @@ namespace Volian.Controls.Library { get { return _origDisplayText.TextFont; } } + public bool ViewRTB = true; private ItemInfo _MyItemInfo; public ItemInfo MyItemInfo { @@ -99,35 +100,42 @@ namespace Volian.Controls.Library _MyItemInfo = value; if (value != null) { - _InitializingRTB = true; - DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode); - _origDisplayText = vlntxt; -#if(DEBUG) - // Use Times New Roman for Debugging - 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 - // Comment this out for DEMO to customer - // 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. - RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT); - AddRtfText(vlntxt); - AddRtfStyles(); - ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit); - _InitializingRTB = false; - _IsDirty = false; - ClearUndo(); - _MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged); + RTBFillIn(!ViewRTB); } } } + + public void RTBFillIn(bool edit) + { + _InitializingRTB = true; + _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; +#elif(RELEASE) + Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format +#else //DEMO + // Comment this out for DEMO to customer + // 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. + RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT); + AddRtfText(vlntxt); + AddRtfStyles(); + ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit); + _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,17 +302,98 @@ namespace Volian.Controls.Library } public void SetSelectedCase(char type) { - switch (type) + // do not change link text + RangeStatus rs = FindRangeStatus(); + if (rs == RangeStatus.NoContainedLinks) { - case 'l': - SelectedText = SelectedText.ToLower(); - break; - case 'U': - SelectedText = SelectedText.ToUpper(); - break; - case 'T': - SelectedText = SelectedText.Substring(0, 1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower(); - break; + 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': + 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; + } + } + //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 @@ -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) @@ -787,7 +874,8 @@ namespace Volian.Controls.Library if (key == 0) { _SendBackSpace = true; - RtbSendKeys("{BS}"); // remove X + 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; @@ -916,7 +1006,7 @@ namespace Volian.Controls.Library e.Handled = true; } // if shift-up & at selection had a link, handle this as special case. - if (e.Shift && SelectionLength>0) + if (e.Shift && SelectionLength > 0) { RangeStatus rs = FindRangeStatus(); if (rs != RangeStatus.NoContainedLinks) @@ -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;