+}
+
+
+void MathCursor::SelStart()
+{
+ seldump("SelStart");
+ if (selection)
+ return;
+
+ Anchor_ = Cursor_;
+ selection = true;
+}
+
+
+void MathCursor::SelClear()
+{
+ selection = false;
+}
+
+
+void MathCursor::drawSelection(Painter & pain) const
+{
+ if (!selection)
+ return;
+
+ MathCursorPos i1;
+ MathCursorPos i2;
+ getSelection(i1, i2);
+
+ //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
+
+ if (i1.idx_ == i2.idx_) {
+ MathXArray & c = i1.xcell();
+ int x1 = c.xo() + c.pos2x(i1.pos_);
+ int y1 = c.yo() - c.ascent();
+ int x2 = c.xo() + c.pos2x(i2.pos_);
+ int y2 = c.yo() + c.descent();
+ pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ } else {
+
+#if RECTANGULAR_SELECT
+ std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
+ for (unsigned i = 0; i < indices.size(); ++i) {
+ MathXArray & c = i1.xcell(indices[i]);
+ int x1 = c.xo();
+ int y1 = c.yo() - c.ascent();
+ int x2 = c.xo() + c.width();
+ int y2 = c.yo() + c.descent();
+ pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ }
+#else
+ // leftmost cell
+ MathXArray & c = i1.xcell();
+ int x1 = c.xo() + c.pos2x(i1.pos_);
+ int y1 = c.yo() - c.ascent();
+ int x2 = c.xo() + c.width();
+ int y2 = c.yo() + c.descent();
+ pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ // middle cells
+ for (int idx = i1.idx_ + 1; idx < i2.idx_; ++idx) {
+ MathXArray & c = i1.xcell(idx);
+ int x1 = c.xo();
+ int y1 = c.yo() - c.ascent();
+ int x2 = c.xo() + c.width();
+ int y2 = c.yo() + c.descent();
+ pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+ }
+ // rightmost cell
+ MathXArray & cr = i2.xcell();
+ x1 = cr.xo();
+ y1 = cr.yo() - cr.ascent();
+ x2 = cr.xo() + cr.pos2x(i2.pos_);
+ y2 = cr.yo() + cr.descent();
+ pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+#endif