}
-void LyXText::anchor_row(Row * row)
+void LyXText::anchor_row(RowList::iterator rit)
{
int old_y = top_y();
anchor_row_offset_ = 0;
- anchor_row_ = row;
+ anchor_row_ = rit;
anchor_row_offset_ = old_y - top_y();
lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
<< &*anchor_row_ << " offset: " << anchor_row_offset_
}
-void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
+void LyXText::computeBidiTables(Buffer const * buf,
+ Row const & row) const
{
bidi_same_direction = true;
if (!lyxrc.rtl_support) {
return;
}
- Inset * inset = row->par()->inInset();
+ Inset * inset = row.par()->inInset();
if (inset && inset->owner() &&
inset->owner()->lyxCode() == Inset::ERT_CODE) {
bidi_start = -1;
return;
}
- bidi_start = row->pos();
- bidi_end = row->lastPrintablePos();
+ bidi_start = row.pos();
+ bidi_end = row.lastPrintablePos();
if (bidi_start > bidi_end) {
bidi_start = -1;
pos_type stack[2];
bool const rtl_par =
- row->par()->isRightToLeftPar(buf->params);
+ row.par()->isRightToLeftPar(buf->params);
int level = 0;
bool rtl = false;
bool rtl0 = false;
- pos_type const body_pos = row->par()->beginningOfBody();
+ pos_type const body_pos = row.par()->beginningOfBody();
for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
- bool is_space = row->par()->isLineSeparator(lpos);
+ bool is_space = row.par()->isLineSeparator(lpos);
pos_type const pos =
(is_space && lpos + 1 <= bidi_end &&
- !row->par()->isLineSeparator(lpos + 1) &&
- !row->par()->isNewline(lpos + 1))
+ !row.par()->isLineSeparator(lpos + 1) &&
+ !row.par()->isNewline(lpos + 1))
? lpos + 1 : lpos;
- LyXFont font = row->par()->getFontSettings(buf->params, pos);
+ LyXFont font = row.par()->getFontSettings(buf->params, pos);
if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
font.number() == LyXFont::ON &&
- row->par()->getFontSettings(buf->params, lpos - 1).number()
+ row.par()->getFontSettings(buf->params, lpos - 1).number()
== LyXFont::ON) {
- font = row->par()->getFontSettings(buf->params, lpos);
+ font = row.par()->getFontSettings(buf->params, lpos);
is_space = false;
}
int new_level;
if (lpos == body_pos - 1
- && row->pos() < body_pos - 1
+ && row.pos() < body_pos - 1
&& is_space) {
new_level = (rtl_par) ? 1 : 0;
new_rtl = new_rtl0 = rtl_par;
}
-int LyXText::leftMargin(Row const * row) const
+int LyXText::leftMargin(RowList::iterator rit) const
{
Inset * ins;
- if (row->pos() < row->par()->size())
- if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
- (ins = row->par()->getInset(row->pos())) &&
+ if (rit->pos() < rit->par()->size())
+ if ((rit->par()->getChar(rit->pos()) == Paragraph::META_INSET) &&
+ (ins = rit->par()->getInset(rit->pos())) &&
(ins->needFullRow() || ins->display()))
return LEFT_MARGIN;
LyXTextClass const & tclass =
bv()->buffer()->params.getLyXTextClass();
- LyXLayout_ptr const & layout = row->par()->layout();
+ LyXLayout_ptr const & layout = rit->par()->layout();
string parindent = layout->parindent;
// this is the way, LyX handles the LaTeX-Environments.
// I have had this idea very late, so it seems to be a
// later added hack and this is true
- if (!row->par()->getDepth()) {
- if (row->par()->layout() == tclass.defaultLayout()) {
+ if (!rit->par()->getDepth()) {
+ if (rit->par()->layout() == tclass.defaultLayout()) {
// find the previous same level paragraph
- if (row->par()->previous()) {
- Paragraph * newpar = row->par()
- ->depthHook(row->par()->getDepth());
+ if (rit->par()->previous()) {
+ Paragraph * newpar = rit->par()
+ ->depthHook(rit->par()->getDepth());
if (newpar &&
newpar->layout()->nextnoindent)
parindent.erase();
} else {
// find the next level paragraph
- Paragraph * newpar = row->par()->outerHook();
+ Paragraph * newpar = rit->par()->outerHook();
// make a corresponding row. Needed to call LeftMargin()
// is used to clear impossible depths after changing
// a layout. Since there is always a redo,
// LeftMargin() is always called
- row->par()->params().depth(0);
+ rit->par()->params().depth(0);
}
- if (newpar && row->par()->layout() == tclass.defaultLayout()) {
+ if (newpar && rit->par()->layout() == tclass.defaultLayout()) {
if (newpar->params().noindent())
parindent.erase();
else {
}
}
- LyXFont const labelfont = getLabelFont(bv()->buffer(), row->par());
+ LyXFont const labelfont = getLabelFont(bv()->buffer(), rit->par());
switch (layout->margintype) {
case MARGIN_DYNAMIC:
if (!layout->leftmargin.empty()) {
x += font_metrics::signedWidth(layout->leftmargin,
tclass.defaultfont());
}
- if (!row->par()->getLabelstring().empty()) {
+ if (!rit->par()->getLabelstring().empty()) {
x += font_metrics::signedWidth(layout->labelindent,
labelfont);
- x += font_metrics::width(row->par()->getLabelstring(),
+ x += font_metrics::width(rit->par()->getLabelstring(),
labelfont);
x += font_metrics::width(layout->labelsep, labelfont);
}
case MARGIN_MANUAL:
x += font_metrics::signedWidth(layout->labelindent, labelfont);
// The width of an empty par, even with manual label, should be 0
- if (!row->par()->empty() && row->pos() >= row->par()->beginningOfBody()) {
- if (!row->par()->getLabelWidthString().empty()) {
- x += font_metrics::width(row->par()->getLabelWidthString(),
+ if (!rit->par()->empty() && rit->pos() >= rit->par()->beginningOfBody()) {
+ if (!rit->par()->getLabelWidthString().empty()) {
+ x += font_metrics::width(rit->par()->getLabelWidthString(),
labelfont);
x += font_metrics::width(layout->labelsep, labelfont);
}
break;
case MARGIN_STATIC:
x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
- / (row->par()->getDepth() + 4);
+ / (rit->par()->getDepth() + 4);
break;
case MARGIN_FIRST_DYNAMIC:
if (layout->labeltype == LABEL_MANUAL) {
- if (row->pos() >= row->par()->beginningOfBody()) {
+ if (rit->pos() >= rit->par()->beginningOfBody()) {
x += font_metrics::signedWidth(layout->leftmargin,
labelfont);
} else {
x += font_metrics::signedWidth(layout->labelindent,
labelfont);
}
- } else if (row->pos()
+ } else if (rit->pos()
// Special case to fix problems with
// theorems (JMarc)
|| (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT
- && ! row->par()->isFirstInSequence())) {
+ && ! rit->par()->isFirstInSequence())) {
x += font_metrics::signedWidth(layout->leftmargin,
labelfont);
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
x += font_metrics::signedWidth(layout->labelindent,
labelfont);
x += font_metrics::width(layout->labelsep, labelfont);
- x += font_metrics::width(row->par()->getLabelstring(),
+ x += font_metrics::width(rit->par()->getLabelstring(),
labelfont);
}
break;
// are *NOT* allowed in the LaTeX realisation of this layout.
// find the first row of this paragraph
- Row const * tmprow = row;
- while (tmprow->previous()
- && tmprow->previous()->par() == row->par())
- tmprow = tmprow->previous();
+ RowList::iterator tmprit = rit;
+ while (tmprit != rows().begin()
+ && boost::prior(tmprit)->par() == rit->par())
+ --tmprit;
- int minfill = tmprow->fill();
- while (tmprow->next() && tmprow->next()->par() == row->par()) {
- tmprow = tmprow->next();
- if (tmprow->fill() < minfill)
- minfill = tmprow->fill();
+ int minfill = tmprit->fill();
+ while (boost::next(tmprit) != rows().end() &&
+ boost::next(tmprit)->par() == rit->par()) {
+ ++tmprit;
+ if (tmprit->fill() < minfill)
+ minfill = tmprit->fill();
}
x += font_metrics::signedWidth(layout->leftmargin,
}
if ((workWidth() > 0) &&
- !row->par()->params().leftIndent().zero())
+ !rit->par()->params().leftIndent().zero())
{
- LyXLength const len = row->par()->params().leftIndent();
+ LyXLength const len = rit->par()->params().leftIndent();
int const tw = inset_owner ?
inset_owner->latexTextWidth(bv()) : workWidth();
x += len.inPixels(tw);
LyXAlignment align; // wrong type
- if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
+ if (rit->par()->params().align() == LYX_ALIGN_LAYOUT)
align = layout->align;
else
- align = row->par()->params().align();
+ align = rit->par()->params().align();
// set the correct parindent
- if (row->pos() == 0) {
+ if (rit->pos() == 0) {
if ((layout->labeltype == LABEL_NO_LABEL
|| layout->labeltype == LABEL_TOP_ENVIRONMENT
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|| (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT
- && ! row->par()->isFirstInSequence()))
+ && ! rit->par()->isFirstInSequence()))
&& align == LYX_ALIGN_BLOCK
- && !row->par()->params().noindent()
+ && !rit->par()->params().noindent()
// in tabulars and ert paragraphs are never indented!
- && (!row->par()->inInset() || !row->par()->inInset()->owner() ||
- (row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
- row->par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
- && (row->par()->layout() != tclass.defaultLayout() ||
+ && (!rit->par()->inInset() || !rit->par()->inInset()->owner() ||
+ (rit->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
+ rit->par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
+ && (rit->par()->layout() != tclass.defaultLayout() ||
bv()->buffer()->params.paragraph_separation ==
BufferParams::PARSEP_INDENT)) {
x += font_metrics::signedWidth(parindent,
if (row.pos() < row.par()->size())
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
- (ins=row.par()->getInset(row.pos())) &&
+ (ins = row.par()->getInset(row.pos())) &&
(ins->needFullRow() || ins->display()))
return PAPER_MARGIN;
// or the end of the par, then choose the possible break
// nearest that.
- int const left = leftMargin(&row);
+ int const left = leftMargin(const_cast<Row*>(&row));
int x = left;
// pixel width since last breakpoint
float dummy;
// this IS needed
rit->width(maxwidth);
- prepareToPrint(&*rit, x, dummy, dummy, dummy, false);
+ prepareToPrint(rit, x, dummy, dummy, dummy, false);
}
rit->width(int(maxwidth + x));
if (inset_owner) {
// this is just a little changed version of break again
-void LyXText::breakAgainOneRow(Row * row)
+void LyXText::breakAgainOneRow(RowList::iterator rit)
{
- lyx::Assert(row);
+ lyx::Assert(rit != rows().end());
- pos_type z = rowBreakPoint(*row);
- Row * tmprow = row;
+ pos_type z = rowBreakPoint(*rit);
+ RowList::iterator tmprit = rit;
- if (z < row->par()->size()) {
- if (!row->next()
- || (row->next() && row->next()->par() != row->par())) {
+ if (z < rit->par()->size()) {
+ if (boost::next(rit) == rows().end()
+ || (boost::next(rit) != rows().end() && boost::next(rit)->par() != rit->par())) {
// insert a new row
++z;
- rowlist_.insert(row->next(), new Row(row->par(), z));
- row = row->next();
+ rit = rowlist_.insert(boost::next(rit), new Row(rit->par(), z));
} else {
- row = row->next();
+ ++rit;
++z;
- if (row->pos() != z)
- row->pos(z);
+ if (rit->pos() != z)
+ rit->pos(z);
}
} else {
// if there are some rows too much, delete them
// only if you broke the whole paragraph!
- Row * tmprow2 = row;
- while (tmprow2->next()
- && tmprow2->next()->par() == row->par()) {
- tmprow2 = tmprow2->next();
+ RowList::iterator tmprit2 = rit;
+ while (boost::next(tmprit2) != rows().end()
+ && boost::next(tmprit2)->par() == rit->par()) {
+ ++tmprit2;
}
- while (tmprow2 != row) {
- tmprow2 = tmprow2->previous();
- removeRow(tmprow2->next());
+ while (tmprit2 != rit) {
+ --tmprit2;
+ removeRow(boost::next(tmprit2));
}
}
// set the dimensions of the row
- tmprow->fill(fill(*tmprow, workWidth()));
- setHeightOfRow(tmprow);
+ tmprit->fill(fill(*tmprit, workWidth()));
+ setHeightOfRow(tmprit);
}
}
-void LyXText::prepareToPrint(Row * row, float & x,
+void LyXText::prepareToPrint(RowList::iterator rit, float & x,
float & fill_separator,
float & fill_hfill,
float & fill_label_hfill,
float nlh;
float ns;
- float w = row->fill();
+ float w = rit->fill();
fill_hfill = 0;
fill_label_hfill = 0;
fill_separator = 0;
fill_label_hfill = 0;
bool const is_rtl =
- row->par()->isRightToLeftPar(bv()->buffer()->params);
+ rit->par()->isRightToLeftPar(bv()->buffer()->params);
if (is_rtl) {
x = (workWidth() > 0)
- ? rightMargin(*bv()->buffer(), *row) : 0;
+ ? rightMargin(*bv()->buffer(), *rit) : 0;
} else
x = (workWidth() > 0)
- ? leftMargin(row) : 0;
+ ? leftMargin(rit) : 0;
// is there a manual margin with a manual label
- LyXLayout_ptr const & layout = row->par()->layout();
+ LyXLayout_ptr const & layout = rit->par()->layout();
if (layout->margintype == MARGIN_MANUAL
&& layout->labeltype == LABEL_MANUAL) {
/// We might have real hfills in the label part
- nlh = row->numberOfLabelHfills();
+ nlh = rit->numberOfLabelHfills();
// A manual label par (e.g. List) has an auto-hfill
// between the label text and the body of the
// paragraph too.
// But we don't want to do this auto hfill if the par
// is empty.
- if (!row->par()->empty())
+ if (!rit->par()->empty())
++nlh;
- if (nlh && !row->par()->getLabelWidthString().empty()) {
- fill_label_hfill = labelFill(*row) / nlh;
+ if (nlh && !rit->par()->getLabelWidthString().empty()) {
+ fill_label_hfill = labelFill(*rit) / nlh;
}
}
// are there any hfills in the row?
- float const nh = row->numberOfHfills();
+ float const nh = rit->numberOfHfills();
if (nh) {
if (w > 0)
// we don't have to look at the alignment if it is ALIGN_LEFT and
// if the row is already larger then the permitted width as then
// we force the LEFT_ALIGN'edness!
- } else if (static_cast<int>(row->width()) < workWidth()) {
+ } else if (static_cast<int>(rit->width()) < workWidth()) {
// is it block, flushleft or flushright?
// set x how you need it
int align;
- if (row->par()->params().align() == LYX_ALIGN_LAYOUT) {
+ if (rit->par()->params().align() == LYX_ALIGN_LAYOUT) {
align = layout->align;
} else {
- align = row->par()->params().align();
+ align = rit->par()->params().align();
}
// center displayed insets
Inset * inset;
- if (row->pos() < row->par()->size()
- && row->par()->isInset(row->pos())
- && (inset = row->par()->getInset(row->pos()))
+ if (rit->pos() < rit->par()->size()
+ && rit->par()->isInset(rit->pos())
+ && (inset = rit->par()->getInset(rit->pos()))
&& (inset->display())) // || (inset->scroll() < 0)))
align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
// ERT insets should always be LEFT ALIGNED on screen
- inset = row->par()->inInset();
+ inset = rit->par()->inInset();
if (inset && inset->owner() &&
inset->owner()->lyxCode() == Inset::ERT_CODE)
{
switch (align) {
case LYX_ALIGN_BLOCK:
- ns = row->numberOfSeparators();
- if (ns && row->next() && row->next()->par() == row->par() &&
- !(row->next()->par()->isNewline(row->next()->pos() - 1))
- && !(row->next()->par()->isInset(row->next()->pos())
- && row->next()->par()->getInset(row->next()->pos())
- && row->next()->par()->getInset(row->next()->pos())->display())
+ ns = rit->numberOfSeparators();
+ if (ns && boost::next(rit) != rows().end() &&
+ boost::next(rit)->par() == rit->par() &&
+ !(boost::next(rit)->par()->isNewline(boost::next(rit)->pos() - 1))
+ && !(boost::next(rit)->par()->isInset(boost::next(rit)->pos())
+ && boost::next(rit)->par()->getInset(boost::next(rit)->pos())
+ && boost::next(rit)->par()->getInset(boost::next(rit)->pos())->display())
)
{
fill_separator = w / ns;
if (!bidi)
return;
- computeBidiTables(bv()->buffer(), row);
+ computeBidiTables(bv()->buffer(), *rit);
if (is_rtl) {
- pos_type body_pos = row->par()->beginningOfBody();
- pos_type last = row->lastPos();
+ pos_type body_pos = rit->par()->beginningOfBody();
+ pos_type last = rit->lastPos();
if (body_pos > 0 &&
(body_pos - 1 > last ||
- !row->par()->isLineSeparator(body_pos - 1))) {
+ !rit->par()->isLineSeparator(body_pos - 1))) {
x += font_metrics::width(layout->labelsep,
- getLabelFont(bv()->buffer(), row->par()));
+ getLabelFont(bv()->buffer(), rit->par()));
if (body_pos - 1 <= last)
x += fill_label_hfill;
}
{
y = 0;
- if (rows().empty()) {
+ if (rows().empty())
return rows().end();
- }
// find the first row of the specified paragraph
RowList::iterator rit = rows().begin();
// remove all following rows of the paragraph of the specified row.
-void LyXText::removeParagraph(Row * row)
+void LyXText::removeParagraph(RowList::iterator rit)
{
- Paragraph * tmppar = row->par();
- row = row->next();
+ Paragraph * tmppar = rit->par();
+ ++rit;
- Row * tmprow;
- while (row && row->par() == tmppar) {
- tmprow = row->next();
- removeRow(row);
- row = tmprow;
+ while (rit != rows().end() && rit->par() == tmppar) {
+ RowList::iterator tmprit = boost::next(rit);
+ removeRow(rit);
+ rit = tmprit;
}
}
// returns the column near the specified x-coordinate of the row
// x is set to the real beginning of this column
pos_type
-LyXText::getColumnNearX(Row * row, int & x,
+LyXText::getColumnNearX(RowList::iterator rit, int & x,
bool & boundary) const
{
float tmpx = 0.0;
float fill_hfill;
float fill_label_hfill;
- prepareToPrint(row, tmpx, fill_separator,
+ prepareToPrint(rit, tmpx, fill_separator,
fill_hfill, fill_label_hfill);
- pos_type vc = row->pos();
- pos_type last = row->lastPrintablePos();
+ pos_type vc = rit->pos();
+ pos_type last = rit->lastPrintablePos();
pos_type c = 0;
- LyXLayout_ptr const & layout = row->par()->layout();
+ LyXLayout_ptr const & layout = rit->par()->layout();
bool left_side = false;
- pos_type body_pos = row->par()->beginningOfBody();
+ pos_type body_pos = rit->par()->beginningOfBody();
float last_tmpx = tmpx;
if (body_pos > 0 &&
(body_pos - 1 > last ||
- !row->par()->isLineSeparator(body_pos - 1)))
+ !rit->par()->isLineSeparator(body_pos - 1)))
body_pos = 0;
// check for empty row
- if (!row->par()->size()) {
+ if (!rit->par()->size()) {
x = int(tmpx);
return 0;
}
while (vc <= last && tmpx <= x) {
c = vis2log(vc);
last_tmpx = tmpx;
- if (body_pos > 0 && c == body_pos-1) {
+ if (body_pos > 0 && c == body_pos - 1) {
tmpx += fill_label_hfill +
font_metrics::width(layout->labelsep,
- getLabelFont(bv()->buffer(), row->par()));
- if (row->par()->isLineSeparator(body_pos - 1))
- tmpx -= singleWidth(row->par(), body_pos-1);
+ getLabelFont(bv()->buffer(), rit->par()));
+ if (rit->par()->isLineSeparator(body_pos - 1))
+ tmpx -= singleWidth(rit->par(), body_pos - 1);
}
- if (row->hfillExpansion(c)) {
- tmpx += singleWidth(row->par(), c);
+ if (rit->hfillExpansion(c)) {
+ tmpx += singleWidth(rit->par(), c);
if (c >= body_pos)
tmpx += fill_hfill;
else
tmpx += fill_label_hfill;
- } else if (row->par()->isSeparator(c)) {
- tmpx += singleWidth(row->par(), c);
+ } else if (rit->par()->isSeparator(c)) {
+ tmpx += singleWidth(rit->par(), c);
if (c >= body_pos)
tmpx+= fill_separator;
} else {
- tmpx += singleWidth(row->par(), c);
+ tmpx += singleWidth(rit->par(), c);
}
++vc;
}
boundary = false;
bool const lastrow = lyxrc.rtl_support // This is not needed, but gives
// some speedup if rtl_support=false
- && (!row->next() || row->next()->par() != row->par());
+ && (boost::next(rit) == rows().end() ||
+ boost::next(rit)->par() != rit->par());
bool const rtl = (lastrow)
- ? row->par()->isRightToLeftPar(bv()->buffer()->params)
+ ? rit->par()->isRightToLeftPar(bv()->buffer()->params)
: false; // If lastrow is false, we don't need to compute
// the value of rtl.
if (lastrow &&
- ((rtl && left_side && vc == row->pos() && x < tmpx - 5) ||
+ ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
c = last + 1;
- else if (vc == row->pos()) {
+ else if (vc == rit->pos()) {
c = vis2log(vc);
if (bidi_level(c) % 2 == 1)
++c;
bool const rtl = (bidi_level(c) % 2 == 1);
if (left_side == rtl) {
++c;
- boundary = isBoundary(bv()->buffer(), row->par(), c);
+ boundary = isBoundary(bv()->buffer(), rit->par(), c);
}
}
- if (row->pos() <= last && c > last
- && row->par()->isNewline(last)) {
+ if (rit->pos() <= last && c > last
+ && rit->par()->isNewline(last)) {
if (bidi_level(last) % 2 == 0)
- tmpx -= singleWidth(row->par(), last);
+ tmpx -= singleWidth(rit->par(), last);
else
- tmpx += singleWidth(row->par(), last);
+ tmpx += singleWidth(rit->par(), last);
c = last;
}
- c -= row->pos();
+ c -= rit->pos();
x = int(tmpx);
return c;
}
// FIXME: we should probably remove this y parameter,
// make refresh_y be 0, and use row->y etc.
-void LyXText::postRowPaint(Row * row, int start_y)
+void LyXText::postRowPaint(RowList::iterator rit, int start_y)
{
if (refresh_status_ != REFRESH_NONE && refresh_y < start_y) {
refresh_status_ = REFRESH_AREA;
return;
refresh_status_ = REFRESH_ROW;
- refresh_row = row;
+ refresh_row = rit;
if (!inset_owner)
return;