]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
more cursor dispatch
[lyx.git] / src / tabular.C
index 79261e6bd285077512cc8450af7120cc8b97d520..3f43ff0de86612db84a9600964b7880e89354c26 100644 (file)
@@ -24,6 +24,7 @@
 #include "debug.h"
 #include "LaTeXFeatures.h"
 #include "lyxlex.h"
+#include "outputparams.h"
 #include "paragraph.h"
 
 #include "insets/insettabular.h"
@@ -240,9 +241,7 @@ bool getTokenValue(string const & str, const char * token, int & num)
 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);
 }
 
 
@@ -250,9 +249,7 @@ bool getTokenValue(string const & str, const char * token,
                                   LyXTabular::VAlignment & num)
 {
        string tmp;
-       if (!getTokenValue(str, token, tmp))
-               return false;
-       return string2type(tmp, num);
+       return getTokenValue(str, token, tmp) && string2type(tmp, num);
 }
 
 
@@ -260,9 +257,7 @@ bool getTokenValue(string const & str, const char * token,
                                   LyXTabular::BoxType & num)
 {
        string tmp;
-       if (!getTokenValue(str, token, tmp))
-               return false;
-       return string2type(tmp, num);
+       return getTokenValue(str, token, tmp) && string2type(tmp, num);
 }
 
 
@@ -272,9 +267,7 @@ bool getTokenValue(string const & str, const char * token, bool & flag)
        // 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);
 }
 
 
@@ -284,9 +277,7 @@ bool getTokenValue(string const & str, const char * token, LyXLength & len)
        // 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);
 }
 
 
@@ -407,10 +398,6 @@ void LyXTabular::setOwner(InsetTabular * inset)
 }
 
 
-#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_;
@@ -458,8 +445,6 @@ void LyXTabular::appendColumn(BufferParams const & bp, int cell)
 {
        ++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());
@@ -467,21 +452,16 @@ void LyXTabular::appendColumn(BufferParams const & bp, int cell)
        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);
@@ -1407,7 +1387,7 @@ void LyXTabular::setMultiColumn(Buffer * buffer, int cell, int number)
        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();
@@ -1915,7 +1895,7 @@ int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
 
 
 int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf,
-                                        LatexRunParams const & runparams) const
+                                        OutputParams const & runparams) const
 {
        if (!is_long_tabular)
                return 0;
@@ -2015,7 +1995,7 @@ bool LyXTabular::isValidRow(int row) const
 
 
 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);
@@ -2028,8 +2008,8 @@ int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
                ret += TeXCellPreamble(os, cell);
                InsetText & inset = getCellInset(cell);
 
-               bool rtl = inset.paragraphs.begin()->isRightToLeftPar(bufferparams) &&
-                       !inset.paragraphs.begin()->empty() && getPWidth(cell).zero();
+               bool rtl = inset.paragraphs().begin()->isRightToLeftPar(bufferparams) &&
+                       !inset.paragraphs().begin()->empty() && getPWidth(cell).zero();
 
                if (rtl)
                        os << "\\R{";
@@ -2052,7 +2032,7 @@ int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
 
 
 int LyXTabular::latex(Buffer const & buf, ostream & os,
-                     LatexRunParams const & runparams) const
+                     OutputParams const & runparams) const
 {
        int ret = 0;
 
@@ -2159,7 +2139,8 @@ int LyXTabular::latex(Buffer const & buf, ostream & os,
 }
 
 
-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) {
@@ -2184,7 +2165,7 @@ int LyXTabular::linuxdoc(Buffer const & buf, ostream & os) const
                                continue;
                        InsetText & inset = getCellInset(cell);
 
-                       ret += inset.linuxdoc(buf, os);
+                       ret += inset.linuxdoc(buf, os, runparams);
 
                        if (isLastCellInRow(cell)) {
                                os << "@\n";
@@ -2200,7 +2181,8 @@ int LyXTabular::linuxdoc(Buffer const & buf, ostream & os) const
 }
 
 
-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);
@@ -2242,7 +2224,9 @@ int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row) const
                }
 
                os << '>';
-               ret += getCellInset(cell).docbook(buf, os, true);
+               OutputParams runp = runparams;
+               runp.mixed_content = true;
+               ret += getCellInset(cell).docbook(buf, os, runp);
                os << "</entry>\n";
                ++cell;
        }
@@ -2252,7 +2236,7 @@ int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row) const
 
 
 int LyXTabular::docbook(Buffer const & buf, ostream & os,
-                       bool /*mixcont*/) const
+                       OutputParams const & runparams) const
 {
        int ret = 0;
 
@@ -2290,7 +2274,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os,
                ++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";
@@ -2302,7 +2286,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os,
                ++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";
@@ -2317,7 +2301,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os,
        ++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";
@@ -2428,12 +2412,13 @@ int LyXTabular::asciiBottomHLine(ostream & os, int row,
 
 
 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();
@@ -2477,8 +2462,10 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os,
 }
 
 
-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;
 
@@ -2494,7 +2481,7 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
                                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();
                        }
@@ -2506,7 +2493,7 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
                                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)
@@ -2526,7 +2513,8 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
                                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;
@@ -2554,7 +2542,7 @@ InsetText & LyXTabular::getCellInset(int row, int column) const
 }
 
 
-int LyXTabular::getCellFromInset(InsetOld const * inset) const
+int LyXTabular::getCellFromInset(InsetBase const * inset) const
 {
        // is this inset part of the tabular?
        if (!inset) {
@@ -2562,7 +2550,7 @@ int LyXTabular::getCellFromInset(InsetOld const * inset) const
                return -1;
        }
 
-       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;
@@ -2570,7 +2558,8 @@ int LyXTabular::getCellFromInset(InsetOld const * inset) const
                }
 
        // We should have found a cell at this point
-       lyxerr << "LyXTabular::getCellFromInset: Cell not found!" << endl;
+       lyxerr << "LyXTabular::getCellFromInset: Cell of inset "
+               << inset << " not found!" << endl;
        return -1;
 }
 
@@ -2602,7 +2591,7 @@ void LyXTabular::getLabelList(Buffer const & buffer,
 
 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();