This commit is contained in:
2011-01-19 21:53:01 +00:00
parent fbce101db9
commit 0fafccf62c
6 changed files with 717 additions and 161 deletions

View File

@@ -16,6 +16,8 @@ namespace Volian.Controls.Library
{
private TableCellEditor _tableCellEditor;
private TableClipBoardFuncts _clpbrdCpyPste;
private int _minSplitColWidth = 10;
private int _minSplitRowHeight = 20;
#region Grid Initialize
@@ -54,7 +56,7 @@ namespace Volian.Controls.Library
this.Cols.Fixed = 0;
this.DrawMode = DrawModeEnum.OwnerDraw;
this.ScrollBars = ScrollBars.None;
this.ScrollBars = ScrollBars.None;
// grid styles
this.Styles.EmptyArea.BackColor = Color.Transparent;
@@ -62,7 +64,7 @@ namespace Volian.Controls.Library
this.Styles.Normal.Border.Color = Color.Black;
this.Styles.Normal.TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.LeftCenter;
SetupCellStyles();
//SetupCellStyles();
this.FocusRect = FocusRectEnum.Solid;
this.Styles.Highlight.BackColor = Color.LightCyan;
@@ -125,26 +127,28 @@ namespace Volian.Controls.Library
#region Grid and Cell Styles
//public void CellBackgroundYellow()
//{
// CellRange cr = this.Selection;
// cr.Style = this.Styles["Yellow"];
//}
public void ChangeBackgroundColor(string bckgndColor)
{
CellRange cr = this.Selection;
string stylename = string.Format("R{0}C{1}Style", cr.r1, cr.c1);
if (!bckgndColor.EndsWith(";"))
bckgndColor+=";";
string strBckgndColor = string.Format("BackColor:{0}", bckgndColor);
CellStyle cs = this.Styles.Add(stylename, cr.Style);
cs.ParseString(strBckgndColor);
cr.Style = cs;
for (int rw = cr.r1; rw <= cr.r2; rw++)
for (int cl = cr.c1; cl <= cr.c2; cl++)
{
CellRange tmp = this.GetCellRange(rw, cl, rw, cl);
string StyleName = string.Format("R{0}C{1}Style", rw, cl);
CellStyle cs = this.Styles.Add(StyleName, tmp.Style);
cs.ParseString(strBckgndColor);
tmp.Style = cs;
}
}
public void ToggleCellTextAlignment()
{
// only used in test program
CellRange cr = this.Selection;
StepRTB srtb = new StepRTB();
srtb.Rtf = this.GetCellRTFString(cr.r1, cr.c1);
@@ -157,119 +161,71 @@ namespace Volian.Controls.Library
this.PutCellRTFString(cr.r1, cr.c1, srtb.Rtf);
}
public void TableBorderNone()
public void RTFTextAlignment(CellRange cr, HorizontalAlignment ha)
{
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.None;
StepRTB srtb = new StepRTB();
for (int rw = cr.r1; rw <= cr.r2; rw++)
for (int cl = cr.c1; cl <= cr.c2; cl++)
{
srtb.Rtf = this.GetCellRTFString(rw, cl);
srtb.SelectAll();
srtb.SelectionAlignment = ha;
this.PutCellRTFString(rw, cl, srtb.Rtf);
}
}
public void SetTableBorder(C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum border)
{
this.BorderStyle = border;
this.AdjustGridControlSize();
}
public void TableBorderFixedSingle()
public void ChangeCellBorder(CellRange cr, BorderStyleEnum newBorder)
{
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.FixedSingle;
this.AdjustGridControlSize();
for (int rw = cr.r1; rw <= cr.r2; rw++)
for (int col = cr.c1; col <= cr.c2; col++)
{
CellRange tmp = this.GetCellRange(rw, col, rw, col);
string StyleName = string.Format("R{0}C{1}Style", rw, col);
CellStyle cs = this.Styles.Add(StyleName, tmp.Style);
cs.Border.Style = newBorder;
tmp.Style = cs;
}
}
public void TableBorderFixed3d()
{
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.Fixed3D;
this.AdjustGridControlSize();
}
//public void SetupCellStyles()
//{
// //CellStyle cs;
public void TableBorderLight3D()
{
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.Light3D;
this.AdjustGridControlSize();
}
public void TableBorderXpThemes()
{
this.BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.XpThemes;
this.AdjustGridControlSize();
}
private CellRange GetSelectedCellRange()
{
return this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
}
public void SelectedCellsBorderNone()
{
CellRange cr = GetSelectedCellRange();
cr.Style = this.Styles["None"];
}
public void SelectedCellsBorderFlat()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Flat"];
}
public void SelectedCellsBorderDouble()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Double"];
}
public void SelectedCellsBorderRaised()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Raised"];
}
public void SelectedCellsBorderInset()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Inset"];
}
public void SelectedCellsBorderGroove()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Groove"];
}
public void SelectedCellsBorderFillet()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Fillet"];
}
public void SelectedCellsBorderDotted()
{
CellRange cr = this.GetCellRange(this.Selection.TopRow, this.Selection.LeftCol, this.Selection.BottomRow, this.Selection.RightCol);
cr.Style = this.Styles["Dotted"];
}
public void SetupCellStyles()
{
CellStyle cs;
//cs = this.Styles.Add("Dotted");
//cs.Border.Style = BorderStyleEnum.Dotted;
//cs = this.Styles.Add("Double");
//cs.Border.Style = BorderStyleEnum.Double;
//cs = this.Styles.Add("Fillet");
//cs.Border.Style = BorderStyleEnum.Fillet;
//cs = this.Styles.Add("Flat");
//cs.Border.Style = BorderStyleEnum.Flat;
//cs = this.Styles.Add("Groove");
//cs.Border.Style = BorderStyleEnum.Groove;
//cs = this.Styles.Add("Inset");
//cs.Border.Style = BorderStyleEnum.Inset;
//cs = this.Styles.Add("None");
//cs.Border.Style = BorderStyleEnum.None;
//cs = this.Styles.Add("Raised");
//cs.Border.Style = BorderStyleEnum.Raised;
//cs = this.Styles.Add("CenterRight");
//cs.TextAlign = TextAlignEnum.RightCenter; //.LeftCenter; // this is being ignored - probably due to RTF conversion
//cs = this.Styles.Add("Yellow");
//cs.BackColor = Color.Yellow;
//cs = this.Styles.Add("Margins");
//cs.Margins.Bottom = 5;
//cs.Margins.Top = 10;
//cs.Margins.Left = 15;
//cs.Margins.Right = 20;
}
// //cs = this.Styles.Add("Dotted");
// //cs.Border.Style = BorderStyleEnum.Dotted;
// //cs = this.Styles.Add("Double");
// //cs.Border.Style = BorderStyleEnum.Double;
// //cs = this.Styles.Add("Fillet");
// //cs.Border.Style = BorderStyleEnum.Fillet;
// //cs = this.Styles.Add("Flat");
// //cs.Border.Style = BorderStyleEnum.Flat;
// //cs = this.Styles.Add("Groove");
// //cs.Border.Style = BorderStyleEnum.Groove;
// //cs = this.Styles.Add("Inset");
// //cs.Border.Style = BorderStyleEnum.Inset;
// //cs = this.Styles.Add("None");
// //cs.Border.Style = BorderStyleEnum.None;
// //cs = this.Styles.Add("Raised");
// //cs.Border.Style = BorderStyleEnum.Raised;
// //cs = this.Styles.Add("CenterRight");
// //cs.TextAlign = TextAlignEnum.RightCenter; //.LeftCenter; // this is being ignored - probably due to RTF conversion
// //cs = this.Styles.Add("Yellow");
// //cs.BackColor = Color.Yellow;
// //cs = this.Styles.Add("Margins");
// //cs.Margins.Bottom = 5;
// //cs.Margins.Top = 10;
// //cs.Margins.Left = 15;
// //cs.Margins.Right = 20;
//}
#endregion //Grid and Cell Styles
#region Grid Size Adjustments
@@ -543,19 +499,93 @@ namespace Volian.Controls.Library
public void MergeSelection()
{
//string tstr = "";
//C1.Win.C1FlexGrid.CellRange sel = this.Selection;
//tstr = sel.Clip; // clip hold the data for the selected cells (used for un-merge)
this.MergedRanges.Add(this.Selection);
this.Invalidate();
}
public void SplitSelection()
public void SplitSelection(bool bSplitCols)
{
C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
if (this.MergedRanges.Contains(sel))
this.MergedRanges.Remove(sel);
this.Invalidate();
else //split cells
{
if (bSplitCols)
SplitSelectionColumns();
else
SplitSelectionRows();
}
this.Refresh();
this.AdjustGridControlSize();
}
private void SplitSelectionColumns()
{
CellRange cr = this.Selection;
int numSelCols = (cr.c2 - cr.c1) + 1;
// for each column in the selection, add a new column
for (int c = cr.c2; c >= cr.c1; c--)
InsertColumnAfter();
// include new columns in selection
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + numSelCols);
cr = this.Selection;
for (int r = 0; r < this.Rows.Count; r++)
for (int c = cr.c1; c <= cr.c2; c += 2)
{
if (!this.IsCellSelected(r, c))
{
//this.Select(r, c, r, c + 1);
CellRange tcr = this.GetCellRange(r, c, r, c+1);
this.MergedRanges.Add(tcr);
}
}
//this.Select(cr);
// Adjust selected column widths
for (int c = cr.c1; c <= cr.c2; c++)
{
int recWidth = this.GetCellRect(cr.r1, c).Width;
this.Cols[c].Width = Math.Max(recWidth / 2, _minSplitColWidth);
//Console.WriteLine("Cell[{0},{1}].Width = {2}", cr.r1, c, recWidth);
}
}
private void SplitSelectionRows()
{
CellRange cr = this.Selection;
int numSelRows = (cr.r2 - cr.r1) + 1;
//Console.WriteLine("numSelRows = {0}", numSelRows);
//Console.WriteLine("Inital Selection [{0},{1}] - [{2},{3}]", cr.r1, cr.c1, cr.r2, cr.c2);
// for each row in the selection, add a new row
for (int r = cr.r2; r >= cr.r1; r--)
{
//Console.WriteLine("Inserted new Row at [{0},{1}]", r, cr.c1);
InsertRowAfter();
}
// include new rows in selection
this.Select(cr.r1, cr.c1, cr.r2 + numSelRows, cr.c2);
cr = this.Selection;
//Console.WriteLine(" After Insert [{0},{1}] - [{2},{3}]", cr.r1, cr.c1, cr.r2, cr.c2);
for (int c = 0; c < this.Cols.Count; c++)
for (int r = cr.r1; r <= cr.r2; r += 2)
{
if (!this.IsCellSelected(r, c))
{
CellRange tcr = this.GetCellRange(r, c, r + 1, c);
this.MergedRanges.Add(tcr);
//Console.WriteLine("cellrange {0}", tcr);
//Console.WriteLine("merge [{0},{1}] - [{2},{3}]", r, c, r + 1, c);
}
}
// Adjust selected Row Heights
for (int r = cr.r1; r <= cr.r2; r++)
{
int recHeight = this.GetCellRect(r, cr.c1).Height;
this.Rows[r].Height = Math.Max(recHeight / 2, _minSplitRowHeight);
//Console.WriteLine("Cell[{0},{1}].Height = {2}", r, cr.c1, recHeight);
}
//foreach (CellRange crng in this.MergedRanges)
// Console.WriteLine("merge ranges [{0},{1}] - [{2},{3}]", crng.r1, crng.c1, crng.r2, crng.c2);
}
private void AdjustMergedRows(int row, bool above, bool removing)
@@ -740,11 +770,18 @@ namespace Volian.Controls.Library
private int GetRowInsertPosition(Boolean before)
{
int rtnrow;
CellRange cr = this.Selection;
CellRange selcr = this.Selection;
CellRange cr = selcr;
int idx = this.MergedRanges.IndexOf(cr.r1, cr.c2);
if (idx > -1)
cr = this.MergedRanges[idx]; // we want first or last row in merge range
rtnrow = (before) ? cr.r1 : cr.r2;
// The following is an adjustment needed when we are copying an entire row that includes some merged cells
if (selcr.c1 != selcr.c2)
{
while (!before && rtnrow > selcr.r2) rtnrow--;
while (before && rtnrow < selcr.r2) rtnrow++;
}
return rtnrow;
}
@@ -752,12 +789,18 @@ namespace Volian.Controls.Library
private int GetColInsertPosition(Boolean before)
{
int rtncol;
CellRange cr = this.Selection;
CellRange selcr = this.Selection;
CellRange cr = selcr;
int idx = this.MergedRanges.IndexOf(cr.r1, cr.c2);
if (idx > -1)
cr = this.MergedRanges[idx]; // we want the first of last col in merge range
rtncol = (before) ? cr.c1 : cr.c2;
// The following is an adjustment needed when we are copying an entire column that includes some merged cells
if (selcr.r1 != selcr.r2)
{
while (!before && rtncol > selcr.c2) rtncol--;
while (before && rtncol < selcr.c2) rtncol++;
}
return rtncol;
}
@@ -765,6 +808,8 @@ namespace Volian.Controls.Library
{
int newcol = this.GetColInsertPosition(true);
this.Cols.Insert(newcol);
// set new column width to same width as column from where it was inserted
this.Cols[newcol].Width = this.Cols[newcol + 1].Width;
this.AdjustMergedColumns(newcol, true, false);
this.AdjustGridControlSize();
}
@@ -776,6 +821,8 @@ namespace Volian.Controls.Library
this.Cols.Add(1);
else
this.Cols.Insert(colidx + 1);
// set new column width to same width as column from where it was inserted
this.Cols[colidx + 1].Width = this.Cols[colidx].Width;
this.AdjustMergedColumns(colidx + 1, false, false);
this.AdjustGridControlSize();
}
@@ -784,6 +831,8 @@ namespace Volian.Controls.Library
{
int newrow = this.GetRowInsertPosition(true);
this.Rows.Insert(newrow);
// set new row Height to same heidht as row from where it was inserted
this.Rows[newrow].Height = this.Rows[newrow+1].Height;
this.AdjustMergedRows(newrow, true, false);
this.AdjustGridControlSize();
}
@@ -795,6 +844,8 @@ namespace Volian.Controls.Library
this.Rows.Add(1);
else
this.Rows.Insert(rowidx + 1);
// set new row Height to same heidht as row from where it was inserted
this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height;
this.AdjustMergedRows(rowidx + 1, false, false);
this.AdjustGridControlSize();
}
@@ -978,6 +1029,11 @@ namespace Volian.Controls.Library
if (aryCellList != null && aryCellList.Count > 0)
{
// Since we're pasting an entire row, make sure the current selection includes
// all the columns to ensure proper logic path when inserting a new (empty) row
this.SelectionMode = SelectionModeEnum.Row;
this.Select(this.Selection.r1, 0, this.Selection.r2, this.Cols.Count - 1, true);
this.SelectionMode = SelectionModeEnum.Default;
// get row/column starting position in which new rows will be added
int startrow = this.Selection.r1 + ((pp == enmPastePos.After) ? 1 : 0);
int startcol = this.Selection.c1;
@@ -1004,19 +1060,24 @@ namespace Volian.Controls.Library
if (aryCellList != null && aryCellList.Count > 0)
{
// Since we're pasting an entire column, make sure the current selection includes
// all the rows to ensure proper logic path when inserting a new (empty) column
this.SelectionMode = SelectionModeEnum.Column;
this.Select(0, this.Selection.c1, this.Rows.Count - 1, this.Selection.c2, true);
this.SelectionMode = SelectionModeEnum.Default;
// get row/column starting position in which new rows will be added
int startrow = 0;//grd.Selection.r1+((pp == enmPastePos.After) ? 1 : 0);
int startcol = this.Selection.c1 + ((pp == enmPastePos.After) ? 1 : 0);
// get the number of rows needed based on what was save to the clipboard
// get the number of columns needed based on what was save to the clipboard
int numcols = Math.Max(1, (aryCellList.Count / this.Rows.Count));
// insert that number of new rows.
if (pp != enmPastePos.Replace) // insert new rows before or after
// insert that number of new columns.
if (pp != enmPastePos.Replace) // insert new columns before or after
for (int c = 0; c < numcols; c++)
if (pp == enmPastePos.After) // create new rows after
if (pp == enmPastePos.After) // create new columns after
this.InsertColumnAfter();
else
this.InsertColumnBefore();
// copy each grid cell text (aryCellList) into the newly inserted rows
// copy each grid cell text (aryCellList) into the newly inserted colmns
this.CopyTextFromCellRange(aryCellList, startrow, startcol, startrow + this.Rows.Count - 1, startcol + numcols - 1);
this.AdjustGridControlSize();
}
@@ -1417,6 +1478,22 @@ namespace Volian.Controls.Library
}
#endregion //Bug Work Around
//public void CenterTheCellText()
//{
// // Cannot use this type of text allignment with RTF text cells
// CellRange cr = this.Selection;
// for (int rw = cr.r1; rw <= cr.r2; rw++)
// for (int col = cr.c1; col <= cr.c2; col++)
// {
// CellRange tmp = this.GetCellRange(rw, col, rw, col);
// string StyleName = string.Format("R{0}C{1}Style", rw, col);
// CellStyle cs = this.Styles.Add(StyleName, tmp.Style);
// cs.TextAlign = TextAlignEnum.CenterCenter;
// tmp.Style = cs;
// }
//}
}
#region RTF Class for Cell rendering
class RTF : StepRTB //RichTextBox
@@ -1811,6 +1888,7 @@ namespace Volian.Controls.Library
// Clip get the value (text) of all the cells in the selected range
// This is saved as one RTF string.
Clipboard.SetDataObject(cr.Clip, true); // the "true" make the copy persistent
//Console.WriteLine("\nClip: '{0}' \n'{1}'", cr.Clip,cr.DataDisplay);
}
public ArrayList Get()
@@ -1829,40 +1907,77 @@ namespace Volian.Controls.Library
// This function will separate each cell text and place them in an array.
// This allow the clipboard information to be pasted independently from
// how it was selected.
// Bug fix: the CellRange.Clip (see cr.clip in the Put() function above) is replacing
// new lines with spaces. We need to put them back.
instr = instr.Replace(@"}} \", "}}\r\n\\");
string tstr = ""; // this will contain the parsed out cell text
ArrayList arylstCellStrings = new ArrayList();
int sidx = 0; // start index
int tidx = 0;
if (instr != null)
{
int idx = instr.IndexOf("\r\n\t"); // cell boarder
if (idx < 0) idx = instr.IndexOf("\r\n\r"); // new line (needed for multiple lines in one cell)
int idx = instr.IndexOf(@"{\rtf",sidx+1); // cell boarder
while (idx > 0)
{
tstr = instr.Substring(sidx, idx - sidx);
tidx = tstr.IndexOf("\r\n\r");
if (tidx > 0)
{
idx = instr.IndexOf("\r\n\r", sidx);
tstr = instr.Substring(sidx, idx - sidx);
}
arylstCellStrings.Add(tstr.Substring(tstr.IndexOf("{\\rtf")));
sidx = idx + 3;
if (sidx < instr.Length)
{
idx = instr.IndexOf("\r\n\t", sidx);
if (idx < 0) idx = instr.IndexOf("\r\n\r", sidx);
}
tstr = tstr.Substring(0, tstr.LastIndexOf('}') + 1);
//Console.WriteLine("\ntstr: '{0}'", tstr);
arylstCellStrings.Add(tstr);
sidx = idx;
idx = instr.IndexOf(@"{\rtf",sidx+1);
}
if (sidx < instr.Length)
{
tstr = instr.Substring(sidx);
arylstCellStrings.Add(tstr.Substring(tstr.IndexOf("{\\rtf")));
arylstCellStrings.Add(tstr);
}
}
return arylstCellStrings;
}
//private ArrayList GetCellStrings(string instr)
//{
// // The table cells placed on the clipboard is saved as one long RTF string.
// // "\r\n\t" defines a cell border
// // "\r\n\r" defines beginning of next line (row)
// // This function will separate each cell text and place them in an array.
// // This allow the clipboard information to be pasted independently from
// // how it was selected.
// string tstr = ""; // this will contain the parsed out cell text
// ArrayList arylstCellStrings = new ArrayList();
// int sidx = 0; // start index
// int tidx = 0;
// if (instr != null)
// {
// int idx = instr.IndexOf("\r\n\t"); // cell boarder
// if (idx < 0) idx = instr.IndexOf("\r\n\r"); // new line (needed for multiple lines in one cell)
// while (idx > 0)
// {
// tstr = instr.Substring(sidx, idx - sidx);
// tidx = tstr.IndexOf("\r\n\r");
// if (tidx > 0)
// {
// idx = instr.IndexOf("\r\n\r", sidx);
// tstr = instr.Substring(sidx, idx - sidx);
// }
// arylstCellStrings.Add(tstr.Substring(tstr.IndexOf("{\\rtf")));
// sidx = idx + 3;
// if (sidx < instr.Length)
// {
// idx = instr.IndexOf("\r\n\t", sidx);
// if (idx < 0) idx = instr.IndexOf("\r\n\r", sidx);
// }
// }
// if (sidx < instr.Length)
// {
// tstr = instr.Substring(sidx);
// arylstCellStrings.Add(tstr.Substring(tstr.IndexOf("{\\rtf")));
// }
// }
// return arylstCellStrings;
//}
}
[Serializable]