]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.C
cursor is no more damaging the background. L-shaped cursor is broken right now....
[lyx.git] / src / mathed / InsetMathGrid.C
index 8c160fc63961ba36078bd0485311020cd285990b..7d52295604e65a423b2f47da8766ffb3e8395dec 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "InsetMathGrid.h"
 #include "MathData.h"
-#include "MathMLStream.h"
 #include "MathStream.h"
 
 #include "BufferView.h"
 
 #include <sstream>
 
-using lyx::support::bformat;
+
+namespace lyx {
+
+using support::bformat;
 
 using std::endl;
 using std::max;
@@ -59,12 +61,12 @@ public:
        ///
        virtual string const inset2string(Buffer const &) const
        {
-               lyx::odocstringstream data;
+               odocstringstream data;
                //data << name() << " active_cell " << inset.getActCell() << '\n';
-               data << lyx::from_utf8(name()) << " active_cell " << 0 << '\n';
+               data << from_utf8(name()) << " active_cell " << 0 << '\n';
                WriteStream ws(data);
                inset_.write(ws);
-               return lyx::to_utf8(data.str());
+               return to_utf8(data.str());
        }
 
 protected:
@@ -77,9 +79,9 @@ void mathed_parse_normal(InsetMathGrid &, string const & argument);
 
 namespace {
 
-string verboseHLine(int n)
+docstring verboseHLine(int n)
 {
-       string res;
+       docstring res;
        for (int i = 0; i < n; ++i)
                res += "\\hline";
        if (n)
@@ -135,7 +137,7 @@ InsetMathGrid::ColInfo::ColInfo()
 //////////////////////////////////////////////////////////////
 
 
-InsetMathGrid::InsetMathGrid(char v, string const & h)
+InsetMathGrid::InsetMathGrid(char v, docstring const & h)
        : InsetMathNest(guessColumns(h)),
          rowinfo_(2),
          colinfo_(guessColumns(h) + 1),
@@ -170,7 +172,7 @@ InsetMathGrid::InsetMathGrid(col_type m, row_type n)
 }
 
 
-InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, string const & h)
+InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h)
        : InsetMathNest(m * n),
          rowinfo_(n + 1),
          colinfo_(m + 1),
@@ -215,18 +217,18 @@ void InsetMathGrid::setDefaults()
 }
 
 
-void InsetMathGrid::halign(string const & hh)
+void InsetMathGrid::halign(docstring const & hh)
 {
        col_type col = 0;
-       for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
-               char c = *it;
+       for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
+               char_type c = *it;
                if (c == '|') {
                        colinfo_[col].lines_++;
                } else if (col >= ncols()) {
                        // Only '|' is allowed in the last dummy column
                        break;
                } else if (c == 'c' || c == 'l' || c == 'r') {
-                       colinfo_[col].align_ = c;
+                       colinfo_[col].align_ = (char)c;
                        ++col;
                        colinfo_[col].lines_ = 0;
                } else {
@@ -244,10 +246,10 @@ void InsetMathGrid::halign(string const & hh)
 }
 
 
-InsetMathGrid::col_type InsetMathGrid::guessColumns(string const & hh) const
+InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
 {
        col_type col = 0;
-       for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
+       for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
                if (*it == 'c' || *it == 'l' || *it == 'r')
                        ++col;
        // let's have at least one column, even if we did not recognize its
@@ -270,14 +272,14 @@ char InsetMathGrid::halign(col_type col) const
 }
 
 
-string InsetMathGrid::halign() const
+docstring InsetMathGrid::halign() const
 {
-       string res;
+       docstring res;
        for (col_type col = 0; col < ncols(); ++col) {
-               res += string(colinfo_[col].lines_, '|');
+               res += docstring(colinfo_[col].lines_, '|');
                res += colinfo_[col].align_;
        }
-       return res + string(colinfo_[ncols()].lines_, '|');
+       return res + docstring(colinfo_[ncols()].lines_, '|');
 }
 
 
@@ -605,12 +607,12 @@ void InsetMathGrid::drawT(TextPainter & pain, int x, int y) const
 }
 
 
-string InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
+docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
 {
-       string eol;
+       docstring eol;
 
        if (!rowinfo_[row].crskip_.zero())
-               eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
+               eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
 
        // make sure an upcoming '[' does not break anything
        if (row + 1 < nrows()) {
@@ -622,17 +624,17 @@ string InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) cons
 
        // only add \\ if necessary
        if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
-               return string();
+               return docstring();
 
        return (fragile ? "\\protect\\\\" : "\\\\") + eol;
 }
 
 
-string InsetMathGrid::eocString(col_type col, col_type lastcol) const
+docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
 {
        if (col + 1 == lastcol)
-               return string();
-       return " & ";
+               return docstring();
+       return from_ascii(" & ");
 }
 
 
