fix cursor positioning using the mouse

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2724 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-09-11 12:46:58 +00:00
parent d75ce75b25
commit b6113c5b8a
6 changed files with 38 additions and 113 deletions

View File

@ -52,7 +52,7 @@ MathAtom const * MathArray::at(int pos) const
void MathArray::insert(int pos, MathInset * p) void MathArray::insert(int pos, MathInset * p)
{ {
//cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n"; //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n";
// inserting th // inserting here invalidates the pointer!
bf_.insert(begin() + pos, MathAtom(p)); bf_.insert(begin() + pos, MathAtom(p));
//cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n"; //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n";
} }

View File

@ -315,9 +315,9 @@ void MathAtom::draw(Painter & pain, int x, int y) const
if (nucleus()) if (nucleus())
nucleus()->draw(pain, x + dxx(), y); nucleus()->draw(pain, x + dxx(), y);
if (up()) if (up())
up()->xcell(0).draw(pain, x + dx1(), y - dy1()); up()->draw(pain, x + dx1(), y - dy1());
if (down()) if (down())
down()->xcell(0).draw(pain, x + dx0(), y + dy0()); down()->draw(pain, x + dx0(), y + dy0());
} }

View File

@ -232,22 +232,34 @@ bool MathCursor::openable(MathInset * p, bool sel) const
} }
bool MathCursor::positionable(MathInset * p, bool sel) const MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
{ {
if (!p) if (!t)
return false; return 0;
if (!p->nargs()) if (selection_) {
return false;
if (sel) {
// we can't move into anything new during selection // we can't move into anything new during selection
if (Cursor_.size() == Anchor_.size()) if (Cursor_.size() == Anchor_.size())
return false; return 0;
if (p != Anchor_[Cursor_.size()].par_) //if (t != Anchor_[Cursor_.size()].par_)
return false; // 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;
} }
@ -327,7 +339,7 @@ void MathCursor::last()
void MathCursor::setPos(int x, int y) void MathCursor::setPos(int x, int y)
{ {
dump("setPos 1"); //dump("setPos 1");
//lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n"; //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
macroModeClose(); macroModeClose();
@ -339,7 +351,7 @@ void MathCursor::setPos(int x, int y)
while (1) { while (1) {
idx() = -1; idx() = -1;
cursor().pos_ = -1; cursor().pos_ = -1;
//lyxerr << "found idx: " << idx_ << " cursor: " << pos() << "\n"; //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
int distmin = 1 << 30; // large enough int distmin = 1 << 30; // large enough
for (int i = 0; i < par()->nargs(); ++i) { for (int i = 0; i < par()->nargs(); ++i) {
MathXArray const & ar = par()->xcell(i); MathXArray const & ar = par()->xcell(i);
@ -351,23 +363,21 @@ void MathCursor::setPos(int x, int y)
//lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
// << " c: " << c << " xo: " << ar.xo() << "\n"; // << " c: " << c << " xo: " << ar.xo() << "\n";
if (yy + xx <= distmin) { if (yy + xx <= distmin) {
distmin = yy + xx; distmin = yy + xx;
idx() = i; idx() = i;
pos() = c; pos() = c;
} }
} }
//lyxerr << "found idx: " << idx() << " cursor: " //lyxerr << "found idx: " << idx() << " cursor: "
// << pos() << "\n"; // << pos() << "\n";
MathInset * n = nextInset(); if (MathInset * p = positionable(nextAtom(), x, y))
MathInset * p = prevInset(); pushLeft(p);
if (positionable(n, selection_) && n->covers(x, y)) else if (MathInset * p = positionable(prevAtom(), x, y))
pushLeft(n);
else if (positionable(p, selection_) && p->covers(x, y))
pushRight(p); pushRight(p);
else else
break; break;
} }
dump("setPos 2"); //dump("setPos 2");
} }

View File

@ -259,7 +259,7 @@ private:
/// can we enter the inset? /// can we enter the inset?
bool openable(MathInset *, bool selection) const; bool openable(MathInset *, bool selection) const;
/// can the setPos routine enter that inset? /// 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 /// write access to cursor cell position
int & pos(); int & pos();
/// write access to cursor cell index /// write access to cursor cell index

View File

@ -267,6 +267,8 @@ void MathInset::push_back(MathInset *)
bool MathInset::covers(int x, int y) const bool MathInset::covers(int x, int y) const
{ {
//lyxerr << "cover? p: " << this << " x: " << x << " y: " << y
// << " xo_: " << xo_ << " yo_: " << yo_ << endl;
return return
x >= xo_ && x >= xo_ &&
x <= xo_ + width() && x <= xo_ + width() &&

View File

@ -1,6 +1,5 @@
#include <config.h> #include <config.h>
#include "debug.h" #include "debug.h"
#include "support.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#ifdef __GNUG__ #ifdef __GNUG__
@ -20,92 +19,6 @@ MathInset * MathScriptInset::clone() const
return new MathScriptInset(*this); 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 void MathScriptInset::write(std::ostream & os, bool fragile) const
{ {