]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_matrixinset.C
update libtool
[lyx.git] / src / mathed / math_matrixinset.C
index 8a58205f2477c52e430b5c0b28d7855467fff10a..7495df99a8d10010f36283e348cc738610987d20 100644 (file)
@@ -1,5 +1,9 @@
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "math_matrixinset.h"
 #include "math_rowst.h"
 #include "math_xiter.h"
@@ -11,70 +15,29 @@ 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 * 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_)
-{
-       MathedIter it;
-       it.SetData(mt->GetData());
-       array = it.Copy();
-       if (mt->row_ != 0) {
-               MathedRowSt * ro = 0;
-               MathedRowSt * mrow = mt->row_;
-
-               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_;
-       while (r) {
-               MathedRowSt * q = r->getNext();
-               delete r;
-               r = q;
-       }
-}
-
-
 MathedInset * MathMatrixInset::Clone()
 {
-       return new MathMatrixInset(this);
+       return new MathMatrixInset(*this);
 }
 
 
@@ -86,10 +49,11 @@ void MathMatrixInset::SetAlign(char vv, string const & hh)
 
 
 // Check the number of tabs and crs
-void MathMatrixInset::setData(MathedArray * a)
+void MathMatrixInset::setData(MathedArray const & a)
 {
-       if (!a) return;
-       MathedIter it(a);
+       array = a;
+
+       MathedIter it(&array);
        int nn = nc_ - 1;
        nr_ = 1;
        // count tabs per row
@@ -117,7 +81,6 @@ void MathMatrixInset::setData(MathedArray * a)
        
        // Automatically inserts tabs around bops
        // DISABLED because it's very easy to insert tabs 
-       array = a;
 }
 
 
@@ -130,62 +93,66 @@ void MathMatrixInset::draw(Painter & pain, int x, int baseline)
 
 void MathMatrixInset::Metrics()
 {
-       if (!row_) {
-               // 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      
-       MathedRowSt * cxrow = row_;
-       while (cxrow) {   
+       for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
                for (int i = 0; i <= nc_; ++i)
-                       cxrow->setTab(i, 0);
-               cxrow = cxrow->getNext();
-       }
+                       it->setTab(i, 0);
        
        // Basic metrics
        MathParInset::Metrics();
-       
-       if (nc_ <= 1 && !row_->getNext()) {
-               row_->ascent(ascent);
-               row_->descent(descent);
+
+       MathedRowContainer::iterator cxrow = row_.begin();
+       if (nc_ <= 1 && cxrow.is_last()) {
+               cxrow->ascent(ascent);
+               cxrow->descent(descent);
        }
        
        // Vertical positions of each row
-       cxrow = row_;     
-       MathedRowSt * cprow = 0;
+       MathedRowContainer::iterator cprow = cxrow;
        int h = 0;
-       while (cxrow) {
+       for ( ; cxrow; ++cxrow) {
                for (int i = 0; i < nc_; ++i) {
-                       if (cxrow == row_ || ws_[i] < cxrow->getTab(i))
+                       if (cxrow == row_.begin() || ws_[i] < cxrow->getTab(i))
                                ws_[i] = cxrow->getTab(i);
-                       if (cxrow->getNext() == 0 && ws_[i] == 0)
+                       if (cxrow.is_last() && ws_[i] == 0)
                                ws_[i] = df_width;
                }
                
-               cxrow->setBaseline((cxrow == row_) ?
+               cxrow->setBaseline((cxrow == row_.begin()) ?
                                   cxrow->ascent() :
                                   cxrow->ascent() + cprow->descent()
                                   + MATH_ROWSEP + cprow->getBaseline());
                h += cxrow->ascent() + cxrow->descent() + MATH_ROWSEP;  
                cprow = cxrow;
-               cxrow = cxrow->getNext();
        }
        
-       int hl = Descent();
+       int const hl = Descent();
        h -= MATH_ROWSEP;
        
        //  Compute vertical align
        switch (v_align_) {
        case 't':
-               ascent = row_->getBaseline();
+               ascent = row_.begin()->getBaseline();
                break;
        case 'b':
                ascent = h - hl;
                break;
        default:
-               ascent = (row_->getNext()) ? h / 2 : h - hl;
+               ascent = (row_.begin().is_last()) ? h / 2 : h - hl;
                break;
        }
        descent = h - ascent + 2;
@@ -200,9 +167,8 @@ void MathMatrixInset::Metrics()
                        ws_[0] = 7 * workWidth / 8;
        
        // Adjust local tabs
-       cxrow = row_;
        width = MATH_COLSEP;
-       while (cxrow) {   
+       for (cxrow = row_.begin(); cxrow; ++cxrow) {   
                int rg = MATH_COLSEP;
                int lf = 0;
                for (int i = 0; i < nc_; ++i) {
@@ -223,22 +189,21 @@ void MathMatrixInset::Metrics()
                                lf = ws_[i] - cxrow->getTab(i);
                                break;
                        case 'C':
-                               if (cxrow == row_)
+                               if (cxrow == row_.begin())
                                        lf = 0;
-                               else if (!cxrow->getNext())
+                               else if (cxrow.is_last())
                                        lf = ws_[i] - cxrow->getTab(i);
                                else
                                        lf = (ws_[i] - cxrow->getTab(i))/2; 
                                break;
                        }
-                       int ww = (isvoid) ? lf : lf + cxrow->getTab(i);
+                       int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
                        cxrow->setTab(i, lf + rg);
                        rg = ws_[i] - ww + MATH_COLSEP;
-                       if (cxrow == row_)
+                       if (cxrow == row_.begin())
                                width += ws_[i] + MATH_COLSEP;
                }
                cxrow->setBaseline(cxrow->getBaseline() - ascent);
-               cxrow = cxrow->getNext();
        }
 }