]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
fix nullstream also in pch files
[lyx.git] / src / tabular.C
index 334e2151ef8c066ea21b7e5cccc3451d5eeb57a0..212431cbb853936f54030a89bc002fff06bd89e2 100644 (file)
 
 #include "buffer.h"
 #include "bufferparams.h"
+#include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
 #include "LaTeXFeatures.h"
 #include "lyxlex.h"
 #include "outputparams.h"
 #include "paragraph.h"
+#include "paragraph_funcs.h"
 
 #include "insets/insettabular.h"
 
@@ -515,7 +518,7 @@ 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(false);
+               cell_info[i][column + 1].inset->clear();
                if (bp.tracking_changes)
                        cell_info[i][column + 1].inset->markNew(true);
        }
@@ -872,7 +875,38 @@ void LyXTabular::setVAlignment(idx_type cell, VAlignment align,
 }
 
 
-void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width)
+namespace {
+
+/**
+ * Allow line and paragraph breaks for fixed width cells or disallow them,
+ * merge cell paragraphs and reset layout to standard for variable width
+ * cells.
+ */
+void toggleFixedWidth(LCursor & cur, InsetText * inset, bool fixedWidth)
+{
+       inset->setAutoBreakRows(fixedWidth);
+       if (fixedWidth)
+               return;
+
+       // merge all paragraphs to one
+       BufferParams const & bp =
+               inset->getText(0)->bv_owner->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,
+                       bp.getLyXTextClass().defaultLayoutName());
+       cur.pop();
+}
+
+}
+
+
+void LyXTabular::setColumnPWidth(LCursor & cur, idx_type cell,
+               LyXLength const & width)
 {
        col_type const j = column_of_cell(cell);
 
@@ -880,18 +914,32 @@ void LyXTabular::setColumnPWidth(idx_type cell, LyXLength const & width)
        for (row_type i = 0; i < rows_; ++i) {
                idx_type const cell = getCellNumber(i, j);
                // because of multicolumns
-               getCellInset(cell)->setAutoBreakRows(!getPWidth(cell).zero());
+               toggleFixedWidth(cur, getCellInset(cell).get(),
+                                !getPWidth(cell).zero());
        }
+       // cur paragraph can become invalid after paragraphs were merged
+       if (cur.pit() > cur.lastpit())
+               cur.pit() = cur.lastpit();
+       // cur position can become invalid after newlines were removed
+       if (cur.pos() > cur.lastpos())
+               cur.pos() = cur.lastpos();
 }
 
 
-bool LyXTabular::setMColumnPWidth(idx_type cell, LyXLength const & width)
+bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell,
+               LyXLength const & width)
 {
        if (!isMultiColumn(cell))
                return false;
 
        cellinfo_of_cell(cell).p_width = width;
-       getCellInset(cell)->setAutoBreakRows(!width.zero());
+       toggleFixedWidth(cur, getCellInset(cell).get(), !width.zero());
+       // cur paragraph can become invalid after paragraphs were merged
+       if (cur.pit() > cur.lastpit())
+               cur.pit() = cur.lastpit();
+       // cur position can become invalid after newlines were removed
+       if (cur.pos() > cur.lastpos())
+               cur.pos() = cur.lastpos();
        return true;
 }
 
@@ -1350,7 +1398,7 @@ void LyXTabular::setMultiColumn(Buffer * buffer, idx_type cell,
                cellstruct & cs1 = cellinfo_of_cell(cell + i);
                cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
                cs.inset->appendParagraphs(buffer, cs1.inset->paragraphs());
-               cs1.inset->clear(false);
+               cs1.inset->clear();
        }
        set_row_column_number_info();
 }
@@ -2559,15 +2607,6 @@ void LyXTabular::validate(LaTeXFeatures & features) const
 }
 
 
-void LyXTabular::getLabelList(Buffer const & buffer,
-                             std::vector<string> & list) const
-{
-       for (row_type i = 0; i < rows_; ++i)
-               for (col_type j = 0; j < columns_; ++j)
-                       getCellInset(i, j)->getLabelList(buffer, list);
-}
-
-
 LyXTabular::BoxType LyXTabular::useParbox(idx_type cell) const
 {
        ParagraphList const & parlist = getCellInset(cell)->paragraphs();