public Cells.ICell this[int row, int col]
{
get
{
Cells.ICell cell = DirectGetCell(new Position(row,col));
if (cell != null)
return cell;
//this alghorithm search the spanned cell with a sqare search:
// 4 4 4 4 4
// 4 3 3 3 3
// 4 3 2 2 2
// 4 3 2 1 1
// 4 3 2 1 X
// the X represents the requestPos, the number represents the searchIteration loop.
// search first on the row and then on the columns
Position requestPos = new Position(row, col);
int startPosRow = requestPos.Row;
int startPosCol = requestPos.Column;
bool endRow = false;
bool endCol = false;
Cells.ICell testCell;
for (int searchIteration = 0; searchIteration < MaxSpan; searchIteration++)
{
if (endCol == false)
{
for (int r = startPosRow; r <= requestPos.Row; r++)
{
//if the cell contains the requested cell
testCell = DirectGetCell(new Position(r,startPosCol));
if (testCell != null && testCell.Range.Contains(requestPos))
return testCell;
}
}
if (endRow == false)
{
for (int c = startPosCol; c <= requestPos.Column; c++)
{
//if the cell contains the requested cell
testCell = DirectGetCell(new Position(startPosRow,c));
if (testCell != null && testCell.Range.Contains(requestPos))
return testCell;
}
}
if (startPosRow == 0 && startPosCol == 0)
return null; //not found
if (startPosRow == 0)
endRow = true;
else
startPosRow--;
if (startPosCol == 0)
endCol = true;
else
startPosCol--;
}
return null;
}
set
{
InsertCell(row,col,value);
}
}