static int const MAX_STACK_ITEMS = 32;
struct MathStackXIter {
- int i, imax;
- MathedXIter * item;
+ std::vector<MathedXIter> 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() {
}
MathedXIter * pop() {
- --i;
- return &item[i - 1];
+ return &item[--i];
}
MathedXIter * Item(int idx) {
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 ---------------------------***/
if (!cursor->Next() && !Pop())
break;
}
- if (x-xp < cursor->GetX()-x) cursor->ipop();
+ if (x - xp < cursor->GetX() - x)
+ cursor->ipop();
cursor->Adjust();
}
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);
{
lyxerr[Debug::MATHED] << "Clearing sel " << endl;
selection = false;
- delete selstk;
- selstk = 0;
anchor = 0;
}
// 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
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();
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;
} 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);
{
int posx = pos;
GoBegin();
- while (posx > pos && OK()) Next();
+ while (posx > pos && OK())
+ Next();
}
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
<< cx << ']' << endl;
break;
}
- if (pos < pos2) Next();
+ if (pos < pos2)
+ Next();
}
width = x_ - x1;
}