This is along the way to dealing with the InsetTableCell issue. But even this little bit causes LyX to crash when you try to make a table. Debugging shows that the problem is in Tabular::init(), at this line: cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf))); The first bit, cell_vector(columns_arg, CellData(buf)), actually works OK (separate it out); it's the next call that fails, with a complaint that CellData::inset is null in the CellData copy constructor, here:

I can't myself see how anything in this patch could cause this problem.
     inset(dynamic_cast<InsetTableCell*>(cs.inset->clone()))
It's cs.inset---the argument to CellData(CellData)---that's apparently uninitialized. But how can it be? The only CellData constructor that's available initializes cs.inset.

???

rh

Index: insets/InsetTabular.h
===================================================================
--- insets/InsetTabular.h	(revision 23855)
+++ insets/InsetTabular.h	(working copy)
@@ -49,14 +49,15 @@
 
 namespace lyx {
 
-class FuncStatus;
-class Lexer;
-class BufferView;
 class Buffer;
 class BufferParams;
-class Paragraph;
+class BufferView;
 class CompletionList;
 class CursorSlice;
+class InsetTableCell;
+class FuncStatus;
+class Lexer;
+class Paragraph;
 
 namespace frontend { class Painter; }
 
@@ -443,13 +444,13 @@
 	///
 	// end longtable support
 	///
-	boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
+	boost::shared_ptr<InsetTableCell> getCellInset(idx_type cell) const;
 	///
-	boost::shared_ptr<InsetText> getCellInset(row_type row,
+	boost::shared_ptr<InsetTableCell> getCellInset(row_type row,
 						  col_type column) const;
 	///
 	void setCellInset(row_type row, col_type column,
-			  boost::shared_ptr<InsetText>) const;
+			  boost::shared_ptr<InsetTableCell>) const;
 	/// Search for \param inset in the tabular, with the
 	///
 	idx_type getCellFromInset(Inset const * inset) const;
@@ -499,7 +500,9 @@
 		///
 		Length p_width; // this is only set for multicolumn!!!
 		///
-		boost::shared_ptr<InsetText> inset;
+		boost::shared_ptr<InsetTableCell> inset;
+	private:
+		CellData();
 	};
 	CellData & cellinfo_of_cell(idx_type cell) const;
 	///
@@ -722,9 +725,9 @@
 	/// number of cells
 	size_t nargs() const { return tabular.cellCount(); }
 	///
-	boost::shared_ptr<InsetText const> cell(idx_type) const;
+	boost::shared_ptr<InsetTableCell const> cell(idx_type) const;
 	///
-	boost::shared_ptr<InsetText> cell(idx_type);
+	boost::shared_ptr<InsetTableCell> cell(idx_type);
 	///
 	Text * getText(int) const;
 
Index: insets/InsetTableCell.cpp
===================================================================
--- insets/InsetTableCell.cpp	(revision 0)
+++ insets/InsetTableCell.cpp	(revision 0)
@@ -0,0 +1,19 @@
+/**
+ * \file InsetTableCell.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetTableCell.h"
+
+#include "InsetTabular.h"
+
+namespace lyx {
+
+} // namespace lyx
Index: insets/InsetTabular.cpp
===================================================================
--- insets/InsetTabular.cpp	(revision 23855)
+++ insets/InsetTabular.cpp	(working copy)
@@ -31,6 +31,7 @@
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetTableCell.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
@@ -482,7 +483,7 @@
 	  right_line(false),
 	  usebox(BOX_NONE),
 	  rotate(false),
-	  inset(new InsetText(buf))
+	  inset(new InsetTableCell(buf))
 {
 	inset->setBuffer(const_cast<Buffer &>(buf));
 	inset->paragraphs().back().setLayout(buf.params().documentClass().emptyLayout());
@@ -503,7 +504,7 @@
 	  rotate(cs.rotate),
 	  align_special(cs.align_special),
 	  p_width(cs.p_width),
-	  inset(dynamic_cast<InsetText*>(cs.inset->clone()))
+	  inset(dynamic_cast<InsetTableCell*>(cs.inset->clone()))
 {}
 
 
@@ -1018,7 +1019,7 @@
  * merge cell paragraphs and reset layout to standard for variable width
  * cells.
  */
-void toggleFixedWidth(Cursor & cur, InsetText * inset, bool fixedWidth)
+void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
 {
 	inset->setAutoBreakRows(fixedWidth);
 	if (fixedWidth)
@@ -2226,7 +2227,7 @@
 		if (isPartOfMultiColumn(i, j))
 			continue;
 		ret += TeXCellPreamble(os, cell);
-		shared_ptr<InsetText> inset = getCellInset(cell);
+		shared_ptr<InsetTableCell> inset = getCellInset(cell);
 
 		Paragraph const & par = inset->paragraphs().front();
 		bool rtl = par.isRTL(buffer().params())
@@ -2743,13 +2744,13 @@
 }
 
 
-shared_ptr<InsetText> Tabular::getCellInset(idx_type cell) const
+shared_ptr<InsetTableCell> Tabular::getCellInset(idx_type cell) const
 {
 	return cell_info[cellRow(cell)][cellColumn(cell)].inset;
 }
 
 
-shared_ptr<InsetText> Tabular::getCellInset(row_type row,
+shared_ptr<InsetTableCell> Tabular::getCellInset(row_type row,
 					       col_type column) const
 {
 	return cell_info[row][column].inset;
@@ -2757,7 +2758,7 @@
 
 
 void Tabular::setCellInset(row_type row, col_type column,
-			      shared_ptr<InsetText> ins) const
+			      shared_ptr<InsetTableCell> ins) const
 {
 	cell_info[row][column].inset = ins;
 }
@@ -3222,7 +3223,7 @@
 		    && tablemode(bvcur)) 
 			;
 		else
