]> git.lyx.org Git - features.git/commitdiff
rowlist2
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 29 Mar 2003 23:11:20 +0000 (23:11 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 29 Mar 2003 23:11:20 +0000 (23:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6646 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/insets/ChangeLog
src/insets/insetert.C
src/insets/insetminipage.C
src/insets/insettext.C
src/lyxrow.C
src/lyxrow.h
src/lyxtext.h
src/text.C
src/text2.C

index f8b2870b663d31409222d7c88e6eb4848e314e0f..8664dc0b68c38409b46151e0a741284dc5804fb2 100644 (file)
@@ -1,3 +1,29 @@
+2003-03-30  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * text2.C (init): adjust
+       (insertRow): remove function
+       (insertParagraph): adjust
+       (redoParagraphs): adjust
+       (fullRebreak): adjust
+       (updateCounters): adjust
+
+       * text.C (top_y): rewrite to use RowList iterators.
+       (top_y): adjust
+       (setHeightOfRow): rewrite to sue RowList iterators.
+       (appendParagraph): adjust
+       (breakAgain): adjust
+       (breakAgainOneRow): adjust
+       (breakParagraph): adjust
+       (getRow): adjust
+       (getRowNearY): adjust, and remove commented code.
+
+       * lyxtext.h (firstRow): delete function
+       (lastRow): delete function
+       (rows): new function (const and non-const versions.)
+       (insertRow): delete function
+
+       * lyxrow.[Ch] (Row): new constructor taking a par and a pos
+
 2003-03-29  John Levon  <levon@movementarian.org>
 
        * BufferView_pimpl.C: always update scrollbar top
index 0d62850b38da09da6c0c12f06f8a532d5d80c4f9..fb60c92316d971c4de7a0d5bd70675e7fef625ec 100644 (file)
@@ -1,3 +1,16 @@
+2003-03-30  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * insettext.C (ascent): adjust for RowList
+       (descent): ditto
+       (draw): ditto
+       (getLyXText): adjust
+       (toggleSelection): adjust
+
+       * insetminipage.C (localDispatch): adjust for RowList
+
+       * insetert.C (localDispatch): adjust for RowList
+       (getMaxWidth): adjust for RowList
+
 2003-03-29  John Levon  <levon@movementarian.org>
 
        * insetert.C: Alert cleanup
index 0774d61ee0a0400d61eb5854908f9b6f502d66f8..6499ea54b173deb16d5bf7c7dce0f3c24e71fa5e 100644 (file)
@@ -455,7 +455,7 @@ Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
                 * taken by the text).
                 */
                LyXText * t = inset.getLyXText(cmd.view());
-               t->need_break_row = t->firstRow();
+               t->need_break_row = &*t->rows().begin();
                t->fullRebreak();
                t->setCursorIntern(t->cursor.par(), t->cursor.pos());
                inset.update(cmd.view(), true);
@@ -677,11 +677,11 @@ int InsetERT::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
        if (status_ != Inlined || w < 0)
                return w;
        LyXText * text = inset.getLyXText(bv);
-       int rw = text->firstRow()->width();
+       int rw = text->rows().begin()->width();
        if (!rw)
                rw = w;
        rw += 40;
-       if (!text->firstRow()->next() && rw < w)
+       if (text->rows().size() == 1 && rw < w)
                return -1;
        return w;
 }
index 98ffdb2bcb0976fa802fe572119e6f6cb17bdfb0..bc0ffda2d158904d00de023d7d31ab821cd92214 100644 (file)
@@ -120,7 +120,7 @@ dispatch_result InsetMinipage::localDispatch(FuncRequest const & cmd)
                /* FIXME: I refuse to believe we have to live
                 * with ugliness like this ... */
                LyXText * t = inset.getLyXText(cmd.view());
-               t->need_break_row = t->firstRow();
+               t->need_break_row = &*t->rows().begin();
                t->fullRebreak();
                inset.update(cmd.view(), true);
                t->setCursorIntern(t->cursor.par(), t->cursor.pos());
