]> git.lyx.org Git - lyx.git/blob - src/text3.C
e584b7540704262212ee0fff1d2fdbab3d31ec8d
[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 "buffer.h"
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "cursor.h"
24 #include "debug.h"
25 #include "dispatchresult.h"
26 #include "factory.h"
27 #include "FloatList.h"
28 #include "funcrequest.h"
29 #include "gettext.h"
30 #include "intl.h"
31 #include "language.h"
32 #include "lyxfunc.h"
33 #include "lyxlex.h"
34 #include "lyxrc.h"
35 #include "lyxrow.h"
36 #include "paragraph.h"
37 #include "paragraph_funcs.h"
38 #include "ParagraphParameters.h"
39 #include "undo.h"
40 #include "vspace.h"
41
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
44
45 #include "insets/insetcommand.h"
46 #include "insets/insetfloatlist.h"
47 #include "insets/insetnewline.h"
48 #include "insets/insetquotes.h"
49 #include "insets/insetspecialchar.h"
50 #include "insets/insettext.h"
51
52 #include "support/lstrings.h"
53 #include "support/lyxlib.h"
54 #include "support/tostr.h"
55 #include "support/std_sstream.h"
56
57 #include "mathed/math_hullinset.h"
58 #include "mathed/formulamacro.h"
59
60 #include <clocale>
61
62 using lyx::pos_type;
63
64 using lyx::support::isStrUnsignedInt;
65 using lyx::support::strToUnsignedInt;
66 using lyx::support::atoi;
67 using lyx::support::token;
68
69 using std::endl;
70 using std::find;
71 using std::string;
72 using std::istringstream;
73 using std::vector;
74
75
76 extern string current_layout;
77
78 // the selection possible is needed, that only motion events are
79 // used, where the button press event was on the drawing area too
80 bool selection_possible = false;
81
82
83 namespace {
84
85         // globals...
86         LyXFont freefont(LyXFont::ALL_IGNORE);
87         bool toggleall = false;
88
89
90         void toggleAndShow(LCursor & cur, LyXText * text,
91                 LyXFont const & font, bool toggleall = true)
92         {
93                 text->toggleFree(cur, font, toggleall);
94
95                 if (font.language() != ignore_language ||
96                                 font.number() != LyXFont::IGNORE) {
97                         Paragraph & par = cur.paragraph();
98                         text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
99                         if (cur.boundary() !=
100                                         text->bidi.isBoundary(*cur.bv().buffer(), par,
101                                                         cur.pos(),
102                                                         text->real_current_font))
103                                 text->setCursor(cur, cur.par(), cur.pos(),
104                                                 false, !cur.boundary());
105                 }
106         }
107
108
109         void moveCursor(LCursor & cur, bool selecting)
110         {
111                 if (selecting || cur.mark())
112                         cur.setSelection();
113                 if (!cur.selection())
114                         cur.bv().haveSelection(false);
115                 cur.bv().switchKeyMap();
116         }
117
118
119         void finishChange(LCursor & cur, bool selecting)
120         {
121                 finishUndo();
122                 moveCursor(cur, selecting);
123         }
124
125
126         void mathDispatch(LCursor & cur, LyXText * text,
127                 FuncRequest const & cmd, bool display)
128         {
129                 recordUndo(cur);
130                 string sel = cur.selectionAsString(false);
131                 lyxerr << "selection is: '" << sel << "'" << endl;
132
133                 if (sel.empty()) {
134                         cur.insert(new MathHullInset);
135                         cur.dispatch(FuncRequest(LFUN_RIGHT));
136                         cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
137                         // don't do that also for LFUN_MATH_MODE unless you want end up with
138                         // always changing to mathrm when opening an inlined inset
139                         // -- I really hate "LyXfunc overloading"...
140                         if (display)
141                                 cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
142                         cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
143                 } else {
144                         // create a macro if we see "\\newcommand" somewhere, and an ordinary
145                         // formula otherwise
146                         text->cutSelection(cur, true, true);
147                         if (sel.find("\\newcommand") == string::npos
148                             && sel.find("\\def") == string::npos)
149                         {
150                                 cur.insert(new MathHullInset);
151                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
152                                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
153                                 cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
154                         } else {
155                                 cur.insert(new InsetFormulaMacro(sel));
156                                 cur.dispatch(FuncRequest(LFUN_RIGHT));
157                         }
158                 }
159                 cur.message(N_("Math editor mode"));
160         }
161
162 } // namespace anon
163
164
165
166 namespace bv_funcs {
167
168 string const freefont2string()
169 {
170         string data;
171         if (font2string(freefont, toggleall, data))
172                 return data;
173         return string();
174 }
175
176 }
177
178
179 //takes absolute x,y coordinates
180 InsetBase * LyXText::checkInsetHit(int x, int y)
181 {
182         ParagraphList::iterator pit;
183         ParagraphList::iterator end;
184
185         getParsInRange(paragraphs(),
186                        bv()->top_y() - yo_,
187                        bv()->top_y() - yo_ + bv()->workHeight(),
188                        pit, end);
189
190         lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
191         for ( ; pit != end; ++pit) {
192                 InsetList::iterator iit = pit->insetlist.begin();
193                 InsetList::iterator iend = pit->insetlist.end();
194                 for ( ; iit != iend; ++iit) {
195                         InsetBase * inset = iit->inset;
196 #if 1
197                         lyxerr << "examining inset " << inset
198                         //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
199                                 << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
200                                 << " yo: " << inset->yo() - inset->ascent() << "..."
201                                 << inset->yo() + inset->descent() << endl;
202 #endif
203                         if (inset->covers(x, y)) {
204                                 lyxerr << "Hit inset: " << inset << endl;
205                                 return inset;
206                         }
207                 }
208         }
209         lyxerr << "No inset hit. " << endl;
210         return 0;
211 }
212
213
214 bool LyXText::gotoNextInset(LCursor & cur,
215         vector<InsetOld_code> const & codes, string const & contents)
216 {
217         BOOST_ASSERT(this == cur.text());
218         ParagraphList::iterator end = paragraphs().end();
219         ParagraphList::iterator pit = getPar(cur.par());
220         pos_type pos = cur.pos();
221
222         InsetBase * inset;
223         do {
224                 if (pos + 1 < pit->size()) {
225                         ++pos;
226                 } else  {
227                         ++pit;
228                         pos = 0;
229                 }
230
231         } while (pit != end &&
232                  !(pit->isInset(pos) &&
233                    (inset = pit->getInset(pos)) != 0 &&
234                    find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
235                    (contents.empty() ||
236                     static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
237                     == contents)));
238
239         if (pit == end)
240                 return false;
241
242         setCursor(cur, parOffset(pit), pos, false);
243         return true;
244 }
245
246
247 void LyXText::gotoInset(LCursor & cur,
248         vector<InsetOld_code> const & codes, bool same_content)
249 {
250         cur.clearSelection();
251
252         string contents;
253         if (same_content
254             && cur.pos() < cur.lastpos()
255             && cur.paragraph().isInset(cur.pos())) {
256                 InsetBase const * inset = cur.paragraph().getInset(cur.pos());
257                 if (find(codes.begin(), codes.end(), inset->lyxCode())
258                     != codes.end())
259                         contents = static_cast<InsetCommand const *>(inset)->getContents();
260         }
261
262         if (!gotoNextInset(cur, codes, contents)) {
263                 if (cur.pos() || cur.par() != 0) {
264                         CursorSlice tmp = cur.top();
265                         cur.par() = 0;
266                         cur.pos() = 0;
267                         if (!gotoNextInset(cur, codes, contents)) {
268                                 cursor() = tmp;
269                                 cur.message(_("No more insets"));
270                         }
271                 } else {
272                         cur.message(_("No more insets"));
273                 }
274         }
275         cur.update();
276         cur.resetAnchor();
277 }
278
279
280 void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
281 {
282         gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
283 }
284
285
286 void LyXText::cursorPrevious(LCursor & cur)
287 {
288         pos_type cpos = cur.pos();
289         lyx::paroffset_type cpar = cur.par();
290
291         int x = cur.x_target();
292         int y = bv()->top_y();
293         setCursorFromCoordinates(cur, x, y);
294
295         if (cpar == cur.par() && cpos == cur.pos()) {
296                 // we have a row which is taller than the workarea. The
297                 // simplest solution is to move to the previous row instead.
298                 cursorUp(cur);
299         }
300
301         bv()->updateScrollbar();
302         finishUndo();
303 }
304
305
306 void LyXText::cursorNext(LCursor & cur)
307 {
308         pos_type cpos = cur.pos();
309         lyx::paroffset_type cpar = cur.par();
310
311         int x = cur.x_target();
312         int y = bv()->top_y() + bv()->workHeight();
313         setCursorFromCoordinates(cur, x, y);
314
315         if (cpar == cur.par() && cpos == cur.pos()) {
316                 // we have a row which is taller than the workarea. The
317                 // simplest solution is to move to the next row instead.
318                 cursorDown(cur);
319         }
320
321         bv()->updateScrollbar();
322         finishUndo();
323 }
324
325
326 namespace {
327
328 void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
329 {
330         text->replaceSelection(cur);
331         cur.insert(new InsetSpecialChar(kind));
332         cur.update();
333 }
334
335
336 void doInsertInset(LCursor & cur, LyXText * text,
337         FuncRequest const & cmd, bool edit, bool pastesel)
338 {
339         InsetBase * inset = createInset(&cur.bv(), cmd);
340         if (!inset)
341                 return;
342
343         recordUndo(cur);
344         bool gotsel = false;
345         if (cur.selection()) {
346                 cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
347                 gotsel = true;
348         }
349         text->insertInset(cur, inset);
350         if (edit)
351                 inset->edit(cur, true);
352         if (gotsel && pastesel)
353                 cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
354 }
355
356 } // anon namespace
357
358
359 void LyXText::number(LCursor & cur)
360 {
361         LyXFont font(LyXFont::ALL_IGNORE);
362         font.setNumber(LyXFont::TOGGLE);
363         toggleAndShow(cur, this, font);
364 }
365
366
367 bool LyXText::isRTL(Paragraph const & par) const
368 {
369         return par.isRightToLeftPar(bv()->buffer()->params());
370 }
371
372
373 void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
374 {
375         lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
376         //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
377
378         BufferView * bv = &cur.bv();
379         CursorSlice sl = cur.top();
380
381         switch (cmd.action) {
382
383         case LFUN_APPENDIX: {
384                 Paragraph & par = cur.paragraph();
385                 bool start = !par.params().startOfAppendix();
386
387                 // ensure that we have only one start_of_appendix in this document
388                 ParagraphList::iterator tmp = paragraphs().begin();
389                 ParagraphList::iterator end = paragraphs().end();
390
391                 for (; tmp != end; ++tmp) {
392                         if (tmp->params().startOfAppendix()) {
393                                 recUndo(parOffset(tmp));
394                                 tmp->params().startOfAppendix(false);
395                                 redoParagraph(tmp);
396                                 break;
397                         }
398                 }
399
400                 recordUndo(cur);
401                 par.params().startOfAppendix(start);
402
403                 // we can set the refreshing parameters now
404                 updateCounters();
405                 redoParagraph(cur);
406                 cur.update();
407                 break;
408         }
409
410         case LFUN_DELETE_WORD_FORWARD:
411                 cur.clearSelection();
412                 deleteWordForward(cur);
413                 finishChange(cur, false);
414                 break;
415
416         case LFUN_DELETE_WORD_BACKWARD:
417                 cur.clearSelection();
418                 deleteWordBackward(cur);
419                 finishChange(cur, false);
420                 break;
421
422         case LFUN_DELETE_LINE_FORWARD:
423                 cur.clearSelection();
424                 deleteLineForward(cur);
425                 finishChange(cur, false);
426                 break;
427
428         case LFUN_WORDRIGHT:
429                 if (!cur.mark())
430                         cur.clearSelection();
431                 if (isRTL(cur.paragraph()))
432                         cursorLeftOneWord(cur);
433                 else
434                         cursorRightOneWord(cur);
435                 finishChange(cur, false);
436                 break;
437
438         case LFUN_WORDLEFT:
439                 if (!cur.mark())
440                         cur.clearSelection();
441                 if (isRTL(cur.paragraph()))
442                         cursorRightOneWord(cur);
443                 else
444                         cursorLeftOneWord(cur);
445                 finishChange(cur, false);
446                 break;
447
448         case LFUN_BEGINNINGBUF:
449                 if (!cur.mark())
450                         cur.clearSelection();
451                 cursorTop(cur);
452                 finishChange(cur, false);
453                 break;
454
455         case LFUN_ENDBUF:
456                 if (!cur.mark())
457                         cur.clearSelection();
458                 cursorBottom(cur);
459                 finishChange(cur, false);
460                 break;
461
462         case LFUN_RIGHT:
463         case LFUN_RIGHTSEL:
464                 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
465                 if (isRTL(cur.paragraph()))
466                         cursorLeft(cur);
467                 else
468                         cursorRight(cur);
469                 if (sl == cur.top())
470                         cur.dispatched(FINISHED_RIGHT);
471                 break;
472
473         case LFUN_LEFT:
474         case LFUN_LEFTSEL:
475                 cur.selHandle(cmd.action == LFUN_LEFTSEL);
476                 if (isRTL(cur.paragraph()))
477                         cursorRight(cur);
478                 else
479                         cursorLeft(cur);
480                 if (sl == cur.top())
481                         cur.dispatched(FINISHED_LEFT);
482                 break;
483
484         case LFUN_UP:
485         case LFUN_UPSEL:
486                 cur.selHandle(cmd.action == LFUN_UPSEL);
487                 cursorUp(cur);
488                 if (sl == cur.top())
489                         cur.dispatched(FINISHED_UP);
490                 break;
491
492         case LFUN_DOWN:
493         case LFUN_DOWNSEL:
494                 cur.selHandle(cmd.action == LFUN_DOWNSEL);
495                 cursorDown(cur);
496                 if (sl == cur.top())
497                         cur.dispatched(FINISHED_DOWN);
498                 break;
499
500         case LFUN_UP_PARAGRAPHSEL:
501                 if (!cur.selection())
502                         cur.resetAnchor();
503                 cursorUpParagraph(cur);
504                 finishChange(cur, true);
505                 break;
506
507         case LFUN_DOWN_PARAGRAPHSEL:
508                 if (!cur.selection())
509                         cur.resetAnchor();
510                 cursorDownParagraph(cur);
511                 finishChange(cur, true);
512                 break;
513
514         case LFUN_PRIORSEL:
515                 if (!cur.selection())
516                         cur.resetAnchor();
517                 cursorPrevious(cur);
518                 finishChange(cur, true);
519                 break;
520
521         case LFUN_NEXTSEL:
522                 if (!cur.selection())
523                         cur.resetAnchor();
524                 cursorNext(cur);
525                 finishChange(cur, true);
526                 break;
527
528         case LFUN_HOMESEL:
529                 if (!cur.selection())
530                         cur.resetAnchor();
531                 cursorHome(cur);
532                 finishChange(cur, true);
533                 break;
534
535         case LFUN_ENDSEL:
536                 if (!cur.selection())
537                         cur.resetAnchor();
538                 cursorEnd(cur);
539                 finishChange(cur, true);
540                 break;
541
542         case LFUN_WORDRIGHTSEL:
543                 if (!cur.selection())
544                         cur.resetAnchor();
545                 if (isRTL(cur.paragraph()))
546                         cursorLeftOneWord(cur);
547                 else
548                         cursorRightOneWord(cur);
549                 finishChange(cur, true);
550                 break;
551
552         case LFUN_WORDLEFTSEL:
553                 if (!cur.selection())
554                         cur.resetAnchor();
555                 if (isRTL(cur.paragraph()))
556                         cursorRightOneWord(cur);
557                 else
558                         cursorLeftOneWord(cur);
559                 finishChange(cur, true);
560                 break;
561
562         case LFUN_WORDSEL: {
563                 selectWord(cur, lyx::WHOLE_WORD);
564                 finishChange(cur, true);
565                 break;
566         }
567
568         case LFUN_UP_PARAGRAPH:
569                 if (!cur.mark())
570                         cur.clearSelection();
571                 cursorUpParagraph(cur);
572                 finishChange(cur, false);
573                 break;
574
575         case LFUN_DOWN_PARAGRAPH:
576                 if (!cur.mark())
577                         cur.clearSelection();
578                 cursorDownParagraph(cur);
579                 finishChange(cur, false);
580                 break;
581
582         case LFUN_PRIOR:
583                 if (!cur.mark())
584                         cur.clearSelection();
585                 finishChange(cur, false);
586                 if (cur.par() == 0 && cur.textRow().pos() == 0)
587                         cur.dispatched(FINISHED_UP);
588                 else
589                         cursorPrevious(cur);
590                 break;
591
592         case LFUN_NEXT:
593                 if (!cur.mark())
594                         cur.clearSelection();
595                 finishChange(cur, false);
596                 if (cur.par() == cur.lastpar()
597                           && cur.textRow().endpos() == cur.lastpos())
598                         cur.dispatched(FINISHED_DOWN);
599                 else
600                         cursorNext(cur);
601                 break;
602
603         case LFUN_HOME:
604                 if (!cur.mark())
605                         cur.clearSelection();
606                 cursorHome(cur);
607                 finishChange(cur, false);
608                 break;
609
610         case LFUN_END:
611                 if (!cur.mark())
612                         cur.clearSelection();
613                 cursorEnd(cur);
614                 finishChange(cur, false);
615                 break;
616
617         case LFUN_BREAKLINE: {
618                 // Not allowed by LaTeX (labels or empty par)
619                 if (cur.pos() > cur.paragraph().beginOfBody()) {
620                         replaceSelection(cur);
621                         cur.insert(new InsetNewline);
622                         moveCursor(cur, false);
623                 }
624                 break;
625         }
626
627         case LFUN_DELETE:
628                 if (!cur.selection()) {
629                         Delete(cur);
630                         cur.resetAnchor();
631                         // It is possible to make it a lot faster still
632                         // just comment out the line below...
633                 } else {
634                         cutSelection(cur, true, false);
635                 }
636                 moveCursor(cur, false);
637                 break;
638
639         case LFUN_DELETE_SKIP:
640                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
641                 if (!cur.selection()) {
642                         if (cur.pos() == cur.lastpos()) {
643                                 cursorRight(cur);
644                                 cursorLeft(cur);
645                         }
646                         Delete(cur);
647                         cur.resetAnchor();
648                 } else {
649                         cutSelection(cur, true, false);
650                 }
651                 cur.update();
652                 break;
653
654
655         case LFUN_BACKSPACE:
656                 if (!cur.selection()) {
657                         if (bv->owner()->getIntl().getTransManager().backspace()) {
658                                 backspace(cur);
659                                 cur.resetAnchor();
660                                 // It is possible to make it a lot faster still
661                                 // just comment out the line below...
662                         }
663                 } else {
664                         cutSelection(cur, true, false);
665                 }
666                 bv->switchKeyMap();
667                 cur.update();
668                 break;
669
670         case LFUN_BACKSPACE_SKIP:
671                 // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
672                 if (!cur.selection()) {
673 #warning look here
674                         //CursorSlice cur = cursor();
675                         backspace(cur);
676                         //anchor() = cur;
677                 } else {
678                         cutSelection(cur, true, false);
679                 }
680                 cur.update();
681                 break;
682
683         case LFUN_BREAKPARAGRAPH:
684                 replaceSelection(cur);
685                 breakParagraph(cur, 0);
686                 cur.update();
687                 cur.resetAnchor();
688                 bv->switchKeyMap();
689                 break;
690
691         case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
692                 replaceSelection(cur);
693                 breakParagraph(cur, 1);
694                 cur.update();
695                 cur.resetAnchor();
696                 bv->switchKeyMap();
697                 break;
698
699         case LFUN_BREAKPARAGRAPH_SKIP: {
700                 // When at the beginning of a paragraph, remove
701                 // indentation and add a "defskip" at the top.
702                 // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
703                 replaceSelection(cur);
704                 if (cur.pos() == 0) {
705                         ParagraphParameters & params = cur.paragraph().params();
706                         setParagraph(cur,
707                                         params.spacing(),
708                                         params.align(),
709                                         params.labelWidthString(), 1);
710                 } else {
711                         breakParagraph(cur, 0);
712                 }
713                 cur.update();
714 //      anchor() = cur;
715                 bv->switchKeyMap();
716                 break;
717         }
718
719         case LFUN_PARAGRAPH_SPACING: {
720                 Paragraph & par = cur.paragraph();
721                 Spacing::Space cur_spacing = par.params().spacing().getSpace();
722                 float cur_value = 1.0;
723                 if (cur_spacing == Spacing::Other)
724                         cur_value = par.params().spacing().getValue();
725
726                 istringstream is(cmd.argument);
727                 string tmp;
728                 is >> tmp;
729                 Spacing::Space new_spacing = cur_spacing;
730                 float new_value = cur_value;
731                 if (tmp.empty()) {
732                         lyxerr << "Missing argument to `paragraph-spacing'"
733                                << endl;
734                 } else if (tmp == "single") {
735                         new_spacing = Spacing::Single;
736                 } else if (tmp == "onehalf") {
737                         new_spacing = Spacing::Onehalf;
738                 } else if (tmp == "double") {
739                         new_spacing = Spacing::Double;
740                 } else if (tmp == "other") {
741                         new_spacing = Spacing::Other;
742                         float tmpval = 0.0;
743                         is >> tmpval;
744                         lyxerr << "new_value = " << tmpval << endl;
745                         if (tmpval != 0.0)
746                                 new_value = tmpval;
747                 } else if (tmp == "default") {
748                         new_spacing = Spacing::Default;
749                 } else {
750                         lyxerr << _("Unknown spacing argument: ")
751                                << cmd.argument << endl;
752                 }
753                 if (cur_spacing != new_spacing || cur_value != new_value) {
754                         par.params().spacing(Spacing(new_spacing, new_value));
755                         redoParagraph(cur);
756                         cur.update();
757                 }
758                 break;
759         }
760
761         case LFUN_INSET_APPLY: {
762                 string const name = cmd.getArg(0);
763                 InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
764                 if (inset)
765                         inset->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
766                 else
767                         dispatch(cur, FuncRequest(LFUN_INSET_INSERT, cmd.argument));
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                 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_INSET_TOGGLE:
785                 cur.clearSelection();
786                 if (!toggleInset(cur))
787                         cur.undispatched();
788                 else
789                         bv->switchKeyMap();
790                 break;
791
792         case LFUN_SPACE_INSERT:
793                 if (cur.paragraph().layout()->free_spacing)
794                         insertChar(cur, ' ');
795                 else
796                         doInsertInset(cur, this, cmd, false, false);
797                 moveCursor(cur, false);
798                 break;
799
800         case LFUN_HYPHENATION:
801                 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
802                 break;
803
804         case LFUN_LIGATURE_BREAK:
805                 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
806                 break;
807
808         case LFUN_LDOTS:
809                 specialChar(cur, this, InsetSpecialChar::LDOTS);
810                 break;
811
812         case LFUN_END_OF_SENTENCE:
813                 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
814                 break;
815
816         case LFUN_MENU_SEPARATOR:
817                 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
818                 break;
819
820         case LFUN_UPCASE_WORD:
821                 changeCase(cur, LyXText::text_uppercase);
822                 cur.update();
823                 break;
824
825         case LFUN_LOWCASE_WORD:
826                 changeCase(cur, LyXText::text_lowercase);
827                 cur.update();
828                 break;
829
830         case LFUN_CAPITALIZE_WORD:
831                 changeCase(cur, LyXText::text_capitalization);
832                 cur.update();
833                 break;
834
835         case LFUN_TRANSPOSE_CHARS:
836                 recordUndo(cur);
837                 redoParagraph(cur);
838                 cur.update();
839                 break;
840
841         case LFUN_PASTE:
842                 cur.message(_("Paste"));
843                 replaceSelection(cur);
844 #warning FIXME Check if the arg is in the domain of available selections.
845                 if (isStrUnsignedInt(cmd.argument))
846                         pasteSelection(cur, strToUnsignedInt(cmd.argument));
847                 else
848                         pasteSelection(cur, 0);
849                 cur.clearSelection(); // bug 393
850                 cur.update();
851                 bv->switchKeyMap();
852                 finishUndo();
853                 break;
854
855         case LFUN_CUT:
856                 cutSelection(cur, true, true);
857                 cur.message(_("Cut"));
858                 cur.update();
859                 break;
860
861         case LFUN_COPY:
862                 copySelection(cur);
863                 cur.message(_("Copy"));
864                 break;
865
866         case LFUN_GETXY:
867                 cur.message(tostr(cursorX(cur.top())) + ' '
868                           + tostr(cursorY(cur.top())));
869                 break;
870
871         case LFUN_SETXY: {
872                 int x = 0;
873                 int y = 0;
874                 istringstream is(cmd.argument);
875                 is >> x >> y;
876                 if (!is)
877                         lyxerr << "SETXY: Could not parse coordinates in '"
878                                << cmd.argument << std::endl;
879                 else
880                         setCursorFromCoordinates(cur, x, y);
881                 break;
882         }
883
884         case LFUN_GETFONT:
885                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
886                         cur.message("E");
887                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
888                         cur.message("N");
889                 else
890                         cur.message("0");
891                 break;
892
893         case LFUN_GETLAYOUT:
894                 cur.message(cur.paragraph().layout()->name());
895                 break;
896
897         case LFUN_LAYOUT: {
898                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
899                   << cmd.argument << endl;
900
901                 // This is not the good solution to the empty argument
902                 // problem, but it will hopefully suffice for 1.2.0.
903                 // The correct solution would be to augument the
904                 // function list/array with information about what
905                 // functions needs arguments and their type.
906                 if (cmd.argument.empty()) {
907                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
908                         break;
909                 }
910
911                 // Derive layout number from given argument (string)
912                 // and current buffer's textclass (number)
913                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
914                 bool hasLayout = tclass.hasLayout(cmd.argument);
915                 string layout = cmd.argument;
916
917                 // If the entry is obsolete, use the new one instead.
918                 if (hasLayout) {
919                         string const & obs = tclass[layout]->obsoleted_by();
920                         if (!obs.empty())
921                                 layout = obs;
922                 }
923
924                 if (!hasLayout) {
925                         cur.errorMessage(string(N_("Layout ")) + cmd.argument +
926                                 N_(" not known"));
927                         break;
928                 }
929
930                 bool change_layout = (current_layout != layout);
931
932                 if (!change_layout && cur.selection() &&
933                         cur.selBegin().par() != cur.selEnd().par())
934                 {
935                         ParagraphList::iterator spit = getPar(cur.selBegin());
936                         ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
937                         while (spit != epit) {
938                                 if (spit->layout()->name() != current_layout) {
939                                         change_layout = true;
940                                         break;
941                                 }
942                                 ++spit;
943                         }
944                 }
945
946                 if (change_layout) {
947                         current_layout = layout;
948                         setLayout(cur, layout);
949                         bv->owner()->setLayout(layout);
950                         cur.update();
951                         bv->switchKeyMap();
952                 }
953                 break;
954         }
955
956         case LFUN_PASTESELECTION: {
957                 cur.clearSelection();
958                 string const clip = bv->getClipboard();
959                 if (!clip.empty()) {
960                         if (cmd.argument == "paragraph")
961                                 insertStringAsParagraphs(cur, clip);
962                         else
963                                 insertStringAsLines(cur, clip);
964                         cur.update();
965                 }
966                 break;
967         }
968
969         case LFUN_GOTOERROR:
970                 gotoInset(cur, InsetBase::ERROR_CODE, false);
971                 break;
972
973         case LFUN_GOTONOTE:
974                 gotoInset(cur, InsetBase::NOTE_CODE, false);
975                 break;
976
977         case LFUN_REFERENCE_GOTO: {
978                 vector<InsetOld_code> tmp;
979                 tmp.push_back(InsetBase::LABEL_CODE);
980                 tmp.push_back(InsetBase::REF_CODE);
981                 gotoInset(cur, tmp, true);
982                 break;
983         }
984
985         case LFUN_QUOTE: {
986                 replaceSelection(cur);
987                 Paragraph & par = cur.paragraph();
988                 lyx::pos_type pos = cur.pos();
989                 char c;
990                 if (pos == 0)
991                         c = ' ';
992                 else if (cur.prevInset() && cur.prevInset()->isSpace())
993                         c = ' ';
994                 else
995                         c = par.getChar(pos - 1);
996
997                 LyXLayout_ptr const & style = par.layout();
998                 
999                 BufferParams const & bufparams = bv->buffer()->params();
1000                 if (!style->pass_thru
1001                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1002                         string arg = cmd.argument;
1003                         if (arg == "single")
1004                                 cur.insert(new InsetQuotes(c,
1005                                     bufparams.quotes_language, 
1006                                     InsetQuotes::SingleQ));
1007                         else if (arg == "double")
1008                                 cur.insert(new InsetQuotes(c,
1009                                     bufparams.quotes_language, 
1010                                     InsetQuotes::DoubleQ));
1011                         else
1012                                 cur.insert(new InsetQuotes(c, bufparams));
1013                         }
1014                 else
1015                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1016                 break;
1017         }
1018
1019         case LFUN_DATE_INSERT: {
1020                 replaceSelection(cur);
1021                 time_t now_time_t = time(NULL);
1022                 struct tm * now_tm = localtime(&now_time_t);
1023                 setlocale(LC_TIME, "");
1024                 string arg;
1025                 if (!cmd.argument.empty())
1026                         arg = cmd.argument;
1027                 else
1028                         arg = lyxrc.date_insert_format;
1029                 char datetmp[32];
1030                 int const datetmp_len =
1031                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1032
1033                 for (int i = 0; i < datetmp_len; i++)
1034                         insertChar(cur, datetmp[i]);
1035
1036                 cur.resetAnchor();
1037                 moveCursor(cur, false);
1038                 break;
1039         }
1040
1041         case LFUN_MOUSE_TRIPLE:
1042                 if (cmd.button() == mouse_button::button1) {
1043                         selection_possible = true;
1044                         cursorHome(cur);
1045                         cur.resetAnchor();
1046                         cursorEnd(cur);
1047                         cur.setSelection();
1048                         bv->haveSelection(cur.selection());
1049                 }
1050                 break;
1051
1052         case LFUN_MOUSE_DOUBLE:
1053                 if (cmd.button() == mouse_button::button1) {
1054                         selection_possible = true;
1055                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
1056                         bv->haveSelection(cur.selection());
1057                 }
1058                 break;
1059
1060         case LFUN_MOUSE_MOTION: {
1061                 // Only use motion with button 1
1062                 //if (cmd.button() != mouse_button::button1)
1063                 //      return false;
1064                 // The test for not selection possible is needed, that
1065                 // only motion events are used, where the bottom press
1066                 // event was on the drawing area too
1067                 if (!selection_possible) {
1068                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1069                                 "Dispatch: no selection possible\n";
1070                         break;
1071                 }
1072                 CursorSlice old = cur.top();
1073                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1074
1075                 // This is to allow jumping over large insets
1076                 // FIXME: shouldn't be top-text-specific
1077                 if (isMainText() && cur.top() == old) {
1078                         if (cmd.y - bv->top_y() >= bv->workHeight())
1079                                 cursorDown(cur);
1080                         else if (cmd.y - bv->top_y() < 0)
1081                                 cursorUp(cur);
1082                 }
1083
1084                 // don't set anchor_
1085                 bv->cursor().setCursor(cur, false);
1086                 break;
1087         }
1088
1089         // Single-click on work area
1090         case LFUN_MOUSE_PRESS: {
1091                 // ok ok, this is a hack (for xforms)
1092                 // We shouldn't go further down as we really should only do the
1093                 // scrolling and be done with this. Otherwise we may open some
1094                 // dialogs (Jug 20020424).
1095                 if (cmd.button() == mouse_button::button4) {
1096                         bv->scroll(-lyxrc.wheel_jump);
1097                         break;
1098                 }
1099
1100                 if (cmd.button() == mouse_button::button5) {
1101                         bv->scroll(lyxrc.wheel_jump);
1102                         break;
1103                 }
1104
1105                 // Right click on a footnote flag opens float menu
1106                 if (cmd.button() == mouse_button::button3) {
1107                         cur.clearSelection();
1108                         selection_possible = false;
1109                         break;
1110                 }
1111
1112                 // Middle button press pastes if we have a selection
1113                 // We do this here as if the selection was inside an inset
1114                 // it could get cleared on the unlocking of the inset so
1115                 // we have to check this first
1116                 bool paste_internally = false;
1117                 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1118                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1119                         paste_internally = true;
1120                 }
1121
1122                 selection_possible = true;
1123
1124                 // Clear the selection
1125                 cur.clearSelection();
1126
1127                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1128                 cur.resetAnchor();
1129                 finishUndo();
1130                 cur.x_target() = cursorX(cur.top());
1131
1132                 // set cursor and anchor to this position
1133                 bv->cursor() = cur;
1134
1135                 if (bv->fitCursor())
1136                         selection_possible = false;
1137
1138                 // Insert primary selection with middle mouse
1139                 // if there is a local selection in the current buffer,
1140                 // insert this
1141                 if (cmd.button() == mouse_button::button2) {
1142                         if (paste_internally)
1143                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1144                         else
1145                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1146                         selection_possible = false;
1147                 }
1148                 break;
1149         }
1150
1151         case LFUN_MOUSE_RELEASE: {
1152                 // do nothing if we used the mouse wheel
1153                 if (cmd.button() == mouse_button::button4
1154                  || cmd.button() == mouse_button::button5) {
1155                         cur.undispatched();
1156                         break;
1157                 }
1158
1159                 selection_possible = false;
1160
1161                 if (cmd.button() == mouse_button::button2)
1162                         break;
1163
1164                 // finish selection
1165                 if (cmd.button() == mouse_button::button1)
1166                         bv->haveSelection(cur.selection());
1167
1168                 bv->switchKeyMap();
1169                 bv->owner()->updateMenubar();
1170                 bv->owner()->updateToolbar();
1171                 break;
1172         }
1173
1174         case LFUN_SELFINSERT: {
1175                 if (cmd.argument.empty())
1176                         break;
1177
1178                 // Automatically delete the currently selected
1179                 // text and replace it with what is being
1180                 // typed in now. Depends on lyxrc settings
1181                 // "auto_region_delete", which defaults to
1182                 // true (on).
1183
1184                 if (lyxrc.auto_region_delete) {
1185                         if (cur.selection())
1186                                 cutSelection(cur, false, false);
1187                         bv->haveSelection(false);
1188                 }
1189
1190                 cur.clearSelection();
1191                 LyXFont const old_font = real_current_font;
1192
1193                 string::const_iterator cit = cmd.argument.begin();
1194                 string::const_iterator end = cmd.argument.end();
1195                 for (; cit != end; ++cit)
1196                         bv->owner()->getIntl().getTransManager().
1197                                 TranslateAndInsert(*cit, this);
1198
1199                 cur.resetAnchor();
1200                 moveCursor(cur, false);
1201
1202                 // real_current_font.number can change so we need to
1203                 // update the minibuffer
1204                 if (old_font != real_current_font)
1205                 bv->updateScrollbar();
1206                 break;
1207         }
1208
1209         case LFUN_URL: {
1210                 InsetCommandParams p("url");
1211                 string const data = InsetCommandMailer::params2string("url", p);
1212                 bv->owner()->getDialogs().show("url", data, 0);
1213                 break;
1214         }
1215
1216         case LFUN_HTMLURL: {
1217                 InsetCommandParams p("htmlurl");
1218                 string const data = InsetCommandMailer::params2string("url", p);
1219                 bv->owner()->getDialogs().show("url", data, 0);
1220                 break;
1221         }
1222
1223         case LFUN_INSERT_LABEL: {
1224                 InsetCommandParams p("label");
1225                 string const data = InsetCommandMailer::params2string("label", p);
1226                 bv->owner()->getDialogs().show("label", data, 0);
1227                 break;
1228         }
1229
1230
1231 #if 0
1232         case LFUN_INSET_LIST:
1233         case LFUN_INSET_THEOREM:
1234         case LFUN_INSET_CAPTION:
1235 #endif
1236         case LFUN_INSERT_NOTE:
1237         case LFUN_INSERT_CHARSTYLE:
1238         case LFUN_INSERT_BOX:
1239         case LFUN_INSERT_BRANCH:
1240         case LFUN_INSERT_BIBITEM:
1241         case LFUN_INSET_ERT:
1242         case LFUN_INSET_FLOAT:
1243         case LFUN_INSET_FOOTNOTE:
1244         case LFUN_INSET_MARGINAL:
1245         case LFUN_INSET_OPTARG:
1246         case LFUN_INSET_WIDE_FLOAT:
1247         case LFUN_INSET_WRAP:
1248         case LFUN_TABULAR_INSERT:
1249         case LFUN_ENVIRONMENT_INSERT:
1250                 // Open the inset, and move the current selection
1251                 // inside it.
1252                 doInsertInset(cur, this, cmd, true, true);
1253                 break;
1254
1255         case LFUN_INDEX_INSERT:
1256                 // Just open the inset
1257                 doInsertInset(cur, this, cmd, true, false);
1258                 break;
1259
1260         case LFUN_INDEX_PRINT:
1261         case LFUN_TOC_INSERT:
1262         case LFUN_HFILL:
1263         case LFUN_INSERT_LINE:
1264         case LFUN_INSERT_PAGEBREAK:
1265                 // do nothing fancy
1266                 doInsertInset(cur, this, cmd, false, false);
1267                 break;
1268
1269         case LFUN_DEPTH_MIN:
1270                 changeDepth(cur, bv_funcs::DEC_DEPTH);
1271                 cur.update();
1272                 break;
1273
1274         case LFUN_DEPTH_PLUS:
1275                 changeDepth(cur, bv_funcs::INC_DEPTH);
1276                 cur.update();
1277                 break;
1278
1279         case LFUN_MATH_DISPLAY:
1280                 mathDispatch(cur, this, cmd, true);
1281                 break;
1282
1283         case LFUN_MATH_IMPORT_SELECTION:
1284         case LFUN_MATH_MODE:
1285                 mathDispatch(cur, this, cmd, false);
1286                 break;
1287
1288         case LFUN_MATH_MACRO:
1289                 if (cmd.argument.empty())
1290                         cur.errorMessage(N_("Missing argument"));
1291                 else {
1292                         string s = cmd.argument;
1293                         string const s1 = token(s, ' ', 1);
1294                         int const nargs = s1.empty() ? 0 : atoi(s1);
1295                         string const s2 = token(s, ' ', 2);
1296                         string const type = s2.empty() ? "newcommand" : s2;
1297                         cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1298                         cur.nextInset()->edit(cur, true);
1299                 }
1300                 break;
1301
1302         case LFUN_INSERT_MATH:
1303         case LFUN_INSERT_MATRIX:
1304         case LFUN_MATH_DELIM: {
1305                 cur.insert(new MathHullInset);
1306                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1307                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1308                 cur.dispatch(cmd);
1309                 break;
1310         }
1311
1312         case LFUN_EMPH: {
1313                 LyXFont font(LyXFont::ALL_IGNORE);
1314                 font.setEmph(LyXFont::TOGGLE);
1315                 toggleAndShow(cur, this, font);
1316                 break;
1317         }
1318
1319         case LFUN_BOLD: {
1320                 LyXFont font(LyXFont::ALL_IGNORE);
1321                 font.setSeries(LyXFont::BOLD_SERIES);
1322                 toggleAndShow(cur, this, font);
1323                 break;
1324         }
1325
1326         case LFUN_NOUN: {
1327                 LyXFont font(LyXFont::ALL_IGNORE);
1328                 font.setNoun(LyXFont::TOGGLE);
1329                 toggleAndShow(cur, this, font);
1330                 break;
1331         }
1332
1333         case LFUN_CODE: {
1334                 LyXFont font(LyXFont::ALL_IGNORE);
1335                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1336                 toggleAndShow(cur, this, font);
1337                 break;
1338         }
1339
1340         case LFUN_SANS: {
1341                 LyXFont font(LyXFont::ALL_IGNORE);
1342                 font.setFamily(LyXFont::SANS_FAMILY);
1343                 toggleAndShow(cur, this, font);
1344                 break;
1345         }
1346
1347         case LFUN_ROMAN: {
1348                 LyXFont font(LyXFont::ALL_IGNORE);
1349                 font.setFamily(LyXFont::ROMAN_FAMILY);
1350                 toggleAndShow(cur, this, font);
1351                 break;
1352         }
1353
1354         case LFUN_DEFAULT: {
1355                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1356                 toggleAndShow(cur, this, font);
1357                 break;
1358         }
1359
1360         case LFUN_UNDERLINE: {
1361                 LyXFont font(LyXFont::ALL_IGNORE);
1362                 font.setUnderbar(LyXFont::TOGGLE);
1363                 toggleAndShow(cur, this, font);
1364                 break;
1365         }
1366
1367         case LFUN_FONT_SIZE: {
1368                 LyXFont font(LyXFont::ALL_IGNORE);
1369                 font.setLyXSize(cmd.argument);
1370                 toggleAndShow(cur, this, font);
1371                 break;
1372         }
1373
1374         case LFUN_LANGUAGE: {
1375                 Language const * lang = languages.getLanguage(cmd.argument);
1376                 if (!lang)
1377                         break;
1378                 LyXFont font(LyXFont::ALL_IGNORE);
1379                 font.setLanguage(lang);
1380                 toggleAndShow(cur, this, font);
1381                 bv->switchKeyMap();
1382                 break;
1383         }
1384
1385         case LFUN_FREEFONT_APPLY:
1386                 toggleAndShow(cur, this, freefont, toggleall);
1387                 cur.message(_("Character set"));
1388                 break;
1389
1390         // Set the freefont using the contents of \param data dispatched from
1391         // the frontends and apply it at the current cursor location.
1392         case LFUN_FREEFONT_UPDATE: {
1393                 LyXFont font;
1394                 bool toggle;
1395                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1396                         freefont = font;
1397                         toggleall = toggle;
1398                         toggleAndShow(cur, this, freefont, toggleall);
1399                         cur.message(_("Character set"));
1400                 }
1401                 break;
1402         }
1403
1404         case LFUN_FINISHED_LEFT:
1405                 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1406                 if (isRTL(cur.paragraph()))
1407                         cursorLeft(cur);
1408                 cur.bv().cursor() = cur;
1409                 break;
1410
1411         case LFUN_FINISHED_RIGHT:
1412                 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1413                 if (!isRTL(cur.paragraph()))
1414                         cursorRight(cur);
1415                 cur.bv().cursor() = cur;
1416                 break;
1417
1418         case LFUN_FINISHED_UP:
1419                 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1420                 cursorUp(cur);
1421                 cur.bv().cursor() = cur;
1422                 break;
1423
1424         case LFUN_FINISHED_DOWN:
1425                 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1426                 cursorDown(cur);
1427                 cur.bv().cursor() = 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                 cur.update();
1502                 break;
1503         }
1504
1505         case LFUN_REJECT_CHANGE: {
1506                 rejectChange(cur);
1507                 cur.update();
1508                 break;
1509         }
1510
1511         case LFUN_THESAURUS_ENTRY: {
1512                 string arg = cmd.argument;
1513                 if (arg.empty()) {
1514                         arg = cur.selectionAsString(false);
1515                         // FIXME
1516                         if (arg.size() > 100 || arg.empty()) {
1517                                 // Get word or selection
1518                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1519                                 arg = cur.selectionAsString(false);
1520                         }
1521                 }
1522                 bv->owner()->getDialogs().show("thesaurus", arg);
1523                 break;
1524         }
1525
1526         case LFUN_PARAGRAPH_APPLY: {
1527                 // Given data, an encoding of the ParagraphParameters
1528                 // generated in the Paragraph dialog, this function sets
1529                 // the current paragraph appropriately.
1530                 istringstream is(cmd.argument);
1531                 LyXLex lex(0, 0);
1532                 lex.setStream(is);
1533                 ParagraphParameters params;
1534                 params.read(lex);
1535                 setParagraph(cur,
1536                                          params.spacing(),
1537                                          params.align(),
1538                                          params.labelWidthString(),
1539                                          params.noindent());
1540                 cur.update();
1541                 cur.message(_("Paragraph layout set"));
1542                 break;
1543         }
1544
1545         case LFUN_ESCAPE:
1546                 if (cur.selection())
1547                         cur.selection() = false;
1548                 else
1549                         cur.dispatched(FINISHED_LEFT);
1550                 break;
1551
1552         default:
1553                 cur.undispatched();
1554                 break;
1555         }
1556 }
1557
1558
1559 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
1560 {
1561         return false;
1562 }