From ef9cb74104a464e6484fe819329cee9d3c6c706e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 20 Nov 2001 11:15:18 +0000 Subject: [PATCH] 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 --- src/mathed/formulabase.C | 44 ++++++++++++++++++------------------- src/mathed/math_cursor.C | 35 ++++++++++------------------- src/mathed/math_cursor.h | 3 +-- src/mathed/math_nestinset.C | 3 +++ 4 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 4ad563632d..48b3041e00 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 274b8bf522..a6055f5e79 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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; diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 3aa02de956..dd305bb4fd 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 09d8116767..e12664d3f8 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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; } -- 2.39.2