parlist-9-a.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6787 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-04-13 02:23:30 +00:00
parent cc46c4b975
commit 3b8f3462ed
5 changed files with 80 additions and 66 deletions

View File

@ -1,5 +1,10 @@
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 * text2.C (cursorTop): simplify implementation
(cursorBottom): ditto (cursorBottom): ditto
(setParagraph): use ParagraphList::iterator (setParagraph): use ParagraphList::iterator

View File

@ -62,7 +62,7 @@ textclass_type textclass = 0;
} // namespace anon } // namespace anon
bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar, bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph * endpar,
int start, int & end, textclass_type tc, int start, int & end, textclass_type tc,
bool doclear, bool realcut) bool doclear, bool realcut)
{ {
@ -70,10 +70,10 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
return false; return false;
if (realcut) { 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)) { if (startpar->erase(start, end)) {
// Some chars were erased, go to start to be safe // Some chars were erased, go to start to be safe
end = start; end = start;
@ -85,7 +85,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
// clear end/begin fragments of the first/last par in selection // clear end/begin fragments of the first/last par in selection
actually_erased |= (startpar)->erase(start, startpar->size()); actually_erased |= (startpar)->erase(start, startpar->size());
if ((*endpar)->erase(0, end)) { if (endpar->erase(0, end)) {
actually_erased = true; actually_erased = true;
end = 0; end = 0;
} }
@ -102,7 +102,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
Paragraph * next = pit->next(); Paragraph * next = pit->next();
// "erase" the contents of the par // "erase" the contents of the par
if (pit != *endpar) { if (pit != endpar) {
actually_erased |= pit->erase(0, pit->size()); actually_erased |= pit->erase(0, pit->size());
// remove the par if it's now empty // remove the par if it's now empty
@ -116,7 +116,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
} }
} }
if (pit == *endpar) if (pit == endpar)
break; break;
pit = next; pit = next;
@ -152,7 +152,7 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
// the insets paragraphs, and not the buffers. (Lgb) // the insets paragraphs, and not the buffers. (Lgb)
mergeParagraph(buffer->params, buffer->paragraphs, startpar); mergeParagraph(buffer->params, buffer->paragraphs, startpar);
// this because endpar gets deleted here! // this because endpar gets deleted here!
(*endpar) = startpar; endpar = startpar;
} }
return true; return true;

View File

@ -21,7 +21,7 @@ class LyXTextClass;
namespace CutAndPaste { namespace CutAndPaste {
/// realcut == false is we actually want a delete /// 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, int start, int & end, lyx::textclass_type tc,
bool doclear = false, bool realcut = true); bool doclear = false, bool realcut = true);

View File

@ -1248,7 +1248,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
// a section, or between the items of a itemize or enumerate // a section, or between the items of a itemize or enumerate
// environment // environment
if (!firstpit->params().pagebreakBottom() if (!firstpit->params().pagebreakBottom()
&& rit->par()->next()) { && boost::next(rit->par()) != ownerParagraphs().end()) {
ParagraphList::iterator nextpit = boost::next(rit->par()); ParagraphList::iterator nextpit = boost::next(rit->par());
ParagraphList::iterator comparepit = rit->par(); ParagraphList::iterator comparepit = rit->par();
float usual = 0; float usual = 0;
@ -1485,7 +1485,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
cursor.par()->applyLayout(tclass.defaultLayout()); cursor.par()->applyLayout(tclass.defaultLayout());
else else
// set to standard-layout // 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,
@ -1522,17 +1522,18 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
// When ::breakParagraph is called from within an inset we must // When ::breakParagraph is called from within an inset we must
// ensure that the correct ParagraphList is used. Today that is not // ensure that the correct ParagraphList is used. Today that is not
// the case and the Buffer::paragraphs is used. Not good. (Lgb) // the case and the Buffer::paragraphs is used. Not good. (Lgb)
while (!cursor.par()->next()->empty() ParagraphList::iterator next_par = boost::next(cursor.par());
&& cursor.par()->next()->isNewline(0))
cursor.par()->next()->erase(0);
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(); updateCounters();
// This check is necessary. Otherwise the new empty paragraph will // This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user! // be deleted automatically. And it is more friendly for the user!
if (cursor.pos() || isempty) if (cursor.pos() || isempty)
setCursor(boost::next(cursor.par()), 0); setCursor(next_par, 0);
else else
setCursor(cursor.par(), 0); setCursor(cursor.par(), 0);
@ -1955,8 +1956,8 @@ void LyXText::cursorRightOneWord()
// CHECK See comment on top of text.C // CHECK See comment on top of text.C
if (tmpcursor.pos() == tmpcursor.par()->size() if (tmpcursor.pos() == tmpcursor.par()->size()
&& tmpcursor.par()->next()) { && boost::next(tmpcursor.par()) != ownerParagraphs().end()) {
tmpcursor.par(tmpcursor.par()->next()); tmpcursor.par(boost::next(tmpcursor.par()));
tmpcursor.pos(0); tmpcursor.pos(0);
} else { } else {
int steps = 0; int steps = 0;
@ -2133,7 +2134,7 @@ void LyXText::rejectChange()
startc.par()->rejectChange(startc.pos(), endc.pos()); startc.par()->rejectChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
clearSelection(); clearSelection();
redoParagraphs(startc, startc.par()->next()); redoParagraphs(startc, boost::next(startc.par()));
setCursorIntern(startc.par(), 0); setCursorIntern(startc.par(), 0);
} }
#warning handle multi par selection #warning handle multi par selection
@ -2154,9 +2155,9 @@ LyXText::selectNextWordToSpellcheck(float & value)
} }
// we have to go on checking so move cursor to the next char // we have to go on checking so move cursor to the next char
if (cursor.pos() == cursor.par()->size()) { if (cursor.pos() == cursor.par()->size()) {
if (!cursor.par()->next()) if (boost::next(cursor.par()) == ownerParagraphs().end())
return word; return word;
cursor.par(cursor.par()->next()); cursor.par(boost::next(cursor.par()));
cursor.pos(0); cursor.pos(0);
} else } else
cursor.pos(cursor.pos() + 1); cursor.pos(cursor.pos() + 1);

