]> git.lyx.org Git - lyx.git/blobdiff - src/cursor_slice.C
more cursor dispatch
[lyx.git] / src / cursor_slice.C
index 25e5f3f141468856e16d88a9e8d24cb96f5d0d82..cbbda47d1a276cf24d277ac417d6244b81ccced6 100644 (file)
 
 #include "cursor_slice.h"
 #include "debug.h"
+#include "lyxtext.h"
+#include "paragraph.h"
 
 #include "mathed/math_inset.h"
+#include "mathed/math_data.h"
+
 #include "insets/updatableinset.h"
 
+
 #include <boost/assert.hpp>
 
 using std::endl;
@@ -36,30 +41,84 @@ CursorSlice::CursorSlice(InsetBase * p)
 }
 
 
-void CursorSlice::par(lyx::paroffset_type par)
+void CursorSlice::idx(idx_type idx)
+{
+       idx_ = idx;
+}
+
+
+size_t CursorSlice::nargs() const
+{
+       return inset_->nargs();
+}
+
+
+size_t CursorSlice::nrows() const
+{
+       return inset_->nrows();
+}
+
+
+size_t CursorSlice::ncols() const
+{
+       return inset_->ncols();
+}
+
+
+CursorSlice::idx_type CursorSlice::idx() const
+{
+       return idx_;
+}
+
+
+CursorSlice::idx_type & CursorSlice::idx()
+{
+       return idx_;
+}
+
+
+void CursorSlice::par(par_type par)
 {
        par_ = par;
 }
 
 
-lyx::paroffset_type CursorSlice::par() const
+CursorSlice::par_type CursorSlice::par() const
+{
+       return par_;
+}
+
+
+CursorSlice::par_type & CursorSlice::par()
 {
        return par_;
 }
 
 
-void CursorSlice::pos(lyx::pos_type pos)
+void CursorSlice::pos(pos_type pos)
 {
        pos_ = pos;
 }
 
 
-lyx::pos_type CursorSlice::pos() const
+CursorSlice::pos_type CursorSlice::pos() const
+{
+       return pos_;
+}
+
+
+CursorSlice::pos_type & CursorSlice::pos()
 {
        return pos_;
 }
 
 
+CursorSlice::pos_type CursorSlice::lastpos() const
+{
+       return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
+}
+
+
 void CursorSlice::boundary(bool boundary)
 {
        boundary_ = boundary;
@@ -72,47 +131,64 @@ bool CursorSlice::boundary() const
 }
 
 
-MathInset * CursorSlice::asMathInset() const
+bool & CursorSlice::boundary()
 {
-       return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
+       return boundary_;
 }
 
 
-UpdatableInset * CursorSlice::asUpdatableInset() const
+CursorSlice::row_type CursorSlice::row() const
+{
+       BOOST_ASSERT(asMathInset());
+       return asMathInset()->row(idx_);
+}
+
+
+CursorSlice::col_type CursorSlice::col() const
+{
+       BOOST_ASSERT(asMathInset());
+       return asMathInset()->col(idx_);
+}
+
+
+MathInset * CursorSlice::asMathInset() const
 {
-       return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
+       return inset_ ? inset_->asMathInset() : 0;
 }
 
 
-MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
+UpdatableInset * CursorSlice::asUpdatableInset() const
 {
-       BOOST_ASSERT(inset_);
-       return asMathInset()->cell(idx);
+       return inset_ ? inset_->asUpdatableInset() : 0;
 }
 
 
 MathArray & CursorSlice::cell() const
 {
-       BOOST_ASSERT(inset_);
+       BOOST_ASSERT(asMathInset());
        return asMathInset()->cell(idx_);
 }
 
 
-void CursorSlice::getPos(int & x, int & y) const
+LyXText * CursorSlice::text() const
 {
-       asMathInset()->getPos(idx_, pos_, x, y);
+       return inset_ ? inset_->getText(idx_) : 0;
 }
 
 
-void CursorSlice::setPos(int pos)
+Paragraph & CursorSlice::paragraph()
 {
-       pos_ = pos;
+       // access to the main lyx text must be handled in the cursor
+       BOOST_ASSERT(text());
+       return *text()->getPar(par_);
 }
 
 
-LyXText * CursorSlice::text() const
+Paragraph const & CursorSlice::paragraph() const
 {
-       return asUpdatableInset()->getText(idx_);
+       // access to the main lyx text must be handled in the cursor
+       BOOST_ASSERT(text());
+       return *text()->getPar(par_);
 }
 
 
@@ -149,24 +225,21 @@ bool operator<(CursorSlice const & p, CursorSlice const & q)
 }
 
 
-//std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
-//{
-//     os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
-//     return os;
-//}
+bool operator>(CursorSlice const & p, CursorSlice const & q)
+{
+       return q < p;
+}
 
 
 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 {
-       os << " inset: " << item.inset_
-//        << " text: " << item.text()
+       os << "inset: " << item.inset_
+          << " text: " << item.text()
           << " idx: " << item.idx_
-//        << " par: " << item.par_
-//        << " pos: " << item.pos_
+          << " par: " << item.par_
+          << " pos: " << item.pos_
 //        << " x: " << item.inset_->x()
 //        << " y: " << item.inset_->y()
 ;
        return os;
 }
-
-