using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Volian.Base.Library; namespace ctlXMLEditLib { public partial class roRichTextBox : RichTextBox // C2022-003 Symbols in RO Editor. Customized RichTextBox for RO Editor. { public roRichTextBox() { InitializeComponent(); } private string _RtfPrefix; // contains Font table and styles (bold/underline/italics) for rtb from step style public string RtfPrefixForSymbols { get { //B2020-100 RHM Use SelectionFont rather than the font from the format file. StringBuilder selectedRtfSB = new StringBuilder(); AddFontTable(selectedRtfSB, FormatFont, true); _RtfPrefix = selectedRtfSB.ToString(); return _RtfPrefix + @"\f1\fs" + 10 * 2 + " "; } } public void InsertSymbol( int symbcode) { int position = this.SelectionStart; string sym = string.Format(symbcode < 256 ? "\'{0:X2}" : @"\u{0}", symbcode); this.SelectedRtf = RtfPrefixForSymbols + sym + @"}"; Select(position, -1); Select(position + 1, 0); } public void rchtxtBox_KeyDown(object sender,string RO_IDEN) // C2022-003 code used to prevent a symbol from being inserted into RO ID. { bool symFlg = false; roRichTextBox o = (roRichTextBox)sender; if (o.Name == RO_IDEN) { if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { string clpBrd = Clipboard.GetText(); if (clpBrd.Any(c => c > 166)) { MessageBox.Show("Symbols are not allowed in the field. Clipbroad: '" + clpBrd + "'"); Clipboard.Clear(); } } } } private static void AddFontTable(StringBuilder selectedRtfSB, Font myFont, bool isFixed) { StringBuilder sbbeg = new StringBuilder(); StringBuilder sbend = new StringBuilder(); if (myFont.Bold) { sbbeg.Append(@"\b"); sbend.Append(@"\b0"); } if (myFont.Underline) { sbbeg.Append(@"\ul"); sbend.Insert(0, @"\ulnone"); } if (myFont.Italic) { sbbeg.Append(@"\i"); sbend.Insert(0, @"\i0"); } // RO Editor add symbols C2022-003 selectedRtfSB.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 " + myFont.FontFamily.Name + @";}"); selectedRtfSB.Append(@"{\f1\fnil\fcharset0 FreeMono;}}{\colortbl ;\red255\green0\blue0;\red0\green0\blue255;}"); // FreeMono is now used for symbols display. selectedRtfSB.Append("\r\n"); selectedRtfSB.Append(@"\viewkind4\uc1\pard" + sbbeg.ToString() + @"\fs" + Convert.ToInt32(myFont.SizeInPoints * 2).ToString() + @" "); } private Font _FormatFont; public Font FormatFont { get { if (_FormatFont == null) { Font formatFont; formatFont = Font; _FormatFont = formatFont; } return _FormatFont; } set { _FormatFont = value; } } } }