mathed51.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1721 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-03-09 08:45:10 +00:00
parent b95e8f250d
commit 7d2c9440e7
4 changed files with 46 additions and 57 deletions

View File

@ -1,3 +1,11 @@
2001-03-09 André Pönitz <poenitz@htwm.de>
* 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 <poenitz@htwm.de>
* math_rowst.h: give MathedRowContainer an 'insert' method.

View File

@ -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<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() {
@ -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

View File

@ -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_;

View File

@ -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;
}