]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
more cursor dispatch
[lyx.git] / src / tabular.C
index ce073eb46309fc921fdeb2d3567f2cad3d07fb6f..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"
@@ -48,6 +49,7 @@ using std::istream;
 using std::ostream;
 using std::ostringstream;
 using std::vector;
+using std::string;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::strlen;
@@ -143,6 +145,7 @@ string const tostr(LyXTabular::BoxType const & num)
        return string();
 }
 
+
 // I would have liked a fromstr template a lot better. (Lgb)
 bool string2type(string const str, LyXAlignment & num)
 {
@@ -213,11 +216,11 @@ bool getTokenValue(string const & str, const char * token, string & ret)
                return false;
        pos += token_length + 1;
        char ch = str[pos];
-       if ((ch != '"') && (ch != '\'')) { // only read till next space
+       if (ch != '"' && ch != '\'') { // only read till next space
                ret += ch;
                ch = ' ';
        }
-       while ((pos < str.length() - 1) && (str[++pos] != ch))
+       while (pos < str.length() - 1 && str[++pos] != ch)
                ret += str[pos];
 
        return true;
@@ -238,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);
 }
 
 
@@ -248,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);
 }
 
 
@@ -258,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);
 }
 
 
@@ -270,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);
 }
 
 
@@ -282,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);
 }
 
 
@@ -302,8 +295,8 @@ void l_getline(istream & is, string & str)
 
 /// Define a few methods for the inner structs
 
-LyXTabular::cellstruct::cellstruct(BufferParams const & bg)
-       : inset(bg)
+LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
+       : inset(bp)
 {
        cellno = 0;
        width_of_cell = 0;
@@ -351,71 +344,57 @@ LyXTabular::ltType::ltType()
 }
 
 
-LyXTabular::LyXTabular(BufferParams const & bp,
-                      InsetTabular * inset, int rows_arg, int columns_arg)
+LyXTabular::LyXTabular(BufferParams const & bp, int rows_arg, int columns_arg)
 {
-       owner_ = inset;
-       cur_cell = -1;
        init(bp, rows_arg, columns_arg);
 }
 
 
-LyXTabular::LyXTabular(BufferParams const & bp,
-                      InsetTabular * inset, LyXTabular const & lt)
-{
-       owner_ = inset;
-       cur_cell = -1;
-       init(bp, lt.rows_, lt.columns_, &lt);
-}
-
-
-LyXTabular::LyXTabular(Buffer const & buf, InsetTabular * inset, LyXLex & lex)
-{
-       owner_ = inset;
-       cur_cell = -1;
-       read(buf, lex);
-}
-
-
 // activates all lines and sets all widths to 0
-void LyXTabular::init(BufferParams const & bp,
-                     int rows_arg, int columns_arg, LyXTabular const * lt)
+void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
 {
-       rows_ = rows_arg;
+       rows_    = rows_arg;
        columns_ = columns_arg;
-       row_info = row_vector(rows_, rowstruct());
-       column_info = column_vector(columns_, columnstruct());
+       row_info = row_vector(rows_);
+       column_info = column_vector(columns_);
        cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
+       row_info.reserve(10);
+       column_info.reserve(10);
+       cell_info.reserve(100);
+       fixCellNums();
+       for (int i = 0; i < rows_; ++i)
+               cell_info[i].back().right_line = true;
+       row_info.back().bottom_line = true;
+       row_info.front().bottom_line = true;
+       column_info.back().right_line = true;
+       is_long_tabular = false;
+       rotate = false;
+}
 
-       if (lt) {
-               operator=(*lt);
-               return;
-       }
 
+void LyXTabular::fixCellNums()
+{
        int cellno = 0;
        for (int i = 0; i < rows_; ++i) {
                for (int j = 0; j < columns_; ++j) {
-                       cell_info[i][j].inset.setOwner(owner_);
                        cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
                        cell_info[i][j].cellno = cellno++;
                }
                cell_info[i].back().right_line = true;
        }
-       row_info.back().bottom_line = true;
-       row_info.front().bottom_line = true;
-
-       for (int i = 0; i < columns_; ++i)
-               calculate_width_of_column(i);
 
-       column_info.back().right_line = true;
+       set_row_column_number_info();
+}
 
