]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
hopefully fix tex2lyx linking.
[lyx.git] / src / tabular.C
index cdfa5e320fe03eadcc71bcbe89268b85c03d417e..711e5432ab5f1044e0fa8b5c219f034386ae6ad0 100644 (file)
 
 #include <sstream>
 
-using lyx::support::ltrim;
-using lyx::support::prefixIs;
-using lyx::support::rtrim;
-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;
@@ -495,9 +498,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();
 }
@@ -516,6 +519,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_;
@@ -540,8 +558,8 @@ 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();
-               if (bp.tracking_changes)
-                       cell_info[i][column + 1].inset->markNew(true);
+               if (bp.trackChanges)
+                       cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED));
        }
        fixCellNums();
 }
@@ -561,6 +579,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;
@@ -628,29 +662,29 @@ LyXTabular::idx_type LyXTabular::numberOfCellsInRow(idx_type const cell) const
 }
 
 
-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 (use_booktabs)
                return false;
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholecolumn && isMultiColumn(cell) &&
                (isFirstCellInRow(cell) || isMultiColumn(cell-1)))
        {
                if (cellinfo_of_cell(cell).align_special.empty())
@@ -663,11 +697,11 @@ bool LyXTabular::leftLine(idx_type cell, bool onlycolumn) const
 }
 
 
-bool LyXTabular::rightLine(idx_type cell, bool onlycolumn) const
+bool LyXTabular::rightLine(idx_type cell, bool wholecolumn) const
 {
        if (use_booktabs)
                return false;
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholecolumn && isMultiColumn(cell) &&
                (isLastCellInRow(cell) || isMultiColumn(cell + 1)))
        {
                if (cellinfo_of_cell(cell).align_special.empty())
@@ -918,15 +952,14 @@ void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth)
                return;
 
        // merge all paragraphs to one
-       BufferParams const & bp =
-               inset->getText(0)->bv_owner->buffer()->params();
+       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(0, cur.lastpit() + 1,
+       inset->getText(0)->setLayout(*cur.bv().buffer(), 0, cur.lastpit() + 1,
                        bp.getLyXTextClass().defaultLayoutName());
        cur.pop();
 }
@@ -992,37 +1025,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;
@@ -1791,7 +1824,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);
@@ -1827,7 +1860,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_)
@@ -1863,7 +1896,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;
 
@@ -1874,7 +1907,8 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const
        if (isMultiColumn(cell)) {
                os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
                if (!cellinfo_of_cell(cell).align_special.empty()) {
-                       os << cellinfo_of_cell(cell).align_special << "}{";
+                       os << from_ascii(cellinfo_of_cell(cell).align_special)
+                          << "}{";
                } else {
                        if (leftLine(cell) &&
                                (isFirstCellInRow(cell) ||
@@ -1896,7 +1930,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, idx_type cell) const
                                        break;
                                }
                                os << '{'
-                                  << getPWidth(cell).asLatexString()
+                                  << from_ascii(getPWidth(cell).asLatexString())
                                   << '}';
                        } else {
                                switch (getAlignment(cell)) {
@@ -1932,7 +1966,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)) {
@@ -1946,14 +1981,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;
 
@@ -1975,7 +2011,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)
@@ -2075,7 +2111,7 @@ 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);
@@ -2088,10 +2124,12 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf,
        } else if(!row_info[i].top_space.zero()) {
                if (use_booktabs)
                        os << "\\addlinespace["
-                          << row_info[i].top_space.asLatexString() << "]\n";
+                          << from_ascii(row_info[i].top_space.asLatexString())
+                          << "]\n";
                else {
                        os << "\\noalign{\\vskip"
-                          << row_info[i].top_space.asLatexString() << "}\n";
+                          << from_ascii(row_info[i].top_space.asLatexString())
+                          << "}\n";
                }
                ++ret;
        }
@@ -2115,8 +2153,7 @@ 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;
        }
@@ -2129,7 +2166,9 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf,
        } else if (!row_info[i].bottom_space.zero()) {
                if (use_booktabs)
                        os << "\\addlinespace";
-               os << '[' << row_info[i].bottom_space.asLatexString() << ']';
+               os << '['
+                  << from_ascii(row_info[i].bottom_space.asLatexString())
+                  << ']';
        }
        os << '\n';
        ++ret;
