// This method requires a previous call to ComputeBidiTables()
-bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
+bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
pos_type pos) const
{
if (!lyxrc.rtl_support || pos == 0)
bool const rtl = bidi_level(pos - 1) % 2;
bool const rtl2 = bidi_InRange(pos)
? bidi_level(pos) % 2
- : par->isRightToLeftPar(buf->params);
+ : par.isRightToLeftPar(buf->params);
return rtl != rtl2;
}
-bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
+bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
pos_type pos, LyXFont const & font) const
{
if (!lyxrc.rtl_support)
bool const rtl = font.isVisibleRightToLeft();
bool const rtl2 = bidi_InRange(pos)
? bidi_level(pos) % 2
- : par->isRightToLeftPar(buf->params);
+ : par.isRightToLeftPar(buf->params);
return rtl != rtl2;
}
if (!row.par()->getDepth()) {
if (row.par()->layout() == tclass.defaultLayout()) {
// find the previous same level paragraph
- if (row.par()->previous()) {
+ if (row.par() != ownerParagraphs().begin()) {
Paragraph * newpar = row.par()
->depthHook(row.par()->getDepth());
if (newpar &&
x += len.inPixels(tw);
}
- LyXAlignment align; // wrong type
+ LyXAlignment align;
if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
align = layout->align;
namespace {
// this needs special handling - only newlines count as a break point
-pos_type addressBreakPoint(pos_type i, Paragraph * par)
+pos_type addressBreakPoint(pos_type i, Paragraph const & par)
{
- for (; i < par->size(); ++i) {
- if (par->isNewline(i))
+ for (; i < par.size(); ++i) {
+ if (par.isNewline(i))
return i;
}
- return par->size();
+ return par.size();
}
};
LyXLayout_ptr const & layout = pit->layout();
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
- return addressBreakPoint(row.pos(), &*pit);
+ return addressBreakPoint(row.pos(), *pit);
pos_type const pos = row.pos();
pos_type const body_pos = pit->beginningOfBody();
{
if (layout->isParagraph()
&& firstpit->getDepth() == 0
- && firstpit->previous())
+ && firstpit != ownerParagraphs().begin())
{
maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
- } else if (firstpit->previous() &&
- firstpit->previous()->layout()->isParagraph() &&
- firstpit->previous()->getDepth() == 0)
+ } else if (firstpit != ownerParagraphs().begin() &&
+ boost::prior(firstpit)->layout()->isParagraph() &&
+ boost::prior(firstpit)->getDepth() == 0)
{
// is it right to use defskip here too? (AS)
maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
}
// the top margin
- if (!rit->par()->previous() && !isInInset())
+ if (rit->par() == ownerParagraphs().begin() && !isInInset())
maxasc += PAPER_MARGIN;
// add the vertical spaces, that the user added
if (prev) {
maxasc += int(prev->layout()->parsep * defaultRowHeight());
} else {
- if (firstpit->previous() &&
- firstpit->previous()->getDepth() == 0 &&
- firstpit->previous()->layout() !=
+ if (firstpit != ownerParagraphs().begin() &&
+ boost::prior(firstpit)->getDepth() == 0 &&
+ boost::prior(firstpit)->layout() !=
firstpit->layout())
{
// avoid parsep
- } else if (firstpit->previous()) {
+ } else if (firstpit != ownerParagraphs().begin()) {
maxasc += int(layout->parsep * defaultRowHeight());
}
}
// This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user!
if (cursor.pos() || isempty)
- setCursor(cursor.par()->next(), 0);
+ setCursor(boost::next(cursor.par()), 0);
else
setCursor(cursor.par(), 0);
void LyXText::redoParagraph()
{
clearSelection();
- redoParagraphs(cursor, cursor.par()->next());
+ redoParagraphs(cursor, boost::next(cursor.par()));
setCursorIntern(cursor.par(), cursor.pos());
}
setCursor(cursor.par(), cursor.pos() + 1, false,
cursor.boundary());
- if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
+ if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
!= cursor.boundary())
setCursor(cursor.par(), cursor.pos(), false,
!cursor.boundary());
|| cur.par()->isHfill(cur.pos() - 1))) {
cur.pos(cur.pos() - 1);
} else if (!cur.pos()) {
- if (cur.par()->previous()) {
- cur.par(cur.par()->previous());
+ if (cur.par() != ownerParagraphs().begin()) {
+ cur.par(boost::prior(cur.par()));
cur.pos(cur.par()->size());
}
} else { // Here, cur != 0
startc.par()->acceptChange(startc.pos(), endc.pos());
finishUndo();
clearSelection();
- redoParagraphs(startc, startc.par()->next());
+ redoParagraphs(startc, boost::next(startc.par()));
setCursorIntern(startc.par(), 0);
}
#warning handle multi par selection
// If this is not the very first word, skip rest of
// current word because we are probably in the middle
// of a word if there is text here.
- if (cursor.pos() || cursor.par()->previous()) {
+ if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
while (cursor.pos() < cursor.par()->size()
&& cursor.par()->isLetter(cursor.pos()))
cursor.pos(cursor.pos() + 1);
LyXCursor old_cursor = cursor;
int const old_cur_par_id = old_cursor.par()->id();
- int const old_cur_par_prev_id = old_cursor.par()->previous() ?
- old_cursor.par()->previous()->id() : -1;
+ int const old_cur_par_prev_id =
+ (old_cursor.par() != ownerParagraphs().begin() ?
+ boost::prior(old_cursor.par())->id() : -1);
// just move to the right
cursorRight(bv());
// and that can very well delete the par or par->previous in
// old_cursor. Will a solution where we compare paragraph id's
//work better?
- if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
+ if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
== old_cur_par_prev_id
&& cursor.par()->id() != old_cur_par_id) {
// delete-empty-paragraph-mechanism has done it
// left and let the DeleteEmptyParagraphMechanism handle the actual deletion
// of the paragraph.
- if (cursor.par()->previous()) {
- Paragraph * tmppar = cursor.par()->previous();
- if (cursor.par()->layout() == tmppar->layout()
- && cursor.par()->getAlign() == tmppar->getAlign()) {
+ if (cursor.par() != ownerParagraphs().begin()) {
+ ParagraphList::iterator tmppit = boost::prior(cursor.par());
+ if (cursor.par()->layout() == tmppit->layout()
+ && cursor.par()->getAlign() == tmppit->getAlign()) {
// Inherit bottom DTD from the paragraph below.
// (the one we are deleting)
- tmppar->params().lineBottom(cursor.par()->params().lineBottom());
- tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
- tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
+ tmppit->params().lineBottom(cursor.par()->params().lineBottom());
+ tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
+ tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
}
cursorLeft(bv());
}
}
- if (cursor.par()->previous()) {
+ if (cursor.par() != ownerParagraphs().begin()) {
setUndo(bv(), Undo::DELETE,
- cursor.par()->previous(), cursor.par()->next());
+ &*boost::prior(cursor.par()),
+ &*boost::next(cursor.par()));
}
ParagraphList::iterator tmppit = cursor.par();
// current_font = rawtmpfont;
// real_current_font = realtmpfont;
- if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
+ if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
!= cursor.boundary())
setCursor(cursor.par(), cursor.pos(), false,
!cursor.boundary());
void LyXText::cursorTop()
{
- while (cursor.par()->previous())
- cursor.par(cursor.par()->previous());
- setCursor(cursor.par(), 0);
+ setCursor(ownerParagraphs().begin(), 0);
}
void LyXText::cursorBottom()
{
- while (cursor.par()->next())
- cursor.par(cursor.par()->next());
- setCursor(cursor.par(), cursor.par()->size());
+#warning FIXME
+ // This is how it should be:
+ // ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
+ ParagraphList::iterator lastpit = &ownerParagraphs().back();
+ int pos = lastpit->size();
+ setCursor(lastpit, pos);
}
}
// make sure that the depth behind the selection are restored, too
- Paragraph * endpar = selection.end.par()->next();
- Paragraph * undoendpar = endpar;
-
- if (endpar && endpar->getDepth()) {
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
- undoendpar = endpar;
+ ParagraphList::iterator endpit = boost::next(selection.end.par());
+ ParagraphList::iterator undoendpit = endpit;
+
+ if (endpit != ownerParagraphs().end() && endpit->getDepth()) {
+ while (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ ++endpit;
+ undoendpit = endpit;
}
}
- else if (endpar) {
+ else if (endpit != ownerParagraphs().end()) {
// because of parindents etc.
- endpar = endpar->next();
+ ++endpit;
}
- setUndo(bv(), Undo::EDIT, &*selection.start.par(), undoendpar);
+ setUndo(bv(), Undo::EDIT, &*selection.start.par(), &*undoendpit);
ParagraphList::iterator tmppit = selection.end.par();
tmppit = boost::prior(cursor.par());
}
- redoParagraphs(selection.start, endpar);
+ redoParagraphs(selection.start, endpit);
clearSelection();
setCursor(selection.start.par(), selection.start.pos());
real_current_font = getFont(bv()->buffer(), cursor.par(), pos);
if (cursor.pos() == cursor.par()->size() &&
- isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()) &&
+ isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()) &&
!cursor.boundary()) {
Language const * lang =
cursor.par()->getParLanguage(bv()->buffer()->params);
bool const rtl = (bidi_level(c) % 2 == 1);
if (left_side == rtl) {
++c;
- boundary = isBoundary(bv()->buffer(), &*rit->par(), c);
+ boundary = isBoundary(bv()->buffer(), *rit->par(), c);
}
}
bool boundary = cursor.boundary();
setCursor(cursor.par(), cursor.pos() - 1, true, false);
if (!internal && !boundary &&
- isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos() + 1))
+ isBoundary(bv()->buffer(), *cursor.par(), cursor.pos() + 1))
setCursor(cursor.par(), cursor.pos() + 1, true, true);
- } else if (cursor.par()->previous()) { // steps into the above paragraph.
- Paragraph * par = cursor.par()->previous();
- setCursor(par, par->size());
+ } else if (cursor.par() != ownerParagraphs().begin()) { // steps into the above paragraph.
+ ParagraphList::iterator pit = boost::prior(cursor.par());
+ setCursor(pit, pit->size());
}
}
else if (!at_end) {
setCursor(cursor.par(), cursor.pos() + 1, true, false);
if (!internal &&
- isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()))
+ isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
setCursor(cursor.par(), cursor.pos(), true, true);
} else if (cursor.par()->next())
setCursor(cursor.par()->next(), 0);
if (cursor.pos() > 0) {
setCursor(cursor.par(), 0);
}
- else if (cursor.par()->previous()) {
- setCursor(cursor.par()->previous(), 0);
+ else if (cursor.par() != ownerParagraphs().begin()) {
+ setCursor(boost::prior(cursor.par()), 0);
}
}
}
// don't delete anything if this is the ONLY paragraph!
- if (!old_cursor.par()->next() && !old_cursor.par()->previous())
+ if (ownerParagraphs().size() == 1)
return false;
// Do not delete empty paragraphs with keepempty set.
// we can't possibly have deleted a paragraph before this point
bool deleted = false;
- if ((old_cursor.par()->empty()
- || (old_cursor.par()->size() == 1
- && old_cursor.par()->isLineSeparator(0)))) {
+ if (old_cursor.par()->empty() ||
+ (old_cursor.par()->size() == 1 &&
+ old_cursor.par()->isLineSeparator(0))) {
// ok, we will delete anything
LyXCursor tmpcursor;
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next();
-#warning FIXME This if clause looks very redundant. (Lgb)
- if (endpar && endpar->getDepth()) {
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
- }
+ while (endpar && endpar->getDepth()) {
+ endpar = endpar->next();
}
+
setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
cursor = tmpcursor;
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next();
- if (endpar && endpar->getDepth()) {
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
- }
+ while (endpar && endpar->getDepth()) {
+ endpar = endpar->next();
}
+
setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
cursor = tmpcursor;