lyx-rowlist0-e with small alterations

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6593 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-03-27 12:41:47 +00:00
parent 9c01e98af7
commit 42e2aabad1
6 changed files with 102 additions and 107 deletions

View File

@ -1,3 +1,33 @@
2003-03-27 Lars Gullik Bjønnes <larsbj@gullik.net>
* 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 <leeming@lyx.org> 2003-03-26 Angus Leeming <leeming@lyx.org>
* BufferView_pimpl.C (dispatch): changes to the Dialogs interface for * BufferView_pimpl.C (dispatch): changes to the Dialogs interface for

View File

@ -88,14 +88,17 @@ RowList::RowList()
RowList::iterator RowList::iterator
RowList::insert(RowList::iterator it, Row * row) RowList::insert(RowList::iterator it, Row * row)
{ {
if (it != end()) { if (rowlist == 0) {
rowlist = row;
} else if (it != end()) {
Row * prev = it->previous(); Row * prev = it->previous();
row->next(&*it); row->next(&*it);
row->previous(prev); row->previous(prev);
prev->next(row); if (prev)
prev->next(row);
else
rowlist = row;
it->previous(row); it->previous(row);
} else if (rowlist == 0) {
rowlist = row;
} else { } else {
// Find last par. // Find last par.
Row * last = rowlist; Row * last = rowlist;
@ -127,7 +130,7 @@ void RowList::erase(RowList::iterator it)
prev->next(next); prev->next(next);
else else
rowlist = next; rowlist = next;
if (next) if (next)
next->previous(prev); next->previous(prev);

View File

@ -168,7 +168,7 @@ bool Row::isParEnd() const
pos_type Row::lastPos() const pos_type Row::lastPos() const
{ {
if (!par()->size()) if (par()->empty())
return 0; return 0;
if (isParEnd()) { if (isParEnd()) {

View File

@ -17,6 +17,7 @@
#include "layout.h" #include "layout.h"
#include "LColor.h" #include "LColor.h"
#include "insets/inset.h" #include "insets/inset.h"
#include "RowList.h"
class Buffer; class Buffer;
class BufferParams; class BufferParams;
@ -66,9 +67,6 @@ public:
/// sets inset as owner /// sets inset as owner
LyXText(BufferView *, InsetText *); LyXText(BufferView *, InsetText *);
/// Destructor
~LyXText();
void init(BufferView *, bool reinit = false); void init(BufferView *, bool reinit = false);
/// ///
int height; int height;
@ -251,8 +249,8 @@ public:
IMO it's stupid to have to allocate a dummy y all the time I need IMO it's stupid to have to allocate a dummy y all the time I need
the first row the first row
*/ */
Row * firstRow() const { return firstrow; } Row * firstRow() const { return &*rowlist_.begin(); }
Row * lastRow() const { return &const_cast<LyXText*>(this)->rowlist_.back(); }
/** The cursor. /** The cursor.
Later this variable has to be removed. There should be now internal 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 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; bool bidi_InRange(lyx::pos_type pos) const;
private: private:
/// ///
Row * firstrow; RowList rowlist_;
///
Row * lastrow;
/// ///
void cursorLeftOneWord(LyXCursor &); void cursorLeftOneWord(LyXCursor &);
@ -516,6 +511,7 @@ private:
/** inserts a new row behind the specified row, increments /** inserts a new row behind the specified row, increments
the touched counters */ the touched counters */
void insertRow(Row * row, Paragraph * par, lyx::pos_type pos); void insertRow(Row * row, Paragraph * par, lyx::pos_type pos);
/// removes the row and reset the touched counters /// removes the row and reset the touched counters
void removeRow(Row * row); void removeRow(Row * row);

View File

@ -78,7 +78,7 @@ int LyXText::top_y() const
return 0; return 0;
int y = 0; int y = 0;
for (Row * row = firstrow; for (Row * row = firstRow();
row && row != anchor_row_; row = row->next()) { row && row != anchor_row_; row = row->next()) {
y += row->height(); y += row->height();
} }
@ -88,7 +88,7 @@ int LyXText::top_y() const
void LyXText::top_y(int newy) void LyXText::top_y(int newy)
{ {
if (!firstrow) if (!firstRow())
return; return;
lyxerr[Debug::GUI] << "setting top y = " << newy << endl; lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
@ -1299,7 +1299,7 @@ void LyXText::setHeightOfRow(Row * row)
} }
row->width(int(maxwidth + x)); row->width(int(maxwidth + x));
if (inset_owner) { if (inset_owner) {
Row * r = firstrow; Row * r = firstRow();
width = max(0, workWidth()); width = max(0, workWidth());
while (r) { while (r) {
if (r->width() > width) if (r->width() > width)
@ -1396,6 +1396,7 @@ void LyXText::breakAgainOneRow(Row * row)
// insert a new row // insert a new row
++z; ++z;
insertRow(row, row->par(), z); insertRow(row, row->par(), z);
row = row->next();
} else { } else {
row = row->next(); row = row->next();
++z; ++z;
@ -1513,7 +1514,6 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
cursor.par()->next()->erase(0); cursor.par()->next()->erase(0);
insertParagraph(cursor.par()->next(), cursor.row()); insertParagraph(cursor.par()->next(), cursor.row());
updateCounters(); updateCounters();
// This check is necessary. Otherwise the new empty paragraph will // This check is necessary. Otherwise the new empty paragraph will
@ -2763,10 +2763,10 @@ void LyXText::backspace()
// returns pointer to a specified row // returns pointer to a specified row
Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
{ {
if (!firstrow) if (!firstRow())
return 0; return 0;
Row * tmprow = firstrow; Row * tmprow = firstRow();
y = 0; y = 0;
// find the first row of the specified paragraph // find the first row of the specified paragraph
@ -2792,7 +2792,7 @@ Row * LyXText::getRowNearY(int & y) const
{ {
#if 1 #if 1
// If possible we should optimize this method. (Lgb) // If possible we should optimize this method. (Lgb)
Row * tmprow = firstrow; Row * tmprow = firstRow();
int tmpy = 0; int tmpy = 0;
while (tmprow->next() && tmpy + tmprow->height() <= y) { while (tmprow->next() && tmpy + tmprow->height() <= y) {

View File

@ -54,8 +54,9 @@ using lyx::pos_type;
LyXText::LyXText(BufferView * bv) LyXText::LyXText(BufferView * bv)
: height(0), width(0), anchor_row_(0), anchor_row_offset_(0), : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
inset_owner(0), the_locking_inset(0), need_break_row(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(); clearPaint();
} }
@ -63,8 +64,9 @@ LyXText::LyXText(BufferView * bv)
LyXText::LyXText(BufferView * bv, InsetText * inset) LyXText::LyXText(BufferView * bv, InsetText * inset)
: height(0), width(0), anchor_row_(0), anchor_row_offset_(0), : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
inset_owner(inset), the_locking_inset(0), need_break_row(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(); clearPaint();
} }
@ -72,49 +74,32 @@ LyXText::LyXText(BufferView * bv, InsetText * inset)
void LyXText::init(BufferView * bview, bool reinit) void LyXText::init(BufferView * bview, bool reinit)
{ {
if (reinit) { if (reinit) {
// Delete all rows, this does not touch the paragraphs! rowlist_.clear();
Row * tmprow = firstrow;
while (firstrow) {
tmprow = firstrow->next();
delete firstrow;
firstrow = tmprow;
}
lastrow = 0;
need_break_row = 0; need_break_row = 0;
width = height = 0; width = height = 0;
copylayouttype.erase(); copylayouttype.erase();
top_y(0); top_y(0);
clearPaint(); clearPaint();
} else if (firstrow) } else if (firstRow())
return; return;
Paragraph * par = ownerParagraph(); Paragraph * par = ownerParagraph();
current_font = getFont(bview->buffer(), par, 0); current_font = getFont(bview->buffer(), par, 0);
while (par) { while (par) {
insertParagraph(par, lastrow); if (rowlist_.empty())
insertParagraph(par, 0);
else
insertParagraph(par, lastRow());
par = par->next(); par = par->next();
} }
setCursorIntern(firstrow->par(), 0); setCursorIntern(firstRow()->par(), 0);
selection.cursor = cursor; selection.cursor = cursor;
updateCounters(); 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 { namespace {
LyXFont const realizeFont(LyXFont const & font, LyXFont const realizeFont(LyXFont const & font,
@ -282,52 +267,30 @@ void LyXText::insertRow(Row * row, Paragraph * par,
pos_type pos) pos_type pos)
{ {
Row * tmprow = new Row; 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->par(par);
tmprow->pos(pos); tmprow->pos(pos);
if (row == lastrow) if (!row) {
lastrow = tmprow; rowlist_.insert(rowlist_.begin(), tmprow);
} else {
rowlist_.insert(row->next(), tmprow);
}
} }
// removes the row and reset the touched counters // removes the row and reset the touched counters
void LyXText::removeRow(Row * row) void LyXText::removeRow(Row * row)
{ {
lyx::Assert(row);
Row * row_prev = row->previous(); Row * row_prev = row->previous();
if (row->next()) Row * row_next = row->next();
row->next()->previous(row_prev); int const row_height = row->height();
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;
}
/* FIXME: when we cache the bview, this should just /* FIXME: when we cache the bview, this should just
* become a postPaint(), I think */ * become a postPaint(), I think */
if (refresh_row == row) { if (refresh_row == row) {
refresh_row = row_prev ? row_prev : row->next(); refresh_row = row_prev ? row_prev : row_next;
// what about refresh_y // what about refresh_y
} }
@ -336,14 +299,15 @@ void LyXText::removeRow(Row * row)
anchor_row_ = row_prev; anchor_row_ = row_prev;
anchor_row_offset_ += row_prev->height(); anchor_row_offset_ += row_prev->height();
} else { } else {
anchor_row_ = row->next(); anchor_row_ = row_next;
anchor_row_offset_ -= row->height(); 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 // insert a new row, starting at position 0
insertRow(row, par, 0); insertRow(row, par, 0);
// and now append the whole paragraph before the new row // and now append the whole paragraph before the new row
if (!row) { if (!row) {
appendParagraph(firstrow); appendParagraph(firstRow());
} else { } else {
appendParagraph(row->next()); appendParagraph(row->next());
} }
@ -745,22 +707,24 @@ void LyXText::redoDrawingOfParagraph(LyXCursor const & cur)
void LyXText::redoParagraphs(LyXCursor const & cur, void LyXText::redoParagraphs(LyXCursor const & cur,
Paragraph const * endpar) Paragraph const * endpar)
{ {
Row * tmprow2;
Paragraph * tmppar = 0;
Paragraph * first_phys_par = 0;
Row * tmprow = cur.row(); Row * tmprow = cur.row();
int y = cur.y() - tmprow->baseline(); int y = cur.y() - tmprow->baseline();
Paragraph * first_phys_par = 0;
if (!tmprow->previous()) { if (!tmprow->previous()) {
// a trick/hack for UNDO // a trick/hack for UNDO
// This is needed because in an UNDO/REDO we could have changed // This is needed because in an UNDO/REDO we could have changed
// the ownerParagrah() so the paragraph inside the row is NOT // the ownerParagrah() so the paragraph inside the row is NOT
// my really first par anymore. Got it Lars ;) (Jug 20011206) // my really first par anymore. Got it Lars ;) (Jug 20011206)
first_phys_par = ownerParagraph(); first_phys_par = ownerParagraph();
lyxerr << "ownerParagraph" << endl;
} else { } else {
first_phys_par = tmprow->par(); first_phys_par = tmprow->par();
lyxerr << "tmprow->par()" << endl;
// Find first row of this paragraph.
while (tmprow->previous() while (tmprow->previous()
&& tmprow->previous()->par() == first_phys_par) && tmprow->previous()->par() == first_phys_par)
{ {
@ -771,11 +735,10 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
Row * prevrow = tmprow->previous(); Row * prevrow = tmprow->previous();
// remove it // Remove all the rows until we reach endpar
Paragraph * tmppar = 0;
if (tmprow->next()) if (tmprow->next())
tmppar = tmprow->next()->par(); tmppar = tmprow->next()->par();
else
tmppar = 0;
while (tmprow->next() && tmppar != endpar) { while (tmprow->next() && tmppar != endpar) {
removeRow(tmprow->next()); removeRow(tmprow->next());
if (tmprow->next()) { if (tmprow->next()) {
@ -785,19 +748,19 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
} }
} }
// remove the first one // Remove the first of the paragraphs rows.
tmprow2 = tmprow; /* this is because tmprow->previous() // This is because tmprow->previous() can be 0
can be 0 */ Row * tmprow2 = tmprow;
tmprow = tmprow->previous(); tmprow = tmprow->previous();
removeRow(tmprow2); removeRow(tmprow2);
// Reinsert the paragraphs.
tmppar = first_phys_par; tmppar = first_phys_par;
do { do {
if (tmppar) { if (tmppar) {
insertParagraph(tmppar, tmprow); insertParagraph(tmppar, tmprow);
if (!tmprow) { if (!tmprow) {
tmprow = firstrow; tmprow = firstRow();
} }
while (tmprow->next() while (tmprow->next()
&& tmprow->next()->par() == tmppar) { && tmprow->next()->par() == tmppar) {
@ -812,7 +775,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
setHeightOfRow(prevrow); setHeightOfRow(prevrow);
const_cast<LyXText *>(this)->postPaint(y - prevrow->height()); const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
} else { } else {
setHeightOfRow(firstrow); setHeightOfRow(firstRow());
const_cast<LyXText *>(this)->postPaint(0); const_cast<LyXText *>(this)->postPaint(0);
} }
@ -824,7 +787,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
void LyXText::fullRebreak() void LyXText::fullRebreak()
{ {
if (!firstrow) { if (!firstRow()) {
init(bv()); init(bv());
return; return;
} }
@ -1330,7 +1293,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par)
// Updates all counters. Paragraphs with changed label string will be rebroken // Updates all counters. Paragraphs with changed label string will be rebroken
void LyXText::updateCounters() void LyXText::updateCounters()
{ {
Row * row = firstrow; Row * row = firstRow();
Paragraph * par = row->par(); Paragraph * par = row->par();
// CHECK if this is really needed. (Lgb) // 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 parindent that can occur or dissappear.
* The next row can change its height, if * The next row can change its height, if
* there is another layout before */ * there is another layout before */
if (refresh_row->next()) { if (refresh_row) {
breakAgain(refresh_row->next()); if (refresh_row->next()) {
updateCounters(); breakAgain(refresh_row->next());
updateCounters();
}
setHeightOfRow(refresh_row);
} }
setHeightOfRow(refresh_row);
} else { } else {
Row * nextrow = old_cursor.row()->next(); Row * nextrow = old_cursor.row()->next();
const_cast<LyXText *>(this)->postPaint( const_cast<LyXText *>(this)->postPaint(