From 55a3d847282495fec4d5c6ac5859a5110ac58ff1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 14 Aug 2003 14:10:13 +0000 Subject: [PATCH] some infrastructure to prepare the rowlist split git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7544 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/insettext.C | 6 ++--- src/lyxtext.h | 4 +++- src/rowpainter.C | 6 +++-- src/text.C | 53 ++++++++++++++++++++++-------------------- src/text2.C | 31 ++++++++++++------------ src/text3.C | 2 +- 6 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f7eb5677f9..18e3d0d5ad 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -287,8 +287,8 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const x += TEXT_TO_INSET_OFFSET; - RowList::iterator rit = text_.rows().begin(); - RowList::iterator end = text_.rows().end(); + RowList::iterator rit = text_.firstRow(); + RowList::iterator end = text_.endRow(); int y_offset = baseline - rit->ascent_of_text(); int y2 = pain.paperHeight(); @@ -297,7 +297,7 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const while (rit != end && y + rit->height() <= 0) { y += rit->height(); first += rit->height(); - ++rit; + rit = text_.nextRow(rit); } if (y_offset < 0) { text_.top_y(-y_offset); diff --git a/src/lyxtext.h b/src/lyxtext.h index ee31a699bb..7eaabf3265 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -524,8 +524,10 @@ public: RowList::iterator endRow(ParagraphList::iterator pit) const; /// return first row of text RowList::iterator firstRow() const; - /// return row "behind" last of par + /// return last row of text RowList::iterator lastRow() const; + /// return row "behind" last row of text + RowList::iterator endRow() const; /// return next row crossing paragraph boundaries RowList::iterator nextRow(RowList::iterator rit) const; /// return previous row crossing paragraph boundaries diff --git a/src/rowpainter.C b/src/rowpainter.C index 4b058bf130..6cae7c85fa 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -1104,14 +1104,16 @@ int paintRows(BufferView const & bv, LyXText const & text, #endif } + //lyxerr << "text: " << &text << " y: " << y << " yf: " << yf + // << " y2: " << y2 << " yo: " << yo << "\n"; int yy = yf - y; - RowList::iterator end = text.rows().end(); + RowList::iterator end = text.endRow(); while (rit != end && yy + y < y2) { //const_cast(text).setHeightOfRow(rit); ParagraphList::iterator pit = text.getPar(rit); paintRow(bv, text, pit, rit, y + yo, xo, y + text.top_y()); y += rit->height(); - ++rit; + rit = text.nextRow(rit); } return y; } diff --git a/src/text.C b/src/text.C index 714fce9838..14994d067a 100644 --- a/src/text.C +++ b/src/text.C @@ -82,9 +82,9 @@ BufferView * LyXText::bv() const void LyXText::updateRowPositions() { - RowList::iterator rit = rows().begin(); - RowList::iterator rend = rows().end(); - for (int y = 0; rit != rend ; ++rit) { + RowList::iterator rit = firstRow(); + RowList::iterator rend = endRow(); + for (int y = 0; rit != rend ; rit = nextRow(rit)) { rit->y(y); y += rit->height(); } @@ -93,7 +93,7 @@ void LyXText::updateRowPositions() int LyXText::top_y() const { - if (anchor_row_ == rowlist_.end()) + if (anchor_row_ == endRow()) return 0; return anchor_row_->y() + anchor_row_offset_; @@ -106,7 +106,7 @@ void LyXText::top_y(int newy) return; if (isInInset()) { - anchor_row_ = rows().begin(); + anchor_row_ = firstRow(); anchor_row_offset_ = newy; return; } @@ -1005,8 +1005,6 @@ LColor::color LyXText::backgroundColor() const void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit) { - Assert(rit != rows().end()); - // get the maximum ascent and the maximum descent double layoutasc = 0; double layoutdesc = 0; @@ -1216,12 +1214,11 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit) prev->getLabelWidthString() == pit->getLabelWidthString()) { layoutasc = (layout->itemsep * defaultRowHeight()); - } else if (rit != rows().begin()) { + } else if (rit != firstRow()) { tmptop = layout->topsep; - if (boost::prior(pit)->getDepth() >= pit->getDepth()) { + if (boost::prior(pit)->getDepth() >= pit->getDepth()) tmptop -= getPar(boost::prior(rit))->layout()->bottomsep; - } if (tmptop > 0) layoutasc = (tmptop * defaultRowHeight()); @@ -1322,11 +1319,11 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit) rit->width(int(maxwidth + x)); if (inset_owner) { width = max(0, workWidth()); - RowList::iterator it = rows().begin(); - RowList::iterator end = rows().end(); - for (; it != end; ++it) - if (it->width() > width) - width = it->width(); + RowList::iterator rit = firstRow(); + RowList::iterator end = endRow(); + for (; rit != end; rit = nextRow(rit)) + if (rit->width() > width) + width = rit->width(); } } @@ -2205,8 +2202,8 @@ RowList::iterator LyXText::cursorIRow() const RowList::iterator LyXText::getRowNearY(int & y) const { RowList::iterator rit = anchor_row_; - RowList::iterator const beg = rows().begin(); - RowList::iterator const end = rows().end(); + RowList::iterator const beg = firstRow(); + RowList::iterator const end = endRow(); if (rows().empty()) { y = 0; @@ -2220,15 +2217,15 @@ RowList::iterator LyXText::getRowNearY(int & y) const if (tmpy <= y) { while (rit != end && tmpy <= y) { tmpy += rit->height(); - ++rit; + rit = nextRow(rit); } if (rit != beg) { - --rit; + rit = previousRow(rit); tmpy -= rit->height(); } } else { while (rit != beg && tmpy > y) { - --rit; + rit = previousRow(rit); tmpy -= rit->height(); } } @@ -2256,19 +2253,19 @@ int LyXText::getDepth() const ParagraphList::iterator LyXText::getPar(RowList::iterator row) const { - if (row == rows().end()) { + if (row == endRow()) { lyxerr << "getPar() pit at end " << endl; Assert(false); } - if (row == rows().begin()) { + if (row == firstRow()) { return ownerParagraphs().begin(); } ParagraphList::iterator pit = ownerParagraphs().begin(); - RowList::iterator rit = rows().begin(); - RowList::iterator rend = rows().end(); - for (++rit ; rit != rend; ++rit) { + RowList::iterator rit = firstRow(); + RowList::iterator rend = endRow(); + for (++rit ; rit != rend; rit = nextRow(rit)) { if (rit->pos() == 0) { ++pit; if (pit == ownerParagraphs().end()) { @@ -2319,6 +2316,12 @@ RowList::iterator LyXText::lastRow() const } +RowList::iterator LyXText::endRow() const +{ + return rowlist_.end(); +} + + RowList::iterator LyXText::nextRow(RowList::iterator rit) const { return boost::next(rit); diff --git a/src/text2.C b/src/text2.C index b3cc5fe99c..66328865d8 100644 --- a/src/text2.C +++ b/src/text2.C @@ -63,7 +63,7 @@ LyXText::LyXText(BufferView * bv) : height(0), width(0), anchor_row_offset_(0), inset_owner(0), the_locking_inset(0), bv_owner(bv) { - anchor_row_ = rows().end(); + anchor_row_ = endRow(); } @@ -71,7 +71,7 @@ LyXText::LyXText(BufferView * bv, InsetText * inset) : height(0), width(0), anchor_row_offset_(0), inset_owner(inset), the_locking_inset(0), bv_owner(bv) { - anchor_row_ = rows().end(); + anchor_row_ = endRow(); } @@ -83,7 +83,7 @@ void LyXText::init(BufferView * bview) width = 0; height = 0; - anchor_row_ = rows().end(); + anchor_row_ = endRow(); anchor_row_offset_ = 0; current_font = getFont(ownerParagraphs().begin(), 0); @@ -244,12 +244,12 @@ void LyXText::setCharFont( void LyXText::removeRow(RowList::iterator rit) { if (anchor_row_ == rit) { - if (rit != rows().begin()) { - anchor_row_ = boost::prior(rit); - anchor_row_offset_ += anchor_row_->height(); - } else { + if (rit == firstRow()) { anchor_row_ = boost::next(rit); anchor_row_offset_ -= rit->height(); + } else { + anchor_row_ = boost::prior(rit); + anchor_row_offset_ += anchor_row_->height(); } } @@ -650,7 +650,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) width = 0; height = 0; - anchor_row_ = rows().end(); + anchor_row_ = endRow(); anchor_row_offset_ = 0; ParagraphList::iterator pit = ownerParagraphs().begin(); @@ -671,7 +671,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) } // final dimension - dim.asc = rows().begin()->ascent_of_text(); + dim.asc = firstRow()->ascent_of_text(); dim.des = height - dim.asc; dim.wid = std::max(mi.base.textwidth, int(width)); } @@ -1695,7 +1695,7 @@ namespace { bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur) { RowList::iterator row = lt.getRow(cur); - if (boost::next(row) == lt.rows().end()) + if (boost::next(row) == lt.endRow()) return false; RowList::iterator next = boost::next(row); @@ -1794,8 +1794,8 @@ void LyXText::cursorUp(bool selecting) } } #else - setCursorFromCoordinates(bv(), cursor.x_fix(), - cursor.y() - cursorRow()->baseline() - 1); + setCursorFromCoordinates(cursor.x_fix(), + cursor.y() - cursorRow()->baseline() - 1); #endif } @@ -1818,9 +1818,8 @@ void LyXText::cursorDown(bool selecting) } } #else - setCursorFromCoordinates(bv(), cursor.x_fix(), - cursor.y() - cursorRow()->baseline() - + cursorRow()->height() + 1); + setCursorFromCoordinates(cursor.x_fix(), + cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1); #endif } @@ -1960,7 +1959,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) selection.cursor.par() == old_cursor.par() && selection.cursor.pos() == old_cursor.pos()); - if (getRow(old_cursor) != rows().begin()) { + if (getRow(old_cursor) != firstRow()) { RowList::iterator prevrow = boost::prior(getRow(old_cursor)); tmpcursor = cursor; cursor = old_cursor; // that undo can restore the right cursor position diff --git a/src/text3.C b/src/text3.C index 12a6318c62..dec8c26e74 100644 --- a/src/text3.C +++ b/src/text3.C @@ -242,7 +242,7 @@ void LyXText::cursorPrevious() RowList::iterator rit = cursorRow(); - if (rit == rows().begin()) { + if (rit == firstRow()) { if (y > 0) bv()->updateScrollbar(); return; -- 2.39.2