fix Herbert's up/down problem

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3795 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-03-21 09:48:46 +00:00
parent 277e305082
commit 74e3712580
12 changed files with 90 additions and 97 deletions

View File

@ -1180,29 +1180,65 @@ bool MathCursor::goUpDown(bool up)
int xo, yo;
getPos(xo, yo);
// try current cell first
xarray().boundingBox(xlow, xhigh, ylow, yhigh);
if (up)
yhigh = yo - 4;
else
ylow = yo + 4;
if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh))
return true;
// try neigbouring script insets
// try left
if (hasPrevAtom()) {
MathScriptInset * p = prevAtom()->asScriptInset();
if (p && p->has(up)) {
--pos();
push(nextAtom());
idx() = up; // the superscript has index 1
pos() = size();
///lyxerr << "updown: handled by scriptinset to the left\n";
return true;
}
}
// try right
if (hasNextAtom()) {
MathScriptInset * p = nextAtom()->asScriptInset();
if (p && p->has(up)) {
push(nextAtom());
idx() = up;
pos() = 0;
///lyxerr << "updown: handled by scriptinset to the right\n";
return true;
}
}
// try current cell
//xarray().boundingBox(xlow, xhigh, ylow, yhigh);
//if (up)
// yhigh = yo - 4;
//else
// ylow = yo + 4;
//if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
// lyxerr << "updown: handled by brute find in the same cell\n";
// return true;
//}
// try to find an inset that knows better then we
while (1) {
// we found a cell that think something "below" us.
if (up) {
if (par()->idxUp(idx()))
break;
} else {
if (par()->idxDown(idx()))
break;
// we found a cell that thinks it has something "below" us.
if (par()->idxUpDown(idx(), up)) {
///lyxerr << "updown: found inset that handles UpDown\n";
xarray().boundingBox(xlow, xhigh, ylow, yhigh);
// project (xo,yo) onto proper box
///lyxerr << "\n xo: " << xo << " yo: " << yo
/// << "\n xlow: " << xlow << " ylow: " << ylow
/// << "\n xhigh: " << xhigh << " yhigh: " << yhigh;
xo = min(max(xo, xlow), xhigh);
yo = min(max(yo, ylow), yhigh);
///lyxerr << "\n xo2: " << xo << " yo2: " << yo << "\n";
bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
///lyxerr << "updown: handled by final brute find\n";
return true;
}
if (!popLeft()) {
// no such inset found, just take something "above"
return
///lyxerr << "updown: handled by strange case\n";
return
bruteFind(xo, yo,
formula()->xlow(),
formula()->xhigh(),
@ -1210,14 +1246,13 @@ bool MathCursor::goUpDown(bool up)
up ? yo - 4 : formula()->yhigh()
);
}
///lyxerr << "updown: looping\n";
}
xarray().boundingBox(xlow, xhigh, ylow, yhigh);
bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
return true;
}
bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
bool MathCursor::bruteFind
(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
cursor_type best_cursor;
double best_dist = 1e10;
@ -1230,9 +1265,7 @@ bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhig
MathCursorPos const & top = it.position();
int xo = top.xpos();
int yo = top.ypos();
if (xlow - 2 <= xo && xo <= xhigh + 2 &&
ylow - 2 <= yo && yo <= yhigh + 2)
{
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
if (d < best_dist) {
best_dist = d;

View File

@ -23,19 +23,11 @@ bool MathFracbaseInset::idxLeft(idx_type &, pos_type &) const
}
bool MathFracbaseInset::idxUp(idx_type & idx) const
bool MathFracbaseInset::idxUpDown(idx_type & idx, bool up) const
{
if (idx == 0)
int target = !up; // up ? 0 : 1, since upper cell has idx 0
if (idx == target)
return false;
idx = 0;
return true;
}
bool MathFracbaseInset::idxDown(idx_type & idx) const
{
if (idx == 1)
return false;
idx = 1;
idx = target;
return true;
}

View File

@ -12,10 +12,8 @@ class MathFracbaseInset : public MathNestInset {
public:
///
MathFracbaseInset();
///
bool idxUp(idx_type &) const;
///
bool idxDown(idx_type &) const;
///
bool idxUpDown(idx_type &, bool up) const;
///
bool idxLeft(idx_type &, pos_type &) const;
///

View File

@ -35,7 +35,7 @@ void MathFracInset::metrics(MathMetricsInfo const & mi) const
smallerStyleFrac(m);
xcell(0).metrics(m);
xcell(1).metrics(m);
width_ = max(xcell(0).width(), xcell(1).width()) + 4;
width_ = max(xcell(0).width(), xcell(1).width()) + 2;
ascent_ = xcell(0).height() + 2 + 5;
descent_ = xcell(1).height() + 2 - 5;
}
@ -47,7 +47,7 @@ void MathFracInset::draw(Painter & pain, int x, int y) const
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 2 - 5);
if (!atop_)
pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::math);
pain.line(x, y - 5, x + width(), y - 5, LColor::math);
}

