X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftabular.C;h=7d873348eefb5c772c9208d912815d838b02251c;hb=0657a91fd08e9c31d7f9e6be26055cc5050e5f8b;hp=9655a5c50899fab606c4de83cc170306991a001d;hpb=742ffb30325d81fe4517ef86aa3f0073a7f68270;p=lyx.git diff --git a/src/tabular.C b/src/tabular.C index 9655a5c508..7d873348ee 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -21,24 +21,29 @@ #include "buffer.h" #include "bufferparams.h" +#include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "LaTeXFeatures.h" #include "lyxlex.h" #include "outputparams.h" #include "paragraph.h" +#include "paragraph_funcs.h" #include "insets/insettabular.h" #include "support/lstrings.h" -#include "support/tostr.h" +#include "support/convert.h" #include -using lyx::support::ltrim; -using lyx::support::prefixIs; -using lyx::support::rtrim; -using lyx::support::strToInt; -using lyx::support::suffixIs; + +namespace lyx { + +using support::prefixIs; +using support::ltrim; +using support::rtrim; +using support::suffixIs; using boost::shared_ptr; using boost::dynamic_pointer_cast; @@ -62,6 +67,8 @@ using std::strlen; namespace { int const WIDTH_OF_LINE = 5; +int const default_line_space = 10; + template string const write_attribute(string const & name, T const & t) @@ -70,36 +77,48 @@ string const write_attribute(string const & name, T const & t) return s.empty() ? s : " " + name + "=\"" + s + "\""; } +template <> string const write_attribute(string const & name, string const & t) { return t.empty() ? t : " " + name + "=\"" + t + "\""; } +template <> +string const write_attribute(string const & name, docstring const & t) +{ + return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\""; +} + + +template <> string const write_attribute(string const & name, bool const & b) { // we write only true attribute values so we remove a bit of the // file format bloat for tabulars. - return b ? write_attribute(name, tostr(b)) : string(); + return b ? write_attribute(name, convert(b)) : string(); } +template <> string const write_attribute(string const & name, int const & i) { // we write only true attribute values so we remove a bit of the // file format bloat for tabulars. - return i ? write_attribute(name, tostr(i)) : string(); + return i ? write_attribute(name, convert(i)) : string(); } +template <> string const write_attribute(string const & name, LyXTabular::idx_type const & i) { // we write only true attribute values so we remove a bit of the // file format bloat for tabulars. - return i ? write_attribute(name, tostr(i)) : string(); + return i ? write_attribute(name, convert(i)) : string(); } +template <> string const write_attribute(string const & name, LyXLength const & value) { // we write only the value if we really have one same reson as above. @@ -238,13 +257,22 @@ bool getTokenValue(string const & str, char const * token, string & ret) } +bool getTokenValue(string const & str, char const * token, docstring & ret) +{ + string tmp; + bool const success = getTokenValue(str, token, tmp); + ret = from_utf8(tmp); + return success; +} + + bool getTokenValue(string const & str, char const * token, int & num) { string tmp; num = 0; if (!getTokenValue(str, token, tmp)) return false; - num = strToInt(tmp); + num = convert(tmp); return true; } @@ -292,6 +320,21 @@ bool getTokenValue(string const & str, char const * token, LyXLength & len) } +bool getTokenValue(string const & str, char const * token, LyXLength & len, bool & flag) +{ + len = LyXLength(); + flag = false; + string tmp; + if (!getTokenValue(str, token, tmp)) + return false; + if (tmp == "default") { + flag = true; + return true; + } + return isValidLength(tmp, &len); +} + + void l_getline(istream & is, string & str) { str.erase(); @@ -373,6 +416,9 @@ LyXTabular::rowstruct::rowstruct() descent_of_row(0), top_line(true), bottom_line(false), + top_space_default(false), + bottom_space_default(false), + interline_space_default(false), endhead(false), endfirsthead(false), endfoot(false), @@ -399,7 +445,7 @@ LyXTabular::ltType::ltType() LyXTabular::LyXTabular(BufferParams const & bp, row_type rows_arg, - col_type columns_arg) + col_type columns_arg) { init(bp, rows_arg, columns_arg); } @@ -407,7 +453,7 @@ LyXTabular::LyXTabular(BufferParams const & bp, row_type rows_arg, // activates all lines and sets all widths to 0 void LyXTabular::init(BufferParams const & bp, row_type rows_arg, - col_type columns_arg) + col_type columns_arg) { rows_ = rows_arg; columns_ = columns_arg; @@ -425,6 +471,7 @@ void LyXTabular::init(BufferParams const & bp, row_type rows_arg, column_info.back().right_line = true; is_long_tabular = false; rotate = false; + use_booktabs = false; } @@ -467,9 +514,9 @@ void LyXTabular::appendRow(BufferParams const & bp, idx_type const cell) for (row_type i = row + 2; i < rows_; ++i) swap(cell_info[i], old[i - 1]); - if (bp.tracking_changes) + if (bp.trackChanges) for (col_type j = 0; j < columns_; ++j) - cell_info[row + 1][j].inset->markNew(true); + cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED)); set_row_column_number_info(); } @@ -488,6 +535,21 @@ void LyXTabular::deleteRow(row_type const row) } +void LyXTabular::copyRow(BufferParams const & bp, row_type const row) +{ + ++rows_; + + row_info.insert(row_info.begin() + row, row_info[row]); + cell_info.insert(cell_info.begin() + row, cell_info[row]); + + if (bp.trackChanges) + for (col_type j = 0; j < columns_; ++j) + cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED)); + + set_row_column_number_info(); +} + + void LyXTabular::appendColumn(BufferParams const & bp, idx_type const cell) { ++columns_; @@ -511,9 +573,9 @@ void LyXTabular::appendColumn(BufferParams const & bp, idx_type const cell) } //++column; for (row_type i = 0; i < rows_; ++i) { - 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->clear(); + if (bp.trackChanges) + cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED)); } fixCellNums(); } @@ -533,6 +595,22 @@ void LyXTabular::deleteColumn(col_type const column) } +void LyXTabular::copyColumn(BufferParams const & bp, col_type const column) +{ + ++columns_; + + column_info.insert(column_info.begin() + column, column_info[column]); + + for (row_type i = 0; i < rows_; ++i) + cell_info[i].insert(cell_info[i].begin() + column, cell_info[i][column]); + + if (bp.trackChanges) + for (row_type i = 0; i < rows_; ++i) + cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED)); + fixCellNums(); +} + + void LyXTabular::set_row_column_number_info() { numberofcells = 0; @@ -600,50 +678,55 @@ LyXTabular::idx_type LyXTabular::numberOfCellsInRow(idx_type const cell) const } -// returns 1 if there is a topline, returns 0 if not -bool LyXTabular::topLine(idx_type const cell, bool const onlycolumn) const +bool LyXTabular::topLine(idx_type const cell, bool const wholerow) const { - if (!onlycolumn && isMultiColumn(cell)) + if (!wholerow && isMultiColumn(cell) && + !(use_booktabs && row_of_cell(cell) == 0)) return cellinfo_of_cell(cell).top_line; return row_info[row_of_cell(cell)].top_line; } -bool LyXTabular::bottomLine(idx_type const cell, bool onlycolumn) const +bool LyXTabular::bottomLine(idx_type const cell, bool wholerow) const { - if (!onlycolumn && isMultiColumn(cell)) + if (!wholerow && isMultiColumn(cell) && + !(use_booktabs && isLastRow(cell))) return cellinfo_of_cell(cell).bottom_line; return row_info[row_of_cell(cell)].bottom_line; } -bool LyXTabular::leftLine(idx_type cell, bool onlycolumn) const +bool LyXTabular::leftLine(idx_type cell, bool wholecolumn) const { - if (!onlycolumn && isMultiColumn(cell) && + if (use_booktabs) + return false; + if (!wholecolumn && isMultiColumn(cell) && (isFirstCellInRow(cell) || isMultiColumn(cell-1))) { if (cellinfo_of_cell(cell).align_special.empty()) return cellinfo_of_cell(cell).left_line; - return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), "|"); + return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), '|'); } if (column_info[column_of_cell(cell)].align_special.empty()) return column_info[column_of_cell(cell)].left_line; - return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), "|"); + return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), '|'); } -bool LyXTabular::rightLine(idx_type cell, bool onlycolumn) const +bool LyXTabular::rightLine(idx_type cell, bool wholecolumn) const { - if (!onlycolumn && isMultiColumn(cell) && + if (use_booktabs) + return false; + if (!wholecolumn && isMultiColumn(cell) && (isLastCellInRow(cell) || isMultiColumn(cell + 1))) { if (cellinfo_of_cell(cell).align_special.empty()) return cellinfo_of_cell(cell).right_line; - return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), "|"); + return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), '|'); } if (column_info[column_of_cell(cell)].align_special.empty()) return column_info[right_column_of_cell(cell)].right_line; - return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), "|"); + return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), '|'); } @@ -714,9 +797,12 @@ int LyXTabular::getAdditionalHeight(row_type row) const top = row_info[row].top_line; } } + int const interline_space = row_info[row - 1].interline_space_default ? + default_line_space : + row_info[row - 1].interline_space.inPixels(width_of_tabular); if (top && bottom) - return WIDTH_OF_LINE; - return 0; + return interline_space + WIDTH_OF_LINE; + return interline_space; } @@ -794,9 +880,9 @@ void LyXTabular::recalculateMulticolumnsOfColumn(col_type column) // 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)) + if (columns_ < 2 || column > (columns_ - 2)) return; - for(row_type row = 0; row < rows_; ++row) { + for (row_type 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 @@ -813,7 +899,6 @@ void LyXTabular::recalculateMulticolumnsOfColumn(col_type column) } -// returns 1 if a complete update is necessary, otherwise 0 void LyXTabular::setWidthOfCell(idx_type cell, int new_width) { row_type const row = row_of_cell(cell); @@ -850,7 +935,7 @@ void LyXTabular::setWidthOfCell(idx_type cell, int new_width) void LyXTabular::setAlignment(idx_type cell, LyXAlignment align, - bool onlycolumn) + bool onlycolumn) { if (!isMultiColumn(cell) || onlycolumn) column_info[column_of_cell(cell)].alignment = align; @@ -860,7 +945,7 @@ void LyXTabular::setAlignment(idx_type cell, LyXAlignment align, void LyXTabular::setVAlignment(idx_type cell, VAlignment align, - bool onlycolumn) + bool onlycolumn) { if (!isMultiColumn(cell) || onlycolumn) column_info[column_of_cell(cell)].valignment = align; @@ -869,7 +954,37 @@ void LyXTabular::setVAlignment(idx_type cell, VAlignment align, } -void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width) +namespace { + +/** + * Allow line and paragraph breaks for fixed width cells or disallow them, + * merge cell paragraphs and reset layout to standard for variable width + * cells. + */ +void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth) +{ + inset->setAutoBreakRows(fixedWidth); + if (fixedWidth) + return; + + // merge all paragraphs to one + BufferParams const & bp = cur.bv().buffer()->params(); + while (inset->paragraphs().size() > 1) + mergeParagraph(bp, inset->paragraphs(), 0); + + // reset layout + cur.push(*inset); + // undo information has already been recorded + inset->getText(0)->setLayout(*cur.bv().buffer(), 0, cur.lastpit() + 1, + bp.getLyXTextClass().defaultLayoutName()); + cur.pop(); +} + +} + + +void LyXTabular::setColumnPWidth(LCursor & cur, idx_type cell, + LyXLength const & width) { col_type const j = column_of_cell(cell); @@ -877,23 +992,37 @@ void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width) for (row_type i = 0; i < rows_; ++i) { idx_type const cell = getCellNumber(i, j); // because of multicolumns - getCellInset(cell)->setAutoBreakRows(!getPWidth(cell).zero()); + toggleFixedWidth(cur, getCellInset(cell).get(), + !getPWidth(cell).zero()); } + // cur paragraph can become invalid after paragraphs were merged + if (cur.pit() > cur.lastpit()) + cur.pit() = cur.lastpit(); + // cur position can become invalid after newlines were removed + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); } -bool LyXTabular::setMColumnPWidth(idx_type cell, LyXLength const & width) +bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell, + LyXLength const & width) { if (!isMultiColumn(cell)) return false; cellinfo_of_cell(cell).p_width = width; - getCellInset(cell)->setAutoBreakRows(!width.zero()); + toggleFixedWidth(cur, getCellInset(cell).get(), !width.zero()); + // cur paragraph can become invalid after paragraphs were merged + if (cur.pit() > cur.lastpit()) + cur.pit() = cur.lastpit(); + // cur position can become invalid after newlines were removed + if (cur.pos() > cur.lastpos()) + cur.pos() = cur.lastpos(); return true; } -void LyXTabular::setAlignSpecial(idx_type cell, string const & special, +void LyXTabular::setAlignSpecial(idx_type cell, docstring const & special, LyXTabular::Feature what) { if (what == SET_SPECIAL_MULTI) @@ -912,37 +1041,37 @@ void LyXTabular::setAllLines(idx_type cell, bool line) } -void LyXTabular::setTopLine(idx_type cell, bool line, bool onlycolumn) +void LyXTabular::setTopLine(idx_type cell, bool line, bool wholerow) { row_type const row = row_of_cell(cell); - if (onlycolumn || !isMultiColumn(cell)) + if (wholerow || !isMultiColumn(cell)) row_info[row].top_line = line; else cellinfo_of_cell(cell).top_line = line; } -void LyXTabular::setBottomLine(idx_type cell, bool line, bool onlycolumn) +void LyXTabular::setBottomLine(idx_type cell, bool line, bool wholerow) { - if (onlycolumn || !isMultiColumn(cell)) + if (wholerow || !isMultiColumn(cell)) row_info[row_of_cell(cell)].bottom_line = line; else cellinfo_of_cell(cell).bottom_line = line; } -void LyXTabular::setLeftLine(idx_type cell, bool line, bool onlycolumn) +void LyXTabular::setLeftLine(idx_type cell, bool line, bool wholecolumn) { - if (onlycolumn || !isMultiColumn(cell)) + if (wholecolumn || !isMultiColumn(cell)) column_info[column_of_cell(cell)].left_line = line; else cellinfo_of_cell(cell).left_line = line; } -void LyXTabular::setRightLine(idx_type cell, bool line, bool onlycolumn) +void LyXTabular::setRightLine(idx_type cell, bool line, bool wholecolumn) { - if (onlycolumn || !isMultiColumn(cell)) + if (wholecolumn || !isMultiColumn(cell)) column_info[right_column_of_cell(cell)].right_line = line; else cellinfo_of_cell(cell).right_line = line; @@ -988,7 +1117,7 @@ LyXLength const LyXTabular::getMColumnPWidth(idx_type cell) const } -string const LyXTabular::getAlignSpecial(idx_type cell, int what) const +docstring const LyXTabular::getAlignSpecial(idx_type cell, int what) const { if (what == SET_SPECIAL_MULTI) return cellinfo_of_cell(cell).align_special; @@ -1142,6 +1271,7 @@ void LyXTabular::write(Buffer const & buf, ostream & os) const // global longtable options os << "appendParagraphs(buffer, cs1.inset->paragraphs()); - cs1.inset->clear(false); + cs1.inset->clear(); } set_row_column_number_info(); } @@ -1391,6 +1542,18 @@ LyXTabular::idx_type LyXTabular::unsetMultiColumn(idx_type cell) } +void LyXTabular::setBookTabs(bool what) +{ + use_booktabs = what; +} + + +bool LyXTabular::useBookTabs() const +{ + return use_booktabs; +} + + void LyXTabular::setLongTabular(bool what) { is_long_tabular = what; @@ -1484,10 +1647,10 @@ LyXTabular::idx_type LyXTabular::getLastCellBelow(idx_type cell) const LyXTabular::idx_type LyXTabular::getCellNumber(row_type row, - col_type column) const + col_type column) const { BOOST_ASSERT(column != npos && column < columns_ && - row != npos && row < rows_); + row != npos && row < rows_); return cell_info[row][column].cellno; } @@ -1513,7 +1676,7 @@ LyXTabular::BoxType LyXTabular::getUsebox(idx_type cell) const // This are functions used for the longtable support /// void LyXTabular::setLTHead(row_type row, bool flag, ltType const & hd, - bool first) + bool first) { if (first) { endfirsthead = hd; @@ -1544,7 +1707,7 @@ bool LyXTabular::getRowOfLTFirstHead(row_type row, ltType & hd) const void LyXTabular::setLTFoot(row_type row, bool flag, ltType const & fd, - bool last) + bool last) { if (last) { endlastfoot = fd; @@ -1677,7 +1840,7 @@ bool LyXTabular::isPartOfMultiColumn(row_type row, col_type column) const } -int LyXTabular::TeXTopHLine(ostream & os, row_type row) const +int LyXTabular::TeXTopHLine(odocstream & os, row_type row) const { // FIXME: assert or return 0 as in TeXBottomHLine()? BOOST_ASSERT(row != npos); @@ -1691,12 +1854,14 @@ int LyXTabular::TeXTopHLine(ostream & os, row_type row) const if (topLine(i)) ++tmp; } - if (tmp == n - fcell) { - os << "\\hline "; + if (use_booktabs && row == 0) { + os << "\\toprule "; + } else if (tmp == n - fcell) { + os << (use_booktabs ? "\\midrule " : "\\hline "); } else if (tmp) { for (idx_type i = fcell; i < n; ++i) { if (topLine(i)) { - os << "\\cline{" + os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << column_of_cell(i) + 1 << '-' << right_column_of_cell(i) + 1 @@ -1711,7 +1876,7 @@ int LyXTabular::TeXTopHLine(ostream & os, row_type row) const } -int LyXTabular::TeXBottomHLine(ostream & os, row_type row) const +int LyXTabular::TeXBottomHLine(odocstream & os, row_type row) const { // FIXME: return 0 or assert as in TeXTopHLine()? if (row == npos || row >= rows_) @@ -1725,12 +1890,14 @@ int LyXTabular::TeXBottomHLine(ostream & os, row_type row) const if (bottomLine(i)) ++tmp; } - if (tmp == n - fcell) { - os << "\\hline"; + if (use_booktabs && row == rows_ - 1) { + os << "\\bottomrule"; + } else if (tmp == n - fcell) { + os << (use_booktabs ? "\\midrule" : "\\hline"); } else if (tmp) { for (idx_type i = fcell; i < n; ++i) { if (bottomLine(i)) { - os << "\\cline{" + os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << column_of_cell(i) + 1 << '-' << right_column_of_cell(i) + 1 @@ -1745,7 +1912,7 @@ int LyXTabular::TeXBottomHLine(ostream & os, row_type row) const } -int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const +int LyXTabular::TeXCellPreamble(odocstream & os, idx_type cell) const { int ret = 0; @@ -1778,7 +1945,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const break; } os << '{' - << getPWidth(cell).asLatexString() + << from_ascii(getPWidth(cell).asLatexString()) << '}'; } else { switch (getAlignment(cell)) { @@ -1814,7 +1981,8 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const os << 'b'; break; } - os << "]{" << getPWidth(cell).asLatexString() << "}{"; + os << "]{" << from_ascii(getPWidth(cell).asLatexString()) + << "}{"; } else if (getUsebox(cell) == BOX_MINIPAGE) { os << "\\begin{minipage}["; switch (getVAlignment(cell)) { @@ -1828,14 +1996,15 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const os << 'b'; break; } - os << "]{" << getPWidth(cell).asLatexString() << "}\n"; + os << "]{" << from_ascii(getPWidth(cell).asLatexString()) + << "}\n"; ++ret; } return ret; } -int LyXTabular::TeXCellPostamble(ostream & os, idx_type cell) const +int LyXTabular::TeXCellPostamble(odocstream & os, idx_type cell) const { int ret = 0; @@ -1857,7 +2026,7 @@ int LyXTabular::TeXCellPostamble(ostream & os, idx_type cell) const } -int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf, +int LyXTabular::TeXLongtableHeaderFooter(odocstream & os, Buffer const & buf, OutputParams const & runparams) const { if (!is_long_tabular) @@ -1957,12 +2126,29 @@ bool LyXTabular::isValidRow(row_type row) const } -int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, +int LyXTabular::TeXRow(odocstream & os, row_type i, Buffer const & buf, OutputParams const & runparams) const { idx_type cell = getCellNumber(i, 0); - int ret = TeXTopHLine(os, i); + if (row_info[i].top_space_default) { + if (use_booktabs) + os << "\\addlinespace\n"; + else + os << "\\noalign{\\vskip\\doublerulesep}\n"; + } else if(!row_info[i].top_space.zero()) { + if (use_booktabs) + os << "\\addlinespace[" + << from_ascii(row_info[i].top_space.asLatexString()) + << "]\n"; + else { + os << "\\noalign{\\vskip" + << from_ascii(row_info[i].top_space.asLatexString()) + << "}\n"; + } + ++ret; + } + for (col_type j = 0; j < columns_; ++j) { if (isPartOfMultiColumn(i, j)) continue; @@ -1982,19 +2168,47 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf, ret += TeXCellPostamble(os, cell); if (!isLastCellInRow(cell)) { // not last cell in row - os << "&\n"; - ++ret; + os << " & "; } ++cell; } - os << "\\tabularnewline\n"; + os << "\\tabularnewline"; + if (row_info[i].bottom_space_default) { + if (use_booktabs) + os << "\\addlinespace"; + else + os << "[\\doublerulesep]"; + } else if (!row_info[i].bottom_space.zero()) { + if (use_booktabs) + os << "\\addlinespace"; + os << '[' + << from_ascii(row_info[i].bottom_space.asLatexString()) + << ']'; + } + os << '\n'; ++ret; ret += TeXBottomHLine(os, i); + if (row_info[i].interline_space_default) { + if (use_booktabs) + os << "\\addlinespace\n"; + else + os << "\\noalign{\\vskip\\doublerulesep}\n"; + } else if (!row_info[i].interline_space.zero()) { + if (use_booktabs) + os << "\\addlinespace[" + << from_ascii(row_info[i].interline_space.asLatexString()) + << "]\n"; + else + os << "\\noalign{\\vskip" + << from_ascii(row_info[i].interline_space.asLatexString()) + << "}\n"; + ++ret; + } return ret; } -int LyXTabular::latex(Buffer const & buf, ostream & os, +int LyXTabular::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { int ret = 0; @@ -2015,7 +2229,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, if (!column_info[i].align_special.empty()) { os << column_info[i].align_special; } else { - if (column_info[i].left_line) + if (!use_booktabs && column_info[i].left_line) os << '|'; if (!column_info[i].p_width.zero()) { switch (column_info[i].alignment) { @@ -2047,7 +2261,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, break; } os << '{' - << column_info[i].p_width.asLatexString() + << from_ascii(column_info[i].p_width.asLatexString()) << '}'; } else { switch (column_info[i].alignment) { @@ -2062,7 +2276,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, break; } } - if (column_info[i].right_line) + if (!use_booktabs && column_info[i].right_line) os << '|'; } } @@ -2102,49 +2316,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os, } -int LyXTabular::linuxdoc(Buffer const & buf, ostream & os, - const OutputParams & runparams) const -{ - os << "\n"; - idx_type cell = 0; - int ret = 0; - for (row_type i = 0; i < rows_; ++i) { - for (col_type j = 0; j < columns_; ++j) { - if (isPartOfMultiColumn(i, j)) - continue; - shared_ptr inset = getCellInset(cell); - - ret += inset->linuxdoc(buf, os, runparams); - - if (isLastCellInRow(cell)) { - os << "@\n"; - ++ret; - } else { - os << "|"; - } - ++cell; - } - } - os << "\n"; - return ret; -} - - -int LyXTabular::docbookRow(Buffer const & buf, ostream & os, row_type row, +int LyXTabular::docbookRow(Buffer const & buf, odocstream & os, row_type row, OutputParams const & runparams) const { int ret = 0; @@ -2196,7 +2368,7 @@ int LyXTabular::docbookRow(Buffer const & buf, ostream & os, row_type row, } -int LyXTabular::docbook(Buffer const & buf, ostream & os, +int LyXTabular::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { int ret = 0; @@ -2281,7 +2453,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os, } -int LyXTabular::asciiTopHLine(ostream & os, row_type row, +int LyXTabular::plaintextTopHLine(odocstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -2297,7 +2469,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, if (!tmp) return 0; - unsigned char ch; + char_type ch; for (idx_type i = fcell; i < n; ++i) { if (topLine(i)) { if (leftLine(i)) @@ -2314,7 +2486,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, while (column < columns_ - 1 && isPartOfMultiColumn(row, ++column)) len += clen[column] + 4; - os << string(len, ch); + os << docstring(len, ch); if (topLine(i)) { if (rightLine(i)) os << "-+"; @@ -2329,7 +2501,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, } -int LyXTabular::asciiBottomHLine(ostream & os, row_type row, +int LyXTabular::plaintextBottomHLine(odocstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -2345,7 +2517,7 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, if (!tmp) return 0; - unsigned char ch; + char_type ch; for (idx_type i = fcell; i < n; ++i) { if (bottomLine(i)) { if (leftLine(i)) @@ -2362,7 +2534,7 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, while (column < columns_ -1 && isPartOfMultiColumn(row, ++column)) len += clen[column] + 4; - os << string(len, ch); + os << docstring(len, ch); if (bottomLine(i)) { if (rightLine(i)) os << "-+"; @@ -2377,13 +2549,13 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, } -int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, +int LyXTabular::plaintextPrintCell(Buffer const & buf, odocstream & os, OutputParams const & runparams, idx_type cell, row_type row, col_type column, vector const & clen, bool onlydata) const { - ostringstream sstr; + odocstringstream sstr; int const ret = getCellInset(cell)->plaintext(buf, sstr, runparams); if (onlydata) { @@ -2418,7 +2590,8 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, break; } - os << string(len1, ' ') << sstr.str() << string(len2, ' '); + os << docstring(len1, ' ') << sstr.str() + << docstring(len2, ' '); if (rightLine(cell)) os << " |"; @@ -2429,7 +2602,7 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, } -int LyXTabular::plaintext(Buffer const & buf, ostream & os, +int LyXTabular::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams, int const depth, bool onlydata, unsigned char delim) const @@ -2447,7 +2620,7 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, idx_type cell = getCellNumber(i, j); if (isMultiColumnReal(cell)) continue; - ostringstream sstr; + odocstringstream sstr; getCellInset(cell)->plaintext(buf, sstr, runparams); if (clen[j] < sstr.str().length()) clen[j] = sstr.str().length(); @@ -2459,7 +2632,7 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, idx_type cell = getCellNumber(i, j); if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j)) continue; - ostringstream sstr; + odocstringstream sstr; getCellInset(cell)->plaintext(buf, sstr, runparams); int len = int(sstr.str().length()); idx_type const n = cells_in_multicolumn(cell); @@ -2472,22 +2645,22 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, } idx_type cell = 0; for (row_type i = 0; i < rows_; ++i) { - if (!onlydata && asciiTopHLine(os, i, clen)) - os << string(depth * 2, ' '); + if (!onlydata && plaintextTopHLine(os, i, clen)) + os << docstring(depth * 2, ' '); for (col_type j = 0; j < columns_; ++j) { if (isPartOfMultiColumn(i, j)) continue; if (onlydata && j > 0) os << delim; - ret += asciiPrintCell(buf, os, runparams, + ret += plaintextPrintCell(buf, os, runparams, cell, i, j, clen, onlydata); ++cell; } os << endl; if (!onlydata) { - os << string(depth * 2, ' '); - if (asciiBottomHLine(os, i, clen)) - os << string(depth * 2, ' '); + os << docstring(depth * 2, ' '); + if (plaintextBottomHLine(os, i, clen)) + os << docstring(depth * 2, ' '); } } return ret; @@ -2501,12 +2674,19 @@ shared_ptr LyXTabular::getCellInset(idx_type cell) const shared_ptr LyXTabular::getCellInset(row_type row, - col_type column) const + col_type column) const { return cell_info[row][column].inset; } +void LyXTabular::setCellInset(row_type row, col_type column, + shared_ptr ins) const +{ + cell_info[row][column].inset = ins; +} + + LyXTabular::idx_type LyXTabular::getCellFromInset(InsetBase const * inset) const { @@ -2535,6 +2715,8 @@ LyXTabular::getCellFromInset(InsetBase const * inset) const void LyXTabular::validate(LaTeXFeatures & features) const { features.require("NeedTabularnewline"); + if (useBookTabs()) + features.require("booktabs"); if (isLongTabular()) features.require("longtable"); if (needRotating()) @@ -2548,15 +2730,6 @@ void LyXTabular::validate(LaTeXFeatures & features) const } -void LyXTabular::getLabelList(Buffer const & buffer, - std::vector & list) const -{ - for (row_type i = 0; i < rows_; ++i) - for (col_type j = 0; j < columns_; ++j) - getCellInset(i, j)->getLabelList(buffer, list); -} - - LyXTabular::BoxType LyXTabular::useParbox(idx_type cell) const { ParagraphList const & parlist = getCellInset(cell)->paragraphs(); @@ -2570,3 +2743,6 @@ LyXTabular::BoxType LyXTabular::useParbox(idx_type cell) const return BOX_NONE; } + + +} // namespace lyx