*
* LyX, The Document Processor
*
- * Copyright 2000-2001 The LyX Team.
+ * Copyright 2000-2002 The LyX Team.
*
* @author: Jürgen Vigna
*
/// Define a few methods for the inner structs
-LyXTabular::cellstruct::cellstruct()
+LyXTabular::cellstruct::cellstruct(BufferParams const & bg)
+ : inset(bg)
{
cellno = 0;
width_of_cell = 0;
/* konstruktor */
-LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
+LyXTabular::LyXTabular(BufferParams const & bp,
+ InsetTabular * inset, int rows_arg, int columns_arg)
{
owner_ = inset;
cur_cell = -1;
- Init(rows_arg, columns_arg);
+ Init(bp, rows_arg, columns_arg);
}
-LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt,
+LyXTabular::LyXTabular(BufferParams const & bp,
+ InsetTabular * inset, LyXTabular const & lt,
bool same_id)
{
owner_ = inset;
cur_cell = -1;
- Init(lt.rows_, lt.columns_, <);
+ Init(bp, lt.rows_, lt.columns_, <);
// we really should change again to have InsetText as a pointer
// and allocate it then we would not have to do this stuff all
// double!
}
-LyXTabular * LyXTabular::clone(InsetTabular * inset, bool same_id)
+LyXTabular * LyXTabular::clone(BufferParams const & bp,
+ InsetTabular * inset, bool same_id)
{
- LyXTabular * result = new LyXTabular(inset, *this, same_id);
+ LyXTabular * result = new LyXTabular(bp, inset, *this, same_id);
#if 0
// don't know if this is good but I need to Clone also
// the text-insets here, this is for the Undo-facility!
/* activates all lines and sets all widths to 0 */
-void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt)
+void LyXTabular::Init(BufferParams const & bp,
+ int rows_arg, int columns_arg, LyXTabular const * lt)
{
rows_ = rows_arg;
columns_ = columns_arg;
row_info = row_vector(rows_, rowstruct());
column_info = column_vector(columns_, columnstruct());
- cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct()));
+ cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
if (lt) {
operator=(*lt);
}
-void LyXTabular::AppendRow(int cell)
+void LyXTabular::AppendRow(BufferParams const & bp, int cell)
{
++rows_;
row_vector::iterator rit = row_info.begin() + row;
row_info.insert(rit, rowstruct());
// now set the values of the row before
- row_info[row] = row_info[row+1];
+ row_info[row] = row_info[row + 1];
#if 0
cell_vvector::iterator cit = cell_info.begin() + row;
- cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
+ cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct(bp)));
#else
cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
- cellstruct()));
+ cellstruct(bp)));
for (int i = 0; i <= row; ++i) {
for (int j = 0; j < columns_; ++j) {
}
-void LyXTabular::AppendColumn(int cell)
+void LyXTabular::AppendColumn(BufferParams const & bp, int cell)
{
++columns_;
cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
- cellstruct()));
+ cellstruct(bp)));
int const column = column_of_cell(cell);
column_vector::iterator cit = column_info.begin() + column + 1;
column_info.insert(cit, columnstruct());
// set the column values of the column before
- column_info[column+1] = column_info[column];
+ column_info[column + 1] = column_info[column];
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j <= column; ++j) {
int const row = row_of_cell(cell);
int const column1 = column_of_cell(cell);
int const column2 = right_column_of_cell(cell);
-
+ int const old_val = cell_info[row][column2].width_of_cell;
+
// first set columns to 0 so we can calculate the right width
for (int i = column1; i <= column2; ++i) {
cell_info[row][i].width_of_cell = 0;
}
// set the width to MAX_WIDTH until width > 0
int width = (new_width + 2 * WIDTH_OF_LINE);
-
int i = column1;
for (; i < column2 && width > column_info[i].width_of_column; ++i) {
cell_info[row][i].width_of_cell = column_info[i].width_of_column;
if (width > 0) {
cell_info[row][i].width_of_cell = width;
}
+ if (old_val != cell_info[row][column2].width_of_cell) {
+ // in this case we have to recalculate all multicolumn cells which
+ // have this column as one of theirs but not as last one
+ recalculateMulticolumnsOfColumn(i);
+ }
return true;
}
-void LyXTabular::recalculateMulticolCells(int cell, int new_width)
+void LyXTabular::recalculateMulticolumnsOfColumn(int column)
{
- int const row = row_of_cell(cell);
- int const column1 = column_of_cell(cell);
- int const column2 = right_column_of_cell(cell);
-
- // first set columns to 0 so we can calculate the right width
- int i = column1;
- for (; i <= column2; ++i)
- cell_info[row][i].width_of_cell = 0;
- for (i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
- ;
- if (i < numberofcells)
- recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
- SetWidthOfMulticolCell(cell, new_width);
+ // the last column does not have to be recalculated because all
+ // multicolumns will have here there last multicolumn cell which
+ // always will have the whole rest of the width of the cell.
+ if (column > (columns_ - 2))
+ return;
+ for(int row = 0; row < rows_; ++row) {
+ int mc = cell_info[row][column].multicolumn;
+ int nmc = cell_info[row][column+1].multicolumn;
+ // we only have to update multicolumns which do not have this
+ // column as their last column!
+ if (mc == CELL_BEGIN_OF_MULTICOLUMN ||
+ ((mc == CELL_PART_OF_MULTICOLUMN) &&
+ (nmc == CELL_PART_OF_MULTICOLUMN)))
+ {
+ int const cellno = cell_info[row][column].cellno;
+ SetWidthOfMulticolCell(cellno,
+ GetWidthOfCell(cellno)-(2 * WIDTH_OF_LINE));
+ }
+ }
}
width = (new_width + 2*WIDTH_OF_LINE + add_width);
cell_info[row][column1].width_of_cell = width;
tmp = calculate_width_of_column_NMC(column1);
+ if (tmp)
+ recalculateMulticolumnsOfColumn(column1);
}
if (tmp) {
- int i = 0;
- for (; i<columns_; ++i)
- calculate_width_of_column_NMC(i);
- for (i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
- ;
- if (i < numberofcells)
- recalculateMulticolCells(i, GetWidthOfCell(i)-(2 * WIDTH_OF_LINE));
- for (i = 0; i < columns_; ++i)
+ for (int i = 0; i < columns_; ++i)
calculate_width_of_column(i);
calculate_width_of_tabular();
return true;
l_getline(is, line);
if (!prefixIs(line, "<lyxtabular ")
&& !prefixIs(line, "<LyXTabular ")) {
- OldFormatRead(lex, line);
+ OldFormatRead(buf->params, lex, line);
return;
}
row_info[--fhr].endfirsthead = true;
row_info[fhr].endhead = false;
}
- } else if (row_info[fhr-1].endhead) {
+ } else if (row_info[fhr - 1].endhead) {
endfirsthead.empty = true;
} else {
while((fhr > 0) && !row_info[--fhr].endhead) {
row_info[fr].endfoot = true;
row_info[fr].endfirsthead = false;
}
- } else if (!row_info[fr-1].endhead && !row_info[fr-1].endfirsthead) {
+ } else if (!row_info[fr - 1].endhead && !row_info[fr - 1].endfirsthead) {
while((fr > 0) && !row_info[--fr].endhead &&
!row_info[fr].endfirsthead)
{
}
// set lastfooter info
if (lfr && (lfr < rows_)) {
- if (row_info[lfr].endhead && row_info[lfr-1].endhead) {
+ if (row_info[lfr].endhead && row_info[lfr - 1].endhead) {
while((lfr > 0) && !row_info[--lfr].endhead) {
row_info[lfr].endlastfoot = true;
row_info[lfr].endhead = false;
}
} else if (row_info[lfr].endfirsthead &&
- row_info[lfr-1].endfirsthead)
+ row_info[lfr - 1].endfirsthead)
{
while((lfr > 0) && !row_info[--lfr].endfirsthead) {
row_info[lfr].endlastfoot = true;
row_info[lfr].endfirsthead = false;
}
- } else if (row_info[lfr].endfoot && row_info[lfr-1].endfoot) {
+ } else if (row_info[lfr].endfoot
+ && row_info[lfr - 1].endfoot) {
while((lfr > 0) && !row_info[--lfr].endfoot) {
row_info[lfr].endlastfoot = true;
row_info[lfr].endfoot = false;
}
- } else if (!row_info[fr-1].endhead && !row_info[fr-1].endfirsthead &&
- !row_info[fr-1].endfoot)
+ } else if (!row_info[fr - 1].endhead
+ && !row_info[fr - 1].endfirsthead &&
+ !row_info[fr - 1].endfoot)
{
while((lfr > 0) &&
!row_info[--lfr].endhead && !row_info[lfr].endfirsthead &&
}
void LyXTabular::ReadNew(Buffer const * buf, istream & is,
- LyXLex & lex, string const & l, int const version)
+ LyXLex & lex, string const & l, int const version)
{
string line(l);
int rows_arg;
int columns_arg;
if (!getTokenValue(line, "columns", columns_arg))
return;
- Init(rows_arg, columns_arg);
+ Init(buf->params, rows_arg, columns_arg);
l_getline(is, line);
if (!prefixIs(line, "<features")) {
lyxerr << "Wrong tabular format (expected <features ...> got" <<
}
-void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
+void LyXTabular::OldFormatRead(BufferParams const & bp,
+ LyXLex & lex, string const & fl)
{
int version;
int i;
>> rotate_arg >> a >> b >> c >> d;
} else
is >> rows_arg >> columns_arg;
- Init(rows_arg, columns_arg);
+ Init(bp, rows_arg, columns_arg);
cont_row_info = vector<int>(rows_arg);
SetLongTabular(is_long_tabular_arg);
SetRotateTabular(rotate_arg);
} else {
is >> rows_arg >> columns_arg >> is_long_tabular_arg
>> rotate_arg >> a >> b >> c >> d;
- Init(rows_arg, columns_arg);
+ Init(bp, rows_arg, columns_arg);
cont_row_info = vector<int>(rows_arg);
SetLongTabular(is_long_tabular_arg);
SetRotateTabular(rotate_arg);