X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_matrixinset.C;h=7495df99a8d10010f36283e348cc738610987d20;hb=4590c8cfab02a3bc56813cfb1f2e80bd1119af9e;hp=8ba729f5cc6a14714fd668d589f85952ef11172f;hpb=04a2d2ddb034ebc2eaff92997d078eee5d5805fe;p=lyx.git diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 8ba729f5cc..7495df99a8 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -1,5 +1,9 @@ #include +#ifdef __GNUG__ +#pragma implementation +#endif + #include "math_matrixinset.h" #include "math_rowst.h" #include "math_xiter.h" @@ -11,68 +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_) -{ - array = mt->GetData(); - 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); } @@ -128,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; @@ -198,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) { @@ -221,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(); } }