]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_gridinset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_gridinset.C
index 9e5f84dc0cd1a4f384c2db3fde2da90533be7d14..d18713b0ec4a754cc2cdaf1acafc775a24ad1969 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "math_gridinset.h"
 #include "math_mathmlstream.h"
+#include "math_streamstr.h"
 #include "lyxfont.h"
 #include "Painter.h"
 #include "debug.h"
@@ -89,6 +90,12 @@ MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
 }
 
 
+MathInset * MathGridInset::clone() const
+{
+       return new MathGridInset(*this);
+}
+
+
 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
 {
        return col + ncols() * row;
@@ -379,7 +386,7 @@ string MathGridInset::eolString(row_type row) const
 {
        string eol;
 
-       if (rowinfo_[row].crskip_.value() != 0)
+       if (!rowinfo_[row].crskip_.zero())
                eol += "[" + rowinfo_[row].crskip_.asLatexString() + "]";
 
        // make sure an upcoming '[' does not break anything
@@ -486,24 +493,20 @@ int MathGridInset::cellYOffset(idx_type idx) const
 }
 
 
-bool MathGridInset::idxUp(idx_type & idx, pos_type & pos) const
+bool MathGridInset::idxUp(idx_type & idx) const
 {
        if (idx < ncols())
                return false;
-       int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
        idx -= ncols();
-       pos = xcell(idx).x2pos(x - cellXOffset(idx));
        return true;
 }
 
        
-bool MathGridInset::idxDown(idx_type & idx, pos_type & pos) const
+bool MathGridInset::idxDown(idx_type & idx) const
 {
        if (idx >= ncols() * (nrows() - 1))
                return false;
-       int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
        idx += ncols();
-       pos = xcell(idx).x2pos(x - cellXOffset(idx));
        return true;
 }
        
@@ -513,7 +516,7 @@ bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
        // leave matrix if on the left hand edge
        if (col(idx) == 0)
                return false;
-       idx--;
+       --idx;
        pos = cell(idx).size();
        return true;
 }
@@ -524,7 +527,7 @@ bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
        // leave matrix if on the right hand edge
        if (col(idx) + 1 == ncols())
                return false;
-       idx++;
+       ++idx;
        pos = 0;
        return true;
 }
@@ -540,7 +543,7 @@ bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
                        idx = (nrows() - 1) * ncols();
                        break;
                default: 
-                       idx = (nrows() / 2) * ncols();
+                       idx = ((nrows() - 1) / 2) * ncols();
        }
        pos = 0;
        return true;
@@ -557,7 +560,7 @@ bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
                        idx = nargs() - 1;
                        break;
                default:
-                       idx = (nrows() / 2 + 1) * ncols() - 1;
+                       idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
        }
        pos = cell(idx).size();
        return true;
@@ -706,13 +709,13 @@ void MathGridInset::mathmlize(MathMLStream & os) const
 void MathGridInset::write(WriteStream & os) const
 {
        for (row_type row = 0; row < nrows(); ++row) {
-               os << verboseHLine(rowinfo_[row].lines_).c_str();
+               os << verboseHLine(rowinfo_[row].lines_);
                for (col_type col = 0; col < ncols(); ++col) 
-                       os << cell(index(row, col)) << eocString(col).c_str();
-               os << eolString(row).c_str();
+                       os << cell(index(row, col)) << eocString(col);
+               os << eolString(row);
        }
-       string s = verboseHLine(rowinfo_[nrows()].lines_);
-       if (s.size())
-               os << "\\\\" << s.c_str();
+       string const s = verboseHLine(rowinfo_[nrows()].lines_);
+       if (!s.empty())
+               os << "\\\\" << s;
 }