]> git.lyx.org Git - lyx.git/blobdiff - src/DocIterator.cpp
BufferParams.cpp: fix bug 3568:
[lyx.git] / src / DocIterator.cpp
index c2e2653d4a44605777a6af484636dae160b406f2..cf84b1b1c7cff0657ec2da7ac22322748e3d347a 100644 (file)
 #include "DocIterator.h"
 
 #include "debug.h"
-#include "LyXText.h"
+#include "Text.h"
 #include "Paragraph.h"
 
-#include "mathed/MathArray.h"
+#include "mathed/MathData.h"
 #include "mathed/InsetMath.h"
 
 #include "insets/InsetTabular.h"
@@ -38,12 +38,12 @@ DocIterator::DocIterator()
 {}
 
 
-DocIterator::DocIterator(InsetBase & inset)
+DocIterator::DocIterator(Inset & inset)
        : boundary_(false), inset_(&inset)
 {}
 
 
-DocIterator doc_iterator_begin(InsetBase & inset)
+DocIterator doc_iterator_begin(Inset & inset)
 {
        DocIterator dit(inset);
        dit.forwardPos();
@@ -51,13 +51,13 @@ DocIterator doc_iterator_begin(InsetBase & inset)
 }
 
 
-DocIterator doc_iterator_end(InsetBase & inset)
+DocIterator doc_iterator_end(Inset & inset)
 {
        return DocIterator(inset);
 }
 
 
-InsetBase * DocIterator::nextInset()
+Inset * DocIterator::nextInset()
 {
        BOOST_ASSERT(!empty());
        if (pos() == lastpos())
@@ -72,7 +72,7 @@ InsetBase * DocIterator::nextInset()
 }
 
 
-InsetBase * DocIterator::prevInset()
+Inset * DocIterator::prevInset()
 {
        BOOST_ASSERT(!empty());
        if (pos() == 0)
@@ -89,7 +89,7 @@ InsetBase * DocIterator::prevInset()
 }
 
 
-InsetBase const * DocIterator::prevInset() const
+Inset const * DocIterator::prevInset() const
 {
        BOOST_ASSERT(!empty());
        if (pos() == 0)
@@ -106,11 +106,11 @@ InsetBase const * DocIterator::prevInset() const
 }
 
 
-InsetBase * DocIterator::realInset() const
+Inset * DocIterator::realInset() const
 {
        BOOST_ASSERT(inTexted());
        // if we are in a tabular, we need the cell
-       if (inset().lyxCode() == InsetBase::TABULAR_CODE) {
+       if (inset().lyxCode() == Inset::TABULAR_CODE) {
                InsetTabular & tabular = static_cast<InsetTabular&>(inset());
                return tabular.cell(idx()).get();
        }
@@ -152,13 +152,13 @@ MathAtom & DocIterator::nextAtom()
 }
 
 
-LyXText * DocIterator::text()
+Text * DocIterator::text()
 {
        BOOST_ASSERT(!empty());
        return top().text();
 }
 
-LyXText const * DocIterator::text() const
+Text const * DocIterator::text() const
 {
        BOOST_ASSERT(!empty());
        return top().text();
@@ -181,6 +181,22 @@ Paragraph const & DocIterator::paragraph() const
 }
 
 
+Paragraph const & DocIterator::innerParagraph() const
+{
+       BOOST_ASSERT(!empty());
+       // go up until first non-0 text is hit
+       // (innermost text is 0 in mathed)
+       for (int i = depth() - 1; i >= 0; --i)
+               if (slices_[i].text())
+                       return slices_[i].paragraph();
+
+       // This case is in principe not possible. We _must_
+       // be inside a Paragraph.
+       BOOST_ASSERT(false);
+       return paragraph();
+}
+
+
 pit_type DocIterator::lastpit() const
 {
        return inMathed() ? 0 : text()->paragraphs().size() - 1;
@@ -232,21 +248,21 @@ DocIterator::col_type DocIterator::col() const
 }
 
 
-MathArray const & DocIterator::cell() const
+MathData const & DocIterator::cell() const
 {
 //     BOOST_ASSERT(inMathed());
        return top().cell();
 }
 
 
-MathArray & DocIterator::cell()
+MathData & DocIterator::cell()
 {
 //     BOOST_ASSERT(inMathed());
        return top().cell();
 }
 
 
-LyXText * DocIterator::innerText()
+Text * DocIterator::innerText()
 {
        BOOST_ASSERT(!empty());
        // Go up until first non-0 text is hit
@@ -257,7 +273,7 @@ LyXText * DocIterator::innerText()
        return 0;
 }
 
-LyXText const * DocIterator::innerText() const
+Text const * DocIterator::innerText() const
 {
        BOOST_ASSERT(!empty());
        // go up until first non-0 text is hit
@@ -269,7 +285,7 @@ LyXText const * DocIterator::innerText() const
 }
 
 
-InsetBase * DocIterator::innerInsetOfType(int code) const
+Inset * DocIterator::innerInsetOfType(int code) const
 {
        for (int i = depth() - 1; i >= 0; --i)
                if (slices_[i].inset_->lyxCode() == code)
@@ -286,12 +302,12 @@ void DocIterator::forwardPos(bool ignorecollapsed)
                return;
        }
 
-       InsetBase * const nextinset = nextInset();
+       Inset * const nextinset = nextInset();
        // jump over collapsables if they are collapsed
        // FIXME: the check for asInsetMath() shouldn't be necessary
        // but math insets do not return a sensible editable() state yet.
        if (ignorecollapsed && nextinset && (!nextinset->asInsetMath()
-           && nextinset->editable() != InsetBase::HIGHLY_EDITABLE)) {
+           && nextinset->editable() != Inset::HIGHLY_EDITABLE)) {
                ++top().pos();
                return;
        }
@@ -303,7 +319,7 @@ void DocIterator::forwardPos(bool ignorecollapsed)
        pos_type const lastp = lastpos();
 
        // move into an inset to the right if possible
-       InsetBase * n = 0;
+       Inset * n = 0;
 
        if (tip.pos() != lastp) {
                // this is impossible for pos() == size()
@@ -481,7 +497,7 @@ void DocIterator::backwardPos()
        }
 
        // move into an inset to the left if possible
-       InsetBase * n = 0;
+       Inset * n = 0;
 
        if (inMathed()) {
                n = (tip.cell().begin() + tip.pos())->nucleus();
@@ -510,7 +526,7 @@ bool DocIterator::hasPart(DocIterator const & it) const
 }
 
 
-void DocIterator::updateInsets(InsetBase * inset)
+void DocIterator::updateInsets(Inset * inset)
 {
        // this function re-creates the cache of inset pointers.
        // code taken in part from StableDocIterator::asDocIterator.
@@ -548,7 +564,7 @@ StableDocIterator::StableDocIterator(DocIterator const & dit)
 }
 
 
-DocIterator StableDocIterator::asDocIterator(InsetBase * inset) const
+DocIterator StableDocIterator::asDocIterator(Inset * inset) const
 {
        // this function re-creates the cache of inset pointers
        //lyxerr << "converting:\n" << *this << endl;