Bo Peng wrote:

I think we only need to support official releases, but if you insist,
I will do something with lyx2lyx.

Attached please find an updated patch with lyx2lyx support for RC1.

OK to apply?

if there is going to be a fileformat change afterall, then it would be nice to have cline support...
Index: src/frontends/controllers/ControlTabular.cpp
===================================================================
--- src/frontends/controllers/ControlTabular.cpp	(revision 18739)
+++ src/frontends/controllers/ControlTabular.cpp	(working copy)
@@ -83,24 +83,6 @@
 }
 
 
-void ControlTabular::toggleTopLine()
-{
-	if (tabular().isMultiColumn(getActiveCell()))
-		set(Tabular::M_TOGGLE_LINE_TOP);
-	else
-		set(Tabular::TOGGLE_LINE_TOP);
-}
-
-
-void ControlTabular::toggleBottomLine()
-{
-	if (tabular().isMultiColumn(getActiveCell()))
-		set(Tabular::M_TOGGLE_LINE_BOTTOM);
-	else
-		set(Tabular::TOGGLE_LINE_BOTTOM);
-}
-
-
 void ControlTabular::toggleLeftLine()
 {
 	if (tabular().isMultiColumn(getActiveCell()))
Index: src/frontends/controllers/ControlTabular.h
===================================================================
--- src/frontends/controllers/ControlTabular.h	(revision 18739)
+++ src/frontends/controllers/ControlTabular.h	(working copy)
@@ -47,8 +47,6 @@
 	void set(Tabular::Feature, std::string const & arg = std::string());
 
 	/// borders
-	void toggleTopLine();
-	void toggleBottomLine();
 	void toggleLeftLine();
 	void toggleRightLine();
 
Index: src/frontends/qt4/QTabular.cpp
===================================================================
--- src/frontends/qt4/QTabular.cpp	(revision 18739)
+++ src/frontends/qt4/QTabular.cpp	(working copy)
@@ -257,14 +257,14 @@
 
 void QTabularDialog::topBorder_changed()
 {
-	form_->controller().toggleTopLine();
+	form_->controller().set(Tabular::TOGGLE_LINE_TOP);
 	form_->changed();
 }
 
 
 void QTabularDialog::bottomBorder_changed()
 {
-	form_->controller().toggleBottomLine();
+	form_->controller().set(Tabular::TOGGLE_LINE_BOTTOM);
 	form_->changed();
 }
 
@@ -598,8 +598,8 @@
 	if (!isMulticolumnCell) {
 		dialog_->borders->setLeftEnabled(true);
 		dialog_->borders->setRightEnabled(true);
-		dialog_->borders->setTop(tabular.topLine(cell, true));
-		dialog_->borders->setBottom(tabular.bottomLine(cell, true));
+		dialog_->borders->setTop(tabular.topLine(cell));
+		dialog_->borders->setBottom(tabular.bottomLine(cell));
 		dialog_->borders->setLeft(tabular.leftLine(cell, true));
 		dialog_->borders->setRight(tabular.rightLine(cell, true));
 		// repaint the setborder widget
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp	(revision 18739)
+++ src/insets/InsetTabular.cpp	(working copy)
@@ -132,8 +132,6 @@
 	{ Tabular::VALIGN_TOP, "valign-top" },
 	{ Tabular::VALIGN_BOTTOM, "valign-bottom" },
 	{ Tabular::VALIGN_MIDDLE, "valign-middle" },
-	{ Tabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
-	{ Tabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
 	{ Tabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
 	{ Tabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
 	{ Tabular::M_ALIGN_LEFT, "m-align-left" },
@@ -490,9 +488,9 @@
 	  multicolumn(Tabular::CELL_NORMAL),
 	  alignment(LYX_ALIGN_CENTER),
 	  valignment(LYX_VALIGN_TOP),
-	  top_line(true),
+	  top_line(false),
 	  bottom_line(false),
-	  left_line(true),
+	  left_line(false),
 	  right_line(false),
 	  usebox(BOX_NONE),
 	  rotate(false),
@@ -549,7 +547,7 @@
 Tabular::rowstruct::rowstruct()
 	: ascent_of_row(0),
 	  descent_of_row(0),
-	  top_line(true),
+	  top_line(false),
 	  bottom_line(false),
 	  top_space_default(false),
 	  bottom_space_default(false),
@@ -565,7 +563,7 @@
 Tabular::columnstruct::columnstruct()
 	: alignment(LYX_ALIGN_CENTER),
 	  valignment(LYX_VALIGN_TOP),
-	  left_line(true),
+	  left_line(false),
 	  right_line(false),
 	  width_of_column(0)
 {
@@ -599,14 +597,21 @@
 	column_info.reserve(10);
 	cell_info.reserve(100);
 	fixCellNums();
-	for (row_type 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;
 	use_booktabs = false;
+	// set silly default lyx tabular lines
+	row_info.front().bottom_line = true;
+	row_info.back().bottom_line = true;
+	column_info.back().right_line = true;
+	for (row_type i = 0; i < rows_; ++i) {
+		row_info[i].top_line = true;
+		for (col_type j = 0; j < columns_; ++j) {
+			column_info[j].left_line = true;
+			cell_info[i][j].top_line = row_info[i].top_line;
+			cell_info[i][j].bottom_line = row_info[i].bottom_line;
+		}
+	}
 }
 
 
@@ -620,7 +625,6 @@
 			cell_info[i][j].inset->setDrawFrame(false);
 			cell_info[i][j].cellno = cellno++;
 		}
-		cell_info[i].back().right_line = true;
 	}
 
 	set_row_column_number_info();
@@ -813,21 +817,21 @@
 }
 
 
-bool Tabular::topLine(idx_type const cell, bool const wholerow) const
+bool Tabular::topLine(idx_type const cell) const
 {
-	if (!wholerow && isMultiColumn(cell) &&
-	    !(use_booktabs && row_of_cell(cell) == 0))
-		return cellinfo_of_cell(cell).top_line;
-	return row_info[row_of_cell(cell)].top_line;
+	if (use_booktabs && row_of_cell(cell) == 0)
+		return row_info[row_of_cell(cell)].top_line;
+
+	return cellinfo_of_cell(cell).top_line;
 }
 
 
-bool Tabular::bottomLine(idx_type const cell, bool wholerow) const
+bool Tabular::bottomLine(idx_type const cell) const
 {
-	if (!wholerow && isMultiColumn(cell) &&
-	    !(use_booktabs && isLastRow(cell)))
-		return cellinfo_of_cell(cell).bottom_line;
-	return row_info[row_of_cell(cell)].bottom_line;
+	if (use_booktabs && isLastRow(cell))
+		return row_info[row_of_cell(cell)].bottom_line;
+
+	return cellinfo_of_cell(cell).bottom_line;
 }
 
 
@@ -863,10 +867,7 @@
 			   && cell_info[row][column].multicolumn
 			   == Tabular::CELL_PART_OF_MULTICOLUMN)
 			--column;
-		if (cell_info[row][column].multicolumn == Tabular::CELL_NORMAL)
-			return row_info[row].bottom_line;
-		else
-			return cell_info[row][column].bottom_line;
+		return cell_info[row][column].bottom_line;
 	}
 	return false;
 }
@@ -899,31 +900,27 @@
 	if (!row || row >= rows_)
 		return 0;
 
-	bool top = true;
-	bool bottom = true;
+	bool bottomfull = true;
+	for (col_type column = 0; bottomfull && column < columns_; ++column)
+		bottomfull = cell_info[row - 1][column].bottom_line;
 
-	for (col_type column = 0; column < columns_ && bottom; ++column) {
-		switch (cell_info[row - 1][column].multicolumn) {
-		case Tabular::CELL_BEGIN_OF_MULTICOLUMN:
-			bottom = cell_info[row - 1][column].bottom_line;
-			break;
-		case Tabular::CELL_NORMAL:
-			bottom = row_info[row - 1].bottom_line;
-		}
+	bool topfull = true;
+	for (col_type column = 0; topfull && column < columns_; ++column)
+		topfull = cell_info[row][column].top_line;
+
+	bool bottomempty = true;
+	bool topempty = true;
+	if (use_booktabs) {
+		for (col_type column = 0; bottomempty && column < columns_; ++column)
+			bottomempty = !cell_info[row - 1][column].bottom_line;
+		for (col_type column = 0; topempty && column < columns_; ++column)
+			topempty = !cell_info[row][column].top_line;
 	}
-	for (col_type column = 0; column < columns_ && top; ++column) {
-		switch (cell_info[row][column].multicolumn) {
-		case Tabular::CELL_BEGIN_OF_MULTICOLUMN:
-			top = cell_info[row][column].top_line;
-			break;
-		case Tabular::CELL_NORMAL:
-			top = row_info[row].top_line;
-		}
-	}
+
 	int const interline_space = row_info[row - 1].interline_space_default ?
 		default_line_space :
 		row_info[row - 1].interline_space.inPixels(width_of_tabular);
-	if (top && bottom)
+	if ((topfull && bottomfull) || (use_booktabs && (!bottomempty && !topempty)))
 		return interline_space + WIDTH_OF_LINE;
 	return interline_space;
 }
@@ -1164,22 +1161,57 @@
 }
 
 
