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

View File

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

View File

@ -110,8 +110,7 @@ public:
/// ///
void delLine(); void delLine();
/// This is in pixels from (maybe?) the top of inset /// 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);
void setPos(int x, int y, bool respect_anchor = false);
/// This is in pixels from (maybe?) the top of inset, don't move further /// This is in pixels from (maybe?) the top of inset, don't move further
/// ///
void getPos(int & x, int & y); 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()); x1 = std::max(x1, xcell(i).xo() + xcell(i).width());
y1 = std::max(y1, xcell(i).yo() + xcell(i).descent()); 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; return x >= x0 && x <= x1 && y >= y0 && y <= y1;
} }