]> git.lyx.org Git - features.git/commitdiff
In order to support multiple LyXView each BufferView needs its own CoordCache. This...
authorAbdelrazak Younes <younes@lyx.org>
Fri, 13 Oct 2006 16:44:44 +0000 (16:44 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 13 Oct 2006 16:44:44 +0000 (16:44 +0000)
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

22 files changed:
src/BufferView.C
src/BufferView.h
src/bufferview_funcs.C
src/bufferview_funcs.h
src/coordcache.C
src/coordcache.h
src/cursor.C
src/insets/inset.C
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insettabular.C
src/insets/insettabular.h
src/mathed/InsetMathDim.C
src/mathed/InsetMathGrid.C
src/mathed/InsetMathNest.C
src/mathed/InsetMathScript.C
src/mathed/MathData.C
src/mathed/MathData.h
src/rowpainter.C
src/rowpainter.h
src/text.C
src/text2.C

index 1a2314885c87c619b03c1f291a0879e55b03c30f..b56600006731e81ee9b4e6ffb5f66547b63e32c1 100644 (file)
@@ -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();
index 9825e8fbc5cfa49bba3f9fddb309f0658180bf4e..53fcf3a6962e80dc84c3505c9d33df49a5c04853 100644 (file)
@@ -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_;
 
index 48dbad035778f6887436dc3df972556200995e12..b5cdfd0d4885b07b531dfa120ae4814b42267366 100644 (file)
@@ -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;
index 7cd3f17be40ded3a19be51a69cfef23832f479c8..aaa2400af128fc105bf03d2785a52a5c1a41dc2b 100644 (file)
@@ -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,
index ecfffec949cf21786e822a93233dac51bb823dc7..262aaa7d8a7ff9b687b707f53f1d97840265aea5 100644 (file)
@@ -19,8 +19,6 @@
 #include <boost/assert.hpp>
 
 
-CoordCache theCoords;
-
 // just a helper to be able to set a breakpoint
 void lyxbreaker(void const * data, const char * hint, int size)
 {
index 535a712716335793da79335c2392b64481edeaa5..1d49a1aa8fd05d8643b76ef035b2ef4d08cef365 100644 (file)
@@ -150,6 +150,4 @@ private:
        SliceCache slices1_;
 };
 
-extern CoordCache theCoords;
-
 #endif
index a2990d05bec560986cd35e1bcaf07b6230747d25..6920dd6e5df5e7999cce86a08873b375b31b36a6 100644 (file)
@@ -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_;
 }
index fddf3a448b8cf6a993e0003f1a2429bcfbed8788..044ff35d1c236b55896fd1d2fac1bb34b5c9a099 100644 (file)
@@ -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);
 }
index 7cef1778c865733dafe79cec9e24b6f3019ecb06..6f5453a2836b3e243f71115b4aeb0ef0656c63ef 100644 (file)
@@ -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();
 }
 
 
index 805248428104bd5940b9999b4b5c9269fe787999..05a797909edd44331563e4aef9fdd865e2fe2180 100644 (file)
@@ -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;
index 451b009898d6bad80699ef64bb23d3166005c859..61a327774f71c61e35f8d6f1ff8c8a1e331a41c4 100644 (file)
@@ -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<int>::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)
index 7feb753958533d6a0ccd9c5be3c5e110c141a210..2b77adc5a9d946646208ba813ed060b397e1c6e9 100644 (file)
@@ -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_;
index d267c2bca40732c4b739b9dc3d50b34b1843cb42..1b0eecb601248d94be08b3f12fa0ec0e89d1805f 100644 (file)
 #include <config.h>
 
 #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);
 }
index 4336e0657278ab41eb31cbe0ac6bac65c2d36836..63d96f6a3ef8833ca1f9fab8801a7d3a786dfc46 100644 (file)
@@ -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;
 }
 
index a882e0e65949b7ee1af61b0a62081ba7601ba8e9..25569afe88ff7ac0e355be99afbd0af93b05f92b 100644 (file)
@@ -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;
index b55962fb218c01e045c342fb0d921dc115a3fc92..b6bfa2fa87a1c81bb3aedc9d8830943702de5432 100644 (file)
@@ -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('.'));
        }
index e644b7dcc3744107f53c921f6d2b4694d751bbca..f124a5d04319906c92717826d7d12daa50f41aec 100644 (file)
 #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);
 }
index 9889b1a2f0da4679042efa8580ff07538533bee5..eb0441106acc0be336afcc44b214322d6453d7d1 100644 (file)
@@ -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; }
index d5c1d5438b17d94e8d90dbf4922f51e88fa4b258..8b7a8e2b9fe38237ebc60a66db34facdd9ee6c5b 100644 (file)
@@ -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());
        }
 
index 4eca056c3974da518de4a9a5bb8a8fccc6b3f503..f59dc1eca52fb104499ab852e4f7ed87aa949bba 100644 (file)
@@ -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
index f2354a98f4325ee6df5f543011bc1c5f30769755..c8a9af6468f0ae199f9bd65e989633c39dac8560 100644 (file)
@@ -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
index 1deec53ee6e183c627c40409f5561fde459de7df..bc8257fc0af4d3627eb02772d6937b22dbdb4231 100644 (file)
@@ -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;