]> git.lyx.org Git - features.git/commitdiff
Asger's commentary, const-correct and bug-squashing little beauty.
authorAngus Leeming <leeming@lyx.org>
Mon, 31 Jan 2005 16:29:48 +0000 (16:29 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 31 Jan 2005 16:29:48 +0000 (16:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9558 a592a061-630c-0410-9148-cb99ea01b6c8

32 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/ChangeLog
src/RowList_fwd.h
src/buffer.h
src/bufferview_funcs.C
src/coordcache.C
src/coordcache.h
src/cursor.C
src/cursor_slice.C
src/cursor_slice.h
src/dociterator.C
src/dociterator.h
src/insets/ChangeLog
src/insets/inset.C
src/insets/insetbase.C
src/insets/insettabular.C
src/insets/updatableinset.C
src/lyxrow.h
src/lyxtext.h
src/mathed/ChangeLog
src/mathed/math_data.C
src/mathed/math_diminset.C
src/mathed/math_nestinset.C
src/paragraph.C
src/paragraph.h
src/paragraph_funcs.h
src/rowpainter.C
src/text.C
src/text2.C
src/text3.C

index 2be15d5e9009e3e493bc6c649a330df6f615f08f..30c0de050ee88349cd9182d6b0000aa4267c1d7e 100644 (file)
@@ -290,8 +290,7 @@ void BufferView::hideCursor()
        screen().hideCursor();
 }
 
-
-LyXText * BufferView::getLyXText() const
+LyXText * BufferView::getLyXText()
 {
        LyXText * text = cursor().innerText();
        BOOST_ASSERT(text);
@@ -299,6 +298,14 @@ LyXText * BufferView::getLyXText() const
 }
 
 
+LyXText const * BufferView::getLyXText() const
+{
+       LyXText const * text = cursor().innerText();
+       BOOST_ASSERT(text);
+       return text;
+}
+
+
 void BufferView::haveSelection(bool sel)
 {
        pimpl_->workarea().haveSelection(sel);
index 1197ea34f5090c6e48ddb38b007519ed02373a46..88d307daf82eb60b8eaf02d8419cc545eddd04f6 100644 (file)
@@ -102,7 +102,10 @@ public:
        Change const getCurrentChange();
 
        /// return the lyxtext we are using
-       LyXText * getLyXText() const;
+       LyXText * getLyXText();
+
+       /// return the lyxtext we are using
+       LyXText const * getLyXText() const;
 
        /// simple replacing. Use the font of the first selected character
        void replaceSelectionWithString(std::string const & str);
index 7491e27213e26af48a1458d9a254455cdedc8ea5..23bc6e0a97657704cb30546e3ea11c1a29d2dc6c 100644 (file)
@@ -445,7 +445,6 @@ void BufferView::Pimpl::scrollDocView(int value)
        t.redoParagraph(anchor_ref_);
        int const h = t.getPar(anchor_ref_).height();
        offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
-       lyxerr << "scrolling: " << value << std::endl;
        update();
 
        if (!lyxrc.cursor_follows_scrollbar)
@@ -612,6 +611,7 @@ void BufferView::Pimpl::update(bool fitcursor, bool forceupdate)
 
                CoordCache backup;
                std::swap(theCoords, backup);
+               theCoords.startUpdating();
                //
                ViewMetricsInfo vi = metrics();
 
@@ -622,8 +622,11 @@ void BufferView::Pimpl::update(bool fitcursor, bool forceupdate)
                if (forceupdate) {
                        // second drawing step
                        screen().redraw(*bv_, vi);
-               } else
+                       theCoords.doneUpdating();
+               } else {
+                       // Abort updating of the coord cache - just restore the old one
                        std::swap(theCoords, backup);
+               }
        } else
                screen().greyOut();
 
@@ -743,7 +746,7 @@ void BufferView::Pimpl::switchKeyMap()
 
 void BufferView::Pimpl::center()
 {
-       CursorSlice const & bot = bv_->cursor().bottom();
+       CursorSlice & bot = bv_->cursor().bottom();
        lyx::pit_type const pit = bot.pit();
        bot.text()->redoParagraph(pit);
        Paragraph const & par = bot.text()->paragraphs()[pit];
@@ -1247,7 +1250,7 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
        int y = y1;
        for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
                y += text->getPar(pit).ascent();
-               theCoords.pars_[text][pit] = Point(0, y);
+               theCoords.parPos()[text][pit] = Point(0, y);
                y += text->getPar(pit).descent();
        }
 
index 260b097364f50b30b0f0ab665d2e4b689b84c91b..302cba77df93ee9dec48333aa90b5ba7627cd70c 100644 (file)
@@ -2,6 +2,38 @@
 
        * lyxlex_pimpl.h: #include <fstream>.
 
