-bool LyXTabular::IsLastCellInRow(int cell) const
-{
- return (right_column_of_cell(cell) == (columns_ - 1));
-}
-
-
-int LyXTabular::GetLastCellInRow(int row) const
-{
- if (row > (rows_-1))
- row = rows_ - 1;
- return cell_info[row][columns_-1].cellno;
-}
-
-
-bool LyXTabular::calculate_width_of_column(int column)
-{
- int const old_column_width = column_info[column].width_of_column;
- int maximum = 0;
-
- for (int i = 0; i < rows_; ++i) {
- maximum = max(cell_info[i][column].width_of_cell, maximum);
- }
- column_info[column].width_of_column = maximum;
- return (column_info[column].width_of_column != old_column_width);
-}
-
-
-//
-// calculate the with of the column without regarding REAL MultiColumn
-// cells. This means MultiColumn-cells spanning more than 1 column.
-//
-bool LyXTabular::calculate_width_of_column_NMC(int column)
-{
- int const old_column_width = column_info[column].width_of_column;
- int max = 0;
- for (int i = 0; i < rows_; ++i) {
- if (!IsMultiColumn(GetCellNumber(i, column), true) &&
- (cell_info[i][column].width_of_cell > max)) {
- max = cell_info[i][column].width_of_cell;
- }
- }
- column_info[column].width_of_column = max;
- return (column_info[column].width_of_column != old_column_width);
-}
-
-
-void LyXTabular::calculate_width_of_tabular()
-{
- width_of_tabular = 0;
- for (int i = 0; i < columns_; ++i) {
- width_of_tabular += column_info[i].width_of_column;
- }
-}
-
-
-int LyXTabular::row_of_cell(int cell) const
-{
- if (cell >= numberofcells)
- return rows_ - 1;
- else if (cell < 0)
- return 0;
- return rowofcell[cell];
-}
-
-
-int LyXTabular::column_of_cell(int cell) const
-{
- if (cell >= numberofcells)
- return columns_ - 1;
- else if (cell < 0)
- return 0;
- return columnofcell[cell];
-}
-
-
-int LyXTabular::right_column_of_cell(int cell) const
-{
- int const row = row_of_cell(cell);
- int column = column_of_cell(cell);
- while (column < (columns_ - 1) &&
- cell_info[row][column + 1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
- ++column;
- return column;
-}
-
-
-// Perfect case for a template... (Lgb)
-#if 1
-template<class T>
-string const write_attribute(string const & name, T const & t)
-{
- string str = " " + name + "=\"" + tostr(t) + "\"";
- return str;
-}
-
-template <>
-string const write_attribute(string const & name, bool const & b)
-{
- return write_attribute(name, int(b));
-}
-
-#else
-
-string const write_attribute(string const & name, int value)
-{
- string str = " " + name + "=\"" + tostr(value) + "\"";
- return str;
-}
-
-
-string const write_attribute(string const & name, string const & value)
-{
- string str = " " + name + "=\"" + value + "\"";
- return str;
-}
-
-
-string const write_attribute(string const & name, bool value)
-{
- string str = " " + name + "=\"" + tostr(static_cast<int>(value)) + "\"";
- return str;
-}
-#endif
-
-
-template<>
-inline
-string const tostr(LyXAlignment const & num)
-{
- switch(num) {
- case LYX_ALIGN_NONE:
- return "none";
- case LYX_ALIGN_BLOCK:
- return "block";
- case LYX_ALIGN_LEFT:
- return "left";
- case LYX_ALIGN_CENTER:
- return "center";
- case LYX_ALIGN_RIGHT:
- return "right";
- case LYX_ALIGN_LAYOUT:
- return "layout";
- case LYX_ALIGN_SPECIAL:
- return "special";
- }
- return string();
-}
-
-
-template<>
-inline
-string const tostr(LyXTabular::VAlignment const & num)
-{
- switch(num) {
- case LyXTabular::LYX_VALIGN_TOP:
- return "top";
- case LyXTabular::LYX_VALIGN_CENTER:
- return "center";
- case LyXTabular::LYX_VALIGN_BOTTOM:
- return "bottom";
- }
- return string();
-}
-
-
-template<>
-inline
-string const tostr(LyXTabular::BoxType const & num)
-{
- switch(num) {
- case LyXTabular::BOX_NONE:
- return "none";
- case LyXTabular::BOX_PARBOX:
- return "parbox";
- case LyXTabular::BOX_MINIPAGE:
- return "minipage";
- }
- return string();
-}
-
-
-void LyXTabular::Write(Buffer const * buf, ostream & os) const
-{
- // header line
- os << "<lyxtabular"
- << write_attribute("version", 2)
- << write_attribute("rows", rows_)
- << write_attribute("columns", columns_)
- << ">\n";
- // global longtable options
- os << "<features"
- << write_attribute("rotate", tostr(rotate))
- << write_attribute("islongtable", tostr(is_long_tabular))
- << write_attribute("endhead", endhead)
- << write_attribute("endfirsthead", endfirsthead)
- << write_attribute("endfoot", endfoot)
- << write_attribute("endlastfoot", endlastfoot)
- << ">\n";
- for (int j = 0; j < columns_; ++j) {
- os << "<column"
- << write_attribute("alignment", tostr(column_info[j].alignment))
- << write_attribute("valignment", tostr(column_info[j].valignment))
- << write_attribute("leftline", tostr(column_info[j].left_line))
- << write_attribute("rightline", tostr(column_info[j].right_line))
- << write_attribute("width",
- VSpace(column_info[j].p_width)
- .asLyXCommand())
- << write_attribute("special", column_info[j].align_special)
- << ">\n";
- }
- for (int i = 0; i < rows_; ++i) {
- os << "<row"
- << write_attribute("topline", tostr(row_info[i].top_line))
- << write_attribute("bottomline", tostr(row_info[i].bottom_line))
- << write_attribute("newpage", tostr(row_info[i].newpage))
- << ">\n";
- for (int j = 0; j < columns_; ++j) {
- os << "<cell"
- << write_attribute("multicolumn", cell_info[i][j].multicolumn)
- << write_attribute("alignment", tostr(cell_info[i][j].alignment))
- << write_attribute("valignment", tostr(cell_info[i][j].valignment))
- << write_attribute("topline", tostr(cell_info[i][j].top_line))
- << write_attribute("bottomline", tostr(cell_info[i][j].bottom_line))
- << write_attribute("leftline", tostr(cell_info[i][j].left_line))
- << write_attribute("rightline", tostr(cell_info[i][j].right_line))
- << write_attribute("rotate", tostr(cell_info[i][j].rotate))
- << write_attribute("usebox", tostr(cell_info[i][j].usebox))
- << write_attribute("width", cell_info[i][j].p_width)
- << write_attribute("special", cell_info[i][j].align_special)
- << ">\n";
- os << "\\begin_inset ";
- cell_info[i][j].inset.Write(buf, os);
- os << "\n\\end_inset \n"
- << "</cell>\n";
- }
- os << "</row>\n";
- }
- os << "</lyxtabular>\n";
-}
-
-
-namespace {
-
-// I would have liked a fromstr template a lot better. (Lgb)
-
-inline
-bool string2type(string const str, LyXAlignment & num)
-{
- if (str == "none")
- num = LYX_ALIGN_NONE;
- else if (str == "block")
- num = LYX_ALIGN_BLOCK;
- else if (str == "left")
- num = LYX_ALIGN_LEFT;
- else if (str == "center")
- num = LYX_ALIGN_CENTER;
- else if (str == "right")
- num = LYX_ALIGN_RIGHT;
- else
- return false;
- return true;
-}
-
-
-inline
-bool string2type(string const str, LyXTabular::VAlignment & num)
-{
- if (str == "top")
- num = LyXTabular::LYX_VALIGN_TOP;
- else if (str == "center")
- num = LyXTabular::LYX_VALIGN_CENTER;
- else if (str == "bottom")
- num = LyXTabular::LYX_VALIGN_BOTTOM;
- else
- return false;
- return true;
-}
-
-
-inline
-bool string2type(string const str, LyXTabular::BoxType & num)
-{
- if (str == "none")
- num = LyXTabular::BOX_NONE;
- else if (str == "parbox")
- num = LyXTabular::BOX_PARBOX;
- else if (str == "minipage")
- num = LyXTabular::BOX_MINIPAGE;
- else
- return false;
- return true;
-}
-