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 cur.recordUndoSelection();
417 // this whole function is a hack and won't work for incremental font
419 if (cur.inset().asInsetMath()->name() == font)
420 cur.handleFont(to_utf8(font));
422 handleNest(cur, createInsetMath(font), arg);
426 void InsetMathNest::handleNest(Cursor & cur, MathAtom const & nest)
428 handleNest(cur, nest, docstring());
432 void InsetMathNest::handleNest(Cursor & cur, MathAtom const & nest,
433 docstring const & arg)
435 CursorSlice i1 = cur.selBegin();
436 CursorSlice i2 = cur.selEnd();
437 if (!i1.inset().asInsetMath())
439 if (i1.idx() == i2.idx()) {
440 // the easy case where only one cell is selected
441 cur.handleNest(nest);
446 // multiple selected cells in a simple non-grid inset
447 if (i1.asInsetMath()->nrows() == 0 || i1.asInsetMath()->ncols() == 0) {
448 for (idx_type i = i1.idx(); i <= i2.idx(); ++i) {
453 cur.pos() = cur.lastpos();
456 // change font of cell
457 cur.handleNest(nest);
460 // cur is in the font inset now. If the loop continues,
461 // we need to get outside again for the next cell
462 if (i + 1 <= i2.idx())
468 // the complicated case with multiple selected cells in a grid
471 cap::region(i1, i2, r1, r2, c1, c2);
472 for (row_type row = r1; row <= r2; ++row) {
473 for (col_type col = c1; col <= c2; ++col) {
475 cur.idx() = i1.asInsetMath()->index(row, col);
478 cur.pos() = cur.lastpos();
482 cur.handleNest(nest);
485 // cur is in the font inset now. If the loop continues,
486 // we need to get outside again for the next cell
487 if (col + 1 <= c2 || row + 1 <= r2)
494 void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
496 cur.recordUndoSelection();
499 font.fromString(to_utf8(arg), b);
500 if (font.fontInfo().color() != Color_inherit &&
501 font.fontInfo().color() != Color_ignore)
502 handleNest(cur, MathAtom(new InsetMathColor(true, font.fontInfo().color())));
504 // FIXME: support other font changes here as well?
508 void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
510 //lyxerr << "InsetMathNest: request: " << cmd << endl;
512 switch (cmd.action) {
515 cur.recordUndoSelection();
516 cur.message(_("Paste"));
517 replaceSelection(cur);
519 if (cmd.argument().empty() && !theClipboard().isInternal())
520 topaste = theClipboard().getAsText();
523 idocstringstream is(cmd.argument());
525 topaste = cap::selection(n);
527 cur.niceInsert(topaste);
528 cur.clearSelection(); // bug 393
535 cutSelection(cur, true, true);
536 cur.message(_("Cut"));
537 // Prevent stale position >= size crash
538 // Probably not necessary anymore, see eraseSelection (gb 2005-10-09)
544 cur.message(_("Copy"));
547 case LFUN_MOUSE_PRESS:
548 lfunMousePress(cur, cmd);
551 case LFUN_MOUSE_MOTION:
552 lfunMouseMotion(cur, cmd);
555 case LFUN_MOUSE_RELEASE:
556 lfunMouseRelease(cur, cmd);
559 case LFUN_FINISHED_LEFT: // in math, left is backwards
560 case LFUN_FINISHED_BACKWARD:
561 cur.bv().cursor() = cur;
564 case LFUN_FINISHED_RIGHT: // in math, right is forward
565 case LFUN_FINISHED_FORWARD:
567 cur.bv().cursor() = cur;
570 case LFUN_CHAR_RIGHT:
572 case LFUN_CHAR_BACKWARD:
573 case LFUN_CHAR_FORWARD:
574 cur.updateFlags(Update::Decoration | Update::FitCursor);
575 case LFUN_CHAR_RIGHT_SELECT:
576 case LFUN_CHAR_LEFT_SELECT:
577 case LFUN_CHAR_BACKWARD_SELECT:
578 case LFUN_CHAR_FORWARD_SELECT: {
579 // are we in a selection?
580 bool select = (cmd.action == LFUN_CHAR_RIGHT_SELECT
581 || cmd.action == LFUN_CHAR_LEFT_SELECT
582 || cmd.action == LFUN_CHAR_BACKWARD_SELECT
583 || cmd.action == LFUN_CHAR_FORWARD_SELECT);
584 // are we moving forward or backwards?
585 // If the command was RIGHT or LEFT, then whether we're moving forward
586 // or backwards depends on the cursor movement mode (logical or visual):
587 // * in visual mode, since math is always LTR, right -> forward,
589 // * in logical mode, the mapping is determined by the
590 // reverseDirectionNeeded() function
593 FuncCode finish_lfun;
595 if (cmd.action == LFUN_CHAR_FORWARD
596 || cmd.action == LFUN_CHAR_FORWARD_SELECT) {
598 finish_lfun = LFUN_FINISHED_FORWARD;
600 else if (cmd.action == LFUN_CHAR_BACKWARD
601 || cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
603 finish_lfun = LFUN_FINISHED_BACKWARD;
606 bool right = (cmd.action == LFUN_CHAR_RIGHT_SELECT
607 || cmd.action == LFUN_CHAR_RIGHT);
608 if (lyxrc.visual_cursor || !reverseDirectionNeeded(cur))
614 finish_lfun = LFUN_FINISHED_RIGHT;
616 finish_lfun = LFUN_FINISHED_LEFT;
618 // Now that we know exactly what we want to do, let's do it!
619 cur.selHandle(select);
620 cur.autocorrect() = false;
622 cur.macroModeClose();
623 // try moving forward or backwards as necessary...
624 if (!(forward ? cursorMathForward(cur) : cursorMathBackward(cur))) {
625 // ... and if movement failed, then finish forward or backwards
627 cmd = FuncRequest(finish_lfun);
635 cur.updateFlags(Update::Decoration | Update::FitCursor);
636 case LFUN_DOWN_SELECT:
637 case LFUN_UP_SELECT: {
638 // close active macro
639 if (cur.inMacroMode()) {
640 cur.macroModeClose();
644 // stop/start the selection
645 bool select = cmd.action == LFUN_DOWN_SELECT ||
646 cmd.action == LFUN_UP_SELECT;
647 cur.selHandle(select);
650 bool up = cmd.action == LFUN_UP || cmd.action == LFUN_UP_SELECT;
651 bool successful = cur.upDownInMath(up);
655 if (cur.fixIfBroken())
656 // FIXME: Something bad happened. We pass the corrected Cursor
657 // instead of letting things go worse.
660 // We did not manage to move the cursor.
665 case LFUN_MOUSE_DOUBLE:
666 case LFUN_MOUSE_TRIPLE:
667 case LFUN_WORD_SELECT:
671 cur.selection() = true;
672 cur.pos() = cur.lastpos();
673 cur.idx() = cur.lastidx();
676 case LFUN_PARAGRAPH_UP:
677 case LFUN_PARAGRAPH_DOWN:
678 cur.updateFlags(Update::Decoration | Update::FitCursor);
679 case LFUN_PARAGRAPH_UP_SELECT:
680 case LFUN_PARAGRAPH_DOWN_SELECT:
683 case LFUN_LINE_BEGIN:
684 case LFUN_WORD_BACKWARD:
686 cur.updateFlags(Update::Decoration | Update::FitCursor);
687 case LFUN_LINE_BEGIN_SELECT:
688 case LFUN_WORD_BACKWARD_SELECT:
689 case LFUN_WORD_LEFT_SELECT:
690 cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
691 cmd.action == LFUN_WORD_LEFT_SELECT ||
692 cmd.action == LFUN_LINE_BEGIN_SELECT);
693 cur.macroModeClose();
694 if (cur.pos() != 0) {
696 } else if (cur.col() != 0) {
697 cur.idx() -= cur.col();
699 } else if (cur.idx() != 0) {
703 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
708 case LFUN_WORD_FORWARD:
709 case LFUN_WORD_RIGHT:
711 cur.updateFlags(Update::Decoration | Update::FitCursor);
712 case LFUN_WORD_FORWARD_SELECT:
713 case LFUN_WORD_RIGHT_SELECT:
714 case LFUN_LINE_END_SELECT:
715 cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
716 cmd.action == LFUN_WORD_RIGHT_SELECT ||
717 cmd.action == LFUN_LINE_END_SELECT);
718 cur.macroModeClose();
720 if (cur.pos() != cur.lastpos()) {
721 cur.pos() = cur.lastpos();
722 } else if (ncols() && (cur.col() != cur.lastcol())) {
723 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
724 cur.pos() = cur.lastpos();
725 } else if (cur.idx() != cur.lastidx()) {
726 cur.idx() = cur.lastidx();
727 cur.pos() = cur.lastpos();
729 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
734 case LFUN_CELL_FORWARD:
735 cur.updateFlags(Update::Decoration | Update::FitCursor);
736 cur.inset().idxNext(cur);
739 case LFUN_CELL_BACKWARD:
740 cur.updateFlags(Update::Decoration | Update::FitCursor);
741 cur.inset().idxPrev(cur);
744 case LFUN_WORD_DELETE_BACKWARD:
745 case LFUN_CHAR_DELETE_BACKWARD:
747 // May affect external cell:
748 cur.recordUndoInset();
750 cur.recordUndoSelection();
751 // if the inset can not be removed from within, delete it
752 if (!cur.backspace()) {
753 FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
754 cur.innerText()->dispatch(cur, cmd);
758 case LFUN_WORD_DELETE_FORWARD:
759 case LFUN_CHAR_DELETE_FORWARD:
760 if (cur.pos() == cur.lastpos())
761 // May affect external cell:
762 cur.recordUndoInset();
764 cur.recordUndoSelection();
765 // if the inset can not be removed from within, delete it
767 FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
768 cur.innerText()->dispatch(cur, cmd);
774 cur.clearSelection();
776 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
781 // 'Locks' the math inset. A 'locked' math inset behaves as a unit
782 // that is traversed by a single <CursorLeft>/<CursorRight>.
783 case LFUN_INSET_TOGGLE:
789 case LFUN_SELF_INSERT:
790 if (cmd.argument().size() != 1) {
791 cur.recordUndoSelection();
792 docstring const arg = cmd.argument();
793 if (!interpretString(cur, arg))
797 // Don't record undo steps if we are in macro mode and
798 // cmd.argument is the next character of the macro name.
799 // Otherwise we'll get an invalid cursor if we undo after
800 // the macro was finished and the macro is a known command,
801 // e.g. sqrt. Cursor::macroModeClose replaces in this case
802 // the InsetMathUnknown with name "frac" by an empty
803 // InsetMathFrac -> a pos value > 0 is invalid.
804 // A side effect is that an undo before the macro is finished
805 // undoes the complete macro, not only the last character.
806 if (!cur.inMacroMode())
807 cur.recordUndoSelection();
809 // spacial handling of space. If we insert an inset
810 // via macro mode, we want to put the cursor inside it
811 // if relevant. Think typing "\frac<space>".
812 if (cmd.argument()[0] == ' '
813 && cur.inMacroMode() && cur.macroName() != "\\"
814 && cur.macroModeClose()) {
815 MathAtom const atom = cur.prevAtom();
816 if (atom->asNestInset() && atom->isActive()) {
818 cur.pushBackward(*cur.nextInset());
820 } else if (!interpretChar(cur, cmd.argument()[0])) {
821 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
826 //case LFUN_SERVER_GET_XY:
827 // sprintf(dispatch_buffer, "%d %d",);
830 case LFUN_SERVER_SET_XY: {
831 lyxerr << "LFUN_SERVER_SET_XY broken!" << endl;
834 istringstream is(to_utf8(cmd.argument()));
836 cur.setScreenPos(x, y);
840 // Special casing for superscript in case of LyX handling
842 case LFUN_ACCENT_CIRCUMFLEX:
843 if (cmd.argument().empty()) {
844 // do superscript if LyX handles
846 cur.recordUndoSelection();
847 script(cur, true, grabAndEraseSelection(cur));
851 case LFUN_ACCENT_UMLAUT:
852 case LFUN_ACCENT_ACUTE:
853 case LFUN_ACCENT_GRAVE:
854 case LFUN_ACCENT_BREVE:
855 case LFUN_ACCENT_DOT:
856 case LFUN_ACCENT_MACRON:
857 case LFUN_ACCENT_CARON:
858 case LFUN_ACCENT_TILDE:
859 case LFUN_ACCENT_CEDILLA:
860 case LFUN_ACCENT_CIRCLE:
861 case LFUN_ACCENT_UNDERDOT:
862 case LFUN_ACCENT_TIE:
863 case LFUN_ACCENT_OGONEK:
864 case LFUN_ACCENT_HUNGARIAN_UMLAUT:
868 case LFUN_FONT_FREE_APPLY:
869 case LFUN_FONT_FREE_UPDATE:
870 handleFont2(cur, cmd.argument());
874 if (currentMode() == TEXT_MODE)
875 handleFont(cur, cmd.argument(), "textbf");
877 handleFont(cur, cmd.argument(), "boldsymbol");
880 if (currentMode() == TEXT_MODE)
881 handleFont(cur, cmd.argument(), "textsf");
883 handleFont(cur, cmd.argument(), "mathsf");
886 if (currentMode() == TEXT_MODE)
887 handleFont(cur, cmd.argument(), "emph");
889 handleFont(cur, cmd.argument(), "mathcal");
891 case LFUN_FONT_ROMAN:
892 if (currentMode() == TEXT_MODE)
893 handleFont(cur, cmd.argument(), "textrm");
895 handleFont(cur, cmd.argument(), "mathrm");
897 case LFUN_FONT_TYPEWRITER:
898 if (currentMode() == TEXT_MODE)
899 handleFont(cur, cmd.argument(), "texttt");
901 handleFont(cur, cmd.argument(), "mathtt");
904 handleFont(cur, cmd.argument(), "mathfrak");
907 if (currentMode() == TEXT_MODE)
908 handleFont(cur, cmd.argument(), "textit");
910 handleFont(cur, cmd.argument(), "mathit");
913 if (currentMode() == TEXT_MODE)
914 // FIXME: should be "noun"
915 handleFont(cur, cmd.argument(), "textsc");
917 handleFont(cur, cmd.argument(), "mathbb");
920 case LFUN_FONT_FREE_APPLY:
921 handleFont(cur, cmd.argument(), "textrm");
924 case LFUN_FONT_DEFAULT:
925 handleFont(cur, cmd.argument(), "textnormal");
928 case LFUN_MATH_MODE: {
930 // ignore math-mode on when already in math mode
931 if (currentMode() == Inset::MATH_MODE && cmd.argument() == "on")
933 cur.macroModeClose();
934 docstring const save_selection = grabAndEraseSelection(cur);
936 //cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv())));
937 cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox"))));
939 cur.pushBackward(*cur.nextInset());
940 cur.niceInsert(save_selection);
942 if (currentMode() == Inset::TEXT_MODE) {
943 cur.niceInsert(MathAtom(new InsetMathHull("simple")));
944 cur.message(_("create new math text environment ($...$)"));
946 handleFont(cur, cmd.argument(), "textrm");
947 cur.message(_("entered math text mode (textrm)"));
955 cur.recordUndoSelection();
960 case LFUN_MATH_MATRIX: {
966 idocstringstream is(cmd.argument());
967 is >> m >> n >> v_align >> h_align;
974 MathAtom(new InsetMathArray(from_ascii("array"), m, n, (char)v_align[0], h_align)));
978 case LFUN_MATH_DELIM: {
980 docstring rs = split(cmd.argument(), ls, ' ');
981 // Reasonable default values
987 cur.handleNest(MathAtom(new InsetMathDelim(ls, rs)));
991 case LFUN_MATH_BIGDELIM: {
992 docstring const lname = from_utf8(cmd.getArg(0));
993 docstring const ldelim = from_utf8(cmd.getArg(1));
994 docstring const rname = from_utf8(cmd.getArg(2));
995 docstring const rdelim = from_utf8(cmd.getArg(3));
996 latexkeys const * l = in_word_set(lname);
997 bool const have_l = l && l->inset == "big" &&
998 InsetMathBig::isBigInsetDelim(ldelim);
999 l = in_word_set(rname);
1000 bool const have_r = l && l->inset == "big" &&
1001 InsetMathBig::isBigInsetDelim(rdelim);
1002 // We mimic LFUN_MATH_DELIM in case we have an empty left
1003 // or right delimiter.
1004 if (have_l || have_r) {
1006 docstring const selection = grabAndEraseSelection(cur);
1009 cur.insert(MathAtom(new InsetMathBig(lname,
1011 cur.niceInsert(selection);
1013 cur.insert(MathAtom(new InsetMathBig(rname,
1016 // Don't call cur.undispatched() if we did nothing, this would
1017 // lead to infinite recursion via Text::dispatch().
1021 case LFUN_SPACE_INSERT:
1022 case LFUN_MATH_SPACE:
1023 cur.recordUndoSelection();
1024 cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
1027 case LFUN_ERT_INSERT:
1028 // interpret this as if a backslash was typed
1030 interpretChar(cur, '\\');
1033 case LFUN_MATH_SUBSCRIPT:
1034 // interpret this as if a _ was typed
1035 cur.recordUndoSelection();
1036 interpretChar(cur, '_');
1039 case LFUN_MATH_SUPERSCRIPT:
1040 // interpret this as if a ^ was typed
1041 cur.recordUndoSelection();
1042 interpretChar(cur, '^');
1045 case LFUN_MATH_MACRO_FOLD:
1046 case LFUN_MATH_MACRO_UNFOLD: {
1048 bool fold = cmd.action == LFUN_MATH_MACRO_FOLD;
1049 bool found = findMacroToFoldUnfold(it, fold);
1051 MathMacro * macro = it.nextInset()->asInsetMath()->asMacro();
1052 cur.recordUndoInset();
1061 case LFUN_QUOTE_INSERT:
1062 // interpret this as if a straight " was typed
1063 cur.recordUndoSelection();
1064 interpretChar(cur, '\"');
1067 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
1068 // handling such that "self-insert" works on "arbitrary stuff" too, and
1069 // math-insert only handles special math things like "matrix".
1070 case LFUN_MATH_INSERT: {
1071 cur.recordUndoSelection();
1072 if (cmd.argument() == "^" || cmd.argument() == "_")
1073 interpretChar(cur, cmd.argument()[0]);
1076 asArray(cmd.argument(), ar);
1077 if (ar.size() == 1 && ar[0]->asNestInset()
1078 && ar[0]->asNestInset()->nargs())
1079 handleNest(cur, ar[0]);
1081 cur.niceInsert(cmd.argument());
1086 case LFUN_DIALOG_SHOW_NEW_INSET: {
1087 docstring const & name = cmd.argument();
1089 if (name == "ref") {
1090 InsetMathRef tmp(name);
1091 data = tmp.createDialogStr(to_utf8(name));
1093 cur.bv().showDialog(to_utf8(name), data);
1097 case LFUN_INSET_INSERT: {
1099 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
1100 cur.recordUndoSelection();
1106 case LFUN_INSET_DISSOLVE:
1107 if (!asHullInset()) {
1108 cur.recordUndoInset();
1114 InsetMath::doDispatch(cur, cmd);
1120 bool InsetMathNest::findMacroToFoldUnfold(Cursor & it, bool fold) const {
1121 // look for macro to open/close, but stay in mathed
1122 for (; !it.empty(); it.pop_back()) {
1124 // go backward through the current cell
1125 Inset * inset = it.nextInset();
1126 while (inset && inset->asInsetMath()) {
1127 MathMacro * macro = inset->asInsetMath()->asMacro();
1129 // found the an macro to open/close?
1130 if (macro->folded() != fold)
1133 // Wrong folding state.
1134 // If this was the first we see in this slice, look further left,
1136 if (inset != it.nextInset())
1140 // go up if this was the left most position
1146 inset = it.nextInset();
1154 bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
1155 FuncStatus & flag) const
1157 // the font related toggles
1158 //string tc = "mathnormal";
1160 string const arg = to_utf8(cmd.argument());
1161 switch (cmd.action) {
1162 case LFUN_TABULAR_FEATURE:
1163 flag.enabled(false);
1166 case LFUN_TABULAR_FEATURE:
1167 // FIXME: check temporarily disabled
1169 char align = mathcursor::valign();
1170 if (align == '\0') {
1174 if (cmd.argument().empty()) {
1178 if (!contains("tcb", cmd.argument()[0])) {
1182 flag.setOnOff(cmd.argument()[0] == align);
1185 /// We have to handle them since 1.4 blocks all unhandled actions
1186 case LFUN_FONT_ITAL:
1187 case LFUN_FONT_BOLD:
1188 case LFUN_FONT_SANS:
1189 case LFUN_FONT_EMPH:
1190 case LFUN_FONT_TYPEWRITER:
1191 case LFUN_FONT_NOUN:
1192 case LFUN_FONT_ROMAN:
1193 case LFUN_FONT_DEFAULT:
1196 case LFUN_MATH_MUTATE:
1197 //flag.setOnOff(mathcursor::formula()->hullType() == to_utf8(cmd.argument()));
1198 flag.setOnOff(false);
1201 // we just need to be in math mode to enable that
1202 case LFUN_MATH_SIZE:
1203 case LFUN_MATH_SPACE:
1204 case LFUN_MATH_LIMITS:
1205 case LFUN_MATH_EXTERN:
1209 case LFUN_FONT_FRAK:
1210 flag.enabled(currentMode() != TEXT_MODE);
1213 case LFUN_MATH_INSERT: {
1214 bool const textarg =
1215 arg == "\\textbf" || arg == "\\textsf" ||
1216 arg == "\\textrm" || arg == "\\textmd" ||
1217 arg == "\\textit" || arg == "\\textsc" ||
1218 arg == "\\textsl" || arg == "\\textup" ||
1219 arg == "\\texttt" || arg == "\\textbb" ||
1220 arg == "\\textnormal";
1221 flag.enabled(currentMode() != TEXT_MODE || textarg);
1225 case LFUN_MATH_MATRIX:
1226 flag.enabled(currentMode() == MATH_MODE);
1229 case LFUN_INSET_INSERT: {
1230 // Don't test createMathInset_fromDialogStr(), since
1231 // getStatus is not called with a valid reference and the
1232 // dialog would not be applyable.
1233 string const name = cmd.getArg(0);
1234 flag.enabled(name == "ref");
1238 case LFUN_MATH_DELIM:
1239 case LFUN_MATH_BIGDELIM:
1240 // Don't do this with multi-cell selections
1241 flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
1244 case LFUN_MATH_MACRO_FOLD:
1245 case LFUN_MATH_MACRO_UNFOLD: {
1247 bool found = findMacroToFoldUnfold(it, cmd.action == LFUN_MATH_MACRO_FOLD);
1248 flag.enabled(found);
1252 case LFUN_SPECIALCHAR_INSERT:
1253 // FIXME: These would probably make sense in math-text mode
1254 flag.enabled(false);
1257 case LFUN_INSET_DISSOLVE:
1258 flag.enabled(!asHullInset());
1269 void InsetMathNest::edit(Cursor & cur, bool front, EntryDirection entry_from)
1272 bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_RIGHT ||
1273 (entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
1274 cur.idx() = enter_front ? 0 : cur.lastidx();
1275 cur.pos() = enter_front ? 0 : cur.lastpos();
1277 //lyxerr << "InsetMathNest::edit, cur:\n" << cur << endl;
1281 Inset * InsetMathNest::editXY(Cursor & cur, int x, int y)
1284 int dist_min = 1000000;
1285 for (idx_type i = 0, n = nargs(); i != n; ++i) {
1286 int const d = cell(i).dist(cur.bv(), x, y);
1292 MathData & ar = cell(idx_min);
1294 cur.idx() = idx_min;
1295 cur.pos() = ar.x2pos(&cur.bv(), x - ar.xo(cur.bv()));
1297 //lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
1298 if (dist_min == 0) {
1300 for (pos_type i = 0, n = ar.size(); i < n; ++i)
1301 if (ar[i]->covers(cur.bv(), x, y))
1302 return ar[i].nucleus()->editXY(cur, x, y);
1308 void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd)
1310 //lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
1311 BufferView & bv = cur.bv();
1312 bool do_selection = cmd.button() == mouse_button::button1
1313 && cmd.argument() == "region-select";
1314 bv.mouseSetCursor(cur, do_selection);
1315 if (cmd.button() == mouse_button::button1) {
1316 //lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
1317 // Update the cursor update flags as needed:
1319 // Update::Decoration: tells to update the decoration
1320 // (visual box corners that define
1322 // Update::FitCursor: adjust the screen to the cursor
1323 // position if needed
1324 // cur.result().update(): don't overwrite previously set flags.
1325 cur.updateFlags(Update::Decoration | Update::FitCursor
1326 | cur.result().update());
1327 } else if (cmd.button() == mouse_button::button2) {
1328 if (cap::selection()) {
1329 // See comment in Text::dispatch why we do this
1330 cap::copySelectionToStack();
1331 cmd = FuncRequest(LFUN_PASTE, "0");
1332 doDispatch(bv.cursor(), cmd);
1335 asArray(theSelection().get(), ar);
1336 bv.cursor().insert(ar);
1342 void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd)
1344 // only select with button 1
1345 if (cmd.button() == mouse_button::button1) {
1346 Cursor & bvcur = cur.bv().cursor();
1347 if (bvcur.anchor_.hasPart(cur)) {
1348 //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
1349 bvcur.setCursor(cur);
1350 bvcur.selection() = true;
1351 //lyxerr << "MOTION " << bvcur << endl;
1358 void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
1360 //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
1362 if (cmd.button() == mouse_button::button1) {
1363 if (!cur.selection())
1366 Cursor & bvcur = cur.bv().cursor();
1367 bvcur.selection() = true;
1376 bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
1378 //lyxerr << "interpret 2: '" << c << "'" << endl;
1379 docstring save_selection;
1380 if (c == '^' || c == '_')
1381 save_selection = grabAndEraseSelection(cur);
1386 if (cur.inMacroMode()) {
1387 docstring name = cur.macroName();
1389 /// are we currently typing '#1' or '#2' or...?
1390 if (name == "\\#") {
1393 if (n >= 1 && n <= 9)
1394 cur.insert(new MathMacroArgument(n));
1398 // do not finish macro for known * commands
1399 MathWordList const & mwl = mathedWordList();
1400 bool star_macro = c == '*'
1401 && (mwl.find(name.substr(1) + "*") != mwl.end()
1402 || cur.buffer().getMacro(name.substr(1) + "*", cur, true));
1403 if (isAlphaASCII(c) || star_macro) {
1404 cur.activeMacro()->setName(name + docstring(1, c));
1408 // handle 'special char' macros
1413 if (currentMode() == InsetMath::TEXT_MODE)
1414 cur.niceInsert(createInsetMath("textbackslash"));
1416 cur.niceInsert(createInsetMath("backslash"));
1417 } else if (c == '{') {
1419 cur.niceInsert(MathAtom(new InsetMathBrace));
1420 } else if (c == '%') {
1422 cur.niceInsert(MathAtom(new InsetMathComment));
1423 } else if (c == '#') {
1424 BOOST_ASSERT(cur.activeMacro());
1425 cur.activeMacro()->setName(name + docstring(1, c));
1428 cur.niceInsert(createInsetMath(docstring(1, c)));
1433 // One character big delimiters. The others are handled in
1434 // interpretString().
1435 latexkeys const * l = in_word_set(name.substr(1));
1436 if (name[0] == '\\' && l && l->inset == "big") {
1440 delim = from_ascii("\\{");
1443 delim = from_ascii("\\}");
1446 delim = docstring(1, c);
1449 if (InsetMathBig::isBigInsetDelim(delim)) {
1450 // name + delim ared a valid InsetMathBig.
1451 // We can't use cur.macroModeClose() because
1452 // it does not handle delim.
1453 InsetMathUnknown * p = cur.activeMacro();
1456 cur.cell().erase(cur.pos());
1457 cur.plainInsert(MathAtom(
1458 new InsetMathBig(name.substr(1), delim)));
1463 // leave macro mode and try again if necessary
1464 cur.macroModeClose();
1466 cur.niceInsert(MathAtom(new InsetMathBrace));
1468 interpretChar(cur, c);
1472 // This is annoying as one has to press <space> far too often.
1476 // leave autocorrect mode if necessary
1477 if (autocorrect() && c == ' ') {
1478 autocorrect() = false;
1483 // just clear selection on pressing the space bar
1484 if (cur.selection() && c == ' ') {
1485 cur.selection() = false;
1490 //lyxerr << "starting with macro" << endl;
1491 bool reduced = cap::reduceSelectionToOneCell(cur);
1492 if (reduced || !cur.selection()) {
1493 docstring const safe = cap::grabAndEraseSelection(cur);
1494 cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
1502 if (currentMode() == InsetMath::TEXT_MODE)
1508 if (currentMode() == InsetMath::TEXT_MODE) {
1509 // insert spaces in text mode,
1510 // but suppress direct insertion of two spaces in a row
1511 // the still allows typing '<space>a<space>' and deleting the 'a', but
1512 // it is better than nothing...
1513 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ') {
1515 // FIXME: we have to enable full redraw here because of the
1516 // visual box corners that define the inset. If we know for
1517 // sure that we stay within the same cell we can optimize for
1519 //cur.updateFlags(Update::SinglePar | Update::FitCursor);
1523 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1524 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1525 // FIXME: we have to enable full redraw here because of the
1526 // visual box corners that define the inset. If we know for
1527 // sure that we stay within the same cell we can optimize for
1529 //cur.updateFlags(Update::SinglePar | Update::FitCursor);
1533 if (cur.popForward()) {
1534 // FIXME: we have to enable full redraw here because of the
1535 // visual box corners that define the inset. If we know for
1536 // sure that we stay within the same cell we can optimize for
1538 //cur.updateFlags(Update::FitCursor);
1542 // if we are at the very end, leave the formula
1543 return cur.pos() != cur.lastpos();
1546 // These shouldn't work in text mode:
1547 if (currentMode() != InsetMath::TEXT_MODE) {
1549 script(cur, false, save_selection);
1553 script(cur, true, save_selection);
1557 cur.niceInsert(createInsetMath("sim"));
1562 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
1563 c == '%' || c == '_' || c == '^') {
1564 cur.niceInsert(createInsetMath(docstring(1, c)));
1569 // try auto-correction
1570 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1573 // no special circumstances, so insert the character without any fuss
1575 cur.autocorrect() = true;
1580 bool InsetMathNest::interpretString(Cursor & cur, docstring const & str)
1582 // Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if
1584 if (!cur.empty() && cur.pos() > 0 &&
1585 cur.cell()[cur.pos() - 1]->asUnknownInset()) {
1586 if (InsetMathBig::isBigInsetDelim(str)) {
1587 docstring prev = asString(cur.cell()[cur.pos() - 1]);
1588 if (prev[0] == '\\') {
1589 prev = prev.substr(1);
1590 latexkeys const * l = in_word_set(prev);
1591 if (l && l->inset == "big") {
1592 cur.cell()[cur.pos() - 1] =
1593 MathAtom(new InsetMathBig(prev, str));
1603 bool InsetMathNest::script(Cursor & cur, bool up)
1605 return script(cur, up, docstring());
1609 bool InsetMathNest::script(Cursor & cur, bool up,
1610 docstring const & save_selection)
1612 // Hack to get \^ and \_ working
1613 //lyxerr << "handling script: up: " << up << endl;
1614 if (cur.inMacroMode() && cur.macroName() == "\\") {
1616 cur.niceInsert(createInsetMath("mathcircumflex"));
1618 interpretChar(cur, '_');
1622 cur.macroModeClose();
1623 if (asScriptInset() && cur.idx() == 0) {
1624 // we are in a nucleus of a script inset, move to _our_ script
1625 InsetMathScript * inset = asScriptInset();
1626 //lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1628 cur.idx() = inset->idxOfScript(up);
1630 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1632 InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
1635 cur.idx() = inset->idxOfScript(up);
1636 cur.pos() = cur.lastpos();
1638 // convert the thing to our left to a scriptinset or create a new
1639 // one if in the very first position of the array
1640 if (cur.pos() == 0) {
1641 //lyxerr << "new scriptinset" << endl;
1642 cur.insert(new InsetMathScript(up));
1644 //lyxerr << "converting prev atom " << endl;
1645 cur.prevAtom() = MathAtom(new InsetMathScript(cur.prevAtom(), up));
1648 InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
1649 // See comment in MathParser.cpp for special handling of {}-bases
1655 //lyxerr << "inserting selection 1:\n" << save_selection << endl;
1656 cur.niceInsert(save_selection);
1658 //lyxerr << "inserting selection 2:\n" << save_selection << endl;
1663 bool InsetMathNest::completionSupported(Cursor const & cur) const
1665 return cur.inMacroMode();
1669 bool InsetMathNest::inlineCompletionSupported(Cursor const & cur) const
1671 return cur.inMacroMode();
1675 bool InsetMathNest::automaticInlineCompletion() const
1677 return lyxrc.completion_inline_math;
1681 bool InsetMathNest::automaticPopupCompletion() const
1683 return lyxrc.completion_popup_math;
1687 CompletionList const *
1688 InsetMathNest::createCompletionList(Cursor const & cur) const
1690 if (!cur.inMacroMode())
1693 return new MathCompletionList(cur);
1697 docstring InsetMathNest::completionPrefix(Cursor const & cur) const
1699 if (!cur.inMacroMode())
1702 return cur.activeMacro()->name();
1706 bool InsetMathNest::insertCompletion(Cursor & cur, docstring const & s,
1709 if (!cur.inMacroMode())
1712 // append completion to active macro
1713 InsetMathUnknown * inset = cur.activeMacro();
1714 inset->setName(inset->name() + s);
1719 // FIXME: this creates duplicates in the completion popup
1720 // which looks ugly. Moreover the changes the list lengths
1722 confuse the popup as well.
1723 MathCompletionList::addToFavorites(inset->name());
1725 lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, " "));
1732 void InsetMathNest::completionPosAndDim(Cursor const & cur, int & x, int & y,
1733 Dimension & dim) const
1735 Inset const * inset = cur.activeMacro();
1739 // get inset dimensions
1740 dim = cur.bv().coordCache().insets().dim(inset);
1741 // FIXME: these 3 are no accurate, but should depend on the font.
1742 // Now the popup jumps down if you enter a char with descent > 0.
1748 = cur.bv().coordCache().insets().xy(inset);
1754 bool InsetMathNest::cursorMathForward(Cursor & cur)
1756 if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
1757 cur.pushBackward(*cur.nextAtom().nucleus());
1758 cur.inset().idxFirst(cur);
1761 if (cur.posForward() || idxForward(cur))
1763 // try to pop forwards --- but don't pop out of math! leave that to
1765 int s = cur.depth() - 2;
1766 if (s >= 0 && cur[s].inset().asInsetMath())
1767 return cur.popForward();
1772 bool InsetMathNest::cursorMathBackward(Cursor & cur)
1774 if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
1776 cur.push(*cur.nextAtom().nucleus());
1777 cur.inset().idxLast(cur);
1780 if (cur.posBackward() || idxBackward(cur))
1782 // try to pop backwards --- but don't pop out of math! leave that to
1784 int s = cur.depth() - 2;
1785 if (s >= 0 && cur[s].inset().asInsetMath())
1786 return cur.popBackward();
1791 ////////////////////////////////////////////////////////////////////
1793 MathCompletionList::MathCompletionList(Cursor const & cur)
1795 // fill it with macros from the buffer
1796 MacroNameSet macros;
1797 cur.buffer().listMacroNames(macros);
1798 MacroNameSet::const_iterator it;
1799 for (it = macros.begin(); it != macros.end(); ++it) {
1800 if (cur.buffer().getMacro(*it, cur, false))
1801 locals.push_back("\\" + *it);
1803 sort(locals.begin(), locals.end());
1805 if (globals.size() > 0)
1808 // fill in global macros
1810 MacroTable::globalMacros().getMacroNames(macros);
1811 lyxerr << "Globals completion macros: ";
1812 for (it = macros.begin(); it != macros.end(); ++it) {
1813 lyxerr << "\\" + *it << " ";
1814 globals.push_back("\\" + *it);
1816 lyxerr << std::endl;
1818 // fill in global commands
1819 globals.push_back(from_ascii("\\boxed"));
1820 globals.push_back(from_ascii("\\fbox"));
1821 globals.push_back(from_ascii("\\framebox"));
1822 globals.push_back(from_ascii("\\makebox"));
1823 globals.push_back(from_ascii("\\kern"));
1824 globals.push_back(from_ascii("\\xrightarrow"));
1825 globals.push_back(from_ascii("\\xleftarrow"));
1826 globals.push_back(from_ascii("\\split"));
1827 globals.push_back(from_ascii("\\gathered"));
1828 globals.push_back(from_ascii("\\aligned"));
1829 globals.push_back(from_ascii("\\alignedat"));
1830 globals.push_back(from_ascii("\\cases"));
1831 globals.push_back(from_ascii("\\substack"));
1832 globals.push_back(from_ascii("\\subarray"));
1833 globals.push_back(from_ascii("\\array"));
1834 globals.push_back(from_ascii("\\sqrt"));
1835 globals.push_back(from_ascii("\\root"));
1836 globals.push_back(from_ascii("\\tabular"));
1837 globals.push_back(from_ascii("\\stackrel"));
1838 globals.push_back(from_ascii("\\binom"));
1839 globals.push_back(from_ascii("\\choose"));
1840 globals.push_back(from_ascii("\\brace"));
1841 globals.push_back(from_ascii("\\brack"));
1842 globals.push_back(from_ascii("\\frac"));
1843 globals.push_back(from_ascii("\\over"));
1844 globals.push_back(from_ascii("\\nicefrac"));
1845 globals.push_back(from_ascii("\\unitfrac"));
1846 globals.push_back(from_ascii("\\unitfracthree"));
1847 globals.push_back(from_ascii("\\unitone"));
1848 globals.push_back(from_ascii("\\unittwo"));
1849 globals.push_back(from_ascii("\\infer"));
1850 globals.push_back(from_ascii("\\atop"));
1851 globals.push_back(from_ascii("\\lefteqn"));
1852 globals.push_back(from_ascii("\\boldsymbol"));
1853 globals.push_back(from_ascii("\\bm"));
1854 globals.push_back(from_ascii("\\color"));
1855 globals.push_back(from_ascii("\\normalcolor"));
1856 globals.push_back(from_ascii("\\textcolor"));
1857 globals.push_back(from_ascii("\\dfrac"));
1858 globals.push_back(from_ascii("\\tfrac"));
1859 globals.push_back(from_ascii("\\dbinom"));
1860 globals.push_back(from_ascii("\\tbinom"));
1861 globals.push_back(from_ascii("\\hphantom"));
1862 globals.push_back(from_ascii("\\phantom"));
1863 globals.push_back(from_ascii("\\vphantom"));
1864 MathWordList const & words = mathedWordList();
1865 MathWordList::const_iterator it2;
1866 lyxerr << "Globals completion commands: ";
1867 for (it2 = words.begin(); it2 != words.end(); ++it2) {
1868 globals.push_back("\\" + (*it2).first);
1869 lyxerr << "\\" + (*it2).first << " ";
1871 lyxerr << std::endl;
1872 sort(globals.begin(), globals.end());
1876 MathCompletionList::~MathCompletionList()
1881 size_type MathCompletionList::size() const
1883 return locals.size() + globals.size();
1887 docstring const & MathCompletionList::data(size_t idx) const
1889 size_t lsize = locals.size();
1891 return globals[idx - lsize];
1897 std::string MathCompletionList::icon(size_t idx) const
1899 // get the latex command
1901 size_t lsize = locals.size();
1903 cmd = globals[idx - lsize];
1907 // get the icon resource name by stripping the backslash
1908 return "images/math/" + to_utf8(cmd.substr(1)) + ".png";
1911 std::vector<docstring> MathCompletionList::globals;