protected CellPos FindNextEditableCell(CellPos start, bool wrap, bool forward, bool includeStart)
{
if (this.ColumnCount == 0 || this.RowCount == 0)
{
return CellPos.Empty;
}
int startRow = start.Row != -1 ? start.Row : 0;
int startCol = start.Column != -1 ? start.Column : 0;
bool first = true;
if (forward)
{
for (int i = startRow; i < this.RowCount; i++)
{
int j = (first ? startCol : 0);
for (; j < this.TableModel.Rows[i].Cells.Count; j++)
{
if (i == startRow && j == startCol)
{
if (!first)
{
return CellPos.Empty;
}
first = false;
if (!includeStart)
{
continue;
}
}
if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Editable && this.ColumnModel.Columns[j].Editable)
{
return new CellPos(i, j);
}
}
if (wrap)
{
if (i + 1 == this.TableModel.Rows.Count)
{
i = -1;
}
}
else
{
break;
}
}
}
else
{
for (int i = startRow; i >= 0; i--)
{
int j = (first ? startCol : this.TableModel.Rows[i].Cells.Count);
for (; j >= 0; j--)
{
if (i == startRow && j == startCol)
{
if (!first)
{
return CellPos.Empty;
}
first = false;
if (!includeStart)
{
continue;
}
}
if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Editable && this.ColumnModel.Columns[j].Editable)
{
return new CellPos(i, j);
}
}
if (wrap)
{
if (i - 1 == -1)
{
i = this.TableModel.Rows.Count;
}
}
else
{
break;
}
}
}
return CellPos.Empty;
}