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)
{
//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";
}

View File

@ -315,9 +315,9 @@ void MathAtom::draw(Painter & pain, int x, int y) const
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());
}

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)
return false;
if (!t)
return 0;
if (!p->nargs())
return false;
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;
}
@ -327,7 +339,7 @@ void MathCursor::last()
void MathCursor::setPos(int x, int y)
{
dump("setPos 1");
//dump("setPos 1");
//lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
macroModeClose();
@ -339,7 +351,7 @@ void MathCursor::setPos(int x, int y)
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);
@ -351,23 +363,21 @@ void MathCursor::setPos(int x, int y)
//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");
}

View File

@ -259,7 +259,7 @@ private:
/// 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

View File

@ -267,6 +267,8 @@ void MathInset::push_back(MathInset *)
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() &&

View File

@ -1,6 +1,5 @@
#include <config.h>
#include "debug.h"
#include "support.h"
#include "support/LOstream.h"
#ifdef __GNUG__
@ -20,92 +19,6 @@ MathInset * MathScriptInset::clone() const
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
{