2 * \file InsetMathNest.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathNest.h"
15 #include "InsetMathArray.h"
16 #include "InsetMathBig.h"
17 #include "InsetMathBox.h"
18 #include "InsetMathBrace.h"
19 #include "InsetMathColor.h"
20 #include "InsetMathComment.h"
21 #include "InsetMathDelim.h"
22 #include "InsetMathHull.h"
23 #include "InsetMathRef.h"
24 #include "InsetMathScript.h"
25 #include "InsetMathSpace.h"
26 #include "InsetMathSymbol.h"
27 #include "InsetMathUnknown.h"
28 #include "MathCompletionList.h"
30 #include "MathFactory.h"
31 #include "MathMacro.h"
32 #include "MathMacroArgument.h"
33 #include "MathParser.h"
34 #include "MathStream.h"
35 #include "MathSupport.h"
39 #include "BufferView.h"
40 #include "CoordCache.h"
42 #include "CutAndPaste.h"
43 #include "DispatchResult.h"
44 #include "FuncRequest.h"
45 #include "FuncStatus.h"
48 #include "OutputParams.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Painter.h"
53 #include "frontends/Selection.h"
55 #include "support/debug.h"
56 #include "support/gettext.h"
57 #include "support/lstrings.h"
58 #include "support/textutils.h"
59 #include "support/docstream.h"
65 using namespace lyx::support;
69 using cap::copySelection;
70 using cap::grabAndEraseSelection;
71 using cap::cutSelection;
72 using cap::replaceSelection;
73 using cap::selClearOrDel;
76 InsetMathNest::InsetMathNest(idx_type nargs)
77 : cells_(nargs), lock_(false), mouse_hover_(false)
81 InsetMathNest::InsetMathNest(InsetMathNest const & inset)
82 : InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_),
87 InsetMathNest & InsetMathNest::operator=(InsetMathNest const & inset)
89 cells_ = inset.cells_;
92 InsetMath::operator=(inset);
97 InsetMath::idx_type InsetMathNest::nargs() const
103 void InsetMathNest::cursorPos(BufferView const & bv,
104 CursorSlice const & sl, bool /*boundary*/,
105 int & x, int & y) const
107 // FIXME: This is a hack. Ideally, the coord cache should not store
108 // absolute positions, but relative ones. This would mean to call
109 // setXY() not in MathData::draw(), but in the parent insets' draw()
110 // with the correctly adjusted x,y values. But this means that we'd have
111 // to touch all (math)inset's draw() methods. Right now, we'll store
112 // absolute value, and make them here relative, only to make them
113 // absolute again when actually drawing the cursor. What a mess.
114 BOOST_ASSERT(&sl.inset() == this);
115 MathData const & ar = sl.cell();
116 CoordCache const & coord_cache = bv.coordCache();
117 if (!coord_cache.getArrays().has(&ar)) {
118 // this can (semi-)legally happen if we just created this cell
119 // and it never has been drawn before. So don't ASSERT.
120 //lyxerr << "no cached data for array " << &ar << endl;
125 Point const pt = coord_cache.getArrays().xy(&ar);
126 if (!coord_cache.getInsets().has(this)) {
128 //lyxerr << "no cached data for inset " << this << endl;
133 Point const pt2 = coord_cache.getInsets().xy(this);
134 //lyxerr << "retrieving position cache for MathData "
135 // << pt.x_ << ' ' << pt.y_ << endl;
136 x = pt.x_ - pt2.x_ + ar.pos2x(&bv, sl.pos());
138 // lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
139 // << " asc: " << ascent() << " des: " << descent()
140 // << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl;
141 // move cursor visually into empty cells ("blue rectangles");
147 void InsetMathNest::metrics(MetricsInfo const & mi) const
150 for (idx_type i = 0, n = nargs(); i != n; ++i) {
152 cell(i).metrics(m, dim);
157 bool InsetMathNest::idxNext(Cursor & cur) const
159 BOOST_ASSERT(&cur.inset() == this);
160 if (cur.idx() == cur.lastidx())
168 bool InsetMathNest::idxForward(Cursor & cur) const
174 bool InsetMathNest::idxPrev(Cursor & cur) const
176 BOOST_ASSERT(&cur.inset() == this);
180 cur.pos() = cur.lastpos();
185 bool InsetMathNest::idxBackward(Cursor & cur) const
191 bool InsetMathNest::idxFirst(Cursor & cur) const
193 BOOST_ASSERT(&cur.inset() == this);
202 bool InsetMathNest::idxLast(Cursor & cur) const
204 BOOST_ASSERT(&cur.inset() == this);
207 cur.idx() = cur.lastidx();
208 cur.pos() = cur.lastpos();
213 void InsetMathNest::dump() const
215 odocstringstream oss;
217 os << "---------------------------------------------\n";
220 for (idx_type i = 0, n = nargs(); i != n; ++i)
221 os << cell(i) << "\n";
222 os << "---------------------------------------------\n";
223 lyxerr << to_utf8(oss.str());
227 void InsetMathNest::draw(PainterInfo & pi, int x, int y) const
231 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
234 setPosCache(pi, x, y);
238 void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
240 BufferView & bv = *pi.base.bv;
241 // this should use the x/y values given, not the cached values
242 Cursor & cur = bv.cursor();
243 if (!cur.selection())
245 if (&cur.inset() != this)
248 // FIXME: hack to get position cache warm
249 bool const original_drawing_state = pi.pain.isDrawingEnabled();
250 pi.pain.setDrawingEnabled(false);
252 pi.pain.setDrawingEnabled(original_drawing_state);
254 CursorSlice s1 = cur.selBegin();
255 CursorSlice s2 = cur.selEnd();
257 //lyxerr << "InsetMathNest::drawing selection: "
258 // << " s1: " << s1 << " s2: " << s2 << endl;
259 if (s1.idx() == s2.idx()) {
260 MathData const & c = cell(s1.idx());
261 Geometry const & g = bv.coordCache().getArrays().geometry(&c);
262 int x1 = g.pos.x_ + c.pos2x(pi.base.bv, s1.pos());
263 int y1 = g.pos.y_ - g.dim.ascent();
264 int x2 = g.pos.x_ + c.pos2x(pi.base.bv, s2.pos());
265 int y2 = g.pos.y_ + g.dim.descent();
266 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection);
267 //lyxerr << "InsetMathNest::drawing selection 3: "
268 // << " x1: " << x1 << " x2: " << x2
269 // << " y1: " << y1 << " y2: " << y2 << endl;
271 for (idx_type i = 0; i < nargs(); ++i) {
272 if (idxBetween(i, s1.idx(), s2.idx())) {
273 MathData const & c = cell(i);
274 Geometry const & g = bv.coordCache().getArrays().geometry(&c);
276 int y1 = g.pos.y_ - g.dim.ascent();
277 int x2 = g.pos.x_ + g.dim.width();
278 int y2 = g.pos.y_ + g.dim.descent();
279 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection);
286 void InsetMathNest::validate(LaTeXFeatures & features) const
288 for (idx_type i = 0; i < nargs(); ++i)
289 cell(i).validate(features);
293 void InsetMathNest::replace(ReplaceData & rep)
295 for (idx_type i = 0; i < nargs(); ++i)
296 cell(i).replace(rep);
300 bool InsetMathNest::contains(MathData const & ar) const
302 for (idx_type i = 0; i < nargs(); ++i)
303 if (cell(i).contains(ar))
309 bool InsetMathNest::lock() const
315 void InsetMathNest::lock(bool l)
321 bool InsetMathNest::isActive() const
327 MathData InsetMathNest::glue() const
330 for (size_t i = 0; i < nargs(); ++i)
336 void InsetMathNest::write(WriteStream & os) const
338 os << '\\' << name().c_str();
339 for (size_t i = 0; i < nargs(); ++i)
340 os << '{' << cell(i) << '}';
342 os.pendingSpace(true);
343 if (lock_ && !os.latex()) {
345 os.pendingSpace(true);
350 void InsetMathNest::normalize(NormalStream & os) const
352 os << '[' << name().c_str();
353 for (size_t i = 0; i < nargs(); ++i)
354 os << ' ' << cell(i);
359 int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
361 WriteStream wi(os, runparams.moving_arg, true);
367 bool InsetMathNest::setMouseHover(bool mouse_hover)
369 mouse_hover_ = mouse_hover;
374 bool InsetMathNest::notifyCursorLeaves(Cursor const & /*old*/, Cursor & /*cur*/)
378 MathData & ar = cur.cell();
379 // remove base-only "scripts"
380 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
381 InsetMathScript * p = operator[](i).nucleus()->asScriptInset();
382 if (p && p->nargs() == 1) {
383 MathData ar = p->nuc();
386 cur.adjust(i, ar.size() - 1);
390 // glue adjacent font insets of the same kind
391 for (pos_type i = 0; i + 1 < size(); ++i) {
392 InsetMathFont * p = operator[](i).nucleus()->asFontInset();
393 InsetMathFont const * q = operator[](i + 1)->asFontInset();
394 if (p && q && p->name() == q->name()) {
395 p->cell(0).append(q->cell(0));
405 void InsetMathNest::handleFont
406 (Cursor & cur, docstring const & arg, char const * const font)
408 handleFont(cur, arg, from_ascii(font));
412 void InsetMathNest::handleFont(Cursor & cur, docstring const & arg,
413 docstring const & font)
415 // this whole function is a hack and won't work for incremental font
418 if (cur.inset().asInsetMath()->name() == font) {
419 cur.recordUndoInset();
420 cur.handleFont(to_utf8(font));
422 handleNest(cur, createInsetMath(font), arg);
427 void InsetMathNest::handleNest(Cursor & cur, MathAtom const & nest)
429 handleNest(cur, nest, docstring());
433 void InsetMathNest::handleNest(Cursor & cur, MathAtom const & nest,
434 docstring const & arg)
436 CursorSlice i1 = cur.selBegin();
437 CursorSlice i2 = cur.selEnd();
438 if (!i1.inset().asInsetMath())
440 if (i1.idx() == i2.idx()) {
441 // the easy case where only one cell is selected
443 cur.handleNest(nest);
448 // multiple selected cells in a simple non-grid inset
449 if (i1.asInsetMath()->nrows() == 0 || i1.asInsetMath()->ncols() == 0) {
450 cur.recordUndoInset();
451 for (idx_type i = i1.idx(); i <= i2.idx(); ++i) {
456 cur.pos() = cur.lastpos();
459 // change font of cell
460 cur.handleNest(nest);
463 // cur is in the font inset now. If the loop continues,
464 // we need to get outside again for the next cell
465 if (i + 1 <= i2.idx())
471 // the complicated case with multiple selected cells in a grid
472 cur.recordUndoInset();
475 cap::region(i1, i2, r1, r2, c1, c2);
476 for (row_type row = r1; row <= r2; ++row) {
477 for (col_type col = c1; col <= c2; ++col) {
479 cur.idx() = i1.asInsetMath()->index(row, col);
482 cur.pos() = cur.lastpos();
486 cur.handleNest(nest);
489 // cur is in the font inset now. If the loop continues,
490 // we need to get outside again for the next cell
491 if (col + 1 <= c2 || row + 1 <= r2)
498 void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
503 font.fromString(to_utf8(arg), b);
504 if (font.fontInfo().color() != Color_inherit &&
505 font.fontInfo().color() != Color_ignore)
506 handleNest(cur, MathAtom(new InsetMathColor(true, font.fontInfo().color())));
508 // FIXME: support other font changes here as well?
512 void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
514 //lyxerr << "InsetMathNest: request: " << cmd << endl;
516 switch (cmd.action) {
519 cur.recordUndoSelection();
520 cur.message(_("Paste"));
521 replaceSelection(cur);
523 if (cmd.argument().empty() && !theClipboard().isInternal())
524 topaste = theClipboard().getAsText();
527 idocstringstream is(cmd.argument());
529 topaste = cap::selection(n);
531 cur.niceInsert(topaste);
532 cur.clearSelection(); // bug 393
539 cutSelection(cur, true, true);
540 cur.message(_("Cut"));
541 // Prevent stale position >= size crash
542 // Probably not necessary anymore, see eraseSelection (gb 2005-10-09)
548 cur.message(_("Copy"));
551 case LFUN_MOUSE_PRESS:
552 lfunMousePress(cur, cmd);
555 case LFUN_MOUSE_MOTION:
556 lfunMouseMotion(cur, cmd);
559 case LFUN_MOUSE_RELEASE:
560 lfunMouseRelease(cur, cmd);
563 case LFUN_FINISHED_LEFT: // in math, left is backwards
564 case LFUN_FINISHED_BACKWARD:
565 cur.bv().cursor() = cur;
568 case LFUN_FINISHED_RIGHT: // in math, right is forward
569 case LFUN_FINISHED_FORWARD:
571 cur.bv().cursor() = cur;
574 case LFUN_CHAR_RIGHT:
576 case LFUN_CHAR_BACKWARD:
577 case LFUN_CHAR_FORWARD:
578 cur.updateFlags(Update::Decoration | Update::FitCursor);
579 case LFUN_CHAR_RIGHT_SELECT:
580 case LFUN_CHAR_LEFT_SELECT:
581 case LFUN_CHAR_BACKWARD_SELECT:
582 case LFUN_CHAR_FORWARD_SELECT: {
583 // are we in a selection?
584 bool select = (cmd.action == LFUN_CHAR_RIGHT_SELECT
585 || cmd.action == LFUN_CHAR_LEFT_SELECT
586 || cmd.action == LFUN_CHAR_BACKWARD_SELECT
587 || cmd.action == LFUN_CHAR_FORWARD_SELECT);
588 // are we moving forward or backwards?
589 // If the command was RIGHT or LEFT, then whether we're moving forward
590 // or backwards depends on the cursor movement mode (logical or visual):
591 // * in visual mode, since math is always LTR, right -> forward,
593 // * in logical mode, the mapping is determined by the
594 // reverseDirectionNeeded() function
597 FuncCode finish_lfun;
599 if (cmd.action == LFUN_CHAR_FORWARD
600 || cmd.action == LFUN_CHAR_FORWARD_SELECT) {
602 finish_lfun = LFUN_FINISHED_FORWARD;
604 else if (cmd.action == LFUN_CHAR_BACKWARD
605 || cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
607 finish_lfun = LFUN_FINISHED_BACKWARD;
610 bool right = (cmd.action == LFUN_CHAR_RIGHT_SELECT
611 || cmd.action == LFUN_CHAR_RIGHT);
612 if (lyxrc.visual_cursor || !reverseDirectionNeeded(cur))
618 finish_lfun = LFUN_FINISHED_RIGHT;
620 finish_lfun = LFUN_FINISHED_LEFT;
622 // Now that we know exactly what we want to do, let's do it!
623 cur.selHandle(select);
624 cur.autocorrect() = false;
626 cur.macroModeClose();
627 // try moving forward or backwards as necessary...
628 if (!(forward ? cursorMathForward(cur) : cursorMathBackward(cur))) {
629 // ... and if movement failed, then finish forward or backwards
631 cmd = FuncRequest(finish_lfun);
639 cur.updateFlags(Update::Decoration | Update::FitCursor);
640 case LFUN_DOWN_SELECT:
641 case LFUN_UP_SELECT: {
642 // close active macro
643 if (cur.inMacroMode()) {
644 cur.macroModeClose();
648 // stop/start the selection
649 bool select = cmd.action == LFUN_DOWN_SELECT ||
650 cmd.action == LFUN_UP_SELECT;
651 cur.selHandle(select);
654 bool up = cmd.action == LFUN_UP || cmd.action == LFUN_UP_SELECT;
655 bool successful = cur.upDownInMath(up);
659 if (cur.fixIfBroken())
660 // FIXME: Something bad happened. We pass the corrected Cursor
661 // instead of letting things go worse.
664 // We did not manage to move the cursor.
669 case LFUN_MOUSE_DOUBLE:
670 case LFUN_MOUSE_TRIPLE:
671 case LFUN_WORD_SELECT:
675 cur.selection() = true;
676 cur.pos() = cur.lastpos();
677 cur.idx() = cur.lastidx();
680 case LFUN_PARAGRAPH_UP:
681 case LFUN_PARAGRAPH_DOWN:
682 cur.updateFlags(Update::Decoration | Update::FitCursor);
683 case LFUN_PARAGRAPH_UP_SELECT:
684 case LFUN_PARAGRAPH_DOWN_SELECT:
687 case LFUN_LINE_BEGIN:
688 case LFUN_WORD_BACKWARD:
690 cur.updateFlags(Update::Decoration | Update::FitCursor);
691 case LFUN_LINE_BEGIN_SELECT:
692 case LFUN_WORD_BACKWARD_SELECT:
693 case LFUN_WORD_LEFT_SELECT:
694 cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
695 cmd.action == LFUN_WORD_LEFT_SELECT ||
696 cmd.action == LFUN_LINE_BEGIN_SELECT);
697 cur.macroModeClose();
698 if (cur.pos() != 0) {
700 } else if (cur.col() != 0) {
701 cur.idx() -= cur.col();
703 } else if (cur.idx() != 0) {
707 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
712 case LFUN_WORD_FORWARD:
713 case LFUN_WORD_RIGHT:
715 cur.updateFlags(Update::Decoration | Update::FitCursor);
716 case LFUN_WORD_FORWARD_SELECT:
717 case LFUN_WORD_RIGHT_SELECT:
718 case LFUN_LINE_END_SELECT:
719 cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
720 cmd.action == LFUN_WORD_RIGHT_SELECT ||
721 cmd.action == LFUN_LINE_END_SELECT);
722 cur.macroModeClose();
724 if (cur.pos() != cur.lastpos()) {
725 cur.pos() = cur.lastpos();
726 } else if (ncols() && (cur.col() != cur.lastcol())) {
727 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
728 cur.pos() = cur.lastpos();
729 } else if (cur.idx() != cur.lastidx()) {
730 cur.idx() = cur.lastidx();
731 cur.pos() = cur.lastpos();
733 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
738 case LFUN_CELL_FORWARD:
739 cur.updateFlags(Update::Decoration | Update::FitCursor);
740 cur.inset().idxNext(cur);
743 case LFUN_CELL_BACKWARD:
744 cur.updateFlags(Update::Decoration | Update::FitCursor);
745 cur.inset().idxPrev(cur);
748 case LFUN_WORD_DELETE_BACKWARD:
749 case LFUN_CHAR_DELETE_BACKWARD:
751 // May affect external cell:
752 cur.recordUndoInset();
754 cur.recordUndoSelection();
755 // if the inset can not be removed from within, delete it
756 if (!cur.backspace()) {
757 FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
758 cur.innerText()->dispatch(cur, cmd);
762 case LFUN_WORD_DELETE_FORWARD:
763 case LFUN_CHAR_DELETE_FORWARD:
764 if (cur.pos() == cur.lastpos())
765 // May affect external cell:
766 cur.recordUndoInset();
768 cur.recordUndoSelection();
769 // if the inset can not be removed from within, delete it
771 FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
772 cur.innerText()->dispatch(cur, cmd);
778 cur.clearSelection();
780 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
785 // 'Locks' the math inset. A 'locked' math inset behaves as a unit
786 // that is traversed by a single <CursorLeft>/<CursorRight>.
787 case LFUN_INSET_TOGGLE:
793 case LFUN_SELF_INSERT:
794 if (cmd.argument().size() != 1) {
795 cur.recordUndoSelection();
796 docstring const arg = cmd.argument();
797 if (!interpretString(cur, arg))
801 // Don't record undo steps if we are in macro mode and
802 // cmd.argument is the next character of the macro name.
803 // Otherwise we'll get an invalid cursor if we undo after
804 // the macro was finished and the macro is a known command,
805 // e.g. sqrt. Cursor::macroModeClose replaces in this case
806 // the InsetMathUnknown with name "frac" by an empty
807 // InsetMathFrac -> a pos value > 0 is invalid.
808 // A side effect is that an undo before the macro is finished
809 // undoes the complete macro, not only the last character.
810 if (!cur.inMacroMode())
811 cur.recordUndoSelection();
813 // spacial handling of space. If we insert an inset
814 // via macro mode, we want to put the cursor inside it
815 // if relevant. Think typing "\frac<space>".
816 if (cmd.argument()[0] == ' '
817 && cur.inMacroMode() && cur.macroName() != "\\"
818 && cur.macroModeClose()) {
819 MathAtom const atom = cur.prevAtom();
820 if (atom->asNestInset() && atom->isActive()) {
822 cur.pushBackward(*cur.nextInset());
824 } else if (!interpretChar(cur, cmd.argument()[0])) {
825 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
830 //case LFUN_SERVER_GET_XY:
831 // sprintf(dispatch_buffer, "%d %d",);
834 case LFUN_SERVER_SET_XY: {
835 lyxerr << "LFUN_SERVER_SET_XY broken!" << endl;
838 istringstream is(to_utf8(cmd.argument()));
840 cur.setScreenPos(x, y);
844 // Special casing for superscript in case of LyX handling
846 case LFUN_ACCENT_CIRCUMFLEX:
847 if (cmd.argument().empty()) {
848 // do superscript if LyX handles
850 cur.recordUndoSelection();
851 script(cur, true, grabAndEraseSelection(cur));
855 case LFUN_ACCENT_UMLAUT:
856 case LFUN_ACCENT_ACUTE:
857 case LFUN_ACCENT_GRAVE:
858 case LFUN_ACCENT_BREVE:
859 case LFUN_ACCENT_DOT:
860 case LFUN_ACCENT_MACRON:
861 case LFUN_ACCENT_CARON:
862 case LFUN_ACCENT_TILDE:
863 case LFUN_ACCENT_CEDILLA:
864 case LFUN_ACCENT_CIRCLE:
865 case LFUN_ACCENT_UNDERDOT:
866 case LFUN_ACCENT_TIE:
867 case LFUN_ACCENT_OGONEK:
868 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
872 case LFUN_FONT_FREE_APPLY:
873 case LFUN_FONT_FREE_UPDATE:
874 handleFont2(cur, cmd.argument());
878 if (currentMode() == TEXT_MODE)
879 handleFont(cur, cmd.argument(), "textbf");
881 handleFont(cur, cmd.argument(), "boldsymbol");
884 if (currentMode() == TEXT_MODE)
885 handleFont(cur, cmd.argument(), "textsf");
887 handleFont(cur, cmd.argument(), "mathsf");
890 if (currentMode() == TEXT_MODE)
891 handleFont(cur, cmd.argument(), "emph");
893 handleFont(cur, cmd.argument(), "mathcal");
895 case LFUN_FONT_ROMAN:
896 if (currentMode() == TEXT_MODE)
897 handleFont(cur, cmd.argument(), "textrm");
899 handleFont(cur, cmd.argument(), "mathrm");
901 case LFUN_FONT_TYPEWRITER:
902 if (currentMode() == TEXT_MODE)
903 handleFont(cur, cmd.argument(), "texttt");
905 handleFont(cur, cmd.argument(), "mathtt");
908 handleFont(cur, cmd.argument(), "mathfrak");
911 if (currentMode() == TEXT_MODE)
912 handleFont(cur, cmd.argument(), "textit");
914 handleFont(cur, cmd.argument(), "mathit");
917 if (currentMode() == TEXT_MODE)
918 // FIXME: should be "noun"
919 handleFont(cur, cmd.argument(), "textsc");
921 handleFont(cur, cmd.argument(), "mathbb");
924 case LFUN_FONT_FREE_APPLY:
925 handleFont(cur, cmd.argument(), "textrm");
928 case LFUN_FONT_DEFAULT:
929 handleFont(cur, cmd.argument(), "textnormal");
932 case LFUN_MATH_MODE: {
934 // ignore math-mode on when already in math mode
935 if (currentMode() == Inset::MATH_MODE && cmd.argument() == "on")
937 cur.macroModeClose();
938 docstring const save_selection = grabAndEraseSelection(cur);
940 //cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv())));
941 cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox"))));
943 cur.pushBackward(*cur.nextInset());
944 cur.niceInsert(save_selection);
946 if (currentMode() == Inset::TEXT_MODE) {
947 cur.niceInsert(MathAtom(new InsetMathHull("simple")));
948 cur.message(_("create new math text environment ($...$)"));
950 handleFont(cur, cmd.argument(), "textrm");
951 cur.message(_("entered math text mode (textrm)"));
959 cur.recordUndoSelection();
964 case LFUN_MATH_MATRIX: {
970 idocstringstream is(cmd.argument());
971 is >> m >> n >> v_align >> h_align;
978 MathAtom(new InsetMathArray(from_ascii("array"), m, n, (char)v_align[0], h_align)));
982 case LFUN_MATH_DELIM: {
984 docstring rs = split(cmd.argument(), ls, ' ');
985 // Reasonable default values
991 cur.handleNest(MathAtom(new InsetMathDelim(ls, rs)));
995 case LFUN_MATH_BIGDELIM: {
996 docstring const lname = from_utf8(cmd.getArg(0));
997 docstring const ldelim = from_utf8(cmd.getArg(1));
998 docstring const rname = from_utf8(cmd.getArg(2));
999 docstring const rdelim = from_utf8(cmd.getArg(3));
1000 latexkeys const * l = in_word_set(lname);
1001 bool const have_l = l && l->inset == "big" &&
1002 InsetMathBig::isBigInsetDelim(ldelim);
1003 l = in_word_set(rname);
1004 bool const have_r = l && l->inset == "big" &&
1005 InsetMathBig::isBigInsetDelim(rdelim);
1006 // We mimic LFUN_MATH_DELIM in case we have an empty left
1007 // or right delimiter.
1008 if (have_l || have_r) {
1010 docstring const selection = grabAndEraseSelection(cur);
1013 cur.insert(MathAtom(new InsetMathBig(lname,
1015 cur.niceInsert(selection);
1017 cur.insert(MathAtom(new InsetMathBig(rname,
1020 // Don't call cur.undispatched() if we did nothing, this would
1021 // lead to infinite recursion via Text::dispatch().
1025 case LFUN_SPACE_INSERT:
1026 case LFUN_MATH_SPACE:
1027 cur.recordUndoSelection();
1028 cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
1031 case LFUN_ERT_INSERT:
1032 // interpret this as if a backslash was typed
1034 interpretChar(cur, '\\');
1037 case LFUN_MATH_SUBSCRIPT:
1038 // interpret this as if a _ was typed
1039 cur.recordUndoSelection();
1040 interpretChar(cur, '_');
1043 case LFUN_MATH_SUPERSCRIPT:
1044 // interpret this as if a ^ was typed
1045 cur.recordUndoSelection();
1046 interpretChar(cur, '^');
1049 case LFUN_MATH_MACRO_FOLD:
1050 case LFUN_MATH_MACRO_UNFOLD: {
1052 bool fold = cmd.action == LFUN_MATH_MACRO_FOLD;
1053 bool found = findMacroToFoldUnfold(it, fold);
1055 MathMacro * macro = it.nextInset()->asInsetMath()->asMacro();
1056 cur.recordUndoInset();
1065 case LFUN_QUOTE_INSERT:
1066 // interpret this as if a straight " was typed
1067 cur.recordUndoSelection();
1068 interpretChar(cur, '\"');
1071 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
1072 // handling such that "self-insert" works on "arbitrary stuff" too, and
1073 // math-insert only handles special math things like "matrix".
1074 case LFUN_MATH_INSERT: {
1075 cur.recordUndoSelection();
1076 if (cmd.argument() == "^" || cmd.argument() == "_") {
1077 interpretChar(cur, cmd.argument()[0]);
1079 cur.niceInsert(cmd.argument());
1083 case LFUN_DIALOG_SHOW_NEW_INSET: {
1084 docstring const & name = cmd.argument();
1086 if (name == "ref") {
1087 InsetMathRef tmp(name);
1088 data = tmp.createDialogStr(to_utf8(name));
1090 cur.bv().showDialog(to_utf8(name), data);
1094 case LFUN_INSET_INSERT: {
1096 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
1097 cur.recordUndoSelection();
1103 case LFUN_INSET_DISSOLVE:
1104 if (!asHullInset()) {
1105 cur.recordUndoInset();
1111 InsetMath::doDispatch(cur, cmd);
1117 bool InsetMathNest::findMacroToFoldUnfold(Cursor & it, bool fold) const {
1118 // look for macro to open/close, but stay in mathed
1119 for (; !it.empty(); it.pop_back()) {
1121 // go backward through the current cell
1122 Inset * inset = it.nextInset();
1123 while (inset && inset->asInsetMath()) {
1124 MathMacro * macro = inset->asInsetMath()->asMacro();
1126 // found the an macro to open/close?
1127 if (macro->folded() != fold)
1130 // Wrong folding state.
1131 // If this was the first we see in this slice, look further left,
1133 if (inset != it.nextInset())
1137 // go up if this was the left most position
1143 inset = it.nextInset();
1151 bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
1152 FuncStatus & flag) const
1154 // the font related toggles
1155 //string tc = "mathnormal";
1157 string const arg = to_utf8(cmd.argument());
1158 switch (cmd.action) {
1159 case LFUN_TABULAR_FEATURE:
1160 flag.enabled(false);
1163 case LFUN_TABULAR_FEATURE:
1164 // FIXME: check temporarily disabled
1166 char align = mathcursor::valign();
1167 if (align == '\0') {
1171 if (cmd.argument().empty()) {
1175 if (!contains("tcb", cmd.argument()[0])) {
1179 flag.setOnOff(cmd.argument()[0] == align);
1182 /// We have to handle them since 1.4 blocks all unhandled actions
1183 case LFUN_FONT_ITAL:
1184 case LFUN_FONT_BOLD:
1185 case LFUN_FONT_SANS:
1186 case LFUN_FONT_EMPH:
1187 case LFUN_FONT_TYPEWRITER:
1188 case LFUN_FONT_NOUN:
1189 case LFUN_FONT_ROMAN:
1190 case LFUN_FONT_DEFAULT:
1193 case LFUN_MATH_MUTATE:
1194 //flag.setOnOff(mathcursor::formula()->hullType() == to_utf8(cmd.argument()));
1195 flag.setOnOff(false);
1198 // we just need to be in math mode to enable that
1199 case LFUN_MATH_SIZE:
1200 case LFUN_MATH_SPACE:
1201 case LFUN_MATH_LIMITS:
1202 case LFUN_MATH_EXTERN:
1206 case LFUN_FONT_FRAK:
1207 flag.enabled(currentMode() != TEXT_MODE);
1210 case LFUN_MATH_INSERT: {
1211 bool const textarg =
1212 arg == "\\textbf" || arg == "\\textsf" ||
1213 arg == "\\textrm" || arg == "\\textmd" ||
1214 arg == "\\textit" || arg == "\\textsc" ||
1215 arg == "\\textsl" || arg == "\\textup" ||
1216 arg == "\\texttt" || arg == "\\textbb" ||
1217 arg == "\\textnormal";
1218 flag.enabled(currentMode() != TEXT_MODE || textarg);
1222 case LFUN_MATH_MATRIX:
1223 flag.enabled(currentMode() == MATH_MODE);
1226 case LFUN_INSET_INSERT: {
1227 // Don't test createMathInset_fromDialogStr(), since
1228 // getStatus is not called with a valid reference and the
1229 // dialog would not be applyable.
1230 string const name = cmd.getArg(0);
1231 flag.enabled(name == "ref");
1235 case LFUN_MATH_DELIM:
1236 case LFUN_MATH_BIGDELIM:
1237 // Don't do this with multi-cell selections
1238 flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
1241 case LFUN_MATH_MACRO_FOLD:
1242 case LFUN_MATH_MACRO_UNFOLD: {
1244 bool found = findMacroToFoldUnfold(it, cmd.action == LFUN_MATH_MACRO_FOLD);
1245 flag.enabled(found);
1249 case LFUN_SPECIALCHAR_INSERT:
1250 // FIXME: These would probably make sense in math-text mode
1251 flag.enabled(false);
1254 case LFUN_INSET_DISSOLVE:
1255 flag.enabled(!asHullInset());
1266 void InsetMathNest::edit(Cursor & cur, bool front, EntryDirection entry_from)
1269 bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_RIGHT ||
1270 (entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
1271 cur.idx() = enter_front ? 0 : cur.lastidx();
1272 cur.pos() = enter_front ? 0 : cur.lastpos();
1274 //lyxerr << "InsetMathNest::edit, cur:\n" << cur << endl;
1278 Inset * InsetMathNest::editXY(Cursor & cur, int x, int y)
1281 int dist_min = 1000000;
1282 for (idx_type i = 0, n = nargs(); i != n; ++i) {
1283 int const d = cell(i).dist(cur.bv(), x, y);
1289 MathData & ar = cell(idx_min);
1291 cur.idx() = idx_min;
1292 cur.pos() = ar.x2pos(&cur.bv(), x - ar.xo(cur.bv()));
1294 //lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
1295 if (dist_min == 0) {
1297 for (pos_type i = 0, n = ar.size(); i < n; ++i)
1298 if (ar[i]->covers(cur.bv(), x, y))
1299 return ar[i].nucleus()->editXY(cur, x, y);
1305 void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd)
1307 //lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
1308 BufferView & bv = cur.bv();
1309 bool do_selection = cmd.button() == mouse_button::button1
1310 && cmd.argument() == "region-select";
1311 bv.mouseSetCursor(cur, do_selection);
1312 if (cmd.button() == mouse_button::button1) {
1313 //lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
1314 // Update the cursor update flags as needed:
1316 // Update::Decoration: tells to update the decoration
1317 // (visual box corners that define
1319 // Update::FitCursor: adjust the screen to the cursor
1320 // position if needed
1321 // cur.result().update(): don't overwrite previously set flags.
1322 cur.updateFlags(Update::Decoration | Update::FitCursor
1323 | cur.result().update());
1324 } else if (cmd.button() == mouse_button::button2) {
1325 if (cap::selection()) {
1326 // See comment in Text::dispatch why we do this
1327 cap::copySelectionToStack();
1328 cmd = FuncRequest(LFUN_PASTE, "0");
1329 doDispatch(bv.cursor(), cmd);
1332 asArray(theSelection().get(), ar);
1333 bv.cursor().insert(ar);
1339 void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd)
1341 // only select with button 1
1342 if (cmd.button() == mouse_button::button1) {
1343 Cursor & bvcur = cur.bv().cursor();
1344 if (bvcur.anchor_.hasPart(cur)) {
1345 //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
1346 bvcur.setCursor(cur);
1347 bvcur.selection() = true;
1348 //lyxerr << "MOTION " << bvcur << endl;
1355 void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
1357 //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
1359 if (cmd.button() == mouse_button::button1) {
1360 if (!cur.selection())
1363 Cursor & bvcur = cur.bv().cursor();
1364 bvcur.selection() = true;
1373 bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
1375 //lyxerr << "interpret 2: '" << c << "'" << endl;
1376 docstring save_selection;
1377 if (c == '^' || c == '_')
1378 save_selection = grabAndEraseSelection(cur);
1383 if (cur.inMacroMode()) {
1384 docstring name = cur.macroName();
1386 /// are we currently typing '#1' or '#2' or...?
1387 if (name == "\\#") {
1390 if (n >= 1 && n <= 9)
1391 cur.insert(new MathMacroArgument(n));
1395 // do not finish macro for known * commands
1396 MathWordList const & mwl = mathedWordList();
1397 bool star_macro = c == '*'
1398 && (mwl.find(name.substr(1) + "*") != mwl.end()
1399 || cur.buffer().getMacro(name.substr(1) + "*", cur, true));
1400 if (isAlphaASCII(c) || star_macro) {
1401 cur.activeMacro()->setName(name + docstring(1, c));
1405 // handle 'special char' macros
1410 if (currentMode() == InsetMath::TEXT_MODE)
1411 cur.niceInsert(createInsetMath("textbackslash"));
1413 cur.niceInsert(createInsetMath("backslash"));
1414 } else if (c == '{') {
1416 cur.niceInsert(MathAtom(new InsetMathBrace));
1417 } else if (c == '%') {
1419 cur.niceInsert(MathAtom(new InsetMathComment));
1420 } else if (c == '#') {
1421 BOOST_ASSERT(cur.activeMacro());
1422 cur.activeMacro()->setName(name + docstring(1, c));
1425 cur.niceInsert(createInsetMath(docstring(1, c)));
1430 // One character big delimiters. The others are handled in
1431 // interpretString().
1432 latexkeys const * l = in_word_set(name.substr(1));
1433 if (name[0] == '\\' && l && l->inset == "big") {
1437 delim = from_ascii("\\{");
1440 delim = from_ascii("\\}");
1443 delim = docstring(1, c);
1446 if (InsetMathBig::isBigInsetDelim(delim)) {
1447 // name + delim ared a valid InsetMathBig.
1448 // We can't use cur.macroModeClose() because
1449 // it does not handle delim.
1450 InsetMathUnknown * p = cur.activeMacro();
1453 cur.cell().erase(cur.pos());
1454 cur.plainInsert(MathAtom(
1455 new InsetMathBig(name.substr(1), delim)));
1460 // leave macro mode and try again if necessary
1461 cur.macroModeClose();
1463 cur.niceInsert(MathAtom(new InsetMathBrace));
1465 interpretChar(cur, c);
1469 // This is annoying as one has to press <space> far too often.
1473 // leave autocorrect mode if necessary
1474 if (autocorrect() && c == ' ') {
1475 autocorrect() = false;
1480 // just clear selection on pressing the space bar
1481 if (cur.selection() && c == ' ') {
1482 cur.selection() = false;
1487 //lyxerr << "starting with macro" << endl;
1488 bool reduced = cap::reduceSelectionToOneCell(cur);
1489 if (reduced || !cur.selection()) {
1490 docstring const safe = cap::grabAndEraseSelection(cur);
1491 cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
1499 if (currentMode() == InsetMath::TEXT_MODE)
1505 if (currentMode() == InsetMath::TEXT_MODE) {
1506 // insert spaces in text mode,
1507 // but suppress direct insertion of two spaces in a row
1508 // the still allows typing '<space>a<space>' and deleting the 'a', but
1509 // it is better than nothing...
1510 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ') {
1512 // FIXME: we have to enable full redraw here because of the
1513 // visual box corners that define the inset. If we know for
1514 // sure that we stay within the same cell we can optimize for
1516 //cur.updateFlags(Update::SinglePar | Update::FitCursor);
1520 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1521 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1522 // FIXME: we have to enable full redraw here because of the
1523 // visual box corners that define the inset. If we know for
1524 // sure that we stay within the same cell we can optimize for
1526 //cur.updateFlags(Update::SinglePar | Update::FitCursor);
1530 if (cur.popForward()) {
1531 // FIXME: we have to enable full redraw here because of the
1532 // visual box corners that define the inset. If we know for
1533 // sure that we stay within the same cell we can optimize for
1535 //cur.updateFlags(Update::FitCursor);
1539 // if we are at the very end, leave the formula
1540 return cur.pos() != cur.lastpos();
1543 // These shouldn't work in text mode:
1544 if (currentMode() != InsetMath::TEXT_MODE) {
1546 script(cur, false, save_selection);
1550 script(cur, true, save_selection);
1554 cur.niceInsert(createInsetMath("sim"));
1559 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
1560 c == '%' || c == '_' || c == '^') {
1561 cur.niceInsert(createInsetMath(docstring(1, c)));
1566 // try auto-correction
1567 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1570 // no special circumstances, so insert the character without any fuss
1572 cur.autocorrect() = true;
1577 bool InsetMathNest::interpretString(Cursor & cur, docstring const & str)
1579 // Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if
1581 if (!cur.empty() && cur.pos() > 0 &&
1582 cur.cell()[cur.pos() - 1]->asUnknownInset()) {
1583 if (InsetMathBig::isBigInsetDelim(str)) {
1584 docstring prev = asString(cur.cell()[cur.pos() - 1]);
1585 if (prev[0] == '\\') {
1586 prev = prev.substr(1);
1587 latexkeys const * l = in_word_set(prev);
1588 if (l && l->inset == "big") {
1589 cur.cell()[cur.pos() - 1] =
1590 MathAtom(new InsetMathBig(prev, str));
1600 bool InsetMathNest::script(Cursor & cur, bool up)
1602 return script(cur, up, docstring());
1606 bool InsetMathNest::script(Cursor & cur, bool up,
1607 docstring const & save_selection)
1609 // Hack to get \^ and \_ working
1610 //lyxerr << "handling script: up: " << up << endl;
1611 if (cur.inMacroMode() && cur.macroName() == "\\") {
1613 cur.niceInsert(createInsetMath("mathcircumflex"));
1615 interpretChar(cur, '_');
1619 cur.macroModeClose();
1620 if (asScriptInset() && cur.idx() == 0) {
1621 // we are in a nucleus of a script inset, move to _our_ script
1622 InsetMathScript * inset = asScriptInset();
1623 //lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1625 cur.idx() = inset->idxOfScript(up);
1627 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1629 InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
1632 cur.idx() = inset->idxOfScript(up);
1633 cur.pos() = cur.lastpos();
1635 // convert the thing to our left to a scriptinset or create a new
1636 // one if in the very first position of the array
1637 if (cur.pos() == 0) {
1638 //lyxerr << "new scriptinset" << endl;
1639 cur.insert(new InsetMathScript(up));
1641 //lyxerr << "converting prev atom " << endl;
1642 cur.prevAtom() = MathAtom(new InsetMathScript(cur.prevAtom(), up));
1645 InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
1646 // See comment in MathParser.cpp for special handling of {}-bases
1652 //lyxerr << "inserting selection 1:\n" << save_selection << endl;
1653 cur.niceInsert(save_selection);
1655 //lyxerr << "inserting selection 2:\n" << save_selection << endl;
1660 bool InsetMathNest::completionSupported(Cursor const & cur) const
1662 return cur.inMacroMode();
1666 bool InsetMathNest::inlineCompletionSupported(Cursor const & cur) const
1668 return cur.inMacroMode();
1672 bool InsetMathNest::automaticInlineCompletion() const
1674 return lyxrc.completion_inline_math;
1678 bool InsetMathNest::automaticPopupCompletion() const
1680 return lyxrc.completion_popup_math;
1684 CompletionList const *
1685 InsetMathNest::createCompletionList(Cursor const & cur) const
1687 if (!cur.inMacroMode())
1690 return new MathCompletionList(cur);
1694 docstring InsetMathNest::completionPrefix(Cursor const & cur) const
1696 if (!cur.inMacroMode())
1699 return cur.activeMacro()->name();
1703 bool InsetMathNest::insertCompletion(Cursor & cur, docstring const & s,
1706 if (!cur.inMacroMode())
1709 // append completion to active macro
1710 InsetMathUnknown * inset = cur.activeMacro();
1711 inset->setName(inset->name() + s);
1716 // FIXME: this creates duplicates in the completion popup
1717 // which looks ugly. Moreover the changes the list lengths
1719 confuse the popup as well.
1720 MathCompletionList::addToFavorites(inset->name());
1722 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, " "));
1729 void InsetMathNest::completionPosAndDim(Cursor const & cur, int & x, int & y,
1730 Dimension & dim) const
1732 Inset const * inset = cur.activeMacro();
1736 // get inset dimensions
1737 dim = cur.bv().coordCache().insets().dim(inset);
1738 // FIXME: these 3 are no accurate, but should depend on the font.
1739 // Now the popup jumps down if you enter a char with descent > 0.
1745 = cur.bv().coordCache().insets().xy(inset);
1751 bool InsetMathNest::cursorMathForward(Cursor & cur)
1753 if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
1754 cur.pushBackward(*cur.nextAtom().nucleus());
1755 cur.inset().idxFirst(cur);
1758 if (cur.posForward() || idxForward(cur) || cur.selection())
1760 // try to pop forwards --- but don't pop out of math! leave that to
1762 int s = cur.depth() - 2;
1763 if (s >= 0 && cur[s].inset().asInsetMath())
1764 return cur.popForward();
1769 bool InsetMathNest::cursorMathBackward(Cursor & cur)
1771 if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
1773 cur.push(*cur.nextAtom().nucleus());
1774 cur.inset().idxLast(cur);
1777 if (cur.posBackward() || idxBackward(cur) || cur.selection())
1779 // try to pop backwards --- but don't pop out of math! leave that to
1781 int s = cur.depth() - 2;
1782 if (s >= 0 && cur[s].inset().asInsetMath())
1783 return cur.popBackward();
1788 ////////////////////////////////////////////////////////////////////
1790 MathCompletionList::MathCompletionList(Cursor const & cur)
1792 // fill it with macros from the buffer
1793 MacroNameSet macros;
1794 cur.buffer().listMacroNames(macros);
1795 MacroNameSet::const_iterator it;
1796 for (it = macros.begin(); it != macros.end(); ++it) {
1797 if (cur.buffer().getMacro(*it, cur, false))
1798 locals.push_back("\\" + *it);
1800 sort(locals.begin(), locals.end());
1802 if (globals.size() > 0)
1805 // fill in global macros
1807 MacroTable::globalMacros().getMacroNames(macros);
1808 lyxerr << "Globals completion macros: ";
1809 for (it = macros.begin(); it != macros.end(); ++it) {
1810 lyxerr << "\\" + *it << " ";
1811 globals.push_back("\\" + *it);
1813 lyxerr << std::endl;
1815 // fill in global commands
1816 globals.push_back(from_ascii("\\boxed"));
1817 globals.push_back(from_ascii("\\fbox"));
1818 globals.push_back(from_ascii("\\framebox"));
1819 globals.push_back(from_ascii("\\makebox"));
1820 globals.push_back(from_ascii("\\kern"));
1821 globals.push_back(from_ascii("\\xrightarrow"));
1822 globals.push_back(from_ascii("\\xleftarrow"));
1823 globals.push_back(from_ascii("\\split"));
1824 globals.push_back(from_ascii("\\gathered"));
1825 globals.push_back(from_ascii("\\aligned"));
1826 globals.push_back(from_ascii("\\alignedat"));
1827 globals.push_back(from_ascii("\\cases"));
1828 globals.push_back(from_ascii("\\substack"));
1829 globals.push_back(from_ascii("\\subarray"));
1830 globals.push_back(from_ascii("\\array"));
1831 globals.push_back(from_ascii("\\sqrt"));
1832 globals.push_back(from_ascii("\\root"));
1833 globals.push_back(from_ascii("\\tabular"));
1834 globals.push_back(from_ascii("\\stackrel"));
1835 globals.push_back(from_ascii("\\binom"));
1836 globals.push_back(from_ascii("\\choose"));
1837 globals.push_back(from_ascii("\\choose"));
1838 globals.push_back(from_ascii("\\frac"));
1839 globals.push_back(from_ascii("\\over"));
1840 globals.push_back(from_ascii("\\nicefrac"));
1841 globals.push_back(from_ascii("\\unitfrac"));
1842 globals.push_back(from_ascii("\\unitfracthree"));
1843 globals.push_back(from_ascii("\\unitone"));
1844 globals.push_back(from_ascii("\\unittwo"));
1845 globals.push_back(from_ascii("\\infer"));
1846 globals.push_back(from_ascii("\\atop"));
1847 globals.push_back(from_ascii("\\lefteqn"));
1848 globals.push_back(from_ascii("\\boldsymbol"));
1849 globals.push_back(from_ascii("\\bm"));
1850 globals.push_back(from_ascii("\\color"));
1851 globals.push_back(from_ascii("\\normalcolor"));
1852 globals.push_back(from_ascii("\\textcolor"));
1853 globals.push_back(from_ascii("\\dfrac"));
1854 globals.push_back(from_ascii("\\tfrac"));
1855 globals.push_back(from_ascii("\\dbinom"));
1856 globals.push_back(from_ascii("\\tbinom"));
1857 globals.push_back(from_ascii("\\hphantom"));
1858 globals.push_back(from_ascii("\\phantom"));
1859 globals.push_back(from_ascii("\\vphantom"));
1860 MathWordList const & words = mathedWordList();
1861 MathWordList::const_iterator it2;
1862 lyxerr << "Globals completion commands: ";
1863 for (it2 = words.begin(); it2 != words.end(); ++it2) {
1864 globals.push_back("\\" + (*it2).first);
1865 lyxerr << "\\" + (*it2).first << " ";
1867 lyxerr << std::endl;
1868 sort(globals.begin(), globals.end());
1872 MathCompletionList::~MathCompletionList()
1877 size_type MathCompletionList::size() const
1879 return locals.size() + globals.size();
1883 docstring const & MathCompletionList::data(size_t idx) const
1885 size_t lsize = locals.size();
1887 return globals[idx - lsize];
1893 std::string MathCompletionList::icon(size_t idx) const
1895 // get the latex command
1897 size_t lsize = locals.size();
1899 cmd = globals[idx - lsize];
1903 // get the icon resource name by stripping the backslash
1904 return "images/math/" + to_utf8(cmd.substr(1)) + ".png";
1907 std::vector<docstring> MathCompletionList::globals;