]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_nestinset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_nestinset.C
index fc316df70ca69566088d5ddc47a36fd1c3298299..6113621b43f1b8e583467055f433d5dc562c5775 100644 (file)
@@ -3,39 +3,40 @@
 #endif
 
 #include "math_nestinset.h"
+#include "math_mathmlstream.h"
 #include "debug.h"
 
 
-MathNestInset::MathNestInset(unsigned int nargs)
+MathNestInset::MathNestInset(idx_type nargs)
        : MathDimInset(), cells_(nargs)
 {}
 
 
-unsigned int MathNestInset::nargs() const
+MathInset::idx_type MathNestInset::nargs() const
 {
        return cells_.size();
 }
 
 
-MathXArray & MathNestInset::xcell(unsigned int i)
+MathXArray & MathNestInset::xcell(idx_type i)
 {
        return cells_[i];
 }
 
 
-MathXArray const & MathNestInset::xcell(unsigned int i) const
+MathXArray const & MathNestInset::xcell(idx_type i) const
 {
        return cells_[i];
 }
 
 
-MathArray & MathNestInset::cell(unsigned int i)
+MathArray & MathNestInset::cell(idx_type i)
 {
        return cells_[i].data_;
 }
 
 
-MathArray const & MathNestInset::cell(unsigned int i) const
+MathArray const & MathNestInset::cell(idx_type i) const
 {
        return cells_[i].data_;
 }
@@ -43,29 +44,26 @@ MathArray const & MathNestInset::cell(unsigned int i) const
 
 void MathNestInset::substitute(MathMacro const & m)
 {
-       for (unsigned int i = 0; i < nargs(); ++i)
+       for (idx_type i = 0; i < nargs(); ++i)
                cell(i).substitute(m);
 }
 
 
-void MathNestInset::metrics(MathStyles st) const
+void MathNestInset::metrics(MathMetricsInfo const & mi) const
 {
-       size_ = st;
-       for (unsigned int i = 0; i < nargs(); ++i)
-               xcell(i).metrics(st);
+       for (idx_type i = 0; i < nargs(); ++i)
+               xcell(i).metrics(mi);
 }
 
 
 void MathNestInset::draw(Painter & pain, int x, int y) const
 {
-       xo(x);
-       yo(y);
-       for (unsigned int i = 0; i < nargs(); ++i)
+       for (idx_type i = 0; i < nargs(); ++i)
                xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
 }
 
 
-bool MathNestInset::idxNext(unsigned int & idx, unsigned int & pos) const
+bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
 {
        if (idx + 1 >= nargs())
                return false;
@@ -75,13 +73,13 @@ bool MathNestInset::idxNext(unsigned int & idx, unsigned int & pos) const
 }
 
 
-bool MathNestInset::idxRight(unsigned int & idx, unsigned int & pos) const
+bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
 {
        return idxNext(idx, pos);
 }
 
 
-bool MathNestInset::idxPrev(unsigned int & idx, unsigned int & pos) const
+bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
 {
        if (idx == 0)
                return false;
@@ -91,13 +89,13 @@ bool MathNestInset::idxPrev(unsigned int & idx, unsigned int & pos) const
 }
 
 
-bool MathNestInset::idxLeft(unsigned int & idx, unsigned int & pos) const
+bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
 {
        return idxPrev(idx, pos);
 }
 
 
-bool MathNestInset::idxFirst(unsigned int & i, unsigned int & pos) const
+bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
 {
        if (nargs() == 0)
                return false;
@@ -107,7 +105,7 @@ bool MathNestInset::idxFirst(unsigned int & i, unsigned int & pos) const
 }
 
 
-bool MathNestInset::idxLast(unsigned int & i, unsigned int & pos) const
+bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
 {
        if (nargs() == 0)
                return false;
@@ -117,7 +115,7 @@ bool MathNestInset::idxLast(unsigned int & i, unsigned int & pos) const
 }
 
 
-bool MathNestInset::idxHome(unsigned int & /* idx */, unsigned int & pos) const
+bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
 {
        if (pos == 0)
                return false;
@@ -126,12 +124,11 @@ bool MathNestInset::idxHome(unsigned int & /* idx */, unsigned int & pos) const
 }
 
 
-bool MathNestInset::idxEnd(unsigned int & idx, unsigned int & pos) const
+bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
 {
-       unsigned int n = cell(idx).size();
+       pos_type n = cell(idx).size();
        if (pos == n)
                return false;
-
        pos = n;
        return true;
 }
@@ -139,26 +136,36 @@ bool MathNestInset::idxEnd(unsigned int & idx, unsigned int & pos) const
 
 void MathNestInset::dump() const
 {
-       lyxerr << "---------------------------------------------\n";
-       write(lyxerr, false);
-       lyxerr << "\n";
-       for (unsigned int i = 0; i < nargs(); ++i)
-               lyxerr << cell(i) << "\n";
-       lyxerr << "---------------------------------------------\n";
+       WriteStream os(lyxerr);
+       os << "---------------------------------------------\n";
+       write(os);
+       os << "\n";
+       for (idx_type i = 0; i < nargs(); ++i)
+               os << cell(i) << "\n";
+       os << "---------------------------------------------\n";
 }
 
 
-void MathNestInset::push_back(MathInset * p)
+void MathNestInset::validate(LaTeXFeatures & features) const
 {
-       if (nargs())
-               cells_.back().data_.push_back(p);
-       else
-               lyxerr << "can't push without a cell\n";
+       for (idx_type i = 0; i < nargs(); ++i)
+               cell(i).validate(features);
 }
 
 
-void MathNestInset::validate(LaTeXFeatures & features) const
+bool MathNestInset::match(MathInset * p) const
 {
-       for (unsigned int i = 0; i < nargs(); ++i)
-               cell(i).validate(features);
+       if (nargs() != p->nargs())
+               return false;
+       for (idx_type i = 0; i < nargs(); ++i)
+               if (!cell(i).match(p->cell(i)))
+                       return false;
+       return true;
+}
+
+
+void MathNestInset::replace(ReplaceData & rep)
+{
+       for (idx_type i = 0; i < nargs(); ++i)
+               cell(i).replace(rep);
 }