]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.C
4c2f8fab3a7195dfbd9d7e4f8aae887ffa42447b
[lyx.git] / src / mathed / formulabase.C
1  /*
2 *  File:        formulabase.C
3 *  Purpose:     Implementation of common parts of the LyX  math insets
4 *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 *  Created:     January 1996
6 *
7 *  Copyright: 1996-1998 Alejandro Aguilar Sierra
8 *
9 *  Version: 0.4, Lyx project.
10 *
11 *   You are free to use and modify this code under the terms of
12 *   the GNU General Public Licence version 2 or later.
13 */
14
15 #include <config.h>
16 #include <fstream>
17
18 #include "Lsstream.h"
19
20 #ifdef __GNUG__
21 #pragma implementation
22 #endif
23
24 #include "formula.h"
25 #include "formulamacro.h"
26 #include "commandtags.h"
27 #include "math_cursor.h"
28 #include "math_parser.h"
29 #include "BufferView.h"
30 #include "lyxtext.h"
31 #include "lyxfunc.h"
32 #include "gettext.h"
33 #include "LaTeXFeatures.h"
34 #include "debug.h"
35 #include "support.h"
36 #include "support/lstrings.h"
37 #include "LyXView.h"
38 #include "Painter.h"
39 #include "font.h"
40 #include "math_arrayinset.h"
41 #include "math_spaceinset.h"
42 #include "math_macrotable.h"
43 #include "math_factory.h"
44 #include "support/lyxlib.h"
45 #include "undo_funcs.h"
46
47 using std::endl;
48 using std::ostream;
49 using std::vector;
50
51 extern char const * latex_mathenv[];
52 MathCursor        * mathcursor = 0;
53
54
55 namespace {
56
57
58 // local global
59 int sel_x;
60 int sel_y;
61 bool sel_flag;
62
63 void mathed_init_fonts();
64
65 string nicelabel(string const & label)
66 {
67         return "(" + (label.empty() ? "#" : label) + ")";
68 }
69
70 void handleFont(BufferView * bv, MathTextCodes t) 
71 {
72         if (mathcursor->selection())
73                 bv->lockedInsetStoreUndo(Undo::EDIT);
74         mathcursor->handleFont(t);
75 }
76
77
78 void handleAccent(BufferView * bv, string const & name)
79 {
80         bv->lockedInsetStoreUndo(Undo::EDIT);
81         mathcursor->insert(createMathInset(name));
82 }
83
84
85 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
86 {
87         LyXText * lt = bv->getLyXText();
88         
89         bv->beforeChange(lt);
90         finishUndo();
91         if (!bv->insertInset(new_inset)) {
92                 delete new_inset;
93                 return false;
94         }
95         new_inset->edit(bv, 0, 0, 0);
96         return true;
97 }
98
99
100 // returns the nearest enclosing grid
101 MathArrayInset * matrixpar(int & idx)
102 {
103         idx = 0;
104         return (mathcursor ? mathcursor->enclosingArray(idx) : 0); 
105 }
106
107
108 } // namespace anon
109
110
111
112 InsetFormulaBase::InsetFormulaBase()
113 {
114         // This is needed as long the math parser is not re-entrant
115         MathMacroTable::builtinMacros();
116         //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
117 }
118
119
120 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
121 {
122         read(lex);
123 }
124
125
126 void InsetFormulaBase::write(Buffer const *, ostream & os) const
127 {
128         write(os);
129 }
130
131
132 int InsetFormulaBase::latex(Buffer const *, ostream & os,
133         bool fragile, bool spacing) const
134 {
135         return latex(os, fragile, spacing);
136 }
137
138
139 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
140 {
141         return ascii(os, spacing);
142 }
143
144
145 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
146 {
147         return linuxdoc(os);
148 }
149
150
151 int InsetFormulaBase::docbook(Buffer const *, ostream & os) const
152 {
153         return docbook(os);
154 }
155
156
157
158 // Check if uses AMS macros
159 void InsetFormulaBase::validate(LaTeXFeatures &) const
160 {}
161
162
163 string const InsetFormulaBase::editMessage() const
164 {
165         return _("Math editor mode");
166 }
167
168
169 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
170 {
171         mathcursor = new MathCursor(this);
172
173         if (!bv->lockInset(this))
174                 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
175
176         metrics();
177         // if that is removed, we won't get the magenta box when entering an
178         // inset for the first time
179         bv->updateInset(this, false);
180         if (x == 0)
181                 mathcursor->first();
182         else
183                 mathcursor->last();
184         sel_x = 0;
185         sel_y = 0;
186         sel_flag = false;
187 }
188
189
190 void InsetFormulaBase::edit(BufferView * bv, bool front)
191 {
192         // looks hackish but seems to work
193         edit(bv, front ? 0 : 1, 0, 0);
194 }
195
196
197 void InsetFormulaBase::insetUnlock(BufferView * bv)
198 {
199         if (mathcursor) {
200                 if (mathcursor->inMacroMode()) {
201                         mathcursor->macroModeClose();
202                         updateLocal(bv, true);
203                 }
204                 delete mathcursor;
205                 mathcursor = 0;
206         }
207         bv->updateInset(this, false);
208 }
209
210
211 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
212 {
213         mathcursor->getPos(x, y);
214         x -= par()->xo();
215         y -= par()->yo();
216         y -= 3;
217 }
218
219
220 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
221 {
222         if (!mathcursor)
223                 return;
224
225         if (isCursorVisible())
226                 bv->hideLockedInsetCursor();
227         else {
228                 int x;
229                 int y;
230                 mathcursor->getPos(x, y);
231                 //x -= par()->xo();
232                 y -= par()->yo();
233                 y -= 3;
234                 int asc;
235                 int des;
236                 math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
237                 bv->showLockedInsetCursor(x, y, asc, des);
238         }
239
240         toggleCursorVisible();
241 }
242
243
244 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
245 {
246         if (!isCursorVisible()) {
247                 if (mathcursor) {
248                         int x;
249                         int y;
250                         mathcursor->getPos(x, y);
251                         x -= par()->xo();
252                         y -= par()->yo();
253                         int asc;
254                         int des;
255                         math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
256                         bv->fitLockedInsetCursor(x, y, asc, des);
257                 }
258                 toggleInsetCursor(bv);
259         }
260 }
261
262
263 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
264 {
265         if (isCursorVisible())
266                 toggleInsetCursor(bv);
267 }
268
269
270 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
271 {
272         if (mathcursor)
273                 bv->updateInset(this, false);
274 }
275
276
277 vector<string> const InsetFormulaBase::getLabelList() const
278 {
279   return std::vector<string>();
280 }
281
282
283 void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
284 {
285         metrics();
286         bv->updateInset(this, dirty);
287 }
288
289
290 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
291                                           int x, int y, int /*button*/)
292 {
293         if (mathcursor) {
294                 hideInsetCursor(bv);
295                 x += par()->xo();
296                 y += par()->yo();
297                 mathcursor->setPos(x, y);
298                 showInsetCursor(bv);
299                 if (sel_flag) {
300                         sel_flag = false;
301                         sel_x = 0;
302                         sel_y = 0;
303                 }
304                 bv->updateInset(this, false);
305         }
306 }
307
308
309 void InsetFormulaBase::insetButtonPress(BufferView * bv,
310                                         int x, int y, int /*button*/)
311 {
312         sel_flag = false;
313         sel_x = x;
314         sel_y = y;
315         if (mathcursor && mathcursor->selection()) {
316                 mathcursor->selClear();
317                 bv->updateInset(this, false);
318         }
319 }
320
321
322 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
323                                          int x, int y, int /*button*/)
324 {
325         if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
326                 sel_flag = true;
327                 hideInsetCursor(bv);
328                 mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
329                 mathcursor->selStart();
330                 showInsetCursor(bv);
331                 mathcursor->getPos(sel_x, sel_y);
332         } else if (sel_flag) {
333                 hideInsetCursor(bv);
334                 x += par()->xo();
335                 y += par()->yo();
336                 mathcursor->setPos(x, y);
337                 showInsetCursor(bv);
338                 mathcursor->getPos(x, y);
339                 if (sel_x != x || sel_y != y)
340                         bv->updateInset(this, false);
341                 sel_x = x;
342                 sel_y = y;
343         }
344 }
345
346
347 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
348 {
349         lyxerr[Debug::MATHED] << "Used InsetFormulaBase::InsetKeyPress." << endl;
350 }
351
352
353 int greek_kb_flag = 0;
354
355 UpdatableInset::RESULT
356 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
357                             string const & arg)
358 {
359         //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
360         //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
361
362
363         if (!mathcursor) 
364                 return UNDISPATCHED;
365
366         RESULT result      = DISPATCHED;
367         bool sel           = false;
368         bool was_macro     = mathcursor->inMacroMode();
369         bool was_selection = mathcursor->selection();
370
371         hideInsetCursor(bv);
372
373         mathcursor->normalize();
374
375         switch (action) {
376
377                 // --- Cursor Movements ---------------------------------------------
378
379         case LFUN_RIGHTSEL:
380                 sel = true; // fall through...
381
382         case LFUN_RIGHT:
383                 result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
384                 updateLocal(bv, false);
385                 break;
386
387
388         case LFUN_LEFTSEL:
389                 sel = true; // fall through
390
391         case LFUN_LEFT:
392                 result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
393                 updateLocal(bv, false);
394                 break;
395
396
397         case LFUN_UPSEL:
398                 sel = true;
399
400         case LFUN_UP:
401                 result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
402                 updateLocal(bv, false);
403                 break;
404
405
406         case LFUN_DOWNSEL:
407                 sel = true;
408
409         case LFUN_DOWN:
410                 result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
411                 updateLocal(bv, false);
412                 break;
413
414         case LFUN_HOMESEL:
415                 sel = true;
416
417         case LFUN_HOME:
418                 mathcursor->home(sel);
419                 updateLocal(bv, false);
420                 break;
421
422         case LFUN_ENDSEL:
423                 sel = true;
424
425         case LFUN_END:
426                 mathcursor->end(sel);
427                 updateLocal(bv, false);
428                 break;
429
430         case LFUN_DELETE_LINE_FORWARD:
431                 bv->lockedInsetStoreUndo(Undo::DELETE);
432                 mathcursor->delLine();
433                 updateLocal(bv, true);
434                 break;
435
436         case LFUN_TAB:
437                 mathcursor->idxNext();
438                 updateLocal(bv, false);
439                 break;
440
441         case LFUN_SHIFT_TAB:
442                 mathcursor->idxPrev();
443                 updateLocal(bv, false);
444                 break;
445
446         case LFUN_TABINSERT:
447                 bv->lockedInsetStoreUndo(Undo::EDIT);
448                 mathcursor->splitCell();
449                 updateLocal(bv, true);
450                 break;
451
452         case LFUN_BACKSPACE:
453                 bv->lockedInsetStoreUndo(Undo::DELETE);
454                 mathcursor->backspace();
455                 bv->updateInset(this, true);
456                 break;
457
458         case LFUN_DELETE:
459                 bv->lockedInsetStoreUndo(Undo::DELETE);
460                 mathcursor->erase();
461                 bv->updateInset(this, true);
462                 break;
463
464                 //    case LFUN_GETXY:
465                 //      sprintf(dispatch_buffer, "%d %d",);
466                 //      dispatch_result = dispatch_buffer;
467                 //      break;
468         case LFUN_SETXY: {
469                 lyxerr << "LFUN_SETXY broken!\n";
470                 int x;
471                 int y;
472                 int x1;
473                 int y1;
474                 istringstream is(arg.c_str());
475                 is >> x >> y;
476                 par()->getXY(x1, y1);
477                 mathcursor->setPos(x1 + x, y1 + y);
478                 updateLocal(bv, false);
479                 break;
480         }
481
482         case LFUN_PASTE:
483                 if (was_macro)
484                         mathcursor->macroModeClose();
485                 bv->lockedInsetStoreUndo(Undo::INSERT);
486                 mathcursor->selPaste();
487                 updateLocal(bv, true);
488                 break;
489
490         case LFUN_CUT:
491                 bv->lockedInsetStoreUndo(Undo::DELETE);
492                 mathcursor->selCut();
493                 updateLocal(bv, true);
494                 break;
495
496         case LFUN_COPY:
497                 mathcursor->selCopy();
498                 break;
499
500         case LFUN_WORDRIGHTSEL:
501         case LFUN_WORDLEFTSEL:
502                 break;
503
504                 // --- accented characters ------------------------------
505
506         case LFUN_UMLAUT:       handleAccent(bv, "ddot"); break;
507         case LFUN_CIRCUMFLEX:   handleAccent(bv, "hat"); break;
508         case LFUN_GRAVE:        handleAccent(bv, "grave"); break;
509         case LFUN_ACUTE:        handleAccent(bv, "acute"); break;
510         case LFUN_TILDE:        handleAccent(bv, "tilde"); break;
511         case LFUN_MACRON:       handleAccent(bv, "bar"); break;
512         case LFUN_DOT:          handleAccent(bv, "dot"); break;
513         case LFUN_CARON:        handleAccent(bv, "check"); break;
514         case LFUN_BREVE:        handleAccent(bv, "breve"); break;
515         case LFUN_VECTOR:       handleAccent(bv, "vec"); break;
516
517         //  Math fonts
518         case LFUN_GREEK:        handleFont(bv, LM_TC_GREEK1); break;
519         case LFUN_GREEK_TOGGLE: handleFont(bv, LM_TC_GREEK); break;
520         case LFUN_BOLD:         handleFont(bv, LM_TC_BF); break;
521         case LFUN_SANS:         handleFont(bv, LM_TC_SF); break;
522         case LFUN_EMPH:         handleFont(bv, LM_TC_CAL); break;
523         case LFUN_ROMAN:        handleFont(bv, LM_TC_RM); break;
524         case LFUN_CODE:         handleFont(bv, LM_TC_TT); break;
525         case LFUN_NOUN:         handleFont(bv, LM_TC_BB); break;
526         case LFUN_DEFAULT:      handleFont(bv, LM_TC_VAR); break;
527
528         case LFUN_MATH_MODE:
529                 handleFont(bv, LM_TC_TEXTRM);
530                 //bv->owner()->message(_("math text mode toggled"));
531                 break;
532
533         case LFUN_MATH_LIMITS:
534                 bv->lockedInsetStoreUndo(Undo::INSERT);
535                 if (mathcursor->toggleLimits())
536                         updateLocal(bv, true);
537                 break;
538
539         case LFUN_MATH_SIZE:
540                 if (!arg.empty()) {
541                         bv->lockedInsetStoreUndo(Undo::INSERT);
542                         latexkeys const * l = in_word_set(arg);
543                         mathcursor->setSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
544                         updateLocal(bv, true);
545                 }
546                 break;
547
548         case LFUN_INSERT_MATRIX:
549                 if (!arg.empty()) {
550                         bv->lockedInsetStoreUndo(Undo::INSERT);
551                         mathcursor->interpret("matrix " + arg);
552                         updateLocal(bv, true);
553                 }
554                 break;
555
556         case LFUN_MATH_SPACE:
557         {
558                 bv->lockedInsetStoreUndo(Undo::EDIT);
559                 //MathSpaceInset * p = mathcursor->prevSpaceInset();
560                 //if (p) 
561                 //      p->incSpace();
562                 //else
563                 //      mathcursor->insert(new MathSpaceInset(1));
564                 mathcursor->insert(new MathSpaceInset(1));
565                 updateLocal(bv, true);
566                 break;
567         }
568
569         case LFUN_MATH_DELIM:
570         {
571                 bv->lockedInsetStoreUndo(Undo::INSERT);
572                 //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
573                 string ls;
574                 string rs;
575                 istringstream is(arg.c_str());
576                 is >> ls >> rs;
577                 if (!is) {
578                         lyxerr << "can't parse delimeters from '" << arg << "'\n";
579                         break;
580                 }
581                 bv->lockedInsetStoreUndo(Undo::EDIT);
582                 mathcursor->handleDelim(ls, rs);
583                 updateLocal(bv, true);
584                 break;
585         }
586
587         case LFUN_PROTECTEDSPACE:
588                 //lyxerr << " called LFUN_PROTECTEDSPACE\n";
589                 bv->lockedInsetStoreUndo(Undo::INSERT);
590                 mathcursor->insert(new MathSpaceInset(1));
591                 updateLocal(bv, true);
592                 break;
593
594         case LFUN_UNDO:
595                 bv->owner()->message(_("Invalid action in math mode!"));
596                 break;
597
598
599         case LFUN_MATH_HALIGN:
600         {
601                 bv->lockedInsetStoreUndo(Undo::INSERT);
602                 lyxerr << "handling halign '" << arg << "'\n";
603                 int idx;
604                 MathArrayInset * p = matrixpar(idx);
605                 if (!p)
606                         break; 
607                 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
608                 updateLocal(bv, true);
609                 break;
610         }
611
612         case LFUN_MATH_VALIGN:
613         {
614                 bv->lockedInsetStoreUndo(Undo::INSERT);
615                 lyxerr << "handling valign '" << arg << "'\n";
616                 int idx;
617                 MathArrayInset * p = matrixpar(idx);
618                 if (!p)
619                         break; 
620                 p->valign(arg.size() ? arg[0] : 'c');
621                 updateLocal(bv, true);
622                 break;
623         }
624
625         case LFUN_MATH_ROW_INSERT:
626         {
627                 bv->lockedInsetStoreUndo(Undo::INSERT);
628                 int idx;
629                 MathArrayInset * p = matrixpar(idx);
630                 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
631                 if (!p)
632                         break; 
633                 p->addRow(p->row(idx));
634                 updateLocal(bv, true);
635                 break;
636         }
637
638         case LFUN_MATH_ROW_DELETE:
639         {
640                 bv->lockedInsetStoreUndo(Undo::INSERT);
641                 int idx;
642                 MathArrayInset * p = matrixpar(idx);
643                 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
644                 if (!p)
645                         break; 
646                 p->delRow(p->row(idx));
647                 updateLocal(bv, true);
648                 break;
649         }
650
651         case LFUN_MATH_COLUMN_INSERT:
652         {
653                 bv->lockedInsetStoreUndo(Undo::INSERT);
654                 int idx;
655                 MathArrayInset * p = matrixpar(idx);
656                 if (!p)
657                         break; 
658                 p->addCol(p->col(idx));
659                 updateLocal(bv, true);
660                 break;
661         }
662
663         case LFUN_MATH_COLUMN_DELETE:
664         {
665                 bv->lockedInsetStoreUndo(Undo::INSERT);
666                 int idx;
667                 MathArrayInset * p = matrixpar(idx);
668                 if (!p)
669                         break; 
670                 p->delCol(p->col(idx));
671                 updateLocal(bv, true);
672                 break;
673         }
674
675         case LFUN_EXEC_COMMAND:
676                 result = UNDISPATCHED;
677                 break;
678
679         case -1:
680         case LFUN_INSERT_MATH:
681         case LFUN_SELFINSERT:
682                 if (!arg.empty()) {
683                         bv->lockedInsetStoreUndo(Undo::INSERT);
684                         mathcursor->interpret(arg);
685                         updateLocal(bv, true);
686                 }
687                 break;
688
689         case LFUN_MATH_PANEL:
690                 result = UNDISPATCHED;
691                 break;
692
693         default:
694                 result = UNDISPATCHED;
695         }
696
697         //mathcursor->normalize();
698
699         if (was_macro != mathcursor->inMacroMode()
700                                 && action >= 0 && action != LFUN_BACKSPACE) 
701                 updateLocal(bv, true);
702         
703         if (mathcursor->selection() || was_selection)
704                 toggleInsetSelection(bv);
705
706         if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
707             result == UNDISPATCHED)
708                 showInsetCursor(bv);
709         else
710                 bv->unlockInset(this);
711
712         return result;  // original version
713 }
714
715
716 Inset::Code InsetFormulaBase::lyxCode() const
717 {
718         return Inset::MATH_CODE;
719 }
720
721
722 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
723 {
724         if (bv->available()) {
725                 // use selection if available..
726                 //string sel;
727                 //if (action == LFUN_MATH_IMPORT_SELECTION)
728                 //      sel = "";
729                 //else
730
731                 string sel = bv->getLyXText()->selectionAsString(bv->buffer(),
732                                                                  false);
733
734                 InsetFormulaBase * f;
735                 if (sel.empty()) {
736                                 f = new InsetFormula;
737                                 if (openNewInset(bv, f)) {
738                                         // don't do that also for LFUN_MATH_MODE unless you want end up with
739                                         // always changing to mathrm when opening an inlined inset
740                                         // -- I really hate "LyXfunc overloading"...
741                                         if (display)
742                                                 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
743                                         f->localDispatch(bv, LFUN_INSERT_MATH, arg);
744                                 }
745                 } else {
746                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
747                         // formula otherwise
748                         if (sel.find("\\newcommand") == string::npos) 
749                                 f = new InsetFormula(sel);
750                         else
751                                 f = new InsetFormulaMacro(sel);
752                         bv->getLyXText()->cutSelection(bv);
753                         openNewInset(bv, f);
754                 }
755         }
756         bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
757 }
758
759
760 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
761 {
762         mathDispatchCreation(bv, arg, true);
763 }
764
765         
766 void mathDispatchMathMode(BufferView * bv, string const & arg)
767 {
768         mathDispatchCreation(bv, arg, false);
769 }
770
771
772 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
773 {
774         mathDispatchCreation(bv, arg, true);
775 }
776
777
778 void mathDispatchMathMacro(BufferView * bv, string const & arg)
779 {
780         if (bv->available()) {
781                 if (arg.empty())
782                         bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
783                 else {
784                         string s(arg);
785                         string const s1 = token(s, ' ', 1);
786                         int const na = s1.empty() ? 0 : lyx::atoi(s1);
787                         openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
788                 }
789         }
790 }
791
792
793 void mathDispatchMathDelim(BufferView * bv, string const & arg)
794 {          
795         if (bv->available()) { 
796                 if (openNewInset(bv, new InsetFormula))
797                         bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
798         }
799 }          
800
801
802 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
803 {          
804         if (bv->available()) { 
805                 if (openNewInset(bv, new InsetFormula))
806                         bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
807         }
808 }          
809
810
811 void mathDispatchInsertMath(BufferView * bv, string const & arg)
812 {
813         if (bv->available()) {
814                 if (arg.size() && arg[0] == '\\')
815                         openNewInset(bv, new InsetFormula(arg));
816                 else
817                         mathDispatchMathMode(bv, arg);
818         }
819 }
820
821
822 void mathDispatchGreek(BufferView * bv, string const & arg)
823 {          
824         if (bv->available()) { 
825                 InsetFormula * f = new InsetFormula;
826                 if (openNewInset(bv, f)) {
827                         bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, string());
828                         bv->theLockingInset()->localDispatch(bv, LFUN_SELFINSERT, arg);
829                         bv->unlockInset(f);
830                 }
831         }
832 }          
833