The reason for bug 2380 is that awful BufferView cache in InsetText. It does
not get set correctly for table cells, and therefore we get an assert
sooner or later. The patch fixes that by always constructing the cell
insets with a valid BufferView. The other possibility would be to get rid
of the cache, but that requires large changes, so I don't want to do that
now.
The patch has been tested by Simon, and it works. Is it OK for trunk and
1.4?


Georg

Log:
Fix bug 2380:
* src/insets/insettabular.C
        (InsetTabular::hasPasteBuffer):
        (InsetTabular::doDispatch):
        (InsetTabular::insertAsciiString): Construct LyXTabulars with a
        BufferView
* src/tabular.[Ch]
        (cellstruct): Set bv_owner of the text inset
        (LyXTabular::fixCellNums):
        (LyXTabular::appendRow):
        (LyXTabular::deleteRow):
        (LyXTabular::appendColumn):
        (LyXTabular::read): Construct cellstructs with a BufferView
Index: src/insets/insettabular.C
===================================================================
--- src/insets/insettabular.C	(Revision 13407)
+++ src/insets/insettabular.C	(Arbeitskopie)
@@ -167,7 +167,7 @@ bool InsetTabular::hasPasteBuffer() cons
 InsetTabular::InsetTabular(Buffer const & buf, row_type rows,
                            col_type columns)
 	: tabular(buf.params(), max(rows, row_type(1)),
-	  max(columns, col_type(1))), buffer_(&buf), scx_(0)
+	  max(columns, col_type(1)), buf.text().bv()), buffer_(&buf), scx_(0)
 {}
 
 
@@ -693,7 +693,7 @@ void InsetTabular::doDispatch(LCursor & 
 			maxCols = max(cols, maxCols);
 
 			paste_tabular.reset(
-				new LyXTabular(cur.buffer().params(), rows, maxCols));
+				new LyXTabular(cur.buffer().params(), rows, maxCols, &cur.bv()));
 
 			string::size_type op = 0;
 			idx_type cell = 0;
@@ -1876,7 +1876,7 @@ bool InsetTabular::insertAsciiString(Buf
 	row_type row = 0;
 	if (usePaste) {
 		paste_tabular.reset(
-			new LyXTabular(bv.buffer()->params(), rows, maxCols));
+			new LyXTabular(bv.buffer()->params(), rows, maxCols, &bv));
 		loctab = paste_tabular.get();
 		cols = 0;
 	} else {
Index: src/tabular.C
===================================================================
--- src/tabular.C	(Revision 13407)
+++ src/tabular.C	(Arbeitskopie)
@@ -313,7 +313,8 @@ void l_getline(istream & is, string & st
 
 /// Define a few methods for the inner structs
 
-LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
+LyXTabular::cellstruct::cellstruct(BufferParams const & bp,
+		BufferView const * bv)
 	: cellno(0),
 	  width_of_cell(0),
 	  multicolumn(LyXTabular::CELL_NORMAL),
@@ -326,7 +327,9 @@ LyXTabular::cellstruct::cellstruct(Buffe
 	  usebox(BOX_NONE),
 	  rotate(false),
 	  inset(new InsetText(bp))
-{}
+{
+	inset->setViewCache(bv);
+}
 
 
 LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
@@ -406,21 +409,21 @@ LyXTabular::ltType::ltType()
 
 
 LyXTabular::LyXTabular(BufferParams const & bp, row_type rows_arg,
-                       col_type columns_arg)
+                       col_type columns_arg, BufferView const * bv)
 {
-	init(bp, rows_arg, columns_arg);
+	init(bp, rows_arg, columns_arg, bv);
 }
 
 
 // activates all lines and sets all widths to 0
 void LyXTabular::init(BufferParams const & bp, row_type rows_arg,
-                      col_type columns_arg)
+                      col_type columns_arg, BufferView const * bv)
 {
 	rows_    = rows_arg;
 	columns_ = columns_arg;
 	row_info = row_vector(rows_);
 	column_info = column_vector(columns_);
-	cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
+	cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp, bv)));
 	row_info.reserve(10);
 	column_info.reserve(10);
 	cell_info.reserve(100);
@@ -454,6 +457,7 @@ void LyXTabular::fixCellNums()
 
 void LyXTabular::appendRow(BufferParams const & bp, idx_type const cell)
 {
+	BufferView const * const bv = getCellInset(0)->getText(0)->bv();
 	++rows_;
 
 	row_type const row = row_of_cell(cell);
@@ -467,7 +471,7 @@ void LyXTabular::appendRow(BufferParams 
 	for (row_type i = 0; i < rows_ - 1; ++i)
 		swap(cell_info[i], old[i]);
 
-	cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp)));
+	cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp, bv)));
 
 	for (row_type i = 0; i <= row; ++i)
 		swap(cell_info[i], old[i]);
@@ -497,6 +501,7 @@ void LyXTabular::deleteRow(row_type cons
 
 void LyXTabular::appendColumn(BufferParams const & bp, idx_type const cell)
 {
+	BufferView const * const bv = getCellInset(0)->getText(0)->bv();
 	++columns_;
 
 	col_type const column = column_of_cell(cell);
@@ -506,7 +511,7 @@ void LyXTabular::appendColumn(BufferPara
 	column_info[column + 1] = column_info[column];
 
 	for (row_type i = 0; i < rows_; ++i) {
-		cell_info[i].insert(cell_info[i].begin() + column + 1, cellstruct(bp));
+		cell_info[i].insert(cell_info[i].begin() + column + 1, cellstruct(bp, bv));
 
 		// care about multicolumns
 		if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
@@ -1273,7 +1278,7 @@ void LyXTabular::read(Buffer const & buf
 	int columns_arg;
 	if (!getTokenValue(line, "columns", columns_arg))
 		return;
-	init(buf.params(), rows_arg, columns_arg);
+	init(buf.params(), rows_arg, columns_arg, buf.text().bv());
 	l_getline(is, line);
 	if (!prefixIs(line, "<features")) {
 		lyxerr << "Wrong tabular format (expected <features ...> got"
Index: src/tabular.h
===================================================================
--- src/tabular.h	(Revision 13407)
+++ src/tabular.h	(Arbeitskopie)
@@ -23,6 +23,7 @@
 #include <iosfwd>
 #include <vector>
 
+class BufferView;
 class InsetTabular;
 class LCursor;
 class OutputParams;
@@ -185,7 +186,7 @@ public:
 
 	/// constructor
 	LyXTabular(BufferParams const &, col_type columns_arg,
-	           row_type rows_arg);
+	           row_type rows_arg, BufferView const *);
 
 	/// Returns true if there is a topline, returns false if not
 	bool topLine(idx_type cell, bool onlycolumn = false) const;
@@ -403,7 +404,7 @@ public:
 	class cellstruct {
 	public:
 		///
-		cellstruct(BufferParams const &);
+		cellstruct(BufferParams const &, BufferView const *);
 		///
 		cellstruct(cellstruct const &);
 		///
@@ -531,7 +532,7 @@ public:
 
 	///
 	void init(BufferParams const &, row_type rows_arg,
-	          col_type columns_arg);
+	          col_type columns_arg, BufferView const *);
 	///
 	void set_row_column_number_info();
 	/// Returns true if a complete update is necessary, otherwise false

Reply via email to