Make lyxcursor store a ParagraphList::iterator, change three functions to take a ParagraphList::iterator instead of a ParagraphList::iterator. Other changes to adjust for this.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6741 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-04-09 09:15:20 +00:00
parent 80837fb324
commit 0408f69287
17 changed files with 280 additions and 196 deletions

View File

@ -358,7 +358,7 @@ bool BufferView::insertLyXFile(string const & filen)
bool BufferView::removeAutoInsets() bool BufferView::removeAutoInsets()
{ {
// keep track of which pos and par the cursor was on // keep track of which pos and par the cursor was on
Paragraph * cursor_par = text->cursor.par(); Paragraph * cursor_par = &*text->cursor.par();
Paragraph * cursor_par_prev = cursor_par ? cursor_par->previous() : 0; Paragraph * cursor_par_prev = cursor_par ? cursor_par->previous() : 0;
Paragraph * cursor_par_next = cursor_par ? cursor_par->next() : 0; Paragraph * cursor_par_next = cursor_par ? cursor_par->next() : 0;
pos_type cursor_pos = text->cursor.pos(); pos_type cursor_pos = text->cursor.pos();
@ -712,7 +712,7 @@ bool BufferView::lockInset(UpdatableInset * inset)
if (!theLockingInset()) { if (!theLockingInset()) {
// first check if it's the inset under the cursor we want lock // first check if it's the inset under the cursor we want lock
// should be most of the time // should be most of the time
if (text->cursor.pos() < text->cursor.par()->size() if (text->cursor.pos() < text->cursor.par()->size()
&& text->cursor.par()->getChar(text->cursor.pos()) == && text->cursor.par()->getChar(text->cursor.pos()) ==
Paragraph::META_INSET) { Paragraph::META_INSET) {
Inset * in = text->cursor.par()->getInset(text->cursor.pos()); Inset * in = text->cursor.par()->getInset(text->cursor.pos());
@ -830,7 +830,7 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
if (kind == Undo::EDIT) // in this case insets would not be stored! if (kind == Undo::EDIT) // in this case insets would not be stored!
kind = Undo::FINISH; kind = Undo::FINISH;
setUndo(this, kind, setUndo(this, kind,
text->cursor.par(), &*text->cursor.par(),
text->cursor.par()->next()); text->cursor.par()->next());
} }

View File

@ -275,11 +275,11 @@ int BufferView::Pimpl::resizeCurrentBuffer()
owner_->message(_("Formatting document...")); owner_->message(_("Formatting document..."));
if (bv_->text) { if (bv_->text) {
par = bv_->text->cursor.par(); par = &*bv_->text->cursor.par();
pos = bv_->text->cursor.pos(); pos = bv_->text->cursor.pos();
selstartpar = bv_->text->selection.start.par(); selstartpar = &*bv_->text->selection.start.par();
selstartpos = bv_->text->selection.start.pos(); selstartpos = bv_->text->selection.start.pos();
selendpar = bv_->text->selection.end.par(); selendpar = &*bv_->text->selection.end.par();
selendpos = bv_->text->selection.end.pos(); selendpos = bv_->text->selection.end.pos();
selection = bv_->text->selection.set(); selection = bv_->text->selection.set();
mark_set = bv_->text->selection.mark(); mark_set = bv_->text->selection.mark();
@ -1172,7 +1172,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
break; break;
case LFUN_LAYOUT_PARAGRAPH: { case LFUN_LAYOUT_PARAGRAPH: {
Paragraph const * par = bv_->getLyXText()->cursor.par(); Paragraph const * par = &*bv_->getLyXText()->cursor.par();
if (!par) if (!par)
break; break;
@ -1185,7 +1185,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
} }
case LFUN_PARAGRAPH_UPDATE: { case LFUN_PARAGRAPH_UPDATE: {
Paragraph const * par = bv_->getLyXText()->cursor.par(); Paragraph const * par = &*bv_->getLyXText()->cursor.par();
if (!par) if (!par)
break; break;

View File

@ -1,3 +1,59 @@
2003-04-09 Lars Gullik Bjønnes <larsbj@gullik.net>
* undo_funcs.C (setCursorParUndo): adjust
* text_funcs.C (transposeChars): adjust
* text3.C (gotoNextInset): adjust
(dispatch): adjust
* text2.C (setLayout): adjust
(changeDepth): adjust
(setFont): adjust
(redoParagraphs): adjust
(selectionAsString): adjust
(setParagraph): adjust
(insertInset): adjust
(cutSelection): adjust
(copySelection): adjust
(pasteSelection): adjust
(insertStringAsLines): adjust
(updateInset): adjust
(setCursor): change to take a ParagraphList::iterator parameter
(setCursorIntern): change to take a ParagraphList::iterator parameter
(setCurrentFont): adjust
(cursorLeft): adjust
(cursorRight): adjust
(deleteEmptyParagraphMechanism): adjust
* text.C (breakParagraph): adjust
(insertChar): adjust
(acceptChange): adjust
(rejectChange): adjust
(selectNextWordToSpellcheck): adjust
(changeCase): adjust
(Delete): adjust
(backspace): adjust
* lyxfind.C (SearchForward): adjust
(SearchBackward): adjust
(nextChange): adjust
* lyxcursor.C (par): adjust
* lyxcursor.h: store a ParagraphList::iterator instead of a
Paragraph*
* lyx_cb.C (getPossibleLabel): adjust
* bufferview_funcs.C (toggleAndShow): adjust
* BufferView_pimpl.C (resizeCurrentBuffer): adjust
(dispatch): adjust
* BufferView.C (removeAutoInsets): adjust
(lockedInsetStoreUndo): adjust
2003-04-09 John Levon <levon@movementarian.org> 2003-04-09 John Levon <levon@movementarian.org>
* ToolbarBackend.C: try icon without argument * ToolbarBackend.C: try icon without argument
@ -17,7 +73,7 @@
* text2.C (changeDepth): do not setUndo on test_only (make undo work * text2.C (changeDepth): do not setUndo on test_only (make undo work
again) again)
2003-04-05 Alfredo Braunstein <abraunst@libero.it> 2003-04-05 Alfredo Braunstein <abraunst@libero.it>
* lyxfind.C (searchForward, searchBackwards): bug 782 * lyxfind.C (searchForward, searchBackwards): bug 782
@ -91,10 +147,10 @@
* lyxrow.h: store a ParagraphList::iterator instead of a * lyxrow.h: store a ParagraphList::iterator instead of a
Paragraph* and adjust other class functions to suit. Paragraph* and adjust other class functions to suit.
* lyxrow_funcs.C, text.C, text2.C, text3.C: adjust because of the * lyxrow_funcs.C, text.C, text2.C, text3.C: adjust because of the
above. above.
2003-04-01 Alfredo Braunstein <abraunst@libero.it> 2003-04-01 Alfredo Braunstein <abraunst@libero.it>
* text2.C (setCursor): do not anchor to cursor row for the time being * text2.C (setCursor): do not anchor to cursor row for the time being

View File

@ -400,7 +400,7 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
LyXCursor & cursor = text->cursor; LyXCursor & cursor = text->cursor;
text->computeBidiTables(bv->buffer(), cursor.row()); text->computeBidiTables(bv->buffer(), cursor.row());
if (cursor.boundary() != if (cursor.boundary() !=
text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(), text->isBoundary(bv->buffer(), &*cursor.par(), cursor.pos(),
text->real_current_font)) text->real_current_font))
text->setCursor(cursor.par(), cursor.pos(), text->setCursor(cursor.par(), cursor.pos(),
false, !cursor.boundary()); false, !cursor.boundary());

View File

@ -1,5 +1,18 @@
2003-04-09 Lars Gullik Bjønnes <larsbj@gullik.net>
* insettext.C (saveLyXTextState): adjust
(localDispatch): adjust
(setFont): adjust
(cx): adjust
(cix): adjust
(cpar): adjust
* insettabular.C (localDispatch): adjust
(setFont): adjust
(tabularFeatures): adjust
2003-04-05 Alfredo Braunstein <abraunst@libero.it> 2003-04-05 Alfredo Braunstein <abraunst@libero.it>
* insettabular.C (searchForward,searchBackward): fix bug 782 * insettabular.C (searchForward,searchBackward): fix bug 782
2003-04-07 John Levon <levon@movementarian.org> 2003-04-07 John Levon <levon@movementarian.org>

View File

@ -1070,8 +1070,8 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
// no break here! // no break here!
case LFUN_DELETE: case LFUN_DELETE:
setUndo(bv, Undo::DELETE, setUndo(bv, Undo::DELETE,
bv->text->cursor.par(), &*bv->text->cursor.par(),
bv->text->cursor.par()->next()); &*boost::next(bv->text->cursor.par()));
cutSelection(bv->buffer()->params); cutSelection(bv->buffer()->params);
updateLocal(bv, INIT); updateLocal(bv, INIT);
break; break;
@ -1155,8 +1155,8 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
case LFUN_PASTE: case LFUN_PASTE:
if (hasPasteBuffer()) { if (hasPasteBuffer()) {
setUndo(bv, Undo::INSERT, setUndo(bv, Undo::INSERT,
bv->text->cursor.par(), &*bv->text->cursor.par(),
bv->text->cursor.par()->next()); &*boost::next(bv->text->cursor.par()));
pasteSelection(bv); pasteSelection(bv);
updateLocal(bv, INIT); updateLocal(bv, INIT);
break; break;
@ -1684,8 +1684,8 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
} }
if (hasSelection()) { if (hasSelection()) {
setUndo(bv, Undo::EDIT, setUndo(bv, Undo::EDIT,
bv->text->cursor.par(), &*bv->text->cursor.par(),
bv->text->cursor.par()->next()); &*boost::next(bv->text->cursor.par()));
bool const frozen = undo_frozen; bool const frozen = undo_frozen;
if (!frozen) if (!frozen)
freezeUndo(); freezeUndo();
@ -1808,8 +1808,8 @@ void InsetTabular::tabularFeatures(BufferView * bv,
sel_row_start = sel_row_end = tabular->row_of_cell(actcell); sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
} }
setUndo(bv, Undo::FINISH, setUndo(bv, Undo::FINISH,
bv->text->cursor.par(), &*bv->text->cursor.par(),
bv->text->cursor.par()->next()); &*boost::next(bv->text->cursor.par()));
int row = tabular->row_of_cell(actcell); int row = tabular->row_of_cell(actcell);
int column = tabular->column_of_cell(actcell); int column = tabular->column_of_cell(actcell);

View File

@ -84,13 +84,13 @@ void InsetText::saveLyXTextState(LyXText * t) const
} }
if (it != end && t->cursor.pos() <= it->size()) { if (it != end && t->cursor.pos() <= it->size()) {
sstate.lpar = t->cursor.par(); sstate.lpar = &*t->cursor.par();
sstate.pos = t->cursor.pos(); sstate.pos = t->cursor.pos();
sstate.boundary = t->cursor.boundary(); sstate.boundary = t->cursor.boundary();
sstate.selstartpar = t->selection.start.par(); sstate.selstartpar = &*t->selection.start.par();
sstate.selstartpos = t->selection.start.pos(); sstate.selstartpos = t->selection.start.pos();
sstate.selstartboundary = t->selection.start.boundary(); sstate.selstartboundary = t->selection.start.boundary();
sstate.selendpar = t->selection.end.par(); sstate.selendpar = &*t->selection.end.par();
sstate.selendpos = t->selection.end.pos(); sstate.selendpos = t->selection.end.pos();
sstate.selendboundary = t->selection.end.boundary(); sstate.selendboundary = t->selection.end.boundary();
sstate.selection = t->selection.set(); sstate.selection = t->selection.set();
@ -1397,11 +1397,11 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
// inherit bufferparams/paragraphparams in a strange way. (Lgb) // inherit bufferparams/paragraphparams in a strange way. (Lgb)
// FIXME: how old is this comment ? ... // FIXME: how old is this comment ? ...
{ {
Paragraph * par = lt->cursor.par(); ParagraphList::iterator pit = lt->cursor.par();
Spacing::Space cur_spacing = par->params().spacing().getSpace(); Spacing::Space cur_spacing = pit->params().spacing().getSpace();
float cur_value = 1.0; float cur_value = 1.0;
if (cur_spacing == Spacing::Other) { if (cur_spacing == Spacing::Other) {
cur_value = par->params().spacing().getValue(); cur_value = pit->params().spacing().getValue();
} }
istringstream istr(ev.argument.c_str()); istringstream istr(ev.argument.c_str());
@ -1432,7 +1432,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
<< ev.argument << endl; << ev.argument << endl;
} }
if (cur_spacing != new_spacing || cur_value != new_value) { if (cur_spacing != new_spacing || cur_value != new_value) {
par->params().spacing(Spacing(new_spacing, new_value)); pit->params().spacing(Spacing(new_spacing, new_value));
updwhat = CURSOR_PAR; updwhat = CURSOR_PAR;
updflag = true; updflag = true;
} }
@ -1938,7 +1938,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
clear = true; clear = true;
} }
if (lt->selection.set()) { if (lt->selection.set()) {
setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next()); setUndo(bv, Undo::EDIT, &*lt->cursor.par(), lt->cursor.par()->next());
} }
if (selectall) if (selectall)
selectAll(bv); selectAll(bv);
@ -2106,7 +2106,7 @@ int InsetText::cx(BufferView * bv) const
LyXText * llt = getLyXText(bv); LyXText * llt = getLyXText(bv);
int x = llt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET; int x = llt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
if (the_locking_inset) { if (the_locking_inset) {
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(), LyXFont font = llt->getFont(bv->buffer(), &*llt->cursor.par(),
llt->cursor.pos()); llt->cursor.pos());
if (font.isVisibleRightToLeft()) if (font.isVisibleRightToLeft())
x -= the_locking_inset->width(bv, font); x -= the_locking_inset->width(bv, font);
@ -2121,7 +2121,7 @@ int InsetText::cix(BufferView * bv) const
LyXText * llt = getLyXText(bv); LyXText * llt = getLyXText(bv);
int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET; int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
if (the_locking_inset) { if (the_locking_inset) {
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(), LyXFont font = llt->getFont(bv->buffer(), &*llt->cursor.par(),
llt->cursor.pos()); llt->cursor.pos());
if (font.isVisibleRightToLeft()) if (font.isVisibleRightToLeft())
x -= the_locking_inset->width(bv, font); x -= the_locking_inset->width(bv, font);
@ -2152,7 +2152,7 @@ pos_type InsetText::cpos(BufferView * bv) const
Paragraph * InsetText::cpar(BufferView * bv) const Paragraph * InsetText::cpar(BufferView * bv) const
{ {
return getLyXText(bv)->cursor.par(); return &*getLyXText(bv)->cursor.par();
} }

View File

@ -462,7 +462,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
string const getPossibleLabel(BufferView const & bv) string const getPossibleLabel(BufferView const & bv)
{ {
Paragraph * par = bv.getLyXText()->cursor.par(); Paragraph * par = &*bv.getLyXText()->cursor.par();
LyXLayout_ptr layout = par->layout(); LyXLayout_ptr layout = par->layout();
if (layout->latextype == LATEX_PARAGRAPH && par->previous()) { if (layout->latextype == LATEX_PARAGRAPH && par->previous()) {
Paragraph * par2 = par->previous(); Paragraph * par2 = par->previous();

View File

@ -17,13 +17,13 @@ LyXCursor::LyXCursor()
{} {}
void LyXCursor::par(Paragraph * p) void LyXCursor::par(ParagraphList::iterator pit)
{ {
par_ = p; par_ = pit;
} }
Paragraph * LyXCursor::par() const ParagraphList::iterator LyXCursor::par() const
{ {
return par_; return par_;
} }

View File

@ -11,10 +11,9 @@
#define LYXCURSOR_H #define LYXCURSOR_H
#include "RowList.h" #include "RowList.h"
#include "ParagraphList.h"
#include "support/types.h" #include "support/types.h"
class Paragraph;
/** /**
* The cursor class describes the position of a cursor within a document. * The cursor class describes the position of a cursor within a document.
* Several cursors exist within LyX; for example, when locking an inset, * Several cursors exist within LyX; for example, when locking an inset,
@ -26,9 +25,9 @@ class LyXCursor {
public: public:
LyXCursor(); LyXCursor();
/// set the paragraph that contains this cursor /// set the paragraph that contains this cursor
void par(Paragraph * p); void par(ParagraphList::iterator pit);
/// return the paragraph this cursor is in /// return the paragraph this cursor is in
Paragraph * par() const; ParagraphList::iterator par() const;
/// set the position within the paragraph /// set the position within the paragraph
void pos(lyx::pos_type p); void pos(lyx::pos_type p);
/// return the position within the paragraph /// return the position within the paragraph
@ -96,7 +95,7 @@ public:
RowList::iterator irow() const; RowList::iterator irow() const;
private: private:
/// The paragraph the cursor is in. /// The paragraph the cursor is in.
Paragraph * par_; ParagraphList::iterator par_;
/// The position inside the paragraph /// The position inside the paragraph
lyx::pos_type pos_; lyx::pos_type pos_;
/** /**

View File

@ -232,14 +232,14 @@ bool IsStringInText(Paragraph * par, pos_type pos,
SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str, SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
bool const & cs, bool const & mw) bool const & cs, bool const & mw)
{ {
Paragraph * par = text->cursor.par(); Paragraph * par = &*text->cursor.par();
pos_type pos = text->cursor.pos(); pos_type pos = text->cursor.pos();
UpdatableInset * inset; UpdatableInset * inset;
while (par && !IsStringInText(par, pos, str, cs, mw)) { while (par && !IsStringInText(par, pos, str, cs, mw)) {
if (pos < par->size() if (pos < par->size()
&& par->isInset(pos) && par->isInset(pos)
&& (inset = (UpdatableInset *)par->getInset(pos)) && (inset = (UpdatableInset *)par->getInset(pos))
&& inset->isTextInset() && inset->isTextInset()
&& inset->searchForward(bv, str, cs, mw)) && inset->searchForward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE; return SR_FOUND_NOUPDATE;
@ -265,7 +265,7 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
string const & str, string const & str,
bool const & cs, bool const & mw) bool const & cs, bool const & mw)
{ {
Paragraph * par = text->cursor.par(); Paragraph * par = &*text->cursor.par();
pos_type pos = text->cursor.pos(); pos_type pos = text->cursor.pos();
do { do {
@ -280,8 +280,8 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
} while (par && pos < 0); } while (par && pos < 0);
} }
UpdatableInset * inset; UpdatableInset * inset;
if (par && par->isInset(pos) if (par && par->isInset(pos)
&& (inset = (UpdatableInset *)par->getInset(pos)) && (inset = (UpdatableInset *)par->getInset(pos))
&& inset->isTextInset() && inset->isTextInset()
&& inset->searchBackward(bv, str, cs, mw)) && inset->searchBackward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE; return SR_FOUND_NOUPDATE;
@ -297,7 +297,7 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length) SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
{ {
Paragraph * par = text->cursor.par(); Paragraph * par = &*text->cursor.par();
pos_type pos = text->cursor.pos(); pos_type pos = text->cursor.pos();
Paragraph * prev_par = par; Paragraph * prev_par = par;
UpdatableInset * inset; UpdatableInset * inset;

View File

@ -330,16 +330,16 @@ public:
/// ///
void selectSelectedWord(); void selectSelectedWord();
/// returns true if par was empty and was removed /// returns true if par was empty and was removed
bool setCursor(Paragraph * par, bool setCursor(ParagraphList::iterator pit,
lyx::pos_type pos, lyx::pos_type pos,
bool setfont = true, bool setfont = true,
bool boundary = false); bool boundary = false);
/// ///
void setCursor(LyXCursor &, Paragraph * par, void setCursor(LyXCursor &, ParagraphList::iterator pit,
lyx::pos_type pos, lyx::pos_type pos,
bool boundary = false); bool boundary = false);
/// ///
void setCursorIntern(Paragraph * par, void setCursorIntern(ParagraphList::iterator pit,
lyx::pos_type pos, lyx::pos_type pos,
bool setfont = true, bool setfont = true,
bool boundary = false); bool boundary = false);

View File

@ -119,7 +119,7 @@ void LyXText::anchor_row(RowList::iterator rit)
anchor_row_ = rit; anchor_row_ = rit;
anchor_row_offset_ = old_y - top_y(); anchor_row_offset_ = old_y - top_y();
lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: " lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
<< &*anchor_row_ << " offset: " << &*anchor_row_ << " offset: "
<< anchor_row_offset_ << endl; << anchor_row_offset_ << endl;
} }
@ -787,7 +787,6 @@ LyXText::rowBreakPoint(Row const & row) const
pos_type i = pos; pos_type i = pos;
for (; i < last; ++i) { for (; i < last; ++i) {
if (pit->isNewline(i)) { if (pit->isNewline(i)) {
point = i; point = i;
break; break;
@ -1430,7 +1429,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
&& !layout->keepempty) && !layout->keepempty)
return; return;
setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next()); setUndo(bv(), Undo::FINISH, &*cursor.par(), &*boost::next(cursor.par()));
// Always break behind a space // Always break behind a space
// //
@ -1532,7 +1531,7 @@ void LyXText::redoParagraph()
// same Paragraph one to the right and make a rebreak // same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c) void LyXText::insertChar(char c)
{ {
setUndo(bv(), Undo::INSERT, cursor.par(), cursor.par()->next()); setUndo(bv(), Undo::INSERT, &*cursor.par(), &*boost::next(cursor.par()));
// When the free-spacing option is set for the current layout, // When the free-spacing option is set for the current layout,
// disable the double-space checking // disable the double-space checking
@ -1551,10 +1550,10 @@ void LyXText::insertChar(char c)
cursor.pos() >= 1 && cursor.pos() >= 1 &&
cursor.pos() < cursor.par()->size() && cursor.pos() < cursor.par()->size() &&
getFont(bv()->buffer(), getFont(bv()->buffer(),
cursor.par(), &*cursor.par(),
cursor.pos()).number() == LyXFont::ON && cursor.pos()).number() == LyXFont::ON &&
getFont(bv()->buffer(), getFont(bv()->buffer(),
cursor.par(), &*cursor.par(),
cursor.pos() - 1).number() == LyXFont::ON) cursor.pos() - 1).number() == LyXFont::ON)
) )
number(bv()); // Set current_font.number to OFF number(bv()); // Set current_font.number to OFF
@ -1570,16 +1569,16 @@ void LyXText::insertChar(char c)
cursor.par()->isNewline(cursor.pos() - 2)) cursor.par()->isNewline(cursor.pos() - 2))
) { ) {
setCharFont(bv()->buffer(), setCharFont(bv()->buffer(),
cursor.par(), &*cursor.par(),
cursor.pos() - 1, cursor.pos() - 1,
current_font); current_font);
} else if (contains(number_seperators, c) && } else if (contains(number_seperators, c) &&
cursor.pos() >= 2 && cursor.pos() >= 2 &&
getFont(bv()->buffer(), getFont(bv()->buffer(),
cursor.par(), &*cursor.par(),
cursor.pos() - 2).number() == LyXFont::ON) { cursor.pos() - 2).number() == LyXFont::ON) {
setCharFont(bv()->buffer(), setCharFont(bv()->buffer(),
cursor.par(), &*cursor.par(),
cursor.pos() - 1, cursor.pos() - 1,
current_font); current_font);
} }
@ -1648,7 +1647,7 @@ void LyXText::insertChar(char c)
// Here case LyXText::InsertInset already insertet the character // Here case LyXText::InsertInset already insertet the character
cursor.par()->insertChar(cursor.pos(), c); cursor.par()->insertChar(cursor.pos(), c);
} }
setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont); setCharFont(bv()->buffer(), &*cursor.par(), cursor.pos(), rawtmpfont);
if (!jumped_over_space) { if (!jumped_over_space) {
// refresh the positions // refresh the positions
@ -1733,7 +1732,7 @@ void LyXText::insertChar(char c)
setCursor(cursor.par(), cursor.pos() + 1, false, setCursor(cursor.par(), cursor.pos() + 1, false,
cursor.boundary()); cursor.boundary());
if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos()) if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
!= cursor.boundary()) != cursor.boundary())
setCursor(cursor.par(), cursor.pos(), false, setCursor(cursor.par(), cursor.pos(), false,
!cursor.boundary()); !cursor.boundary());
@ -2083,7 +2082,7 @@ void LyXText::acceptChange()
if (selection.start.par() == selection.end.par()) { if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start; LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end; LyXCursor & endc = selection.end;
setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next()); setUndo(bv(), Undo::INSERT, &*startc.par(), &*boost::next(startc.par()));
startc.par()->acceptChange(startc.pos(), endc.pos()); startc.par()->acceptChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
clearSelection(); clearSelection();
@ -2104,7 +2103,8 @@ void LyXText::rejectChange()
if (selection.start.par() == selection.end.par()) { if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start; LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end; LyXCursor & endc = selection.end;
setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next()); setUndo(bv(), Undo::INSERT, &*startc.par(),
&*boost::next(startc.par()));
startc.par()->rejectChange(startc.pos(), endc.pos()); startc.par()->rejectChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
clearSelection(); clearSelection();
@ -2136,7 +2136,7 @@ LyXText::selectNextWordToSpellcheck(float & value)
} else } else
cursor.pos(cursor.pos() + 1); cursor.pos(cursor.pos() + 1);
} }
Paragraph * tmppar = cursor.par(); ParagraphList::iterator tmppit = cursor.par();
// If this is not the very first word, skip rest of // If this is not the very first word, skip rest of
// current word because we are probably in the middle // current word because we are probably in the middle
@ -2148,23 +2148,23 @@ LyXText::selectNextWordToSpellcheck(float & value)
} }
// Now, skip until we have real text (will jump paragraphs) // Now, skip until we have real text (will jump paragraphs)
while (1) { while (true) {
Paragraph * cpar(cursor.par()); ParagraphList::iterator cpit = cursor.par();
pos_type const cpos(cursor.pos()); pos_type const cpos(cursor.pos());
if (cpos == cpar->size()) { if (cpos == cpit->size()) {
if (cpar->next()) { if (boost::next(cpit) != ownerParagraphs().end()) {
cursor.par(cpar->next()); cursor.par(boost::next(cpit));
cursor.pos(0); cursor.pos(0);
continue; continue;
} }
break; break;
} }
bool const is_bad_inset(cpar->isInset(cpos) bool const is_bad_inset(cpit->isInset(cpos)
&& !cpar->getInset(cpos)->allowSpellcheck()); && !cpit->getInset(cpos)->allowSpellcheck());
if (cpar->isLetter(cpos) && !isDeletedText(*cpar, cpos) if (cpit->isLetter(cpos) && !isDeletedText(*cpit, cpos)
&& !is_bad_inset) && !is_bad_inset)
break; break;
@ -2182,7 +2182,7 @@ LyXText::selectNextWordToSpellcheck(float & value)
} }
// Update the value if we changed paragraphs // Update the value if we changed paragraphs
if (cursor.par() != tmppar) { if (cursor.par() != tmppit) {
setCursor(cursor.par(), cursor.pos()); setCursor(cursor.par(), cursor.pos());
value = float(cursor.y())/float(height); value = float(cursor.y())/float(height);
} }
@ -2191,7 +2191,7 @@ LyXText::selectNextWordToSpellcheck(float & value)
selection.cursor = cursor; selection.cursor = cursor;
string lang_code( string lang_code(
getFont(bv()->buffer(), cursor.par(), cursor.pos()) getFont(bv()->buffer(), &*cursor.par(), cursor.pos())
.language()->code()); .language()->code());
// and find the end of the word (insets like optional hyphens // and find the end of the word (insets like optional hyphens
// and ligature break are part of a word) // and ligature break are part of a word)
@ -2320,18 +2320,19 @@ void LyXText::changeCase(LyXText::TextCase action)
lyx::Assert(from <= to); lyx::Assert(from <= to);
setUndo(bv(), Undo::FINISH, from.par(), to.par()->next()); setUndo(bv(), Undo::FINISH, &*from.par(), &*boost::next(to.par()));
pos_type pos = from.pos(); pos_type pos = from.pos();
Paragraph * par = from.par(); ParagraphList::iterator pit = from.par();
while (par && (pos != to.pos() || par != to.par())) { while (pit != ownerParagraphs().end() &&
if (pos == par->size()) { (pos != to.pos() || pit != to.par())) {
par = par->next(); if (pos == pit->size()) {
++pit;
pos = 0; pos = 0;
continue; continue;
} }
unsigned char c = par->getChar(pos); unsigned char c = pit->getChar(pos);
if (!IsInsetChar(c)) { if (!IsInsetChar(c)) {
switch (action) { switch (action) {
case text_lowercase: case text_lowercase:
@ -2347,8 +2348,8 @@ void LyXText::changeCase(LyXText::TextCase action)
} }
} }
#warning changes #warning changes
par->setChar(pos, c); pit->setChar(pos, c);
checkParagraph(par, pos); checkParagraph(&*pit, pos);
++pos; ++pos;
} }
@ -2389,7 +2390,7 @@ void LyXText::Delete()
// to make sure undo gets the right cursor position // to make sure undo gets the right cursor position
cursor = old_cursor; cursor = old_cursor;
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE,
cursor.par(), cursor.par()->next()); &*cursor.par(), &*boost::next(cursor.par()));
cursor = tmpcursor; cursor = tmpcursor;
backspace(); backspace();
} }
@ -2450,17 +2451,17 @@ void LyXText::backspace()
cursor.par()->previous(), cursor.par()->next()); cursor.par()->previous(), cursor.par()->next());
} }
Paragraph * tmppar = cursor.par(); ParagraphList::iterator tmppit = cursor.par();
RowList::iterator tmprow = cursor.row(); RowList::iterator tmprow = cursor.row();
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,
// without the dreaded mechanism. (JMarc) // without the dreaded mechanism. (JMarc)
if (cursor.par()->previous()) { if (cursor.par() != ownerParagraphs().begin()) {
// steps into the above paragraph. // steps into the above paragraph.
setCursorIntern(cursor.par()->previous(), setCursorIntern(boost::prior(cursor.par()),
cursor.par()->previous()->size(), boost::prior(cursor.par())->size(),
false); false);
} }
@ -2476,10 +2477,10 @@ void LyXText::backspace()
LyXTextClass const & tclass = LyXTextClass const & tclass =
bv()->buffer()->params.getLyXTextClass(); bv()->buffer()->params.getLyXTextClass();
if (cursor.par() != tmppar if (cursor.par() != tmppit
&& (cursor.par()->layout() == tmppar->layout() && (cursor.par()->layout() == tmppit->layout()
|| tmppar->layout() == tclass.defaultLayout()) || tmppit->layout() == tclass.defaultLayout())
&& cursor.par()->getAlign() == tmppar->getAlign()) { && cursor.par()->getAlign() == tmppit->getAlign()) {
removeParagraph(tmprow); removeParagraph(tmprow);
removeRow(tmprow); removeRow(tmprow);
mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par()); mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
@ -2514,7 +2515,7 @@ void LyXText::backspace()
// this is the code for a normal backspace, not pasting // this is the code for a normal backspace, not pasting
// any paragraphs // any paragraphs
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE,
cursor.par(), cursor.par()->next()); &*cursor.par(), &*boost::next(cursor.par()));
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,
@ -2541,7 +2542,7 @@ void LyXText::backspace()
if (cursor.pos() < lastPos(*this, row) || if (cursor.pos() < lastPos(*this, row) ||
!cursor.par()->isLineSeparator(cursor.pos())) { !cursor.par()->isLineSeparator(cursor.pos())) {
row->fill(row->fill() + singleWidth( row->fill(row->fill() + singleWidth(
cursor.par(), &*cursor.par(),
cursor.pos())); cursor.pos()));
} }
@ -2562,7 +2563,7 @@ void LyXText::backspace()
if (cursor.pos() < cursor.par()->size() if (cursor.pos() < cursor.par()->size()
&& !cursor.par()->isSeparator(cursor.pos())) { && !cursor.par()->isSeparator(cursor.pos())) {
cursor.par()->insertChar(cursor.pos(), ' '); cursor.par()->insertChar(cursor.pos(), ' ');
setCharFont(bv()->buffer(), cursor.par(), setCharFont(bv()->buffer(), &*cursor.par(),
cursor.pos(), current_font); cursor.pos(), current_font);
// refresh the positions // refresh the positions
tmprow = row; tmprow = row;
@ -2689,7 +2690,7 @@ void LyXText::backspace()
// current_font = rawtmpfont; // current_font = rawtmpfont;
// real_current_font = realtmpfont; // real_current_font = realtmpfont;
if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos()) if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
!= cursor.boundary()) != cursor.boundary())
setCursor(cursor.par(), cursor.pos(), false, setCursor(cursor.par(), cursor.pos(), false,
!cursor.boundary()); !cursor.boundary());

View File

@ -394,32 +394,32 @@ Paragraph * LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
endpar = endpar->next(); // because of parindents etc. endpar = endpar->next(); // because of parindents etc.
} }
setUndo(bv(), Undo::EDIT, sstart_cur.par(), undoendpar); setUndo(bv(), Undo::EDIT, &*sstart_cur.par(), undoendpar);
// 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
cur = sstart_cur; cur = sstart_cur;
Paragraph * par = sstart_cur.par(); ParagraphList::iterator pit = sstart_cur.par();
Paragraph * epar = send_cur.par()->next(); ParagraphList::iterator epit = boost::next(send_cur.par());
LyXLayout_ptr const & lyxlayout = LyXLayout_ptr const & lyxlayout =
bv()->buffer()->params.getLyXTextClass()[layout]; bv()->buffer()->params.getLyXTextClass()[layout];
do { do {
par->applyLayout(lyxlayout); pit->applyLayout(lyxlayout);
makeFontEntriesLayoutSpecific(*bv()->buffer(), *par); makeFontEntriesLayoutSpecific(*bv()->buffer(), *pit);
Paragraph * fppar = par; ParagraphList::iterator fppit = pit;
fppar->params().spaceTop(lyxlayout->fill_top ? fppit->params().spaceTop(lyxlayout->fill_top ?
VSpace(VSpace::VFILL) VSpace(VSpace::VFILL)
: VSpace(VSpace::NONE)); : VSpace(VSpace::NONE));
fppar->params().spaceBottom(lyxlayout->fill_bottom ? fppit->params().spaceBottom(lyxlayout->fill_bottom ?
VSpace(VSpace::VFILL) VSpace(VSpace::VFILL)
: VSpace(VSpace::NONE)); : VSpace(VSpace::NONE));
if (lyxlayout->margintype == MARGIN_MANUAL) if (lyxlayout->margintype == MARGIN_MANUAL)
par->setLabelWidthString(lyxlayout->labelstring()); pit->setLabelWidthString(lyxlayout->labelstring());
cur.par(par); cur.par(pit);
par = par->next(); ++pit;
} while (par != epar); } while (pit != epit);
return endpar; return endpar;
} }
@ -465,8 +465,8 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
start = pit; start = pit;
} }
ParagraphList::iterator pastend = end; ParagraphList::iterator pastend = boost::next(end);
++pastend;
if (!test_only) if (!test_only)
setUndo(bv(), Undo::EDIT, &(*start), &(*pastend)); setUndo(bv(), Undo::EDIT, &(*start), &(*pastend));
@ -474,8 +474,9 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
int prev_after_depth = 0; int prev_after_depth = 0;
#warning parlist ... could be nicer ? #warning parlist ... could be nicer ?
if (start != ownerParagraphs().begin()) if (start != ownerParagraphs().begin()) {
prev_after_depth = boost::prior(start)->getMaxDepthAfter(); prev_after_depth = boost::prior(start)->getMaxDepthAfter();
}
while (true) { while (true) {
int const depth = pit->params().depth(); int const depth = pit->params().depth();
@ -483,8 +484,10 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
if (depth < prev_after_depth if (depth < prev_after_depth
&& pit->layout()->labeltype != LABEL_BIBLIO) { && pit->layout()->labeltype != LABEL_BIBLIO) {
changed = true; changed = true;
if (!test_only) if (!test_only) {
pit->params().depth(depth + 1); pit->params().depth(depth + 1);
}
} }
} else if (depth) { } else if (depth) {
changed = true; changed = true;
@ -494,8 +497,9 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
prev_after_depth = pit->getMaxDepthAfter(); prev_after_depth = pit->getMaxDepthAfter();
if (pit == end) if (pit == end) {
break; break;
}
++pit; ++pit;
} }
@ -506,6 +510,8 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
// Wow, redoParagraphs is stupid. // Wow, redoParagraphs is stupid.
LyXCursor tmpcursor; LyXCursor tmpcursor;
setCursor(tmpcursor, &(*start), 0); setCursor(tmpcursor, &(*start), 0);
//redoParagraphs(tmpcursor, &(*pastend));
redoParagraphs(tmpcursor, &(*pastend)); redoParagraphs(tmpcursor, &(*pastend));
// We need to actually move the text->cursor. I don't // We need to actually move the text->cursor. I don't
@ -540,10 +546,10 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
LyXFont layoutfont; LyXFont layoutfont;
if (cursor.pos() < cursor.par()->beginningOfBody()) { if (cursor.pos() < cursor.par()->beginningOfBody()) {
layoutfont = getLabelFont(bv()->buffer(), layoutfont = getLabelFont(bv()->buffer(),
cursor.par()); &*cursor.par());
} else { } else {
layoutfont = getLayoutFont(bv()->buffer(), layoutfont = getLayoutFont(bv()->buffer(),
cursor.par()); &*cursor.par());
} }
// Update current font // Update current font
real_current_font.update(font, real_current_font.update(font,
@ -565,7 +571,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
// and sel_end cursor // and sel_end cursor
setUndo(bv(), Undo::EDIT, setUndo(bv(), Undo::EDIT,
selection.start.par(), selection.end.par()->next()); &*selection.start.par(), &*boost::next(selection.end.par()));
freezeUndo(); freezeUndo();
cursor = selection.start; cursor = selection.start;
while (cursor.par() != selection.end.par() || while (cursor.par() != selection.end.par() ||
@ -573,7 +579,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
{ {
if (cursor.pos() < cursor.par()->size()) { if (cursor.pos() < cursor.par()->size()) {
// an open footnote should behave like a closed one // an open footnote should behave like a closed one
setCharFont(cursor.par(), cursor.pos(), setCharFont(&*cursor.par(), cursor.pos(),
font, toggleall); font, toggleall);
cursor.pos(cursor.pos() + 1); cursor.pos(cursor.pos() + 1);
} else { } else {
@ -642,6 +648,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
Paragraph const * ep) Paragraph const * ep)
{ {
RowList::iterator tmprit = cur.row(); RowList::iterator tmprit = cur.row();
ParagraphList::iterator begpit = cur.row()->par();
ParagraphList::iterator endpit(const_cast<Paragraph*>(ep)); ParagraphList::iterator endpit(const_cast<Paragraph*>(ep));
int y = cur.y() - tmprit->baseline(); int y = cur.y() - tmprit->baseline();
@ -711,6 +718,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
} }
if (tmprit != rows().end()) if (tmprit != rows().end())
setHeightOfRow(tmprit); setHeightOfRow(tmprit);
updateCounters(); updateCounters();
} }
@ -799,32 +807,34 @@ string const LyXText::selectionAsString(Buffer const * buffer,
if (!selection.set()) return string(); if (!selection.set()) return string();
// should be const ... // should be const ...
Paragraph * startpar(selection.start.par()); ParagraphList::iterator startpit = selection.start.par();
Paragraph * endpar(selection.end.par()); ParagraphList::iterator endpit = selection.end.par();
pos_type const startpos(selection.start.pos()); pos_type const startpos(selection.start.pos());
pos_type const endpos(selection.end.pos()); pos_type const endpos(selection.end.pos());
if (startpar == endpar) { if (startpit == endpit) {
return startpar->asString(buffer, startpos, endpos, label); return startpit->asString(buffer, startpos, endpos, label);
} }
string result; string result;
// First paragraph in selection // First paragraph in selection
result += startpar->asString(buffer, startpos, startpar->size(), label) + "\n\n"; result += startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
// The paragraphs in between (if any) // The paragraphs in between (if any)
#warning FIXME Why isnt ParagraphList::iterator used here?
// as loop variable.
LyXCursor tmpcur(selection.start); LyXCursor tmpcur(selection.start);
tmpcur.par(tmpcur.par()->next()); tmpcur.par(tmpcur.par()->next());
while (tmpcur.par() != endpar) { while (tmpcur.par() != endpit) {
result += tmpcur.par()->asString(buffer, 0, result += tmpcur.par()->asString(buffer, 0,
tmpcur.par()->size(), tmpcur.par()->size(),
label) + "\n\n"; label) + "\n\n";
tmpcur.par(tmpcur.par()->next()); tmpcur.par(boost::next(tmpcur.par()));
} }
// Last paragraph in selection // Last paragraph in selection
result += endpar->asString(buffer, 0, endpos, label); result += endpit->asString(buffer, 0, endpos, label);
return result; return result;
} }
@ -986,13 +996,13 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
endpar = endpar->next(); endpar = endpar->next();
} }
setUndo(bv(), Undo::EDIT, selection.start.par(), undoendpar); setUndo(bv(), Undo::EDIT, &*selection.start.par(), undoendpar);
Paragraph * tmppar = selection.end.par(); ParagraphList::iterator tmppit = selection.end.par();
while (tmppar != selection.start.par()->previous()) { while (tmppit != boost::prior(selection.start.par())) {
setCursor(tmppar, 0); setCursor(tmppit, 0);
postPaint(cursor.y() - cursor.row()->baseline()); postPaint(cursor.y() - cursor.row()->baseline());
cursor.par()->params().lineTop(line_top); cursor.par()->params().lineTop(line_top);
cursor.par()->params().lineBottom(line_bottom); cursor.par()->params().lineBottom(line_bottom);
@ -1014,7 +1024,7 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
} }
cursor.par()->setLabelWidthString(labelwidthstring); cursor.par()->setLabelWidthString(labelwidthstring);
cursor.par()->params().noindent(noindent); cursor.par()->params().noindent(noindent);
tmppar = cursor.par()->previous(); tmppit = boost::prior(cursor.par());
} }
redoParagraphs(selection.start, endpar); redoParagraphs(selection.start, endpar);
@ -1267,7 +1277,8 @@ void LyXText::insertInset(Inset * inset)
{ {
if (!cursor.par()->insetAllowed(inset->lyxCode())) if (!cursor.par()->insetAllowed(inset->lyxCode()))
return; return;
setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next()); setUndo(bv(), Undo::FINISH, &*cursor.par(),
&*boost::next(cursor.par()));
freezeUndo(); freezeUndo();
cursor.par()->insertInset(cursor.pos(), inset); cursor.par()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly. // Just to rebreak and refresh correctly.
@ -1332,23 +1343,23 @@ void LyXText::cutSelection(bool doclear, bool realcut)
} }
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE,
selection.start.par(), undoendpar); &*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(); endpar = &*selection.end.par();
int pos = selection.end.pos(); int pos = selection.end.pos();
CutAndPaste::cutSelection(selection.start.par(), &endpar, CutAndPaste::cutSelection(&*selection.start.par(), &endpar,
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(); endpar = &*selection.end.par();
int pos = selection.end.pos(); int pos = selection.end.pos();
CutAndPaste::cutSelection(selection.start.par(), &endpar, CutAndPaste::cutSelection(&*selection.start.par(), &endpar,
selection.start.pos(), pos, selection.start.pos(), pos,
bv()->buffer()->params.textclass, bv()->buffer()->params.textclass,
doclear, realcut); doclear, realcut);
@ -1398,7 +1409,8 @@ void LyXText::copySelection()
|| selection.start.pos() < selection.end.pos())) || selection.start.pos() < selection.end.pos()))
selection.start.pos(selection.start.pos() + 1); selection.start.pos(selection.start.pos() + 1);
CutAndPaste::copySelection(selection.start.par(), selection.end.par(), CutAndPaste::copySelection(&*selection.start.par(),
&*selection.end.par(),
selection.start.pos(), selection.end.pos(), selection.start.pos(), selection.end.pos(),
bv()->buffer()->params.textclass); bv()->buffer()->params.textclass);
} }
@ -1411,12 +1423,13 @@ void LyXText::pasteSelection()
return; return;
setUndo(bv(), Undo::INSERT, setUndo(bv(), Undo::INSERT,
cursor.par(), cursor.par()->next()); &*cursor.par(), &*boost::next(cursor.par()));
Paragraph * endpar; Paragraph * endpar;
Paragraph * actpar = cursor.par(); ParagraphList::iterator actpit = cursor.par();
int pos = cursor.pos(); int pos = cursor.pos();
Paragraph * actpar = &*actpit;
CutAndPaste::pasteSelection(&actpar, &endpar, pos, CutAndPaste::pasteSelection(&actpar, &endpar, pos,
bv()->buffer()->params.textclass); bv()->buffer()->params.textclass);
@ -1426,7 +1439,7 @@ void LyXText::pasteSelection()
clearSelection(); clearSelection();
selection.cursor = cursor; selection.cursor = cursor;
setCursor(actpar, pos); setCursor(actpit, pos);
setSelection(); setSelection();
updateCounters(); updateCounters();
} }
@ -1477,21 +1490,22 @@ void LyXText::replaceSelectionWithString(string const & str)
// needed to insert the selection // needed to insert the selection
void LyXText::insertStringAsLines(string const & str) void LyXText::insertStringAsLines(string const & str)
{ {
Paragraph * par = cursor.par(); ParagraphList::iterator pit = cursor.par();
pos_type pos = cursor.pos(); pos_type pos = cursor.pos();
Paragraph * endpar = cursor.par()->next(); ParagraphList::iterator endpit = boost::next(cursor.par());
setCursorParUndo(bv()); setCursorParUndo(bv());
// only to be sure, should not be neccessary // only to be sure, should not be neccessary
clearSelection(); clearSelection();
Paragraph * par = &*pit;
bv()->buffer()->insertStringAsLines(par, pos, current_font, str); bv()->buffer()->insertStringAsLines(par, pos, current_font, str);
redoParagraphs(cursor, endpar); redoParagraphs(cursor, &*endpit);
setCursor(cursor.par(), cursor.pos()); setCursor(cursor.par(), cursor.pos());
selection.cursor = cursor; selection.cursor = cursor;
setCursor(par, pos); setCursor(pit, pos);
setSelection(); setSelection();
} }
@ -1605,7 +1619,7 @@ bool LyXText::updateInset(Inset * inset)
// first check the current paragraph // first check the current paragraph
int pos = cursor.par()->getPositionOfInset(inset); int pos = cursor.par()->getPositionOfInset(inset);
if (pos != -1) { if (pos != -1) {
checkParagraph(cursor.par(), pos); checkParagraph(&*cursor.par(), pos);
return true; return true;
} }
@ -1627,28 +1641,28 @@ bool LyXText::updateInset(Inset * inset)
} }
bool LyXText::setCursor(Paragraph * par, bool LyXText::setCursor(ParagraphList::iterator pit,
pos_type pos, pos_type pos,
bool setfont, bool boundary) bool setfont, bool boundary)
{ {
LyXCursor old_cursor = cursor; LyXCursor old_cursor = cursor;
setCursorIntern(par, pos, setfont, boundary); setCursorIntern(pit, pos, setfont, boundary);
return deleteEmptyParagraphMechanism(old_cursor); return deleteEmptyParagraphMechanism(old_cursor);
} }
void LyXText::setCursor(LyXCursor & cur, Paragraph * par, void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
pos_type pos, bool boundary) pos_type pos, bool boundary)
{ {
lyx::Assert(par); lyx::Assert(pit != ownerParagraphs().end());
cur.par(par); cur.par(pit);
cur.pos(pos); cur.pos(pos);
cur.boundary(boundary); cur.boundary(boundary);
// get the cursor y position in text // get the cursor y position in text
int y = 0; int y = 0;
RowList::iterator row = getRow(par, pos, y); RowList::iterator row = getRow(&*pit, pos, y);
RowList::iterator beg = rows().begin(); RowList::iterator beg = rows().begin();
RowList::iterator old_row = row; RowList::iterator old_row = row;
@ -1660,9 +1674,9 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
Inset * ins; Inset * ins;
if (row != beg && pos && if (row != beg && pos &&
boost::prior(row)->par() == row->par() && boost::prior(row)->par() == row->par() &&
pos < par->size() && pos < pit->size() &&
par->getChar(pos) == Paragraph::META_INSET && pit->getChar(pos) == Paragraph::META_INSET &&
(ins = par->getInset(pos)) && (ins->needFullRow() || ins->display())) (ins = pit->getInset(pos)) && (ins->needFullRow() || ins->display()))
{ {
--row; --row;
y -= row->height(); y -= row->height();
@ -1677,7 +1691,7 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
pos_type last = lastPrintablePos(*this, old_row); pos_type last = lastPrintablePos(*this, old_row);
// None of these should happen, but we're scaredy-cats // None of these should happen, but we're scaredy-cats
if (pos > par->size()) { if (pos > pit->size()) {
lyxerr << "dont like 1 please report" << endl; lyxerr << "dont like 1 please report" << endl;
pos = 0; pos = 0;
cur.pos(0); cur.pos(0);
@ -1701,11 +1715,11 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
cur.ix(int(x)); cur.ix(int(x));
} else } else
cur.ix(cur.x()); cur.ix(cur.x());
/* We take out this for the time being because 1) the redraw code is not /* We take out this for the time being because 1) the redraw code is not
prepared to this yet and 2) because some good policy has yet to be decided prepared to this yet and 2) because some good policy has yet to be decided
while editting: for instance how to act on rows being created/deleted while editting: for instance how to act on rows being created/deleted
because of DEPM. because of DEPM.
*/ */
#if 0 #if 0
//if the cursor is in a visible row, anchor to it //if the cursor is in a visible row, anchor to it
int topy = top_y(); int topy = top_y();
@ -1777,10 +1791,10 @@ float LyXText::getCursorX(RowList::iterator rit,
} }
void LyXText::setCursorIntern(Paragraph * par, void LyXText::setCursorIntern(ParagraphList::iterator pit,
pos_type pos, bool setfont, bool boundary) pos_type pos, bool setfont, bool boundary)
{ {
InsetText * it = static_cast<InsetText *>(par->inInset()); InsetText * it = static_cast<InsetText *>(pit->inInset());
if (it) { if (it) {
if (it != inset_owner) { if (it != inset_owner) {
lyxerr[Debug::INSETS] << "InsetText is " << it lyxerr[Debug::INSETS] << "InsetText is " << it
@ -1806,7 +1820,7 @@ void LyXText::setCursorIntern(Paragraph * par,
} }
} }
setCursor(cursor, par, pos, boundary); setCursor(cursor, pit, pos, boundary);
if (setfont) if (setfont)
setCurrentFont(); setCurrentFont();
} }
@ -1834,10 +1848,10 @@ void LyXText::setCurrentFont()
current_font = current_font =
cursor.par()->getFontSettings(bv()->buffer()->params, pos); cursor.par()->getFontSettings(bv()->buffer()->params, pos);
real_current_font = getFont(bv()->buffer(), cursor.par(), pos); real_current_font = getFont(bv()->buffer(), &*cursor.par(), pos);
if (cursor.pos() == cursor.par()->size() && if (cursor.pos() == cursor.par()->size() &&
isBoundary(bv()->buffer(), cursor.par(), cursor.pos()) && isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()) &&
!cursor.boundary()) { !cursor.boundary()) {
Language const * lang = Language const * lang =
cursor.par()->getParLanguage(bv()->buffer()->params); cursor.par()->getParLanguage(bv()->buffer()->params);
@ -2031,7 +2045,7 @@ void LyXText::cursorLeft(bool internal)
bool boundary = cursor.boundary(); bool boundary = cursor.boundary();
setCursor(cursor.par(), cursor.pos() - 1, true, false); setCursor(cursor.par(), cursor.pos() - 1, true, false);
if (!internal && !boundary && 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); setCursor(cursor.par(), cursor.pos() + 1, true, true);
} else if (cursor.par()->previous()) { // steps into the above paragraph. } else if (cursor.par()->previous()) { // steps into the above paragraph.
Paragraph * par = cursor.par()->previous(); Paragraph * par = cursor.par()->previous();
@ -2048,7 +2062,7 @@ void LyXText::cursorRight(bool internal)
else if (cursor.pos() < cursor.par()->size()) { else if (cursor.pos() < cursor.par()->size()) {
setCursor(cursor.par(), cursor.pos() + 1, true, false); setCursor(cursor.par(), cursor.pos() + 1, true, false);
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 (cursor.par()->next())
setCursor(cursor.par()->next(), 0); setCursor(cursor.par()->next(), 0);
@ -2242,7 +2256,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
deleted = true; deleted = true;
if (old_cursor.row() != rows().begin()) { if (old_cursor.row() != rows().begin()) {
RowList::iterator RowList::iterator
prevrow = boost::prior(old_cursor.row()); prevrow = boost::prior(old_cursor.row());
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;
@ -2253,7 +2267,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
endpar = endpar->next(); endpar = endpar->next();
} }
} }
setUndo(bv(), Undo::DELETE, old_cursor.par(), endpar); setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
cursor = tmpcursor; cursor = tmpcursor;
// delete old row // delete old row
@ -2261,8 +2275,9 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
if (ownerParagraphs().begin() == old_cursor.par()) { if (ownerParagraphs().begin() == old_cursor.par()) {
ownerParagraph(&*boost::next(ownerParagraphs().begin())); ownerParagraph(&*boost::next(ownerParagraphs().begin()));
} }
#warning FIXME Do the proper ParagraphList operation here (Lgb)
// delete old par // delete old par
delete old_cursor.par(); delete &*old_cursor.par();
/* Breakagain the next par. Needed because of /* Breakagain the next par. Needed because of
* the parindent that can occur or dissappear. * the parindent that can occur or dissappear.
@ -2286,7 +2301,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
endpar = endpar->next(); endpar = endpar->next();
} }
} }
setUndo(bv(), Undo::DELETE, old_cursor.par(), endpar); setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
cursor = tmpcursor; cursor = tmpcursor;
// delete old row // delete old row
@ -2295,8 +2310,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
if (ownerParagraphs().begin() == old_cursor.par()) { if (ownerParagraphs().begin() == old_cursor.par()) {
ownerParagraph(&*boost::next(ownerParagraphs().begin())); ownerParagraph(&*boost::next(ownerParagraphs().begin()));
} }
#warning FIXME Do the proper ParagraphList operations here. (Lgb)
delete old_cursor.par(); delete &*old_cursor.par();
/* Breakagain the next par. Needed because of /* Breakagain the next par. Needed because of
the parindent that can occur or dissappear. the parindent that can occur or dissappear.

View File

@ -176,11 +176,11 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
if (res.pos() < res.par()->size() - 1) { if (res.pos() < res.par()->size() - 1) {
res.pos(res.pos() + 1); res.pos(res.pos() + 1);
} else { } else {
res.par(res.par()->next()); res.par(boost::next(res.par()));
res.pos(0); res.pos(0);
} }
} while (res.par() && } while (res.par() != ownerParagraphs().end()&&
!(res.par()->isInset(res.pos()) !(res.par()->isInset(res.pos())
&& (inset = res.par()->getInset(res.pos())) != 0 && (inset = res.par()->getInset(res.pos())) != 0
&& find(codes.begin(), codes.end(), inset->lyxCode()) && find(codes.begin(), codes.end(), inset->lyxCode())
@ -190,7 +190,7 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
res.par()->getInset(res.pos()))->getContents() res.par()->getInset(res.pos()))->getContents()
== contents))); == contents)));
if (res.par()) { if (res.par() != ownerParagraphs().end()) {
setCursor(res.par(), res.pos(), false); setCursor(res.par(), res.pos(), false);
return true; return true;
} }
@ -407,8 +407,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
switch (cmd.action) { switch (cmd.action) {
case LFUN_APPENDIX: { case LFUN_APPENDIX: {
Paragraph * par = cursor.par(); ParagraphList::iterator pit = cursor.par();
bool start = !par->params().startOfAppendix(); bool start = !pit->params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document // ensure that we have only one start_of_appendix in this document
ParagraphList::iterator tmp = ownerParagraphs().begin(); ParagraphList::iterator tmp = ownerParagraphs().begin();
@ -424,8 +424,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
} }
} }
setUndo(bv, Undo::EDIT, par, par->next()); setUndo(bv, Undo::EDIT, &*pit, &*boost::next(pit));
par->params().startOfAppendix(start); pit->params().startOfAppendix(start);
// we can set the refreshing parameters now // we can set the refreshing parameters now
updateCounters(); updateCounters();
@ -874,11 +874,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
} }
case LFUN_PARAGRAPH_SPACING: { case LFUN_PARAGRAPH_SPACING: {
Paragraph * par = cursor.par(); ParagraphList::iterator pit = cursor.par();
Spacing::Space cur_spacing = par->params().spacing().getSpace(); Spacing::Space cur_spacing = pit->params().spacing().getSpace();
float cur_value = 1.0; float cur_value = 1.0;
if (cur_spacing == Spacing::Other) if (cur_spacing == Spacing::Other)
cur_value = par->params().spacing().getValue(); cur_value = pit->params().spacing().getValue();
istringstream is(cmd.argument.c_str()); istringstream is(cmd.argument.c_str());
string tmp; string tmp;
@ -908,7 +908,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
<< cmd.argument << endl; << cmd.argument << endl;
} }
if (cur_spacing != new_spacing || cur_value != new_value) { if (cur_spacing != new_spacing || cur_value != new_value) {
par->params().spacing(Spacing(new_spacing, new_value)); pit->params().spacing(Spacing(new_spacing, new_value));
redoParagraph(); redoParagraph();
update(); update();
} }
@ -1123,14 +1123,14 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
if (!change_layout && selection.set() && if (!change_layout && selection.set() &&
selection.start.par() != selection.end.par()) selection.start.par() != selection.end.par())
{ {
Paragraph * spar = selection.start.par(); ParagraphList::iterator spit = selection.start.par();
Paragraph * epar = selection.end.par()->next(); ParagraphList::iterator epit = boost::next(selection.end.par());
while (spar != epar) { while (spit != epit) {
if (spar->layout()->name() != current_layout) { if (spit->layout()->name() != current_layout) {
change_layout = true; change_layout = true;
break; break;
} }
spar = spar->next(); ++spit;
} }
} }
if (change_layout) { if (change_layout) {
@ -1182,21 +1182,21 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
} }
case LFUN_QUOTE: { case LFUN_QUOTE: {
Paragraph const * par = cursor.par(); ParagraphList::iterator pit = cursor.par();
lyx::pos_type pos = cursor.pos(); lyx::pos_type pos = cursor.pos();
char c; char c;
if (!pos) if (!pos)
c = ' '; c = ' ';
else if (par->isInset(pos - 1) && par->getInset(pos - 1)->isSpace()) else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
c = ' '; c = ' ';
else else
c = par->getChar(pos - 1); c = pit->getChar(pos - 1);
bv->hideCursor(); bv->hideCursor();
LyXLayout_ptr const & style = par->layout(); LyXLayout_ptr const & style = pit->layout();
if (style->pass_thru || if (style->pass_thru ||
par->getFontSettings(bv->buffer()->params, pit->getFontSettings(bv->buffer()->params,
pos).language()->lang() == "hebrew" || pos).language()->lang() == "hebrew" ||
(!bv->insertInset(new InsetQuotes(c, bv->buffer()->params)))) (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\"")); bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
@ -1279,7 +1279,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
Inset * tli = bv->theLockingInset(); Inset * tli = bv->theLockingInset();
LyXCursor cursor = bv->text->cursor; LyXCursor cursor = bv->text->cursor;
LyXFont font = bv->text->getFont(bv->buffer(), LyXFont font = bv->text->getFont(bv->buffer(),
cursor.par(), cursor.pos()); &*cursor.par(), cursor.pos());
int width = tli->width(bv, font); int width = tli->width(bv, font);
int inset_x = font.isVisibleRightToLeft() int inset_x = font.isVisibleRightToLeft()
? cursor.ix() - width : cursor.ix(); ? cursor.ix() - width : cursor.ix();

View File

@ -9,7 +9,7 @@
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
* *
* This file contains some utility functions for actually mutating * This file contains some utility functions for actually mutating
* the text contents of a document * the text contents of a document
*/ */
#include <config.h> #include <config.h>
@ -23,7 +23,7 @@ using lyx::pos_type;
void transposeChars(LyXText & text, LyXCursor const & cursor) void transposeChars(LyXText & text, LyXCursor const & cursor)
{ {
Paragraph * tmppar = cursor.par(); Paragraph * tmppar = &*cursor.par();
setUndo(text.bv(), Undo::FINISH, tmppar, tmppar->next()); setUndo(text.bv(), Undo::FINISH, tmppar, tmppar->next());

View File

@ -486,6 +486,6 @@ void setRedo(BufferView * bv, Undo::undo_kind kind,
void setCursorParUndo(BufferView * bv) void setCursorParUndo(BufferView * bv)
{ {
setUndo(bv, Undo::FINISH, bv->text->cursor.par(), setUndo(bv, Undo::FINISH, &*bv->text->cursor.par(),
bv->text->cursor.par()->next()); bv->text->cursor.par()->next());
} }