+       * BufferView.[Ch] (getLyXText): add a const version.
+
+       * BufferView_pimpl.C: add debug aids.
+
+       * RowList_fwd.h:
+       * buffer.h:
+       * lyxrow.h:
+       * paragraph_funcs.h: add commentary explaining what the class does.
+
+
+       * coordcache.[Ch]: add lots of commentary.
+       (startUpdating, doneUpdating): debug aids.
+       (arrays, insets, parPos, getParPos): accessors to private data.
+
+       * cursor_slice.[Ch] (text): add a const version.
+       * dociterator.[Ch] (text, innerText): add const versions.
+
+       * lyxtext.h (breakParagraph): change the keep_layout arg to a
+       bool.
+
+       * paragraph.C (getRow, pos2ros): add asserts.
+
+       * paragraph.h: add commentary. Lots of.
+
+       * paragraph.[Ch] (metrucs, draw): removed.
+
+       * cursor.C:
+       * rowpainter.[Ch]: const-correct changes.
+
+       * text.C: various obvious clean-ups. Removal of ancient cruft.
+       Bug fixes, even.
+       
 2005-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * vc-backend.C (find_file): rewrite to use boost.filesystem
index 1682257b0a7f95f2f862b3ec476be2762bd056ec..c1a4de1cf1ff6c9c1e62e78a5501beaf9e4c62bf 100644 (file)
 
 #include <vector>
 
+/**
+ * Each paragraph is broken up into a number of rows on the screen.
+ * This is a list of such on-screen rows, ordered from the top row
+ * downwards.
+ */
 typedef std::vector<Row> RowList;
 
 #endif
