]> git.lyx.org Git - lyx.git/blob - src/text3.C
4b69a2b0106a5930ea578bd6f241903dec718d95
[lyx.git] / src / text3.C
1 /**
2  * \file text3.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  * \author Angus Leeming
10  * \author John Levon
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "lyxtext.h"
19
20 #include "FloatList.h"
21 #include "FuncStatus.h"
22 #include "buffer.h"
23 #include "bufferparams.h"
24 #include "BufferView.h"
25 #include "cursor.h"
26 #include "coordcache.h"
27 #include "CutAndPaste.h"
28 #include "debug.h"
29 #include "dispatchresult.h"
30 #include "factory.h"
31 #include "funcrequest.h"
32 #include "gettext.h"
33 #include "intl.h"
34 #include "language.h"
35 #include "lyxfunc.h"
36 #include "lyxlex.h"
37 #include "lyxrc.h"
38 #include "lyxrow.h"
39 #include "paragraph.h"
40 #include "paragraph_funcs.h"
41 #include "ParagraphParameters.h"
42 #include "undo.h"
43 #include "vspace.h"
44
45 #include "frontends/Dialogs.h"
46 #include "frontends/LyXView.h"
47
48 #include "insets/insetcommand.h"
49 #include "insets/insetfloatlist.h"
50 #include "insets/insetnewline.h"
51 #include "insets/insetquotes.h"
52 #include "insets/insetspecialchar.h"
53 #include "insets/insettext.h"
54
55 #include "support/lstrings.h"
56 #include "support/lyxlib.h"
57 #include "support/tostr.h"
58
59 #include "mathed/math_hullinset.h"
60 #include "mathed/math_macrotemplate.h"
61
62 #include <clocale>
63 #include <sstream>
64
65 using lyx::pos_type;
66
67 using lyx::cap::copySelection;
68 using lyx::cap::cutSelection;
69 using lyx::cap::pasteSelection;
70 using lyx::cap::replaceSelection;
71
72 using lyx::support::isStrUnsignedInt;
73 using lyx::support::strToUnsignedInt;
74 using lyx::support::atoi;
75 using lyx::support::token;
76
77 using std::endl;
78 using std::find;
79 using std::string;
80 using std::istringstream;
81 using std::vector;
82
83
84 extern string current_layout;
85
86 // the selection possible is needed, that only motion events are
87 // used, where the button press event was on the drawing area too
88 bool selection_possible = false;
89
90
91 namespace {
92
93         // globals...
94         LyXFont freefont(LyXFont::ALL_IGNORE);
95         bool toggleall = false;
96
97
98         void toggleAndShow(LCursor & cur, LyXText * text,
99                 LyXFont const & font, bool toggleall = true)
100         {
101                 text->toggleFree(cur, font, toggleall);
102
103                 if (font.language() != ignore_language ||
104                                 font.number() != LyXFont::IGNORE) {
105                         Paragraph & par = cur.paragraph();
106                         text->bidi.computeTables(par, cur.buffer(), cur.textRow());
107                         if (cur.boundary() !=
108                                         text->bidi.isBoundary(cur.buffer(), par,
109                                                         cur.pos(),
110                                                         text->real_current_font))
111                                 text->setCursor(cur, cur.par(), cur.pos(),
112                                                 false, !cur.boundary());
113                 }
114         }
115
116
117         void moveCursor(LCursor & cur, bool selecting)
118         {
119                 if (selecting || cur.mark())
120                         cur.setSelection();
121                 if (!cur.selection())
122                         cur.bv().haveSelection(false);
123                 cur.bv().switchKeyMap();
124         }
125
126
127         void finishChange(LCursor & cur, bool selecting)
128         {
129                 finishUndo();
130                 moveCursor(cur, selecting);
131         }
132
133
134         void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
135         {
136                 recordUndo(cur);
137                 string sel = cur.selectionAsString(false);
138                 lyxerr << "selection is: '" << sel << "'" << endl;
139
140                 if (sel.empty()) {
141                         const int old_pos = cur.pos();
142                         cur.insert(new MathHullInset);
143                         BOOST_ASSERT(old_pos == cur.pos());
144                         cur.nextInset()->edit(cur, true);
145                         cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
146                         // don't do that also for LFUN_MATH_MODE unless you want end up with
147                         // always changing to mathrm when opening an inlined inset
148                         // -- I really hate "LyXfunc overloading"...
149                         if (display)
150                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
151                         cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
152                 } else {
153                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
154                         // formula otherwise
155                         cutSelection(cur, true, true);
156                         if (sel.find("\\newcommand") == string::npos
157                             && sel.find("\\def") == string::npos)
158                         {
159                                 cur.insert(new MathHullInset);
160                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
161                                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
162                                 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
163                         } else {
164                                 istringstream is(sel);
165                                 cur.insert(new MathMacroTemplate(is));
166                         }
167                 }
168                 cur.message(N_("Math editor mode"));
169         }
170
171 } // namespace anon
172
173
174
175 namespace bv_funcs {
176
177 string const freefont2string()
178 {
179         string data;
180         if (font2string(freefont, toggleall, data))
181                 return data;
182         return string();
183 }
184
185 }
186
187 bool LyXText::gotoNextInset(LCursor & cur,
188         vector<InsetOld_code> const & codes, string const & contents)
189 {
190         BOOST_ASSERT(this == cur.text());
191         par_type end = paragraphs().size();
192         par_type pit = cur.par();
193         pos_type pos = cur.pos();
194
195         InsetBase * inset;
196         do {
197                 if (pos + 1 < pars_[pit].size()) {
198                         ++pos;
199                 } else  {
200                         ++pit;
201                         pos = 0;
202                 }
203
204         } while (pit != end &&
205                  !(pars_[pit].isInset(pos) &&
206                    (inset = pars_[pit].getInset(pos)) != 0 &&
207                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
208                    (contents.empty() ||
209                     static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
210                     == contents)));
211
212         if (pit == end)
213                 return false;
214
215         setCursor(cur, pit, pos, false);
216         return true;
217 }
218
219
220 void LyXText::gotoInset(LCursor & cur,
221         vector<InsetOld_code> const & codes, bool same_content)
222 {
223         cur.clearSelection();
224
225         string contents;
226         if (same_content
227             && cur.pos() < cur.lastpos()
228             && cur.paragraph().isInset(cur.pos())) {
229                 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
230                 if (find(codes.begin(), codes.end(), inset->lyxCode())
231                     != codes.end())
232                         contents = static_cast<InsetCommand const *>(inset)->getContents();
233         }
234
235         if (!gotoNextInset(cur, codes, contents)) {
236                 if (cur.pos() || cur.par() != 0) {
237                         CursorSlice tmp = cur.top();
238                         cur.par() = 0;
239                         cur.pos() = 0;
240                         if (!gotoNextInset(cur, codes, contents)) {
241                                 cur.top() = tmp;
242                                 cur.message(_("No more insets"));
243                         }
244                 } else {
245                         cur.message(_("No more insets"));
246                 }
247         }
248         cur.resetAnchor();
249 }
250
251
252 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
253 {
254         gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
255 }
256
257
258 void LyXText::cursorPrevious(LCursor & cur)
259 {
260         pos_type cpos = cur.pos();
261         lyx::par_type cpar = cur.par();
262
263         int x = cur.x_target();
264         int y = cur.bv().top_y();
265         setCursorFromCoordinates(cur, x, y);
266
267         if (cpar == cur.par() && cpos == cur.pos()) {
268                 // we have a row which is taller than the workarea. The
269                 // simplest solution is to move to the previous row instead.
270                 cursorUp(cur);
271         }
272
273         cur.bv().updateScrollbar();
274         finishUndo();
275 }
276
277
278 void LyXText::cursorNext(LCursor & cur)
279 {
280         pos_type cpos = cur.pos();
281         lyx::par_type cpar = cur.par();
282
283         int x = cur.x_target();
284         int y = cur.bv().top_y() + cur.bv().workHeight();
285         setCursorFromCoordinates(cur, x, y);
286
287         if (cpar == cur.par() && cpos == cur.pos()) {
288                 // we have a row which is taller than the workarea. The
289                 // simplest solution is to move to the next row instead.
290                 cursorDown(cur);
291         }
292
293         cur.bv().updateScrollbar();
294         finishUndo();
295 }
296
297
298 namespace {
299
300 void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
301 {
302         lyx::cap::replaceSelection(cur);
303         cur.insert(new InsetSpecialChar(kind));
304 }
305
306
307 void doInsertInset(LCursor & cur, LyXText * text,
308         FuncRequest const & cmd, bool edit, bool pastesel)
309 {
310         InsetBase * inset = createInset(&cur.bv(), cmd);
311         if (!inset)
312                 return;
313
314         recordUndo(cur);
315         bool gotsel = false;
316         if (cur.selection()) {
317                 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
318                 gotsel = true;
319         }
320         text->insertInset(cur, inset);
321
322         if (edit)
323                 inset->edit(cur, true);
324
325         if (gotsel && pastesel)
326                 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
327 }
328
329 } // anon namespace
330
331
332 void LyXText::number(LCursor & cur)
333 {
334         LyXFont font(LyXFont::ALL_IGNORE);
335         font.setNumber(LyXFont::TOGGLE);
336         toggleAndShow(cur, this, font);
337 }
338
339
340 bool LyXText::isRTL(Paragraph const & par) const
341 {
342         return par.isRightToLeftPar(bv()->buffer()->params());
343 }
344
345
346 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
347 {
348         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
349         //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
350
351         BOOST_ASSERT(cur.text() == this);
352         BufferView * bv = &cur.bv();
353         CursorSlice sl = cur.top();
354         bool sel = cur.selection();
355         bool moving = false;
356
357         switch (cmd.action) {
358
359         case LFUN_APPENDIX: {
360                 Paragraph & par = cur.paragraph();
361                 bool start = !par.params().startOfAppendix();
362
363                 // ensure that we have only one start_of_appendix in this document
364                 for (par_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
365                         if (pars_[tmp].params().startOfAppendix()) {
366                                 recUndo(tmp);
367                                 pars_[tmp].params().startOfAppendix(false);
368                                 redoParagraph(tmp);
369                                 break;
370                         }
371                 }
372
373                 recordUndo(cur);
374                 par.params().startOfAppendix(start);
375
376                 // we can set the refreshing parameters now
377                 updateCounters();
378                 redoParagraph(cur);
379                 break;
380         }
381
382         case LFUN_DELETE_WORD_FORWARD:
383                 cur.clearSelection();
384                 deleteWordForward(cur);
385                 finishChange(cur, false);
386                 break;
387
388         case LFUN_DELETE_WORD_BACKWARD:
389                 cur.clearSelection();
390                 deleteWordBackward(cur);
391                 finishChange(cur, false);
392                 break;
393
394         case LFUN_DELETE_LINE_FORWARD:
395                 cur.clearSelection();
396                 deleteLineForward(cur);
397                 finishChange(cur, false);
398                 break;
399
400         case LFUN_WORDRIGHT:
401                 moving = true;
402                 if (!cur.mark())
403                         cur.clearSelection();
404                 if (isRTL(cur.paragraph()))
405                         cursorLeftOneWord(cur);
406                 else
407                         cursorRightOneWord(cur);
408                 finishChange(cur, false);
409                 break;
410
411         case LFUN_WORDLEFT:
412                 moving = true;
413                 if (!cur.mark())
414                         cur.clearSelection();
415                 if (isRTL(cur.paragraph()))
416                         cursorRightOneWord(cur);
417                 else
418                         cursorLeftOneWord(cur);
419                 finishChange(cur, false);
420                 break;
421
422         case LFUN_BEGINNINGBUF:
423                 if (cur.size() == 1) {
424                         if (!cur.mark())
425                                 cur.clearSelection();
426                         cursorTop(cur);
427                         finishChange(cur, false);
428                 } else {
429                         cur.undispatched();
430                 }
431                 break;
432
433         case LFUN_ENDBUF:
434                 if (cur.size() == 1) {
435                         if (!cur.mark())
436                                 cur.clearSelection();
437                         cursorBottom(cur);
438                         finishChange(cur, false);
439                 } else {
440                         cur.undispatched();
441                 }
442                 break;
443
444         case LFUN_RIGHT:
445                 moving = true;
446         case LFUN_RIGHTSEL:
447                 //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
448                 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
449                 if (isRTL(cur.paragraph()))
450                         cursorLeft(cur);
451                 else
452                         cursorRight(cur);
453                 if (sl == cur.top()) {
454                         cur.undispatched();
455                         cmd = FuncRequest(LFUN_FINISHED_RIGHT);
456                 }
457                 break;
458
459         case LFUN_LEFT:
460                 moving = true;
461         case LFUN_LEFTSEL:
462                 //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
463                 cur.selHandle(cmd.action == LFUN_LEFTSEL);
464                 if (isRTL(cur.paragraph()))
465                         cursorRight(cur);
466                 else
467                         cursorLeft(cur);
468                 if (sl == cur.top()) {
469                         cur.undispatched();
470                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
471                 }
472                 break;
473
474         case LFUN_UP:
475                 moving = true;
476         case LFUN_UPSEL:
477                 //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
478                 cur.selHandle(cmd.action == LFUN_UPSEL);
479                 cursorUp(cur);
480                 if (sl == cur.top()) {
481                         cur.undispatched();
482                         cmd = FuncRequest(LFUN_FINISHED_UP);
483                 }
484                 break;
485
486         case LFUN_DOWN:
487                 moving = true;
488         case LFUN_DOWNSEL:
489                 //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
490                 cur.selHandle(cmd.action == LFUN_DOWNSEL);
491                 cursorDown(cur);
492                 if (sl == cur.top()) {
493                         cur.undispatched();
494                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
495                 }
496                 break;
497
498         case LFUN_UP_PARAGRAPHSEL:
499                 if (!cur.selection())
500                         cur.resetAnchor();
501                 cursorUpParagraph(cur);
502                 finishChange(cur, true);
503                 break;
504
505         case LFUN_DOWN_PARAGRAPHSEL:
506                 if (!cur.selection())
507                         cur.resetAnchor();
508                 cursorDownParagraph(cur);
509                 finishChange(cur, true);
510                 break;
511
512         case LFUN_PRIORSEL:
513                 if (!cur.selection())
514                         cur.resetAnchor();
515                 cursorPrevious(cur);
516                 finishChange(cur, true);
517                 break;
518
519         case LFUN_NEXTSEL:
520                 if (!cur.selection())
521                         cur.resetAnchor();
522                 cursorNext(cur);
523                 finishChange(cur, true);
524                 break;
525
526         case LFUN_HOMESEL:
527                 if (!cur.selection())
528                         cur.resetAnchor();
529                 cursorHome(cur);
530                 finishChange(cur, true);
531                 break;
532
533         case LFUN_ENDSEL:
534                 if (!cur.selection())
535                         cur.resetAnchor();
536                 cursorEnd(cur);
537                 finishChange(cur, true);
538                 break;
539
540         case LFUN_WORDRIGHTSEL:
541                 if (!cur.selection())
542                         cur.resetAnchor();
543                 if (isRTL(cur.paragraph()))
544                         cursorLeftOneWord(cur);
545                 else
546                         cursorRightOneWord(cur);
547                 finishChange(cur, true);
548                 break;
549
550         case LFUN_WORDLEFTSEL:
551                 if (!cur.selection())
552                         cur.resetAnchor();
553                 if (isRTL(cur.paragraph()))
554                         cursorRightOneWord(cur);
555                 else
556                         cursorLeftOneWord(cur);
557                 finishChange(cur, true);
558                 break;
559
560         case LFUN_WORDSEL: {
561                 selectWord(cur, lyx::WHOLE_WORD);
562                 finishChange(cur, true);
563                 break;
564         }
565
566         case LFUN_UP_PARAGRAPH:
567                 moving = true;
568                 if (!cur.mark())
569                         cur.clearSelection();
570                 cursorUpParagraph(cur);
571                 finishChange(cur, false);
572                 break;
573
574         case LFUN_DOWN_PARAGRAPH:
575                 moving = true;
576                 if (!cur.mark())
577                         cur.clearSelection();
578                 cursorDownParagraph(cur);
579                 finishChange(cur, false);
580                 break;
581
582         case LFUN_PRIOR:
583                 moving = true;
584                 if (!cur.mark())
585                         cur.clearSelection();
586                 finishChange(cur, false);
587                 if (cur.par() == 0 && cur.textRow().pos() == 0) {
588                         cur.undispatched();
589                         cmd = FuncRequest(LFUN_FINISHED_UP);
590                 } else {
591                         cursorPrevious(cur);
592                 }
593                 break;
594
595         case LFUN_NEXT:
596                 moving = true;
597                 if (!cur.mark())
598                         cur.clearSelection();
599                 finishChange(cur, false);
600                 if (cur.par() == cur.lastpar()
601                           && cur.textRow().endpos() == cur.lastpos()) {
602                         cur.undispatched();
603                         cmd = FuncRequest(LFUN_FINISHED_DOWN);
604                 } else {
605                         cursorNext(cur);
606                 }
607                 break;
608
609         case LFUN_HOME:
610                 if (!cur.mark())
611                         cur.clearSelection();
612                 cursorHome(cur);
613                 finishChange(cur, false);
614                 break;
615
616         case LFUN_END:
617                 if (!cur.mark())
618                         cur.clearSelection();
619                 cursorEnd(cur);
620                 finishChange(cur, false);
621                 break;
622
623         case LFUN_BREAKLINE: {
624                 // Not allowed by LaTeX (labels or empty par)
625                 if (cur.pos() > cur.paragraph().beginOfBody()) {
626                         lyx::cap::replaceSelection(cur);
627                         cur.insert(new InsetNewline);
628                         moveCursor(cur, false);
629                 }
630                 break;
631         }
632
633         case LFUN_DELETE:
634                 if (!cur.selection()) {
635                         Delete(cur);
636                         cur.resetAnchor();
637                         // It is possible to make it a lot faster still
638                         // just comment out the line below...
639                 } else {
640                         cutSelection(cur, true, false);
641                 }
642                 moveCursor(cur, false);
643                 break;
644
645         case LFUN_DELETE_SKIP:
646                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
647                 if (!cur.selection()) {
648                         if (cur.pos() == cur.lastpos()) {
649                                 cursorRight(cur);
650                                 cursorLeft(cur);
651                         }
652                         Delete(cur);
653                         cur.resetAnchor();
654                 } else {
655                         cutSelection(cur, true, false);
656                 }
657                 break;
658
659
660         case LFUN_BACKSPACE:
661                 if (!cur.selection()) {
662                         if (bv->owner()->getIntl().getTransManager().backspace()) {
663                                 backspace(cur);
664                                 cur.resetAnchor();
665                                 // It is possible to make it a lot faster still
666                                 // just comment out the line below...
667                         }
668                 } else {
669                         cutSelection(cur, true, false);
670                 }
671                 bv->switchKeyMap();
672                 break;
673
674         case LFUN_BACKSPACE_SKIP:
675                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
676                 if (!cur.selection()) {
677 #ifdef WITH_WARNINGS
678 #warning look here
679 #endif
680                         //CursorSlice cur = cursor();
681                         backspace(cur);
682                         //anchor() = cur;
683                 } else {
684                         cutSelection(cur, true, false);
685                 }
686                 break;
687
688         case LFUN_BREAKPARAGRAPH:
689                 lyx::cap::replaceSelection(cur);
690                 breakParagraph(cur, 0);
691                 cur.resetAnchor();
692                 bv->switchKeyMap();
693                 break;
694
695         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
696                 lyx::cap::replaceSelection(cur);
697                 breakParagraph(cur, 1);
698                 cur.resetAnchor();
699                 bv->switchKeyMap();
700                 break;
701
702         case LFUN_BREAKPARAGRAPH_SKIP: {
703                 // When at the beginning of a paragraph, remove
704                 // indentation.  Otherwise, do the same as LFUN_BREAKPARAGRAPH.
705                 lyx::cap::replaceSelection(cur);
706                 if (cur.pos() == 0)
707                         cur.paragraph().params().labelWidthString(string());
708                 else
709                         breakParagraph(cur, 0);
710                 cur.resetAnchor();
711                 bv->switchKeyMap();
712                 break;
713         }
714
715         case LFUN_PARAGRAPH_SPACING: {
716                 Paragraph & par = cur.paragraph();
717                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
718                 float cur_value = 1.0;
719                 if (cur_spacing == Spacing::Other)
720                         cur_value = par.params().spacing().getValue();
721
722                 istringstream is(cmd.argument);
723                 string tmp;
724                 is >> tmp;
725                 Spacing::Space new_spacing = cur_spacing;
726                 float new_value = cur_value;
727                 if (tmp.empty()) {
728                         lyxerr << "Missing argument to `paragraph-spacing'"
729                                << endl;
730                 } else if (tmp == "single") {
731                         new_spacing = Spacing::Single;
732                 } else if (tmp == "onehalf") {
733                         new_spacing = Spacing::Onehalf;
734                 } else if (tmp == "double") {
735                         new_spacing = Spacing::Double;
736                 } else if (tmp == "other") {
737                         new_spacing = Spacing::Other;
738                         float tmpval = 0.0;
739                         is >> tmpval;
740                         lyxerr << "new_value = " << tmpval << endl;
741                         if (tmpval != 0.0)
742                                 new_value = tmpval;
743                 } else if (tmp == "default") {
744                         new_spacing = Spacing::Default;
745                 } else {
746                         lyxerr << _("Unknown spacing argument: ")
747                                << cmd.argument << endl;
748                 }
749                 if (cur_spacing != new_spacing || cur_value != new_value) {
750                         par.params().spacing(Spacing(new_spacing, new_value));
751                         redoParagraph(cur);
752                 }
753                 break;
754         }
755
756         case LFUN_INSET_APPLY: {
757                 string const name = cmd.getArg(0);
758                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
759                 if (inset) {
760                         FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
761                         inset->dispatch(cur, fr);
762                 } else {
763                         FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
764                         dispatch(cur, fr);
765                 }
766                 break;
767         }
768
769         case LFUN_INSET_INSERT: {
770                 recordUndo(cur);
771                 InsetBase * inset = createInset(bv, cmd);
772                 if (inset) {
773                         insertInset(cur, inset);
774                         cur.posRight();
775                 }
776                 break;
777         }
778
779         case LFUN_INSET_SETTINGS:
780                 if (cur.inset().asUpdatableInset())
781                         cur.inset().asUpdatableInset()->showInsetDialog(bv);
782                 break;
783
784         case LFUN_NEXT_INSET_TOGGLE: {
785                 InsetBase * inset = cur.nextInset();
786                 if (inset) {
787                         cur.clearSelection();
788                         FuncRequest fr = cmd;
789                         fr.action = LFUN_INSET_TOGGLE;
790                         inset->dispatch(cur, fr);
791                 }
792                 break;
793         }
794
795         case LFUN_KEYMAP_TOGGLE:
796                 cur.clearSelection();
797                 bv->switchKeyMap();
798                 break;
799
800         case LFUN_SPACE_INSERT:
801                 if (cur.paragraph().layout()->free_spacing)
802                         insertChar(cur, ' ');
803                 else
804                         doInsertInset(cur, this, cmd, false, false);
805                 moveCursor(cur, false);
806                 break;
807
808         case LFUN_HYPHENATION:
809                 specialChar(cur, InsetSpecialChar::HYPHENATION);
810                 break;
811
812         case LFUN_LIGATURE_BREAK:
813                 specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
814                 break;
815
816         case LFUN_LDOTS:
817                 specialChar(cur, InsetSpecialChar::LDOTS);
818                 break;
819
820         case LFUN_END_OF_SENTENCE:
821                 specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
822                 break;
823
824         case LFUN_MENU_SEPARATOR:
825                 specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
826                 break;
827
828         case LFUN_UPCASE_WORD:
829                 changeCase(cur, LyXText::text_uppercase);
830                 break;
831
832         case LFUN_LOWCASE_WORD:
833                 changeCase(cur, LyXText::text_lowercase);
834                 break;
835
836         case LFUN_CAPITALIZE_WORD:
837                 changeCase(cur, LyXText::text_capitalization);
838                 break;
839
840         case LFUN_TRANSPOSE_CHARS:
841                 recordUndo(cur);
842                 redoParagraph(cur);
843                 break;
844
845         case LFUN_PASTE:
846                 cur.message(_("Paste"));
847                 lyx::cap::replaceSelection(cur);
848 #ifdef WITH_WARNINGS
849 #warning FIXME Check if the arg is in the domain of available selections.
850 #endif
851                 if (isStrUnsignedInt(cmd.argument))
852                         pasteSelection(cur, strToUnsignedInt(cmd.argument));
853                 else
854                         pasteSelection(cur, 0);
855                 cur.clearSelection(); // bug 393
856                 bv->switchKeyMap();
857                 finishUndo();
858                 break;
859
860         case LFUN_CUT:
861                 cutSelection(cur, true, true);
862                 cur.message(_("Cut"));
863                 break;
864
865         case LFUN_COPY:
866                 copySelection(cur);
867                 cur.message(_("Copy"));
868                 break;
869
870         case LFUN_GETXY:
871                 cur.message(tostr(cursorX(cur.top())) + ' '
872                           + tostr(cursorY(cur.top())));
873                 break;
874
875         case LFUN_SETXY: {
876                 int x = 0;
877                 int y = 0;
878                 istringstream is(cmd.argument);
879                 is >> x >> y;
880                 if (!is)
881                         lyxerr << "SETXY: Could not parse coordinates in '"
882                                << cmd.argument << std::endl;
883                 else
884                         setCursorFromCoordinates(cur, x, y);
885                 break;
886         }
887
888         case LFUN_GETFONT:
889                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
890                         cur.message("E");
891                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
892                         cur.message("N");
893                 else
894                         cur.message("0");
895                 break;
896
897         case LFUN_GETLAYOUT:
898                 cur.message(cur.paragraph().layout()->name());
899                 break;
900
901         case LFUN_LAYOUT: {
902                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
903                   << cmd.argument << endl;
904
905                 // This is not the good solution to the empty argument
906                 // problem, but it will hopefully suffice for 1.2.0.
907                 // The correct solution would be to augument the
908                 // function list/array with information about what
909                 // functions needs arguments and their type.
910                 if (cmd.argument.empty()) {
911                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
912                         break;
913                 }
914
915                 // Derive layout number from given argument (string)
916                 // and current buffer's textclass (number)
917                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
918                 bool hasLayout = tclass.hasLayout(cmd.argument);
919                 string layout = cmd.argument;
920
921                 // If the entry is obsolete, use the new one instead.
922                 if (hasLayout) {
923                         string const & obs = tclass[layout]->obsoleted_by();
924                         if (!obs.empty())
925                                 layout = obs;
926                 }
927
928                 if (!hasLayout) {
929                         cur.errorMessage(string(N_("Layout ")) + cmd.argument +
930                                 N_(" not known"));
931                         break;
932                 }
933
934                 bool change_layout = (current_layout != layout);
935
936                 if (!change_layout && cur.selection() &&
937                         cur.selBegin().par() != cur.selEnd().par())
938                 {
939                         par_type spit = cur.selBegin().par();
940                         par_type epit = cur.selEnd().par() + 1;
941                         while (spit != epit) {
942                                 if (pars_[spit].layout()->name() != current_layout) {
943                                         change_layout = true;
944                                         break;
945                                 }
946                                 ++spit;
947                         }
948                 }
949
950                 if (change_layout) {
951                         current_layout = layout;
952                         setLayout(cur, layout);
953                         bv->owner()->setLayout(layout);
954                         bv->switchKeyMap();
955                 }
956                 break;
957         }
958
959         case LFUN_PASTESELECTION: {
960                 cur.clearSelection();
961                 string const clip = bv->getClipboard();
962                 if (!clip.empty()) {
963                         if (cmd.argument == "paragraph")
964                                 insertStringAsParagraphs(cur, clip);
965                         else
966                                 insertStringAsLines(cur, clip);
967                 }
968                 break;
969         }
970
971         case LFUN_GOTOERROR:
972                 gotoInset(cur, InsetBase::ERROR_CODE, false);
973                 break;
974
975         case LFUN_GOTONOTE:
976                 gotoInset(cur, InsetBase::NOTE_CODE, false);
977                 break;
978
979         case LFUN_REFERENCE_GOTO: {
980                 vector<InsetOld_code> tmp;
981                 tmp.push_back(InsetBase::LABEL_CODE);
982                 tmp.push_back(InsetBase::REF_CODE);
983                 gotoInset(cur, tmp, true);
984                 break;
985         }
986
987         case LFUN_QUOTE: {
988                 lyx::cap::replaceSelection(cur);
989                 Paragraph & par = cur.paragraph();
990                 lyx::pos_type pos = cur.pos();
991                 char c;
992                 if (pos == 0)
993                         c = ' ';
994                 else if (cur.prevInset() && cur.prevInset()->isSpace())
995                         c = ' ';
996                 else
997                         c = par.getChar(pos - 1);
998
999                 LyXLayout_ptr const & style = par.layout();
1000
1001                 BufferParams const & bufparams = bv->buffer()->params();
1002                 if (!style->pass_thru
1003                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1004                         string arg = cmd.argument;
1005                         if (arg == "single")
1006                                 cur.insert(new InsetQuotes(c,
1007                                     bufparams.quotes_language,
1008                                     InsetQuotes::SingleQ));
1009                         else if (arg == "double")
1010                                 cur.insert(new InsetQuotes(c,
1011                                     bufparams.quotes_language,
1012                                     InsetQuotes::DoubleQ));
1013                         else
1014                                 cur.insert(new InsetQuotes(c, bufparams));
1015                         cur.posRight();
1016                 }
1017                 else
1018                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1019                 break;
1020         }
1021
1022         case LFUN_DATE_INSERT: {
1023                 lyx::cap::replaceSelection(cur);
1024                 time_t now_time_t = time(NULL);
1025                 struct tm * now_tm = localtime(&now_time_t);
1026                 setlocale(LC_TIME, "");
1027                 string arg;
1028                 if (!cmd.argument.empty())
1029                         arg = cmd.argument;
1030                 else
1031                         arg = lyxrc.date_insert_format;
1032                 char datetmp[32];
1033                 int const datetmp_len =
1034                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1035
1036                 for (int i = 0; i < datetmp_len; i++)
1037                         insertChar(cur, datetmp[i]);
1038
1039                 cur.resetAnchor();
1040                 moveCursor(cur, false);
1041                 break;
1042         }
1043
1044         case LFUN_MOUSE_TRIPLE:
1045                 if (cmd.button() == mouse_button::button1) {
1046                         selection_possible = true;
1047                         cursorHome(cur);
1048                         cur.resetAnchor();
1049                         cursorEnd(cur);
1050                         cur.setSelection();
1051                         bv->haveSelection(cur.selection());
1052                 }
1053                 break;
1054
1055         case LFUN_MOUSE_DOUBLE:
1056                 if (cmd.button() == mouse_button::button1) {
1057                         selection_possible = true;
1058                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
1059                         bv->haveSelection(cur.selection());
1060                 }
1061                 break;
1062
1063         case LFUN_MOUSE_MOTION: {
1064                 // Only use motion with button 1
1065                 //if (cmd.button() != mouse_button::button1)
1066                 //      return false;
1067                 // We want to use only motion events for which
1068                 // the button press event was on the drawing area too.
1069                 if (!selection_possible) {
1070                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1071                                 "dispatch: no selection possible\n";
1072                         lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
1073                         break;
1074                 }
1075
1076                 // ignore motions deeper nested than the real anchor
1077                 LCursor & bvcur = cur.bv().cursor();
1078                 if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
1079                         break;
1080
1081                 CursorSlice old = cur.top();
1082                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1083
1084                 // This is to allow jumping over large insets
1085                 // FIXME: shouldn't be top-text-specific
1086                 if (isMainText() && cur.top() == old) {
1087                         if (cmd.y - bv->top_y() >= bv->workHeight())
1088                                 cursorDown(cur);
1089                         else if (cmd.y - bv->top_y() < 0)
1090                                 cursorUp(cur);
1091                 }
1092
1093                 // don't set anchor_
1094                 bv->cursor().setCursor(cur);
1095                 bv->cursor().selection() = true;
1096                 lyxerr << "MOTION: " << bv->cursor() << endl;
1097                 break;
1098         }
1099
1100         // Single-click on work area
1101         case LFUN_MOUSE_PRESS: {
1102                 // Right click on a footnote flag opens float menu
1103                 if (cmd.button() == mouse_button::button3) {
1104                         cur.clearSelection();
1105                         selection_possible = false;
1106                         break;
1107                 }
1108
1109                 // Middle button press pastes if we have a selection
1110                 // We do this here as if the selection was inside an inset
1111                 // it could get cleared on the unlocking of the inset so
1112                 // we have to check this first
1113                 bool paste_internally = false;
1114                 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1115                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1116                         paste_internally = true;
1117                 }
1118
1119                 selection_possible = true;
1120
1121                 // Clear the selection
1122                 cur.clearSelection();
1123
1124                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1125                 cur.resetAnchor();
1126                 finishUndo();
1127                 cur.x_target() = cursorX(cur.top());
1128
1129                 // Has the cursor just left the inset?
1130                 if (bv->cursor().inMathed() && !cur.inMathed())
1131                         bv->cursor().inset().notifyCursorLeaves(bv->cursor());
1132
1133                 // Set cursor here.
1134                 bv->cursor() = cur;
1135
1136                 // Don't allow selection after a big jump.
1137                 if (bv->fitCursor())
1138                         selection_possible = false;
1139
1140                 // Insert primary selection with middle mouse
1141                 // if there is a local selection in the current buffer,
1142                 // insert this
1143                 if (cmd.button() == mouse_button::button2) {
1144                         if (paste_internally)
1145                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1146                         else
1147                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1148                         selection_possible = false;
1149                 }
1150
1151                 break;
1152         }
1153
1154         case LFUN_MOUSE_RELEASE: {
1155                 selection_possible = false;
1156
1157                 if (cmd.button() == mouse_button::button2)
1158                         break;
1159
1160                 // finish selection
1161                 if (cmd.button() == mouse_button::button1)
1162                         bv->haveSelection(cur.selection());
1163
1164                 bv->switchKeyMap();
1165                 bv->owner()->updateMenubar();
1166                 bv->owner()->updateToolbars();
1167                 break;
1168         }
1169
1170         case LFUN_SELFINSERT: {
1171                 if (cmd.argument.empty())
1172                         break;
1173
1174                 // Automatically delete the currently selected
1175                 // text and replace it with what is being
1176                 // typed in now. Depends on lyxrc settings
1177                 // "auto_region_delete", which defaults to
1178                 // true (on).
1179
1180                 if (lyxrc.auto_region_delete) {
1181                         if (cur.selection())
1182                                 cutSelection(cur, false, false);
1183                         bv->haveSelection(false);
1184                 }
1185
1186                 cur.clearSelection();
1187                 LyXFont const old_font = real_current_font;
1188
1189                 string::const_iterator cit = cmd.argument.begin();
1190                 string::const_iterator end = cmd.argument.end();
1191                 for (; cit != end; ++cit)
1192                         bv->owner()->getIntl().getTransManager().
1193                                 TranslateAndInsert(*cit, this);
1194
1195                 cur.resetAnchor();
1196                 moveCursor(cur, false);
1197
1198                 // real_current_font.number can change so we need to
1199                 // update the minibuffer
1200                 if (old_font != real_current_font)
1201                 bv->updateScrollbar();
1202                 break;
1203         }
1204
1205         case LFUN_URL: {
1206                 InsetCommandParams p("url");
1207                 string const data = InsetCommandMailer::params2string("url", p);
1208                 bv->owner()->getDialogs().show("url", data, 0);
1209                 break;
1210         }
1211
1212         case LFUN_HTMLURL: {
1213                 InsetCommandParams p("htmlurl");
1214                 string const data = InsetCommandMailer::params2string("url", p);
1215                 bv->owner()->getDialogs().show("url", data, 0);
1216                 break;
1217         }
1218
1219         case LFUN_INSERT_LABEL: {
1220                 // Try to generate a valid label
1221                 string const contents = cmd.argument.empty() ?
1222                         cur.getPossibleLabel() : cmd.argument;
1223
1224                 InsetCommandParams p("label", contents);
1225                 string const data = InsetCommandMailer::params2string("label", p);
1226
1227                 if (cmd.argument.empty()) {
1228                         bv->owner()->getDialogs().show("label", data, 0);
1229                 } else {
1230                         FuncRequest fr(LFUN_INSET_INSERT, data);
1231                         dispatch(cur, fr);
1232                 }
1233                 break;
1234         }
1235
1236
1237 #if 0
1238         case LFUN_INSET_LIST:
1239         case LFUN_INSET_THEOREM:
1240         case LFUN_INSET_CAPTION:
1241 #endif
1242         case LFUN_INSERT_NOTE:
1243         case LFUN_INSERT_CHARSTYLE:
1244         case LFUN_INSERT_BOX:
1245         case LFUN_INSERT_BRANCH:
1246         case LFUN_INSERT_BIBITEM:
1247         case LFUN_INSET_ERT:
1248         case LFUN_INSET_FLOAT:
1249         case LFUN_INSET_FOOTNOTE:
1250         case LFUN_INSET_MARGINAL:
1251         case LFUN_INSET_OPTARG:
1252         case LFUN_INSET_WIDE_FLOAT:
1253         case LFUN_INSET_WRAP:
1254         case LFUN_TABULAR_INSERT:
1255         case LFUN_ENVIRONMENT_INSERT:
1256                 // Open the inset, and move the current selection
1257                 // inside it.
1258                 doInsertInset(cur, this, cmd, true, true);
1259                 cur.posRight();
1260                 break;
1261
1262         case LFUN_INDEX_INSERT:
1263                 // Just open the inset
1264                 doInsertInset(cur, this, cmd, true, false);
1265                 cur.posRight();
1266                 break;
1267
1268         case LFUN_INDEX_PRINT:
1269         case LFUN_TOC_INSERT:
1270         case LFUN_HFILL:
1271         case LFUN_INSERT_LINE:
1272         case LFUN_INSERT_PAGEBREAK:
1273                 // do nothing fancy
1274                 doInsertInset(cur, this, cmd, false, false);
1275                 cur.posRight();
1276                 break;
1277
1278         case LFUN_DEPTH_MIN:
1279                 changeDepth(cur, DEC_DEPTH);
1280                 break;
1281
1282         case LFUN_DEPTH_PLUS:
1283                 changeDepth(cur, INC_DEPTH);
1284                 break;
1285
1286         case LFUN_MATH_DISPLAY:
1287                 mathDispatch(cur, cmd, true);
1288                 break;
1289
1290         case LFUN_MATH_IMPORT_SELECTION:
1291         case LFUN_MATH_MODE:
1292                 mathDispatch(cur, cmd, false);
1293                 break;
1294
1295         case LFUN_MATH_MACRO:
1296                 if (cmd.argument.empty())
1297                         cur.errorMessage(N_("Missing argument"));
1298                 else {
1299                         string s = cmd.argument;
1300                         string const s1 = token(s, ' ', 1);
1301                         int const nargs = s1.empty() ? 0 : atoi(s1);
1302                         string const s2 = token(s, ' ', 2);
1303                         string const type = s2.empty() ? "newcommand" : s2;
1304                         cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
1305                         //cur.nextInset()->edit(cur, true);
1306                 }
1307                 break;
1308
1309         case LFUN_INSERT_MATH:
1310         case LFUN_INSERT_MATRIX:
1311         case LFUN_MATH_DELIM: {
1312                 cur.insert(new MathHullInset);
1313                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1314                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1315                 cur.dispatch(cmd);
1316                 break;
1317         }
1318
1319         case LFUN_EMPH: {
1320                 LyXFont font(LyXFont::ALL_IGNORE);
1321                 font.setEmph(LyXFont::TOGGLE);
1322                 toggleAndShow(cur, this, font);
1323                 break;
1324         }
1325
1326         case LFUN_BOLD: {
1327                 LyXFont font(LyXFont::ALL_IGNORE);
1328                 font.setSeries(LyXFont::BOLD_SERIES);
1329                 toggleAndShow(cur, this, font);
1330                 break;
1331         }
1332
1333         case LFUN_NOUN: {
1334                 LyXFont font(LyXFont::ALL_IGNORE);
1335                 font.setNoun(LyXFont::TOGGLE);
1336                 toggleAndShow(cur, this, font);
1337                 break;
1338         }
1339
1340         case LFUN_CODE: {
1341                 LyXFont font(LyXFont::ALL_IGNORE);
1342                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1343                 toggleAndShow(cur, this, font);
1344                 break;
1345         }
1346
1347         case LFUN_SANS: {
1348                 LyXFont font(LyXFont::ALL_IGNORE);
1349                 font.setFamily(LyXFont::SANS_FAMILY);
1350                 toggleAndShow(cur, this, font);
1351                 break;
1352         }
1353
1354         case LFUN_ROMAN: {
1355                 LyXFont font(LyXFont::ALL_IGNORE);
1356                 font.setFamily(LyXFont::ROMAN_FAMILY);
1357                 toggleAndShow(cur, this, font);
1358                 break;
1359         }
1360
1361         case LFUN_DEFAULT: {
1362                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1363                 toggleAndShow(cur, this, font);
1364                 break;
1365         }
1366
1367         case LFUN_UNDERLINE: {
1368                 LyXFont font(LyXFont::ALL_IGNORE);
1369                 font.setUnderbar(LyXFont::TOGGLE);
1370                 toggleAndShow(cur, this, font);
1371                 break;
1372         }
1373
1374         case LFUN_FONT_SIZE: {
1375                 LyXFont font(LyXFont::ALL_IGNORE);
1376                 font.setLyXSize(cmd.argument);
1377                 toggleAndShow(cur, this, font);
1378                 break;
1379         }
1380
1381         case LFUN_LANGUAGE: {
1382                 Language const * lang = languages.getLanguage(cmd.argument);
1383                 if (!lang)
1384                         break;
1385                 LyXFont font(LyXFont::ALL_IGNORE);
1386                 font.setLanguage(lang);
1387                 toggleAndShow(cur, this, font);
1388                 bv->switchKeyMap();
1389                 break;
1390         }
1391
1392         case LFUN_FREEFONT_APPLY:
1393                 toggleAndShow(cur, this, freefont, toggleall);
1394                 cur.message(_("Character set"));
1395                 break;
1396
1397         // Set the freefont using the contents of \param data dispatched from
1398         // the frontends and apply it at the current cursor location.
1399         case LFUN_FREEFONT_UPDATE: {
1400                 LyXFont font;
1401                 bool toggle;
1402                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1403                         freefont = font;
1404                         toggleall = toggle;
1405                         toggleAndShow(cur, this, freefont, toggleall);
1406                         cur.message(_("Character set"));
1407                 }
1408                 break;
1409         }
1410
1411         case LFUN_FINISHED_LEFT:
1412                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
1413                 break;
1414
1415         case LFUN_FINISHED_RIGHT:
1416                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
1417                 ++cur.pos();
1418                 break;
1419
1420         case LFUN_FINISHED_UP:
1421                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_UP:\n" << cur << endl;
1422                 cursorUp(cur);
1423                 break;
1424
1425         case LFUN_FINISHED_DOWN:
1426                 lyxerr[Debug::DEBUG] << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
1427                 cursorDown(cur);
1428                 break;
1429
1430         case LFUN_LAYOUT_PARAGRAPH: {
1431                 string data;
1432                 params2string(cur.paragraph(), data);
1433                 data = "show\n" + data;
1434                 bv->owner()->getDialogs().show("paragraph", data);
1435                 break;
1436         }
1437
1438         case LFUN_PARAGRAPH_UPDATE: {
1439                 if (!bv->owner()->getDialogs().visible("paragraph"))
1440                         break;
1441                 string data;
1442                 params2string(cur.paragraph(), data);
1443
1444                 // Will the paragraph accept changes from the dialog?
1445                 InsetBase & inset = cur.inset();
1446                 bool const accept = !inset.forceDefaultParagraphs(&inset);
1447
1448                 data = "update " + tostr(accept) + '\n' + data;
1449                 bv->owner()->getDialogs().update("paragraph", data);
1450                 break;
1451         }
1452
1453         case LFUN_UMLAUT:
1454         case LFUN_CIRCUMFLEX:
1455         case LFUN_GRAVE:
1456         case LFUN_ACUTE:
1457         case LFUN_TILDE:
1458         case LFUN_CEDILLA:
1459         case LFUN_MACRON:
1460         case LFUN_DOT:
1461         case LFUN_UNDERDOT:
1462         case LFUN_UNDERBAR:
1463         case LFUN_CARON:
1464         case LFUN_SPECIAL_CARON:
1465         case LFUN_BREVE:
1466         case LFUN_TIE:
1467         case LFUN_HUNG_UMLAUT:
1468         case LFUN_CIRCLE:
1469         case LFUN_OGONEK:
1470                 bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
1471                 if (!cmd.argument.empty())
1472                         bv->owner()->getIntl().getTransManager()
1473                                 .TranslateAndInsert(cmd.argument[0], this);
1474                 break;
1475
1476         case LFUN_FLOAT_LIST: {
1477                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
1478                 if (tclass.floats().typeExist(cmd.argument)) {
1479                         // not quite sure if we want this...
1480                         recordUndo(cur);
1481                         cur.clearSelection();
1482                         breakParagraph(cur);
1483
1484                         if (cur.lastpos() != 0) {
1485                                 cursorLeft(cur);
1486                                 breakParagraph(cur);
1487                         }
1488
1489                         setLayout(cur, tclass.defaultLayoutName());
1490                         setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
1491                         insertInset(cur, new InsetFloatList(cmd.argument));
1492                 } else {
1493                         lyxerr << "Non-existent float type: "
1494                                << cmd.argument << endl;
1495                 }
1496                 break;
1497         }
1498
1499         case LFUN_ACCEPT_CHANGE: {
1500                 acceptChange(cur);
1501                 break;
1502         }
1503
1504         case LFUN_REJECT_CHANGE: {
1505                 rejectChange(cur);
1506                 break;
1507         }
1508
1509         case LFUN_THESAURUS_ENTRY: {
1510                 string arg = cmd.argument;
1511                 if (arg.empty()) {
1512                         arg = cur.selectionAsString(false);
1513                         // FIXME
1514                         if (arg.size() > 100 || arg.empty()) {
1515                                 // Get word or selection
1516                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1517                                 arg = cur.selectionAsString(false);
1518                         }
1519                 }
1520                 bv->owner()->getDialogs().show("thesaurus", arg);
1521                 break;
1522         }
1523
1524         case LFUN_PARAGRAPH_APPLY: {
1525                 // Given data, an encoding of the ParagraphParameters
1526                 // generated in the Paragraph dialog, this function sets
1527                 // the current paragraph appropriately.
1528                 istringstream is(cmd.argument);
1529                 LyXLex lex(0, 0);
1530                 lex.setStream(is);
1531                 ParagraphParameters params;
1532                 params.read(lex);
1533                 setParagraph(cur,
1534                                          params.spacing(),
1535                                          params.align(),
1536                                          params.labelWidthString(),
1537                                          params.noindent());
1538                 cur.message(_("Paragraph layout set"));
1539                 break;
1540         }
1541
1542         case LFUN_INSET_DIALOG_SHOW: {
1543                 InsetBase * inset = cur.nextInset();
1544                 if (inset) {
1545                         FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1546                         inset->dispatch(cur, fr);
1547                 }
1548                 break;
1549         }
1550
1551         case LFUN_ESCAPE:
1552                 if (cur.selection()) {
1553                         cur.selection() = false;
1554                 } else {
1555                         cur.undispatched();
1556                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
1557                 }
1558                 break;
1559
1560         default:
1561                 cur.undispatched();
1562                 break;
1563         }
1564
1565         // avoid to update when navigating
1566         if (moving
1567             && &sl.inset() == &cur.inset()
1568             && sl.idx() == cur.idx()
1569             && sel == false
1570             && cur.selection() == false)
1571                 cur.noUpdate();
1572 }
1573
1574
1575 bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
1576         FuncStatus & flag) const
1577 {
1578         BOOST_ASSERT(cur.text() == this);
1579         LyXFont const & font = real_current_font;
1580         bool enable = true;
1581
1582         switch (cmd.action) {
1583
1584         case LFUN_DEPTH_MIN:
1585                 enable = changeDepthAllowed(cur, DEC_DEPTH);
1586                 break;
1587
1588         case LFUN_DEPTH_PLUS:
1589                 enable = changeDepthAllowed(cur, INC_DEPTH);
1590                 break;
1591
1592         case LFUN_INSET_OPTARG:
1593                 enable = cur.paragraph().layout()->optionalargs;
1594                 break;
1595
1596         case LFUN_APPENDIX:
1597                 flag.setOnOff(cur.paragraph().params().startOfAppendix());
1598                 break;
1599
1600 #if 0
1601         // the functions which insert insets
1602         InsetOld::Code code = InsetOld::NO_CODE;
1603         switch (cmd.action) {
1604         case LFUN_DIALOG_SHOW_NEW_INSET:
1605                 if (cmd.argument == "bibitem")
1606                         code = InsetOld::BIBITEM_CODE;
1607                 else if (cmd.argument == "bibtex")
1608                         code = InsetOld::BIBTEX_CODE;
1609                 else if (cmd.argument == "box")
1610                         code = InsetOld::BOX_CODE;
1611                 else if (cmd.argument == "branch")
1612                         code = InsetOld::BRANCH_CODE;
1613                 else if (cmd.argument == "citation")
1614                         code = InsetOld::CITE_CODE;
1615                 else if (cmd.argument == "ert")
1616                         code = InsetOld::ERT_CODE;
1617                 else if (cmd.argument == "external")
1618                         code = InsetOld::EXTERNAL_CODE;
1619                 else if (cmd.argument == "float")
1620                         code = InsetOld::FLOAT_CODE;
1621                 else if (cmd.argument == "graphics")
1622                         code = InsetOld::GRAPHICS_CODE;
1623                 else if (cmd.argument == "include")
1624                         code = InsetOld::INCLUDE_CODE;
1625                 else if (cmd.argument == "index")
1626                         code = InsetOld::INDEX_CODE;
1627                 else if (cmd.argument == "label")
1628                         code = InsetOld::LABEL_CODE;
1629                 else if (cmd.argument == "note")
1630                         code = InsetOld::NOTE_CODE;
1631                 else if (cmd.argument == "ref")
1632                         code = InsetOld::REF_CODE;
1633                 else if (cmd.argument == "toc")
1634                         code = InsetOld::TOC_CODE;
1635                 else if (cmd.argument == "url")
1636                         code = InsetOld::URL_CODE;
1637                 else if (cmd.argument == "vspace")
1638                         code = InsetOld::VSPACE_CODE;
1639                 else if (cmd.argument == "wrap")
1640                         code = InsetOld::WRAP_CODE;
1641                 break;
1642
1643         case LFUN_INSET_ERT:
1644                 code = InsetOld::ERT_CODE;
1645                 break;
1646         case LFUN_INSET_FOOTNOTE:
1647                 code = InsetOld::FOOT_CODE;
1648                 break;
1649         case LFUN_TABULAR_INSERT:
1650                 code = InsetOld::TABULAR_CODE;
1651                 break;
1652         case LFUN_INSET_MARGINAL:
1653                 code = InsetOld::MARGIN_CODE;
1654                 break;
1655         case LFUN_INSET_FLOAT:
1656         case LFUN_INSET_WIDE_FLOAT:
1657                 code = InsetOld::FLOAT_CODE;
1658                 break;
1659         case LFUN_INSET_WRAP:
1660                 code = InsetOld::WRAP_CODE;
1661                 break;
1662         case LFUN_FLOAT_LIST:
1663                 code = InsetOld::FLOAT_LIST_CODE;
1664                 break;
1665 #if 0
1666         case LFUN_INSET_LIST:
1667                 code = InsetOld::LIST_CODE;
1668                 break;
1669         case LFUN_INSET_THEOREM:
1670                 code = InsetOld::THEOREM_CODE;
1671                 break;
1672 #endif
1673         case LFUN_INSET_CAPTION:
1674                 code = InsetOld::CAPTION_CODE;
1675                 break;
1676         case LFUN_INSERT_NOTE:
1677                 code = InsetOld::NOTE_CODE;
1678                 break;
1679         case LFUN_INSERT_CHARSTYLE:
1680                 code = InsetOld::CHARSTYLE_CODE;
1681                 if (buf->params().getLyXTextClass().charstyles().empty())
1682                         enable = false;
1683                 break;
1684         case LFUN_INSERT_BOX:
1685                 code = InsetOld::BOX_CODE;
1686                 break;
1687         case LFUN_INSERT_BRANCH:
1688                 code = InsetOld::BRANCH_CODE;
1689                 if (buf->params().branchlist().empty())
1690                         enable = false;
1691                 break;
1692         case LFUN_INSERT_LABEL:
1693                 code = InsetOld::LABEL_CODE;
1694                 break;
1695         case LFUN_INSET_OPTARG:
1696                 code = InsetOld::OPTARG_CODE;
1697                 break;
1698         case LFUN_ENVIRONMENT_INSERT:
1699                 code = InsetOld::BOX_CODE;
1700                 break;
1701         case LFUN_INDEX_INSERT:
1702                 code = InsetOld::INDEX_CODE;
1703                 break;
1704         case LFUN_INDEX_PRINT:
1705                 code = InsetOld::INDEX_PRINT_CODE;
1706                 break;
1707         case LFUN_TOC_INSERT:
1708                 code = InsetOld::TOC_CODE;
1709                 break;
1710         case LFUN_HTMLURL:
1711         case LFUN_URL:
1712                 code = InsetOld::URL_CODE;
1713                 break;
1714         case LFUN_QUOTE:
1715                 // always allow this, since we will inset a raw quote
1716                 // if an inset is not allowed.
1717                 break;
1718         case LFUN_HYPHENATION:
1719         case LFUN_LIGATURE_BREAK:
1720         case LFUN_HFILL:
1721         case LFUN_MENU_SEPARATOR:
1722         case LFUN_LDOTS:
1723         case LFUN_END_OF_SENTENCE:
1724                 code = InsetOld::SPECIALCHAR_CODE;
1725                 break;
1726         case LFUN_SPACE_INSERT:
1727                 // slight hack: we know this is allowed in math mode
1728                 if (cur.inTexted())
1729                         code = InsetOld::SPACE_CODE;
1730                 break;
1731         case LFUN_INSET_DIALOG_SHOW: {
1732                 InsetBase * inset = cur.nextInset();
1733                 enable = inset;
1734                 if (inset) {
1735                         code = inset->lyxCode();
1736                         if (!(code == InsetOld::INCLUDE_CODE
1737                                 || code == InsetOld::BIBTEX_CODE
1738                                 || code == InsetOld::FLOAT_LIST_CODE
1739                                 || code == InsetOld::TOC_CODE))
1740                                 enable = false;
1741                 }
1742                 break;
1743         }
1744         default:
1745                 break;
1746         }
1747
1748         if (code != InsetOld::NO_CODE
1749                         && (cur.empty() || !cur.inset().insetAllowed(code)))
1750                 enable = false;
1751
1752 #endif
1753
1754         case LFUN_DIALOG_SHOW_NEW_INSET:
1755         case LFUN_INSET_ERT:
1756         case LFUN_INSERT_BOX:
1757         case LFUN_INSERT_BRANCH:
1758         case LFUN_ENVIRONMENT_INSERT:
1759         case LFUN_INDEX_INSERT:
1760         case LFUN_INDEX_PRINT:
1761         case LFUN_TOC_INSERT:
1762         case LFUN_HTMLURL:
1763         case LFUN_URL:
1764         case LFUN_QUOTE:
1765         case LFUN_HYPHENATION:
1766         case LFUN_LIGATURE_BREAK:
1767         case LFUN_HFILL:
1768         case LFUN_MENU_SEPARATOR:
1769         case LFUN_LDOTS:
1770         case LFUN_END_OF_SENTENCE:
1771         case LFUN_SPACE_INSERT:
1772         case LFUN_INSET_DIALOG_SHOW:
1773                 break;
1774
1775         case LFUN_EMPH:
1776                 flag.setOnOff(font.emph() == LyXFont::ON);
1777                 break;
1778
1779         case LFUN_NOUN:
1780                 flag.setOnOff(font.noun() == LyXFont::ON);
1781                 break;
1782
1783         case LFUN_BOLD:
1784                 flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
1785                 break;
1786
1787         case LFUN_SANS:
1788                 flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
1789                 break;
1790
1791         case LFUN_ROMAN:
1792                 flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
1793                 break;
1794
1795         case LFUN_CODE:
1796                 flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
1797                 break;
1798
1799         case LFUN_DELETE_WORD_FORWARD:
1800         case LFUN_DELETE_WORD_BACKWARD:
1801         case LFUN_DELETE_LINE_FORWARD:
1802         case LFUN_WORDRIGHT:
1803         case LFUN_WORDLEFT:
1804         case LFUN_RIGHT:
1805         case LFUN_RIGHTSEL:
1806         case LFUN_LEFT:
1807         case LFUN_LEFTSEL:
1808         case LFUN_UP:
1809         case LFUN_UPSEL:
1810         case LFUN_DOWN:
1811         case LFUN_DOWNSEL:
1812         case LFUN_UP_PARAGRAPHSEL:
1813         case LFUN_DOWN_PARAGRAPHSEL:
1814         case LFUN_PRIORSEL:
1815         case LFUN_NEXTSEL:
1816         case LFUN_HOMESEL:
1817         case LFUN_ENDSEL:
1818         case LFUN_WORDRIGHTSEL:
1819         case LFUN_WORDLEFTSEL:
1820         case LFUN_WORDSEL:
1821         case LFUN_UP_PARAGRAPH:
1822         case LFUN_DOWN_PARAGRAPH:
1823         case LFUN_PRIOR:
1824         case LFUN_NEXT:
1825         case LFUN_HOME:
1826         case LFUN_END:
1827         case LFUN_BREAKLINE:
1828         case LFUN_DELETE:
1829         case LFUN_DELETE_SKIP:
1830         case LFUN_BACKSPACE:
1831         case LFUN_BACKSPACE_SKIP:
1832         case LFUN_BREAKPARAGRAPH:
1833         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1834         case LFUN_BREAKPARAGRAPH_SKIP:
1835         case LFUN_PARAGRAPH_SPACING:
1836         case LFUN_INSET_APPLY:
1837         case LFUN_INSET_INSERT:
1838         case LFUN_NEXT_INSET_TOGGLE:
1839         case LFUN_UPCASE_WORD:
1840         case LFUN_LOWCASE_WORD:
1841         case LFUN_CAPITALIZE_WORD:
1842         case LFUN_TRANSPOSE_CHARS:
1843         case LFUN_PASTE:
1844         case LFUN_CUT:
1845         case LFUN_COPY:
1846         case LFUN_GETXY:
1847         case LFUN_SETXY:
1848         case LFUN_GETFONT:
1849         case LFUN_GETLAYOUT:
1850         case LFUN_LAYOUT:
1851         case LFUN_PASTESELECTION:
1852         case LFUN_GOTOERROR:
1853         case LFUN_GOTONOTE:
1854         case LFUN_REFERENCE_GOTO:
1855         case LFUN_DATE_INSERT:
1856         case LFUN_SELFINSERT:
1857         case LFUN_INSERT_LABEL:
1858         case LFUN_INSERT_NOTE:
1859         case LFUN_INSERT_CHARSTYLE:
1860         case LFUN_INSERT_BIBITEM:
1861         case LFUN_INSET_FLOAT:
1862         case LFUN_INSET_FOOTNOTE:
1863         case LFUN_INSET_MARGINAL:
1864         case LFUN_INSET_WIDE_FLOAT:
1865         case LFUN_INSET_WRAP:
1866         case LFUN_TABULAR_INSERT:
1867         case LFUN_INSERT_LINE:
1868         case LFUN_INSERT_PAGEBREAK:
1869         case LFUN_MATH_DISPLAY:
1870         case LFUN_MATH_IMPORT_SELECTION:
1871         case LFUN_MATH_MODE:
1872         case LFUN_MATH_MACRO:
1873         case LFUN_INSERT_MATH:
1874         case LFUN_INSERT_MATRIX:
1875         case LFUN_MATH_DELIM:
1876         case LFUN_DEFAULT:
1877         case LFUN_UNDERLINE:
1878         case LFUN_FONT_SIZE:
1879         case LFUN_LANGUAGE:
1880         case LFUN_FREEFONT_APPLY:
1881         case LFUN_FREEFONT_UPDATE:
1882         case LFUN_LAYOUT_PARAGRAPH:
1883         case LFUN_PARAGRAPH_UPDATE:
1884         case LFUN_UMLAUT:
1885         case LFUN_CIRCUMFLEX:
1886         case LFUN_GRAVE:
1887         case LFUN_ACUTE:
1888         case LFUN_TILDE:
1889         case LFUN_CEDILLA:
1890         case LFUN_MACRON:
1891         case LFUN_DOT:
1892         case LFUN_UNDERDOT:
1893         case LFUN_UNDERBAR:
1894         case LFUN_CARON:
1895         case LFUN_SPECIAL_CARON:
1896         case LFUN_BREVE:
1897         case LFUN_TIE:
1898         case LFUN_HUNG_UMLAUT:
1899         case LFUN_CIRCLE:
1900         case LFUN_OGONEK:
1901         case LFUN_FLOAT_LIST:
1902         case LFUN_ACCEPT_CHANGE:
1903         case LFUN_REJECT_CHANGE:
1904         case LFUN_THESAURUS_ENTRY:
1905         case LFUN_PARAGRAPH_APPLY:
1906         case LFUN_ESCAPE:
1907         case LFUN_KEYMAP_TOGGLE:
1908                 // these are handled in our dispatch()
1909                 enable = true;
1910                 break;
1911
1912         case LFUN_ENDBUF:
1913         case LFUN_BEGINNINGBUF:
1914                 enable = true;
1915                 break;
1916
1917         default:
1918                 enable = false;
1919                 break;
1920         }
1921         flag.enabled(enable);
1922         return true;
1923 }