-void Tabular::setTopLine(idx_type cell, bool line, bool wholerow)
+void Tabular::setTopLine(idx_type cell, bool line)
 {
 	row_type const row = row_of_cell(cell);
-	if (wholerow || !isMultiColumn(cell))
-		row_info[row].top_line = line;
-	else
-		cellinfo_of_cell(cell).top_line = line;
+	if (use_booktabs && row == 0)
+		return;
+
+	cellinfo_of_cell(cell).top_line = line;
+
+	col_type col = column_of_cell(cell);
+	if (cell_info[row][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
+		++col;
+		while (cell_info[row][col].multicolumn == CELL_PART_OF_MULTICOLUMN) {
+			cell_info[row][col].top_line = line;
+			++col;
+		}
+	}
+		
+	idx_type const i0 = getFirstCellInRow(row);
+	idx_type const i1 = getLastCellInRow(row);
+	bool rowset = true;
+	for (idx_type j = i0; rowset && j <= i1; ++j)
+		rowset = cellinfo_of_cell(j).top_line;
+
+	row_info[row].top_line = rowset;
 }
 
 
-void Tabular::setBottomLine(idx_type cell, bool line, bool wholerow)
+void Tabular::setBottomLine(idx_type cell, bool line)
 {
-	if (wholerow || !isMultiColumn(cell))
-		row_info[row_of_cell(cell)].bottom_line = line;
-	else
-		cellinfo_of_cell(cell).bottom_line = line;
+	row_type const row = row_of_cell(cell);
+	if (use_booktabs && row == rows_ - 1)
+		return;
+
+	cellinfo_of_cell(cell).bottom_line = line;
+
+	col_type col = column_of_cell(cell);
+	if (cell_info[row][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
+		++col;
+		while (cell_info[row][col].multicolumn == CELL_PART_OF_MULTICOLUMN) {
+			cell_info[row][col].bottom_line = line;
+			++col;
+		}
+	}
+
+	idx_type const i0 = getFirstCellInRow(row);
+	idx_type const i1 = getLastCellInRow(row);
+	bool rowset = true;
+	for (idx_type j = i0; rowset && j <= i1; ++j)
+		rowset = cellinfo_of_cell(j).bottom_line;
+
+	row_info[row].bottom_line = rowset;
 }
 
 
@@ -1612,8 +1644,6 @@
 	cellstruct & cs = cellinfo_of_cell(cell);
 	cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
 	cs.alignment = column_info[column_of_cell(cell)].alignment;
-	cs.top_line = row_info[row_of_cell(cell)].top_line;
-	cs.bottom_line = row_info[row_of_cell(cell)].bottom_line;
 	cs.left_line = column_info[column_of_cell(cell)].left_line;
 	cs.right_line = column_info[column_of_cell(cell+number-1)].right_line;
 	for (idx_type i = 1; i < number; ++i) {
@@ -1651,6 +1681,8 @@
 
 	if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
 		cell_info[row][column].multicolumn = CELL_NORMAL;
+		cell_info[row][column].left_line = false;
+		cell_info[row][column].right_line = false;
 		++column;
 		while (column < columns_ &&
 			   cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
@@ -1668,6 +1700,22 @@
 void Tabular::setBookTabs(bool what)
 {
 	use_booktabs = what;
+
+	if (!use_booktabs)
+		return;
+
+	// set top line in 1st row
+	row_info[0].top_line = true;
+	idx_type i0 = getFirstCellInRow(0);
+	idx_type i1 = getLastCellInRow(0);
+	for (idx_type j = i0; j <= i1; ++j)
+		cellinfo_of_cell(j).top_line = true;
+	// set bottom line in bottom row
+	row_info[rows_ - 1].bottom_line = true;
+	i0 = getFirstCellInRow(rows_ - 1);
+	i1 = getLastCellInRow(rows_ - 1);
+	for (idx_type j = i0; j <= i1; ++j)
+		cellinfo_of_cell(j).bottom_line = true;
 }
 
 
@@ -3585,18 +3633,18 @@
 			status.setOnOff(tabular.isMultiColumn(cur.idx()));
 			break;
 
-		case Tabular::M_TOGGLE_LINE_TOP:
-			flag = false;
-		case Tabular::TOGGLE_LINE_TOP:
-			status.setOnOff(tabular.topLine(cur.idx(), flag));
+		case Tabular::TOGGLE_LINE_TOP: {
+			row_type const row = tabular.row_of_cell(cur.idx());
+			status.enabled(!(tabular.use_booktabs && row == 0));
+			status.setOnOff(tabular.topLine(cur.idx()));
 			break;
-
-		case Tabular::M_TOGGLE_LINE_BOTTOM:
-			flag = false;
-		case Tabular::TOGGLE_LINE_BOTTOM:
-			status.setOnOff(tabular.bottomLine(cur.idx(), flag));
+			}
+		case Tabular::TOGGLE_LINE_BOTTOM: {
+			row_type const row = tabular.row_of_cell(cur.idx());
+			status.enabled(!(tabular.use_booktabs && row == tabular.rows_ - 1));
+			status.setOnOff(tabular.bottomLine(cur.idx()));
 			break;
-
+			}
 		case Tabular::M_TOGGLE_LINE_LEFT:
 			flag = false;
 		case Tabular::TOGGLE_LINE_LEFT:
@@ -4234,28 +4282,19 @@
 		cur.idx() = tabular.getCellNumber(row, column);
 		break;
 
-	case Tabular::M_TOGGLE_LINE_TOP:
-		flag = false;
 	case Tabular::TOGGLE_LINE_TOP: {
-		bool lineSet = !tabular.topLine(cur.idx(), flag);
+		bool lineSet = !tabular.topLine(cur.idx());
 		for (row_type i = sel_row_start; i <= sel_row_end; ++i)
 			for (col_type j = sel_col_start; j <= sel_col_end; ++j)
-				tabular.setTopLine(
-					tabular.getCellNumber(i, j),
-					lineSet, flag);
+				tabular.setTopLine(tabular.getCellNumber(i, j),	lineSet);
 		break;
 	}
 
-	case Tabular::M_TOGGLE_LINE_BOTTOM:
-		flag = false;
 	case Tabular::TOGGLE_LINE_BOTTOM: {
-		bool lineSet = !tabular.bottomLine(cur.idx(), flag);
+		bool lineSet = !tabular.bottomLine(cur.idx());
 		for (row_type i = sel_row_start; i <= sel_row_end; ++i)
 			for (col_type j = sel_col_start; j <= sel_col_end; ++j)
-				tabular.setBottomLine(
-					tabular.getCellNumber(i, j),
-					lineSet,
-					flag);
+				tabular.setBottomLine(tabular.getCellNumber(i, j), lineSet);
 		break;
 	}
 
@@ -4547,9 +4586,9 @@
 	while (paste_tabular->rows() > rows)
 		paste_tabular->deleteRow(rows);
 
-	paste_tabular->setTopLine(0, true, true);
+	paste_tabular->setTopLine(0, true);
 	paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
-				     true, true);
+				     true);
 
 	for (col_type i = 0; i < cs; ++i)
 		paste_tabular->deleteColumn(0);
Index: src/insets/InsetTabular.h
===================================================================
--- src/insets/InsetTabular.h	(revision 18739)
+++ src/insets/InsetTabular.h	(working copy)
@@ -106,10 +106,6 @@
 		///
 		VALIGN_MIDDLE,
 		///
-		M_TOGGLE_LINE_TOP,
-		///
-		M_TOGGLE_LINE_BOTTOM,
-		///
 		M_TOGGLE_LINE_LEFT,
 		///
 		M_TOGGLE_LINE_RIGHT,
@@ -243,9 +239,9 @@
 		   row_type rows_arg);
 
 	/// Returns true if there is a topline, returns false if not
-	bool topLine(idx_type cell, bool wholerow = false) const;
+	bool topLine(idx_type cell) const;
 	/// Returns true if there is a topline, returns false if not
-	bool bottomLine(idx_type cell, bool wholerow = false) const;
+	bool bottomLine(idx_type cell) const;
 	/// Returns true if there is a topline, returns false if not
 	bool leftLine(idx_type cell, bool wholecolumn = false) const;
 	/// Returns true if there is a topline, returns false if not
@@ -284,9 +280,9 @@
 	///
 	void setAllLines(idx_type cell, bool line);
 	///
-	void setTopLine(idx_type cell, bool line, bool wholerow = false);
+	void setTopLine(idx_type cell, bool line);
 	///
-	void setBottomLine(idx_type cell, bool line, bool wholerow = false);
+	void setBottomLine(idx_type cell, bool line);
 	///
 	void setLeftLine(idx_type cell, bool line, bool wholecolumn = false);
 	///

Reply via email to