index ebf879445e3479c3888a625cb22f61de0edfeea3..6a523f2a843a45d36bcd0a7a5cfeac2ee3e1a089 100644 (file)
@@ -297,7 +297,7 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
 
 int InsetText::ascent(BufferView * bv, LyXFont const &) const
 {
-       insetAscent = getLyXText(bv)->firstRow()->ascent_of_text() +
+       insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() +
                TEXT_TO_INSET_OFFSET;
        return insetAscent;
 }
@@ -306,7 +306,7 @@ int InsetText::ascent(BufferView * bv, LyXFont const &) const
 int InsetText::descent(BufferView * bv, LyXFont const &) const
 {
        LyXText * llt = getLyXText(bv);
-       insetDescent = llt->height - llt->firstRow()->ascent_of_text() +
+       insetDescent = llt->height - llt->rows().begin()->ascent_of_text() +
                TEXT_TO_INSET_OFFSET;
        return insetDescent;
 }
@@ -396,15 +396,17 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        }
        x += TEXT_TO_INSET_OFFSET;
 
-       Row * row = lt->firstRow();
-       int y_offset = baseline - row->ascent_of_text();
+       RowList::iterator rowit = lt->rows().begin();
+       RowList::iterator end = lt->rows().end();
+
+       int y_offset = baseline - rowit->ascent_of_text();
        int ph = pain.paperHeight();
        int first = 0;
        int y = y_offset;
