]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / tabular.C
index 259f93bcf397dcf591e95cf6e703bcb54364ae74..1aaff8e3788de6be51ac1064135af0828375a511 100644 (file)
@@ -84,6 +84,13 @@ string const write_attribute(string const & name, string const & t)
 }
 
 
+template <>
+string const write_attribute(string const & name, docstring const & t)
+{
+       return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\"";
+}
+
+
 template <>
 string const write_attribute(string const & name, bool const & b)
 {
@@ -250,6 +257,15 @@ bool getTokenValue(string const & str, char const * token, string & ret)
 }
 
 
+bool getTokenValue(string const & str, char const * token, docstring & ret)
+{
+       string tmp;
+       bool const success = getTokenValue(str, token, tmp);
+       ret = from_utf8(tmp);
+       return success;
+}
+
+
 bool getTokenValue(string const & str, char const * token, int & num)
 {
        string tmp;
@@ -499,7 +515,6 @@ void LyXTabular::appendRow(BufferParams const & bp, idx_type const cell)
                swap(cell_info[i], old[i - 1]);
 
        if (bp.trackChanges)
-               // FIXME: Change Tracking (MG)
                for (col_type j = 0; j < columns_; ++j)
                        cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED));
 
@@ -528,7 +543,6 @@ void LyXTabular::copyRow(BufferParams const & bp, row_type const row)
        cell_info.insert(cell_info.begin() + row, cell_info[row]);
 
        if (bp.trackChanges)
-               // FIXME: Change Tracking (MG)
                for (col_type j = 0; j < columns_; ++j)
                        cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED));
 
@@ -560,7 +574,6 @@ void LyXTabular::appendColumn(BufferParams const & bp, idx_type const cell)
        //++column;
        for (row_type i = 0; i < rows_; ++i) {
                cell_info[i][column + 1].inset->clear();
-               // FIXME: Change Tracking (MG)
                if (bp.trackChanges)
                        cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED));
        }
@@ -592,7 +605,6 @@ void LyXTabular::copyColumn(BufferParams const & bp, col_type const column)
                cell_info[i].insert(cell_info[i].begin() + column, cell_info[i][column]);
 
        if (bp.trackChanges)
-               // FIXME: Change Tracking (MG)
                for (row_type i = 0; i < rows_; ++i)
                        cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED));
        fixCellNums();
@@ -666,55 +678,55 @@ LyXTabular::idx_type LyXTabular::numberOfCellsInRow(idx_type const cell) const
 }
 
 
-bool LyXTabular::topLine(idx_type const cell, bool const onlycolumn) const
+bool LyXTabular::topLine(idx_type const cell, bool const wholerow) const
 {
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholerow && isMultiColumn(cell) &&
            !(use_booktabs && row_of_cell(cell) == 0))
                return cellinfo_of_cell(cell).top_line;
        return row_info[row_of_cell(cell)].top_line;
 }
 
 
-bool LyXTabular::bottomLine(idx_type const cell, bool onlycolumn) const
+bool LyXTabular::bottomLine(idx_type const cell, bool wholerow) const
 {
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholerow && isMultiColumn(cell) &&
            !(use_booktabs && isLastRow(cell)))
                return cellinfo_of_cell(cell).bottom_line;
        return row_info[row_of_cell(cell)].bottom_line;
 }
 
 
-bool LyXTabular::leftLine(idx_type cell, bool onlycolumn) const
+bool LyXTabular::leftLine(idx_type cell, bool wholecolumn) const
 {
        if (use_booktabs)
                return false;
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholecolumn && isMultiColumn(cell) &&
                (isFirstCellInRow(cell) || isMultiColumn(cell-1)))
        {
                if (cellinfo_of_cell(cell).align_special.empty())
                        return cellinfo_of_cell(cell).left_line;
-               return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), "|");
+               return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), '|');
        }
        if (column_info[column_of_cell(cell)].align_special.empty())
                return column_info[column_of_cell(cell)].left_line;
-       return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), "|");
+       return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), '|');
 }
 
 
-bool LyXTabular::rightLine(idx_type cell, bool onlycolumn) const
+bool LyXTabular::rightLine(idx_type cell, bool wholecolumn) const
 {
        if (use_booktabs)
                return false;
-       if (!onlycolumn && isMultiColumn(cell) &&
+       if (!wholecolumn && isMultiColumn(cell) &&
                (isLastCellInRow(cell) || isMultiColumn(cell + 1)))
        {
                if (cellinfo_of_cell(cell).align_special.empty())
                        return cellinfo_of_cell(cell).right_line;
-               return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), "|");
+               return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), '|');
        }
        if (column_info[column_of_cell(cell)].align_special.empty())
                return column_info[right_column_of_cell(cell)].right_line;
