#include <algorithm>
#include <cctype>
-#include "math_inset.h"
-#include "math_arrayinset.h"
-#include "math_parser.h"
-#include "math_cursor.h"
-#include "math_macro.h"
-#include "math_macroarg.h"
-#include "math_macrotable.h"
-#include "math_root.h"
-#include "support/lstrings.h"
#include "debug.h"
#include "LColor.h"
#include "Painter.h"
-#include "math_matrixinset.h"
-#include "math_grid.h"
-#include "math_spaceinset.h"
-#include "math_funcinset.h"
+#include "mathed/support.h"
+#include "formulabase.h"
+#include "math_cursor.h"
+#include "math_arrayinset.h"
#include "math_bigopinset.h"
-#include "math_fracinset.h"
#include "math_decorationinset.h"
-#include "math_dotsinset.h"
#include "math_deliminset.h"
+#include "math_dotsinset.h"
+#include "math_fracinset.h"
+#include "math_funcinset.h"
+#include "math_gridinset.h"
+#include "math_macro.h"
+#include "math_macroarg.h"
+#include "math_macrotable.h"
#include "math_macrotemplate.h"
+#include "math_matrixinset.h"
+#include "math_rootinset.h"
+#include "math_spaceinset.h"
#include "math_sqrtinset.h"
+#include "support/lstrings.h"
#include "math_scriptinset.h"
-#include "mathed/support.h"
-#include "formulabase.h"
-
+#include "math_parser.h"
using std::endl;
using std::min;
std::vector<MathArray> data_;
};
-Selection theSelection;
+Selection theSelection;
bool IsMacro(short tok, int id)
!(tok == LM_TK_SYM && id < 255);
}
-ostream & operator<<(ostream & os, MathCursorPos const & p)
+
+std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
{
- os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
+ os << "(par: " << p.par_ << " idx: " << p.idx_
+ << " pos: " << p.pos_ << ")";
return os;
}
return Cursor_[i].par_;
}
+
void MathCursor::dump(char const * what) const
{
return;
- lyxerr << "MC: " << what
- << " cursor.pos: " << cursor().pos_
- << " cursor.idx: " << cursor().idx_
- << " cursor.par: " << cursor().par_
- << " sel: " << selection
- << " data: " << array()
- << "\n";
+ lyxerr << "MC: " << what << "\n";
+ for (unsigned i = 0; i < Cursor_.size(); ++i)
+ lyxerr << " i: " << i
+ << " pos: " << Cursor_[i].pos_
+ << " idx: " << Cursor_[i].idx_
+ << " par: " << Cursor_[i].par_ << "\n";
+
+ //lyxerr << " sel: " << selection << " data: " << array() << "\n";
}
+
void MathCursor::seldump(char const *) const
{
//lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
return true;
}
+
bool MathCursor::plainLeft()
{
return array().prev(cursor().pos_);
MathInset * p = prevInset();
if (openable(p, sel, false)) {
- array().prev(cursor().pos_);
+ plainLeft();
push(p, false);
return true;
}
- if (array().prev(cursor().pos_))
+ if (plainLeft())
return true;
if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
return true;
if (openable(n, selection, true) && n->covers(x, y))
push(n, true);
else if (openable(p, selection, true) && p->covers(x, y)) {
- array().prev(cursor().pos_);
+ plainLeft();
push(p, false);
} else
break;
Delete();
}
-#ifdef WITH_WARNINGS
-#warning pullArg disabled
-#endif
- //if (cursor().pos_ == 0 && Cursor_.size() >= 1) {
- // lyxerr << "Delete: popping...\n";
- // pop();
- //}
-
dump("Delete 2");
}
if (p) {
int idx, pos;
if (p->idxLastUp(idx, pos)) {
- array().prev(cursor().pos_);
+ plainLeft();
push(p, false);
cursor().par_ = p;
cursor().idx_ = idx;
if (p) {
int idx, pos;
if (p->idxLastDown(idx, pos)) {
- array().prev(cursor().pos_);
+ plainLeft();
push(p, false);
cursor().idx_ = idx;
cursor().pos_ = pos;
if (!p) {
p = new MathScriptInset(true, false);
insert(p);
- array().prev(cursor().pos_);
+ plainLeft();
}
push(p, true);
p->up(true);
if (!p) {
p = new MathScriptInset(false, true);
insert(p);
- array().prev(cursor().pos_);
+ plainLeft();
}
push(p, true);
p->down(true);
p = new MathBigopInset(l->name, l->id);
break;
- case LM_TK_SYM:
- if (l->id < 255)
- insert(l->id, MathIsBOPS(l->id) ? LM_TC_BOPS : LM_TC_SYMB);
+ case LM_TK_SYM: {
+ MathTextCodes code = static_cast<MathTextCodes>(l->id);
+ if (code < 255)
+ insert(l->id, MathIsBOPS(code) ? LM_TC_BOPS : LM_TC_SYMB);
else
p = new MathFuncInset(l->name);
break;
+ }
case LM_TK_STACK:
p = new MathFracInset("stackrel");
SelCut();
insert(p);
if (p->nargs()) {
- array().prev(cursor().pos_);
+ plainLeft();
push(p, true);
if (oldsel)
SelPaste();
}
}
+
void MathCursor::SelCut()
{
seldump("SelCut");
SelClear();
}
+
void MathCursor::SelHandle(bool sel)
{
if (sel && !selection)
}
-
void MathCursor::drawSelection(Painter & pain) const
{
if (!selection)
push(p, true);
}
+
void MathCursor::handleDelim(int l, int r)
{
MathDelimInset * p = new MathDelimInset(l, r);
p->cell(0) = theSelection.glue();
}
insert(p);
+ plainLeft();
push(p, true);
}
return 0;
}
+
void MathCursor::pullArg()
{
// pullArg
+ dump("pullarg");
MathArray a = array();
- if (!Left())
- return;
- normalize();
- array().erase(cursor().pos_);
- array().insert(cursor().pos_, a);
+ if (pop()) {
+ array().erase(cursor().pos_);
+ array().insert(cursor().pos_, a);
+ }
}
}
*/
+
MathInset * MathCursor::prevInset() const
{
normalize();
return xarray().pos2x(cursor().pos_);
}
+
void MathCursor::gotoX(int x)
{
cursor().pos_ = xarray().x2pos(x);
}
+
void MathCursor::idxNext()
{
cursor().par_->idxNext(cursor().idx_, cursor().pos_);
}
+
void MathCursor::idxPrev()
{
cursor().par_->idxPrev(cursor().idx_, cursor().pos_);
}
+
void MathCursor::splitCell()
{
if (cursor().idx_ == cursor().par_->nargs() - 1)
array().insert(0, ar);
}
+
void MathCursor::breakLine()
{
MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
}
}
+
char MathCursor::valign() const
{
int idx;
return p ? p->valign() : 0;
}
+
char MathCursor::halign() const
{
int idx;
////////////////////////////////////////////////////////////////////////
-bool MathCursorPos::operator==(const MathCursorPos & it) const
+bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
{
- return par_ == it.par_ && idx_ == it.idx_ && pos_ == it.pos_;
+ return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
}
-bool MathCursorPos::operator<(const MathCursorPos & it) const
+
+bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
{
- if (par_ != it.par_) {
+ if (ti.par_ != it.par_) {
lyxerr << "can't compare cursor and anchor in different insets\n";
return true;
}
- if (idx_ != it.idx_)
- return idx_ < it.idx_;
- return pos_ < it.pos_;
+ if (ti.idx_ != it.idx_)
+ return ti.idx_ < it.idx_;
+ return ti.pos_ < it.pos_;
}
return par_->xcell(idx);
}
+
MathXArray & MathCursorPos::xcell() const
{
return par_->xcell(idx_);
}
+
MathCursorPos MathCursor::normalAnchor() const
{
// use Anchor on the same level as Cursor
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
- if (Cursor_.size() < Anchor_.size() && !(cursor() > normal)) {
+ if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset
normal.cell().next(normal.pos_);
}
return normal;
}
+
bool MathCursorPos::idxUp()
{
return par_->idxUp(idx_, pos_);
}
+
bool MathCursorPos::idxDown()
{
return par_->idxDown(idx_, pos_);
}
+
bool MathCursorPos::idxLeft()
{
return par_->idxLeft(idx_, pos_);
}
+
bool MathCursorPos::idxRight()
{
return par_->idxRight(idx_, pos_);