-/* This file is part of
- * ======================================================
+/**
+ * \file tabular.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Processor
+ * \author Lars Gullik Bjønnes
+ * \author Matthias Ettrich
+ * \author José Matos
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
+ * \author Jürgen Vigna
*
- * Copyright 2000-2002 The LyX Team.
- *
- * @author: Jürgen Vigna
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "tabular.h"
#include "LaTeXFeatures.h"
-#include "Lsstream.h"
+#include "support/std_sstream.h"
#include "buffer.h"
#include "debug.h"
-#include "gettext.h"
#include "lyxlex.h"
-#include "vspace.h"
#include "insets/insettabular.h"
-#include "insets/insettext.h"
#include "support/LAssert.h"
-#include "support/LIstream.h"
#include "support/lstrings.h"
-#include "support/lyxmanip.h"
#include "support/tostr.h"
-#include "frontends/Alert.h"
-#include "frontends/Painter.h"
-#include <algorithm>
-#include <cstdlib>
using namespace lyx::support;
switch (num) {
case LyXTabular::LYX_VALIGN_TOP:
return "top";
- case LyXTabular::LYX_VALIGN_CENTER:
- return "center";
+ case LyXTabular::LYX_VALIGN_MIDDLE:
+ return "middle";
case LyXTabular::LYX_VALIGN_BOTTOM:
return "bottom";
}
{
if (str == "top")
num = LyXTabular::LYX_VALIGN_TOP;
- else if (str == "center")
- num = LyXTabular::LYX_VALIGN_CENTER;
+ else if (str == "middle" )
+ num = LyXTabular::LYX_VALIGN_MIDDLE;
else if (str == "bottom")
num = LyXTabular::LYX_VALIGN_BOTTOM;
else
}
-LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
+LyXTabular::LyXTabular(Buffer const & buf, InsetTabular * inset, LyXLex & lex)
{
owner_ = inset;
cur_cell = -1;
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j < columns_; ++j) {
cell_info[i][j].inset.setOwner(owner_);
- cell_info[i][j].inset.setDrawFrame(0, InsetText::LOCKED);
+ cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
cell_info[i][j].cellno = cellno++;
}
cell_info[i].back().right_line = true;
row_info.back().bottom_line = true;
row_info.front().bottom_line = true;
- for (int i = 0; i < columns_; ++i) {
+ for (int i = 0; i < columns_; ++i)
calculate_width_of_column(i);
- }
+
column_info.back().right_line = true;
calculate_width_of_tabular();
- rowofcell = vector<int>();
- columnofcell = vector<int>();
+ rowofcell.clear();
+ columnofcell.clear();
set_row_column_number_info();
is_long_tabular = false;
rotate = false;
cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
cellstruct(bp)));
- for (int i = 0; i <= row; ++i) {
- for (int j = 0; j < columns_; ++j) {
+ for (int i = 0; i <= row; ++i)
+ for (int j = 0; j < columns_; ++j)
c_info[i][j] = cell_info[i][j];
- }
- }
- for (int i = row + 1; i < rows_; ++i) {
- for (int j = 0; j < columns_; ++j) {
+
+ for (int i = row + 1; i < rows_; ++i)
+ for (int j = 0; j < columns_; ++j)
c_info[i][j] = cell_info[i-1][j];
- }
- }
+
cell_info = c_info;
++row;
for (int j = 0; j < columns_; ++j) {
column_info[column + 1] = column_info[column];
for (int i = 0; i < rows_; ++i) {
- for (int j = 0; j <= column; ++j) {
+ for (int j = 0; j <= column; ++j)
c_info[i][j] = cell_info[i][j];
- }
- for (int j = column + 1; j < columns_; ++j) {
+
+ for (int j = column + 1; j < columns_; ++j)
c_info[i][j] = cell_info[i][j - 1];
- }
+
// care about multicolumns
- if (c_info[i][column + 1].multicolumn==CELL_BEGIN_OF_MULTICOLUMN)
- {
+ if (c_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
c_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
- }
- if (column + 2 >= columns_ ||
- c_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN)
- {
+
+ if (column + 2 >= columns_
+ || c_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN)
c_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
- }
}
cell_info = c_info;
//++column;
} while (column < columns_ &&
cell_info[row][column].multicolumn
== LyXTabular::CELL_PART_OF_MULTICOLUMN);
+
if (column == columns_) {
column = 0;
++row;
// returns 1 if a complete update is necessary, otherwise 0
-bool LyXTabular::setWidthOfCell(int cell, int new_width)
+void LyXTabular::setWidthOfCell(int cell, int new_width)
{
int const row = row_of_cell(cell);
int const column1 = column_of_cell(cell);
column1 < columns_ - 1 &&
leftLine(cell_info[row][column1+1].cellno, true))
{
- // additional width
add_width = WIDTH_OF_LINE;
}
- if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width) {
- return false;
- }
+
+ if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width)
+ return;
+
if (isMultiColumn(cell, true)) {
tmp = setWidthOfMulticolCell(cell, new_width);
} else {
for (int i = 0; i < columns_; ++i)
calculate_width_of_column(i);
calculate_width_of_tabular();
- return true;
}
- return false;
}
}
-void LyXTabular::write(Buffer const * buf, ostream & os) const
+void LyXTabular::write(Buffer const & buf, ostream & os) const
{
// header line
os << "<lyxtabular"
}
-void LyXTabular::read(Buffer const * buf, LyXLex & lex)
+void LyXTabular::read(Buffer const & buf, LyXLex & lex)
{
string line;
istream & is = lex.getStream();
int columns_arg;
if (!getTokenValue(line, "columns", columns_arg))
return;
- init(buf->params, 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"
// end longtable support functions
-bool LyXTabular::setAscentOfRow(int row, int height)
+void LyXTabular::setAscentOfRow(int row, int height)
{
if (row >= rows_ || row_info[row].ascent_of_row == height)
- return false;
+ return;
row_info[row].ascent_of_row = height;
- return true;
}
-bool LyXTabular::setDescentOfRow(int row, int height)
+void LyXTabular::setDescentOfRow(int row, int height)
{
if (row >= rows_ || row_info[row].descent_of_row == height)
- return false;
+ return;
row_info[row].descent_of_row = height;
- return true;
}
case LYX_VALIGN_TOP:
os << 'p';
break;
- case LYX_VALIGN_CENTER:
+ case LYX_VALIGN_MIDDLE:
os << 'm';
break;
case LYX_VALIGN_BOTTOM:
case LYX_VALIGN_TOP:
os << 't';
break;
- case LYX_VALIGN_CENTER:
+ case LYX_VALIGN_MIDDLE:
os << 'c';
break;
case LYX_VALIGN_BOTTOM:
case LYX_VALIGN_TOP:
os << 't';
break;
- case LYX_VALIGN_CENTER:
+ case LYX_VALIGN_MIDDLE:
os << 'm';
break;
case LYX_VALIGN_BOTTOM:
}
-int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const * buf,
+int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf,
LatexRunParams const & runparams) const
{
if (!is_long_tabular)
}
-int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf,
+int LyXTabular::TeXRow(ostream & os, int const i, Buffer const & buf,
LatexRunParams const & runparams) const
{
int ret = 0;
ret += TeXCellPreamble(os, cell);
InsetText & inset = getCellInset(cell);
- bool rtl = inset.paragraphs.begin()->isRightToLeftPar(buf->params) &&
+ bool rtl = inset.paragraphs.begin()->isRightToLeftPar(buf.params) &&
!inset.paragraphs.begin()->empty() && getPWidth(cell).zero();
if (rtl)
}
-int LyXTabular::latex(Buffer const * buf, ostream & os,
+int LyXTabular::latex(Buffer const & buf, ostream & os,
LatexRunParams const & runparams) const
{
int ret = 0;
case LYX_VALIGN_TOP:
os << 'p';
break;
- case LYX_VALIGN_CENTER:
+ case LYX_VALIGN_MIDDLE:
os << 'm';
break;
case LYX_VALIGN_BOTTOM:
}
-int LyXTabular::linuxdoc(Buffer const * buf, ostream & os) const
+int LyXTabular::linuxdoc(Buffer const & buf, ostream & os) const
{
os << "<tabular ca=\"";
for (int i = 0; i < columns_; ++i) {
if (isPartOfMultiColumn(i, j))
continue;
InsetText & inset = getCellInset(cell);
-
+
ret += inset.linuxdoc(buf, os);
if (isLastCellInRow(cell)) {
}
-int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const
+int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row) const
{
int ret = 0;
int cell = getFirstCellInRow(row);
case LYX_VALIGN_BOTTOM:
os << "bottom";
break;
- case LYX_VALIGN_CENTER:
+ case LYX_VALIGN_MIDDLE:
os << "middle";
}
os << '"';
}
-int LyXTabular::docbook(Buffer const * buf, ostream & os,
+int LyXTabular::docbook(Buffer const & buf, ostream & os,
bool /*mixcont*/) const
{
int ret = 0;
}
-int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os,
+int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os,
int cell, int row, int column,
vector<unsigned int> const & clen,
bool onlydata) const
}
-int LyXTabular::ascii(Buffer const * buf, ostream & os, int const depth,
+int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
bool onlydata, unsigned char delim) const
{
int ret = 0;
{
// is this inset part of the tabular?
if (!inset || inset->owner() != owner_) {
- lyxerr << "this is not a cell of the tabular!" << endl;
- Assert(0);
+ lyxerr << "Error: this is not a cell of the tabular!" << endl;
+ return -1;
}
const int save_cur_cell = cur_cell;
int cell = cur_cell;
if (&getCellInset(cell) != inset) {
cell = maybe_cell;
- if (cell == -1 || &getCellInset(cell) != inset) {
+ if (cell == -1 || &getCellInset(cell) != inset)
cell = -1;
- }
}
if (cell == -1) {
- for (cell = getNumberOfCells(); cell >= 0; --cell) {
+ for (cell = getNumberOfCells(); cell >= 0; --cell)
if (&getCellInset(cell) == inset)
break;
- }
+
lyxerr[Debug::INSETTEXT]
<< "LyXTabular::getCellFromInset: "
<< "cell=" << cell