3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Stefan Schimanski
10 * Full author contact details are available in file CREDITS.
15 #include "MathMacro.h"
17 #include "InsetMathChar.h"
18 #include "MathCompletionList.h"
19 #include "MathExtern.h"
20 #include "MathFactory.h"
21 #include "MathStream.h"
22 #include "MathSupport.h"
25 #include "BufferView.h"
26 #include "CoordCache.h"
28 #include "FuncStatus.h"
29 #include "FuncRequest.h"
30 #include "LaTeXFeatures.h"
34 #include "frontends/Painter.h"
36 #include "support/debug.h"
37 #include "support/gettext.h"
38 #include "support/lassert.h"
39 #include "support/lstrings.h"
40 #include "support/textutils.h"
45 using namespace lyx::support;
51 /// A proxy for the macro values
52 class ArgumentProxy : public InsetMath {
55 ArgumentProxy(MathMacro & mathMacro, size_t idx)
56 : mathMacro_(mathMacro), idx_(idx) {}
58 ArgumentProxy(MathMacro & mathMacro, size_t idx, docstring const & def)
59 : mathMacro_(mathMacro), idx_(idx)
64 InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
66 void metrics(MetricsInfo & mi, Dimension & dim) const {
67 mathMacro_.macro()->unlock();
68 mathMacro_.cell(idx_).metrics(mi, dim);
70 if (!mathMacro_.editMetrics(mi.base.bv)
71 && mathMacro_.cell(idx_).empty())
72 def_.metrics(mi, dim);
74 mathMacro_.macro()->lock();
76 // FIXME Other external things need similar treatment.
78 void mathmlize(MathStream & ms) const { ms << mathMacro_.cell(idx_); }
80 void htmlize(HtmlStream & ms) const { ms << mathMacro_.cell(idx_); }
82 void draw(PainterInfo & pi, int x, int y) const {
83 if (mathMacro_.editMetrics(pi.base.bv)) {
84 // The only way a ArgumentProxy can appear is in a cell of the
85 // MathMacro. Moreover the cells are only drawn in the DISPLAY_FOLDED
86 // mode and then, if the macro is edited the monochrome
87 // mode is entered by the MathMacro before calling the cells' draw
88 // method. Then eventually this code is reached and the proxy leaves
89 // monochrome mode temporarely. Hence, if it is not in monochrome
90 // here (and the assert triggers in pain.leaveMonochromeMode())
92 pi.pain.leaveMonochromeMode();
93 mathMacro_.cell(idx_).draw(pi, x, y);
94 pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
95 } else if (mathMacro_.cell(idx_).empty()) {
96 mathMacro_.cell(idx_).setXY(*pi.base.bv, x, y);
99 mathMacro_.cell(idx_).draw(pi, x, y);
102 size_t idx() const { return idx_; }
104 int kerning(BufferView const * bv) const
106 if (mathMacro_.editMetrics(bv)
107 || !mathMacro_.cell(idx_).empty())
108 return mathMacro_.cell(idx_).kerning(bv);
110 return def_.kerning(bv);
115 Inset * clone() const
117 return new ArgumentProxy(*this);
120 MathMacro & mathMacro_;
128 MathMacro::MathMacro(Buffer * buf, docstring const & name)
129 : InsetMathNest(buf, 0), name_(name), displayMode_(DISPLAY_INIT),
130 expanded_(buf), attachedArgsNum_(0), optionals_(0), nextFoldMode_(true),
131 macroBackup_(buf), macro_(0), needsUpdate_(false),
132 isUpdating_(false), appetite_(9)
136 Inset * MathMacro::clone() const
138 MathMacro * copy = new MathMacro(*this);
139 copy->needsUpdate_ = true;
140 //copy->expanded_.cell(0).clear();
145 void MathMacro::normalize(NormalStream & os) const
147 os << "[macro " << name();
148 for (size_t i = 0; i < nargs(); ++i)
149 os << ' ' << cell(i);
154 docstring MathMacro::name() const
156 if (displayMode_ == DISPLAY_UNFOLDED)
157 return asString(cell(0));
163 void MathMacro::cursorPos(BufferView const & bv,
164 CursorSlice const & sl, bool boundary, int & x, int & y) const
166 // We may have 0 arguments, but InsetMathNest requires at least one.
168 InsetMathNest::cursorPos(bv, sl, boundary, x, y);
172 bool MathMacro::editMode(BufferView const * bv) const {
173 // find this in cursor trace
174 Cursor const & cur = bv->cursor();
175 for (size_t i = 0; i != cur.depth(); ++i)
176 if (&cur[i].inset() == this) {
177 // look if there is no other macro in edit mode above
179 for (; i != cur.depth(); ++i) {
180 InsetMath * im = cur[i].asInsetMath();
182 MathMacro const * macro = im->asMacro();
183 if (macro && macro->displayMode() == DISPLAY_NORMAL)
188 // ok, none found, I am the highest one
196 bool MathMacro::editMetrics(BufferView const * bv) const
202 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
204 // set edit mode for which we will have calculated metrics. But only
205 editing_[mi.base.bv] = editMode(mi.base.bv);
207 // calculate new metrics according to display mode
208 if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
209 mathed_string_dim(mi.base.font, from_ascii("\\") + name(), dim);
210 } else if (displayMode_ == DISPLAY_UNFOLDED) {
211 cell(0).metrics(mi, dim);
213 mathed_string_dim(mi.base.font, from_ascii("\\"), bsdim);
214 dim.wid += bsdim.width() + 1;
215 dim.asc = max(bsdim.ascent(), dim.ascent());
216 dim.des = max(bsdim.descent(), dim.descent());
218 } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
219 && editing_[mi.base.bv]) {
220 // Macro will be edited in a old-style list mode here:
224 FontInfo labelFont = sane_font;
225 math_font_max_dim(labelFont, fontDim.asc, fontDim.des);
227 // get dimension of components of list view
229 nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": ");
230 nameDim.asc = fontDim.asc;
231 nameDim.des = fontDim.des;
234 argDim.wid = mathed_string_width(labelFont, from_ascii("#9: "));
235 argDim.asc = fontDim.asc;
236 argDim.des = fontDim.des;
239 definition_.metrics(mi, defDim);
242 dim.wid = nameDim.wid + defDim.wid;
243 dim.asc = max(nameDim.asc, defDim.asc);
244 dim.des = max(nameDim.des, defDim.des);
246 for (idx_type i = 0; i < nargs(); ++i) {
248 cell(i).metrics(mi, cdim);
249 dim.des += max(argDim.height(), cdim.height()) + 1;
250 dim.wid = max(dim.wid, argDim.wid + cdim.wid);
253 // make space for box and markers, 2 pixels
257 metricsMarkers2(dim);
261 // calculate metrics, hoping that all cells are seen
263 expanded_.cell(0).metrics(mi, dim);
265 // otherwise do a manual metrics call
266 CoordCache & coords = mi.base.bv->coordCache();
267 for (idx_type i = 0; i < nargs(); ++i) {
268 if (!coords.getArrays().hasDim(&cell(i))) {
270 cell(i).metrics(mi, tdim);
275 // calculate dimension with label while editing
276 if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
277 && editing_[mi.base.bv]) {
278 FontInfo font = mi.base.font;
279 augmentFont(font, from_ascii("lyxtex"));
281 mathed_string_dim(font, name(), namedim);
283 dim.wid += 2 + namedim.wid + 2 + 2;
284 dim.asc = max(dim.asc, namedim.asc) + 2;
285 dim.des = max(dim.des, namedim.des) + 2;
287 dim.wid = max(1 + namedim.wid + 1, 2 + dim.wid + 2);
288 dim.asc += 1 + namedim.height() + 1;
295 int MathMacro::kerning(BufferView const * bv) const {
296 if (displayMode_ == DISPLAY_NORMAL && !editing_[bv])
297 return expanded_.kerning(bv);
303 void MathMacro::updateMacro(MacroContext const & mc)
306 macro_ = mc.get(name());
307 if (macro_ && macroBackup_ != *macro_) {
308 macroBackup_ = *macro_;
317 class MathMacro::UpdateLocker
320 explicit UpdateLocker(MathMacro & mm) : mac(mm)
322 mac.isUpdating_ = true;
324 ~UpdateLocker() { mac.isUpdating_ = false; }
328 /** Avoid wrong usage of UpdateLocker.
329 To avoid wrong usage:
330 UpdateLocker(...); // wrong
331 UpdateLocker locker(...); // right
333 #define UpdateLocker(x) unnamed_UpdateLocker;
334 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
337 void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
340 // block recursive calls (bug 8999)
344 UpdateLocker locker(*this);
351 requires_ = macro_->requires();
354 // non-normal mode? We are done!
355 || (displayMode_ != DISPLAY_NORMAL))
358 needsUpdate_ = false;
360 // get default values of macro
361 vector<docstring> const & defaults = macro_->defaults();
363 // create MathMacroArgumentValue objects pointing to the cells of the macro
364 vector<MathData> values(nargs());
365 for (size_t i = 0; i < nargs(); ++i) {
366 ArgumentProxy * proxy;
367 if (i < defaults.size())
368 proxy = new ArgumentProxy(*this, i, defaults[i]);
370 proxy = new ArgumentProxy(*this, i);
371 values[i].insert(0, MathAtom(proxy));
373 // expanding macro with the values
374 // Only update the argument macros if anything was expanded, otherwise
375 // we would get an endless loop (bug 9140). UpdateLocker does not work
376 // in this case, since MacroData::expand() creates new MathMacro
377 // objects, so this would be a different recursion path than the one
378 // protected by UpdateLocker.
379 if (macro_->expand(values, expanded_.cell(0))) {
380 if (utype == OutputUpdate && !expanded_.cell(0).empty())
381 expanded_.cell(0).updateMacros(cur, mc, utype);
383 // get definition for list edit mode
384 docstring const & display = macro_->display();
385 asArray(display.empty() ? macro_->definition() : display, definition_);
389 void MathMacro::draw(PainterInfo & pi, int x, int y) const
391 Dimension const dim = dimension(*pi.base.bv);
393 setPosCache(pi, x, y);
397 if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
398 FontSetChanger dummy(pi.base, "lyxtex");
399 pi.pain.text(x, y, from_ascii("\\") + name(), pi.base.font);
400 } else if (displayMode_ == DISPLAY_UNFOLDED) {
401 FontSetChanger dummy(pi.base, "lyxtex");
402 pi.pain.text(x, y, from_ascii("\\"), pi.base.font);
403 x += mathed_string_width(pi.base.font, from_ascii("\\")) + 1;
404 cell(0).draw(pi, x, y);
405 drawMarkers(pi, expx, expy);
406 } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
407 && editing_[pi.base.bv]) {
408 // Macro will be edited in a old-style list mode here:
410 CoordCache const & coords = pi.base.bv->coordCache();
411 FontInfo const & labelFont = sane_font;
413 // markers and box needs two pixels
416 // get maximal font height
418 math_font_max_dim(pi.base.font, fontDim.asc, fontDim.des);
421 docstring label = from_ascii("Macro \\") + name() + from_ascii(": ");
422 pi.pain.text(x, y, label, labelFont);
423 x += mathed_string_width(labelFont, label);
426 definition_.draw(pi, x, y);
427 Dimension const & defDim = coords.getArrays().dim(&definition_);
428 y += max(fontDim.des, defDim.des);
431 docstring str = from_ascii("#9");
432 int strw1 = mathed_string_width(labelFont, from_ascii("#9"));
433 int strw2 = mathed_string_width(labelFont, from_ascii(": "));
435 for (idx_type i = 0; i < nargs(); ++i) {
437 Dimension const & cdim = coords.getArrays().dim(&cell(i));
439 y += max(fontDim.asc, cdim.asc) + 1;
443 pi.pain.text(x, y, str, labelFont);
445 pi.pain.text(x, y, from_ascii(":"), labelFont);
449 cell(i).draw(pi, x, y);
452 y += max(fontDim.des, cdim.des);
455 pi.pain.rectangle(expx + 1, expy - dim.asc + 1, dim.wid - 3,
456 dim.height() - 2, Color_mathmacroframe);
457 drawMarkers2(pi, expx, expy);
459 bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
462 for (size_t i = 0; i < nargs(); ++i)
463 cell(i).setXY(*pi.base.bv, x, y);
465 if (drawBox && editing_[pi.base.bv]) {
466 // draw header and rectangle around
467 FontInfo font = pi.base.font;
468 augmentFont(font, from_ascii("lyxtex"));
469 font.setSize(FONT_SIZE_TINY);
470 font.setColor(Color_mathmacrolabel);
472 mathed_string_dim(font, name(), namedim);
474 pi.pain.fillRectangle(x, y - dim.asc, dim.wid, 1 + namedim.height() + 1, Color_mathmacrobg);
475 pi.pain.text(x + 1, y - dim.asc + namedim.asc + 2, name(), font);
476 expx += (dim.wid - expanded_.cell(0).dimension(*pi.base.bv).width()) / 2;
479 if (editing_[pi.base.bv]) {
480 pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
481 expanded_.cell(0).draw(pi, expx, expy);
482 pi.pain.leaveMonochromeMode();
485 pi.pain.rectangle(x, y - dim.asc, dim.wid,
486 dim.height(), Color_mathmacroframe);
488 expanded_.cell(0).draw(pi, expx, expy);
491 drawMarkers(pi, x, y);
494 // edit mode changed?
495 if (editing_[pi.base.bv] != editMode(pi.base.bv))
496 pi.base.bv->cursor().screenUpdateFlags(Update::SinglePar);
500 void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
502 // We may have 0 arguments, but InsetMathNest requires at least one.
504 InsetMathNest::drawSelection(pi, x, y);
508 void MathMacro::setDisplayMode(MathMacro::DisplayMode mode, int appetite)
510 if (displayMode_ != mode) {
511 // transfer name if changing from or to DISPLAY_UNFOLDED
512 if (mode == DISPLAY_UNFOLDED) {
514 asArray(name_, cell(0));
515 } else if (displayMode_ == DISPLAY_UNFOLDED) {
516 name_ = asString(cell(0));
524 // the interactive init mode is non-greedy by default
526 appetite_ = (mode == DISPLAY_INTERACTIVE_INIT) ? 0 : 9;
528 appetite_ = size_t(appetite);
532 MathMacro::DisplayMode MathMacro::computeDisplayMode() const
534 if (nextFoldMode_ == true && macro_ && !macro_->locked())
535 return DISPLAY_NORMAL;
537 return DISPLAY_UNFOLDED;
541 bool MathMacro::validName() const
543 docstring n = name();
548 // converting back and force doesn't swallow anything?
551 if (asString(ma) != n)
555 for (size_t i = 0; i<n.size(); ++i) {
556 if (!(n[i] >= 'a' && n[i] <= 'z')
557 && !(n[i] >= 'A' && n[i] <= 'Z')
566 void MathMacro::validate(LaTeXFeatures & features) const
568 if (!requires_.empty())
569 features.require(requires_);
571 if (name() == "binom")
572 features.require("binom");
574 // validate the cells and the definition
575 if (displayMode() == DISPLAY_NORMAL) {
576 definition_.validate(features);
577 InsetMathNest::validate(features);
582 void MathMacro::edit(Cursor & cur, bool front, EntryDirection entry_from)
584 cur.screenUpdateFlags(Update::SinglePar);
585 InsetMathNest::edit(cur, front, entry_from);
589 Inset * MathMacro::editXY(Cursor & cur, int x, int y)
591 // We may have 0 arguments, but InsetMathNest requires at least one.
593 cur.screenUpdateFlags(Update::SinglePar);
594 return InsetMathNest::editXY(cur, x, y);
600 void MathMacro::removeArgument(Inset::pos_type pos) {
601 if (displayMode_ == DISPLAY_NORMAL) {
602 LASSERT(size_t(pos) < cells_.size(), return);
603 cells_.erase(cells_.begin() + pos);
604 if (size_t(pos) < attachedArgsNum_)
606 if (size_t(pos) < optionals_) {
615 void MathMacro::insertArgument(Inset::pos_type pos) {
616 if (displayMode_ == DISPLAY_NORMAL) {
617 LASSERT(size_t(pos) <= cells_.size(), return);
618 cells_.insert(cells_.begin() + pos, MathData());
619 if (size_t(pos) < attachedArgsNum_)
621 if (size_t(pos) < optionals_)
629 void MathMacro::detachArguments(vector<MathData> & args, bool strip)
631 LASSERT(displayMode_ == DISPLAY_NORMAL, return);
634 // strip off empty cells, but not more than arity-attachedArgsNum_
637 for (i = cells_.size(); i > attachedArgsNum_; --i)
638 if (!cell(i - 1).empty()) break;
642 attachedArgsNum_ = 0;
643 expanded_.cell(0) = MathData();
650 void MathMacro::attachArguments(vector<MathData> const & args, size_t arity, int optionals)
652 LASSERT(displayMode_ == DISPLAY_NORMAL, return);
654 attachedArgsNum_ = args.size();
655 cells_.resize(arity);
656 expanded_.cell(0) = MathData();
657 optionals_ = optionals;
663 bool MathMacro::idxFirst(Cursor & cur) const
665 cur.screenUpdateFlags(Update::SinglePar);
666 return InsetMathNest::idxFirst(cur);
670 bool MathMacro::idxLast(Cursor & cur) const
672 cur.screenUpdateFlags(Update::SinglePar);
673 return InsetMathNest::idxLast(cur);
677 bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur)
679 if (displayMode_ == DISPLAY_UNFOLDED) {
680 docstring const & unfolded_name = name();
681 if (unfolded_name != name_) {
682 // The macro name was changed
683 Cursor inset_cursor = old;
684 int macroSlice = inset_cursor.find(this);
685 // returning true means the cursor is "now" invalid,
687 LASSERT(macroSlice != -1, return true);
688 inset_cursor.cutOff(macroSlice);
689 inset_cursor.recordUndoInset();
691 inset_cursor.cell().erase(inset_cursor.pos());
692 inset_cursor.cell().insert(inset_cursor.pos(),
693 createInsetMath(unfolded_name, cur.buffer()));
695 cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
699 cur.screenUpdateFlags(Update::Force);
700 return InsetMathNest::notifyCursorLeaves(old, cur);
704 void MathMacro::fold(Cursor & cur)
706 if (!nextFoldMode_) {
707 nextFoldMode_ = true;
708 cur.screenUpdateFlags(Update::SinglePar);
713 void MathMacro::unfold(Cursor & cur)
716 nextFoldMode_ = false;
717 cur.screenUpdateFlags(Update::SinglePar);
722 bool MathMacro::folded() const
724 return nextFoldMode_;
728 void MathMacro::write(WriteStream & os) const
730 MathEnsurer ensurer(os, macro_ != 0, true);
733 if (displayMode_ != DISPLAY_NORMAL) {
734 os << "\\" << name();
735 if (name().size() != 1 || isAlphaASCII(name()[0]))
736 os.pendingSpace(true);
741 // we should be ok to continue even if this fails.
744 // Always protect macros in a fragile environment
748 os << "\\" << name();
751 // Optional arguments:
752 // First find last non-empty optional argument
753 idx_type emptyOptFrom = 0;
755 for (; i < cells_.size() && i < optionals_; ++i) {
756 if (!cell(i).empty())
757 emptyOptFrom = i + 1;
760 // print out optionals
761 for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
763 os << "[" << cell(i) << "]";
766 // skip the tailing empty optionals
769 // Print remaining arguments
770 for (; i < cells_.size(); ++i) {
771 if (cell(i).size() == 1
772 && cell(i)[0].nucleus()->asCharInset()
773 && isASCII(cell(i)[0].nucleus()->asCharInset()->getChar())) {
778 os << "{" << cell(i) << "}";
782 // add space if there was no argument
784 os.pendingSpace(true);
788 void MathMacro::maple(MapleStream & os) const
790 lyx::maple(expanded_.cell(0), os);
794 void MathMacro::mathmlize(MathStream & os) const
796 // macro_ is 0 if this is an unknown macro
797 LATTEST(macro_ || displayMode_ != DISPLAY_NORMAL);
799 docstring const xmlname = macro_->xmlname();
800 if (!xmlname.empty()) {
801 char const * type = macro_->MathMLtype();
802 os << '<' << type << "> " << xmlname << " /<"
807 MathData const & data = expanded_.cell(0);
809 // this means that we do not recognize the macro
810 throw MathExportException();
816 void MathMacro::htmlize(HtmlStream & os) const
818 // macro_ is 0 if this is an unknown macro
819 LATTEST(macro_ || displayMode_ != DISPLAY_NORMAL);
821 docstring const xmlname = macro_->xmlname();
822 if (!xmlname.empty()) {
823 os << ' ' << xmlname << ' ';
827 MathData const & data = expanded_.cell(0);
829 // this means that we do not recognize the macro
830 throw MathExportException();
836 void MathMacro::octave(OctaveStream & os) const
838 lyx::octave(expanded_.cell(0), os);
842 void MathMacro::infoize(odocstream & os) const
844 os << bformat(_("Macro: %1$s"), name());
848 void MathMacro::infoize2(odocstream & os) const
850 os << bformat(_("Macro: %1$s"), name());
854 bool MathMacro::completionSupported(Cursor const & cur) const
856 if (displayMode() != DISPLAY_UNFOLDED)
857 return InsetMathNest::completionSupported(cur);
859 return lyxrc.completion_popup_math
860 && displayMode() == DISPLAY_UNFOLDED
861 && cur.bv().cursor().pos() == int(name().size());
865 bool MathMacro::inlineCompletionSupported(Cursor const & cur) const
867 if (displayMode() != DISPLAY_UNFOLDED)
868 return InsetMathNest::inlineCompletionSupported(cur);
870 return lyxrc.completion_inline_math
871 && displayMode() == DISPLAY_UNFOLDED
872 && cur.bv().cursor().pos() == int(name().size());
876 bool MathMacro::automaticInlineCompletion() const
878 if (displayMode() != DISPLAY_UNFOLDED)
879 return InsetMathNest::automaticInlineCompletion();
881 return lyxrc.completion_inline_math;
885 bool MathMacro::automaticPopupCompletion() const
887 if (displayMode() != DISPLAY_UNFOLDED)
888 return InsetMathNest::automaticPopupCompletion();
890 return lyxrc.completion_popup_math;
894 CompletionList const *
895 MathMacro::createCompletionList(Cursor const & cur) const
897 if (displayMode() != DISPLAY_UNFOLDED)
898 return InsetMathNest::createCompletionList(cur);
900 return new MathCompletionList(cur.bv().cursor());
904 docstring MathMacro::completionPrefix(Cursor const & cur) const
906 if (displayMode() != DISPLAY_UNFOLDED)
907 return InsetMathNest::completionPrefix(cur);
909 if (!completionSupported(cur))
912 return "\\" + name();
916 bool MathMacro::insertCompletion(Cursor & cur, docstring const & s,
919 if (displayMode() != DISPLAY_UNFOLDED)
920 return InsetMathNest::insertCompletion(cur, s, finished);
922 if (!completionSupported(cur))
926 docstring newName = name() + s;
927 asArray(newName, cell(0));
928 cur.bv().cursor().pos() = name().size();
929 cur.screenUpdateFlags(Update::SinglePar);
933 cur.bv().cursor().pop();
934 ++cur.bv().cursor().pos();
935 cur.screenUpdateFlags(Update::SinglePar);
942 void MathMacro::completionPosAndDim(Cursor const & cur, int & x, int & y,
943 Dimension & dim) const
945 if (displayMode() != DISPLAY_UNFOLDED)
946 InsetMathNest::completionPosAndDim(cur, x, y, dim);
948 // get inset dimensions
949 dim = cur.bv().coordCache().insets().dim(this);
950 // FIXME: these 3 are no accurate, but should depend on the font.
951 // Now the popup jumps down if you enter a char with descent > 0.
957 = cur.bv().coordCache().insets().xy(this);