From a9d4d09715edcb4d5ab508874e5a828af24836bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 14 Aug 2003 08:17:27 +0000 Subject: [PATCH] grr.. revert. wrong patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7535 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 17 +-- src/bufferview_funcs.C | 3 +- src/lyxrow.C | 25 +++- src/lyxrow.h | 11 +- src/lyxrow_funcs.C | 56 ++++----- src/lyxrow_funcs.h | 23 ++-- src/lyxtext.h | 37 ++---- src/rowpainter.C | 28 ++--- src/support/LAssert.C | 12 -- src/support/LAssert.h | 8 +- src/text.C | 263 +++++++++++++++++------------------------ src/text2.C | 148 +++++++++++++---------- src/text3.C | 4 +- 13 files changed, 291 insertions(+), 344 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 67ebbbcfe2..978c1fc604 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,24 +1,11 @@ -2003-08-14 André Pönitz - - * lyxrow.[Ch]: remove Row::pit_ member and par() accessors - - * bufferview_funcs.C: - * lyxrow_funcs.[Ch]: - * lyxtext.h: - * rowpainter.C: - * text.C: - * text2.C: - * text3.C: adjust - 2003-08-11 André Pönitz - * lyxtext.h (getPar): - * text.C: new function - * Makefile.am: * tracer.[Ch]: remove unneeded files +2003-08-11 André Pönitz + * InsetList.[Ch]: remove resizeInsetsLyXText() * lyxtext.h: diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 04dd68d74b..c343a5d416 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -390,8 +390,7 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall) if (font.language() != ignore_language || font.number() != LyXFont::IGNORE) { LyXCursor & cursor = text->cursor; - text->computeBidiTables(text->cursor.par(), bv->buffer(), - text->cursorRow()); + text->computeBidiTables(bv->buffer(), text->cursorRow()); if (cursor.boundary() != text->isBoundary(bv->buffer(), *cursor.par(), cursor.pos(), text->real_current_font)) diff --git a/src/lyxrow.C b/src/lyxrow.C index 204dbf5ea9..d387cd65bc 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -13,6 +13,9 @@ #include #include "lyxrow.h" +#include "paragraph.h" +#include "layout.h" +#include "lyxlayout.h" #include "debug.h" using lyx::pos_type; @@ -26,8 +29,8 @@ Row::Row() {} -Row::Row(pos_type po) - : pos_(po), fill_(0), height_(0), width_(0), y_(0), +Row::Row(ParagraphList::iterator pit, pos_type po) + : pit_(pit), pos_(po), fill_(0), height_(0), width_(0), y_(0), ascent_of_text_(0), baseline_(0) {} @@ -44,12 +47,30 @@ unsigned int Row::y() const } +ParagraphList::iterator Row::par() +{ + return pit_; +} + + +ParagraphList::iterator Row::par() const +{ + return pit_; +} + + unsigned short Row::height() const { return height_; } +void Row::par(ParagraphList::iterator pit) +{ + pit_ = pit; +} + + void Row::pos(pos_type p) { pos_ = p; diff --git a/src/lyxrow.h b/src/lyxrow.h index b1612974e8..2ad6a0577e 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -15,6 +15,7 @@ #ifndef LYXROW_H #define LYXROW_H +#include "ParagraphList.h" #include "support/types.h" /// @@ -23,7 +24,13 @@ public: /// Row(); /// - Row(lyx::pos_type pos); + Row(ParagraphList::iterator pit, lyx::pos_type pos); + /// + void par(ParagraphList::iterator pit); + /// + ParagraphList::iterator par(); + /// + ParagraphList::iterator par() const; /// void pos(lyx::pos_type p); /// @@ -61,6 +68,8 @@ public: /// current debugging only void dump(const char * = "") const; private: + /// + ParagraphList::iterator pit_; /// lyx::pos_type pos_; /** what is missing to a full row. Can be negative. diff --git a/src/lyxrow_funcs.C b/src/lyxrow_funcs.C index 586c1f0320..f2ed678408 100644 --- a/src/lyxrow_funcs.C +++ b/src/lyxrow_funcs.C @@ -9,27 +9,24 @@ #include using lyx::pos_type; - using std::max; using std::min; -bool isParEnd(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +bool isParEnd(LyXText const & lt, RowList::iterator rit) { RowList::iterator next_row = boost::next(rit); - return next_row == lt.rows().end() || lt.getPar(next_row) != pit; + return next_row == lt.rows().end() || next_row->par() != rit->par(); } -pos_type lastPos(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +pos_type lastPos(LyXText const & lt, RowList::iterator rit) { - if (pit->empty()) + if (rit->par()->empty()) return 0; - if (isParEnd(lt, pit, rit)) - return pit->size() - 1; + if (isParEnd(lt, rit)) + return rit->par()->size() - 1; return boost::next(rit)->pos() - 1; } @@ -37,9 +34,10 @@ pos_type lastPos(LyXText const & lt, namespace { -bool nextRowIsAllInset( - ParagraphList::iterator pit, RowList::iterator rit, pos_type last) +bool nextRowIsAllInset(Row const & row, pos_type last) { + ParagraphList::iterator pit = row.par(); + if (last + 1 >= pit->size()) return false; @@ -53,26 +51,27 @@ bool nextRowIsAllInset( } // anon namespace -pos_type lastPrintablePos(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit) { - pos_type const last = lastPos(lt, pit, rit); + pos_type const last = lastPos(lt, rit); // if this row is an end of par, just act like lastPos() - if (isParEnd(lt, pit, rit)) + if (isParEnd(lt, rit)) return last; - if (!nextRowIsAllInset(pit, rit, last) && pit->isSeparator(last)) + bool const nextrownotinset = !nextRowIsAllInset(*rit, last); + + if (nextrownotinset && rit->par()->isSeparator(last)) return last - 1; return last; } -int numberOfSeparators(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +int numberOfSeparators(LyXText const & lt, RowList::iterator rit) { - pos_type const last = lastPrintablePos(lt, pit, rit); + pos_type const last = lastPrintablePos(lt, rit); + ParagraphList::iterator pit = rit->par(); int n = 0; pos_type p = max(rit->pos(), pit->beginningOfBody()); for ( ; p < last; ++p) @@ -84,11 +83,11 @@ int numberOfSeparators(LyXText const & lt, // This is called _once_ from LyXText and should at least be moved into // an anonymous namespace there. (Lgb) -int numberOfHfills(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +int numberOfHfills(LyXText const & lt, RowList::iterator rit) { - pos_type const last = lastPos(lt, pit, rit); + pos_type const last = lastPos(lt, rit); pos_type first = rit->pos(); + ParagraphList::iterator pit = rit->par(); // hfill *DO* count at the beginning of paragraphs! if (first) { @@ -111,11 +110,11 @@ int numberOfHfills(LyXText const & lt, // This is called _once_ from LyXText and should at least be moved into // an anonymous namespace there. (Lgb) -int numberOfLabelHfills(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit) +int numberOfLabelHfills(LyXText const & lt, RowList::iterator rit) { - pos_type last = lastPos(lt, pit, rit); + pos_type last = lastPos(lt, rit); pos_type first = rit->pos(); + ParagraphList::iterator pit = rit->par(); // hfill *DO* count at the beginning of paragraphs! if (first) { @@ -135,15 +134,16 @@ int numberOfLabelHfills(LyXText const & lt, } -bool hfillExpansion(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit, pos_type pos) +bool hfillExpansion(LyXText const & lt, RowList::iterator rit, pos_type pos) { + ParagraphList::iterator pit = rit->par(); + if (!pit->isHfill(pos)) return false; // at the end of a row it does not count // unless another hfill exists on the line - if (pos >= lastPos(lt, pit, rit)) + if (pos >= lastPos(lt, rit)) for (pos_type i = rit->pos(); i < pos && !pit->isHfill(i); ++i) return false; diff --git a/src/lyxrow_funcs.h b/src/lyxrow_funcs.h index c09a04f283..0ed8955b5a 100644 --- a/src/lyxrow_funcs.h +++ b/src/lyxrow_funcs.h @@ -4,31 +4,22 @@ #define LYXROW_FUNCS_H #include "RowList.h" -#include "ParagraphList.h" - #include "support/types.h" class LyXText; -bool isParEnd(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +bool isParEnd(LyXText const & lt, RowList::iterator rit); -lyx::pos_type lastPos(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +lyx::pos_type lastPos(LyXText const & lt, RowList::iterator rit); -lyx::pos_type lastPrintablePos(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +lyx::pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit); -int numberOfSeparators(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +int numberOfSeparators(LyXText const & lt, RowList::iterator rit); -int numberOfHfills(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +int numberOfHfills(LyXText const & lt, RowList::iterator rit); -int numberOfLabelHfills(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit); +int numberOfLabelHfills(LyXText const & lt, RowList::iterator rit); -bool hfillExpansion(LyXText const & lt, - ParagraphList::iterator pit, RowList::iterator rit, lyx::pos_type pos); +bool hfillExpansion(LyXText const & lt, RowList::iterator rit, lyx::pos_type pos); #endif diff --git a/src/lyxtext.h b/src/lyxtext.h index 26a0d05ee6..59f015cbf9 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -136,6 +136,8 @@ public: void redoParagraph(ParagraphList::iterator pit); /// rebreaks the cursor par void redoParagraph(); + /// returns first row belongin to some par + RowList::iterator firstRow(ParagraphList::iterator pit); /// void toggleFree(LyXFont const &, bool toggleall = false); @@ -194,8 +196,8 @@ public: /** returns the column near the specified x-coordinate of the row x is set to the real beginning of this column */ - lyx::pos_type getColumnNearX(ParagraphList::iterator pit, - RowList::iterator rit, int & x, bool & boundary) const; + lyx::pos_type getColumnNearX(RowList::iterator rit, + int & x, bool & boundary) const; /** returns a pointer to a specified row. y is set to the beginning of the row @@ -367,8 +369,7 @@ public: int workWidth() const; /// - void computeBidiTables(ParagraphList::iterator pit, - Buffer const *, RowList::iterator row) const; + void computeBidiTables(Buffer const *, RowList::iterator row) const; /// Maps positions in the visual string to positions in logical string. lyx::pos_type log2vis(lyx::pos_type pos) const; /// Maps positions in the logical string to positions in visual string. @@ -382,8 +383,7 @@ private: mutable RowList rowlist_; /// - float getCursorX(ParagraphList::iterator pit, - RowList::iterator rit, lyx::pos_type pos, + float getCursorX(RowList::iterator rit, lyx::pos_type pos, lyx::pos_type last, bool boundary) const; /// used in setlayout void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par); @@ -447,15 +447,13 @@ public: * in LaTeX the beginning of the text fits in some cases * (for example sections) exactly the label-width. */ - int leftMargin(ParagraphList::iterator pit, Row const & row) const; + int leftMargin(Row const & row) const; /// - int rightMargin(ParagraphList::iterator pit, Buffer const &, Row const & row) const; + int rightMargin(Buffer const &, Row const & row) const; /** this calculates the specified parameters. needed when setting * the cursor and when creating a visible row */ - void prepareToPrint( - ParagraphList::iterator pit, - RowList::iterator row, double & x, + void prepareToPrint(RowList::iterator row, double & x, double & fill_separator, double & fill_hfill, double & fill_label_hfill, @@ -478,8 +476,7 @@ private: /// return the pos value *before* which a row should break. /// for example, the pos at which IsNewLine(pos) == true - lyx::pos_type rowBreakPoint(ParagraphList::iterator pit, - Row const & row) const; + lyx::pos_type rowBreakPoint(Row const & row) const; /// returns the minimum space a row needs on the screen in pixel int fill(RowList::iterator row, int workwidth) const; @@ -488,10 +485,10 @@ private: * returns the minimum space a manual label needs on the * screen in pixels */ - int labelFill(ParagraphList::iterator pit, Row const & row) const; + int labelFill(Row const & row) const; /// FIXME - int labelEnd(ParagraphList::iterator pit, Row const & row) const; + int labelEnd(Row const & row) const; /// mutable std::vector log2vis_list; @@ -515,16 +512,6 @@ public: /// return true if this is owned by an inset. bool isInInset() const; - /// compute paragraphlist iterator from rowlist iterator - ParagraphList::iterator getPar(RowList::iterator rit) const; - - /// return first row of par - RowList::iterator beginRow(ParagraphList::iterator pit) const; - /// return row "behind" last of par - RowList::iterator endRow(ParagraphList::iterator pit) const; - /// return row "behind" last of implizitly given par - RowList::iterator endRow(RowList::iterator rit) const; - private: /** Cursor related data. Later this variable has to be removed. There should be now internal diff --git a/src/rowpainter.C b/src/rowpainter.C index 4c14111611..bd5cd6a338 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -131,7 +131,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text, RowList::iterator rit, int y_offset, int x_offset, int y) : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit), - pit_(text.getPar(rit)), + pit_(rit->par()), xo_(x_offset), yo_(y_offset), y_(y) {} @@ -169,7 +169,7 @@ char const RowPainter::transformChar(char c, lyx::pos_type pos) const int RowPainter::leftMargin() const { - return text_.leftMargin(pit_, *row_); + return text_.leftMargin(*row_); } @@ -255,7 +255,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos) void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic) { pos_type pos = text_.vis2log(vpos); - pos_type const last = lastPrintablePos(text_, pit_, row_); + pos_type const last = lastPrintablePos(text_, row_); LyXFont orig_font = getFont(pos); // first character @@ -432,7 +432,7 @@ void RowPainter::paintSelection() int(x_), row_->height(), LColor::selection); pos_type const body_pos = pit_->beginningOfBody(); - pos_type const last = lastPrintablePos(text_, pit_, row_); + pos_type const last = lastPrintablePos(text_, row_); double tmpx = x_; for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) { @@ -448,7 +448,7 @@ void RowPainter::paintSelection() tmpx -= singleWidth(body_pos - 1); } - if (hfillExpansion(text_, pit_, row_, pos)) { + if (hfillExpansion(text_, row_, pos)) { tmpx += singleWidth(pos); if (pos >= body_pos) tmpx += hfill_; @@ -484,7 +484,7 @@ void RowPainter::paintSelection() void RowPainter::paintChangeBar() { pos_type const start = row_->pos(); - pos_type const end = lastPrintablePos(text_, pit_, row_); + pos_type const end = lastPrintablePos(text_, row_); if (!pit_->isChanged(start, end)) return; @@ -524,12 +524,12 @@ void RowPainter::paintDepthBar() Paragraph::depth_type prev_depth = 0; if (row_ != text_.rows().begin()) - prev_depth = text_.getPar(boost::prior(row_))->getDepth(); + prev_depth = boost::prior(row_)->par()->getDepth(); Paragraph::depth_type next_depth = 0; RowList::iterator next_row = boost::next(row_); if (next_row != text_.rows().end()) - next_depth = text_.getPar(next_row)->getDepth(); + next_depth = next_row->par()->getDepth(); for (Paragraph::depth_type i = 1; i <= depth; ++i) { int const w = PAPER_MARGIN / 5; @@ -795,7 +795,7 @@ void RowPainter::paintFirst() double x = x_; if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) { x = ((is_rtl ? leftMargin() : x_) - + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2; + + ww - text_.rightMargin(*bv_.buffer(), *row_)) / 2; x -= font_metrics::width(str, font) / 2; } else if (is_rtl) { x = ww - leftMargin() - @@ -875,7 +875,7 @@ void RowPainter::paintLast() string const & str = pit_->layout()->endlabelstring(); double const x = is_rtl ? x_ - font_metrics::width(str, font) - : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill(); + : ww - text_.rightMargin(*bv_.buffer(), *row_) - row_->fill(); pain_.text(int(x), yo_ + row_->baseline(), str, font); break; } @@ -887,7 +887,7 @@ void RowPainter::paintLast() void RowPainter::paintText() { - pos_type const last = lastPrintablePos(text_, pit_, row_); + pos_type const last = lastPrintablePos(text_, row_); pos_type body_pos = pit_->beginningOfBody(); if (body_pos > 0 && (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) { @@ -952,7 +952,7 @@ void RowPainter::paintText() pain_.line(int(x_), y1, int(x_), y0, LColor::added_space); - if (hfillExpansion(text_, pit_, row_, pos)) { + if (hfillExpansion(text_, row_, pos)) { int const y2 = (y0 + y1) / 2; if (pos >= body_pos) { @@ -997,7 +997,7 @@ void RowPainter::paint() // FIXME: must be a cleaner way here. Aren't these calculations // belonging to row metrics ? - text_.prepareToPrint(pit_, row_, x_, separator_, hfill_, label_hfill_); + text_.prepareToPrint(row_, x_, separator_, hfill_, label_hfill_); // FIXME: what is this fixing ? if (text_.isInInset() && x_ < 0) @@ -1025,7 +1025,7 @@ void RowPainter::paint() if (row_->isParStart()) paintFirst(); - if (isParEnd(text_, pit_, row_)) + if (isParEnd(text_, row_)) paintLast(); // paint text diff --git a/src/support/LAssert.C b/src/support/LAssert.C index 558d9a8136..30248b0807 100644 --- a/src/support/LAssert.C +++ b/src/support/LAssert.C @@ -11,7 +11,6 @@ #include #include "LAssert.h" -#include "debug.h" #include "support/lyxlib.h" #ifdef ENABLE_ASSERTIONS @@ -35,17 +34,6 @@ void emergencyCleanup() } // namespace anon - -void Assert(bool assertion, char const * message) -{ - if (!assertion) { - lyxerr << "Assert triggered: " << message << std::endl; - emergencyCleanup(); - lyx::support::abort(); - } -} - - void Assert(bool assertion) { if (!assertion) { diff --git a/src/support/LAssert.h b/src/support/LAssert.h index 6a7ca9482f..e791820285 100644 --- a/src/support/LAssert.h +++ b/src/support/LAssert.h @@ -18,13 +18,11 @@ namespace support { #ifdef ENABLE_ASSERTIONS /** Live assertion. - This is a debug tool to ensure that the assertion holds. If it - doesn't hold we run #emergencyCleanup()# and then #lyx::abort". + This is a debug tool to ensure that the assertion holds. If it don't hole + we run #emergencyCleanup()# and then #lyx::abort". @param assertion this should evaluate to true unless you want an abort. */ void Assert(bool assertion); -/// same as above, print message before aborting -void Assert(bool assertion, const char * message); #else @@ -33,8 +31,6 @@ void Assert(bool assertion, const char * message); */ inline void Assert(bool /*assertion*/) {} -inline -void Assert(bool /*assertion*/, const char * /*message*/) {} #endif /* ENABLE_ASSERTIONS */ diff --git a/src/text.C b/src/text.C index cd2cd571f7..4337d289e2 100644 --- a/src/text.C +++ b/src/text.C @@ -317,8 +317,8 @@ bool LyXText::bidi_InRange(lyx::pos_type pos) const } -void LyXText::computeBidiTables(ParagraphList::iterator row_par, - Buffer const * buf, RowList::iterator row) const +void LyXText::computeBidiTables(Buffer const * buf, + RowList::iterator row) const { bidi_same_direction = true; if (!lyxrc.rtl_support) { @@ -326,6 +326,8 @@ void LyXText::computeBidiTables(ParagraphList::iterator row_par, return; } + ParagraphList::iterator row_par = row->par(); + InsetOld * inset = row_par->inInset(); if (inset && inset->owner() && inset->owner()->lyxCode() == InsetOld::ERT_CODE) { @@ -334,7 +336,7 @@ void LyXText::computeBidiTables(ParagraphList::iterator row_par, } bidi_start = row->pos(); - bidi_end = lastPrintablePos(*this, row_par, row); + bidi_end = lastPrintablePos(*this, row); if (bidi_start > bidi_end) { bidi_start = -1; @@ -479,19 +481,19 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par, } -int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const +int LyXText::leftMargin(Row const & row) const { InsetOld * ins; - if (row.pos() < pit->size()) - if (pit->getChar(row.pos()) == Paragraph::META_INSET && - (ins = pit->getInset(row.pos())) && + if (row.pos() < row.par()->size()) + if (row.par()->getChar(row.pos()) == Paragraph::META_INSET && + (ins = row.par()->getInset(row.pos())) && (ins->needFullRow() || ins->display())) return LEFT_MARGIN; LyXTextClass const & tclass = bv()->buffer()->params.getLyXTextClass(); - LyXLayout_ptr const & layout = pit->layout(); + LyXLayout_ptr const & layout = row.par()->layout(); string parindent = layout->parindent; @@ -502,14 +504,14 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const // this is the way, LyX handles the LaTeX-Environments. // I have had this idea very late, so it seems to be a // later added hack and this is true - if (!pit->getDepth()) { - if (pit->layout() == tclass.defaultLayout()) { + if (!row.par()->getDepth()) { + if (row.par()->layout() == tclass.defaultLayout()) { // find the previous same level paragraph - if (pit != ownerParagraphs().begin()) { + if (row.par() != ownerParagraphs().begin()) { ParagraphList::iterator newpit = - depthHook(pit, ownerParagraphs(), - pit->getDepth()); - if (newpit == pit && + depthHook(row.par(), ownerParagraphs(), + row.par()->getDepth()); + if (newpit == row.par() && newpit->layout()->nextnoindent) parindent.erase(); } @@ -517,7 +519,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const } else { // find the next level paragraph - ParagraphList::iterator newpar = outerHook(pit, + ParagraphList::iterator newpar = outerHook(row.par(), ownerParagraphs()); // make a corresponding row. Needed to call leftMargin() @@ -525,11 +527,14 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const // check wether it is a sufficent paragraph if (newpar != ownerParagraphs().end() && newpar->layout()->isEnvironment()) { - x = leftMargin(newpar, Row(newpar->size())); + Row dummyrow; + dummyrow.par(newpar); + dummyrow.pos(newpar->size()); + x = leftMargin(dummyrow); } if (newpar != ownerParagraphs().end() && - pit->layout() == tclass.defaultLayout()) { + row.par()->layout() == tclass.defaultLayout()) { if (newpar->params().noindent()) parindent.erase(); else { @@ -539,17 +544,17 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const } } - LyXFont const labelfont = getLabelFont(pit); + LyXFont const labelfont = getLabelFont(row.par()); switch (layout->margintype) { case MARGIN_DYNAMIC: if (!layout->leftmargin.empty()) { x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()); } - if (!pit->getLabelstring().empty()) { + if (!row.par()->getLabelstring().empty()) { x += font_metrics::signedWidth(layout->labelindent, labelfont); - x += font_metrics::width(pit->getLabelstring(), + x += font_metrics::width(row.par()->getLabelstring(), labelfont); x += font_metrics::width(layout->labelsep, labelfont); } @@ -557,9 +562,9 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const case MARGIN_MANUAL: x += font_metrics::signedWidth(layout->labelindent, labelfont); // The width of an empty par, even with manual label, should be 0 - if (!pit->empty() && row.pos() >= pit->beginningOfBody()) { - if (!pit->getLabelWidthString().empty()) { - x += font_metrics::width(pit->getLabelWidthString(), + if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) { + if (!row.par()->getLabelWidthString().empty()) { + x += font_metrics::width(row.par()->getLabelWidthString(), labelfont); x += font_metrics::width(layout->labelsep, labelfont); } @@ -567,11 +572,11 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const break; case MARGIN_STATIC: x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4 - / (pit->getDepth() + 4); + / (row.par()->getDepth() + 4); break; case MARGIN_FIRST_DYNAMIC: if (layout->labeltype == LABEL_MANUAL) { - if (row.pos() >= pit->beginningOfBody()) { + if (row.pos() >= row.par()->beginningOfBody()) { x += font_metrics::signedWidth(layout->leftmargin, labelfont); } else { @@ -583,7 +588,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const // theorems (JMarc) || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, ownerParagraphs()))) { + && !isFirstInSequence(row.par(), ownerParagraphs()))) { x += font_metrics::signedWidth(layout->leftmargin, labelfont); } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT @@ -593,7 +598,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const x += font_metrics::signedWidth(layout->labelindent, labelfont); x += font_metrics::width(layout->labelsep, labelfont); - x += font_metrics::width(pit->getLabelstring(), + x += font_metrics::width(row.par()->getLabelstring(), labelfont); } break; @@ -607,12 +612,12 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const // find the first row of this paragraph RowList::iterator tmprit = rowlist_.begin(); while (tmprit != rowlist_.end() - && getPar(tmprit) != pit) + && tmprit->par() != row.par()) ++tmprit; int minfill = tmprit->fill(); while (boost::next(tmprit) != rowlist_.end() && - getPar(boost::next(tmprit)) == pit) { + boost::next(tmprit)->par() == row.par()) { ++tmprit; if (tmprit->fill() < minfill) minfill = tmprit->fill(); @@ -625,8 +630,10 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const break; } - if (workWidth() > 0 && !pit->params().leftIndent().zero()) { - LyXLength const len = pit->params().leftIndent(); + if ((workWidth() > 0) && + !row.par()->params().leftIndent().zero()) + { + LyXLength const len = row.par()->params().leftIndent(); int const tw = inset_owner ? inset_owner->latexTextWidth(bv()) : workWidth(); x += len.inPixels(tw); @@ -634,10 +641,10 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const LyXAlignment align; - if (pit->params().align() == LYX_ALIGN_LAYOUT) + if (row.par()->params().align() == LYX_ALIGN_LAYOUT) align = layout->align; else - align = pit->params().align(); + align = row.par()->params().align(); // set the correct parindent if (row.pos() == 0) { @@ -646,14 +653,14 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, ownerParagraphs()))) + && !isFirstInSequence(row.par(), ownerParagraphs()))) && align == LYX_ALIGN_BLOCK - && !pit->params().noindent() + && !row.par()->params().noindent() // in tabulars and ert paragraphs are never indented! - && (!pit->inInset() || !pit->inInset()->owner() || - (pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE && - pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE)) - && (pit->layout() != tclass.defaultLayout() || + && (!row.par()->inInset() || !row.par()->inInset()->owner() || + (row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE && + row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE)) + && (row.par()->layout() != tclass.defaultLayout() || bv()->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT)) { x += font_metrics::signedWidth(parindent, @@ -668,36 +675,35 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const } -int LyXText::rightMargin(ParagraphList::iterator pit, - Buffer const & buf, Row const & row) const +int LyXText::rightMargin(Buffer const & buf, Row const & row) const { InsetOld * ins; - if (row.pos() < pit->size()) - if ((pit->getChar(row.pos()) == Paragraph::META_INSET) && - (ins = pit->getInset(row.pos())) && + if (row.pos() < row.par()->size()) + if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) && + (ins = row.par()->getInset(row.pos())) && (ins->needFullRow() || ins->display())) return PAPER_MARGIN; LyXTextClass const & tclass = buf.params.getLyXTextClass(); - LyXLayout_ptr const & layout = pit->layout(); + LyXLayout_ptr const & layout = row.par()->layout(); return PAPER_MARGIN + font_metrics::signedWidth(tclass.rightmargin(), tclass.defaultfont()); + font_metrics::signedWidth(layout->rightmargin, tclass.defaultfont()) - * 4 / (pit->getDepth() + 4); + * 4 / (row.par()->getDepth() + 4); } -int LyXText::labelEnd(ParagraphList::iterator pit, Row const & row) const +int LyXText::labelEnd(Row const & row) const { - if (pit->layout()->margintype == MARGIN_MANUAL) { + if (row.par()->layout()->margintype == MARGIN_MANUAL) { Row tmprow = row; - tmprow.pos(pit->size()); + tmprow.pos(row.par()->size()); // return the beginning of the body - return leftMargin(pit, tmprow); + return leftMargin(tmprow); } // LabelEnd is only needed if the layout @@ -722,11 +728,12 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par) }; -pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, - Row const & row) const +pos_type LyXText::rowBreakPoint(Row const & row) const { + ParagraphList::iterator pit = row.par(); + // maximum pixel width of a row. - int width = workWidth() - rightMargin(pit, *bv()->buffer(), row); + int width = workWidth() - rightMargin(*bv()->buffer(), row); // inset->textWidth() returns -1 via workWidth(), // but why ? @@ -750,7 +757,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, // or the end of the par, then choose the possible break // nearest that. - int const left = leftMargin(pit, row); + int const left = leftMargin(row); int x = left; // pixel width since last breakpoint @@ -778,7 +785,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, thiswidth = font_metrics::width(layout->labelsep, getLabelFont(pit)); if (pit->isLineSeparator(i - 1)) thiswidth -= singleWidth(pit, i - 1); - int left_margin = labelEnd(pit, row); + int left_margin = labelEnd(row); if (thiswidth + x < left_margin) thiswidth = left_margin - x; thiswidth += singleWidth(pit, i, c); @@ -882,19 +889,19 @@ int LyXText::fill(RowList::iterator row, int paper_width) const int w; // get the pure distance - ParagraphList::iterator pit = getPar(row); - pos_type const last = lastPrintablePos(*this, pit, row); + pos_type const last = lastPrintablePos(*this, row); + ParagraphList::iterator pit = row->par(); LyXLayout_ptr const & layout = pit->layout(); // special handling of the right address boxes if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) { int const tmpfill = row->fill(); row->fill(0); // the minfill in MarginLeft() - w = leftMargin(pit, *row); + w = leftMargin(*row); row->fill(tmpfill); } else - w = leftMargin(pit, *row); + w = leftMargin(*row); pos_type const body_pos = pit->beginningOfBody(); pos_type i = row->pos(); @@ -908,7 +915,7 @@ int LyXText::fill(RowList::iterator row, int paper_width) const w += font_metrics::width(layout->labelsep, getLabelFont(pit)); if (pit->isLineSeparator(i - 1)) w -= singleWidth(pit, i - 1); - int left_margin = labelEnd(pit, *row); + int left_margin = labelEnd(*row); if (w < left_margin) w = left_margin; } @@ -943,12 +950,12 @@ int LyXText::fill(RowList::iterator row, int paper_width) const w += font_metrics::width(layout->labelsep, getLabelFont(pit)); if (last >= 0 && pit->isLineSeparator(last)) w -= singleWidth(pit, last); - int const left_margin = labelEnd(pit, *row); + int const left_margin = labelEnd(*row); if (w < left_margin) w = left_margin; } - int const fill = paper_width - w - rightMargin(pit, *bv()->buffer(), *row); + int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row); // If this case happens, it means that our calculation // of the widths of the chars when we do rowBreakPoint() @@ -960,15 +967,17 @@ int LyXText::fill(RowList::iterator row, int paper_width) const if (lyxerr.debugging() && fill < 0) { lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill << " w " << w << " paper_width " << paper_width - << " right margin " << rightMargin(pit, *bv()->buffer(), *row) << endl; + << " right margin " << rightMargin(*bv()->buffer(), *row) << endl; } return fill; } // returns the minimum space a manual label needs on the screen in pixel -int LyXText::labelFill(ParagraphList::iterator pit, Row const & row) const +int LyXText::labelFill(Row const & row) const { + ParagraphList::iterator pit = row.par(); + pos_type last = pit->beginningOfBody(); Assert(last > 0); @@ -1021,7 +1030,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // ok, let us initialize the maxasc and maxdesc value. // Only the fontsize count. The other properties // are taken from the layoutfont. Nicer on the screen :) - ParagraphList::iterator pit = getPar(rit); + ParagraphList::iterator pit = rit->par(); LyXLayout_ptr const & layout = pit->layout(); @@ -1048,7 +1057,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) int maxdesc = int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val); - pos_type const pos_end = lastPos(*this, pit, rit); + pos_type const pos_end = lastPos(*this, rit); int labeladdon = 0; int maxwidth = 0; @@ -1227,9 +1236,8 @@ void LyXText::setHeightOfRow(RowList::iterator rit) } else if (rit != rows().begin()) { tmptop = layout->topsep; - if (boost::prior(pit)->getDepth() >= pit->getDepth()) { - tmptop -= getPar(boost::prior(rit))->layout()->bottomsep; - } + if (boost::prior(pit)->getDepth() >= pit->getDepth()) + tmptop -= boost::prior(rit)->par()->layout()->bottomsep; if (tmptop > 0) layoutasc = (tmptop * defaultRowHeight()); @@ -1255,7 +1263,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // is it a bottom line? RowList::iterator next_rit = boost::next(rit); - if (next_rit == rows().end() || getPar(next_rit) != pit) { + if (next_rit == rows().end() || next_rit->par() != pit) { // the bottom margin ParagraphList::iterator nextpit = boost::next(pit); if (nextpit == ownerParagraphs().end() && @@ -1326,7 +1334,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // this IS needed rit->width(maxwidth); double dummy; - prepareToPrint(pit, rit, x, dummy, dummy, dummy, false); + prepareToPrint(rit, x, dummy, dummy, dummy, false); } rit->width(int(maxwidth + x)); if (inset_owner) { @@ -1395,13 +1403,18 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout) // This touches only the screen-update. Otherwise we would may have // an empty row on the screen if (cursor.pos() && cursorRow()->pos() == cursor.pos() - && !cursor.par()->isNewline(cursor.pos() - 1)) + && !cursorRow()->par()->isNewline(cursor.pos() - 1)) { cursorLeft(bv()); } removeParagraph(cursorRow()); + // set the dimensions of the cursor row + cursorRow()->fill(fill(cursorRow(), workWidth())); + + setHeightOfRow(cursorRow()); + #warning Trouble Point! (Lgb) // When ::breakParagraph is called from within an inset we must // ensure that the correct ParagraphList is used. Today that is not @@ -1425,7 +1438,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout) } -// convenience function +// Just a macro to make some thing easier. void LyXText::redoParagraph() { clearSelection(); @@ -1443,8 +1456,8 @@ void LyXText::insertChar(char c) // When the free-spacing option is set for the current layout, // disable the double-space checking - bool const freeSpacing = cursor.par()->layout()->free_spacing || - cursor.par()->isFreeSpacing(); + bool const freeSpacing = cursorRow()->par()->layout()->free_spacing || + cursorRow()->par()->isFreeSpacing(); if (lyxrc.auto_number) { static string const number_operators = "+-/*"; @@ -1554,8 +1567,7 @@ void LyXText::charInserted() } -void LyXText::prepareToPrint(ParagraphList::iterator pit, - RowList::iterator rit, double & x, +void LyXText::prepareToPrint(RowList::iterator rit, double & x, double & fill_separator, double & fill_hfill, double & fill_label_hfill, @@ -1567,12 +1579,14 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, fill_separator = 0; fill_label_hfill = 0; + ParagraphList::iterator pit = rit->par(); + bool const is_rtl = pit->isRightToLeftPar(bv()->buffer()->params); if (is_rtl) - x = workWidth() > 0 ? rightMargin(pit, *bv()->buffer(), *rit) : 0; + x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0; else - x = workWidth() > 0 ? leftMargin(pit, *rit) : 0; + x = workWidth() > 0 ? leftMargin(*rit) : 0; // is there a manual margin with a manual label LyXLayout_ptr const & layout = pit->layout(); @@ -1580,7 +1594,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, if (layout->margintype == MARGIN_MANUAL && layout->labeltype == LABEL_MANUAL) { /// We might have real hfills in the label part - int nlh = numberOfLabelHfills(*this, pit, rit); + int nlh = numberOfLabelHfills(*this, rit); // A manual label par (e.g. List) has an auto-hfill // between the label text and the body of the @@ -1591,12 +1605,12 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, ++nlh; if (nlh && !pit->getLabelWidthString().empty()) { - fill_label_hfill = labelFill(pit, *rit) / double(nlh); + fill_label_hfill = labelFill(*rit) / double(nlh); } } // are there any hfills in the row? - int const nh = numberOfHfills(*this, pit, rit); + int const nh = numberOfHfills(*this, rit); if (nh) { if (w > 0) @@ -1633,12 +1647,12 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, switch (align) { case LYX_ALIGN_BLOCK: { - int const ns = numberOfSeparators(*this, pit, rit); + int const ns = numberOfSeparators(*this, rit); RowList::iterator next_row = boost::next(rit); - ParagraphList::iterator next_pit; + ParagraphList::iterator next_pit = next_row->par(); if (ns && next_row != rowlist_.end() && - (next_pit = getPar(next_row)) == pit && + next_pit == pit && !(next_pit->isNewline(next_row->pos() - 1)) && !(next_pit->isInset(next_row->pos()) && next_pit->getInset(next_row->pos()) && @@ -1661,10 +1675,10 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, if (!bidi) return; - computeBidiTables(pit, bv()->buffer(), rit); + computeBidiTables(bv()->buffer(), rit); if (is_rtl) { pos_type body_pos = pit->beginningOfBody(); - pos_type last = lastPos(*this, pit, rit); + pos_type last = lastPos(*this, rit); if (body_pos > 0 && (body_pos - 1 > last || @@ -1878,7 +1892,7 @@ void LyXText::selectSelectedWord() // now find the end of the word while (cursor.pos() < cursor.par()->size() - && cursor.par()->isLetter(cursor.pos())) + && (cursor.par()->isLetter(cursor.pos()))) cursor.pos(cursor.pos() + 1); setCursor(cursor.par(), cursor.pos()); @@ -2167,14 +2181,14 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const // find the first row of the specified paragraph RowList::iterator rit = rowlist_.begin(); RowList::iterator end = rowlist_.end(); - while (boost::next(rit) != end && getPar(rit) != pit) { + while (boost::next(rit) != end && rit->par() != pit) { ++rit; } // now find the wanted row while (rit->pos() < pos && boost::next(rit) != end - && getPar(boost::next(rit)) == pit + && boost::next(rit)->par() == pit && boost::next(rit)->pos() <= pos) { ++rit; } @@ -2195,7 +2209,7 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const // find the first row of the specified paragraph RowList::iterator rit = rowlist_.begin(); RowList::iterator end = rowlist_.end(); - while (boost::next(rit) != end && getPar(rit) != pit) { + while (boost::next(rit) != end && rit->par() != pit) { y += rit->height(); ++rit; } @@ -2203,7 +2217,7 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const // now find the wanted row while (rit->pos() < pos && boost::next(rit) != end - && getPar(boost::next(rit)) == pit + && boost::next(rit)->par() == pit && boost::next(rit)->pos() <= pos) { y += rit->height(); ++rit; @@ -2267,68 +2281,3 @@ int LyXText::getDepth() const { return cursor.par()->getDepth(); } - - -#warning Expensive. Remove before 1.4! -// computes a ParagraphList::iterator from RowList::iterator by -// counting zeros in the sequence of pos values. - -ParagraphList::iterator LyXText::getPar(RowList::iterator row) const -{ - if (row == rows().end()) { - lyxerr << "getPar() pit at end " << endl; - Assert(false); - } - - if (row == rows().begin()) { - return ownerParagraphs().begin(); - } - - ParagraphList::iterator pit = ownerParagraphs().begin(); - RowList::iterator rit = rows().begin(); - RowList::iterator rend = rows().end(); - for (++rit ; rit != rend; ++rit) { - if (rit->pos() == 0) { - ++pit; - if (pit == ownerParagraphs().end()) { - lyxerr << "unexpected in LyXText::getPar()" << endl; - Assert(false); - } - } - if (rit == row) { - return pit; - } - } - - lyxerr << "LyXText::getPar: row not found " << endl; - Assert(false); - return ownerParagraphs().end(); // shut up compiler -} - - -RowList::iterator LyXText::beginRow(ParagraphList::iterator pit) const -{ - int n = std::distance(ownerParagraphs().begin(), pit); - - RowList::iterator rit = rows().begin(); - RowList::iterator end = rows().end(); - for ( ; rit != end; ++rit) - if (rit->pos() == 0 && n-- == 0) - return rit; - - return rit; -} - - -RowList::iterator LyXText::endRow(ParagraphList::iterator pit) const -{ - return beginRow(boost::next(pit)); -} - - -RowList::iterator LyXText::endRow(RowList::iterator rit) const -{ - for (++rit; rit != rows().end() && rit->pos(); ++rit) - ; - return rit; -} diff --git a/src/text2.C b/src/text2.C index 01dbfd13ed..857ee4aa3b 100644 --- a/src/text2.C +++ b/src/text2.C @@ -89,7 +89,8 @@ void LyXText::init(BufferView * bview) current_font = getFont(ownerParagraphs().begin(), 0); redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); - setCursorIntern(ownerParagraphs().begin(), 0); + + setCursorIntern(rowlist_.begin()->par(), 0); selection.cursor = cursor; updateCounters(); @@ -263,10 +264,10 @@ void LyXText::removeRow(RowList::iterator rit) // remove all following rows of the paragraph of the specified row. void LyXText::removeParagraph(RowList::iterator rit) { - ParagraphList::iterator tmppit = getPar(rit); + ParagraphList::iterator tmppit = rit->par(); ++rit; - while (rit != rows().end() && getPar(rit) == tmppit) { + while (rit != rows().end() && rit->par() == tmppit) { RowList::iterator tmprit = boost::next(rit); removeRow(rit); rit = tmprit; @@ -278,21 +279,23 @@ void LyXText::insertParagraph(ParagraphList::iterator pit, RowList::iterator rit) { // insert a new row, starting at position 0 - rit = rowlist_.insert(rit, Row(0)); + rit = rowlist_.insert(rit, Row(pit, 0)); // and now append the whole paragraph before the new row + Assert(rit != rowlist_.end()); - pos_type const last = pit->size(); + pos_type const last = rit->par()->size(); bool done = false; do { - pos_type z = rowBreakPoint(pit, *rit); + pos_type z = rowBreakPoint(*rit); RowList::iterator tmprow = rit; if (z < last) { ++z; - rit = rowlist_.insert(boost::next(rit), Row(z)); + Row newrow(rit->par(), z); + rit = rowlist_.insert(boost::next(rit), newrow); } else { done = true; } @@ -606,6 +609,16 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) } +RowList::iterator LyXText::firstRow(ParagraphList::iterator pit) +{ + RowList::iterator rit; + for (rit = rows().begin(); rit != rows().end(); ++rit) + if (rit->par() == pit) + break; + return rit; +} + + // rebreaks all paragraphs between the specified pars // This function is needed after SetLayout and SetFont etc. void LyXText::redoParagraphs(ParagraphList::iterator start, @@ -618,18 +631,19 @@ void LyXText::redoParagraphs(ParagraphList::iterator start, void LyXText::redoParagraph(ParagraphList::iterator pit) { - RowList::iterator first = beginRow(pit); - RowList::iterator last = endRow(first); + RowList::iterator rit = firstRow(pit); // remove paragraph from rowlist - while (first != last) { - RowList::iterator rit2 = first; - ++first; + while (rit != rows().end() && rit->par() == pit) { + RowList::iterator rit2 = rit++; removeRow(rit2); } // reinsert the paragraph - insertParagraph(pit, last); + insertParagraph(pit, rit); + + // why? + setHeightOfRow(rows().begin()); } @@ -716,10 +730,10 @@ void LyXText::cursorEnd() RowList::iterator rit = cursorRow(); RowList::iterator next_rit = boost::next(rit); - ParagraphList::iterator pit = cursor.par(); - pos_type last_pos = lastPos(*this, pit, rit); + ParagraphList::iterator pit = rit->par(); + pos_type last_pos = lastPos(*this, rit); - if (next_rit == rows().end() || getPar(next_rit) != pit) { + if (next_rit == rows().end() || next_rit->par() != pit) { ++last_pos; } else { if (pit->empty() || @@ -1406,7 +1420,7 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, cur.iy(y + row->baseline()); if (row != beg && pos && - getPar(boost::prior(row)) == getPar(row) && + boost::prior(row)->par() == row->par() && pos < pit->size() && pit->getChar(pos) == Paragraph::META_INSET) { InsetOld * ins = pit->getInset(pos); @@ -1421,7 +1435,7 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, // y is now the cursor baseline cur.y(y); - pos_type last = lastPrintablePos(*this, pit, old_row); + pos_type last = lastPrintablePos(*this, old_row); // None of these should happen, but we're scaredy-cats if (pos > pit->size()) { @@ -1440,11 +1454,11 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, } // now get the cursors x position - float x = getCursorX(pit, row, pos, last, boundary); + float x = getCursorX(row, pos, last, boundary); cur.x(int(x)); cur.x_fix(cur.x()); if (old_row != row) { - x = getCursorX(pit, old_row, pos, last, boundary); + x = getCursorX(old_row, pos, last, boundary); cur.ix(int(x)); } else cur.ix(cur.x()); @@ -1462,7 +1476,7 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, } -float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit, +float LyXText::getCursorX(RowList::iterator rit, pos_type pos, pos_type last, bool boundary) const { pos_type cursor_vpos = 0; @@ -1471,15 +1485,16 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit, double fill_hfill; double fill_label_hfill; // This call HAS to be here because of the BidiTables!!! - prepareToPrint(pit, rit, x, fill_separator, fill_hfill, + prepareToPrint(rit, x, fill_separator, fill_hfill, fill_label_hfill); + ParagraphList::iterator rit_par = rit->par(); pos_type const rit_pos = rit->pos(); if (last < rit_pos) cursor_vpos = rit_pos; else if (pos > last && !boundary) - cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params)) + cursor_vpos = (rit_par->isRightToLeftPar(bv()->buffer()->params)) ? rit_pos : last + 1; else if (pos > rit_pos && (pos > last || boundary)) // Place cursor after char at (logical) position pos - 1 @@ -1490,9 +1505,9 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit, cursor_vpos = (bidi_level(pos) % 2 == 0) ? log2vis(pos) : log2vis(pos) + 1; - pos_type body_pos = pit->beginningOfBody(); + pos_type body_pos = rit_par->beginningOfBody(); if (body_pos > 0 && - (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1))) + (body_pos - 1 > last || !rit_par->isLineSeparator(body_pos - 1))) body_pos = 0; for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) { @@ -1500,23 +1515,23 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit, if (body_pos > 0 && pos == body_pos - 1) { x += fill_label_hfill + font_metrics::width( - pit->layout()->labelsep, getLabelFont(pit)); - if (pit->isLineSeparator(body_pos - 1)) - x -= singleWidth(pit, body_pos - 1); + rit_par->layout()->labelsep, getLabelFont(rit_par)); + if (rit_par->isLineSeparator(body_pos - 1)) + x -= singleWidth(rit_par, body_pos - 1); } - if (hfillExpansion(*this, pit, rit, pos)) { - x += singleWidth(pit, pos); + if (hfillExpansion(*this, rit, pos)) { + x += singleWidth(rit_par, pos); if (pos >= body_pos) x += fill_hfill; else x += fill_label_hfill; - } else if (pit->isSeparator(pos)) { - x += singleWidth(pit, pos); + } else if (rit_par->isSeparator(pos)) { + x += singleWidth(rit_par, pos); if (pos >= body_pos) x += fill_separator; } else - x += singleWidth(pit, pos); + x += singleWidth(rit_par, pos); } return x; } @@ -1571,33 +1586,35 @@ void LyXText::setCurrentFont() // returns the column near the specified x-coordinate of the row // x is set to the real beginning of this column -pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, - RowList::iterator rit, int & x, bool & boundary) const +pos_type +LyXText::getColumnNearX(RowList::iterator rit, int & x, bool & boundary) const { double tmpx = 0; double fill_separator; double fill_hfill; double fill_label_hfill; - prepareToPrint(pit, rit, tmpx, fill_separator, fill_hfill, fill_label_hfill); + prepareToPrint(rit, tmpx, fill_separator, fill_hfill, fill_label_hfill); pos_type vc = rit->pos(); - pos_type last = lastPrintablePos(*this, pit, rit); + pos_type last = lastPrintablePos(*this, rit); pos_type c = 0; - LyXLayout_ptr const & layout = pit->layout(); + + ParagraphList::iterator rit_par = rit->par(); + LyXLayout_ptr const & layout = rit->par()->layout(); bool left_side = false; - pos_type body_pos = pit->beginningOfBody(); + pos_type body_pos = rit_par->beginningOfBody(); double last_tmpx = tmpx; if (body_pos > 0 && (body_pos - 1 > last || - !pit->isLineSeparator(body_pos - 1))) + !rit_par->isLineSeparator(body_pos - 1))) body_pos = 0; // check for empty row - if (!pit->size()) { + if (!rit_par->size()) { x = int(tmpx); return 0; } @@ -1607,23 +1624,23 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, last_tmpx = tmpx; if (body_pos > 0 && c == body_pos - 1) { tmpx += fill_label_hfill + - font_metrics::width(layout->labelsep, getLabelFont(pit)); - if (pit->isLineSeparator(body_pos - 1)) - tmpx -= singleWidth(pit, body_pos - 1); + font_metrics::width(layout->labelsep, getLabelFont(rit_par)); + if (rit_par->isLineSeparator(body_pos - 1)) + tmpx -= singleWidth(rit_par, body_pos - 1); } - if (hfillExpansion(*this, pit, rit, c)) { - tmpx += singleWidth(pit, c); + if (hfillExpansion(*this, rit, c)) { + tmpx += singleWidth(rit_par, c); if (c >= body_pos) tmpx += fill_hfill; else tmpx += fill_label_hfill; - } else if (pit->isSeparator(c)) { - tmpx += singleWidth(pit, c); + } else if (rit_par->isSeparator(c)) { + tmpx += singleWidth(rit_par, c); if (c >= body_pos) tmpx += fill_separator; } else { - tmpx += singleWidth(pit, c); + tmpx += singleWidth(rit_par, c); } ++vc; } @@ -1642,12 +1659,13 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, RowList::iterator next_rit = boost::next(rit); bool const lastrow = lyxrc.rtl_support && - (next_rit == rowlist_.end() || getPar(next_rit) != pit); + (next_rit == rowlist_.end() || + next_rit->par() != rit_par); // If lastrow is false, we don't need to compute // the value of rtl. bool const rtl = (lastrow) - ? pit->isRightToLeftPar(bv()->buffer()->params) + ? rit_par->isRightToLeftPar(bv()->buffer()->params) : false; if (lastrow && ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) || @@ -1662,15 +1680,16 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, bool const rtl = (bidi_level(c) % 2 == 1); if (left_side == rtl) { ++c; - boundary = isBoundary(bv()->buffer(), *pit, c); + boundary = isBoundary(bv()->buffer(), *rit_par, c); } } - if (rit->pos() <= last && c > last && pit->isNewline(last)) { + if (rit->pos() <= last && c > last + && rit_par->isNewline(last)) { if (bidi_level(last) % 2 == 0) - tmpx -= singleWidth(pit, last); + tmpx -= singleWidth(rit_par, last); else - tmpx += singleWidth(pit, last); + tmpx += singleWidth(rit_par, last); c = last; } @@ -1703,9 +1722,9 @@ namespace { if (boost::next(row) == lt.rows().end()) return false; - RowList::iterator next = boost::next(row); + Row const & next = *boost::next(row); - if (next->pos() != cur.pos() || lt.getPar(next) != cur.par()) + if (next.pos() != cur.pos() || next.par() != cur.par()) return false; if (cur.pos() == cur.par()->size() @@ -1726,18 +1745,19 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) // Get the row first. RowList::iterator row = getRowNearY(y); - ParagraphList::iterator pit = getPar(row); bool bound = false; - pos_type const column = getColumnNearX(pit, row, x, bound); - cur.par(pit); + pos_type const column = getColumnNearX(row, x, bound); + cur.par(row->par()); cur.pos(row->pos() + column); cur.x(x); cur.y(y + row->baseline()); if (beforeFullRowInset(*this, cur)) { - pos_type const last = lastPrintablePos(*this, pit, row); + pos_type const last = lastPrintablePos(*this, row); RowList::iterator next_row = boost::next(row); - cur.ix(int(getCursorX(pit, next_row, cur.pos(), last, bound))); + + float x = getCursorX(next_row, cur.pos(), last, bound); + cur.ix(int(x)); cur.iy(y + row->height() + next_row->baseline()); } else { cur.iy(cur.y()); @@ -1991,7 +2011,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) * there is another layout before */ RowList::iterator tmprit = boost::next(prevrow); if (tmprit != rows().end()) { - redoParagraph(getPar(tmprit)); + redoParagraph(tmprit->par()); updateCounters(); } setHeightOfRow(prevrow); @@ -2020,7 +2040,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) The next row can change its height, if there is another layout before */ if (nextrow != rows().end()) { - redoParagraph(getPar(nextrow)); + redoParagraph(nextrow->par()); updateCounters(); } } diff --git a/src/text3.C b/src/text3.C index 85976556b0..e1d1373422 100644 --- a/src/text3.C +++ b/src/text3.C @@ -275,7 +275,7 @@ void LyXText::cursorPrevious() //bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y); if (cursorRow() != rows().begin()) { LyXCursor cur; - setCursor(cur, getPar(boost::prior(cursorRow())), + setCursor(cur, boost::prior(cursorRow())->par(), boost::prior(cursorRow())->pos(), false); if (cur.y() > top_y()) { cursorUp(true); @@ -338,7 +338,7 @@ void LyXText::cursorNext() RowList::iterator next_row = boost::next(cursorRow()); if (next_row != rows().end()) { LyXCursor cur; - setCursor(cur, getPar(next_row), next_row->pos(), false); + setCursor(cur, next_row->par(), next_row->pos(), false); if (cur.y() < top_y() + bv()->workHeight()) { cursorDown(true); } -- 2.39.2