X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftabular.C;h=86091c6e36a02486ec4f65ffa911810f50349877;hb=7521b5d20f42102cf444e3fd8718a088a60d0098;hp=3d68635b218d858c59564110881b35e661ed2bd8;hpb=4c6091b63f6ac4dae69ddcee26bf22e4f35a3cdf;p=lyx.git diff --git a/src/tabular.C b/src/tabular.C index 3d68635b21..86091c6e36 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -3,7 +3,7 @@ * * LyX, The Document Processor * - * Copyright 2000 The LyX Team. + * Copyright 2000-2001 The LyX Team. * * @author: Jürgen Vigna * @@ -41,6 +41,10 @@ using std::max; using std::endl; using std::vector; +#ifndef CXX_GLOBAL_CSTD +using std::strlen; +#endif + namespace { int const WIDTH_OF_LINE = 5; @@ -89,6 +93,7 @@ LyXTabular::columnstruct::columnstruct() LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) { owner_ = inset; + cur_cell = -1; Init(rows_arg, columns_arg); } @@ -96,6 +101,7 @@ LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt) { owner_ = inset; + cur_cell = -1; Init(lt.rows_, lt.columns_, <); #if 0 #ifdef WITH_WARNINGS @@ -109,17 +115,24 @@ LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt) LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex) { owner_ = inset; + cur_cell = -1; Read(buf, lex); } LyXTabular & LyXTabular::operator=(LyXTabular const & lt) { +#if 0 +#warning This while method should look like this: (Lgb) + + LyXTabular tmp(lt); + tmp.swap(*this); +#else // If this and lt is not of the same size we have a serious bug // So then it is ok to throw an exception, or for now // call abort() lyx::Assert(rows_ == lt.rows_ && columns_ == lt.columns_); - + cur_cell = -1; cell_info = lt.cell_info; row_info = lt.row_info; column_info = lt.column_info; @@ -134,12 +147,12 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) rotate = lt.rotate; Reinit(); - +#endif return *this; } -LyXTabular * LyXTabular::Clone(InsetTabular * inset) +LyXTabular * LyXTabular::clone(InsetTabular * inset) { LyXTabular * result = new LyXTabular(inset, *this); #if 0 @@ -174,7 +187,7 @@ void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt) 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(0, InsetText::LOCKED); cell_info[i][j].cellno = cellno++; } cell_info[i].back().right_line = true; @@ -369,7 +382,7 @@ void LyXTabular::set_row_column_number_info(bool oldformat) cell_info[row][column].right_line = cell_info[row][column+cn-1].right_line; } - cell_info[row][column].inset.SetAutoBreakRows( + cell_info[row][column].inset.setAutoBreakRows( !GetPWidth(GetCellNumber(row, column)).empty()); } } @@ -655,7 +668,7 @@ bool LyXTabular::SetColumnPWidth(int cell, string const & width) for (int i = 0; i < rows_; ++i) { int c = GetCellNumber(i, j); flag = !GetPWidth(c).empty(); // because of multicolumns! - GetCellInset(c)->SetAutoBreakRows(flag); + GetCellInset(c)->setAutoBreakRows(flag); } return true; } @@ -667,7 +680,7 @@ bool LyXTabular::SetMColumnPWidth(int cell, string const & width) cellinfo_of_cell(cell)->p_width = width; if (IsMultiColumn(cell)) { - GetCellInset(cell)->SetAutoBreakRows(flag); + GetCellInset(cell)->setAutoBreakRows(flag); return true; } return false; @@ -1065,7 +1078,7 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const << write_attribute("special", cell_info[i][j].align_special) << ">\n"; os << "\\begin_inset "; - cell_info[i][j].inset.Write(buf, os); + cell_info[i][j].inset.write(buf, os); os << "\n\\end_inset \n" << "\n"; } @@ -1146,8 +1159,8 @@ bool getTokenValue(string const & str, const char * token, string & ret) size_t token_length = strlen(token); string::size_type pos = str.find(token); - if (pos == string::npos || pos+token_length+1 >= str.length() - || str[pos+token_length] != '=') + if (pos == string::npos || pos + token_length + 1 >= str.length() + || str[pos + token_length] != '=') return false; ret.erase(); pos += token_length + 1; @@ -1316,7 +1329,7 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, getTokenValue(line, "special", cell_info[i][j].align_special); l_getline(is, line); if (prefixIs(line, "\\begin_inset")) { - cell_info[i][j].inset.Read(buf, lex); + cell_info[i][j].inset.read(buf, lex); l_getline(is, line); } if (!prefixIs(line, "")) { @@ -1473,14 +1486,14 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) } set_row_column_number_info(true); - LyXParagraph * par = new LyXParagraph; - LyXParagraph * return_par = 0; + Paragraph * par = new Paragraph; + Paragraph * return_par = 0; string tmptok; int pos = 0; - char depth = 0; + Paragraph::depth_type depth = 0; LyXFont font(LyXFont::ALL_INHERIT); - font.setLanguage(owner_->BufferOwner()->GetLanguage()); + font.setLanguage(owner_->bufferOwner()->getLanguage()); while (lex.IsOK()) { lex.nextToken(); @@ -1493,7 +1506,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) lex.pushToken(token); break; } - if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par, + if (owner_->bufferOwner()->parseSingleLyXformat2Token(lex, par, return_par, token, pos, depth, font)) { @@ -1515,7 +1528,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) int row; for (int i = 0; i < par->size(); ++i) { - if (par->IsNewline(i)) { + if (par->isNewline(i)) { ++cell; if (cell > GetNumberOfCells()) { lyxerr << "Some error in reading old table format occured!" << @@ -1538,12 +1551,12 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox) { // insert a space instead - par->Erase(i); - par->InsertChar(i, ' '); + par->erase(i); + par->insertChar(i, ' '); } } - par->CopyIntoMinibuffer(*owner_->BufferOwner(), i); - inset->par->InsertFromMinibuffer(inset->par->size()); + par->copyIntoMinibuffer(*owner_->bufferOwner(), i); + inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size()); } delete par; Reinit(); @@ -1961,8 +1974,13 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const if (!cellinfo_of_cell(cell)->align_special.empty()) { os << cellinfo_of_cell(cell)->align_special << "}{"; } else { - if (LeftLine(cell)) + if (LeftLine(cell) && + (IsFirstCellInRow(cell) || + (!IsMultiColumn(cell-1) && !LeftLine(cell, true) && + !RightLine(cell-1, true)))) + { os << '|'; + } if (!GetPWidth(cell).empty()) { switch (GetVAlignment(cell)) { case LYX_VALIGN_TOP: @@ -2145,12 +2163,12 @@ int LyXTabular::Latex(Buffer const * buf, ret += TeXCellPreamble(os, cell); InsetText * inset = GetCellInset(cell); - bool rtl = inset->par->isRightToLeftPar(buf->params) && - inset->par->size() > 0 && GetPWidth(cell).empty(); + bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) && + inset->paragraph()->size() > 0 && GetPWidth(cell).empty(); if (rtl) os << "\\R{"; - ret += inset->Latex(buf, os, fragile, fp); + ret += inset->latex(buf, os, fragile, fp); if (rtl) os << "}"; @@ -2279,7 +2297,7 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const } os << ">"; - ret += GetCellInset(cell)->DocBook(buf, os); + ret += GetCellInset(cell)->docBook(buf, os); os << ""; ++cell; } @@ -2407,7 +2425,7 @@ int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os, vector const & clen) const { ostringstream sstr; - int ret = GetCellInset(cell)->Ascii(buf, sstr, 0); + int ret = GetCellInset(cell)->ascii(buf, sstr, 0); if (LeftLine(cell)) os << "| "; @@ -2466,7 +2484,7 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const if (IsMultiColumn(cell, true)) continue; ostringstream sstr; - GetCellInset(cell)->Ascii(buf, sstr, 0); + GetCellInset(cell)->ascii(buf, sstr, 0); if (clen[j] < sstr.str().length()) clen[j] = sstr.str().length(); } @@ -2478,7 +2496,7 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j)) continue; ostringstream sstr; - GetCellInset(cell)->Ascii(buf, sstr, 0); + GetCellInset(cell)->ascii(buf, sstr, 0); int len = int(sstr.str().length()); int const n = cells_in_multicolumn(cell); for (int k = j; (len > 0) && (k < (j + n - 1)); ++k) @@ -2505,13 +2523,20 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const InsetText * LyXTabular::GetCellInset(int cell) const { + cur_cell = cell; return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset; } InsetText * LyXTabular::GetCellInset(int row, int column) const { - return GetCellInset(GetCellNumber(row, column)); +#ifdef WITH_WARNINGS +#warning Juergen, should we check whether the row/column values are correct? +// If we do not need to do that, the tests in GetCellNumber should be +// changed to asserts. +#endif + cur_cell = GetCellNumber(row, column); + return & cell_info[row][column].inset; } @@ -2524,7 +2549,7 @@ void LyXTabular::Validate(LaTeXFeatures & features) const for (int cell = 0; !features.array && (cell < numberofcells); ++cell) { if (GetVAlignment(cell) != LYX_VALIGN_TOP) features.array = true; - GetCellInset(cell)->Validate(features); + GetCellInset(cell)->validate(features); } } @@ -2545,11 +2570,11 @@ std::vector const LyXTabular::getLabelList() const LyXTabular::BoxType LyXTabular::UseParbox(int cell) const { - LyXParagraph * par = GetCellInset(cell)->par; + Paragraph * par = GetCellInset(cell)->paragraph(); for (; par; par = par->next()) { for (int i = 0; i < par->size(); ++i) { - if (par->GetChar(i) == LyXParagraph::META_NEWLINE) + if (par->getChar(i) == Paragraph::META_NEWLINE) return BOX_PARBOX; } }