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.
22 #include "support/lstrings.h"
23 #include "support/LAssert.h"
25 #include "frontends/Painter.h"
26 #include "math_cursor.h"
27 #include "formulabase.h"
28 #include "funcrequest.h"
29 #include "math_autocorrect.h"
30 #include "math_braceinset.h"
31 #include "math_commentinset.h"
32 #include "math_charinset.h"
33 #include "math_extern.h"
34 #include "math_factory.h"
35 #include "math_fontinset.h"
36 #include "math_gridinset.h"
37 #include "math_iterator.h"
38 #include "math_macroarg.h"
39 #include "math_macrotemplate.h"
40 #include "math_mathmlstream.h"
41 #include "math_scriptinset.h"
42 #include "math_spaceinset.h"
43 #include "math_support.h"
44 #include "math_unknowninset.h"
56 using std::ostringstream;
60 // matheds own cut buffer
64 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
65 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
67 front ? first() : last();
72 MathCursor::~MathCursor()
74 // ensure that 'notifyCursorLeave' is called
80 void MathCursor::push(MathAtom & t)
82 Cursor_.push_back(MathCursorPos(t.nucleus()));
86 void MathCursor::pushLeft(MathAtom & t)
88 //lyxerr << "Entering atom " << t << " left\n";
90 t->idxFirst(idx(), pos());
94 void MathCursor::pushRight(MathAtom & t)
96 //lyxerr << "Entering atom " << t << " right\n";
99 t->idxLast(idx(), pos());
103 bool MathCursor::popLeft()
105 //cerr << "Leaving atom to the left\n";
108 par()->notifyCursorLeaves(idx());
111 par()->notifyCursorLeaves(idx());
117 bool MathCursor::popRight()
119 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
122 par()->notifyCursorLeaves(idx());
125 par()->notifyCursorLeaves(idx());
134 void MathCursor::dump(char const * what) const
136 lyxerr << "MC: " << what << endl;
137 lyxerr << " Cursor: " << depth() << endl;
138 for (unsigned i = 0; i < depth(); ++i)
139 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
140 lyxerr << " Anchor: " << Anchor_.size() << endl;
141 for (unsigned i = 0; i < Anchor_.size(); ++i)
142 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
143 lyxerr << " sel: " << selection_ << endl;
146 void MathCursor::dump(char const *) const {}
150 bool MathCursor::isInside(MathInset const * p) const
152 for (unsigned i = 0; i < depth(); ++i)
153 if (Cursor_[i].par_ == p)
159 bool MathCursor::openable(MathAtom const & t, bool sel) const
168 // we can't move into anything new during selection
169 if (depth() == Anchor_.size())
171 if (t.operator->() != Anchor_[depth()].par_)
178 bool MathCursor::inNucleus() const
180 return par()->asScriptInset() && idx() == 2;
184 bool MathCursor::posLeft()
193 bool MathCursor::posRight()
202 bool MathCursor::left(bool sel)
205 autocorrect_ = false;
206 targetx_ = -1; // "no target"
213 if (hasPrevAtom() && openable(prevAtom(), sel)) {
214 pushRight(prevAtom());
218 return posLeft() || idxLeft() || popLeft() || selection_;
222 bool MathCursor::right(bool sel)
225 autocorrect_ = false;
226 targetx_ = -1; // "no target"
233 if (hasNextAtom() && openable(nextAtom(), sel)) {
234 pushLeft(nextAtom());
238 return posRight() || idxRight() || popRight() || selection_;
242 void MathCursor::first()
245 push(formula_->par());
246 par()->idxFirst(idx(), pos());
250 void MathCursor::last()
253 push(formula_->par());
254 par()->idxLast(idx(), pos());
259 (MathIterator const & cursor, MathIterator const & anchor)
261 // avoid deeper nested insets when selecting
262 if (cursor.size() > anchor.size())
265 // anchor might be deeper, should have same path then
266 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
267 if (cursor[i].par_ != anchor[i].par_)
270 // position should be ok.
275 void MathCursor::setPos(int x, int y)
278 bool res = bruteFind(x, y,
279 formula()->xlow(), formula()->xhigh(),
280 formula()->ylow(), formula()->yhigh());
282 // this can happen on creation of "math-display"
286 targetx_ = -1; // "no target"
292 bool MathCursor::home(bool sel)
295 autocorrect_ = false;
298 if (!par()->idxHome(idx(), pos()))
301 targetx_ = -1; // "no target"
306 bool MathCursor::end(bool sel)
309 autocorrect_ = false;
312 if (!par()->idxEnd(idx(), pos()))
315 targetx_ = -1; // "no target"
320 void MathCursor::plainErase()
322 array().erase(pos());
326 void MathCursor::markInsert()
328 //lyxerr << "inserting mark\n";
329 array().insert(pos(), MathAtom(new MathCharInset(0)));
333 void MathCursor::markErase()
335 //lyxerr << "deleting mark\n";
336 array().erase(pos());
340 void MathCursor::plainInsert(MathAtom const & t)
343 array().insert(pos(), t);
348 void MathCursor::insert(string const & str)
350 //lyxerr << "inserting '" << str << "'\n";
352 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
353 plainInsert(MathAtom(new MathCharInset(*it)));
357 void MathCursor::insert(char c)
359 //lyxerr << "inserting '" << c << "'\n";
361 plainInsert(MathAtom(new MathCharInset(c)));
365 void MathCursor::insert(MathAtom const & t)
373 void MathCursor::niceInsert(string const & t)
375 MathArray ar = asArray(t);
383 void MathCursor::niceInsert(MathAtom const & t)
386 string safe = grabAndEraseSelection();
388 // enter the new inset and move the contents of the selection if possible
391 pushLeft(nextAtom());
397 void MathCursor::insert(MathArray const & ar)
402 array().insert(pos(), ar);
407 void MathCursor::paste(string const & data)
409 dispatch(FuncRequest(LFUN_PASTE, data));
413 bool MathCursor::backspace()
415 autocorrect_ = false;
423 if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
432 MathUnknownInset * p = activeMacro();
433 if (p->name().size() > 1) {
434 p->setName(p->name().substr(0, p->name().size() - 1));
445 bool MathCursor::erase()
447 autocorrect_ = false;
456 // delete empty cells if possible
458 if (par()->idxDelete(idx()))
461 // old behaviour when in last position of cell
462 if (pos() == size()) {
463 if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
466 par()->idxGlue(idx());
476 bool MathCursor::up(bool sel)
481 MathIterator save = Cursor_;
485 autocorrect_ = false;
490 bool MathCursor::down(bool sel)
495 MathIterator save = Cursor_;
499 autocorrect_ = false;
504 void MathCursor::macroModeClose()
508 MathUnknownInset * p = activeMacro();
510 string s = p->name();
512 array().erase(pos());
514 // do nothing if the macro name is empty
518 string name = s.substr(1);
520 // prevent entering of recursive macros
521 if (formula()->lyxCode() == Inset::MATHMACRO_CODE
522 && formula()->getInsetName() == name)
523 lyxerr << "can't enter recursive macro\n";
525 niceInsert(createMathInset(name));
529 string MathCursor::macroName() const
531 return inMacroMode() ? activeMacro()->name() : string();
535 void MathCursor::selClear()
542 void MathCursor::selCopy()
546 theCutBuffer = grabSelection();
549 theCutBuffer.erase();
554 void MathCursor::selCut()
557 theCutBuffer = grabAndEraseSelection();
561 void MathCursor::selDel()
571 void MathCursor::selPaste()
581 void MathCursor::selHandle(bool sel)
583 if (sel == selection_)
591 void MathCursor::selStart()
601 void MathCursor::selClearOrDel()
603 if (lyxrc.auto_region_delete)
610 void MathCursor::drawSelection(MathPainterInfo & pi) const
616 getSelection(i1, i2);
617 i1.par_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
621 void MathCursor::handleNest(MathAtom const & a)
624 at.nucleus()->cell(0) = asArray(grabAndEraseSelection());
626 pushRight(prevAtom());
630 void MathCursor::getPos(int & x, int & y) const
632 par()->getPos(idx(), pos(), x, y);
636 int MathCursor::targetX() const
646 MathInset * MathCursor::par() const
648 return cursor().par_;
652 InsetFormulaBase * MathCursor::formula() const
658 MathCursor::idx_type MathCursor::idx() const
660 return cursor().idx_;
664 MathCursor::idx_type & MathCursor::idx()
666 return cursor().idx_;
670 MathCursor::pos_type MathCursor::pos() const
672 return cursor().pos_;
676 void MathCursor::adjust(pos_type from, difference_type diff)
678 if (cursor().pos_ > from)
679 cursor().pos_ += diff;
680 if (Anchor_.back().pos_ > from)
681 Anchor_.back().pos_ += diff;
682 // just to be on the safe side
683 // theoretically unecessary
688 MathCursor::pos_type & MathCursor::pos()
690 return cursor().pos_;
694 bool MathCursor::inMacroMode() const
698 MathUnknownInset const * p = prevAtom()->asUnknownInset();
699 return p && !p->final();
703 MathUnknownInset * MathCursor::activeMacro()
705 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
709 MathUnknownInset const * MathCursor::activeMacro() const
711 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
715 bool MathCursor::inMacroArgMode() const
717 return pos() > 0 && prevAtom()->getChar() == '#';
721 bool MathCursor::selection() const
727 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
729 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
730 MathGridInset * p = Cursor_[i].par_->asGridInset();
732 idx = Cursor_[i].idx_;
740 void MathCursor::popToHere(MathInset const * p)
742 while (depth() && Cursor_.back().par_ != p)
747 void MathCursor::popToEnclosingGrid()
749 while (depth() && !Cursor_.back().par_->asGridInset())
754 void MathCursor::popToEnclosingHull()
756 while (depth() && !Cursor_.back().par_->asHullInset())
761 void MathCursor::pullArg()
764 MathArray a = array();
767 array().insert(pos(), a);
770 formula()->mutateToText();
775 void MathCursor::touch()
777 MathIterator::const_iterator it = Cursor_.begin();
778 MathIterator::const_iterator et = Cursor_.end();
779 for ( ; it != et; ++it)
784 void MathCursor::normalize()
786 if (idx() >= par()->nargs()) {
787 lyxerr << "this should not really happen - 1: "
788 << idx() << ' ' << par()->nargs()
789 << " in: " << par() << endl;
792 idx() = min(idx(), par()->nargs() - 1);
794 if (pos() > size()) {
795 lyxerr << "this should not really happen - 2: "
796 << pos() << ' ' << size() << " in idx: " << idx()
798 WriteStream wi(lyxerr, false, true);
803 pos() = min(pos(), size());
807 MathCursor::size_type MathCursor::size() const
809 return array().size();
813 bool MathCursor::hasPrevAtom() const
819 bool MathCursor::hasNextAtom() const
821 return pos() < size();
825 MathAtom const & MathCursor::prevAtom() const
827 lyx::Assert(pos() > 0);
828 return array()[pos() - 1];
832 MathAtom & MathCursor::prevAtom()
834 lyx::Assert(pos() > 0);
835 return array()[pos() - 1];
839 MathAtom const & MathCursor::nextAtom() const
841 lyx::Assert(pos() < size());
842 return array()[pos()];
846 MathAtom & MathCursor::nextAtom()
848 lyx::Assert(pos() < size());
849 return array()[pos()];
853 MathArray & MathCursor::array() const
855 static MathArray dummy;
857 if (idx() >= par()->nargs()) {
858 lyxerr << "############ idx_ " << idx() << " not valid\n";
863 lyxerr << "############ depth() == 0 not valid\n";
867 return cursor().cell();
871 void MathCursor::idxNext()
873 par()->idxNext(idx(), pos());
877 void MathCursor::idxPrev()
879 par()->idxPrev(idx(), pos());
883 char MathCursor::valign() const
886 MathGridInset * p = enclosingGrid(idx);
887 return p ? p->valign() : '\0';
891 char MathCursor::halign() const
894 MathGridInset * p = enclosingGrid(idx);
895 return p ? p->halign(idx % p->ncols()) : '\0';
899 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
901 MathCursorPos anc = normalAnchor();
902 if (anc < cursor()) {
912 MathCursorPos & MathCursor::cursor()
914 lyx::Assert(depth());
915 return Cursor_.back();
919 MathCursorPos const & MathCursor::cursor() const
921 lyx::Assert(depth());
922 return Cursor_.back();
926 bool MathCursor::goUpDown(bool up)
928 // Be warned: The 'logic' implemented in this function is highly fragile.
929 // A distance of one pixel or a '<' vs '<=' _really_ matters.
930 // So fiddle around with it only if you know what you are doing!
935 // check if we had something else in mind, if not, this is the future goal
941 // try neigbouring script insets
944 MathScriptInset const * p = prevAtom()->asScriptInset();
945 if (p && p->has(up)) {
948 idx() = up; // the superscript has index 1
950 ///lyxerr << "updown: handled by scriptinset to the left\n";
957 MathScriptInset const * p = nextAtom()->asScriptInset();
958 if (p && p->has(up)) {
962 ///lyxerr << "updown: handled by scriptinset to the right\n";
968 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
973 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
974 // lyxerr << "updown: handled by brute find in the same cell\n";
978 // try to find an inset that knows better then we
980 ///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
982 if (par()->idxUpDown(idx(), pos(), up, targetx_)) {
983 // try to find best position within this inset
989 // no such inset found, just take something "above"
990 ///lyxerr << "updown: handled by strange case\n";
996 up ? formula()->ylow() : yo + 4,
997 up ? yo - 4 : formula()->yhigh()
1000 // any improvement so far?
1003 if (up ? ynew < yo : ynew > yo)
1009 bool MathCursor::bruteFind
1010 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1012 MathIterator best_cursor;
1013 double best_dist = 1e10;
1015 MathIterator it = ibegin(formula()->par().nucleus());
1016 MathIterator et = iend(formula()->par().nucleus());
1018 // avoid invalid nesting when selecting
1019 if (!selection_ || positionable(it, Anchor_)) {
1021 it.back().getPos(xo, yo);
1022 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1023 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1024 // '<=' in order to take the last possible position
1025 // this is important for clicking behind \sum in e.g. '\sum_i a'
1026 if (d <= best_dist) {
1038 if (best_dist < 1e10)
1039 Cursor_ = best_cursor;
1040 return best_dist < 1e10;
1044 void MathCursor::bruteFind2(int x, int y)
1046 double best_dist = 1e10;
1048 MathIterator it = Cursor_;
1049 it.back().setPos(0);
1050 MathIterator et = Cursor_;
1051 et.back().setPos(it.cell().size());
1054 it.back().getPos(xo, yo);
1055 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1056 // '<=' in order to take the last possible position
1057 // this is important for clicking behind \sum in e.g. '\sum_i a'
1058 if (d <= best_dist) {
1069 bool MathCursor::idxLineLast()
1071 idx() -= idx() % par()->ncols();
1072 idx() += par()->ncols() - 1;
1077 bool MathCursor::idxLeft()
1079 return par()->idxLeft(idx(), pos());
1083 bool MathCursor::idxRight()
1085 return par()->idxRight(idx(), pos());
1089 bool MathCursor::script(bool up)
1091 // Hack to get \\^ and \\_ working
1092 if (inMacroMode() && macroName() == "\\") {
1094 niceInsert(createMathInset("mathcircumflex"));
1101 string safe = grabAndEraseSelection();
1103 // we are in a nucleus of a script inset, move to _our_ script
1104 par()->asScriptInset()->ensure(up);
1107 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1108 prevAtom().nucleus()->asScriptInset()->ensure(up);
1109 pushRight(prevAtom());
1112 } else if (hasPrevAtom()) {
1114 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1115 pushLeft(nextAtom());
1119 plainInsert(MathAtom(new MathScriptInset(up)));
1120 prevAtom().nucleus()->asScriptInset()->ensure(up);
1121 pushRight(prevAtom());
1131 bool MathCursor::interpret(char c)
1133 //lyxerr << "interpret 2: '" << c << "'\n";
1134 targetx_ = -1; // "no target"
1135 if (inMacroArgMode()) {
1139 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1140 if (p && 1 <= n && n <= p->numargs())
1141 insert(MathAtom(new MathMacroArgument(c - '0')));
1143 insert(createMathInset("#"));
1144 interpret(c); // try again
1150 if (inMacroMode()) {
1151 string name = macroName();
1152 //lyxerr << "interpret name: '" << name << "'\n";
1155 activeMacro()->setName(activeMacro()->name() + c);
1159 // handle 'special char' macros
1164 if (currentMode() == MathInset::TEXT_MODE)
1165 niceInsert(createMathInset("textbackslash"));
1167 niceInsert(createMathInset("backslash"));
1168 } else if (c == '{') {
1169 niceInsert(MathAtom(new MathBraceInset));
1171 niceInsert(createMathInset(string(1, c)));
1176 // leave macro mode and try again if necessary
1179 niceInsert(MathAtom(new MathBraceInset));
1185 // This is annoying as one has to press <space> far too often.
1189 // leave autocorrect mode if necessary
1190 if (autocorrect_ && c == ' ') {
1191 autocorrect_ = false;
1196 // just clear selection on pressing the space bar
1197 if (selection_ && c == ' ') {
1205 //lyxerr << "starting with macro\n";
1206 insert(MathAtom(new MathUnknownInset("\\", false)));
1211 if (currentMode() == MathInset::TEXT_MODE)
1217 if (currentMode() == MathInset::TEXT_MODE) {
1218 // insert spaces in text mode,
1219 // but suppress direct insertion of two spaces in a row
1220 // the still allows typing '<space>a<space>' and deleting the 'a', but
1221 // it is better than nothing...
1222 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1226 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1227 prevAtom().nucleus()->asSpaceInset()->incSpace();
1232 // if are at the very end, leave the formula
1233 return pos() != size();
1241 if (c == '{' || c == '}') {
1242 niceInsert(createMathInset(string(1, c)));
1247 insert(createMathInset("$"));
1252 niceInsert(MathAtom(new MathCommentInset));
1256 // try auto-correction
1257 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1260 // no special circumstances, so insert the character without any fuss
1262 autocorrect_ = true;
1267 void MathCursor::setSelection(MathIterator const & where, size_type n)
1276 void MathCursor::insetToggle()
1278 if (hasNextAtom()) {
1279 // toggle previous inset ...
1280 nextAtom().nucleus()->lock(!nextAtom()->lock());
1281 } else if (popLeft() && hasNextAtom()) {
1282 // ... or enclosing inset if we are in the last inset position
1283 nextAtom().nucleus()->lock(!nextAtom()->lock());
1289 string MathCursor::info() const
1292 os << "Math editor mode. ";
1293 for (int i = 0, n = depth(); i < n; ++i) {
1294 Cursor_[i].par_->infoize(os);
1298 prevAtom()->infoize2(os);
1300 return STRCONV(os.str());
1304 unsigned MathCursor::depth() const
1306 return Cursor_.size();
1314 void region(MathCursorPos const & i1, MathCursorPos const & i2,
1315 MathInset::row_type & r1, MathInset::row_type & r2,
1316 MathInset::col_type & c1, MathInset::col_type & c2)
1318 MathInset * p = i1.par_;
1319 c1 = p->col(i1.idx_);
1320 c2 = p->col(i2.idx_);
1323 r1 = p->row(i1.idx_);
1324 r2 = p->row(i2.idx_);
1332 string MathCursor::grabSelection() const
1339 getSelection(i1, i2);
1341 if (i1.idx_ == i2.idx_) {
1342 MathArray::const_iterator it = i1.cell().begin();
1343 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1348 region(i1, i2, r1, r2, c1, c2);
1351 for (row_type row = r1; row <= r2; ++row) {
1354 for (col_type col = c1; col <= c2; ++col) {
1357 data += asString(i1.par_->cell(i1.par_->index(row, col)));
1364 void MathCursor::eraseSelection()
1368 getSelection(i1, i2);
1369 if (i1.idx_ == i2.idx_)
1370 i1.cell().erase(i1.pos_, i2.pos_);
1372 MathInset * p = i1.par_;
1375 region(i1, i2, r1, r2, c1, c2);
1376 for (row_type row = r1; row <= r2; ++row)
1377 for (col_type col = c1; col <= c2; ++col)
1378 p->cell(p->index(row, col)).clear();
1384 string MathCursor::grabAndEraseSelection()
1388 string res = grabSelection();
1395 MathCursorPos MathCursor::normalAnchor() const
1397 if (Anchor_.size() < depth()) {
1399 lyxerr << "unusual Anchor size\n";
1401 //lyx::Assert(Anchor_.size() >= cursor.depth());
1402 // use Anchor on the same level as Cursor
1403 MathCursorPos normal = Anchor_[depth() - 1];
1404 if (depth() < Anchor_.size() && !(normal < cursor())) {
1405 // anchor is behind cursor -> move anchor behind the inset
1412 MathInset::result_type MathCursor::dispatch(FuncRequest const & cmd)
1414 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1415 MathCursorPos & pos = Cursor_[i];
1416 MathInset::result_type
1417 res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_);
1418 if (res != MathInset::UNDISPATCHED) {
1419 if (res == MathInset::DISPATCHED_POP) {
1420 Cursor_.shrink(i + 1);
1426 return MathInset::UNDISPATCHED;
1430 MathInset::mode_type MathCursor::currentMode() const
1432 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1433 MathInset::mode_type res = Cursor_[i].par_->currentMode();
1434 if (res != MathInset::UNDECIDED_MODE)
1437 return MathInset::UNDECIDED_MODE;
1441 void MathCursor::handleFont(string const & font)
1446 safe = grabAndEraseSelection();
1449 if (array().size()) {
1450 // something left in the cell
1452 // cursor in first position
1454 } else if (pos() == array().size()) {
1455 // cursor in last position
1458 // cursor in between. split cell
1459 MathArray::iterator bt = array().begin();
1460 MathAtom at = createMathInset(font);
1461 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1462 cursor().cell().erase(bt, bt + pos());
1467 // nothing left in the cell
1475 void releaseMathCursor(BufferView * bv)
1478 InsetFormulaBase * f = mathcursor->formula();
1479 f->hideInsetCursor(bv);