This commit is contained in:
John Jenko 2011-04-15 14:45:39 +00:00
parent ee90d4d732
commit 6ac65a51a3
4 changed files with 495 additions and 795 deletions

View File

@ -341,6 +341,7 @@ namespace DataLoader
}
private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)");
private string ConvertTableToGrid(string stepText, Content content, FormatInfo fmt, bool isROTable)
{
string savethis = stepText;
@ -350,48 +351,6 @@ namespace DataLoader
VE_Font vefont = fmt.PlantFormat.FormatData.StepDataList.Table.Font;
Font GridFont = new Font(vefont.Family, (float)vefont.Size);
grd.Font = GridFont; // this also changes the default Row Height "Rows.DefaultSize"
stepText = FixStepText(stepText);
stepText = stepText.Replace(@"\u8209?", "-");
stepText = stepText.Replace(@"\u9474?", "\xB3"); // Vert Line graphic character
stepText = stepText.Replace(@"\'b0", "\xB0");
stepText = stepText.Replace(@"\up2 ", "\x9566");
stepText = stepText.Replace(@"\up0 ", "\x9567");
stepText = stepText.Replace(@"\ulnone", "\xBB");
stepText = stepText.Replace(@"\ul", "\xAB");
stepText = stepText.Replace(@"\{", "{");
stepText = stepText.Replace(@"\}", "}");
stepText = stepText.Replace(@"\b0", "\xD6");
stepText = stepText.Replace(@"\b", "\xD5");
stepText = stepText.Replace(@"\u160?", "\xA0"); //hard space
stepText = stepText.Replace(@"\u916?", "\x7F"); // delta
stepText = stepText.Replace(@"\u8805?", "\xF2"); //greater than or equal
stepText = stepText.Replace(@"\u8804?", "\xF3"); // less than or equal
stepText = stepText.Replace(@"\u931?", "\xE4"); // sigma
stepText = stepText.Replace(@"\u947?", "\xE7"); // gamma
stepText = stepText.Replace(@"\u9604?", "\xFE"); // accum 2584
stepText = stepText.Replace(@"\u9679?", "\x7"); // bullet 25CF
stepText = stepText.Replace(@"\u8776?", "\xF7"); // approx eq
stepText = stepText.Replace(@"\u8773?", "\xF0"); // similar eq 2245
stepText = stepText.Replace(@"\u8730?", "\xFB"); // square root
stepText = stepText.Replace(@"\u961?", "\xE2"); // rho 3C1
stepText = stepText.Replace(@"\u960?", "\xE3"); // pi
stepText = stepText.Replace(@"\u956?", "\xE6"); // micro
stepText = stepText.Replace(@"\u948?", "\xEB"); // lower case delta
stepText = stepText.Replace(@"\u963?", "\xE5"); // lower case sigma
stepText = stepText.Replace(@"\u274?", "\x90"); // energy, 112
stepText = stepText.Replace(@"\u949?", "\xEE"); // epsilon
stepText = stepText.Replace(@"\u952?", "\xE9"); // theta, 3B8
stepText = stepText.Replace(@"\u8857?", "\xEC"); // dot in oval, 2299
stepText = stepText.Replace(@"\u964?", "\xA8"); // tau, 3C4
stepText = stepText.Replace(@"\u9830?", "\xA9"); // diamond, 2666
stepText = stepText.Replace(@"\u8593?", "\x18"); // Up Arrow - changes to \xff
stepText = stepText.Replace(@"\u8595?", "\x19"); // Down Arrow - changes to \xd6
//Console.WriteLine("B4 Parse Orig Text: '{0}'", savethis);
//Console.WriteLine("B4 Parse sym repl: '{0}'", stepText);
if (grd.IsRoTable)
grd.ParseTableFromText(_RemoveComments.Replace(stepText, ""));
else
grd.ParseTableFromText(stepText);
grd.AutoSizeCols();
grd.AutoSizeRows();
@ -407,23 +366,7 @@ namespace DataLoader
}
return strGrid;
}
//private void FixSymbolsInGridTable(Content content, ItemInfo ii)
//{
// VlnFlexGrid grd = new VlnFlexGrid(1, 1);
// using (TextReader stringreader = new StringReader(content.MyGrid.Data))
// {
// grd.ReadXml(stringreader);
// stringreader.Close();
// }
// for (int r = 0; r < grd.Rows.Count; r++)
// for (int c = 0; c < grd.Cols.Count; c++)
// {
// StepRTB trtb = new StepRTB();
// trtb = grd[r, c];
// DisplayText dt = new DisplayText(trtb.Rtf, true);
// grd[r, c] = dt.OriginalText;
// }
//}
private bool IsATable(int? contenttype)
{
bool rtnval = false;

View File

@ -290,12 +290,13 @@ namespace Volian.Controls.Library
{
if (MyFlexGrid.IsRoTable)
{
MyFlexGrid.MergedRanges.Clear();
MyFlexGrid.Clear();
ConvertTableToGrid(args.RawValText);
MyFlexGrid.RODbId = args.RODbID;
MyFlexGrid.ROID = args.ROID;
SaveContents();
MyFlexGrid.ConvertTableROToGrid(args.ValText, args.RODbID, args.ROID);
//MyFlexGrid.MergedRanges.Clear();
//MyFlexGrid.Clear();
//ConvertTableToGrid(args.RawValText, args.RODbID, args.ROID);
//MyFlexGrid.RODbId = args.RODbID;
//MyFlexGrid.ROID = args.ROID;
//SaveContents();
}
else
MyStepRTB.UpdateStepRtb(args.LinkText, args.ValText);
@ -498,17 +499,23 @@ namespace Volian.Controls.Library
MyItemInfo.MyContent.RefreshContentRoUsages();
return string.Format(@"#Link:ReferencedObject:{0} {1} {2}", rousg.ROUsageID, MyFlexGrid.ROID, MyFlexGrid.RODbId);
}
private void ConvertTableToGrid(string valtext)
{
VE_Font vefont = MyItemInfo.GetItemFont();
MyFlexGrid.Font = vefont.WindowsFont;
Initializing = true;
MyFlexGrid.ParseTableFromText(valtext);
MyFlexGrid.AutoSizeCols();
MyFlexGrid.AutoSizeRows();
MyFlexGrid.MakeRTFcells();
Initializing = false;
}
//private void ConvertTableToGrid(string valtext, int rodbid, string roid)
//{
// VE_Font vefont = MyItemInfo.GetItemFont();
// MyFlexGrid.Font = vefont.WindowsFont;
// //Initializing = true;
// MyFlexGrid.MergedRanges.Clear();
// MyFlexGrid.Clear();
// MyFlexGrid.ParseTableFromText(valtext);
// MyFlexGrid.AutoSizeCols();
// MyFlexGrid.AutoSizeRows();
// MyFlexGrid.MakeRTFcells();
// MyFlexGrid.RODbId = rodbid;
// MyFlexGrid.ROID = roid;
// MyFlexGrid.IsRoTable = true;
// //Initializing = false;
// SaveContents();
//}
private bool FinishSave(string searchableText)
{
// Just in case if the grid was in a mode to change sizes, clear out that setting
@ -879,18 +886,19 @@ namespace Volian.Controls.Library
IdentifyMe(false);
}
private void RefreshGridData()
{
string ROID = MyFlexGrid.ROID;
int rodbid = MyFlexGrid.RODbId;
MyFlexGrid.Clear();
ROFSTLookup MyROFSTLookup = MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup;
ConvertTableToGrid(MyROFSTLookup.GetRoValue(ROID));
MyFlexGrid.RODbId = rodbid;
MyFlexGrid.ROID = ROID;
MyFlexGrid.IsRoTable = true;
SaveContents();
}
//private void RefreshGridData()
//{
// string ROID = MyFlexGrid.ROID;
// int rodbid = MyFlexGrid.RODbId;
// //MyFlexGrid.Clear();
// ROFSTLookup MyROFSTLookup = MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup;
// MyFlexGrid.ConvertTableROToGrid(MyROFSTLookup.GetRoValue(ROID), rodbid, ROID);
// //ConvertTableToGrid(MyROFSTLookup.GetRoValue(ROID), rodbid, ROID);
// //MyFlexGrid.RODbId = rodbid;
// //MyFlexGrid.ROID = ROID;
// //MyFlexGrid.IsRoTable = true;
// //SaveContents();
//}
public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table
public void SavePastedCellRoTran()
{

View File

@ -1171,15 +1171,17 @@ namespace Volian.Controls.Library
}
string roid = myGrid.ROID;
int rodbid = myGrid.RODbId;
Font GridFont = myGrid.Font;
myGrid.Clear();
myGrid.ParseTableFromText(args.ROText);
myGrid.AutoSizeCols();
myGrid.AutoSizeRows();
myGrid.MakeRTFcells();
myGrid.RODbId = rodbid;
myGrid.ROID = roid;
myGrid.IsRoTable = true;
////Font GridFont = myGrid.Font;
//myGrid.MergedRanges.Clear();
//myGrid.Clear();
//myGrid.ParseTableFromText(args.ROText);
//myGrid.AutoSizeCols();
//myGrid.AutoSizeRows();
//myGrid.MakeRTFcells();
//myGrid.RODbId = rodbid;
//myGrid.ROID = roid;
//myGrid.IsRoTable = true;
myGrid.ConvertTableROToGrid(args.ROText, rodbid, roid);
using (StringWriter sw = new StringWriter())
{
myGrid.WriteXml(sw);

View File

@ -296,6 +296,7 @@ namespace Volian.Controls.Library
{
return GetRangeHeight(GetMergedRange(row, col))-3;
}
public int GetRangeHeight(CellRange cr)
{
int height = 0;
@ -303,6 +304,7 @@ namespace Volian.Controls.Library
height += (Rows[r].Height == -1) ? Rows.DefaultSize : Rows[r].Height;
return height;
}
public int GetRangeTop(CellRange cr)
{
int top = 0;
@ -310,6 +312,7 @@ namespace Volian.Controls.Library
top += (Rows[r].Height == -1) ? Rows.DefaultSize : Rows[r].Height;
return top;
}
public int GetRangeWidth(CellRange cr)
{
int width = 0;
@ -317,6 +320,7 @@ namespace Volian.Controls.Library
width += (Cols[c].Width == -1) ? Cols.DefaultSize : Cols[c].Width;
return width;
}
public int GetRangeLeft(CellRange cr)
{
int left = 0;
@ -324,6 +328,7 @@ namespace Volian.Controls.Library
left += (Cols[c].Width == -1) ? Cols.DefaultSize : Cols[c].Width;
return left;
}
public int GetRangeRowsMin(CellRange cr)
{
int rowsMin = 1 + cr.r2 - cr.r1;
@ -340,6 +345,7 @@ namespace Volian.Controls.Library
}
return rowsMin;
}
public int GetRangeRowsMax(CellRange cr)
{
int rowsMax = 0;
@ -356,6 +362,7 @@ namespace Volian.Controls.Library
}
return rowsMax;
}
public int GetRangeColsMin(CellRange cr)
{
int colsMin = 1 + cr.c2 - cr.c1;
@ -372,6 +379,7 @@ namespace Volian.Controls.Library
}
return colsMin;
}
public int GetRangeColsMax(CellRange cr)
{
int colsMax = 0;
@ -388,6 +396,7 @@ namespace Volian.Controls.Library
}
return colsMax;
}
public string GetRangeRowList(CellRange cr)
{
StringBuilder sb = new StringBuilder();
@ -404,16 +413,7 @@ namespace Volian.Controls.Library
}
return sb.ToString();
}
private int GetCellWidth(int row, int col)
{
int width = 0;
CellRange cr = GetMergedRange(row, col);
for (int c = cr.c1; c <= cr.c2; c++)
{
width += (Cols[c].Width == -1) ? Cols.DefaultSize - 3 : Cols[c].Width -3;
}
return width;
}
private int BlankRowSpace()
{
int curRowHeight = (Rows[Row].Height == -1) ? Rows.DefaultSize - 3 : Rows[Row].Height - 3;
@ -435,6 +435,18 @@ namespace Volian.Controls.Library
//Console.WriteLine("BlankRowSpace {0}", blankRowSpace);
return blankRowSpace;
}
private int GetCellWidth(int row, int col)
{
int width = 0;
CellRange cr = GetMergedRange(row, col);
for (int c = cr.c1; c <= cr.c2; c++)
{
width += (Cols[c].Width == -1) ? Cols.DefaultSize - 3 : Cols[c].Width -3;
}
return width;
}
private int BlankColSpace()
{
int curColWidth = (Cols[Col].Width == -1) ? Cols.DefaultSize - 3 : Cols[Col].Width - 3;
@ -450,7 +462,7 @@ namespace Volian.Controls.Library
{
int cellWidth = GetCellWidth(r, Col);
srtb.Width = cellWidth;
Application.DoEvents();
//Application.DoEvents();
//int mergeCellHeightNLines = cellHeight / (Rows.DefaultSize - 3);
//int dataHeight = (cr.UserData == null) ? cellHeight : (int)cr.UserData;
//int ud = dataHeight / (Rows.DefaultSize - 3);
@ -502,16 +514,16 @@ namespace Volian.Controls.Library
// return maxRTFHeight;
//}
//private bool IsInMergeRange(int row, int col)
private bool IsInMergeRange(int row, int col)
{
//foreach (CellRange cr in this.MergedRanges)
//{
// //foreach (CellRange cr in this.MergedRanges)
// //{
// // if (cr.Contains(row, col))
// // return true; // in a merged range
// //}
// CellRange cr = GetMergedRange(row, col);
// return (cr.r1 == row && cr.c1 == col);
// if (cr.Contains(row, col))
// return true; // in a merged range
//}
CellRange cr = GetMergedRange(row, col);
return (cr.r1 == row && cr.c1 == col);
}
private static Regex _ReplaceVESymbFix = new Regex(@"({\\f[0-9]+[^ ]* )(VESymbFix)(;})");
private static Regex _ReplaceArialUnicodeMS = new Regex(@"({\\f[0-9]+[^ ]* )(Arial Unicode MS)(;})");
private static Regex _ReplaceTextFont = new Regex(@"({\\f[0-9]+[^ ]* )(?((?!VESymbFix)(?!Arial Unicode MS))([^;]*)|(!!!!))(;})");
@ -1296,6 +1308,8 @@ namespace Volian.Controls.Library
// Now adjust the Height and Width in the defined merge ranges
AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink);
//// Now see the the selected row,col is in the defined merge ranges
//bool mrgrows = false;
//bool mrgcols = false;
@ -1562,52 +1576,53 @@ namespace Volian.Controls.Library
// }
//}
private void Compare(string fromRTF, string fromStr, string rawstr)
{
int istart = fromRTF.IndexOf(" ",fromRTF.IndexOf("viewkind"));
int jstart = fromStr.IndexOf(" ",fromStr.IndexOf("viewkind"));
for (int i = istart; i < fromRTF.Length; i++)
{
int j = i - istart + jstart;
//else if (fromRTF[i] != fromStr[j])
if (fromRTF[i] != fromStr[j])
{
if (fromRTF.Substring(i, 1) == @"~" && fromStr.Substring(j, 3) == @"'a0")
{
//i++;
jstart += 2;
}
else
{
Console.WriteLine("fromStr:\r\n'{0}'\r\nfromRTF:\r\n'{1}'", fromStr, fromRTF);
ShowRawString(rawstr, "rawstr");
Console.WriteLine("Str:'{0}' , RTF:'{1}'", fromStr.Substring(j, Math.Min(10,fromStr.Length-j-1)), fromRTF.Substring(i, Math.Min(10,fromRTF.Length-i-1)));
return;
}
}
}
}
//private void Compare(string fromRTF, string fromStr, string rawstr)
//{
// int istart = fromRTF.IndexOf(" ",fromRTF.IndexOf("viewkind"));
// int jstart = fromStr.IndexOf(" ",fromStr.IndexOf("viewkind"));
// for (int i = istart; i < fromRTF.Length; i++)
// {
// int j = i - istart + jstart;
// //else if (fromRTF[i] != fromStr[j])
// if (fromRTF[i] != fromStr[j])
// {
// if (fromRTF.Substring(i, 1) == @"~" && fromStr.Substring(j, 3) == @"'a0")
// {
// //i++;
// jstart += 2;
// }
// else
// {
// Console.WriteLine("fromStr:\r\n'{0}'\r\nfromRTF:\r\n'{1}'", fromStr, fromRTF);
// ShowRawString(rawstr, "rawstr");
// Console.WriteLine("Str:'{0}' , RTF:'{1}'", fromStr.Substring(j, Math.Min(10,fromStr.Length-j-1)), fromRTF.Substring(i, Math.Min(10,fromRTF.Length-i-1)));
// return;
// }
// }
// }
//}
private void ShowRawString(string str, string title)
{
Console.WriteLine("Raw Start --{0}:\n", title);
foreach (char c in str)
{
int ic= (int)c;
if (c!='\n'&&( ic > 126 || ic < 32))
Console.Write("<<{0:x4}>>", ic);
else
Console.Write(c);
}
Console.WriteLine("\n-- Raw End:{0}", title);
}
#region DEBUG
//private void ShowRawString(string str, string title)
//{
// Console.WriteLine("Raw Start --{0}:\n", title);
// foreach (char c in str)
// {
// int ic= (int)c;
// if (c!='\n'&&( ic > 126 || ic < 32))
// Console.Write("<<{0:x4}>>", ic);
// else
// Console.Write(c);
// }
// Console.WriteLine("\n-- Raw End:{0}", title);
//}
#endregion
private void Grid_AfterResize(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
this.AdjustGridControlSize();
}
#endregion // Grid Size Adjustments
#region Cell Text
@ -1623,36 +1638,14 @@ namespace Volian.Controls.Library
this.ConvertTextCellToRTF(r, c);
}
//this.Refresh();
//Application.DoEvents();
this.AdjustGridControlSize();
SetupCellUserData();
//RemoveBlankSpaceFromColumns();
TrimColumnWidths();
RemoveBlankSpaceFromRows();
SetupCellUserData();
this.AdjustGridControlSize();
}
public void FixTableCellsHeightWidth()
{
//StepRTB trtb = new StepRTB();
////trtb.SetTableGridCellRTFPrefix(this.Font);
//trtb.Font = this.Font;
//// This will spin through all the cells in the grid:
//// - adjust the grid dimensions based on the cell info.
//for (int r = 0; r < this.Rows.Count; r++)
//{
// this.Rows[r].Height = Rows.DefaultSize;//_minRowHeight;//20;//10;
// for (int c = 0; c < this.Cols.Count; c++)
// {
// trtb.Clear();
// trtb.Rtf = (string)this[r, c];
// this.AdjustCellHeightWidth(r, c, trtb);
// }
//}
//this.AdjustGridControlSize();
//SetupCellUserData();
RemoveBlankSpaceFromColumns();
RemoveBlankSpaceFromRows();
}
@ -1679,6 +1672,34 @@ namespace Volian.Controls.Library
}
}
private void TrimColumnWidths()
{
for (int c = 0; c < Cols.Count; c++)
{
Select(0, c);
int newColWidth = MinColWidth();
Cols[c].Width = newColWidth;
}
}
private int MinColWidth()
{
int curColWidth = 0;
for (int r = 0; r < Rows.Count; r++)
{
CellRange cr = GetMergedRange(r, Col);
// find the needed cell width
if (Col == cr.c1)
{
StepRTB srtb = new StepRTB();
srtb.Rtf = GetCellRTFString(cr.r1, cr.c1);
srtb.AdjustWidthForContent();
curColWidth = Math.Max(curColWidth, srtb.Width + 3);
}
}
return curColWidth;
}
//private bool RemoveBoldUlineItalicChars(string str)
//{
// int rtn = 0;
@ -1704,13 +1725,10 @@ namespace Volian.Controls.Library
//}
//private string ConvertTableText(string str, VE_Font vf)
private string ConvertTableText(string str)
{
string rtn = str;
//ShowRawString(str, "ConvertTableText IN");
//if (!str.StartsWith(@"{\rtf"))
//{
rtn = rtn.Replace(@"START]\v0", @"START]\cf1\v0");
rtn = rtn.Replace(@"\v #Link:", @"\cf0\v #Link:");
rtn = rtn.Replace("\n", "\\par\r\n");
@ -1754,97 +1772,11 @@ namespace Volian.Controls.Library
rtn = rtn.Replace("}", @"\}");
rtn = rtn.Replace("\xd5", @"\b");
rtn = rtn.Replace("\xd6", @"\b0");
//}
//else
//{
// // Underline next word
// rtn = SomethingNextWord(rtn, @"\'17", @"\ul ", @"\ulnone ");
// // Bold next word
// rtn = SomethingNextWord(rtn, @"\'13", @"\b ", @"\b0 ");
// // Italics On
// rtn = rtn.Replace(@"\'1B4", @"\i ");
// // Italics Off
// rtn = rtn.Replace(@"\'1B5", @"\i0 ");
// // underline On
// rtn = rtn.Replace(@"\'ab", @"\ul");
// // underline Off
// rtn = rtn.Replace(@"\'bb", @"\ulnone");
// rtn = rtn.Replace(@"\'ef\'e6", @"\up2 ");
// rtn = rtn.Replace(@"\'ef\'e7", @"\up0 ");
// rtn = rtn.Replace(@"\'f2", @"\f1 \u8805?\f0 "); //greater than or equal
// //rtn = rtn.Replace("\xB0 ", @"\'b0 ");
// //rtn = rtn.Replace("\x2552", "\\b ");
// //rtn = rtn.Replace("\x2553", "\\b0 ");
// rtn = rtn.Replace(@"\'d5", @"\b");
// rtn = rtn.Replace(@"\'d6", @"\b0");
// //rtn = rtn.Replace("\xA0", @"\u160?");
// //rtn = rtn.Replace(@"\'a0", @"\u160?");
// rtn = rtn.Replace(@"\'ff", @"\u160?");
// //rtn = rtn.Replace("\xFF", @"\u160?");
// //rtn = rtn.Replace(@"\~", @"\u160?");
// rtn = rtn.Replace("\x7F", @"\f1 \u916?\f0 "); // delta
//}
//ShowRawString(rtn, "ConvertTableText OUT");
return rtn;
}
//private void ConvertTableText(StepRTB srtb)
//{
// string[] symb = { @"\'f2"};
// string str = srtb.Rtf;
// // Underline next word
// str = SomethingNextWord(str, @"\'17", @"\ul ", @"\ulnone ");
// // Bold next word
// str = SomethingNextWord(str, @"\'13", @"\b ", @"\b0 ");
// // Italics On
// str = str.Replace(@"\'1B4", @"\i ");
// // Italics Off
// str = str.Replace(@"\'1B5", @"\i0 ");
// // underline On
// str = str.Replace(@"\'ab", @"\ul");
// // underline Off
// str = str.Replace(@"\'bb", @"\ulnone");
// str = str.Replace(@"\'ef\'e6", @"\up2 ");
// str = str.Replace(@"\'ef\'e7", @"\up0 ");
// str = str.Replace(@"\'d5", @"\b");
// str = str.Replace(@"\'d6", @"\b0");
// str = str.Replace("\xA0", @"\u160?");
// str = str.Replace("\x7F", @"\u916?");
// VE_Font vf = new VE_Font(this.Font.FontFamily.Name,(int)this.Font.Size,E_Style.None);
// DisplayText dt = new DisplayText(str,vf, true);
// srtb.Rtf = str;
// //srtb.SelectionStart = 0;
// //foreach (string s in symb)
// //{
// // int idx = srtb.Rtf.LastIndexOf(s, srtb.Rtf.Length-1);
// // while (idx >= 0)
// // {
// // srtb.Rtf = srtb.Rtf.Remove(idx, s.Length);
// // srtb.SelectionStart = idx;
// // srtb.InsertSymbol(s);
// // idx = srtb.Rtf.LastIndexOf(s,idx);
// // }
// //}
// //rtn = rtn.Replace("\xf2 ", @"\u8805?"); //greater than or equal
// //rtn = rtn.Replace("\xA0", @"\u160?");
// //rtn = rtn.Replace("\x7F", @"\u916?");
//}
// This converts Underline or bold next word character to the corresponding on/off commands
private static string SomethingNextWord(string str, string nxtwordcmd, string cmdOn, string cmdOff)
{
string rtn = "";
@ -1880,13 +1812,6 @@ namespace Volian.Controls.Library
private void _StartEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
// start editing the cell with the custom editor
//CellStyle cs = this.Styles["Focus"];
////CellStyle cs=this.GetCellRange(e.Row, e.Col).StyleNew;
////cs.Name = string.Format("R{0}C{1}", e.Row, e.Col);
//cs.ForeColor = Color.White;
//cs = this.Styles["Highlight"];
//cs.ForeColor = Color.LightCyan;
////Console.WriteLine("Style = {0}",cs.Name);
_tableCellEditor.StartEditing(e.Row, e.Col);
e.Cancel = true;
}
@ -1894,7 +1819,6 @@ namespace Volian.Controls.Library
// after edit handler (built-in editors)
private void _AfterEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
//Console.WriteLine("Style = {0}", this.GetCellRange(e.Row, e.Col).Style.Name);
this.GetCellRange(e.Row, e.Col).Style.ForeColor = Color.Black;
this.AdjustGridControlSize();
}
@ -1942,8 +1866,6 @@ namespace Volian.Controls.Library
public void ClearSelectedCellText()
{
CellRange cr = this.Selection;
//DialogResult dr = MessageBox.Show("Clear Selected cells?", "Clear", MessageBoxButtons.YesNo);
//if (dr == DialogResult.Yes)
cr.Clear(ClearFlags.Content);
}
public void SetupCellUserData()
@ -1959,7 +1881,6 @@ namespace Volian.Controls.Library
_rtf.Rtf = rtfText;
CellRange cr = GetCellRange(r, c);
cr.UserData = _rtf.ContentsRectangle.Height;
//Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height);
}
}
}
@ -1980,7 +1901,11 @@ namespace Volian.Controls.Library
}
public void SplitSelection(bool bSplitCols)
{
//Console.WriteLine("SplitSelection this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
//foreach (CellRange sel in MySelection)
//{
if (this.MergedRanges.Contains(sel))
this.MergedRanges.Remove(sel);
else //split cells
@ -1990,12 +1915,15 @@ namespace Volian.Controls.Library
else
SplitSelectionRows();
}
//}
this.Refresh();
this.AdjustGridControlSize();
}
private void SplitSelectionColumns()
{
//Console.WriteLine("SplitSelectionColumns this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
CellRange cr = this.Selection;
int numSelCols = (cr.c2 - cr.c1) + 1;
// for each column in the selection, add a new column
@ -2936,14 +2864,88 @@ namespace Volian.Controls.Library
return rtn;
}
public void ConvertTableROToGrid(string valtext, int rodbid, string roid)
{
VE_Font vefont = MyItemInfo.GetItemFont();
this.Font = vefont.WindowsFont;
this.MergedRanges.Clear();
this.Clear();
this.IsRoTable = true;
this.ParseTableFromText(valtext);
this.AutoSizeCols();
this.AutoSizeRows();
this.MakeRTFcells();
this.RODbId = rodbid;
this.ROID = roid;
}
private Regex _ReplaceSpaceNewLine = new Regex(@"(?<=\\[^' \\?\r\n\t]*) (?=\r\n)");
private Regex _ReplaceTokenSpaceToken = new Regex(@"(?<=\\[^' \\?\r\n\t]*) (?=\\)");
private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)");
private string PrepROTableText(string stepText)
{
// we need to convert some RTF command to DOS so that we can
// figure out the table size
stepText = stepText.Replace("\xF8", @"\'f8");
stepText = stepText.Replace(@"\par ", "\r\n");
stepText = _ReplaceTokenSpaceToken.Replace(stepText, "");
//Change Token Order to match RTB output
stepText = stepText.Replace(@"\v0\b0", @"\b0\v0");
stepText = stepText.Replace(@"\b0\ulnone", @"\ulnone\b0");
stepText = _ReplaceSpaceNewLine.Replace(stepText, "");
// Now change the Unicode symbols to DOS symbols
stepText = stepText.Replace(@"\u8209?", "-");
stepText = stepText.Replace(@"\u9474?", "\xB3"); // Vert Line graphic character
stepText = stepText.Replace(@"\'b0", "\xB0");
stepText = stepText.Replace(@"\up2 ", "\x9566");
stepText = stepText.Replace(@"\up0 ", "\x9567");
stepText = stepText.Replace(@"\ulnone", "\xBB");
stepText = stepText.Replace(@"\ul", "\xAB");
stepText = stepText.Replace(@"\{", "{");
stepText = stepText.Replace(@"\}", "}");
stepText = stepText.Replace(@"\b0", "\xD6");
stepText = stepText.Replace(@"\b", "\xD5");
stepText = stepText.Replace(@"\u160?", "\xA0"); //hard space
stepText = stepText.Replace(@"\u916?", "\x7F"); // delta
stepText = stepText.Replace(@"\u8805?", "\xF2"); //greater than or equal
stepText = stepText.Replace(@"\u8804?", "\xF3"); // less than or equal
stepText = stepText.Replace(@"\u931?", "\xE4"); // sigma
stepText = stepText.Replace(@"\u947?", "\xE7"); // gamma
stepText = stepText.Replace(@"\u9604?", "\xFE"); // accum 2584
stepText = stepText.Replace(@"\u9679?", "\x7"); // bullet 25CF
stepText = stepText.Replace(@"\u8776?", "\xF7"); // approx eq
stepText = stepText.Replace(@"\u8773?", "\xF0"); // similar eq 2245
stepText = stepText.Replace(@"\u8730?", "\xFB"); // square root
stepText = stepText.Replace(@"\u961?", "\xE2"); // rho 3C1
stepText = stepText.Replace(@"\u960?", "\xE3"); // pi
stepText = stepText.Replace(@"\u956?", "\xE6"); // micro
stepText = stepText.Replace(@"\u948?", "\xEB"); // lower case delta
stepText = stepText.Replace(@"\u963?", "\xE5"); // lower case sigma
stepText = stepText.Replace(@"\u274?", "\x90"); // energy, 112
stepText = stepText.Replace(@"\u949?", "\xEE"); // epsilon
stepText = stepText.Replace(@"\u952?", "\xE9"); // theta, 3B8
stepText = stepText.Replace(@"\u8857?", "\xEC"); // dot in oval, 2299
stepText = stepText.Replace(@"\u964?", "\xA8"); // tau, 3C4
stepText = stepText.Replace(@"\u9830?", "\xA9"); // diamond, 2666
stepText = stepText.Replace(@"\u8593?", "\x18"); // Up Arrow - changes to \xff
stepText = stepText.Replace(@"\u8595?", "\x19"); // Down Arrow - changes to \xd6
return stepText;
}
/// <summary>
/// This will parse a string containing the ascii text of the old style VE-PROMS (16-bit) tables.
/// It will find the number of rows and columns base on newlines, vertical bars, and dashes.
/// Then it will parse the the text, place them in cells, and attempt to merge cells were needed.
/// </summary>
/// <param name="txtbuff"></param>
public void ParseTableFromText(string txtbuff)
public void ParseTableFromText(string buff)
{
string txtbuff = PrepROTableText(buff);
if (IsRoTable) txtbuff = _RemoveComments.Replace(txtbuff, "");
int curRow = 0;
int curCol = 0;
int maxRow = 0;
@ -3108,7 +3110,7 @@ namespace Volian.Controls.Library
tstr = txtbuff.Substring(idxst, idx - idxst);
if (tstr.EndsWith("\r")) // strip off carrage return
tstr = tstr.Substring(0, tstr.Length - 1);
tstr = tstr.TrimEnd(" ".ToCharArray());
//tstr = tstr.TrimEnd(" ".ToCharArray());
if (tstr.Length == 0)
tstr += " ";
// test for a string of '-' characters
@ -3174,7 +3176,7 @@ namespace Volian.Controls.Library
}
// parse out the remaining text
tstr = txtbuff.Substring(idxst);
tstr = tstr.TrimEnd(" ".ToCharArray());
//tstr = tstr.TrimEnd(" ".ToCharArray());
if (tstr.Length == 0)
tstr += " ";
// test for a string of '-' characters
@ -3250,6 +3252,7 @@ namespace Volian.Controls.Library
{
string cellstr = this[r, c].ToString();
this[r, c] = cellstr.TrimEnd("\r\n\t".ToCharArray());
//this[r, c] = cellstr.TrimEnd(" \r\n\t".ToCharArray());
CellRange cr = this.GetMergedRange(r, c);
if (cr.r1 != cr.r2)
TrimMergedRangeCellText(cr);
@ -3258,312 +3261,6 @@ namespace Volian.Controls.Library
MyBorders = new VlnBorders(GridLinePattern.Single, Rows.Count, Cols.Count);
}
//private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)");
//public void ParseTableFromText2(string rtfText)
//{
// //string txtbuff = _RemoveComments.Replace(rtfText, "");
// string txtbuff = "";
// int curRow = 0;
// int curCol = 0;
// int maxRow = 0;
// int maxCol = 0;
// // Get Max Rows and Max Cols
// char[] test = "|\n\x02".ToCharArray();
// int idx = 0;
// int idxst = 0;
// int colPos = 0;
// int strow = 0;
// Dictionary<int, int> dicCols = new Dictionary<int, int>();
// //Dictionary<int, int> dicCols2 = new Dictionary<int, int>();
// //If this is not a table ro, then process the RTF version of the text so as to caputure Link references
// if (!this.IsRoTable)
// txtbuff = rtfText;
// else
// txtbuff = _RemoveComments.Replace(rtfText, "");
// do
// {
// idx = txtbuff.IndexOfAny(test, idxst);
// if (idx > -1)
// {
// switch (txtbuff[idx])
// {
// case '|': // end of a column
// colPos = idxst - strow;
// if (!dicCols.ContainsKey(colPos))
// dicCols.Add(colPos, curCol);
// else if (curCol > dicCols[colPos])
// {
// dicCols.Remove(colPos);
// dicCols.Add(colPos, curCol);
// }
// curCol++;
// break;
// case '\x02':
// case '\n': // end of a row
// colPos = idxst - strow;
// if (!dicCols.ContainsKey(colPos))
// dicCols.Add(colPos, curCol);
// else if (curCol > dicCols[colPos])
// {
// dicCols.Remove(colPos);
// dicCols.Add(colPos, curCol);
// }
// curRow++;
// strow = idx + 1;
// if (curCol > maxCol)
// maxCol = curCol;
// curCol = 0;
// break;
// }
// idxst = idx + 1;
// if (idxst >= txtbuff.Length)
// idx = -1;
// }
// } while (idx != -1);
// maxRow = curRow + 1;
// curRow = 0;
// curCol = 0;
// // The resulting Table Grid size in rows and columns
// this.Cols.Count = maxCol + 1;
// this.Rows.Count = maxRow + 1;
// // make all rows and columns editable
// this.Rows.Fixed = 0;
// this.Cols.Fixed = 0;
// // TableCellInfo is used to assign merge ranges
// // Make a two dimensional array of TableCellinfo the same size as the table grid
// TableCellInfo[,] tci = new TableCellInfo[maxRow + 1, maxCol + 1];
// for (int r = 0; r <= maxRow; r++)
// for (int c = 0; c <= maxCol; c++)
// tci[r, c] = new TableCellInfo();
// // Read in each cell of the grid
// idx = 0;
// idxst = 0;
// colPos = 0;
// strow = 0;
// int prevCol = 0;
// int tstidx = 0;
// string tstr = "";
// bool incRow = false;
// ////If this is not a table ro, then process the RTF version of the text so as to caputure Link references
// //if (!this.IsRoTable)
// // txtbuff = rtfText;
// do
// {
// idx = txtbuff.IndexOfAny(test, idxst);
// if (idx > -1)
// {
// switch (txtbuff[idx])
// {
// case '|': // end of column
// colPos = idxst - strow;
// // based on the position of the | char, find what column we are in.
// // note that this will tell us if any columns to the left were merged
// // the while loop will flag cell that need to be merged
// curCol = dicCols[colPos];
// while (curCol > prevCol + 1)
// {
// tci[curRow, prevCol].MergeColRight = true;
// prevCol++;
// }
// prevCol = curCol;
// // parse out the text to be placed in the table cell
// tstr = txtbuff.Substring(idxst, idx - idxst);
// if (tstr.Length == 0)
// tstr += " ";
// // test for a string of '-' characters
// for (tstidx = 0; (tstidx < tstr.Length) && (tstr[tstidx] == '-'); tstidx++) ;
// if (tstidx < tstr.Length) // not a full line (row) of '-' chars
// {
// // if this column is in a merged grouping of rows,
// // get the cell text in the first cell of the merged grouping of cells
// // we will append the newly parsed text to this cell's text.
// int rw = curRow;
// while (rw - 1 >= 0 && tci[rw - 1, curCol].MergeRowBellow) rw--;
// int cl = curCol;
// while (cl - 1 >= 0 && tci[rw, cl - 1].MergeColRight) cl--;
// //string jstr = (string)this[rw, curCol];
// string jstr = (string)this[rw, cl];
// if (jstr == null)
// jstr = tstr;
// else
// jstr += ((cl == curCol) ? "\n" : "") + tstr; // multi line cell
// //jstr += "\n" + tstr; // multi line cell
// //this[rw, curCol] = jstr;
// this[rw, cl] = jstr;
// // take a peek at the start of the next piece of table text to parse
// // if it starts with a '-' char, then flag to merge the columns up to
// // this point with the same columns in the next row
// if (idx < txtbuff.Length - 1 && txtbuff[idx + 1] == '-')
// {
// for (int c = curCol; c >= -0; c--)
// if (!tci[curRow, c].ColEnd)
// tci[curRow, c].MergeRowBellow = true;
// }
// }
// else // parsed text contains all dashes
// {
// tci[curRow, curCol].ColEnd = true;
// incRow = true;
// }
// break;
// case '\x02': // end of file
// case '\n': // new line of 16-bit table text
// colPos = idxst - strow;
// // see what column we are in - new line might occure before last grid column
// curCol = dicCols[colPos];
// strow = idx + 1;
// // parse out the cell text
// tstr = txtbuff.Substring(idxst, idx - idxst);
// if (tstr.EndsWith("\r")) // strip off carrage return
// tstr = tstr.Substring(0, tstr.Length - 1);
// tstr = tstr.TrimEnd(" ".ToCharArray());
// if (tstr.Length == 0)
// tstr += " ";
// // test for a string of '-' characters
// for (tstidx = 0; (tstidx < tstr.Length) && (tstr[tstidx] == '-'); tstidx++) ;
// if (tstidx < tstr.Length) // not a full line (row) of '-' chars
// {
// // if this column is in a merged grouping of rows,
// // get the cell text in the first cell of the merged grouping of cells
// // we will append the newly parsed text to this cell's text.
// int rw = curRow;
// while (rw - 1 >= 0 && tci[rw - 1, curCol].MergeRowBellow) rw--;
// int cl = curCol;
// while (cl - 1 >= 0 && tci[rw, cl - 1].MergeColRight) cl--;
// //string jstr = (string)this[rw, curCol];
// string jstr = (string)this[rw, cl];
// if (jstr == null)
// jstr = tstr;
// else
// jstr += ((cl == curCol) ? "\n" : "") + tstr; // multi line cell
// //jstr += "\n" + tstr; // multi line cell
// //this[rw, curCol] = jstr;
// this[rw, cl] = jstr;
// }
// else if (tstr.Length > 0) // parsed text is all dash characters
// {
// incRow = true;
// if (curRow > 0) // merge the column in the previous row with this one
// tci[curRow - 1, curCol].MergeRowBellow = false;
// }
// // if were are that the end of the 16-bit text line, but not in the last column,
// // merge the remaining columns to the right
// if ((curCol < maxCol) && (tstidx < tstr.Length))
// {
// for (int i = curCol; i < maxCol; i++)
// tci[curRow, i].MergeColRight = true;
// }
// if (incRow)
// curRow++;
// curCol = 0;
// incRow = false;
// break;
// }
// idxst = idx + 1;
// if (idxst >= txtbuff.Length)
// idx = -1;
// }
// else if (idxst < txtbuff.Length - 1) // handle any remaining text not yet parsed
// {
// // find the curent column and merge remaining columns to the right
// colPos = idxst - strow;
// curCol = dicCols[colPos];
// while (curCol > prevCol + 1)
// {
// tci[curRow, prevCol].MergeColRight = true;
// prevCol++;
// }
// // parse out the remaining text
// tstr = txtbuff.Substring(idxst);
// tstr = tstr.TrimEnd(" ".ToCharArray());
// if (tstr.Length == 0)
// tstr += " ";
// // test for a string of '-' characters
// for (tstidx = 0; (tstidx < tstr.Length) && (tstr[tstidx] == '-'); tstidx++) ;
// if (tstidx < tstr.Length)
// {
// // if this column is in a merged grouping of rows,
// // get the cell text in the first cell of the merged grouping of cells
// // we will append the newly parsed text to this cell's text.
// int rw = curRow;
// while (rw - 1 >= 0 && tci[rw - 1, curCol].MergeRowBellow) rw--;
// int cl = curCol;
// while (cl - 1 >= 0 && tci[rw, cl - 1].MergeColRight) cl--;
// //string jstr = (string)this[rw, curCol];
// string jstr = (string)this[rw, cl];
// if (jstr == null)
// jstr = tstr;
// else
// jstr += ((cl == curCol) ? "\n" : "") + tstr; // multi line cell
// //jstr += "\n" + tstr; // multi line cell
// //this[rw, curCol] = jstr;
// this[rw, cl] = jstr;
// }
// }
// } while (idx != -1);
// // we are done parsing the 16-bit text.
// // now set the merge ranges in the table grid, based on the
// // information saved in that two dimensional array of TableCellinfo
// this.Rows.Count = curRow + 1;
// this.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom;
// maxRow = curRow;
// int rR = 0;
// int rC = 0;
// for (int r = 0; r <= maxRow; r++)
// for (int c = 0; c <= maxCol; c++)
// {
// if (tci[r, c].MergeColRight)
// {
// rC = c;
// while ((rC < maxCol) && (tci[r, rC].MergeColRight)) rC++;
// if (rC > c)
// {
// this.MergedRanges.Add(this.GetCellRange(r, c, r, rC));
// string cellstr = this[r, c].ToString();
// for (int x = c + 1; x <= rC; x++)
// this[r, x] = cellstr;
// c = rC;
// }
// }
// }
// for (int c = 0; c <= maxCol; c++)
// for (int r = 0; r <= maxRow; r++)
// {
// if (tci[r, c].MergeRowBellow)
// {
// rR = r;
// while ((rR < maxRow) && (tci[rR, c].MergeRowBellow)) rR++;
// if (rR > r)
// {
// this.MergedRanges.Add(this.GetCellRange(r, c, rR, c));
// string cellstr = this[r, c].ToString();
// for (int x = r + 1; x <= rR; x++)
// this[x, c] = cellstr;
// r = rR;
// }
// }
// }
// for (int c = 0; c <= maxCol; c++)
// for (int r = 0; r <= maxRow; r++)
// {
// if (this[r, c] != null)
// {
// string cellstr = this[r, c].ToString();
// this[r, c] = cellstr.TrimEnd(" \r\n\t".ToCharArray());
// CellRange cr = this.GetMergedRange(r, c);
// if (cr.r1 != cr.r2)
// TrimMergedRangeCellText(cr);
// }
// }
//}
private void TrimMergedRangeCellText(CellRange cr)
{
// count number of newlines
@ -3572,22 +3269,55 @@ namespace Volian.Controls.Library
int nlines = strary.Length;
// count number of rows in merge range
int nrows = (cr.r2 - cr.r1) + 1;
// if nlines > rows then trim blank lines from top
bool bNeedToTrim = (nlines > nrows);
int neededLines = (nlines - (nrows - 1));
bool bNeedToTrim = (nlines > neededLines);
string jstr = "";
foreach (string tmpstr in strary)
int LinesToGo = neededLines;
if (bNeedToTrim)
{
int numBlanksEnd = 0;
// find the number of blank lines at the end of this table cell
for (int i = nlines-1; i >= 0; i--)
{
if (strary[i].Trim().Length == 0)
numBlanksEnd++;
else
break;
}
int preBlanksLines = 0;
//foreach (string tmpstr in strary)
// we ignore the ending blank lines
// this allows us to include any blank lines that are between text lines
for (int i = 0; i < nlines - numBlanksEnd; i++)
{
string tmpstr = strary[i];
int tlen = tmpstr.Trim().Length;
if (!bNeedToTrim || tlen > 0)
if (tlen > 0 || (LinesToGo < neededLines))
{
if (jstr.Length > 0) jstr += "\n";
jstr += tmpstr;
LinesToGo--;
}
else if (LinesToGo == (nlines - (nrows - 1)))
preBlanksLines++;
}
while (LinesToGo > 0)
{
// need to put this type of hard space (not \xA0) to hold the newline position
if (preBlanksLines > 0)
{
jstr = "\\~\n" + jstr;
LinesToGo--;
}
if (numBlanksEnd > 0)
{
jstr += "\n\\~";
LinesToGo--;
}
else nlines--;
bNeedToTrim = (tlen == 0 && nlines > nrows);
}
this[cr.r1, cr.c1] = jstr;
}
}
#endregion //Import / Export Grid
@ -3816,6 +3546,23 @@ namespace Volian.Controls.Library
Select(r1,c1,r2,c2);
}
public void Debug_WritelineMySelection()
{
int r1 = MySelection[0].r1;
int r2 = MySelection[0].r2;
int c1 = MySelection[0].c1;
int c2 = MySelection[0].c2;
Console.WriteLine("Initial MySelection[0] {0}", MySelection[0]);
foreach (CellRange cr in MySelection)
{
r1 = Math.Min(r1, cr.r1);
c1 = Math.Min(c1, cr.c1);
r2 = Math.Max(r2, cr.r2);
c2 = Math.Max(c2, cr.c2);
Console.WriteLine("Foreach range ({0},{1}) - ({2},{3})", r1, c1, r2, c2);
}
}
#endregion
}
/// <summary>