From 42e2aabad1a6eb67adf474a481f262a1e82957ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 27 Mar 2003 12:41:47 +0000 Subject: [PATCH] lyx-rowlist0-e with small alterations git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6593 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 30 +++++++++++ src/RowList.C | 13 +++-- src/lyxrow.C | 2 +- src/lyxtext.h | 14 ++---- src/text.C | 14 +++--- src/text2.C | 136 +++++++++++++++++++------------------------------- 6 files changed, 102 insertions(+), 107 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ef605f94df..bdd165f173 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,33 @@ +2003-03-27 Lars Gullik Bjønnes + + * text2.C (LyXText): adjust, initialize refresh_row. + (init): adjust + (removeRow): adjust + (insertRow): adjust + (insertParagraph): adjst + (redoParagraphs): adjust + (fullRebreak): adjust + (updateCounters): adjust + (deleteEmptyParagraphMechanism): first attempt at fixing a + crashing bug. + + * text.C (top_y): adjust + (setHeightOfRow): adjust + (getRow): adjust + (getRowNearY): adjust + + * lyxtext.h: include RowList.h + (~LyXText): not needed anymore, deleted. + (firstRow): modify for RowList + (lastRow): new function + Delete firstrow and lastrow class variables, add a Rowlist + rowlist_ class variable. + + * lyxrow.C (lastPos): use empty() and not !size() to check if a + paragraph is empty. + + * RowList.C (insert): fix case where it == begin(). + 2003-03-26 Angus Leeming * BufferView_pimpl.C (dispatch): changes to the Dialogs interface for diff --git a/src/RowList.C b/src/RowList.C index 599afa3c7a..70e11bb056 100644 --- a/src/RowList.C +++ b/src/RowList.C @@ -88,14 +88,17 @@ RowList::RowList() RowList::iterator RowList::insert(RowList::iterator it, Row * row) { - if (it != end()) { + if (rowlist == 0) { + rowlist = row; + } else if (it != end()) { Row * prev = it->previous(); row->next(&*it); row->previous(prev); - prev->next(row); + if (prev) + prev->next(row); + else + rowlist = row; it->previous(row); - } else if (rowlist == 0) { - rowlist = row; } else { // Find last par. Row * last = rowlist; @@ -127,7 +130,7 @@ void RowList::erase(RowList::iterator it) prev->next(next); else rowlist = next; - + if (next) next->previous(prev); diff --git a/src/lyxrow.C b/src/lyxrow.C index 2ba125665e..ca328bc33f 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -168,7 +168,7 @@ bool Row::isParEnd() const pos_type Row::lastPos() const { - if (!par()->size()) + if (par()->empty()) return 0; if (isParEnd()) { diff --git a/src/lyxtext.h b/src/lyxtext.h index 8bcb5667d4..5a4f8efc51 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -17,6 +17,7 @@ #include "layout.h" #include "LColor.h" #include "insets/inset.h" +#include "RowList.h" class Buffer; class BufferParams; @@ -66,9 +67,6 @@ public: /// sets inset as owner LyXText(BufferView *, InsetText *); - /// Destructor - ~LyXText(); - void init(BufferView *, bool reinit = false); /// int height; @@ -251,8 +249,8 @@ public: IMO it's stupid to have to allocate a dummy y all the time I need the first row */ - Row * firstRow() const { return firstrow; } - + Row * firstRow() const { return &*rowlist_.begin(); } + Row * lastRow() const { return &const_cast(this)->rowlist_.back(); } /** 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 @@ -489,10 +487,7 @@ public: bool bidi_InRange(lyx::pos_type pos) const; private: /// - Row * firstrow; - /// - Row * lastrow; - + RowList rowlist_; /// void cursorLeftOneWord(LyXCursor &); @@ -516,6 +511,7 @@ private: /** inserts a new row behind the specified row, increments the touched counters */ void insertRow(Row * row, 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 494fcf18f0..396ca0e08c 100644 --- a/src/text.C +++ b/src/text.C @@ -78,7 +78,7 @@ int LyXText::top_y() const return 0; int y = 0; - for (Row * row = firstrow; + for (Row * row = firstRow(); row && row != anchor_row_; row = row->next()) { y += row->height(); } @@ -88,7 +88,7 @@ int LyXText::top_y() const void LyXText::top_y(int newy) { - if (!firstrow) + if (!firstRow()) return; lyxerr[Debug::GUI] << "setting top y = " << newy << endl; @@ -1299,7 +1299,7 @@ void LyXText::setHeightOfRow(Row * row) } row->width(int(maxwidth + x)); if (inset_owner) { - Row * r = firstrow; + Row * r = firstRow(); width = max(0, workWidth()); while (r) { if (r->width() > width) @@ -1396,6 +1396,7 @@ void LyXText::breakAgainOneRow(Row * row) // insert a new row ++z; insertRow(row, row->par(), z); + row = row->next(); } else { row = row->next(); ++z; @@ -1513,7 +1514,6 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout) cursor.par()->next()->erase(0); insertParagraph(cursor.par()->next(), cursor.row()); - updateCounters(); // This check is necessary. Otherwise the new empty paragraph will @@ -2763,10 +2763,10 @@ void LyXText::backspace() // returns pointer to a specified row Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const { - if (!firstrow) + if (!firstRow()) return 0; - Row * tmprow = firstrow; + Row * tmprow = firstRow(); y = 0; // find the first row of the specified paragraph @@ -2792,7 +2792,7 @@ Row * LyXText::getRowNearY(int & y) const { #if 1 // If possible we should optimize this method. (Lgb) - Row * tmprow = firstrow; + Row * tmprow = firstRow(); int tmpy = 0; while (tmprow->next() && tmpy + tmprow->height() <= y) { diff --git a/src/text2.C b/src/text2.C index 71f115b40b..b5a5689573 100644 --- a/src/text2.C +++ b/src/text2.C @@ -54,8 +54,9 @@ using lyx::pos_type; LyXText::LyXText(BufferView * bv) : height(0), width(0), anchor_row_(0), anchor_row_offset_(0), inset_owner(0), the_locking_inset(0), need_break_row(0), - bv_owner(bv), firstrow(0), lastrow(0) + bv_owner(bv) { + refresh_row = 0; clearPaint(); } @@ -63,8 +64,9 @@ LyXText::LyXText(BufferView * bv) LyXText::LyXText(BufferView * bv, InsetText * inset) : height(0), width(0), anchor_row_(0), anchor_row_offset_(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), - bv_owner(bv), firstrow(0), lastrow(0) + bv_owner(bv) { + refresh_row = 0; clearPaint(); } @@ -72,49 +74,32 @@ LyXText::LyXText(BufferView * bv, InsetText * inset) void LyXText::init(BufferView * bview, bool reinit) { if (reinit) { - // Delete all rows, this does not touch the paragraphs! - Row * tmprow = firstrow; - while (firstrow) { - tmprow = firstrow->next(); - delete firstrow; - firstrow = tmprow; - } - - lastrow = 0; + rowlist_.clear(); need_break_row = 0; width = height = 0; copylayouttype.erase(); top_y(0); clearPaint(); - } else if (firstrow) + } else if (firstRow()) return; Paragraph * par = ownerParagraph(); current_font = getFont(bview->buffer(), par, 0); while (par) { - insertParagraph(par, lastrow); + if (rowlist_.empty()) + insertParagraph(par, 0); + else + insertParagraph(par, lastRow()); par = par->next(); } - setCursorIntern(firstrow->par(), 0); + setCursorIntern(firstRow()->par(), 0); selection.cursor = cursor; updateCounters(); } -LyXText::~LyXText() -{ - // Delete all rows, this does not touch the paragraphs! - Row * tmprow = firstrow; - while (firstrow) { - tmprow = firstrow->next(); - delete firstrow; - firstrow = tmprow; - } -} - - namespace { LyXFont const realizeFont(LyXFont const & font, @@ -282,52 +267,30 @@ void LyXText::insertRow(Row * row, Paragraph * par, pos_type pos) { Row * tmprow = new Row; - if (!row) { - tmprow->previous(0); - tmprow->next(firstrow); - firstrow = tmprow; - } else { - tmprow->previous(row); - tmprow->next(row->next()); - row->next(tmprow); - } - - if (tmprow->next()) - tmprow->next()->previous(tmprow); - - if (tmprow->previous()) - tmprow->previous()->next(tmprow); - - tmprow->par(par); tmprow->pos(pos); - if (row == lastrow) - lastrow = tmprow; + if (!row) { + rowlist_.insert(rowlist_.begin(), tmprow); + } else { + rowlist_.insert(row->next(), tmprow); + } } // removes the row and reset the touched counters void LyXText::removeRow(Row * row) { + lyx::Assert(row); + Row * row_prev = row->previous(); - if (row->next()) - row->next()->previous(row_prev); - if (!row_prev) { - firstrow = row->next(); -// lyx::Assert(firstrow); - } else { - row_prev->next(row->next()); - } - if (row == lastrow) { - lyx::Assert(!row->next()); - lastrow = row_prev; - } + Row * row_next = row->next(); + int const row_height = row->height(); /* FIXME: when we cache the bview, this should just * become a postPaint(), I think */ if (refresh_row == row) { - refresh_row = row_prev ? row_prev : row->next(); + refresh_row = row_prev ? row_prev : row_next; // what about refresh_y } @@ -336,14 +299,15 @@ void LyXText::removeRow(Row * row) anchor_row_ = row_prev; anchor_row_offset_ += row_prev->height(); } else { - anchor_row_ = row->next(); - anchor_row_offset_ -= row->height(); + anchor_row_ = row_next; + anchor_row_offset_ -= row_height; } } - height -= row->height(); // the text becomes smaller + // the text becomes smaller + height -= row_height; - delete row; + rowlist_.erase(row); } @@ -362,16 +326,14 @@ void LyXText::removeParagraph(Row * row) } -// insert the specified paragraph behind the specified row -void LyXText::insertParagraph(Paragraph * par, - Row * row) +void LyXText::insertParagraph(Paragraph * par, Row * row) { // insert a new row, starting at position 0 insertRow(row, par, 0); // and now append the whole paragraph before the new row if (!row) { - appendParagraph(firstrow); + appendParagraph(firstRow()); } else { appendParagraph(row->next()); } @@ -745,22 +707,24 @@ void LyXText::redoDrawingOfParagraph(LyXCursor const & cur) void LyXText::redoParagraphs(LyXCursor const & cur, Paragraph const * endpar) { - Row * tmprow2; - Paragraph * tmppar = 0; - Paragraph * first_phys_par = 0; - Row * tmprow = cur.row(); int y = cur.y() - tmprow->baseline(); + Paragraph * first_phys_par = 0; if (!tmprow->previous()) { // a trick/hack for UNDO // This is needed because in an UNDO/REDO we could have changed // the ownerParagrah() so the paragraph inside the row is NOT // my really first par anymore. Got it Lars ;) (Jug 20011206) first_phys_par = ownerParagraph(); + lyxerr << "ownerParagraph" << endl; + } else { first_phys_par = tmprow->par(); + lyxerr << "tmprow->par()" << endl; + + // Find first row of this paragraph. while (tmprow->previous() && tmprow->previous()->par() == first_phys_par) { @@ -771,11 +735,10 @@ void LyXText::redoParagraphs(LyXCursor const & cur, Row * prevrow = tmprow->previous(); - // remove it + // Remove all the rows until we reach endpar + Paragraph * tmppar = 0; if (tmprow->next()) tmppar = tmprow->next()->par(); - else - tmppar = 0; while (tmprow->next() && tmppar != endpar) { removeRow(tmprow->next()); if (tmprow->next()) { @@ -785,19 +748,19 @@ void LyXText::redoParagraphs(LyXCursor const & cur, } } - // remove the first one - tmprow2 = tmprow; /* this is because tmprow->previous() - can be 0 */ + // Remove the first of the paragraphs rows. + // This is because tmprow->previous() can be 0 + Row * tmprow2 = tmprow; tmprow = tmprow->previous(); removeRow(tmprow2); + // Reinsert the paragraphs. tmppar = first_phys_par; - do { if (tmppar) { insertParagraph(tmppar, tmprow); if (!tmprow) { - tmprow = firstrow; + tmprow = firstRow(); } while (tmprow->next() && tmprow->next()->par() == tmppar) { @@ -812,7 +775,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur, setHeightOfRow(prevrow); const_cast(this)->postPaint(y - prevrow->height()); } else { - setHeightOfRow(firstrow); + setHeightOfRow(firstRow()); const_cast(this)->postPaint(0); } @@ -824,7 +787,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur, void LyXText::fullRebreak() { - if (!firstrow) { + if (!firstRow()) { init(bv()); return; } @@ -1330,7 +1293,7 @@ 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; + Row * row = firstRow(); Paragraph * par = row->par(); // CHECK if this is really needed. (Lgb) @@ -2348,11 +2311,14 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) * the parindent that can occur or dissappear. * The next row can change its height, if * there is another layout before */ - if (refresh_row->next()) { - breakAgain(refresh_row->next()); - updateCounters(); + if (refresh_row) { + if (refresh_row->next()) { + breakAgain(refresh_row->next()); + updateCounters(); + } + setHeightOfRow(refresh_row); } - setHeightOfRow(refresh_row); + } else { Row * nextrow = old_cursor.row()->next(); const_cast(this)->postPaint( -- 2.39.5