static int const WIDTH_OF_LINE = 5;
+extern BufferView * current_view;
+
/// Define a few methods for the inner structs
LyXTabular::cellstruct::cellstruct()
bottom_line = false;
rotate = false;
linebreaks = false;
- inset = 0;
-}
-
-
-LyXTabular::cellstruct::~cellstruct()
-{
- delete inset;
-}
-
-
-LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
-{
- cellno = cs.cellno;
- width_of_cell = cs.width_of_cell;
- multicolumn = cs.multicolumn;
- alignment = cs.alignment;
- top_line = cs.top_line;
- bottom_line = cs.bottom_line;
- rotate = cs.rotate;
- linebreaks = cs.linebreaks;
- inset = 0;
-}
-
-
-LyXTabular::cellstruct &
-LyXTabular::cellstruct::operator=(cellstruct const & cs)
-{
- cellno = cs.cellno;
- width_of_cell = cs.width_of_cell;
- multicolumn = cs.multicolumn;
- alignment = cs.alignment;
- top_line = cs.top_line;
- bottom_line = cs.bottom_line;
- rotate = cs.rotate;
- linebreaks = cs.linebreaks;
- return *this;
}
}
-LyXTabular::LyXTabular(InsetTabular * inset, LyXLex & lex)
+LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
{
owner_ = inset;
- Read(lex);
+ Read(buf, lex);
}
int i,j;
for(i=0; i < rows_; ++i) {
for(j=0; j < columns_; ++j) {
- delete result->cell_info[i][j].inset;
- result->cell_info[i][j].inset=new InsetText(*cell_info[i][j].inset,
- inset->BufferOwner());
- result->cell_info[i][j].inset->setOwner(inset);
+ result->cell_info[i][j].inset = cell_info[i][j].inset;
+ result->cell_info[i][j].inset.setOwner(inset);
}
}
return result;
// Jürgen, use iterators.
for (i = 0; i < rows_; ++i) {
for (j = 0; j < columns_; ++j) {
- cell_info[i][j].inset = new InsetText(owner_->BufferOwner());
- cell_info[i][j].inset->setOwner(owner_);
- cell_info[i][j].inset->SetDrawLockedFrame(true);
+ cell_info[i][j].inset.setOwner(owner_);
+ cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
cell_info[i][j].cellno = cellno++;
}
}
}
-void LyXTabular::AppendRow(int /* cell */)
+void LyXTabular::AppendRow(int cell )
{
-#if 0
+ ++rows_;
+
int row = row_of_cell(cell);
- rowstruct * row_info2 = new rowstruct[rows_ + 1];
- cellstruct ** cell_info2 = new cellstruct * [rows_ + 1];
- int i;
- for (i = 0; i <= row; ++i) {
- cell_info2[i] = cell_info[i];
- row_info2[i] = row_info[i];
+ row_vector::iterator rit = row_info.begin() + row;
+ row_info.insert(rit, rowstruct());
+
+#if 0
+ cell_vvector::iterator cit = cell_info.begin() + row;
+ cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
+#else
+ cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
+ cellstruct()));
+
+ for(int i = 0; i <= row; ++i) {
+ for(int j = 0; j < columns_; ++j) {
+ c_info[i][j] = cell_info[i][j];
+ }
}
- for (i = rows_ - 1; i >= row; --i) {
- cell_info2[i + 1] = cell_info[i];
- row_info2[i + 1] = row_info[i];
+ for(int i = row+1; i < rows_; ++i) {
+ for(int j = 0; j < columns_; ++j) {
+ c_info[i][j] = cell_info[i-1][j];
+ }
}
- row_info2[row + 1].top_line = row_info[i].top_line;
- cell_info2[row + 1] = new cellstruct[columns_](owner_->BufferOwner());
- for (i = 0; i < columns_; ++i) {
- cell_info2[row + 1][i].width_of_cell = 0;
- cell_info2[row + 1][i] = cell_info2[row][i];
+ cell_info = c_info;
+ ++row;
+ for (int j = 0; j < columns_; ++j) {
+ cell_info[row][j].inset.clear();
}
-
- delete[] cell_info;
- cell_info = cell_info2;
- delete[] row_info;
- row_info = row_info2;
-
- ++rows_;
-
- Reinit();
#endif
+ Reinit();
}
void LyXTabular::DeleteRow(int row)
{
- row_info.erase(row_info.begin() + row); //&row_info[row]);
- cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
- --rows_;
- Reinit();
+ if (!(rows_ - 1))
+ return;
+ row_info.erase(row_info.begin() + row); //&row_info[row]);
+ cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
+ --rows_;
+ Reinit();
}
-void LyXTabular::AppendColumn(int /*cell*/)
+void LyXTabular::AppendColumn(int cell)
{
-#if 0
- int j;
- columnstruct * column_info2 = new columnstruct[columns_ + 1];
- int column = right_column_of_cell(cell);
+ ++columns_;
+
+ cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
+ cellstruct()));
+ int column = column_of_cell(cell);
+ int i, j;
+ column_vector::iterator cit = column_info.begin() + column;
+ column_info.insert(cit, columnstruct());
- int i = 0;
- for (; i <= column; ++i) {
- column_info2[i] = column_info[i];
- }
- for (i = columns_ - 1; i >= column; --i) {
- column_info2[i + 1] = column_info[i];
- }
-
- delete[] column_info;
- column_info = column_info2;
-
for (i = 0; i < rows_; ++i) {
- cellstruct * tmp = cell_info[i];
- cell_info[i] = new cellstruct[columns_ + 1](owner_->BufferOwner());
for (j = 0; j <= column; ++j) {
- cell_info[i][j] = tmp[j];
+ c_info[i][j] = cell_info[i][j];
}
- for (j = column; j < columns_; ++j) {
- cell_info[i][j + 1] = tmp[j];
+ for (j = column+1; j < columns_; ++j) {
+ c_info[i][j] = cell_info[i][j-1];
}
// care about multicolumns
- if (cell_info[i][column + 1].multicolumn
- == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
- cell_info[i][column + 1].multicolumn =
- LyXTabular::CELL_PART_OF_MULTICOLUMN;
+ if (cell_info[i][column+1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
+ cell_info[i][column+1].multicolumn = CELL_PART_OF_MULTICOLUMN;
}
- if (column + 1 == columns_
- || cell_info[i][column + 2].multicolumn
- != LyXTabular::CELL_PART_OF_MULTICOLUMN){
- cell_info[i][column + 1].multicolumn =
- LyXTabular::CELL_NORMAL;
+ if (((column+1) == columns_) ||
+ (cell_info[i][column+2].multicolumn != CELL_PART_OF_MULTICOLUMN)) {
+ cell_info[i][column+1].multicolumn = LyXTabular::CELL_NORMAL;
}
- delete[] tmp;
}
-
- ++columns_;
- Reinit();
-#endif
-}
-
-
-void LyXTabular::DeleteColumn(int /*cell*/)
-{
-#if 0
- int column1 = column_of_cell(cell);
- int column2 = right_column_of_cell(cell);
-
- if (column1 == 0 && column2 == columns_ - 1)
- return;
-
- for (int column = column1; column <= column2; ++column) {
- delete_column(column1);
+ cell_info = c_info;
+ ++column;
+ for (i = 0; i < rows_; ++i) {
+ cell_info[i][column].inset.clear();
}
Reinit();
-#endif
}
-void LyXTabular::delete_column(int /*column*/)
+void LyXTabular::DeleteColumn(int column)
{
-#if 0
- int i, j;
- columnstruct * column_info2 = new columnstruct[columns_-1];
-
- for (i = 0; i < column; ++i) {
- column_info2[i] = column_info[i];
- }
- for (i = column; i < columns_ - 1; ++i) {
- column_info2[i] = column_info[i + 1];
- }
-
- delete[] column_info;
- column_info = column_info2;
-
- for (i = 0; i < rows_; ++i) {
- cellstruct * tmp = cell_info[i];
- cell_info[i] = new cellstruct[columns_ - 1](owner_->BufferOwner());
- for (j = 0; j < column; ++j) {
- cell_info[i][j] = tmp[j];
- }
- for (j = column; j < columns_ - 1; ++j) {
- cell_info[i][j] = tmp[j + 1];
- }
- delete[] tmp;
+ if (!(columns_ - 1))
+ return;
+ column_info.erase(column_info.begin() + column);
+ for (int i = 0; i < rows_; ++i) {
+ cell_info[i].erase(cell_info[i].begin() + column);
}
-
--columns_;
Reinit();
-#endif
}
for (; i < rows_; ++i) {
for (j = 0; j < columns_; ++j) {
cell_info[i][j].width_of_cell = 0;
+ cell_info[i][j].inset.setOwner(owner_);
}
}
for (column = 0; column<columns_; ++column) {
if (IsPartOfMultiColumn(row,column))
continue;
- cell_info[row][column].inset->SetAutoBreakRows(
+ cell_info[row][column].inset.SetAutoBreakRows(
!GetPWidth(GetCellNumber(row, column)).empty());
}
}
}
-int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell)
-{
- return (right_column_of_cell(append_cell) ==
- right_column_of_cell(question_cell));
-}
-
-
-int LyXTabular::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
-{
- if (column_of_cell(delete_column_cell) == 0 &&
- right_column_of_cell(delete_column_cell) == columns_ - 1)
- return 0;
- else
- return
- (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
- column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
-}
-
-
/* returns 1 if there is a topline, returns 0 if not */
bool LyXTabular::TopLine(int cell) const
{
}
-void LyXTabular::Write(ostream & os) const
+void LyXTabular::Write(Buffer const * buf, ostream & os) const
{
int i, j;
"\" special=\"" << cell_info[i][j].align_special <<
"\">" << endl;
os << "\\begin_inset ";
- cell_info[i][j].inset->Write(os);
+ cell_info[i][j].inset.Write(buf, os);
os << "\n\\end_inset " << endl;
os << "</Cell>" << endl;
os << "</Column>" << endl;
}
-void LyXTabular::Read(LyXLex & lex)
+void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
{
string line;
istream & is = lex.getStream();
(void)getTokenValue(line, "special", cell_info[i][j].align_special);
l_getline(is, line);
if (prefixIs(line, "\\begin_inset")) {
- cell_info[i][j].inset->Read(lex);
+ cell_info[i][j].inset.Read(buf, lex);
l_getline(is, line);
}
if (line != "</Cell>") {
token = lex.GetString();
if (token.empty())
continue;
- if ((token == "\\layout") || (token == "\\end_float")) {
+ if ((token == "\\layout") || (token == "\\end_float") ||
+ (token == "\\end_deeper"))
+ {
lex.pushToken(token);
break;
}
}
// now we have the par we should fill the insets with this!
int cell = 0;
- InsetText *inset = GetCellInset(cell);
+ InsetText * inset = GetCellInset(cell);
int row;
- for(int i=0; i < par->Last(); ++i) {
+ for(int i = 0; i < par->Last(); ++i) {
if (par->IsNewline(i)) {
++cell;
if (cell > GetNumberOfCells()) {
par->InsertChar(i, ' ');
}
}
- par->CopyIntoMinibuffer(i);
+ par->CopyIntoMinibuffer(current_view->buffer()->params, i);
inset->par->InsertFromMinibuffer(inset->par->Last());
}
Reinit();
void LyXTabular::SetMultiColumn(int cell, int number)
{
- int new_width = cellinfo_of_cell(cell)->width_of_cell;
-
- cellinfo_of_cell(cell)->multicolumn = LyXTabular::CELL_BEGIN_OF_MULTICOLUMN;
+ cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
for (number--; number > 0; --number) {
- cellinfo_of_cell(cell+number)->multicolumn =
- LyXTabular::CELL_PART_OF_MULTICOLUMN;
- new_width += cellinfo_of_cell(cell+number)->width_of_cell;
+ cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
}
set_row_column_number_info();
- SetWidthOfCell(cell, new_width);
}
int column = column_of_cell(cell);
int result = 1;
++column;
- while (column < columns_ && cell_info[row][column].multicolumn
- == LyXTabular::CELL_PART_OF_MULTICOLUMN){
+ while ((column < columns_) &&
+ cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
+ {
++result;
++column;
}
int result = 0;
- if (cell_info[row][column].multicolumn
- == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
- cell_info[row][column].multicolumn = LyXTabular::CELL_NORMAL;
+ if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
+ cell_info[row][column].multicolumn = CELL_NORMAL;
++column;
- while (column < columns_ &&
- cell_info[row][column].multicolumn
- == LyXTabular::CELL_PART_OF_MULTICOLUMN){
- cell_info[row][column].multicolumn =
- LyXTabular::CELL_NORMAL;
+ while ((column < columns_) &&
+ (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
+ {
+ cell_info[row][column].multicolumn = CELL_NORMAL;
++column;
++result;
}
bool LyXTabular::IsLastCell(int cell) const
{
- if (cell < GetNumberOfCells())
+ if ((cell+1) < GetNumberOfCells())
return false;
return true;
}
}
+int LyXTabular::GetCellBelow(int cell) const
+{
+ if (row_of_cell(cell)+1 < rows_)
+ return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
+ return cell;
+}
+
+
+int LyXTabular::GetLastCellAbove(int cell) const
+{
+ if (row_of_cell(cell) <= 0)
+ return cell;
+ if (!IsMultiColumn(cell))
+ return GetCellAbove(cell);
+ return cell_info[row_of_cell(cell)-1][right_column_of_cell(cell)].cellno;
+}
+
+
+int LyXTabular::GetLastCellBelow(int cell) const
+{
+ if (row_of_cell(cell)+1 >= rows_)
+ return cell;
+ if (!IsMultiColumn(cell))
+ return GetCellBelow(cell);
+ return cell_info[row_of_cell(cell)+1][right_column_of_cell(cell)].cellno;
+}
+
+
int LyXTabular::GetCellNumber(int row, int column) const
{
if (column >= columns_)
}
-void LyXTabular::SetAscentOfRow(int row, int height)
+bool LyXTabular::SetAscentOfRow(int row, int height)
{
- if (row >= rows_)
- return;
+ if ((row >= rows_) || (row_info[row].ascent_of_row == height))
+ return false;
row_info[row].ascent_of_row = height;
+ return true;
}
-void LyXTabular::SetDescentOfRow(int row, int height)
+bool LyXTabular::SetDescentOfRow(int row, int height)
{
- if (row >= rows_)
- return;
+ if ((row >= rows_) || (row_info[row].descent_of_row == height))
+ return false;
row_info[row].descent_of_row = height;
+ return true;
}
}
-int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
+int LyXTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
{
int ret = 0;
int i,j;
if (IsPartOfMultiColumn(i,j))
continue;
ret += TeXCellPreamble(os, cell);
- ret += GetCellInset(cell)->Latex(os, fragile, fp);
+ ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
ret += TeXCellPostamble(os, cell);
if (!IsLastCellInRow(cell)) { // not last cell in row
os << "&" << endl;
InsetText * LyXTabular::GetCellInset(int cell) const
{
- return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
+ return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
}
void LyXTabular::Validate(LaTeXFeatures & features) const