]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Applied Angus patch to compile on DEC C++ and to avoid name clashes
[lyx.git] / src / tabular.C
index 7f98e397f65ee8ef0a78dfbbbc40ea518e1ae7cb..5f149ce2660bc1ca72a7eee90ba8133aefd410f0 100644 (file)
@@ -40,7 +40,11 @@ using std::max;
 using std::endl;
 using std::vector;
 
-static int const WIDTH_OF_LINE = 5;
+namespace {
+
+int const WIDTH_OF_LINE = 5;
+
+} // namespace
 
 /// Define a few methods for the inner structs
 
@@ -195,6 +199,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 +252,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) {
@@ -1078,9 +1086,11 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const
 }
 
 
+namespace {
+
 // I would have liked a fromstr template a lot better. (Lgb)
 
-static inline
+inline
 bool string2type(string const str, LyXAlignment & num)
 {
     if (str == "none")
@@ -1099,7 +1109,7 @@ bool string2type(string const str, LyXAlignment & num)
 }
 
 
-static inline
+inline
 bool string2type(string const str, LyXTabular::VAlignment & num)
 {
     if (str == "top")
@@ -1114,7 +1124,7 @@ bool string2type(string const str, LyXTabular::VAlignment & num)
 }
 
 
-static inline
+inline
 bool string2type(string const str, LyXTabular::BoxType & num)
 {
     if (str == "none")
@@ -1129,7 +1139,7 @@ bool string2type(string const str, LyXTabular::BoxType & num)
 }
 
 
-static inline
+inline
 bool string2type(string const str, bool & num)
 {
     if (str == "true")
@@ -1142,7 +1152,6 @@ bool string2type(string const str, bool & num)
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token, string & ret)
 {
     size_t token_length = strlen(token);
@@ -1165,7 +1174,6 @@ bool getTokenValue(string const & str, const char * token, string & ret)
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token, int & num)
 {
     string tmp;
@@ -1176,7 +1184,6 @@ bool getTokenValue(string const & str, const char * token, int & num)
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
 {
     string tmp;
@@ -1186,7 +1193,6 @@ bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token,
                   LyXTabular::VAlignment & num)
 {
@@ -1197,7 +1203,6 @@ bool getTokenValue(string const & str, const char * token,
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token,
                   LyXTabular::BoxType & num)
 {
@@ -1208,7 +1213,6 @@ bool getTokenValue(string const & str, const char * token,
 }
 
 
-static
 bool getTokenValue(string const & str, const char * token, bool & flag)
 {
     string tmp;
@@ -1218,14 +1222,19 @@ bool getTokenValue(string const & str, const char * token, bool & flag)
 }    
 
 
-static inline
+inline
 void l_getline(istream & is, string & str)
 {
-    getline(is, str);
-    while(str.empty())
+    str.erase();
+    while (str.empty()) {
        getline(is, str);
+       if (!str.empty() && str[str.length() - 1] == '\r')
+           str.erase(str.length() - 1);
+    }
 }
 
+} // namespace anon
+
 
 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
 {
@@ -1321,20 +1330,20 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is,
                cell_info[i][j].inset.Read(buf, lex);
                l_getline(is, line);
            }
-           if (line != "</cell>") {
+           if (!prefixIs(line, "</cell>")) {
                lyxerr << "Wrong tabular format (expected </cell> got" <<
                    line << ")" << endl;
                return;
            }
        }
        l_getline(is, line);
-       if (line != "</row>") {
+       if (!prefixIs(line, "</row>")) {
            lyxerr << "Wrong tabular format (expected </row> got" <<
                line << ")" << endl;
            return;
        }
     }
-    while (line != "</lyxtabular>") {
+    while (!prefixIs(line, "</lyxtabular>")) {
        l_getline(is, line);
     }
     set_row_column_number_info();
@@ -1344,7 +1353,8 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is,
 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;
@@ -1525,7 +1535,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()) {
@@ -1554,174 +1568,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)
-              << "</ENTRY>"
-              << newlineAndDepth(--depth)
-              << "</ROW>"
-              << newlineAndDepth(--depth)
-              << "</TBODY>"
-              << newlineAndDepth(--depth);
-        if (is_long_tabular)
-               os << "</TGROUP>";
-        else
-               os << "</TGROUP>"
-                  << newlineAndDepth(--depth);
-        ret += 4;
-    } else {
-        if (cell < 0) {
-            // preamble
-            if (is_long_tabular)
-                   os << "<TGROUP ";
-            else
-                   os << "<TGROUP ";
-            os << "COLS='"
-              << columns_
-              << "' COLSEP='1' ROWSEP='1'>"
-              << newlineAndDepth(++depth);
-            ++ret;
-            for (int i = 0; i < columns_; ++i) {
-                   os << "<COLSPEC ALIGN='"
-                      << GetDocBookAlign(i, true)
-                      << "' COLNAME='col"
-                      << i + 1
-                      << "' COLNUM='"
-                      << i + 1
-                      << "' COLSEP='";
-               if (i == (columns_-1)) {
-                      os << '1';
-               } else {
-                   if (column_info[i].right_line ||
-                       column_info[i+1].left_line)
-                          os << '1';
-                   else
-                          os << '0';
-               }
-               os << "'>"
-                 << newlineAndDepth(depth);
-                ++ret;
-#ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
-                if (column_info[i].left_line)
-                       os << '|';
-#endif
-            }
-            os << "<TBODY>"
-              << newlineAndDepth(++depth)
-              << "<ROW>"
-              << newlineAndDepth(++depth)
-              << "<ENTRY ALIGN='"
-              << GetDocBookAlign(0)
-              << "'";
-           if (IsMultiColumn(0)) {
-                  os << " NAMEST='col1' NAMEEND='col"
-                     << cells_in_multicolumn(0)
-                     << "'";
-           }
-          os << ">"
-             << newlineAndDepth(++depth);
-            ret += 3;
-        } else {
-            if (IsLastCellInRow(cell)) {
-                   os << newlineAndDepth(--depth)
-                      << "</ENTRY>"
-                      << newlineAndDepth(--depth)
-                      << "</ROW>"
-                      << newlineAndDepth(depth)
-                      << "<ROW>"
-                      << newlineAndDepth(++depth)
-                      << "<ENTRY ALIGN='"
-                      << GetDocBookAlign(cell + 1)
-                      << "' VALIGN='middle'";
-               if (IsMultiColumn(cell + 1)) {
-                      os << " NAMEST='col"
-                         << column_of_cell(cell + 1) + 1
-                         << "' NAMEEND='col"
-                         << column_of_cell(cell + 1) +
-                              cells_in_multicolumn(cell + 1)
-                         << "'";
-               }
-               os << ">"
-                 << newlineAndDepth(++depth);
-                ret += 4;
-            } else {
-                   os << newlineAndDepth(--depth)
-                      << "</ENTRY>"
-                      << newlineAndDepth(depth)
-                      << "<ENTRY ALIGN='"
-                      << GetDocBookAlign(cell + 1)
-                      << "' VALIGN='middle'";
-               if (IsMultiColumn(cell + 1)) {
-                      os << " NAMEST='col"
-                         << column_of_cell(cell + 1) + 1
-                         << "' NAMEEND='col"
-                         << column_of_cell(cell + 1) +
-                              cells_in_multicolumn(cell + 1)
-                         << "'";
-               }
-               os << ">"
-                 << 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))) &&
@@ -2136,6 +1993,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
            if (LeftLine(cell))
                os << '|';
            if (!GetPWidth(cell).empty()) {
+#warning Jürgen, are these alignments correct? (Lgb)
                switch (GetVAlignment(cell)) {
                case LYX_VALIGN_TOP:
                    os << "p";
@@ -2186,6 +2044,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
     } else if (GetUsebox(cell) == BOX_MINIPAGE) {
        os << "\\begin{minipage}[";
        switch (GetVAlignment(cell)) {
+#warning Jürgen, are these alignments correct? (Lgb)
        case LYX_VALIGN_TOP:
            os << "t";
            break;
@@ -2250,6 +2109,7 @@ int LyXTabular::Latex(Buffer const * buf,
            os << column_info[i].align_special;
        } else if (!column_info[i].p_width.empty()) {
            switch (column_info[i].valignment) {
+#warning Jürgen, are these alignments correct? (Lgb)
            case LYX_VALIGN_TOP:
                os << "p";
                break;
@@ -2318,7 +2178,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);
@@ -2468,13 +2332,16 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
 }
 
 
-static
+namespace {
+
 inline
 void print_n_chars(ostream & os, unsigned char ch, int n)
 {
        os << string(n, ch);
 }
 
+} // namespace anon
+
 
 int LyXTabular::AsciiTopHLine(ostream & os, int row,
                              vector<unsigned int> const & clen) const
@@ -2613,8 +2480,7 @@ int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
     else
        os << "  ";
 
-#warning What is this supposed to do? (Lgb)
-    return ret * 0; // eh? (Lgb)
+    return ret;
 }
 
 
@@ -2690,7 +2556,7 @@ void LyXTabular::Validate(LaTeXFeatures & features) const
         features.longtable = true;
     if (NeedRotating())
        features.rotating = true;
-    for (int cell = 0; cell < numberofcells; ++cell) {
+    for (int cell = 0; !features.array && (cell < numberofcells); ++cell) {
        if (GetVAlignment(cell) != LYX_VALIGN_TOP)
            features.array = true;
        GetCellInset(cell)->Validate(features);
@@ -2698,11 +2564,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;
@@ -2710,3 +2577,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