X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftabular.C;h=10e0b797ae4f84c7e10221b1a97a1c68d1d56022;hb=24f8676130d1e0769db394b7142dae7eeb1d955e;hp=263b9ac22f64e0f6a9dab0f2d1d8f0373e8aa0a4;hpb=2e57f2ff0ae7cd4a6efbf634ffe6d2f4379d9cfc;p=lyx.git diff --git a/src/tabular.C b/src/tabular.C index 263b9ac22f..10e0b797ae 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -1,13 +1,18 @@ -/* This file is part of - * ====================================================== +/** + * \file tabular.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author Lars Gullik Bjønnes + * \author Matthias Ettrich + * \author José Matos + * \author Jean-Marc Lasgouttes + * \author Angus Leeming + * \author John Levon + * \author André Pönitz + * \author Jürgen Vigna * - * Copyright 2000-2002 The LyX Team. - * - * @author: Jürgen Vigna - * - * ====================================================== + * Full author contact details are available in file CREDITS. */ #include @@ -54,6 +59,13 @@ namespace { int const WIDTH_OF_LINE = 5; +template +string const write_attribute(string const & name, T const & t) +{ + string const s = tostr(t); + return s.empty() ? s : " " + name + "=\"" + s + "\""; +} + string const write_attribute(string const & name, string const & t) { return t.empty() ? t : " " + name + "=\"" + t + "\""; @@ -110,8 +122,8 @@ 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_MIDDLE: + return "middle"; case LyXTabular::LYX_VALIGN_BOTTOM: return "bottom"; } @@ -155,8 +167,8 @@ 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 == "middle" ) + num = LyXTabular::LYX_VALIGN_MIDDLE; else if (str == "bottom") num = LyXTabular::LYX_VALIGN_BOTTOM; else @@ -358,7 +370,7 @@ LyXTabular::LyXTabular(BufferParams const & bp, } -LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex) +LyXTabular::LyXTabular(Buffer const & buf, InsetTabular * inset, LyXLex & lex) { owner_ = inset; cur_cell = -1; @@ -385,7 +397,7 @@ void LyXTabular::init(BufferParams const & bp, for (int i = 0; i < rows_; ++i) { for (int j = 0; j < columns_; ++j) { cell_info[i][j].inset.setOwner(owner_); - cell_info[i][j].inset.setDrawFrame(0, InsetText::LOCKED); + cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED); cell_info[i][j].cellno = cellno++; } cell_info[i].back().right_line = true; @@ -393,15 +405,15 @@ void LyXTabular::init(BufferParams const & bp, row_info.back().bottom_line = true; row_info.front().bottom_line = true; - for (int i = 0; i < columns_; ++i) { + for (int i = 0; i < columns_; ++i) calculate_width_of_column(i); - } + column_info.back().right_line = true; calculate_width_of_tabular(); - rowofcell = vector(); - columnofcell = vector(); + rowofcell.clear(); + columnofcell.clear(); set_row_column_number_info(); is_long_tabular = false; rotate = false; @@ -426,16 +438,14 @@ void LyXTabular::appendRow(BufferParams const & bp, int cell) cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, cellstruct(bp))); - for (int i = 0; i <= row; ++i) { - for (int j = 0; j < columns_; ++j) { + for (int i = 0; i <= row; ++i) + for (int j = 0; j < columns_; ++j) c_info[i][j] = cell_info[i][j]; - } - } - for (int i = row + 1; i < rows_; ++i) { - for (int j = 0; j < columns_; ++j) { + + for (int i = row + 1; i < rows_; ++i) + for (int j = 0; j < columns_; ++j) c_info[i][j] = cell_info[i-1][j]; - } - } + cell_info = c_info; ++row; for (int j = 0; j < columns_; ++j) { @@ -474,22 +484,19 @@ void LyXTabular::appendColumn(BufferParams const & bp, int cell) column_info[column + 1] = column_info[column]; for (int i = 0; i < rows_; ++i) { - for (int j = 0; j <= column; ++j) { + for (int j = 0; j <= column; ++j) c_info[i][j] = cell_info[i][j]; - } - for (int j = column + 1; j < columns_; ++j) { + + for (int j = column + 1; j < columns_; ++j) c_info[i][j] = cell_info[i][j - 1]; - } + // care about multicolumns - if (c_info[i][column + 1].multicolumn==CELL_BEGIN_OF_MULTICOLUMN) - { + if (c_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) c_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN; - } - if (column + 2 >= columns_ || - c_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) - { + + if (column + 2 >= columns_ + || c_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) c_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL; - } } cell_info = c_info; //++column; @@ -568,6 +575,7 @@ void LyXTabular::set_row_column_number_info(bool oldformat) } while (column < columns_ && cell_info[row][column].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN); + if (column == columns_) { column = 0; ++row; @@ -824,7 +832,7 @@ void LyXTabular::recalculateMulticolumnsOfColumn(int column) // returns 1 if a complete update is necessary, otherwise 0 -bool LyXTabular::setWidthOfCell(int cell, int new_width) +void LyXTabular::setWidthOfCell(int cell, int new_width) { int const row = row_of_cell(cell); int const column1 = column_of_cell(cell); @@ -836,12 +844,12 @@ bool LyXTabular::setWidthOfCell(int cell, int new_width) column1 < columns_ - 1 && leftLine(cell_info[row][column1+1].cellno, true)) { - // additional width add_width = WIDTH_OF_LINE; } - if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width) { - return false; - } + + if (getWidthOfCell(cell) == new_width + 2 * WIDTH_OF_LINE + add_width) + return; + if (isMultiColumn(cell, true)) { tmp = setWidthOfMulticolCell(cell, new_width); } else { @@ -855,9 +863,7 @@ bool LyXTabular::setWidthOfCell(int cell, int new_width) for (int i = 0; i < columns_; ++i) calculate_width_of_column(i); calculate_width_of_tabular(); - return true; } - return false; } @@ -1143,7 +1149,7 @@ int LyXTabular::right_column_of_cell(int cell) const } -void LyXTabular::write(Buffer const * buf, ostream & os) const +void LyXTabular::write(Buffer const & buf, ostream & os) const { // header line os << "params, rows_arg, columns_arg); + init(buf.params, rows_arg, columns_arg); l_getline(is, line); if (!prefixIs(line, " got" @@ -1727,21 +1733,19 @@ bool LyXTabular::haveLTLastFoot() const // end longtable support functions -bool LyXTabular::setAscentOfRow(int row, int height) +void LyXTabular::setAscentOfRow(int row, int height) { if (row >= rows_ || row_info[row].ascent_of_row == height) - return false; + return; row_info[row].ascent_of_row = height; - return true; } -bool LyXTabular::setDescentOfRow(int row, int height) +void LyXTabular::setDescentOfRow(int row, int height) { if (row >= rows_ || row_info[row].descent_of_row == height) - return false; + return; row_info[row].descent_of_row = height; - return true; } @@ -1870,7 +1874,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const case LYX_VALIGN_TOP: os << 'p'; break; - case LYX_VALIGN_CENTER: + case LYX_VALIGN_MIDDLE: os << 'm'; break; case LYX_VALIGN_BOTTOM: @@ -1907,7 +1911,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const case LYX_VALIGN_TOP: os << 't'; break; - case LYX_VALIGN_CENTER: + case LYX_VALIGN_MIDDLE: os << 'c'; break; case LYX_VALIGN_BOTTOM: @@ -1921,7 +1925,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const case LYX_VALIGN_TOP: os << 't'; break; - case LYX_VALIGN_CENTER: + case LYX_VALIGN_MIDDLE: os << 'm'; break; case LYX_VALIGN_BOTTOM: @@ -1957,7 +1961,7 @@ int LyXTabular::TeXCellPostamble(ostream & os, int cell) const } -int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const * buf, +int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const & buf, LatexRunParams const & runparams) const { if (!is_long_tabular) @@ -2057,7 +2061,7 @@ bool LyXTabular::isValidRow(int const row) const } -int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf, +int LyXTabular::TeXRow(ostream & os, int const i, Buffer const & buf, LatexRunParams const & runparams) const { int ret = 0; @@ -2070,7 +2074,7 @@ int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf, ret += TeXCellPreamble(os, cell); InsetText & inset = getCellInset(cell); - bool rtl = inset.paragraphs.begin()->isRightToLeftPar(buf->params) && + bool rtl = inset.paragraphs.begin()->isRightToLeftPar(buf.params) && !inset.paragraphs.begin()->empty() && getPWidth(cell).zero(); if (rtl) @@ -2093,7 +2097,7 @@ int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf, } -int LyXTabular::latex(Buffer const * buf, ostream & os, +int LyXTabular::latex(Buffer const & buf, ostream & os, LatexRunParams const & runparams) const { int ret = 0; @@ -2138,7 +2142,7 @@ int LyXTabular::latex(Buffer const * buf, ostream & os, case LYX_VALIGN_TOP: os << 'p'; break; - case LYX_VALIGN_CENTER: + case LYX_VALIGN_MIDDLE: os << 'm'; break; case LYX_VALIGN_BOTTOM: @@ -2201,7 +2205,48 @@ int LyXTabular::latex(Buffer const * buf, ostream & os, } -int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const +int LyXTabular::linuxdoc(Buffer const & buf, ostream & os) const +{ + os << "\n"; + int cell = 0; + int ret = 0; + for (int i = 0; i < rows_; ++i) { + for (int j = 0; j < columns_; ++j) { + if (isPartOfMultiColumn(i, j)) + continue; + InsetText & inset = getCellInset(cell); + + ret += inset.linuxdoc(buf, os); + + if (isLastCellInRow(cell)) { + os << "@\n"; + ++ret; + } else { + os << "|"; + } + ++cell; + } + } + os << "\n"; + return ret; +} + + +int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row) const { int ret = 0; int cell = getFirstCellInRow(row); @@ -2232,7 +2277,7 @@ int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const case LYX_VALIGN_BOTTOM: os << "bottom"; break; - case LYX_VALIGN_CENTER: + case LYX_VALIGN_MIDDLE: os << "middle"; } os << '"'; @@ -2252,7 +2297,7 @@ int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const } -int LyXTabular::docbook(Buffer const * buf, ostream & os, +int LyXTabular::docbook(Buffer const & buf, ostream & os, bool /*mixcont*/) const { int ret = 0; @@ -2428,7 +2473,7 @@ int LyXTabular::asciiBottomHLine(ostream & os, int row, } -int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os, +int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, int cell, int row, int column, vector const & clen, bool onlydata) const @@ -2478,7 +2523,7 @@ int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os, } -int LyXTabular::ascii(Buffer const * buf, ostream & os, int const depth, +int LyXTabular::ascii(Buffer const & buf, ostream & os, int const depth, bool onlydata, unsigned char delim) const { int ret = 0; @@ -2561,24 +2606,23 @@ int LyXTabular::getCellFromInset(InsetOld const * inset, int maybe_cell) const { // is this inset part of the tabular? if (!inset || inset->owner() != owner_) { - lyxerr << "this is not a cell of the tabular!" << endl; - Assert(0); + lyxerr << "Error: this is not a cell of the tabular!" << endl; + return -1; } const int save_cur_cell = cur_cell; int cell = cur_cell; if (&getCellInset(cell) != inset) { cell = maybe_cell; - if (cell == -1 || &getCellInset(cell) != inset) { + if (cell == -1 || &getCellInset(cell) != inset) cell = -1; - } } if (cell == -1) { - for (cell = getNumberOfCells(); cell >= 0; --cell) { + for (cell = getNumberOfCells(); cell >= 0; --cell) if (&getCellInset(cell) == inset) break; - } + lyxerr[Debug::INSETTEXT] << "LyXTabular::getCellFromInset: " << "cell=" << cell