selection using the mouse should work now. Note: an x is not a y, nor is

a y an x. Even if x's and y's come in disguise as xo's or yo's. Then, an xo
is not a yo nor is a yo a x0.  Aaaargh...


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3047 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-11-20 11:15:18 +00:00
parent a415942e01
commit ef9cb74104
4 changed files with 37 additions and 48 deletions

View File

@ -56,8 +56,8 @@ namespace {
// local global
int sel_x;
int sel_y;
int last_x;
int last_y;
int first_x;
int first_y;
void handleFont(BufferView * bv, MathTextCodes t)
@ -242,10 +242,11 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
int /*x*/, int /*y*/, int /*button*/)
int x, int y, int /*button*/)
{
if (!mathcursor)
return;
//lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
hideInsetCursor(bv);
showInsetCursor(bv);
bv->updateInset(this, false);
@ -255,15 +256,13 @@ void InsetFormulaBase::insetButtonRelease(BufferView * bv,
void InsetFormulaBase::insetButtonPress(BufferView * bv,
int x, int y, int /*button*/)
{
if (!mathcursor)
return;
//lyxerr << "insetButtonPress: " << x + xo_ << " " << y + yo_ << "\n";
sel_x = x + xo_;
sel_y = y + yo_;
last_x = x;
last_y = y;
mathcursor->setPos(x + xo_, y + yo_);
mathcursor->selStart();
first_x = x;
first_y = y;
if (mathcursor) {
mathcursor->selClear();
mathcursor->setPos(x + xo_, y + yo_);
}
bv->updateInset(this, false);
}
@ -274,23 +273,22 @@ void InsetFormulaBase::insetMotionNotify(BufferView * bv,
if (!mathcursor)
return;
if (abs(x - last_x) < 2 && abs(y - last_y) < 2) {
if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
//lyxerr << "insetMotionNotify: ignored\n";
return;
}
last_x = x;
last_y = y;
first_x = x;
first_y = y;
if (!mathcursor->selection())
mathcursor->selStart();
//lyxerr << "insetMotionNotify: " << x + xo_ << " " << y + yo_
//lyxerr << "insetMotionNotify: " << x + xo_ << ' ' << y + yo_
// << ' ' << button << "\n";
if (button == 256) {
hideInsetCursor(bv);
mathcursor->setPos(x + xo_, y + xo_);
showInsetCursor(bv);
bv->updateInset(this, false);
} else {
insetButtonPress(bv, x, y, button);
}
hideInsetCursor(bv);
mathcursor->setPos(x + xo_, y + yo_);
showInsetCursor(bv);
bv->updateInset(this, false);
}

View File

@ -218,12 +218,12 @@ void MathCursor::seldump(char const * str) const
lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
<< str << "\ntheSelection: " << selection_
<< " '" << theSelection.glue() << "'\n";
<< " '" /*<< theSelection.glue()*/ << "'\nCursor:";
for (unsigned int i = 0; i < Cursor_.size(); ++i)
lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
lyxerr << "\n";
lyxerr << Cursor_[i].par_ << "\n'" /*<< Cursor_[i].cell()*/ << "'\n";
lyxerr << "\nAnchor: ";
for (unsigned int i = 0; i < Anchor_.size(); ++i)
lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
lyxerr << Anchor_[i].par_ << "\n'" /*<< Anchor_[i].cell()*/ << "'\n";
//lyxerr << "\ncursor.pos_: " << pos();
//lyxerr << "\nanchor.pos_: " << anchor().pos_;
lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
@ -278,12 +278,14 @@ bool MathCursor::positionable(MathAtom const & t, int x, int y) const
{
if (selection_) {
// we can't move into anything new during selection
if (Cursor_.size() == Anchor_.size())
return 0;
//if (t != Anchor_[Cursor_.size()].par_)
// return 0;
if (Cursor_.size() >= Anchor_.size())
return false;
if (&t != Anchor_[Cursor_.size()].par_)
return false;
}
//lyxerr << " positionable: 1 " << t->nargs() << "\n";
//lyxerr << " positionable: 2 " << t->covers(x, y) << "\n";
return t->nargs() && t->covers(x, y);
}
@ -369,7 +371,7 @@ void MathCursor::last()
}
void MathCursor::setPos(int x, int y, bool respect_anchor)
void MathCursor::setPos(int x, int y)
{
//dump("setPos 1");
//lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
@ -400,25 +402,13 @@ void MathCursor::setPos(int x, int y, bool respect_anchor)
pos() = c;
}
}
//lyxerr << "found idx: " << idx() << " cursor: "
// << pos() << "\n";
//lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
if (hasNextAtom() && positionable(nextAtom(), x, y))
pushLeft(nextAtom());
else if (hasPrevAtom() && positionable(prevAtom(), x, y))
pushRight(prevAtom());
else
break;
if (respect_anchor) {
if (Cursor_.size() > Anchor_.size()) {
popLeft();
break;
}
if (Anchor_[Cursor_.size() - 1].par_ != Cursor_.back().par_) {
popLeft();
break;
}
}
}
//dump("setPos 2");
}
@ -750,7 +740,6 @@ void MathCursor::selHandle(bool sel)
{
if (sel == selection_)
return;
theSelection.clear();
Anchor_ = Cursor_;
selection_ = sel;

View File

@ -110,8 +110,7 @@ public:
///
void delLine();
/// This is in pixels from (maybe?) the top of inset
// don't move further in than the Anchor's inset if respect_anchor == true
void setPos(int x, int y, bool respect_anchor = false);
void setPos(int x, int y);
/// This is in pixels from (maybe?) the top of inset, don't move further
///
void getPos(int & x, int & y);

View File

@ -176,6 +176,9 @@ bool MathNestInset::covers(int x, int y) const
x1 = std::max(x1, xcell(i).xo() + xcell(i).width());
y1 = std::max(y1, xcell(i).yo() + xcell(i).descent());
}
//lyxerr << "xO: " << x0 << " x1: " << x1 << " "
// << "yO: " << y0 << " y1: " << y1 << " "
// << "x: " << x << " y: " << y << '\n';
return x >= x0 && x <= x1 && y >= y0 && y <= y1;
}