]> git.lyx.org Git - lyx.git/blob - src/text3.C
ffc121ef12de0baafa29241bdf9e246abfa8ef99
[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                                 cur.top() = 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 & 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                         cmd = FuncRequest(LFUN_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                         cmd = FuncRequest(LFUN_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                         cmd = FuncRequest(LFUN_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                         cmd = FuncRequest(LFUN_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                         cmd = FuncRequest(LFUN_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                         cmd = FuncRequest(LFUN_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                         FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
766                         inset->dispatch(cur, fr);
767                 } else {
768                         FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
769                         dispatch(cur, fr);
770                 }
771                 break;
772         }
773
774         case LFUN_INSET_INSERT: {
775                 recordUndo(cur);
776                 InsetBase * inset = createInset(bv, cmd);
777                 if (inset)
778                         insertInset(cur, inset);
779                 break;
780         }
781
782         case LFUN_INSET_SETTINGS:
783                 if (cur.inset().asUpdatableInset())
784                         cur.inset().asUpdatableInset()->showInsetDialog(bv);
785                 break;
786
787         case LFUN_INSET_TOGGLE:
788                 cur.clearSelection();
789                 if (!toggleInset(cur))
790                         cur.undispatched();
791                 else
792                         bv->switchKeyMap();
793                 break;
794
795         case LFUN_SPACE_INSERT:
796                 if (cur.paragraph().layout()->free_spacing)
797                         insertChar(cur, ' ');
798                 else
799                         doInsertInset(cur, this, cmd, false, false);
800                 moveCursor(cur, false);
801                 break;
802
803         case LFUN_HYPHENATION:
804                 specialChar(cur, this, InsetSpecialChar::HYPHENATION);
805                 break;
806
807         case LFUN_LIGATURE_BREAK:
808                 specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
809                 break;
810
811         case LFUN_LDOTS:
812                 specialChar(cur, this, InsetSpecialChar::LDOTS);
813                 break;
814
815         case LFUN_END_OF_SENTENCE:
816                 specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
817                 break;
818
819         case LFUN_MENU_SEPARATOR:
820                 specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
821                 break;
822
823         case LFUN_UPCASE_WORD:
824                 changeCase(cur, LyXText::text_uppercase);
825                 cur.update();
826                 break;
827
828         case LFUN_LOWCASE_WORD:
829                 changeCase(cur, LyXText::text_lowercase);
830                 cur.update();
831                 break;
832
833         case LFUN_CAPITALIZE_WORD:
834                 changeCase(cur, LyXText::text_capitalization);
835                 cur.update();
836                 break;
837
838         case LFUN_TRANSPOSE_CHARS:
839                 recordUndo(cur);
840                 redoParagraph(cur);
841                 cur.update();
842                 break;
843
844         case LFUN_PASTE:
845                 cur.message(_("Paste"));
846                 replaceSelection(cur);
847 #warning FIXME Check if the arg is in the domain of available selections.
848                 if (isStrUnsignedInt(cmd.argument))
849                         pasteSelection(cur, strToUnsignedInt(cmd.argument));
850                 else
851                         pasteSelection(cur, 0);
852                 cur.clearSelection(); // bug 393
853                 cur.update();
854                 bv->switchKeyMap();
855                 finishUndo();
856                 break;
857
858         case LFUN_CUT:
859                 cutSelection(cur, true, true);
860                 cur.message(_("Cut"));
861                 cur.update();
862                 break;
863
864         case LFUN_COPY:
865                 copySelection(cur);
866                 cur.message(_("Copy"));
867                 break;
868
869         case LFUN_GETXY:
870                 cur.message(tostr(cursorX(cur.top())) + ' '
871                           + tostr(cursorY(cur.top())));
872                 break;
873
874         case LFUN_SETXY: {
875                 int x = 0;
876                 int y = 0;
877                 istringstream is(cmd.argument);
878                 is >> x >> y;
879                 if (!is)
880                         lyxerr << "SETXY: Could not parse coordinates in '"
881                                << cmd.argument << std::endl;
882                 else
883                         setCursorFromCoordinates(cur, x, y);
884                 break;
885         }
886
887         case LFUN_GETFONT:
888                 if (current_font.shape() == LyXFont::ITALIC_SHAPE)
889                         cur.message("E");
890                 else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
891                         cur.message("N");
892                 else
893                         cur.message("0");
894                 break;
895
896         case LFUN_GETLAYOUT:
897                 cur.message(cur.paragraph().layout()->name());
898                 break;
899
900         case LFUN_LAYOUT: {
901                 lyxerr[Debug::INFO] << "LFUN_LAYOUT: (arg) "
902                   << cmd.argument << endl;
903
904                 // This is not the good solution to the empty argument
905                 // problem, but it will hopefully suffice for 1.2.0.
906                 // The correct solution would be to augument the
907                 // function list/array with information about what
908                 // functions needs arguments and their type.
909                 if (cmd.argument.empty()) {
910                         cur.errorMessage(_("LyX function 'layout' needs an argument."));
911                         break;
912                 }
913
914                 // Derive layout number from given argument (string)
915                 // and current buffer's textclass (number)
916                 LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
917                 bool hasLayout = tclass.hasLayout(cmd.argument);
918                 string layout = cmd.argument;
919
920                 // If the entry is obsolete, use the new one instead.
921                 if (hasLayout) {
922                         string const & obs = tclass[layout]->obsoleted_by();
923                         if (!obs.empty())
924                                 layout = obs;
925                 }
926
927                 if (!hasLayout) {
928                         cur.errorMessage(string(N_("Layout ")) + cmd.argument +
929                                 N_(" not known"));
930                         break;
931                 }
932
933                 bool change_layout = (current_layout != layout);
934
935                 if (!change_layout && cur.selection() &&
936                         cur.selBegin().par() != cur.selEnd().par())
937                 {
938                         ParagraphList::iterator spit = getPar(cur.selBegin());
939                         ParagraphList::iterator epit = boost::next(getPar(cur.selEnd()));
940                         while (spit != epit) {
941                                 if (spit->layout()->name() != current_layout) {
942                                         change_layout = true;
943                                         break;
944                                 }
945                                 ++spit;
946                         }
947                 }
948
949                 if (change_layout) {
950                         current_layout = layout;
951                         setLayout(cur, layout);
952                         bv->owner()->setLayout(layout);
953                         cur.update();
954                         bv->switchKeyMap();
955                 }
956                 break;
957         }
958
959         case LFUN_PASTESELECTION: {
960                 cur.clearSelection();
961                 string const clip = bv->getClipboard();
962                 if (!clip.empty()) {
963                         if (cmd.argument == "paragraph")
964                                 insertStringAsParagraphs(cur, clip);
965                         else
966                                 insertStringAsLines(cur, clip);
967                         cur.update();
968                 }
969                 break;
970         }
971
972         case LFUN_GOTOERROR:
973                 gotoInset(cur, InsetBase::ERROR_CODE, false);
974                 break;
975
976         case LFUN_GOTONOTE:
977                 gotoInset(cur, InsetBase::NOTE_CODE, false);
978                 break;
979
980         case LFUN_REFERENCE_GOTO: {
981                 vector<InsetOld_code> tmp;
982                 tmp.push_back(InsetBase::LABEL_CODE);
983                 tmp.push_back(InsetBase::REF_CODE);
984                 gotoInset(cur, tmp, true);
985                 break;
986         }
987
988         case LFUN_QUOTE: {
989                 replaceSelection(cur);
990                 Paragraph & par = cur.paragraph();
991                 lyx::pos_type pos = cur.pos();
992                 char c;
993                 if (pos == 0)
994                         c = ' ';
995                 else if (cur.prevInset() && cur.prevInset()->isSpace())
996                         c = ' ';
997                 else
998                         c = par.getChar(pos - 1);
999
1000                 LyXLayout_ptr const & style = par.layout();
1001                 
1002                 BufferParams const & bufparams = bv->buffer()->params();
1003                 if (!style->pass_thru
1004                     && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
1005                         string arg = cmd.argument;
1006                         if (arg == "single")
1007                                 cur.insert(new InsetQuotes(c,
1008                                     bufparams.quotes_language, 
1009                                     InsetQuotes::SingleQ));
1010                         else if (arg == "double")
1011                                 cur.insert(new InsetQuotes(c,
1012                                     bufparams.quotes_language, 
1013                                     InsetQuotes::DoubleQ));
1014                         else
1015                                 cur.insert(new InsetQuotes(c, bufparams));
1016                 }
1017                 else
1018                         bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
1019                 break;
1020         }
1021
1022         case LFUN_DATE_INSERT: {
1023                 replaceSelection(cur);
1024                 time_t now_time_t = time(NULL);
1025                 struct tm * now_tm = localtime(&now_time_t);
1026                 setlocale(LC_TIME, "");
1027                 string arg;
1028                 if (!cmd.argument.empty())
1029                         arg = cmd.argument;
1030                 else
1031                         arg = lyxrc.date_insert_format;
1032                 char datetmp[32];
1033                 int const datetmp_len =
1034                         ::strftime(datetmp, 32, arg.c_str(), now_tm);
1035
1036                 for (int i = 0; i < datetmp_len; i++)
1037                         insertChar(cur, datetmp[i]);
1038
1039                 cur.resetAnchor();
1040                 moveCursor(cur, false);
1041                 break;
1042         }
1043
1044         case LFUN_MOUSE_TRIPLE:
1045                 if (cmd.button() == mouse_button::button1) {
1046                         selection_possible = true;
1047                         cursorHome(cur);
1048                         cur.resetAnchor();
1049                         cursorEnd(cur);
1050                         cur.setSelection();
1051                         bv->haveSelection(cur.selection());
1052                 }
1053                 break;
1054
1055         case LFUN_MOUSE_DOUBLE:
1056                 if (cmd.button() == mouse_button::button1) {
1057                         selection_possible = true;
1058                         selectWord(cur, lyx::WHOLE_WORD_STRICT);
1059                         bv->haveSelection(cur.selection());
1060                 }
1061                 break;
1062
1063         case LFUN_MOUSE_MOTION: {
1064                 // Only use motion with button 1
1065                 //if (cmd.button() != mouse_button::button1)
1066                 //      return false;
1067                 // The test for not selection possible is needed, that
1068                 // only motion events are used, where the bottom press
1069                 // event was on the drawing area too
1070                 if (!selection_possible) {
1071                         lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
1072                                 "Dispatch: no selection possible\n";
1073                         break;
1074                 }
1075                 CursorSlice old = cur.top();
1076                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1077
1078                 // This is to allow jumping over large insets
1079                 // FIXME: shouldn't be top-text-specific
1080                 if (isMainText() && cur.top() == old) {
1081                         if (cmd.y - bv->top_y() >= bv->workHeight())
1082                                 cursorDown(cur);
1083                         else if (cmd.y - bv->top_y() < 0)
1084                                 cursorUp(cur);
1085                 }
1086
1087                 // don't set anchor_
1088                 bv->cursor().setCursor(cur, false);
1089                 break;
1090         }
1091
1092         // Single-click on work area
1093         case LFUN_MOUSE_PRESS: {
1094                 // ok ok, this is a hack (for xforms)
1095                 // We shouldn't go further down as we really should only do the
1096                 // scrolling and be done with this. Otherwise we may open some
1097                 // dialogs (Jug 20020424).
1098                 if (cmd.button() == mouse_button::button4) {
1099                         bv->scroll(-lyxrc.wheel_jump);
1100                         break;
1101                 }
1102
1103                 if (cmd.button() == mouse_button::button5) {
1104                         bv->scroll(lyxrc.wheel_jump);
1105                         break;
1106                 }
1107
1108                 // Right click on a footnote flag opens float menu
1109                 if (cmd.button() == mouse_button::button3) {
1110                         cur.clearSelection();
1111                         selection_possible = false;
1112                         break;
1113                 }
1114
1115                 // Middle button press pastes if we have a selection
1116                 // We do this here as if the selection was inside an inset
1117                 // it could get cleared on the unlocking of the inset so
1118                 // we have to check this first
1119                 bool paste_internally = false;
1120                 if (cmd.button() == mouse_button::button2 && cur.selection()) {
1121                         bv->owner()->dispatch(FuncRequest(LFUN_COPY));
1122                         paste_internally = true;
1123                 }
1124
1125                 selection_possible = true;
1126
1127                 // Clear the selection
1128                 cur.clearSelection();
1129
1130                 setCursorFromCoordinates(cur, cmd.x, cmd.y);
1131                 cur.resetAnchor();
1132                 finishUndo();
1133                 cur.x_target() = cursorX(cur.top());
1134
1135                 // set cursor and anchor to this position
1136                 bv->cursor() = cur;
1137
1138                 if (bv->fitCursor())
1139                         selection_possible = false;
1140
1141                 // Insert primary selection with middle mouse
1142                 // if there is a local selection in the current buffer,
1143                 // insert this
1144                 if (cmd.button() == mouse_button::button2) {
1145                         if (paste_internally)
1146                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
1147                         else
1148                                 bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
1149                         selection_possible = false;
1150                 }
1151                 break;
1152         }
1153
1154         case LFUN_MOUSE_RELEASE: {
1155                 // do nothing if we used the mouse wheel
1156                 if (cmd.button() == mouse_button::button4
1157                  || cmd.button() == mouse_button::button5) {
1158                         cur.undispatched();
1159                         break;
1160                 }
1161
1162                 selection_possible = false;
1163
1164                 if (cmd.button() == mouse_button::button2)
1165                         break;
1166
1167                 // finish selection
1168                 if (cmd.button() == mouse_button::button1)
1169                         bv->haveSelection(cur.selection());
1170
1171                 bv->switchKeyMap();
1172                 bv->owner()->updateMenubar();
1173                 bv->owner()->updateToolbar();
1174                 break;
1175         }
1176
1177         case LFUN_SELFINSERT: {
1178                 if (cmd.argument.empty())
1179                         break;
1180
1181                 // Automatically delete the currently selected
1182                 // text and replace it with what is being
1183                 // typed in now. Depends on lyxrc settings
1184                 // "auto_region_delete", which defaults to
1185                 // true (on).
1186
1187                 if (lyxrc.auto_region_delete) {
1188                         if (cur.selection())
1189                                 cutSelection(cur, false, false);
1190                         bv->haveSelection(false);
1191                 }
1192
1193                 cur.clearSelection();
1194                 LyXFont const old_font = real_current_font;
1195
1196                 string::const_iterator cit = cmd.argument.begin();
1197                 string::const_iterator end = cmd.argument.end();
1198                 for (; cit != end; ++cit)
1199                         bv->owner()->getIntl().getTransManager().
1200                                 TranslateAndInsert(*cit, this);
1201
1202                 cur.resetAnchor();
1203                 moveCursor(cur, false);
1204
1205                 // real_current_font.number can change so we need to
1206                 // update the minibuffer
1207                 if (old_font != real_current_font)
1208                 bv->updateScrollbar();
1209                 break;
1210         }
1211
1212         case LFUN_URL: {
1213                 InsetCommandParams p("url");
1214                 string const data = InsetCommandMailer::params2string("url", p);
1215                 bv->owner()->getDialogs().show("url", data, 0);
1216                 break;
1217         }
1218
1219         case LFUN_HTMLURL: {
1220                 InsetCommandParams p("htmlurl");
1221                 string const data = InsetCommandMailer::params2string("url", p);
1222                 bv->owner()->getDialogs().show("url", data, 0);
1223                 break;
1224         }
1225
1226         case LFUN_INSERT_LABEL: {
1227                 InsetCommandParams p("label");
1228                 string const data = InsetCommandMailer::params2string("label", p);
1229                 bv->owner()->getDialogs().show("label", data, 0);
1230                 break;
1231         }
1232
1233
1234 #if 0
1235         case LFUN_INSET_LIST:
1236         case LFUN_INSET_THEOREM:
1237         case LFUN_INSET_CAPTION:
1238 #endif
1239         case LFUN_INSERT_NOTE:
1240         case LFUN_INSERT_CHARSTYLE:
1241         case LFUN_INSERT_BOX:
1242         case LFUN_INSERT_BRANCH:
1243         case LFUN_INSERT_BIBITEM:
1244         case LFUN_INSET_ERT:
1245         case LFUN_INSET_FLOAT:
1246         case LFUN_INSET_FOOTNOTE:
1247         case LFUN_INSET_MARGINAL:
1248         case LFUN_INSET_OPTARG:
1249         case LFUN_INSET_WIDE_FLOAT:
1250         case LFUN_INSET_WRAP:
1251         case LFUN_TABULAR_INSERT:
1252         case LFUN_ENVIRONMENT_INSERT:
1253                 // Open the inset, and move the current selection
1254                 // inside it.
1255                 doInsertInset(cur, this, cmd, true, true);
1256                 break;
1257
1258         case LFUN_INDEX_INSERT:
1259                 // Just open the inset
1260                 doInsertInset(cur, this, cmd, true, false);
1261                 break;
1262
1263         case LFUN_INDEX_PRINT:
1264         case LFUN_TOC_INSERT:
1265         case LFUN_HFILL:
1266         case LFUN_INSERT_LINE:
1267         case LFUN_INSERT_PAGEBREAK:
1268                 // do nothing fancy
1269                 doInsertInset(cur, this, cmd, false, false);
1270                 break;
1271
1272         case LFUN_DEPTH_MIN:
1273                 changeDepth(cur, bv_funcs::DEC_DEPTH);
1274                 cur.update();
1275                 break;
1276
1277         case LFUN_DEPTH_PLUS:
1278                 changeDepth(cur, bv_funcs::INC_DEPTH);
1279                 cur.update();
1280                 break;
1281
1282         case LFUN_MATH_DISPLAY:
1283                 mathDispatch(cur, this, cmd, true);
1284                 break;
1285
1286         case LFUN_MATH_IMPORT_SELECTION:
1287         case LFUN_MATH_MODE:
1288                 mathDispatch(cur, this, cmd, false);
1289                 break;
1290
1291         case LFUN_MATH_MACRO:
1292                 if (cmd.argument.empty())
1293                         cur.errorMessage(N_("Missing argument"));
1294                 else {
1295                         string s = cmd.argument;
1296                         string const s1 = token(s, ' ', 1);
1297                         int const nargs = s1.empty() ? 0 : atoi(s1);
1298                         string const s2 = token(s, ' ', 2);
1299                         string const type = s2.empty() ? "newcommand" : s2;
1300                         cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
1301                         cur.nextInset()->edit(cur, true);
1302                 }
1303                 break;
1304
1305         case LFUN_INSERT_MATH:
1306         case LFUN_INSERT_MATRIX:
1307         case LFUN_MATH_DELIM: {
1308                 cur.insert(new MathHullInset);
1309                 cur.dispatch(FuncRequest(LFUN_RIGHT));
1310                 cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
1311                 cur.dispatch(cmd);
1312                 break;
1313         }
1314
1315         case LFUN_EMPH: {
1316                 LyXFont font(LyXFont::ALL_IGNORE);
1317                 font.setEmph(LyXFont::TOGGLE);
1318                 toggleAndShow(cur, this, font);
1319                 break;
1320         }
1321
1322         case LFUN_BOLD: {
1323                 LyXFont font(LyXFont::ALL_IGNORE);
1324                 font.setSeries(LyXFont::BOLD_SERIES);
1325                 toggleAndShow(cur, this, font);
1326                 break;
1327         }
1328
1329         case LFUN_NOUN: {
1330                 LyXFont font(LyXFont::ALL_IGNORE);
1331                 font.setNoun(LyXFont::TOGGLE);
1332                 toggleAndShow(cur, this, font);
1333                 break;
1334         }
1335
1336         case LFUN_CODE: {
1337                 LyXFont font(LyXFont::ALL_IGNORE);
1338                 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
1339                 toggleAndShow(cur, this, font);
1340                 break;
1341         }
1342
1343         case LFUN_SANS: {
1344                 LyXFont font(LyXFont::ALL_IGNORE);
1345                 font.setFamily(LyXFont::SANS_FAMILY);
1346                 toggleAndShow(cur, this, font);
1347                 break;
1348         }
1349
1350         case LFUN_ROMAN: {
1351                 LyXFont font(LyXFont::ALL_IGNORE);
1352                 font.setFamily(LyXFont::ROMAN_FAMILY);
1353                 toggleAndShow(cur, this, font);
1354                 break;
1355         }
1356
1357         case LFUN_DEFAULT: {
1358                 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
1359                 toggleAndShow(cur, this, font);
1360                 break;
1361         }
1362
1363         case LFUN_UNDERLINE: {
1364                 LyXFont font(LyXFont::ALL_IGNORE);
1365                 font.setUnderbar(LyXFont::TOGGLE);
1366                 toggleAndShow(cur, this, font);
1367                 break;
1368         }
1369
1370         case LFUN_FONT_SIZE: {
1371                 LyXFont font(LyXFont::ALL_IGNORE);
1372                 font.setLyXSize(cmd.argument);
1373                 toggleAndShow(cur, this, font);
1374                 break;
1375         }
1376
1377         case LFUN_LANGUAGE: {
1378                 Language const * lang = languages.getLanguage(cmd.argument);
1379                 if (!lang)
1380                         break;
1381                 LyXFont font(LyXFont::ALL_IGNORE);
1382                 font.setLanguage(lang);
1383                 toggleAndShow(cur, this, font);
1384                 bv->switchKeyMap();
1385                 break;
1386         }
1387
1388         case LFUN_FREEFONT_APPLY:
1389                 toggleAndShow(cur, this, freefont, toggleall);
1390                 cur.message(_("Character set"));
1391                 break;
1392
1393         // Set the freefont using the contents of \param data dispatched from
1394         // the frontends and apply it at the current cursor location.
1395         case LFUN_FREEFONT_UPDATE: {
1396                 LyXFont font;
1397                 bool toggle;
1398                 if (bv_funcs::string2font(cmd.argument, font, toggle)) {
1399                         freefont = font;
1400                         toggleall = toggle;
1401                         toggleAndShow(cur, this, freefont, toggleall);
1402                         cur.message(_("Character set"));
1403                 }
1404                 break;
1405         }
1406
1407         case LFUN_FINISHED_LEFT:
1408                 lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
1409                 if (isRTL(cur.paragraph()))
1410                         cursorLeft(cur);
1411                 cur.bv().cursor() = cur;
1412                 break;
1413
1414         case LFUN_FINISHED_RIGHT:
1415                 lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
1416                 if (!isRTL(cur.paragraph()))
1417                         cursorRight(cur);
1418                 cur.bv().cursor() = cur;
1419                 break;
1420
1421         case LFUN_FINISHED_UP:
1422                 lyxerr << "handle LFUN_FINISHED_UP" << endl;
1423                 cursorUp(cur);
1424                 cur.bv().cursor() = cur;
1425                 break;
1426
1427         case LFUN_FINISHED_DOWN:
1428                 lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
1429                 cursorDown(cur);
1430                 cur.bv().cursor() = 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                 } else {
1496                         lyxerr << "Non-existent float type: "
1497                                << cmd.argument << endl;
1498                 }
1499                 break;
1500         }
1501
1502         case LFUN_ACCEPT_CHANGE: {
1503                 acceptChange(cur);
1504                 cur.update();
1505                 break;
1506         }
1507
1508         case LFUN_REJECT_CHANGE: {
1509                 rejectChange(cur);
1510                 cur.update();
1511                 break;
1512         }
1513
1514         case LFUN_THESAURUS_ENTRY: {
1515                 string arg = cmd.argument;
1516                 if (arg.empty()) {
1517                         arg = cur.selectionAsString(false);
1518                         // FIXME
1519                         if (arg.size() > 100 || arg.empty()) {
1520                                 // Get word or selection
1521                                 selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
1522                                 arg = cur.selectionAsString(false);
1523                         }
1524                 }
1525                 bv->owner()->getDialogs().show("thesaurus", arg);
1526                 break;
1527         }
1528
1529         case LFUN_PARAGRAPH_APPLY: {
1530                 // Given data, an encoding of the ParagraphParameters
1531                 // generated in the Paragraph dialog, this function sets
1532                 // the current paragraph appropriately.
1533                 istringstream is(cmd.argument);
1534                 LyXLex lex(0, 0);
1535                 lex.setStream(is);
1536                 ParagraphParameters params;
1537                 params.read(lex);
1538                 setParagraph(cur,
1539                                          params.spacing(),
1540                                          params.align(),
1541                                          params.labelWidthString(),
1542                                          params.noindent());
1543                 cur.update();
1544                 cur.message(_("Paragraph layout set"));
1545                 break;
1546         }
1547
1548         case LFUN_INSET_DIALOG_SHOW: {
1549                 InsetBase * inset = cur.nextInset();
1550                 if (inset) {
1551                         FuncRequest fr(LFUN_INSET_DIALOG_SHOW);
1552                         inset->dispatch(cur, fr);
1553                 }
1554                 break;
1555         }
1556
1557         case LFUN_ESCAPE:
1558                 if (cur.selection())
1559                         cur.selection() = false;
1560                 else
1561                         cmd = FuncRequest(LFUN_FINISHED_LEFT);
1562                 break;
1563
1564         default:
1565                 cur.undispatched();
1566                 break;
1567         }
1568 }
1569
1570
1571 bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
1572 {
1573         return false;
1574 }