2003-04-13 Lars Gullik Bjønnes <larsbj@gullik.net>
2003-04-13 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * text.C, text2.C: exchange all usage of Paragraph::next with
+ boost::next(ParagraphList::iterator)
+
+ * CutAndPaste.C (cutSelection): change 2. arg to a Paragraph*
+
* text2.C (cursorTop): simplify implementation
(cursorBottom): ditto
(setParagraph): use ParagraphList::iterator
* text2.C (cursorTop): simplify implementation
(cursorBottom): ditto
(setParagraph): use ParagraphList::iterator
-bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
+bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph * endpar,
int start, int & end, textclass_type tc,
bool doclear, bool realcut)
{
int start, int & end, textclass_type tc,
bool doclear, bool realcut)
{
return false;
if (realcut) {
return false;
if (realcut) {
- copySelection(startpar, *endpar, start, end, tc);
+ copySelection(startpar, endpar, start, end, tc);
- if (!endpar || startpar == *endpar) {
+ if (!endpar || startpar == endpar) {
if (startpar->erase(start, end)) {
// Some chars were erased, go to start to be safe
end = start;
if (startpar->erase(start, end)) {
// Some chars were erased, go to start to be safe
end = start;
// clear end/begin fragments of the first/last par in selection
actually_erased |= (startpar)->erase(start, startpar->size());
// clear end/begin fragments of the first/last par in selection
actually_erased |= (startpar)->erase(start, startpar->size());
- if ((*endpar)->erase(0, end)) {
+ if (endpar->erase(0, end)) {
actually_erased = true;
end = 0;
}
actually_erased = true;
end = 0;
}
Paragraph * next = pit->next();
// "erase" the contents of the par
Paragraph * next = pit->next();
// "erase" the contents of the par
actually_erased |= pit->erase(0, pit->size());
// remove the par if it's now empty
actually_erased |= pit->erase(0, pit->size());
// remove the par if it's now empty
// the insets paragraphs, and not the buffers. (Lgb)
mergeParagraph(buffer->params, buffer->paragraphs, startpar);
// this because endpar gets deleted here!
// the insets paragraphs, and not the buffers. (Lgb)
mergeParagraph(buffer->params, buffer->paragraphs, startpar);
// this because endpar gets deleted here!
namespace CutAndPaste {
/// realcut == false is we actually want a delete
namespace CutAndPaste {
/// realcut == false is we actually want a delete
-bool cutSelection(Paragraph * startpar, Paragraph ** endpar,
+bool cutSelection(Paragraph * startpar, Paragraph * endpar,
int start, int & end, lyx::textclass_type tc,
bool doclear = false, bool realcut = true);
int start, int & end, lyx::textclass_type tc,
bool doclear = false, bool realcut = true);
// a section, or between the items of a itemize or enumerate
// environment
if (!firstpit->params().pagebreakBottom()
// a section, or between the items of a itemize or enumerate
// environment
if (!firstpit->params().pagebreakBottom()
- && rit->par()->next()) {
+ && boost::next(rit->par()) != ownerParagraphs().end()) {
ParagraphList::iterator nextpit = boost::next(rit->par());
ParagraphList::iterator comparepit = rit->par();
float usual = 0;
ParagraphList::iterator nextpit = boost::next(rit->par());
ParagraphList::iterator comparepit = rit->par();
float usual = 0;
cursor.par()->applyLayout(tclass.defaultLayout());
else
// set to standard-layout
cursor.par()->applyLayout(tclass.defaultLayout());
else
// set to standard-layout
- cursor.par()->next()->applyLayout(tclass.defaultLayout());
+ boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
}
// if the cursor is at the beginning of a row without prior newline,
}
// if the cursor is at the beginning of a row without prior newline,
// When ::breakParagraph is called from within an inset we must
// ensure that the correct ParagraphList is used. Today that is not
// the case and the Buffer::paragraphs is used. Not good. (Lgb)
// When ::breakParagraph is called from within an inset we must
// ensure that the correct ParagraphList is used. Today that is not
// the case and the Buffer::paragraphs is used. Not good. (Lgb)
- while (!cursor.par()->next()->empty()
- && cursor.par()->next()->isNewline(0))
- cursor.par()->next()->erase(0);
+ ParagraphList::iterator next_par = boost::next(cursor.par());
- insertParagraph(cursor.par()->next(), boost::next(cursor.row()));
+ while (!next_par->empty() && next_par->isNewline(0))
+ next_par->erase(0);
+
+ insertParagraph(next_par, boost::next(cursor.row()));
updateCounters();
// 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)
updateCounters();
// 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(boost::next(cursor.par()), 0);
+ setCursor(next_par, 0);
else
setCursor(cursor.par(), 0);
else
setCursor(cursor.par(), 0);
// CHECK See comment on top of text.C
if (tmpcursor.pos() == tmpcursor.par()->size()
// CHECK See comment on top of text.C
if (tmpcursor.pos() == tmpcursor.par()->size()
- && tmpcursor.par()->next()) {
- tmpcursor.par(tmpcursor.par()->next());
+ && boost::next(tmpcursor.par()) != ownerParagraphs().end()) {
+ tmpcursor.par(boost::next(tmpcursor.par()));
tmpcursor.pos(0);
} else {
int steps = 0;
tmpcursor.pos(0);
} else {
int steps = 0;
startc.par()->rejectChange(startc.pos(), endc.pos());
finishUndo();
clearSelection();
startc.par()->rejectChange(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
setCursorIntern(startc.par(), 0);
}
#warning handle multi par selection
}
// we have to go on checking so move cursor to the next char
if (cursor.pos() == cursor.par()->size()) {
}
// we have to go on checking so move cursor to the next char
if (cursor.pos() == cursor.par()->size()) {
- if (!cursor.par()->next())
+ if (boost::next(cursor.par()) == ownerParagraphs().end())
- cursor.par(cursor.par()->next());
+ cursor.par(boost::next(cursor.par()));
cursor.pos(0);
} else
cursor.pos(cursor.pos() + 1);
cursor.pos(0);
} else
cursor.pos(cursor.pos() + 1);
LyXCursor & send_cur,
string const & layout)
{
LyXCursor & send_cur,
string const & layout)
{
- Paragraph * endpar = send_cur.par()->next();
- Paragraph * undoendpar = endpar;
+ ParagraphList::iterator endpit = boost::next(send_cur.par());
+ ParagraphList::iterator undoendpit = endpit;
- if (endpar && endpar->getDepth()) {
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
- undoendpar = endpar;
+ if (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ while (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ ++endpit;
+ undoendpit = endpit;
- } else if (endpar) {
- endpar = endpar->next(); // because of parindents etc.
+ } else if (endpit != ownerParagraphs().end()) {
+ // because of parindents etc.
+ ++endpit;
- setUndo(bv(), Undo::EDIT, &*sstart_cur.par(), undoendpar);
+ setUndo(bv(), Undo::EDIT, &*sstart_cur.par(), &*undoendpit);
// ok we have a selection. This is always between sstart_cur
// and sel_end cursor
// ok we have a selection. This is always between sstart_cur
// and sel_end cursor
++pit;
} while (pit != epit);
++pit;
} while (pit != epit);
cursor.pos(cursor.pos() + 1);
} else {
cursor.pos(0);
cursor.pos(cursor.pos() + 1);
} else {
cursor.pos(0);
- cursor.par(cursor.par()->next());
+ cursor.par(boost::next(cursor.par()));
- redoParagraphs(selection.start, selection.end.par()->next());
+ redoParagraphs(selection.start, boost::next(selection.end.par()));
// we have to reset the selection, because the
// geometry could have changed, but we keep
// we have to reset the selection, because the
// geometry could have changed, but we keep
#warning FIXME Why isnt ParagraphList::iterator used here?
// as loop variable.
LyXCursor tmpcur(selection.start);
#warning FIXME Why isnt ParagraphList::iterator used here?
// as loop variable.
LyXCursor tmpcur(selection.start);
- tmpcur.par(tmpcur.par()->next());
+ tmpcur.par(boost::next(tmpcur.par()));
while (tmpcur.par() != endpit) {
result += tmpcur.par()->asString(buffer, 0,
tmpcur.par()->size(),
while (tmpcur.par() != endpit) {
result += tmpcur.par()->asString(buffer, 0,
tmpcur.par()->size(),
// and selection.end
// make sure that the depth behind the selection are restored, too
// and selection.end
// make sure that the depth behind the selection are restored, too
- Paragraph * endpar = selection.end.par()->next();
- Paragraph * undoendpar = endpar;
+ ParagraphList::iterator endpit = boost::next(selection.end.par());
+ ParagraphList::iterator undoendpit = endpit;
- if (endpar && endpar->getDepth()) {
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
- undoendpar = endpar;
+ if (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ while (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ ++endpit;
+ undoendpit = endpit;
- } else if (endpar) {
- endpar = endpar->next(); // because of parindents etc.
+ } else if (endpit != ownerParagraphs().end()) {
+ // because of parindents etc.
+ ++endpit;
- setUndo(bv(), Undo::DELETE,
- &*selection.start.par(), undoendpar);
+ setUndo(bv(), Undo::DELETE, &*selection.start.par(), &*undoendpit);
// there are two cases: cut only within one paragraph or
// more than one paragraph
if (selection.start.par() == selection.end.par()) {
// only within one paragraph
// there are two cases: cut only within one paragraph or
// more than one paragraph
if (selection.start.par() == selection.end.par()) {
// only within one paragraph
- endpar = &*selection.end.par();
+ endpit = selection.end.par();
int pos = selection.end.pos();
int pos = selection.end.pos();
- CutAndPaste::cutSelection(&*selection.start.par(), &endpar,
+ CutAndPaste::cutSelection(&*selection.start.par(), &*endpit,
selection.start.pos(), pos,
bv()->buffer()->params.textclass,
doclear, realcut);
selection.end.pos(pos);
} else {
selection.start.pos(), pos,
bv()->buffer()->params.textclass,
doclear, realcut);
selection.end.pos(pos);
} else {
- endpar = &*selection.end.par();
+ endpit = selection.end.par();
int pos = selection.end.pos();
int pos = selection.end.pos();
- CutAndPaste::cutSelection(&*selection.start.par(), &endpar,
+ CutAndPaste::cutSelection(&*selection.start.par(), &*endpit,
selection.start.pos(), pos,
bv()->buffer()->params.textclass,
doclear, realcut);
selection.start.pos(), pos,
bv()->buffer()->params.textclass,
doclear, realcut);
- cursor.par(endpar);
- selection.end.par(endpar);
+ cursor.par(endpit);
+ selection.end.par(endpit);
selection.end.pos(pos);
cursor.pos(selection.end.pos());
}
selection.end.pos(pos);
cursor.pos(selection.end.pos());
}
- endpar = endpar->next();
// sometimes necessary
if (doclear)
selection.start.par()->stripLeadingSpaces();
// sometimes necessary
if (doclear)
selection.start.par()->stripLeadingSpaces();
- redoParagraphs(selection.start, endpar);
+ redoParagraphs(selection.start, endpit);
// cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb)
// cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb)
if (!internal &&
isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
setCursor(cursor.par(), cursor.pos(), true, true);
if (!internal &&
isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
setCursor(cursor.par(), cursor.pos(), true, true);
- } else if (cursor.par()->next())
- setCursor(cursor.par()->next(), 0);
+ } else if (boost::next(cursor.par()) != ownerParagraphs().end())
+ setCursor(boost::next(cursor.par()), 0);
void LyXText::cursorDownParagraph()
{
void LyXText::cursorDownParagraph()
{
- if (cursor.par()->next()) {
- setCursor(cursor.par()->next(), 0);
+ if (boost::next(cursor.par()) != ownerParagraphs().end()) {
+ setCursor(boost::next(cursor.par()), 0);
} else {
setCursor(cursor.par(), cursor.par()->size());
}
} else {
setCursor(cursor.par(), cursor.par()->size());
}
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
old_cursor.par()->erase(old_cursor.pos() - 1);
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
old_cursor.par()->erase(old_cursor.pos() - 1);
- redoParagraphs(old_cursor, old_cursor.par()->next());
+ redoParagraphs(old_cursor, boost::next(old_cursor.par()));
#ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer
#ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer
const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline() - prevrow->height());
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline() - prevrow->height());
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
- Paragraph * endpar = old_cursor.par()->next();
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
+ #warning FIXME. --end() iterator is usable here
+ ParagraphList::iterator endpit = boost::next(old_cursor.par());
+ while (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ ++endpit;
- setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
+ setUndo(bv(), Undo::DELETE, &*old_cursor.par(), &*endpit);
cursor = tmpcursor;
// delete old row
cursor = tmpcursor;
// delete old row
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position
- Paragraph * endpar = old_cursor.par()->next();
- while (endpar && endpar->getDepth()) {
- endpar = endpar->next();
+#warning FIXME. --end() iterator is usable here
+ ParagraphList::iterator endpit = boost::next(old_cursor.par());
+ while (endpit != ownerParagraphs().end() &&
+ endpit->getDepth()) {
+ ++endpit;
- setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
+ setUndo(bv(), Undo::DELETE, &*old_cursor.par(), &*endpit);
cursor = tmpcursor;
// delete old row
cursor = tmpcursor;
// delete old row
}
if (!deleted) {
if (old_cursor.par()->stripLeadingSpaces()) {
}
if (!deleted) {
if (old_cursor.par()->stripLeadingSpaces()) {
- redoParagraphs(old_cursor,
- old_cursor.par()->next());
+ redoParagraphs(old_cursor, boost::next(old_cursor.par()));
// correct cursor y
setCursorIntern(cursor.par(), cursor.pos());
selection.cursor = cursor;
// correct cursor y
setCursorIntern(cursor.par(), cursor.pos());
selection.cursor = cursor;