#include "debug.h"
#include "LaTeXFeatures.h"
#include "lyxlex.h"
+#include "outputparams.h"
#include "paragraph.h"
#include "insets/insettabular.h"
#include "support/lstrings.h"
#include "support/tostr.h"
-#include "support/std_sstream.h"
+#include <sstream>
using lyx::support::ltrim;
using lyx::support::prefixIs;
bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
{
string tmp;
- if (!getTokenValue(str, token, tmp))
- return false;
- return string2type(tmp, num);
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
}
LyXTabular::VAlignment & num)
{
string tmp;
- if (!getTokenValue(str, token, tmp))
- return false;
- return string2type(tmp, num);
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
}
LyXTabular::BoxType & num)
{
string tmp;
- if (!getTokenValue(str, token, tmp))
- return false;
- return string2type(tmp, num);
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
}
// not in the file-format.
flag = false;
string tmp;
- if (!getTokenValue(str, token, tmp))
- return false;
- return string2type(tmp, flag);
+ return getTokenValue(str, token, tmp) && string2type(tmp, flag);
}
// in the file format.
len = LyXLength();
string tmp;
- if (!getTokenValue(str, token, tmp))
- return false;
- return isValidLength(tmp, &len);
+ return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
}
void LyXTabular::fixCellNums()
{
- BOOST_ASSERT(rows_ == row_info.size());
- BOOST_ASSERT(columns_ == column_info.size());
- BOOST_ASSERT(rows_ == cell_info.size());
int cellno = 0;
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j < columns_; ++j) {
- cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
+ // When debugging it can be nice to set
+ // this to true.
+ cell_info[i][j].inset.setDrawFrame(false);
cell_info[i][j].cellno = cellno++;
}
cell_info[i].back().right_line = true;
}
set_row_column_number_info();
- BOOST_ASSERT(rows_ == row_info.size());
- BOOST_ASSERT(columns_ == column_info.size());
- BOOST_ASSERT(rows_ == cell_info.size());
-}
-
-
-void LyXTabular::setOwner(InsetTabular * inset)
-{
- for (int i = 0; i < rows_; ++i)
- for (int j = 0; j < columns_; ++j) {
- cell_info[i][j].inset.setOwner(inset);
- cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
- }
}
-#warning for some strange reason, cellstruct does not seem to have copy-semantics
-
-// work around using 'swap' only...
-
void LyXTabular::appendRow(BufferParams const & bp, int cell)
{
++rows_;
{
++columns_;
- cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
- cellstruct(bp)));
int const column = column_of_cell(cell);
column_vector::iterator cit = column_info.begin() + column + 1;
column_info.insert(cit, columnstruct());
column_info[column + 1] = column_info[column];
for (int i = 0; i < rows_; ++i) {
- for (int j = 0; j <= column; ++j)
- c_info[i][j] = cell_info[i][j];
-
- for (int j = column + 1; j < columns_; ++j)
- c_info[i][j] = cell_info[i][j - 1];
+ cell_info[i].insert(cell_info[i].begin() + column + 1, cellstruct(bp));
// care about multicolumns
- if (c_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
- c_info[i][column + 1].multicolumn = 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 + 2 >= columns_
- || c_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN)
- c_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
+ || cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN)
+ cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
}
- cell_info = c_info;
//++column;
for (int i = 0; i < rows_; ++i) {
cell_info[i][column + 1].inset.clear(false);
<< ">\n";
os << "\\begin_inset ";
cell_info[i][j].inset.write(buf, os);
- os << "\n\\end_inset \n"
+ os << "\n\\end_inset\n"
<< "</cell>\n";
}
os << "</row>\n";
for (int i = 1; i < number; ++i) {
cellstruct & cs1 = cellinfo_of_cell(cell + i);
cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
- cs.inset.appendParagraphs(buffer, cs1.inset.paragraphs);
+ cs.inset.appendParagraphs(buffer, cs1.inset.paragraphs());
cs1.inset.clear(false);
}
set_row_column_number_info();
int LyXTabular::getDescentOfRow(int row) const
{
- if (row >= rows_)
- return 0;
+ BOOST_ASSERT(row < rows_);
return row_info[row].descent_of_row;
}
bool LyXTabular::isPartOfMultiColumn(int row, int column) const
{
- if (row >= rows_ || column >= columns_)
- return false;
+ BOOST_ASSERT(row < rows_);
+ BOOST_ASSERT(column < columns_);
return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
}
int LyXTabular::TeXTopHLine(ostream & os, int row) const
{
- if (row < 0 || row >= rows_)
- return 0;
+ BOOST_ASSERT(row >= 0);
+ BOOST_ASSERT(row < rows_);
int const fcell = getFirstCellInRow(row);
int const n = numberOfCellsInRow(fcell) + fcell;
int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf,
- LatexRunParams const & runparams) const
+ OutputParams const & runparams) const
{
if (!is_long_tabular)
return 0;
int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
- LatexRunParams const & runparams) const
+ OutputParams const & runparams) const
{
int ret = 0;
int cell = getCellNumber(i, 0);
- BufferParams const & bufferparams = buf.params();
ret += TeXTopHLine(os, i);
for (int j = 0; j < columns_; ++j) {
ret += TeXCellPreamble(os, cell);
InsetText & inset = getCellInset(cell);
- bool rtl = inset.paragraphs.begin()->isRightToLeftPar(bufferparams) &&
- !inset.paragraphs.begin()->empty() && getPWidth(cell).zero();
+ Paragraph & par = inset.paragraphs().front();
+ bool rtl = par.isRightToLeftPar(buf.params())
+ && !par.empty()
+ && getPWidth(cell).zero();
if (rtl)
os << "\\R{";
int LyXTabular::latex(Buffer const & buf, ostream & os,
- LatexRunParams const & runparams) const
+ OutputParams const & runparams) const
{
int ret = 0;
}
-int LyXTabular::linuxdoc(Buffer const & buf, ostream & os) const
+int LyXTabular::linuxdoc(Buffer const & buf, ostream & os,
+ const OutputParams & runparams) const
{
os << "<tabular ca=\"";
for (int i = 0; i < columns_; ++i) {
continue;
InsetText & inset = getCellInset(cell);
- ret += inset.linuxdoc(buf, os);
+ ret += inset.linuxdoc(buf, os, runparams);
if (isLastCellInRow(cell)) {
os << "@\n";
}
-int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row) const
+int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row,
+ OutputParams const & runparams) const
{
int ret = 0;
int cell = getFirstCellInRow(row);
}
os << '>';
- ret += getCellInset(cell).docbook(buf, os, true);
+ ret += getCellInset(cell).docbook(buf, os, runparams);
os << "</entry>\n";
++cell;
}
int LyXTabular::docbook(Buffer const & buf, ostream & os,
- bool /*mixcont*/) const
+ OutputParams const & runparams) const
{
int ret = 0;
os << "center";
break;
}
- os << "\">\n";
+ os << '"';
+ if (runparams.flavor == OutputParams::XML)
+ os << '/';
+ os << ">\n";
++ret;
}
++ret;
for (int i = 0; i < rows_; ++i) {
if (row_info[i].endhead || row_info[i].endfirsthead) {
- ret += docbookRow(buf, os, i);
+ ret += docbookRow(buf, os, i, runparams);
}
}
os << "</thead>\n";
++ret;
for (int i = 0; i < rows_; ++i) {
if (row_info[i].endfoot || row_info[i].endlastfoot) {
- ret += docbookRow(buf, os, i);
+ ret += docbookRow(buf, os, i, runparams);
}
}
os << "</tfoot>\n";
++ret;
for (int i = 0; i < rows_; ++i) {
if (isValidRow(i)) {
- ret += docbookRow(buf, os, i);
+ ret += docbookRow(buf, os, i, runparams);
}
}
os << "</tbody>\n";
}
int column = column_of_cell(i);
int len = clen[column];
- while (isPartOfMultiColumn(row, ++column))
+ while (column < columns_ - 1
+ && isPartOfMultiColumn(row, ++column))
len += clen[column] + 4;
os << string(len, ch);
if (topLine(i)) {
}
int column = column_of_cell(i);
int len = clen[column];
- while (isPartOfMultiColumn(row, ++column))
+ while (column < columns_ -1
+ && isPartOfMultiColumn(row, ++column))
len += clen[column] + 4;
os << string(len, ch);
if (bottomLine(i)) {
int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os,
+ OutputParams const & runparams,
int cell, int row, int column,
vector<unsigned int> const & clen,
bool onlydata) const
{
ostringstream sstr;
- int ret = getCellInset(cell).ascii(buf, sstr, 0);
+ int ret = getCellInset(cell).plaintext(buf, sstr, runparams);
if (onlydata) {
os << sstr.str();
unsigned int len1 = sstr.str().length();
unsigned int len2 = clen[column];
- while (isPartOfMultiColumn(row, ++column))
+ while (column < columns_ -1
+ && isPartOfMultiColumn(row, ++column))
len2 += clen[column] + 4;
len2 -= len1;
}
-int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
- bool onlydata, unsigned char delim) const
+int LyXTabular::plaintext(Buffer const & buf, ostream & os,
+ OutputParams const & runparams,
+ int const depth,
+ bool onlydata, unsigned char delim) const
{
int ret = 0;
if (isMultiColumnReal(cell))
continue;
ostringstream sstr;
- getCellInset(cell).ascii(buf, sstr, 0);
+ getCellInset(cell).plaintext(buf, sstr, runparams);
if (clen[j] < sstr.str().length())
clen[j] = sstr.str().length();
}
if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j))
continue;
ostringstream sstr;
- getCellInset(cell).ascii(buf, sstr, 0);
+ getCellInset(cell).plaintext(buf, sstr, runparams);
int len = int(sstr.str().length());
int const n = cells_in_multicolumn(cell);
for (int k = j; len > 0 && k < j + n - 1; ++k)
continue;
if (onlydata && j > 0)
os << delim;
- ret += asciiPrintCell(buf, os, cell, i, j, clen, onlydata);
+ ret += asciiPrintCell(buf, os, runparams,
+ cell, i, j, clen, onlydata);
++cell;
}
os << endl;
}
-int LyXTabular::getCellFromInset(InsetOld const * inset) const
+int LyXTabular::getCellFromInset(InsetBase const * inset) const
{
// is this inset part of the tabular?
if (!inset) {
lyxerr << "Error: this is not a cell of the tabular!" << endl;
- return -1;
+ BOOST_ASSERT(false);
}
- for (int cell = getNumberOfCells(); cell >= 0; --cell)
+ for (int cell = 0, n = getNumberOfCells(); cell < n; ++cell)
if (&getCellInset(cell) == inset) {
lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: "
<< "cell=" << cell << endl;
}
// We should have found a cell at this point
- lyxerr << "LyXTabular::getCellFromInset: Cell not found!" << endl;
- return -1;
+ lyxerr << "LyXTabular::getCellFromInset: Cell of inset "
+ << inset << " not found!" << endl;
+ BOOST_ASSERT(false);
+ // shut up compiler
+ return 0;
}
LyXTabular::BoxType LyXTabular::useParbox(int cell) const
{
- ParagraphList const & parlist = getCellInset(cell).paragraphs;
+ ParagraphList const & parlist = getCellInset(cell).paragraphs();
ParagraphList::const_iterator cit = parlist.begin();
ParagraphList::const_iterator end = parlist.end();