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 "math_inset.h"
27 #include "math_arrayinset.h"
28 #include "math_parser.h"
29 #include "math_cursor.h"
30 #include "math_macro.h"
31 #include "math_macroarg.h"
32 #include "math_macrotable.h"
33 #include "math_root.h"
34 #include "support/lstrings.h"
38 #include "math_matrixinset.h"
39 #include "math_grid.h"
40 #include "math_spaceinset.h"
41 #include "math_funcinset.h"
42 #include "math_bigopinset.h"
43 #include "math_fracinset.h"
44 #include "math_decorationinset.h"
45 #include "math_dotsinset.h"
46 #include "math_deliminset.h"
47 #include "math_macrotemplate.h"
48 #include "math_sqrtinset.h"
49 #include "math_scriptinset.h"
50 #include "mathed/support.h"
51 #include "formulabase.h"
59 #define RECTANGULAR_SELECT 1
65 void grab(MathCursor const & cursor)
70 cursor.getSelection(i1, i2);
71 if (i1.idx_ == i2.idx_)
72 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
74 #ifdef RECTANGULAR_SELECT
75 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
76 for (unsigned i = 0; i < indices.size(); ++i)
77 data_.push_back(i1.cell(indices[i]));
79 data_.push_back(MathArray(i1.cell(), i1.pos_, i1.cell().size()));
80 for (int i = i1.idx_ + 1; i < i2.idx_; ++i)
81 data_.push_back(i1.cell(i));
82 data_.push_back(MathArray(i2.cell(), 0, i2.pos_));
87 void erase(MathCursor & cursor)
91 cursor.getSelection(i1, i2);
92 if (i1.idx_ == i2.idx_) {
93 i1.cell().erase(i1.pos_, i2.pos_);
95 #ifdef RECTANGULAR_SELECT
96 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
97 for (unsigned i = 0; i < indices.size(); ++i)
98 i1.cell(indices[i]).erase();
100 i1.cell().erase(i1.pos_, i1.cell().size());
101 for (int i = i1.idx_ + 1; i < i2.idx_; ++i)
103 i2.cell().erase(0, i2.pos_);
105 int from = i1.cell().size() ? i1.idx_ + 1 : i1.idx_;
106 int to = i2.cell().size() ? i2.idx_ : i2.idx_ + 1;
107 i1.par_->idxDeleteRange(from, to);
110 cursor.cursor() = i1;
113 void paste(MathCursor & cursor) const
115 #ifdef RECTANGULAR_SELECT
116 cursor.cursor().cell().push_back(glue());
118 unsigned na = cursor.cursor().par_->nargs();
119 unsigned idx = cursor.cursor().idx_;
120 unsigned end = std::min(idx + data_.size(), na);
121 for (int i = 0; i < end - idx; ++i)
122 cursor.cursor().cell(idx + i).push_back(data_[i]);
123 for (unsigned i = end - idx; i < data_.size(); ++i)
124 cursor.cursor().cell(end - 1).push_back(data_[i]);
128 // glues selection to one cell
129 MathArray glue() const
132 for (unsigned i = 0; i < data_.size(); ++i)
133 ar.push_back(data_[i]);
144 std::vector<MathArray> data_;
148 Selection theSelection;
151 bool IsMacro(short tok, int id)
153 return tok != LM_TK_STACK &&
156 tok != LM_TK_DECORATION &&
157 tok != LM_TK_SPACE &&
159 tok != LM_TK_FUNCLIM &&
160 tok != LM_TK_BIGSYM &&
161 !(tok == LM_TK_SYM && id < 255);
165 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
167 os << "(par: " << p.par_ << " idx: " << p.idx_
168 << " pos: " << p.pos_ << ")";
175 MathCursor::MathCursor(InsetFormulaBase * formula)
178 lastcode = LM_TC_MIN;
185 void MathCursor::push(MathInset * par, bool first)
190 par->idxFirst(p.idx_, p.pos_);
192 par->idxLast(p.idx_, p.pos_);
193 Cursor_.push_back(p);
197 bool MathCursor::pop()
199 if (Cursor_.size() <= 1)
206 MathInset * MathCursor::parInset(int i) const
208 return Cursor_[i].par_;
212 void MathCursor::dump(char const * what) const
216 lyxerr << "MC: " << what
217 << " cursor.pos: " << cursor().pos_
218 << " cursor.idx: " << cursor().idx_
219 << " cursor.par: " << cursor().par_
220 << " sel: " << selection
221 << " data: " << array()
226 void MathCursor::seldump(char const *) const
228 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
232 //lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
233 // << str << "\ntheSelection: " << theSelection;
234 //for (unsigned int i = 0; i < Cursor_.size(); ++i)
235 // lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
236 //lyxerr << "\ncursor.pos_: " << cursor().pos_;
237 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
238 //lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
242 bool MathCursor::isInside(MathInset * p) const
244 for (unsigned i = 0; i < Cursor_.size(); ++i)
245 if (parInset(i) == p)
251 bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
255 if (!(p->isActive() || (useupdown && p->isUpDownInset())))
259 // we can't move into everything during selection
260 if (Cursor_.size() == Anchor_.size())
262 if (p != Anchor_[Cursor_.size()].par_)
269 bool MathCursor::plainLeft()
271 return array().prev(cursor().pos_);
275 bool MathCursor::Left(bool sel)
279 // was MacroModeBack()
280 if (!imacro->name().empty()) {
281 imacro->SetName(imacro->name().substr(0, imacro->name().length()-1));
282 imacro->Metrics(imacro->size());
290 MathInset * p = prevInset();
291 if (openable(p, sel, false)) {
292 array().prev(cursor().pos_);
296 if (array().prev(cursor().pos_))
298 if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
306 bool MathCursor::plainRight()
308 return array().next(cursor().pos_);
312 bool MathCursor::Right(bool sel)
322 MathInset * p = nextInset();
323 if (openable(p, sel, false)) {
327 if (array().next(cursor().pos_))
329 if (cursor().par_->idxRight(cursor().idx_, cursor().pos_))
333 array().next(cursor().pos_);
338 void MathCursor::first()
341 push(formula_->par(), true);
345 void MathCursor::last()
348 push(formula_->par(), false);
352 void MathCursor::SetPos(int x, int y)
355 //lyxerr << "MathCursor::SetPos x: " << x << " y: " << y << "\n";
358 lastcode = LM_TC_MIN;
361 cursor().par_ = formula()->par();
366 //lyxerr << "found idx: " << idx_ << " cursor: " << cursor().pos_ << "\n";
367 int distmin = 1 << 30; // large enough
368 for (int i = 0; i < cursor().par_->nargs(); ++i) {
369 MathXArray const & ar = cursor().par_->xcell(i);
370 int x1 = x - ar.xo();
371 int y1 = y - ar.yo();
372 int c = ar.x2pos(x1);
373 int xx = abs(x1 - ar.pos2x(c));
375 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
376 // << " c: " << c << " xo: " << ar.xo() << "\n";
377 if (yy + xx <= distmin) {
383 //lyxerr << "found idx: " << cursor().idx_ << " cursor: "
384 // << cursor().pos_ << "\n";
385 MathInset * n = nextInset();
386 MathInset * p = prevInset();
387 if (openable(n, selection, true) && n->covers(x, y))
389 else if (openable(p, selection, true) && p->covers(x, y)) {
390 array().prev(cursor().pos_);
399 void MathCursor::Home()
405 if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
411 void MathCursor::End()
417 if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
419 array().next(cursor().pos_);
425 void MathCursor::insert(char c, MathTextCodes t)
427 //lyxerr << "inserting '" << c << "'\n";
434 if (macro_mode && !(MathIsAlphaFont(t) || t == LM_TC_MIN))
438 if (MathIsAlphaFont(t) || t == LM_TC_MIN) {
439 // was MacroModeinsert(c);
440 imacro->SetName(imacro->name() + static_cast<char>(c));
445 array().insert(cursor().pos_, c, t);
446 array().next(cursor().pos_);
452 void MathCursor::insert(MathInset * p)
463 array().insert(cursor().pos_, p);
464 array().next(cursor().pos_);
468 void MathCursor::insert(MathArray const & ar)
474 array().insert(cursor().pos_, ar);
475 cursor().pos_ += ar.size();
479 void MathCursor::Delete()
490 if (cursor().pos_ < array().size())
491 array().erase(cursor().pos_);
493 // delete empty cells if necessary
494 if (cursor().pos_ == 0 && array().size() == 0) {
497 cursor().par_->idxDelete(cursor().idx_, popit, removeit);
498 if (popit && pop() && removeit)
503 #warning pullArg disabled
505 //if (cursor().pos_ == 0 && Cursor_.size() >= 1) {
506 // lyxerr << "Delete: popping...\n";
514 void MathCursor::DelLine()
523 if (cursor().par_->nrows() > 1)
524 cursor().par_->delRow(row());
528 bool MathCursor::Up(bool sel)
535 int x = xarray().pos2x(cursor().pos_);
536 if (cursor().par_->idxUp(cursor().idx_, cursor().pos_)) {
537 cursor().pos_ = xarray().x2pos(x);
545 // check whether we could move into an inset on the right or on the left
546 MathInset * p = nextInset();
549 if (p->idxFirstUp(idx, pos)) {
562 if (p->idxLastUp(idx, pos)) {
563 array().prev(cursor().pos_);
573 int x = xarray().pos2x(cursor().pos_);
574 if (cursor().idxUp()) {
575 cursor().pos_ = xarray().x2pos(x);
584 bool MathCursor::Down(bool sel)
591 int x = xarray().pos2x(cursor().pos_);
592 if (cursor().idxDown()) {
593 cursor().pos_ = xarray().x2pos(x);
601 // check whether we could move into an inset on the right or on the left
602 MathInset * p = nextInset();
605 if (p->idxFirstDown(idx, pos)) {
617 if (p->idxLastDown(idx, pos)) {
618 array().prev(cursor().pos_);
627 int x = xarray().pos2x(cursor().pos_);
628 if (cursor().par_->idxDown(cursor().idx_, cursor().pos_)) {
629 cursor().pos_ = xarray().x2pos(x);
638 bool MathCursor::toggleLimits()
642 MathInset * p = prevInset();
643 int old = p->limits();
644 p->limits(old < 0 ? 1 : -1);
645 return old != p->limits();
649 void MathCursor::SetSize(MathStyles size)
651 cursor().par_->UserSetSize(size);
656 void MathCursor::Interpret(string const & s)
658 lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " <<
659 in_word_set(s) << " \n";
662 MathUpDownInset * p = nearbyUpDownInset();
664 p = new MathScriptInset(true, false);
666 array().prev(cursor().pos_);
675 MathUpDownInset * p = nearbyUpDownInset();
677 p = new MathScriptInset(false, true);
679 array().prev(cursor().pos_);
687 if (s[0] == '!' || s[0] == ',' || s[0] == ':' || s[0] == ';') {
688 int sp = (s[0] == ',') ? 1:((s[0] == ':') ? 2:((s[0] == ';') ? 3: 0));
689 insert(new MathSpaceInset(sp));
694 latexkeys const * l = in_word_set(s);
698 p = new MathRootInset;
699 else if (MathMacroTable::hasTemplate(s))
700 p = new MathMacro(MathMacroTable::provideTemplate(s));
701 else if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
706 istringstream is(s.substr(7).c_str());
707 is >> m >> n >> v_align >> h_align;
711 MathArrayInset * pp = new MathArrayInset(m, n);
712 pp->valign(v_align[0]);
717 p = new MathFuncInset(s, LM_OT_UNDEF);
721 p = new MathBigopInset(l->name, l->id);
726 insert(l->id, MathIsBOPS(l->id) ? LM_TC_BOPS : LM_TC_SYMB);
728 p = new MathFuncInset(l->name);
732 p = new MathFracInset("stackrel");
736 p = new MathFracInset("frac");
740 p = new MathSqrtInset;
743 case LM_TK_DECORATION:
744 p = new MathDecorationInset(l->name, l->id);
748 p = new MathFuncInset(l->name, LM_OT_FUNCLIM);
752 p = new MathSpaceInset(l->id);
756 p = new MathDotsInset(l->name, l->id);
760 p = new MathMacro(MathMacroTable::provideTemplate(s));
764 p = new MathFuncInset(l->name);
770 bool oldsel = selection;
775 array().prev(cursor().pos_);
780 p->Metrics(p->size());
785 void MathCursor::MacroModeOpen()
788 imacro = new MathFuncInset("");
792 lyxerr << "Math Warning: Already in macro mode" << endl;
796 void MathCursor::MacroModeClose()
800 latexkeys const * l = in_word_set(imacro->name());
801 if (!imacro->name().empty()
802 && (!l || (l && IsMacro(l->token, l->id)))
803 && !MathMacroTable::hasTemplate(imacro->name()))
806 //imacro->SetName(macrobf);
807 // This guarantees that the string will be removed by destructor
808 imacro->SetType(LM_OT_UNDEF);
810 imacro->SetName(l->name);
813 array().erase(cursor().pos_);
814 if (l || MathMacroTable::hasTemplate(imacro->name()))
815 Interpret(imacro->name());
816 imacro->SetName(string());
823 void MathCursor::SelCopy()
827 theSelection.grab(*this);
833 void MathCursor::SelCut()
837 theSelection.grab(*this);
838 theSelection.erase(*this);
844 void MathCursor::SelDel()
848 theSelection.erase(*this);
854 void MathCursor::SelPaste()
857 theSelection.paste(*this);
862 void MathCursor::SelHandle(bool sel)
864 if (sel && !selection)
866 if (!sel && selection)
871 void MathCursor::SelStart()
882 void MathCursor::SelClear()
888 void MathCursor::drawSelection(Painter & pain) const
895 getSelection(i1, i2);
897 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
899 if (i1.idx_ == i2.idx_) {
900 MathXArray & c = i1.xcell();
901 int x1 = c.xo() + c.pos2x(i1.pos_);
902 int y1 = c.yo() - c.ascent();
903 int x2 = c.xo() + c.pos2x(i2.pos_);
904 int y2 = c.yo() + c.descent();
905 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
908 #if RECTANGULAR_SELECT
909 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
910 for (unsigned i = 0; i < indices.size(); ++i) {
911 MathXArray & c = i1.xcell(indices[i]);
913 int y1 = c.yo() - c.ascent();
914 int x2 = c.xo() + c.width();
915 int y2 = c.yo() + c.descent();
916 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
920 MathXArray & c = i1.xcell();
921 int x1 = c.xo() + c.pos2x(i1.pos_);
922 int y1 = c.yo() - c.ascent();
923 int x2 = c.xo() + c.width();
924 int y2 = c.yo() + c.descent();
925 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
927 for (int idx = i1.idx_ + 1; idx < i2.idx_; ++idx) {
928 MathXArray & c = i1.xcell(idx);
930 int y1 = c.yo() - c.ascent();
931 int x2 = c.xo() + c.width();
932 int y2 = c.yo() + c.descent();
933 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
936 MathXArray & cr = i2.xcell();
938 y1 = cr.yo() - cr.ascent();
939 x2 = cr.xo() + cr.pos2x(i2.pos_);
940 y2 = cr.yo() + cr.descent();
941 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
947 void MathCursor::handleFont(MathTextCodes t)
952 getSelection(i1, i2);
953 if (i1.idx_ == i2.idx_) {
954 MathArray & ar = i1.cell();
955 for (int pos = i1.pos_; pos != i2.pos_; ar.next(pos))
956 if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) {
957 MathTextCodes c = ar.GetCode(pos) == t ? LM_TC_VAR : t;
962 lastcode = (lastcode == t) ? LM_TC_VAR : t;
967 void MathCursor::handleAccent(string const & name, int code)
969 MathDecorationInset * p = new MathDecorationInset(name, code);
972 p->cell(0) = theSelection.glue();
979 void MathCursor::handleDelim(int l, int r)
981 MathDelimInset * p = new MathDelimInset(l, r);
984 p->cell(0) = theSelection.glue();
991 void MathCursor::GetPos(int & x, int & y)
993 x = xarray().xo() + xarray().pos2x(cursor().pos_);
998 MathTextCodes MathCursor::nextCode() const
1000 return array().GetCode(cursor().pos_);
1004 MathTextCodes MathCursor::prevCode() const
1006 return array().GetCode(cursor().pos_ - 1);
1010 MathInset * MathCursor::par() const
1012 return cursor().par_;
1016 InsetFormulaBase const * MathCursor::formula()
1022 int MathCursor::pos() const
1024 return cursor().pos_;
1028 bool MathCursor::InMacroMode() const
1034 bool MathCursor::Selection() const
1040 void MathCursor::clearLastCode()
1042 lastcode = LM_TC_MIN;
1046 void MathCursor::setLastCode(MathTextCodes t)
1052 MathTextCodes MathCursor::getLastCode() const
1058 MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const
1060 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1061 //lyxerr << "checking level " << i << "\n";
1062 if (Cursor_[i].par_->GetType() == t) {
1063 idx = Cursor_[i].idx_;
1064 return Cursor_[i].par_;
1071 void MathCursor::pullArg()
1074 MathArray a = array();
1078 array().erase(cursor().pos_);
1079 array().insert(cursor().pos_, a);
1083 MathStyles MathCursor::style() const
1085 return xarray().style();
1089 void MathCursor::normalize() const
1091 #ifdef WITH_WARNINGS
1092 #warning This is evil!
1094 MathCursor * it = const_cast<MathCursor *>(this);
1096 if (cursor().idx_ < 0 || cursor().idx_ > cursor().par_->nargs())
1097 lyxerr << "this should not really happen - 1\n";
1098 it->cursor().idx_ = max(cursor().idx_, 0);
1099 it->cursor().idx_ = min(cursor().idx_, cursor().par_->nargs());
1101 if (cursor().pos_ < 0 || cursor().pos_ > array().size())
1102 lyxerr << "this should not really happen - 2\n";
1103 it->cursor().pos_ = max(cursor().pos_, 0);
1104 it->cursor().pos_ = min(cursor().pos_, array().size());
1108 int MathCursor::col() const
1110 return par()->col(cursor().idx_);
1114 int MathCursor::row() const
1116 return par()->row(cursor().idx_);
1121 char MathCursorPos::GetChar() const
1123 return array().GetChar(cursor().pos_);
1127 string MathCursorPos::readString()
1130 int code = nextCode();
1131 for ( ; OK() && nextCode() == code; Next())
1139 MathInset * MathCursor::prevInset() const
1142 int c = cursor().pos_;
1143 if (!array().prev(c))
1145 return array().nextInset(c);
1149 MathInset * MathCursor::nextInset() const
1152 return array().nextInset(cursor().pos_);
1156 MathUpDownInset * MathCursor::nearbyUpDownInset() const
1159 MathInset * p = array().prevInset(cursor().pos_);
1160 if (p && p->isUpDownInset())
1161 return static_cast<MathUpDownInset *>(p);
1162 p = array().nextInset(cursor().pos_);
1163 if (p && p->isUpDownInset())
1164 return static_cast<MathUpDownInset *>(p);
1169 MathArray & MathCursor::array() const
1171 static MathArray dummy;
1172 if (!cursor().par_) {
1173 lyxerr << "############ par_ not valid\n";
1177 if (cursor().idx_ < 0 || cursor().idx_ >= cursor().par_->nargs()) {
1178 lyxerr << "############ idx_ " << cursor().idx_ << " not valid\n";
1182 return cursor().cell();
1186 MathXArray & MathCursor::xarray() const
1188 return cursor().xcell();
1192 bool MathCursor::nextIsInset() const
1194 return cursor().pos_ < array().size() && MathIsInset(nextCode());
1198 bool MathCursor::prevIsInset() const
1200 return cursor().pos_ > 0 && MathIsInset(prevCode());
1204 int MathCursor::xpos() const
1207 return xarray().pos2x(cursor().pos_);
1211 void MathCursor::gotoX(int x)
1213 cursor().pos_ = xarray().x2pos(x);
1217 void MathCursor::idxNext()
1219 cursor().par_->idxNext(cursor().idx_, cursor().pos_);
1223 void MathCursor::idxPrev()
1225 cursor().par_->idxPrev(cursor().idx_, cursor().pos_);
1229 void MathCursor::splitCell()
1231 if (cursor().idx_ == cursor().par_->nargs() - 1)
1233 MathArray ar = array();
1234 ar.erase(0, cursor().pos_);
1235 array().erase(cursor().pos_, array().size());
1238 array().insert(0, ar);
1242 void MathCursor::breakLine()
1244 MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
1245 if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) {
1246 p->mutate(LM_OT_EQNARRAY);
1248 cursor().idx_ = p->nrows();
1254 const int r = row();
1255 for (int c = col() + 1; c < p->ncols(); ++c) {
1256 const int i1 = p->index(r, c);
1257 const int i2 = p->index(r + 1, c);
1258 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1259 p->cell(i1).swap(p->cell(i2));
1264 p->cell(cursor().idx_).swap(p->cell(cursor().idx_ + p->ncols() - 1));
1269 char MathCursor::valign() const
1273 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1274 return p ? p->valign() : 0;
1278 char MathCursor::halign() const
1282 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1283 return p ? p->halign(idx % p->ncols()) : 0;
1287 MathCursorPos MathCursor::firstSelectionPos() const
1289 MathCursorPos anc = normalAnchor();
1290 return anc < cursor() ? anc : cursor();
1294 MathCursorPos MathCursor::lastSelectionPos() const
1296 MathCursorPos anc = normalAnchor();
1297 return anc < cursor() ? cursor() : anc;
1301 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1303 MathCursorPos anc = normalAnchor();
1304 if (anc < cursor()) {
1314 MathCursorPos & MathCursor::cursor()
1316 return Cursor_.back();
1320 MathCursorPos const & MathCursor::cursor() const
1322 return Cursor_.back();
1327 ////////////////////////////////////////////////////////////////////////
1330 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1332 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1336 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1338 if (ti.par_ != it.par_) {
1339 lyxerr << "can't compare cursor and anchor in different insets\n";
1342 if (ti.idx_ != it.idx_)
1343 return ti.idx_ < it.idx_;
1344 return ti.pos_ < it.pos_;
1348 MathArray & MathCursorPos::cell(int idx) const
1350 return par_->cell(idx);
1353 MathArray & MathCursorPos::cell() const
1355 return par_->cell(idx_);
1359 MathXArray & MathCursorPos::xcell(int idx) const
1361 return par_->xcell(idx);
1365 MathXArray & MathCursorPos::xcell() const
1367 return par_->xcell(idx_);
1371 MathCursorPos MathCursor::normalAnchor() const
1373 // use Anchor on the same level as Cursor
1374 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1375 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1376 // anchor is behind cursor -> move anchor behind the inset
1377 normal.cell().next(normal.pos_);
1379 //lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
1380 // << normal << "\n";
1385 bool MathCursorPos::idxUp()
1387 return par_->idxUp(idx_, pos_);
1391 bool MathCursorPos::idxDown()
1393 return par_->idxDown(idx_, pos_);
1397 bool MathCursorPos::idxLeft()
1399 return par_->idxLeft(idx_, pos_);
1403 bool MathCursorPos::idxRight()
1405 return par_->idxRight(idx_, pos_);