#include "frontends/Painter.h"
#include "math_cursor.h"
#include "formulabase.h"
+#include "funcrequest.h"
#include "math_autocorrect.h"
#include "math_arrayinset.h"
#include "math_braceinset.h"
-#include "math_casesinset.h"
+#include "math_commentinset.h"
#include "math_charinset.h"
#include "math_extern.h"
#include "math_factory.h"
void MathCursor::pushLeft(MathAtom & t)
{
- //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
+ //lyxerr << "Entering atom " << t << " left\n";
push(t);
t->idxFirst(idx(), pos());
}
void MathCursor::pushRight(MathAtom & t)
{
- //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
+ //lyxerr << "Entering atom " << t << " right\n";
posLeft();
push(t);
t->idxLast(idx(), pos());
void MathCursor::paste(MathGridInset const & data)
{
- if (data.nargs() == 1) {
- // single cell/part of cell
- paste(data.cell(0));
- } else {
- // multiple cells
- idx_type idx; // index of upper left cell
- MathGridInset * p = enclosingGrid(idx);
- col_type const numcols = min(data.ncols(), p->ncols() - p->col(idx));
- row_type const numrows = min(data.nrows(), p->nrows() - p->row(idx));
- for (row_type row = 0; row < numrows; ++row) {
- for (col_type col = 0; col < numcols; ++col) {
- idx_type i = p->index(row + p->row(idx), col + p->col(idx));
- p->cell(i).append(data.cell(data.index(row, col)));
- }
- // append the left over horizontal cells to the last column
- idx_type i = p->index(row + p->row(idx), p->ncols() - 1);
- for (MathInset::col_type col = numcols; col < data.ncols(); ++col)
- p->cell(i).append(data.cell(data.index(row, col)));
- }
- // append the left over vertical cells to the last _cell_
- idx_type i = p->nargs() - 1;
- for (row_type row = numrows; row < data.nrows(); ++row)
- for (col_type col = 0; col < data.ncols(); ++col)
- p->cell(i).append(data.cell(data.index(row, col)));
- }
+ ostringstream os;
+ WriteStream wi(os, false, false);
+ data.write(wi);
+ dispatch(FuncRequest(LFUN_PASTE, os.str()));
}
return;
}
+ if (inMacroMode()) {
+ MathUnknownInset * p = activeMacro();
+ if (p->name().size() > 1) {
+ p->setName(p->name().substr(0, p->name().size() - 1));
+ return;
+ }
+ }
+
/*
if (prevAtom()->asScriptInset()) {
// simply enter nucleus
}
-void MathCursor::getPos(int & x, int & y)
+void MathCursor::getPos(int & x, int & y) const
{
par()->getPos(idx(), pos(), x, y);
}
+int MathCursor::targetX() const
+{
+ if (targetx_ != -1)
+ return targetx_;
+ int x = 0, y = 0;
+ getPos(x, y);
+ return x;
+}
+
+
MathInset * MathCursor::par() const
{
return cursor().par_;
}
-MathHullInset * MathCursor::enclosingHull(MathCursor::idx_type & idx) const
-{
- for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
- MathHullInset * p = Cursor_[i].par_->asHullInset();
- if (p) {
- idx = Cursor_[i].idx_;
- return p;
- }
- }
- return 0;
-}
-
-
void MathCursor::popToHere(MathInset const * p)
{
while (depth() && Cursor_.back().par_ != p)
}
-MathCursor::col_type MathCursor::hullCol() const
-{
- idx_type idx = 0;
- MathHullInset * p = enclosingHull(idx);
- return p->col(idx);
-}
-
-
-MathCursor::row_type MathCursor::hullRow() const
-{
- idx_type idx = 0;
- MathHullInset * p = enclosingHull(idx);
- return p->row(idx);
-}
-
-
bool MathCursor::hasPrevAtom() const
{
return pos() > 0;
}
-bool MathCursor::idxLineFirst()
-{
- idx() -= idx() % par()->ncols();
- pos() = 0;
- return true;
-}
-
-
bool MathCursor::idxLineLast()
{
idx() -= idx() % par()->ncols();
//owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
//lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
- if (s.size() >= 5 && s.substr(0, 5) == "cases") {
- unsigned int n = 1;
- istringstream is(s.substr(5).c_str());
- is >> n;
- n = max(1u, n);
- niceInsert(MathAtom(new MathCasesInset(n)));
- return true;
- }
-
if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
unsigned int m = 1;
unsigned int n = 1;
// Hack to get \\^ and \\_ working
if (inMacroMode() && macroName() == "\\") {
if (up)
- interpret("\\mathcircumflex");
+ niceInsert(createMathInset("mathcircumflex"));
else
interpret('_');
return true;
string name = macroName();
//lyxerr << "interpret name: '" << name << "'\n";
- if (name.empty() && c == '\\') {
- backspace();
- interpret("\\backslash");
- return true;
- }
-
if (isalpha(c)) {
activeMacro()->setName(activeMacro()->name() + c);
return true;
if (name == "\\") {
// remove the '\\'
backspace();
- if (c == '\\')
- interpret("\\backslash");
- else
- interpret(string("\\") + c);
+ if (c == '\\') {
+ if (currentMode() == MathInset::TEXT_MODE)
+ niceInsert(createMathInset("textbackslash"));
+ else
+ niceInsert(createMathInset("backslash"));
+ } else
+ niceInsert(createMathInset(string(1, c)));
return true;
}
}
if (c == '%') {
- insert(createMathInset("%"));
+ niceInsert(MathAtom(new MathCommentInset));
return true;
}
}
-
-void MathCursor::handleExtern(const string & arg)
-{
- string lang;
- string extra;
- istringstream iss(arg.c_str());
- iss >> lang >> extra;
- if (extra.empty())
- extra = "noextra";
-
- if (selection()) {
- MathArray ar;
- selGet(ar);
- lyxerr << "use selection: " << ar << "\n";
- insert(pipeThroughExtern(lang, extra, ar));
- return;
- }
-
- MathArray eq;
- eq.push_back(MathAtom(new MathCharInset('=')));
-
- popToEnclosingHull();
-
- idx_type idx = 0;
- MathHullInset * hull = enclosingHull(idx);
- lyx::Assert(hull);
- idxLineFirst();
-
- if (hull->getType() == "simple") {
- MathArray::size_type pos = cursor().cell().find_last(eq);
- MathArray ar;
- if (pos == size()) {
- ar = array();
- lyxerr << "use whole cell: " << ar << "\n";
- } else {
- ar = MathArray(array().begin() + pos + 1, array().end());
- lyxerr << "use partial cell form pos: " << pos << "\n";
- }
- end();
- insert(eq);
- insert(pipeThroughExtern(lang, extra, ar));
- return;
- }
-
- if (hull->getType() == "equation") {
- lyxerr << "use equation inset\n";
- hull->mutate("eqnarray");
- MathArray & ar = cursor().cell();
- lyxerr << "use cell: " << ar << "\n";
- idxRight();
- cursor().cell() = eq;
- idxRight();
- cursor().cell() = pipeThroughExtern(lang, extra, ar);
- idxLineLast();
- return;
- }
-
- {
- lyxerr << "use eqnarray\n";
- idxLineLast();
- MathArray ar = cursor().cell();
- lyxerr << "use cell: " << ar << "\n";
-#ifdef WITH_WARNINGS
-#warning temporarily disabled
-#endif
- //breakLine();
- //idxRight();
- cursor().cell() = eq;
- //idxRight();
- cursor().cell() = pipeThroughExtern(lang, extra, ar);
- idxLineLast();
- }
-
-}
-
-
MathInset::result_type MathCursor::dispatch(FuncRequest const & cmd)
{
// try to dispatch to adajcent items if they are not editable