This commit is contained in:
John Jenko 2011-04-20 16:08:22 +00:00
parent 6a63b4634c
commit a54391cc69

View File

@ -1975,7 +1975,7 @@ namespace Volian.Controls.Library
}
private void SplitSelectionColumns()
{
bool nonMergedInSelection = false;
bool hasNonMergedColumn = false;
//Console.WriteLine("SplitSelectionColumns this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
CellRange cr = this.Selection;
@ -1983,10 +1983,16 @@ namespace Volian.Controls.Library
foreach (CellRange sel in MySelection)
{
if (!this.MergedRanges.Contains(sel))
nonMergedInSelection = true;
hasNonMergedColumn = true;
else
{
CellRange mr = GetMergedRange(sel.r1, sel.c1);
if (mr.c1 == mr.c2)
hasNonMergedColumn = true;
}
}
// for each column in the selection, add a new column
if (nonMergedInSelection)
if (hasNonMergedColumn)
{
for (int c = cr.c2; c >= cr.c1; c--)
{
@ -1995,7 +2001,7 @@ namespace Volian.Controls.Library
}
}
// include new columns in selection
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + ((nonMergedInSelection) ? numSelCols : 0));
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + ((hasNonMergedColumn) ? numSelCols : 0));
//if a merged range is part of the selectin, try to split it
foreach (CellRange sel in MySelection)
{
@ -2004,7 +2010,7 @@ namespace Volian.Controls.Library
SplitMergedRange(sel, true);
}
cr = this.Selection;
if (nonMergedInSelection)
if (hasNonMergedColumn)
{
for (int r = 0; r < this.Rows.Count; r++)
for (int c = cr.c1; c <= cr.c2; c += 2)
@ -2036,16 +2042,31 @@ namespace Volian.Controls.Library
private void SplitSelectionRows()
{
bool hasNonMergedRow = false;
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--)
foreach (CellRange sel in MySelection)
{
//Console.WriteLine("Inserted new Row at [{0},{1}]", r, cr.c1);
Select(r, cr.c1, r, cr.c2);
InsertRowAfter();
if (!this.MergedRanges.Contains(sel))
hasNonMergedRow = true;
else
{
CellRange mr = GetMergedRange(sel.r1, sel.c1);
if (mr.r1 == mr.r2)
hasNonMergedRow = true;
}
}
// for each row in the selection, add a new row
if (hasNonMergedRow)
{
for (int r = cr.r2; r >= cr.r1; r--)
{
//Console.WriteLine("Inserted new Row at [{0},{1}]", r, cr.c1);
Select(r, cr.c1, r, cr.c2);
InsertRowAfter();
}
}
// include new rows in selection
this.Select(cr.r1, cr.c1, cr.r2 + numSelRows, cr.c2);
@ -2058,29 +2079,31 @@ namespace Volian.Controls.Library
}
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))
if (hasNonMergedRow)
{
for (int c = 0; c < this.Cols.Count; c++)
for (int r = cr.r1; r <= cr.r2; r += 2)
{
CellRange crTmp = GetMergedRange(r, c);
if (crTmp.IsSingleCell)
if (!this.IsCellSelected(r, c))
{
CellRange tcr = this.GetCellRange(r, c, r + 1, c);
this.MergedRanges.Add(tcr);
this.Invalidate();
CellRange crTmp = GetMergedRange(r, c);
if (crTmp.IsSingleCell)
{
CellRange tcr = this.GetCellRange(r, c, r + 1, c);
this.MergedRanges.Add(tcr);
this.Invalidate();
}
}
}
// 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, Rows.DefaultSize);
//this.Rows[r].Height = Math.Max(recHeight / 2, _minRowSplitHeight);
//Console.WriteLine("Cell[{0},{1}].Height = {2}", r, cr.c1, recHeight);
}
// 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, Rows.DefaultSize);
//this.Rows[r].Height = Math.Max(recHeight / 2, _minRowSplitHeight);
//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);
}