void MathArray::insert(int pos, MathInset * p)
{
//cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
- // inserting th
+ // inserting here invalidates the pointer!
bf_.insert(begin() + pos, MathAtom(p));
//cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
}
if (nucleus())
nucleus()->draw(pain, x + dxx(), y);
if (up())
- up()->xcell(0).draw(pain, x + dx1(), y - dy1());
+ up()->draw(pain, x + dx1(), y - dy1());
if (down())
- down()->xcell(0).draw(pain, x + dx0(), y + dy0());
+ down()->draw(pain, x + dx0(), y + dy0());
}
}
-bool MathCursor::positionable(MathInset * p, bool sel) const
+MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
{
- if (!p)
- return false;
-
- if (!p->nargs())
- return false;
+ if (!t)
+ return 0;
- if (sel) {
+ if (selection_) {
// we can't move into anything new during selection
if (Cursor_.size() == Anchor_.size())
- return false;
- if (p != Anchor_[Cursor_.size()].par_)
- return false;
+ return 0;
+ //if (t != Anchor_[Cursor_.size()].par_)
+ // return 0;
}
- return true;
+
+ MathInset * p;
+
+ p = t->nucleus();
+ if (p && p->nargs() && p->covers(x, y))
+ return p;
+
+ p = t->up();
+ if (p && p->nargs() && p->covers(x, y))
+ return p;
+
+ p = t->down();
+ if (p && p->nargs() && p->covers(x, y))
+ return p;
+
+ return 0;
}
void MathCursor::setPos(int x, int y)
{
- dump("setPos 1");
+ //dump("setPos 1");
//lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
macroModeClose();
while (1) {
idx() = -1;
cursor().pos_ = -1;
- //lyxerr << "found idx: " << idx_ << " cursor: " << pos() << "\n";
+ //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
int distmin = 1 << 30; // large enough
for (int i = 0; i < par()->nargs(); ++i) {
MathXArray const & ar = par()->xcell(i);
//lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
// << " c: " << c << " xo: " << ar.xo() << "\n";
if (yy + xx <= distmin) {
- distmin = yy + xx;
- idx() = i;
- pos() = c;
+ distmin = yy + xx;
+ idx() = i;
+ pos() = c;
}
}
//lyxerr << "found idx: " << idx() << " cursor: "
// << pos() << "\n";
- MathInset * n = nextInset();
- MathInset * p = prevInset();
- if (positionable(n, selection_) && n->covers(x, y))
- pushLeft(n);
- else if (positionable(p, selection_) && p->covers(x, y))
+ if (MathInset * p = positionable(nextAtom(), x, y))
+ pushLeft(p);
+ else if (MathInset * p = positionable(prevAtom(), x, y))
pushRight(p);
else
break;
}
- dump("setPos 2");
+ //dump("setPos 2");
}
/// can we enter the inset?
bool openable(MathInset *, bool selection) const;
/// can the setPos routine enter that inset?
- bool positionable(MathInset *, bool selection) const;
+ MathInset * positionable(MathAtom *, int x, int y) const;
/// write access to cursor cell position
int & pos();
/// write access to cursor cell index
bool MathInset::covers(int x, int y) const
{
+ //lyxerr << "cover? p: " << this << " x: " << x << " y: " << y
+ // << " xo_: " << xo_ << " yo_: " << yo_ << endl;
return
x >= xo_ &&
x <= xo_ + width() &&
#include <config.h>
#include "debug.h"
-#include "support.h"
#include "support/LOstream.h"
#ifdef __GNUG__
return new MathScriptInset(*this);
}
-#if 0
-
-bool MathScriptInset::idxUp(int & idx, int & pos) const
-{
- if (idx == 0 || !up())
- return false;
- idx = 0;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxDown(int & idx, int & pos) const
-{
- if (idx == 1 || !down())
- return false;
- idx = 1;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxFirst(int & idx, int & pos) const
-{
- idx = up() ? 0 : 1;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxLast(int & idx, int & pos) const
-{
- idx = down() ? 1 : 0;
- pos = cell(idx).size();
- return true;
-}
-
-
-bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
-{
- if (!up())
- return false;
- idx = 0;
- pos = 0;
- return true;
-}
-
-
-bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
-{
- if (!down())
- return false;
- idx = 1;
- pos = 0;
- return true;
-}
-
-
-bool MathScriptInset::idxLastUp(int & idx, int & pos) const
-{
- if (!up())
- return false;
- idx = 0;
- pos = cell(idx).size();
- return true;
-}
-
-
-bool MathScriptInset::idxLastDown(int & idx, int & pos) const
-{
- if (!down())
- return false;
- idx = 1;
- pos = cell(idx).size();
- return true;
-}
-
-void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
-{
- if (idx == 0)
- up(false);
- else
- down(false);
- popit = true;
- deleteit = !(up() || down());
-}
-
-#endif
-
void MathScriptInset::write(std::ostream & os, bool fragile) const
{