From 6c13215907f27d360bf1dbe2b8cd580e9122df8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 12 Dec 2001 14:05:38 +0000 Subject: [PATCH] more up/down tweaking; remove unneeded functions git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3198 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_cursor.C | 106 ++++++++++------------------------ src/mathed/math_cursor.h | 2 +- src/mathed/math_fracbase.C | 38 +----------- src/mathed/math_fracbase.h | 8 --- src/mathed/math_inset.C | 24 -------- src/mathed/math_inset.h | 8 --- src/mathed/math_scriptinset.C | 40 ------------- src/mathed/math_scriptinset.h | 8 --- 8 files changed, 33 insertions(+), 201 deletions(-) diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 1593aabe12..41d078b512 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -331,30 +331,11 @@ bool positionable(MathCursor::cursor_type const & cursor, void MathCursor::setPos(int x, int y) { - dump("setPos 1"); - cursor_type best_cursor; - double best_dist = 1e10; - - MathIterator it = ibegin(formula()->par().nucleus()); - MathIterator et = iend(formula()->par().nucleus()); - for ( ; it != et; ++it) { - //lyxerr << "*it: " << *it << " *et: " << *et << "\n"; - // avoid invalid nesting hen selecting - if (selection_ && !positionable(it.cursor(), Anchor_)) - continue; - //lyxerr << it.position() << endl; - int xo = it.position().xpos(); - int yo = it.position().ypos(); - double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); - if (d < best_dist) { - best_dist = d; - best_cursor = it.cursor(); - } - } - if (best_dist < 1e10) - Cursor_ = best_cursor; - //lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n"; - lyx::Assert(Cursor_.size()); + dump("setPos 2"); + bool res = bruteFind(x, y, + formula()->xlow(), formula()->xhigh(), + formula()->ylow(), formula()->yhigh()); + lyx::Assert(res); dump("setPos 2"); } @@ -540,27 +521,6 @@ bool MathCursor::up(bool sel) dump("up 1"); macroModeClose(); selHandle(sel); - - if (!selection_) { - MathInset::idx_type i = 0; - MathInset::pos_type p = 0; - - // check whether we could move into the inset - if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) { - pushRight(prevAtom()); - idx() = i; - pos() = p; - return true; - } - - if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) { - pushLeft(nextAtom()); - idx() = i; - pos() = p; - return true; - } - } - cursor_type save = Cursor_; if (goUpDown(true)) return true; @@ -574,27 +534,6 @@ bool MathCursor::down(bool sel) dump("down 1"); macroModeClose(); selHandle(sel); - - if (!selection_) { - MathInset::idx_type i = 0; - MathInset::pos_type p = 0; - - // check whether we could move into the inset - if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) { - pushRight(prevAtom()); - idx() = i; - pos() = p; - return true; - } - - if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) { - pushLeft(nextAtom()); - idx() = i; - pos() = p; - return true; - } - } - cursor_type save = Cursor_; if (goUpDown(false)) return true; @@ -1130,9 +1069,20 @@ MathCursorPos const & MathCursor::cursor() const bool MathCursor::goUpDown(bool up) { - int xo, yo; + int xlow, xhigh, ylow, yhigh; + + int xo, yo; getPos(xo, yo); + // try current cell first + xarray().boundingBox(xlow, xhigh, ylow, yhigh); + if (up) + yhigh = yo - 4; + else + ylow = yo + 4; + if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) + return true; + // try to find an inset that knows better then we while (1) { // we found a cell that think something "below" us. @@ -1145,7 +1095,7 @@ bool MathCursor::goUpDown(bool up) } if (!popLeft()) { - // have reached hull + // no such inset found, just take something "above" return bruteFind(xo, yo, formula()->xlow(), @@ -1155,7 +1105,6 @@ bool MathCursor::goUpDown(bool up) ); } } - int xlow, xhigh, ylow, yhigh; xarray().boundingBox(xlow, xhigh, ylow, yhigh); bruteFind(xo, yo, xlow, xhigh, ylow, yhigh); return true; @@ -1164,20 +1113,20 @@ bool MathCursor::goUpDown(bool up) bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh) { - //lyxerr << "looking at range: " - // << "[" << xlow << "..." << xhigh << "]" - // << " x [" << ylow << "..." << yhigh << "]" - // << " xo: " << x << " yo: " << y << "\n"; - cursor_type best_cursor; double best_dist = 1e10; MathIterator it = ibegin(formula()->par().nucleus()); MathIterator et = iend(formula()->par().nucleus()); for ( ; it != et; ++it) { + // avoid invalid nesting hen selecting + if (selection_ && !positionable(it.cursor(), Anchor_)) + continue; int xo = it.position().xpos(); int yo = it.position().ypos(); - if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { + if (xlow - 2 <= xo && xo <= xhigh + 2 && + ylow - 2 <= yo && yo <= yhigh + 2) + { double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); if (d < best_dist) { best_dist = d; @@ -1414,7 +1363,12 @@ bool MathCursor::interpret(char c) MathCursorPos MathCursor::normalAnchor() const { - lyx::Assert(Anchor_.size() >= Cursor_.size()); + if (Anchor_.size() < Cursor_.size()) { + Anchor_ = Cursor_; + lyxerr << "unusual Anchor size\n"; + dump("1"); + } + //lyx::Assert(Anchor_.size() >= Cursor_.size()); // use Anchor on the same level as Cursor MathCursorPos normal = Anchor_[Cursor_.size() - 1]; if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) { diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 23c4f21308..0a764c16c5 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -216,7 +216,7 @@ public: /// path of positions the cursor had to go if it were leving each inset cursor_type Cursor_; /// path of positions the anchor had to go if it were leving each inset - cursor_type Anchor_; + mutable cursor_type Anchor_; /// reference to the last item of the path, i.e. "The Cursor" MathCursorPos & cursor(); diff --git a/src/mathed/math_fracbase.C b/src/mathed/math_fracbase.C index b1137ac226..2a6ac48d76 100644 --- a/src/mathed/math_fracbase.C +++ b/src/mathed/math_fracbase.C @@ -11,52 +11,18 @@ MathFracbaseInset::MathFracbaseInset() {} -bool MathFracbaseInset::idxRight(MathInset::idx_type &, - MathInset::pos_type &) const +bool MathFracbaseInset::idxRight(idx_type &, pos_type &) const { return false; } -bool MathFracbaseInset::idxLeft(MathInset::idx_type &, - MathInset::pos_type &) const +bool MathFracbaseInset::idxLeft(idx_type &, pos_type &) const { return false; } -bool MathFracbaseInset::idxFirstUp(idx_type & idx, pos_type & pos) const -{ - idx = 0; - pos = 0; - return true; -} - - -bool MathFracbaseInset::idxFirstDown(idx_type & idx, pos_type & pos) const -{ - idx = 1; - pos = 0; - return true; -} - - -bool MathFracbaseInset::idxLastUp(idx_type & idx, pos_type & pos) const -{ - idx = 0; - pos = cell(0).size(); - return true; -} - - -bool MathFracbaseInset::idxLastDown(idx_type & idx, pos_type & pos) const -{ - idx = 1; - pos = cell(1).size(); - return true; -} - - bool MathFracbaseInset::idxUp(idx_type & idx) const { if (idx == 0) diff --git a/src/mathed/math_fracbase.h b/src/mathed/math_fracbase.h index 6fc8e5e1ea..8fff7cfaf3 100644 --- a/src/mathed/math_fracbase.h +++ b/src/mathed/math_fracbase.h @@ -20,14 +20,6 @@ public: bool idxLeft(idx_type &, pos_type &) const; /// bool idxRight(idx_type &, pos_type &) const; - /// - bool idxFirstUp(idx_type &, pos_type &) const; - /// - bool idxFirstDown(idx_type &, pos_type &) const; - /// - bool idxLastUp(idx_type &, pos_type &) const; - /// - bool idxLastDown(idx_type &, pos_type &) const; }; #endif diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 05cf176f12..0ad48f919d 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -124,36 +124,12 @@ bool MathInset::idxFirst(idx_type &, pos_type &) const } -bool MathInset::idxFirstUp(idx_type &, pos_type &) const -{ - return false; -} - - -bool MathInset::idxFirstDown(idx_type &, pos_type &) const -{ - return false; -} - - bool MathInset::idxLast(idx_type &, pos_type &) const { return false; } -bool MathInset::idxLastUp(idx_type &, pos_type &) const -{ - return false; -} - - -bool MathInset::idxLastDown(idx_type &, pos_type &) const -{ - return false; -} - - bool MathInset::idxHome(idx_type &, pos_type &) const { return false; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 17bb6706e4..9e1bbde71f 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -129,16 +129,8 @@ public: /// Target pos when we enter the inset from the left by pressing "Right" virtual bool idxFirst(idx_type & idx, pos_type & pos) const; - /// Target pos when we enter the inset from the left by pressing "Up" - virtual bool idxFirstUp(idx_type & idx, pos_type & pos) const; - /// Target pos when we enter the inset from the left by pressing "Down" - virtual bool idxFirstDown(idx_type & idx, pos_type & pos) const; /// Target pos when we enter the inset from the right by pressing "Left" virtual bool idxLast(idx_type & idx, pos_type & pos) const; - /// Target pos when we enter the inset from the right by pressing "Up" - virtual bool idxLastUp(idx_type & idx, pos_type & pos) const; - /// Target pos when we enter the inset from the right by pressing "Down" - virtual bool idxLastDown(idx_type & idx, pos_type & pos) const; /// Where should we go if we press home? virtual bool idxHome(idx_type & idx, pos_type & pos) const; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index f05ed54b6d..b752716f3a 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -291,46 +291,6 @@ bool MathScriptInset::idxLeft(MathInset::idx_type &, } -bool MathScriptInset::idxFirstUp(idx_type & idx, pos_type & pos) const -{ - if (!hasUp()) - return false; - idx = 1; - pos = 0; - return true; -} - - -bool MathScriptInset::idxFirstDown(idx_type & idx, pos_type & pos) const -{ - if (!hasDown()) - return false; - idx = 0; - pos = 0; - return true; -} - - -bool MathScriptInset::idxLastUp(idx_type & idx, pos_type & pos) const -{ - if (!hasUp()) - return false; - idx = 1; - pos = up().data_.size(); - return true; -} - - -bool MathScriptInset::idxLastDown(idx_type & idx, pos_type & pos) const -{ - if (!hasDown()) - return false; - idx = 0; - pos = down().data_.size(); - return true; -} - - void MathScriptInset::write(WriteStream & os) const { //lyxerr << "unexpected call to MathScriptInset::write()\n"; diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 669e0e9bfd..608ce1fda5 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -44,14 +44,6 @@ public: bool idxLeft(idx_type &, pos_type &) const; /// bool idxRight(idx_type &, pos_type &) const; - /// - bool idxFirstUp(idx_type &, pos_type &) const; - /// - bool idxFirstDown(idx_type &, pos_type &) const; - /// - bool idxLastUp(idx_type &, pos_type &) const; - /// - bool idxLastDown(idx_type &, pos_type &) const; /// identifies scriptinsets MathScriptInset const * asScriptInset() const; -- 2.39.2