]> git.lyx.org Git - lyx.git/blobdiff - src/dociterator.C
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[lyx.git] / src / dociterator.C
index 264df011274a88580ff74a1a3171750d53e0fdd7..2e89e4503a84905c2e1b257a6a16f06cbe7b51b5 100644 (file)
@@ -3,8 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author unknown
- * \author Lars Gullik Bjønnes
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 using std::endl;
 
 
-//we could be able to get rid of this if only every BufferView were
-//associated to a buffer on construction
-DocIterator::DocIterator() : inset_(0)
+// We could be able to get rid of this if only every BufferView were
+// associated to a buffer on construction.
+DocIterator::DocIterator()
+       : inset_(0)
+{}
+
+
+DocIterator::DocIterator(InsetBase & inset)
+       : inset_(&inset)
 {}
 
 
@@ -47,15 +52,15 @@ DocIterator doc_iterator_end(InsetBase & inset)
 }
 
 
-DocIterator::DocIterator(InsetBase & inset) : inset_(&inset)
-{}
-
-
 InsetBase * DocIterator::nextInset()
 {
        BOOST_ASSERT(!empty());
        if (pos() == lastpos())
                return 0;
+       if (pos() > lastpos()) {
+               lyxerr << "Should not happen, but it does. " << endl;
+               return 0;
+       }
        if (inMathed())
                return nextAtom().nucleus();
        return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0;
@@ -103,6 +108,7 @@ MathAtom & DocIterator::prevAtom()
 MathAtom const & DocIterator::nextAtom() const
 {
        BOOST_ASSERT(!empty());
+       //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
@@ -111,6 +117,7 @@ MathAtom const & DocIterator::nextAtom() const
 MathAtom & DocIterator::nextAtom()
 {
        BOOST_ASSERT(!empty());
+       //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
@@ -139,17 +146,17 @@ Paragraph const & DocIterator::paragraph() const
 
 Row & DocIterator::textRow()
 {
-       return *paragraph().getRow(pos());
+       return paragraph().getRow(pos());
 }
 
 
 Row const & DocIterator::textRow() const
 {
-       return *paragraph().getRow(pos());
+       return paragraph().getRow(pos());
 }
 
 
-DocIterator::par_type DocIterator::lastpar() const
+DocIterator::pit_type DocIterator::lastpit() const
 {
        return inMathed() ? 0 : text()->paragraphs().size() - 1;
 }
@@ -161,18 +168,6 @@ DocIterator::pos_type DocIterator::lastpos() const
 }
 
 
-DocIterator::row_type DocIterator::crow() const
-{
-       return paragraph().row(pos());
-}
-
-
-DocIterator::row_type DocIterator::lastcrow() const
-{
-       return paragraph().rows.size();
-}
-
-
 DocIterator::idx_type DocIterator::lastidx() const
 {
        return top().lastidx();
@@ -301,19 +296,19 @@ void DocIterator::forwardPos()
        //lyxerr << "... no next pos" << endl;
 
        // otherwise move on one paragraph if possible
-       if (top.par() < lastpar()) {
+       if (top.pit() < lastpit()) {
                //lyxerr << "... next par" << endl;
-               ++top.par();
+               ++top.pit();
                top.pos() = 0;
                return;
        }
-       //lyxerr << "... no next par" << endl;
+       //lyxerr << "... no next pit" << endl;
 
        // otherwise try to move on one cell if possible
        if (top.idx() < lastidx()) {
                //lyxerr << "... next idx" << endl;
                ++top.idx();
-               top.par() = 0;
+               top.pit() = 0;
                top.pos() = 0;
                return;
        }
@@ -365,7 +360,7 @@ void DocIterator::backwardPos()
        if (empty()) {
                push_back(CursorSlice(*inset_));
                back().idx() = lastidx();
-               back().par() = lastpar();
+               back().pit() = lastpit();
                back().pos() = lastpos();
                return;
        }
@@ -374,13 +369,13 @@ void DocIterator::backwardPos()
 
        if (top.pos() != 0) {
                --top.pos();
-       } else if (top.par() != 0) {
-               --top.par();
+       } else if (top.pit() != 0) {
+               --top.pit();
                top.pos() = lastpos();
                return;
        } else if (top.idx() != 0) {
                --top.idx();
-               top.par() = lastpar();
+               top.pit() = lastpit();
                top.pos() = lastpos();
                return;
        } else {
@@ -401,12 +396,23 @@ void DocIterator::backwardPos()
        if (n && n->isActive()) {
                push_back(CursorSlice(*n));
                back().idx() = lastidx();
-               back().par() = lastpar();
+               back().pit() = lastpit();
                back().pos() = lastpos();
        }
 }
 
 
+bool DocIterator::hasPart(DocIterator const & it) const
+{
+       // it can't be a part if it is larger
+       if (it.size() > size())
+               return false;
+
+       // as inset adresses are the 'last' level
+       return &it.back().inset() == &operator[](it.size() - 1).inset();
+}
+
+
 std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
 {
        for (size_t i = 0, n = dit.size(); i != n; ++i)
@@ -426,13 +432,20 @@ StableDocIterator::StableDocIterator(const DocIterator & dit)
 }
 
 
-DocIterator
-StableDocIterator::asDocIterator(InsetBase * inset) const
+DocIterator StableDocIterator::asDocIterator(InsetBase * inset) const
 {
        // this function re-creates the cache of inset pointers
        //lyxerr << "converting:\n" << *this << endl;
        DocIterator dit = DocIterator(*inset);
        for (size_t i = 0, n = data_.size(); i != n; ++i) {
+               if (inset == 0) {
+                       // FIXME
+                       lyxerr << "Should not happen, but does e.g. after C-n C-l C-z S-C-z"
+                               << endl << "dit: " << dit << endl
+                               << " lastpos: " << dit.lastpos() << endl;
+                       //break;
+                       BOOST_ASSERT(false);
+               }
                dit.push_back(data_[i]);
                dit.back().inset_ = inset;
                if (i + 1 != n)