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 // write(), normalize(), infoize() and infoize2() are not needed since
77 // MathMacro uses the definition and not the expanded cells.
79 void maple(MapleStream & ms) const { ms << mathMacro_.cell(idx_); }
81 void maxima(MaximaStream & ms) const { ms << mathMacro_.cell(idx_); }
83 void mathematica(MathematicaStream & ms) const { ms << mathMacro_.cell(idx_); }
85 void mathmlize(MathStream & ms) const { ms << mathMacro_.cell(idx_); }
87 void htmlize(HtmlStream & ms) const { ms << mathMacro_.cell(idx_); }
89 void octave(OctaveStream & os) const { os << mathMacro_.cell(idx_); }
91 void draw(PainterInfo & pi, int x, int y) const {
92 if (mathMacro_.editMetrics(pi.base.bv)) {
93 // The only way a ArgumentProxy can appear is in a cell of the
94 // MathMacro. Moreover the cells are only drawn in the DISPLAY_FOLDED
95 // mode and then, if the macro is edited the monochrome
96 // mode is entered by the MathMacro before calling the cells' draw
97 // method. Then eventually this code is reached and the proxy leaves
98 // monochrome mode temporarely. Hence, if it is not in monochrome
99 // here (and the assert triggers in pain.leaveMonochromeMode())
101 pi.pain.leaveMonochromeMode();
102 mathMacro_.cell(idx_).draw(pi, x, y);
103 pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
104 } else if (mathMacro_.cell(idx_).empty()) {
105 mathMacro_.cell(idx_).setXY(*pi.base.bv, x, y);
108 mathMacro_.cell(idx_).draw(pi, x, y);
111 size_t idx() const { return idx_; }
113 int kerning(BufferView const * bv) const
115 if (mathMacro_.editMetrics(bv)
116 || !mathMacro_.cell(idx_).empty())
117 return mathMacro_.cell(idx_).kerning(bv);
119 return def_.kerning(bv);
124 Inset * clone() const
126 return new ArgumentProxy(*this);
129 MathMacro & mathMacro_;
137 MathMacro::MathMacro(Buffer * buf, docstring const & name)
138 : InsetMathNest(buf, 0), name_(name), displayMode_(DISPLAY_INIT),
139 expanded_(buf), definition_(buf), attachedArgsNum_(0),
140 optionals_(0), nextFoldMode_(true),
141 macroBackup_(buf), macro_(0), needsUpdate_(false),
142 isUpdating_(false), appetite_(9)
146 Inset * MathMacro::clone() const
148 MathMacro * copy = new MathMacro(*this);
149 copy->needsUpdate_ = true;
150 //copy->expanded_.clear();
155 void MathMacro::normalize(NormalStream & os) const
157 os << "[macro " << name();
158 for (size_t i = 0; i < nargs(); ++i)
159 os << ' ' << cell(i);
164 docstring MathMacro::name() const
166 if (displayMode_ == DISPLAY_UNFOLDED)
167 return asString(cell(0));
173 void MathMacro::cursorPos(BufferView const & bv,
174 CursorSlice const & sl, bool boundary, int & x, int & y) const
176 // We may have 0 arguments, but InsetMathNest requires at least one.
178 InsetMathNest::cursorPos(bv, sl, boundary, x, y);
182 bool MathMacro::editMode(BufferView const * bv) const {
183 // find this in cursor trace
184 Cursor const & cur = bv->cursor();
185 for (size_t i = 0; i != cur.depth(); ++i)
186 if (&cur[i].inset() == this) {
187 // look if there is no other macro in edit mode above
189 for (; i != cur.depth(); ++i) {
190 InsetMath * im = cur[i].asInsetMath();
192 MathMacro const * macro = im->asMacro();
193 if (macro && macro->displayMode() == DISPLAY_NORMAL)
198 // ok, none found, I am the highest one
206 bool MathMacro::editMetrics(BufferView const * bv) const
212 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
214 // set edit mode for which we will have calculated metrics. But only
215 editing_[mi.base.bv] = editMode(mi.base.bv);
217 // calculate new metrics according to display mode
218 if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
219 mathed_string_dim(mi.base.font, from_ascii("\\") + name(), dim);
220 } else if (displayMode_ == DISPLAY_UNFOLDED) {
221 cell(0).metrics(mi, dim);
223 mathed_string_dim(mi.base.font, from_ascii("\\"), bsdim);
224 dim.wid += bsdim.width() + 1;
225 dim.asc = max(bsdim.ascent(), dim.ascent());
226 dim.des = max(bsdim.descent(), dim.descent());
228 } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
229 && editing_[mi.base.bv]) {
230 // Macro will be edited in a old-style list mode here:
234 FontInfo labelFont = sane_font;
235 math_font_max_dim(labelFont, fontDim.asc, fontDim.des);
237 // get dimension of components of list view
239 nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": ");
240 nameDim.asc = fontDim.asc;
241 nameDim.des = fontDim.des;
244 argDim.wid = mathed_string_width(labelFont, from_ascii("#9: "));
245 argDim.asc = fontDim.asc;
246 argDim.des = fontDim.des;
249 definition_.metrics(mi, defDim);
252 dim.wid = nameDim.wid + defDim.wid;
253 dim.asc = max(nameDim.asc, defDim.asc);
254 dim.des = max(nameDim.des, defDim.des);
256 for (idx_type i = 0; i < nargs(); ++i) {
258 cell(i).metrics(mi, cdim);
259 dim.des += max(argDim.height(), cdim.height()) + 1;
260 dim.wid = max(dim.wid, argDim.wid + cdim.wid);
263 // make space for box and markers, 2 pixels
267 metricsMarkers2(dim);
271 // calculate metrics, hoping that all cells are seen
273 expanded_.metrics(mi, dim);
275 // otherwise do a manual metrics call
276 CoordCache & coords = mi.base.bv->coordCache();
277 for (idx_type i = 0; i < nargs(); ++i) {
278 if (!coords.getArrays().hasDim(&cell(i))) {
280 cell(i).metrics(mi, tdim);
285 // calculate dimension with label while editing
286 if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
287 && editing_[mi.base.bv]) {
288 FontInfo font = mi.base.font;
289 augmentFont(font, from_ascii("lyxtex"));
291 mathed_string_dim(font, name(), namedim);
293 dim.wid += 2 + namedim.wid + 2 + 2;
294 dim.asc = max(dim.asc, namedim.asc) + 2;
295 dim.des = max(dim.des, namedim.des) + 2;
297 dim.wid = max(1 + namedim.wid + 1, 2 + dim.wid + 2);
298 dim.asc += 1 + namedim.height() + 1;
305 int MathMacro::kerning(BufferView const * bv) const {
306 if (displayMode_ == DISPLAY_NORMAL && !editing_[bv])
307 return expanded_.kerning(bv);
313 void MathMacro::updateMacro(MacroContext const & mc)
316 macro_ = mc.get(name());
317 if (macro_ && macroBackup_ != *macro_) {
318 macroBackup_ = *macro_;
327 class MathMacro::UpdateLocker
330 explicit UpdateLocker(MathMacro & mm) : mac(mm)
332 mac.isUpdating_ = true;
334 ~UpdateLocker() { mac.isUpdating_ = false; }
338 /** Avoid wrong usage of UpdateLocker.
339 To avoid wrong usage:
340 UpdateLocker(...); // wrong
341 UpdateLocker locker(...); // right
343 #define UpdateLocker(x) unnamed_UpdateLocker;
344 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
347 void MathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
350 // block recursive calls (bug 8999)
354 UpdateLocker locker(*this);
361 requires_ = macro_->requires();
364 // non-normal mode? We are done!
365 || (displayMode_ != DISPLAY_NORMAL))
368 needsUpdate_ = false;
370 // get default values of macro
371 vector<docstring> const & defaults = macro_->defaults();
373 // create MathMacroArgumentValue objects pointing to the cells of the macro
374 vector<MathData> values(nargs());
375 for (size_t i = 0; i < nargs(); ++i) {
376 ArgumentProxy * proxy;
377 if (i < defaults.size())
378 proxy = new ArgumentProxy(*this, i, defaults[i]);
380 proxy = new ArgumentProxy(*this, i);
381 values[i].insert(0, MathAtom(proxy));
383 // expanding macro with the values
384 // Only update the argument macros if anything was expanded, otherwise
385 // we would get an endless loop (bug 9140). UpdateLocker does not work
386 // in this case, since MacroData::expand() creates new MathMacro
387 // objects, so this would be a different recursion path than the one
388 // protected by UpdateLocker.
389 if (macro_->expand(values, expanded_)) {
390 if (utype == OutputUpdate && !expanded_.empty())
391 expanded_.updateMacros(cur, mc, utype);
393 // get definition for list edit mode
394 docstring const & display = macro_->display();
395 asArray(display.empty() ? macro_->definition() : display, definition_);
399 void MathMacro::draw(PainterInfo & pi, int x, int y) const
401 Dimension const dim = dimension(*pi.base.bv);
403 setPosCache(pi, x, y);
407 if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
408 FontSetChanger dummy(pi.base, "lyxtex");
409 pi.pain.text(x, y, from_ascii("\\") + name(), pi.base.font);
410 } else if (displayMode_ == DISPLAY_UNFOLDED) {
411 FontSetChanger dummy(pi.base, "lyxtex");
412 pi.pain.text(x, y, from_ascii("\\"), pi.base.font);
413 x += mathed_string_width(pi.base.font, from_ascii("\\")) + 1;
414 cell(0).draw(pi, x, y);
415 drawMarkers(pi, expx, expy);
416 } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
417 && editing_[pi.base.bv]) {
418 // Macro will be edited in a old-style list mode here:
420 CoordCache const & coords = pi.base.bv->coordCache();
421 FontInfo const & labelFont = sane_font;
423 // markers and box needs two pixels
426 // get maximal font height
428 math_font_max_dim(pi.base.font, fontDim.asc, fontDim.des);
431 docstring label = from_ascii("Macro \\") + name() + from_ascii(": ");
432 pi.pain.text(x, y, label, labelFont);
433 x += mathed_string_width(labelFont, label);
436 definition_.draw(pi, x, y);
437 Dimension const & defDim = coords.getArrays().dim(&definition_);
438 y += max(fontDim.des, defDim.des);
441 docstring str = from_ascii("#9");
442 int strw1 = mathed_string_width(labelFont, from_ascii("#9"));
443 int strw2 = mathed_string_width(labelFont, from_ascii(": "));
445 for (idx_type i = 0; i < nargs(); ++i) {
447 Dimension const & cdim = coords.getArrays().dim(&cell(i));
449 y += max(fontDim.asc, cdim.asc) + 1;
453 pi.pain.text(x, y, str, labelFont);
455 pi.pain.text(x, y, from_ascii(":"), labelFont);
459 cell(i).draw(pi, x, y);
462 y += max(fontDim.des, cdim.des);
465 pi.pain.rectangle(expx + 1, expy - dim.asc + 1, dim.wid - 3,
466 dim.height() - 2, Color_mathmacroframe);
467 drawMarkers2(pi, expx, expy);
469 bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
472 for (size_t i = 0; i < nargs(); ++i)
473 cell(i).setXY(*pi.base.bv, x, y);
475 if (drawBox && editing_[pi.base.bv]) {
476 // draw header and rectangle around
477 FontInfo font = pi.base.font;
478 augmentFont(font, from_ascii("lyxtex"));
479 font.setSize(FONT_SIZE_TINY);
480 font.setColor(Color_mathmacrolabel);
482 mathed_string_dim(font, name(), namedim);
484 pi.pain.fillRectangle(x, y - dim.asc, dim.wid, 1 + namedim.height() + 1, Color_mathmacrobg);
485 pi.pain.text(x + 1, y - dim.asc + namedim.asc + 2, name(), font);
486 expx += (dim.wid - expanded_.dimension(*pi.base.bv).width()) / 2;
489 if (editing_[pi.base.bv]) {
490 pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
491 expanded_.draw(pi, expx, expy);
492 pi.pain.leaveMonochromeMode();
495 pi.pain.rectangle(x, y - dim.asc, dim.wid,
496 dim.height(), Color_mathmacroframe);
498 expanded_.draw(pi, expx, expy);
501 drawMarkers(pi, x, y);
504 // edit mode changed?
505 if (editing_[pi.base.bv] != editMode(pi.base.bv))
506 pi.base.bv->cursor().screenUpdateFlags(Update::SinglePar);
510 void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
512 // We may have 0 arguments, but InsetMathNest requires at least one.
514 InsetMathNest::drawSelection(pi, x, y);
518 void MathMacro::setDisplayMode(MathMacro::DisplayMode mode, int appetite)
520 if (displayMode_ != mode) {
521 // transfer name if changing from or to DISPLAY_UNFOLDED
522 if (mode == DISPLAY_UNFOLDED) {
524 asArray(name_, cell(0));
525 } else if (displayMode_ == DISPLAY_UNFOLDED) {
526 name_ = asString(cell(0));
534 // the interactive init mode is non-greedy by default
536 appetite_ = (mode == DISPLAY_INTERACTIVE_INIT) ? 0 : 9;
538 appetite_ = size_t(appetite);
542 MathMacro::DisplayMode MathMacro::computeDisplayMode() const
544 if (nextFoldMode_ == true && macro_ && !macro_->locked())
545 return DISPLAY_NORMAL;
547 return DISPLAY_UNFOLDED;
551 bool MathMacro::validName() const
553 docstring n = name();
558 // converting back and force doesn't swallow anything?
561 if (asString(ma) != n)
565 for (size_t i = 0; i<n.size(); ++i) {
566 if (!(n[i] >= 'a' && n[i] <= 'z')
567 && !(n[i] >= 'A' && n[i] <= 'Z')
576 void MathMacro::validate(LaTeXFeatures & features) const
578 if (!requires_.empty())
579 features.require(requires_);
581 if (name() == "binom")
582 features.require("binom");
584 // validate the cells and the definition
585 if (displayMode() == DISPLAY_NORMAL) {
586 definition_.validate(features);
587 InsetMathNest::validate(features);
592 void MathMacro::edit(Cursor & cur, bool front, EntryDirection entry_from)
594 cur.screenUpdateFlags(Update::SinglePar);
595 InsetMathNest::edit(cur, front, entry_from);
599 Inset * MathMacro::editXY(Cursor & cur, int x, int y)
601 // We may have 0 arguments, but InsetMathNest requires at least one.
603 cur.screenUpdateFlags(Update::SinglePar);
604 return InsetMathNest::editXY(cur, x, y);
610 void MathMacro::removeArgument(Inset::pos_type pos) {
611 if (displayMode_ == DISPLAY_NORMAL) {
612 LASSERT(size_t(pos) < cells_.size(), return);
613 cells_.erase(cells_.begin() + pos);
614 if (size_t(pos) < attachedArgsNum_)
616 if (size_t(pos) < optionals_) {
625 void MathMacro::insertArgument(Inset::pos_type pos) {
626 if (displayMode_ == DISPLAY_NORMAL) {
627 LASSERT(size_t(pos) <= cells_.size(), return);
628 cells_.insert(cells_.begin() + pos, MathData());
629 if (size_t(pos) < attachedArgsNum_)
631 if (size_t(pos) < optionals_)
639 void MathMacro::detachArguments(vector<MathData> & args, bool strip)
641 LASSERT(displayMode_ == DISPLAY_NORMAL, return);
644 // strip off empty cells, but not more than arity-attachedArgsNum_
647 for (i = cells_.size(); i > attachedArgsNum_; --i)
648 if (!cell(i - 1).empty()) break;
652 attachedArgsNum_ = 0;
653 expanded_ = MathData();
660 void MathMacro::attachArguments(vector<MathData> const & args, size_t arity, int optionals)
662 LASSERT(displayMode_ == DISPLAY_NORMAL, return);
664 attachedArgsNum_ = args.size();
665 cells_.resize(arity);
666 expanded_ = MathData();
667 optionals_ = optionals;
673 bool MathMacro::idxFirst(Cursor & cur) const
675 cur.screenUpdateFlags(Update::SinglePar);
676 return InsetMathNest::idxFirst(cur);
680 bool MathMacro::idxLast(Cursor & cur) const
682 cur.screenUpdateFlags(Update::SinglePar);
683 return InsetMathNest::idxLast(cur);
687 bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur)
689 if (displayMode_ == DISPLAY_UNFOLDED) {
690 docstring const & unfolded_name = name();
691 if (unfolded_name != name_) {
692 // The macro name was changed
693 Cursor inset_cursor = old;
694 int macroSlice = inset_cursor.find(this);
695 // returning true means the cursor is "now" invalid,
697 LASSERT(macroSlice != -1, return true);
698 inset_cursor.cutOff(macroSlice);
699 inset_cursor.recordUndoInset();
701 inset_cursor.cell().erase(inset_cursor.pos());
702 inset_cursor.cell().insert(inset_cursor.pos(),
703 createInsetMath(unfolded_name, cur.buffer()));
705 cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
709 cur.screenUpdateFlags(Update::Force);
710 return InsetMathNest::notifyCursorLeaves(old, cur);
714 void MathMacro::fold(Cursor & cur)
716 if (!nextFoldMode_) {
717 nextFoldMode_ = true;
718 cur.screenUpdateFlags(Update::SinglePar);
723 void MathMacro::unfold(Cursor & cur)
726 nextFoldMode_ = false;
727 cur.screenUpdateFlags(Update::SinglePar);
732 bool MathMacro::folded() const
734 return nextFoldMode_;
738 void MathMacro::write(WriteStream & os) const
740 MathEnsurer ensurer(os, macro_ != 0, true);
743 if (displayMode_ != DISPLAY_NORMAL) {
744 os << "\\" << name();
745 if (name().size() != 1 || isAlphaASCII(name()[0]))
746 os.pendingSpace(true);
751 // we should be ok to continue even if this fails.
754 // Always protect macros in a fragile environment
758 os << "\\" << name();
761 // Optional arguments:
762 // First find last non-empty optional argument
763 idx_type emptyOptFrom = 0;
765 for (; i < cells_.size() && i < optionals_; ++i) {
766 if (!cell(i).empty())
767 emptyOptFrom = i + 1;
770 // print out optionals
771 for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
773 os << "[" << cell(i) << "]";
776 // skip the tailing empty optionals
779 // Print remaining arguments
780 for (; i < cells_.size(); ++i) {
781 if (cell(i).size() == 1
782 && cell(i)[0].nucleus()->asCharInset()
783 && isASCII(cell(i)[0].nucleus()->asCharInset()->getChar())) {
788 os << "{" << cell(i) << "}";
792 // add space if there was no argument
794 os.pendingSpace(true);
798 void MathMacro::maple(MapleStream & os) const
800 lyx::maple(expanded_, os);
804 void MathMacro::maxima(MaximaStream & os) const
806 lyx::maxima(expanded_, os);
810 void MathMacro::mathematica(MathematicaStream & os) const
812 lyx::mathematica(expanded_, os);
816 void MathMacro::mathmlize(MathStream & 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 char const * type = macro_->MathMLtype();
824 os << '<' << type << "> " << xmlname << " /<"
829 if (expanded_.empty()) {
830 // this means that we do not recognize the macro
831 throw MathExportException();
837 void MathMacro::htmlize(HtmlStream & os) const
839 // macro_ is 0 if this is an unknown macro
840 LATTEST(macro_ || displayMode_ != DISPLAY_NORMAL);
842 docstring const xmlname = macro_->xmlname();
843 if (!xmlname.empty()) {
844 os << ' ' << xmlname << ' ';
848 if (expanded_.empty()) {
849 // this means that we do not recognize the macro
850 throw MathExportException();
856 void MathMacro::octave(OctaveStream & os) const
858 lyx::octave(expanded_, os);
862 void MathMacro::infoize(odocstream & os) const
864 os << bformat(_("Macro: %1$s"), name());
868 void MathMacro::infoize2(odocstream & os) const
870 os << bformat(_("Macro: %1$s"), name());
874 bool MathMacro::completionSupported(Cursor const & cur) const
876 if (displayMode() != DISPLAY_UNFOLDED)
877 return InsetMathNest::completionSupported(cur);
879 return lyxrc.completion_popup_math
880 && displayMode() == DISPLAY_UNFOLDED
881 && cur.bv().cursor().pos() == int(name().size());
885 bool MathMacro::inlineCompletionSupported(Cursor const & cur) const
887 if (displayMode() != DISPLAY_UNFOLDED)
888 return InsetMathNest::inlineCompletionSupported(cur);
890 return lyxrc.completion_inline_math
891 && displayMode() == DISPLAY_UNFOLDED
892 && cur.bv().cursor().pos() == int(name().size());
896 bool MathMacro::automaticInlineCompletion() const
898 if (displayMode() != DISPLAY_UNFOLDED)
899 return InsetMathNest::automaticInlineCompletion();
901 return lyxrc.completion_inline_math;
905 bool MathMacro::automaticPopupCompletion() const
907 if (displayMode() != DISPLAY_UNFOLDED)
908 return InsetMathNest::automaticPopupCompletion();
910 return lyxrc.completion_popup_math;
914 CompletionList const *
915 MathMacro::createCompletionList(Cursor const & cur) const
917 if (displayMode() != DISPLAY_UNFOLDED)
918 return InsetMathNest::createCompletionList(cur);
920 return new MathCompletionList(cur.bv().cursor());
924 docstring MathMacro::completionPrefix(Cursor const & cur) const
926 if (displayMode() != DISPLAY_UNFOLDED)
927 return InsetMathNest::completionPrefix(cur);
929 if (!completionSupported(cur))
932 return "\\" + name();
936 bool MathMacro::insertCompletion(Cursor & cur, docstring const & s,
939 if (displayMode() != DISPLAY_UNFOLDED)
940 return InsetMathNest::insertCompletion(cur, s, finished);
942 if (!completionSupported(cur))
946 docstring newName = name() + s;
947 asArray(newName, cell(0));
948 cur.bv().cursor().pos() = name().size();
949 cur.screenUpdateFlags(Update::SinglePar);
953 cur.bv().cursor().pop();
954 ++cur.bv().cursor().pos();
955 cur.screenUpdateFlags(Update::SinglePar);
962 void MathMacro::completionPosAndDim(Cursor const & cur, int & x, int & y,
963 Dimension & dim) const
965 if (displayMode() != DISPLAY_UNFOLDED)
966 InsetMathNest::completionPosAndDim(cur, x, y, dim);
968 // get inset dimensions
969 dim = cur.bv().coordCache().insets().dim(this);
970 // FIXME: these 3 are no accurate, but should depend on the font.
971 // Now the popup jumps down if you enter a char with descent > 0.
977 = cur.bv().coordCache().insets().xy(this);