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"
27 #include "support/LAssert.h"
31 #include "formulabase.h"
32 #include "math_arrayinset.h"
33 #include "math_braceinset.h"
34 #include "math_casesinset.h"
35 #include "math_charinset.h"
36 #include "math_cursor.h"
37 #include "math_deliminset.h"
38 #include "math_factory.h"
39 #include "math_hullinset.h"
40 #include "math_iterator.h"
41 #include "math_mathmlstream.h"
42 #include "math_parser.h"
43 #include "math_replace.h"
44 #include "math_scriptinset.h"
45 #include "math_spaceinset.h"
46 #include "math_specialcharinset.h"
47 #include "math_support.h"
61 void grab(MathCursor const & cursor)
66 cursor.getSelection(i1, i2);
67 if (i1.idx_ == i2.idx_)
68 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
70 std::vector<MathInset::idx_type> indices =
71 i1.par_->idxBetween(i1.idx_, i2.idx_);
72 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
73 data_.push_back(i1.cell(indices[i]));
77 void erase(MathCursor & cursor)
81 cursor.getSelection(i1, i2);
82 if (i1.idx_ == i2.idx_)
83 i1.cell().erase(i1.pos_, i2.pos_);
85 std::vector<MathInset::idx_type> indices =
86 i1.par_->idxBetween(i1.idx_, i2.idx_);
87 for (unsigned i = 0; i < indices.size(); ++i)
88 i1.cell(indices[i]).erase();
93 void paste(MathCursor & cursor) const
95 MathArray ar = glue();
99 // glues selection to one cell
100 MathArray glue() const
103 for (unsigned i = 0; i < data_.size(); ++i)
104 ar.push_back(data_[i]);
113 std::vector<MathArray> data_;
117 Selection theSelection;
124 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
125 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
127 left ? first() : last();
131 void MathCursor::push(MathAtom & t)
133 Cursor_.push_back(MathCursorPos(t.nucleus()));
137 void MathCursor::pushLeft(MathAtom & t)
139 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
141 t->idxFirst(idx(), pos());
145 void MathCursor::pushRight(MathAtom & t)
147 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
150 t->idxLast(idx(), pos());
154 bool MathCursor::popLeft()
156 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
157 if (Cursor_.size() <= 1)
160 // nextInset()->removeEmptyScripts();
163 // nextAtom()->removeEmptyScripts();
168 bool MathCursor::popRight()
170 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
171 if (Cursor_.size() <= 1)
174 // nextInset()->removeEmptyScripts();
177 // nextInset()->removeEmptyScripts();
185 void MathCursor::dump(char const * what) const
187 lyxerr << "MC: " << what << "\n";
188 lyxerr << " Cursor: " << Cursor_.size() << "\n";
189 for (unsigned i = 0; i < Cursor_.size(); ++i)
190 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
191 lyxerr << " Anchor: " << Anchor_.size() << "\n";
192 for (unsigned i = 0; i < Anchor_.size(); ++i)
193 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
194 lyxerr << " sel: " << selection_ << "\n";
197 void MathCursor::dump(char const *) const {}
201 UpdatableInset * MathCursor::asHyperActiveInset() const
203 return par()->asHyperActiveInset();
207 bool MathCursor::isInside(MathInset const * p) const
209 for (unsigned i = 0; i < Cursor_.size(); ++i)
210 if (Cursor_[i].par_ == p)
216 bool MathCursor::openable(MathAtom const & t, bool sel) const
218 if (t->isHyperActive())
224 if (t->asScriptInset())
228 // we can't move into anything new during selection
229 if (Cursor_.size() == Anchor_.size())
231 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
238 bool MathCursor::posLeft()
247 bool MathCursor::posRight()
256 bool MathCursor::left(bool sel)
261 lastcode_ = LM_TC_VAR;
265 lastcode_ = LM_TC_VAR;
267 if (hasPrevAtom() && openable(prevAtom(), sel)) {
268 if (prevAtom()->isHyperActive()) {
269 lyxerr << "entering hyperactive inset\n";
271 pushRight(prevAtom());
275 return posLeft() || idxLeft() || popLeft() || selection_;
279 bool MathCursor::right(bool sel)
284 lastcode_ = LM_TC_VAR;
288 lastcode_ = LM_TC_VAR;
290 if (hasNextAtom() && openable(nextAtom(), sel)) {
291 if (nextAtom()->isHyperActive()) {
292 lyxerr << "entering hyperactive inset\n";
295 nextAtom()->edit(formula()->view(), x, y, 0);
297 pushLeft(nextAtom());
301 return posRight() || idxRight() || popRight() || selection_;
305 void MathCursor::first()
308 pushLeft(formula_->par());
312 void MathCursor::last()
320 void MathCursor::setPos(int x, int y)
323 cursor_type best_cursor;
324 double best_dist = 1e10;
326 MathIterator it(formula()->par().nucleus());
328 for ( ; it != et; ++it) {
330 // avoid deeper nested insets when selecting
331 if (it.cursor().size() > Anchor_.size())
333 // anchor might be deeper!
334 if (it.cursor().size() == Anchor_.size())
335 if (it.par() != Anchor_.back().par_)
337 //if (it.par() != Anchor_[it.cursor().size()].par_)
340 //lyxerr << it.position() << endl;
341 int xo = it.position().xpos();
342 int yo = it.position().ypos();
343 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
346 best_cursor = it.cursor();
349 if (best_dist < 1e10)
350 Cursor_ = best_cursor;
351 //lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n";
357 void MathCursor::home(bool sel)
362 lastcode_ = LM_TC_VAR;
363 if (!par()->idxHome(idx(), pos()))
369 void MathCursor::end(bool sel)
374 lastcode_ = LM_TC_VAR;
375 if (!par()->idxEnd(idx(), pos()))
381 void MathCursor::plainErase()
383 array().erase(pos());
387 void MathCursor::plainInsert(MathAtom const & t)
389 array().insert(pos(), t);
394 void MathCursor::insert(char c, MathTextCodes t)
396 //lyxerr << "inserting '" << c << "'\n";
397 plainInsert(MathAtom(new MathCharInset(c, t)));
401 void MathCursor::insert(MathAtom const & t)
416 void MathCursor::niceInsert(MathAtom const & t)
419 insert(t); // inserting invalidates the pointer!
420 MathAtom const & p = prevAtom();
423 right(); // do not push for e.g. MathSymbolInset
429 void MathCursor::insert(MathArray const & ar)
435 array().insert(pos(), ar);
440 void MathCursor::paste(MathArray const & ar)
444 array().insert(pos(), ar);
449 void MathCursor::backspace()
461 MathScriptInset * p = prevAtom()->asScriptInset();
463 p->removeScript(p->hasUp());
464 // Don't delete if there is anything left
465 if (p->hasUp() || p->hasDown())
474 void MathCursor::erase()
484 // delete empty cells if necessary
485 if (array().empty()) {
488 par()->idxDelete(idx(), popit, removeit);
489 if (popit && popLeft() && removeit)
497 MathScriptInset * p = nextAtom()->asScriptInset();
499 p->removeScript(p->hasUp());
500 // Don't delete if there is anything left
501 if (p->hasUp() || p->hasDown())
509 void MathCursor::delLine()
518 if (par()->nrows() > 1)
519 par()->delRow(row());
521 if (idx() > par()->nargs())
522 idx() = par()->nargs();
529 bool MathCursor::up(bool sel)
536 MathInset::idx_type i = 0;
537 MathInset::pos_type p = 0;
539 // check whether we could move into the inset
540 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
541 pushRight(prevAtom());
547 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
548 pushLeft(nextAtom());
555 return goUp() || selection_;
559 bool MathCursor::down(bool sel)
566 MathInset::idx_type i = 0;
567 MathInset::pos_type p = 0;
569 // check whether we could move into the inset
570 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
571 pushRight(prevAtom());
577 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
578 pushLeft(nextAtom());
585 return goDown() || selection_;
589 bool MathCursor::toggleLimits()
593 MathScriptInset * t = nextAtom()->asScriptInset();
596 int old = t->limits();
597 t->limits(old < 0 ? 1 : -1);
598 return old != t->limits();
602 void MathCursor::macroModeClose()
604 string s = macroName();
606 size_type old = pos();
608 array().erase(pos(), old);
614 int MathCursor::macroNamePos() const
616 for (int i = pos() - 1; i >= 0; --i) {
617 MathAtom & p = array().at(i);
618 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
625 string MathCursor::macroName() const
628 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
629 s += array().at(i)->getChar();
634 void MathCursor::selCopy()
638 theSelection.grab(*this);
644 void MathCursor::selCut()
648 theSelection.grab(*this);
649 theSelection.erase(*this);
652 theSelection.clear();
657 void MathCursor::selDel()
661 theSelection.erase(*this);
669 void MathCursor::selPaste()
672 theSelection.paste(*this);
673 //theSelection.grab(*this);
678 void MathCursor::selHandle(bool sel)
680 if (sel == selection_)
682 //theSelection.clear();
688 void MathCursor::selStart()
691 //theSelection.clear();
698 void MathCursor::selClear()
706 void MathCursor::selGet(MathArray & ar)
712 theSelection.grab(*this);
713 ar = theSelection.glue();
718 void MathCursor::drawSelection(Painter & pain) const
725 getSelection(i1, i2);
726 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
728 if (i1.idx_ == i2.idx_) {
729 MathXArray & c = i1.xcell();
730 int x1 = c.xo() + c.pos2x(i1.pos_);
731 int y1 = c.yo() - c.ascent();
732 int x2 = c.xo() + c.pos2x(i2.pos_);
733 int y2 = c.yo() + c.descent();
734 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
736 std::vector<MathInset::idx_type> indices
737 = i1.par_->idxBetween(i1.idx_, i2.idx_);
738 for (unsigned i = 0; i < indices.size(); ++i) {
739 MathXArray & c = i1.xcell(indices[i]);
741 int y1 = c.yo() - c.ascent();
742 int x2 = c.xo() + c.width();
743 int y2 = c.yo() + c.descent();
744 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
749 // draw anchor if different from selection boundary
750 MathCursorPos anc = Anchor_.back();
751 if (anc != i1 && anc != i2) {
752 MathXArray & c = anc.xcell();
753 int x = c.xo() + c.pos2x(anc.pos_);
754 int y1 = c.yo() - c.ascent();
755 int y2 = c.yo() + c.descent();
756 pain.line(x, y1, x, y2, LColor::math);
762 void MathCursor::handleFont(MathTextCodes t)
768 getSelection(i1, i2);
769 if (i1.idx_ == i2.idx_) {
770 MathArray & ar = i1.cell();
771 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
772 ar.at(pos)->handleFont(t);
775 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
779 void MathCursor::handleDelim(string const & l, string const & r)
781 handleNest(new MathDelimInset(l, r));
785 void MathCursor::handleNest(MathInset * p)
789 p->cell(0) = theSelection.glue();
791 insert(MathAtom(p)); // this invalidates p!
792 pushRight(prevAtom());
796 void MathCursor::getPos(int & x, int & y)
799 #warning This should probably take cellXOffset and cellYOffset into account
802 x = xarray().xo() + xarray().pos2x(pos());
808 MathInset * MathCursor::par() const
810 return cursor().par_;
814 InsetFormulaBase const * MathCursor::formula()
820 MathCursor::idx_type MathCursor::idx() const
822 return cursor().idx_;
826 MathCursor::idx_type & MathCursor::idx()
828 return cursor().idx_;
832 MathCursor::pos_type MathCursor::pos() const
834 return cursor().pos_;
838 MathCursor::pos_type & MathCursor::pos()
840 return cursor().pos_;
844 bool MathCursor::inMacroMode() const
846 return macroNamePos() != -1;
850 bool MathCursor::selection() const
856 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
858 for (int i = Cursor_.size() - 1; i >= 0; --i) {
859 MathGridInset * p = Cursor_[i].par_->asGridInset();
861 idx = Cursor_[i].idx_;
869 void MathCursor::pullArg(bool goright)
872 MathArray a = array();
874 MathScriptInset const * p = par()->asScriptInset();
876 // special handling for scripts
877 const bool up = p->hasUp();
879 MathScriptInset * q = nextAtom()->asScriptInset();
883 array().insert(pos(), a);
889 array().insert(pos(), a);
896 void MathCursor::normalize() const
899 #warning This is evil!
901 MathCursor * it = const_cast<MathCursor *>(this);
903 if (idx() >= par()->nargs()) {
904 lyxerr << "this should not really happen - 1: "
905 << idx() << " " << par()->nargs() << "\n";
908 it->idx() = min(idx(), par()->nargs() - 1);
910 if (pos() > size()) {
911 lyxerr << "this should not really happen - 2: "
912 << pos() << " " << size() << " in idx: " << it->idx()
914 WriteStream wi(lyxerr, false);
915 it->par()->write(wi);
919 it->pos() = min(pos(), size());
923 MathCursor::size_type MathCursor::size() const
925 return array().size();
929 MathCursor::col_type MathCursor::col() const
931 return par()->col(idx());
935 MathCursor::row_type MathCursor::row() const
937 return par()->row(idx());
941 bool MathCursor::hasPrevAtom() const
947 bool MathCursor::hasNextAtom() const
949 return pos() < size();
953 MathAtom const & MathCursor::prevAtom() const
955 lyx::Assert(pos() > 0);
956 return array().at(pos() - 1);
960 MathAtom & MathCursor::prevAtom()
962 lyx::Assert(pos() > 0);
963 return array().at(pos() - 1);
967 MathAtom const & MathCursor::nextAtom() const
969 lyx::Assert(pos() < size());
970 return array().at(pos());
974 MathAtom & MathCursor::nextAtom()
976 lyx::Assert(pos() < size());
977 return array().at(pos());
981 MathArray & MathCursor::array() const
983 static MathArray dummy;
985 if (idx() >= par()->nargs()) {
986 lyxerr << "############ idx_ " << idx() << " not valid\n";
990 return cursor().cell();
994 MathXArray & MathCursor::xarray() const
996 return cursor().xcell();
1000 void MathCursor::idxNext()
1002 par()->idxNext(idx(), pos());
1006 void MathCursor::idxPrev()
1008 par()->idxPrev(idx(), pos());
1012 void MathCursor::splitCell()
1014 if (idx() + 1 == par()->nargs())
1016 MathArray ar = array();
1018 array().erase(pos(), size());
1021 array().insert(0, ar);
1025 void MathCursor::breakLine()
1027 // leave inner cells
1031 MathHullInset * p = formula()->par()->asHullInset();
1035 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1036 p->mutate(LM_OT_EQNARRAY);
1045 const row_type r = row();
1046 for (col_type c = col() + 1; c < p->ncols(); ++c)
1047 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1051 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1055 void MathCursor::readLine(MathArray & ar) const
1057 idx_type base = row() * par()->ncols();
1058 for (idx_type off = 0; off < par()->ncols(); ++off)
1059 ar.push_back(par()->cell(base + off));
1063 char MathCursor::valign() const
1066 MathGridInset * p = enclosingGrid(idx);
1067 return p ? p->valign() : '\0';
1071 char MathCursor::halign() const
1074 MathGridInset * p = enclosingGrid(idx);
1075 return p ? p->halign(idx % p->ncols()) : '\0';
1079 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1081 MathCursorPos anc = normalAnchor();
1082 if (anc < cursor()) {
1092 MathCursorPos & MathCursor::cursor()
1094 return Cursor_.back();
1098 MathCursorPos const & MathCursor::cursor() const
1100 return Cursor_.back();
1104 bool MathCursor::goUp()
1106 // first ask the inset if it knows better then we
1107 if (par()->idxUp(idx(), pos())) {
1108 //lyxerr << "ask cell\n";
1109 int xlow, xhigh, ylow, yhigh;
1110 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1111 bruteFind(xlow, xhigh, ylow, yhigh);
1115 // if not, apply brute force.
1116 //lyxerr << "brute force\n";
1122 xarray().yo() - 4 - xarray().ascent()
1127 bool MathCursor::goDown()
1129 // first ask the inset if it knows better then we
1130 if (par()->idxDown(idx(), pos())) {
1131 //lyxerr << "ask cell\n";
1132 int xlow, xhigh, ylow, yhigh;
1133 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1134 bruteFind(xlow, xhigh, ylow, yhigh);
1138 // if not, apply brute force.
1139 //lyxerr << "brute force\n";
1144 xarray().yo() + 4 + xarray().descent(),
1150 bool MathCursor::bruteFind(int xlow, int xhigh, int ylow, int yhigh)
1155 //lyxerr << "looking at range: "
1156 // << "[" << xlow << "..." << xhigh << "]"
1157 // << " x [" << ylow << "..." << yhigh << "]"
1158 // << " xo: " << x << " yo: " << y << "\n";
1160 cursor_type best_cursor;
1161 double best_dist = 1e10;
1163 MathIterator it(formula()->par().nucleus());
1165 for ( ; it != et; ++it) {
1166 int xo = it.position().xpos();
1167 int yo = it.position().ypos();
1168 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1169 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1170 if (d < best_dist) {
1172 best_cursor = it.cursor();
1176 if (best_dist < 1e10)
1177 Cursor_ = best_cursor;
1178 return best_dist < 1e10;
1182 bool MathCursor::idxLeft()
1184 return par()->idxLeft(idx(), pos());
1188 bool MathCursor::idxRight()
1190 return par()->idxRight(idx(), pos());
1194 bool MathCursor::interpret(string const & s)
1196 //lyxerr << "interpret 1: '" << s << "'\n";
1201 return interpret(s[0]);
1203 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1204 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1205 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1207 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1209 istringstream is(s.substr(5).c_str());
1211 n = std::max(1u, n);
1212 niceInsert(MathAtom(new MathCasesInset(n)));
1216 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1221 istringstream is(s.substr(6).c_str());
1222 is >> m >> n >> v_align >> h_align;
1223 m = std::max(1u, m);
1224 n = std::max(1u, n);
1226 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1230 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1232 istringstream is(s.substr(7).c_str());
1235 mathed_parse_cell(rep.from, from);
1236 mathed_parse_cell(rep.to, to);
1237 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1238 par()->replace(rep);
1242 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1243 MathArray ar = array();
1244 MathAtom t = createMathInset(s.substr(1));
1245 t->asNestInset()->cell(0).swap(array());
1253 niceInsert(createMathInset(s.substr(1)));
1258 bool MathCursor::interpret(char c)
1260 //lyxerr << "interpret 2: '" << c << "'\n";
1261 if (c == '^' || c == '_') {
1263 const bool up = (c == '^');
1265 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1266 prevAtom()->asScriptInset()->ensure(up);
1267 pushRight(prevAtom());
1270 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1271 nextAtom()->asScriptInset()->ensure(up);
1272 pushLeft(nextAtom());
1276 plainInsert(MathAtom(new MathScriptInset(up)));
1277 prevAtom()->asScriptInset()->ensure(up);
1278 pushRight(prevAtom());
1289 if (inMacroMode()) {
1290 string name = macroName();
1292 if (name == "\\" && c == '#') {
1293 insert(c, LM_TC_TEX);
1297 if (name == "\\" && c == '\\') {
1299 interpret("\\backslash");
1303 if (name == "\\#" && '1' <= c && c <= '9') {
1304 insert(c, LM_TC_TEX);
1310 insert(c, LM_TC_TEX);
1315 insert(c, LM_TC_TEX);
1327 if (lastcode_ == LM_TC_TEXTRM) {
1328 // suppress direct insertion of to spaces in a row
1329 // the still allows typing '<space>a<space>' and deleting the 'a', but
1330 // it is better than nothing
1331 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1333 insert(c, LM_TC_TEXTRM);
1338 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1339 prevAtom()->asSpaceInset()->incSpace();
1343 if (mathcursor->popRight())
1346 // if are at the very end, leave the formula
1347 return pos() != size();
1351 if (strchr("{}", c)) {
1352 insert(c, LM_TC_TEX);
1358 niceInsert(MathAtom(new MathBraceInset));
1366 if (strchr("#$%", c)) {
1367 insert(MathAtom(new MathSpecialCharInset(c)));
1368 lastcode_ = LM_TC_VAR;
1372 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1373 insert(c, LM_TC_VAR);
1377 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1378 insert(c, LM_TC_VAR);
1379 lastcode_ = LM_TC_VAR;
1384 insert(c, LM_TC_TEX);
1385 //bv->owner()->message(_("TeX mode"));
1389 // no special circumstances, so insert the character without any fuss
1390 insert(c, LM_TC_MIN);
1396 MathCursorPos MathCursor::normalAnchor() const
1398 // use Anchor on the same level as Cursor
1399 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1400 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1401 // anchor is behind cursor -> move anchor behind the inset
1408 void MathCursor::stripFromLastEqualSign()
1410 // find position of last '=' in the array
1411 MathArray & ar = cursor().cell();
1412 MathArray::const_iterator et = ar.end();
1413 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1414 if ((*it)->getChar() == '=')
1417 // delete everything behind this position
1418 ar.erase(et - ar.begin(), ar.size());
1423 ////////////////////////////////////////////////////////////////////////
1426 MathCursorPos::MathCursorPos()
1427 : par_(0), idx_(0), pos_(0)
1431 MathCursorPos::MathCursorPos(MathInset * p)
1432 : par_(p), idx_(0), pos_(0)
1436 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1438 return par_->cell(idx);
1442 MathArray & MathCursorPos::cell() const
1444 return par_->cell(idx_);
1448 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1450 return par_->xcell(idx);
1454 MathXArray & MathCursorPos::xcell() const
1456 return par_->xcell(idx_);
1460 int MathCursorPos::xpos() const
1462 return xcell().xo() + xcell().pos2x(pos_);
1466 int MathCursorPos::ypos() const
1468 return xcell().yo();
1471 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
1473 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
1478 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1480 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1484 bool operator!=(MathCursorPos const & ti, MathCursorPos const & it)
1486 return ti.par_ != it.par_ || ti.idx_ != it.idx_ || ti.pos_ != it.pos_;
1490 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1492 if (ti.par_ != it.par_) {
1493 lyxerr << "can't compare cursor and anchor in different insets\n";
1496 if (ti.idx_ != it.idx_)
1497 return ti.idx_ < it.idx_;
1498 return ti.pos_ < it.pos_;