]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_matrixinset.C
update libtool
[lyx.git] / src / mathed / math_matrixinset.C
index cddfe2566d8e5daf22bc52c11ea12be8bebd0da7..7495df99a8d10010f36283e348cc738610987d20 100644 (file)
@@ -15,66 +15,26 @@ extern int number_of_newlines;
 
 MathMatrixInset::MathMatrixInset(int m, int n, short st)
        : MathParInset(st, "array", LM_OT_MATRIX), nc_(m), nr_(0), ws_(m),
-         v_align_(0), h_align_(nc_, 'c'), row_(0)
+         v_align_(0), h_align_(nc_, 'c')
 {
        flag = 15;
        if (n > 0) {
-               row_ = new MathedRowSt(nc_ + 1);
                MathedXIter it(this);
-               for (int j = 1; j < n; ++j) it.addRow();
+               for (int j = 1; j < n; ++j)
+                       it.addRow();
                nr_ = n;
                if (nr_ == 1 && nc_ > 1) {
                        for (int j = 0; j < nc_ - 1; ++j) 
                                it.insert('T', LM_TC_TAB);
                }
        } else if (n < 0) {
-               row_ = new MathedRowSt(nc_ + 1);
+               MathedXIter it(this);
+               it.addRow();
                nr_ = 1;
        }
 }
 
 
-MathMatrixInset::MathMatrixInset(MathMatrixInset const & mt)
-       : MathParInset(mt.GetStyle(), mt.GetName(), mt.GetType()),
-         nc_(mt.nc_), nr_(0), ws_(mt.nc_),
-         v_align_(mt.v_align_), h_align_(mt.h_align_)
-{
-       array = mt.GetData();
-       if (!mt.row_.empty()) {
-               MathedRowSt * ro = 0;
-               MathedRowSt * mrow = mt.row_.data_;
-
-               while (mrow) {
-                       MathedRowSt * r = new MathedRowSt(nc_ + 1);
-                       r->setNumbered(mrow->isNumbered());
-                       //if (mrow->label) 
-                       r->setLabel(mrow->getLabel());
-                       if (!ro) 
-                               row_ = r;
-                       else
-                               ro->setNext(r);
-                       mrow = mrow->getNext();
-                       ro = r;
-                       ++nr_;
-               }
-       } else   
-               row_ = 0;
-       flag = mt.flag;
-}
-
-
-MathMatrixInset::~MathMatrixInset()
-{
-       MathedRowSt * r = row_.data_;
-       while (r) {
-               MathedRowSt * q = r->getNext();
-               delete r;
-               r = q;
-       }
-}
-
-
-
 MathedInset * MathMatrixInset::Clone()
 {
        return new MathMatrixInset(*this);
@@ -133,11 +93,19 @@ void MathMatrixInset::draw(Painter & pain, int x, int baseline)
 
 void MathMatrixInset::Metrics()
 {
-       if (row_.empty()) {
-               // lyxerr << " MIDA ";
-               MathedXIter it(this);
-               row_ = it.adjustVerticalSt();
-       } 
+       // Adjust row structure
+       MathedXIter it(this);
+       it.GoBegin();
+       int nrows = 1;
+       while (it.OK()) {
+               if (it.IsCR()) {
+                       ++nrows;
+                       if (it.col >= it.ncols)
+                               it.ncols = it.col + 1; 
+               }   
+               it.Next();      
+       }
+       row_.data_.resize(nrows);
        
        // Clean the arrays      
        for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
@@ -184,7 +152,7 @@ void MathMatrixInset::Metrics()
                ascent = h - hl;
                break;
        default:
-               ascent = (row_.data_->getNext()) ? h / 2 : h - hl;
+               ascent = (row_.begin().is_last()) ? h / 2 : h - hl;
                break;
        }
        descent = h - ascent + 2;