3 * Purpose: Implementation of formula inset
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Allows the edition of math paragraphs inside Lyx.
8 * Copyright: 1996-1998 Alejandro Aguilar Sierra
10 * Version: 0.4, Lyx project.
12 * You are free to use and modify this code under the terms of
13 * the GNU General Public Licence version 2 or later.
21 #pragma implementation "formula.h"
25 #include "commandtags.h"
26 #include "math_cursor.h"
27 #include "math_parser.h"
29 #include "minibuffer.h"
30 #include "BufferView.h"
33 #include "LaTeXFeatures.h"
35 #include "lyx_gui_misc.h"
36 #include "support/LOstream.h"
40 #include "support/lyxlib.h"
49 //extern char * mathed_label;
50 extern string mathed_label;
52 extern char const * latex_special_chars;
54 int greek_kb_flag = 0;
56 LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_fonts (Lgb)
58 static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
65 MathedCursor * InsetFormula::mathcursor = 0;
68 int MathedInset::df_asc;
69 int MathedInset::df_des;
70 int MathedInset::df_width;
74 bool IsMacro(short token, int id)
76 return (token != LM_TK_FRAC && token != LM_TK_SQRT &&
77 !((token == LM_TK_SYM || token == LM_TC_BSYM) && id < 255));
82 void mathedValidate(LaTeXFeatures & features, MathParInset * par);
85 LyXFont WhichFont(short type, int size)
115 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
125 f.setSize(lfont_size);
129 if (type == LM_TC_BSYM) {
139 case LM_ST_SCRIPTSCRIPT:
144 lyxerr << "Mathed Error: wrong font size: " << size << endl;
148 if (type != LM_TC_TEXTRM)
149 f.setColor(LColor::math);
154 void mathed_init_fonts() //removed 'static' because DEC cxx does not
156 // Probably because this func is declared as a friend in math_defs.h
160 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
162 for (int i = 0 ; i < 8 ; ++i) {
163 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
165 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
167 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
169 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
170 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
172 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
174 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
175 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
177 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
179 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
181 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
183 LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
184 MathedInset::df_asc = lyxfont::maxAscent(f);
185 MathedInset::df_des = lyxfont::maxDescent(f);
186 MathedInset::df_width = lyxfont::width('I', f);
190 LyXFont mathed_get_font(short type, int size)
192 LyXFont f = WhichFont(type, size);
193 if (type == LM_TC_TEX) {
194 f.setLatex(LyXFont::ON);
200 int mathed_string_width(short type, int size, byte const * s, int ls)
202 LyXFont f = WhichFont(type, size);
205 if (MathIsBinary(type)) {
207 for (int i = 0; i < ls && i < 75; ++i) {
216 return lyxfont::width(reinterpret_cast<char const *>(s), ls, f);
219 int mathed_string_width(short type, int size, string const & str)
221 return mathed_string_width(type, size, reinterpret_cast<unsigned char const *>(str.c_str()), str.length());
225 int mathed_char_width(short type, int size, byte c)
227 int t = (MathIsBinary(type)) ? mathed_string_width(type, size, &c, 1) :
228 lyxfont::width(c, WhichFont(type, size));
233 int mathed_string_height(short type, int size, byte const * s,
234 int ls, int & asc, int & des)
236 LyXFont font = WhichFont(type, size);
238 for (int i = 0; i < ls; ++i) {
239 des = max(des, lyxfont::descent(s[i], font));
240 asc = max(asc, lyxfont::ascent(s[i], font));
246 int mathed_string_height(short type, int size, string const & str,
247 int & asc, int & des)
249 return mathed_string_height(type, size,
250 reinterpret_cast<unsigned char const *>(str.c_str()), str.length(),
255 int mathed_char_height(short type, int size, byte c, int & asc, int & des)
257 LyXFont font = WhichFont(type, size);
258 des = lyxfont::descent(c, font);
259 asc = lyxfont::ascent(c, font);
264 // In a near future maybe we use a better fonts renderer
265 void MathedInset::drawStr(Painter & pain, short type, int siz,
266 int x, int y, byte const * s, int ls)
269 if (MathIsBinary(type)) {
270 for (int i = 0; i < ls; ++i) {
271 st += string(" ") + char(s[i]) + ' ';
274 st = string(reinterpret_cast<char const *>(s), ls);
276 LyXFont const mf = mathed_get_font(type, siz);
277 pain.text(x, y, st, mf);
281 InsetFormula::InsetFormula(bool display)
283 par = new MathParInset; // this leaks
288 par->SetType(LM_OT_PAR);
289 par->SetStyle(LM_ST_DISPLAY);
294 InsetFormula::InsetFormula(MathParInset * p)
296 par = (p->GetType()>= LM_OT_MPAR) ?
297 new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
301 disp_flag = (par->GetType()>0);
306 InsetFormula::~InsetFormula()
312 Inset * InsetFormula::Clone() const
314 InsetFormula * f = new InsetFormula(par);
320 void InsetFormula::Write(Buffer const * buf, ostream & os) const
323 Latex(buf, os, false, false);
327 int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
330 //#warning Alejandro, the number of lines is not returned in this case
331 // This problem will disapear at 0.13.
332 mathed_write(par, os, &ret, fragile, label);
337 int InsetFormula::Ascii(Buffer const *, ostream & os, int) const
339 par->Write(os, false);
344 int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const
346 return Ascii(buf, os, 0);
350 int InsetFormula::DocBook(Buffer const * buf, ostream & os) const
352 return Ascii(buf, os, 0);
356 // Check if uses AMS macros
357 void InsetFormula::Validate(LaTeXFeatures & features) const
359 // Validation only necesary if not using an AMS Style
360 if (!features.amsstyle)
361 mathedValidate(features, par);
365 void InsetFormula::Read(Buffer const *, LyXLex & lex)
367 istream & is = lex.getStream();
369 mathed_parser_file(is, lex.GetLineNo());
371 // Silly hack to read labels.
373 mathed_label.erase();
375 mathed_parse(0, 0, &par);
377 disp_flag = (par->GetType() > 0);
379 // Update line number
380 lex.setLineNo(mathed_parser_lineno());
382 //if (mathed_label) {
383 if (!mathed_label.empty()) {
384 label = mathed_label;
386 mathed_label.erase();
389 // reading of end_inset in the inset!!!
392 if (lex.GetString() == "\\end_inset")
394 lyxerr << "InsetFormula::Read: Garbage before \\end_inset,"
395 " or missing \\end_inset!" << endl;
404 int InsetFormula::ascent(BufferView *, LyXFont const &) const
406 return par->Ascent() + ((disp_flag) ? 8 : 1);
410 int InsetFormula::descent(BufferView *, LyXFont const &) const
412 return par->Descent() + ((disp_flag) ? 8 : 1);
416 int InsetFormula::width(BufferView *, LyXFont const & f) const
418 lfont_size = f.size();
420 return par->Width(); //+2;
424 void InsetFormula::draw(BufferView * bv, LyXFont const & f,
425 int baseline, float & x, bool) const
427 Painter & pain = bv->painter();
428 // Seems commenting out solves a problem.
429 LyXFont font = mathed_get_font(LM_TC_TEXTRM, LM_ST_TEXT);
430 font.setSize(f.size());
431 lfont_size = font.size();
432 /// Let's try to wait a bit with this... (Lgb)
433 //UpdatableInset::draw(pain, font, baseline, x);
435 // otherwise a segfault could occur
436 // in some XDrawRectangles (i.e. matrix) (Matthias)
437 if (mathcursor && mathcursor->GetPar() == par) {
438 if (mathcursor->Selection()) {
442 mathcursor->SelGetArea(&xp, &yp, n);
443 pain.fillPolygon(xp, yp, n, LColor::selection);
445 mathcursor->draw(pain, int(x), baseline);
447 par->draw(pain, int(x), baseline);
449 x += float(width(bv, font));
451 if (par->GetType() == LM_OT_PARN || par->GetType() == LM_OT_MPARN) {
452 LyXFont wfont = WhichFont(LM_TC_BF, par->size);
453 wfont.setLatex(LyXFont::OFF);
455 if (par->GetType() == LM_OT_PARN) {
458 str = string("(") + label + ")";
461 pain.text(int(x + 20), baseline, str, wfont);
462 } else if (par->GetType() == LM_OT_MPARN) {
463 MathMatrixInset * mt =
464 static_cast<MathMatrixInset*>(par);
466 MathedRowSt const * crow = mt->getRowSt();
468 y = baseline + crow->getBaseline();
469 if (crow->isNumbered()) {
471 if (!crow->getLabel().empty())
472 str = string("(") + crow->getLabel() + ")";
475 pain.text(int(x + 20), y, str, wfont);
477 crow = crow->getNext();
481 cursor_visible = false;
485 string const InsetFormula::EditMessage() const
487 return _("Math editor mode");
491 void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
493 mathcursor = new MathedCursor(par);
494 if (!bv->lockInset(this))
495 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
497 bv->updateInset(this, false);
500 mathcursor->SetPos(x, y);
506 void InsetFormula::InsetUnlock(BufferView * bv)
509 if (mathcursor->InMacroMode()) {
510 mathcursor->MacroModeClose();
516 bv->updateInset(this, false);
520 // Now a symbol can be inserted only if the inset is locked
521 void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
523 if (s.empty() || !mathcursor) return;
524 mathcursor->Interpret(s);
529 void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const
531 mathcursor->GetPos(x, y);
537 void InsetFormula::ToggleInsetCursor(BufferView * bv)
544 mathcursor->GetPos(x, y);
547 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
548 int asc = lyxfont::maxAscent(font);
549 int desc = lyxfont::maxDescent(font);
552 bv->hideLockedInsetCursor();
554 bv->showLockedInsetCursor(x, y, asc, desc);
555 cursor_visible = !cursor_visible;
559 void InsetFormula::ShowInsetCursor(BufferView * bv)
561 if (!cursor_visible) {
565 mathcursor->GetPos(x, y);
568 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
569 int asc = lyxfont::maxAscent(font);
570 int desc = lyxfont::maxDescent(font);
571 bv->fitLockedInsetCursor(x, y, asc, desc);
573 ToggleInsetCursor(bv);
578 void InsetFormula::HideInsetCursor(BufferView * bv)
581 ToggleInsetCursor(bv);
585 void InsetFormula::ToggleInsetSelection(BufferView * bv)
593 //mathcursor->SelGetArea(n);
594 // XFillPolygon(fl_display, pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin);
598 bv->updateInset(this, false);
603 void InsetFormula::display(bool dspf)
605 if (dspf != disp_flag) {
607 par->SetType(LM_OT_PAR);
608 par->SetStyle(LM_ST_DISPLAY);
610 if (par->GetType() >= LM_OT_MPAR) {
611 MathParInset * p = new MathParInset(par);
615 mathcursor->SetPar(par);
617 par->SetType(LM_OT_MIN);
618 par->SetStyle(LM_ST_TEXT);
619 if (!label.empty() && par->GetType() != LM_OT_MPARN) {
628 vector<string> const InsetFormula::getLabelList() const
630 //#warning This is dirty, I know. Ill clean it at 0.11
631 // Correction, the only way to clean this is with a new kernel: 0.13.
633 vector<string> label_list;
635 if (par->GetType() == LM_OT_MPARN) {
636 MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
637 MathedRowSt const * crow = mt->getRowSt();
639 if (!crow->getLabel().empty())
640 label_list.push_back(crow->getLabel());
641 crow = crow->getNext();
643 } else if (!label.empty())
644 label_list.push_back(label);
650 void InsetFormula::UpdateLocal(BufferView * bv)
652 par->Metrics(); // To inform lyx kernel the exact size
653 // (there were problems with arrays).
654 bv->updateInset(this, true);
658 void InsetFormula::InsetButtonRelease(BufferView * bv,
659 int x, int y, int /*button*/)
665 mathcursor->SetPos(x, y);
670 bv->updateInset(this, false);
676 void InsetFormula::InsetButtonPress(BufferView * bv,
677 int x, int y, int /*button*/)
680 sel_x = x; sel_y = y;
681 if (mathcursor && mathcursor->Selection()) {
682 mathcursor->SelClear();
683 bv->updateInset(this, false);
688 void InsetFormula::InsetMotionNotify(BufferView * bv,
689 int x, int y, int /*button*/)
691 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
694 mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo);
695 mathcursor->SelStart();
697 mathcursor->GetPos(sel_x, sel_y);
698 } else if (sel_flag) {
702 mathcursor->SetPos(x, y);
704 mathcursor->GetPos(x, y);
705 if (sel_x!= x || sel_y!= y)
706 bv->updateInset(this, false);
707 sel_x = x; sel_y = y;
712 void InsetFormula::InsetKeyPress(XKeyEvent *)
714 lyxerr[Debug::MATHED] << "Used InsetFormula::InsetKeyPress." << endl;
718 // Special Mathed functions
719 bool InsetFormula::SetNumber(bool numbf)
722 short type = par->GetType();
723 bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
724 if (numbf && !oldf) ++type;
725 if (!numbf && oldf) --type;
733 UpdatableInset::RESULT
734 InsetFormula::LocalDispatch(BufferView * bv,
735 int action, string const & arg)
737 // extern char *dispatch_result;
738 MathedTextCodes varcode = LM_TC_MIN;
739 bool was_macro = mathcursor->InMacroMode();
741 bool space_on = false;
742 bool was_selection = mathcursor->Selection();
743 RESULT result = DISPATCHED;
744 static MathSpaceInset * sp= 0;
748 if (mathcursor->getLastCode() == LM_TC_TEX) {
753 // --- Cursor Movements ---------------------------------------------
754 case LFUN_RIGHTSEL: sel = true;
757 result = DISPATCH_RESULT(mathcursor->Right(sel));
758 if (!sel && (result == DISPATCHED))
759 result = DISPATCHED_NOUPDATE;
762 case LFUN_LEFTSEL: sel = true;
765 result = DISPATCH_RESULT(mathcursor->Left(sel));
766 if (!sel && (result == DISPATCHED))
767 result = DISPATCHED_NOUPDATE;
770 case LFUN_UPSEL: sel = true;
772 result = DISPATCH_RESULT(mathcursor->Up(sel));
773 if (!sel && (result == DISPATCHED))
774 result = DISPATCHED_NOUPDATE;
777 case LFUN_DOWNSEL: sel = true;
779 result = DISPATCH_RESULT(mathcursor->Down(sel));
780 if (!sel && (result == DISPATCHED))
781 result = DISPATCHED_NOUPDATE;
785 result = DISPATCHED_NOUPDATE;
789 result = DISPATCHED_NOUPDATE;
791 case LFUN_DELETE_LINE_FORWARD:
792 //current_view->lockedInsetStoreUndo(Undo::INSERT);
793 bv->lockedInsetStoreUndo(Undo::DELETE);
794 mathcursor->DelLine();
798 bv->lockedInsetStoreUndo(Undo::INSERT);
799 mathcursor->Insert(' ', LM_TC_CR);
800 par = mathcursor->GetPar();
804 bv->lockedInsetStoreUndo(Undo::INSERT);
805 mathcursor->Insert(0, LM_TC_TAB);
809 bv->lockedInsetStoreUndo(Undo::INSERT);
810 mathcursor->Insert('T', LM_TC_TAB);
814 if (!mathcursor->Left())
817 if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
818 bv->updateInset(this, true);
823 //current_view->lockedInsetStoreUndo(Undo::INSERT);
824 bv->lockedInsetStoreUndo(Undo::DELETE);
825 mathcursor->Delete();
826 bv->updateInset(this, true);
829 // sprintf(dispatch_buffer, "%d %d",);
830 // dispatch_result = dispatch_buffer;
838 istringstream ist(arg.c_str());
841 mathcursor->SetPos(x1 + x, y1 + y);
845 /* cursor selection ---------------------------- */
849 mathcursor->MacroModeClose();
850 bv->lockedInsetStoreUndo(Undo::INSERT);
851 mathcursor->SelPaste(); UpdateLocal(bv); break;
853 bv->lockedInsetStoreUndo(Undo::DELETE);
854 mathcursor->SelCut(); UpdateLocal(bv); break;
855 case LFUN_COPY: mathcursor->SelCopy(); break;
858 case LFUN_WORDRIGHTSEL:
859 case LFUN_WORDLEFTSEL:
862 // --- accented characters ------------------------------
864 case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
865 case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
866 case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
867 case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
868 case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
869 case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
870 case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
871 case LFUN_CARON: mathcursor->setAccent(LM_check); break;
872 case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
873 case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
878 if (!greek_kb_flag) {
880 bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
887 case LFUN_GREEK_TOGGLE:
889 greek_kb_flag = (greek_kb_flag) ? 0 : 2;
891 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
893 bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
898 case LFUN_BOLD: mathcursor->setLastCode(LM_TC_BF); break;
899 case LFUN_SANS: mathcursor->setLastCode( LM_TC_SF); break;
900 case LFUN_EMPH: mathcursor->setLastCode(LM_TC_CAL); break;
901 case LFUN_ROMAN: mathcursor->setLastCode(LM_TC_RM); break;
902 case LFUN_CODE: mathcursor->setLastCode(LM_TC_TT); break;
903 case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR ) ; break;
906 // varcode = LM_TC_TEX;
907 mathcursor->setLastCode(LM_TC_TEX);
908 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
912 case LFUN_MATH_NUMBER:
914 bv->lockedInsetStoreUndo(Undo::INSERT);
916 short type = par->GetType();
917 bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
920 if (!label.empty()) {
923 bv->owner()->getMiniBuffer()->Set(_("No number"));
926 bv->owner()->getMiniBuffer()->Set(_("Number"));
934 case LFUN_MATH_NONUMBER:
936 if (par->GetType() == LM_OT_MPARN) {
937 // MathMatrixInset *mt = (MathMatrixInset*)par;
939 // mt->SetNumbered(!mt->IsNumbered());
941 mathcursor->setNumbered();
947 case LFUN_MATH_LIMITS:
949 bv->lockedInsetStoreUndo(Undo::INSERT);
950 if (mathcursor->Limits())
956 latexkeys * l = in_word_set (arg);
957 int sz = (l) ? l->id: -1;
958 mathcursor->SetSize(sz);
963 case LFUN_INSERT_MATH:
965 bv->lockedInsetStoreUndo(Undo::INSERT);
966 InsertSymbol(bv, arg);
970 case LFUN_INSERT_MATRIX:
972 bv->lockedInsetStoreUndo(Undo::INSERT);
974 char s[80], arg2[80];
975 // This is just so that too long args won't ooze out of s.
976 strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
977 k = sscanf(arg2, "%d %d %s", &m, &n, s);
986 MathMatrixInset * p = new MathMatrixInset(m, n);
987 if (mathcursor && p) {
988 if (k > 2 && int(strlen(s)) > m)
989 p->SetAlign(s[0], &s[1]);
990 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
996 case LFUN_MATH_DELIM:
998 bv->lockedInsetStoreUndo(Undo::INSERT);
999 char lf[40], rg[40], arg2[40];
1000 int ilf = '(', irg = '.';
1002 string vdelim("(){}[]./|");
1006 strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
1007 int n = sscanf(arg2, "%s %s", lf, rg);
1008 lf[39] = '\0'; rg[39] = '\0';
1012 ilf = lyx::atoi(lf);
1015 l = in_word_set(lf, strlen(lf));
1016 // Long words will cause l == 0; so check.
1019 if (vdelim.find(lf[0]) != string::npos)
1024 irg = lyx::atoi(rg);
1027 l = in_word_set(rg, strlen(rg));
1030 if (vdelim.find(rg[0]) != string::npos)
1035 MathDelimInset * p = new MathDelimInset(ilf, irg);
1036 mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
1041 case LFUN_PROTECTEDSPACE:
1043 bv->lockedInsetStoreUndo(Undo::INSERT);
1044 sp = new MathSpaceInset(1);
1045 mathcursor->Insert(sp);
1051 case LFUN_INSERT_LABEL:
1053 bv->lockedInsetStoreUndo(Undo::INSERT);
1054 if (par->GetType() < LM_OT_PAR) break;
1058 res = askForText(_("Enter new label to insert:"));
1063 if (!lb.empty() && lb[0] > ' ') {
1065 if (par->GetType() == LM_OT_MPARN) {
1066 mathcursor->setLabel(lb);
1067 // MathMatrixInset *mt = (MathMatrixInset*)par;
1068 // mt->SetLabel(lb);
1070 //if (label.notEmpty()) delete label;
1079 case LFUN_MATH_DISPLAY:
1080 //current_view->lockedInsetStoreUndo(Undo::INSERT);
1081 bv->lockedInsetStoreUndo(Undo::EDIT);
1082 display(!disp_flag);
1086 // Invalid actions under math mode
1087 case LFUN_MATH_MODE:
1089 if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
1090 bv->owner()->getMiniBuffer()->Set(_("math text mode"));
1091 varcode = LM_TC_TEXTRM;
1093 varcode = LM_TC_VAR;
1095 mathcursor->setLastCode(varcode);
1099 bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
1102 //------- dummy actions
1103 case LFUN_EXEC_COMMAND:
1104 bv->owner()->getMiniBuffer()->ExecCommand();
1108 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
1109 unsigned char c = arg[0];
1110 bv->lockedInsetStoreUndo(Undo::INSERT);
1112 if (c == ' ' && mathcursor->getAccent() == LM_hat) {
1114 mathcursor->setAccent(0);
1116 if (c == 0) { // Dead key, do nothing
1117 //lyxerr << "deadkey" << endl;
1121 if (mathcursor->getLastCode() == LM_TC_TEX) {
1122 mathcursor->MacroModeOpen();
1123 mathcursor->clearLastCode();
1124 varcode = LM_TC_MIN;
1127 short f = (mathcursor->getLastCode()) ?
1128 mathcursor->getLastCode() :
1129 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1130 varcode = MathIsAlphaFont(f) ?
1131 static_cast<MathedTextCodes>(f) :
1135 // lyxerr << "Varcode << vardoce;
1136 MathedTextCodes char_code = varcode;
1137 if (greek_kb_flag) {
1139 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
1140 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
1141 'Y', 0, 0, 0, 0 , 'Z' };
1142 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
1143 char_code = LM_TC_RM;
1146 char_code = LM_TC_SYMB;
1148 mathcursor->Insert(c, char_code);
1149 if (greek_kb_flag && char_code == LM_TC_RM )
1150 mathcursor->setLastCode(LM_TC_VAR);
1151 varcode = LM_TC_MIN;
1152 if (greek_kb_flag<2) greek_kb_flag = 0;
1154 if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
1155 mathcursor->Insert(c, LM_TC_TEX);
1157 mathcursor->Insert('}', LM_TC_TEX);
1160 mathcursor->clearLastCode();
1161 // varcode = LM_TC_MIN;
1163 if (c == '_' && varcode == LM_TC_TEX) {
1164 mathcursor->Insert(c, LM_TC_SPECIAL);
1165 mathcursor->clearLastCode();
1166 // varcode = LM_TC_MIN;
1168 if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
1169 mathcursor->MacroModeOpen();
1170 mathcursor->clearLastCode();
1171 mathcursor->Insert(c, LM_TC_MIN);
1174 if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c))
1175 mathcursor->Insert(c, LM_TC_CONST);
1177 if (strchr("+/-*<>=", c))
1178 mathcursor->Insert(c, LM_TC_BOP);
1180 if (strchr(latex_special_chars, c) && c!= '_')
1181 mathcursor->Insert(c, LM_TC_SPECIAL);
1183 if (c == '_' || c == '^') {
1187 mathcursor->Interpret (s);
1191 short f = (mathcursor->getLastCode()) ?
1192 mathcursor->getLastCode() :
1193 static_cast<MathedTextCodes>(mathcursor->GetFCode());
1194 varcode = MathIsAlphaFont(f) ?
1195 static_cast<MathedTextCodes>(f) :
1198 if (varcode == LM_TC_TEXTRM) {
1199 mathcursor->Insert(c, LM_TC_TEXTRM);
1202 mathcursor->MacroModeClose();
1205 int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
1209 if (!mathcursor->Pop() && mathcursor->IsEnd())
1214 mathcursor->Insert (c, LM_TC_VAR);
1218 mathcursor->MacroModeClose();
1219 bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
1220 mathcursor->setLastCode(LM_TC_TEX);
1224 // lyxerr << "Closed by action " << action << endl;
1228 if (was_macro != mathcursor->InMacroMode()
1230 && action != LFUN_BACKSPACE)
1232 if (sp && !space_on) sp = 0;
1233 if (mathcursor->Selection() || was_selection)
1234 ToggleInsetSelection(bv);
1236 if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE))
1237 ShowInsetCursor(bv);
1239 bv->unlockInset(this);
1246 MathFuncInset::draw(Painter & pain, int x, int y)
1248 if (!name.empty() && name[0] > ' ') {
1249 LyXFont font = WhichFont(LM_TC_TEXTRM, size);
1250 font.setLatex(LyXFont::ON);
1251 x += (lyxfont::width('I', font) + 3) / 4;
1252 pain.text(x, y, name, font);
1257 void MathFuncInset::Metrics()
1259 //ln = (name) ? strlen(name): 0;
1260 LyXFont font = WhichFont(LM_TC_TEXTRM, size);
1261 font.setLatex(LyXFont::ON);
1267 width = lyxfont::width(name, font)
1268 + lyxfont::width('I', font) / 2;
1269 mathed_string_height(LM_TC_TEXTRM, size, name, ascent, descent);
1275 void mathedValidate(LaTeXFeatures & features, MathParInset * par)
1277 MathedIter it(par->GetData());
1279 while (it.OK() && !(features.binom && features.boldsymbol)) {
1282 MathParInset * p = it.GetActiveInset();
1283 if (!features.binom && p->GetType() == LM_OT_MACRO &&
1284 p->GetName() == "binom") {
1285 features.binom = true;
1287 for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
1288 p->setArgumentIdx(i);
1289 mathedValidate(features, p);
1293 MathedInset* p = it.GetInset();
1294 if (!features.boldsymbol &&
1295 p->GetName() == "boldsymbol") {
1296 features.boldsymbol = true;