From d37fae169ceb695bb36089ff7552fd18fae2af7e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 13 Oct 2006 16:44:44 +0000 Subject: [PATCH] In order to support multiple LyXView each BufferView needs its own CoordCache. This is what's implemented in this commit. theCoords is now a thing of the past and all CoordCache accesses are done via BufferView::coordCache() now. I had to modify a number of methods to pass BufferView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15324 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 9 ++++---- src/BufferView.h | 11 ++++++++- src/bufferview_funcs.C | 9 ++++---- src/bufferview_funcs.h | 2 +- src/coordcache.C | 2 -- src/coordcache.h | 2 -- src/cursor.C | 12 ++++++---- src/insets/inset.C | 5 ++-- src/insets/insetbase.C | 26 ++++++++++----------- src/insets/insetbase.h | 6 ++--- src/insets/insettabular.C | 16 ++++++------- src/insets/insettabular.h | 4 ++-- src/mathed/InsetMathDim.C | 7 ++++-- src/mathed/InsetMathGrid.C | 2 +- src/mathed/InsetMathNest.C | 37 +++++++++++++++++------------- src/mathed/InsetMathScript.C | 2 +- src/mathed/MathData.C | 44 ++++++++++++++++++++++++------------ src/mathed/MathData.h | 13 ++++++----- src/rowpainter.C | 12 +++++----- src/rowpainter.h | 2 +- src/text.C | 20 ++++++++-------- src/text2.C | 24 ++++++++++---------- 22 files changed, 151 insertions(+), 116 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 1a2314885c..b566000067 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -103,7 +103,6 @@ using std::vector; namespace Alert = lyx::frontend::Alert; - namespace { unsigned int const saved_positions_num = 20; @@ -335,7 +334,7 @@ bool BufferView::fitCursor() theFontMetrics(cursor_.getFont()); int const asc = fm.maxAscent(); int const des = fm.maxDescent(); - Point const p = bv_funcs::getPos(cursor_, cursor_.boundary()); + Point const p = bv_funcs::getPos(*this, cursor_, cursor_.boundary()); if (p.y_ - asc >= 0 && p.y_ + des < height_) return false; } @@ -491,7 +490,7 @@ void BufferView::setCursorFromScrollbar() cur.clearSelection(); break; case bv_funcs::CUR_INSIDE: - int const y = bv_funcs::getPos(cur, cur.boundary()).y_; + int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_; int const newy = min(last, max(y, first)); if (y != newy) { cur.reset(buffer_->inset()); @@ -1261,7 +1260,7 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo() void BufferView::updateMetrics(bool singlepar) { // Remove old position cache - theCoords.clear(); + coord_cache_.clear(); LyXText & buftext = buffer_->text(); lyx::pit_type size = int(buftext.paragraphs().size()); @@ -1325,7 +1324,7 @@ void BufferView::updateMetrics(bool singlepar) // The coordinates of all these paragraphs are correct, cache them int y = y1; - CoordCache::InnerParPosCache & parPos = theCoords.parPos()[&buftext]; + CoordCache::InnerParPosCache & parPos = coord_cache_.parPos()[&buftext]; for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) { Paragraph const & par = buftext.getPar(pit); y += par.ascent(); diff --git a/src/BufferView.h b/src/BufferView.h index 9825e8fbc5..53fcf3a696 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -15,6 +15,7 @@ #ifndef BUFFER_VIEW_H #define BUFFER_VIEW_H +#include "coordcache.h" #include "cursor.h" #include "metricsinfo.h" @@ -199,6 +200,14 @@ public: /// void updateMetrics(bool singlepar = false); + /// + CoordCache & coordCache() { + return coord_cache_; + } + /// + CoordCache const & coordCache() const { + return coord_cache_; + } /// get this view's keyboard map handler Intl & getIntl() { return *intl_.get(); } /// @@ -238,7 +247,7 @@ private: /// ViewMetricsInfo metrics_info_; - + CoordCache coord_cache_; /// Buffer * buffer_; diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 48dbad0357..b5cdfd0d48 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -198,12 +198,12 @@ Point coordOffset(DocIterator const & dit, bool boundary) } -Point getPos(DocIterator const & dit, bool boundary) +Point getPos(BufferView & bv, DocIterator const & dit, bool boundary) { CursorSlice const & bot = dit.bottom(); CoordCache::ParPosCache::const_iterator cache_it = - theCoords.getParPos().find(bot.text()); - if (cache_it == theCoords.getParPos().end()) + bv.coordCache().getParPos().find(bot.text()); + if (cache_it == bv.coordCache().getParPos().end()) return Point(-1, -1); CoordCache::InnerParPosCache const & cache = cache_it->second; @@ -221,7 +221,8 @@ Point getPos(DocIterator const & dit, bool boundary) // this could be used elsewhere as well? CurStatus status(BufferView const * bv, DocIterator const & dit) { - CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(dit.bottom().text())->second; + CoordCache::InnerParPosCache const & cache = + bv->coordCache().getParPos().find(dit.bottom().text())->second; if (cache.find(dit.bottom().pit()) != cache.end()) return CUR_INSIDE; diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 7cd3f17be4..aaa2400af1 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -37,7 +37,7 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle); */ std::string const freefont2string(); -Point getPos(DocIterator const & dit, bool boundary); +Point getPos(BufferView & bv, DocIterator const & dit, bool boundary); enum CurStatus { CUR_INSIDE, diff --git a/src/coordcache.C b/src/coordcache.C index ecfffec949..262aaa7d8a 100644 --- a/src/coordcache.C +++ b/src/coordcache.C @@ -19,8 +19,6 @@ #include -CoordCache theCoords; - // just a helper to be able to set a breakpoint void lyxbreaker(void const * data, const char * hint, int size) { diff --git a/src/coordcache.h b/src/coordcache.h index 535a712716..1d49a1aa8f 100644 --- a/src/coordcache.h +++ b/src/coordcache.h @@ -150,6 +150,4 @@ private: SliceCache slices1_; }; -extern CoordCache theCoords; - #endif diff --git a/src/cursor.C b/src/cursor.C index a2990d05be..6920dd6e5d 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -98,7 +98,7 @@ namespace { int xo; int yo; InsetBase const * inset = &it.inset(); - Point o = theCoords.getInsets().xy(inset); + Point o = c.bv().coordCache().getInsets().xy(inset); inset->cursorPos(it.top(), c.boundary(), xo, yo); // Convert to absolute xo += o.x_; @@ -126,8 +126,10 @@ namespace { { BOOST_ASSERT(!cursor.empty()); InsetBase & inset = cursor[0].inset(); + BufferView & bv = cursor.bv(); - CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(cursor.bottom().text())->second; + CoordCache::InnerParPosCache const & cache = + bv.coordCache().getParPos().find(cursor.bottom().text())->second; // Get an iterator on the first paragraph in the cache DocIterator it(inset); it.push_back(CursorSlice(inset)); @@ -147,7 +149,7 @@ namespace { for ( ; it != et; it.forwardPos(true)) { // avoid invalid nesting when selecting if (!cursor.selection() || positionable(it, cursor.anchor_)) { - Point p = bv_funcs::getPos(it, false); + Point p = bv_funcs::getPos(bv, it, false); int xo = p.x_; int yo = p.y_; if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -204,7 +206,7 @@ namespace { // avoid invalid nesting when selecting if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE && (!cur.selection() || positionable(it, cur.anchor_))) { - Point p = bv_funcs::getPos(it, false); + Point p = bv_funcs::getPos(bv, it, false); int xo = p.x_; int yo = p.y_; if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -383,7 +385,7 @@ int LCursor::currentMode() void LCursor::getPos(int & x, int & y) const { - Point p = bv_funcs::getPos(*this, boundary()); + Point p = bv_funcs::getPos(bv(), *this, boundary()); x = p.x_; y = p.y_; } diff --git a/src/insets/inset.C b/src/insets/inset.C index fddf3a448b..044ff35d1c 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -15,6 +15,7 @@ #include "inset.h" +#include "BufferView.h" #include "debug.h" #include "gettext.h" #include "lyxtext.h" @@ -67,8 +68,8 @@ int InsetOld::width() const } -void InsetOld::setPosCache(PainterInfo const &, int x, int y) const +void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const { //lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl; - theCoords.insets().add(this, x, y); + pi.base.bv->coordCache().insets().add(this, x, y); } diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 7cef1778c8..6f5453a283 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -327,30 +327,30 @@ bool InsetBase::editing(BufferView * bv) const } -int InsetBase::xo() const +int InsetBase::xo(BufferView & bv) const { - return theCoords.getInsets().x(this); + return bv.coordCache().getInsets().x(this); } -int InsetBase::yo() const +int InsetBase::yo(BufferView & bv) const { - return theCoords.getInsets().y(this); + return bv.coordCache().getInsets().y(this); } -bool InsetBase::covers(int x, int y) const +bool InsetBase::covers(BufferView & bv, int x, int y) const { //lyxerr << "InsetBase::covers, x: " << x << " y: " << y - // << " xo: " << xo() << " yo: " << yo() - // << " x1: " << xo() << " x2: " << xo() + width() - // << " y1: " << yo() - ascent() << " y2: " << yo() + descent() + // << " xo: " << xo(bv) << " yo: " << yo() + // << " x1: " << xo(bv) << " x2: " << xo() + width() + // << " y1: " << yo(bv) - ascent() << " y2: " << yo() + descent() // << std::endl; - return theCoords.getInsets().has(this) - && x >= xo() - && x <= xo() + width() - && y >= yo() - ascent() - && y <= yo() + descent(); + return bv.coordCache().getInsets().has(this) + && x >= xo(bv) + && x <= xo(bv) + width() + && y >= yo(bv) - ascent() + && y <= yo(bv) + descent(); } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 8052484281..05a797909e 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -116,13 +116,13 @@ public: /// add space for markers void metricsMarkers2(Dimension & dim, int framesize = 1) const; /// last drawn position for 'important' insets - int xo() const; + int xo(BufferView & bv) const; /// last drawn position for 'important' insets - int yo() const; + int yo(BufferView & bv) const; /// set x/y drawing position cache if available virtual void setPosCache(PainterInfo const &, int, int) const {} /// do we cover screen position x/y? - virtual bool covers(int x, int y) const; + virtual bool covers(BufferView & bv, int x, int y) const; /// get the screen positions of the cursor (see note in cursor.C) virtual void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 451b009898..61a327774f 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1147,12 +1147,12 @@ void InsetTabular::cursorPos } -int InsetTabular::dist(idx_type const cell, int x, int y) const +int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const { int xx = 0; int yy = 0; InsetBase const & inset = *tabular.getCellInset(cell); - Point o = theCoords.getInsets().xy(&inset); + Point o = bv.coordCache().getInsets().xy(&inset); int const xbeg = o.x_ - tabular.getBeginningOfTextInCell(cell); int const xend = xbeg + tabular.getWidthOfColumn(cell); row_type const row = tabular.row_of_cell(cell); @@ -1183,7 +1183,7 @@ InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) //lyxerr << "InsetTabular::editXY: " << this << endl; cur.selection() = false; cur.push(*this); - cur.idx() = getNearestCell(x, y); + cur.idx() = getNearestCell(cur.bv(), x, y); resetPos(cur); return cell(cur.idx())->text_.editXY(cur, x, y); } @@ -1191,18 +1191,18 @@ InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) void InsetTabular::setCursorFromCoordinates(LCursor & cur, int x, int y) const { - cur.idx() = getNearestCell(x, y); + cur.idx() = getNearestCell(cur.bv(), x, y); cell(cur.idx())->text_.setCursorFromCoordinates(cur, x, y); } -InsetTabular::idx_type InsetTabular::getNearestCell(int x, int y) const +InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const { idx_type idx_min = 0; int dist_min = std::numeric_limits::max(); for (idx_type i = 0, n = nargs(); i != n; ++i) { - if (theCoords.getInsets().has(tabular.getCellInset(i).get())) { - int const d = dist(i, x, y); + if (bv.coordCache().getInsets().has(tabular.getCellInset(i).get())) { + int const d = dist(bv, i, x, y); if (d < dist_min) { dist_min = d; idx_min = i; @@ -1238,7 +1238,7 @@ void InsetTabular::resetPos(LCursor & cur) const int const X1 = 0; int const X2 = maxwidth; int const offset = ADD_TO_TABULAR_WIDTH + 2; - int const x1 = xo() + getCellXPos(cur.idx()) + offset; + int const x1 = xo(cur.bv()) + getCellXPos(cur.idx()) + offset; int const x2 = x1 + tabular.getWidthOfColumn(cur.idx()); if (x1 < X1) diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 7feb753958..2b77adc5a9 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -192,9 +192,9 @@ private: bool tablemode(LCursor & cur) const; /// return the "Manhattan distance" to nearest corner - int dist(idx_type cell, int x, int y) const; + int dist(BufferView &, idx_type cell, int x, int y) const; /// return the cell nearest to x, y - idx_type getNearestCell(int x, int y) const; + idx_type getNearestCell(BufferView &, int x, int y) const; /// Buffer const * buffer_; diff --git a/src/mathed/InsetMathDim.C b/src/mathed/InsetMathDim.C index d267c2bca4..1b0eecb601 100644 --- a/src/mathed/InsetMathDim.C +++ b/src/mathed/InsetMathDim.C @@ -11,8 +11,11 @@ #include #include "InsetMathDim.h" + +#include "BufferView.h" #include "coordcache.h" #include "debug.h" +#include "metricsinfo.h" InsetMathDim::InsetMathDim() @@ -37,8 +40,8 @@ int InsetMathDim::width() const } -void InsetMathDim::setPosCache(PainterInfo const &, int x, int y) const +void InsetMathDim::setPosCache(PainterInfo const & pi, int x, int y) const { //lyxerr << "InsetMathDim: cache to " << x << " " << y << std::endl; - theCoords.insets().add(this, x, y); + pi.base.bv->coordCache().insets().add(this, x, y); } diff --git a/src/mathed/InsetMathGrid.C b/src/mathed/InsetMathGrid.C index 4336e06572..63d96f6a3e 100644 --- a/src/mathed/InsetMathGrid.C +++ b/src/mathed/InsetMathGrid.C @@ -784,7 +784,7 @@ bool InsetMathGrid::idxUpDown(LCursor & cur, bool up) const return false; cur.idx() += ncols(); } - cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo()); + cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo(cur.bv())); return true; } diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index a882e0e659..25569afe88 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -44,6 +44,7 @@ #include "dispatchresult.h" #include "funcrequest.h" #include "gettext.h" +#include "lyxtext.h" #include "outputparams.h" #include "undo.h" @@ -106,7 +107,8 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/, // absolute again when actually drawing the cursor. What a mess. BOOST_ASSERT(ptr_cmp(&sl.inset(), this)); MathArray const & ar = sl.cell(); - if (!theCoords.getArrays().has(&ar)) { + CoordCache & coord_cache = sl.text()->bv()->coordCache(); + if (!coord_cache.getArrays().has(&ar)) { // this can (semi-)legally happen if we just created this cell // and it never has been drawn before. So don't ASSERT. //lyxerr << "no cached data for array " << &ar << endl; @@ -114,15 +116,15 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/, y = 0; return; } - Point const pt = theCoords.getArrays().xy(&ar); - if (!theCoords.getInsets().has(this)) { + Point const pt = coord_cache.getArrays().xy(&ar); + if (!coord_cache.getInsets().has(this)) { // same as above //lyxerr << "no cached data for inset " << this << endl; x = 0; y = 0; return; } - Point const pt2 = theCoords.getInsets().xy(this); + Point const pt2 = coord_cache.getInsets().xy(this); //lyxerr << "retrieving position cache for MathArray " // << pt.x_ << ' ' << pt.y_ << std::endl; x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos()); @@ -225,8 +227,9 @@ void InsetMathNest::draw(PainterInfo & pi, int x, int y) const void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const { + BufferView & bv = *pi.base.bv; // this should use the x/y values given, not the cached values - LCursor & cur = pi.base.bv->cursor(); + LCursor & cur = bv.cursor(); if (!cur.selection()) return; if (!ptr_cmp(&cur.inset(), this)) @@ -240,14 +243,15 @@ void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const CursorSlice s1 = cur.selBegin(); CursorSlice s2 = cur.selEnd(); + //lyxerr << "InsetMathNest::drawing selection: " // << " s1: " << s1 << " s2: " << s2 << endl; if (s1.idx() == s2.idx()) { MathArray const & c = cell(s1.idx()); - int x1 = c.xo() + c.pos2x(s1.pos()); - int y1 = c.yo() - c.ascent(); - int x2 = c.xo() + c.pos2x(s2.pos()); - int y2 = c.yo() + c.descent(); + int x1 = c.xo(bv) + c.pos2x(s1.pos()); + int y1 = c.yo(bv) - c.ascent(); + int x2 = c.xo(bv) + c.pos2x(s2.pos()); + int y2 = c.yo(bv) + c.descent(); pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); //lyxerr << "InsetMathNest::drawing selection 3: " // << " x1: " << x1 << " x2: " << x2 @@ -256,10 +260,10 @@ void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const for (idx_type i = 0; i < nargs(); ++i) { if (idxBetween(i, s1.idx(), s2.idx())) { MathArray const & c = cell(i); - int x1 = c.xo(); - int y1 = c.yo() - c.ascent(); - int x2 = c.xo() + c.width(); - int y2 = c.yo() + c.descent(); + int x1 = c.xo(bv); + int y1 = c.yo(bv) - c.ascent(); + int x2 = c.xo(bv) + c.width(); + int y2 = c.yo(bv) + c.descent(); pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection); } } @@ -1075,7 +1079,7 @@ InsetBase * InsetMathNest::editXY(LCursor & cur, int x, int y) int idx_min = 0; int dist_min = 1000000; for (idx_type i = 0, n = nargs(); i != n; ++i) { - int const d = cell(i).dist(x, y); + int const d = cell(i).dist(cur.bv(), x, y); if (d < dist_min) { dist_min = d; idx_min = i; @@ -1084,12 +1088,13 @@ InsetBase * InsetMathNest::editXY(LCursor & cur, int x, int y) MathArray & ar = cell(idx_min); cur.push(*this); cur.idx() = idx_min; - cur.pos() = ar.x2pos(x - ar.xo()); + cur.pos() = ar.x2pos(x - ar.xo(cur.bv())); + //lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl; if (dist_min == 0) { // hit inside cell for (pos_type i = 0, n = ar.size(); i < n; ++i) - if (ar[i]->covers(x, y)) + if (ar[i]->covers(cur.bv(), x, y)) return ar[i].nucleus()->editXY(cur, x, y); } return this; diff --git a/src/mathed/InsetMathScript.C b/src/mathed/InsetMathScript.C index b55962fb21..b6bfa2fa87 100644 --- a/src/mathed/InsetMathScript.C +++ b/src/mathed/InsetMathScript.C @@ -246,7 +246,7 @@ void InsetMathScript::draw(PainterInfo & pi, int x, int y) const if (nuc().size()) nuc().draw(pi, x + dxx(), y); else { - nuc().setXY(x + dxx(), y); + nuc().setXY(*pi.base.bv, x + dxx(), y); if (editing(pi.base.bv)) pi.draw(x + dxx(), y, char_type('.')); } diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index e644b7dcc3..f124a5d043 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -19,11 +19,11 @@ #include "MathSupport.h" #include "MathReplace.h" -#include "coordcache.h" -#include "LColor.h" +#include "BufferView.h" #include "buffer.h" #include "cursor.h" #include "debug.h" +#include "LColor.h" #include "frontends/Painter.h" @@ -275,7 +275,7 @@ void MathArray::metrics(MetricsInfo & mi) const void MathArray::draw(PainterInfo & pi, int x, int y) const { //lyxerr << "MathArray::draw: x: " << x << " y: " << y << endl; - setXY(x, y); + setXY(*pi.base.bv, x, y); if (empty()) { pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline); @@ -309,7 +309,8 @@ void MathArray::draw(PainterInfo & pi, int x, int y) const } } #endif - theCoords.insets().add(at.nucleus(), x, y); + //BufferView & bv = *pi.base.bv; + pi.base.bv->coordCache().insets().add(at.nucleus(), x, y); at->drawSelection(pi, x, y); at->draw(pi, x, y); x += at->width(); @@ -331,7 +332,22 @@ void MathArray::metricsT(TextMetricsInfo const & mi, Dimension & dim) const void MathArray::drawT(TextPainter & pain, int x, int y) const { //lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl; - setXY(x, y); + + // FIXME: Abdel 13/10/2006 + // The setXV() call below is commented out for now because + // we don't have access to a BufferView at this level. + // In any case, this drawT() method is never used, this is dead code. + // + /* Georg explanation of current situation: + AFAIK the text painter was used to export math formulas as ASCII art. + Therefore the setXY() call makes sense. Imagine that the text painter is + like a real painter, but operating on a very coarse grid of character cells + where each cell can be filled with an ASCII character. + I don't know why it is currently disabled. I do know that we have a bugzilla + request for reenabling it. I believe only Andre can tell whether that is + doable or whether the whole drawT machinery should be removed. + */ + //setXY(bv, x, y); for (const_iterator it = begin(), et = end(); it != et; ++it) { (*it)->drawT(pain, x, y); @@ -402,13 +418,13 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const } -int MathArray::dist(int x, int y) const +int MathArray::dist(BufferView & bv, int x, int y) const { int xx = 0; int yy = 0; - const int xo_ = xo(); - const int yo_ = yo(); + const int xo_ = xo(bv); + const int yo_ = yo(bv); if (x < xo_) xx = xo_ - x; @@ -424,20 +440,20 @@ int MathArray::dist(int x, int y) const } -void MathArray::setXY(int x, int y) const +void MathArray::setXY(BufferView & bv, int x, int y) const { //lyxerr << "setting position cache for MathArray " << this << std::endl; - theCoords.arrays().add(this, x, y); + bv.coordCache().arrays().add(this, x, y); } -int MathArray::xo() const +int MathArray::xo(BufferView & bv) const { - return theCoords.getArrays().x(this); + return bv.coordCache().getArrays().x(this); } -int MathArray::yo() const +int MathArray::yo(BufferView & bv) const { - return theCoords.getArrays().y(this); + return bv.coordCache().getArrays().y(this); } diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 9889b1a2f0..eb0441106a 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -20,6 +20,7 @@ #include "MathAtom.h" #include "dimension.h" +class BufferView; class LaTeXFeatures; class ReplaceData; class MetricsInfo; @@ -112,15 +113,15 @@ public: void touch() const; /// access to cached x coordinate of last drawing - int xo() const; + int xo(BufferView & bv) const; /// access to cached y coordinate of last drawing - int yo() const; + int yo(BufferView & bv) const; /// access to cached x coordinate of mid point of last drawing - int xm() const { return xo() + dim_.wid / 2; } + int xm(BufferView & bv) const { return xo(bv) + dim_.wid / 2; } /// access to cached y coordinate of mid point of last drawing - int ym() const { return yo() + (dim_.des - dim_.asc) / 2; } + int ym(BufferView & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; } /// write access to coordinate; - void setXY(int x, int y) const; + void setXY(BufferView & bv, int x, int y) const; /// returns x coordinate of given position in the array int pos2x(size_type pos) const; /// returns position of given x coordinate @@ -131,7 +132,7 @@ public: size_type x2pos(int targetx, int glue) const; /// returns distance of this cell to the point given by x and y // assumes valid position and size cache - int dist(int x, int y) const; + int dist(BufferView & bv, int x, int y) const; /// ascent of this cell above the baseline int ascent() const { return dim_.asc; } diff --git a/src/rowpainter.C b/src/rowpainter.C index d5c1d5438b..8b7a8e2b9f 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -97,7 +97,7 @@ private: LyXFont const getLabelFont() const; /// bufferview to paint on - BufferView const & bv_; + BufferView & bv_; /// Painter to use Painter & pain_; @@ -173,7 +173,7 @@ void RowPainter::paintInset(pos_type const pos, LyXFont const & font) font; pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0); pi.erased_ = erased_ || isDeletedText(par_, pos); - theCoords.insets().add(inset, int(x_), yo_); + bv_.coordCache().insets().add(inset, int(x_), yo_); InsetText const * const in = inset->asTextInset(); // non-wide insets are painted completely. Recursive bool tmp = refreshInside; @@ -828,7 +828,7 @@ void paintPar static PainterInfo nullpi(pi.base.bv, nop); int const ww = pi.base.bv->workHeight(); - theCoords.parPos()[&text][pit] = Point(x, y); + pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y); Paragraph const & par = text.paragraphs()[pit]; if (par.rows().empty()) @@ -913,7 +913,7 @@ void paintPar } // namespace anon -void paintText(BufferView const & bv, ViewMetricsInfo const & vi, +void paintText(BufferView & bv, ViewMetricsInfo const & vi, Painter & pain) { LyXText & text = bv.buffer()->text(); @@ -948,13 +948,13 @@ void paintText(BufferView const & bv, ViewMetricsInfo const & vi, if (vi.p1 > 0) { text.redoParagraph(vi.p1 - 1); - theCoords.parPos()[&text][vi.p1 - 1] = + bv.coordCache().parPos()[&text][vi.p1 - 1] = Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent()); } if (vi.p2 < lyx::pit_type(text.paragraphs().size()) - 1) { text.redoParagraph(vi.p2 + 1); - theCoords.parPos()[&text][vi.p2 + 1] = + bv.coordCache().parPos()[&text][vi.p2 + 1] = Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent()); } diff --git a/src/rowpainter.h b/src/rowpainter.h index 4eca056c39..f59dc1eca5 100644 --- a/src/rowpainter.h +++ b/src/rowpainter.h @@ -29,7 +29,7 @@ class Painter; /// paint visible paragraph of main text -void paintText(BufferView const & bv, ViewMetricsInfo const & vi, +void paintText(BufferView & bv, ViewMetricsInfo const & vi, lyx::frontend::Painter & painter); /// paint the rows of a text inset diff --git a/src/text.C b/src/text.C index f2354a98f4..c8a9af6468 100644 --- a/src/text.C +++ b/src/text.C @@ -2063,17 +2063,19 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const DocIterator beg = cur.selectionBegin(); DocIterator end = cur.selectionEnd(); + BufferView * bv = pi.base.bv; + // the selection doesn't touch the visible screen - if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW - || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE) + if (bv_funcs::status(bv, beg) == bv_funcs::CUR_BELOW + || bv_funcs::status(bv, end) == bv_funcs::CUR_ABOVE) return; Paragraph const & par1 = pars_[beg.pit()]; Paragraph const & par2 = pars_[end.pit()]; - bool const above = (bv_funcs::status(pi.base.bv, beg) + bool const above = (bv_funcs::status(bv, beg) == bv_funcs::CUR_ABOVE); - bool const below = (bv_funcs::status(pi.base.bv, end) + bool const below = (bv_funcs::status(bv, end) == bv_funcs::CUR_BELOW); int y1,y2,x1,x2; if (above) { @@ -2083,7 +2085,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const x2 = dim_.wid; } else { Row const & row1 = par1.getRow(beg.pos(), beg.boundary()); - y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent(); + y1 = bv_funcs::getPos(*bv, beg, beg.boundary()).y_ - row1.ascent(); y2 = y1 + row1.height(); int const startx = cursorX(beg.top(), beg.boundary()); x1 = !isRTL(par1) ? startx : 0; @@ -2092,13 +2094,13 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const int Y1,Y2,X1,X2; if (below) { - Y1 = pi.base.bv->workHeight(); - Y2 = pi.base.bv->workHeight(); + Y1 = bv->workHeight(); + Y2 = bv->workHeight(); X1 = 0; X2 = dim_.wid; } else { Row const & row2 = par2.getRow(end.pos(), end.boundary()); - Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent(); + Y1 = bv_funcs::getPos(*bv, end, end.boundary()).y_ - row2.ascent(); Y2 = Y1 + row2.height(); int const endx = cursorX(end.top(), end.boundary()); X1 = !isRTL(par2) ? 0 : endx; @@ -2549,7 +2551,7 @@ bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y) { BOOST_ASSERT(this == cur.text()); pit_type pit = getPitNearY(y); - int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent(); + int yy = cur.bv().coordCache().get(this, pit).y_ - pars_[pit].ascent(); lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": x: " << x diff --git a/src/text2.C b/src/text2.C index 1deec53ee6..bc8257fc0a 100644 --- a/src/text2.C +++ b/src/text2.C @@ -128,21 +128,21 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const << BOOST_CURRENT_FUNCTION << ": examining inset " << inset << endl; - if (theCoords.getInsets().has(inset)) + if (bv()->coordCache().getInsets().has(inset)) lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION - << ": xo: " << inset->xo() << "..." - << inset->xo() + inset->width() - << " yo: " << inset->yo() - inset->ascent() + << ": xo: " << inset->xo(*bv()) << "..." + << inset->xo(*bv()) + inset->width() + << " yo: " << inset->yo(*bv()) - inset->ascent() << "..." - << inset->yo() + inset->descent() + << inset->yo(*bv()) + inset->descent() << endl; else lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": inset has no cached position" << endl; #endif - if (inset->covers(x, y)) { + if (inset->covers(*bv(), x, y)) { lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": Hit inset: " << inset << endl; @@ -777,7 +777,7 @@ void LyXText::setCurrentFont(LCursor & cur) pos_type LyXText::getColumnNearX(pit_type const pit, Row const & row, int & x, bool & boundary) const { - int const xo = theCoords.get(this, pit).x_; + int const xo = bv()->coordCache().get(this, pit).x_; x -= xo; RowMetrics const r = computeRowMetrics(pit, row); Paragraph const & par = pars_[pit]; @@ -913,8 +913,8 @@ pos_type LyXText::getColumnNearX(pit_type const pit, pit_type LyXText::getPitNearY(int y) const { BOOST_ASSERT(!paragraphs().empty()); - BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end()); - CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second; + BOOST_ASSERT(bv()->coordCache().getParPos().find(this) != bv()->coordCache().getParPos().end()); + CoordCache::InnerParPosCache const & cc = bv()->coordCache().getParPos().find(this)->second; lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": y: " << y << " cache size: " << cc.size() @@ -950,7 +950,7 @@ pit_type LyXText::getPitNearY(int y) const Row const & LyXText::getRowNearY(int y, pit_type pit) const { Paragraph const & par = pars_[pit]; - int yy = theCoords.get(this, pit).y_ - par.ascent(); + int yy = bv()->coordCache().get(this, pit).y_ - par.ascent(); BOOST_ASSERT(!par.rows().empty()); RowList::const_iterator rit = par.rows().begin(); RowList::const_iterator const rlast = boost::prior(par.rows().end()); @@ -1085,7 +1085,7 @@ bool LyXText::cursorUp(LCursor & cur) row = par.pos2row(cur.pos()); if (!cur.selection()) { - int const y = bv_funcs::getPos(cur, cur.boundary()).y_; + int const y = bv_funcs::getPos(cur.bv(), cur, cur.boundary()).y_; LCursor old = cur; // Go to middle of previous row. 16 found to work OK; // 12 = top/bottom margin of display math @@ -1134,7 +1134,7 @@ bool LyXText::cursorDown(LCursor & cur) row = par.pos2row(cur.pos()); if (!cur.selection()) { - int const y = bv_funcs::getPos(cur, cur.boundary()).y_; + int const y = bv_funcs::getPos(cur.bv(), cur, cur.boundary()).y_; LCursor old = cur; // To middle of next row int const margin = 3 * InsetMathHull::displayMargin() / 2; -- 2.39.2