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