]> git.lyx.org Git - features.git/commitdiff
rowlist7
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 31 Mar 2003 16:57:45 +0000 (16:57 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 31 Mar 2003 16:57:45 +0000 (16:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6663 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/RowList.C
src/RowList.h
src/lyxtext.h
src/text.C
src/text2.C

index 87f859a240d0d5915cd3f4c9c682784e7d1b41da..3ba04c78f6585e6f15a1f8fd2626f82a30a7aab3 100644 (file)
@@ -1,5 +1,22 @@
 2003-03-31  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
+       * text2.C (redoParagraphs): adjust
+       (updateCounters): adjust
+       (checkParagraph): adjust
+       (getColumnNearX): adjust and reformat a bit.
+
+       * text.C (top_y): adjust
+       (workWidth): adjust
+       (leftMargin): adjust
+       (prepareToPrint): adjust
+       (getRow): adjust
+       (getRowNearY): adjust
+
+       * lyxtext.h: make rowlist_ mutable.
+
+       * RowList.h: add const_iterator
+       * RowList.C: adjust for RowList::const_iterator.
+
        * text2.C (getCursorX): make it take a RowList::iterator as arg,
        adjust.
 
index 70e11bb05679c33382130876d62f3343ea85c21a..3693c9c048ad95afbda1eb70c55325437a14d0f1 100644 (file)
@@ -79,6 +79,81 @@ bool operator!=(RowList::iterator const & i1,
 }
 
 
+////////// The RowList::const_iterator
+
+RowList::const_iterator::const_iterator()
+       : ptr(0)
+{}
+
+
+RowList::const_iterator::const_iterator(Row * p)
+       : ptr(p)
+{}
+
+
+RowList::const_iterator::const_reference
+RowList::const_iterator::operator*()
+{
+       return *ptr;
+}
+
+
+RowList::const_iterator::const_pointer
+RowList::const_iterator::operator->()
+{
+       return ptr;
+}
+
+
+RowList::const_iterator &
+RowList::const_iterator::operator++()
+{
+       ptr = ptr->next();
+       return *this;
+}
+
+
+RowList::const_iterator
+RowList::const_iterator::operator++(int)
+{
+       const_iterator tmp = *this;
+       ++*this;
+       return tmp;
+}
+
+
+RowList::const_iterator &
+RowList::const_iterator::operator--()
+{
+       ptr = ptr->previous();
+       return *this;
+}
+
+
+RowList::const_iterator
+RowList::const_iterator::operator--(int)
+{
+       const_iterator tmp = *this;
+       --*this;
+       return tmp;
+}
+
+
+bool operator==(RowList::const_iterator const & i1,
+               RowList::const_iterator const & i2)
+{
+       return &(*const_cast<RowList::const_iterator&>(i1))
+           == &(*const_cast<RowList::const_iterator&>(i2));
+}
+
+
+bool operator!=(RowList::const_iterator const & i1,
+               RowList::const_iterator const & i2)
+{
+       return !(i1 == i2);
+}
+
+
 ////////// The RowList proper
 RowList::RowList()
        : rowlist(0)
@@ -144,9 +219,9 @@ RowList::iterator RowList::begin()
 }
 
 
-RowList::iterator RowList::begin() const
+RowList::const_iterator RowList::begin() const
 {
-       return iterator(rowlist);
+       return const_iterator(rowlist);
 }
 
 
@@ -156,9 +231,9 @@ RowList::iterator RowList::end()
 }
 
 
-RowList::iterator RowList::end() const
+RowList::const_iterator RowList::end() const
 {
-       return iterator();
+       return const_iterator();
 }
 
 
@@ -192,12 +267,6 @@ Row & RowList::back()
 }
 
 