View File

@ -389,19 +389,22 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
LyXCursor & send_cur, LyXCursor & send_cur,
string const & layout) string const & layout)
{ {
Paragraph * endpar = send_cur.par()->next(); ParagraphList::iterator endpit = boost::next(send_cur.par());
Paragraph * undoendpar = endpar; ParagraphList::iterator undoendpit = endpit;
if (endpar && endpar->getDepth()) { if (endpit != ownerParagraphs().end() &&
while (endpar && endpar->getDepth()) { endpit->getDepth()) {
endpar = endpar->next(); while (endpit != ownerParagraphs().end() &&
undoendpar = endpar; endpit->getDepth()) {
++endpit;
undoendpit = endpit;
} }
} else if (endpar) { } else if (endpit != ownerParagraphs().end()) {
endpar = endpar->next(); // because of parindents etc. // 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 // ok we have a selection. This is always between sstart_cur
// and sel_end cursor // and sel_end cursor
@ -428,7 +431,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
++pit; ++pit;
} while (pit != epit); } while (pit != epit);
return endpar; return endpit;
} }
@ -591,12 +594,12 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
cursor.pos(cursor.pos() + 1); cursor.pos(cursor.pos() + 1);
} else { } else {
cursor.pos(0); cursor.pos(0);
cursor.par(cursor.par()->next()); cursor.par(boost::next(cursor.par()));
} }
} }
unFreezeUndo(); unFreezeUndo();
redoParagraphs(selection.start, selection.end.par()->next()); redoParagraphs(selection.start, boost::next(selection.end.par()));
// we have to reset the selection, because the // we have to reset the selection, because the
// geometry could have changed, but we keep // geometry could have changed, but we keep
@ -830,7 +833,7 @@ string const LyXText::selectionAsString(Buffer const * buffer,
#warning FIXME Why isnt ParagraphList::iterator used here? #warning FIXME Why isnt ParagraphList::iterator used here?
// as loop variable. // as loop variable.
LyXCursor tmpcur(selection.start); LyXCursor tmpcur(selection.start);
tmpcur.par(tmpcur.par()->next()); tmpcur.par(boost::next(tmpcur.par()));
while (tmpcur.par() != endpit) { while (tmpcur.par() != endpit) {
result += tmpcur.par()->asString(buffer, 0, result += tmpcur.par()->asString(buffer, 0,
tmpcur.par()->size(), tmpcur.par()->size(),
@ -1339,51 +1342,53 @@ void LyXText::cutSelection(bool doclear, bool realcut)
// and selection.end // and selection.end
// make sure that the depth behind the selection are restored, too // make sure that the depth behind the selection are restored, too
Paragraph * endpar = selection.end.par()->next(); ParagraphList::iterator endpit = boost::next(selection.end.par());
Paragraph * undoendpar = endpar; ParagraphList::iterator undoendpit = endpit;
if (endpar && endpar->getDepth()) { if (endpit != ownerParagraphs().end() &&
while (endpar && endpar->getDepth()) { endpit->getDepth()) {
endpar = endpar->next(); while (endpit != ownerParagraphs().end() &&
undoendpar = endpar; endpit->getDepth()) {
++endpit;
undoendpit = endpit;
} }
} else if (endpar) { } else if (endpit != ownerParagraphs().end()) {
endpar = endpar->next(); // because of parindents etc. // because of parindents etc.
++endpit;
} }
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE, &*selection.start.par(), &*undoendpit);
&*selection.start.par(), undoendpar);
// there are two cases: cut only within one paragraph or // there are two cases: cut only within one paragraph or
// more than one paragraph // more than one paragraph
if (selection.start.par() == selection.end.par()) { if (selection.start.par() == selection.end.par()) {
// only within one paragraph // 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, selection.start.pos(), pos,
bv()->buffer()->params.textclass, bv()->buffer()->params.textclass,
doclear, realcut); doclear, realcut);
selection.end.pos(pos); selection.end.pos(pos);
} else { } 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, selection.start.pos(), pos,
bv()->buffer()->params.textclass, bv()->buffer()->params.textclass,
doclear, realcut); doclear, realcut);
cursor.par(endpar); cursor.par(endpit);
selection.end.par(endpar); selection.end.par(endpit);
selection.end.pos(pos); selection.end.pos(pos);
cursor.pos(selection.end.pos()); cursor.pos(selection.end.pos());
} }
endpar = endpar->next(); ++endpit;
// sometimes necessary // sometimes necessary
if (doclear) if (doclear)
selection.start.par()->stripLeadingSpaces(); selection.start.par()->stripLeadingSpaces();
redoParagraphs(selection.start, endpar); redoParagraphs(selection.start, endpit);
// cutSelection can invalidate the cursor so we need to set // cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb) // it anew. (Lgb)
@ -2076,8 +2081,8 @@ void LyXText::cursorRight(bool internal)
if (!internal && if (!internal &&
isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())) isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
setCursor(cursor.par(), cursor.pos(), true, true); setCursor(cursor.par(), cursor.pos(), true, true);
} else if (cursor.par()->next()) } else if (boost::next(cursor.par()) != ownerParagraphs().end())
setCursor(cursor.par()->next(), 0); setCursor(boost::next(cursor.par()), 0);
} }
@ -2142,8 +2147,8 @@ void LyXText::cursorUpParagraph()
void LyXText::cursorDownParagraph() void LyXText::cursorDownParagraph()
{ {
if (cursor.par()->next()) { if (boost::next(cursor.par()) != ownerParagraphs().end()) {
setCursor(cursor.par()->next(), 0); setCursor(boost::next(cursor.par()), 0);
} else { } else {
setCursor(cursor.par(), cursor.par()->size()); setCursor(cursor.par(), cursor.par()->size());
} }
@ -2219,7 +2224,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
&& old_cursor.par()->isLineSeparator(old_cursor.pos()) && old_cursor.par()->isLineSeparator(old_cursor.pos())
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) { && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
old_cursor.par()->erase(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 #ifdef WITH_WARNINGS
#warning This will not work anymore when we have multiple views of the same buffer #warning This will not work anymore when we have multiple views of the same buffer
@ -2273,12 +2278,14 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline() - prevrow->height()); const_cast<LyXText *>(this)->postPaint(old_cursor.y() - old_cursor.row()->baseline() - prevrow->height());
tmpcursor = cursor; tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next(); #warning FIXME. --end() iterator is usable here
while (endpar && endpar->getDepth()) { ParagraphList::iterator endpit = boost::next(old_cursor.par());
endpar = endpar->next(); 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; cursor = tmpcursor;
// delete old row // delete old row
@ -2306,12 +2313,14 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
tmpcursor = cursor; tmpcursor = cursor;
cursor = old_cursor; // that undo can restore the right cursor position cursor = old_cursor; // that undo can restore the right cursor position
Paragraph * endpar = old_cursor.par()->next(); #warning FIXME. --end() iterator is usable here
while (endpar && endpar->getDepth()) { ParagraphList::iterator endpit = boost::next(old_cursor.par());
endpar = endpar->next(); 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; cursor = tmpcursor;
// delete old row // delete old row
@ -2344,8 +2353,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
} }
if (!deleted) { if (!deleted) {
if (old_cursor.par()->stripLeadingSpaces()) { if (old_cursor.par()->stripLeadingSpaces()) {
redoParagraphs(old_cursor, redoParagraphs(old_cursor, boost::next(old_cursor.par()));
old_cursor.par()->next());
// correct cursor y // correct cursor y
setCursorIntern(cursor.par(), cursor.pos()); setCursorIntern(cursor.par(), cursor.pos());
selection.cursor = cursor; selection.cursor = cursor;