-namespace {
-
-void region(CursorSlice const & i1, CursorSlice const & i2,
- LCursor::row_type & r1, LCursor::row_type & r2,
- LCursor::col_type & c1, LCursor::col_type & c2)
-{
- InsetBase * p = i1.inset();
- c1 = p->col(i1.idx_);
- c2 = p->col(i2.idx_);
- if (c1 > c2)
- swap(c1, c2);
- r1 = p->row(i1.idx_);
- r2 = p->row(i2.idx_);
- if (r1 > r2)
- swap(r1, r2);
-}
-
-}
-
-
-string LCursor::grabSelection()
-{
- if (!selection())
- return string();
-
- CursorSlice i1 = selBegin();
- CursorSlice i2 = selEnd();
-
- if (i1.idx_ == i2.idx_) {
- if (i1.inset()->asMathInset()) {
- MathArray::const_iterator it = i1.cell().begin();
- return asString(MathArray(it + i1.pos_, it + i2.pos_));
- } else {
- return "unknown selection 1";
- }
- }
-
- row_type r1, r2;
- col_type c1, c2;
- region(i1, i2, r1, r2, c1, c2);
-
- string data;
- if (i1.inset()->asMathInset()) {
- for (row_type row = r1; row <= r2; ++row) {
- if (row > r1)
- data += "\\\\";
- for (col_type col = c1; col <= c2; ++col) {
- if (col > c1)
- data += '&';
- data += asString(i1.asMathInset()->cell(i1.asMathInset()->index(row, col)));
- }
- }
- } else {
- data = "unknown selection 2";
- }
- return data;
-}
-
-
-void LCursor::eraseSelection()
-{
- CursorSlice i1 = selBegin();
- CursorSlice i2 = selEnd();
-#warning FIXME
- if (i1.inset()->asMathInset()) {
- if (i1.idx_ == i2.idx_) {
- i1.cell().erase(i1.pos_, i2.pos_);
- } else {
- MathInset * p = i1.asMathInset();
- row_type r1, r2;
- col_type c1, c2;
- region(i1, i2, r1, r2, c1, c2);
- for (row_type row = r1; row <= r2; ++row)
- for (col_type col = c1; col <= c2; ++col)
- p->cell(p->index(row, col)).clear();
- }
- current() = i1;
- } else {
- lyxerr << "can't erase this selection 1" << endl;
- }
-}
-
-
-string LCursor::grabAndEraseSelection()
-{
- if (!selection())
- return string();
- string res = grabSelection();
- eraseSelection();
- selection() = false;
- return res;
-}
-
-
-void LCursor::selClear()
-{
- resetAnchor();
- clearSelection();
-}
-
-
-void LCursor::selCopy()
-{
- if (selection()) {
- theCutBuffer.push(grabSelection());
- selection() = false;
- } else {
- //theCutBuffer.erase();
- }
-}
-
-
-void LCursor::selCut()
-{
- theCutBuffer.push(grabAndEraseSelection());
-}
-
-
-void LCursor::selDel()
-{
- if (selection()) {
- eraseSelection();
- selection() = false;
- }
-}
-
-
-void LCursor::selPaste(size_t n)
-{
- selClearOrDel();
- if (n < theCutBuffer.size())
- paste(theCutBuffer[n]);
- //grabSelection();
- selection() = false;
-}
-
-