@@ -2142,11 +2181,11 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf,
        } else if (!row_info[i].interline_space.zero()) {
                if (use_booktabs)
                        os << "\\addlinespace["
-                          << row_info[i].interline_space.asLatexString()
+                          << from_ascii(row_info[i].interline_space.asLatexString())
                           << "]\n";
                else
                        os << "\\noalign{\\vskip"
-                          << row_info[i].interline_space.asLatexString()
+                          << from_ascii(row_info[i].interline_space.asLatexString())
                           << "}\n";
                ++ret;
        }
@@ -2154,7 +2193,7 @@ int LyXTabular::TeXRow(ostream & os, row_type i, Buffer const & buf,
 }
 
 
-int LyXTabular::latex(Buffer const & buf, ostream & os,
+int LyXTabular::latex(Buffer const & buf, odocstream & os,
                      OutputParams const & runparams) const
 {
        int ret = 0;
@@ -2173,7 +2212,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os,
                os << "\\begin{tabular}{";
        for (col_type i = 0; i < columns_; ++i) {
                if (!column_info[i].align_special.empty()) {
-                       os << column_info[i].align_special;
+                       os << from_ascii(column_info[i].align_special);
                } else {
                        if (!use_booktabs && column_info[i].left_line)
                                os << '|';
@@ -2207,7 +2246,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) {
@@ -2262,49 +2301,7 @@ int LyXTabular::latex(Buffer const & buf, ostream & os,
 }
 
 
-int LyXTabular::linuxdoc(Buffer const & buf, ostream & os,
-                        const OutputParams & runparams) const
-{
-       os << "<tabular ca=\"";
-       for (col_type i = 0; i < columns_; ++i) {
-               switch (column_info[i].alignment) {
-               case LYX_ALIGN_LEFT:
-                       os << 'l';
-                       break;
-               case LYX_ALIGN_RIGHT:
-                       os << 'r';
-                       break;
-               default:
-                       os << 'c';
-                       break;
-               }
-       }
-       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<InsetText> inset = getCellInset(cell);
-
-                       ret += inset->linuxdoc(buf, os, runparams);
-
-                       if (isLastCellInRow(cell)) {
-                               os << "@\n";
-                               ++ret;
-                       } else {
-                               os << "|";
-                       }
-                       ++cell;
-               }
-       }
-       os << "</tabular>\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;
@@ -2356,7 +2353,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;
@@ -2441,7 +2438,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os,
 }
 
 
-int LyXTabular::asciiTopHLine(ostream & os, row_type row,
+int LyXTabular::asciiTopHLine(odocstream & os, row_type row,
                              vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
@@ -2457,7 +2454,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))
@@ -2474,7 +2471,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 << "-+";
@@ -2489,7 +2486,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row,
 }
 
 
-int LyXTabular::asciiBottomHLine(ostream & os, row_type row,
+int LyXTabular::asciiBottomHLine(odocstream & os, row_type row,
                                 vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
@@ -2505,7 +2502,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))
@@ -2522,7 +2519,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 << "-+";
@@ -2537,13 +2534,13 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row,
 }
 
 
-int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os,
+int LyXTabular::asciiPrintCell(Buffer const & buf, odocstream & os,
                               OutputParams const & runparams,
                               idx_type cell, row_type row, col_type column,
                               vector<unsigned int> const & clen,
                               bool onlydata) const
 {
-       ostringstream sstr;
+       odocstringstream sstr;
        int const ret = getCellInset(cell)->plaintext(buf, sstr, runparams);
 
        if (onlydata) {
@@ -2578,7 +2575,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 << " |";
@@ -2589,7 +2587,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
@@ -2607,7 +2605,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();
@@ -2619,7 +2617,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);
@@ -2633,7 +2631,7 @@ 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, ' ');
+                       os << docstring(depth * 2, ' ');
                for (col_type j = 0; j < columns_; ++j) {
                        if (isPartOfMultiColumn(i, j))
                                continue;
@@ -2645,9 +2643,9 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os,
                }
                os << endl;
                if (!onlydata) {
-                       os << string(depth * 2, ' ');
+                       os << docstring(depth * 2, ' ');
                        if (asciiBottomHLine(os, i, clen))
-                               os << string(depth * 2, ' ');
+                               os << docstring(depth * 2, ' ');
                }
        }
        return ret;
@@ -2730,3 +2728,6 @@ LyXTabular::BoxType LyXTabular::useParbox(idx_type cell) const
 
        return BOX_NONE;
 }
+
+
+} // namespace lyx