diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/insets/insetert.C lyx-rowlist2/src/insets/insetert.C --- lyx-rowlist/src/insets/insetert.C 2003-03-22 18:34:10.000000000 +0100 +++ lyx-rowlist2/src/insets/insetert.C 2003-03-22 19:13:44.000000000 +0100 @@ -453,7 +453,7 @@ * 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); @@ -675,11 +675,11 @@ 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; } diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/insets/insetminipage.C lyx-rowlist2/src/insets/insetminipage.C --- lyx-rowlist/src/insets/insetminipage.C 2003-03-22 18:34:12.000000000 +0100 +++ lyx-rowlist2/src/insets/insetminipage.C 2003-03-22 19:13:21.000000000 +0100 @@ -120,7 +120,7 @@ /* 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()); diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/insets/insettext.C lyx-rowlist2/src/insets/insettext.C --- lyx-rowlist/src/insets/insettext.C 2003-03-22 18:34:13.000000000 +0100 +++ lyx-rowlist2/src/insets/insettext.C 2003-03-22 19:13:21.000000000 +0100 @@ -302,7 +302,7 @@ 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; } @@ -311,7 +311,7 @@ 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; } @@ -401,15 +401,17 @@ } 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); @@ -422,12 +424,12 @@ 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(); @@ -2169,7 +2171,7 @@ 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) @@ -2538,12 +2540,13 @@ 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; Binary files lyx-rowlist/src/lyx and lyx-rowlist2/src/lyx differ diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/lyxrow.C lyx-rowlist2/src/lyxrow.C --- lyx-rowlist/src/lyxrow.C 2003-03-21 15:20:45.000000000 +0100 +++ lyx-rowlist2/src/lyxrow.C 2003-03-22 01:03:48.000000000 +0100 @@ -28,6 +28,12 @@ {} +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_; diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/lyxrow.h lyx-rowlist2/src/lyxrow.h --- lyx-rowlist/src/lyxrow.h 2003-03-21 15:20:45.000000000 +0100 +++ lyx-rowlist2/src/lyxrow.h 2003-03-22 01:03:02.000000000 +0100 @@ -23,7 +23,8 @@ public: /// Row(); - + /// + Row(Paragraph * pa, lyx::pos_type po); /// void par(Paragraph * p); /// diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/lyxtext.h lyx-rowlist2/src/lyxtext.h --- lyx-rowlist/src/lyxtext.h 2003-03-22 18:33:48.000000000 +0100 +++ lyx-rowlist2/src/lyxtext.h 2003-03-22 18:57:50.000000000 +0100 @@ -246,12 +246,14 @@ 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 @@ -509,12 +511,6 @@ */ 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); diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/text2.C lyx-rowlist2/src/text2.C --- lyx-rowlist/src/text2.C 2003-03-22 18:33:53.000000000 +0100 +++ lyx-rowlist2/src/text2.C 2003-03-22 18:57:55.000000000 +0100 @@ -78,7 +78,7 @@ copylayouttype.erase(); top_y(0); clearPaint(); - } else if (firstRow()) + } else if (!rowlist_.empty()) return; Paragraph * par = ownerParagraph(); @@ -88,7 +88,7 @@ insertParagraph(par, rowlist_.end()); par = par->next(); } - setCursorIntern(firstRow()->par(), 0); + setCursorIntern(rowlist_.begin()->par(), 0); selection.cursor = cursor; updateCounters(); @@ -256,19 +256,6 @@ } -// 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); - - return rowlist_.insert(rowit, tmprow); -} - - // removes the row and reset the touched counters void LyXText::removeRow(Row * row) { @@ -315,7 +302,7 @@ 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 rit->height(0); @@ -742,7 +729,7 @@ if (tmppar) { insertParagraph(tmppar, tmprow); if (!tmprow) { - tmprow = firstRow(); + tmprow = &*rows().begin(); } while (tmprow->next() && tmprow->next()->par() == tmppar) { @@ -757,7 +744,7 @@ setHeightOfRow(prevrow); const_cast<LyXText *>(this)->postPaint(y - prevrow->height()); } else { - setHeightOfRow(firstRow()); + setHeightOfRow(&*rows().begin()); const_cast<LyXText *>(this)->postPaint(0); } @@ -769,7 +756,7 @@ void LyXText::fullRebreak() { - if (!firstRow()) { + if (rows().empty()) { init(bv()); return; } @@ -1275,15 +1262,15 @@ // 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(); @@ -1293,8 +1280,8 @@ string const & newLabel = par->params().labelString(); if (oldLabel.empty() && !newLabel.empty()) { - removeParagraph(row); - appendParagraph(row); + removeParagraph(&*rowit); + appendParagraph(rowit); } par = par->next(); diff -ru --exclude=CVS -x '*.o' -x '*.libs*' -x '*~' -x '*.#*' -x '*.deps*' lyx-rowlist/src/text.C lyx-rowlist2/src/text.C --- lyx-rowlist/src/text.C 2003-03-22 18:55:08.000000000 +0100 +++ lyx-rowlist2/src/text.C 2003-03-22 19:09:20.000000000 +0100 @@ -78,9 +78,12 @@ 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,8 +91,8 @@ void LyXText::top_y(int newy) { - if (!firstRow()) + if (rows().empty()) return; lyxerr[Debug::GUI] << "setting top y = " << newy << endl; @@ -1299,12 +1303,12 @@ } 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(); } } } @@ -1324,7 +1328,8 @@ if (z < last) { ++z; - rowit = insertRow(rowit->next(), rowit->par(), z); + rowit = rowlist_.insert(rowit->next(), + new Row(rowit->par(), z)); rowit->height(0); } else { done = true; @@ -1352,7 +1357,7 @@ if (!row->next() || (row->next() && row->next()->par() != row->par())) { // insert a new row ++z; - insertRow(row, row->par(), z); + rowlist_.insert(row, new Row(row->par(), z)); row = row->next(); row->height(0); } else { @@ -1396,7 +1401,7 @@ || (row->next() && row->next()->par() != row->par())) { // insert a new row ++z; - insertRow(row, row->par(), z); + rowlist_.insert(row, new Row(row->par(), z)); row = row->next(); row->height(0); } else { @@ -2765,84 +2770,50 @@ // 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; }
-- Lgb