]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Unify the parameters of the [append/copy][row/column] family
[lyx.git] / src / insets / InsetTabular.cpp
index dca6a18c3d021f92c48e63c5d2c5283a2adb7de9..fec2fa5c5f22d0d82d038abf2bf6a3ad1289128b 100644 (file)
@@ -700,10 +700,8 @@ void Tabular::init(Buffer * buf, row_type rows_arg,
 }
 
 
-void Tabular::appendRow(idx_type const cell)
+void Tabular::appendRow(row_type row)
 {
-       row_type const row = cellRow(cell);
-
        row_info.insert(row_info.begin() + row + 1, RowData());
        row_info[row + 1] = row_info[row];
 
@@ -759,21 +757,42 @@ void Tabular::deleteRow(row_type const row)
 
 void Tabular::copyRow(row_type const row)
 {
-       row_info.insert(row_info.begin() + row, row_info[row]);
-       cell_info.insert(cell_info.begin() + row, cell_info[row]);
-
-       if (buffer().params().trackChanges)
-               for (col_type c = 0; c < ncols(); ++c)
+       row_info.insert(row_info.begin() + row + 1, RowData(row_info[row]));
+       cell_info.insert(cell_info.begin() + row + 1, 
+               cell_vector(0, CellData(buffer_)));
+       
+       for (col_type c = 0; c < ncols(); ++c) {
+               cell_info[row + 1].insert(cell_info[row + 1].begin() + c,
+                       CellData(cell_info[row][c]));
+               if (buffer().params().trackChanges)
                        cell_info[row + 1][c].inset->setChange(Change(Change::INSERTED));
-
+               if (cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW)
+                       cell_info[row + 1][c].multirow = CELL_PART_OF_MULTIROW;
+       }
+       
        updateIndexes();
+       for (col_type c = 0; c < ncols(); ++c) {
+               if (isPartOfMultiRow(row, c))
+                       continue;
+               // inherit line settings
+               idx_type const i = cellIndex(row + 1, c);
+               idx_type const j = cellIndex(row, c);
+               setLeftLine(i, leftLine(j));
+               setRightLine(i, rightLine(j));
+               setTopLine(i, topLine(j));
+               if (topLine(j) && bottomLine(j)) {
+                       setBottomLine(i, true);
+                       setBottomLine(j, false);
+               }
+               // mark track changes
+               if (buffer().params().trackChanges)
+                       cellInfo(i).inset->setChange(Change(Change::INSERTED));
+       }
 }
 
 
-void Tabular::appendColumn(idx_type const cell)
-{
-       col_type const c = cellColumn(cell);
-       
+void Tabular::appendColumn(col_type c)
+{      
        column_info.insert(column_info.begin() + c + 1, ColumnData());
        column_info[c + 1] = column_info[c];
 
@@ -826,14 +845,30 @@ void Tabular::deleteColumn(col_type const col)
 void Tabular::copyColumn(col_type const col)
 {
        BufferParams const & bp = buffer().params();
-       column_info.insert(column_info.begin() + col, column_info[col]);
+       column_info.insert(column_info.begin() + col + 1, ColumnData(column_info[col]));
 
        for (row_type r = 0; r < nrows(); ++r) {
-               cell_info[r].insert(cell_info[r].begin() + col, cell_info[r][col]);
+               cell_info[r].insert(cell_info[r].begin() + col + 1, CellData(cell_info[r][col]));
                if (bp.trackChanges)
                        cell_info[r][col + 1].inset->setChange(Change(Change::INSERTED));
+               if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
+                       cell_info[r][col + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
        }
        updateIndexes();
+       for (row_type r = 0; r < nrows(); ++r) {
+               // inherit line settings
+               idx_type const i = cellIndex(r, col + 1);
+               idx_type const j = cellIndex(r, col);
+               setBottomLine(i, bottomLine(j));
+               setTopLine(i, topLine(j));
+               setLeftLine(i, leftLine(j));
+               if (rightLine(j) && rightLine(j)) {
+                       setRightLine(i, true);
+                       setRightLine(j, false);
+               }
+               if (buffer().params().trackChanges)
+                       cellInfo(i).inset->setChange(Change(Change::INSERTED));
+       }
 }
 
 
@@ -5295,12 +5330,12 @@ void InsetTabular::tabularFeatures(Cursor & cur,
 
        case Tabular::APPEND_ROW:
                // append the row into the tabular
-               tabular.appendRow(cur.idx());
+               tabular.appendRow(row);
                break;
 
        case Tabular::APPEND_COLUMN:
                // append the column into the tabular
-               tabular.appendColumn(cur.idx());
+               tabular.appendColumn(column);
                cur.idx() = tabular.cellIndex(row, column);
                break;