return a Paragraph & from ParIterator::operator*()

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7161 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-06-12 11:09:55 +00:00
parent ba01e80b7c
commit 596dec6592
11 changed files with 71 additions and 49 deletions

View File

@ -379,7 +379,7 @@ void BufferView::setCursorFromRow(int row)
texrowpar = text->ownerParagraphs().begin();
tmppos = 0;
} else {
texrowpar = *buffer()->getParFromID(tmpid);
texrowpar = buffer()->getParFromID(tmpid).pit();
}
text->setCursor(texrowpar, tmppos);
}
@ -645,7 +645,7 @@ bool BufferView::ChangeInsets(Inset::Code code,
// The test it.size()==1 was needed to prevent crashes.
// How to set the cursor corretly when it.size()>1 ??
if (it.size() == 1) {
text->setCursorIntern(*it, 0);
text->setCursorIntern(it.pit(), 0);
text->redoParagraphs(text->cursor,
boost::next(text->cursor.par()));
text->fullRebreak();

View File

@ -651,8 +651,8 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
if (par == buffer_->par_iterator_end())
return;
bv_->text->setCursor(*par,
min((*par)->size(), saved_positions[i].par_pos));
bv_->text->setCursor(par.pit(),
min(par->size(), saved_positions[i].par_pos));
update(BufferView::SELECT);
if (i > 0)
@ -861,9 +861,8 @@ void BufferView::Pimpl::trackChanges()
if (!tracking) {
ParIterator const end = buf->par_iterator_end();
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
(*it)->trackChanges();
}
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
it->trackChanges();
buf->params.tracking_changes = true;
// we cannot allow undos beyond the freeze point
@ -881,9 +880,8 @@ void BufferView::Pimpl::trackChanges()
}
ParIterator const end = buf->par_iterator_end();
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) {
(*it)->untrackChanges();
}
for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
it->untrackChanges();
buf->params.tracking_changes = false;
}

View File

@ -1,3 +1,15 @@
2003-06-12 André Pönitz <poenitz@gmx.net>
* BufferView.C:
* BufferView_pimpl.C:
* CutAndPaste.C:
* buffer.C:
* iterators.[Ch]:
* lyxfunc.C:
* text.C:
* toc.C: Return a Paragraph & for ParIterator::operator*()
2003-06-11 John Levon <levon@movementarian.org>
* lyx_main.C:

View File

@ -377,25 +377,24 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
LyXTextClass const & tclass2 = textclasslist[c2];
ParIterator end = ParIterator(pars.end(), pars);
for (ParIterator it = ParIterator(pars.begin(), pars); it != end; ++it) {
Paragraph * par = &*(*it);
string const name = par->layout()->name();
string const name = it->layout()->name();
bool hasLayout = tclass2.hasLayout(name);
if (hasLayout)
par->layout(tclass2[name]);
it->layout(tclass2[name]);
else
par->layout(tclass2.defaultLayout());
it->layout(tclass2.defaultLayout());
if (!hasLayout && name != tclass1.defaultLayoutName()) {
++ret;
string const s = bformat(
_("Layout had to be changed from\n%1$s to %2$s\n"
"because of class conversion from\n%3$s to %4$s"),
name, par->layout()->name(), tclass1.name(), tclass2.name());
name, it->layout()->name(), tclass1.name(), tclass2.name());
// To warn the user that something had to be done.
errorlist.push_back(ErrorItem("Changed Layout", s,
par->id(), 0,
par->size()));
it->id(), 0,
it->size()));
}
}
return ret;

View File

