This commit is contained in:
@@ -8,17 +8,48 @@ using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using Volian.Controls.Library;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using C1.Win.C1FlexGrid;
|
||||
|
||||
namespace Volian.Controls.Library
|
||||
{
|
||||
public delegate void VlnFlexGridEvent(object sender, EventArgs args);
|
||||
public delegate void VlnFlexGridCursorMovementEvent(object sender, VlnFlexGridCursorMovementEventArgs args);
|
||||
public partial class VlnFlexGrid : C1.Win.C1FlexGrid.C1FlexGrid
|
||||
{
|
||||
public event VlnFlexGridEvent OpenAnnotations;
|
||||
public void OnOpenAnnotations(object sender, EventArgs args)
|
||||
{
|
||||
if (OpenAnnotations != null) OpenAnnotations(sender, args);
|
||||
}
|
||||
public event VlnFlexGridCursorMovementEvent CursorMovement;
|
||||
internal void OnCursorMovement(object sender, VlnFlexGridCursorMovementEventArgs args)
|
||||
{
|
||||
if (CursorMovement != null) CursorMovement(sender, args);
|
||||
}
|
||||
private TableCellEditor _tableCellEditor;
|
||||
private TableClipBoardFuncts _clpbrdCpyPste;
|
||||
private int _minSplitColWidth = 10;
|
||||
private int _minSplitRowHeight = 20;
|
||||
|
||||
public TableCellEditor TableCellEditor
|
||||
{
|
||||
get { return _tableCellEditor; }
|
||||
set { _tableCellEditor = value; }
|
||||
}
|
||||
private TableClipBoardFuncts _clpbrdCpyPste;
|
||||
private int _minColSplitWidth = 10;
|
||||
//private int _minRowSplitHeight = 23;
|
||||
|
||||
//private int _minSplitColWidth = 10;
|
||||
//private int _minSplitRowHeight = 20;
|
||||
private E_ViewMode _vwMode = E_ViewMode.Edit;
|
||||
public E_ViewMode VwMode
|
||||
{
|
||||
get { return _vwMode; }
|
||||
set
|
||||
{
|
||||
_vwMode = value;
|
||||
AllowEditing = _vwMode == E_ViewMode.Edit;
|
||||
}
|
||||
}
|
||||
#region Grid Initialize
|
||||
|
||||
public VlnFlexGrid()
|
||||
@@ -33,14 +64,118 @@ namespace Volian.Controls.Library
|
||||
SetupGrid(rows, cols);
|
||||
}
|
||||
|
||||
public VlnFlexGrid(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
_tableCellEditor = new TableCellEditor(this);
|
||||
public VlnFlexGrid(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
SetupGrid(1, 1);
|
||||
}
|
||||
|
||||
//public VlnFlexGrid(IContainer container)
|
||||
//{
|
||||
// container.Add(this);
|
||||
|
||||
// InitializeComponent();
|
||||
// _tableCellEditor = new TableCellEditor(this);
|
||||
// _tableCellEditor.ContentsResized += new ContentsResizedEventHandler(_tableCellEditor_ContentsResized);
|
||||
//}
|
||||
|
||||
void _tableCellEditor_ContentsResized(object sender, ContentsResizedEventArgs e)
|
||||
{
|
||||
if (_tableCellEditor._initializingEdit) return;
|
||||
CellRange cr = GetMergedRange(Row, Col);
|
||||
int oH = cr.UserData == null? 0 : (int)cr.UserData;
|
||||
int nH = _tableCellEditor.ContentsRectangle.Height;
|
||||
int Hadj = (nH - oH);
|
||||
cr.UserData = _tableCellEditor.ContentsRectangle.Height;
|
||||
int cellHeight = GetCellHeight(Row,Col);
|
||||
int cellheightNLines = cellHeight / (Rows.DefaultSize - 3);
|
||||
int nHNLines = nH / (Rows.DefaultSize - 3);
|
||||
if (Hadj != 0)
|
||||
{
|
||||
int curHeight = (Rows[Row].Height == -1) ? Rows.DefaultSize : Rows[Row].Height;
|
||||
//if (Hadj > 0 && cellHeight <= oH)
|
||||
if (Hadj > 0 && cellheightNLines < nHNLines)
|
||||
curHeight += (Rows.DefaultSize - 3);
|
||||
if (Hadj < 0 && CanReduceRow())
|
||||
curHeight -= (Rows.DefaultSize-3);
|
||||
Rows[Row].Height = curHeight;
|
||||
AdjustGridControlSize();
|
||||
}
|
||||
//cr.UserData = _tableCellEditor.ContentsRectangle.Height;
|
||||
//int mh = GetMaxRowHeight();
|
||||
////Rows[Row].Height = mh + 2;
|
||||
//int h = 0;
|
||||
//if (cr.r1 == cr.r2 && cr.c1 == cr.c2)
|
||||
// h = Rows[Row].Height - 2;
|
||||
//else
|
||||
//{
|
||||
// for (int r = cr.r1; r <= cr.r2; r++)
|
||||
// h += Rows[r].Height - 2;
|
||||
//}
|
||||
//Rows[Row].Height += (mh - h);
|
||||
////AdjustGridControlSize();
|
||||
}
|
||||
private int GetCellHeight(int row, int col)
|
||||
{
|
||||
int height = 0;
|
||||
CellRange cr = GetMergedRange(row, col);
|
||||
for (int r = cr.r1; r <= cr.r2; r++)
|
||||
{
|
||||
height += (Rows[r].Height == -1) ? Rows.DefaultSize -3 : Rows[r].Height - 3;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
private bool CanReduceRow()
|
||||
{
|
||||
int curRowHeight = (Rows[Row].Height == -1) ? Rows.DefaultSize - 3 : Rows[Row].Height -3;
|
||||
int curRowHeightNLines = curRowHeight / (Rows.DefaultSize - 3);
|
||||
bool bReduce = (curRowHeight > (Rows.DefaultSize - 3));
|
||||
if (bReduce)
|
||||
{
|
||||
for (int c = 0; c < Cols.Count; c++)
|
||||
{
|
||||
CellRange cr = GetMergedRange(Row, c);
|
||||
if (Row >= cr.r1 && Row <= cr.r2)
|
||||
{
|
||||
int mergeCellHeightNLines = GetCellHeight(Row, c) / (Rows.DefaultSize - 3);
|
||||
//int ud = (cr.UserData == null) ? 0 : (int)cr.UserData;
|
||||
//if ((c != Col) && curRowHeight <= ud && ud >= mergeCellHeight)
|
||||
// bReduce = false;
|
||||
int ud = ((cr.UserData == null) ? 0 : (int)cr.UserData) / (Rows.DefaultSize - 3);
|
||||
if ((c != Col) && curRowHeightNLines <= ud && ud >= mergeCellHeightNLines)
|
||||
bReduce = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bReduce;
|
||||
}
|
||||
//private int GetMaxRowHeight()
|
||||
//{
|
||||
// int maxRTFHeight = _minRowSplitHeight; //Rows.DefaultSize;// the smallest a row can be
|
||||
// Console.WriteLine("=================================================================");
|
||||
// for (int c = 0; c < Cols.Count; c++)
|
||||
// {
|
||||
// CellRange cr = GetMergedRange(Row, c);//GetCellRange(Row, c);
|
||||
// maxRTFHeight = Math.Max(maxRTFHeight, (int)cr.UserData);
|
||||
// if (c==0)
|
||||
// Console.WriteLine("Height in Row[{0}] = {1}", Row, Rows[Row].Height);
|
||||
// Console.WriteLine("UserData Cell[{0},{1}] = {2}", Row, c, cr.UserData);
|
||||
// }
|
||||
// return maxRTFHeight;
|
||||
//}
|
||||
|
||||
//private bool IsInMergeRange(int row, int col)
|
||||
//{
|
||||
// //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);
|
||||
//}
|
||||
|
||||
private void SetupGrid(int numrows, int numcols) //C1FlexGrid NewGrid()
|
||||
{
|
||||
// setup the default size of each cell in the table/grid
|
||||
@@ -70,25 +205,109 @@ namespace Volian.Controls.Library
|
||||
this.Styles.Highlight.BackColor = Color.LightCyan;
|
||||
this.Styles.Highlight.ForeColor = Color.Black;
|
||||
this.Styles.Focus.BackColor = Color.LightCyan;
|
||||
this.HighLight = HighLightEnum.Always;
|
||||
this.HighLight = HighLightEnum.WithFocus;
|
||||
|
||||
this.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom;
|
||||
|
||||
this.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.Both;
|
||||
|
||||
|
||||
_tableCellEditor = new TableCellEditor(this);
|
||||
_tableCellEditor.ContentsResized += new ContentsResizedEventHandler(_tableCellEditor_ContentsResized);
|
||||
_clpbrdCpyPste = new TableClipBoardFuncts();
|
||||
|
||||
//this.Enter += new System.EventHandler(this.Grid_Enter);
|
||||
this.AfterResizeRow += new C1.Win.C1FlexGrid.RowColEventHandler(this.Grid_AfterResize);
|
||||
this.StartEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._StartEdit);
|
||||
this.AfterEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._AfterEdit);
|
||||
//this.LeaveEdit += new RowColEventHandler(VlnFlexGrid_LeaveEdit);
|
||||
this.AfterScroll += new C1.Win.C1FlexGrid.RangeEventHandler(this._AfterScroll);
|
||||
this.AfterResizeColumn += new C1.Win.C1FlexGrid.RowColEventHandler(this.Grid_AfterResize);
|
||||
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this._KeyPress);
|
||||
this.OwnerDrawCell += new OwnerDrawCellEventHandler(this.Grid_OwnerDrawCell);
|
||||
this.LeaveCell += new EventHandler(VlnFlexGrid_LeaveCell);
|
||||
|
||||
//this.ValidateEdit += new ValidateEditEventHandler(VlnFlexGrid_ValidateEdit);
|
||||
this.KeyDown += new KeyEventHandler(VlnFlexGrid_KeyDown);
|
||||
this.KeyUp +=new KeyEventHandler(VlnFlexGrid_KeyUp);
|
||||
this.SelChange += new EventHandler(VlnFlexGrid_SelChange);
|
||||
TableCellEditor.EditMode = TableCellEditor.Visible; // need to comment out for compile for only jsj - 07FEB2011
|
||||
}
|
||||
void VlnFlexGrid_SelChange(object sender, EventArgs e)
|
||||
{
|
||||
// Possibilities
|
||||
// Selection is a single cell
|
||||
// It is part of a range
|
||||
// It is
|
||||
//Console.WriteLine("Where Am I {0} {1} {2}", Selection, GetMergedRange(Row, Col), Selection.Equals(GetMergedRange(Row, Col)));
|
||||
}
|
||||
void VlnFlexGrid_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Control)
|
||||
{
|
||||
if (e.Alt)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.M:
|
||||
OnOpenAnnotations(this, new EventArgs());
|
||||
e.Handled = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void VlnFlexGrid_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Left:
|
||||
if (e.Shift) return;
|
||||
_tableCellEditor.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlLeft : E_ArrowKeys.Left);
|
||||
e.Handled = true;
|
||||
break;
|
||||
case Keys.Up:
|
||||
if (e.Shift) return;
|
||||
_tableCellEditor.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlUp : E_ArrowKeys.Up);
|
||||
e.Handled = true;
|
||||
break;
|
||||
case Keys.Right:
|
||||
if (e.Shift) return;
|
||||
_tableCellEditor.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlRight : E_ArrowKeys.Right);
|
||||
e.Handled = true;
|
||||
break;
|
||||
case Keys.Down:
|
||||
if (e.Shift) return;
|
||||
_tableCellEditor.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlDown : E_ArrowKeys.Down);
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VlnFlexGrid_LeaveCell(object sender, EventArgs e)
|
||||
{
|
||||
//CellStyle csd = this.CursorCell.StyleDisplay;
|
||||
//CellStyle cs = this.GetCellRange(Row, Col).Style;
|
||||
//if (cs != null)
|
||||
//{
|
||||
// Console.WriteLine("LeaveCell Style = {0}", cs.Name);
|
||||
// Console.WriteLine("LeaveCell StyleDisplay = {0}", csd.Name);
|
||||
// cs.ForeColor = Color.Black;
|
||||
//}
|
||||
CellStyle cs = this.Styles["Focus"];
|
||||
cs.ForeColor = Color.Black;
|
||||
cs = this.Styles["Highlight"];
|
||||
cs.ForeColor = Color.Black;
|
||||
}
|
||||
|
||||
//void VlnFlexGrid_LeaveEdit(object sender, RowColEventArgs e)
|
||||
//{
|
||||
// //Console.WriteLine("LeaveEdit Style = {0}", this.GetCellRange(e.Row, e.Col).Style.Name);
|
||||
// this.GetCellRange(e.Row, e.Col).Style.ForeColor = Color.Black;
|
||||
//}
|
||||
|
||||
private void Grid_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
|
||||
{
|
||||
@@ -109,10 +328,14 @@ namespace Volian.Controls.Library
|
||||
// draw the RTF text
|
||||
if (e.Bounds.Width > 0 && e.Bounds.Height > 0)
|
||||
{
|
||||
_rtf.Width = Cols[e.Col].Width;
|
||||
_rtf.Rtf = rtfText;
|
||||
_rtf.ForeColor = e.Style.ForeColor;
|
||||
_rtf.BackColor = e.Style.BackColor;
|
||||
_rtf.Render(e.Graphics, e.Bounds);
|
||||
//CellRange cr = GetCellRange(e.Row, e.Col);
|
||||
//Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height);
|
||||
//cr.UserData = _rtf.ContentsRectangle.Height;
|
||||
}
|
||||
|
||||
// and draw border last
|
||||
@@ -195,6 +418,64 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
|
||||
public void VerticalCenterText()
|
||||
{
|
||||
StepRTB myStepRTB = new StepRTB();
|
||||
CellRange selRange = this.Selection;
|
||||
for (int r = selRange.r1; r <= selRange.r2; r++)
|
||||
for (int c = selRange.c1; c <= selRange.c2; c++)
|
||||
{
|
||||
CellRange mr = this.GetMergedRange(r, c);
|
||||
if (mr.r1 == r)
|
||||
{
|
||||
int editHeight = (int)mr.UserData;
|
||||
int cellHeight = GetCellHeight(mr.r1, mr.c1);
|
||||
if (editHeight < cellHeight)
|
||||
{
|
||||
myStepRTB.Rtf = (string)mr.Data;
|
||||
RTBAPI.SetSpaceBefore(myStepRTB, (cellHeight - editHeight) / 2);
|
||||
PutCellRTFString(mr.r1, mr.c1, myStepRTB.Rtf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void VerticalTopText()
|
||||
{
|
||||
StepRTB myStepRTB = new StepRTB();
|
||||
CellRange selRange = this.Selection;
|
||||
for (int r = selRange.r1; r <= selRange.r2; r++)
|
||||
for (int c = selRange.c1; c <= selRange.c2; c++)
|
||||
{
|
||||
CellRange mr = this.GetMergedRange(r, c);
|
||||
if (mr.r1 == r)
|
||||
{
|
||||
myStepRTB.Rtf = (string)mr.Data;
|
||||
RTBAPI.SetSpaceBefore(myStepRTB, 0);
|
||||
PutCellRTFString(mr.r1, mr.c1, myStepRTB.Rtf);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void VerticalBottomText()
|
||||
{
|
||||
StepRTB myStepRTB = new StepRTB();
|
||||
CellRange selRange = this.Selection;
|
||||
for (int r = selRange.r1; r <= selRange.r2; r++)
|
||||
for (int c = selRange.c1; c <= selRange.c2; c++)
|
||||
{
|
||||
CellRange mr = this.GetMergedRange(r, c);
|
||||
if (mr.r1 == r)
|
||||
{
|
||||
int editHeight = (int)mr.UserData;
|
||||
int cellHeight = GetCellHeight(mr.r1, mr.c1);
|
||||
if (editHeight < cellHeight)
|
||||
{
|
||||
myStepRTB.Rtf = (string)mr.Data;
|
||||
RTBAPI.SetSpaceBefore(myStepRTB, (cellHeight - editHeight));
|
||||
PutCellRTFString(mr.r1, mr.c1, myStepRTB.Rtf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public void SetupCellStyles()
|
||||
//{
|
||||
@@ -245,6 +526,7 @@ namespace Volian.Controls.Library
|
||||
|
||||
int height = 0;
|
||||
foreach (C1.Win.C1FlexGrid.Row row in this.Rows)
|
||||
//height += (row.Height >= 0) ? row.Height : this.Rows.DefaultSize + 2;
|
||||
height += (row.Height >= 0) ? row.Height : this.Rows.DefaultSize;
|
||||
|
||||
this.Size = new Size(wid + difW, height + difH);
|
||||
@@ -293,6 +575,8 @@ namespace Volian.Controls.Library
|
||||
this[r, c] = trtb.Rtf; // save the cleaned up and processed cell text as RTF
|
||||
|
||||
this.Select(r, c, false);
|
||||
CellRange sel = this.Selection;
|
||||
//sel.UserData = trtb.ContentsRectangle.Height;
|
||||
|
||||
// Now see the the selected row,col is in the defined merge ranges
|
||||
bool mrgrows = false;
|
||||
@@ -315,23 +599,53 @@ namespace Volian.Controls.Library
|
||||
if (!mrgrows)
|
||||
{
|
||||
// add adjustment for grid and cell borders
|
||||
int newheight = trtb.Height + 2;// (int)numGridLineBorderAdj.Value;
|
||||
int newheight = trtb.Height + 3;
|
||||
|
||||
//Console.WriteLine("{0} {1} {2} '{3}'", r, c, newheight,trtb.Text);
|
||||
if (newheight > this.Rows[r].Height)
|
||||
{
|
||||
//Console.WriteLine("1 Row {0} Old Height = {1}, New Height = {2}", r, Rows[r].Height, newheight);
|
||||
this.Rows[r].Height = newheight;
|
||||
}
|
||||
}
|
||||
// IF the column of the selected sell is NOT in merged range
|
||||
// IF the column of the selected cell is NOT in merged range
|
||||
// then go ahead and adjust the column width (if needed)
|
||||
if (!mrgcols)
|
||||
{
|
||||
// add adjustment for grid and cell borders
|
||||
int newwidth = trtb.Width + 2;//(int)numGridLineBorderAdj.Value;
|
||||
int newwidth = trtb.Width + 2;
|
||||
|
||||
if (newwidth > this.Cols[c].Width || AllowWidthShrink || r == 0)
|
||||
this.Cols[c].Width = newwidth;
|
||||
}
|
||||
}
|
||||
if (mrgrows && tstr != null)
|
||||
{
|
||||
CellRange cr = GetMergedRange(r, c);
|
||||
//Console.WriteLine("grid[{0},{1}] merge = {2}", r, c,cr);
|
||||
if (cr.r1 == r && cr.c1 == c)
|
||||
{
|
||||
// if in merged rows, then make sure the cell's height is large enough
|
||||
string[] strary = tstr.Split("\n".ToCharArray());
|
||||
// count number of lines of text
|
||||
int nlines = strary.Length;
|
||||
// count number of rows in merge range
|
||||
int nrows = (cr.r2 - cr.r1) + 1;
|
||||
//Console.WriteLine("2 Row {0} Height = {1}", cr.r1, Rows[cr.r1].Height);
|
||||
while (nlines > nrows)
|
||||
{
|
||||
// add length to first row in merged range
|
||||
int h = this.Rows[cr.r1].Height;
|
||||
int defH = Rows.DefaultSize - 3;
|
||||
//h = (h == -1) ? _minRowHeight * 2 : h + _minRowHeight;
|
||||
h = (h == -1) ? (defH * 2) + 3 : h + defH;
|
||||
//h = (h == -1) ? (Rows.DefaultSize + 2) * 2 : h + Rows.DefaultSize + 2;
|
||||
//Console.WriteLine("3 Row {0} Old Height = {1}, New Height = {2}", cr.r1, Rows[cr.r1].Height, h);
|
||||
this.Rows[cr.r1].Height = h;
|
||||
nrows++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Grid_AfterResize(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
|
||||
@@ -350,11 +664,14 @@ namespace Volian.Controls.Library
|
||||
// - adjust the grid dimensions based on the cell info.
|
||||
for (int r = 0; r < this.Rows.Count; r++)
|
||||
{
|
||||
this.Rows[r].Height = 20;//10;
|
||||
this.Rows[r].Height = Rows.DefaultSize;//_minRowHeight;//20;//10;
|
||||
for (int c = 0; c < this.Cols.Count; c++)
|
||||
this.AdjustGridHeightWidth(r, c);
|
||||
}
|
||||
//this.Refresh();
|
||||
//Application.DoEvents();
|
||||
this.AdjustGridControlSize();
|
||||
SetupCellUserData();
|
||||
}
|
||||
|
||||
private bool RemoveBoldUlineItalicChars(string str)
|
||||
@@ -442,6 +759,13 @@ 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;
|
||||
}
|
||||
@@ -449,6 +773,8 @@ 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();
|
||||
}
|
||||
|
||||
@@ -499,6 +825,24 @@ namespace Volian.Controls.Library
|
||||
if (dr == DialogResult.Yes)
|
||||
cr.Clear(ClearFlags.Content);
|
||||
}
|
||||
public void SetupCellUserData()
|
||||
{
|
||||
for (int r = 0; r < Rows.Count; r++)
|
||||
for (int c = 0; c < Cols.Count; c++)
|
||||
{
|
||||
string rtfText = GetDataDisplay(r, c);
|
||||
if (rtfText.StartsWith(@"{\rtf"))
|
||||
{
|
||||
RTF _rtf = new RTF();
|
||||
_rtf.Width = Cols[c].Width;
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion //Cell Text
|
||||
|
||||
#region Merged / Split Range
|
||||
@@ -550,7 +894,7 @@ namespace Volian.Controls.Library
|
||||
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);
|
||||
this.Cols[c].Width = Math.Max(recWidth / 2, _minColSplitWidth);
|
||||
//Console.WriteLine("Cell[{0},{1}].Width = {2}", cr.r1, c, recWidth);
|
||||
}
|
||||
}
|
||||
@@ -586,7 +930,8 @@ namespace Volian.Controls.Library
|
||||
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);
|
||||
this.Rows[r].Height = Math.Max(recHeight / 2, Rows.DefaultSize);
|
||||
//this.Rows[r].Height = Math.Max(recHeight / 2, _minRowSplitHeight);
|
||||
//Console.WriteLine("Cell[{0},{1}].Height = {2}", r, cr.c1, recHeight);
|
||||
}
|
||||
|
||||
@@ -838,7 +1183,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.Rows[newrow].Height = (Rows[newrow + 1].Height == -1) ? Rows.DefaultSize : Rows[newrow + 1].Height;
|
||||
//this.Rows[newrow].Height = this.Rows[newrow + 1].Height;
|
||||
this.AdjustMergedRows(newrow, true, false);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
@@ -851,7 +1197,8 @@ namespace Volian.Controls.Library
|
||||
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.Rows[rowidx + 1].Height = (Rows[rowidx].Height == -1) ? Rows.DefaultSize : Rows[rowidx].Height;
|
||||
//this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height;
|
||||
this.AdjustMergedRows(rowidx + 1, false, false);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
@@ -1460,7 +1807,44 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
string cellstr = this[cr.r1, cr.c1].ToString();
|
||||
string[] strary = cellstr.Split("\n".ToCharArray());
|
||||
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);
|
||||
string jstr = "";
|
||||
foreach (string tmpstr in strary)
|
||||
{
|
||||
int tlen = tmpstr.Trim().Length;
|
||||
if (!bNeedToTrim || tlen > 0)
|
||||
{
|
||||
if (jstr.Length > 0) jstr += "\n";
|
||||
jstr += tmpstr;
|
||||
}
|
||||
else nlines--;
|
||||
bNeedToTrim = (tlen == 0 && nlines > nrows);
|
||||
}
|
||||
this[cr.r1, cr.c1] = jstr;
|
||||
}
|
||||
|
||||
#endregion //Import / Export Grid
|
||||
|
||||
#region Bug Work Around
|
||||
@@ -1628,15 +2012,17 @@ namespace Volian.Controls.Library
|
||||
private int _row, _col;
|
||||
private char _pendingKey;
|
||||
private bool _cancel;
|
||||
public bool _initializingEdit;
|
||||
|
||||
// constructor: attach to owner grid
|
||||
public TableCellEditor(VlnFlexGrid owner)
|
||||
{
|
||||
Visible = false;
|
||||
AutoSize = false;
|
||||
BackColor = Color.Beige;
|
||||
BackColor = Color.SkyBlue;
|
||||
BorderStyle = BorderStyle.None;
|
||||
|
||||
_initializingEdit = false;
|
||||
_pendingKey = (char)0;
|
||||
_cancel = false;
|
||||
_owner = owner;
|
||||
@@ -1650,10 +2036,11 @@ namespace Volian.Controls.Library
|
||||
// start editing: move to cell and activate
|
||||
public void StartEditing(int row, int col)
|
||||
{
|
||||
_initializingEdit = true;
|
||||
// save coordinates of cell being edited
|
||||
_row = row;
|
||||
_col = col;
|
||||
this.Clear();
|
||||
//this.Clear(); //jsj
|
||||
// assume we'll save the edits
|
||||
_cancel = false;
|
||||
// move editor over the current cell
|
||||
@@ -1685,6 +2072,7 @@ namespace Volian.Controls.Library
|
||||
|
||||
// and get the focus
|
||||
Select();
|
||||
_initializingEdit = false;
|
||||
}
|
||||
|
||||
void TableCellEditor_CursorKeyPress(object sender, KeyEventArgs args)
|
||||
@@ -1696,7 +2084,7 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
int row = _owner.Selection.r1;
|
||||
int col = _owner.Selection.c1;
|
||||
CellRange cr = _owner.Selection;
|
||||
CellRange cr = _owner.GetMergedRange(row, col);
|
||||
//Console.WriteLine("keystroke {0} selection {1},{2}", args.Key, row, col);
|
||||
//vlnStackTrace.ShowStack("keystroke {0} selection {1},{2}", args.Key, row, col);
|
||||
_owner.Select();
|
||||
@@ -1704,8 +2092,8 @@ namespace Volian.Controls.Library
|
||||
// if so, use the merged range instead of the selected range
|
||||
// so that we can jump to the top/bottom/left/right of the range
|
||||
// before attempting the move to the next grid cell.
|
||||
int idx = _owner.MergedRanges.IndexOf(row, col);
|
||||
if (idx > -1) cr = _owner.MergedRanges[idx];
|
||||
//int idx = _owner.MergedRanges.IndexOf(row, col);
|
||||
//if (idx > -1) cr = _owner.MergedRanges[idx];
|
||||
|
||||
switch (args.Key)
|
||||
{
|
||||
@@ -1713,31 +2101,51 @@ namespace Volian.Controls.Library
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.Down:
|
||||
row = cr.r2;
|
||||
if (row < _owner.Rows.Count - 1)
|
||||
_owner.Select(row + 1, col);
|
||||
_owner.Select(_owner.GetMergedRange(row + 1, col));
|
||||
else
|
||||
_owner.OnCursorMovement(this, new VlnFlexGridCursorMovementEventArgs(args.Key));
|
||||
break;
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.CtrlLeft:
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.Left:
|
||||
col = cr.c1;
|
||||
if (col > 0)
|
||||
_owner.Select(row, col - 1);
|
||||
_owner.Select(_owner.GetMergedRange(row, col - 1));
|
||||
else if(row > 0)
|
||||
_owner.Select(_owner.GetMergedRange(row - 1, _owner.Cols.Count - 1));
|
||||
else
|
||||
_owner.OnCursorMovement(this, new VlnFlexGridCursorMovementEventArgs(args.Key));
|
||||
break;
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.CtrlRight:
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.Right:
|
||||
col = cr.c2;
|
||||
if (col < _owner.Cols.Count - 1)
|
||||
_owner.Select(row, col + 1);
|
||||
_owner.Select(_owner.GetMergedRange(row, col + 1));
|
||||
else if (cr.r2 < _owner.Rows.Count - 1)
|
||||
{
|
||||
CellRange crDest = _owner.GetMergedRange(cr.r2 + 1, 0);
|
||||
if (cr.r2 < crDest.r1) // It will move to the correct place
|
||||
_owner.Select(crDest);
|
||||
else if (crDest.r2 < _owner.Rows.Count)
|
||||
_owner.Select(_owner.GetMergedRange(crDest.r2 + 1, 0));
|
||||
else
|
||||
_owner.OnCursorMovement(this, new VlnFlexGridCursorMovementEventArgs(args.Key));
|
||||
}
|
||||
else
|
||||
_owner.OnCursorMovement(this, new VlnFlexGridCursorMovementEventArgs(args.Key));
|
||||
break;
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.CtrlUp:
|
||||
case VEPROMS.CSLA.Library.E_ArrowKeys.Up:
|
||||
row = cr.r1;
|
||||
if (row > 0)
|
||||
_owner.Select(row - 1, col);
|
||||
_owner.Select(_owner.GetMergedRange(row - 1, col));
|
||||
else
|
||||
_owner.OnCursorMovement(this, new VlnFlexGridCursorMovementEventArgs(args.Key));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//Console.WriteLine("selection {0}", _owner.Selection);
|
||||
_owner.Focus(); // focus was jumping out of the grid this keeps it in.
|
||||
//_owner.Focus(); // focus was jumping out of the grid this keeps it in.
|
||||
}
|
||||
|
||||
// after edit handler (custom editor)
|
||||
@@ -2004,4 +2412,17 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
|
||||
#endregion // TableClipBoardFuncts Class
|
||||
public class VlnFlexGridCursorMovementEventArgs
|
||||
{
|
||||
private E_ArrowKeys _Key;
|
||||
public E_ArrowKeys Key
|
||||
{
|
||||
get { return _Key; }
|
||||
set { _Key = value; }
|
||||
}
|
||||
public VlnFlexGridCursorMovementEventArgs(E_ArrowKeys key)
|
||||
{
|
||||
_Key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user