]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Fix bug 886 and others not reported related with the document paper size.
[lyx.git] / src / tabular.C
index 21eaa46ad68d1f04482d8ed60da55049aeafb1ba..bde0dc4f78c869bdd83e536433e7396925e72308 100644 (file)
 #include "insets/insettabular.h"
 
 #include "support/lstrings.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include <sstream>
 
 using lyx::support::ltrim;
 using lyx::support::prefixIs;
 using lyx::support::rtrim;
-using lyx::support::strToInt;
 using lyx::support::suffixIs;
 
 using boost::shared_ptr;
@@ -70,36 +69,41 @@ string const write_attribute(string const & name, T const & t)
        return s.empty() ? s : " " + name + "=\"" + s + "\"";
 }
 
+template <>
 string const write_attribute(string const & name, string const & t)
 {
        return t.empty() ? t : " " + name + "=\"" + t + "\"";
 }
 
 
+template <>
 string const write_attribute(string const & name, bool const & b)
 {
        // we write only true attribute values so we remove a bit of the
        // file format bloat for tabulars.
-       return b ? write_attribute(name, tostr(b)) : string();
+       return b ? write_attribute(name, convert<string>(b)) : string();
 }
 
 
+template <>
 string const write_attribute(string const & name, int const & i)
 {
        // we write only true attribute values so we remove a bit of the
        // file format bloat for tabulars.
-       return i ? write_attribute(name, tostr(i)) : string();
+       return i ? write_attribute(name, convert<string>(i)) : string();
 }
 
 
+template <>
 string const write_attribute(string const & name, LyXTabular::idx_type const & i)
 {
        // we write only true attribute values so we remove a bit of the
        // file format bloat for tabulars.
-       return i ? write_attribute(name, tostr(i)) : string();
+       return i ? write_attribute(name, convert<string>(i)) : string();
 }
 
 
+template <>
 string const write_attribute(string const & name, LyXLength const & value)
 {
        // we write only the value if we really have one same reson as above.
@@ -244,7 +248,7 @@ bool getTokenValue(string const & str, char const * token, int & num)
        num = 0;
        if (!getTokenValue(str, token, tmp))
                return false;
-       num = strToInt(tmp);
+       num = convert<int>(tmp);
        return true;
 }
 
@@ -813,7 +817,6 @@ void LyXTabular::recalculateMulticolumnsOfColumn(col_type column)
 }
 
 
-// returns 1 if a complete update is necessary, otherwise 0
 void LyXTabular::setWidthOfCell(idx_type cell, int new_width)
 {
        row_type const row = row_of_cell(cell);
@@ -1199,85 +1202,6 @@ void LyXTabular::write(Buffer const & buf, ostream & os) const
 }
 
 