@@ -935,7 +937,7 @@ void InsetMathGrid::normalize(NormalStream & os) const
 }
 
 
-void InsetMathGrid::mathmlize(MathMLStream & os) const
+void InsetMathGrid::mathmlize(MathStream & os) const
 {
        os << MTag("mtable");
        for (row_type row = 0; row < nrows(); ++row) {
@@ -950,7 +952,7 @@ void InsetMathGrid::mathmlize(MathMLStream & os) const
 
 void InsetMathGrid::write(WriteStream & os) const
 {
-       string eol;
+       docstring eol;
        for (row_type row = 0; row < nrows(); ++row) {
                os << verboseHLine(rowinfo_[row].lines_);
                // don't write & and empty cells at end of line
@@ -970,7 +972,7 @@ void InsetMathGrid::write(WriteStream & os) const
                if (!emptyline && row + 1 < nrows())
                        os << "\n";
        }
-       string const s = verboseHLine(rowinfo_[nrows()].lines_);
+       docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
        if (!s.empty()) {
                if (eol.empty()) {
                        if (os.fragile())
@@ -1111,8 +1113,8 @@ void InsetMathGrid::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_TABULAR_FEATURE: {
                recordUndoInset(cur);
-               //lyxerr << "handling tabular-feature " << lyx::to_utf8(cmd.argument()) << endl;
-               istringstream is(lyx::to_utf8(cmd.argument()));
+               //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
+               istringstream is(to_utf8(cmd.argument()));
                string s;
                is >> s;
                if (s == "valign-top")
@@ -1204,14 +1206,14 @@ void InsetMathGrid::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_PASTE: {
                cur.message(_("Paste"));
-               lyx::cap::replaceSelection(cur);
-               istringstream is(lyx::to_utf8(cmd.argument()));
+               cap::replaceSelection(cur);
+               istringstream is(to_utf8(cmd.argument()));
                int n = 0;
                is >> n;
                InsetMathGrid grid(1, 1);
                // FIXME UNICODE
                mathed_parse_normal(grid,
-                       lyx::to_utf8(lyx::cap::getSelection(cur.buffer(), n)));
+                       to_utf8(lyx::cap::getSelection(cur.buffer(), n)));
                if (grid.nargs() == 1) {
                        // single cell/part of cell
                        recordUndo(cur);
@@ -1300,16 +1302,16 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
 {
        switch (cmd.action) {
        case LFUN_TABULAR_FEATURE: {
-               string const s = lyx::to_utf8(cmd.argument());
+               string const s = to_utf8(cmd.argument());
                if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
                        status.enabled(false);
-                       status.message(lyx::from_utf8(N_("Only one row")));
+                       status.message(from_utf8(N_("Only one row")));
                        return true;
                }
                if (ncols() <= 1 &&
                    (s == "delete-column" || s == "swap-column")) {
                        status.enabled(false);
-                       status.message(lyx::from_utf8(N_("Only one column")));
+                       status.message(from_utf8(N_("Only one column")));
                        return true;
                }
                if ((rowinfo_[cur.row()].lines_ == 0 &&
@@ -1317,7 +1319,7 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
                    (rowinfo_[cur.row() + 1].lines_ == 0 &&
                     s == "delete-hline-below")) {
                        status.enabled(false);
-                       status.message(lyx::from_utf8(N_("No hline to delete")));
+                       status.message(from_utf8(N_("No hline to delete")));
                        return true;
                }
 
@@ -1326,7 +1328,7 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
                    (colinfo_[cur.col() + 1].lines_ == 0 &&
                     s == "delete-vline-right")) {
                        status.enabled(false);
-                       status.message(lyx::from_utf8(N_("No vline to delete")));
+                       status.message(from_utf8(N_("No vline to delete")));
                        return true;
                }
                if (s == "valign-top" || s == "valign-middle" ||
@@ -1344,7 +1346,7 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
                else {
                        status.enabled(false);
                        status.message(bformat(
-                               lyx::from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
+                               from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
                }
 
                status.setOnOff(s == "align-left"    && halign(cur.col()) == 'l'
@@ -1366,7 +1368,7 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
                        status.enable(false);
                        break;
                }
-               if (!lyx::support::contains("tcb", cmd.argument()[0])) {
+               if (!support::contains("tcb", cmd.argument()[0])) {
                        status.enable(false);
                        break;
                }
@@ -1389,3 +1391,6 @@ bool InsetMathGrid::getStatus(LCursor & cur, FuncRequest const & cmd,
                return InsetMathNest::getStatus(cur, cmd, status);
        }
 }
+
+
+} // namespace lyx