- BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
- MathArray const & ar = cur.cell();
- x = ar.xo() + ar.pos2x(cur.pos());
- y = ar.yo() + cur.bv().top_y();
+// FIXME: This is a hack. Ideally, the coord cache should not store
+// absolute positions, but relative ones. This would mean to call
+// setXY() not in MathArray::draw(), but in the parent insets' draw()
+// with the correctly adjusted x,y values. But this means that we'd have
+// to touch all (math)inset's draw() methods. Right now, we'll store
+// absolute value, and make them here relative, only to make them
+// absolute again when actually drawing the cursor. What a mess.
+ BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
+ MathArray const & ar = sl.cell();
+ if (!theCoords.getArrays().has(&ar)) {
+ // this can (semi-)legally happen if we just created this cell
+ // and it never has been drawn before. So don't ASSERT.
+ //lyxerr << "no cached data for array " << &ar << endl;
+ x = 0;
+ y = 0;
+ return;
+ }
+ Point const pt = theCoords.getArrays().xy(&ar);
+ if (!theCoords.getInsets().has(this)) {
+ // same as above
+ //lyxerr << "no cached data for inset " << this << endl;
+ x = 0;
+ y = 0;
+ return;
+ }
+ Point const pt2 = theCoords.getInsets().xy(this);
+ //lyxerr << "retrieving position cache for MathArray "
+ // << pt.x_ << ' ' << pt.y_ << std::endl;
+ x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
+ y = pt.y_ - pt2.y_;
+// lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
+// << " asc: " << ascent() << " des: " << descent()
+// << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl;