#include "insets/insettext.h"
#include "mathed/math_data.h"
-#include "mathed/math_support.h"
#include "mathed/math_inset.h"
+#include "mathed/math_macrotable.h"
#include "support/limited_stack.h"
#include "support/std_sstream.h"
using std::swap;
-
-// our own cut buffer
-limited_stack<string> theCutBuffer;
-
-
-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);
-}
-
-}
-
-
LCursor::LCursor(BufferView & bv)
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
selection_(false), mark_(false)
x = 0;
y = 0;
if (!empty())
- inset().getCursorPos(back(), x, y);
+ inset().getCursorPos(*this, x, y);
}
{
selection() = true;
// a selection with no contents is not a selection
+#ifdef WITH_WARNINGS
#warning doesnt look ok
+#endif
if (par() == anchor().par() && pos() == anchor().pos())
selection() = false;
}
}
-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();
-#ifdef WITH_WARNINGS
-#warning FIXME
-#endif
- 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::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)
{
//lyxerr << "LCursor::selHandle" << endl;
- if (sel == selection()) {
- if (!sel)
- noUpdate();
+ if (sel == selection())
return;
- }
-
+
resetAnchor();
selection() = sel;
}
-void LCursor::selClearOrDel()
-{
- //lyxerr << "LCursor::selClearOrDel" << endl;
- if (lyxrc.auto_region_delete)
- selDel();
- else
- selection() = false;
-}
-
-
std::ostream & operator<<(std::ostream & os, LCursor const & cur)
{
for (size_t i = 0, n = cur.size(); i != n; ++i) {
//lyxerr << "LCursor::insert char '" << c << "'" << endl;
BOOST_ASSERT(!empty());
if (inMathed()) {
- selClearOrDel();
+ lyx::cap::selClearOrDel(*this);
insert(new MathCharInset(c));
} else {
text()->insertChar(*this, c);
{
//lyxerr << "LCursor::insert MathAtom: " << endl;
macroModeClose();
- selClearOrDel();
+ lyx::cap::selClearOrDel(*this);
plainInsert(t);
lyxerr << "LCursor::insert MathAtom: cur:\n" << *this << endl;
}
void LCursor::niceInsert(MathAtom const & t)
{
macroModeClose();
- string safe = grabAndEraseSelection();
+ string safe = lyx::cap::grabAndEraseSelection(*this);
plainInsert(t);
// enter the new inset and move the contents of the selection if possible
if (t->isActive()) {
{
macroModeClose();
if (selection())
- eraseSelection();
+ lyx::cap::eraseSelection(*this);
cell().insert(pos(), ar);
pos() += ar.size();
}
autocorrect() = false;
if (selection()) {
- selDel();
+ lyx::cap::selDel(*this);
return true;
}
return true;
if (selection()) {
- selDel();
+ lyx::cap::selDel(*this);
return true;
}
{
//lyxerr << "LCursor::handleNest: " << c << endl;
MathAtom t = a;
- asArray(grabAndEraseSelection(), t.nucleus()->cell(c));
+ asArray(lyx::cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
insert(t);
posLeft();
pushLeft(*nextInset());
// avoid invalid nesting when selecting
if (!selection() || positionable(it, anchor_)) {
int xo = 0, yo = 0;
- CursorSlice & cur = it.back();
+ LCursor cur = *this;
+ cur.setCursor(it, false);
cur.inset().getCursorPos(cur, xo, yo);
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
et.back().pos() = et.back().asMathInset()->cell(et.back().idx()).size();
for (int i = 0; ; ++i) {
int xo, yo;
- CursorSlice & cur = it.back();
+ LCursor cur = *this;
+ cur.setCursor(it, false);
cur.inset().getCursorPos(cur, xo, yo);
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
// '<=' in order to take the last possible position
string safe;
if (selection()) {
macroModeClose();
- safe = grabAndEraseSelection();
+ safe = lyx::cap::grabAndEraseSelection(*this);
}
if (lastpos() != 0) {