From a848fced972853b5942f64c14abb32c430502431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 1 Aug 2003 14:12:04 +0000 Subject: [PATCH] duplicate rowbreaking code in redoParagraph as starting point for later consolidation. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7474 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/lyxrow.C | 13 +++++++++++ src/lyxrow.h | 2 ++ src/text.C | 2 +- src/text2.C | 62 ++++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/lyxrow.C b/src/lyxrow.C index 682186c71f..d387cd65bc 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -16,6 +16,7 @@ #include "paragraph.h" #include "layout.h" #include "lyxlayout.h" +#include "debug.h" using lyx::pos_type; @@ -152,3 +153,15 @@ bool Row::isParStart() const { return !pos(); } + + +void Row::dump(const char * s) const +{ + lyxerr << s << " pos: " << pos_ << " width: " << width_ + << " height: " << height_ + << " fill: " << fill_ + << " ascent_of_text: " << ascent_of_text_ + << " top_of_text: " << top_of_text_ + << " y: " << y_ << "\n"; +} + diff --git a/src/lyxrow.h b/src/lyxrow.h index e7c1183958..2ad6a0577e 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -65,6 +65,8 @@ public: unsigned int y() const; /// cache the y position void y(unsigned int newy); + /// current debugging only + void dump(const char * = "") const; private: /// ParagraphList::iterator pit_; diff --git a/src/text.C b/src/text.C index 53211171d2..5ff3b50111 100644 --- a/src/text.C +++ b/src/text.C @@ -1094,12 +1094,12 @@ void LyXText::setHeightOfRow(RowList::iterator rit) } else { // Special handling of insets - are any larger? if (par.isInset(pos)) { - LyXFont const tmpfont = getFont(pit, pos); InsetOld const * tmpinset = par.getInset(pos); if (tmpinset) { #if 1 // this is needed for deep update on initialitation #warning inset->update FIXME //tmpinset->update(bv()); + LyXFont const tmpfont = getFont(pit, pos); Dimension dim; MetricsInfo mi(bv(), tmpfont, workWidth()); tmpinset->metrics(mi, dim); diff --git a/src/text2.C b/src/text2.C index e5dc042c03..16c8484a14 100644 --- a/src/text2.C +++ b/src/text2.C @@ -281,11 +281,11 @@ void LyXText::removeParagraph(RowList::iterator rit) void LyXText::insertParagraph(ParagraphList::iterator pit, - RowList::iterator rowit) + RowList::iterator rit) { // insert a new row, starting at position 0 Row newrow(pit, 0); - RowList::iterator rit = rowlist_.insert(rowit, newrow); + rit = rowlist_.insert(rit, newrow); // and now append the whole paragraph before the new row appendParagraph(rit); @@ -645,7 +645,44 @@ void LyXText::redoParagraph(ParagraphList::iterator pit) } // reinsert the paragraph - insertParagraph(pit, rit); + // insert a new row, starting at position 0 + Row newrow(pit, 0); + rit = rowlist_.insert(rit, newrow); + newrow.dump("newrow: "); + + // and now append the whole paragraph before the new row + // was: appendParagraph(rit); + + pos_type const last = rit->par()->size(); + bool done = false; + + do { + pos_type z = rowBreakPoint(*rit); + + RowList::iterator tmprow = rit; + tmprow->dump("tmprow: "); + + if (z < last) { + ++z; + Row newrow(rit->par(), z); + newrow.dump("newrow2: "); + rit = rowlist_.insert(boost::next(rit), newrow); + } else { + done = true; + } + + // Set the dimensions of the row + // fixed fill setting now by calling inset->update() in + // SingleWidth when needed! + tmprow->dump("tmprow 1: "); + tmprow->fill(fill(tmprow, workWidth())); + tmprow->dump("tmprow 2: "); + setHeightOfRow(tmprow); + tmprow->dump("tmprow 3: "); + height += rit->height(); + + } while (!done); + setHeightOfRow(rows().begin()); } @@ -661,7 +698,7 @@ void LyXText::fullRebreak() void LyXText::metrics(MetricsInfo & mi, Dimension & dim) { - lyxerr << "LyXText::metrics: width: " << mi.base.textwidth << "\n"; + //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth << "\n"; //Assert(mi.base.textwidth); // rebuild row cache @@ -680,6 +717,8 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) for (; ii != iend; ++ii) { Dimension dim; MetricsInfo m = mi; +#warning FIXME: pos != 0 + m.base.font = getFont(pit, 0); ii->inset->metrics(m, dim); } @@ -1873,7 +1912,8 @@ void LyXText::cursorLeft(bool internal) if (!internal && !boundary && isBoundary(bv()->buffer(), *cursor.par(), cursor.pos() + 1)) setCursor(cursor.par(), cursor.pos() + 1, true, true); - } else if (cursor.par() != ownerParagraphs().begin()) { // steps into the above paragraph. + } else if (cursor.par() != ownerParagraphs().begin()) { + // steps into the paragraph above ParagraphList::iterator pit = boost::prior(cursor.par()); setCursor(pit, pit->size()); } @@ -1949,12 +1989,10 @@ void LyXText::cursorDown(bool selecting) void LyXText::cursorUpParagraph() { - if (cursor.pos() > 0) { + if (cursor.pos() > 0) setCursor(cursor.par(), 0); - } - else if (cursor.par() != ownerParagraphs().begin()) { + else if (cursor.par() != ownerParagraphs().begin()) setCursor(boost::prior(cursor.par()), 0); - } } @@ -1963,13 +2001,13 @@ void LyXText::cursorDownParagraph() ParagraphList::iterator par = cursor.par(); ParagraphList::iterator next_par = boost::next(par); - if (next_par != ownerParagraphs().end()) { + if (next_par != ownerParagraphs().end()) setCursor(next_par, 0); - } else { + else setCursor(par, par->size()); - } } + // fix the cursor `cur' after a characters has been deleted at `where' // position. Called by deleteEmptyParagraphMechanism void LyXText::fixCursorAfterDelete(LyXCursor & cur,