]> git.lyx.org Git - features.git/commitdiff
remove per-inset position cahce, use new external map instead.
authorAndré Pönitz <poenitz@gmx.net>
Sat, 14 Aug 2004 14:03:42 +0000 (14:03 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 14 Aug 2004 14:03:42 +0000 (14:03 +0000)
this allows us to bomb early on uninitialized cache values.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8923 a592a061-630c-0410-9148-cb99ea01b6c8

24 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/Makefile.am
src/frontends/xforms/XWorkArea.C
src/insets/ChangeLog
src/insets/inset.C
src/insets/inset.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insettabular.C
src/insets/updatableinset.C
src/lyxfunc.C
src/mathed/math_data.C
src/mathed/math_data.h
src/mathed/math_decorationinset.C
src/mathed/math_diminset.C
src/mathed/math_diminset.h
src/mathed/math_factory.C
src/mathed/math_nestinset.C
src/mathed/math_parser.C
src/mathed/math_splitinset.C
src/rowpainter.C
src/text.C
src/text3.C

index 1fdc75a779953f43b533583a1e87b2f6d3787d7b..d80723d200b0969b40483bbc50bb09e009e4ace4 100644 (file)
@@ -23,6 +23,7 @@
 #include "buffer_funcs.h"
 #include "bufferlist.h"
 #include "bufferparams.h"
+#include "coordcache.h"
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
@@ -602,7 +603,13 @@ void BufferView::Pimpl::update()
                // and the scrollbar
                updateScrollbar();
        }
+
+       // remove old position cache
+       theCoords.clear();
+
+       // The real, big redraw.
        screen().redraw(*bv_);
+
        bv_->owner()->view_state_changed();
 }
 