-			// Let InsetText do it
+			// Let InsetTableCell do it
 			cell(cur.idx())->dispatch(cur, cmd);
 		break;
 	}
@@ -3871,13 +3872,13 @@
 }
 
 
-shared_ptr<InsetText const> InsetTabular::cell(idx_type idx) const
+shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
 {
 	return tabular.getCellInset(idx);
 }
 
 
-shared_ptr<InsetText> InsetTabular::cell(idx_type idx)
+shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
 {
 	return tabular.getCellInset(idx);
 }
@@ -4593,8 +4594,8 @@
 				--c1;
 				continue;
 			}
-			shared_ptr<InsetText> inset(
-				new InsetText(*paste_tabular->getCellInset(r1, c1)));
+			shared_ptr<InsetTableCell> inset(
+				new InsetTableCell(*paste_tabular->getCellInset(r1, c1)));
 			tabular.setCellInset(r2, c2, inset);
 			// FIXME: change tracking (MG)
 			inset->setChange(Change(cur.buffer().params().trackChanges ?
@@ -4616,7 +4617,7 @@
 	getSelection(cur, rs, re, cs, ce);
 	for (row_type i = rs; i <= re; ++i) {
 		for (col_type j = cs; j <= ce; ++j) {
-			shared_ptr<InsetText> t
+			shared_ptr<InsetTableCell> t
 				= cell(tabular.cellIndex(i, j));
 			if (cur.buffer().params().trackChanges)
 				// FIXME: Change tracking (MG)
@@ -4765,7 +4766,7 @@
 		case '\t':
 			// we can only set this if we are not too far right
 			if (cols < columns) {
-				shared_ptr<InsetText> inset = loctab->getCellInset(cell);
+				shared_ptr<InsetTableCell> inset = loctab->getCellInset(cell);
 				Font const font = bv.textMetrics(&inset->text_).
 					displayFont(0, 0);
 				inset->setText(buf.substr(op, p - op), font,
@@ -4777,7 +4778,7 @@
 		case '\n':
 			// we can only set this if we are not too far right
 			if (cols < columns) {
-				shared_ptr<InsetText> inset = tabular.getCellInset(cell);
+				shared_ptr<InsetTableCell> inset = tabular.getCellInset(cell);
 				Font const font = bv.textMetrics(&inset->text_).
 					displayFont(0, 0);
 				inset->setText(buf.substr(op, p - op), font,
@@ -4794,7 +4795,7 @@
 	}
 	// check for the last cell if there is no trailing '\n'
 	if (cell < cells && op < len) {
-		shared_ptr<InsetText> inset = loctab->getCellInset(cell);
+		shared_ptr<InsetTableCell> inset = loctab->getCellInset(cell);
 		Font const font = bv.textMetrics(&inset->text_).displayFont(0, 0);
 		inset->setText(buf.substr(op, len - op), font,
 			buffer().params().trackChanges);
Index: insets/InsetTableCell.h
===================================================================
--- insets/InsetTableCell.h	(revision 0)
+++ insets/InsetTableCell.h	(revision 0)
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+/**
+ * \file InsetTableCell.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef INSETTABLECELL_H
+#define INSETTABLECELL_H
+
+#include "InsetTabular.h"
+#include "InsetText.h"
+#include <boost/assert.hpp>
+
+namespace lyx {
+
+
+///
+class InsetTableCell : public InsetText {
+public:
+	///
+	explicit InsetTableCell(Buffer const & buf)
+		: InsetText(buf)
+	{}
+	///
+	InsetTableCell(InsetTableCell const & rhs)
+		: InsetText(rhs) 
+	{}
+	///
+	virtual InsetCode lyxCode() const { return CELL_CODE; }
+private:
+	InsetTableCell();
+};
+
+} // namespace lyx
+
+#endif
Index: insets/InsetCode.h
===================================================================
--- insets/InsetCode.h	(revision 23855)
+++ insets/InsetCode.h	(working copy)
@@ -112,6 +112,8 @@
 	INFO_CODE, // 45
 	///
 	COLLAPSABLE_CODE,
+	///
+ 	CELL_CODE,
 #if 0
 	///
 	THEOREM_CODE,
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 23855)
+++ Makefile.am	(working copy)
@@ -522,6 +522,7 @@
 	insets/InsetRef.cpp \
 	insets/InsetSpace.cpp \
 	insets/InsetSpecialChar.cpp \
+	insets/InsetTableCell.cpp \
 	insets/InsetTabular.cpp \
 	insets/InsetText.cpp \
 	insets/InsetTOC.cpp \
@@ -577,6 +578,7 @@
 	insets/InsetRef.h \
 	insets/InsetSpace.h \
 	insets/InsetSpecialChar.h \
+	insets/InsetTableCell.h \
 	insets/InsetTabular.h \
 	insets/InsetText.h \
 	insets/InsetTOC.h \
Index: DocIterator.cpp
===================================================================
--- DocIterator.cpp	(revision 23855)
+++ DocIterator.cpp	(working copy)
@@ -22,6 +22,7 @@
 #include "mathed/InsetMath.h"
 
 #include "insets/InsetTabular.h"
+#include "insets/InsetTableCell.h"
 
 #include "support/debug.h"
 

Reply via email to