using lyx::support::strToInt;
using lyx::support::suffixIs;
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
+
using std::abs;
using std::endl;
using std::getline;
}
-bool getTokenValue(string const & str, const char * token, string & ret)
+bool getTokenValue(string const & str, char const * token, string & ret)
{
ret.erase();
size_t token_length = strlen(token);
}
-bool getTokenValue(string const & str, const char * token, int & num)
+bool getTokenValue(string const & str, char const * token, int & num)
{
string tmp;
num = 0;
}
-bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
+bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
{
string tmp;
return getTokenValue(str, token, tmp) && string2type(tmp, num);
}
-bool getTokenValue(string const & str, const char * token,
+bool getTokenValue(string const & str, char const * token,
LyXTabular::VAlignment & num)
{
string tmp;
}
-bool getTokenValue(string const & str, const char * token,
+bool getTokenValue(string const & str, char const * token,
LyXTabular::BoxType & num)
{
string tmp;
}
-bool getTokenValue(string const & str, const char * token, bool & flag)
+bool getTokenValue(string const & str, char const * token, bool & flag)
{
// set the flag always to false as this should be the default for bools
// not in the file-format.
}
-bool getTokenValue(string const & str, const char * token, LyXLength & len)
+bool getTokenValue(string const & str, char const * token, LyXLength & len)
{
// set the lenght to be zero() as default as this it should be if not
// in the file format.
/// Define a few methods for the inner structs
LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
- : inset(bp)
-{
- cellno = 0;
- width_of_cell = 0;
- multicolumn = LyXTabular::CELL_NORMAL;
- alignment = LYX_ALIGN_CENTER;
- valignment = LYX_VALIGN_TOP;
- top_line = true;
- bottom_line = false;
- left_line = true;
- right_line = false;
- usebox = BOX_NONE;
- rotate = false;
+ : cellno(0),
+ width_of_cell(0),
+ multicolumn(LyXTabular::CELL_NORMAL),
+ alignment(LYX_ALIGN_CENTER),
+ valignment(LYX_VALIGN_TOP),
+ top_line(true),
+ bottom_line(false),
+ left_line(true),
+ right_line(false),
+ usebox(BOX_NONE),
+ rotate(false),
+ inset(new InsetText(bp))
+{}
+
+
+LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
+ : cellno(cs.cellno),
+ width_of_cell(cs.width_of_cell),
+ multicolumn(cs.multicolumn),
+ alignment(cs.alignment),
+ valignment(cs.valignment),
+ top_line(cs.top_line),
+ bottom_line(cs.bottom_line),
+ left_line(cs.left_line),
+ right_line(cs.right_line),
+ usebox(cs.usebox),
+ rotate(cs.rotate),
+ align_special(cs.align_special),
+ p_width(cs.p_width),
+ inset(dynamic_cast<InsetText*>(cs.inset->clone().release()))
+{}
+
+
+LyXTabular::cellstruct &
+LyXTabular::cellstruct::operator=(cellstruct cs)
+{
+ swap(cs);
+ return *this;
+}
+
+
+void
+LyXTabular::cellstruct::swap(cellstruct & rhs)
+{
+ std::swap(cellno, rhs.cellno);
+ std::swap(width_of_cell, rhs.width_of_cell);
+ std::swap(multicolumn, rhs.multicolumn);
+ std::swap(alignment, rhs.alignment);
+ std::swap(valignment, rhs.valignment);
+ std::swap(top_line, rhs.top_line);
+ std::swap(bottom_line, rhs.bottom_line);
+ std::swap(left_line, rhs.left_line);
+ std::swap(right_line, rhs.right_line);
+ std::swap(usebox, rhs.usebox);
+ std::swap(rotate, rhs.rotate);
+ std::swap(align_special, rhs.align_special);
+ p_width.swap(rhs.p_width);
+ inset.swap(rhs.inset);
}
LyXTabular::rowstruct::rowstruct()
-{
- top_line = true;
- bottom_line = false;
- ascent_of_row = 0;
- descent_of_row = 0;
- endhead = false;
- endfirsthead = false;
- endfoot = false;
- endlastfoot = false;
- newpage = false;
-}
+ : ascent_of_row(0),
+ descent_of_row(0),
+ top_line(true),
+ bottom_line(false),
+ endhead(false),
+ endfirsthead(false),
+ endfoot(false),
+ endlastfoot(false),
+ newpage(false)
+{}
LyXTabular::columnstruct::columnstruct()
+ : alignment(LYX_ALIGN_CENTER),
+ valignment(LYX_VALIGN_TOP),
+ left_line(true),
+ right_line(false),
+ width_of_column(0)
{
- left_line = true;
- right_line = false;
- alignment = LYX_ALIGN_CENTER;
- valignment = LYX_VALIGN_TOP;
- width_of_column = 0;
}
LyXTabular::ltType::ltType()
-{
- topDL = false;
- bottomDL = false;
- empty = false;
-}
+ : topDL(false),
+ bottomDL(false),
+ empty(false)
+{}
LyXTabular::LyXTabular(BufferParams const & bp, int rows_arg, int columns_arg)
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;
}
-void LyXTabular::appendRow(BufferParams const & bp, int cell)
+void LyXTabular::appendRow(BufferParams const & bp, int const cell)
{
++rows_;
- int row = row_of_cell(cell);
+ int const row = row_of_cell(cell);
row_vector::iterator rit = row_info.begin() + row;
row_info.insert(rit, rowstruct());
if (bp.tracking_changes)
for (int j = 0; j < columns_; ++j)
- cell_info[row + 1][j].inset.markNew(true);
+ cell_info[row + 1][j].inset->markNew(true);
set_row_column_number_info();
}
-void LyXTabular::deleteRow(int row)
+void LyXTabular::deleteRow(int const row)
{
// Not allowed to delete last row
if (rows_ == 1)
}
-void LyXTabular::appendColumn(BufferParams const & bp, int cell)
+void LyXTabular::appendColumn(BufferParams const & bp, int const cell)
{
++columns_;
}
//++column;
for (int i = 0; i < rows_; ++i) {
- cell_info[i][column + 1].inset.clear(false);
+ cell_info[i][column + 1].inset->clear(false);
if (bp.tracking_changes)
- cell_info[i][column + 1].inset.markNew(true);
+ cell_info[i][column + 1].inset->markNew(true);
}
fixCellNums();
}
-void LyXTabular::deleteColumn(int column)
+void LyXTabular::deleteColumn(int const column)
{
// Not allowed to delete last column
if (columns_ == 1)
for (int 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)).zero());
}
}
}
-int LyXTabular::numberOfCellsInRow(int cell) const
+int LyXTabular::numberOfCellsInRow(int const cell) const
{
int const row = row_of_cell(cell);
int result = 0;
// returns 1 if there is a topline, returns 0 if not
-bool LyXTabular::topLine(int cell, bool onlycolumn) const
+bool LyXTabular::topLine(int const cell, bool const onlycolumn) const
{
if (!onlycolumn && isMultiColumn(cell))
return cellinfo_of_cell(cell).top_line;
for (int i = 0; i < rows_; ++i) {
int const cell = getCellNumber(i, j);
// because of multicolumns
- getCellInset(cell).setAutoBreakRows(!getPWidth(cell).zero());
+ getCellInset(cell)->setAutoBreakRows(!getPWidth(cell).zero());
}
}
return false;
cellinfo_of_cell(cell).p_width = width;
- getCellInset(cell).setAutoBreakRows(!width.zero());
+ getCellInset(cell)->setAutoBreakRows(!width.zero());
return true;
}
<< write_attribute("special", cell_info[i][j].align_special)
<< ">\n";
os << "\\begin_inset ";
- cell_info[i][j].inset.write(buf, os);
- os << "\n\\end_inset \n"
+ cell_info[i][j].inset->write(buf, os);
+ os << "\n\\end_inset\n"
<< "</cell>\n";
}
os << "</row>\n";
getTokenValue(line, "special", cell_info[i][j].align_special);
l_getline(is, line);
if (prefixIs(line, "\\begin_inset")) {
- cell_info[i][j].inset.read(buf, lex);
+ cell_info[i][j].inset->read(buf, lex);
l_getline(is, line);
}
if (!prefixIs(line, "</cell>")) {
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());
- cs1.inset.clear(false);
+ 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::TeXRow(ostream & os, int i, Buffer const & buf,
OutputParams const & runparams) const
{
- int ret = 0;
int cell = getCellNumber(i, 0);
- ret += TeXTopHLine(os, i);
+ int ret = TeXTopHLine(os, i);
for (int j = 0; j < columns_; ++j) {
if (isPartOfMultiColumn(i, j))
continue;
ret += TeXCellPreamble(os, cell);
- InsetText & inset = getCellInset(cell);
+ shared_ptr<InsetText> inset = getCellInset(cell);
- Paragraph & par = inset.paragraphs().front();
+ Paragraph const & par = inset->paragraphs().front();
bool rtl = par.isRightToLeftPar(buf.params())
&& !par.empty()
&& getPWidth(cell).zero();
if (rtl)
os << "\\R{";
- ret += inset.latex(buf, os, runparams);
+ ret += inset->latex(buf, os, runparams);
if (rtl)
os << '}';
for (int j = 0; j < columns_; ++j) {
if (isPartOfMultiColumn(i, j))
continue;
- InsetText & inset = getCellInset(cell);
+ shared_ptr<InsetText> inset = getCellInset(cell);
- ret += inset.linuxdoc(buf, os, runparams);
+ ret += inset->linuxdoc(buf, os, runparams);
if (isLastCellInRow(cell)) {
os << "@\n";
}
os << '>';
- OutputParams runp = runparams;
- runp.mixed_content = true;
- ret += getCellInset(cell).docbook(buf, os, runp);
+ ret += getCellInset(cell)->docbook(buf, os, runparams);
os << "</entry>\n";
++cell;
}
os << "center";
break;
}
- os << "\">\n";
+ os << '"';
+ if (runparams.flavor == OutputParams::XML)
+ os << '/';
+ os << ">\n";
++ret;
}
}
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)) {
bool onlydata) const
{
ostringstream sstr;
- int ret = getCellInset(cell).plaintext(buf, sstr, runparams);
+ int const 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;
if (isMultiColumnReal(cell))
continue;
ostringstream sstr;
- getCellInset(cell).plaintext(buf, sstr, runparams);
+ 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).plaintext(buf, sstr, runparams);
+ 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)
int cell = 0;
for (int i = 0; i < rows_; ++i) {
if (!onlydata && asciiTopHLine(os, i, clen))
- for (int j = 0; j < depth; ++j)
- os << " ";
+ os << string(depth * 2, ' ');
for (int j = 0; j < columns_; ++j) {
if (isPartOfMultiColumn(i, j))
continue;
}
os << endl;
if (!onlydata) {
- for (int j = 0; j < depth; ++j)
- os << " ";
+ os << string(depth * 2, ' ');
if (asciiBottomHLine(os, i, clen))
- for (int j = 0; j < depth; ++j)
- os << " ";
+ os << string(depth * 2, ' ');
}
}
return ret;
}
-InsetText & LyXTabular::getCellInset(int cell) const
+shared_ptr<InsetText> LyXTabular::getCellInset(int cell) const
{
return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
}
-InsetText & LyXTabular::getCellInset(int row, int column) const
+shared_ptr<InsetText> LyXTabular::getCellInset(int row, int column) const
{
return cell_info[row][column].inset;
}
}
for (int cell = 0, n = getNumberOfCells(); cell < n; ++cell)
- if (&getCellInset(cell) == inset) {
+ if (getCellInset(cell).get() == inset) {
lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: "
<< "cell=" << cell << endl;
return cell;
if (getVAlignment(cell) != LYX_VALIGN_TOP ||
(!getPWidth(cell).zero() && !isMultiColumn(cell)))
features.require("array");
- getCellInset(cell).validate(features);
+ getCellInset(cell)->validate(features);
}
}
{
for (int i = 0; i < rows_; ++i)
for (int j = 0; j < columns_; ++j)
- getCellInset(i, j).getLabelList(buffer, list);
+ getCellInset(i, j)->getLabelList(buffer, list);
}
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();