@ -2134,7 +2134,7 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
ParIterator end = par_iterator_end();
for (ParIterator it = par_iterator_begin(); it != end; ++it)
(*it)->changeLanguage(params, from, to);
it->changeLanguage(params, from, to);
}
@ -2148,7 +2148,7 @@ bool Buffer::isMultiLingual()
{
ParIterator end = par_iterator_end();
for (ParIterator it = par_iterator_begin(); it != end; ++it)
if ((*it)->isMultiLingual(params))
if (it->isMultiLingual(params))
return true;
return false;
@ -2195,7 +2195,7 @@ ParIterator Buffer::getParFromID(int id) const
}
for (; it != end; ++it)
if ((*it)->id() == id)
if (it->id() == id)
return it;
return end;
@ -2204,8 +2204,8 @@ ParIterator Buffer::getParFromID(int id) const
bool Buffer::hasParWithID(int id) const
{
ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
ParConstIterator it = par_iterator_begin();
ParConstIterator end = par_iterator_end();
if (id < 0) {
// John says this is called with id == -1 from undo
@ -2214,7 +2214,7 @@ bool Buffer::hasParWithID(int id) const
}
for (; it != end; ++it)
if ((*it)->id() == id)
if (it->id() == id)
return true;
return false;

View File

@ -54,15 +54,12 @@ string const & ControlErrorList::name()
void ControlErrorList::goTo(int item)
{
BufferView * const bv = kernel().bufferview();
Buffer * const buf = kernel().buffer();
ErrorItem const & err = errorlist_[item];
if (err.par_id == -1)
return;
Buffer * const buf = kernel().buffer();
ParIterator pit = buf->getParFromID(err.par_id);
if (pit == buf->par_iterator_end()) {
@ -72,14 +69,15 @@ void ControlErrorList::goTo(int item)
int range = err.pos_end - err.pos_start;
if (err.pos_end > (*pit)->size() || range <= 0)
range = (*pit)->size() - err.pos_start;
if (err.pos_end > pit->size() || range <= 0)
range = pit->size() - err.pos_start;
// Now make the selection.
BufferView * const bv = kernel().bufferview();
bv->insetUnlock();
bv->toggleSelection();
bv->text->clearSelection();
bv->text->setCursor(*pit, err.pos_start);
bv->text->setCursor(pit.pit(), err.pos_start);
bv->text->setSelectionRange(range);
bv->toggleSelection(false);
bv->fitCursor();

View File

@ -47,7 +47,7 @@ public:
ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl)
: pit(p), plist(&pl)
{
if (p != const_cast<ParagraphList&>(pl).end()) {
if (p != pl.end()) {
it.reset(p->insetlist.begin());
}
}
@ -129,7 +129,7 @@ ParIterator & ParIterator::operator++()
}
// Try to go to the next paragarph
if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
if (next(p.pit) != p.plist->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
@ -145,7 +145,13 @@ ParIterator & ParIterator::operator++()
}
ParagraphList::iterator ParIterator::operator*() const
Paragraph & ParIterator::operator*() const
{
return *pimpl_->positions.back().pit;
}
ParagraphList::iterator ParIterator::pit() const
{
return pimpl_->positions.back().pit;
}
@ -247,7 +253,7 @@ ParConstIterator & ParConstIterator::operator++()
}
// Try to go to the next paragarph
if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
if (next(p.pit) != p.plist->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
@ -264,13 +270,19 @@ ParConstIterator & ParConstIterator::operator++()
}
ParagraphList::iterator ParConstIterator::operator*() const
Paragraph const & ParConstIterator::operator*() const
{
return *pimpl_->positions.back().pit;
}
ParagraphList::const_iterator ParConstIterator::pit() const
{
return pimpl_->positions.back().pit;
}
ParagraphList::iterator ParConstIterator::operator->() const
ParagraphList::const_iterator ParConstIterator::operator->() const
{
return pimpl_->positions.back().pit;
}

View File

@ -29,12 +29,14 @@ public:
///
ParIterator & operator++();
///
ParagraphList::iterator operator*() const;
Paragraph & operator*() const;
///
ParagraphList::iterator operator->() const;
///
ParagraphList::iterator outerPar() const;
///
ParagraphList::iterator pit() const;
///
ParagraphList & plist() const;
///
size_t size() const;
@ -64,11 +66,13 @@ public:
///
ParConstIterator & operator++();
///
ParagraphList::iterator operator*() const;
ParagraphList::const_iterator pit() const;
///
ParagraphList::iterator operator->() const;
Paragraph const & operator*() const;
///
ParagraphList::const_iterator operator->() const;
///
/// depth of nesting
size_t size() const;
///
friend

View File

@ -1363,18 +1363,18 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
<< id << ']' << endl;
break;
} else {
lyxerr[Debug::INFO] << "Paragraph " << (*par)->id()
lyxerr[Debug::INFO] << "Paragraph " << par->id()
<< " found." << endl;
}
if (view()->theLockingInset())
view()->unlockInset(view()->theLockingInset());
if ((*par)->inInset()) {
if (par->inInset()) {
FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
(*par)->inInset()->localDispatch(cmd);
par->inInset()->localDispatch(cmd);
}
// Set the cursor
view()->getLyXText()->setCursor(*par, 0);
view()->getLyXText()->setCursor(par.pit(), 0);
view()->switchKeyMap();
owner->view_state_changed();

View File

@ -770,8 +770,7 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par)
};
pos_type
LyXText::rowBreakPoint(Row const & row) const
pos_type LyXText::rowBreakPoint(Row const & row) const
{
ParagraphList::iterator pit = row.par();
@ -800,7 +799,7 @@ LyXText::rowBreakPoint(Row const & row) const
// or the end of the par, then choose the possible break
// nearest that.
int const left = leftMargin(const_cast<Row&>(row));
int const left = leftMargin(row);
int x = left;
// pixel width since last breakpoint

View File

@ -94,8 +94,8 @@ TocList const getTocList(Buffer const * buf)
// For each paragraph, traverse its insets and look for
// FLOAT_CODE or WRAP_CODE
InsetList::iterator it = pit->insetlist.begin();
InsetList::iterator end = pit->insetlist.end();
InsetList::const_iterator it = pit->insetlist.begin();
InsetList::const_iterator end = pit->insetlist.end();
for (; it != end; ++it) {
if (it->inset->lyxCode() == Inset::FLOAT_CODE) {
InsetFloat * il =