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>
* BufferView_pimpl.C (dispatch): changes to the Dialogs interface for

View File

@ -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);

View File

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

View File

@ -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<LyXText*>(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);

View File

@ -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) {

View File

@ -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<LyXText *>(this)->postPaint(y - prevrow->height());
} else {
setHeightOfRow(firstrow);
setHeightOfRow(firstRow());
const_cast<LyXText *>(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<LyXText *>(this)->postPaint(