]> git.lyx.org Git - features.git/commitdiff
return a ParIterator from getParFromID
authorAndré Pönitz <poenitz@gmx.net>
Thu, 22 May 2003 08:01:41 +0000 (08:01 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 22 May 2003 08:01:41 +0000 (08:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6996 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView_pimpl.C
src/ChangeLog
src/buffer.C
src/buffer.h
src/frontends/controllers/ControlErrorList.C
src/iterators.C
src/iterators.h
src/lyxfunc.C
src/undo_funcs.C

index 730e30ac974ef5a9527673979e38e31462831e91..fc1ac3a97ea110087fc9dbf59f67bd016a17aa29 100644 (file)
@@ -509,13 +509,13 @@ void BufferView::setCursorFromRow(int row)
 
        buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
 
-       Paragraph * texrowpar;
+       ParagraphList::iterator texrowpar;
 
        if (tmpid == -1) {
-               texrowpar = &*text->ownerParagraphs().begin();
+               texrowpar = text->ownerParagraphs().begin();
                tmppos = 0;
        } else {
-               texrowpar = &*buffer()->getParFromID(tmpid);
+               texrowpar = *buffer()->getParFromID(tmpid);
        }
        text->setCursor(texrowpar, tmppos);
 }
index 9787625304cd1e21c508de1ebdcdbe9a2917a99a..7a7790b3da3cdd5049046a4916b030d5eb8e095a 100644 (file)
@@ -642,12 +642,12 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
                if (b != 0) buffer(b);
        }
 
-       Paragraph * par = &*buffer_->getParFromID(saved_positions[i].par_id);
-       if (!par)
+       ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
+       if (par == buffer_->par_iterator_end())
                return;
 
-       bv_->text->setCursor(par,
-                            min(par->size(), saved_positions[i].par_pos));
+       bv_->text->setCursor(*par,
+                            min((*par)->size(), saved_positions[i].par_pos));
 
        update(BufferView::SELECT);
        if (i > 0)
index cae91f9913854c252c93bf6b043130916967ef6d..dc95b4fadacb2011f10e73d89661ef415b7f2528 100644 (file)
@@ -1,3 +1,15 @@
+
+2003-05-22  André Pönitz  <poenitz@gmx.net>
+
+       * BufferView.C:
+       * BufferView_pimpl.C:
+       * buffer.[Ch]:  
+       * lyxfunc.C:
+       * undo_funcs.C: return a ParIterator from getParFromID.
+
+       * iterators.[Ch]: add two const's
+
+
 2003-05-21  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * toc.C (getTocList): adjust
index 3bb3d789518e390cf590a928b0e9705589609346..e8c8f9de84e2c2f8d5391ec025a81c4c7f6b058f 100644 (file)
@@ -2203,7 +2203,7 @@ Inset * Buffer::getInsetFromID(int id_arg) const
 }
 
 
-ParagraphList::iterator Buffer::getParFromID(int id) const
+ParIterator Buffer::getParFromID(int id) const
 {
 #warning FIXME: const correctness! (Andre)
        ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
@@ -2213,18 +2213,14 @@ ParagraphList::iterator Buffer::getParFromID(int id) const
        if (id < 0) {
                // John says this is called with id == -1 from undo
                lyxerr << "getParFromID(), id: " << id << endl;
-               return 0;
+               return end;
        }
 
-       for (; it != end; ++it) {
-               // go on then, show me how to remove
-               // the cast
-               if ((*it)->id() == id) {
-                       return *it;
-               }
-       }
+       for (; it != end; ++it)
+               if ((*it)->id() == id)
+                       return it;
 
-       return 0;
+       return end;
 }
 
 
index c6a2cb8901e50c1fffdd4e708735c2d690200b12..c7dd087ba787445f558ed4da516239e0337976c7 100644 (file)
@@ -23,6 +23,7 @@
 #include "ParagraphList.h"
 #include "paragraph.h"
 #include "author.h"
+#include "iterators.h"
 
 #include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
@@ -122,7 +123,7 @@ public:
        void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
                                 LyXFont const &, string const &);
        ///
