]> git.lyx.org Git - lyx.git/blobdiff - src/dociterator.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / dociterator.C
index 2ede4d4518fdc1c5f27a41bf54f01ebe5ec4dcbf..4955cbf910951b472f91095859244187c19755d4 100644 (file)
 #include "lyxrow.h"
 #include "paragraph.h"
 
-#include "mathed/math_data.h"
-#include "mathed/math_inset.h"
+#include "mathed/MathData.h"
+#include "mathed/InsetMath.h"
+
+#include "insets/insettabular.h"
 
 #include <boost/assert.hpp>
 #include <boost/current_function.hpp>
@@ -30,12 +32,12 @@ 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), boundary_(false)
+       : boundary_(false), inset_(0)
 {}
 
 
 DocIterator::DocIterator(InsetBase & inset)
-       : inset_(&inset), boundary_(false)
+       : boundary_(false), inset_(&inset)
 {}
 
 
@@ -90,6 +92,18 @@ InsetBase const * DocIterator::prevInset() const
 }
 
 
+InsetBase * DocIterator::realInset() const
+{
+       BOOST_ASSERT(inTexted());
+       // if we are in a tabular, we need the cell
+       if (inset().lyxCode() == InsetBase::TABULAR_CODE) {
+               InsetTabular & tabular = static_cast<InsetTabular&>(inset());
+               return tabular.cell(idx()).get();
+       }
+       return &inset();
+}
+
+
 MathAtom const & DocIterator::prevAtom() const
 {
        BOOST_ASSERT(!empty());
@@ -276,7 +290,7 @@ InsetBase * DocIterator::innerInsetOfType(int code) const
 }
 
 
-void DocIterator::forwardPos()
+void DocIterator::forwardPos(bool ignorecollapsed)
 {
        //this dog bites his tail
        if (empty()) {
@@ -284,6 +298,15 @@ void DocIterator::forwardPos()
                return;
        }
 
+       // 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)) {
+               ++top().pos();
+               return;
+       }
+
        CursorSlice & tip = top();
        //lyxerr << "XXX\n" << *this << endl;
 
@@ -376,7 +399,11 @@ void DocIterator::forwardPosNoDescend()
        }
        //lyxerr << "... no next idx" << endl;
 
-       // otherwise we can't move on
+       // otherwise leave inset and jump over inset as a whole
+       pop_back();
+       // 'top' is invalid now...
+       if (!empty())
+               ++top().pos();
 }
 
 
@@ -490,6 +517,25 @@ bool DocIterator::hasPart(DocIterator const & it) const
 }
 
 
+void DocIterator::updateInsets(InsetBase * inset)
+{
+       // this function re-creates the cache of inset pointers.
+       // code taken in part from StableDocIterator::asDocIterator.
+       //lyxerr << "converting:\n" << *this << endl;
+       DocIterator dit = DocIterator(*inset);
+       size_t const n = slices_.size();
+       for (size_t i = 0 ; i < n; ++i) {
+               BOOST_ASSERT(inset);
+               dit.push_back(slices_[i]);
+               dit.top().inset_ = inset;
+               if (i + 1 != n)
+                       inset = dit.nextInset();
+       }
+       //lyxerr << "converted:\n" << *this << endl;
+       operator=(dit);
+}
+
+
 std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
 {
        for (size_t i = 0, n = dit.depth(); i != n; ++i)
@@ -546,4 +592,3 @@ bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2)
 {
        return dit1.data_ == dit2.data_;
 }
-