-       calculate_width_of_tabular();
 
-       rowofcell.clear();
-       columnofcell.clear();
-       set_row_column_number_info();
-       is_long_tabular = false;
-       rotate = false;
+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);
+               }
+       }
 }
 
 
@@ -430,30 +409,22 @@ void LyXTabular::appendRow(BufferParams const & bp, int cell)
        // now set the values of the row before
        row_info[row] = row_info[row + 1];
 
-#if 0
-       cell_vvector::iterator cit = cell_info.begin() + row;
-       cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct(bp)));
-#else
-       cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
-                                                             cellstruct(bp)));
+       cell_vvector old(rows_ - 1);
+       for (int i = 0; i < rows_ - 1; ++i)
+               swap(cell_info[i], old[i]);
+
+       cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
 
        for (int i = 0; i <= row; ++i)
-               for (int j = 0; j < columns_; ++j)
-                       c_info[i][j] = cell_info[i][j];
+               swap(cell_info[i], old[i]);
+       for (int i = row + 2; i < rows_; ++i)
+               swap(cell_info[i], old[i - 1]);
 
-       for (int i = row + 1; i < rows_; ++i)
+       if (bp.tracking_changes)
                for (int j = 0; j < columns_; ++j)
-                       c_info[i][j] = cell_info[i-1][j];
+                       cell_info[row + 1][j].inset.markNew(true);
 
-       cell_info = c_info;
-       ++row;
-       for (int j = 0; j < columns_; ++j) {
-               cell_info[row][j].inset.clear(false);
-               if (bp.tracking_changes)
-                       cell_info[row][j].inset.markNew(true);
-       }
-#endif
-       Reinit();
+       set_row_column_number_info();
 }
 
 
@@ -466,7 +437,7 @@ void LyXTabular::deleteRow(int row)
        row_info.erase(row_info.begin() + row);
        cell_info.erase(cell_info.begin() + row);
        --rows_;
-       Reinit();
+       fixCellNums();
 }
 
 
@@ -474,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());
@@ -483,28 +452,23 @@ 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);
                if (bp.tracking_changes)
                        cell_info[i][column + 1].inset.markNew(true);
        }
-       Reinit();
+       fixCellNums();
 }
 
 
@@ -518,37 +482,11 @@ void LyXTabular::deleteColumn(int column)
        for (int i = 0; i < rows_; ++i)
                cell_info[i].erase(cell_info[i].begin() + column);
        --columns_;
-       Reinit();
-}
-
-
-void LyXTabular::reinit()
-{
-       Reinit(false);
-}
-
-
-void LyXTabular::Reinit(bool reset_widths)
-{
-       if (reset_widths) {
-               for (int i = 0; i < rows_; ++i) {
-                       for (int j = 0; j < columns_; ++j) {
-                               cell_info[i][j].width_of_cell = 0;
-                               cell_info[i][j].inset.setOwner(owner_);
-                       }
-               }
-       }
-
-       for (int i = 0; i < columns_; ++i)
-               calculate_width_of_column(i);
-
-       calculate_width_of_tabular();
-
-       set_row_column_number_info();
+       fixCellNums();
 }
 
 
