Fix for the 'spurious selection with RMB' and improved 'cursor up/down'

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5416 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-10-15 16:17:40 +00:00
parent fe2ea80ac9
commit c2771dd61f
6 changed files with 62 additions and 19 deletions

View File

@ -297,7 +297,8 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
BufferView * bv = cmd.view();
hideInsetCursor(bv);
showInsetCursor(bv);
bv->updateInset(this, false);
bv->updateInset(this, true);
//lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << "\n";
if (cmd.button() == mouse_button::button3) {
// try to dispatch to enclosed insets first
@ -336,6 +337,12 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
BufferView * bv = cmd.view();
releaseMathCursor(bv);
mathcursor = new MathCursor(this, cmd.x == 0);
//lyxerr << "lfunMousePress: buttons: " << cmd.button() << "\n";
if (cmd.button() == mouse_button::button3) {
mathcursor->dispatch(cmd);
return DISPATCHED;
}
if (cmd.button() == mouse_button::button1) {
// just set the cursor here
@ -349,12 +356,6 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
return DISPATCHED;
}
if (cmd.button() == mouse_button::button3) {
mathcursor->dispatch(cmd);
//delete mathcursor;
return DISPATCHED;
}
bv->updateInset(this, false);
return DISPATCHED;
}
@ -368,10 +369,13 @@ Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
return DISPATCHED;
if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2) {
//lyxerr << "insetMotionNotify: ignored\n";
// only select with button 1
if (cmd.button() != mouse_button::button1)
return DISPATCHED;
}
if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
return DISPATCHED;
first_x = cmd.x;
first_y = cmd.y;

View File

@ -262,7 +262,8 @@ void MathCursor::last()
}
bool positionable(MathIterator const & cursor, MathIterator const & anchor)
bool positionable
(MathIterator const & cursor, MathIterator const & anchor)
{
// avoid deeper nested insets when selecting
if (cursor.size() > anchor.size())
@ -1003,8 +1004,12 @@ bool MathCursor::goUpDown(bool up)
while (1) {
///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
// ask inset first
if (par()->idxUpDown(idx(), pos(), up, targetx_))
if (par()->idxUpDown(idx(), pos(), up, targetx_)) {
// try to find best position within this inset
if (!selection())
bruteFind2(xo, yo);
return true;
}
// no such inset found, just take something "above"
///lyxerr << "updown: handled by strange case\n";
@ -1061,6 +1066,31 @@ bool MathCursor::bruteFind
}
void MathCursor::bruteFind2(int x, int y)
{
double best_dist = 1e10;
MathIterator it = Cursor_;
it.back().setPos(0);
MathIterator et = Cursor_;
et.back().setPos(it.cell().size());
while (1) {
int xo, yo;
it.back().getPos(xo, yo);
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
// '<=' in order to take the last possible position
// this is important for clicking behind \sum in e.g. '\sum_i a'
if (d <= best_dist) {
best_dist = d;
Cursor_ = it;
}
if (it == et)
break;
++it;
}
}
bool MathCursor::idxLineLast()
{
idx() -= idx() % par()->ncols();

View File

@ -260,12 +260,13 @@ private:
bool posRight();
/// moves position somehow up or down
bool goUpDown(bool up);
/// moves position into box
bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
/// moves position closest to (x, y) in given box
bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
/// moves position closest to (x, y) in current cell
void bruteFind2(int x, int y);
/// are we in a nucleus of a script inset?
bool inNucleus() const;
/// grab grid marked by anchor and current cursor
MathGridInset grabSelection() const;
/// erase the selected part and re-sets the cursor
@ -273,9 +274,9 @@ private:
/// guess what
MathGridInset grabAndEraseSelection();
///
/// the name of the macro we are currently inputting
string macroName() const;
///
/// where in the curent cell does the macro name start?
MathInset::difference_type macroNamePos() const;
/// can we enter the inset?
bool openable(MathAtom const &, bool selection) const;

View File

@ -77,8 +77,8 @@ void MathIterator::goEnd()
void MathIterator::operator++()
{
MathCursorPos & top = back();
MathArray & ar = top.par_->cell(top.idx_);
MathCursorPos & top = back();
MathArray & ar = top.par_->cell(top.idx_);
// move into the current inset if possible
// it is impossible for pos() == size()!

View File

@ -44,6 +44,12 @@ void MathCursorPos::getPos(int & x, int & y) const
}
void MathCursorPos::setPos(MathArray::pos_type pos)
{
pos_ = pos;
}
std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
{
os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";

View File

@ -23,6 +23,8 @@ public:
MathArray & cell(MathArray::idx_type idx) const;
/// gets screen position of the thing
void getPos(int & x, int & y) const;
/// set position
void setPos(MathArray::pos_type pos);
public:
/// pointer to an inset