-void LyXTabular::setHeaderFooterRows(row_type hr, row_type fhr,
-                                     row_type fr, row_type lfr)
-{
-       // set header info
-       while (hr > 0) {
-               row_info[--hr].endhead = true;
-       }
-       // set firstheader info
-       if (fhr && fhr < rows_) {
-               if (row_info[fhr].endhead) {
-                       while (fhr > 0) {
-                               row_info[--fhr].endfirsthead = true;
-                               row_info[fhr].endhead = false;
-                       }
-               } else if (row_info[fhr - 1].endhead) {
-                       endfirsthead.empty = true;
-               } else {
-                       while (fhr > 0 && !row_info[--fhr].endhead) {
-                               row_info[fhr].endfirsthead = true;
-                       }
-               }
-       }
-       // set footer info
-       if (fr && fr < rows_) {
-               if (row_info[fr].endhead && row_info[fr-1].endhead) {
-                       while (fr > 0 && !row_info[--fr].endhead) {
-                               row_info[fr].endfoot = true;
-                               row_info[fr].endhead = false;
-                       }
-               } else if (row_info[fr].endfirsthead && row_info[fr-1].endfirsthead) {
-                       while (fr > 0 && !row_info[--fr].endfirsthead) {
-                               row_info[fr].endfoot = true;
-                               row_info[fr].endfirsthead = false;
-                       }
-               } else if (!row_info[fr - 1].endhead && !row_info[fr - 1].endfirsthead) {
-                       while (fr > 0 && !row_info[--fr].endhead &&
-                                 !row_info[fr].endfirsthead)
-                       {
-                               row_info[fr].endfoot = true;
-                       }
-               }
-       }
-       // set lastfooter info
-       if (lfr && lfr < rows_) {
-               if (row_info[lfr].endhead && row_info[lfr - 1].endhead) {
-                       while (lfr > 0 && !row_info[--lfr].endhead) {
-                               row_info[lfr].endlastfoot = true;
-                               row_info[lfr].endhead = false;
-                       }
-               } else if (row_info[lfr].endfirsthead &&
-                                  row_info[lfr - 1].endfirsthead)
-               {
-                       while (lfr > 0 && !row_info[--lfr].endfirsthead) {
-                               row_info[lfr].endlastfoot = true;
-                               row_info[lfr].endfirsthead = false;
-                       }
-               } else if (row_info[lfr].endfoot
-                          && row_info[lfr - 1].endfoot) {
-                       while (lfr > 0 && !row_info[--lfr].endfoot) {
-                               row_info[lfr].endlastfoot = true;
-                               row_info[lfr].endfoot = false;
-                       }
-               } else if (!row_info[fr - 1].endhead
-                          && !row_info[fr - 1].endfirsthead &&
-                                  !row_info[fr - 1].endfoot)
-               {
-                       while (lfr > 0 &&
-                                 !row_info[--lfr].endhead && !row_info[lfr].endfirsthead &&
-                                 !row_info[lfr].endfoot)
-                       {
-                               row_info[lfr].endlastfoot = true;
-                       }
-               } else if (haveLTFoot()) {
-                       endlastfoot.empty = true;
-               }
-       }
-}
-
-
 void LyXTabular::read(Buffer const & buf, LyXLex & lex)
 {
        string line;
@@ -1310,37 +1234,17 @@ void LyXTabular::read(Buffer const & buf, LyXLex & lex)
        }
        getTokenValue(line, "rotate", rotate);
        getTokenValue(line, "islongtable", is_long_tabular);
-       // compatibility read for old longtable options. Now we can make any
-       // row part of the header/footer type we want before it was strict
-       // sequential from the first row down (as LaTeX does it!). So now when
-       // we find a header/footer line we have to go up the rows and set it
-       // on all preceding rows till the first or one with already a h/f option
-       // set. If we find a firstheader on the same line as a header or a
-       // lastfooter on the same line as a footer then this should be set empty.
-       // (Jug 20011220)
-       if (version < 3) {
-               int hrow;
-               int fhrow;
-               int frow;
-               int lfrow;
-
-               getTokenValue(line, "endhead", hrow);
-               getTokenValue(line, "endfirsthead", fhrow);
-               getTokenValue(line, "endfoot", frow);
-               getTokenValue(line, "endlastfoot", lfrow);
-               setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
-       } else {
-               getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
-               getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
-               getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
-               getTokenValue(line, "headTopDL", endhead.topDL);
-               getTokenValue(line, "headBottomDL", endhead.bottomDL);
-               getTokenValue(line, "footTopDL", endfoot.topDL);
-               getTokenValue(line, "footBottomDL", endfoot.bottomDL);
-               getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
-               getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
-               getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
-       }
+       getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
+       getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
+       getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
+       getTokenValue(line, "headTopDL", endhead.topDL);
+       getTokenValue(line, "headBottomDL", endhead.bottomDL);
+       getTokenValue(line, "footTopDL", endfoot.topDL);
+       getTokenValue(line, "footBottomDL", endfoot.bottomDL);
+       getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
+       getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
+       getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
+
        for (col_type j = 0; j < columns_; ++j) {
                l_getline(is,line);
                if (!prefixIs(line,"<column")) {
@@ -2606,6 +2510,13 @@ shared_ptr<InsetText> LyXTabular::getCellInset(row_type row,
 }
 
 
+void LyXTabular::setCellInset(row_type row, col_type column,
+                             shared_ptr<InsetText> ins) const
+{
+       cell_info[row][column].inset = ins;
+}
+
+
 LyXTabular::idx_type
 LyXTabular::getCellFromInset(InsetBase const * inset) const
 {