From d2718b36690ffab9da4169264ead9f4ed4c2619b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 29 Mar 2003 23:11:20 +0000 Subject: [PATCH] rowlist2 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6646 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 26 ++++++++++ src/insets/ChangeLog | 13 +++++ src/insets/insetert.C | 6 +-- src/insets/insetminipage.C | 2 +- src/insets/insettext.C | 41 ++++++++------- src/lyxrow.C | 6 +++ src/lyxrow.h | 3 +- src/lyxtext.h | 19 +++---- src/text.C | 104 +++++++++++++------------------------ src/text2.C | 53 +++++++------------ 10 files changed, 137 insertions(+), 136 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f8b2870b66..8664dc0b68 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ +2003-03-30 Lars Gullik Bjønnes + + * 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 * BufferView_pimpl.C: always update scrollbar top diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 0d62850b38..fb60c92316 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,16 @@ +2003-03-30 Lars Gullik Bjønnes + + * 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 * insetert.C: Alert cleanup diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 0774d61ee0..6499ea54b1 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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; } diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 98ffdb2bcb..bc0ffda2d1 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -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()); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index ebf879445e..6a523f2a84 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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; diff --git a/src/lyxrow.C b/src/lyxrow.C index ca328bc33f..956c350ee6 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -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_; diff --git a/src/lyxrow.h b/src/lyxrow.h index 68f229f7fb..ef7e6bc33c 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -23,7 +23,8 @@ class Row { public: /// Row(); - + /// + Row(Paragraph * pa, lyx::pos_type po); /// void par(Paragraph * p); /// diff --git a/src/lyxtext.h b/src/lyxtext.h index beddb960e5..fc1a76e127 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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(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); diff --git a/src/text.C b/src/text.C index d615e7e5ad..3a735c3c0e 100644 --- a/src/text.C +++ b/src/text.C @@ -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; } diff --git a/src/text2.C b/src/text2.C index bb9dba2a67..23aa876815 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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(this)->postPaint(y - prevrow->height()); } else { - setHeightOfRow(firstRow()); + setHeightOfRow(&*rows().begin()); const_cast(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(); -- 2.39.5