#include "CursorSlice.h"
-#include "debug.h"
#include "Text.h"
#include "Paragraph.h"
+#include "support/debug.h"
+
#include "insets/Inset.h"
#include "mathed/InsetMath.h"
#include "mathed/MathData.h"
#include <boost/assert.hpp>
-#include <boost/bind.hpp>
+#include <ostream>
-namespace lyx {
+using namespace std;
-using std::endl;
+namespace lyx {
CursorSlice::CursorSlice()
}
-CursorSlice::CursorSlice(CursorSlice const & cs)
+MathData & CursorSlice::cell() const
{
- operator=(cs);
+ return inset_->asInsetMath()->cell(idx_);
}
-CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
+Paragraph & CursorSlice::paragraph() const
{
- inset_ = cs.inset_;
- idx_ = cs.idx_;
- pit_ = cs.pit_;
- pos_ = cs.pos_;
- return *this;
+ return text()->getPar(pit_);
}
-void CursorSlice::invalidate()
+pos_type CursorSlice::lastpos() const
{
- inset_ = 0;
+ BOOST_ASSERT(inset_);
+ return inset_->asInsetMath() ? cell().size() : paragraph().size();
}
-bool CursorSlice::isValid() const
+pit_type CursorSlice::lastpit() const
{
- return inset_ != 0;
+ if (inset().inMathed())
+ return 0;
+ return text()->paragraphs().size() - 1;
}
-MathData & CursorSlice::cell() const
+CursorSlice::row_type CursorSlice::row() const
{
- return inset_->asInsetMath()->cell(idx_);
+ BOOST_ASSERT(asInsetMath());
+ return asInsetMath()->row(idx_);
}
-Paragraph & CursorSlice::paragraph()
+CursorSlice::col_type CursorSlice::col() const
{
- return text()->getPar(pit_);
+ BOOST_ASSERT(asInsetMath());
+ return asInsetMath()->col(idx_);
}
-Paragraph const & CursorSlice::paragraph() const
+void CursorSlice::forwardPos()
{
- return text()->getPar(pit_);
+ // move on one position if possible
+ if (pos() < lastpos()) {
+ //lyxerr << "... next pos" << endl;
+ ++pos();
+ return;
+ }
+
+ // otherwise move on one paragraph if possible
+ if (pit() < lastpit()) {
+ //lyxerr << "... next par" << endl;
+ ++pit();
+ pos() = 0;
+ return;
+ }
+
+ // otherwise move on one cell
+ //lyxerr << "... next idx" << endl;
+
+ BOOST_ASSERT(idx() < nargs());
+
+ ++idx();
+ pit() = 0;
+ pos() = 0;
}
-pos_type CursorSlice::lastpos() const
+void CursorSlice::forwardIdx()
{
- BOOST_ASSERT(inset_);
- return inset_->asInsetMath() ? cell().size() : paragraph().size();
+ BOOST_ASSERT(idx() < nargs());
+
+ ++idx();
+ pit() = 0;
+ pos() = 0;
}
-pit_type CursorSlice::lastpit() const
+void CursorSlice::backwardPos()
{
- if (inset().inMathed())
- return 0;
- return text()->paragraphs().size() - 1;
+ if (pos() != 0) {
+ --pos();
+ return;
+ }
+
+ if (pit() != 0) {
+ --pit();
+ pos() = lastpos();
+ return;
+ }
+
+ if (idx() != 0) {
+ --idx();
+ pit() = lastpit();
+ pos() = lastpos();
+ return;
+ }
+
+ BOOST_ASSERT(false);
}
-CursorSlice::row_type CursorSlice::row() const
+bool CursorSlice::at_end() const
{
- BOOST_ASSERT(asInsetMath());
- return asInsetMath()->row(idx_);
+ return idx() == lastidx() && pit() == lastpit() && pos() == lastpos();
}
-CursorSlice::col_type CursorSlice::col() const
+bool CursorSlice::at_begin() const
{
- BOOST_ASSERT(asInsetMath());
- return asInsetMath()->col(idx_);
+ return idx() == 0 && pit() == 0 && pos() == 0;
}
bool operator<(CursorSlice const & p, CursorSlice const & q)
{
if (&p.inset() != &q.inset()) {
- lyxerr << "can't compare cursor and anchor in different insets\n"
- << "p: " << p << '\n' << "q: " << q << endl;
+ LYXERR0("can't compare cursor and anchor in different insets\n"
+ << "p: " << p << '\n' << "q: " << q);
BOOST_ASSERT(false);
}
if (p.idx() != q.idx())
}
-std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
+ostream & operator<<(ostream & os, CursorSlice const & item)
{
return os
- << "inset: " << &item.inset()
+ << "inset: " << (void *)&item.inset()
// << " text: " << item.text()
<< " idx: " << item.idx()
<< " par: " << item.pit()