X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftabular.C;h=0dc9287192a0eeb709d7b78e355105843d0ed0b3;hb=8cb2e519b3975cc643f2c93706137cf2e6a4f4d8;hp=a41f430d30d7dd7d258b9c20db5db5746c5b18db;hpb=26db00333da75fbbb43d1c31250c9ae482e931a1;p=lyx.git diff --git a/src/tabular.C b/src/tabular.C index a41f430d30..0dc9287192 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -195,6 +195,8 @@ void LyXTabular::AppendRow(int cell) row_vector::iterator rit = row_info.begin() + row; row_info.insert(rit, rowstruct()); + // now set the values of the row before + row_info[row] = row_info[row+1]; #if 0 cell_vvector::iterator cit = cell_info.begin() + row; @@ -246,6 +248,8 @@ void LyXTabular::AppendColumn(int cell) int const column = column_of_cell(cell); column_vector::iterator cit = column_info.begin() + column + 1; column_info.insert(cit, columnstruct()); + // set the column values of the column before + column_info[column+1] = column_info[column]; for (int i = 0; i < rows_; ++i) { for (int j = 0; j <= column; ++j) { @@ -943,65 +947,6 @@ string const write_attribute(string const & name, bool value) #endif -// #if 0 -// static inline -// string const type2string(LyXAlignment 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(); -// } - - -// static inline -// string const type2string(LyXTabular::VAlignment 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(); -// } - - -// static inline -// string const type2string(LyXTabular::BoxType num) -// { -// switch(num) { -// case LyXTabular::BOX_NONE: -// return "none"; -// case LyXTabular::BOX_PARBOX: -// return "parbox"; -// case LyXTabular::BOX_MINIPAGE: -// return "minipage"; -// } -// return string(); -// } - -// static inline -// string const type2string(bool flag) -// { -// return (flag ? "true" : "false"); -// } -// #else template<> inline string const tostr(LyXAlignment const & num) @@ -1057,53 +1002,30 @@ string const tostr(LyXTabular::BoxType const & num) return string(); } -// We already have a function like this in lstring.h (Lgb) -//string const type2string(bool flag) -//{ -// return (flag ? "true" : "false"); -//} - - -//#endif - - - void LyXTabular::Write(Buffer const * buf, ostream & os) const { // header line - os << "\n"; // global longtable options - os << "\n"; for (int j = 0; j < columns_; ++j) { - os << "\n"; } for (int i = 0; i < rows_; ++i) { - os << "\n"; for (int j = 0; j < columns_; ++j) { #if 0 if (!i) { - os << "\n"; } else { - os << "\n"; + os << "\n"; } #endif - os << "\n"; os << "\\begin_inset "; cell_info[i][j].inset.Write(buf, os); os << "\n\\end_inset \n" - << "\n"; + << "\n"; #if 0 - << "\n"; + << "\n"; #endif } - os << "\n"; + os << "\n"; } - os << "\n"; + os << "\n"; } @@ -1272,9 +1169,6 @@ bool getTokenValue(string const & str, const char * token, string & ret) } -//#define USE_OLD_READFORMAT - -//#ifndef USE_OLD_READFORMAT static bool getTokenValue(string const & str, const char * token, int & num) { @@ -1327,90 +1221,6 @@ bool getTokenValue(string const & str, const char * token, bool & flag) return string2type(tmp, flag); } -//#else - -// static -// bool getTokenValue(string const & str, const char * token, int & num) -// { -// string::size_type pos = str.find(token); -// char ch = str[pos + strlen(token)]; - -// if ((pos == string::npos) || (ch != '=')) -// return false; -// string ret; -// pos += strlen(token) + 1; -// ch = str[pos]; -// if ((ch != '"') && (ch != '\'')) { // only read till next space -// if (!isdigit(ch)) -// return false; -// ret += ch; -// } -// ++pos; -// while((pos < str.length() - 1) && isdigit(str[pos])) -// ret += str[pos++]; - -// num = strToInt(ret); -// return true; -// } - - -// static -// bool getTokenValue(string const & str, const char * token, LyXAlignment & num) -// { -// int tmp; -// bool const ret = getTokenValue(str, token, tmp); -// num = static_cast(tmp); -// return ret; -// } - - -// static -// bool getTokenValue(string const & str, const char * token, -// LyXTabular::VAlignment & num) -// { -// int tmp; -// bool const ret = getTokenValue(str, token, tmp); -// num = static_cast(tmp); -// return ret; -// } - - -// static -// bool getTokenValue(string const & str, const char * token, -// LyXTabular::BoxType & num) -// { -// int tmp; -// bool ret = getTokenValue(str, token, tmp); -// num = static_cast(tmp); -// return ret; -// } - - -// static -// bool getTokenValue(string const & str, const char * token, bool & flag) -// { -// string::size_type pos = str.find(token); -// char ch = str[pos + strlen(token)]; - -// if ((pos == string::npos) || (ch != '=')) -// return false; -// string ret; -// pos += strlen(token) + 1; -// ch = str[pos]; -// if ((ch != '"') && (ch != '\'')) { // only read till next space -// if (!isdigit(ch)) -// return false; -// ret += ch; -// } -// ++pos; -// while((pos < str.length() - 1) && isdigit(str[pos])) -// ret += str[pos++]; - -// flag = strToInt(ret); -// return true; -// } - -// #endif static inline void l_getline(istream & is, string & str) @@ -1421,15 +1231,14 @@ void l_getline(istream & is, string & str) } -//#ifndef USE_OLD_READFORMAT - void LyXTabular::Read(Buffer const * buf, LyXLex & lex) { string line; istream & is = lex.getStream(); l_getline(is, line); - if (!prefixIs(line, " got" << + if (!prefixIs(line, " got" << line << ")" << endl; return; } @@ -1487,8 +1279,8 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, for (int j = 0; j < columns_; ++j) { l_getline(is,line); - if (!prefixIs(line," got" << + if (!prefixIs(line," got" << line << ")" << endl; return; } @@ -1502,8 +1294,8 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, for (int i = 0; i < rows_; ++i) { l_getline(is, line); - if (!prefixIs(line, " got" << + if (!prefixIs(line, " got" << line << ")" << endl; return; } @@ -1512,8 +1304,8 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, getTokenValue(line, "newpage", row_info[i].newpage); for (int j = 0; j < columns_; ++j) { l_getline(is, line); - if (!prefixIs(line, " got" << + if (!prefixIs(line, " got" << line << ")" << endl; return; } @@ -1533,137 +1325,31 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is, cell_info[i][j].inset.Read(buf, lex); l_getline(is, line); } - if (line != "") { - lyxerr << "Wrong tabular format (expected got" << + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << line << ")" << endl; return; } } l_getline(is, line); - if (line != "") { - lyxerr << "Wrong tabular format (expected got" << + if (line != "") { + lyxerr << "Wrong tabular format (expected got" << line << ")" << endl; return; } } - while (line != "") { + while (line != "") { l_getline(is, line); } set_row_column_number_info(); } -// #else - -// void LyXTabular::Read(Buffer const * buf, LyXLex & lex) -// { -// string line; -// istream & is = lex.getStream(); - -// l_getline(is, line); -// if (!prefixIs(line, " got" << -// line << ")" << endl; -// return; -// } -// getTokenValue(line, "islongtable", is_long_tabular); -// getTokenValue(line, "endhead", endhead); -// getTokenValue(line, "endfirsthead", endfirsthead); -// getTokenValue(line, "endfoot", endfoot); -// getTokenValue(line, "endlastfoot", endlastfoot); - -// for (int i = 0; i < rows_; ++i) { -// l_getline(is, line); -// if (!prefixIs(line, " got" << -// line << ")" << endl; -// return; -// } -// getTokenValue(line, "topline", row_info[i].top_line); -// getTokenValue(line, "bottomline", row_info[i].bottom_line); -// getTokenValue(line, "newpage", row_info[i].newpage); -// for (int j = 0; j < columns_; ++j) { -// l_getline(is,line); -// if (!prefixIs(line," got" << -// line << ")" << endl; -// return; -// } -// if (!i) { -// getTokenValue(line, "alignment", column_info[j].alignment); -// getTokenValue(line, "valignment", column_info[j].valignment); -// getTokenValue(line, "leftline", column_info[j].left_line); -// getTokenValue(line, "rightline", column_info[j].right_line); -// getTokenValue(line, "width", column_info[j].p_width); -// getTokenValue(line, "special", column_info[j].align_special); -// } -// l_getline(is, line); -// if (!prefixIs(line, " got" << -// line << ")" << endl; -// return; -// } -// getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn); -// getTokenValue(line, "alignment", cell_info[i][j].alignment); -// getTokenValue(line, "valignment", cell_info[i][j].valignment); -// getTokenValue(line, "topline", cell_info[i][j].top_line); -// getTokenValue(line, "bottomline", cell_info[i][j].bottom_line); -// getTokenValue(line, "leftline", cell_info[i][j].left_line); -// getTokenValue(line, "rightline", cell_info[i][j].right_line); -// getTokenValue(line, "rotate", cell_info[i][j].rotate); -// getTokenValue(line, "usebox", cell_info[i][j].usebox); -// getTokenValue(line, "width", cell_info[i][j].p_width); -// 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); -// l_getline(is, line); -// } -// if (line != "") { -// lyxerr << "Wrong tabular format (expected got" << -// line << ")" << endl; -// return; -// } -// l_getline(is, line); -// if (line != "") { -// lyxerr << "Wrong tabular format (expected got" << -// line << ")" << endl; -// return; -// } -// } -// l_getline(is, line); -// if (line != "") { -// lyxerr << "Wrong tabular format (expected got" << -// line << ")" << endl; -// return; -// } -// } -// while (line != "") { -// l_getline(is, line); -// } -// set_row_column_number_info(); -// } -// #endif void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) { int version; - int i, j; + int i; + int j; int rows_arg = 0; int columns_arg = 0; int is_long_tabular_arg = false; @@ -1844,7 +1530,11 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) InsetText * inset = GetCellInset(cell); int row; +#ifndef NEW_INSETS for (int i = 0; i < par->Last(); ++i) { +#else + for (int i = 0; i < par->size(); ++i) { +#endif if (par->IsNewline(i)) { ++cell; if (cell > GetNumberOfCells()) { @@ -1873,174 +1563,17 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl) } } par->CopyIntoMinibuffer(*owner_->BufferOwner(), i); +#ifndef NEW_INSETS inset->par->InsertFromMinibuffer(inset->par->Last()); +#else + inset->par->InsertFromMinibuffer(inset->par->size()); +#endif } delete par; Reinit(); } -string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const -{ - int const i = isColumn ? cell : column_of_cell(cell); - - if (!isColumn && IsMultiColumn(cell)) { - if (!cellinfo_of_cell(cell)->align_special.empty()) { - return cellinfo_of_cell(cell)->align_special; - } else { - switch (GetAlignment(cell)) { - case LYX_ALIGN_LEFT: - return "left"; - case LYX_ALIGN_RIGHT: - return "right"; - default: - return "center"; - } - } - } else { - if (!column_info[i].align_special.empty()) { - return column_info[i].align_special; - } -#ifdef IGNORE_THIS_FOR_NOW - else if (!column_info[i].p_width.empty()) { - file += "p{"; - file += column_info[i].p_width; - file += '}'; - } -#endif - else { - switch (column_info[i].alignment) { - case LYX_ALIGN_LEFT: - return "left"; - case LYX_ALIGN_RIGHT: - return "right"; - default: - return "center"; - } - } - } -} - - -// cell <0 will tex the preamble -// returns the number of printed newlines -int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const -{ - int ret = 0; - if (IsLastCell(cell)) { - os << newlineAndDepth(--depth) - << "" - << newlineAndDepth(--depth) - << "" - << newlineAndDepth(--depth) - << "" - << newlineAndDepth(--depth); - if (is_long_tabular) - os << ""; - else - os << "" - << newlineAndDepth(--depth); - ret += 4; - } else { - if (cell < 0) { - // preamble - if (is_long_tabular) - os << "" - << newlineAndDepth(++depth); - ++ret; - for (int i = 0; i < columns_; ++i) { - os << "" - << newlineAndDepth(depth); - ++ret; -#ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW - if (column_info[i].left_line) - os << '|'; -#endif - } - os << "" - << newlineAndDepth(++depth) - << "" - << newlineAndDepth(++depth) - << "" - << newlineAndDepth(++depth); - ret += 3; - } else { - if (IsLastCellInRow(cell)) { - os << newlineAndDepth(--depth) - << "" - << newlineAndDepth(--depth) - << "" - << newlineAndDepth(depth) - << "" - << newlineAndDepth(++depth) - << "" - << newlineAndDepth(++depth); - ret += 4; - } else { - os << newlineAndDepth(--depth) - << "" - << newlineAndDepth(depth) - << "" - << newlineAndDepth(++depth); - ret += 3; - } - } - } - return ret; -} - - bool LyXTabular::IsMultiColumn(int cell, bool real) const { return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) && @@ -2605,7 +2138,6 @@ int LyXTabular::Latex(Buffer const * buf, //+ the single row and columns (cells) + //+--------------------------------------------------------------------- - //int bret; for (int i = 0; i < rows_; ++i) { ret += TeXTopHLine(os, i); int bret = ret; @@ -2638,7 +2170,11 @@ int LyXTabular::Latex(Buffer const * buf, InsetText * inset = GetCellInset(cell); bool rtl = inset->par->isRightToLeftPar(buf->params) && +#ifndef NEW_INSETS inset->par->Last() > 0 && GetPWidth(cell).empty(); +#else + inset->par->size() > 0 && GetPWidth(cell).empty(); +#endif if (rtl) os << "\\R{"; ret += inset->Latex(buf, os, fragile, fp); @@ -2933,7 +2469,7 @@ int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os, else os << " "; - return ret * 0; // eh? (Lgb) + return ret; } @@ -3017,11 +2553,12 @@ void LyXTabular::Validate(LaTeXFeatures & features) const } +#ifndef NEW_INSETS LyXTabular::BoxType LyXTabular::UseParbox(int cell) const { LyXParagraph * par = GetCellInset(cell)->par; - for (; par; par = par->next) { + for (; par; par = par->next_) { for (int i = 0; i < par->Last(); ++i) { if (par->GetChar(i) == LyXParagraph::META_NEWLINE) return BOX_PARBOX; @@ -3029,3 +2566,17 @@ LyXTabular::BoxType LyXTabular::UseParbox(int cell) const } return BOX_NONE; } +#else +LyXTabular::BoxType LyXTabular::UseParbox(int cell) const +{ + LyXParagraph * par = GetCellInset(cell)->par; + + for (; par; par = par->next()) { + for (int i = 0; i < par->size(); ++i) { + if (par->GetChar(i) == LyXParagraph::META_NEWLINE) + return BOX_PARBOX; + } + } + return BOX_NONE; +} +#endif