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_;
147 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);
164 ostream & operator<<(ostream & os, MathCursorPos const & p)
166 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
173 MathCursor::MathCursor(InsetFormulaBase * formula)
176 lastcode = LM_TC_MIN;
183 void MathCursor::push(MathInset * par, bool first)
188 par->idxFirst(p.idx_, p.pos_);
190 par->idxLast(p.idx_, p.pos_);
191 Cursor_.push_back(p);
195 bool MathCursor::pop()
197 if (Cursor_.size() <= 1)
204 MathInset * MathCursor::parInset(int i) const
206 return Cursor_[i].par_;
209 void MathCursor::dump(char const * what) const
213 lyxerr << "MC: " << what
214 << " cursor.pos: " << cursor().pos_
215 << " cursor.idx: " << cursor().idx_
216 << " cursor.par: " << cursor().par_
217 << " sel: " << selection
218 << " data: " << array()
222 void MathCursor::seldump(char const *) const
224 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
228 //lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
229 // << str << "\ntheSelection: " << theSelection;
230 //for (unsigned int i = 0; i < Cursor_.size(); ++i)
231 // lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
232 //lyxerr << "\ncursor.pos_: " << cursor().pos_;
233 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
234 //lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
238 bool MathCursor::isInside(MathInset * p) const
240 for (unsigned i = 0; i < Cursor_.size(); ++i)
241 if (parInset(i) == p)
247 bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
251 if (!(p->isActive() || (useupdown && p->isUpDownInset())))
255 // we can't move into everything during selection
256 if (Cursor_.size() == Anchor_.size())
258 if (p != Anchor_[Cursor_.size()].par_)
264 bool MathCursor::plainLeft()
266 return array().prev(cursor().pos_);
270 bool MathCursor::Left(bool sel)
274 // was MacroModeBack()
275 if (!imacro->name().empty()) {
276 imacro->SetName(imacro->name().substr(0, imacro->name().length()-1));
277 imacro->Metrics(imacro->size());
285 MathInset * p = prevInset();
286 if (openable(p, sel, false)) {
287 array().prev(cursor().pos_);
291 if (array().prev(cursor().pos_))
293 if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
301 bool MathCursor::plainRight()
303 return array().next(cursor().pos_);
307 bool MathCursor::Right(bool sel)
317 MathInset * p = nextInset();
318 if (openable(p, sel, false)) {
322 if (array().next(cursor().pos_))
324 if (cursor().par_->idxRight(cursor().idx_, cursor().pos_))
328 array().next(cursor().pos_);
333 void MathCursor::first()
336 push(formula_->par(), true);
340 void MathCursor::last()
343 push(formula_->par(), false);
347 void MathCursor::SetPos(int x, int y)
350 //lyxerr << "MathCursor::SetPos x: " << x << " y: " << y << "\n";
353 lastcode = LM_TC_MIN;
356 cursor().par_ = formula()->par();
361 //lyxerr << "found idx: " << idx_ << " cursor: " << cursor().pos_ << "\n";
362 int distmin = 1 << 30; // large enough
363 for (int i = 0; i < cursor().par_->nargs(); ++i) {
364 MathXArray const & ar = cursor().par_->xcell(i);
365 int x1 = x - ar.xo();
366 int y1 = y - ar.yo();
367 int c = ar.x2pos(x1);
368 int xx = abs(x1 - ar.pos2x(c));
370 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
371 // << " c: " << c << " xo: " << ar.xo() << "\n";
372 if (yy + xx <= distmin) {
378 //lyxerr << "found idx: " << cursor().idx_ << " cursor: "
379 // << cursor().pos_ << "\n";
380 MathInset * n = nextInset();
381 MathInset * p = prevInset();
382 if (openable(n, selection, true) && n->covers(x, y))
384 else if (openable(p, selection, true) && p->covers(x, y)) {
385 array().prev(cursor().pos_);
394 void MathCursor::Home()
400 if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
406 void MathCursor::End()
412 if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
414 array().next(cursor().pos_);
420 void MathCursor::insert(char c, MathTextCodes t)
422 //lyxerr << "inserting '" << c << "'\n";
429 if (macro_mode && !(MathIsAlphaFont(t) || t == LM_TC_MIN))
433 if (MathIsAlphaFont(t) || t == LM_TC_MIN) {
434 // was MacroModeinsert(c);
435 imacro->SetName(imacro->name() + static_cast<char>(c));
440 array().insert(cursor().pos_, c, t);
441 array().next(cursor().pos_);
447 void MathCursor::insert(MathInset * p)
458 array().insert(cursor().pos_, p);
459 array().next(cursor().pos_);
463 void MathCursor::insert(MathArray const & ar)
469 array().insert(cursor().pos_, ar);
470 cursor().pos_ += ar.size();
474 void MathCursor::Delete()
485 if (cursor().pos_ < array().size())
486 array().erase(cursor().pos_);
488 // delete empty cells if necessary
489 if (cursor().pos_ == 0 && array().size() == 0) {
492 cursor().par_->idxDelete(cursor().idx_, popit, removeit);
493 if (popit && pop() && removeit)
498 #warning pullArg disabled
500 //if (cursor().pos_ == 0 && Cursor_.size() >= 1) {
501 // lyxerr << "Delete: popping...\n";
509 void MathCursor::DelLine()
518 if (cursor().par_->nrows() > 1)
519 cursor().par_->delRow(row());
523 bool MathCursor::Up(bool sel)
530 int x = xarray().pos2x(cursor().pos_);
531 if (cursor().par_->idxUp(cursor().idx_, cursor().pos_)) {
532 cursor().pos_ = xarray().x2pos(x);
540 // check whether we could move into an inset on the right or on the left
541 MathInset * p = nextInset();
544 if (p->idxFirstUp(idx, pos)) {
557 if (p->idxLastUp(idx, pos)) {
558 array().prev(cursor().pos_);
568 int x = xarray().pos2x(cursor().pos_);
569 if (cursor().idxUp()) {
570 cursor().pos_ = xarray().x2pos(x);
579 bool MathCursor::Down(bool sel)
586 int x = xarray().pos2x(cursor().pos_);
587 if (cursor().idxDown()) {
588 cursor().pos_ = xarray().x2pos(x);
596 // check whether we could move into an inset on the right or on the left
597 MathInset * p = nextInset();
600 if (p->idxFirstDown(idx, pos)) {
612 if (p->idxLastDown(idx, pos)) {
613 array().prev(cursor().pos_);
622 int x = xarray().pos2x(cursor().pos_);
623 if (cursor().par_->idxDown(cursor().idx_, cursor().pos_)) {
624 cursor().pos_ = xarray().x2pos(x);
633 bool MathCursor::toggleLimits()
637 MathInset * p = prevInset();
638 int old = p->limits();
639 p->limits(old < 0 ? 1 : -1);
640 return old != p->limits();
644 void MathCursor::SetSize(MathStyles size)
646 cursor().par_->UserSetSize(size);
651 void MathCursor::Interpret(string const & s)
653 lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " <<
654 in_word_set(s) << " \n";
657 MathUpDownInset * p = nearbyUpDownInset();
659 p = new MathScriptInset(true, false);
661 array().prev(cursor().pos_);
670 MathUpDownInset * p = nearbyUpDownInset();
672 p = new MathScriptInset(false, true);
674 array().prev(cursor().pos_);
682 if (s[0] == '!' || s[0] == ',' || s[0] == ':' || s[0] == ';') {
683 int sp = (s[0] == ',') ? 1:((s[0] == ':') ? 2:((s[0] == ';') ? 3: 0));
684 insert(new MathSpaceInset(sp));
689 latexkeys const * l = in_word_set(s);
693 p = new MathRootInset;
694 else if (MathMacroTable::hasTemplate(s))
695 p = new MathMacro(MathMacroTable::provideTemplate(s));
696 else if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
701 istringstream is(s.substr(7).c_str());
702 is >> m >> n >> v_align >> h_align;
706 MathArrayInset * pp = new MathArrayInset(m, n);
707 pp->valign(v_align[0]);
712 p = new MathFuncInset(s, LM_OT_UNDEF);
716 p = new MathBigopInset(l->name, l->id);
721 insert(l->id, MathIsBOPS(l->id) ? LM_TC_BOPS : LM_TC_SYMB);
723 p = new MathFuncInset(l->name);
727 p = new MathFracInset("stackrel");
731 p = new MathFracInset("frac");
735 p = new MathSqrtInset;
738 case LM_TK_DECORATION:
739 p = new MathDecorationInset(l->name, l->id);
743 p = new MathFuncInset(l->name, LM_OT_FUNCLIM);
747 p = new MathSpaceInset(l->id);
751 p = new MathDotsInset(l->name, l->id);
755 p = new MathMacro(MathMacroTable::provideTemplate(s));
759 p = new MathFuncInset(l->name);
765 bool oldsel = selection;
770 array().prev(cursor().pos_);
775 p->Metrics(p->size());
780 void MathCursor::MacroModeOpen()
783 imacro = new MathFuncInset("");
787 lyxerr << "Math Warning: Already in macro mode" << endl;
791 void MathCursor::MacroModeClose()
795 latexkeys const * l = in_word_set(imacro->name());
796 if (!imacro->name().empty()
797 && (!l || (l && IsMacro(l->token, l->id)))
798 && !MathMacroTable::hasTemplate(imacro->name()))
801 //imacro->SetName(macrobf);
802 // This guarantees that the string will be removed by destructor
803 imacro->SetType(LM_OT_UNDEF);
805 imacro->SetName(l->name);
808 array().erase(cursor().pos_);
809 if (l || MathMacroTable::hasTemplate(imacro->name()))
810 Interpret(imacro->name());
811 imacro->SetName(string());
818 void MathCursor::SelCopy()
822 theSelection.grab(*this);
827 void MathCursor::SelCut()
831 theSelection.grab(*this);
832 theSelection.erase(*this);
838 void MathCursor::SelDel()
842 theSelection.erase(*this);
848 void MathCursor::SelPaste()
851 theSelection.paste(*this);
855 void MathCursor::SelHandle(bool sel)
857 if (sel && !selection)
859 if (!sel && selection)
864 void MathCursor::SelStart()
875 void MathCursor::SelClear()
882 void MathCursor::drawSelection(Painter & pain) const
889 getSelection(i1, i2);
891 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
893 if (i1.idx_ == i2.idx_) {
894 MathXArray & c = i1.xcell();
895 int x1 = c.xo() + c.pos2x(i1.pos_);
896 int y1 = c.yo() - c.ascent();
897 int x2 = c.xo() + c.pos2x(i2.pos_);
898 int y2 = c.yo() + c.descent();
899 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
902 #if RECTANGULAR_SELECT
903 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
904 for (unsigned i = 0; i < indices.size(); ++i) {
905 MathXArray & c = i1.xcell(indices[i]);
907 int y1 = c.yo() - c.ascent();
908 int x2 = c.xo() + c.width();
909 int y2 = c.yo() + c.descent();
910 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
914 MathXArray & c = i1.xcell();
915 int x1 = c.xo() + c.pos2x(i1.pos_);
916 int y1 = c.yo() - c.ascent();
917 int x2 = c.xo() + c.width();
918 int y2 = c.yo() + c.descent();
919 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
921 for (int idx = i1.idx_ + 1; idx < i2.idx_; ++idx) {
922 MathXArray & c = i1.xcell(idx);
924 int y1 = c.yo() - c.ascent();
925 int x2 = c.xo() + c.width();
926 int y2 = c.yo() + c.descent();
927 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
930 MathXArray & cr = i2.xcell();
932 y1 = cr.yo() - cr.ascent();
933 x2 = cr.xo() + cr.pos2x(i2.pos_);
934 y2 = cr.yo() + cr.descent();
935 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
941 void MathCursor::handleFont(MathTextCodes t)
946 getSelection(i1, i2);
947 if (i1.idx_ == i2.idx_) {
948 MathArray & ar = i1.cell();
949 for (int pos = i1.pos_; pos != i2.pos_; ar.next(pos))
950 if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) {
951 MathTextCodes c = ar.GetCode(pos) == t ? LM_TC_VAR : t;
956 lastcode = (lastcode == t) ? LM_TC_VAR : t;
961 void MathCursor::handleAccent(string const & name, int code)
963 MathDecorationInset * p = new MathDecorationInset(name, code);
966 p->cell(0) = theSelection.glue();
972 void MathCursor::handleDelim(int l, int r)
974 MathDelimInset * p = new MathDelimInset(l, r);
977 p->cell(0) = theSelection.glue();
984 void MathCursor::GetPos(int & x, int & y)
986 x = xarray().xo() + xarray().pos2x(cursor().pos_);
991 MathTextCodes MathCursor::nextCode() const
993 return array().GetCode(cursor().pos_);
997 MathTextCodes MathCursor::prevCode() const
999 return array().GetCode(cursor().pos_ - 1);
1003 MathInset * MathCursor::par() const
1005 return cursor().par_;
1009 InsetFormulaBase const * MathCursor::formula()
1015 int MathCursor::pos() const
1017 return cursor().pos_;
1021 bool MathCursor::InMacroMode() const
1027 bool MathCursor::Selection() const
1033 void MathCursor::clearLastCode()
1035 lastcode = LM_TC_MIN;
1039 void MathCursor::setLastCode(MathTextCodes t)
1045 MathTextCodes MathCursor::getLastCode() const
1051 MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const
1053 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1054 //lyxerr << "checking level " << i << "\n";
1055 if (Cursor_[i].par_->GetType() == t) {
1056 idx = Cursor_[i].idx_;
1057 return Cursor_[i].par_;
1063 void MathCursor::pullArg()
1066 MathArray a = array();
1070 array().erase(cursor().pos_);
1071 array().insert(cursor().pos_, a);
1075 MathStyles MathCursor::style() const
1077 return xarray().style();
1081 void MathCursor::normalize() const
1083 #ifdef WITH_WARNINGS
1084 #warning This is evil!
1086 MathCursor * it = const_cast<MathCursor *>(this);
1088 if (cursor().idx_ < 0 || cursor().idx_ > cursor().par_->nargs())
1089 lyxerr << "this should not really happen - 1\n";
1090 it->cursor().idx_ = max(cursor().idx_, 0);
1091 it->cursor().idx_ = min(cursor().idx_, cursor().par_->nargs());
1093 if (cursor().pos_ < 0 || cursor().pos_ > array().size())
1094 lyxerr << "this should not really happen - 2\n";
1095 it->cursor().pos_ = max(cursor().pos_, 0);
1096 it->cursor().pos_ = min(cursor().pos_, array().size());
1100 int MathCursor::col() const
1102 return par()->col(cursor().idx_);
1106 int MathCursor::row() const
1108 return par()->row(cursor().idx_);
1113 char MathCursorPos::GetChar() const
1115 return array().GetChar(cursor().pos_);
1119 string MathCursorPos::readString()
1122 int code = nextCode();
1123 for ( ; OK() && nextCode() == code; Next())
1130 MathInset * MathCursor::prevInset() const
1133 int c = cursor().pos_;
1134 if (!array().prev(c))
1136 return array().nextInset(c);
1140 MathInset * MathCursor::nextInset() const
1143 return array().nextInset(cursor().pos_);
1147 MathUpDownInset * MathCursor::nearbyUpDownInset() const
1150 MathInset * p = array().prevInset(cursor().pos_);
1151 if (p && p->isUpDownInset())
1152 return static_cast<MathUpDownInset *>(p);
1153 p = array().nextInset(cursor().pos_);
1154 if (p && p->isUpDownInset())
1155 return static_cast<MathUpDownInset *>(p);
1160 MathArray & MathCursor::array() const
1162 static MathArray dummy;
1163 if (!cursor().par_) {
1164 lyxerr << "############ par_ not valid\n";
1168 if (cursor().idx_ < 0 || cursor().idx_ >= cursor().par_->nargs()) {
1169 lyxerr << "############ idx_ " << cursor().idx_ << " not valid\n";
1173 return cursor().cell();
1177 MathXArray & MathCursor::xarray() const
1179 return cursor().xcell();
1183 bool MathCursor::nextIsInset() const
1185 return cursor().pos_ < array().size() && MathIsInset(nextCode());
1189 bool MathCursor::prevIsInset() const
1191 return cursor().pos_ > 0 && MathIsInset(prevCode());
1195 int MathCursor::xpos() const
1198 return xarray().pos2x(cursor().pos_);
1201 void MathCursor::gotoX(int x)
1203 cursor().pos_ = xarray().x2pos(x);
1206 void MathCursor::idxNext()
1208 cursor().par_->idxNext(cursor().idx_, cursor().pos_);
1211 void MathCursor::idxPrev()
1213 cursor().par_->idxPrev(cursor().idx_, cursor().pos_);
1216 void MathCursor::splitCell()
1218 if (cursor().idx_ == cursor().par_->nargs() - 1)
1220 MathArray ar = array();
1221 ar.erase(0, cursor().pos_);
1222 array().erase(cursor().pos_, array().size());
1225 array().insert(0, ar);
1228 void MathCursor::breakLine()
1230 MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
1231 if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) {
1232 p->mutate(LM_OT_EQNARRAY);
1234 cursor().idx_ = p->nrows();
1240 const int r = row();
1241 for (int c = col() + 1; c < p->ncols(); ++c) {
1242 const int i1 = p->index(r, c);
1243 const int i2 = p->index(r + 1, c);
1244 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1245 p->cell(i1).swap(p->cell(i2));
1250 p->cell(cursor().idx_).swap(p->cell(cursor().idx_ + p->ncols() - 1));
1254 char MathCursor::valign() const
1258 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1259 return p ? p->valign() : 0;
1262 char MathCursor::halign() const
1266 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1267 return p ? p->halign(idx % p->ncols()) : 0;
1271 MathCursorPos MathCursor::firstSelectionPos() const
1273 MathCursorPos anc = normalAnchor();
1274 return anc < cursor() ? anc : cursor();
1278 MathCursorPos MathCursor::lastSelectionPos() const
1280 MathCursorPos anc = normalAnchor();
1281 return anc < cursor() ? cursor() : anc;
1285 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1287 MathCursorPos anc = normalAnchor();
1288 if (anc < cursor()) {
1298 MathCursorPos & MathCursor::cursor()
1300 return Cursor_.back();
1304 MathCursorPos const & MathCursor::cursor() const
1306 return Cursor_.back();
1311 ////////////////////////////////////////////////////////////////////////
1314 bool MathCursorPos::operator==(const MathCursorPos & it) const
1316 return par_ == it.par_ && idx_ == it.idx_ && pos_ == it.pos_;
1319 bool MathCursorPos::operator<(const MathCursorPos & it) const
1321 if (par_ != it.par_) {
1322 lyxerr << "can't compare cursor and anchor in different insets\n";
1325 if (idx_ != it.idx_)
1326 return idx_ < it.idx_;
1327 return pos_ < it.pos_;
1331 MathArray & MathCursorPos::cell(int idx) const
1333 return par_->cell(idx);
1336 MathArray & MathCursorPos::cell() const
1338 return par_->cell(idx_);
1342 MathXArray & MathCursorPos::xcell(int idx) const
1344 return par_->xcell(idx);
1347 MathXArray & MathCursorPos::xcell() const
1349 return par_->xcell(idx_);
1352 MathCursorPos MathCursor::normalAnchor() const
1354 // use Anchor on the same level as Cursor
1355 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1356 if (Cursor_.size() < Anchor_.size() && !(cursor() > normal)) {
1357 // anchor is behind cursor -> move anchor behind the inset
1358 normal.cell().next(normal.pos_);
1360 //lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
1361 // << normal << "\n";
1365 bool MathCursorPos::idxUp()
1367 return par_->idxUp(idx_, pos_);
1370 bool MathCursorPos::idxDown()
1372 return par_->idxDown(idx_, pos_);
1375 bool MathCursorPos::idxLeft()
1377 return par_->idxLeft(idx_, pos_);
1380 bool MathCursorPos::idxRight()
1382 return par_->idxRight(idx_, pos_);