better handling of up/down

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3123 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-11-30 14:40:38 +00:00
parent 1567c6cd6f
commit 5049e123be
3 changed files with 48 additions and 25 deletions

View File

@ -1167,18 +1167,8 @@ bool MathCursor::goUp()
}
// if not, apply brute force.
int x0;
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
y0 -= xarray().ascent();
for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() < y0)
return true;
}
Cursor_ = save;
return false;
return
bruteUpDown(formula()->upperY() + 24, xarray().yo() - 4 - xarray().ascent());
}
@ -1198,19 +1188,42 @@ bool MathCursor::goDown()
return true;
}
// does the inset know
// if not, apply brute force.
return
bruteUpDown(xarray().yo() + 4 + xarray().descent(), formula()->lowerY());
}
bool MathCursor::bruteUpDown(int ylow, int yhigh)
{
//lyxerr << "looking at range: " << ylow << " " << yhigh << "\n";
int x0;
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
y0 += xarray().descent();
for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
std::vector<MathCursorPos> best;
double best_dist = 1e10; // large enough
bool found = false;
for (int y = ylow; y < yhigh; y += 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() > y0)
int x1;
int y1;
getPos(x1, y1);
if (save != Cursor_ && y1 > ylow && y1 < yhigh) {
found = true;
double d = (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);
if (d < best_dist) {
best_dist = d;
best = Cursor_;
}
}
}
if (found) {
Cursor_ = best;
return true;
}
Cursor_ = save;
return false;
}

View File

@ -67,6 +67,8 @@ public:
typedef MathInset::row_type row_type;
/// type for column numbers
typedef MathInset::col_type col_type;
/// how to store a cursor
typedef std::vector<MathCursorPos> cursor_type;
///
explicit MathCursor(InsetFormulaBase *, bool left);
@ -229,9 +231,9 @@ public:
MathCursorPos normalAnchor() const;
/// path of positions the cursor had to go if it were leving each inset
std::vector<MathCursorPos> Cursor_;
cursor_type Cursor_;
/// path of positions the anchor had to go if it were leving each inset
std::vector<MathCursorPos> Anchor_;
cursor_type Anchor_;
/// reference to the last item of the path
MathCursorPos & cursor();
@ -261,6 +263,8 @@ private:
bool goUp();
/// moves position somehow down
bool goDown();
/// moves position somehow down
bool bruteUpDown(int ylow, int yhigh);
///
string macroName() const;

View File

@ -488,23 +488,29 @@ int MathGridInset::cellYOffset(idx_type idx) const
bool MathGridInset::idxUp(idx_type & idx, pos_type & pos) const
{
return false;
/*
if (idx < ncols())
return false;
int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
idx -= ncols();
pos = xcell(idx).x2pos(x - cellXOffset(idx));
return true;
*/
}
bool MathGridInset::idxDown(idx_type & idx, pos_type & pos) const
{
return false;
/*
if (idx >= ncols() * (nrows() - 1))
return false;
int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
idx += ncols();
pos = xcell(idx).x2pos(x - cellXOffset(idx));
return true;
*/
}