3 * Purpose: Interaction for mathed
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Math interaction for a WYSIWYG math editor.
8 * Dependencies: Xlib, XForms
10 * Copyright: 1996, Alejandro Aguilar Sierra
12 * Version: 0.8beta, Math & Lyx project.
14 * You are free to use and modify this code under the terms of
15 * the GNU General Public Licence version 2 or later.
19 #pragma implementation
26 #include "support/lstrings.h"
31 #include "formulabase.h"
32 #include "math_cursor.h"
33 #include "math_factory.h"
34 #include "math_arrayinset.h"
35 #include "math_charinset.h"
36 #include "math_deliminset.h"
37 #include "math_matrixinset.h"
38 #include "math_scriptinset.h"
39 #include "math_spaceinset.h"
40 #include "math_specialcharinset.h"
41 #include "math_parser.h"
55 void grab(MathCursor const & cursor)
60 cursor.getSelection(i1, i2);
61 if (i1.idx_ == i2.idx_) {
64 ar.push_back(*i1.at());
65 ar.back().removeNucleus();
68 ar.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
70 ar.push_back(*i2.at());
72 ar.back().removeDown();
77 std::vector<MathInset::idx_type> indices =
78 i1.par_->idxBetween(i1.idx_, i2.idx_);
79 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
80 data_.push_back(i1.cell(indices[i]));
84 void erase(MathCursor & cursor)
88 cursor.getSelection(i1, i2);
89 if (i1.idx_ == i2.idx_) {
93 i1.at()->removeDown();
98 i2.at()->removeNucleus();
100 i1.cell().erase(i1.pos_, i2.pos_);
102 std::vector<MathInset::idx_type> indices =
103 i1.par_->idxBetween(i1.idx_, i2.idx_);
104 for (unsigned i = 0; i < indices.size(); ++i)
105 i1.cell(indices[i]).erase();
107 cursor.cursor() = i1;
110 void paste(MathCursor & cursor) const
112 cursor.insert(glue());
115 // glues selection to one cell
116 MathArray glue() const
119 for (unsigned i = 0; i < data_.size(); ++i)
120 ar.push_back(data_[i]);
129 std::vector<MathArray> data_;
133 Selection theSelection;
137 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
139 os << "(par: " << p.par_ << " idx: " << p.idx_
140 << " pos: " << p.pos_ << " inner: " << p.inner_ << ")";
148 MathCursor::MathCursor(InsetFormulaBase * formula)
149 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
155 void MathCursor::pushLeft(MathInset * par)
160 par->idxFirst(p.idx_, p.pos_);
161 Cursor_.push_back(p);
165 void MathCursor::pushRight(MathInset * par)
171 par->idxLast(p.idx_, p.pos_);
172 Cursor_.push_back(p);
176 bool MathCursor::popLeft()
178 if (Cursor_.size() <= 1)
181 nextAtom()->removeEmptyScripts();
184 nextAtom()->removeEmptyScripts();
189 bool MathCursor::popRight()
191 if (Cursor_.size() <= 1)
194 nextAtom()->removeEmptyScripts();
197 nextAtom()->removeEmptyScripts();
205 void MathCursor::dump(char const *) const
207 lyxerr << "MC: " << what << "\n";
208 for (unsigned i = 0; i < Cursor_.size(); ++i)
209 lyxerr << " i: " << i
210 << " pos: " << Cursor_[i].pos_
211 << " idx: " << Cursor_[i].idx_
212 << " par: " << Cursor_[i].par_ << "\n";
213 //lyxerr << " sel: " << selection_ << " data: " << array() << "\n";
216 void MathCursor::seldump(char const * str) const
218 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
221 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
222 << str << "\ntheSelection: " << selection_
223 << " '" << theSelection.glue() << "'\n";
224 for (unsigned int i = 0; i < Cursor_.size(); ++i)
225 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
227 for (unsigned int i = 0; i < Anchor_.size(); ++i)
228 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
229 //lyxerr << "\ncursor.pos_: " << pos();
230 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
231 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
236 void MathCursor::seldump(char const *) const {}
237 void MathCursor::dump(char const *) const {}
242 bool MathCursor::isInside(MathInset const * p) const
244 for (unsigned i = 0; i < Cursor_.size(); ++i)
245 if (Cursor_[i].par_ == p)
251 bool MathCursor::openable(MathInset * p, bool sel) const
260 // we can't move into anything new during selection
261 if (Cursor_.size() == Anchor_.size())
263 if (p != Anchor_[Cursor_.size()].par_)
270 MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
276 // we can't move into anything new during selection
277 if (Cursor_.size() == Anchor_.size())
279 //if (t != Anchor_[Cursor_.size()].par_)
286 if (p && p->nargs() && p->covers(x, y))
290 if (p && p->nargs() && p->covers(x, y))
294 if (p && p->nargs() && p->covers(x, y))
301 bool MathCursor::posLeft()
313 if (nextAtom()->hasInner())
320 bool MathCursor::posRight()
331 if (nextAtom()->hasInner())
340 bool MathCursor::left(bool sel)
345 lastcode_ = LM_TC_VAR;
349 lastcode_ = LM_TC_VAR;
351 MathInset * p = prevInset();
352 if (openable(p, sel)) {
357 return posLeft() || idxLeft() || popLeft();
361 bool MathCursor::right(bool sel)
366 lastcode_ = LM_TC_VAR;
370 lastcode_ = LM_TC_VAR;
372 MathInset * p = nextInset();
373 if (openable(p, sel)) {
378 return posRight() || idxRight() || popRight();
382 void MathCursor::first()
385 pushLeft(outerPar());
389 void MathCursor::last()
396 void MathCursor::setPos(int x, int y)
399 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
402 lastcode_ = LM_TC_VAR;
405 cursor().par_ = outerPar();
410 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
411 int distmin = 1 << 30; // large enough
412 for (unsigned int i = 0; i < par()->nargs(); ++i) {
413 MathXArray const & ar = par()->xcell(i);
414 int x1 = x - ar.xo();
415 int y1 = y - ar.yo();
416 MathXArray::size_type c = ar.x2pos(x1);
417 int xx = abs(x1 - ar.pos2x(c, false));
419 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
420 // << " c: " << c << " xo: " << ar.xo() << "\n";
421 if (yy + xx <= distmin) {
427 //lyxerr << "found idx: " << idx() << " cursor: "
429 if (MathInset * p = positionable(nextAtom(), x, y))
431 else if (MathInset * p = positionable(prevAtom(), x, y))
440 void MathCursor::home(bool sel)
445 lastcode_ = LM_TC_VAR;
446 if (!par()->idxHome(idx(), pos()))
452 void MathCursor::end(bool sel)
457 lastcode_ = LM_TC_VAR;
458 if (!par()->idxEnd(idx(), pos()))
464 void MathCursor::plainErase()
466 array().erase(pos());
470 void MathCursor::plainInsert(MathInset * p)
473 array().insert(pos(), p);
475 swap(prevAtom()->nucleus(), nextAtom()->nucleus());
479 MathAtom * n = nextAtom();
481 if (n && !n->nucleus()) {
487 array().insert(pos(), p); // this invalidates the pointer!
492 void MathCursor::insert(char c, MathTextCodes t)
494 //lyxerr << "inserting '" << c << "'\n";
495 plainInsert(new MathCharInset(c, t));
499 void MathCursor::insert(MathInset * p)
503 if (p && selection_) {
514 void MathCursor::niceInsert(MathInset * p)
517 lyxerr << "should not happen\n";
521 //cerr << "\n2: "; p->write(cerr, true); cerr << "\n";
522 insert(p); // inserting invalidates the pointer!
523 p = prevAtom()->nucleus();
524 //cerr << "\n3: "; p->write(cerr, true); cerr << "\n";
527 right(); // do not push for e.g. MathSymbolInset
530 p->metrics(p->size());
534 void MathCursor::insert(MathArray const & ar)
540 array().insert(pos(), ar);
545 void MathCursor::glueAdjacentAtoms()
547 MathAtom * p = prevAtom();
551 MathAtom * n = nextAtom();
555 if (p->up() && n->up())
558 if (p->down() && n->down())
561 // move everything to the previous atom
563 swap(p->up(), n->up());
566 swap(p->down(), n->down());
570 inner() = nextAtom()->hasInner();
574 void MathCursor::backspace()
577 nextAtom()->removeNucleus();
589 if (prevAtom()->hasInner()) {
600 void MathCursor::erase()
610 // delete empty cells if necessary
611 if (array().empty()) {
614 par()->idxDelete(idx(), popit, removeit);
615 if (popit && popLeft() && removeit)
620 MathAtom * n = nextAtom();
630 if (!n->up() && !n->down()) {
647 void MathCursor::delLine()
656 if (par()->nrows() > 1)
657 par()->delRow(row());
661 bool MathCursor::up(bool sel)
670 // check whether we could move into a superscript on the right or on the left
671 if (prevAtom() && prevAtom()->up()) {
672 pushRight(prevAtom()->up());
676 if (nextAtom() && nextAtom()->up()) {
677 pushLeft(nextAtom()->up());
685 bool MathCursor::down(bool sel)
694 // check whether we could move into an subscript on the right or on the left
695 if (prevAtom() && prevAtom()->down()) {
696 pushRight(prevAtom()->down());
700 if (nextAtom() && nextAtom()->down()) {
701 pushLeft(nextAtom()->down());
709 bool MathCursor::toggleLimits()
711 MathAtom * t = prevAtom();
714 int old = t->limits();
715 t->limits(old < 0 ? 1 : -1);
716 return old != t->limits();
720 void MathCursor::setSize(MathStyles size)
722 par()->userSetSize(size);
726 void MathCursor::macroModeClose()
728 string s = macroName();
730 pos() = pos() - s.size() - 1;
731 for (unsigned i = 0; i <= s.size(); ++i)
733 lastcode_ = LM_TC_VAR;
739 string MathCursor::macroName() const
742 for (int i = pos() - 1; i >= 0; --i) {
743 MathInset * p = array().at(i)->nucleus();
744 if (!p || p->code() != LM_TC_TEX || p->getChar() == '\\')
746 s = p->getChar() + s;
752 void MathCursor::selCopy()
756 theSelection.grab(*this);
762 void MathCursor::selCut()
766 theSelection.grab(*this);
767 theSelection.erase(*this);
770 theSelection.clear();
775 void MathCursor::selDel()
779 theSelection.erase(*this);
785 void MathCursor::selPaste()
788 theSelection.paste(*this);
793 void MathCursor::selHandle(bool sel)
795 if (sel == selection_)
798 theSelection.clear();
804 void MathCursor::selStart()
810 theSelection.clear();
816 void MathCursor::selClear()
823 void MathCursor::drawSelection(Painter & pain) const
830 getSelection(i1, i2);
832 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
834 if (i1.idx_ == i2.idx_) {
835 MathXArray & c = i1.xcell();
836 int x1 = c.xo() + c.pos2x(i1.pos_, i1.inner_);
837 int y1 = c.yo() - c.ascent();
838 int x2 = c.xo() + c.pos2x(i2.pos_, i2.inner_);
839 int y2 = c.yo() + c.descent();
840 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
842 std::vector<MathInset::idx_type> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
843 for (unsigned i = 0; i < indices.size(); ++i) {
844 MathXArray & c = i1.xcell(indices[i]);
846 int y1 = c.yo() - c.ascent();
847 int x2 = c.xo() + c.width();
848 int y2 = c.yo() + c.descent();
849 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
855 MathTextCodes MathCursor::nextCode() const
857 //return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
862 void MathCursor::handleFont(MathTextCodes t)
868 getSelection(i1, i2);
869 if (i1.idx_ == i2.idx_) {
870 MathArray & ar = i1.cell();
871 for (MathInset::pos_type pos = i1.pos_;
872 pos != i2.pos_; ++pos) {
873 MathInset * p = ar.at(pos)->nucleus();
879 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
883 void MathCursor::handleDelim(string const & l, string const & r)
885 handleNest(new MathDelimInset(l, r));
889 void MathCursor::handleNest(MathInset * p)
893 p->cell(0) = theSelection.glue();
895 insert(p); // this invalidates p!
896 p = prevAtom()->nucleus();
901 void MathCursor::getPos(int & x, int & y)
904 #warning This should probably take cellXOffset and cellYOffset into account
906 x = xarray().xo() + xarray().pos2x(pos(), inner());
911 MathInset * MathCursor::par() const
913 return cursor().par_;
917 InsetFormulaBase const * MathCursor::formula()
923 MathCursor::idx_type MathCursor::idx() const
925 return cursor().idx_;
929 MathCursor::idx_type & MathCursor::idx()
931 return cursor().idx_;
935 MathCursor::pos_type MathCursor::pos() const
937 return cursor().pos_;
941 MathCursor::pos_type & MathCursor::pos()
943 return cursor().pos_;
947 bool MathCursor::inner() const
949 return cursor().inner_;
953 bool & MathCursor::inner()
955 return cursor().inner_;
959 bool MathCursor::inMacroMode() const
961 return lastcode_ == LM_TC_TEX;
965 bool MathCursor::selection() const
971 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
973 for (int i = Cursor_.size() - 1; i >= 0; --i) {
974 if (Cursor_[i].par_->isArray()) {
975 idx = Cursor_[i].idx_;
976 return static_cast<MathArrayInset *>(Cursor_[i].par_);
983 void MathCursor::pullArg(bool goright)
987 MathArray a = array();
990 array().insert(pos(), a);
997 MathStyles MathCursor::style() const
999 return xarray().style();
1003 void MathCursor::normalize() const
1005 #ifdef WITH_WARNINGS
1006 #warning This is evil!
1008 MathCursor * it = const_cast<MathCursor *>(this);
1010 if (idx() >= par()->nargs()) {
1011 lyxerr << "this should not really happen - 1: "
1012 << idx() << " " << par()->nargs() << "\n";
1015 it->idx() = min(idx(), par()->nargs() - 1);
1017 if (pos() > size()) {
1018 lyxerr << "this should not really happen - 2: "
1019 << pos() << " " << size() << "\n";
1022 it->pos() = min(pos(), size());
1026 MathCursor::size_type MathCursor::size() const
1028 return array().size();
1032 MathCursor::col_type MathCursor::col() const
1034 return par()->col(idx());
1038 MathCursor::row_type MathCursor::row() const
1040 return par()->row(idx());
1045 char MathCursorPos::getChar() const
1047 return array().getChar(pos());
1051 string MathCursorPos::readString()
1054 int code = nextCode();
1055 for ( ; OK() && nextCode() == code; Next())
1063 MathInset * MathCursor::prevInset() const
1065 return prevAtom() ? prevAtom()->nucleus() : 0;
1069 MathInset * MathCursor::nextInset() const
1071 return nextAtom() ? nextAtom()->nucleus() : 0;
1075 MathSpaceInset * MathCursor::prevSpaceInset() const
1077 MathInset * p = prevInset();
1078 return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
1082 MathAtom const * MathCursor::prevAtom() const
1084 return array().at(pos() - 1);
1088 MathAtom * MathCursor::prevAtom()
1090 return array().at(pos() - 1);
1094 MathAtom const * MathCursor::nextAtom() const
1096 return array().at(pos());
1100 MathAtom * MathCursor::nextAtom()
1102 return array().at(pos());
1106 MathArray & MathCursor::array() const
1108 static MathArray dummy;
1110 lyxerr << "############ par_ not valid\n";
1114 if (idx() >= par()->nargs()) {
1115 lyxerr << "############ idx_ " << idx() << " not valid\n";
1119 return cursor().cell();
1123 MathXArray & MathCursor::xarray() const
1125 return cursor().xcell();
1129 void MathCursor::idxNext()
1131 par()->idxNext(idx(), pos());
1135 void MathCursor::idxPrev()
1137 par()->idxPrev(idx(), pos());
1141 void MathCursor::splitCell()
1143 if (idx() == par()->nargs() - 1)
1145 MathArray ar = array();
1147 array().erase(pos(), size());
1150 array().insert(0, ar);
1154 void MathCursor::breakLine()
1156 // leave inner cells
1160 MathMatrixInset * p = outerPar();
1161 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1162 p->mutate(LM_OT_EQNARRAY);
1169 const row_type r = row();
1170 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1171 const MathMatrixInset::idx_type i1 = p->index(r, c);
1172 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1173 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1174 p->cell(i1).swap(p->cell(i2));
1179 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1184 char MathCursor::valign() const
1187 MathArrayInset * p = enclosingArray(idx);
1188 return p ? p->valign() : '\0';
1192 char MathCursor::halign() const
1195 MathArrayInset * p = enclosingArray(idx);
1196 return p ? p->halign(idx % p->ncols()) : '\0';
1200 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1202 MathCursorPos anc = normalAnchor();
1203 if (anc < cursor()) {
1213 MathCursorPos & MathCursor::cursor()
1215 return Cursor_.back();
1219 MathCursorPos const & MathCursor::cursor() const
1221 return Cursor_.back();
1225 int MathCursor::cellXOffset() const
1227 return par()->cellXOffset(idx());
1231 int MathCursor::cellYOffset() const
1233 return par()->cellYOffset(idx());
1237 int MathCursor::xpos() const
1239 return cellXOffset() + xarray().pos2x(pos(), inner());
1243 int MathCursor::ypos() const
1245 return cellYOffset();
1250 void MathCursor::gotoX(int x)
1252 pos() = xarray().x2pos(x - cellXOffset());
1256 bool MathCursor::goUp()
1258 // first ask the inset if it knows better then we
1259 if (par()->idxUp(idx(), pos()))
1262 // leave subscript to the nearest side
1263 if (par()->asScriptInset() && par()->asScriptInset()->down()) {
1264 if (pos() <= size() / 2)
1271 // if not, apply brute force.
1275 std::vector<MathCursorPos> save = Cursor_;
1276 y0 -= xarray().ascent();
1277 for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
1279 if (save != Cursor_ && xarray().yo() < y0)
1287 bool MathCursor::goDown()
1289 // first ask the inset if it knows better then we
1290 if (par()->idxDown(idx(), pos()))
1293 // leave superscript to the nearest side
1294 if (par()->asScriptInset() && par()->asScriptInset()->up()) {
1295 if (pos() <= size() / 2)
1302 // if not, apply brute force.
1306 std::vector<MathCursorPos> save = Cursor_;
1307 y0 += xarray().descent();
1308 for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
1310 if (save != Cursor_ && xarray().yo() > y0)
1318 bool MathCursor::idxLeft()
1320 return par()->idxLeft(idx(), pos());
1324 bool MathCursor::idxRight()
1326 return par()->idxRight(idx(), pos());
1330 MathMatrixInset * MathCursor::outerPar() const
1333 static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
1337 void MathCursor::interpret(string const & s)
1339 //lyxerr << "interpret: '" << s << "'\n";
1340 //lyxerr << "in: " << in_word_set(s) << " \n";
1347 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
1348 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
1349 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
1351 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1356 istringstream is(s.substr(7).c_str());
1357 is >> m >> n >> v_align >> h_align;
1358 m = std::max(1u, m);
1359 n = std::max(1u, n);
1361 MathArrayInset * p = new MathArrayInset(m, n);
1362 p->valign(v_align[0]);
1368 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1369 MathArray ar = array();
1370 MathInset * p = createMathInset(s.substr(1));
1371 p->cell(0).swap(array());
1380 niceInsert(createMathInset(s.substr(1)));
1385 // we got just a single char now
1387 if (c == '^' || c == '_') {
1388 const bool up = (s[0] == '^');
1394 MathInset * par = prevAtom()->ensure(up);
1403 if (lastcode_ == LM_TC_TEXTRM) {
1404 insert(c, LM_TC_TEXTRM);
1409 if (inMacroMode()) {
1411 lastcode_ = LM_TC_VAR;
1415 MathSpaceInset * p = prevSpaceInset();
1421 if (mathcursor->popRight())
1425 // this would not work if the inset is in an table!
1426 //bv->text->cursorRight(bv, true);
1427 //result = FINISHED;
1431 if (lastcode_ != LM_TC_TEX && strchr("{}", c)) {
1432 insert(c, LM_TC_TEX);
1436 if (lastcode_ != LM_TC_TEX && strchr("#$%", c)) {
1437 insert(new MathSpecialCharInset(c));
1438 lastcode_ = LM_TC_VAR;
1442 if (lastcode_ == LM_TC_TEX) {
1443 if (macroName().empty()) {
1444 insert(c, LM_TC_TEX);
1445 if (!isalpha(c) && c != '#') {
1447 lastcode_ = LM_TC_VAR;
1450 if ('1' <= c && c <= '9' && macroName() == "#") {
1451 insert(c, LM_TC_TEX);
1453 lastcode_ = LM_TC_VAR;
1455 else if (isalpha(c)) {
1456 insert(c, LM_TC_TEX);
1460 lastcode_ = LM_TC_VAR;
1466 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1467 static char const greekl[][26] =
1468 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1469 "gamma", "eta", "iota", "iota", "kappa", "lambda", "mu",
1470 "nu", "omikron", "pi", "omega", "rho", "sigma",
1471 "tau", "upsilon", "theta", "omega", "xi", "upsilon", "zeta"};
1472 static char const greeku[][26] =
1473 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1474 "Gamma", "Eta", "Iota", "Iota", "Kappa", "Lambda", "Mu",
1475 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1476 "Upsilon", "Theta", "Omega", "xi", "Upsilon", "Zeta"};
1478 latexkeys const * l = 0;
1479 if ('a' <= c && c <= 'z')
1480 l = in_word_set(greekl[c - 'a']);
1481 if ('A' <= c && c <= 'Z')
1482 l = in_word_set(greeku[c - 'A']);
1485 insert(createMathInset(l));
1487 insert(c, LM_TC_VAR);
1489 #warning greek insert problem? look here!
1490 if (lastcode_ == LM_TC_GREEK1)
1491 lastcode_ = LM_TC_VAR;
1496 lastcode_ = LM_TC_TEX;
1497 insert(c, LM_TC_TEX);
1498 //bv->owner()->message(_("TeX mode"));
1502 // no special circumstances, so insert the character without any fuss
1503 insert(c, LM_TC_MIN);
1508 ////////////////////////////////////////////////////////////////////////
1511 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1513 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1517 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1519 if (ti.par_ != it.par_) {
1520 lyxerr << "can't compare cursor and anchor in different insets\n";
1523 if (ti.idx_ != it.idx_)
1524 return ti.idx_ < it.idx_;
1525 return ti.pos_ < it.pos_;
1529 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1531 return par_->cell(idx);
1535 MathArray & MathCursorPos::cell() const
1537 return par_->cell(idx_);
1541 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1543 return par_->xcell(idx);
1547 MathXArray & MathCursorPos::xcell() const
1549 return par_->xcell(idx_);
1553 MathAtom * MathCursorPos::at() const
1555 return cell().at(pos_);
1559 MathCursorPos MathCursor::normalAnchor() const
1561 // use Anchor on the same level as Cursor
1562 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1563 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1564 // anchor is behind cursor -> move anchor behind the inset