From 7d2c9440e74368554d820d4c1fff22dddbd22e93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 9 Mar 2001 08:45:10 +0000 Subject: [PATCH] mathed51.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1721 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 8 +++++++ src/mathed/math_cursor.C | 51 ++++++++++++---------------------------- src/mathed/math_rowst.h | 10 ++++++++ src/mathed/math_xiter.C | 34 ++++++++++----------------- 4 files changed, 46 insertions(+), 57 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index bf4db3ce13..c1f3ee1593 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,11 @@ +2001-03-09 André Pönitz + * math_cursor.C: use std::vector<> in MathStackXIter + change selstk from a pointer to the "real thing" + + * math_rowst.h: new MathedRowContainer::erase method + + * math_xiter.C: use MathedRowContainer::erase + 2001-03-08 André Pönitz * math_rowst.h: give MathedRowContainer an 'insert' method. diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 06dce67971..81aba8a6a2 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -66,18 +66,11 @@ bool IsMacro(short tok, int id) static int const MAX_STACK_ITEMS = 32; struct MathStackXIter { - int i, imax; - MathedXIter * item; + std::vector item; + int i; - MathStackXIter(int n = MAX_STACK_ITEMS): imax(n) { - item = new MathedXIter[imax]; - i = 0; - } - - MathStackXIter(MathStackXIter & stk); - - ~MathStackXIter() { - delete[] item; + MathStackXIter(int n = MAX_STACK_ITEMS) + : item(n), i(0) { } MathedXIter * push() { @@ -85,8 +78,7 @@ struct MathStackXIter { } MathedXIter * pop() { - --i; - return &item[i - 1]; + return &item[--i]; } MathedXIter * Item(int idx) { @@ -107,21 +99,9 @@ struct MathStackXIter { int Level() { return i; } -} mathstk, *selstk = 0; +} mathstk, selstk; -MathStackXIter::MathStackXIter(MathStackXIter & stk) -{ - imax = stk.imax; - item = new MathedXIter[imax]; - i = stk.i; - for (int k = 0; k < i; ++k) { - item[k].SetData(stk.item[k].getPar()); - item[k].GoBegin(); - item[k].goPosAbs(stk.item[k].getPos()); - } -} - /***---------------- Mathed Cursor ---------------------------***/ @@ -351,7 +331,8 @@ void MathedCursor::SetPos(int x, int y) if (!cursor->Next() && !Pop()) break; } - if (x-xp < cursor->GetX()-x) cursor->ipop(); + if (x - xp < cursor->GetX() - x) + cursor->ipop(); cursor->Adjust(); } @@ -962,8 +943,8 @@ void MathedCursor::SelStart() lyxerr[Debug::MATHED] << "Starting sel " << endl; if (!anchor) { selpos = cursor->getPos(); - selstk = new MathStackXIter(mathstk); - anchor = selstk->Item(-1); + selstk = mathstk; + anchor = selstk.Item(-1); anchor->SetData(cursor->getPar()); anchor->GoBegin(); anchor->goPosAbs(selpos); @@ -976,8 +957,6 @@ void MathedCursor::SelClear() { lyxerr[Debug::MATHED] << "Clearing sel " << endl; selection = false; - delete selstk; - selstk = 0; anchor = 0; } @@ -986,21 +965,21 @@ void MathedCursor::SelClear() // Anchor position must be at the same level that stack. void MathedCursor::SelBalance() { - int d = mathstk.Level() - selstk->Level(); + int d = mathstk.Level() - selstk.Level(); // If unbalanced, balance them while (d != 0) { if (d < 0) { - // lyxerr << "b[" << mathstk.Level() << " " << selstk->Level + // lyxerr << "b[" << mathstk.Level() << " " << selstk.Level // << " " << anchor->GetX() << " " << cursor->GetX() << "]"; - anchor = selstk->pop(); + anchor = selstk.pop(); if (anchor->GetX() >= cursor->GetX()) anchor->Next(); } else { - // lyxerr <<"a[" << mathstk.Level() << " " << selstk->Level() <<"]"; + // lyxerr <<"a[" << mathstk.Level() << " " << selstk.Level() <<"]"; Pop(); } - d = mathstk.Level() - selstk->Level(); + d = mathstk.Level() - selstk.Level(); } // Once balanced the levels, check that they are at the same paragraph diff --git a/src/mathed/math_rowst.h b/src/mathed/math_rowst.h index ea6c16d037..3b1c7f24ba 100644 --- a/src/mathed/math_rowst.h +++ b/src/mathed/math_rowst.h @@ -174,6 +174,16 @@ struct MathedRowContainer { } } + void erase(iterator & it) { + Assert(it.st_); + MathedRowSt * r = it.st_->next_; + if (r) { + it.st_->next_ = r->next_; + delete r; + } + } + + /// MathedRowSt * data_; diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index d2204c1113..d242a58081 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -123,16 +123,8 @@ void MathedXIter::Clean(int pos2) delete inset; continue; } - if (IsCR()) { - if (crow_) { - MathedRowContainer::iterator r = crow_; - ++r; - if (r) { - crow_.st_->next_ = r.st_->next_; - delete r.st_; - } - } - } + if (IsCR() && crow_) + container().erase(crow_); Next(); } ipop(); @@ -216,14 +208,16 @@ string const MathedXIter::GetString() const bool MathedXIter::Next() { // lyxerr << "Ne[" << pos << "]"; - if (!OK()) return false; + if (!OK()) + return false; int w = 0; // lyxerr << "xt "; if (IsInset()) { MathedInset * px = GetInset(); w = px->Width(); if (px->GetType() == LM_OT_SCRIPT) { - if (w > sw_) sw_ = w; + if (w > sw_) + sw_ = w; w = 0; } else sx_ = (px->GetLimits()) ? w : 0; @@ -240,7 +234,7 @@ bool MathedXIter::Next() } else if (c == LM_TC_CR && p_) { x_ = 0; - if (crow_ && crow_.st_->next_) { + if (crow_ && !crow_.is_last()) { ++crow_; y_ = crow_->getBaseline(); w = crow_->getTab(0); @@ -291,7 +285,8 @@ void MathedXIter::Adjust() { int posx = pos; GoBegin(); - while (posx > pos && OK()) Next(); + while (posx > pos && OK()) + Next(); } @@ -408,16 +403,12 @@ void MathedXIter::delRow() line_empty = false; } } while (Next()); + int const p1 = getPos(); ipop(); if (line_empty) { - - MathedRowContainer::iterator r( crow_.st_->next_ ); - if (r) { - crow_.st_->next_ = r.st_->next_; - delete r.st_; - } + container().erase(crow_); join(p1); Delete(); } else @@ -551,7 +542,8 @@ void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent) << cx << ']' << endl; break; } - if (pos < pos2) Next(); + if (pos < pos2) + Next(); } width = x_ - x1; } -- 2.39.2