-void LyXTabular::set_row_column_number_info(bool oldformat)
+void LyXTabular::set_row_column_number_info()
 {
        numberofcells = -1;
        for (int row = 0; row < rows_; ++row) {
@@ -585,14 +523,6 @@ void LyXTabular::set_row_column_number_info(bool oldformat)
                for (int column = 0; column < columns_; ++column) {
                        if (isPartOfMultiColumn(row,column))
                                continue;
-                       // now set the right line of multicolumns right for oldformat read
-                       if (oldformat &&
-                               cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
-                       {
-                               int cn = cells_in_multicolumn(cell_info[row][column].cellno);
-                               cell_info[row][column].right_line =
-                                       cell_info[row][column+cn-1].right_line;
-                       }
                        cell_info[row][column].inset.setAutoBreakRows(
                                !getPWidth(getCellNumber(row, column)).zero());
                }
@@ -652,7 +582,7 @@ bool LyXTabular::leftLine(int cell, bool onlycolumn) const
 bool LyXTabular::rightLine(int cell, bool onlycolumn) const
 {
        if (!onlycolumn && isMultiColumn(cell) &&
-               (isLastCellInRow(cell) || isMultiColumn(cell+1)))
+               (isLastCellInRow(cell) || isMultiColumn(cell + 1)))
        {
                if (cellinfo_of_cell(cell).align_special.empty())
                        return cellinfo_of_cell(cell).right_line;
@@ -701,7 +631,7 @@ bool LyXTabular::leftAlreadyDrawn(int cell) const
 
 bool LyXTabular::isLastRow(int cell) const
 {
-       return (row_of_cell(cell) == rows_ - 1);
+       return row_of_cell(cell) == rows_ - 1;
 }
 
 
@@ -849,7 +779,7 @@ void LyXTabular::setWidthOfCell(int cell, int new_width)
        if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width)
                return;
 
-       if (isMultiColumn(cell, true)) {
+       if (isMultiColumnReal(cell)) {
                tmp = setWidthOfMulticolCell(cell, new_width);
        } else {
                width = new_width + 2 * WIDTH_OF_LINE + add_width;
@@ -899,14 +829,12 @@ void LyXTabular::setColumnPWidth(int cell, LyXLength const & width)
 
 bool LyXTabular::setMColumnPWidth(int cell, LyXLength const & width)
 {
-       bool const flag = !width.zero();
+       if (!isMultiColumn(cell))
+               return false;
 
        cellinfo_of_cell(cell).p_width = width;
-       if (isMultiColumn(cell)) {
-               getCellInset(cell).setAutoBreakRows(flag);
-               return true;
-       }
-       return false;
+       getCellInset(cell).setAutoBreakRows(!width.zero());
+       return true;
 }
 
 
@@ -1097,7 +1025,7 @@ bool LyXTabular::calculate_width_of_column_NMC(int column)
        int max = 0;
        for (int i = 0; i < rows_; ++i) {
                int cell = getCellNumber(i, column);
-               bool ismulti = isMultiColumn(cell, true);
+               bool ismulti = isMultiColumnReal(cell);
                if ((!ismulti || column == right_column_of_cell(cell)) &&
                        cell_info[i][column].width_of_cell > max)
                {
@@ -1429,9 +1357,15 @@ void LyXTabular::read(Buffer const & buf, LyXLex & lex)
 }
 
 
-bool LyXTabular::isMultiColumn(int cell, bool real) const
+bool LyXTabular::isMultiColumn(int cell) const
 {
-       return (!real || column_of_cell(cell) != right_column_of_cell(cell)) &&
+       return cellinfo_of_cell(cell).multicolumn != LyXTabular::CELL_NORMAL;
+}
+
+
+bool LyXTabular::isMultiColumnReal(int cell) const
+{
+       return column_of_cell(cell) != right_column_of_cell(cell) &&
                        cellinfo_of_cell(cell).multicolumn != LyXTabular::CELL_NORMAL;
 }
 
@@ -1453,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();
@@ -1961,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;
@@ -2051,17 +1985,17 @@ int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf,
 }
 
 
-bool LyXTabular::isValidRow(int const row) const
+bool LyXTabular::isValidRow(int row) const
 {
        if (!is_long_tabular)
                return true;
-       return (!row_info[row].endhead && !row_info[row].endfirsthead &&
-                       !row_info[row].endfoot && !row_info[row].endlastfoot);
+       return !row_info[row].endhead && !row_info[row].endfirsthead &&
+                       !row_info[row].endfoot && !row_info[row].endlastfoot;
 }
 
 
-int LyXTabular::TeXRow(ostream & os, int const i, Buffer const & buf,
-                      LatexRunParams const & runparams) const
+int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
+                      OutputParams const & runparams) const
 {
        int ret = 0;
        int cell = getCellNumber(i, 0);
@@ -2074,8 +2008,8 @@ int LyXTabular::TeXRow(ostream & os, int const 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{";
@@ -2098,7 +2032,7 @@ int LyXTabular::TeXRow(ostream & os, int const i, Buffer const & buf,
 
 
 int LyXTabular::latex(Buffer const & buf, ostream & os,
-                     LatexRunParams const & runparams) const
+                     OutputParams const & runparams) const
 {
        int ret = 0;
 
@@ -2205,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) {
@@ -2230,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";
@@ -2246,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);
@@ -2288,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;
        }
@@ -2298,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;
 
@@ -2336,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";
@@ -2348,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";
@@ -2363,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";
@@ -2474,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();
@@ -2523,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;
 
@@ -2537,10 +2478,10 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
                        clen[j] = 0;
                        for (int i = 0; i < rows_; ++i) {
                                int cell = getCellNumber(i, j);
-                               if (isMultiColumn(cell, true))
+                               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();
                        }
@@ -2549,10 +2490,10 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
                for (int j = 0; j < columns_; ++j) {
                        for (int i = 0; i < rows_; ++i) {
                                int cell = getCellNumber(i, j);
-                               if (!isMultiColumn(cell, true) || isPartOfMultiColumn(i, j))
+                               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)
@@ -2572,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;
@@ -2590,53 +2532,35 @@ int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth,
 
 InsetText & LyXTabular::getCellInset(int cell) const
 {
-       cur_cell = cell;
        return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
 }
 
 
 InsetText & LyXTabular::getCellInset(int row, int column) const
 {
-       cur_cell = getCellNumber(row, column);
        return cell_info[row][column].inset;
 }
 
 
-int LyXTabular::getCellFromInset(InsetOld const * inset, int maybe_cell) const
+int LyXTabular::getCellFromInset(InsetBase const * inset) const
 {
        // is this inset part of the tabular?
-       if (!inset || inset->owner() != owner_) {
+       if (!inset) {
                lyxerr << "Error: this is not a cell of the tabular!" << endl;
                return -1;
        }
 
-       const int save_cur_cell = cur_cell;
-       int cell = cur_cell;
-       if (&getCellInset(cell) != inset) {
-               cell = maybe_cell;
-               if (cell == -1 || &getCellInset(cell) != inset)
-                       cell = -1;
-       }
-
-       if (cell == -1) {
-               for (cell = getNumberOfCells(); cell >= 0; --cell)
-                       if (&getCellInset(cell) == inset)
-                               break;
-
-               lyxerr[Debug::INSETTEXT]
-                        << "LyXTabular::getCellFromInset: "
-                                   << "cell=" << cell
-                                   << ", cur_cell=" << save_cur_cell
-                                   << ", maybe_cell=" << maybe_cell
-                                   << endl;
-               // We should have found a cell at this point
-               if (cell == -1) {
-                       lyxerr << "LyXTabular::getCellFromInset: "
-                              << "Cell not found!" << endl;
+       for (int cell = 0, n = getNumberOfCells(); cell < n; ++cell)
+               if (&getCellInset(cell) == inset) {
+                       lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: "
+                               << "cell=" << cell << endl;
+                       return cell;
                }
-       }
 
-       return cell;
+       // We should have found a cell at this point
+       lyxerr << "LyXTabular::getCellFromInset: Cell of inset "
+               << inset << " not found!" << endl;
+       return -1;
 }
 
 
@@ -2656,17 +2580,18 @@ void LyXTabular::validate(LaTeXFeatures & features) const
 }
 
 
-void LyXTabular::getLabelList(std::vector<string> & list) const
+void LyXTabular::getLabelList(Buffer const & buffer,
+                             std::vector<string> & list) const
 {
        for (int i = 0; i < rows_; ++i)
                for (int j = 0; j < columns_; ++j)
-                       getCellInset(i, j).getLabelList(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();