]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_data.C
some (yet unfinished) up/down work
[lyx.git] / src / mathed / math_data.C
index 8a97e3e53a677856ef380cbcbdd7339858a652e8..d981af2b7691b83065e129cfd5b73cd8c423eeb1 100644 (file)
@@ -19,6 +19,7 @@
 #include "math_support.h"
 #include "math_replace.h"
 
+#include "coordcache.h"
 #include "LColor.h"
 #include "BufferView.h"
 #include "buffer.h"
@@ -38,12 +39,11 @@ using std::vector;
 
 
 MathArray::MathArray()
-       : xo_(0), yo_(0) 
 {}
 
 
 MathArray::MathArray(const_iterator from, const_iterator to)
-       : base_type(from, to), xo_(0), yo_(0)
+       : base_type(from, to)
 {}
 
 
@@ -221,7 +221,7 @@ namespace {
 bool isInside(DocIterator const & it, MathArray const & ar,
        lyx::pos_type p1, lyx::pos_type p2)
 {
-       for (size_t i = 0; i != it.size(); ++i) {
+       for (size_t i = 0; i != it.depth(); ++i) {
                CursorSlice const & sl = it[i];
                if (sl.inset().inMathed() && &sl.cell() == &ar)
                        return p1 <= sl.pos() && sl.pos() < p2;
@@ -276,8 +276,7 @@ void MathArray::metrics(MetricsInfo & mi) const
 void MathArray::draw(PainterInfo & pi, int x, int y) const
 {
        //lyxerr << "MathArray::draw: x: " << x << " y: " << y << endl;
-       xo_ = x;
-       yo_ = y;
+       setXY(x, y);
 
        if (empty()) {
                pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
@@ -332,8 +331,7 @@ void MathArray::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 void MathArray::drawT(TextPainter & pain, int x, int y) const
 {
        //lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
-       xo_ = x;
-       yo_ = y;
+       setXY(x, y);
 
        for (const_iterator it = begin(), et = end(); it != et; ++it) {
                (*it)->drawT(pain, x, y);
@@ -382,8 +380,16 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const
                        currx += glue;
                currx += (*it)->width();
        }
+
        if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
                --it;
+       // The below code guarantees that in this slice, the cursor will
+       // never be on the right edge of an inset after a mouse click.
+       if (it != begin())
+               --it;
+       if (it < end() && (*it)->getChar())
+               ++it;
+
        return it - begin();
 }
 
@@ -393,6 +399,9 @@ int MathArray::dist(int x, int y) const
        int xx = 0;
        int yy = 0;
 
+       const int xo_ = xo();
+       const int yo_ = yo();
+
        if (x < xo_)
                xx = xo_ - x;
        else if (x > xo_ + width())
@@ -409,6 +418,18 @@ int MathArray::dist(int x, int y) const
 
 void MathArray::setXY(int x, int y) const
 {
-       xo_ = x;
-       yo_ = y;
+       //lyxerr << "setting position cache for MathArray " << this << std::endl;
+       theCoords.arrays().add(this, x, y);
+}
+
+
+int MathArray::xo() const
+{
+       return theCoords.getArrays().x(this);
+}
+
+
+int MathArray::yo() const
+{
+       return theCoords.getArrays().y(this);
 }