-       while ((row != 0) && ((y+row->height()) <= 0)) {
-               y += row->height();
-               first += row->height();
-               row = row->next();
+       while ((rowit != end) && ((y + rowit->height()) <= 0)) {
+               y += rowit->height();
+               first += rowit->height();
+               ++rowit;
        }
        if (y_offset < 0) {
                lt->top_y(-y_offset);
@@ -417,12 +419,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        int yf = y_offset + first;
        y = 0;
-       while ((row != 0) && (yf < ph)) {
-               RowPainter rp(*bv, *lt, *row);
+       while ((rowit != end) && (yf < ph)) {
+               RowPainter rp(*bv, *lt, *rowit);
                rp.paint(y + y_offset + first, int(x), y + lt->top_y());
-               y += row->height();
-               yf += row->height();
-               row = row->next();
+               y += rowit->height();
+               yf += rowit->height();
+               ++rowit;
        }
 
        lt->clearPaint();
@@ -2155,7 +2157,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
                if (recursive && the_locking_inset)
                        return the_locking_inset->getLyXText(lbv, true);
                LyXText * lt = cached_text.get();
-               lyx::Assert(lt && lt->firstRow()->par() == &*(paragraphs.begin()));
+               lyx::Assert(lt && lt->rows().begin()->par() == &*(paragraphs.begin()));
                return lt;
        }
        // Super UGLY! (Lgb)
@@ -2524,12 +2526,13 @@ void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
 
        int x = top_x + TEXT_TO_INSET_OFFSET;
 
-       Row * row = lt->firstRow();
-       int y_offset = top_baseline - row->ascent_of_text();
+       RowList::iterator rowit = lt->rows().begin();
+       RowList::iterator end = lt->rows().end();
+       int y_offset = top_baseline - rowit->ascent_of_text();
        int y = y_offset;
-       while ((row != 0) && ((y+row->height()) <= 0)) {
-               y += row->height();
-               row = row->next();
+       while ((rowit != end) && ((y + rowit->height()) <= 0)) {
+               y += rowit->height();
+               ++rowit;
        }
        if (y_offset < 0)
                y_offset = y;
index ca328bc33f5abdaa5eedb4647548b95af8acc384..956c350ee607b569786a3531ff1ee64ecaf7aade 100644 (file)
@@ -28,6 +28,12 @@ Row::Row()
 {}
 
 
+Row::Row(Paragraph * pa, pos_type po)
+       : par_(pa), pos_(po), fill_(0), height_(0), width_(0),
+         ascent_of_text_(0), baseline_(0), next_(0), previous_(0)
+{}
+
+
 Paragraph * Row::par()
 {
        return par_;
index 68f229f7fb44ec8268f3e0d33ef544732b75699c..ef7e6bc33cff5fd8f20c364d51aac75fd4938148 100644 (file)
@@ -23,7 +23,8 @@ class Row {
 public:
        ///
        Row();
-
+       ///
+       Row(Paragraph * pa, lyx::pos_type po);
        ///
        void par(Paragraph * p);
        ///
index beddb960e5110511393471eda4c32e9637bd5e95..fc1a76e12769135ed275828b6b890207b117b3fe 100644 (file)
@@ -245,12 +245,14 @@ public:
         of the row
         */
        Row * getRow(Paragraph * par, lyx::pos_type pos, int & y) const;
-       /** returns the firstrow, this could be done with the above too but
-           IMO it's stupid to have to allocate a dummy y all the time I need
-           the first row
-       */
-       Row * firstRow() const { return &*rowlist_.begin(); }
-       Row * lastRow() const { return &const_cast<LyXText*>(this)->rowlist_.back(); }
+
+       RowList & rows() {
+               return rowlist_;
+       }
+       RowList const & rows() const {
+               return rowlist_;
+       }
+
        /** The cursor.
          Later this variable has to be removed. There should be now internal
          cursor in a text (and thus not in a buffer). By keeping this it is
@@ -508,11 +510,6 @@ private:
          */
        string copylayouttype;
 
-       /** inserts a new row behind the specified row, increments
-           the touched counters */
-       RowList::iterator
-       insertRow(RowList::iterator rowit,
-                 Paragraph * par, lyx::pos_type pos);
        /// removes the row and reset the touched counters
        void removeRow(Row * row);
 
index d615e7e5ad47206bf2b35e999f8998bdedc1ae99..3a735c3c0ee2cea680bf1792481a911bbbea3d09 100644 (file)
@@ -78,9 +78,11 @@ int LyXText::top_y() const
                return 0;
 
        int y = 0;
-       for (Row * row = firstRow();
-            row && row != anchor_row_; row = row->next()) {
-               y += row->height();
+
+       RowList::iterator rit = rows().begin();
+       RowList::iterator end = rows().end();
+       for (; rit != end && rit != anchor_row_; ++rit) {
+               y += rit->height();
        }
        return y + anchor_row_offset_;
 }
@@ -88,7 +90,7 @@ int LyXText::top_y() const
 
 void LyXText::top_y(int newy)
 {
-       if (!firstRow())
+       if (rows().empty())
                return;
        lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
 
@@ -993,6 +995,7 @@ LColor::color LyXText::backgroundColor() const
                return LColor::background;
 }
 
+
 void LyXText::setHeightOfRow(Row * row)
 {
        // get the maximum ascent and the maximum descent
@@ -1299,12 +1302,12 @@ void LyXText::setHeightOfRow(Row * row)
        }
        row->width(int(maxwidth + x));
        if (inset_owner) {
-               Row * r = firstRow();
                width = max(0, workWidth());
-               while (r) {
-                       if (r->width() > width)
-                               width = r->width();
-                       r = r->next();
+               RowList::iterator rit = rows().begin();
+               RowList::iterator end = rows().end();
+               for (; rit != end; ++rit) {
+                       if (rit->width() > width)
+                               width = rit->width();
                }
        }
 }
@@ -1326,7 +1329,8 @@ void LyXText::appendParagraph(RowList::iterator rowit)
 
                if (z < last) {
                        ++z;
-                       rowit = insertRow(rowit, rowit->par(), z);
+                       rowit = rowlist_.insert(rowit->next(),
+                                               new Row(rowit->par(), z));
                } else {
                        done = true;
                }
@@ -1355,7 +1359,7 @@ void LyXText::breakAgain(Row * row)
                        if (!row->next() || (row->next() && row->next()->par() != row->par())) {
                                // insert a new row
                                ++z;
-                               insertRow(row, row->par(), z);
+                               rowlist_.insert(row->next(), new Row(row->par(), z));
                                row = row->next();
                        } else  {
                                row = row->next();
@@ -1400,7 +1404,7 @@ void LyXText::breakAgainOneRow(Row * row)
                    || (row->next() && row->next()->par() != row->par())) {
                        // insert a new row
                        ++z;
-                       insertRow(row, row->par(), z);
+                       rowlist_.insert(row->next(), new Row(row->par(), z));
                        row = row->next();
                } else  {
                        row = row->next();
@@ -1518,7 +1522,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
          && cursor.par()->next()->isNewline(0))
           cursor.par()->next()->erase(0);
 
-       insertParagraph(cursor.par()->next(), cursor.row());
+       insertParagraph(cursor.par()->next(), cursor.row()->next());
        updateCounters();
 
        // This check is necessary. Otherwise the new empty paragraph will
@@ -2768,84 +2772,50 @@ void LyXText::backspace()
 // returns pointer to a specified row
 Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
 {
-       if (!firstRow())
+       if (rows().empty())
                return 0;
 
-       Row * tmprow = firstRow();
        y = 0;
 
        // find the first row of the specified paragraph
-       while (tmprow->next() && tmprow->par() != par) {
-               y += tmprow->height();
-               tmprow = tmprow->next();
+       RowList::iterator rit = rows().begin();
+       RowList::iterator end = rows().end();
+       while (boost::next(rit) != end && rit->par() != par) {
+               y += rit->height();
+               ++rit;
        }
 
        // now find the wanted row
-       while (tmprow->pos() < pos
-              && tmprow->next()
-              && tmprow->next()->par() == par
-              && tmprow->next()->pos() <= pos) {
-               y += tmprow->height();
-               tmprow = tmprow->next();
+       while (rit->pos() < pos
+              && boost::next(rit) != end
+              && boost::next(rit)->par() == par
+              && boost::next(rit)->pos() <= pos) {
+               y += rit->height();
+               ++rit;
        }
 
-       return tmprow;
+       return &*rit;
 }
 
 
 Row * LyXText::getRowNearY(int & y) const
 {
-#if 1
        // If possible we should optimize this method. (Lgb)
-       Row * tmprow = firstRow();
        int tmpy = 0;
 
-       while (tmprow->next() && tmpy + tmprow->height() <= y) {
-               tmpy += tmprow->height();
-               tmprow = tmprow->next();
+       RowList::iterator rit = rows().begin();
+       RowList::iterator end = rows().end();
+
+       while (boost::next(rit) != end && tmpy + rit->height() <= y) {
+               tmpy += rit->height();
+               ++rit;
        }
 
        y = tmpy;   // return the real y
 
        //lyxerr << "returned y = " << y << endl;
 
-       return tmprow;
-#else
-       // Search from the current cursor position.
-
-       Row * tmprow = cursor.row();
-       int tmpy = cursor.y() - tmprow->baseline();
-
-       lyxerr << "cursor.y() = " << tmpy << endl;
-       lyxerr << "tmprow->height() = " << tmprow->height() << endl;
-       lyxerr << "tmprow->baseline() = " << tmprow->baseline() << endl;
-       lyxerr << "first = " << first << endl;
-       lyxerr << "y = " << y << endl;
-
-       if (y < tmpy) {
-               lyxerr << "up" << endl;
-               do {
-                       tmpy -= tmprow->height();
-                       tmprow = tmprow->previous();
-               } while (tmprow && tmpy - tmprow->height() >= y);
-       } else if (y > tmpy) {
-               lyxerr << "down" << endl;
-
-               while (tmprow->next() && tmpy + tmprow->height() <= y) {
-                       tmpy += tmprow->height();
-                       tmprow = tmprow->next();
-               }
-       } else {
-               lyxerr << "equal" << endl;
-       }
-
-       y = tmpy; // return the real y
-
-       lyxerr << "returned y = " << y << endl;
-
-       return tmprow;
-
-#endif
+       return &*rit;
 }
 
 
index bb9dba2a673d93b9c9eb0b24bc90807b6868093f..23aa876815da4d83c61d747730edfee783cda8fb 100644 (file)
@@ -80,20 +80,17 @@ void LyXText::init(BufferView * bview, bool reinit)
                copylayouttype.erase();
                top_y(0);
                clearPaint();
-       } else if (firstRow())
+       } else if (!rowlist_.empty())
                return;
 
        Paragraph * par = ownerParagraph();
        current_font = getFont(bview->buffer(), par, 0);
 
        while (par) {
-               if (rowlist_.empty())
-                       insertParagraph(par, rowlist_.end());
-               else
-                       insertParagraph(par, lastRow());
+               insertParagraph(par, rowlist_.end());
                par = par->next();
        }
-       setCursorIntern(firstRow()->par(), 0);
+       setCursorIntern(rowlist_.begin()->par(), 0);
        selection.cursor = cursor;
 
        updateCounters();
@@ -261,23 +258,6 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
 }
 
 
-// inserts a new row before the specified row, increments
-// the touched counters
-RowList::iterator
- LyXText::insertRow(RowList::iterator rowit, Paragraph * par,
-                   pos_type pos)
-{
-       Row * tmprow = new Row;
-       tmprow->par(par);
-       tmprow->pos(pos);
-
-       if (rowit == rowlist_.end())
-               return rowlist_.insert(rowlist_.begin(), tmprow);
-       else
-               return rowlist_.insert(boost::next(rowit), tmprow);
-}
-
-
 // removes the row and reset the touched counters
 void LyXText::removeRow(Row * row)
 {
@@ -329,7 +309,7 @@ void LyXText::removeParagraph(Row * row)
 void LyXText::insertParagraph(Paragraph * par, RowList::iterator rowit)
 {
        // insert a new row, starting at position 0
-       RowList::iterator rit = insertRow(rowit, par, 0);
+       RowList::iterator rit = rowlist_.insert(rowit, new Row(par, 0));
 
        // and now append the whole paragraph before the new row
        appendParagraph(rit);
@@ -748,10 +728,15 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
        tmppar = first_phys_par;
        do {
                if (tmppar) {
-                       insertParagraph(tmppar, tmprow);
+                       if (!tmprow) {
+                               insertParagraph(tmppar, rowlist_.begin());
+                       } else {
+                               insertParagraph(tmppar, tmprow->next());
+                       }
+                       
 
                        if (!tmprow) {
-                               tmprow = firstRow();
+                               tmprow = &*rows().begin();
                        }
                        while (tmprow->next()
                               && tmprow->next()->par() == tmppar) {
@@ -766,7 +751,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
                setHeightOfRow(prevrow);
                const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
        } else {
-               setHeightOfRow(firstRow());
+               setHeightOfRow(&*rows().begin());
                const_cast<LyXText *>(this)->postPaint(0);
        }
 
@@ -778,7 +763,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
 
 void LyXText::fullRebreak()
 {
-       if (!firstRow()) {
+       if (rows().empty()) {
                init(bv());
                return;
        }
@@ -1287,15 +1272,15 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par)
 // Updates all counters. Paragraphs with changed label string will be rebroken
 void LyXText::updateCounters()
 {
-       Row * row = firstRow();
-       Paragraph * par = row->par();
+       RowList::iterator rowit = rows().begin();
+       Paragraph * par = rowit->par();
 
        // CHECK if this is really needed. (Lgb)
        bv()->buffer()->params.getLyXTextClass().counters().reset();
 
        while (par) {
-               while (row->par() != par)
-                       row = row->next();
+               while (rowit->par() != par)
+                       ++rowit;
 
                string const oldLabel = par->params().labelString();
 
@@ -1305,8 +1290,8 @@ void LyXText::updateCounters()
                string const & newLabel = par->params().labelString();
 
                if (oldLabel.empty() && !newLabel.empty()) {
-                       removeParagraph(row);
-                       appendParagraph(row);
+                       removeParagraph(&*rowit);
+                       appendParagraph(rowit);
                }
 
                par = par->next();