-       return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), "|");
+       return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), '|');
 }
 
 
@@ -1010,7 +1022,7 @@ bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell,
 }
 
 
-void LyXTabular::setAlignSpecial(idx_type cell, string const & special,
+void LyXTabular::setAlignSpecial(idx_type cell, docstring const & special,
                                 LyXTabular::Feature what)
 {
        if (what == SET_SPECIAL_MULTI)
@@ -1029,37 +1041,37 @@ void LyXTabular::setAllLines(idx_type cell, bool line)
 }
 
 
-void LyXTabular::setTopLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setTopLine(idx_type cell, bool line, bool wholerow)
 {
        row_type const row = row_of_cell(cell);
-       if (onlycolumn || !isMultiColumn(cell))
+       if (wholerow || !isMultiColumn(cell))
                row_info[row].top_line = line;
        else
                cellinfo_of_cell(cell).top_line = line;
 }
 
 
-void LyXTabular::setBottomLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setBottomLine(idx_type cell, bool line, bool wholerow)
 {
-       if (onlycolumn || !isMultiColumn(cell))
+       if (wholerow || !isMultiColumn(cell))
                row_info[row_of_cell(cell)].bottom_line = line;
        else
                cellinfo_of_cell(cell).bottom_line = line;
 }
 
 
-void LyXTabular::setLeftLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setLeftLine(idx_type cell, bool line, bool wholecolumn)
 {
-       if (onlycolumn || !isMultiColumn(cell))
+       if (wholecolumn || !isMultiColumn(cell))
                column_info[column_of_cell(cell)].left_line = line;
        else
                cellinfo_of_cell(cell).left_line = line;
 }
 
 
-void LyXTabular::setRightLine(idx_type cell, bool line, bool onlycolumn)
+void LyXTabular::setRightLine(idx_type cell, bool line, bool wholecolumn)
 {
-       if (onlycolumn || !isMultiColumn(cell))
+       if (wholecolumn || !isMultiColumn(cell))
                column_info[right_column_of_cell(cell)].right_line = line;
        else
                cellinfo_of_cell(cell).right_line = line;
@@ -1105,7 +1117,7 @@ LyXLength const LyXTabular::getMColumnPWidth(idx_type cell) const
 }
 
 
-string const LyXTabular::getAlignSpecial(idx_type cell, int what) const
+docstring const LyXTabular::getAlignSpecial(idx_type cell, int what) const
 {
        if (what == SET_SPECIAL_MULTI)
                return cellinfo_of_cell(cell).align_special;
@@ -1911,8 +1923,7 @@ int LyXTabular::TeXCellPreamble(odocstream & os, idx_type cell) const
        if (isMultiColumn(cell)) {
                os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
                if (!cellinfo_of_cell(cell).align_special.empty()) {
-                       os << from_ascii(cellinfo_of_cell(cell).align_special)
-                          << "}{";
+                       os << cellinfo_of_cell(cell).align_special << "}{";
                } else {
                        if (leftLine(cell) &&
                                (isFirstCellInRow(cell) ||
@@ -2125,6 +2136,7 @@ int LyXTabular::TeXRow(odocstream & os, row_type i, Buffer const & buf,
                        os << "\\addlinespace\n";
                else
                        os << "\\noalign{\\vskip\\doublerulesep}\n";
+               ++ret;
        } else if(!row_info[i].top_space.zero()) {
                if (use_booktabs)
                        os << "\\addlinespace["
@@ -2182,6 +2194,7 @@ int LyXTabular::TeXRow(odocstream & os, row_type i, Buffer const & buf,
                        os << "\\addlinespace\n";
                else
                        os << "\\noalign{\\vskip\\doublerulesep}\n";
+               ++ret;
        } else if (!row_info[i].interline_space.zero()) {
                if (use_booktabs)
                        os << "\\addlinespace["
@@ -2216,7 +2229,7 @@ int LyXTabular::latex(Buffer const & buf, odocstream & os,
                os << "\\begin{tabular}{";
        for (col_type i = 0; i < columns_; ++i) {
                if (!column_info[i].align_special.empty()) {
-                       os << from_ascii(column_info[i].align_special);
+                       os << column_info[i].align_special;
                } else {
                        if (!use_booktabs && column_info[i].left_line)
                                os << '|';
@@ -2442,8 +2455,8 @@ int LyXTabular::docbook(Buffer const & buf, odocstream & os,
 }
 
 
-int LyXTabular::asciiTopHLine(odocstream & os, row_type row,
-                             vector<unsigned int> const & clen) const
+bool LyXTabular::plaintextTopHLine(odocstream & os, row_type row,
+                                   vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
        idx_type const n = numberOfCellsInRow(fcell) + fcell;
@@ -2456,7 +2469,7 @@ int LyXTabular::asciiTopHLine(odocstream & os, row_type row,
                }
        }
        if (!tmp)
-               return 0;
+               return false;
 
        char_type ch;
        for (idx_type i = fcell; i < n; ++i) {
@@ -2486,12 +2499,12 @@ int LyXTabular::asciiTopHLine(odocstream & os, row_type row,
                }
        }
        os << endl;
-       return 1;
+       return true;
 }
 
 
-int LyXTabular::asciiBottomHLine(odocstream & os, row_type row,
-                                vector<unsigned int> const & clen) const
+bool LyXTabular::plaintextBottomHLine(odocstream & os, row_type row,
+                                      vector<unsigned int> const & clen) const
 {
        idx_type const fcell = getFirstCellInRow(row);
        idx_type const n = numberOfCellsInRow(fcell) + fcell;
@@ -2504,7 +2517,7 @@ int LyXTabular::asciiBottomHLine(odocstream & os, row_type row,
                }
        }
        if (!tmp)
-               return 0;
+               return false;
 
        char_type ch;
        for (idx_type i = fcell; i < n; ++i) {
@@ -2534,22 +2547,22 @@ int LyXTabular::asciiBottomHLine(odocstream & os, row_type row,
                }
        }
        os << endl;
-       return 1;
+       return true;
 }
 
 
-int LyXTabular::asciiPrintCell(Buffer const & buf, odocstream & os,
+void LyXTabular::plaintextPrintCell(Buffer const & buf, odocstream & os,
                               OutputParams const & runparams,
                               idx_type cell, row_type row, col_type column,
                               vector<unsigned int> const & clen,
                               bool onlydata) const
 {
        odocstringstream sstr;
-       int const ret = getCellInset(cell)->plaintext(buf, sstr, runparams);
+       getCellInset(cell)->plaintext(buf, sstr, runparams);
 
        if (onlydata) {
                os << sstr.str();
-               return ret;
+               return;
        }
 
        if (leftLine(cell))
@@ -2586,18 +2599,13 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, odocstream & os,
                os << " |";
        else
                os << "  ";
-
-       return ret;
 }
 
 
-int LyXTabular::plaintext(Buffer const & buf, odocstream & os,
-                     OutputParams const & runparams,
-                     int const depth,
-                     bool onlydata, unsigned char delim) const
+void LyXTabular::plaintext(Buffer const & buf, odocstream & os,
+                           OutputParams const & runparams, int const depth,
+                           bool onlydata, unsigned char delim) const
 {
-       int ret = 0;
-
        // first calculate the width of the single columns
        vector<unsigned int> clen(columns_);
 
@@ -2634,25 +2642,24 @@ int LyXTabular::plaintext(Buffer const & buf, odocstream & os,
        }
        idx_type cell = 0;
        for (row_type i = 0; i < rows_; ++i) {
-               if (!onlydata && asciiTopHLine(os, i, clen))
+               if (!onlydata && plaintextTopHLine(os, i, clen))
                        os << docstring(depth * 2, ' ');
                for (col_type j = 0; j < columns_; ++j) {
                        if (isPartOfMultiColumn(i, j))
                                continue;
                        if (onlydata && j > 0)
                                os << delim;
-                       ret += asciiPrintCell(buf, os, runparams,
-                                             cell, i, j, clen, onlydata);
+                       plaintextPrintCell(buf, os, runparams,
+                                          cell, i, j, clen, onlydata);
                        ++cell;
                }
                os << endl;
                if (!onlydata) {
                        os << docstring(depth * 2, ' ');
-                       if (asciiBottomHLine(os, i, clen))
+                       if (plaintextBottomHLine(os, i, clen))
                                os << docstring(depth * 2, ' ');
                }
        }
-       return ret;
 }