]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
ws changes only
[lyx.git] / src / tabular.C
index 4888d9c4f13cb7cbf9e6fd5c37145e4c36532a5d..476e36138616228e8b17291bd6f62f291074dd69 100644 (file)
@@ -48,6 +48,7 @@ using std::istream;
 using std::ostream;
 using std::ostringstream;
 using std::vector;
+using std::string;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::strlen;
@@ -303,8 +304,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;
@@ -361,12 +362,27 @@ LyXTabular::LyXTabular(BufferParams const & bp, int rows_arg, int columns_arg)
 // activates all lines and sets all widths to 0
 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;
+}
+
 
+void LyXTabular::fixCellNums()
+{
        int cellno = 0;
        for (int i = 0; i < rows_; ++i) {
                for (int j = 0; j < columns_; ++j) {
@@ -375,22 +391,19 @@ void LyXTabular::init(BufferParams const & bp, int rows_arg, int columns_arg)
                }
                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;
-       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)
+       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);
+               }
+       }
 }
 
 
@@ -405,30 +418,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 old(rows_ - 1);
+       for (int i = 0; i < rows_ - 1; ++i)
+               swap(cell_info[i], old[i]);
 
-       cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
-                                                             cellstruct(bp)));
+       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
+       set_row_column_number_info();
 }
 
 
@@ -441,6 +446,7 @@ void LyXTabular::deleteRow(int row)
        row_info.erase(row_info.begin() + row);
        cell_info.erase(cell_info.begin() + row);
        --rows_;
+       fixCellNums();
 }
 
 
@@ -448,8 +454,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());
@@ -457,27 +461,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);
        }
+       fixCellNums();
 }
 
 
@@ -491,10 +491,11 @@ void LyXTabular::deleteColumn(int column)
        for (int i = 0; i < rows_; ++i)
                cell_info[i].erase(cell_info[i].begin() + column);
        --columns_;
+       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) {
@@ -531,14 +532,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());
                }
@@ -647,7 +640,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;
 }