-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()
-{
- //lyxerr << "LCursor::eraseSelection" << endl;
- CursorSlice const & i1 = selBegin();
- CursorSlice const & 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();
- }
- back() = i1;
- } else {
- lyxerr << "can't erase this selection 1" << endl;
- }
- //lyxerr << "LCursor::eraseSelection end" << 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()
-{
- //lyxerr << "LCursor::selDel" << endl;
- if (selection()) {
- eraseSelection();
- selection() = false;
- }
-}
-
-
-void LCursor::selPaste(size_t n)
-{
- selClearOrDel();
- if (n < theCutBuffer.size())
- paste(theCutBuffer[n]);
- //grabSelection();
- selection() = false;
-}
-
-
-void LCursor::selHandle(bool sel)