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