-       ParagraphList::iterator getParFromID(int id) const;
+       ParIterator getParFromID(int id) const;
        /// do we have a paragraph with this id?
        bool hasParWithID(int id) const;
 
index 128dc2334dbb4d3d8647d9b4905708ee30a271c7..4613989f7ba2d95f443e16151aa8e24de99142b0 100644 (file)
@@ -63,23 +63,23 @@ void ControlErrorList::goTo(int item)
        if (err.par_id == -1)
                return;
 
-       ParagraphList::iterator pit = buf->getParFromID(err.par_id);
+       ParIterator pit = buf->getParFromID(err.par_id);
 
-       if (pit == bv->text->ownerParagraphs().end()) {
+       if (pit == buf->par_iterator_end()) {
                lyxerr << "par id not found" << endl;
                return;
        }
 
        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.
        bv->insetUnlock();
        bv->toggleSelection();
        bv->text->clearSelection();
-       bv->text->setCursor(pit, err.pos_start);
+       bv->text->setCursor(*pit, err.pos_start);
        bv->text->setSelectionRange(range);
        bv->toggleSelection(false);
        bv->fitCursor();
index 7f067728d1e14549f9a3740fede79f14851af54b..aa89cba5a83f3dc63daf9729faf395bd04c47bba 100644 (file)
@@ -136,13 +136,13 @@ ParIterator & ParIterator::operator++()
 }
 
 
-ParagraphList::iterator ParIterator::operator*()
+ParagraphList::iterator ParIterator::operator*() const
 {
        return pimpl_->positions.top().pit;
 }
 
 
-ParagraphList::iterator ParIterator::operator->()
+ParagraphList::iterator ParIterator::operator->() const
 {
        return pimpl_->positions.top().pit;
 }
@@ -243,13 +243,13 @@ ParConstIterator & ParConstIterator::operator++()
 }
 
 
-ParagraphList::iterator ParConstIterator::operator*()
+ParagraphList::iterator ParConstIterator::operator*() const
 {
        return pimpl_->positions.top().pit;
 }
 
 
-ParagraphList::iterator ParConstIterator::operator->()
+ParagraphList::iterator ParConstIterator::operator->() const
 {
        return pimpl_->positions.top().pit;
 }
index 9bc322ec6bae490e301ed3a63c2191de6711a030..5cca3f717d6dc3e2fa4de25696a0a0467960c646 100644 (file)
@@ -27,9 +27,9 @@ public:
        ///
        ParIterator & operator++();
        ///
-       ParagraphList::iterator operator*();
+       ParagraphList::iterator operator*() const;
        ///
-       ParagraphList::iterator operator->();
+       ParagraphList::iterator operator->() const;
        ///
        size_t size() const;
        ///
@@ -58,10 +58,9 @@ public:
        ///
        ParConstIterator & operator++();
        ///
-       ParagraphList::iterator operator*();
-
+       ParagraphList::iterator operator*() const;
        ///
-       ParagraphList::iterator operator->();
+       ParagraphList::iterator operator->() const;
 
        ///
        size_t size() const;
index 7cc5f9424c989ecf62bac80749bd27d90d87fe95..c00c24694b3c0a6e90e34267f35364b1aa880c27 100644 (file)
@@ -1353,24 +1353,24 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 
                int id;
                istr >> id;
