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