-void RowList::set(Row * p)
-{
-       rowlist = p;
-}
-
-
 void RowList::push_back(Row * p)
 {
        if (!rowlist) {
index f5a6a457f7b165384840d8ca468c698a5803ae22..7fe84e322fcbafa8bf6d186c82c4332c88be1975 100644 (file)
@@ -44,6 +44,39 @@ public:
                Row * ptr;
        };
        ///
+       class const_iterator {
+       public:
+               ///
+               typedef std::bidirectional_iterator_tag iterator_category;
+               ///
+               typedef Row * value_type;
+               ///
+               typedef ptrdiff_t difference_type;
+               ///
+               typedef Row const * const_pointer;
+               ///
+               typedef Row const & const_reference;
+               ///
+               const_iterator();
+               ///
+               const_iterator(value_type);
+               ///
+               const_reference operator*();
+               ///
+               const_pointer operator->();
+               ///
+               const_iterator & operator++();
+               ///
+               const_iterator operator++(int);
+               ///
+               const_iterator & operator--();
+               ///
+               const_iterator operator--(int);
+       private:
+               ///
+               Row * ptr;
+       };
+       ///
        RowList();
        ///
        iterator insert(iterator it, Row * row);
@@ -54,13 +87,11 @@ public:
        ///
        iterator begin();
        ///
-       iterator begin() const;
+       const_iterator begin() const;
        ///
        iterator end();
        ///
-       iterator end() const;
-       ///
-       void set(Row *);
+       const_iterator end() const;
        ///
        void push_back(Row *);
        ///
@@ -87,4 +118,11 @@ bool operator==(RowList::iterator const & i1,
 bool operator!=(RowList::iterator const & i1,
                RowList::iterator const & i2);
 
+///
+bool operator==(RowList::const_iterator const & i1,
+               RowList::const_iterator const & i2);
+///
+bool operator!=(RowList::const_iterator const & i1,
+               RowList::const_iterator const & i2);
+
 #endif
index d6e8d89137c9b1fa46ad087b8d80a169493823a1..8b3f2c01113971f84ebcbff3ca9aa29ec64cb34e 100644 (file)
@@ -239,7 +239,7 @@ public:
         x is set to the real beginning of this column
         */
        lyx::pos_type getColumnNearX(RowList::iterator rit,
-                                           int & x, bool & boundary) const;
+                                    int & x, bool & boundary) const;
 
        /** returns a pointer to a specified row. y is set to the beginning
         of the row
@@ -490,7 +490,7 @@ public:
        bool bidi_InRange(lyx::pos_type pos) const;
 private:
        ///
-       RowList rowlist_;
+       mutable RowList rowlist_;
        ///
        void cursorLeftOneWord(LyXCursor &);
 
index e900b46d2a40af60bbe008a5c16d9c12fe67312e..14994acc4d8cec8ade27b1aae91a2e57adfbe296 100644 (file)
@@ -74,13 +74,13 @@ BufferView * LyXText::bv() const
 
 int LyXText::top_y() const
 {
-       if (anchor_row_ == rows().end())
+       if (anchor_row_ == rowlist_.end())
                return 0;
 
        int y = 0;
 
-       RowList::iterator rit = rows().begin();
-       RowList::iterator end = rows().end();
+       RowList::iterator rit = rowlist_.begin();
+       RowList::iterator end = rowlist_.end();
        for (; rit != end && rit != anchor_row_; ++rit) {
                y += rit->height();
        }
@@ -154,7 +154,7 @@ int LyXText::workWidth(Inset * inset) const
                int dummy_y;
                RowList::iterator row = getRow(par, pos, dummy_y);
                RowList::iterator frow = row;
-               RowList::iterator beg = rows().begin();
+               RowList::iterator beg = rowlist_.begin();
 
                while (frow != beg && frow->par() == boost::prior(frow)->par())
                        --frow;
@@ -632,12 +632,12 @@ int LyXText::leftMargin(RowList::iterator rit) const
 
                // find the first row of this paragraph
                RowList::iterator tmprit = rit;
-               while (tmprit != rows().begin()
+               while (tmprit != rowlist_.begin()
                       && boost::prior(tmprit)->par() == rit->par())
                        --tmprit;
 
                int minfill = tmprit->fill();
-               while (boost::next(tmprit) != rows().end() &&
+               while (boost::next(tmprit) != rowlist_.end() &&
                       boost::next(tmprit)->par() == rit->par()) {
                        ++tmprit;
                        if (tmprit->fill() < minfill)
@@ -907,7 +907,7 @@ LyXText::rowBreakPoint(Row const & row) const
 
 
 // returns the minimum space a row needs on the screen in pixel
-int LyXText::fill(Row & row, int paper_width) const
+int LyXText::fill(Row & row, int paper_width)
 {
        if (paper_width < 0)
                return 0;
@@ -1892,13 +1892,15 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x,
 
                switch (align) {
            case LYX_ALIGN_BLOCK:
+           {
                        ns = rit->numberOfSeparators();
-                       if (ns && boost::next(rit) != rows().end() &&
-                           boost::next(rit)->par() == rit->par() &&
-                           !(boost::next(rit)->par()->isNewline(boost::next(rit)->pos() - 1))
-                           && !(boost::next(rit)->par()->isInset(boost::next(rit)->pos())
-                                && boost::next(rit)->par()->getInset(boost::next(rit)->pos())
-                                && boost::next(rit)->par()->getInset(boost::next(rit)->pos())->display())
+                       RowList::iterator next_row = boost::next(rit);
+                       if (ns && next_row != rowlist_.end() &&
+                           next_row->par() == rit->par() &&
+                           !(next_row->par()->isNewline(next_row->pos() - 1))
+                           && !(next_row->par()->isInset(next_row->pos()) &&
+                                next_row->par()->getInset(next_row->pos()) &&
+                                next_row->par()->getInset(next_row->pos())->display())
                                )
                        {
                                fill_separator = w / ns;
@@ -1906,6 +1908,7 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x,
                                x += w;
                        }
                        break;
+           }
            case LYX_ALIGN_RIGHT:
                        x += w;
                        break;
@@ -2783,11 +2786,11 @@ LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
        y = 0;
 
        if (rows().empty())
-               return rows().end();
+               return rowlist_.end();
 
        // find the first row of the specified paragraph
-       RowList::iterator rit = rows().begin();
-       RowList::iterator end = rows().end();
+       RowList::iterator rit = rowlist_.begin();
+       RowList::iterator end = rowlist_.end();
        while (boost::next(rit) != end && rit->par() != par) {
                y += rit->height();
                ++rit;
@@ -2811,17 +2814,16 @@ RowList::iterator LyXText::getRowNearY(int & y) const
        // If possible we should optimize this method. (Lgb)
        int tmpy = 0;
 
-       RowList::iterator rit = rows().begin();
-       RowList::iterator end = rows().end();
+       RowList::iterator rit = rowlist_.begin();
+       RowList::iterator end = rowlist_.end();
 
        while (rit != end && boost::next(rit) != end && tmpy + rit->height() <= y) {
                tmpy += rit->height();
                ++rit;
        }
 
-       y = tmpy;   // return the real y
-
-       //lyxerr << "returned y = " << y << endl;
+       // return the real y
+       y = tmpy;
 
        return rit;
 }
index 9d190a8d42c547ecc32413ca544bcabef39285ca..d0b793b8662548414043bc1d2e576a2e443126c5 100644 (file)
@@ -750,7 +750,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
                setHeightOfRow(prevrow);
                const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
        } else {
-               setHeightOfRow(&*rows().begin());
+               setHeightOfRow(rows().begin());
                const_cast<LyXText *>(this)->postPaint(0);
        }
 
@@ -1289,7 +1289,7 @@ void LyXText::updateCounters()
                string const & newLabel = par->params().labelString();
 
                if (oldLabel.empty() && !newLabel.empty()) {
-                       removeParagraph(&*rowit);
+                       removeParagraph(rowit);
                        appendParagraph(rowit);
                }
 
@@ -1575,7 +1575,7 @@ void LyXText::checkParagraph(Paragraph * par, pos_type pos)
                        y -= boost::prior(row)->height();
                        postPaint(y);
 
-                       breakAgain(&*boost::prior(row));
+                       breakAgain(boost::prior(row));
 
                        // set the cursor again. Otherwise
                        // dangling pointers are possible
@@ -1946,15 +1946,16 @@ LyXText::getColumnNearX(RowList::iterator rit, int & x,
                vc = last + 1;
 
        boundary = false;
-       bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
-                                        // some speedup if rtl_support=false
-               && (boost::next(rit) == rows().end() ||
-                   boost::next(rit)->par() != rit->par());
+       // This (rtl_support test) is not needed, but gives
+       // some speedup if rtl_support=false
+       bool const lastrow = lyxrc.rtl_support &&
+               (boost::next(rit) == rowlist_.end() ||
+                boost::next(rit)->par() != rit->par());
+       // If lastrow is false, we don't need to compute
+       // the value of rtl.
        bool const rtl = (lastrow)
                ? rit->par()->isRightToLeftPar(bv()->buffer()->params)
-               : false; // If lastrow is false, we don't need to compute
-                        // the value of rtl.
-
+               : false;
        if (lastrow &&
                 ((rtl &&  left_side && vc == rit->pos() && x < tmpx - 5) ||
                   (!rtl && !left_side && vc == last + 1   && x > tmpx + 5)))