+2003-03-30 Lars Gullik Bjønnes <larsbj@gullik.net>
+
+ * text2.C (init): adjust
+ (insertRow): remove function
+ (insertParagraph): adjust
+ (redoParagraphs): adjust
+ (fullRebreak): adjust
+ (updateCounters): adjust
+
+ * text.C (top_y): rewrite to use RowList iterators.
+ (top_y): adjust
+ (setHeightOfRow): rewrite to sue RowList iterators.
+ (appendParagraph): adjust
+ (breakAgain): adjust
+ (breakAgainOneRow): adjust
+ (breakParagraph): adjust
+ (getRow): adjust
+ (getRowNearY): adjust, and remove commented code.
+
+ * lyxtext.h (firstRow): delete function
+ (lastRow): delete function
+ (rows): new function (const and non-const versions.)
+ (insertRow): delete function
+
+ * lyxrow.[Ch] (Row): new constructor taking a par and a pos
+
2003-03-29 John Levon <levon@movementarian.org>
* BufferView_pimpl.C: always update scrollbar top
+2003-03-30 Lars Gullik Bjønnes <larsbj@gullik.net>
+
+ * insettext.C (ascent): adjust for RowList
+ (descent): ditto
+ (draw): ditto
+ (getLyXText): adjust
+ (toggleSelection): adjust
+
+ * insetminipage.C (localDispatch): adjust for RowList
+
+ * insetert.C (localDispatch): adjust for RowList
+ (getMaxWidth): adjust for RowList
+
2003-03-29 John Levon <levon@movementarian.org>
* insetert.C: Alert cleanup
* taken by the text).
*/
LyXText * t = inset.getLyXText(cmd.view());
- t->need_break_row = t->firstRow();
+ t->need_break_row = &*t->rows().begin();
t->fullRebreak();
t->setCursorIntern(t->cursor.par(), t->cursor.pos());
inset.update(cmd.view(), true);
if (status_ != Inlined || w < 0)
return w;
LyXText * text = inset.getLyXText(bv);
- int rw = text->firstRow()->width();
+ int rw = text->rows().begin()->width();
if (!rw)
rw = w;
rw += 40;
- if (!text->firstRow()->next() && rw < w)
+ if (text->rows().size() == 1 && rw < w)
return -1;
return w;
}
/* FIXME: I refuse to believe we have to live
* with ugliness like this ... */
LyXText * t = inset.getLyXText(cmd.view());
- t->need_break_row = t->firstRow();
+ t->need_break_row = &*t->rows().begin();
t->fullRebreak();
inset.update(cmd.view(), true);
t->setCursorIntern(t->cursor.par(), t->cursor.pos());
int InsetText::ascent(BufferView * bv, LyXFont const &) const
{
- insetAscent = getLyXText(bv)->firstRow()->ascent_of_text() +
+ insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() +
TEXT_TO_INSET_OFFSET;
return insetAscent;
}
int InsetText::descent(BufferView * bv, LyXFont const &) const
{
LyXText * llt = getLyXText(bv);
- insetDescent = llt->height - llt->firstRow()->ascent_of_text() +
+ insetDescent = llt->height - llt->rows().begin()->ascent_of_text() +
TEXT_TO_INSET_OFFSET;
return insetDescent;
}
}
x += TEXT_TO_INSET_OFFSET;
- Row * row = lt->firstRow();
- int y_offset = baseline - row->ascent_of_text();
+ RowList::iterator rowit = lt->rows().begin();
+ RowList::iterator end = lt->rows().end();
+
+ int y_offset = baseline - rowit->ascent_of_text();
int ph = pain.paperHeight();
int first = 0;
int y = y_offset;
- while ((row != 0) && ((y+row->height()) <= 0)) {
- y += row->height();
- first += row->height();
- row = row->next();
+ while ((rowit != end) && ((y + rowit->height()) <= 0)) {
+ y += rowit->height();
+ first += rowit->height();
+ ++rowit;
}
if (y_offset < 0) {
lt->top_y(-y_offset);
int yf = y_offset + first;
y = 0;
- while ((row != 0) && (yf < ph)) {
- RowPainter rp(*bv, *lt, *row);
+ while ((rowit != end) && (yf < ph)) {
+ RowPainter rp(*bv, *lt, *rowit);
rp.paint(y + y_offset + first, int(x), y + lt->top_y());
- y += row->height();
- yf += row->height();
- row = row->next();
+ y += rowit->height();
+ yf += rowit->height();
+ ++rowit;
}
lt->clearPaint();
if (recursive && the_locking_inset)
return the_locking_inset->getLyXText(lbv, true);
LyXText * lt = cached_text.get();
- lyx::Assert(lt && lt->firstRow()->par() == &*(paragraphs.begin()));
+ lyx::Assert(lt && lt->rows().begin()->par() == &*(paragraphs.begin()));
return lt;
}
// Super UGLY! (Lgb)
int x = top_x + TEXT_TO_INSET_OFFSET;
- Row * row = lt->firstRow();
- int y_offset = top_baseline - row->ascent_of_text();
+ RowList::iterator rowit = lt->rows().begin();
+ RowList::iterator end = lt->rows().end();
+ int y_offset = top_baseline - rowit->ascent_of_text();
int y = y_offset;
- while ((row != 0) && ((y+row->height()) <= 0)) {
- y += row->height();
- row = row->next();
+ while ((rowit != end) && ((y + rowit->height()) <= 0)) {
+ y += rowit->height();
+ ++rowit;
}
if (y_offset < 0)
y_offset = y;
{}
+Row::Row(Paragraph * pa, pos_type po)
+ : par_(pa), pos_(po), fill_(0), height_(0), width_(0),
+ ascent_of_text_(0), baseline_(0), next_(0), previous_(0)
+{}
+
+
Paragraph * Row::par()
{
return par_;
public:
///
Row();
-
+ ///
+ Row(Paragraph * pa, lyx::pos_type po);
///
void par(Paragraph * p);
///
of the row
*/
Row * getRow(Paragraph * par, lyx::pos_type pos, int & y) const;
- /** returns the firstrow, this could be done with the above too but
- IMO it's stupid to have to allocate a dummy y all the time I need
- the first row
- */
- Row * firstRow() const { return &*rowlist_.begin(); }
- Row * lastRow() const { return &const_cast<LyXText*>(this)->rowlist_.back(); }
+
+ RowList & rows() {
+ return rowlist_;
+ }
+ RowList const & rows() const {
+ return rowlist_;
+ }
+
/** 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
*/
string copylayouttype;
- /** inserts a new row behind the specified row, increments
- the touched counters */
- RowList::iterator
- insertRow(RowList::iterator rowit,
- Paragraph * par, lyx::pos_type pos);
/// removes the row and reset the touched counters
void removeRow(Row * row);
return 0;
int y = 0;
- for (Row * row = firstRow();
- row && row != anchor_row_; row = row->next()) {
- y += row->height();
+
+ RowList::iterator rit = rows().begin();
+ RowList::iterator end = rows().end();
+ for (; rit != end && rit != anchor_row_; ++rit) {
+ y += rit->height();
}
return y + anchor_row_offset_;
}
void LyXText::top_y(int newy)
{
- if (!firstRow())
+ if (rows().empty())
return;
lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
return LColor::background;
}
+
void LyXText::setHeightOfRow(Row * row)
{
// get the maximum ascent and the maximum descent
}
row->width(int(maxwidth + x));
if (inset_owner) {
- Row * r = firstRow();
width = max(0, workWidth());
- while (r) {
- if (r->width() > width)
- width = r->width();
- r = r->next();
+ RowList::iterator rit = rows().begin();
+ RowList::iterator end = rows().end();
+ for (; rit != end; ++rit) {
+ if (rit->width() > width)
+ width = rit->width();
}
}
}
if (z < last) {
++z;
- rowit = insertRow(rowit, rowit->par(), z);
+ rowit = rowlist_.insert(rowit->next(),
+ new Row(rowit->par(), z));
} else {
done = true;
}
if (!row->next() || (row->next() && row->next()->par() != row->par())) {
// insert a new row
++z;
- insertRow(row, row->par(), z);
+ rowlist_.insert(row->next(), new Row(row->par(), z));
row = row->next();
} else {
row = row->next();
|| (row->next() && row->next()->par() != row->par())) {
// insert a new row
++z;
- insertRow(row, row->par(), z);
+ rowlist_.insert(row->next(), new Row(row->par(), z));
row = row->next();
} else {
row = row->next();
&& cursor.par()->next()->isNewline(0))
cursor.par()->next()->erase(0);
- insertParagraph(cursor.par()->next(), cursor.row());
+ insertParagraph(cursor.par()->next(), cursor.row()->next());
updateCounters();
// This check is necessary. Otherwise the new empty paragraph will
// returns pointer to a specified row
Row * LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
{
- if (!firstRow())
+ if (rows().empty())
return 0;
- Row * tmprow = firstRow();
y = 0;
// find the first row of the specified paragraph
- while (tmprow->next() && tmprow->par() != par) {
- y += tmprow->height();
- tmprow = tmprow->next();
+ RowList::iterator rit = rows().begin();
+ RowList::iterator end = rows().end();
+ while (boost::next(rit) != end && rit->par() != par) {
+ y += rit->height();
+ ++rit;
}
// now find the wanted row
- while (tmprow->pos() < pos
- && tmprow->next()
- && tmprow->next()->par() == par
- && tmprow->next()->pos() <= pos) {
- y += tmprow->height();
- tmprow = tmprow->next();
+ while (rit->pos() < pos
+ && boost::next(rit) != end
+ && boost::next(rit)->par() == par
+ && boost::next(rit)->pos() <= pos) {
+ y += rit->height();
+ ++rit;
}
- return tmprow;
+ return &*rit;
}
Row * LyXText::getRowNearY(int & y) const
{
-#if 1
// If possible we should optimize this method. (Lgb)
- Row * tmprow = firstRow();
int tmpy = 0;
- while (tmprow->next() && tmpy + tmprow->height() <= y) {
- tmpy += tmprow->height();
- tmprow = tmprow->next();
+ RowList::iterator rit = rows().begin();
+ RowList::iterator end = rows().end();
+
+ while (boost::next(rit) != end && tmpy + rit->height() <= y) {
+ tmpy += rit->height();
+ ++rit;
}
y = tmpy; // return the real y
//lyxerr << "returned y = " << y << endl;
- return tmprow;
-#else
- // Search from the current cursor position.
-
- Row * tmprow = cursor.row();
- int tmpy = cursor.y() - tmprow->baseline();
-
- lyxerr << "cursor.y() = " << tmpy << endl;
- lyxerr << "tmprow->height() = " << tmprow->height() << endl;
- lyxerr << "tmprow->baseline() = " << tmprow->baseline() << endl;
- lyxerr << "first = " << first << endl;
- lyxerr << "y = " << y << endl;
-
- if (y < tmpy) {
- lyxerr << "up" << endl;
- do {
- tmpy -= tmprow->height();
- tmprow = tmprow->previous();
- } while (tmprow && tmpy - tmprow->height() >= y);
- } else if (y > tmpy) {
- lyxerr << "down" << endl;
-
- while (tmprow->next() && tmpy + tmprow->height() <= y) {
- tmpy += tmprow->height();
- tmprow = tmprow->next();
- }
- } else {
- lyxerr << "equal" << endl;
- }
-
- y = tmpy; // return the real y
-
- lyxerr << "returned y = " << y << endl;
-
- return tmprow;
-
-#endif
+ return &*rit;
}
copylayouttype.erase();
top_y(0);
clearPaint();
- } else if (firstRow())
+ } else if (!rowlist_.empty())
return;
Paragraph * par = ownerParagraph();
current_font = getFont(bview->buffer(), par, 0);
while (par) {
- if (rowlist_.empty())
- insertParagraph(par, rowlist_.end());
- else
- insertParagraph(par, lastRow());
+ insertParagraph(par, rowlist_.end());
par = par->next();
}
- setCursorIntern(firstRow()->par(), 0);
+ setCursorIntern(rowlist_.begin()->par(), 0);
selection.cursor = cursor;
updateCounters();
}
-// inserts a new row before the specified row, increments
-// the touched counters
-RowList::iterator
- LyXText::insertRow(RowList::iterator rowit, Paragraph * par,
- pos_type pos)
-{
- Row * tmprow = new Row;
- tmprow->par(par);
- tmprow->pos(pos);
-
- if (rowit == rowlist_.end())
- return rowlist_.insert(rowlist_.begin(), tmprow);
- else
- return rowlist_.insert(boost::next(rowit), tmprow);
-}
-
-
// removes the row and reset the touched counters
void LyXText::removeRow(Row * row)
{
void LyXText::insertParagraph(Paragraph * par, RowList::iterator rowit)
{
// insert a new row, starting at position 0
- RowList::iterator rit = insertRow(rowit, par, 0);
+ RowList::iterator rit = rowlist_.insert(rowit, new Row(par, 0));
// and now append the whole paragraph before the new row
appendParagraph(rit);
tmppar = first_phys_par;
do {
if (tmppar) {
- insertParagraph(tmppar, tmprow);
+ if (!tmprow) {
+ insertParagraph(tmppar, rowlist_.begin());
+ } else {
+ insertParagraph(tmppar, tmprow->next());
+ }
+
if (!tmprow) {
- tmprow = firstRow();
+ tmprow = &*rows().begin();
}
while (tmprow->next()
&& tmprow->next()->par() == tmppar) {
setHeightOfRow(prevrow);
const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
} else {
- setHeightOfRow(firstRow());
+ setHeightOfRow(&*rows().begin());
const_cast<LyXText *>(this)->postPaint(0);
}
void LyXText::fullRebreak()
{
- if (!firstRow()) {
+ if (rows().empty()) {
init(bv());
return;
}
// Updates all counters. Paragraphs with changed label string will be rebroken
void LyXText::updateCounters()
{
- Row * row = firstRow();
- Paragraph * par = row->par();
+ RowList::iterator rowit = rows().begin();
+ Paragraph * par = rowit->par();
// CHECK if this is really needed. (Lgb)
bv()->buffer()->params.getLyXTextClass().counters().reset();
while (par) {
- while (row->par() != par)
- row = row->next();
+ while (rowit->par() != par)
+ ++rowit;
string const oldLabel = par->params().labelString();
string const & newLabel = par->params().labelString();
if (oldLabel.empty() && !newLabel.empty()) {
- removeParagraph(row);
- appendParagraph(row);
+ removeParagraph(&*rowit);
+ appendParagraph(rowit);
}
par = par->next();