View File

@ -585,24 +585,22 @@ int MathGridInset::cellYOffset(idx_type idx) const
}
bool MathGridInset::idxUp(idx_type & idx) const
bool MathGridInset::idxUpDown(idx_type & idx, bool up) const
{
if (idx < ncols())
return false;
idx -= ncols();
return true;
if (up) {
if (idx < ncols())
return false;
idx -= ncols();
return true;
} else {
if (idx >= ncols() * (nrows() - 1))
return false;
idx += ncols();
return true;
}
}
bool MathGridInset::idxDown(idx_type & idx) const
{
if (idx >= ncols() * (nrows() - 1))
return false;
idx += ncols();
return true;
}
bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
{
// leave matrix if on the left hand edge

View File

@ -116,9 +116,7 @@ public:
int cellYOffset(idx_type idx) const;
///
bool idxUp(idx_type &) const;
///
bool idxDown(idx_type &) const;
bool idxUpDown(idx_type &, bool) const;
///
bool idxLeft(idx_type &, pos_type &) const;
///

View File

@ -119,13 +119,7 @@ bool MathInset::idxLeft(idx_type &, pos_type &) const
}
bool MathInset::idxUp(idx_type &) const
{
return false;
}
bool MathInset::idxDown(idx_type &) const
bool MathInset::idxUpDown(idx_type &, bool) const
{
return false;
}

View File

@ -122,10 +122,8 @@ public:
/// total height (== ascent + descent)
virtual int height() const;
/// Where should we go when we press the up cursor key?
virtual bool idxUp(idx_type & idx) const;
/// The down key
virtual bool idxDown(idx_type & idx) const;
/// Where should we go when we press the up or down cursor key?
virtual bool idxUpDown(idx_type & idx, bool up) const;
/// The left key
virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
/// The right key

View File

@ -162,17 +162,11 @@ void MathMacro::dump() const
}
bool MathMacro::idxUp(idx_type & idx) const
bool MathMacro::idxUpDown(idx_type & idx, bool up) const
{
pos_type pos;
return MathNestInset::idxLeft(idx, pos);
}
bool MathMacro::idxDown(idx_type & idx) const
{
pos_type pos;
return MathNestInset::idxRight(idx, pos);
return
up ? MathNestInset::idxLeft(idx, pos) : MathNestInset::idxRight(idx, pos);
}

View File

@ -51,9 +51,7 @@ public:
void dump() const;
///
bool idxUp(idx_type &) const;
///
bool idxDown(idx_type &) const;
bool idxUpDown(idx_type &, bool up) const;
///
bool idxLeft(idx_type &, pos_type &) const;
///

View File

@ -71,24 +71,16 @@ void MathRootInset::write(WriteStream & os) const
void MathRootInset::normalize(NormalStream & os) const
{
os << "[root " << cell(1) << ' ' << cell(1) << ']';
os << "[root " << cell(0) << ' ' << cell(1) << ']';
}
bool MathRootInset::idxUp(idx_type & idx) const
bool MathRootInset::idxUpDown(idx_type & idx, bool up) const
{
if (idx == 0)
bool target = !up; // up ? 0 : 1;
if (idx == target)
return false;
idx = 0;
return true;
}
bool MathRootInset::idxDown(idx_type & idx) const
{
if (idx == 1)
return false;
idx = 1;
idx = target;
return true;
}

View File

@ -32,9 +32,7 @@ public:
///
MathInset * clone() const;
///
bool idxUp(idx_type & idx) const;
///
bool idxDown(idx_type & idx) const;
bool idxUpDown(idx_type & idx, bool up) const;
///
void metrics(MathMetricsInfo const & st) const;
///