]> git.lyx.org Git - lyx.git/blobdiff - src/cursor_slice.C
update build instructions (Qt 4.2.2 etc.)
[lyx.git] / src / cursor_slice.C
index c7eb6673fb6e1824946f4e03a648012a20b526f3..02e7b4ab6270d82dbd3b3b8976c68a2ac8668b29 100644 (file)
 #include "lyxtext.h"
 #include "paragraph.h"
 
-#include "mathed/math_inset.h"
-#include "mathed/math_data.h"
+#include "mathed/InsetMath.h"
+#include "mathed/MathData.h"
 
-#include "insets/updatableinset.h"
+#include <boost/assert.hpp>
 
 
-#include <boost/assert.hpp>
+namespace lyx {
 
 using std::endl;
 
 
 CursorSlice::CursorSlice()
-       : inset_(0), idx_(0), par_(0), pos_(0), boundary_(false)
+       : inset_(0), idx_(0), pit_(0), pos_(0)
 {}
 
 
-CursorSlice::CursorSlice(InsetBase * p)
-       : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false)
-{
-       ///BOOST_ASSERT(inset_);
-}
-
-
-size_t CursorSlice::nargs() const
+CursorSlice::CursorSlice(InsetBase & p)
+       : inset_(&p), idx_(0), pit_(0), pos_(0)
 {
        BOOST_ASSERT(inset_);
-       return inset_->nargs();
 }
 
 
-size_t CursorSlice::nrows() const
-{
-       BOOST_ASSERT(inset_);
-       return inset_->nrows();
-}
-
-
-size_t CursorSlice::ncols() const
-{
-       BOOST_ASSERT(inset_);
-       return inset_->ncols();
-}
-
-
-CursorSlice::idx_type CursorSlice::idx() const
-{
-       return idx_;
-}
-
-
-CursorSlice::idx_type & CursorSlice::idx()
-{
-       return idx_;
-}
-
-
-CursorSlice::par_type CursorSlice::par() const
-{
-       return par_;
-}
-
-
-CursorSlice::par_type & CursorSlice::par()
-{
-       return par_;
-}
-
-
-CursorSlice::pos_type CursorSlice::pos() const
-{
-       return pos_;
-}
-
-
-CursorSlice::pos_type & CursorSlice::pos()
+MathArray & CursorSlice::cell() const
 {
-       return pos_;
+       return inset_->asInsetMath()->cell(idx_);
 }
 
 
-CursorSlice::pos_type CursorSlice::lastpos() const
+Paragraph & CursorSlice::paragraph()
 {
-       return (inset_ && inset_->asMathInset()) ? cell().size() : paragraph().size();
+       return text()->getPar(pit_);
 }
 
 
-bool CursorSlice::boundary() const
+Paragraph const & CursorSlice::paragraph() const
 {
-       return boundary_;
+       return text()->getPar(pit_);
 }
 
 
-bool & CursorSlice::boundary()
+pos_type CursorSlice::lastpos() const
 {
-       return boundary_;
+       BOOST_ASSERT(inset_);
+       return inset_->asInsetMath() ? cell().size() : paragraph().size();
 }
 
 
 CursorSlice::row_type CursorSlice::row() const
 {
-       BOOST_ASSERT(asMathInset());
-       return asMathInset()->row(idx_);
+       BOOST_ASSERT(asInsetMath());
+       return asInsetMath()->row(idx_);
 }
 
 
 CursorSlice::col_type CursorSlice::col() const
 {
-       BOOST_ASSERT(asMathInset());
-       return asMathInset()->col(idx_);
-}
-
-
-MathInset * CursorSlice::asMathInset() const
-{
-       return inset_ ? inset_->asMathInset() : 0;
-}
-
-
-UpdatableInset * CursorSlice::asUpdatableInset() const
-{
-       return inset_ ? inset_->asUpdatableInset() : 0;
-}
-
-
-MathArray & CursorSlice::cell() const
-{
-       BOOST_ASSERT(asMathInset());
-       return asMathInset()->cell(idx_);
-}
-
-
-LyXText * CursorSlice::text() const
-{
-       return inset_ ? inset_->getText(idx_) : 0;
-}
-
-
-Paragraph & CursorSlice::paragraph()
-{
-       // access to the main lyx text must be handled in the cursor
-       BOOST_ASSERT(text());
-       return *text()->getPar(par_);
-}
-
-
-Paragraph const & CursorSlice::paragraph() const
-{
-       // access to the main lyx text must be handled in the cursor
-       BOOST_ASSERT(text());
-       return *text()->getPar(par_);
+       BOOST_ASSERT(asInsetMath());
+       return asInsetMath()->col(idx_);
 }
 
 
 bool operator==(CursorSlice const & p, CursorSlice const & q)
 {
        return p.inset_ == q.inset_
-              && p.idx_ == q.idx_
-              && p.par_ == q.par_
-              && p.pos_ == q.pos_;
+              && p.idx() == q.idx()
+              && p.pit() == q.pit()
+              && p.pos() == q.pos();
 }
 
 
 bool operator!=(CursorSlice const & p, CursorSlice const & q)
 {
        return p.inset_ != q.inset_
-              || p.idx_ != q.idx_
-              || p.par_ != q.par_
-              || p.pos_ != q.pos_;
+              || p.idx() != q.idx()
+              || p.pit() != q.pit()
+              || p.pos() != q.pos();
 }
 
 
 bool operator<(CursorSlice const & p, CursorSlice const & q)
 {
-       if (p.inset_ != q.inset_) {
+       if (&p.inset() != &q.inset()) {
                lyxerr << "can't compare cursor and anchor in different insets\n"
                       << "p: " << p << '\n' << "q: " << q << endl;
-               return true;
+               BOOST_ASSERT(false);
        }
-       if (p.idx_ != q.idx_)
-               return p.idx_ < q.idx_;
-       if (p.par_ != q.par_)
-               return p.par_ < q.par_;
-       return p.pos_ < q.pos_;
+       if (p.idx() != q.idx())
+               return p.idx() < q.idx();
+       if (p.pit() != q.pit())
+               return p.pit() < q.pit();
+       return p.pos() < q.pos();
 }
 
 
@@ -210,16 +119,24 @@ bool operator>(CursorSlice const & p, CursorSlice const & q)
 }
 
 
+bool operator<=(CursorSlice const & p, CursorSlice const & q)
+{
+       return !(q < p);
+}
+
+
 std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 {
-       os
-//        << "inset: " << item.inset_
+       return os
+          << "inset: " << &item.inset()
 //        << " text: " << item.text()
-          << " idx: " << item.idx_
-          << " par: " << item.par_
-          << " pos: " << item.pos_
-//        << " x: " << item.inset_->x()
-//        << " y: " << item.inset_->y()
+          << " idx: " << item.idx()
+          << " par: " << item.pit()
+          << " pos: " << item.pos()
+//        << " x: " << item.inset().x()
+//        << " y: " << item.inset().y()
 ;
-       return os;
 }
+
+
+} // namespace lyx