@@ -835,8 +842,8 @@ void BufferView::Pimpl::trackChanges()
 
 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
 {
-       //lyxerr << "BufferView::Pimpl::workAreaDispatch: request: "
-       //  << cmd << std::endl;
+       lyxerr << "BufferView::Pimpl::workAreaDispatch: request: "
+         << cmd0 << std::endl;
        // this is only called for mouse related events including
        // LFUN_FILE_OPEN generated by drag-and-drop.
        FuncRequest cmd = cmd0;
index 80c5d889b44a86bad5c3697aa03e3102631c725f..29a0121abf60c79f47fd5f3b2342bf3cb59e93e2 100644 (file)
@@ -1,3 +1,13 @@
+2004-08-14  André Pönitz  <poenitz@gmx.net>
+
+       * coordcache.[Ch]:
+       * Makefile.am: new files to accomodate an 'external' (x,y)-position
+    cache for all insets in (at least partially) visible (top-level)
+         paragraphs.
+       
+  * BufferView_pimpl.C: reset external coord cache before every update.
+         This means the coord cache only contains valid entries.
+
 2004-08-14  Lars Gullik Bjonnes  <larsbj@lyx.org>
 
        bug 1096
index 6eaad4b0c3731cbb3e29cb9fa2ceace412e8c712..7a9aa96eec4c2c6a5877833e4a4a0320a07da1d0 100644 (file)
@@ -134,6 +134,8 @@ lyx_SOURCES = \
        converter.h \
        counters.C \
        counters.h \
+       coordcache.C \
+       coordcache.h \
        cursor.C \
        cursor.h \
        cursor_slice.C \
index 949e3ea8976fb03904a0c50e646d962a9a41d5b0..bf2e367925a26567ad8c7bd6f351621cf760423f 100644 (file)
@@ -293,6 +293,9 @@ int XWorkArea::work_area_handler(FL_OBJECT * ob, int event,
                                 FL_Coord, FL_Coord,
                                 int key, void * xev)
 {
+       if (event != 11)
+               lyxerr[Debug::WORKAREA] << "Workarea event: EVENT: " << event << endl;
+
        XEvent * ev = static_cast<XEvent*>(xev);
        XWorkArea * area = static_cast<XWorkArea*>(ob->u_vdata);
 
@@ -385,6 +388,8 @@ int XWorkArea::work_area_handler(FL_OBJECT * ob, int event,
                break;
 
        case FL_DRAG: {
+               lyxerr[Debug::WORKAREA] << "Workarea event: DRAG 0" << endl;
+
                if (!ev || !area->scrollbar)
                        break;
 
index 6916fdfec2b8c7288fdfcf8dfe3e4843e9a19f90..33d652f1b64a9405935ef7a8a08a1c417cf83b7f 100644 (file)
@@ -1,3 +1,9 @@
+
+2004-08-14  André Pönitz  <poenitz@gmx.net>
+
+       * inset.[Ch]:
+       * insetbase.[Ch]:       remove the 'internale' xo, yo position cache
+
 2004-08-13  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * insetoptarg.C (latexOptional): if the optional argument contains
index 37b73dd6342c54afd076338662f4589d3e507bdf..0f8bbc739e611b613aa3ce294506b890ba923319 100644 (file)
 #include "lyxtext.h"
 #include "LColor.h"
 #include "metricsinfo.h"
+#include "coordcache.h"
 
 using std::string;
 
 
 InsetOld::InsetOld()
-       : InsetBase(),
-         xo_(0), yo_(0), scx(0),
+       : scx(0),
          //background_color_(LColor::inherit)
          background_color_(LColor::background)
 {}
 
 
 InsetOld::InsetOld(InsetOld const & in)
-       : InsetBase(),
-         xo_(0), yo_(0), scx(0), name_(in.name_),
+       : InsetBase(in), scx(0), name_(in.name_),
          background_color_(in.background_color_)
 {}
 
@@ -86,6 +85,5 @@ int InsetOld::scroll(bool) const
 void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const
 {
        //lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
-       xo_ = x;
-       yo_ = y + pi.base.bv->top_y();
+       theCoords.insets_.add(this, x, y + pi.base.bv->top_y());
 }
index fe3d22ac39e492f7278eeb401949c9d40ed16dc4..ece7a34e29bbc6c15c954a89b6bc9b10ddd1c097 100644 (file)
@@ -52,20 +52,12 @@ public:
        LColor_color backgroundColor() const;
        /// set x/y drawing position cache
        void setPosCache(PainterInfo const &, int, int) const;
-       ///
-       int xo() const { return xo_; }
-       ///
-       int yo() const { return yo_; }
        /// returns the actual scroll-value
        virtual int scroll(bool recursive = true) const;
 
        ///
        bool forceDefaultParagraphs(InsetBase const * inset) const;
 protected:
-       ///
-       mutable int xo_;
-       ///
-       mutable int yo_;
        ///
        mutable int scx;
        ///
index abfeeb8ca71e8add0ebd7c0718b1be314b0d93de..f40b4d52a777b35d0c5266c63ffb2ad3654af1a8 100644 (file)
@@ -13,6 +13,7 @@
 #include "insetbase.h"
 
 #include "buffer.h"
+#include "coordcache.h"
 #include "BufferView.h"
 #include "LColor.h"
 #include "cursor.h"
@@ -287,6 +288,18 @@ bool InsetBase::editing(BufferView * bv) const
 }
 
 
+int InsetBase::xo() const
+{
+       return theCoords.insets_.x(this);
+}
+
+
+int InsetBase::yo() const
+{
+       return theCoords.insets_.y(this);
+}
+
+
 bool InsetBase::covers(int x, int y) const
 {
        //lyxerr << "InsetBase::covers, x: " << x << " y: " << y
@@ -294,7 +307,8 @@ bool InsetBase::covers(int x, int y) const
        //      << " x1: " << xo() << " x2: " << xo() + width()
        //      << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
        //      << std::endl;
-       return x >= xo()
+       return theCoords.insets_.has(this)
+                       && x >= xo()
                        && x <= xo() + width()
                        && y >= yo() - ascent()
                        && y <= yo() + descent();
index 1287b5a74a8c3068f017ea08d7aa503185213303..0109473402df840732829e1405003ddbe47c4e32 100644 (file)
@@ -98,9 +98,9 @@ public:
        /// add space for markers
        void metricsMarkers2(Dimension & dim, int framesize = 1) const;
        /// last drawn position for 'important' insets
-       virtual int xo() const { return 0; }
+       int xo() const;
        /// last drawn position for 'important' insets
-       virtual int yo() const { return 0; }
+       int yo() const;
        /// set x/y drawing position cache if available
        virtual void setPosCache(PainterInfo const &, int, int) const {}
        /// do we cover screen position x/y?
index 08693477efb85ebff1beae7d716f361789ddc12d..140e1cf279affa459aecbd1b889344a34c82a82b 100644 (file)
@@ -387,8 +387,9 @@ void InsetTabular::edit(LCursor & cur, bool left)
                        cell = tabular.getNumberOfCells() - 1;
        }
        cur.selection() = false;
-       resetPos(cur);
-       cur.bv().fitCursor();
+       // this accesses the position cache before it is initialized
+       //resetPos(cur);
+       //cur.bv().fitCursor();
        cur.push(*this);
        cur.idx() = cell;
 }
@@ -400,7 +401,7 @@ InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
        cur.selection() = false;
        cur.push(const_cast<InsetTabular&>(*this));
        return setPos(cur, x, y);
-       //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
+       //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(actcell);
 }
 
 
@@ -987,7 +988,7 @@ int InsetTabular::getCellXPos(int cell) const
        for (; c < cell; ++c)
                lx += tabular.getWidthOfColumn(c);
 
-       return lx - tabular.getWidthOfColumn(cell) + xo_;
+       return lx - tabular.getWidthOfColumn(cell) + xo();
 }
 
 
