diff --git a/src/BufferView.C b/src/BufferView.C index 6e1ef133ef..016f495ae5 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 04f1f311a3..f8f8fd4bbc 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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; } diff --git a/src/ChangeLog b/src/ChangeLog index dad0094c64..4a3ab61726 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ + +2003-06-12 André Pönitz + + * 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 * lyx_main.C: diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 4a220f144d..0fbb7848ab 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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; diff --git a/src/buffer.C b/src/buffer.C index 9b7ceb0e82..24b8d16677 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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(this)->par_iterator_begin()); - ParIterator end(const_cast(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; diff --git a/src/frontends/controllers/ControlErrorList.C b/src/frontends/controllers/ControlErrorList.C index 4613989f7b..f7eab0039a 100644 --- a/src/frontends/controllers/ControlErrorList.C +++ b/src/frontends/controllers/ControlErrorList.C @@ -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(); diff --git a/src/iterators.C b/src/iterators.C index 5bd591273f..5865272ff1 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -47,7 +47,7 @@ public: ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl) : pit(p), plist(&pl) { - if (p != const_cast(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(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(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; } diff --git a/src/iterators.h b/src/iterators.h index f3153ad8e6..dcb896acc3 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -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 diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 332f0eb267..bf551cd8b5 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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(); diff --git a/src/text.C b/src/text.C index bcc7c640e0..02761b87e3 100644 --- a/src/text.C +++ b/src/text.C @@ -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)); + int const left = leftMargin(row); int x = left; // pixel width since last breakpoint diff --git a/src/toc.C b/src/toc.C index 5709cf8894..de0ce39226 100644 --- a/src/toc.C +++ b/src/toc.C @@ -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 =