-               Paragraph * par = &*owner->buffer()->getParFromID(id);
-               if (par == 0) {
+               ParIterator par = owner->buffer()->getParFromID(id);
+               if (par == owner->buffer()->par_iterator_end()) {
                        lyxerr[Debug::INFO] << "No matching paragraph found! ["
                                            << 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, 0);
                view()->switchKeyMap();
                owner->view_state_changed();
 
index 93ad12cfaf78035c35551c2f6ad962249e2dce96..3d3f659c2e8c29d60859c3fd702688c0eef94629 100644 (file)
@@ -78,12 +78,13 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
 {
        Buffer * b = bv->buffer();
 
-       Paragraph * const before = &*b->getParFromID(undo.number_of_before_par);
-       Paragraph * const behind = &*b->getParFromID(undo.number_of_behind_par);
+       ParIterator const before = b->getParFromID(undo.number_of_before_par);
+       ParIterator const behind = b->getParFromID(undo.number_of_behind_par);
+       ParIterator const end    = b->par_iterator_end();
 
        // If there's no before take the beginning
        // of the document for redoing.
-       if (!before) {
+       if (before == end) {
                LyXText * t = bv->text;
                int num = undo.number_of_inset_id;
                if (undo.number_of_inset_id >= 0) {
@@ -100,7 +101,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
        // Set the right(new) inset-owner of the paragraph if there is any. 
        if (!undo.pars.empty()) {
                Inset * in = 0;
-               if (before)
+               if (before != end)
                        in = before->inInset();
                else if (undo.number_of_inset_id >= 0)
                        in = bv->buffer()->getInsetFromID(undo.number_of_inset_id);
@@ -112,17 +113,20 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
        vector<Paragraph *> deletelist;
 
        // Now add old paragraphs to be deleted.
-       if (before != behind || (!behind && !before)) {
-               Paragraph * deletepar;
-               if (before)
-                       deletepar = before->next();
-               else
-                       deletepar = &undoParagraphs(bv, undo.number_of_inset_id).front();
+       if (before != behind || (behind == end && before == end)) {
+               ParagraphList::iterator deletepar;
+               if (before != end) {
+                       deletepar = *before;
+                       ++deletepar;
+               } else {
+                       deletepar = undoParagraphs(bv, undo.number_of_inset_id).begin();
+               }
                // this surprisingly fills the undo! (Andre')
                size_t par = 0;
-               while (deletepar && deletepar != behind) {
-                       deletelist.push_back(deletepar);
-                       deletepar = deletepar->next();
+               //while (deletepar && deletepar != *behind) {
+               while (deletepar != *behind) {
+                       deletelist.push_back(&*deletepar);
+                       ++deletepar;
 
                        // A memory optimization for edit:
                        // Only layout information
@@ -141,21 +145,21 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
 
        // Thread the end of the undo onto the par in front if any.
        if (!undo.pars.empty()) {
-               undo.pars.back()->next(behind);
-               if (behind)
-                       behind->previous(undo.pars.back());
+               undo.pars.back()->next(&**behind);
+               if (behind != end)
+                       (&**behind)->previous(undo.pars.back());
        }
 
        // Put the new stuff in the list if there is one.
        Paragraph * undopar = undo.pars.empty() ? 0 : undo.pars.front();
        if (!undo.pars.empty()) {
-               undo.pars.front()->previous(before);
-               if (before)
-                       before->next(undopar);
+               undo.pars.front()->previous(&**before);
+               if (before != end)
+                       (&**before)->next(undopar);
                else {
                        int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
-                       Paragraph * op = &*bv->buffer()->getParFromID(id);
-                       if (op && op->inInset()) {
+                       ParIterator op = bv->buffer()->getParFromID(id);
+                       if (op != end && op->inInset()) {
                                static_cast<InsetText*>(op->inInset())->paragraph(undopar);
                        } else {
                                bv->buffer()->paragraphs.set(undopar);
@@ -165,27 +169,27 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                // We enter here on DELETE undo operations where we
                // have to substitue the second paragraph with the
                // first if the removed one is the first.
-               if (!before && behind) {
+               if (before == end && behind != end) {
                        int id = undoParagraphs(bv, undo.number_of_inset_id).front().id();
-                       Paragraph * op = &*bv->buffer()->getParFromID(id);
-                       if (op && op->inInset()) {
-                               static_cast<InsetText*>(op->inInset())->paragraph(behind);
+                       ParIterator op = bv->buffer()->getParFromID(id);
+                       if (op != end && op->inInset()) {
+                               static_cast<InsetText*>(op->inInset())->paragraph(&**behind);
                        } else {
-                               bv->buffer()->paragraphs.set(behind);
+                               bv->buffer()->paragraphs.set(&**behind);
                        }
-                       undopar = behind;
+                       undopar = &**behind;
                }
        }
 
 
        // Set the cursor for redoing.
        // If we have a par before the undopar.
-       if (before) {
+       if (before != end) {
                Inset * it = before->inInset();
                if (it)
-                       it->getLyXText(bv)->setCursorIntern(before, 0);
+                       it->getLyXText(bv)->setCursorIntern(*before, 0);
                else
-                       bv->text->setCursorIntern(before, 0);
+                       bv->text->setCursorIntern(*before, 0);
        }
 
 // we are not ready for this we cannot set the cursor for a paragraph
@@ -200,24 +204,28 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
        }
 #endif
 
-       Paragraph * endpar = 0;
-
-       // Calculate the endpar for redoing the paragraphs.
-       if (behind)
-               endpar = behind->next();
-
        UpdatableInset * it = 0;
        if (undopar)
                it = static_cast<UpdatableInset*>(undopar->inInset());
+
+       LyXText * text = it ? it->getLyXText(bv) : bv->text;
+
+       ParagraphList::iterator endpar = text->ownerParagraphs().end();
+
+       // Calculate the endpar for redoing the paragraphs.
+       if (behind != end) {
+               endpar = *behind;
+               ++endpar;
+       }
+
+       text->redoParagraphs(text->cursor, endpar);
+       ParIterator tmppar =
+               bv->buffer()->getParFromID(undo.number_of_cursor_par);
+
        if (it) {
-               it->getLyXText(bv)->redoParagraphs(
-                                                  it->getLyXText(bv)->cursor,
-                                                  endpar);
-               Paragraph * tmppar =
-                       &*bv->buffer()->getParFromID(undo.number_of_cursor_par);
-               if (tmppar) {
-                       it = static_cast<UpdatableInset*>(tmppar->inInset());
+               if (tmppar != end) {
                        LyXText * t;
+                       Inset * it = tmppar->inInset();
                        if (it) {
                                FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
                                it->localDispatch(cmd);
@@ -225,7 +233,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                        } else {
                                t = bv->text;
                        }
-                       t->setCursorIntern(tmppar, undo.cursor_pos);
+                       t->setCursorIntern(*tmppar, undo.cursor_pos);
                        // Clear any selection and set the selection
                        // cursor for an evt. new selection.
                        t->clearSelection();
@@ -237,10 +245,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                bv->text->setCursorIntern(bv->text->cursor.par(),
                                          bv->text->cursor.pos());
        } else {
-               bv->text->redoParagraphs(bv->text->cursor, endpar);
-               Paragraph * tmppar =
-                       &*bv->buffer()->getParFromID(undo.number_of_cursor_par);
-               if (tmppar) {
+               if (tmppar != end) {
                        LyXText * t;
                        Inset * it = tmppar->inInset();
                        if (it) {
@@ -250,7 +255,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
                        } else {
                                t = bv->text;
                        }
-                       t->setCursorIntern(tmppar, undo.cursor_pos);
+                       t->setCursorIntern(*tmppar, undo.cursor_pos);
                        // Clear any selection and set the selection
                        // cursor for an evt. new selection.
                        t->clearSelection();
@@ -381,17 +386,25 @@ bool textUndoOrRedo(BufferView * bv,
        finishUndo();
 
        if (!undo_frozen) {
-               Paragraph * first = &*b->getParFromID(undo->number_of_before_par);
-               if (first && first->next())
-                       first = first->next();
-               else if (!first)
-                       first = &*undoParagraphs(bv, undo->number_of_inset_id).begin();
+/*
+               ParIterator p = b->getParFromID(undo->number_of_before_par);
+               bool ok = false;
+               ParagraphList::iterator first;
+               // default constructed?
+               ParIterator const end = b->par_iterator_end();
+               if (p != end) {
+                       first = p.par();
+                       if (first->next())
+                               first = first->next();
+               } else
+                       first = undoParagraphs(bv, undo->number_of_inset_id).begin();
                if (first) {
                        shared_ptr<Undo> u;
-                       if (createUndo(bv, undo->kind, first,
-                                            b->getParFromID(undo->number_of_behind_par), u))
+                       ParIterator behind = b->getParFromID(undo->number_of_behind_par);
+                       if (createUndo(bv, undo->kind, first, behind.par(), u))
                                otherstack.push(u);
                }
+*/
        }
 
        // Now we can unlock the inset for saftey because the inset