@@ -1012,8 +1013,8 @@ void InsetTabular::resetPos(LCursor & cur) const
                scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
        } else if (cursorx_ - offset < 20) {
                scroll(bv, 20 - cursorx_ + offset);
-       } else if (scroll() && xo_ > 20 &&
-                  xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
+       } else if (scroll() && xo() > 20 &&
+                  xo() + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
                scroll(bv, old_x - cursorx_);
        }
 
index 1e9aea7d147bd7884b05ca1864b4a8ee7a621c9c..4ba16bc04673eb27c65a0343207ffac4cc334af6 100644 (file)
@@ -16,6 +16,7 @@
 #include "updatableinset.h"
 
 #include "BufferView.h"
+#include "coordcache.h"
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
@@ -46,6 +47,7 @@ void UpdatableInset::scroll(BufferView & bv, float s) const
        }
 
        int const workW = bv.workWidth();
+       int xo_ = theCoords.insets_.x(this);
        int const tmp_xo_ = xo_ - scx;
 
        if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
@@ -65,6 +67,7 @@ void UpdatableInset::scroll(BufferView & bv, float s) const
 
 void UpdatableInset::scroll(BufferView & bv, int offset) const
 {
+       int const xo_ = theCoords.insets_.x(this);
        if (offset > 0) {
                if (!scx && xo_ >= 20)
                        return;
index f4fac34f66115f3050800e2d55a387f41d6c6c73..2103bdb1974c90d50d099b5e78544b08821198f7 100644 (file)
@@ -1433,7 +1433,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                }
 
                if (view()->available()) {
-                       if (view()->fitCursor() || update)
+                       // Redraw screen unless explicitly told otherwise.
+                       // This also initializes the position cache for all insets
+                       // in (at least partially) visible top-level paragraphs.
+                       if (update)
+                               view()->update();
+
+                       // fitCursor() needs valid inset position. The previous call to
+                       // update() makes sure we have such even for freshly created
+                       // insets.
+                       if (view()->fitCursor())
                                view()->update();
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (getStatus(cmd).enabled()
index 8a97e3e53a677856ef380cbcbdd7339858a652e8..b8f44dea0825e15a0d06ec4df9eccf409646fec8 100644 (file)
@@ -19,6 +19,7 @@
 #include "math_support.h"
 #include "math_replace.h"
 
+#include "coordcache.h"
 #include "LColor.h"
 #include "BufferView.h"
 #include "buffer.h"
@@ -38,12 +39,11 @@ using std::vector;
 
 
 MathArray::MathArray()
-       : xo_(0), yo_(0) 
 {}
 
 
 MathArray::MathArray(const_iterator from, const_iterator to)
-       : base_type(from, to), xo_(0), yo_(0)
+       : base_type(from, to)
 {}
 
 
@@ -276,8 +276,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;
-       xo_ = x;
-       yo_ = y;
+       setXY(x, y);    
 
        if (empty()) {
                pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
@@ -332,8 +331,7 @@ 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;
-       xo_ = x;
-       yo_ = y;
+       setXY(x, y);
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
                (*it)->drawT(pain, x, y);
@@ -393,6 +391,9 @@ int MathArray::dist(int x, int y) const
        int xx = 0;
        int yy = 0;
 
+       const int xo_ = xo();
+       const int yo_ = yo();
+
        if (x < xo_)
                xx = xo_ - x;
        else if (x > xo_ + width())
@@ -409,6 +410,19 @@ int MathArray::dist(int x, int y) const
 
 void MathArray::setXY(int x, int y) const
 {
-       xo_ = x;
-       yo_ = y;
+       lyxerr << "setting position cache for MathArray " << this << std::endl;
+       theCoords.arrays_.add(this, x, y);
+}
+
+
+int MathArray::xo() const
+{
+       return theCoords.arrays_.x(this);
 }
+
+
+int MathArray::yo() const
+{
+       return theCoords.arrays_.y(this);
+}
+
index 7e774d2850dadbe3a14e9071084b945aa839fd0a..1720ba44234e01088b48bdd7b98dd7d9d4ea6470 100644 (file)
@@ -112,13 +112,13 @@ public:
        void touch() const;
 
        /// access to cached x coordinate of last drawing
-       int xo() const { return xo_; }
+       int xo() const;
        /// access to cached y coordinate of last drawing
-       int yo() const { return yo_; }
+       int yo() const;
        /// access to cached x coordinate of mid point of last drawing
-       int xm() const { return xo_ + dim_.wid / 2; }
+       int xm() const { return xo() + 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() const { return yo() + (dim_.des - dim_.asc) / 2; }
        /// write access to coordinate;
        void setXY(int x, int y) const;
        /// returns x coordinate of given position in the array
@@ -152,10 +152,6 @@ private:
 
        /// cached dimensions of cell
        mutable Dimension dim_;
-       /// cached x coordinate of last drawing
-       mutable int xo_;
-       /// cached y coordinate of last drawing
-       mutable int yo_;
 };
 
 ///
index 2b1d87cadb576b0b17abf0203fa3a259ea50b338..3f24a73e056a93802059008a74262aa4b3d8498e 100644 (file)
@@ -18,6 +18,8 @@
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
 
+#include "debug.h"
+
 #include "support/std_ostream.h"
 
 using std::auto_ptr;
@@ -25,7 +27,9 @@ using std::auto_ptr;
 
 MathDecorationInset::MathDecorationInset(latexkeys const * key)
        : MathNestInset(1), key_(key)
-{}
+{
+       lyxerr << " creating deco " << key->name << std::endl;
+}
 
 
 auto_ptr<InsetBase> MathDecorationInset::clone() const
index e2e898cfa3285ec4c8add61925336d41371a51ae..00a1befa17a8a07ac49a2628e177e54621fdb1b4 100644 (file)
 #include <config.h>
 
 #include "math_diminset.h"
+#include "coordcache.h"
 #include "debug.h"
 
 
 MathDimInset::MathDimInset()
-       : xo_(-3), yo_(-3) // some sentinel value for debugging
 {}
 
 
@@ -40,6 +40,5 @@ int MathDimInset::width() const
 void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
 {
        //lyxerr << "MathDimInset: cache to " << x << " " << y << std::endl;
-       xo_ = x;
-       yo_ = y;
+       theCoords.insets_.add(this, x, y);
 }
index f0b206b2d7746d1bdc8606f4e0891c4eee3b1b40..3294e8f12e83cfddd4d3cc3a7bcb6a02fcaa9ff8 100644 (file)
@@ -33,20 +33,12 @@ public:
        ///
        int width() const;
 
-       ///
-       int xo() const { return xo_; }
-       ///
-       int yo() const { return yo_; }
        ///
        void setPosCache(PainterInfo const & pi, int x, int y) const;
 
 protected:
        ///
        mutable Dimension dim_;
-       ///
-       mutable int xo_;
-       ///
-       mutable int yo_;
 };
 
 #endif
index 039a7947a27365a68e43707f7fc5db5c482be9ed..5ed3010ee4b541d7c1a89be80435225e62e55414 100644 (file)
@@ -286,7 +286,7 @@ MathAtom createMathInset(string const & s)
                return MathAtom(new MathKernInset);
        if (s == "xrightarrow" || s == "xleftarrow")
                return MathAtom(new MathXArrowInset(s));
-       if (s == "split" || s == "gathered" || s == "aligned")
+       if (s == "split" || s == "gathered" || s == "aligned" || s == "alignedat")
                return MathAtom(new MathSplitInset(s));
        if (s == "cases")
                return MathAtom(new MathCasesInset);
index 3306b0638487ceadef47682a0dcc03c330ab4a0b..2d1596bbff05b08af6e6df5af9c6376c98ce81e9 100644 (file)
@@ -196,8 +196,11 @@ void MathNestInset::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
+void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
 {
+       // FIXME: hack to get position cache warm
+       draw(pi, x, y);
+
        // this should use the x/y values given, not the cached values
        LCursor & cur = pi.base.bv->cursor();
        if (!cur.selection())
index cd2bf6ba90d4feea1b1595637c27a651a2d5163f..3fe2e5c33137fc0e66d5f6404bd1ae228f2c4874 100644 (file)
@@ -985,7 +985,8 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        }
 
                        else if (name == "split" || name == "cases" ||
-                                        name == "gathered" || name == "aligned") {
+                                        name == "gathered" || name == "aligned" ||
+                                  name == "alignedat") {
                                cell->push_back(createMathInset(name));
                                parse2(cell->back(), FLAG_END, mode, false);
                        }
index 83a9caf3b38e7aa6cc6ff56506c8e55fe3b83779..90388dbd385318f6aea0556563aa267aab23dedc 100644 (file)
@@ -41,6 +41,8 @@ char MathSplitInset::defaultColAlign(col_type col)
                return 'c';
        if (name_ == "aligned")
                return (col & 1) ? 'l' : 'r';
+       if (name_ == "alignedat")
+               return (col & 1) ? 'l' : 'r';
        return 'l';
 }
 
index 6bdae7a8131253d091002d9a0071ada0a9aee06f..56fd368fe45c0122c0de363ddcf3216abb436563 100644 (file)
@@ -14,6 +14,7 @@
 #include "rowpainter.h"
 
 #include "buffer.h"
+#include "coordcache.h"
 #include "cursor.h"
 #include "debug.h"
 #include "bufferparams.h"
@@ -200,6 +201,7 @@ void RowPainter::paintInset(pos_type const pos)
        BOOST_ASSERT(inset);
        PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
        pi.base.font = getFont(pos);
+       theCoords.insets_.add(inset, int(x_), yo_ + row_.baseline());
        inset->drawSelection(pi, int(x_), yo_ + row_.baseline());
        inset->draw(pi, int(x_), yo_ + row_.baseline());
        x_ += inset->width();
index d5bbf53c3afb79bdcaede0026d138c84f0ef74d8..6c6c06b303bb11b867cff6320839bfc546f274bd 100644 (file)
@@ -2143,6 +2143,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const
 }
 
 
+// Manhattan distance to nearest corner
 int LyXText::dist(int x, int y) const
 {
        int xx = 0;
index a185e9d0a67d84157407040fdbcab6dedf18ca7e..adf27cfc27cd8e6fceaf3b7754e705a726723901 100644 (file)
@@ -23,6 +23,7 @@
 #include "bufferparams.h"
 #include "BufferView.h"
 #include "cursor.h"
+#include "coordcache.h"
 #include "CutAndPaste.h"
 #include "debug.h"
 #include "dispatchresult.h"
@@ -203,10 +204,14 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const
                for (; iit != iend; ++iit) {
                        InsetBase * inset = iit->inset;
 #if 1
-                       lyxerr << "examining inset " << inset
-                               << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
-                               << " yo: " << inset->yo() - inset->ascent() << "..."
-                               << inset->yo() + inset->descent() << endl;
+                       lyxerr << "examining inset " << inset << endl;
+                       if (theCoords.insets_.has(inset))
+                               lyxerr
+                                       << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
+                                       << " yo: " << inset->yo() - inset->ascent() << "..."
+                                       << inset->yo() + inset->descent() << endl;
+                       else
+                               lyxerr << " inset has no cached position";
 #endif
                        if (inset->covers(x, y)) {
                                lyxerr << "Hit inset: " << inset << endl;