index 9e7b9a1675eb96d4ba5c41e4888be304cd0a734e..fade88655f8c8599010e4a164f3abc646cbbf648 100644 (file)
@@ -49,10 +49,15 @@ class Undo;
 
 
 /** The buffer object.
-  This is the buffer object. It contains all the informations about
-  a document loaded into LyX. I am not sure if the class is complete or
-  minimal, probably not.
-  \author Lars Gullik Bjønnes
+ * This is the buffer object. It contains all the informations about
+ * a document loaded into LyX.
+ * The buffer object owns the LyXText (wrapped in an InsetText), which 
+ * contains the individual paragraphs of the document.
+ *
+ * 
+ * I am not sure if the class is complete or
+ * minimal, probably not.
+ * \author Lars Gullik Bjønnes
   */
 class Buffer {
 public:
index fb977c2dc56bdc1b2a6963b94ff415bf6b560a2a..e83ce1ae85ae08074e1c7eaf534c43eb0a03c7c2 100644 (file)
@@ -180,8 +180,8 @@ Point coordOffset(DocIterator const & dit)
 Point getPos(DocIterator const & dit)
 {
        CursorSlice const & bot = dit.bottom();
-       CoordCache::InnerParPosCache & cache = theCoords.pars_[bot.text()];
-       CoordCache::InnerParPosCache::iterator it = cache.find(bot.pit());
+       CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(bot.text())->second;
+       CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit());
        if (it == cache.end()) {
                //lyxerr << "cursor out of view" << std::endl;
                return Point(-1,-1);
@@ -195,7 +195,7 @@ Point getPos(DocIterator const & dit)
 // this could be used elsewhere as well?
 CurStatus status(BufferView const * bv, DocIterator const & dit)
 {
-       CoordCache::InnerParPosCache & cache = theCoords.pars_[dit.bottom().text()];
+       CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(dit.bottom().text())->second;
 
        if (cache.find(dit.bottom().pit()) != cache.end())
                return CUR_INSIDE;
index d252fb0ee0593ac1b824a335666c0ae54784621f..b574b271c35b46ad87ce43b6f6da8813dd05b82d 100644 (file)
@@ -21,20 +21,24 @@ void lyxbreaker(void const * data, const char * hint, int size)
 }
 
 
-void lyxaborter(int x, int y)
-{
-       lyxerr << "abort on x: " << x << " y: " << y << std::endl;
-       BOOST_ASSERT(false);
-}
-
-
 void CoordCache::clear()
 {
+       BOOST_ASSERT(updating);
        arrays_.clear();
        insets_.clear();
        pars_.clear();
 }
 
+void CoordCache::startUpdating() {
+       BOOST_ASSERT(!updating);
+       updating = true;
+}
+
+
+void CoordCache::doneUpdating() {
+       BOOST_ASSERT(updating);
+       updating = false;
+}
 
 Point CoordCache::get(LyXText const * text, lyx::pit_type pit)
 {
index 3a70e6d78dbe7a653c1e2cf262912bf5ec42bd2e..779427525516c06d4c3112ce7a51d45804a8e4b1 100644 (file)
@@ -12,13 +12,7 @@ class Paragraph;
 
 #include <map>
 
-
-// All positions cached in this cache are only valid between subsequent
-// updated. (x,y) == (0,0) is the upper left screen corner, x increases
-// to the right, y increases downwords.
-
 void lyxbreaker(void const * data, const char * hint, int size);
-void lyxaborter(int x, int y);
 
 class Point {
 public:
@@ -92,21 +86,55 @@ private:
        cache_type data_;
 };
 
-
+/**
+ * A global cache that allows us to come from a paragraph in a document
+ * to a position point on the screen.
+ * All points cached in this cache are only valid between subsequent
+ * updated. (x,y) == (0,0) is the upper left screen corner, x increases
+ * to the right, y increases downwords.
+ * The cache is built in BufferView::Pimpl::metrics which is called
+ * from BufferView::Pimpl::update. The individual points are added
+ * while we paint them. See for instance paintPar in RowPainter.C.
+ */
 class CoordCache {
 public:
+       CoordCache() : updating(false) { }
+       /// In order to find bugs, we record when we start updating the cache
+       void startUpdating();
+       /// When we are done, we record that to help find bugs
+       void doneUpdating();
+
        void clear();
        Point get(LyXText const *, lyx::pit_type);
 
+       /// A map from paragraph index number to screen point
+       typedef std::map<lyx::pit_type, Point> InnerParPosCache;
+       /// A map from a LyXText to the map of paragraphs to screen points
+       typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
+
+       /// A map from MathArray to position on the screen
+       CoordCacheBase<MathArray> & arrays() { BOOST_ASSERT(updating); return arrays_; }
+       CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
+       /// A map from insets to positions on the screen
+       CoordCacheBase<InsetBase> & insets() { BOOST_ASSERT(updating); return insets_; }
+       CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
+       /// A map from (LyXText, paragraph) pair to screen positions
+       ParPosCache & parPos() { BOOST_ASSERT(updating); return pars_; }
+       ParPosCache const & getParPos() const { return pars_; }
+private:
        CoordCacheBase<MathArray> arrays_;
        
        // all insets
        CoordCacheBase<InsetBase> insets_;
 
        // paragraph grouped by owning text
-       typedef std::map<lyx::pit_type, Point> InnerParPosCache;
-       typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
        ParPosCache pars_;
+
+       /**
+        * Debugging flag only: Set to true while the cache is being built.
+        * No changes to the structure are allowed unless we are updating.
+        */
+       bool updating;
 };
 
 extern CoordCache theCoords;
index b78d054fc406f2a422f45d731aa27b8054b1ccc3..e0b4e20453f9149743c793c8b5ca74dd3b8f81bc 100644 (file)
@@ -1086,7 +1086,7 @@ Encoding const * LCursor::getEncoding() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText & text = *sl.text();
+       LyXText const & text = *sl.text();
        LyXFont font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
        return font.language()->encoding();
@@ -1127,7 +1127,7 @@ LyXFont LCursor::getFont() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText & text = *sl.text();
+       LyXText const & text = *sl.text();
        LyXFont font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(),
                sl.pos(),
index 59e544736641527e4a129fd010c535eb697bb04b..b98aed8f25df35b131230be3f8201f9974426286 100644 (file)
@@ -104,7 +104,13 @@ MathArray & CursorSlice::cell() const
 }
 
 
-LyXText * CursorSlice::text() const
+LyXText * CursorSlice::text()
+{
+       BOOST_ASSERT(inset_);
+       return inset_->getText(idx_);
+}
+
+LyXText const * CursorSlice::text() const
 {
        BOOST_ASSERT(inset_);
        return inset_->getText(idx_);
index 30f0b95888496a413a63a2673fa589aa29192eff..06414cfc4f2d3f00b6bddd179542ff82cdd1f1f6 100644 (file)
@@ -97,7 +97,9 @@ public:
        /// see comment for the member
        bool & boundary() { return boundary_; }
        ///
-       LyXText * text() const;
+       LyXText * text();
+       ///
+       LyXText const * text() const;
        ///
        UpdatableInset * asUpdatableInset() const;
        ///
index 2e89e4503a84905c2e1b257a6a16f06cbe7b51b5..fe01067aba2016dd186431a6aa70d6f3b90a98f5 100644 (file)
@@ -123,7 +123,13 @@ MathAtom & DocIterator::nextAtom()
 }
 
 
-LyXText * DocIterator::text() const
+LyXText * DocIterator::text()
+{
+       BOOST_ASSERT(!empty());
+       return top().text();
+}
+
+LyXText const * DocIterator::text() const
 {
        BOOST_ASSERT(!empty());
        return top().text();
@@ -146,12 +152,14 @@ Paragraph const & DocIterator::paragraph() const
 
 Row & DocIterator::textRow()
 {
+       BOOST_ASSERT(!paragraph().rows().empty());
        return paragraph().getRow(pos());
 }
 
 
 Row const & DocIterator::textRow() const
 {
+       BOOST_ASSERT(!paragraph().rows().empty());
        return paragraph().getRow(pos());
 }
 
@@ -233,7 +241,18 @@ bool DocIterator::inTexted() const
 }
 
 
-LyXText * DocIterator::innerText() const
+LyXText * DocIterator::innerText()
+{
+       BOOST_ASSERT(!empty());
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (int i = size() - 1; i >= 0; --i)
+               if (operator[](i).text())
+                       return operator[](i).text();
+       return 0;
+}
+
+LyXText const * DocIterator::innerText() const
 {
        BOOST_ASSERT(!empty());
        // go up until first non-0 text is hit
index da4f082c0c1ec09f9ddb243e747d6d023d2692a4..b5a1e80659cd622587cda55c9b86dcef605732af 100644 (file)
@@ -151,11 +151,15 @@ public:
        /// the row in the paragraph we're in
        Row const & textRow() const;
        ///
-       LyXText * text() const;
+       LyXText * text();
+       ///
+       LyXText const * text() const;
        ///
        InsetBase * innerInsetOfType(int code) const;
        ///
-       LyXText * innerText() const;
+       LyXText * innerText();
+       ///
+       LyXText const * innerText() const;
 
        //
        // elementary moving
index ee538e0e86efb7716531746d34b0620c2e4cb172..a48187693fec8c8a93a5313f116fbe944c6a3cdd 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-31  Asger Ottar Alstrup  <aalstrup@laerdal.dk>
+
+       * inset.C:
+       * insetbase.C:
+       * insettabular.C:
+       * updatableinset.C: Use new cursor accessors.
+
 2005-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * insetinclude.C (loadIfNeeded): rewrite to use boost.filesystem
index 7cecf34e2ca3812e52ec7b6d3b7ddfa37ccad1ef..ef46cd2406ce3d107e117606a01c08a60a018312 100644 (file)
@@ -79,5 +79,5 @@ int InsetOld::scroll(bool) const
 void InsetOld::setPosCache(PainterInfo const &, int x, int y) const
 {
        //lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
-       theCoords.insets_.add(this, x, y);
+       theCoords.insets().add(this, x, y);
 }
index bc390d79b9617b9871869c771296b88f065dea32..b29fb8e24cdd64233d822f96e48e388d6493185c 100644 (file)
@@ -293,13 +293,13 @@ bool InsetBase::editing(BufferView * bv) const
 
 int InsetBase::xo() const
 {
-       return theCoords.insets_.x(this);
+       return theCoords.getInsets().x(this);
 }
 
 
 int InsetBase::yo() const
 {
-       return theCoords.insets_.y(this);
+       return theCoords.getInsets().y(this);
 }
 
 
@@ -310,7 +310,7 @@ bool InsetBase::covers(int x, int y) const
        //      << " x1: " << xo() << " x2: " << xo() + width()
        //      << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
        //      << std::endl;
-       return theCoords.insets_.has(this)
+       return theCoords.getInsets().has(this)
                        && x >= xo()
                        && x <= xo() + width()
                        && y >= yo() - ascent()
index 6a10ab8f77c438f5dd4a126e2e389d62e273ce5e..31d4744469ae64fc378ce04a488be2207b5e861a 100644 (file)
@@ -1024,7 +1024,7 @@ int dist(InsetOld const & inset, int x, int y)
 {
        int xx = 0;
        int yy = 0;
-       Point o = theCoords.insets_.xy(&inset);
+       Point o = theCoords.getInsets().xy(&inset);
        int const xo = o.x_;
        int const yo = o.y_;
 
@@ -1055,7 +1055,7 @@ InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
        idx_type idx_min = 0;
        int dist_min = std::numeric_limits<int>::max();
        for (idx_type i = 0; i < nargs(); ++i) {
-               if (theCoords.insets_.has(tabular.getCellInset(i).get())) {
+               if (theCoords.getInsets().has(tabular.getCellInset(i).get())) {
                        int d = dist(*tabular.getCellInset(i), x, y);
                        if (d < dist_min) {
                                dist_min = d;
index 1018a97bde0d12f5575bd1bed0d36f18bf5fb2d0..3d62deed019ab9bf8e3a37a650de677266c276b2 100644 (file)
@@ -43,7 +43,7 @@ void UpdatableInset::scroll(BufferView & bv, double s) const
        }
 
        int const workW = bv.workWidth();
-       int xo_ = theCoords.insets_.x(this);
+       int xo_ = theCoords.getInsets().x(this);
        int const tmp_xo_ = xo_ - scx;
 
        if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
@@ -63,7 +63,7 @@ void UpdatableInset::scroll(BufferView & bv, double s) const
 
 void UpdatableInset::scroll(BufferView & bv, int offset) const
 {
-       int const xo_ = theCoords.insets_.x(this);
+       int const xo_ = theCoords.getInsets().x(this);
        if (offset > 0) {
                if (!scx && xo_ >= 20)
                        return;
index 58329a13385e9359b50371e1ab36ca3252dbbda8..d1818ea203bcd84d37cb367ccc56feacb4636285 100644 (file)
 
 #include "support/types.h"
 
-///
+/**
+ * An on-screen row of text. A paragraph is broken into a 
+ * RowList for display. Each Row contains position pointers
+ * into the first and last character positions of that row.
+ */
 class Row {
 public:
        ///
index 07b4765bd077b3a047ffca18a0b34969a8c472fc..24191ccaad015f7c6b09c484c7867dd4c1fb08f8 100644 (file)
@@ -70,7 +70,7 @@ public:
                bool toggleall);
 
        /// what you expect when pressing <enter> at cursor position
-       void breakParagraph(LCursor & cur, char keep_layout = 0);
+       void breakParagraph(LCursor & cur, bool keep_layout = false);
 
        /// set layout over selection
        pit_type setLayout(pit_type start, pit_type end,
@@ -124,7 +124,7 @@ public:
                FuncStatus & status) const;
 
        /// access to out BufferView. This should go...
-       BufferView * bv();
+//     BufferView * bv();
        /// access to out BufferView. This should go...
        BufferView * bv() const;
 
index 3de9c489f6775a5f4f5d6d31a7afd62713e1a94d..2717e0cef9f70f22d367ca1b6f9b33cb75e2d436 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-31  Asger Ottar Alstrup  <aalstrup@laerdal.dk>
+
+       * math_data.C:
+       * math_diminset.C:
+       * math_nestinset.C: Use new cursor accessors.
+
 2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * math_parser.C,math_sizeinset.C: use convert<> instead of
index 9c1c3c6931c2cbb94a8ac74f16081155463e1d23..ffda365de26ed54d09a107b4b2f8566e24ac731e 100644 (file)
@@ -411,17 +411,17 @@ int MathArray::dist(int x, int y) const
 void MathArray::setXY(int x, int y) const
 {
        //lyxerr << "setting position cache for MathArray " << this << std::endl;
-       theCoords.arrays_.add(this, x, y);
+       theCoords.arrays().add(this, x, y);
 }
 
 
 int MathArray::xo() const
 {
-       return theCoords.arrays_.x(this);
+       return theCoords.getArrays().x(this);
 }
 
 
 int MathArray::yo() const
 {
-       return theCoords.arrays_.y(this);
+       return theCoords.getArrays().y(this);
 }
index 00a1befa17a8a07ac49a2628e177e54621fdb1b4..939e4b89a82a63b41da6dc726a9c665f5bb683fb 100644 (file)
@@ -40,5 +40,5 @@ int MathDimInset::width() const
 void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
 {
        //lyxerr << "MathDimInset: cache to " << x << " " << y << std::endl;
-       theCoords.insets_.add(this, x, y);
+       theCoords.insets().add(this, x, y);
 }
index 6702a9af8be6dfd287e0a9af384059a84f1be1d4..e7896596969790176665ceed221cfaf45b7136a9 100644 (file)
@@ -110,23 +110,23 @@ void MathNestInset::getCursorPos(CursorSlice const & sl,
 // absolute again when actually drawing the cursor. What a mess.
        BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
        MathArray const & ar = sl.cell();
-       if (!theCoords.arrays_.has(&ar)) {
-               // this can (semi-)legally happen if we jsut created this cell
+       if (!theCoords.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;
                x = 0;
                y = 0;
                return;
        }
-       Point const pt = theCoords.arrays_.xy(&ar);
-       if (!theCoords.insets_.has(this)) {
+       Point const pt = theCoords.getArrays().xy(&ar);
+       if (!theCoords.getInsets().has(this)) {
                // same as above
                //lyxerr << "no cached data for inset " << this << endl;
                x = 0;
                y = 0;
                return;
        }
-       Point const pt2 = theCoords.insets_.xy(this);
+       Point const pt2 = theCoords.getInsets().xy(this);
        //lyxerr << "retrieving position cache for MathArray "
        //      << pt.x_ << ' ' << pt.y_ << std::endl;
        x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
index 81e4038a6ece70adf3056534b6ad38e223936089..755966eff1e815076a095c71bae089de2deaf9ee 100644 (file)
@@ -1795,6 +1795,8 @@ bool Paragraph::allowEmpty() const
 
 Row & Paragraph::getRow(pos_type pos)
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::iterator rit = rows_.end();
        RowList::iterator const begin = rows_.begin();
 
@@ -1807,6 +1809,8 @@ Row & Paragraph::getRow(pos_type pos)
 
 Row const & Paragraph::getRow(pos_type pos) const
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::const_iterator rit = rows_.end();
        RowList::const_iterator const begin = rows_.begin();
 
@@ -1819,6 +1823,8 @@ Row const & Paragraph::getRow(pos_type pos) const
 
 size_t Paragraph::pos2row(pos_type pos) const
 {
+       BOOST_ASSERT(!rows().empty());
+
        RowList::const_iterator rit = rows_.end();
        RowList::const_iterator const begin = rows_.begin();
 
@@ -1873,11 +1879,3 @@ void Paragraph::dump() const
        }
 }
 
-//void Paragraph::metrics(MetricsInfo & mi, Dimension & dim, LyXText & text)
-//{
-//}
-//
-//
-//void draw(PainterInfo & pi, int x, int y, LyXText & text) const
-//{
-//}
index fec3d79c7bca768f88c725381d4f9b125ff3f171..57cf9c9ba1dd6579f4e0c62a07b4ae1802eaba99 100644 (file)
@@ -134,7 +134,7 @@ public:
                                  lyx::depth_type depth) const;
 
        /// Can we drop the standard paragraph wrapper?
-       bool Paragraph::emptyTag() const;
+       bool emptyTag() const;
 
        /// Get the id of the paragraph, usefull for docbook and linuxdoc
        std::string getID(Buffer const & buf,
@@ -293,7 +293,7 @@ public:
                BOOST_ASSERT(pos < int(text_.size()));
                return text_[pos];
        }
-       ///
+       /// Get the char, but mirror all bracket characters if it is right-to-left
        value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
        /// The position must already exist.
        void setChar(lyx::pos_type pos, value_type c);
@@ -326,6 +326,9 @@ public:
        InsetBase * getInset(lyx::pos_type pos);
        ///
        InsetBase const * getInset(lyx::pos_type pos) const;
+       ///
+       InsetList insetlist;
+
 
        ///
        bool isHfill(lyx::pos_type pos) const;
@@ -344,7 +347,7 @@ public:
        /// returns -1 if inset not found
        int getPositionOfInset(InsetBase const * inset) const;
 
-       ///
+       /// Returns the number of line breaks and white-space stripped at the start
        int stripLeadingSpaces();
 
        /// return true if we allow multiple spaces
@@ -352,7 +355,7 @@ public:
 
        /// return true if we allow this par to stay empty
        bool allowEmpty() const;
-       ////
+       /// 
        unsigned char transformChar(unsigned char c, lyx::pos_type pos) const;
        ///
        ParagraphParameters & params();
@@ -366,37 +369,34 @@ public:
        ///
        size_t pos2row(lyx::pos_type pos) const;
 
-       ///
-       InsetList insetlist;
-
        /// total height of paragraph
        unsigned int height() const { return dim_.height(); }
        /// total width of paragraph, may differ from workwidth
        unsigned int width() const { return dim_.width(); }
        unsigned int ascent() const { return dim_.ascent(); }
        unsigned int descent() const { return dim_.descent(); }
-       ///
+       /// LyXText updates the rows using this access point
        RowList & rows() { return rows_; }
-       ///
+       /// The painter and others use this
        RowList const & rows() const { return rows_; }
 
-       // compute paragraph metrics    
-       void metrics(MetricsInfo & mi, Dimension & dim, LyXText & text);
-       // draw paragraph
-       void draw(PainterInfo & pi, int x, int y, LyXText & text) const;
-       /// dump some information
-       void dump() const;
+       /// LyXText::redoParagraph updates this
+       Dimension & dim() { return dim_; }
 
+       /// dump some information to lyxerr
+       void dump() const;
+private:
        /// cached dimensions of paragraph
        Dimension dim_;
 
-private:
        ///
        mutable RowList rows_;
        ///
        LyXLayout_ptr layout_;
-       /// keeping this here instead of in the pimpl makes LyX >10% faster
-       // for average tasks as buffer loading/switching etc.
+       /**
+        * Keeping this here instead of in the pimpl makes LyX >10% faster
+        * for average tasks as buffer loading/switching etc.
+        */
        TextContainer text_;
        /// end of label
        lyx::pos_type begin_of_body_;
@@ -406,7 +406,6 @@ private:
        friend class Paragraph::Pimpl;
        ///
        Pimpl * pimpl_;
-
 };
 
 
index 7bf37146d913007c9fc760ab40998ed44b573d50..3686b36c8429da962807f522ca8bcc50b02bcad1 100644 (file)
@@ -21,8 +21,15 @@ class LyXFont;
 class Paragraph;
 class ParagraphList;
 
-
-///
+/**
+ * This breaks a paragraph at the specified position.
+ * The new paragraph will:
+ * get the default layout, when flag == 0
+ * will inherit the existing one, except for depth, when flag == 1
+ * will inherit the existing one, including depth, when flag == 2
+ * Be aware that the old or new paragraph does not contain any rows
+ * after this.
+ */
 void breakParagraph(BufferParams const & bparams,
                    ParagraphList & paragraphs,
                    lyx::pit_type par,
index 7a6ec164f962514334b432ff9d391a2b15a82629..c9ceb39510ea8a3cc3fd47d3ab0e521b831d5cae 100644 (file)
@@ -58,7 +58,7 @@ class RowPainter {
 public:
        /// initialise and run painter
        RowPainter(PainterInfo & pi, LyXText const & text,
-               pit_type pit, Row & row, int x, int y);
+               pit_type pit, Row const & row, int x, int y);
 
        // paint various parts
        void paintAppendix();
@@ -101,7 +101,7 @@ private:
        ParagraphList & pars_;
 
        /// The row to paint
-       Row & row_;
+       Row const & row_;
 
        /// Row's paragraph
        pit_type const pit_;
@@ -119,7 +119,7 @@ private:
 
 
 RowPainter::RowPainter(PainterInfo & pi,
-       LyXText const & text, pit_type pit, Row & row, int x, int y)
+       LyXText const & text, pit_type pit, Row const & row, int x, int y)
        : bv_(*pi.base.bv), pain_(pi.pain), text_(text), pars_(text.paragraphs()),
          row_(row), pit_(pit), par_(text.paragraphs()[pit]),
          xo_(x), yo_(y), width_(text_.width())
@@ -178,7 +178,7 @@ void RowPainter::paintInset(pos_type const pos)
        PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
        pi.base.font = getFont(pos);
        pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
-       theCoords.insets_.add(inset, int(x_), yo_);
+       theCoords.insets().add(inset, int(x_), yo_);
        inset->drawSelection(pi, int(x_), yo_);
        inset->draw(pi, int(x_), yo_);
        x_ += inset->width();
@@ -738,12 +738,12 @@ void paintPar
 
        Paragraph & par = text.paragraphs()[pit];
 
-       RowList::iterator const rb = par.rows().begin();
-       RowList::iterator const re = par.rows().end();
-       theCoords.pars_[&text][pit] = Point(x, y);
+       RowList::const_iterator const rb = par.rows().begin();
+       RowList::const_iterator const re = par.rows().end();
+       theCoords.parPos()[&text][pit] = Point(x, y);
 
        y -= rb->ascent();
-       for (RowList::iterator rit = rb; rit != re; ++rit) {
+       for (RowList::const_iterator rit = rb; rit != re; ++rit) {
                y += rit->ascent();
                bool const inside = (y + rit->descent() >= 0
                                       && y - rit->ascent() < ww);
@@ -801,12 +801,12 @@ void paintText(BufferView const & bv, ViewMetricsInfo const & vi)
        }
 
        // and grey out above (should not happen later)
-       lyxerr << "par ascent: " << text->getPar(vi.p1).ascent() << endl;
+//     lyxerr << "par ascent: " << text->getPar(vi.p1).ascent() << endl;
        if (vi.y1 > 0)
                pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea);
 
        // and possibly grey out below
-       lyxerr << "par descent: " << text->getPar(vi.p1).ascent() << endl;
+//     lyxerr << "par descent: " << text->getPar(vi.p1).ascent() << endl;
        if (vi.y2 < bv.workHeight())
                pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea);
 }
index 089dceb5c274ff9b055c840d5fca7038c269b1c1..9c04cb9a53f425f488970e63872a0ecd135171ea 100644 (file)
@@ -376,12 +376,6 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
 } // namespace anon
 
 
-BufferView * LyXText::bv()
-{
-       BOOST_ASSERT(bv_owner != 0);
-       return bv_owner;
-}
-
 
 BufferView * LyXText::bv() const
 {
@@ -1017,7 +1011,7 @@ namespace {
 
 }
 
-void LyXText::breakParagraph(LCursor & cur, char keep_layout)
+void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
 {
        BOOST_ASSERT(this == cur.text());
        // allow only if at start or end, or all previous is new text
@@ -1045,25 +1039,30 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
        if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
                cpar.erase(cur.pos());
 
-       // break the paragraph
+       // How should the layout for the new paragraph be?
+       int preserve_layout = 0;
        if (keep_layout)
-               keep_layout = 2;
+               preserve_layout = 2;
        else
-               keep_layout = layout->isEnvironment();
+               preserve_layout = layout->isEnvironment();
+
+       // We need to remember this before we break the paragraph, because
+       // that invalidates the layout variable
+       bool sensitive = layout->labeltype == LABEL_SENSITIVE;
 
-       // we need to set this before we insert the paragraph. IMO the
-       // breakParagraph call should return a bool if it inserts the
-       // paragraph before or behind and we should react on that one
-       // but we can fix this in 1.3.0 (Jug 20020509)
+       // we need to set this before we insert the paragraph.
        bool const isempty = cpar.allowEmpty() && cpar.empty();
+
        ::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
-                        cur.pos(), keep_layout);
+                        cur.pos(), preserve_layout);
+
+       // After this, neither paragraph contains any rows!
 
        cpit = cur.pit();
        pit_type next_par = cpit + 1;
 
        // well this is the caption hack since one caption is really enough
-       if (layout->labeltype == LABEL_SENSITIVE) {
+       if (sensitive) {
                if (cur.pos() == 0)
                        // set to standard-layout
                        pars_[cpit].applyLayout(tclass.defaultLayout());
@@ -1072,16 +1071,6 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
                        pars_[next_par].applyLayout(tclass.defaultLayout());
        }
 
-       // if the cursor is at the beginning of a row without prior newline,
-       // move one row up!
-       // This touches only the screen-update. Otherwise we would may have
-       // an empty row on the screen
-       if (cur.pos() != 0 && cur.textRow().pos() == cur.pos()
-           && !pars_[cpit].isNewline(cur.pos() - 1))
-       {
-               cursorLeft(cur);
-       }
-
        while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
                pars_[next_par].erase(0);
 
@@ -1172,8 +1161,8 @@ void LyXText::insertChar(LCursor & cur, char c)
                                cur.message(_("You cannot insert a space at the "
                                        "beginning of a paragraph. Please read the Tutorial."));
                                sent_space_message = true;
-                               return;
                        }
+                       return;
                }
                BOOST_ASSERT(cur.pos() > 0);
                if (par.isLineSeparator(cur.pos() - 1)
@@ -1686,7 +1675,7 @@ void LyXText::redoParagraph(pit_type const pit)
 
        dim.asc += par.rows()[0].ascent();
        dim.des -= par.rows()[0].ascent();
-       par.dim_ = dim;
+       par.dim() = dim;
        //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
 }
 
index 324d3cbef4d63f0f27407680b2870c52789bfb85..683e47efd1043a09c47b72bb4dadf58e08de53ef 100644 (file)
@@ -119,7 +119,7 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const
                InsetBase * inset = iit->inset;
 #if 1
                lyxerr << "examining inset " << inset << endl;
-               if (theCoords.insets_.has(inset))
+               if (theCoords.getInsets().has(inset))
                        lyxerr
                                << " xo: " << inset->xo() << "..."
                                << inset->xo() + inset->width()
@@ -1122,8 +1122,8 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
 pit_type LyXText::getPitNearY(int y) const
 {
        BOOST_ASSERT(!paragraphs().empty());
-       BOOST_ASSERT(theCoords.pars_.find(this) != theCoords.pars_.end());
-       CoordCache::InnerParPosCache const & cc = theCoords.pars_[this];
+       BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end());
+       CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second;
        lyxerr << "LyXText::getPitNearY: y: " << y << " cache size: "
                << cc.size() << endl;
 
@@ -1282,8 +1282,6 @@ void LyXText::cursorUp(LCursor & cur)
 
 void LyXText::cursorDown(LCursor & cur)
 {
-
-
        Paragraph const & par = cur.paragraph();
        int const row = par.pos2row(cur.pos());
        int const x = cur.targetX();
index daf8a9ab7216eb6825835c9f4273700d5af815b1..57178abd549fa747afc89fcdff08b866970c77c9 100644 (file)
@@ -353,7 +353,7 @@ bool LyXText::isRTL(Paragraph const & par) const
 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
-       //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
+       lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
 
        BOOST_ASSERT(cur.text() == this);
        BufferView * bv = &cur.bv();