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